Skip to content

Commit dec8c60

Browse files
committed
Symex: Simplify left-hand side
With #7622 we may have syntactically changed the type on the right-hand side via simplification. To maintain syntactic type equality we need to apply simplifications on the left-hand side as well. See https://github.com/awslabs/aws-c-common/actions/runs/4822448417 for an example where this failed after #7622.
1 parent cafbcc4 commit dec8c60

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <stdlib.h>
2+
#include <string.h>
3+
4+
struct state
5+
{
6+
size_t size;
7+
int slots[];
8+
};
9+
10+
struct hash_table
11+
{
12+
struct state *p_impl;
13+
};
14+
15+
void main(void)
16+
{
17+
struct hash_table map;
18+
size_t num_entries;
19+
__CPROVER_assume(num_entries <= 8ul);
20+
size_t required_bytes = num_entries * sizeof(int) + sizeof(struct state);
21+
struct state *impl = malloc(required_bytes);
22+
if(impl != NULL)
23+
{
24+
impl->size = num_entries;
25+
map.p_impl = impl;
26+
}
27+
else
28+
map.p_impl = NULL;
29+
30+
if(impl != NULL)
31+
{
32+
// keep this line even though it is never read
33+
struct state *state = impl;
34+
memset(impl->slots, 0, sizeof(int) * map.p_impl->size);
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE broken-smt-backend
2+
main.c
3+
--malloc-may-fail --malloc-fail-null
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^Invariant check failed
9+
^warning: ignoring
10+
--
11+
Simplification of array sizes must be applied consistently and must not result
12+
in value-set assignment invariant failures.

src/goto-symex/goto_symex_state.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ renamedt<ssa_exprt, L2> goto_symex_statet::assignment(
8484

8585
// the type might need renaming
8686
rename<L2>(lhs.type(), l1_identifier, ns);
87+
if(rhs_is_simplified)
88+
simplify(lhs, ns);
8789
lhs.update_type();
8890
if(run_validation_checks)
8991
{

0 commit comments

Comments
 (0)