File tree Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -160,8 +160,10 @@ const ssa_exprt ssa_exprt::get_l1_object() const
160
160
object_descriptor_exprt ode (get_original_expr ());
161
161
162
162
ssa_exprt root (ode.root_object ());
163
- root.set (ID_L0, get (ID_L0));
164
- root.set (ID_L1, get (ID_L1));
163
+ if (!get_level_0 ().empty ())
164
+ root.set (ID_L0, get (ID_L0));
165
+ if (!get_level_1 ().empty ())
166
+ root.set (ID_L1, get (ID_L1));
165
167
::update_identifier (root);
166
168
167
169
return root;
Original file line number Diff line number Diff line change @@ -91,6 +91,27 @@ class ssa_exprt:public symbol_exprt
91
91
DATA_CHECK (
92
92
vm, expr.id () == ID_symbol, " SSA expression symbols are symbols" );
93
93
DATA_CHECK (vm, expr.get_bool (ID_C_SSA_symbol), " wrong SSA expression ID" );
94
+ // Check that each of the L0, L1 and L2 indices are either absent or are
95
+ // set to a non-empty value -- otherwise we could have two ssa_exprts that
96
+ // represent the same value (since get(ID_L0/1/2) will yield an empty string
97
+ // in both cases), but which do not compare equal (since irept::compare
98
+ // does not regard a missing key and an empty value as equivalent)
99
+ const auto &expr_sub = expr.get_named_sub ();
100
+ const auto expr_l0 = expr_sub.find (ID_L0);
101
+ const auto expr_l1 = expr_sub.find (ID_L1);
102
+ const auto expr_l2 = expr_sub.find (ID_L2);
103
+ DATA_CHECK (
104
+ vm,
105
+ expr_l0 == expr_sub.end () || !expr_l0->second .id ().empty (),
106
+ " L0 must not be an empty string" );
107
+ DATA_CHECK (
108
+ vm,
109
+ expr_l1 == expr_sub.end () || !expr_l1->second .id ().empty (),
110
+ " L1 must not be an empty string" );
111
+ DATA_CHECK (
112
+ vm,
113
+ expr_l2 == expr_sub.end () || !expr_l2->second .id ().empty (),
114
+ " L2 must not be an empty string" );
94
115
}
95
116
96
117
static void validate (
Original file line number Diff line number Diff line change @@ -172,6 +172,7 @@ TEST_CASE("ssa_exprt::get_l1_object", "[unit][util][ssa_expr]")
172
172
173
173
WHEN (" get_l1_object is called on the SSA expression" )
174
174
{
175
+
175
176
const ssa_exprt l1_object = ssa.get_l1_object ();
176
177
THEN (" level 0 and level 1 are the same, l2 is removed" )
177
178
{
@@ -211,4 +212,20 @@ TEST_CASE("ssa_exprt::get_l1_object", "[unit][util][ssa_expr]")
211
212
}
212
213
}
213
214
}
215
+
216
+ GIVEN (" An ssa_exprt with its L2 index set" )
217
+ {
218
+ const symbol_exprt symbol{" sym" , int_type};
219
+ ssa_exprt ssa{symbol};
220
+ ssa.set_level_2 (7 );
221
+
222
+ WHEN (" Its L1 object is taken" )
223
+ {
224
+ const ssa_exprt l1_object = ssa.get_l1_object ();
225
+ THEN (" It should compare equal to the base symbol" )
226
+ {
227
+ REQUIRE (l1_object == ssa_exprt{symbol});
228
+ }
229
+ }
230
+ }
214
231
}
You can’t perform that action at this time.
0 commit comments