Fixed #6028 (Improvement: False positive caused by C keywords in assembly comments)
This commit is contained in:
parent
65297ce285
commit
a8a54bbfa8
|
@ -3337,6 +3337,9 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
||||||
|
|
||||||
createLinks();
|
createLinks();
|
||||||
|
|
||||||
|
// Remove __asm..
|
||||||
|
simplifyAsm();
|
||||||
|
|
||||||
// Bail out if code is garbage
|
// Bail out if code is garbage
|
||||||
if (const Token *garbage = findGarbageCode())
|
if (const Token *garbage = findGarbageCode())
|
||||||
syntaxError(garbage);
|
syntaxError(garbage);
|
||||||
|
@ -3488,9 +3491,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
||||||
// syntax error: enum with typedef in it
|
// syntax error: enum with typedef in it
|
||||||
checkForEnumsWithTypedef();
|
checkForEnumsWithTypedef();
|
||||||
|
|
||||||
// Remove __asm..
|
|
||||||
simplifyAsm();
|
|
||||||
|
|
||||||
// Add parentheses to ternary operator where necessary
|
// Add parentheses to ternary operator where necessary
|
||||||
prepareTernaryOpForAST();
|
prepareTernaryOpForAST();
|
||||||
|
|
||||||
|
@ -8835,13 +8835,30 @@ void Tokenizer::simplifyAsm()
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::Match(tok, "_asm|__asm")) {
|
else if (Token::Match(tok, "_asm|__asm")) {
|
||||||
const Token *tok2 = tok;
|
Token *endasm = tok->next();
|
||||||
while (tok2 && (tok2->isNumber() || tok2->isName() || tok2->str() == "," || tok2->str() == ":"))
|
const Token *firstSemiColon = nullptr;
|
||||||
tok2 = tok2->next();
|
unsigned int comment = 0;
|
||||||
if (!tok2 || tok2->str() == ";" || tok2->linenr() != tok->linenr()) {
|
while (Token::Match(endasm, "%num%|%name%|,|:|;") || (endasm && endasm->linenr() == comment)) {
|
||||||
instruction = tok->next()->stringifyList(tok2);
|
if (Token::Match(endasm, "_asm|__asm|__endasm"))
|
||||||
Token::eraseTokens(tok, tok2);
|
break;
|
||||||
if (!tok2 || tok2->str() != ";")
|
if (endasm->str() == ";") {
|
||||||
|
comment = endasm->linenr();
|
||||||
|
if (!firstSemiColon)
|
||||||
|
firstSemiColon = endasm;
|
||||||
|
}
|
||||||
|
endasm = endasm->next();
|
||||||
|
}
|
||||||
|
if (Token::simpleMatch(endasm, "__endasm")) {
|
||||||
|
instruction = tok->next()->stringifyList(endasm);
|
||||||
|
Token::eraseTokens(tok, endasm->next());
|
||||||
|
if (!Token::simpleMatch(tok->next(), ";"))
|
||||||
|
tok->insertToken(";");
|
||||||
|
} else if (firstSemiColon) {
|
||||||
|
instruction = tok->next()->stringifyList(firstSemiColon);
|
||||||
|
Token::eraseTokens(tok, firstSemiColon);
|
||||||
|
} else if (!endasm) {
|
||||||
|
instruction = tok->next()->stringifyList(endasm);
|
||||||
|
Token::eraseTokens(tok, endasm);
|
||||||
tok->insertToken(";");
|
tok->insertToken(";");
|
||||||
} else
|
} else
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -1011,7 +1011,8 @@ private:
|
||||||
ASSERT_EQUALS("asm ( \"\"ddd\"\" ) ;", tokenizeAndStringify(" __asm __volatile (\"ddd\") ;"));
|
ASSERT_EQUALS("asm ( \"\"ddd\"\" ) ;", tokenizeAndStringify(" __asm __volatile (\"ddd\") ;"));
|
||||||
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 ( \"mov ax , bx\" ) ; int a ;", tokenizeAndStringify("asm { mov ax,bx } int a;"));
|
ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ; int a ;", tokenizeAndStringify("asm { mov ax,bx } int a;"));
|
||||||
ASSERT_EQUALS("asm\n\n( \"mov ax , bx __endasm\" ) ;", tokenizeAndStringify("__asm\nmov ax,bx\n__endasm;"));
|
ASSERT_EQUALS("asm\n\n( \"mov ax , bx\" ) ;", tokenizeAndStringify("__asm\nmov ax,bx\n__endasm;"));
|
||||||
|
ASSERT_EQUALS("asm\n\n( \"push b ; for if\" ) ;", tokenizeAndStringify("__asm\npush b ; for if\n__endasm;"));
|
||||||
|
|
||||||
// 'asm ( ) ;' should be in the same line
|
// 'asm ( ) ;' should be in the same line
|
||||||
ASSERT_EQUALS(";\n\nasm ( \"\"mov ax,bx\"\" ) ;", tokenizeAndStringify(";\n\n__asm__ volatile ( \"mov ax,bx\" );", true));
|
ASSERT_EQUALS(";\n\nasm ( \"\"mov ax,bx\"\" ) ;", tokenizeAndStringify(";\n\n__asm__ volatile ( \"mov ax,bx\" );", true));
|
||||||
|
|
Loading…
Reference in New Issue