Skip to content

Commit 1a4bd38

Browse files
authored
Merge pull request #7105 from thomasspriggs/tas/const-prop-returns
Perform remove_returns pass before constant_propagator
2 parents 760ad1b + e4ef59e commit 1a4bd38

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <assert.h>
2+
int ab, bc;
3+
int f(int x)
4+
{
5+
ab = 1 + 1 + 1 + 1;
6+
bc = ab + x;
7+
return ab + bc;
8+
}
9+
int main()
10+
{
11+
int a;
12+
a = -4;
13+
int b;
14+
b = nondet();
15+
a = f(a);
16+
assert(!(0 <= a && a < 5 && 0 <= b && b < 5));
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CORE
2+
main.c
3+
--constant-propagator
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
Removing returns
7+
VERIFICATION FAILED
8+
ASSIGN main\:\:1\:\:a \:\= 4
9+
ASSERT ¬\(main::1::b ≥ 0\) ∨ main::1::b ≥ 5
10+
--
11+
^warning: ignoring
12+
ASSERT true
13+
--
14+
This tests that constants are propagated through function calls, correctly
15+
taking into account the return value. Constant propagation should result in
16+
simplifying away the conditions in the assertion on `a` but not the conditions
17+
on `b`.

src/goto-instrument/goto_instrument_parse_options.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,7 @@ void goto_instrument_parse_optionst::instrument_goto_program()
12851285
if(cmdline.isset("constant-propagator"))
12861286
{
12871287
do_indirect_call_and_rtti_removal();
1288+
do_remove_returns();
12881289

12891290
log.status() << "Propagating Constants" << messaget::eom;
12901291

0 commit comments

Comments
 (0)