llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clangir

Author: Akimasa Watanuki (Men-cotton)

<details>
<summary>Changes</summary>

Diagnose a `LangAddressSpaceAttr` on `cir.global` before selecting the LLVM 
global address space. This keeps standalone global attributes from bypassing 
pointer conversion and silently falling back to address space zero.

Assisted-by: Codex / GPT-5.6 Sol

---
Full diff: https://github.com/llvm/llvm-project/pull/223660.diff


2 Files Affected:

- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+4) 
- (added) clang/test/CIR/Lowering/unlowered-address-spaces.cir (+9) 


``````````diff
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index 81a1bb2576f0a..e725b18f3ff81 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -3000,6 +3000,10 @@ 
CIRToLLVMGlobalOpLowering::matchAndRewriteRegionInitializedGlobal(
 mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
     cir::GlobalOp op, OpAdaptor adaptor,
     mlir::ConversionPatternRewriter &rewriter) const {
+  if (mlir::isa_and_present<cir::LangAddressSpaceAttr>(op.getAddrSpaceAttr()))
+    return op.emitError()
+           << "cannot lower a global with a language address space";
+
   // If this global requires non-trivial initialization or destruction,
   // that needs to be moved to runtime handlers during LoweringPrepare.
   if (!op.getCtorRegion().empty() || !op.getDtorRegion().empty())
diff --git a/clang/test/CIR/Lowering/unlowered-address-spaces.cir 
b/clang/test/CIR/Lowering/unlowered-address-spaces.cir
new file mode 100644
index 0000000000000..0faf18e5d0067
--- /dev/null
+++ b/clang/test/CIR/Lowering/unlowered-address-spaces.cir
@@ -0,0 +1,9 @@
+// RUN: cir-opt %s --split-input-file --cir-to-llvm -verify-diagnostics
+
+!s32i = !cir.int<s, 32>
+
+module attributes {cir.triple = "spirv64-unknown-unknown"} {
+  // expected-error @below {{cannot lower a global with a language address 
space}}
+  // expected-error @below {{failed to legalize operation 'cir.global'}}
+  cir.global external lang_address_space(offload_global) @global = #cir.int<1> 
: !s32i
+}

``````````

</details>


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

Reply via email to