From: Hans Wennborg Date: Wed, 22 Apr 2015 04:05:17 +0000 (+0000) Subject: Don't dllimport/export class members with internal linkage (PR23308) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=26a663ab48dbe7db656ee75d03044bd72c6cad17;p=clang Don't dllimport/export class members with internal linkage (PR23308) For example, a function taking a parameter with internal linkage will itself have internal linkage since it cannot be called outside the translation unit. Differential Revision: http://reviews.llvm.org/D9182 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235471 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index b0e6acaedb..b06b509de1 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -4804,6 +4804,9 @@ static void checkDLLAttribute(Sema &S, CXXRecordDecl *Class) { } } + if (!cast(Member)->isExternallyVisible()) + continue; + if (!getDLLAttr(Member)) { auto *NewAttr = cast(ClassAttr->clone(S.getASTContext())); diff --git a/test/CodeGenCXX/dllexport.cpp b/test/CodeGenCXX/dllexport.cpp index b7bd675602..cc66a66877 100644 --- a/test/CodeGenCXX/dllexport.cpp +++ b/test/CodeGenCXX/dllexport.cpp @@ -691,6 +691,15 @@ extern template struct ExplicitInstantiationDeclExportedTemplate; USEMEMFUNC(ExplicitInstantiationDeclExportedTemplate, f); // M32-DAG: {{declare|define available_externally}} x86_thiscallcc void @"\01?f@?$ExplicitInstantiationDeclExportedTemplate@H@@QAEXXZ" +namespace { struct InternalLinkageType {}; } +struct __declspec(dllexport) PR23308 { + void f(InternalLinkageType*); +}; +void PR23308::f(InternalLinkageType*) {} +long use(PR23308* p) { p->f(nullptr); } +// M32-DAG: define internal x86_thiscallcc void @"\01?f@PR23308@@QAEXPAUInternalLinkageType@?A@@@Z" + + //===----------------------------------------------------------------------===// // Classes with template base classes diff --git a/test/SemaCXX/dllexport.cpp b/test/SemaCXX/dllexport.cpp index 3bb9d224f7..3b9b20d72d 100644 --- a/test/SemaCXX/dllexport.cpp +++ b/test/SemaCXX/dllexport.cpp @@ -393,6 +393,12 @@ extern template struct __declspec(dllexport) ExplicitInstantiationDeclTemplate struct __declspec(dllexport) ExplicitInstantiationDeclExportedTemplate {}; // expected-note{{attribute is here}} extern template struct ExplicitInstantiationDeclExportedTemplate; // expected-warning{{explicit instantiation declaration should not be 'dllexport'}} +namespace { struct InternalLinkageType {}; } +struct __declspec(dllexport) PR23308 { + void f(InternalLinkageType*); +}; +void PR23308::f(InternalLinkageType*) {} // No error; we don't try to export f because it has internal linkage. + //===----------------------------------------------------------------------===// // Classes with template base classes //===----------------------------------------------------------------------===//