diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp --- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -34,6 +34,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/X86TargetParser.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -939,6 +940,7 @@ SMLoc End, unsigned Size, StringRef Identifier, const InlineAsmIdentifierInfo &Info); + bool parseDirectiveArch(); bool parseDirectiveEven(SMLoc L); bool ParseDirectiveCode(StringRef IDVal, SMLoc L); @@ -3973,6 +3975,8 @@ 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")) { @@ -4027,6 +4031,15 @@ return true; } +bool X86AsmParser::parseDirectiveArch() { + SMLoc Loc = getTok().getLoc(); + StringRef CPU = getParser().parseStringToEndOfStatement().trim(); + X86::CPUKind Kind = X86::parseArchX86(CPU); + if (Kind == X86::CK_None) + return Error(Loc, "unknown arch name"); + 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 --- /dev/null +++ b/llvm/test/MC/X86/directive-arch.s @@ -0,0 +1,11 @@ +## We currently parse but ignore .arch directives. +# RUN: llvm-mc -triple=x86_64 %s | FileCheck /dev/null --implicit-check-not=.arch +# RUN: not llvm-mc -triple=x86_64 --defsym=ERR=1 %s 2>&1 | FileCheck %s --check-prefix=ERR + +.arch i386 +retq + +.ifdef ERR +# ERR: {{.*}}.s:[[#@LINE+1]]:7: error: unknown arch name +.arch unknown +.endif