[cfe-commits] r99311 - in /cfe/trunk: lib/CodeGen/CGVtable.cpp lib/CodeGen/CodeGenModule.cpp lib/Sema/SemaTemplate.cpp test/CodeGenCXX/PR6677.cpp

Rafael Espindola rafael.espindola at gmail.com
Tue Mar 23 11:56:16 PDT 2010


Author: rafael
Date: Tue Mar 23 13:56:16 2010
New Revision: 99311

URL: http://llvm.org/viewvc/llvm-project?rev=99311&view=rev
Log:
Avoid producing implicit methods when we have a explicit template instantiation
declaration.


Modified:
    cfe/trunk/lib/CodeGen/CGVtable.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/CodeGenCXX/PR6677.cpp

Modified: cfe/trunk/lib/CodeGen/CGVtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVtable.cpp?rev=99311&r1=99310&r2=99311&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Tue Mar 23 13:56:16 2010
@@ -3805,7 +3805,17 @@
     return;
 
   TemplateSpecializationKind kind = RD->getTemplateSpecializationKind();
-  if (kind == TSK_ImplicitInstantiation)
+
+
+  // The reason we have TSK_ExplicitInstantiationDeclaration in here (but not
+  // in  Sema::MaybeMarkVirtualMembersReferenced) is for the case
+  // template<> void stdio_sync_filebuf<wchar_t>::xsgetn() {
+  // }
+  // extern template class stdio_sync_filebuf<wchar_t>;
+  // Since we are called after the extern declaration is seen.
+
+  if (kind == TSK_ImplicitInstantiation ||
+      kind == TSK_ExplicitInstantiationDeclaration)
     CGM.DeferredVtables.push_back(RD);
   else
     GenerateClassData(CGM.getVtableLinkage(RD), RD);

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=99311&r1=99310&r2=99311&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Mar 23 13:56:16 2010
@@ -310,8 +310,17 @@
   //   instantiated when used so that the body can be considered for 
   //   inlining, but that no out-of-line copy of the inline function would be
   //   generated in the translation unit. -- end note ]
-  if (FD->getTemplateSpecializationKind() 
-                                       == TSK_ExplicitInstantiationDeclaration)
+
+  // We check the specialization kind of the class for implicit methods.
+  // They have a TSK_Undeclared specialization kind.
+  TemplateSpecializationKind TSK;
+  const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD);
+  if (MD && MD->isImplicit())
+    TSK = MD->getParent()->getTemplateSpecializationKind();
+  else
+    TSK = FD->getTemplateSpecializationKind();
+
+  if (TSK == TSK_ExplicitInstantiationDeclaration)
     return CodeGenModule::GVA_C99Inline;
   
   return CodeGenModule::GVA_CXXInline;

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=99311&r1=99310&r2=99311&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Tue Mar 23 13:56:16 2010
@@ -4389,13 +4389,7 @@
   Def = cast_or_null<ClassTemplateSpecializationDecl>(
                                        Specialization->getDefinition());
   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);
+    Def->setTemplateSpecializationKind(TSK);
 
     InstantiateClassTemplateSpecializationMembers(TemplateNameLoc, Def, TSK);
   }

Modified: cfe/trunk/test/CodeGenCXX/PR6677.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/PR6677.cpp?rev=99311&r1=99310&r2=99311&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/PR6677.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/PR6677.cpp Tue Mar 23 13:56:16 2010
@@ -3,6 +3,9 @@
 // CHECK-NOT: @_ZTVN5test118stdio_sync_filebufIwEE = constant
 // CHECK: @_ZTVN5test018stdio_sync_filebufIwEE = constant
 
+// CHECK: define linkonce_odr void @_ZN5test21CIiE5fobarIdEEvT_
+// CHECK: define available_externally void @_ZN5test21CIiE6zedbarEd
+
 namespace test0 {
   struct  basic_streambuf   {
     virtual       ~basic_streambuf();
@@ -13,7 +16,12 @@
   };
 
   // This specialization should cause the vtable to be emitted, even with
-  // the following extern template declaration.
+  // the following extern template declaration (test at the top).
+
+  // The existance of the extern template declaration should prevent us from emitting
+  // destructors.
+  // CHECK: define available_externally void @_ZN5test018stdio_sync_filebufIwED0Ev
+  // CHECK: define available_externally void @_ZN5test018stdio_sync_filebufIwED2Ev
   template<> void stdio_sync_filebuf<wchar_t>::xsgetn()  {
   }
   extern template class stdio_sync_filebuf<wchar_t>;
@@ -28,6 +36,30 @@
     virtual void      xsgetn();
   };
 
-  // Just a declaration should not force the vtable to be emitted.
+  // Just a declaration should not force the vtable to be emitted
+  // (test at the top).
   template<> void stdio_sync_filebuf<wchar_t>::xsgetn();
 }
+
+namespace test2 {
+  template<typename T1>
+  class C {
+    void zedbar(double) {
+    }
+    template<typename T2>
+    void fobar(T2 foo) {
+    }
+  };
+  extern template class C<int>;
+  void g() {
+    C<int> a;
+    // The extern template declaration should not prevent us from producing
+    /// foobar.
+    // (test at the top).
+    a.fobar(0.0);
+
+    // But it should prevent zebbar
+    // (test at the top).
+    a.zedbar(0.0);
+  }
+}





More information about the cfe-commits mailing list