[clang] [lld] [llvm] [WIP][IR][Constants] Change the semantic of `ConstantPointerNull` to represent an actual `nullptr` instead of a zero-value pointer (PR #166667)

Alexander Richardson via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 17 10:42:08 PST 2025


================
@@ -126,6 +126,40 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
   if (isa<PoisonValue>(V))
     return PoisonValue::get(DestTy);
 
+  if (opc == Instruction::IntToPtr) {
+    // We can't fold inttoptr(0) to ConstantPointerNull without checking the
+    // target data layout. However, since data layout is not available here, we
+    // can't do this.
+    if (V->isZeroValue())
+      return nullptr;
----------------
arichardson wrote:

Ah is this because of the `V->isNullValue()` below? In that case let's keep it.

https://github.com/llvm/llvm-project/pull/166667


More information about the llvm-commits mailing list