[cfe-commits] r164927 - in /cfe/trunk: lib/Serialization/ASTReaderDecl.cpp lib/Serialization/ASTWriterDecl.cpp test/Modules/Inputs/redecl-merge-left.h test/Modules/Inputs/redecl-merge-right.h test/Modules/Inputs/redecl-merge-top.h test/Modules/redecl-merge.m

Axel Naumann Axel.Naumann at cern.ch
Mon Oct 1 00:34:47 PDT 2012


Author: axel
Date: Mon Oct  1 02:34:47 2012
New Revision: 164927

URL: http://llvm.org/viewvc/llvm-project?rev=164927&view=rev
Log:
Bring ASTReader and Writer into sync for the case where a canonical template specialization was written, which is non-canonical at the time of reading: force the reading of the ClassTemplateDecl if it was written.
The easiest way out is to store whether the decl was canonical at the time of writing.
Add test.

Modified:
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
    cfe/trunk/test/Modules/Inputs/redecl-merge-left.h
    cfe/trunk/test/Modules/Inputs/redecl-merge-right.h
    cfe/trunk/test/Modules/Inputs/redecl-merge-top.h
    cfe/trunk/test/Modules/redecl-merge.m

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=164927&r1=164926&r2=164927&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Mon Oct  1 02:34:47 2012
@@ -1395,14 +1395,17 @@
                                                      TemplArgs.size());
   D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
   D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
-  
-  if (D->isCanonicalDecl()) { // It's kept in the folding set.
+
+  bool writtenAsCanonicalDecl = Record[Idx++];
+  if (writtenAsCanonicalDecl) {
     ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
-    if (ClassTemplatePartialSpecializationDecl *Partial
-                       = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
-      CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
-    } else {
-      CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
+    if (D->isCanonicalDecl()) { // It's kept in the folding set.
+      if (ClassTemplatePartialSpecializationDecl *Partial
+                        = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
+       CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
+      } else {
+        CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
+      }
     }
   }
 }

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=164927&r1=164926&r2=164927&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Mon Oct  1 02:34:47 2012
@@ -1106,6 +1106,7 @@
   Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record);
   Writer.AddSourceLocation(D->getPointOfInstantiation(), Record);
   Record.push_back(D->getSpecializationKind());
+  Record.push_back(D->isCanonicalDecl());
 
   if (D->isCanonicalDecl()) {
     // When reading, we'll add it to the folding set of the following template. 

Modified: cfe/trunk/test/Modules/Inputs/redecl-merge-left.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/redecl-merge-left.h?rev=164927&r1=164926&r2=164927&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/redecl-merge-left.h (original)
+++ cfe/trunk/test/Modules/Inputs/redecl-merge-left.h Mon Oct  1 02:34:47 2012
@@ -82,6 +82,12 @@
 template<typename T> class Vector;
 
 template<typename T> class Vector;
+
+template<typename T> class List;
+template<> class List<bool> {
+public:
+  void push_back(int);
+};
 #endif
 
 // Make sure this doesn't introduce an ambiguity-creating 'id' at the

Modified: cfe/trunk/test/Modules/Inputs/redecl-merge-right.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/redecl-merge-right.h?rev=164927&r1=164926&r2=164927&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/redecl-merge-right.h (original)
+++ cfe/trunk/test/Modules/Inputs/redecl-merge-right.h Mon Oct  1 02:34:47 2012
@@ -83,6 +83,12 @@
 public:
   void push_back(const T&);
 };
+
+template<typename T> class List;
+template<> class List<bool> {
+public:
+  void push_back(int);
+};
 #endif
 
 int ONE;

Modified: cfe/trunk/test/Modules/Inputs/redecl-merge-top.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/redecl-merge-top.h?rev=164927&r1=164926&r2=164927&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/redecl-merge-top.h (original)
+++ cfe/trunk/test/Modules/Inputs/redecl-merge-top.h Mon Oct  1 02:34:47 2012
@@ -17,4 +17,9 @@
 
 #ifdef __cplusplus
 template<typename T> class Vector;
+
+template<typename T> class List {
+public:
+  void push_back(T);
+};
 #endif

Modified: cfe/trunk/test/Modules/redecl-merge.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/redecl-merge.m?rev=164927&r1=164926&r2=164927&view=diff
==============================================================================
--- cfe/trunk/test/Modules/redecl-merge.m (original)
+++ cfe/trunk/test/Modules/redecl-merge.m Mon Oct  1 02:34:47 2012
@@ -150,6 +150,9 @@
 void testVector() {
   Vector<int> vec_int;
   vec_int.push_back(0);
+
+  List<bool> list_bool;
+  list_bool.push_back(false);
 }
 #endif
 





More information about the cfe-commits mailing list