Skip to content

Commit 9b2bc22

Browse files
committed
add __CPROVER_is_list(p)
This adds a builtin to the C frontend that indicates that the given pointer points to a singly linked null-terminated dynamically allocated list.
1 parent d9e3eb5 commit 9b2bc22

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,6 +2289,33 @@ exprt c_typecheck_baset::do_special_functions(
22892289

22902290
return buffer_size_expr;
22912291
}
2292+
else if(identifier == CPROVER_PREFIX "is_list")
2293+
{
2294+
if(expr.arguments().size() != 1)
2295+
{
2296+
error().source_location = f_op.source_location();
2297+
error() << "is_list expects one operand" << eom;
2298+
throw 0;
2299+
}
2300+
2301+
typecheck_function_call_arguments(expr);
2302+
2303+
if(
2304+
expr.arguments()[0].type().id() != ID_pointer ||
2305+
to_pointer_type(expr.arguments()[0].type()).base_type().id() !=
2306+
ID_struct_tag)
2307+
{
2308+
error().source_location = expr.arguments()[0].source_location();
2309+
error() << "is_list expects a struct-pointer operand" << eom;
2310+
throw 0;
2311+
}
2312+
2313+
predicate_exprt is_list_expr("is_list");
2314+
is_list_expr.operands() = expr.arguments();
2315+
is_list_expr.add_source_location() = source_location;
2316+
2317+
return std::move(is_list_expr);
2318+
}
22922319
else if(identifier==CPROVER_PREFIX "is_zero_string")
22932320
{
22942321
if(expr.arguments().size()!=1)

src/ansi-c/cprover_builtin_headers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ __CPROVER_bool __CPROVER_equal();
1010
__CPROVER_bool __CPROVER_same_object(const void *, const void *);
1111
__CPROVER_bool __CPROVER_is_invalid_pointer(const void *);
1212
_Bool __CPROVER_is_zero_string(const void *);
13+
// a singly-linked null-terminated dynamically-allocated list
14+
__CPROVER_bool __CPROVER_is_list();
1315
__CPROVER_size_t __CPROVER_zero_string_length(const void *);
1416
__CPROVER_size_t __CPROVER_buffer_size(const void *);
1517
__CPROVER_bool __CPROVER_r_ok();

0 commit comments

Comments
 (0)