[cfe-commits] r106440 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGenCXX/visibility-hidden-extern-templates.cpp
Douglas Gregor
dgregor at apple.com
Mon Jun 21 11:41:26 PDT 2010
Author: dgregor
Date: Mon Jun 21 13:41:26 2010
New Revision: 106440
URL: http://llvm.org/viewvc/llvm-project?rev=106440&view=rev
Log:
Instantiations subject to an explicit template instantiation
declaration have default visibility even under
-fvisibility=hidden. Fixes <rdar://problem/8109763>.
Added:
cfe/trunk/test/CodeGenCXX/visibility-hidden-extern-templates.cpp
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=106440&r1=106439&r2=106440&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Jun 21 13:41:26 2010
@@ -23,6 +23,7 @@
#include "clang/AST/CharUnits.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
#include "clang/AST/RecordLayout.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/Diagnostic.h"
@@ -151,14 +152,38 @@
return LangOptions::Protected;
}
}
-
- // If -fvisibility-inlines-hidden was provided, then inline C++ member
- // functions get "hidden" visibility by default.
- if (getLangOptions().InlineVisibilityHidden)
- if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D))
- if (Method->isInlined())
- return LangOptions::Hidden;
+ if (getLangOptions().CPlusPlus) {
+ // Entities subject to an explicit instantiation declaration get default
+ // visibility.
+ if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
+ if (Function->getTemplateSpecializationKind()
+ == TSK_ExplicitInstantiationDeclaration)
+ return LangOptions::Default;
+ } else if (const ClassTemplateSpecializationDecl *ClassSpec
+ = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
+ if (ClassSpec->getSpecializationKind()
+ == TSK_ExplicitInstantiationDeclaration)
+ return LangOptions::Default;
+ } else if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) {
+ if (Record->getTemplateSpecializationKind()
+ == TSK_ExplicitInstantiationDeclaration)
+ return LangOptions::Default;
+ } else if (const VarDecl *Var = dyn_cast<VarDecl>(D)) {
+ if (Var->isStaticDataMember() &&
+ (Var->getTemplateSpecializationKind()
+ == TSK_ExplicitInstantiationDeclaration))
+ return LangOptions::Default;
+ }
+
+ // If -fvisibility-inlines-hidden was provided, then inline C++ member
+ // functions get "hidden" visibility by default.
+ if (getLangOptions().InlineVisibilityHidden)
+ if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D))
+ if (Method->isInlined())
+ return LangOptions::Hidden;
+ }
+
// This decl should have the same visibility as its parent.
if (const DeclContext *DC = D->getDeclContext())
return getDeclVisibilityMode(cast<Decl>(DC));
Added: cfe/trunk/test/CodeGenCXX/visibility-hidden-extern-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/visibility-hidden-extern-templates.cpp?rev=106440&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/visibility-hidden-extern-templates.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/visibility-hidden-extern-templates.cpp Mon Jun 21 13:41:26 2010
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -emit-llvm -o - -fvisibility hidden %s | FileCheck %s
+
+template<typename T>
+struct X {
+ void f();
+ void g() { }
+};
+
+template<typename T> void X<T>::f() { }
+
+extern template struct X<int>;
+template struct X<int>;
+extern template struct X<char>;
+
+// <rdar://problem/8109763>
+void test_X(X<int> xi, X<char> xc) {
+ // CHECK: define weak_odr hidden void @_ZN1XIiE1fEv
+ xi.f();
+ // CHECK: define weak_odr hidden void @_ZN1XIiE1gEv
+ xi.g();
+ // CHECK: declare void @_ZN1XIcE1fEv
+ xc.f();
+ // CHECK: define available_externally void @_ZN1XIcE1gEv
+ xc.g();
+}
+
More information about the cfe-commits
mailing list