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

Shilei Tian via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 13 20:51:59 PST 2026


================
@@ -84,6 +84,11 @@ class DataLayout {
     /// for additional metadata (e.g. AMDGPU buffer fat pointers with bounds
     /// and other flags or CHERI capabilities that contain bounds+permissions).
     uint32_t IndexBitWidth;
+    /// The value of the nullptr in this address space. It can be three values:
+    /// all-zeros, all-ones, or std::nullopt. Since we don't have a way to
+    /// represent an arbitrary bit pattern, we use std::nullopt to represent the
+    /// case where the nullptr value is neither 0 nor -1.
+    std::optional<APInt> NullPtrValue;
----------------
shiltian wrote:

It is because we can't assume the size of the pointer, even though they are `0U` or `~0U`. This function can just return a `std::optional<bool>`, where `true` means `~0U`, and `false` means `0U`, but is that a good design?

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


More information about the llvm-commits mailing list