diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index af54b572b99..88c64c006c4 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9902,7 +9902,7 @@ void Tokenizer::simplifyAsm() Token *endasm = tok->next(); const Token *firstSemiColon = nullptr; int comment = 0; - while (Token::Match(endasm, "%num%|%name%|,|:|;") || (endasm && (endasm->isLiteral() || endasm->linenr() == comment))) { + while (Token::Match(endasm, "%num%|%name%|,|:|;|*|(") || (endasm && (endasm->isLiteral() || endasm->linenr() == comment))) { if (Token::Match(endasm, "_asm|__asm|__endasm")) break; if (endasm->str() == ";") { @@ -9910,6 +9910,11 @@ void Tokenizer::simplifyAsm() if (!firstSemiColon) firstSemiColon = endasm; } + if (endasm->str() == "(") { + if (!firstSemiColon) + endasm = endasm->link(); + break; + } endasm = endasm->next(); } if (Token::simpleMatch(endasm, "__endasm")) { @@ -9920,6 +9925,12 @@ void Tokenizer::simplifyAsm() } else if (firstSemiColon) { instruction = tok->next()->stringifyList(firstSemiColon); Token::eraseTokens(tok, firstSemiColon); + } else if (Token::Match(endasm, ") { !!}")) { + tok->deleteThis(); + tok = endasm->tokAt(2); + endasm = endasm->linkAt(1); + instruction = tok->stringifyList(endasm); + Token::eraseTokens(tok, endasm); } else if (!endasm) { instruction = tok->next()->stringifyList(endasm); Token::eraseTokens(tok, endasm); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b4f075e5749..17ab380bb49 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -1116,6 +1116,15 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS(";\n\nasm ( \"\"mov ax,bx\"\" ) ;", tokenizeAndStringify(";\n\n__asm__ volatile ( \"mov ax,bx\" );")); ASSERT_EQUALS("void func1 ( ) ;", tokenizeAndStringify("void func1() __asm__(\"...\") __attribute__();")); + + // #14250 - assembler function + const char code[] = "__asm void dostuff(uint32_t x) { " + "%reg x " + " e_lis r7, (lf)@h " + "%error " + "}"; + ASSERT_EQUALS("void dostuff ( uint32_t x ) { asm ( \"% reg x e_lis r7 , ( lf ) @ h % error\" ) ; }", + tokenizeAndStringify(code)); } // #4725 - ^{}