Skip to content

Commit 3f7757e

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 d58448f commit 3f7757e

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
@@ -203,17 +203,6 @@ void goto_symext::symex_assign_symbol(
203203
guardt &guard,
204204
assignment_typet assignment_type)
205205
{
206-
// do not assign to L1 objects that have gone out of scope --
207-
// pointer dereferencing may yield such objects; parameters do not
208-
// have an L2 entry set up beforehand either, so exempt them from
209-
// this check (all other L1 objects should have seen a declaration)
210-
const symbolt *s;
211-
if(!ns.lookup(lhs.get_object_name(), s) &&
212-
!s->is_parameter &&
213-
!lhs.get_level_1().empty() &&
214-
state.level2.current_count(lhs.get_identifier())==0)
215-
return;
216-
217206
exprt ssa_rhs=rhs;
218207

219208
// 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)