Fix 11114: FP knownConditionTrueFalse across functions (#4163)
* Fix 11114: FP knownConditionTrueFalse across functions * Format
This commit is contained in:
parent
133b9c2790
commit
72342de0da
|
@ -219,17 +219,17 @@ static void setConditionalValues(const Token* tok,
|
|||
ValueFlow::Value& false_value)
|
||||
{
|
||||
if (Token::Match(tok, "==|!=|>=|<=")) {
|
||||
true_value = ValueFlow::Value{tok, value};
|
||||
setConditionalValue(true_value, tok, value);
|
||||
const char* greaterThan = ">=";
|
||||
const char* lessThan = "<=";
|
||||
if (lhs)
|
||||
std::swap(greaterThan, lessThan);
|
||||
if (Token::simpleMatch(tok, greaterThan, strlen(greaterThan))) {
|
||||
false_value = ValueFlow::Value{tok, value - 1};
|
||||
setConditionalValue(false_value, tok, value - 1);
|
||||
} else if (Token::simpleMatch(tok, lessThan, strlen(lessThan))) {
|
||||
false_value = ValueFlow::Value{tok, value + 1};
|
||||
setConditionalValue(false_value, tok, value + 1);
|
||||
} else {
|
||||
false_value = ValueFlow::Value{tok, value};
|
||||
setConditionalValue(false_value, tok, value);
|
||||
}
|
||||
} else {
|
||||
const char* greaterThan = ">";
|
||||
|
|
|
@ -4382,6 +4382,20 @@ private:
|
|||
" }\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(false, testValueOfX(code, 8U, -1));
|
||||
|
||||
code = "typedef enum {\n"
|
||||
" K0, K1\n"
|
||||
"} K;\n"
|
||||
"bool valid(Object *obj, K x) {\n"
|
||||
" if (!obj || obj->kind != x)\n"
|
||||
" return false;\n"
|
||||
" return x == K0;\n"
|
||||
"}\n"
|
||||
"void f(Object *obj) {\n"
|
||||
" if (valid(obj, K0)) {}\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(true, testValueOfX(code, 7U, 0));
|
||||
ASSERT_EQUALS(false, testValueOfXKnown(code, 7U, 0));
|
||||
}
|
||||
void valueFlowFunctionReturn() {
|
||||
const char *code;
|
||||
|
|
Loading…
Reference in New Issue