Skip to content

Commit f241b8b

Browse files
committed
More constant propagation
Constant propagation now yields different right-hand sides in a test.
1 parent 9cbe0cb commit f241b8b

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

jbmc/regression/jbmc-strings/long_string/test_abort.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Test.class
33
--function Test.checkAbort --trace
44
^EXIT=10$
55
^SIGNAL=0$
6-
dynamic_object[0-9]*=\(assignment removed\)
6+
dynamic_object[0-9]*=.*\?.*
77
--
88
--
99
This tests that the object does not appear in the trace, because concretizing
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
typedef struct _pair
2+
{
3+
int x;
4+
int y;
5+
} pair;
6+
7+
int __VERIFIER_nondet_int();
8+
9+
int main(void)
10+
{
11+
pair p1 = {.x = 0, .y = __VERIFIER_nondet_int()};
12+
pair p2 = {};
13+
p2.x = __VERIFIER_nondet_int();
14+
15+
__CPROVER_assert(p1.x == p2.y, "true by constant propagation");
16+
17+
return 0;
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
^Generated 1 VCC\(s\), 0 remaining after simplification$
8+
--
9+
^warning: ignoring

src/goto-symex/goto_symex_state.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ class goto_symex_is_constantt : public is_constantt
153153
*/
154154
return false;
155155
}
156+
else if(expr.id() == ID_if)
157+
{
158+
const if_exprt &if_expr = to_if_expr(expr);
159+
if(
160+
if_expr.true_case().id() == ID_if || if_expr.false_case().id() == ID_if)
161+
return false;
162+
}
163+
else if(expr.id() == ID_nondet_symbol)
164+
return true;
165+
else if(expr.id() == ID_symbol)
166+
{
167+
const irep_idt &obj_identifier = to_ssa_expr(expr).get_object_name();
168+
return obj_identifier == "goto_symex::\\guard";
169+
}
156170

157171
return is_constantt::is_constant(expr);
158172
}

src/util/expr_util.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ bool is_constantt::is_constant(const exprt &expr) const
240240
expr.id() == ID_with || expr.id() == ID_struct || expr.id() == ID_union ||
241241
// byte_update works, byte_extract may be out-of-bounds
242242
expr.id() == ID_byte_update_big_endian ||
243-
expr.id() == ID_byte_update_little_endian)
243+
expr.id() == ID_byte_update_little_endian ||
244+
// member works, index may be out-of-bounds
245+
expr.id() == ID_member || expr.id() == ID_if)
244246
{
245247
return std::all_of(
246248
expr.operands().begin(), expr.operands().end(), [this](const exprt &e) {
@@ -275,8 +277,12 @@ bool is_constantt::is_constant_address_of(const exprt &expr) const
275277

276278
return is_constant(deref.pointer());
277279
}
278-
else if(expr.id() == ID_string_constant)
280+
else if(
281+
expr.id() == ID_string_constant || expr.id() == ID_array ||
282+
expr.id() == ID_struct || expr.id() == ID_union)
283+
{
279284
return true;
285+
}
280286

281287
return false;
282288
}

0 commit comments

Comments
 (0)