Fix 10354: FP knownConditionTrueFalse after bitwise and/xor (#3360)

This commit is contained in:
Paul Fultz II 2021-07-26 15:22:50 -05:00 committed by GitHub
parent 0d3afbb954
commit c34691ff56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -1533,7 +1533,7 @@ static std::vector<MathLib::bigint> 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<MathLib::bigint> op1 = minUnsignedValue(tok->astOperand1(), depth - 1);
std::vector<MathLib::bigint> op2 = minUnsignedValue(tok->astOperand2(), depth - 1);
if (!op1.empty() && !op2.empty()) {

View File

@ -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() {