Skip to content

Do not assign to objects that have gone out of scope #1116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions regression/cbmc/Local_out_of_scope3/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
unsigned int *GLOBAL_POINTER[1];

int index;

void f(void)
{
unsigned int actual=0u;
GLOBAL_POINTER[0] = &actual;

if(index==0)
*GLOBAL_POINTER[index] = 1u;
else
actual = 2u;

__CPROVER_assume(1u == actual);
}

void main(void)
{
index=nondet_int();
f();
f();
__CPROVER_assert(0==1, "");
}
8 changes: 8 additions & 0 deletions regression/cbmc/Local_out_of_scope3/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c

^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
^warning: ignoring
11 changes: 11 additions & 0 deletions src/goto-symex/symex_assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ void goto_symext::symex_assign_symbol(
guardt &guard,
assignment_typet assignment_type)
{
// do not assign to L1 objects that have gone out of scope --
// pointer dereferencing may yield such objects; parameters do not
// have an L2 entry set up beforehand either, so exempt them from
// this check (all other L1 objects should have seen a declaration)
const symbolt *s;
if(!ns.lookup(lhs.get_object_name(), s) &&
!s->is_parameter &&
!lhs.get_level_1().empty() &&
state.level2.current_count(lhs.get_identifier())==0)
return;

exprt ssa_rhs=rhs;

// put assignment guard into the rhs
Expand Down