Skip to content

Commit fb578a6

Browse files
committedApr 23, 2024
Do not use back-end pointer encoding details in the simplifier
The object:offset encoding is an implementation detail that should be private to the back-end. Expression simplification must not rely on such details. Partly reverts 4d35274.
1 parent 428375a commit fb578a6

File tree

2 files changed

+0
-39
lines changed

2 files changed

+0
-39
lines changed
 

‎src/util/simplify_expr_pointer.cpp

-18
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Author: Daniel Kroening, kroening@kroening.com
1010

1111
#include "arith_tools.h"
1212
#include "c_types.h"
13-
#include "config.h"
1413
#include "expr_util.h"
1514
#include "namespace.h"
1615
#include "pointer_expr.h"
@@ -403,23 +402,6 @@ simplify_exprt::simplify_pointer_offset(const pointer_offset_exprt &expr)
403402
{
404403
return from_integer(0, expr.type());
405404
}
406-
else
407-
{
408-
// this is a pointer, we can't use to_integer
409-
const auto width = to_pointer_type(ptr.type()).get_width();
410-
mp_integer number = bvrep2integer(c_ptr.get_value(), width, false);
411-
// a null pointer would have been caught above, return value 0
412-
// will indicate that conversion failed
413-
if(number==0)
414-
return unchanged(expr);
415-
416-
// The constant address consists of OBJECT-ID || OFFSET.
417-
mp_integer offset_bits =
418-
*pointer_offset_bits(ptr.type(), ns) - config.bv_encoding.object_bits;
419-
number%=power(2, offset_bits);
420-
421-
return from_integer(number, expr.type());
422-
}
423405
}
424406

425407
return unchanged(expr);

‎unit/util/simplify_expr.cpp

-21
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,6 @@ TEST_CASE("Simplify pointer_offset(address of array index)", "[core][util]")
4444
REQUIRE(offset_value==1);
4545
}
4646

47-
TEST_CASE("Simplify const pointer offset", "[core][util]")
48-
{
49-
config.set_arch("none");
50-
51-
symbol_tablet symbol_table;
52-
namespacet ns(symbol_table);
53-
54-
// build a numeric constant of some pointer type
55-
constant_exprt number=from_integer(1234, size_type());
56-
number.type()=pointer_type(char_type());
57-
58-
exprt p_o=pointer_offset(number);
59-
60-
exprt simp=simplify_expr(p_o, ns);
61-
62-
REQUIRE(simp.is_constant());
63-
const mp_integer offset_value =
64-
numeric_cast_v<mp_integer>(to_constant_expr(simp));
65-
REQUIRE(offset_value==1234);
66-
}
67-
6847
TEST_CASE("Simplify byte extract", "[core][util]")
6948
{
7049
// this test does require a proper architecture to be set so that byte extract

0 commit comments

Comments
 (0)
Please sign in to comment.