Reapply r179115, but use parsePrimaryExpression a little more judiciously.
authorChad Rosier <mcrosier@apple.com>
Wed, 10 Apr 2013 17:35:30 +0000 (17:35 +0000)
committerChad Rosier <mcrosier@apple.com>
Wed, 10 Apr 2013 17:35:30 +0000 (17:35 +0000)
Test cases that regressed due to r179115, plus a few more, were added in
r179182.  Original commit message below:

[ms-inline asm] Use parsePrimaryExpr in lieu of parseExpression if we need to
parse an identifier.  Otherwise, parseExpression may parse multiple tokens,
which makes it impossible to properly compute an immediate displacement.
An example of such a case is the source operand (i.e., [Symbol + ImmDisp]) in
the below example:

 __asm mov eax, [Symbol + ImmDisp]

Part of rdar://13611297

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

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

index d7e3902ac478d0e6ac8fc5d5871fbf0d2aecefc3..601f8f7734b42efa6cf3cb648663455ba0886240 100644 (file)
@@ -151,6 +151,13 @@ public:
   virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
   bool parseExpression(const MCExpr *&Res);
 
+  /// parsePrimaryExpr - Parse a primary expression.
+  ///
+  /// @param Res - The value of the expression. The result is undefined
+  /// on error.
+  /// @result - False on success.
+  virtual bool parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) = 0;
+
   /// parseParenExpression - Parse an arbitrary expression, assuming that an
   /// initial '(' has already been consumed.
   ///
index 14577f79beedf983d21de486cf017bebf19ed6f6..c50177cb0a41dbeff96cb61a702732cb16c7a3e6 100644 (file)
@@ -221,6 +221,7 @@ public:
 
   bool parseExpression(const MCExpr *&Res);
   virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc);
+  virtual bool parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc);
   virtual bool parseParenExpression(const MCExpr *&Res, SMLoc &EndLoc);
   virtual bool parseAbsoluteExpression(int64_t &Res);
 
@@ -869,6 +870,10 @@ bool AsmParser::parseExpression(const MCExpr *&Res) {
   return parseExpression(Res, EndLoc);
 }
 
+bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) {
+  return ParsePrimaryExpr(Res, EndLoc);
+}
+
 const MCExpr *
 AsmParser::ApplyModifierToExpr(const MCExpr *E,
                                MCSymbolRefExpr::VariantKind Variant) {
index 60a02702eb712bd1889398af4707d9ef2639dc6f..ba19a9bcdb4f4d2fcb94f4fa5b938310c8856fe4 100644 (file)
@@ -1182,7 +1182,7 @@ X86Operand *X86AsmParser::ParseIntelBracExpression(unsigned SegReg,
         SM.onRegister(TmpReg);
         UpdateLocLex = false;
         break;
-      } else if (!getParser().parseExpression(Disp, End)) {
+      } else if (!getParser().parsePrimaryExpr(Disp, End)) {
         SM.onDispExpr();
         UpdateLocLex = false;
         break;
@@ -1401,7 +1401,7 @@ X86Operand *X86AsmParser::ParseIntelOffsetOfOperator() {
 
   const MCExpr *Val;
   SMLoc Start = Tok.getLoc(), End;
-  if (getParser().parseExpression(Val, End))
+  if (getParser().parsePrimaryExpr(Val, End))
     return ErrorOperand(Start, "Unable to parse expression!");
 
   // Don't emit the offset operator.
@@ -1437,7 +1437,7 @@ X86Operand *X86AsmParser::ParseIntelOperator(unsigned OpKind) {
 
   const MCExpr *Val;
   SMLoc Start = Tok.getLoc(), End;
-  if (getParser().parseExpression(Val, End))
+  if (getParser().parsePrimaryExpr(Val, End))
     return 0;
 
   unsigned Length = 0, Size = 0, Type = 0;