llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Bruno Cardoso Lopes (bcardosolopes)

<details>
<summary>Changes</summary>

emitStaticVarDecl bailed with errorNYI on any `static` local carrying 
`__attribute__((section(...)))`, so a TU using one failed to compile at all 
under -fclangir. Classic CodeGen just forwards the name to the global 
(CodeGenFunction::EmitStaticVarDecl), and everything needed for that already 
exists on the CIR side: cir.global has an optional `section` attribute and 
CIRToLLVMGlobalOpLowering::lowerGlobalAttributes already forwards it. Port the 
one-liner.

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


2 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CIRGenDecl.cpp (+2-3) 
- (modified) clang/test/CIR/CodeGen/global-section.c (+11-4) 


``````````diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp 
b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
index e17550a8c1668..dce0e6fbe7502 100644
--- a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
@@ -760,9 +760,8 @@ void CIRGenFunction::emitStaticVarDecl(const VarDecl &d,
     cgm.errorNYI(d.getSourceRange(),
                  "emitStaticVarDecl: CIR global Relro section attribute");
 
-  if (d.getAttr<SectionAttr>())
-    cgm.errorNYI(d.getSourceRange(),
-                 "emitStaticVarDecl: CIR global object file section 
attribute");
+  if (const SectionAttr *sa = d.getAttr<SectionAttr>())
+    var.setSectionAttr(builder.getStringAttr(sa->getName()));
 
   if (cgm.getCodeGenOpts().KeepPersistentStorageVariables)
     cgm.errorNYI(d.getSourceRange(), "static var keep persistent storage");
diff --git a/clang/test/CIR/CodeGen/global-section.c 
b/clang/test/CIR/CodeGen/global-section.c
index aa2253e95e767..45caf52b6f81c 100644
--- a/clang/test/CIR/CodeGen/global-section.c
+++ b/clang/test/CIR/CodeGen/global-section.c
@@ -6,12 +6,19 @@ extern int __attribute__((section(".shared"))) ext;
 int getExt(void) {
   return ext;
 }
-// CIR: cir.global "private" external @ext : !s32i {{{.*}}section = ".shared"}
-// LLVM: @ext = external global i32, section ".shared"
+// CIR-DAG: cir.global "private" external @ext : !s32i {{{.*}}section = 
".shared"}
+// LLVM-DAG: @ext = external global i32, section ".shared"
 
 int __attribute__((section(".shared"))) glob = 42;
-// CIR: cir.global external @glob = #cir.int<42> : !s32i {{{.*}}section = 
".shared"}
-// LLVM: @glob = global i32 42, section ".shared"
+// CIR-DAG: cir.global external @glob = #cir.int<42> : !s32i {{{.*}}section = 
".shared"}
+// LLVM-DAG: @glob = global i32 42, section ".shared"
+
+int getStaticLocal(void) {
+  static int __attribute__((section(".static_local"))) sloc = 7;
+  return ++sloc;
+}
+// CIR-DAG: cir.global "private" internal dso_local @getStaticLocal.sloc = 
#cir.int<7> : !s32i {{{.*}}section = ".static_local"}
+// LLVM-DAG: @getStaticLocal.sloc = internal global i32 7, section 
".static_local"
 
 __attribute__((section(".custom_fn"))) void func_in_section(void) {}
 // CIR: cir.func {{.*}}@func_in_section() {{.*}}section = ".custom_fn"

``````````

</details>


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

Reply via email to