[cfe-commits] r107469 - in /cfe/trunk/lib/Frontend: PCHReaderDecl.cpp PCHWriterDecl.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Jul 2 04:55:01 PDT 2010


Author: akirtzidis
Date: Fri Jul  2 06:55:01 2010
New Revision: 107469

URL: http://llvm.org/viewvc/llvm-project?rev=107469&view=rev
Log:
Generally types expect an initialized TypeDecl; its safer and less complicated to delay PCH reading the type of a TypeDecl.

Modified:
    cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
    cfe/trunk/lib/Frontend/PCHWriterDecl.cpp

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=107469&r1=107468&r2=107469&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Fri Jul  2 06:55:01 2010
@@ -32,14 +32,17 @@
     PCHReader &Reader;
     const PCHReader::RecordData &Record;
     unsigned &Idx;
+    pch::TypeID TypeIDForTypeDecl;
 
   public:
     PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record,
                   unsigned &Idx)
-      : Reader(Reader), Record(Record), Idx(Idx) { }
+      : Reader(Reader), Record(Record), Idx(Idx), TypeIDForTypeDecl(0) { }
 
     CXXBaseSpecifier *ReadCXXBaseSpecifier();
 
+    void Visit(Decl *D);
+
     void VisitDecl(Decl *D);
     void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
     void VisitNamedDecl(NamedDecl *ND);
@@ -107,6 +110,14 @@
   };
 }
 
+void PCHDeclReader::Visit(Decl *D) {
+  DeclVisitor<PCHDeclReader, void>::Visit(D);
+
+  // if we have a fully initialized TypeDecl, we can safely read its type now.
+  if (TypeDecl *TD = dyn_cast<TypeDecl>(D))
+    TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtr());
+}
+
 void PCHDeclReader::VisitDecl(Decl *D) {
   D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
   D->setLexicalDeclContext(
@@ -134,17 +145,13 @@
 
 void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
   VisitNamedDecl(TD);
-  TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
+  // Delay type reading until after we have fully initialized the decl.
+  TypeIDForTypeDecl = Record[Idx++];
 }
 
 void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
-  // Note that we cannot use VisitTypeDecl here, because we need to
-  // set the underlying type of the typedef *before* we try to read
-  // the type associated with the TypedefDecl.
-  VisitNamedDecl(TD);
-  uint64_t TypeData = Record[Idx++];
+  VisitTypeDecl(TD);
   TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
-  TD->setTypeForDecl(Reader.GetType(TypeData).getTypePtr());
 }
 
 void PCHDeclReader::VisitTagDecl(TagDecl *TD) {

Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=107469&r1=107468&r2=107469&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Fri Jul  2 06:55:01 2010
@@ -137,14 +137,7 @@
 
 void PCHDeclWriter::VisitTypeDecl(TypeDecl *D) {
   VisitNamedDecl(D);
-  if (isa<CXXRecordDecl>(D)) {
-    // FIXME: Hack. To read a templated CXXRecordDecl from PCH, we need an
-    // initialized CXXRecordDecl before creating an InjectedClassNameType.
-    // Delay emitting/reading CXXRecordDecl's TypeForDecl until when we handle
-    // CXXRecordDecl emitting/initialization.
-    Writer.AddTypeRef(QualType(), Record);
-  } else
-    Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
+  Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
 }
 
 void PCHDeclWriter::VisitTypedefDecl(TypedefDecl *D) {





More information about the cfe-commits mailing list