Fix 10223: ValueFlow; known value for a volatile variable (#3658)

This commit is contained in:
Paul Fultz II 2022-01-01 16:15:14 -06:00 committed by GitHub
parent 7bf0ca8d00
commit 0c952ca05d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -4883,6 +4883,12 @@ static void valueFlowForwardAssign(Token* const tok,
if (vars.size() == 1 && vars.front()->isStatic() && init) if (vars.size() == 1 && vars.front()->isStatic() && init)
lowerToPossible(values); lowerToPossible(values);
// is volatile
if (std::any_of(vars.begin(), vars.end(), [&](const Variable* var) {
return var->isVolatile();
}))
lowerToPossible(values);
// Skip RHS // Skip RHS
const Token * nextExpression = tok->astParent() ? nextAfterAstRightmostLeaf(tok->astParent()) : tok->next(); const Token * nextExpression = tok->astParent() ? nextAfterAstRightmostLeaf(tok->astParent()) : tok->next();

View File

@ -3838,6 +3838,18 @@ private:
" if (b) {}\n" " if (b) {}\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #10223
check("static volatile sig_atomic_t is_running;\n"
"static void handler(int signum) {\n"
" is_running = 0;\n"
"}\n"
"void f() {\n"
" signal(SIGINT, &handler);\n"
" is_running = 1;\n"
" while (is_running) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void alwaysTrueSymbolic() void alwaysTrueSymbolic()