[X86] Parse and ignore .arch directives
authorFangrui Song <maskray@google.com>
Thu, 30 Jul 2020 15:30:06 +0000 (08:30 -0700)
committerFangrui Song <maskray@google.com>
Thu, 30 Jul 2020 15:30:06 +0000 (08:30 -0700)
We parse .arch so that some `.arch i386; .code32` code can assemble. It seems
that X86AsmParser does not do a good job tracking what features are needed to
assemble instructions. GNU as's x86 port supports a very wide range of .arch
operands. Ignore the operand for now.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D84900

llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
llvm/test/MC/X86/directive-arch.s [new file with mode: 0644]

index a278c46..f527350 100644 (file)
@@ -937,6 +937,7 @@ private:
                           SMLoc End, unsigned Size, StringRef Identifier,
                           const InlineAsmIdentifierInfo &Info);
 
+  bool parseDirectiveArch();
   bool parseDirectiveEven(SMLoc L);
   bool ParseDirectiveCode(StringRef IDVal, SMLoc L);
 
@@ -3993,6 +3994,8 @@ bool X86AsmParser::OmitRegisterFromClobberLists(unsigned RegNo) {
 bool X86AsmParser::ParseDirective(AsmToken DirectiveID) {
   MCAsmParser &Parser = getParser();
   StringRef IDVal = DirectiveID.getIdentifier();
+  if (IDVal.startswith(".arch"))
+    return parseDirectiveArch();
   if (IDVal.startswith(".code"))
     return ParseDirectiveCode(IDVal, DirectiveID.getLoc());
   else if (IDVal.startswith(".att_syntax")) {
@@ -4047,6 +4050,12 @@ bool X86AsmParser::ParseDirective(AsmToken DirectiveID) {
   return true;
 }
 
+bool X86AsmParser::parseDirectiveArch() {
+  // Ignore .arch for now.
+  getParser().parseStringToEndOfStatement();
+  return false;
+}
+
 /// parseDirectiveEven
 ///  ::= .even
 bool X86AsmParser::parseDirectiveEven(SMLoc L) {
diff --git a/llvm/test/MC/X86/directive-arch.s b/llvm/test/MC/X86/directive-arch.s
new file mode 100644 (file)
index 0000000..5f148a2
--- /dev/null
@@ -0,0 +1,10 @@
+## We currently parse but ignore .arch directives.
+# RUN: llvm-mc -triple=x86_64 %s | FileCheck /dev/null --implicit-check-not=.arch
+
+.arch i286
+.arch generic32
+
+.arch .avx512vl
+.arch .noavx512bw
+.arch .nop
+.arch .sse4.2