Skip to content

Commit 3bf46bf

Browse files
Merge pull request #1189 from peterschrammel/object-encoding-tgs
Set addr_bits via command line and per language (test-gen-support)
2 parents ec3798f + ef43fc9 commit 3bf46bf

File tree

27 files changed

+361
-53
lines changed

27 files changed

+361
-53
lines changed
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class Test {
2+
int x;
3+
Test(int x) { this.x = x; }
4+
5+
public static void main(String[] args) {
6+
int i;
7+
Test[] tests = new Test[30];
8+
for(i = 0; i < 30; ++i) {
9+
tests[i] = new Test(i);
10+
}
11+
assert i == tests[0].x;
12+
}
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CORE
2+
Test.class
3+
--object-bits 4
4+
too many addressed objects
5+
--
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class Test {
2+
int x;
3+
Test(int x) { this.x = x; }
4+
5+
public static void main(String[] args) {
6+
int i;
7+
Test[] tests = new Test[30];
8+
for(i = 0; i < 30; ++i) {
9+
tests[i] = new Test(i);
10+
}
11+
assert i == tests[0].x;
12+
}
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
Test.class
3+
--object-bits 8
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
^\[java::Test.main:\(\[Ljava/lang/String;\)V.assertion.1\] .*: FAILURE$
8+
--
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CORE
22
test.c
3-
--no-simplify --unwind 300
4-
too many variables
3+
--no-simplify --unwind 300 --object-bits 8
4+
too many addressed objects
55
--
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <stdlib.h>
2+
#include <assert.h>
3+
4+
int main(int argc, char** argv)
5+
{
6+
char* c=(char*)malloc(10);
7+
char* d=c;
8+
for(char i=0; i<10; i++, d++);
9+
assert((size_t)d==(size_t)c+10);
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
KNOWNBUG
2+
test.c
3+
--32 --object-bits 31 --unwind 11 --no-simplify
4+
dynamic object too large
5+
--
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
// copy of Pointer_Arithmetic12
2+
3+
#include <stdint.h>
4+
5+
#include <assert.h>
6+
7+
uint32_t __stack[32];
8+
9+
uint32_t eax;
10+
uint32_t ebp;
11+
uint32_t ebx;
12+
uint32_t ecx;
13+
uint32_t edi;
14+
uint32_t edx;
15+
uint32_t esi;
16+
uint32_t esp=(uint32_t)&(__stack[31]);
17+
uint32_t var0;
18+
uint32_t var1;
19+
uint32_t var10;
20+
uint32_t var11;
21+
uint32_t var12;
22+
uint32_t var13;
23+
uint32_t var14;
24+
uint32_t var15;
25+
uint32_t var16;
26+
uint32_t var2;
27+
uint32_t var3;
28+
uint32_t var4;
29+
uint32_t var5;
30+
uint32_t var6;
31+
uint32_t var7;
32+
uint32_t var8;
33+
uint32_t var9;
34+
35+
void g__L_0x3b4_0()
36+
{
37+
L_0x3b4_0: esp-=0x4;
38+
L_0x3b4_1: *(uint32_t*)(esp)=ebp;
39+
L_0x3b5_0: ebp=esp;
40+
L_0x3b7_0: var4=ebp;
41+
L_0x3b7_1: var4+=0xc;
42+
L_0x3b7_2: eax=*(uint32_t*)(var4);
43+
L_0x3ba_0: edx=eax;
44+
L_0x3bc_0: edx&=0x3;
45+
L_0x3bf_0: var5=ebp;
46+
L_0x3bf_1: var5+=0x8;
47+
L_0x3bf_2: eax=*(uint32_t*)(var5);
48+
L_0x3c2_0: *(uint32_t*)(eax)=edx;
49+
L_0x3c4_0: ebp=*(uint32_t*)(esp);
50+
L_0x3c4_1: esp+=0x4;
51+
L_0x3c5_0: return;
52+
}
53+
54+
void f__L_0x3c6_0()
55+
{
56+
L_0x3c6_0: esp-=0x4;
57+
L_0x3c6_1: *(uint32_t*)(esp)=ebp;
58+
L_0x3c7_0: ebp=esp;
59+
L_0x3c9_0: esp-=0x18;
60+
L_0x3cc_0: var6=ebp;
61+
L_0x3cc_1: var6-=0x4;
62+
L_0x3cc_2: *(uint32_t*)(var6)=0x0;
63+
L_0x3d3_0: var7=ebp;
64+
L_0x3d3_1: var7-=0x8;
65+
L_0x3d3_2: *(uint32_t*)(var7)=0x0;
66+
L_0x3da_0: var8=ebp;
67+
L_0x3da_1: var8+=0x8;
68+
L_0x3da_2: eax=*(uint32_t*)(var8);
69+
L_0x3dd_0: var9=ebp;
70+
L_0x3dd_1: var9-=0x4;
71+
L_0x3dd_2: *(uint32_t*)(var9)=eax;
72+
L_0x3e0_0: var10=ebp;
73+
L_0x3e0_1: var10-=0x4;
74+
L_0x3e0_2: eax=*(uint32_t*)(var10);
75+
L_0x3e3_0: var11=esp;
76+
L_0x3e3_1: var11+=0x4;
77+
L_0x3e3_2: *(uint32_t*)(var11)=eax;
78+
L_0x3e7_0: var12=ebp;
79+
L_0x3e7_1: var12-=0x8;
80+
L_0x3e7_2: eax=(uint32_t)&*(uint32_t*)(var12);
81+
L_0x3ea_0: *(uint32_t*)(esp)=eax;
82+
L_0x3ed_0: esp-=4; g__L_0x3b4_0(); esp+=4;
83+
L_0x3f2_0: var13=ebp;
84+
L_0x3f2_1: var13-=0x4;
85+
L_0x3f2_2: *(uint32_t*)(var13)=0x5;
86+
L_0x3f9_0: var14=ebp;
87+
L_0x3f9_1: var14-=0x8;
88+
L_0x3f9_2: eax=*(uint32_t*)(var14);
89+
L_0x3fc_0: esp=ebp;
90+
L_0x3fc_1: ebp=*(uint32_t*)(esp);
91+
L_0x3fc_2: esp+=0x4;
92+
L_0x3fd_0: return;
93+
}
94+
95+
int main()
96+
{
97+
L_0x3fe_0: esp-=0x4;
98+
L_0x3fe_1: *(uint32_t*)(esp)=ebp;
99+
L_0x3ff_0: ebp=esp;
100+
L_0x401_0: esp-=0x14;
101+
L_0x404_0: var15=ebp;
102+
L_0x404_1: var15-=0x4;
103+
#ifdef NONDET
104+
L_0x404_2: *(uint32_t*)(var15)=nondet_uint();
105+
#else
106+
L_0x404_2: *(uint32_t*)(var15)=0xffffffff;
107+
#endif
108+
L_0x40b_0: var16=ebp;
109+
L_0x40b_1: var16-=0x4;
110+
L_0x40b_2: eax=*(uint32_t*)(var16);
111+
L_0x40e_0: *(uint32_t*)(esp)=eax;
112+
L_0x411_0: esp-=4; f__L_0x3c6_0(); esp+=4;
113+
#if 1
114+
uint32_t eax1=eax;
115+
C_0x3ff_0: ebp=esp;
116+
C_0x401_0: esp-=0x14;
117+
C_0x404_0: var15=ebp;
118+
C_0x404_1: var15-=0x4;
119+
#ifdef NONDET
120+
C_0x404_2: *(uint32_t*)(var15)=nondet_uint();
121+
#else
122+
C_0x404_2: *(uint32_t*)(var15)=0xffffffff;
123+
#endif
124+
C_0x40b_0: var16=ebp;
125+
C_0x40b_1: var16-=0x4;
126+
C_0x40b_2: eax=*(uint32_t*)(var16);
127+
C_0x40e_0: *(uint32_t*)(esp)=eax;
128+
C_0x411_0: esp-=4; f__L_0x3c6_0(); esp+=4;
129+
uint32_t eax2=eax;
130+
assert(eax2==eax1);
131+
#endif
132+
L_0x416_0: esp=ebp;
133+
L_0x416_1: ebp=*(uint32_t*)(esp);
134+
L_0x416_2: esp+=0x4;
135+
L_0x417_0: return 0;
136+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
--32 --little-endian --object-bits 25 --pointer-check
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
^.* dereference failure: pointer outside object bounds in .*: FAILURE$
8+
--
9+
^warning: ignoring
10+
--
11+
requires at least 8 offset bits

src/cbmc/cbmc_parse_options.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,23 @@ int cbmc_parse_optionst::doit()
448448
//
449449

450450
optionst options;
451-
get_command_line_options(options);
451+
try
452+
{
453+
get_command_line_options(options);
454+
}
455+
456+
catch(const char *error_msg)
457+
{
458+
error() << error_msg << eom;
459+
return 6; // should contemplate EX_SOFTWARE from sysexits.h
460+
}
461+
462+
catch(const std::string error_msg)
463+
{
464+
error() << error_msg << eom;
465+
return 6; // should contemplate EX_SOFTWARE from sysexits.h
466+
}
467+
452468
eval_verbosity();
453469

454470
//
@@ -677,9 +693,6 @@ int cbmc_parse_optionst::get_goto_program(
677693
}
678694
}
679695

680-
if(!binaries.empty())
681-
config.set_from_symbol_table(symbol_table);
682-
683696
if(cmdline.isset("show-symbol-table"))
684697
{
685698
show_symbol_table();
@@ -707,6 +720,8 @@ int cbmc_parse_optionst::get_goto_program(
707720
show_goto_functions(ns, get_ui(), goto_functions);
708721
return 0;
709722
}
723+
724+
status() << config.object_bits_info() << eom;
710725
}
711726

712727
catch(const char *e)
@@ -1098,6 +1113,7 @@ void cbmc_parse_optionst::help()
10981113
" --graphml-witness filename write the witness in GraphML format to filename\n" // NOLINT(*)
10991114
"\n"
11001115
"Backend options:\n"
1116+
" --object-bits n number of bits used for object addresses\n"
11011117
" --dimacs generate CNF in DIMACS format\n"
11021118
" --beautify beautify the counterexample (greedy heuristic)\n" // NOLINT(*)
11031119
" --localize-faults localize faults (experimental)\n"

src/cbmc/cbmc_parse_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class optionst;
3131
"(debug-level):(no-propagation)(no-simplify-if)" \
3232
"(document-subgoals)(outfile):(test-preprocessor)" \
3333
"D:I:(c89)(c99)(c11)(cpp89)(cpp99)(cpp11)" \
34+
"(object-bits):" \
3435
"(classpath):(cp):(main-class):" \
3536
"(depth):(partial-loops)(no-unwinding-assertions)(unwinding-assertions)" \
3637
OPT_GOTO_CHECK \

src/clobber/clobber_parse_options.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@ bool clobber_parse_optionst::get_goto_program(
208208
symbol_table, goto_functions, get_message_handler()))
209209
return true;
210210

211-
config.set_from_symbol_table(symbol_table);
212-
213211
if(cmdline.isset("show-symbol-table"))
214212
{
215213
show_symbol_table();

src/goto-diff/goto_diff_parse_options.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ int goto_diff_parse_optionst::get_goto_program(
346346
return 6;
347347

348348
config.set(cmdline);
349-
config.set_from_symbol_table(goto_model.symbol_table);
350349

351350
// This one is done.
352351
cmdline.args.erase(cmdline.args.begin());

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,6 @@ void goto_instrument_parse_optionst::get_goto_program()
866866
throw 0;
867867

868868
config.set(cmdline);
869-
config.set_from_symbol_table(symbol_table);
870869
}
871870

872871
void goto_instrument_parse_optionst::instrument_goto_program()

src/goto-programs/initialize_goto_model.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ bool initialize_goto_model(
130130
return true;
131131
}
132132

133-
if(!binaries.empty())
134-
config.set_from_symbol_table(goto_model.symbol_table);
135-
136133
msg.status() << "Generating GOTO Program" << messaget::eom;
137134

138135
goto_convert(

src/goto-programs/json_goto_trace.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ Author: Daniel Kroening
1515

1616
#include <util/json_expr.h>
1717
#include <util/arith_tools.h>
18+
#include <util/config.h>
1819

1920
#include <langapi/language_util.h>
20-
#include <solvers/flattening/pointer_logic.h>
2121

2222
#include "json_goto_trace.h"
2323

@@ -33,7 +33,8 @@ void remove_pointer_offsets(exprt &src)
3333
std::string binary_str=id2string(to_constant_expr(src.op0()).get_value());
3434
// The constant address consists of OBJECT-ID || OFFSET.
3535
// Shift out the object-identifier bits, leaving only the offset:
36-
mp_integer offset=binary2integer(binary_str.substr(BV_ADDR_BITS), false);
36+
mp_integer offset=binary2integer(
37+
binary_str.substr(config.bv_encoding.object_bits), false);
3738
src=from_integer(offset, src.type());
3839
}
3940
else

src/goto-programs/read_goto_binary.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Module: Read Goto Programs
2626
#include <util/tempfile.h>
2727
#include <util/rename_symbol.h>
2828
#include <util/base_type.h>
29+
#include <util/config.h>
2930

3031
#include <langapi/language_ui.h>
3132

@@ -382,6 +383,9 @@ bool read_object_and_link(
382383
linking.object_type_updates))
383384
return true;
384385

386+
// reading successful, let's update config
387+
config.set_from_symbol_table(symbol_table);
388+
385389
return false;
386390
}
387391

src/langapi/language_ui.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, kroening@cs.cmu.edu
1414
#include <util/namespace.h>
1515
#include <util/language.h>
1616
#include <util/cmdline.h>
17+
#include <util/config.h>
1718
#include <util/unicode.h>
1819

1920
#include "language_ui.h"
@@ -125,6 +126,8 @@ bool language_uit::final()
125126
return true;
126127
}
127128

129+
config.set_object_bits_from_symbol_table(symbol_table);
130+
128131
return false;
129132
}
130133

src/musketeer/musketeer_parse_options.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ void goto_fence_inserter_parse_optionst::get_goto_program(
138138
if(read_goto_binary(cmdline.args[0],
139139
symbol_table, goto_functions, get_message_handler()))
140140
throw 0;
141-
142-
config.set_from_symbol_table(symbol_table);
143141
}
144142

145143
void goto_fence_inserter_parse_optionst::instrument_goto_program(

0 commit comments

Comments
 (0)