llvm-mc/x86: Fix bug in disambiguation of displacement operand, introduced by me
authorDaniel Dunbar <daniel@zuster.org>
Thu, 2 Jul 2009 02:09:07 +0000 (02:09 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 2 Jul 2009 02:09:07 +0000 (02:09 +0000)
(I think).
 - We weren't properly parsing the leading parenthesized expression in something
   like 'push (4)(%eax)'.

 - Added ParseParenRelocatableExpression to support this. I suspect we should
   just use lookahead, though.

 - Test case to follow.

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

tools/llvm-mc/AsmParser.cpp
tools/llvm-mc/AsmParser.h
tools/llvm-mc/MC-X86Specific.cpp

index 931e460ab16fc05d70b7ad57dcf1c2c60e8aeeb8..339a16db8c228aa046ed6761d235e65775a804fd 100644 (file)
@@ -167,6 +167,19 @@ bool AsmParser::ParseRelocatableExpression(MCValue &Res) {
   return false;
 }
 
+bool AsmParser::ParseParenRelocatableExpression(MCValue &Res) {
+  AsmExpr *Expr;
+  
+  SMLoc StartLoc = Lexer.getLoc();
+  if (ParseParenExpr(Expr))
+    return true;
+
+  if (!Expr->EvaluateAsRelocatable(Ctx, Res))
+    return Error(StartLoc, "expected relocatable expression");
+
+  return false;
+}
+
 static unsigned getBinOpPrecedence(asmtok::TokKind K, 
                                    AsmBinaryExpr::Opcode &Kind) {
   switch (K) {
index ae5c414c03d7b72962102e2b1b740582f9f4abea..333b284eac9119ab64522df4a91e80c81a3b581e 100644 (file)
@@ -73,6 +73,16 @@ private:
   /// @result - False on success.
   bool ParseRelocatableExpression(MCValue &Res);
 
+  /// ParseParenRelocatableExpression - Parse an expression which must be
+  /// relocatable, assuming that an initial '(' has already been consumed.
+  ///
+  /// @param Res - The relocatable expression value. The result is undefined on
+  /// error.  
+  /// @result - False on success.
+  ///
+  /// @see ParseRelocatableExpression, ParseParenExpr.
+  bool ParseParenRelocatableExpression(MCValue &Res);
+
   bool ParsePrimaryExpr(AsmExpr *&Res);
   bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
   bool ParseParenExpr(AsmExpr *&Res);
index 71d7080432444bd28500fa4e244bb338fd959f60..a1866186d7e06fa528460812ca165d675bfb18cb 100644 (file)
@@ -152,7 +152,7 @@ bool AsmParser::ParseX86MemOperand(X86Operand &Op) {
       // memory operand consumed.
     } else {
       // It must be an parenthesized expression, parse it now.
-      if (ParseRelocatableExpression(Disp))
+      if (ParseParenRelocatableExpression(Disp))
         return true;
       
       // After parsing the base expression we could either have a parenthesized