Skip to content

SMT2 backend: minus on void pointers #7338

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
Nov 15, 2022
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
2 changes: 1 addition & 1 deletion regression/cbmc/void_pointer3/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE broken-smt-backend gcc-only
CORE gcc-only
main.c

^EXIT=0$
Expand Down
24 changes: 18 additions & 6 deletions src/solvers/smt2/smt2_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3825,11 +3825,23 @@ void smt2_convt::convert_minus(const minus_exprt &expr)
expr.op1().type().id()==ID_pointer)
{
// Pointer difference
auto element_size =
pointer_offset_size(to_pointer_type(expr.op0().type()).base_type(), ns);
CHECK_RETURN(element_size.has_value() && *element_size >= 1);
const auto &base_type = to_pointer_type(expr.op0().type()).base_type();
mp_integer element_size;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 It might be nice if this code which works out the element_size were to be factored out into a separate function. This commit seems to be duplicating the code from pointer addition.


if(*element_size >= 2)
if(base_type.id() == ID_empty)
{
// Pointer arithmetic on void is a gcc extension.
// https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html
element_size = 1;
}
else
{
auto element_size_opt = pointer_offset_size(base_type, ns);
CHECK_RETURN(element_size_opt.has_value() && *element_size_opt >= 1);
element_size = *element_size_opt;
}

if(element_size >= 2)
out << "(bvsdiv ";

INVARIANT(
Expand All @@ -3843,8 +3855,8 @@ void smt2_convt::convert_minus(const minus_exprt &expr)
convert_expr(expr.op1());
out << ")";

if(*element_size >= 2)
out << " (_ bv" << *element_size << " " << boolbv_width(expr.type())
if(element_size >= 2)
out << " (_ bv" << element_size << " " << boolbv_width(expr.type())
<< "))";
}
else
Expand Down