Skip to content

Commit 72f3bea

Browse files
committed
Skip phi assignment if one of the merged states has an uninitialised object
With level-2 counters incremented on declaration and non-deterministic initialisation upon allocation, the only remaining sources are pointer dereferencing, where uninitialised objects necessarily refer to invalid objects. This is a cleaner implementation of 369f077. Removing only the code introduced in 369f077 would yield a wrong result for regression/cbmc/Local_out_of_scope3. It also fixes the problem of extern symbols not having an initial value, and thus being skipped. Fixes: #1630
1 parent c9b37c7 commit 72f3bea

File tree

5 files changed

+34
-20
lines changed

5 files changed

+34
-20
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/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33

44
^EXIT=10$

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

+14-8
Original file line numberDiff line numberDiff line change
@@ -469,17 +469,23 @@ static void merge_names(
469469
// 1. Either guard is false, so we can't follow that branch.
470470
// 2. Either identifier is of generation zero, and so hasn't been
471471
// initialized and therefore an invalid target.
472-
if(dest_state.guard.is_false())
473-
rhs = goto_state_rhs;
474-
else if(goto_state.guard.is_false())
475-
rhs = dest_state_rhs;
476-
else if(goto_count == 0)
472+
if(
473+
dest_state.guard.is_false() ||
474+
(dest_count == 0 && !symbol.value.is_not_nil()))
477475
{
478-
rhs = dest_state_rhs;
476+
if(goto_count == 0)
477+
return;
478+
479+
rhs = goto_state_rhs;
479480
}
480-
else if(dest_count == 0)
481+
else if(
482+
goto_state.guard.is_false() ||
483+
(goto_count == 0 && symbol.value.is_not_nil()))
481484
{
482-
rhs = goto_state_rhs;
485+
if(dest_count == 0)
486+
return;
487+
488+
rhs = dest_state_rhs;
483489
}
484490
else
485491
{

0 commit comments

Comments
 (0)