From ec0d96f8fa33a56cf4b9ea7d63bff8c0abcdd13c Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 4 Jun 2013 13:43:35 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183222 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Decl.cpp | 6 +++++- test/CodeGenCXX/linkage.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 80a32c5870..a36fcf2507 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1049,8 +1049,12 @@ static LinkageInfo getLVForLocalDecl(const NamedDecl *D, 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(); diff --git a/test/CodeGenCXX/linkage.cpp b/test/CodeGenCXX/linkage.cpp index 7f6188f457..7c67029399 100644 --- a/test/CodeGenCXX/linkage.cpp +++ b/test/CodeGenCXX/linkage.cpp @@ -184,3 +184,28 @@ namespace test14 { } void h() { f(); } } + +namespace test15 { + // CHECK-DAG: define linkonce_odr void @_ZN6test153zedIZNS_3fooIiEEPvvE3bar_9EEvv( + template void zed() {} + template void *foo() { + class bar { + }; + return reinterpret_cast(zed); + } + void test() { foo(); } +} + +namespace test16 { + // CHECK-DAG: define linkonce_odr void @_ZN6test163zedIZNS_3fooIiE3barEvE1S__10_EEvv( + template void zed() {} + template struct foo { + static void *bar(); + }; + template void *foo::bar() { + class S { + }; + return reinterpret_cast(zed); + } + void *test() { return foo::bar(); } +} -- 2.40.0