From a68d8dbc775c2793a8313380a80c3d8d559b403f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 31 Mar 2010 20:20:51 +0200 Subject: [PATCH] Fixed #1549 (false positive: uninitialized variable) --- lib/checkother.cpp | 6 ++++++ lib/tokenize.cpp | 12 +++++++++++- test/testtokenize.cpp | 2 ++ test/testunusedvar.cpp | 12 ++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 4c146cb9a..725ed84c3 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7205b1815..47f710abf 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b5a056173..ac35d28fa 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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 ;")); } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 8401aaa58..8ed5fb9ac 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -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()