Skip to content

Commit 015396a

Browse files
committed
SMT2 backend: minus on void pointers
This adds support for p-q for void pointers p and q to the SMT2 backend.
1 parent e5f6077 commit 015396a

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

regression/cbmc/void_pointer3/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend gcc-only
1+
CORE gcc-only
22
main.c
33

44
^EXIT=0$

src/solvers/smt2/smt2_conv.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3825,11 +3825,23 @@ void smt2_convt::convert_minus(const minus_exprt &expr)
38253825
expr.op1().type().id()==ID_pointer)
38263826
{
38273827
// Pointer difference
3828-
auto element_size =
3829-
pointer_offset_size(to_pointer_type(expr.op0().type()).base_type(), ns);
3830-
CHECK_RETURN(element_size.has_value() && *element_size >= 1);
3828+
const auto &base_type = to_pointer_type(expr.op0().type()).base_type();
3829+
mp_integer element_size;
38313830

3832-
if(*element_size >= 2)
3831+
if(base_type.id() == ID_empty)
3832+
{
3833+
// Pointer arithmetic on void is a gcc extension.
3834+
// https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html
3835+
element_size = 1;
3836+
}
3837+
else
3838+
{
3839+
auto element_size_opt = pointer_offset_size(base_type, ns);
3840+
CHECK_RETURN(element_size_opt.has_value() && *element_size_opt >= 1);
3841+
element_size = *element_size_opt;
3842+
}
3843+
3844+
if(element_size >= 2)
38333845
out << "(bvsdiv ";
38343846

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

3846-
if(*element_size >= 2)
3847-
out << " (_ bv" << *element_size << " " << boolbv_width(expr.type())
3858+
if(element_size >= 2)
3859+
out << " (_ bv" << element_size << " " << boolbv_width(expr.type())
38483860
<< "))";
38493861
}
38503862
else

0 commit comments

Comments
 (0)