Skip to content

Commit d388e15

Browse files
committed
introduce __CPROVER_separate
1 parent 3bcc2b1 commit d388e15

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,6 +2524,22 @@ exprt c_typecheck_baset::do_special_functions(
25242524

25252525
return writeable_object_expr;
25262526
}
2527+
else if(identifier == CPROVER_PREFIX "separate")
2528+
{
2529+
if(expr.arguments().size() < 2)
2530+
{
2531+
error().source_location = f_op.source_location();
2532+
error() << "separate expects two or more arguments" << eom;
2533+
throw 0;
2534+
}
2535+
2536+
typecheck_function_call_arguments(expr);
2537+
2538+
exprt separate_expr = separate_exprt(expr.arguments());
2539+
separate_expr.add_source_location() = source_location;
2540+
2541+
return separate_expr;
2542+
}
25272543
else if(identifier==CPROVER_PREFIX "POINTER_OFFSET")
25282544
{
25292545
if(expr.arguments().size()!=1)

src/ansi-c/cprover_builtin_headers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ __CPROVER_size_t __CPROVER_POINTER_OBJECT(const void *);
5454
__CPROVER_ssize_t __CPROVER_POINTER_OFFSET(const void *);
5555
__CPROVER_size_t __CPROVER_OBJECT_SIZE(const void *);
5656
__CPROVER_bool __CPROVER_DYNAMIC_OBJECT(const void *);
57+
__CPROVER_bool __CPROVER_separate(const void *, const void *, ...);
5758
void __CPROVER_allocated_memory(__CPROVER_size_t address, __CPROVER_size_t extent);
5859

5960
// float stuff

src/ansi-c/expr2c.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3995,6 +3995,7 @@ optionalt<std::string> expr2ct::convert_function(const exprt &src)
39953995
{ID_dynamic_object, "DYNAMIC_OBJECT"},
39963996
{ID_live_object, "LIVE_OBJECT"},
39973997
{ID_writeable_object, "WRITEABLE_OBJECT"},
3998+
{ID_separate, "SEPARATE"},
39983999
{ID_floatbv_div, "FLOAT/"},
39994000
{ID_floatbv_minus, "FLOAT-"},
40004001
{ID_floatbv_mult, "FLOAT*"},

src/util/irep_ids.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ IREP_ID_TWO(C_dynamic, #dynamic)
456456
IREP_ID_ONE(live_object)
457457
IREP_ID_ONE(writeable_object)
458458
IREP_ID_ONE(object_size)
459+
IREP_ID_ONE(separate)
459460
IREP_ID_ONE(good_pointer)
460461
IREP_ID_ONE(integer_address)
461462
IREP_ID_ONE(integer_address_object)

src/util/pointer_expr.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,4 +1172,56 @@ inline writeable_object_exprt &to_writeable_object_expr(exprt &expr)
11721172
return ret;
11731173
}
11741174

1175+
/// A predicate that indicates that the objects pointed to are distinct
1176+
class separate_exprt : public multi_ary_exprt
1177+
{
1178+
public:
1179+
explicit separate_exprt(exprt::operandst __operands)
1180+
: multi_ary_exprt(ID_separate, std::move(__operands), bool_typet())
1181+
{
1182+
}
1183+
1184+
separate_exprt(exprt __op0, exprt __op1)
1185+
: multi_ary_exprt(
1186+
std::move(__op0),
1187+
ID_separate,
1188+
std::move(__op1),
1189+
bool_typet())
1190+
{
1191+
}
1192+
};
1193+
1194+
template <>
1195+
inline bool can_cast_expr<separate_exprt>(const exprt &base)
1196+
{
1197+
return base.id() == ID_separate;
1198+
}
1199+
1200+
inline void validate_expr(const separate_exprt &value)
1201+
{
1202+
}
1203+
1204+
/// \brief Cast an exprt to a \ref separate_exprt
1205+
///
1206+
/// \a expr must be known to be \ref separate_exprt.
1207+
///
1208+
/// \param expr: Source expression
1209+
/// \return Object of type \ref separate_exprt
1210+
inline const separate_exprt &to_separate_expr(const exprt &expr)
1211+
{
1212+
PRECONDITION(expr.id() == ID_separate);
1213+
const separate_exprt &ret = static_cast<const separate_exprt &>(expr);
1214+
validate_expr(ret);
1215+
return ret;
1216+
}
1217+
1218+
/// \copydoc to_separate_expr(const exprt &)
1219+
inline separate_exprt &to_separate_expr(exprt &expr)
1220+
{
1221+
PRECONDITION(expr.id() == ID_separate);
1222+
separate_exprt &ret = static_cast<separate_exprt &>(expr);
1223+
validate_expr(ret);
1224+
return ret;
1225+
}
1226+
11751227
#endif // CPROVER_UTIL_POINTER_EXPR_H

0 commit comments

Comments
 (0)