Skip to content

Commit 6c387cc

Browse files
smowtontautschnig
authored andcommitted
Symex-dereference: simplify after deref
This is generally useful because it turns member-of-if into if-of-member, which avoids repeatedly quoting large complex if expressions in a with_exprt, but it is especially good for field sensitivity as it puts member expressions directly on top of symbol expressions, which field sensitivity knows how to deal with.
1 parent 54c5ff2 commit 6c387cc

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
: dynamic_object1#\d+\) WITH
9+
--
10+
The above pattern makes sure we don't have a conditional choice of objects
11+
within a "with" expression. We avoid having this by running the simplifier after
12+
dereferencing.

src/goto-symex/symex_dereference.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected]
1616
#include <util/byte_operators.h>
1717
#include <util/c_types.h>
1818
#include <util/exception_utils.h>
19+
#include <util/expr_util.h>
1920
#include <util/invariant.h>
2021
#include <util/pointer_offset_size.h>
2122

@@ -364,4 +365,30 @@ void goto_symext::dereference(exprt &expr, statet &state)
364365
// dereferencing may introduce new symbol_exprt
365366
// (like __CPROVER_memory)
366367
state.rename(expr, ns, goto_symex_statet::L1);
368+
369+
// Dereferencing is likely to introduce new member-of-if constructs --
370+
// for example, "x->field" may have become "(x == &o1 ? o1 : o2).field."
371+
// Run expression simplification, which converts that to
372+
// (x == &o1 ? o1.field : o2.field))
373+
// before applying field sensitivity. Field sensitivity can then turn such
374+
// field-of-symbol expressions into atomic SSA expressions instead of having
375+
// to rewrite all of 'o1' otherwise.
376+
// Even without field sensitivity this can be beneficial: for example,
377+
// "(b ? s1 : s2).member := X" results in
378+
// (b ? s1 : s2) := (b ? s1 : s2) with (member := X)
379+
// and then
380+
// s1 := b ? ((b ? s1 : s2) with (member := X)) : s1
381+
// when all we need is
382+
// s1 := s1 with (member := X) [and guard b]
383+
// s2 := s2 with (member := X) [and guard !b]
384+
do_simplify(expr);
385+
386+
if(symex_config.run_validation_checks)
387+
{
388+
// make sure simplify has not re-introduced any dereferencing that
389+
// had previously been cleaned away
390+
INVARIANT(
391+
!has_subexpr(expr, ID_dereference),
392+
"simplify re-introduced dereferencing");
393+
}
367394
}

0 commit comments

Comments
 (0)