Skip to content

Symex: Simplify left-hand side #7700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions regression/cbmc/simplify-array-size/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <stdlib.h>
#include <string.h>

struct state
{
size_t size;
int slots[];
};

struct hash_table
{
struct state *p_impl;
};

void main(void)
{
struct hash_table map;
size_t num_entries;
__CPROVER_assume(num_entries <= 8ul);
size_t required_bytes = num_entries * sizeof(int) + sizeof(struct state);
struct state *impl = malloc(required_bytes);
if(impl != NULL)
{
impl->size = num_entries;
map.p_impl = impl;
}
else
map.p_impl = NULL;

if(impl != NULL)
{
// keep this line even though it is never read
struct state *state = impl;
memset(impl->slots, 0, sizeof(int) * map.p_impl->size);
}
}
12 changes: 12 additions & 0 deletions regression/cbmc/simplify-array-size/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE broken-smt-backend
main.c
--malloc-may-fail --malloc-fail-null
^VERIFICATION SUCCESSFUL$
^EXIT=0$
^SIGNAL=0$
--
^Invariant check failed
^warning: ignoring
--
Simplification of array sizes must be applied consistently and must not result
in value-set assignment invariant failures.
2 changes: 2 additions & 0 deletions src/goto-symex/goto_symex_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ renamedt<ssa_exprt, L2> goto_symex_statet::assignment(

// the type might need renaming
rename<L2>(lhs.type(), l1_identifier, ns);
if(rhs_is_simplified)
simplify(lhs, ns);
lhs.update_type();
if(run_validation_checks)
{
Expand Down