Skip to content

Commit 15c7af1

Browse files
committed
Skip phi assignment if neither merged state has an initialised object
With non-deterministic initialisation performed on declaration and allocation, the only remaining sources are pointer dereferencing, where uninitialised objects necessarily refer to invalid objects. This is a cleaner implementation of 369f077 as well as removing the dubious init_l1 from "Explicitly initialise non-static objects with non-deterministic values".
1 parent b24ccd0 commit 15c7af1

File tree

4 files changed

+14
-31
lines changed

4 files changed

+14
-31
lines changed

src/goto-symex/goto_symex.h

-2
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,6 @@ class goto_symext
271271
irep_idt guard_identifier;
272272

273273
// symex
274-
irep_idt init_l1;
275-
276274
virtual void symex_transition(
277275
statet &,
278276
goto_programt::const_targett to,

src/goto-symex/symex_assign.cpp

-20
Original file line numberDiff line numberDiff line change
@@ -199,26 +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(
208-
init_l1 != lhs.get_identifier() && !ns.lookup(lhs.get_object_name(), s) &&
209-
!s->is_parameter && !lhs.get_level_1().empty() &&
210-
state.level2.current_count(lhs.get_identifier()) == 0)
211-
{
212-
return;
213-
}
214-
else if(init_l1 == lhs.get_identifier())
215-
{
216-
// the assignment about to happen is the initialisation, clear the
217-
// identifier to make sure future steps are not treated as initialisation
218-
// steps (and we thus cannot reach the early return above
219-
init_l1.clear();
220-
}
221-
222202
exprt ssa_rhs=rhs;
223203

224204
// put assignment guard into the rhs

src/goto-symex/symex_decl.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ void goto_symext::symex_decl(statet &state, const symbol_exprt &expr)
5555
if(state.level2.current_names.find(l1_identifier)==
5656
state.level2.current_names.end())
5757
state.level2.current_names[l1_identifier]=std::make_pair(ssa, 0);
58-
init_l1 = l1_identifier;
5958

6059
// optimisation: skip non-deterministic initialisation if the next instruction
6160
// will take care of initialisation (but ensure int x=x; is handled properly)

src/goto-symex/symex_goto.cpp

+14-8
Original file line numberDiff line numberDiff line change
@@ -447,17 +447,23 @@ void goto_symext::phi_function(
447447
// 1. Either guard is false, so we can't follow that branch.
448448
// 2. Either identifier is of generation zero, and so hasn't been
449449
// initialized and therefor an invalid target.
450-
if(dest_state.guard.is_false())
451-
rhs=goto_state_rhs;
452-
else if(goto_state.guard.is_false())
453-
rhs=dest_state_rhs;
454-
else if(goto_state.level2_current_count(l1_identifier) == 0)
450+
if(
451+
dest_state.guard.is_false() ||
452+
dest_state.level2.current_count(l1_identifier) == 0)
455453
{
456-
rhs = dest_state_rhs;
454+
if(goto_state.level2_current_count(l1_identifier) == 0)
455+
continue;
456+
457+
rhs=goto_state_rhs;
457458
}
458-
else if(dest_state.level2.current_count(l1_identifier) == 0)
459+
else if(
460+
goto_state.guard.is_false() ||
461+
goto_state.level2_current_count(l1_identifier) == 0)
459462
{
460-
rhs = goto_state_rhs;
463+
if(dest_state.level2.current_count(l1_identifier) == 0)
464+
continue;
465+
466+
rhs=dest_state_rhs;
461467
}
462468
else
463469
{

0 commit comments

Comments
 (0)