Skip to content

Commit a94389d

Browse files
authored
Merge pull request #2220 from tautschnig/phi-cleanup
Skip phi assignment if one of the merged states has an uninitialised object [blocks: #35, #2574, #3486]
2 parents 5594db6 + eaa7d93 commit a94389d

File tree

6 files changed

+50
-14
lines changed

6 files changed

+50
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
int __CPROVER_thread_local thlocal = 4;
2+
3+
int main()
4+
{
5+
int loc;
6+
7+
loc = 123;
8+
9+
__CPROVER_ASYNC_3:
10+
thlocal = loc, __CPROVER_assert(thlocal == 123, "hello");
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

regression/cbmc/extern3/main.c

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <assert.h>
2+
3+
extern int x;
4+
5+
int main(int argc, char *argv[])
6+
{
7+
if(argc > 5)
8+
x = 42;
9+
10+
__CPROVER_assert(x == 42, "should fail");
11+
}

regression/cbmc/extern3/test.desc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
--
9+
The change to phi_function of 646cf29941499 failed to consider the case of
10+
extern variables, which we leave uninitialised.

src/goto-symex/symex_assign.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,6 @@ void goto_symext::symex_assign_symbol(
218218
guardt &guard,
219219
assignment_typet assignment_type)
220220
{
221-
// do not assign to L1 objects that have gone out of scope --
222-
// pointer dereferencing may yield such objects; parameters do not
223-
// have an L2 entry set up beforehand either, so exempt them from
224-
// this check (all other L1 objects should have seen a declaration)
225-
const symbolt *s;
226-
if(!ns.lookup(lhs.get_object_name(), s) &&
227-
!s->is_parameter &&
228-
!lhs.get_level_1().empty() &&
229-
state.level2.current_count(lhs.get_identifier())==0)
230-
return;
231-
232221
exprt ssa_rhs=rhs;
233222

234223
// put assignment guard into the rhs

src/goto-symex/symex_goto.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,14 @@ static void merge_names(
423423
if(goto_count == dest_count)
424424
return; // not at all changed
425425

426-
// changed!
426+
// changed - but only on a branch that is now dead, and the other branch is
427+
// uninitialized/invalid
428+
if(
429+
(dest_state.guard.is_false() && goto_count == 0) ||
430+
(goto_state.guard.is_false() && dest_count == 0))
431+
{
432+
return;
433+
}
427434

428435
// shared variables are renamed on every access anyway, we don't need to
429436
// merge anything
@@ -473,11 +480,11 @@ static void merge_names(
473480
rhs = goto_state_rhs;
474481
else if(goto_state.guard.is_false())
475482
rhs = dest_state_rhs;
476-
else if(goto_count == 0)
483+
else if(goto_count == 0 && symbol.value.is_not_nil())
477484
{
478485
rhs = dest_state_rhs;
479486
}
480-
else if(dest_count == 0)
487+
else if(dest_count == 0 && symbol.value.is_not_nil())
481488
{
482489
rhs = goto_state_rhs;
483490
}

0 commit comments

Comments
 (0)