From: Argyrios Kyrtzidis Date: Wed, 13 Oct 2010 02:39:41 +0000 (+0000) Subject: Embrace C++ ABI 5.2.6 and consider that template instantiations don't have key functi... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3bd5b6c3c2ad1d5a6f88cf21f627e8d4f03c4df4;p=clang Embrace C++ ABI 5.2.6 and consider that template instantiations don't have key functions (same as GCC). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116391 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp index 0a095886ff..c5465a5dca 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/lib/AST/RecordLayoutBuilder.cpp @@ -1562,6 +1562,13 @@ RecordLayoutBuilder::ComputeKeyFunction(const CXXRecordDecl *RD) { if (RD->isInAnonymousNamespace()) return 0; + // Template instantiations don't have key functions,see Itanium C++ ABI 5.2.6. + // Same behavior as GCC. + TemplateSpecializationKind TSK = RD->getTemplateSpecializationKind(); + if (TSK == TSK_ImplicitInstantiation || + TSK == TSK_ExplicitInstantiationDefinition) + return 0; + for (CXXRecordDecl::method_iterator I = RD->method_begin(), E = RD->method_end(); I != E; ++I) { const CXXMethodDecl *MD = *I; diff --git a/test/CodeGenCXX/template-instantiation.cpp b/test/CodeGenCXX/template-instantiation.cpp index cb6c812316..47ff16b8a6 100644 --- a/test/CodeGenCXX/template-instantiation.cpp +++ b/test/CodeGenCXX/template-instantiation.cpp @@ -4,6 +4,9 @@ // CHECK-NOT: _ZTVN5test315basic_fstreamXXIcEE // CHECK: @_ZTVN5test018stdio_sync_filebufIwEE = constant +// CHECK-NOT: _ZTVN5test31SIiEE +// CHECK-NOT: _ZTSN5test31SIiEE + // CHECK: define linkonce_odr void @_ZN5test21CIiEC1Ev( // CHECK: define linkonce_odr void @_ZN5test21CIiE6foobarIdEEvT_( // CHECK: define available_externally void @_ZN5test21CIiE6zedbarEd( @@ -75,3 +78,17 @@ namespace test3 { // (test at the top). template void basic_fstreamXX::is_open() const; } + +namespace test3 { + template + struct S { + virtual void m(); + }; + + template + void S::m() { } + + // Should not cause us to produce vtable because template instantiations + // don't have key functions. + template void S::m(); +}