[cfe-commits] r99226 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaTemplate.cpp test/CodeGenCXX/PR6677.cpp

Rafael Espindola rafael.espindola at gmail.com
Mon Mar 22 16:12:48 PDT 2010


Author: rafael
Date: Mon Mar 22 18:12:48 2010
New Revision: 99226

URL: http://llvm.org/viewvc/llvm-project?rev=99226&view=rev
Log:
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.

Added:
    cfe/trunk/test/CodeGenCXX/PR6677.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaTemplate.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=99226&r1=99225&r2=99226&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Mar 22 18:12:48 2010
@@ -5889,7 +5889,7 @@
     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

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=99226&r1=99225&r2=99226&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon Mar 22 18:12:48 2010
@@ -4388,8 +4388,17 @@
   // Instantiate the members of this class template specialization.
   Def = cast_or_null<ClassTemplateSpecializationDecl>(
                                        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);
 }

Added: cfe/trunk/test/CodeGenCXX/PR6677.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/PR6677.cpp?rev=99226&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/PR6677.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/PR6677.cpp Mon Mar 22 18:12:48 2010
@@ -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<typename _CharT >
+  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<wchar_t>::xsgetn()  {
+  }
+  extern template class stdio_sync_filebuf<wchar_t>;
+}
+
+namespace test1 {
+  struct  basic_streambuf   {
+    virtual       ~basic_streambuf();
+  };
+  template<typename _CharT >
+  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<wchar_t>::xsgetn();
+}





More information about the cfe-commits mailing list