[clang] [CIR][SPIR-V] Emit non-generic null pointers via generic null cast (PR #228559)

Steffen Larsen via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 5 23:24:59 PDT 2026


================
@@ -54,10 +54,41 @@ class CommonSPIRTargetCIRGenInfo : public TargetCIRGenInfo {
       ft = getABIInfo().cgt.getASTContext().adjustFunctionType(
           ft, ft->getExtInfo().withCallingConv(CC_DeviceKernel));
   }
+
+  mlir::Value getNullPointer(CIRGenModule &cgm, cir::PointerType ptrTy,
+                             QualType qt, mlir::Location loc) const override;
 };
 
 } // namespace
 
+// The bit pattern of null in non-generic AS is unspecified for SPIR(-V), so
+// materialize it via an address space cast from null in generic AS.
+mlir::Value
+CommonSPIRTargetCIRGenInfo::getNullPointer(CIRGenModule &cgm,
+                                           cir::PointerType ptrTy, QualType qt,
+                                           mlir::Location loc) const {
+  LangAS as = qt->getUnqualifiedDesugaredType()->isNullPtrType()
+                  ? LangAS::Default
+                  : qt->getPointeeType().getAddressSpace();
+  unsigned asAsInt = static_cast<unsigned>(as);
+  unsigned firstTargetASAsInt =
+      static_cast<unsigned>(LangAS::FirstTargetAddressSpace);
+  unsigned codeSectionINTELAS = firstTargetASAsInt + 9;
----------------
steffenlarsen wrote:

At least the `constexpr` tells a more of a story. Thanks!

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


More information about the cfe-commits mailing list