Skip to content

Cleanup of pointer-in-range predicate handling #7459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/ansi-c/c_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2671,7 +2671,6 @@ exprt c_typecheck_baset::do_special_functions(
}
else if(identifier == CPROVER_PREFIX "pointer_in_range")
{
// experimental feature for CHC encodings -- do not use
if(expr.arguments().size() != 3)
{
error().source_location = f_op.source_location();
Expand Down
21 changes: 21 additions & 0 deletions src/ansi-c/expr2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3572,6 +3572,24 @@ std::string expr2ct::convert_r_or_w_ok(const r_or_w_ok_exprt &src)
return dest;
}

std::string expr2ct::convert_pointer_in_range(const pointer_in_range_exprt &src)
{
std::string dest = CPROVER_PREFIX "pointer_in_range";

dest += '(';

unsigned p;
dest += convert_with_precedence(src.lower_bound(), p);
dest += ", ";
dest += convert_with_precedence(src.pointer(), p);
dest += ", ";
dest += convert_with_precedence(src.upper_bound(), p);

dest += ')';

return dest;
}

std::string expr2ct::convert_with_precedence(
const exprt &src,
unsigned &precedence)
Expand Down Expand Up @@ -3984,6 +4002,9 @@ std::string expr2ct::convert_with_precedence(
else if(src.id() == ID_r_ok || src.id() == ID_w_ok || src.id() == ID_rw_ok)
return convert_r_or_w_ok(to_r_or_w_ok_expr(src));

else if(src.id() == ID_pointer_in_range)
return convert_pointer_in_range(to_pointer_in_range_expr(src));

auto function_string_opt = convert_function(src);
if(function_string_opt.has_value())
return *function_string_opt;
Expand Down
2 changes: 2 additions & 0 deletions src/ansi-c/expr2c_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class annotated_pointer_constant_exprt;
class qualifierst;
class namespacet;
class r_or_w_ok_exprt;
class pointer_in_range_exprt;

class expr2ct
{
Expand Down Expand Up @@ -284,6 +285,7 @@ class expr2ct
std::string convert_bitreverse(const bitreverse_exprt &src);

std::string convert_r_or_w_ok(const r_or_w_ok_exprt &src);
std::string convert_pointer_in_range(const pointer_in_range_exprt &src);
};

#endif // CPROVER_ANSI_C_EXPR2C_CLASS_H
17 changes: 16 additions & 1 deletion src/util/pointer_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,21 @@ class pointer_in_range_exprt : public ternary_exprt
PRECONDITION(op2().type().id() == ID_pointer);
}

const exprt &lower_bound() const
{
return op0();
}

const exprt &pointer() const
{
return op1();
}

const exprt &upper_bound() const
{
return op2();
}

// translate into equivalent conjunction
exprt lower() const;
};
Expand Down Expand Up @@ -414,7 +429,7 @@ inline pointer_in_range_exprt &to_pointer_in_range_expr(exprt &expr)
{
PRECONDITION(expr.id() == ID_pointer_in_range);
DATA_INVARIANT(
expr.operands().size() == 3, "pointer_in_range must have one operand");
expr.operands().size() == 3, "pointer_in_range must have three operands");
return static_cast<pointer_in_range_exprt &>(expr);
}

Expand Down