[cfe-commits] r167425 - in /cfe/trunk: lib/Serialization/ASTReaderDecl.cpp lib/Serialization/ASTWriterDecl.cpp test/PCH/friend-template.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Mon Nov 5 16:35:02 PST 2012


Author: akirtzidis
Date: Mon Nov  5 18:35:02 2012
New Revision: 167425

URL: http://llvm.org/viewvc/llvm-project?rev=167425&view=rev
Log:
[PCH] Write out the ClassTemplateDecl::Common::InjectedClassNameType type
reference instead of relying on computing it.

In general, if storage is no issue, it is preferable to deserialize info from
the PCH instead of trying to recompute it after the PCH was loaded.

The incentive to change this now was due to r155303 changing how friend template
classes in dependent contexts are handled; such classes can now be chained to
a previous template class but the computed InjectedClassNameType may be different
due to the extra template parameters from the dependent context.

The new handling requires more investigation but, in the meantime, writing out
InjectedClassNameType fixes PCH issue in rdar://12627738.

Added:
    cfe/trunk/test/PCH/friend-template.cpp
Modified:
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/lib/Serialization/ASTWriterDecl.cpp

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=167425&r1=167424&r2=167425&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Mon Nov  5 18:35:02 2012
@@ -1353,10 +1353,10 @@
     for (unsigned I = 0; I != Size; ++I)
       SpecIDs.push_back(ReadDeclID(Record, Idx));
 
+    ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
     if (SpecIDs[0]) {
       typedef serialization::DeclID DeclID;
       
-      ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
       // FIXME: Append specializations!
       CommonPtr->LazySpecializations
         = new (Reader.getContext()) DeclID [SpecIDs.size()];
@@ -1364,7 +1364,7 @@
              SpecIDs.size() * sizeof(DeclID));
     }
     
-    // InjectedClassNameType is computed.
+    CommonPtr->InjectedClassNameType = Reader.readType(F, Record, Idx);
   }
 }
 

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=167425&r1=167424&r2=167425&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Mon Nov  5 18:35:02 2012
@@ -1084,7 +1084,7 @@
       Writer.AddDeclRef(&*I, Record); 
     }
 
-    // InjectedClassNameType is computed, no need to write it.
+    Writer.AddTypeRef(D->getCommonPtr()->InjectedClassNameType, Record);
   }
   Code = serialization::DECL_CLASS_TEMPLATE;
 }

Added: cfe/trunk/test/PCH/friend-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/friend-template.cpp?rev=167425&view=auto
==============================================================================
--- cfe/trunk/test/PCH/friend-template.cpp (added)
+++ cfe/trunk/test/PCH/friend-template.cpp Mon Nov  5 18:35:02 2012
@@ -0,0 +1,46 @@
+// Test this without pch.
+// RUN: %clang_cc1 -include %s -fsyntax-only -verify %s
+
+// Test with pch.
+// RUN: %clang_cc1 -emit-pch -o %t %s
+// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s 
+
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+// rdar://12627738
+namespace rdar12627738 {
+
+class RecyclerTag {
+    template <typename T> friend class Recycler;
+};
+
+}
+
+#else
+
+namespace rdar12627738 {
+
+template<typename TTag>
+class CRN {
+    template <typename T> friend class Recycler;
+};
+
+
+template<typename T>
+class Recycler {
+public:
+    Recycler ();
+};
+
+
+template<typename T>
+Recycler<T>::Recycler ()
+{
+}
+
+}
+
+#endif





More information about the cfe-commits mailing list