Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9902,14 +9902,19 @@ 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() == ";") {
comment = endasm->linenr();
if (!firstSemiColon)
firstSemiColon = endasm;
}
if (endasm->str() == "(") {
if (!firstSemiColon)
endasm = endasm->link();
break;
}
endasm = endasm->next();
}
if (Token::simpleMatch(endasm, "__endasm")) {
Expand All @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 - ^{}
Expand Down