Fixed #3608 (unreadVariable when variable used in inline assembly)

This commit is contained in:
Daniel Marjamäki 2012-02-19 16:04:35 +01:00
parent 69d03bac34
commit 39b0f1ba95
2 changed files with 6 additions and 3 deletions

View File

@ -8643,13 +8643,15 @@ void Tokenizer::simplifyAsm()
Token::eraseTokens(tok, partok->link()->next()); Token::eraseTokens(tok, partok->link()->next());
} }
else if (Token::simpleMatch(tok, "__asm")) { else if (Token::Match(tok, "_asm|__asm")) {
const Token *tok2 = tok; const Token *tok2 = tok;
while (tok2 && (tok2->isNumber() || tok2->isName() || tok2->str() == ",")) while (tok2 && tok2->linenr() == tok->linenr() && (tok2->isNumber() || tok2->isName() || tok2->str() == ","))
tok2 = tok2->next(); tok2 = tok2->next();
if (tok2 && tok2->str() == ";") { if (!tok2 || tok2->str() == ";" || tok2->linenr() != tok->linenr()) {
instruction = tok->next()->stringify(tok2); instruction = tok->next()->stringify(tok2);
Token::eraseTokens(tok, tok2); Token::eraseTokens(tok, tok2);
if (!tok2 || tok2->str() != ";")
tok->insertToken(";");
} else } else
continue; continue;
} }

View File

@ -784,6 +784,7 @@ private:
void inlineasm() { void inlineasm() {
ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("asm { mov ax,bx };")); ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("asm { mov ax,bx };"));
ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("_asm { mov ax,bx };")); ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("_asm { mov ax,bx };"));
ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("_asm mov ax,bx"));
ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("__asm { mov ax,bx };")); ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("__asm { mov ax,bx };"));
ASSERT_EQUALS("asm ( \"\"mov ax,bx\"\" ) ;", tokenizeAndStringify("__asm__ __volatile__ ( \"mov ax,bx\" );")); ASSERT_EQUALS("asm ( \"\"mov ax,bx\"\" ) ;", tokenizeAndStringify("__asm__ __volatile__ ( \"mov ax,bx\" );"));
ASSERT_EQUALS("asm ( \"_emit 12h\" ) ;", tokenizeAndStringify("__asm _emit 12h ;")); ASSERT_EQUALS("asm ( \"_emit 12h\" ) ;", tokenizeAndStringify("__asm _emit 12h ;"));