[clang] [clang][SPIR][SPIRV] Materialize non-generic null pointers via addrspacecast (PR #161773)
Wenju He via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 3 01:02:28 PDT 2025
================
@@ -240,6 +243,27 @@ void CommonSPIRTargetCodeGenInfo::setOCLKernelStubCallingConvention(
FT, FT->getExtInfo().withCallingConv(CC_SpirFunction));
}
+// LLVM currently assumes a null pointer has the bit pattern 0, but some GPU
+// targets use a non-zero encoding for null in certain address spaces.
+// Because SPIR(-V) is a virtual target and the bit pattern of a non-generic
+// null is unspecified, materialize non-generic null via an addrspacecast from
+// the generic null.
+// This allows later lowering to substitute the target’s real sentinel value.
+llvm::Constant *
+CommonSPIRTargetCodeGenInfo::getNullPointer(const CodeGen::CodeGenModule &CGM,
----------------
wenju-he wrote:
> Can you directly copy the AMDGPU implementation, which checks against getTargetNullPointerValue
`getTargetNullPointerValue` requires defining getNullPointerValue in BaseSPIRTargetInfo, like https://github.com/llvm/llvm-project/blob/441f0c7c9a5e6ae18ecacb0dee4e32e037bf4b1c/clang/lib/Basic/Targets/AMDGPU.h#L424-L430
However, we don't know the return value of getNullPointerValue in BaseSPIRTargetInfo except for generic address space, right?
https://github.com/llvm/llvm-project/pull/161773
More information about the cfe-commits
mailing list