From 8e416a725511f5d16a415834f043077317b78d0e Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sun, 25 Jul 2021 11:13:14 -0500 Subject: [PATCH] Fix issue 10379: FP knownConditionTrueFalse with mod operator (#3354) --- lib/valueflow.cpp | 2 +- test/testvalueflow.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 72a307240..c939577d2 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1533,7 +1533,7 @@ static std::vector minUnsignedValue(const Token* tok, int depth return result; if (tok->hasKnownIntValue()) { result = {tok->values().front().intvalue}; - } else if (tok->str() != "-" && tok->isConstOp() && tok->astOperand1() && tok->astOperand2()) { + } else if (!Token::Match(tok, "-|%") && tok->isConstOp() && tok->astOperand1() && tok->astOperand2()) { std::vector op1 = minUnsignedValue(tok->astOperand1(), depth - 1); std::vector op2 = minUnsignedValue(tok->astOperand2(), depth - 1); if (!op1.empty() && !op2.empty()) { diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index e70835c2a..873a17f15 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -5859,6 +5859,13 @@ private: "}\n"; ASSERT_EQUALS(false, testValueOfXImpossible(code, 4U, 0)); ASSERT_EQUALS(true, testValueOfXImpossible(code, 4U, -1)); + + code = "auto f(uint32_t i) {\n" + " auto x = (i + 1) % 16;\n" + " return x;\n" + "}\n"; + ASSERT_EQUALS(false, testValueOfXImpossible(code, 3U, 0)); + ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, -1)); } void valueFlowMod() {