Skip to content

Commit bc5d042

Browse files
committed
Follow struct-tag before accessing is smt2 datatype
in smt2-conversion. Before std::map threw exception at 'at' (since we follow the tag before inserting the converted datatype). Includes a regression test.
1 parent 06705ca commit bc5d042

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <assert.h>
2+
3+
typedef struct stritem
4+
{
5+
unsigned nkey;
6+
unsigned cas[];
7+
} item;
8+
9+
int foo(item *it)
10+
{
11+
assert(it->cas[0] == 0);
12+
return 0;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
main.c
3+
--function foo --bounds-check --pointer-check --smt2
4+
^\[foo.assertion.1\] line \d+ assertion it->cas\[0\] == 0: FAILURE$
5+
^\[foo.array_bounds.3\] line \d+ array.cas upper bound in it->cas\[\(.*\)0\]: FAILURE$
6+
^\[foo.array_bounds.2\] line \d+ array.cas dynamic object upper bound in it->cas\[\(.*\)0\]: FAILURE$
7+
^\[foo.pointer_dereference.2\] line \d+ dereference failure: pointer invalid in it->cas: SUCCESS$
8+
^\[foo.pointer_dereference.6\] line \d+ dereference failure: pointer outside object bounds in it->cas: FAILURE$
9+
^EXIT=10$
10+
^SIGNAL=0$
11+
^VERIFICATION FAILED$
12+
--
13+
^warning: ignoring

src/solvers/smt2/smt2_conv.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -4533,7 +4533,11 @@ void smt2_convt::convert_type(const typet &type)
45334533
{
45344534
if(use_datatypes)
45354535
{
4536-
out << datatype_map.at(type);
4536+
const typet &struct_type = type.id() == ID_struct_tag
4537+
? ns.follow_tag(to_struct_tag_type(type))
4538+
: type;
4539+
CHECK_RETURN(datatype_map.count(struct_type) > 0);
4540+
out << datatype_map.at(struct_type);
45374541
}
45384542
else
45394543
{

0 commit comments

Comments
 (0)