Skip to content

Commit e42cc6c

Browse files
authored
Merge pull request #5904 from padhi-aws-forks/smt_struct_fix
Fix a crash during SMT translation of structs
2 parents 01c2cd1 + c2ec649 commit e42cc6c

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

regression/cbmc/struct15/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <assert.h>
2+
3+
struct test
4+
{
5+
unsigned int a;
6+
unsigned int b;
7+
};
8+
9+
int main()
10+
{
11+
struct test t;
12+
if(t.a > 10)
13+
assert(t.a > 0);
14+
}

regression/cbmc/struct15/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+
--trace --z3
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^map::at:
9+
key not found
10+
--
11+
This test checks the encoding of C `struct`s using SMT2 data types.

src/solvers/smt2/smt2_conv.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4890,8 +4890,10 @@ void smt2_convt::find_symbols_rec(
48904890

48914891
if(recstack.find(id) == recstack.end())
48924892
{
4893+
const auto &base_struct = ns.follow_tag(struct_tag);
48934894
recstack.insert(id);
4894-
find_symbols_rec(ns.follow_tag(struct_tag), recstack);
4895+
find_symbols_rec(base_struct, recstack);
4896+
datatype_map[type] = datatype_map[base_struct];
48954897
}
48964898
}
48974899
else if(type.id() == ID_union_tag)

src/solvers/smt2/smt2_conv.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ class smt2_convt : public stack_decision_proceduret
209209

210210
identifier_mapt identifier_map;
211211

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

0 commit comments

Comments
 (0)