Fix 10353: FP knownConditionTrueFalse with conditional assignment (#3333)

This commit is contained in:
Paul Fultz II 2021-07-10 00:35:16 -05:00 committed by GitHub
parent ddd117e600
commit 9fc5b9472d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -364,8 +364,8 @@ ProgramMemory ProgramMemoryState::get(const Token* tok, const Token* ctx, const
start = tok;
if (!ctx || precedes(start, ctx)) {
local.addState(start, vars);
local.removeModifiedVars(start);
local.addState(start, vars);
} else {
local.removeModifiedVars(ctx);
}

View File

@ -2283,6 +2283,22 @@ private:
"}\n";
ASSERT_EQUALS(false, testValueOfXKnown(code, 7U, 1));
ASSERT_EQUALS(true, testValueOfXInconclusive(code, 7U, 1));
code = "long foo();\n"
"long bar();\n"
"int test() {\n"
" bool b = true;\n"
" long a = foo();\n"
" if (a != 0)\n"
" return 1;\n"
" a = bar();\n"
" if (a != 0)\n"
" b = false;\n"
" int x = b;\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 12U, 0));
ASSERT_EQUALS(false, testValueOfXKnown(code, 12U, 0));
}
void valueFlowAfterCondition() {