[llvm-branch-commits] [llvm] 9dfeec8 - Reland "[AsmParser] make .ascii support spaces as separators"

Jian Cai via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 14 17:57:29 PST 2021


Author: Jian Cai
Date: 2021-01-14T17:51:47-08:00
New Revision: 9dfeec853008109b1cbe926c22675c96226040d9

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

LOG: Reland "[AsmParser] make .ascii support spaces as separators"

This relands commit e0963ae274be5b071d1e1b00f5e4e019483c09e9, which was
reverted on commit 82c4153e66fa284729da86a8d6c302d4b8cec86c due to a
test failure, which turned out to be a false positive.

Added: 
    

Modified: 
    llvm/lib/MC/MCParser/AsmParser.cpp
    llvm/test/MC/AsmParser/directive_ascii.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 42ac0b66ec2a..c5ff241ead74 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -3008,13 +3008,20 @@ bool AsmParser::parseAngleBracketString(std::string &Data) {
 }
 
 /// parseDirectiveAscii:
-///   ::= ( .ascii | .asciz | .string ) [ "string" ( , "string" )* ]
+//    ::= .ascii [ "string"+ ( , "string"+ )* ]
+///   ::= ( .asciz | .string ) [ "string" ( , "string" )* ]
 bool AsmParser::parseDirectiveAscii(StringRef IDVal, bool ZeroTerminated) {
   auto parseOp = [&]() -> bool {
     std::string Data;
-    if (checkForValidSection() || parseEscapedString(Data))
+    if (checkForValidSection())
       return true;
-    getStreamer().emitBytes(Data);
+    // Only support spaces as separators for .ascii directive for now. See the
+    // discusssion at https://reviews.llvm.org/D91460 for more details.
+    do {
+      if (parseEscapedString(Data))
+        return true;
+      getStreamer().emitBytes(Data);
+    } while (!ZeroTerminated && getTok().is(AsmToken::String));
     if (ZeroTerminated)
       getStreamer().emitBytes(StringRef("\0", 1));
     return false;

diff  --git a/llvm/test/MC/AsmParser/directive_ascii.s b/llvm/test/MC/AsmParser/directive_ascii.s
index ea988879819b..e34aa7a8a561 100644
--- a/llvm/test/MC/AsmParser/directive_ascii.s
+++ b/llvm/test/MC/AsmParser/directive_ascii.s
@@ -48,3 +48,11 @@ TEST6:
 TEST7:
         .ascii "\x64\Xa6B"
         .ascii "\xface\x0Fe"
+
+# CHECK-LABEL: TEST8:
+# CHECK-NEXT: .byte 65
+# CHECK-NEXT: .byte 66
+# CHECK-NEXT: .byte 67
+# CHECK-NEXT: .byte 68
+TEST8:
+        .ascii "A", "B" "C", "D"


        


More information about the llvm-branch-commits mailing list