Skip to content

Commit c49428f

Browse files
smeenailanza
authored andcommitted
[CIR][CIRGen] Ensure default visibility for local linkage functions (#990)
LLVM's verifier enforces this, which was previously causing us to fail verification. This is a bit of a band-aid; the overall linkage and visibility setting flow needs some work to match the original.
1 parent f6aac67 commit c49428f

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,8 +2608,15 @@ void CIRGenModule::setFunctionAttributes(GlobalDecl globalDecl,
26082608

26092609
// TODO(cir): Complete the remaining part of the function.
26102610
assert(!MissingFeatures::setFunctionAttributes());
2611-
auto decl = globalDecl.getDecl();
2612-
func.setGlobalVisibilityAttr(getGlobalVisibilityAttrFromDecl(decl));
2611+
2612+
// TODO(cir): This needs a lot of work to better match CodeGen. That
2613+
// ultimately ends up in setGlobalVisibility, which already has the linkage of
2614+
// the LLVM GV (corresponding to our FuncOp) computed, so it doesn't have to
2615+
// recompute it here. This is a minimal fix for now.
2616+
if (!isLocalLinkage(getFunctionLinkage(globalDecl))) {
2617+
auto decl = globalDecl.getDecl();
2618+
func.setGlobalVisibilityAttr(getGlobalVisibilityAttrFromDecl(decl));
2619+
}
26132620
}
26142621

26152622
/// If the specified mangled name is not in the module,

clang/test/CIR/CodeGen/visibility-attribute.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,24 @@ void __attribute__((__visibility__("protected"))) foo_protected();
3030
// CIR: cir.func no_proto private protected @foo_protected(...)
3131
// LLVM: declare {{.*}} protected void @foo_protected(...)
3232

33+
static void static_foo_default() {}
34+
// CIR: cir.func no_proto internal private @static_foo_default()
35+
// LLVM: define internal void @static_foo_default()
36+
37+
static void __attribute__((__visibility__("hidden"))) static_foo_hidden() {}
38+
// CIR: cir.func no_proto internal private @static_foo_hidden()
39+
// LLVM: define internal void @static_foo_hidden()
40+
41+
static void __attribute__((__visibility__("protected"))) static_foo_protected() {}
42+
// CIR: cir.func no_proto internal private @static_foo_protected()
43+
// LLVM: define internal void @static_foo_protected()
44+
3345
void call_foo()
3446
{
3547
foo_default();
3648
foo_hidden();
3749
foo_protected();
50+
static_foo_default();
51+
static_foo_hidden();
52+
static_foo_protected();
3853
}

0 commit comments

Comments
 (0)