Fixed #2398 (false positive: Uninitialized variable)

This commit is contained in:
Daniel Marjamäki 2011-01-04 19:36:29 +01:00
parent 3cf4e74013
commit 63c1ee375e
2 changed files with 24 additions and 1 deletions

View File

@ -6314,7 +6314,7 @@ bool Tokenizer::simplifyKnownVariables()
if (tok3->varId() == varid) if (tok3->varId() == varid)
{ {
// Continue // Continue
tok2 = bailOutFromLoop; //tok2 = bailOutFromLoop;
break; break;
} }
else if (tok3 == bailOutFromLoop) else if (tok3 == bailOutFromLoop)

View File

@ -125,6 +125,7 @@ private:
TEST_CASE(simplifyKnownVariables34); TEST_CASE(simplifyKnownVariables34);
TEST_CASE(simplifyKnownVariables35); // ticket #2353 - False positive: Division by zero 'if (x == 0) return 0; return 10 / x;' TEST_CASE(simplifyKnownVariables35); // ticket #2353 - False positive: Division by zero 'if (x == 0) return 0; return 10 / x;'
TEST_CASE(simplifyKnownVariables36); // ticket #2304 - known value for strcpy parameter TEST_CASE(simplifyKnownVariables36); // ticket #2304 - known value for strcpy parameter
TEST_CASE(simplifyKnownVariables37); // ticket #2398 - false positive caused by no simplification in for loop
TEST_CASE(simplifyKnownVariablesBailOutAssign); TEST_CASE(simplifyKnownVariablesBailOutAssign);
TEST_CASE(simplifyKnownVariablesBailOutFor1); TEST_CASE(simplifyKnownVariablesBailOutFor1);
TEST_CASE(simplifyKnownVariablesBailOutFor2); TEST_CASE(simplifyKnownVariablesBailOutFor2);
@ -1918,6 +1919,28 @@ private:
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
} }
void simplifyKnownVariables37()
{
// Ticket #2398 - no simplication in for loop
const char code[] = "void f() {\n"
" double x = 0;\n"
" for (int iter=0; iter<42; iter++) {\n"
" int EvaldF = 1;\n"
" if (EvaldF)\n"
" Eval (x);\n"
" }\n"
"}";
const char expected[] = "void f ( ) {\n"
"double x ; x = 0 ;\n"
"for ( int iter = 0 ; iter < 42 ; iter ++ ) {\n"
";\n"
"{\n"
"Eval ( x ) ; }\n"
"}\n"
"}";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
}
void simplifyKnownVariablesBailOutAssign() void simplifyKnownVariablesBailOutAssign()
{ {
const char code[] = "int foo() {\n" const char code[] = "int foo() {\n"