|
22 | 22 | // update_exprt.
|
23 | 23 | // #define USE_UPDATE
|
24 | 24 |
|
| 25 | +constexpr bool use_update() |
| 26 | +{ |
| 27 | +#ifdef USE_UPDATE |
| 28 | + return true; |
| 29 | +#else |
| 30 | + return false; |
| 31 | +#endif |
| 32 | +} |
| 33 | + |
25 | 34 | /// Store the \p what expression by recursively descending into the operands
|
26 | 35 | /// of \p lhs until the first operand \c op0 is _nil_: this _nil_ operand
|
27 | 36 | /// is then replaced with \p what.
|
@@ -151,76 +160,81 @@ struct assignmentt final
|
151 | 160 | /// \param assignment: an assignment to rewrite
|
152 | 161 | /// \param ns: namespace
|
153 | 162 | /// \return the updated assignment
|
| 163 | +template <bool use_update> |
154 | 164 | static assignmentt rewrite_with_to_field_symbols(
|
155 | 165 | goto_symext::statet &state,
|
156 | 166 | assignmentt assignment,
|
157 | 167 | const namespacet &ns)
|
158 | 168 | {
|
159 | 169 | exprt &ssa_rhs = assignment.rhs;
|
160 | 170 | ssa_exprt &lhs_mod = assignment.lhs;
|
161 |
| -#ifdef USE_UPDATE |
162 |
| - while(ssa_rhs.id() == ID_update && |
163 |
| - to_update_expr(ssa_rhs).designator().size() == 1 && |
164 |
| - (lhs_mod.type().id() == ID_array || lhs_mod.type().id() == ID_struct || |
165 |
| - lhs_mod.type().id() == ID_struct_tag)) |
| 171 | + if(use_update) |
166 | 172 | {
|
167 |
| - exprt field_sensitive_lhs; |
168 |
| - const update_exprt &update = to_update_expr(ssa_rhs); |
169 |
| - PRECONDITION(update.designator().size() == 1); |
170 |
| - const exprt &designator = update.designator().front(); |
171 |
| - |
172 |
| - if(lhs_mod.type().id() == ID_array) |
| 173 | + while(ssa_rhs.id() == ID_update && |
| 174 | + to_update_expr(ssa_rhs).designator().size() == 1 && |
| 175 | + (lhs_mod.type().id() == ID_array || |
| 176 | + lhs_mod.type().id() == ID_struct || |
| 177 | + lhs_mod.type().id() == ID_struct_tag)) |
173 | 178 | {
|
174 |
| - field_sensitive_lhs = |
175 |
| - index_exprt(lhs_mod, to_index_designator(designator).index()); |
176 |
| - } |
177 |
| - else |
178 |
| - { |
179 |
| - field_sensitive_lhs = member_exprt( |
180 |
| - lhs_mod, |
181 |
| - to_member_designator(designator).get_component_name(), |
182 |
| - update.new_value().type()); |
183 |
| - } |
| 179 | + exprt field_sensitive_lhs; |
| 180 | + const update_exprt &update = to_update_expr(ssa_rhs); |
| 181 | + PRECONDITION(update.designator().size() == 1); |
| 182 | + const exprt &designator = update.designator().front(); |
| 183 | + |
| 184 | + if(lhs_mod.type().id() == ID_array) |
| 185 | + { |
| 186 | + field_sensitive_lhs = |
| 187 | + index_exprt(lhs_mod, to_index_designator(designator).index()); |
| 188 | + } |
| 189 | + else |
| 190 | + { |
| 191 | + field_sensitive_lhs = member_exprt( |
| 192 | + lhs_mod, |
| 193 | + to_member_designator(designator).get_component_name(), |
| 194 | + update.new_value().type()); |
| 195 | + } |
184 | 196 |
|
185 |
| - state.field_sensitivity.apply(ns, state, field_sensitive_lhs, true); |
| 197 | + state.field_sensitivity.apply(ns, state, field_sensitive_lhs, true); |
186 | 198 |
|
187 |
| - if(field_sensitive_lhs.id() != ID_symbol) |
188 |
| - break; |
| 199 | + if(field_sensitive_lhs.id() != ID_symbol) |
| 200 | + break; |
189 | 201 |
|
190 |
| - ssa_rhs = update.new_value(); |
191 |
| - lhs_mod = to_ssa_expr(field_sensitive_lhs); |
| 202 | + ssa_rhs = update.new_value(); |
| 203 | + lhs_mod = to_ssa_expr(field_sensitive_lhs); |
| 204 | + } |
192 | 205 | }
|
193 |
| -#else |
194 |
| - while(ssa_rhs.id() == ID_with && |
195 |
| - to_with_expr(ssa_rhs).operands().size() == 3 && |
196 |
| - (lhs_mod.type().id() == ID_array || lhs_mod.type().id() == ID_struct || |
197 |
| - lhs_mod.type().id() == ID_struct_tag)) |
| 206 | + else |
198 | 207 | {
|
199 |
| - exprt field_sensitive_lhs; |
200 |
| - const with_exprt &with_expr = to_with_expr(ssa_rhs); |
201 |
| - |
202 |
| - if(lhs_mod.type().id() == ID_array) |
| 208 | + while( |
| 209 | + ssa_rhs.id() == ID_with && to_with_expr(ssa_rhs).operands().size() == 3 && |
| 210 | + (lhs_mod.type().id() == ID_array || lhs_mod.type().id() == ID_struct || |
| 211 | + lhs_mod.type().id() == ID_struct_tag)) |
203 | 212 | {
|
204 |
| - field_sensitive_lhs = index_exprt(lhs_mod, with_expr.where()); |
205 |
| - } |
206 |
| - else |
207 |
| - { |
208 |
| - field_sensitive_lhs = member_exprt( |
209 |
| - lhs_mod, |
210 |
| - with_expr.where().get(ID_component_name), |
211 |
| - with_expr.new_value().type()); |
212 |
| - } |
| 213 | + exprt field_sensitive_lhs; |
| 214 | + const with_exprt &with_expr = to_with_expr(ssa_rhs); |
213 | 215 |
|
214 |
| - field_sensitive_lhs = state.field_sensitivity.apply( |
215 |
| - ns, state, std::move(field_sensitive_lhs), true); |
| 216 | + if(lhs_mod.type().id() == ID_array) |
| 217 | + { |
| 218 | + field_sensitive_lhs = index_exprt(lhs_mod, with_expr.where()); |
| 219 | + } |
| 220 | + else |
| 221 | + { |
| 222 | + field_sensitive_lhs = member_exprt( |
| 223 | + lhs_mod, |
| 224 | + with_expr.where().get(ID_component_name), |
| 225 | + with_expr.new_value().type()); |
| 226 | + } |
| 227 | + |
| 228 | + field_sensitive_lhs = state.field_sensitivity.apply( |
| 229 | + ns, state, std::move(field_sensitive_lhs), true); |
216 | 230 |
|
217 |
| - if(field_sensitive_lhs.id() != ID_symbol) |
218 |
| - break; |
| 231 | + if(field_sensitive_lhs.id() != ID_symbol) |
| 232 | + break; |
219 | 233 |
|
220 |
| - ssa_rhs = with_expr.new_value(); |
221 |
| - lhs_mod = to_ssa_expr(field_sensitive_lhs); |
| 234 | + ssa_rhs = with_expr.new_value(); |
| 235 | + lhs_mod = to_ssa_expr(field_sensitive_lhs); |
| 236 | + } |
222 | 237 | }
|
223 |
| -#endif |
224 | 238 | return assignment;
|
225 | 239 | }
|
226 | 240 |
|
@@ -363,7 +377,8 @@ void symex_assignt::assign_non_struct_symbol(
|
363 | 377 | // in the future these should be omitted.
|
364 | 378 | auto assignment = shift_indexed_access_to_lhs(
|
365 | 379 | state, assignmentt{lhs, std::move(l2_rhs)}, ns, symex_config.simplify_opt);
|
366 |
| - assignment = rewrite_with_to_field_symbols(state, std::move(assignment), ns); |
| 380 | + assignment = rewrite_with_to_field_symbols<use_update()>( |
| 381 | + state, std::move(assignment), ns); |
367 | 382 |
|
368 | 383 | if(symex_config.simplify_opt)
|
369 | 384 | assignment.rhs = simplify_expr(std::move(assignment.rhs), ns);
|
|
0 commit comments