From c34691ff56fdf8daefa6eb36a8d953696c9fb89e Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Mon, 26 Jul 2021 15:22:50 -0500 Subject: [PATCH] Fix 10354: FP knownConditionTrueFalse after bitwise and/xor (#3360) --- lib/valueflow.cpp | 2 +- test/testvalueflow.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 60abb84f4..ee26d4f7c 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 (!Token::Match(tok, "-|%") && 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 873a17f15..a1365868d 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -5866,6 +5866,20 @@ private: "}\n"; ASSERT_EQUALS(false, testValueOfXImpossible(code, 3U, 0)); ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, -1)); + + code = "auto f(uint32_t i) {\n" + " auto x = i ^ 3;\n" + " return x;\n" + "}\n"; + ASSERT_EQUALS(false, testValueOfXImpossible(code, 3U, 2)); + ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, -1)); + + code = "auto f(uint32_t i) {\n" + " auto x = i & 3;\n" + " return x;\n" + "}\n"; + ASSERT_EQUALS(false, testValueOfXImpossible(code, 3U, 2)); + ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, -1)); } void valueFlowMod() {