https://github.com/bcardosolopes updated https://github.com/llvm/llvm-project/pull/214924
>From 8b860f3f6974b0dbb1769a4772ad1f3fb0f40699 Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes <[email protected]> Date: Fri, 7 Aug 2026 18:08:31 -0700 Subject: [PATCH] [CIR] Emit the section attribute on function-local static variables 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. Extend clang/test/CIR/CodeGen/global-section.c with a function-local static; it already covered extern, file-scope, and function sections. The pre-existing global checks become -DAG because CIR and OGCG emit the static-local global at opposite ends of the module. --- clang/lib/CIR/CodeGen/CIRGenDecl.cpp | 5 ++--- clang/test/CIR/CodeGen/global-section.c | 15 +++++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) 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" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
