ms-inline-asm: Fix parsing label names inside bracket expressions
authorEhsan Akhgari <ehsan.akhgari@gmail.com>
Mon, 22 Sep 2014 20:40:36 +0000 (20:40 +0000)
committerEhsan Akhgari <ehsan.akhgari@gmail.com>
Mon, 22 Sep 2014 20:40:36 +0000 (20:40 +0000)
Summary:
This fixes a couple of issues.  One is ensuring that AOK_Label rewrite
rules have a lower priority than AOK_Skip rules, as AOK_Skip needs to
be able to skip the brackets properly.  The other part of the fix ensures
that we don't overwrite Identifier when looking up the identifier, and
that we use the locally available information to generate the AOK_Label
rewrite in ParseIntelIdentifier.  Doing that in CreateMemForInlineAsm
would be problematic since the Start location there may point to the
beginning of a bracket expression, and not necessarily the beginning of
an identifier.

This also means that we don't need to carry around the InternlName field,
which helps simplify the code.

Test Plan: This will be tested on the clang side.

Reviewers: rnk

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D5445

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218270 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCParser/MCAsmParser.h
include/llvm/MC/MCTargetAsmParser.h
lib/Target/X86/AsmParser/X86AsmParser.cpp

index ffe89e6fa1cf152b83cac7f1ccfa8a4ea72bd5b1..bfcb5cd625973b5b90e88a7357e56c627547f1bd 100644 (file)
@@ -35,7 +35,6 @@ public:
   void *OpDecl;
   bool IsVarDecl;
   unsigned Length, Size, Type;
-  StringRef InternalName;
 
   void clear() {
     OpDecl = nullptr;
@@ -43,7 +42,6 @@ public:
     Length = 1;
     Size = 0;
     Type = 0;
-    InternalName = "";
   }
 };
 
index 80bf7dc4de0e00f861213dc4ef2e779bcf598081..cf9230758f2f278f07340faca85e135af211f080 100644 (file)
@@ -44,16 +44,16 @@ enum AsmRewriteKind {
 
 const char AsmRewritePrecedence [] = {
   0, // AOK_Delete
-  1, // AOK_Align
-  1, // AOK_DotOperator
-  1, // AOK_Emit
-  3, // AOK_Imm
-  3, // AOK_ImmPrefix
-  2, // AOK_Input
-  2, // AOK_Output
-  4, // AOK_SizeDirective
+  2, // AOK_Align
+  2, // AOK_DotOperator
+  2, // AOK_Emit
+  4, // AOK_Imm
+  4, // AOK_ImmPrefix
+  3, // AOK_Input
+  3, // AOK_Output
+  5, // AOK_SizeDirective
   1, // AOK_Label
-  1  // AOK_Skip
+  2  // AOK_Skip
 };
 
 struct AsmRewrite {
index 8fec1c3a49dfcb0e874fe2c6fd28f263258228d3..519ada2b4b9498217f6e0dcebc5c67e2b4c498a9 100644 (file)
@@ -1047,12 +1047,6 @@ std::unique_ptr<X86Operand> X86AsmParser::CreateMemForInlineAsm(
         InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_SizeDirective, Start,
                                                     /*Len=*/0, Size));
     }
-    if (!Info.InternalName.empty()) {
-      // Push a rewrite for replacing the identifier name with the internal name.
-      InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_Label, Start,
-                                                  End.getPointer() - Start.getPointer(),
-                                                  Info.InternalName));
-    }
   }
 
   // When parsing inline assembly we set the base register to a non-zero value
@@ -1347,9 +1341,14 @@ bool X86AsmParser::ParseIntelIdentifier(const MCExpr *&Val,
   // If the identifier lookup was unsuccessful, assume that we are dealing with
   // a label.
   if (!Result) {
-    Identifier = SemaCallback->LookupInlineAsmLabel(Identifier, getSourceManager(), Loc, false);
-    assert(Identifier.size() && "We should have an internal name here.");
-    Info.InternalName = Identifier;
+    StringRef InternalName =
+      SemaCallback->LookupInlineAsmLabel(Identifier, getSourceManager(),
+                                         Loc, false);
+    assert(InternalName.size() && "We should have an internal name here.");
+    // Push a rewrite for replacing the identifier name with the internal name.
+    InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_Label, Loc,
+                                                Identifier.size(),
+                                                InternalName));
   }
 
   // Create the symbol reference.