Skip to content

Commit bd3715f

Browse files
committed
Fix SMT2 DT encoding of structs
This commit fixes a `key not found` exception in `convert_type` during SMT2 encoding of structs using data types. Although structs were being mapped to SMT2 datatypes (in `datatype_map`) struct_tags were not.
1 parent f899754 commit bd3715f

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 --smt2
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
@@ -4872,8 +4872,10 @@ void smt2_convt::find_symbols_rec(
48724872

48734873
if(recstack.find(id) == recstack.end())
48744874
{
4875+
const auto &base_struct = ns.follow_tag(struct_tag);
48754876
recstack.insert(id);
4876-
find_symbols_rec(ns.follow_tag(struct_tag), recstack);
4877+
find_symbols_rec(base_struct, recstack);
4878+
datatype_map[type] = datatype_map[base_struct];
48774879
}
48784880
}
48794881
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
@@ -208,8 +208,10 @@ class smt2_convt : public stack_decision_proceduret
208208

209209
identifier_mapt identifier_map;
210210

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

0 commit comments

Comments
 (0)