Skip to content

Commit eb53ca4

Browse files
committed
Fix goto-symex' auto-objects feature
The included test also demonstrates how to use it.
1 parent 2e6200a commit eb53ca4

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
@@ -85,11 +85,14 @@ void goto_symext::trigger_auto_object(const exprt &expr, statet &state)
8585
{
8686
const symbolt &symbol = ns.lookup(obj_identifier);
8787

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

src/goto-symex/symex_dereference.cpp

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

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

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

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

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

0 commit comments

Comments
 (0)