Skip to content

Commit 369f077

Browse files
committed
Do not assign to objects that have gone out of scope
Pointer dereferencing may yield objects that have meanwhile gone out of scope. Assigning to them is unnecessary, and performing a merge on those would yield inconsistent equations (as witnessed by the included regression test). Filtering out the merge in phi nodes is not easily possible as there are several cases where it is permissible that only one of the states entering the phi node has an (L1) object, such as declarations only seen in one branch. Fixes: #1115
1 parent 32b68ce commit 369f077

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
unsigned int *GLOBAL_POINTER[1];
2+
3+
int index;
4+
5+
void f(void)
6+
{
7+
unsigned int actual=0u;
8+
GLOBAL_POINTER[0] = &actual;
9+
10+
if(index==0)
11+
*GLOBAL_POINTER[index] = 1u;
12+
else
13+
actual = 2u;
14+
15+
__CPROVER_assume(1u == actual);
16+
}
17+
18+
void main(void)
19+
{
20+
index=nondet_int();
21+
f();
22+
f();
23+
__CPROVER_assert(0==1, "");
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
^warning: ignoring

src/goto-symex/symex_assign.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ void goto_symext::symex_assign_symbol(
209209
guardt &guard,
210210
assignment_typet assignment_type)
211211
{
212+
// do not assign to L1 objects that have gone out of scope --
213+
// pointer dereferencing may yield such objects; parameters do not
214+
// have an L2 entry set up beforehand either, so exempt them from
215+
// this check (all other L1 objects should have seen a declaration)
216+
const symbolt *s;
217+
if(!ns.lookup(lhs.get_object_name(), s) &&
218+
!s->is_parameter &&
219+
!lhs.get_level_1().empty() &&
220+
state.level2.current_count(lhs.get_identifier())==0)
221+
return;
222+
212223
exprt ssa_rhs=rhs;
213224

214225
// put assignment guard into the rhs

0 commit comments

Comments
 (0)