Skip to content

Commit 39a8542

Browse files
klaaskarkhaz
authored andcommitted
Adds a one-argument points_to_valid_memory
This commit adds support for a one-argument form of __CPROVER_points_to_valid_memory, taking only a pointer, with no size. If ptr has type T*, then __CPROVER_points_to_valid_memory(ptr) is equivalent to __CPROVER_points_to_valid_memory(ptr, sizeof(T)).
1 parent 1bba336 commit 39a8542

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,10 +2113,10 @@ exprt c_typecheck_baset::do_special_functions(
21132113
}
21142114
else if(identifier == CPROVER_PREFIX "points_to_valid_memory")
21152115
{
2116-
if(expr.arguments().size() != 2)
2116+
if(expr.arguments().size() != 2 && expr.arguments().size() != 1)
21172117
{
21182118
error().source_location = f_op.source_location();
2119-
error() << "points_to_valid_memory expects two operands" << eom;
2119+
error() << "points_to_valid_memory expects one or two operands" << eom;
21202120
throw 0;
21212121
}
21222122
if(!is_lvalue(expr.arguments().front()))
@@ -2142,6 +2142,24 @@ exprt c_typecheck_baset::do_special_functions(
21422142
same_object_expr =
21432143
points_to_valid_memory(expr.arguments()[0], expr.arguments()[1]);
21442144
}
2145+
else if(expr.arguments().size() == 1)
2146+
{
2147+
PRECONDITION(expr.arguments()[0].type().id() == ID_pointer);
2148+
2149+
const typet &base_type = expr.arguments()[0].type().subtype();
2150+
auto expr_size = size_of_expr(base_type, *this);
2151+
if(!expr_size)
2152+
{
2153+
error().source_location = expr.source_location();
2154+
error() << "cannot determine size of pointed-to memory region" << eom;
2155+
throw 0;
2156+
}
2157+
2158+
expr_size->add(ID_C_c_sizeof_type) = base_type;
2159+
2160+
same_object_expr =
2161+
points_to_valid_memory(expr.arguments()[0], *expr_size);
2162+
}
21452163
else
21462164
{
21472165
UNREACHABLE;

src/ansi-c/cprover_builtin_headers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ void __CPROVER_havoc_object(void *);
66
__CPROVER_bool __CPROVER_equal();
77
__CPROVER_bool __CPROVER_same_object(const void *, const void *);
88
__CPROVER_bool __CPROVER_invalid_pointer(const void *);
9-
__CPROVER_bool __CPROVER_points_to_valid_memory(const void *, __CPROVER_size_t);
9+
__CPROVER_bool __CPROVER_points_to_valid_memory(const void *, ...);
1010
__CPROVER_bool __CPROVER_is_zero_string(const void *);
1111
__CPROVER_size_t __CPROVER_zero_string_length(const void *);
1212
__CPROVER_size_t __CPROVER_buffer_size(const void *);

0 commit comments

Comments
 (0)