Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2608,8 +2608,15 @@ void CIRGenModule::setFunctionAttributes(GlobalDecl globalDecl,

// TODO(cir): Complete the remaining part of the function.
assert(!MissingFeatures::setFunctionAttributes());
auto decl = globalDecl.getDecl();
func.setGlobalVisibilityAttr(getGlobalVisibilityAttrFromDecl(decl));

// TODO(cir): This needs a lot of work to better match CodeGen. That
// ultimately ends up in setGlobalVisibility, which already has the linkage of
// the LLVM GV (corresponding to our FuncOp) computed, so it doesn't have to
// recompute it here. This is a minimal fix for now.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is subtle enough that it deserves an issue to track it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I filed #992 to fix this up more thoroughly.

if (!isLocalLinkage(getFunctionLinkage(globalDecl))) {
auto decl = globalDecl.getDecl();
func.setGlobalVisibilityAttr(getGlobalVisibilityAttrFromDecl(decl));
}
}

/// If the specified mangled name is not in the module,
Expand Down
15 changes: 15 additions & 0 deletions clang/test/CIR/CodeGen/visibility-attribute.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,24 @@ void __attribute__((__visibility__("protected"))) foo_protected();
// CIR: cir.func no_proto private protected @foo_protected(...)
// LLVM: declare {{.*}} protected void @foo_protected(...)

static void static_foo_default() {}
// CIR: cir.func no_proto internal private @static_foo_default()
// LLVM: define internal void @static_foo_default()

static void __attribute__((__visibility__("hidden"))) static_foo_hidden() {}
// CIR: cir.func no_proto internal private @static_foo_hidden()
// LLVM: define internal void @static_foo_hidden()

static void __attribute__((__visibility__("protected"))) static_foo_protected() {}
// CIR: cir.func no_proto internal private @static_foo_protected()
// LLVM: define internal void @static_foo_protected()

void call_foo()
{
foo_default();
foo_hidden();
foo_protected();
static_foo_default();
static_foo_hidden();
static_foo_protected();
}