From 8d04f0604e114e7e399c7dd74e9a03215ac1d07a Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 22 Mar 2010 23:12:48 +0000 Subject: [PATCH] A fixed version of r99174 which also includes a test that we emit vtables when we see an specialization definition ever if we then see a extern template declaration. llvm-svn: 99226 --- clang/lib/Sema/SemaDeclCXX.cpp | 2 +- clang/lib/Sema/SemaTemplate.cpp | 11 ++++++++++- clang/test/CodeGenCXX/PR6677.cpp | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGenCXX/PR6677.cpp diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 13a7ead76bdf..1522d6399a2b 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -5889,7 +5889,7 @@ static bool needsVtable(CXXMethodDecl *MD, ASTContext &Context) { break; case TSK_ExplicitInstantiationDeclaration: - return true; //FIXME: This looks wrong. + return false; case TSK_ExplicitInstantiationDefinition: // This is method of a explicit instantiation; mark all of the virtual diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 434d5563e1b3..abe9363352ea 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -4388,8 +4388,17 @@ Sema::ActOnExplicitInstantiation(Scope *S, // Instantiate the members of this class template specialization. Def = cast_or_null( Specialization->getDefinition()); - if (Def) + if (Def) { + TemplateSpecializationKind Old_TSK = Def->getTemplateSpecializationKind(); + + // Fix a TSK_ExplicitInstantiationDeclaration followed by a + // TSK_ExplicitInstantiationDefinition + if (Old_TSK == TSK_ExplicitInstantiationDeclaration && + TSK == TSK_ExplicitInstantiationDefinition) + Def->setTemplateSpecializationKind(TSK); + InstantiateClassTemplateSpecializationMembers(TemplateNameLoc, Def, TSK); + } return DeclPtrTy::make(Specialization); } diff --git a/clang/test/CodeGenCXX/PR6677.cpp b/clang/test/CodeGenCXX/PR6677.cpp new file mode 100644 index 000000000000..8d168f110608 --- /dev/null +++ b/clang/test/CodeGenCXX/PR6677.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s + +// CHECK-NOT: @_ZTVN5test118stdio_sync_filebufIwEE = constant +// CHECK: @_ZTVN5test018stdio_sync_filebufIwEE = constant + +namespace test0 { + struct basic_streambuf { + virtual ~basic_streambuf(); + }; + template + struct stdio_sync_filebuf : public basic_streambuf { + virtual void xsgetn(); + }; + + // This specialization should cause the vtable to be emitted, even with + // the following extern template declaration. + template<> void stdio_sync_filebuf::xsgetn() { + } + extern template class stdio_sync_filebuf; +} + +namespace test1 { + struct basic_streambuf { + virtual ~basic_streambuf(); + }; + template + struct stdio_sync_filebuf : public basic_streambuf { + virtual void xsgetn(); + }; + + // Just a declaration should not force the vtable to be emitted. + template<> void stdio_sync_filebuf::xsgetn(); +}