Skip to content

Commit 9587978

Browse files
committed
prophecy_r_or_w_ok_exprt lowering: adjust for dynamic/static objects
We do not need to create comparisons to dead and/or deallocated when handling a dynamic object (which will never be marked "dead") or a static object (which will neither be marked "dead" nor "deallocated"). This avoids unnecessary branches when the prophecy_r_or_w_ok_exprt can now be simplified to a constant.
1 parent 5dc709d commit 9587978

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/util/pointer_expr.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ Author: Daniel Kroening, [email protected]
1212
#include "byte_operators.h"
1313
#include "c_types.h"
1414
#include "expr_util.h"
15+
#include "namespace.h"
1516
#include "pointer_offset_size.h"
1617
#include "pointer_predicates.h"
1718
#include "simplify_expr.h"
19+
#include "symbol.h"
1820

1921
void dynamic_object_exprt::set_instance(unsigned int instance)
2022
{
@@ -247,6 +249,41 @@ exprt pointer_in_range_exprt::lower() const
247249

248250
exprt prophecy_r_or_w_ok_exprt::lower(const namespacet &ns) const
249251
{
252+
exprt base_ptr = skip_typecast(pointer());
253+
if(auto plus_expr = expr_try_dynamic_cast<plus_exprt>(base_ptr))
254+
{
255+
if(plus_expr->op0().id() == ID_address_of)
256+
base_ptr = plus_expr->op0();
257+
}
258+
if(auto address_of = expr_try_dynamic_cast<address_of_exprt>(base_ptr))
259+
{
260+
const exprt &root_object =
261+
object_descriptor_exprt::root_object(address_of->object());
262+
if(auto symbol_expr = expr_try_dynamic_cast<symbol_exprt>(root_object))
263+
{
264+
const symbolt *s_ptr = nullptr;
265+
if(
266+
!ns.lookup(symbol_expr->get_identifier(), s_ptr) &&
267+
s_ptr->is_static_lifetime)
268+
{
269+
return and_exprt{
270+
{not_exprt{null_object(pointer())},
271+
not_exprt{is_invalid_pointer_exprt{pointer()}},
272+
not_exprt{object_lower_bound(pointer(), nil_exprt())},
273+
not_exprt{object_upper_bound(pointer(), size())}}};
274+
}
275+
else if(symbol_expr->get_identifier().starts_with(SYMEX_DYNAMIC_PREFIX
276+
"::"))
277+
{
278+
return and_exprt{
279+
{not_exprt{null_object(pointer())},
280+
not_exprt{is_invalid_pointer_exprt{pointer()}},
281+
not_exprt{same_object(pointer(), deallocated_ptr())},
282+
not_exprt{object_lower_bound(pointer(), nil_exprt())},
283+
not_exprt{object_upper_bound(pointer(), size())}}};
284+
}
285+
}
286+
}
250287
return and_exprt{
251288
{not_exprt{null_object(pointer())},
252289
not_exprt{is_invalid_pointer_exprt{pointer()}},

0 commit comments

Comments
 (0)