Skip to content

Commit f286ec9

Browse files
authored
Merge pull request #7243 from tautschnig/feature/null-simp
Simplify NULL + 1 == NULL to false
2 parents d4f325b + 9d51ea2 commit f286ec9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/util/simplify_expr_int.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,21 @@ simplify_exprt::resultt<> simplify_exprt::simplify_inequality_rhs_is_constant(
16391639
new_expr.op1().type() = new_expr.op0().type();
16401640
return changed(simplify_inequality(new_expr)); // do again!
16411641
}
1642+
else if(expr.op0().id() == ID_plus)
1643+
{
1644+
// NULL + 1 == NULL is false
1645+
const plus_exprt &plus = to_plus_expr(expr.op0());
1646+
if(
1647+
plus.operands().size() == 2 && plus.op0().is_constant() &&
1648+
plus.op1().is_constant() &&
1649+
((is_null_pointer(to_constant_expr(plus.op0())) &&
1650+
!plus.op1().is_zero()) ||
1651+
(is_null_pointer(to_constant_expr(plus.op1())) &&
1652+
!plus.op0().is_zero())))
1653+
{
1654+
return false_exprt();
1655+
}
1656+
}
16421657
}
16431658

16441659
// all we are doing with pointers

0 commit comments

Comments
 (0)