ConstantFoldConstantExpression can theoretically return the original
authorDan Gohman <gohman@apple.com>
Mon, 8 Feb 2010 22:19:11 +0000 (22:19 +0000)
committerDan Gohman <gohman@apple.com>
Mon, 8 Feb 2010 22:19:11 +0000 (22:19 +0000)
expression; don't go into an infinite loop if it does.

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

lib/CodeGen/AsmPrinter/AsmPrinter.cpp

index 5f730e03c6f5181a4fa839c81d27c5d34a943126..2fbd8dc098a80dcc59e684aa5f64472f82edf787 100644 (file)
@@ -892,8 +892,10 @@ static const MCExpr *LowerConstant(const Constant *CV, AsmPrinter &AP) {
     // If the code isn't optimized, there may be outstanding folding
     // opportunities. Attempt to fold the expression using TargetData as a
     // last resort before giving up.
-    if (Constant *C = ConstantFoldConstantExpression(CE, AP.TM.getTargetData()))
-      return LowerConstant(C, AP);
+    if (Constant *C =
+          ConstantFoldConstantExpression(CE, AP.TM.getTargetData()))
+      if (C != CE)
+        return LowerConstant(C, AP);
 #ifndef NDEBUG
     CE->dump();
 #endif