Skip to content

Commit 22a7844

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.
1 parent caecde5 commit 22a7844

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

src/goto-symex/symex_assign.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,6 @@ void goto_symext::symex_assign_symbol(
199199
guardt &guard,
200200
assignment_typet assignment_type)
201201
{
202-
// do not assign to L1 objects that have gone out of scope --
203-
// pointer dereferencing may yield such objects; parameters do not
204-
// have an L2 entry set up beforehand either, so exempt them from
205-
// this check (all other L1 objects should have seen a declaration)
206-
const symbolt *s;
207-
if(!ns.lookup(lhs.get_object_name(), s) &&
208-
!s->is_parameter &&
209-
!lhs.get_level_1().empty() &&
210-
state.level2.current_count(lhs.get_identifier())==0)
211-
return;
212-
213202
exprt ssa_rhs=rhs;
214203

215204
// put assignment guard into the rhs

src/goto-symex/symex_goto.cpp

+14-8
Original file line numberDiff line numberDiff line change
@@ -458,17 +458,23 @@ void goto_symext::phi_function(
458458
// 1. Either guard is false, so we can't follow that branch.
459459
// 2. Either identifier is of generation zero, and so hasn't been
460460
// initialized and therefor an invalid target.
461-
if(dest_state.guard.is_false())
462-
rhs=goto_state_rhs;
463-
else if(goto_state.guard.is_false())
464-
rhs=dest_state_rhs;
465-
else if(goto_state.level2_current_count(l1_identifier) == 0)
461+
if(
462+
dest_state.guard.is_false() ||
463+
dest_state.level2.current_count(l1_identifier) == 0)
466464
{
467-
rhs = dest_state_rhs;
465+
if(goto_state.level2_current_count(l1_identifier) == 0)
466+
continue;
467+
468+
rhs=goto_state_rhs;
468469
}
469-
else if(dest_state.level2.current_count(l1_identifier) == 0)
470+
else if(
471+
goto_state.guard.is_false() ||
472+
goto_state.level2_current_count(l1_identifier) == 0)
470473
{
471-
rhs = goto_state_rhs;
474+
if(dest_state.level2.current_count(l1_identifier) == 0)
475+
continue;
476+
477+
rhs=dest_state_rhs;
472478
}
473479
else
474480
{

0 commit comments

Comments
 (0)