]> granicus.if.org Git - clang/commitdiff
Don't dllimport/export class members with internal linkage (PR23308)
authorHans Wennborg <hans@hanshq.net>
Wed, 22 Apr 2015 04:05:17 +0000 (04:05 +0000)
committerHans Wennborg <hans@hanshq.net>
Wed, 22 Apr 2015 04:05:17 +0000 (04:05 +0000)
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

lib/Sema/SemaDeclCXX.cpp
test/CodeGenCXX/dllexport.cpp
test/SemaCXX/dllexport.cpp

index b0e6acaedb965d9d2af642af3b13bb267d319cdd..b06b509de1e4d8c445b21e34dd931238e3b195d2 100644 (file)
@@ -4804,6 +4804,9 @@ static void checkDLLAttribute(Sema &S, CXXRecordDecl *Class) {
       }
     }
 
+    if (!cast<NamedDecl>(Member)->isExternallyVisible())
+      continue;
+
     if (!getDLLAttr(Member)) {
       auto *NewAttr =
           cast<InheritableAttr>(ClassAttr->clone(S.getASTContext()));
index b7bd675602d0b5a9c48d45b290781f40afacbfbf..cc66a668770a6d136178998bef03f2184a7ca05d 100644 (file)
@@ -691,6 +691,15 @@ extern template struct ExplicitInstantiationDeclExportedTemplate<int>;
 USEMEMFUNC(ExplicitInstantiationDeclExportedTemplate<int>, 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
index 3bb9d224f727179d84844748804acbf922c55d3b..3b9b20d72de6c70b7dea4cab15e9fc9403ce0258 100644 (file)
@@ -393,6 +393,12 @@ extern template struct __declspec(dllexport) ExplicitInstantiationDeclTemplate<i
 template <typename T> struct __declspec(dllexport) ExplicitInstantiationDeclExportedTemplate {}; // expected-note{{attribute is here}}
 extern template struct ExplicitInstantiationDeclExportedTemplate<int>; // 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
 //===----------------------------------------------------------------------===//