Skip to content

Commit 0289d31

Browse files
committed
ITE and binary relations are constant when all operands are constants
This expands the definition of is_constantt to cover if-then-else as well as binary relations and logic or bit operations. In many, but not, cases the simplifier will have turned these into simpler constants. The included regression test is derived from Rust code, where the intermediate representation (together with constant propagation) will yield such comparisons.
1 parent e024ecb commit 0289d31

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
int main(void)
2+
{
3+
int x;
4+
int plus_one_is_null = &x + 1 == (int *)0 ? 1 : 0;
5+
__CPROVER_assert(plus_one_is_null != 2, "cannot be 2");
6+
7+
return 0;
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE new-smt-backend
2+
main.c
3+
4+
^Generated 1 VCC\(s\), 0 remaining after simplification$
5+
^VERIFICATION SUCCESSFUL$
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
^warning: ignoring

src/util/expr_util.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,12 @@ bool is_constantt::is_constant(const exprt &expr) const
239239
expr.id() == ID_typecast || expr.id() == ID_array_of ||
240240
expr.id() == ID_plus || expr.id() == ID_mult || expr.id() == ID_array ||
241241
expr.id() == ID_with || expr.id() == ID_struct || expr.id() == ID_union ||
242-
expr.id() == ID_empty_union ||
243-
expr.id() == ID_byte_update_big_endian ||
242+
expr.id() == ID_empty_union || expr.id() == ID_equal ||
243+
expr.id() == ID_notequal || expr.id() == ID_lt || expr.id() == ID_le ||
244+
expr.id() == ID_gt || expr.id() == ID_ge || expr.id() == ID_if ||
245+
expr.id() == ID_not || expr.id() == ID_and || expr.id() == ID_or ||
246+
expr.id() == ID_bitnot || expr.id() == ID_bitand || expr.id() == ID_bitor ||
247+
expr.id() == ID_bitxor || expr.id() == ID_byte_update_big_endian ||
244248
expr.id() == ID_byte_update_little_endian)
245249
{
246250
return std::all_of(

0 commit comments

Comments
 (0)