================
@@ -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:

> Hm, seems like getNullPointerValue should be able to fail. My main worry here 
> is special casing generic address space, as opposed to default address space

thanks @arsenm, you're right that the default AS is not checked.

I copied the logic from ASTContext::getTargetNullPointerValue into 
CommonSPIRTargetCodeGenInfo::getNullPointer in 
5c5e13ee5e95791c9795714fec01efbe92dbecd4 to avoid changing return type of both 
getNullPointerValue and getTargetNullPointerValue to std::optional<uint64_t>. 
Since getTargetNullPointerValue is used in many places, changing its return 
type looks like unnecessary churn. 

https://github.com/llvm/llvm-project/pull/161773
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to