[clang] [clang][ExprConst] Consider integer pointers of value 0 nullptr (PR #150164)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 24 12:37:54 PDT 2025


================
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple amdgcn -cl-std=clc++ -verify %s
+
+// expected-no-diagnostics
+
+#define fold(x) (__builtin_constant_p(x) ? (x) : (x))
+static_assert(nullptr != fold(reinterpret_cast<private int*>(0)));
+
+static_assert(nullptr == (private int *)0);
+
----------------
zygoloid wrote:

Yeah, it's weird, but that's just how C++ is: converting a null pointer constant to pointer type is a completely different operation from reinterpreting an integer value (that happens to be 0) as a pointer value.

Similar weirdness would happen in C for this target:
```c
private int *p = (private int*)0; // null pointer.
intptr_t n = 0;
private int *q = (private int*)n; // not a null pointer.
intptr_t m = -1;
private int *r = (private int*)m; // null pointer.
```

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


More information about the cfe-commits mailing list