Author: Arseniy Obolenskiy Date: 2026-10-02T13:03:27+02:00 New Revision: fe36d3fa8520adb7ce82ed06c5fd783691ed4995
URL: https://github.com/llvm/llvm-project/commit/fe36d3fa8520adb7ce82ed06c5fd783691ed4995 DIFF: https://github.com/llvm/llvm-project/commit/fe36d3fa8520adb7ce82ed06c5fd783691ed4995.diff LOG: [CIR] Convert null pointer constant types in target lowering (#228068) The pass converted the cir.const result type but not the type inside its `#cir.ptr` attribute, so the verifier rejected address-space null constants Added: Modified: clang/lib/CIR/Dialect/Transforms/TargetLowering.cpp clang/test/CIR/CodeGen/amdgpu-target-lowering-as.cpp clang/test/CIR/CodeGen/spirv-target-lowering-as.cpp Removed: ################################################################################ diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering.cpp index a34b4a00f36c2..769df5572f285 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering.cpp @@ -73,9 +73,9 @@ class CIRGenericTargetLoweringPattern : public mlir::ConversionPattern { mlir::OperationState loweredOpState(op->getLoc(), op->getName()); loweredOpState.addOperands(operands); - // Preserve auxiliary metadata verbatim. Convert only inherent TypeAttrs so - // address-space-bearing operation semantics (e.g. AllocaOp's allocaType) - // stay in sync with the converted result types. + // Preserve auxiliary metadata verbatim. Convert only inherent TypeAttrs and + // pointer constants so address-space-bearing operation semantics (e.g. + // AllocaOp's allocaType) stay in sync with the converted result types. loweredOpState.propertiesAttr = op->getPropertiesAsAttribute(); loweredOpState.addAttributes(op->getDiscardableAttrDictionary().getValue()); @@ -101,6 +101,10 @@ class CIRGenericTargetLoweringPattern : public mlir::ConversionPattern { if (auto typeAttr = mlir::dyn_cast<mlir::TypeAttr>(attr)) attr = mlir::TypeAttr::get( typeConverter->convertType(typeAttr.getValue())); + else if (auto ptrAttr = mlir::dyn_cast<cir::ConstPtrAttr>(attr)) + attr = cir::ConstPtrAttr::get( + typeConverter->convertType(ptrAttr.getType()), + ptrAttr.getValue()); }); rewriter.replaceOp(op, loweredOp); return mlir::success(); diff --git a/clang/test/CIR/CodeGen/amdgpu-target-lowering-as.cpp b/clang/test/CIR/CodeGen/amdgpu-target-lowering-as.cpp index 631cd2819c3bd..9be771e1621a8 100644 --- a/clang/test/CIR/CodeGen/amdgpu-target-lowering-as.cpp +++ b/clang/test/CIR/CodeGen/amdgpu-target-lowering-as.cpp @@ -64,3 +64,13 @@ void get_globals() { // POST: cir.func {{.*}} @_Z11get_globalsv // POST: cir.get_global @g_global : !cir.ptr<!s32i, target_address_space(1)> // POST: cir.get_global @g_constant : !cir.ptr<!s32i, target_address_space(4)> + +// ---- cir.const: null pointer constant type with lang AS -> target AS ---- + +int [[clang::opencl_global]] *null_global() { return nullptr; } + +// PRE: cir.func {{.*}} @_Z11null_globalv +// PRE: cir.const #cir.ptr<null> : !cir.ptr<!s32i, lang_address_space(offload_global)> + +// POST: cir.func {{.*}} @_Z11null_globalv +// POST: cir.const #cir.ptr<null> : !cir.ptr<!s32i, target_address_space(1)> diff --git a/clang/test/CIR/CodeGen/spirv-target-lowering-as.cpp b/clang/test/CIR/CodeGen/spirv-target-lowering-as.cpp index c8057dd4a5af1..67b80236d74da 100644 --- a/clang/test/CIR/CodeGen/spirv-target-lowering-as.cpp +++ b/clang/test/CIR/CodeGen/spirv-target-lowering-as.cpp @@ -71,3 +71,11 @@ generic_int *cast_and_global(global_int *ptr) { // POST: cir.cast address_space // POST-SAME: !cir.ptr<!s32i, target_address_space(1)> // POST-SAME: !cir.ptr<!s32i, target_address_space(4)> + +generic_int *null_generic() { return nullptr; } + +// PRE-LABEL: cir.func {{.*}} @_Z12null_genericv +// PRE: cir.const #cir.ptr<null> : !cir.ptr<!s32i, lang_address_space(offload_generic)> + +// POST-LABEL: cir.func {{.*}} @_Z12null_genericv +// POST: cir.const #cir.ptr<null> : !cir.ptr<!s32i, target_address_space(4)> _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
