Skip to content

Commit edd7b0a

Browse files
committed
Fix remove_pointer_offsets
This previously stripped pointer_offset_exprt, which wasn't correct-- it should mask the pointer expression within it to give the offset between the operand address and the base of its allocation.
1 parent 406a6c4 commit edd7b0a

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed
382 Bytes
Binary file not shown.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class Test {
2+
3+
byte main(byte[] a) {
4+
if (a.length != 9) {
5+
return -1;
6+
}
7+
8+
byte diff = 0;
9+
for (byte i = 0; i < 9; i++) {
10+
if (a[i] == 1) {
11+
diff++;
12+
} else if (a[i] == 2) {
13+
diff--;
14+
} else if (a[i] != 0) {
15+
return -1;
16+
}
17+
}
18+
19+
return -1;
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
Test.class
3+
--cover location --trace --json-ui
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring

src/goto-programs/json_goto_trace.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Daniel Kroening
1717
#include <util/arith_tools.h>
1818

1919
#include <langapi/language_util.h>
20+
#include <solvers/flattening/pointer_logic.h>
2021

2122
#include "json_goto_trace.h"
2223

@@ -25,8 +26,16 @@ Author: Daniel Kroening
2526
/// \param src: an expression
2627
void remove_pointer_offsets(exprt &src)
2728
{
28-
if(src.id()==ID_pointer_offset && src.op0().id()==ID_constant)
29-
src=src.op0();
29+
if(src.id()==ID_pointer_offset &&
30+
src.op0().id()==ID_constant &&
31+
src.op0().type().id()==ID_pointer)
32+
{
33+
std::string binary_str=id2string(to_constant_expr(src.op0()).get_value());
34+
// The constant address consists of OBJECT-ID || OFFSET.
35+
// Shift out the object-identifier bits, leaving only the offset:
36+
mp_integer offset=binary2integer(binary_str.substr(BV_ADDR_BITS), false);
37+
src=from_integer(offset, src.type());
38+
}
3039
else
3140
for(auto &op : src.operands())
3241
remove_pointer_offsets(op);

0 commit comments

Comments
 (0)