[PATCH] D20144: Fix constant folding of addrspacecast

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Fri May 20 14:34:09 PDT 2016


majnemer added inline comments.

================
Comment at: lib/Analysis/ConstantFolding.cpp:1232-1246
@@ -1226,2 +1231,17 @@
       return ConstantExpr::getCast(Opcode, C, DestTy);
+  case Instruction::AddrSpaceCast: {
+    if (isa<UndefValue>(C))
+      return UndefValue::get(DestTy);
+
+    // It is up to the target for how to constant fold immediates.
+    if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
+      if (CE->getOpcode() == Instruction::IntToPtr)
+        return nullptr;
+
+      if (auto *NewCE = ConstantFoldConstantExpression(CE, DL, nullptr))
+        return ConstantExpr::getAddrSpaceCast(NewCE, DestTy);
+    }
+
+    return nullptr;
+  }
   case Instruction::BitCast:
----------------
This is suspicious to me.  It implies that performing a `ConstantExpr::getCast(Instruction::AddrSpaceCast)` on an `IntToPtr` does the wrong thing and suggests to me that the bug lies elsewhere.


http://reviews.llvm.org/D20144





More information about the llvm-commits mailing list