Improved handling of inline assembly (#6813):

- Add ; after asm {} block if required
- Fixed inline suppressions
This commit is contained in:
PKEuS 2015-07-20 22:51:06 +02:00
parent a0890ecd2c
commit 149d11d9ad
4 changed files with 21 additions and 1 deletions

View File

@ -588,8 +588,11 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
} else if ((i == 0 || std::isspace((unsigned char)str[i-1])) && str.compare(i, 5, "__asm") == 0) {
while (i < str.size() && (std::isalpha((unsigned char)str[i]) || str[i] == '_'))
code << str[i++];
while (i < str.size() && std::isspace((unsigned char)str[i]))
while (i < str.size() && std::isspace((unsigned char)str[i])) {
if (str[i] == '\n')
lineno++;
code << str[i++];
}
if (str[i] == '{') {
// Ticket 4873: Extract comments from the __asm / __asm__'s content
std::string asmBody;
@ -599,6 +602,8 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
if (backslashN != std::string::npos) // Ticket #4922: Don't go in infinite loop or crash if there is no '\n'
i = backslashN;
}
if (str[i] == '\n')
lineno++;
asmBody += str[i++];
}
code << removeComments(asmBody, filename);

View File

@ -9528,6 +9528,8 @@ void Tokenizer::simplifyAsm()
// insert "asm ( "instruction" )"
tok->str("asm");
if (tok->strAt(1) != ";" && tok->strAt(1) != "{")
tok->insertToken(";");
tok->insertToken(")");
tok->insertToken("\"" + instruction + "\"");
tok->insertToken("(");

View File

@ -297,6 +297,18 @@ private:
"");
ASSERT_EQUALS("", errout.str());
// suppress uninitvar inline, with asm before (#6813)
(this->*check)("void f() {\n"
" __asm {\n"
" foo\n"
" }"
" int a;\n"
" // cppcheck-suppress uninitvar\n"
" a++;\n"
"}",
"");
ASSERT_EQUALS("", errout.str());
// suppress uninitvar inline, without error present
(this->*check)("void f() {\n"
" int a;\n"

View File

@ -1076,6 +1076,7 @@ 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\" ) ; int a ;", tokenizeAndStringify("asm { mov ax,bx } int a;"));
// 'asm ( ) ;' should be in the same line
ASSERT_EQUALS(";\n\nasm ( \"\"mov ax,bx\"\" ) ;", tokenizeAndStringify(";\n\n__asm__ volatile ( \"mov ax,bx\" );", true));