Fixed #7806 (ValueFlow: better handling of subfunction with early return)
This commit is contained in:
parent
ee56fbe3a1
commit
7ebfb10edd
|
@ -1279,8 +1279,11 @@ static bool valueFlowForward(Token * const startToken,
|
||||||
// goto '}'
|
// goto '}'
|
||||||
tok2 = startToken1->link();
|
tok2 = startToken1->link();
|
||||||
|
|
||||||
if (condAlwaysTrue && isReturnScope(tok2))
|
if (isReturnScope(tok2)) {
|
||||||
return false;
|
if (condAlwaysTrue)
|
||||||
|
return false;
|
||||||
|
removeValues(values, truevalues);
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -2255,7 +2258,7 @@ static void valueFlowInjectParameter(TokenList* tokenlist, ErrorLogger* errorLog
|
||||||
if (!varid2)
|
if (!varid2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
valueFlowForward(const_cast<Token*>(functionScope->classStart->next()), functionScope->classEnd, arg, varid2, argvalues, true, tokenlist, errorLogger, settings);
|
valueFlowForward(const_cast<Token*>(functionScope->classStart->next()), functionScope->classEnd, arg, varid2, argvalues, false, tokenlist, errorLogger, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void valueFlowSwitchVariable(TokenList *tokenlist, SymbolDatabase* symboldatabase, ErrorLogger *errorLogger, const Settings *settings)
|
static void valueFlowSwitchVariable(TokenList *tokenlist, SymbolDatabase* symboldatabase, ErrorLogger *errorLogger, const Settings *settings)
|
||||||
|
|
|
@ -1716,6 +1716,17 @@ private:
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
|
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
|
||||||
|
|
||||||
|
code = "void f1(int x) {\n"
|
||||||
|
" if (x == 0) return;\n"
|
||||||
|
" int y = x;\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"void f2() {\n"
|
||||||
|
" f1(x&4);\n" // possible {0,4}
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
|
||||||
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 4));
|
||||||
|
|
||||||
code = "void f1(int x) { a=x; }\n"
|
code = "void f1(int x) { a=x; }\n"
|
||||||
"void f2(int y) { f1(y<123); }\n";
|
"void f2(int y) { f1(y<123); }\n";
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 1U, 0));
|
ASSERT_EQUALS(true, testValueOfX(code, 1U, 0));
|
||||||
|
|
Loading…
Reference in New Issue