Skip to content

Commit

Permalink
[MCAsmParser] .irpc: correctly handle quoted string
Browse files Browse the repository at this point in the history
The quotes should be stripped.

Improve the test to check all of Identifier, Integer, and String.

GNU assembler also supports `.irpc c,"" a` but there is no real world
use case. So don't implement it.
  • Loading branch information
MaskRay committed Aug 14, 2024
1 parent 5e231ff commit e9f6dea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion llvm/lib/MC/MCParser/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5780,7 +5780,8 @@ bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
SmallString<256> Buf;
raw_svector_ostream OS(Buf);

StringRef Values = A.front().front().getString();
StringRef Values = A[0][0].is(AsmToken::String) ? A[0][0].getStringContents()
: A[0][0].getString();
for (std::size_t I = 0, End = Values.size(); I != End; ++I) {
MCAsmMacroArgument Arg;
Arg.emplace_back(AsmToken::Identifier, Values.slice(I, I + 1));
Expand Down
10 changes: 9 additions & 1 deletion llvm/test/MC/AsmParser/macro-irpc.s
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
// RUN: llvm-mc -triple x86_64-unknown-unknown %s | FileCheck %s

.irpc foo,123
.irpc foo,"123"
.long \foo
.endr
.irpc foo,ab
.long 0x\foo
.endr
.irpc foo,""
.endr

// CHECK: long 1
// CHECK: long 2
// CHECK: long 3
// CHECK: long 10
// CHECK: long 11
// CHECK-NOT: long

.irpc foo,123
.irpc bar,45
Expand Down

0 comments on commit e9f6dea

Please sign in to comment.