Skip to content

Commit 289a14c

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 79233e3 commit 289a14c

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
union U {
2+
int x;
3+
char c[sizeof(int)];
4+
};
5+
6+
int main()
7+
{
8+
union U u;
9+
// make the lowest and highest byte 1
10+
u.x = 1 | (1 << (sizeof(int) * 8 - 8));
11+
int i = u.x;
12+
char c0 = u.c[0];
13+
char c1 = u.c[1];
14+
char c2 = u.c[2];
15+
char c3 = u.c[3];
16+
17+
__CPROVER_assert(u.c[0] == 1, "");
18+
19+
return 0;
20+
}
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
@@ -860,6 +860,7 @@ void interpretert::execute_function_call()
860860
void interpretert::build_memory_map()
861861
{
862862
// put in a dummy for NULL
863+
memory.clear();
863864
memory.resize(1);
864865
inverse_memory_map[0] = {};
865866

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)