Skip to content

Commit b2dc712

Browse files
authored
Merge pull request #5891 from tautschnig/fix-simplify-bitor
Simplify bitor/bitxor with ID_bv-typed zero operand
2 parents fa12ca7 + adefae7 commit b2dc712

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/util/simplify_expr_int.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,14 @@ simplify_exprt::simplify_bitwise(const multi_ary_exprt &expr)
715715
it = new_expr.operands().erase(it);
716716
no_change = false;
717717
}
718+
else if(
719+
it->is_constant() && it->type().id() == ID_bv &&
720+
to_constant_expr(*it).value_is_zero_string() &&
721+
new_expr.operands().size() > 1)
722+
{
723+
it = new_expr.operands().erase(it);
724+
no_change = false;
725+
}
718726
else
719727
it++;
720728
}

unit/util/simplify_expr.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,18 @@ TEST_CASE("Simplifying cast expressions", "[core][util]")
501501
REQUIRE(simplified_expr == expr);
502502
}
503503
}
504+
505+
TEST_CASE("Simplify bitor", "[core][util]")
506+
{
507+
const symbol_tablet symbol_table;
508+
const namespacet ns(symbol_table);
509+
510+
SECTION("Simplification for raw bitvector")
511+
{
512+
bv_typet bv{4};
513+
constant_exprt zero = from_integer(0, bv);
514+
symbol_exprt b{"B", bv};
515+
516+
REQUIRE(simplify_expr(bitor_exprt{b, zero}, ns) == b);
517+
}
518+
}

0 commit comments

Comments
 (0)