diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 3c5898e7e..176db9e38 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -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); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index f3de3ab31..dd1343c16 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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("("); diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index c2b86669c..a331273d4 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -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" diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 5400a388c..ffbadc4d0 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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));