[llvm] e9f6dea - [MCAsmParser] .irpc: correctly handle quoted string

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 13 19:22:37 PDT 2024


Author: Fangrui Song
Date: 2024-08-13T19:22:31-07:00
New Revision: e9f6deaa8fd8ca3247c79f962aed335ada99cd66

URL: https://github.com/llvm/llvm-project/commit/e9f6deaa8fd8ca3247c79f962aed335ada99cd66
DIFF: https://github.com/llvm/llvm-project/commit/e9f6deaa8fd8ca3247c79f962aed335ada99cd66.diff

LOG: [MCAsmParser] .irpc: correctly handle quoted string

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.

Added: 
    

Modified: 
    llvm/lib/MC/MCParser/AsmParser.cpp
    llvm/test/MC/AsmParser/macro-irpc.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 1b9c624136e8bb..af09f2a0ee0cd4 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -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));

diff  --git a/llvm/test/MC/AsmParser/macro-irpc.s b/llvm/test/MC/AsmParser/macro-irpc.s
index d39399b131f70d..c25065bfce17a6 100644
--- a/llvm/test/MC/AsmParser/macro-irpc.s
+++ b/llvm/test/MC/AsmParser/macro-irpc.s
@@ -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


        


More information about the llvm-commits mailing list