Skip to content

Commit 9014506

Browse files
committed
Restore recognition of dynamic objects
These were accidentally disabled when distinguishing ID_is_dynamic_object (a predicate that tests whether an object is dynamic) from ID_dynamic_object (a reference to the object itself, similar to symbol_exprt). I also take the opportunity to restore pretty-printing of dynamic object expressions (while also keeping pretty-printing of the predicate).
1 parent c57a132 commit 9014506

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

src/ansi-c/expr2c.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -3486,6 +3486,9 @@ std::string expr2ct::convert_with_precedence(
34863486
return convert_function(
34873487
src, CPROVER_PREFIX "is_invalid_pointer", precedence = 16);
34883488

3489+
else if(src.id() == ID_dynamic_object)
3490+
return convert_function(src, "DYNAMIC_OBJECT", precedence = 16);
3491+
34893492
else if(src.id() == ID_is_dynamic_object)
34903493
return convert_function(src, "IS_DYNAMIC_OBJECT", precedence = 16);
34913494

src/util/simplify_expr_int.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,7 @@ bool simplify_exprt::simplify_inequality_constant(exprt &expr)
17111711
{
17121712
if(
17131713
expr.op0().op0().id() == ID_symbol ||
1714-
expr.op0().op0().id() == ID_is_dynamic_object ||
1714+
expr.op0().op0().id() == ID_dynamic_object ||
17151715
expr.op0().op0().id() == ID_member ||
17161716
expr.op0().op0().id() == ID_index ||
17171717
expr.op0().op0().id() == ID_string_constant)
@@ -1728,7 +1728,7 @@ bool simplify_exprt::simplify_inequality_constant(exprt &expr)
17281728
{
17291729
if(
17301730
expr.op0().op0().op0().id() == ID_symbol ||
1731-
expr.op0().op0().op0().id() == ID_is_dynamic_object ||
1731+
expr.op0().op0().op0().id() == ID_dynamic_object ||
17321732
expr.op0().op0().op0().id() == ID_member ||
17331733
expr.op0().op0().op0().id() == ID_index ||
17341734
expr.op0().op0().op0().id() == ID_string_constant)

src/util/simplify_expr_pointer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ bool simplify_exprt::simplify_inequality_pointer_object(exprt &expr)
468468
{
469469
if(
470470
op.operands().size() != 1 ||
471-
(op.op0().id() != ID_symbol && op.op0().id() != ID_is_dynamic_object &&
471+
(op.op0().id() != ID_symbol && op.op0().id() != ID_dynamic_object &&
472472
op.op0().id() != ID_string_constant))
473473
{
474474
return true;

unit/util/simplify_expr.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,36 @@ TEST_CASE("Simplify shift")
183183
simplify_expr(lshr_exprt(from_integer(-4, signedbv_typet(8)), 1), ns) ==
184184
from_integer(126, signedbv_typet(8)));
185185
}
186+
187+
TEST_CASE("Simplify dynamic object comparison", "[core][util]")
188+
{
189+
const symbol_tablet symbol_table;
190+
const namespacet ns(symbol_table);
191+
192+
dynamic_object_exprt dynamic_object(signedbv_typet(8));
193+
dynamic_object.set_instance(1);
194+
195+
address_of_exprt address_of_dynamic_object(dynamic_object);
196+
197+
equal_exprt compare_null(
198+
address_of_dynamic_object,
199+
null_pointer_exprt(to_pointer_type(address_of_dynamic_object.type())));
200+
REQUIRE(simplify_expr(compare_null, ns) == false_exprt());
201+
202+
typecast_exprt cast_address(
203+
address_of_dynamic_object, pointer_type(signedbv_typet(16)));
204+
205+
equal_exprt compare_null_through_cast(
206+
cast_address, null_pointer_exprt(to_pointer_type(cast_address.type())));
207+
REQUIRE(simplify_expr(compare_null_through_cast, ns) == false_exprt());
208+
209+
dynamic_object_exprt other_dynamic_object(signedbv_typet(8));
210+
dynamic_object.set_instance(2);
211+
address_of_exprt address_of_other_dynamic_object(other_dynamic_object);
212+
213+
equal_exprt compare_pointer_objects(
214+
pointer_object(address_of_dynamic_object),
215+
pointer_object(address_of_other_dynamic_object));
216+
217+
REQUIRE(simplify_expr(compare_pointer_objects, ns) == false_exprt());
218+
}

0 commit comments

Comments
 (0)