[PATCH] D72686: [AsmParser] Make generic directives and aliases case insensitive.

David Spickett via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 17 01:39:26 PST 2020


DavidSpickett updated this revision to Diff 238716.
DavidSpickett retitled this revision from "[AsmParser] Make directives case insensitive." to "[AsmParser] Make generic directives and aliases case insensitive.".
DavidSpickett edited the summary of this revision.
DavidSpickett added a comment.

Added a comment to init directive map saying that they should all be lower case.
Switched to a generic x86 target and alias for the lit test, to match the other MC/AsmParser tests.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72686/new/

https://reviews.llvm.org/D72686

Files:
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/test/MC/AsmParser/directive_case_insensitive.s


Index: llvm/test/MC/AsmParser/directive_case_insensitive.s
===================================================================
--- /dev/null
+++ llvm/test/MC/AsmParser/directive_case_insensitive.s
@@ -0,0 +1,16 @@
+# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
+
+# CHECK: .byte 65
+        .ascii "A"
+# CHECK: .byte 66
+        .ASCII "B"
+# CHECK: .byte 67
+        .aScIi "C"
+
+# Note: using 2byte because it is an alias
+# CHECK: .short 4660
+        .2byte 0x1234
+# CHECK: .short 4661
+        .2BYTE 0x1235
+# CHECK: .short 4662
+        .2bYtE 0x1236
Index: llvm/lib/MC/MCParser/AsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/AsmParser.cpp
+++ llvm/lib/MC/MCParser/AsmParser.cpp
@@ -199,7 +199,7 @@
   }
 
   void addAliasForDirective(StringRef Directive, StringRef Alias) override {
-    DirectiveKindMap[Directive] = DirectiveKindMap[Alias];
+    DirectiveKindMap[Directive.lower()] = DirectiveKindMap[Alias.lower()];
   }
 
   /// @name MCAsmParser Interface
@@ -1750,7 +1750,7 @@
   // have to do this so that .endif isn't skipped in a ".if 0" block for
   // example.
   StringMap<DirectiveKind>::const_iterator DirKindIt =
-      DirectiveKindMap.find(IDVal);
+      DirectiveKindMap.find(IDVal.lower());
   DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
 
                               ? DK_NO_DIRECTIVE
@@ -5320,6 +5320,12 @@
 }
 
 void AsmParser::initializeDirectiveKindMap() {
+  /* Lookup will be done with the directive
+   * converted to lower case, so all these
+   * keys should be lower case.
+   * (target specific directives are handled
+   *  elsewhere)
+   */
   DirectiveKindMap[".set"] = DK_SET;
   DirectiveKindMap[".equ"] = DK_EQU;
   DirectiveKindMap[".equiv"] = DK_EQUIV;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72686.238716.patch
Type: text/x-patch
Size: 1800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200117/b3ef96d9/attachment.bin>


More information about the llvm-commits mailing list