Skip to content

Commit c6e787f

Browse files
committed
[MCAsmParser] .rept/.irp/.irpc: remove excess tail EOL in expansion
``` .irp foo,1 nop .endr nop ``` expands to an excess EOL between two nop lines. Remove the excess EOL.
1 parent 772b1b0 commit c6e787f

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5629,27 +5629,20 @@ MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) {
56295629
return nullptr;
56305630
}
56315631

5632-
if (Lexer.is(AsmToken::Identifier) &&
5633-
(getTok().getIdentifier() == ".rep" ||
5634-
getTok().getIdentifier() == ".rept" ||
5635-
getTok().getIdentifier() == ".irp" ||
5636-
getTok().getIdentifier() == ".irpc")) {
5637-
++NestLevel;
5638-
}
5639-
5640-
// Otherwise, check whether we have reached the .endr.
5641-
if (Lexer.is(AsmToken::Identifier) && getTok().getIdentifier() == ".endr") {
5642-
if (NestLevel == 0) {
5643-
EndToken = getTok();
5644-
Lex();
5645-
if (Lexer.isNot(AsmToken::EndOfStatement)) {
5646-
printError(getTok().getLoc(),
5647-
"unexpected token in '.endr' directive");
5648-
return nullptr;
5632+
if (Lexer.is(AsmToken::Identifier)) {
5633+
StringRef Ident = getTok().getIdentifier();
5634+
if (Ident == ".rep" || Ident == ".rept" || Ident == ".irp" ||
5635+
Ident == ".irpc") {
5636+
++NestLevel;
5637+
} else if (Ident == ".endr") {
5638+
if (NestLevel == 0) {
5639+
EndToken = getTok();
5640+
Lex();
5641+
if (!parseEOL())
5642+
break;
56495643
}
5650-
break;
5644+
--NestLevel;
56515645
}
5652-
--NestLevel;
56535646
}
56545647

56555648
// Otherwise, scan till the end of the statement.

llvm/test/MC/AsmParser/macro-rept.s

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
// CHECK: .long 1
1414
// CHECK: .long 1
1515

16-
// CHECK: .long 0
17-
// CHECK: .long 0
18-
// CHECK: .long 0
19-
20-
// CHECK: .long 0
21-
// CHECK: .long 0
22-
// CHECK: .long 0
16+
// CHECK: .long 0
17+
// CHECK-NEXT: .long 0
18+
// CHECK-NEXT: .long 0
19+
// CHECK-NEXT: .long 0
20+
// CHECK-NEXT: .long 0
21+
// CHECK-NEXT: .long 0
22+
// CHECK-EMPTY:

0 commit comments

Comments
 (0)