Skip to content

Commit a4eda5c

Browse files
committed
goto-program interpreter: test byte_extract handling
Fix basic execution as sparse vectors do not (yet) support resizing to smaller sizes (performing a clear+resize instead), and perform goto program rewrites before starting the interpreter.
1 parent e17b695 commit a4eda5c

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
union U
2+
{
3+
int x;
4+
char c[sizeof(int)];
5+
};
6+
7+
int main()
8+
{
9+
union U u;
10+
// make the lowest and highest byte 1
11+
u.x = 1 | (1 << (sizeof(int) * 8 - 8));
12+
int i = u.x;
13+
char c0 = u.c[0];
14+
char c1 = u.c[1];
15+
char c2 = u.c[2];
16+
char c3 = u.c[3];
17+
18+
__CPROVER_assert(u.c[0] == 1, "");
19+
20+
return 0;
21+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
KNOWNBUG
2+
main.c
3+
se
4+
^Starting interpreter$
5+
^\d+- Program End\.$
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
^assertion failed at \d+$
10+
--
11+
The memory model of the interpreter does not record individual bytes. Therefore,
12+
an access to individual bytes still yields the full object, making the assertion
13+
in this test spuriously fail.

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Author: Daniel Kroening, [email protected]
4141
#include <goto-programs/remove_unused_functions.h>
4242
#include <goto-programs/remove_virtual_functions.h>
4343
#include <goto-programs/restrict_function_pointers.h>
44+
#include <goto-programs/rewrite_union.h>
4445
#include <goto-programs/set_properties.h>
4546
#include <goto-programs/show_properties.h>
4647
#include <goto-programs/show_symbol_table.h>
@@ -599,6 +600,9 @@ int goto_instrument_parse_optionst::doit()
599600

600601
if(cmdline.isset("interpreter"))
601602
{
603+
do_indirect_call_and_rtti_removal();
604+
rewrite_union(goto_model);
605+
602606
log.status() << "Starting interpreter" << messaget::eom;
603607
interpreter(goto_model, ui_message_handler);
604608
return CPROVER_EXIT_SUCCESS;

src/goto-programs/interpreter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ void interpretert::execute_function_call()
861861
void interpretert::build_memory_map()
862862
{
863863
// put in a dummy for NULL
864+
memory.clear();
864865
memory.resize(1);
865866
inverse_memory_map[0] = {};
866867

src/util/sparse_vector.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ template<class T> class sparse_vectort
5151
_size=new_size;
5252
}
5353

54+
void clear()
55+
{
56+
underlying.clear();
57+
_size = 0;
58+
}
59+
5460
typedef typename underlyingt::iterator iteratort;
5561
typedef typename underlyingt::const_iterator const_iteratort;
5662

0 commit comments

Comments
 (0)