Skip to content

Commit 303be34

Browse files
fixup! fixup! Handle reverse conditions in isOppositeCond function
1 parent 37efa2e commit 303be34

1 file changed

Lines changed: 15 additions & 20 deletions

File tree

lib/astutils.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,34 +1812,29 @@ 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 || cond->astOperand1() == nullptr || cond->astOperand2() == nullptr)
1815+
if (cond == nullptr || !cond->isBinaryOp())
18161816
return false;
18171817

1818-
if ((reverse && !cond->astOperand1()->hasKnownIntValue()) || (!reverse && !cond->astOperand2()->hasKnownIntValue()))
1818+
const Token* op = reverse ? cond->astOperand1() : cond->astOperand2();
1819+
if (!op->hasKnownIntValue())
18191820
return false;
18201821

18211822
// Assume unsigned
1822-
const bool isZero = reverse ? cond->astOperand1()->getKnownIntValue() == 0 : cond->astOperand2()->getKnownIntValue() == 0;
1823+
const bool isZero = op->getKnownIntValue() == 0;
1824+
std::string cmp = cond->str();
18231825
if (reverse) {
1824-
if (cond->str() == "==" || cond->str() == "<=")
1825-
return isZero;
1826-
if (cond->str() == ">=")
1827-
return true;
1828-
if (cond->str() == ">")
1829-
return !isZero;
1830-
if (cond->str() == "<")
1831-
return false;
1832-
} else {
1833-
if (cond->str() == "==" || cond->str() == ">=")
1834-
return isZero;
1835-
if (cond->str() == "<=")
1836-
return true;
1837-
if (cond->str() == "<")
1838-
return !isZero;
1839-
if (cond->str() == ">")
1840-
return false;
1826+
if (cmp[0] == '>')
1827+
cmp[0] = '<';
1828+
else if (cmp[0] == '<')
1829+
cmp[0] = '>';
18411830
}
18421831

1832+
if (cmp == "==" || cmp == ">=")
1833+
return isZero;
1834+
if (cmp == "<=")
1835+
return true;
1836+
if (cmp == "<")
1837+
return !isZero;
18431838
return false;
18441839
}
18451840

0 commit comments

Comments
 (0)