Skip to content

Commit 015d6d8

Browse files
make_and simplifies trivial expressions
This is to avoid generating expressions like TRUE && TRUE
1 parent 955eab1 commit 015d6d8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/util/expr_util.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,19 @@ constant_exprt make_boolean_expr(bool value)
292292

293293
exprt make_and(exprt a, exprt b)
294294
{
295+
PRECONDITION(a.type().id() == ID_bool && b.type().id() == ID_bool);
296+
if(b.is_constant())
297+
{
298+
if(b.get(ID_value) == ID_false)
299+
return false_exprt{};
300+
return a;
301+
}
302+
if(a.is_constant())
303+
{
304+
if(a.get(ID_value) == ID_false)
305+
return false_exprt{};
306+
return b;
307+
}
295308
if(b.id() == ID_and)
296309
{
297310
b.add_to_operands(std::move(a));

src/util/expr_util.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ class is_constantt
101101
constant_exprt make_boolean_expr(bool);
102102

103103
/// Conjunction of two expressions. If the second is already an `and_exprt`
104-
/// add to its operands instead of creating a new expression.
104+
/// add to its operands instead of creating a new expression. If one is `true`,
105+
/// return the other expression. If one is `false` returns `false`.
105106
exprt make_and(exprt a, exprt b);
106107

107108
#endif // CPROVER_UTIL_EXPR_UTIL_H

0 commit comments

Comments
 (0)