Skip to content

Commit 3ad2a27

Browse files
authored
Merge pull request #4923 from smowton/smowton/fix/get-l1-object-empty-strings
get_l1_object: only set L0 and L1 if they are non-empty
2 parents 69a9528 + 56bb4c4 commit 3ad2a27

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/util/ssa_expr.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,10 @@ const ssa_exprt ssa_exprt::get_l1_object() const
160160
object_descriptor_exprt ode(get_original_expr());
161161

162162
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));
165167
::update_identifier(root);
166168

167169
return root;

src/util/ssa_expr.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,27 @@ class ssa_exprt:public symbol_exprt
9191
DATA_CHECK(
9292
vm, expr.id() == ID_symbol, "SSA expression symbols are symbols");
9393
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");
94115
}
95116

96117
static void validate(

unit/util/ssa_expr.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,20 @@ TEST_CASE("ssa_exprt::get_l1_object", "[unit][util][ssa_expr]")
211211
}
212212
}
213213
}
214+
215+
GIVEN("An ssa_exprt with its L2 index set")
216+
{
217+
const symbol_exprt symbol{"sym", int_type};
218+
ssa_exprt ssa{symbol};
219+
ssa.set_level_2(7);
220+
221+
WHEN("Its L1 object is taken")
222+
{
223+
const ssa_exprt l1_object = ssa.get_l1_object();
224+
THEN("It should compare equal to the base symbol")
225+
{
226+
REQUIRE(l1_object == ssa_exprt{symbol});
227+
}
228+
}
229+
}
214230
}

0 commit comments

Comments
 (0)