Skip to content

Commit 70e557e

Browse files
committed
Fix goto-symex' auto-objects feature
The included test also demonstrates how to use it.
1 parent 0325f8e commit 70e557e

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

regression/cbmc/auto_objects1/main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
int main()
2+
{
3+
int *auto_object_source1;
4+
#pragma CPROVER check push
5+
#pragma CPROVER check disable "pointer"
6+
if(auto_object_source1 != 0)
7+
int dummy = *auto_object_source1; // triggers creating an auto object
8+
#pragma CPROVER check pop
9+
if(auto_object_source1 != 0 && *auto_object_source1 == 42) // uses auto object
10+
{
11+
__CPROVER_assert(*auto_object_source1 == 42, "42");
12+
}
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--pointer-check
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring

src/goto-symex/auto_objects.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,14 @@ void goto_symext::trigger_auto_object(const exprt &expr, statet &state)
8484
{
8585
const symbolt &symbol = ns.lookup(obj_identifier);
8686

87-
if(has_prefix(id2string(symbol.base_name), "symex::auto_object"))
87+
if(
88+
has_prefix(id2string(symbol.base_name), "symex::auto_object") ||
89+
has_prefix(id2string(symbol.base_name), "auto_object"))
8890
{
8991
// done already?
90-
if(!state.get_level2().current_names.has_key(
91-
ssa_expr.get_identifier()))
92+
auto l2_index =
93+
state.get_level2().current_names.find(ssa_expr.get_identifier());
94+
if(!l2_index.has_value() || l2_index->get().second == 1)
9295
{
9396
initialize_auto_object(e, state);
9497
}

src/goto-symex/symex_dereference.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ void goto_symext::dereference_rec(
320320

321321
tmp1 = state.field_sensitivity.apply(ns, state, std::move(tmp1), false);
322322

323+
// this may yield a new auto-object
324+
trigger_auto_object(tmp1, state);
325+
323326
// we need to set up some elaborate call-backs
324327
symex_dereference_statet symex_dereference_state(state, ns);
325328

@@ -336,10 +339,6 @@ void goto_symext::dereference_rec(
336339
dereference.dereference(tmp1, symex_config.show_points_to_sets);
337340
// std::cout << "**** " << format(tmp2) << '\n';
338341

339-
340-
// this may yield a new auto-object
341-
trigger_auto_object(tmp2, state);
342-
343342
// Check various conditions for when we should try to cache the expression.
344343
// 1. Caching dereferences must be enabled.
345344
// 2. Do not cache inside LHS of writes.

0 commit comments

Comments
 (0)