Skip to content

Commit 900148c

Browse files
authored
Fix #14250 (syntax error reported for assembler code) (danmar#7947)
1 parent 1f35303 commit 900148c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/tokenize.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9902,14 +9902,19 @@ void Tokenizer::simplifyAsm()
99029902
Token *endasm = tok->next();
99039903
const Token *firstSemiColon = nullptr;
99049904
int comment = 0;
9905-
while (Token::Match(endasm, "%num%|%name%|,|:|;") || (endasm && (endasm->isLiteral() || endasm->linenr() == comment))) {
9905+
while (Token::Match(endasm, "%num%|%name%|,|:|;|*|(") || (endasm && (endasm->isLiteral() || endasm->linenr() == comment))) {
99069906
if (Token::Match(endasm, "_asm|__asm|__endasm"))
99079907
break;
99089908
if (endasm->str() == ";") {
99099909
comment = endasm->linenr();
99109910
if (!firstSemiColon)
99119911
firstSemiColon = endasm;
99129912
}
9913+
if (endasm->str() == "(") {
9914+
if (!firstSemiColon)
9915+
endasm = endasm->link();
9916+
break;
9917+
}
99139918
endasm = endasm->next();
99149919
}
99159920
if (Token::simpleMatch(endasm, "__endasm")) {
@@ -9920,6 +9925,12 @@ void Tokenizer::simplifyAsm()
99209925
} else if (firstSemiColon) {
99219926
instruction = tok->next()->stringifyList(firstSemiColon);
99229927
Token::eraseTokens(tok, firstSemiColon);
9928+
} else if (Token::Match(endasm, ") { !!}")) {
9929+
tok->deleteThis();
9930+
tok = endasm->tokAt(2);
9931+
endasm = endasm->linkAt(1);
9932+
instruction = tok->stringifyList(endasm);
9933+
Token::eraseTokens(tok, endasm);
99239934
} else if (!endasm) {
99249935
instruction = tok->next()->stringifyList(endasm);
99259936
Token::eraseTokens(tok, endasm);

test/testtokenize.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,15 @@ class TestTokenizer : public TestFixture {
11161116
ASSERT_EQUALS(";\n\nasm ( \"\"mov ax,bx\"\" ) ;", tokenizeAndStringify(";\n\n__asm__ volatile ( \"mov ax,bx\" );"));
11171117

11181118
ASSERT_EQUALS("void func1 ( ) ;", tokenizeAndStringify("void func1() __asm__(\"...\") __attribute__();"));
1119+
1120+
// #14250 - assembler function
1121+
const char code[] = "__asm void dostuff(uint32_t x) { "
1122+
"%reg x "
1123+
" e_lis r7, (lf)@h "
1124+
"%error "
1125+
"}";
1126+
ASSERT_EQUALS("void dostuff ( uint32_t x ) { asm ( \"% reg x e_lis r7 , ( lf ) @ h % error\" ) ; }",
1127+
tokenizeAndStringify(code));
11191128
}
11201129

11211130
// #4725 - ^{}

0 commit comments

Comments
 (0)