Skip to content

Commit b899cb0

Browse files
committed
Make guard_exprt::operator-= work with individual conditions
Before, operator-= would only apply when both of the operands were conjunctions. Yet it is perfectly safe use when one or both operands aren't conjunctions.
1 parent 786f7d7 commit b899cb0

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

regression/cbmc-concurrency/atomic_section_sc7/test-guard.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
--program-only
44
^EXIT=0$

src/analyses/guard_expr.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,42 @@ void guard_exprt::add(const exprt &expr)
6565

6666
guard_exprt &operator-=(guard_exprt &g1, const guard_exprt &g2)
6767
{
68-
if(g1.expr.id() != ID_and || g2.expr.id() != ID_and)
68+
if(g1.expr.id() != ID_and)
69+
{
70+
if(g2.expr.id() != ID_and)
71+
{
72+
if(g1.expr == g2.expr)
73+
g1.expr = true_exprt{};
74+
}
75+
else
76+
{
77+
for(const auto &op : g2.expr.operands())
78+
{
79+
if(g1.expr == op)
80+
{
81+
g1.expr = true_exprt{};
82+
break;
83+
}
84+
}
85+
}
86+
6987
return g1;
88+
}
89+
90+
if(g2.expr.id() != ID_and)
91+
{
92+
exprt::operandst &op1 = g1.expr.operands();
93+
for(exprt::operandst::iterator it = op1.begin(); it != op1.end(); ++it)
94+
{
95+
if(g1.expr == g2.expr)
96+
{
97+
op1.erase(it);
98+
break;
99+
}
100+
}
101+
102+
return g1;
103+
}
70104

71105
sort_and_join(g1.expr);
72106
exprt g2_sorted = g2.as_expr();

0 commit comments

Comments
 (0)