[llvm] [DataLayout] Add isNullPointerAllZeroes (PR #165314)

Alexander Richardson via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 27 14:05:20 PDT 2025


================
@@ -398,6 +398,12 @@ class DataLayout {
            PS.HasExternalState;
   }
 
+  /// Returns if the null pointer for this address space has an all-zero bit
+  /// representation.
+  bool isNullPointerAllZeroes(unsigned AddrSpace) const {
+    return AddrSpace == 0;
+  }
----------------
arichardson wrote:

Your suggestion of getNullPointerValue() is probably better, could do something like the following?

```suggestion
  std::optional<APInt> getNullPointerValue(unsigned AS) const {
    // Address space zero is currently defined to always have
    // a all-zero null pointer representation, the others are
    // target-specific and will require a data layout property.
    // See https://discourse.llvm.org/t/rfc-introduce-sentinel-pointer-value-to-datalayout
    if (AS == 0)
      return 0;
    return std::nullopt;
  }
```

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


More information about the llvm-commits mailing list