Skip to content

Commit 124c7ff

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. Fixes: #1630
1 parent 87ce172 commit 124c7ff

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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,
11+
__CPROVER_assert (thlocal == 123, "hello");
12+
}
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

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
@@ -452,17 +452,23 @@ void goto_symext::phi_function(
452452
// 1. Either guard is false, so we can't follow that branch.
453453
// 2. Either identifier is of generation zero, and so hasn't been
454454
// initialized and therefor an invalid target.
455-
if(dest_state.guard.is_false())
456-
rhs=goto_state_rhs;
457-
else if(goto_state.guard.is_false())
458-
rhs=dest_state_rhs;
459-
else if(goto_state.level2_current_count(l1_identifier) == 0)
455+
if(
456+
dest_state.guard.is_false() ||
457+
dest_state.level2.current_count(l1_identifier) == 0)
460458
{
461-
rhs = dest_state_rhs;
459+
if(goto_state.level2_current_count(l1_identifier) == 0)
460+
continue;
461+
462+
rhs = goto_state_rhs;
462463
}
463-
else if(dest_state.level2.current_count(l1_identifier) == 0)
464+
else if(
465+
goto_state.guard.is_false() ||
466+
goto_state.level2_current_count(l1_identifier) == 0)
464467
{
465-
rhs = goto_state_rhs;
468+
if(dest_state.level2.current_count(l1_identifier) == 0)
469+
continue;
470+
471+
rhs = dest_state_rhs;
466472
}
467473
else
468474
{

0 commit comments

Comments
 (0)