From: John McCall Date: Mon, 1 Nov 2010 01:29:57 +0000 (+0000) Subject: Only apply -fvisibility-inlines-hidden to definitions. Apparently X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=66cbcf3f150d075fead7c5935b6e9c61a32cf3d4;p=clang Only apply -fvisibility-inlines-hidden to definitions. Apparently isInlined() just gives meaningless results for non-definitions. Fixes rdar://problem/8614470 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117887 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 7469e8b27f..5eb9e8501e 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -459,9 +459,15 @@ static LinkageInfo getLVForClassMember(const NamedDecl *D, // about whether containing classes have visibility attributes, // and that's intentional. if (TSK != TSK_ExplicitInstantiationDeclaration && - ConsiderGlobalVisibility && MD->isInlined() && - MD->getASTContext().getLangOptions().InlineVisibilityHidden) - LV.setVisibility(HiddenVisibility); + ConsiderGlobalVisibility && + MD->getASTContext().getLangOptions().InlineVisibilityHidden) { + // InlineVisibilityHidden only applies to definitions, and + // isInlined() only gives meaningful answers on definitions + // anyway. + const FunctionDecl *Def = 0; + if (MD->hasBody(Def) && Def->isInlined()) + LV.setVisibility(HiddenVisibility); + } // Note that in contrast to basically every other situation, we // *do* apply -fvisibility to method declarations. diff --git a/test/CodeGenCXX/visibility-inlines-hidden.cpp b/test/CodeGenCXX/visibility-inlines-hidden.cpp index 69ce256025..7f92be2abf 100644 --- a/test/CodeGenCXX/visibility-inlines-hidden.cpp +++ b/test/CodeGenCXX/visibility-inlines-hidden.cpp @@ -64,3 +64,18 @@ void use(X0 *x0, X1 *x1, X2 *x2, X1 *x3) { // CHECK: define available_externally void @_ZN2X1IfE2f2Ev x3->f2(); } + +// rdar://problem/8614470 +namespace test1 { + struct __attribute__((visibility("default"))) A { + inline void foo(); + ~A(); + }; + + void test() { + A a; + a.foo(); + } +// CHECK: declare void @_ZN5test11A3fooEv +// CHECK: declare void @_ZN5test11AD1Ev +}