[go: nahoru, domu]

Skip to content

Commit

Permalink
Revert "[MCAsmParser] .rept/.irp/.irpc: remove excess tail EOL in exp…
Browse files Browse the repository at this point in the history
…ansion"

This reverts commit c6e787f.

parseEOL() would remove \n # after .endr, not recognizing the line marker.

```
// reduced from Linux kernel arch/x86/crypto/sha1_avx2_x86_64_asm.S
.rept 1
nop
.endr
# 512 "a.s"
```
  • Loading branch information
MaskRay committed May 17, 2024
1 parent 48b23c0 commit 1e5f29a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
31 changes: 19 additions & 12 deletions llvm/lib/MC/MCParser/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5624,20 +5624,27 @@ MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) {
return nullptr;
}

if (Lexer.is(AsmToken::Identifier)) {
StringRef Ident = getTok().getIdentifier();
if (Ident == ".rep" || Ident == ".rept" || Ident == ".irp" ||
Ident == ".irpc") {
++NestLevel;
} else if (Ident == ".endr") {
if (NestLevel == 0) {
EndToken = getTok();
Lex();
if (!parseEOL())
break;
if (Lexer.is(AsmToken::Identifier) &&
(getTok().getIdentifier() == ".rep" ||
getTok().getIdentifier() == ".rept" ||
getTok().getIdentifier() == ".irp" ||
getTok().getIdentifier() == ".irpc")) {
++NestLevel;
}

// Otherwise, check whether we have reached the .endr.
if (Lexer.is(AsmToken::Identifier) && getTok().getIdentifier() == ".endr") {
if (NestLevel == 0) {
EndToken = getTok();
Lex();
if (Lexer.isNot(AsmToken::EndOfStatement)) {
printError(getTok().getLoc(),
"unexpected token in '.endr' directive");
return nullptr;
}
--NestLevel;
break;
}
--NestLevel;
}

// Otherwise, scan till the end of the statement.
Expand Down
14 changes: 7 additions & 7 deletions llvm/test/MC/AsmParser/macro-rept.s
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
// CHECK: .long 1
// CHECK: .long 1

// CHECK: .long 0
// CHECK-NEXT: .long 0
// CHECK-NEXT: .long 0
// CHECK-NEXT: .long 0
// CHECK-NEXT: .long 0
// CHECK-NEXT: .long 0
// CHECK-EMPTY:
// CHECK: .long 0
// CHECK: .long 0
// CHECK: .long 0

// CHECK: .long 0
// CHECK: .long 0
// CHECK: .long 0

0 comments on commit 1e5f29a

Please sign in to comment.