[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
Thu Nov 6 11:20:20 PST 2025


================
@@ -126,6 +126,16 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
   if (isa<PoisonValue>(V))
     return PoisonValue::get(DestTy);
 
+  // TODO: For the following two cases, we can fold the constant to a constant
+  // according to the data layout.
+
+  // We can't fold inttoptr(0) to ConstantNullPointer.
+  if (opc == Instruction::IntToPtr && V->isZeroValue())
+    return nullptr;
+  // We can't fold ptrtoint(nullptr) to null.
----------------
arichardson wrote:

```suggestion
  // We can't fold ptrtoint(nullptr) to zero without DataLayout.
```

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


More information about the llvm-commits mailing list