[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:07 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:

```suggestion
    // Note: We can't fold inttoptr(0) to ConstantPointerNull without checking
    // the target data layout since null pointers could also be all-ones.
```
I don't think we need the early return here? Although I guess it's a cheap check and so might actually be better to have it.

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


More information about the llvm-commits mailing list