r183222 - Fix linkage computation for local types in template functions.
Rafael Espindola
rafael.espindola at gmail.com
Tue Jun 4 06:43:35 PDT 2013
Author: rafael
Date: Tue Jun 4 08:43:35 2013
New Revision: 183222
URL: http://llvm.org/viewvc/llvm-project?rev=183222&view=rev
Log:
Fix linkage computation for local types in template functions.
Template functions (and member functions of class templates) present the same
problem as inline functions. They need to be uniqued, so we need to assign
VisibleNoLinkage linkage to types defined in them.
Modified:
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/test/CodeGenCXX/linkage.cpp
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=183222&r1=183221&r2=183222&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Tue Jun 4 08:43:35 2013
@@ -1049,8 +1049,12 @@ static LinkageInfo getLVForLocalDecl(con
return LinkageInfo::none();
const FunctionDecl *FD = getOutermostFunctionContext(D);
- if (!FD || !FD->isInlined())
+ if (!FD)
return LinkageInfo::none();
+
+ if (!FD->isInlined() && FD->getTemplateSpecializationKind() == TSK_Undeclared)
+ return LinkageInfo::none();
+
LinkageInfo LV = getLVForDecl(FD, computation);
if (!isExternallyVisible(LV.getLinkage()))
return LinkageInfo::none();
Modified: cfe/trunk/test/CodeGenCXX/linkage.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/linkage.cpp?rev=183222&r1=183221&r2=183222&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/linkage.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/linkage.cpp Tue Jun 4 08:43:35 2013
@@ -184,3 +184,28 @@ namespace test14 {
}
void h() { f(); }
}
+
+namespace test15 {
+ // CHECK-DAG: define linkonce_odr void @_ZN6test153zedIZNS_3fooIiEEPvvE3bar_9EEvv(
+ template <class T> void zed() {}
+ template <class T> void *foo() {
+ class bar {
+ };
+ return reinterpret_cast<void *>(zed<bar>);
+ }
+ void test() { foo<int>(); }
+}
+
+namespace test16 {
+ // CHECK-DAG: define linkonce_odr void @_ZN6test163zedIZNS_3fooIiE3barEvE1S__10_EEvv(
+ template <class T> void zed() {}
+ template <class T> struct foo {
+ static void *bar();
+ };
+ template <class T> void *foo<T>::bar() {
+ class S {
+ };
+ return reinterpret_cast<void *>(zed<S>);
+ }
+ void *test() { return foo<int>::bar(); }
+}
More information about the cfe-commits
mailing list