Fix 10390: FP: knownConditionTrueFalse (#3374)

This commit is contained in:
Paul Fultz II 2021-08-02 03:49:39 -05:00 committed by GitHub
parent 405e17985a
commit 61ceff39f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -4031,6 +4031,10 @@ static void valueFlowSymbolic(TokenList* tokenlist, SymbolDatabase* symboldataba
continue;
if (tok->astOperand2()->hasKnownIntValue())
continue;
if (tok->astOperand1()->exprId() == 0)
continue;
if (tok->astOperand2()->exprId() == 0)
continue;
if (!isConstExpression(tok->astOperand2(), tokenlist->getSettings()->library, true, tokenlist->isCPP()))
continue;
@ -4068,6 +4072,10 @@ static void valueFlowSymbolicInfer(TokenList* tokenlist, SymbolDatabase* symbold
continue;
if (tok->astOperand2()->hasKnownIntValue())
continue;
if (astIsFloat(tok->astOperand1(), false))
continue;
if (astIsFloat(tok->astOperand2(), false))
continue;
MathLib::bigint rhsvalue = 0;
const ValueFlow::Value* rhs =

View File

@ -6007,6 +6007,20 @@ private:
" return x;\n"
"}\n";
ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, "i++", 0));
code = "float foo() {\n"
" float f = 1.0f;\n"
" float x = f;\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, "1.0f", 0));
code = "int foo(float f) {\n"
" float g = f;\n"
" int x = f == g;\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, 1));
}
};