Skip to content

Commit e39318d

Browse files
authored
Merge pull request #4545 from tautschnig/uninitialised-struct-fix
Create SSA-level 2 names for individual fields
2 parents d535b09 + 24f4674 commit e39318d

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

regression/cbmc/struct14/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct S
2+
{
3+
int x;
4+
};
5+
6+
int main(int argc, char *argv[])
7+
{
8+
struct S s;
9+
10+
if(argc > 3)
11+
s.x = 42;
12+
13+
__CPROVER_assert(s.x == 42, "should fail");
14+
}

regression/cbmc/struct14/test.desc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
^warning: ignoring
9+
--
10+
With field-sensitive SSA encoding we need to make sure that each struct member
11+
is treated as non-deterministic unless initialised.

src/goto-symex/symex_decl.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,17 @@ void goto_symext::symex_decl(statet &state, const symbol_exprt &expr)
6464
}
6565

6666
// L2 renaming
67-
std::size_t generation = state.increase_generation(l1_identifier, ssa);
68-
CHECK_RETURN(generation == 1);
67+
const exprt fields = state.field_sensitivity.get_fields(ns, state, ssa);
68+
std::set<symbol_exprt> fields_set;
69+
find_symbols(fields, fields_set);
70+
71+
for(const auto &l1_symbol : fields_set)
72+
{
73+
ssa_exprt field_ssa = to_ssa_expr(l1_symbol);
74+
std::size_t field_generation =
75+
state.increase_generation(l1_symbol.get_identifier(), field_ssa);
76+
CHECK_RETURN(field_generation == 1);
77+
}
6978

7079
const bool record_events=state.record_events;
7180
state.record_events=false;

0 commit comments

Comments
 (0)