Fixed #1549 (false positive: uninitialized variable)

This commit is contained in:
Daniel Marjamäki 2010-03-31 20:20:51 +02:00
parent 78e54e17f2
commit a68d8dbc77
4 changed files with 31 additions and 1 deletions

View File

@ -501,6 +501,12 @@ void CheckOther::functionVariableUsage()
break;
}
if (Token::Match(tok, "[;{}] asm ( ) ;"))
{
varUsage.clear();
break;
}
if (Token::Match(tok, "[;{}] %type% %var% ;|=") && tok->next()->isStandardType())
varUsage[tok->strAt(2)].declare = true;

View File

@ -1238,7 +1238,6 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s
tok->tokAt(2)->link()->next())
{
Token::eraseTokens(tok, tok->tokAt(2)->link()->next());
}
else if (Token::Match(tok->next(), "__asm__ __volatile__ (") &&
@ -1248,6 +1247,17 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s
Token::eraseTokens(tok, tok->tokAt(3)->link()->next());
}
else if (Token::simpleMatch(tok->next(), "__asm"))
{
const Token *tok2 = tok->next();
while (tok2 && (tok2->isNumber() || tok2->isName() || tok2->str() == ","))
tok2 = tok2->next();
if (tok2 && tok2->str() == ";")
Token::eraseTokens(tok, tok2);
else
continue;
}
else
continue;

View File

@ -397,6 +397,8 @@ private:
ASSERT_EQUALS("; asm ( ) ;", tokenizeAndStringify(";_asm { mov ax,bx };"));
ASSERT_EQUALS("; asm ( ) ;", tokenizeAndStringify(";__asm { mov ax,bx };"));
ASSERT_EQUALS("; asm ( ) ;", tokenizeAndStringify(";__asm__ __volatile__ ( \"mov ax,bx\" );"));
ASSERT_EQUALS("; asm ( ) ;", tokenizeAndStringify(";__asm _emit 12h ;"));
ASSERT_EQUALS("; asm ( ) ;", tokenizeAndStringify(";__asm mov a, b ;"));
}

View File

@ -65,6 +65,7 @@ private:
TEST_CASE(localvar4);
TEST_CASE(localvar5);
TEST_CASE(localvar6);
TEST_CASE(localvarasm);
// Don't give false positives for variables in structs/unions
TEST_CASE(localvarStruct1);
@ -286,6 +287,17 @@ private:
ASSERT_EQUALS(std::string(""), errout.str());
}
void localvarasm()
{
functionVariableUsage("void foo(int &b)\n"
"{\n"
" int a;\n"
" asm();\n"
" b = a;\n"
"}\n");
ASSERT_EQUALS(std::string(""), errout.str());
}
void localvarStruct1()