[llvm-commits] [llvm] r122008 - /llvm/trunk/lib/MC/MCExpr.cpp

Daniel Dunbar daniel at zuster.org
Thu Dec 16 17:07:20 PST 2010


Author: ddunbar
Date: Thu Dec 16 19:07:20 2010
New Revision: 122008

URL: http://llvm.org/viewvc/llvm-project?rev=122008&view=rev
Log:
MC/Expr: Simplify (and add a FIXME).

Modified:
    llvm/trunk/lib/MC/MCExpr.cpp

Modified: llvm/trunk/lib/MC/MCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExpr.cpp?rev=122008&r1=122007&r2=122008&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCExpr.cpp (original)
+++ llvm/trunk/lib/MC/MCExpr.cpp Thu Dec 16 19:07:20 2010
@@ -311,13 +311,21 @@
                                 const MCValue &LHS,const MCSymbolRefExpr *RHS_A,
                                 const MCSymbolRefExpr *RHS_B, int64_t RHS_Cst,
                                 MCValue &Res) {
-  // We can't add or subtract two symbols.
-  if ((LHS.getSymA() && RHS_A) ||
-      (LHS.getSymB() && RHS_B))
+  // FIXME: This routine (and other evaluation parts) are *incredibly* sloppy
+  // about dealing with modifiers. This will ultimately bite us, one day.
+  const MCSymbolRefExpr *LHS_A = LHS.getSymA();
+  const MCSymbolRefExpr *LHS_B = LHS.getSymB();
+  int64_t LHS_Cst = LHS.getConstant();
+
+  // Fold the result constant immediately.
+  int64_t Result_Cst = LHS_Cst + RHS_Cst;
+
+  // We can't represent the addition or subtraction of two symbols.
+  if ((LHS_A && RHS_A) || (LHS_B && RHS_B))
     return false;
 
-  const MCSymbolRefExpr *A = LHS.getSymA() ? LHS.getSymA() : RHS_A;
-  const MCSymbolRefExpr *B = LHS.getSymB() ? LHS.getSymB() : RHS_B;
+  const MCSymbolRefExpr *A = LHS_A ? LHS_A : RHS_A;
+  const MCSymbolRefExpr *B = LHS_B ? LHS_B : RHS_B;
   if (B) {
     // If we have a negated symbol, then we must have also have a non-negated
     // symbol in order to encode the expression. We can do this check later to
@@ -343,8 +351,7 @@
       if (AD.getFragment() == BD.getFragment()) {
         Res = MCValue::get(+ AD.getOffset()
                            - BD.getOffset()
-                           + LHS.getConstant()
-                           + RHS_Cst);
+                           + Result_Cst);
         return true;
       }
 
@@ -353,8 +360,7 @@
         const MCSectionData &SecB = *BD.getFragment()->getParent();
         int64_t Val = + Layout->getSymbolOffset(&AD)
                       - Layout->getSymbolOffset(&BD)
-                      + LHS.getConstant()
-                      + RHS_Cst;
+                      + Result_Cst;
         if (&SecA != &SecB) {
           if (!Addrs)
             return false;
@@ -367,7 +373,7 @@
     }
   }
 
-  Res = MCValue::get(A, B, LHS.getConstant() + RHS_Cst);
+  Res = MCValue::get(A, B, Result_Cst);
   return true;
 }
 





More information about the llvm-commits mailing list