Skip to content

Fix a crash during SMT translation of structs #5904

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 1 commit into from
Mar 31, 2021
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
14 changes: 14 additions & 0 deletions regression/cbmc/struct15/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <assert.h>

struct test
{
unsigned int a;
unsigned int b;
};

int main()
{
struct test t;
if(t.a > 10)
assert(t.a > 0);
}
11 changes: 11 additions & 0 deletions regression/cbmc/struct15/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
main.c
--trace --z3
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^map::at:
key not found
--
This test checks the encoding of C `struct`s using SMT2 data types.
4 changes: 3 additions & 1 deletion src/solvers/smt2/smt2_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4890,8 +4890,10 @@ void smt2_convt::find_symbols_rec(

if(recstack.find(id) == recstack.end())
{
const auto &base_struct = ns.follow_tag(struct_tag);
recstack.insert(id);
find_symbols_rec(ns.follow_tag(struct_tag), recstack);
find_symbols_rec(base_struct, recstack);
datatype_map[type] = datatype_map[base_struct];
}
}
else if(type.id() == ID_union_tag)
Expand Down
6 changes: 4 additions & 2 deletions src/solvers/smt2/smt2_conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,10 @@ class smt2_convt : public stack_decision_proceduret

identifier_mapt identifier_map;

// for modeling structs as Z3 datatype, enabled when
// use_datatype is set
// for modeling structs as SMT datatype when use_datatype is set
//
// it maintains a map of `struct_typet` or `struct_tag_typet`
// to datatype names declared in SMT
typedef std::map<typet, std::string> datatype_mapt;
datatype_mapt datatype_map;

Expand Down