[llvm] r308866 - [X86][InlineAsm][Ms Compatibility]Prefer variable name over a register when the two collides

Coby Tayree via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 24 00:04:55 PDT 2017


Author: coby
Date: Mon Jul 24 00:04:55 2017
New Revision: 308866

URL: http://llvm.org/viewvc/llvm-project?rev=308866&view=rev
Log:
[X86][InlineAsm][Ms Compatibility]Prefer variable name over a register when the two collides

On MS-style, the following snippet:

int eax;
__asm mov eax, ebx

should yield loading of ebx, into the location pointed by the variable eax

This patch sees to it.

Currently, a reg-to-reg move would have been invoked.

clang: D34740

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


Modified:
    llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp

Modified: llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp?rev=308866&r1=308865&r2=308866&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp Mon Jul 24 00:04:55 2017
@@ -944,7 +944,8 @@ bool X86AsmParser::ParseRegister(unsigne
   EndLoc = Tok.getEndLoc();
 
   if (Tok.isNot(AsmToken::Identifier)) {
-    if (isParsingIntelSyntax()) return true;
+    if (isParsingIntelSyntax())
+      return true;
     return Error(StartLoc, "invalid register name",
                  SMRange(StartLoc, EndLoc));
   }
@@ -955,6 +956,16 @@ bool X86AsmParser::ParseRegister(unsigne
   if (RegNo == 0)
     RegNo = MatchRegisterName(Tok.getString().lower());
 
+  // In MS inline-asm we allow variables to be named as registers, and
+  // give them precedence over actual registers
+  // However - we require the match to be case sensitive
+  if (isParsingInlineAsm() && isParsingIntelSyntax() && RegNo) {
+    StringRef LineBuf(Tok.getIdentifier().data());
+    InlineAsmIdentifierInfo Info;
+    if (SemaCallback->LookupInlineAsmIdentifier(LineBuf, Info, false))
+      return true;
+  }
+
   // The "flags" register cannot be referenced directly.
   // Treat it as an identifier instead.
   if (isParsingInlineAsm() && isParsingIntelSyntax() && RegNo == X86::EFLAGS)




More information about the llvm-commits mailing list