Fix 10645: FP knownEmptyContainer after conditional return (#3620)

This commit is contained in:
Paul Fultz II 2021-12-14 00:22:57 -06:00 committed by GitHub
parent f79bb40e3d
commit cb2738a60c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -640,13 +640,13 @@ static ValueFlow::Value execute(const Token* expr, ProgramMemory& pm)
if (rhs.isIntValue()) {
std::vector<ValueFlow::Value> result =
infer(makeIntegralInferModel(), expr->str(), expr->astOperand1()->values(), {rhs});
if (result.empty())
if (result.empty() || !result.front().isKnown())
return unknown;
return result.front();
} else if (lhs.isIntValue()) {
std::vector<ValueFlow::Value> result =
infer(makeIntegralInferModel(), expr->str(), {lhs}, expr->astOperand2()->values());
if (result.empty())
if (result.empty() || !result.front().isKnown())
return unknown;
return result.front();
}

View File

@ -5387,6 +5387,18 @@ private:
"}\n",
true);
ASSERT_EQUALS("", errout.str());
check("void f(const std::vector<int>& v, int e) {\n"
" if (!v.empty()) {\n"
" if (e < 0 || true) {\n"
" if (e < 0)\n"
" return;\n"
" }\n"
" }\n"
" for (auto i : v) {}\n"
"}\n",
true);
ASSERT_EQUALS("", errout.str());
}
void checkMutexes() {