Skip to content

Commit 37efa2e

Browse files
fixup! Handle reverse conditions in isOppositeCond function
1 parent 4fc115d commit 37efa2e

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

lib/astutils.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,10 +1812,14 @@ bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Se
18121812

18131813
static bool isZeroBoundCond(const Token * const cond, bool reverse)
18141814
{
1815-
if (cond == nullptr)
1815+
if (cond == nullptr || cond->astOperand1() == nullptr || cond->astOperand2() == nullptr)
18161816
return false;
1817+
1818+
if ((reverse && !cond->astOperand1()->hasKnownIntValue()) || (!reverse && !cond->astOperand2()->hasKnownIntValue()))
1819+
return false;
1820+
18171821
// Assume unsigned
1818-
const bool isZero = reverse ? cond->astOperand1()->getValue(0) : cond->astOperand2()->getValue(0);
1822+
const bool isZero = reverse ? cond->astOperand1()->getKnownIntValue() == 0 : cond->astOperand2()->getKnownIntValue() == 0;
18191823
if (reverse) {
18201824
if (cond->str() == "==" || cond->str() == "<=")
18211825
return isZero;

0 commit comments

Comments
 (0)