[cfe-commits] r99900 - in /cfe/trunk: lib/CodeGen/CGVtable.cpp test/CodeGenCXX/template-instantiation.cpp
Rafael Espindola
rafael.espindola at gmail.com
Tue Mar 30 11:07:27 PDT 2010
Author: rafael
Date: Tue Mar 30 13:07:27 2010
New Revision: 99900
URL: http://llvm.org/viewvc/llvm-project?rev=99900&view=rev
Log:
Don't produce a vtable if we are just instantiating a method and the
class has no key function.
Fix PR6738.
Modified:
cfe/trunk/lib/CodeGen/CGVtable.cpp
cfe/trunk/test/CodeGenCXX/template-instantiation.cpp
Modified: cfe/trunk/lib/CodeGen/CGVtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVtable.cpp?rev=99900&r1=99899&r2=99900&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Tue Mar 30 13:07:27 2010
@@ -3138,19 +3138,28 @@
// Get the key function.
const CXXMethodDecl *KeyFunction = CGM.getContext().getKeyFunction(RD);
+ TemplateSpecializationKind RDKind = RD->getTemplateSpecializationKind();
+ TemplateSpecializationKind MDKind = MD->getTemplateSpecializationKind();
+
if (KeyFunction) {
// We don't have the right key function.
if (KeyFunction->getCanonicalDecl() != MD->getCanonicalDecl())
return;
+ } else {
+ // If this is an explicit instantiation of a method, we don't need a vtable.
+ // Since we have no key function, we will emit the vtable when we see
+ // a use, and just defining a function is not an use.
+ if ((RDKind == TSK_ImplicitInstantiation ||
+ RDKind == TSK_ExplicitInstantiationDeclaration) &&
+ MDKind == TSK_ExplicitInstantiationDefinition)
+ return;
}
if (Vtables.count(RD))
return;
- TemplateSpecializationKind kind = RD->getTemplateSpecializationKind();
- if (kind == TSK_ImplicitInstantiation)
+ if (RDKind == TSK_ImplicitInstantiation)
CGM.DeferredVtables.push_back(RD);
else
GenerateClassData(CGM.getVtableLinkage(RD), RD);
}
-
Modified: cfe/trunk/test/CodeGenCXX/template-instantiation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/template-instantiation.cpp?rev=99900&r1=99899&r2=99900&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/template-instantiation.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/template-instantiation.cpp Tue Mar 30 13:07:27 2010
@@ -1,6 +1,7 @@
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
// CHECK-NOT: @_ZTVN5test118stdio_sync_filebufIwEE = constant
+// CHECK-NOT: _ZTVN5test315basic_fstreamXXIcEE
// CHECK: @_ZTVN5test018stdio_sync_filebufIwEE = constant
// CHECK: define linkonce_odr void @_ZN5test21CIiEC1Ev(
@@ -60,3 +61,16 @@
a.zedbar(0.0);
}
}
+
+namespace test3 {
+ template<typename T>
+ class basic_fstreamXX {
+ virtual void foo(){}
+ virtual void is_open() const { }
+ };
+
+ extern template class basic_fstreamXX<char>;
+ // This template instantiation should not cause us to produce a vtable.
+ // (test at the top).
+ template void basic_fstreamXX<char>::is_open() const;
+}
More information about the cfe-commits
mailing list