]> granicus.if.org Git - clang/commitdiff
Introduce PCHReader::GetTranslationUnitDecl() and use it instead of ReadDeclRecord...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 8 Jul 2010 17:13:02 +0000 (17:13 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 8 Jul 2010 17:13:02 +0000 (17:13 +0000)
ReadDeclRecord would hit assertion if the translation unit declaration was already loaded during
IdentifierInfo initialization.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107885 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/PCHReader.h
lib/Frontend/PCHReader.cpp

index 9f917391068378560ce777ceddef00a18f0aabae..3d29fccf8f1928e3699af8f30cf97d84b8e2c010 100644 (file)
@@ -616,6 +616,9 @@ public:
   TypeSourceInfo *GetTypeSourceInfo(const RecordData &Record,
                                     unsigned &Idx);
 
+  /// \brief Resolve and return the translation unit declaration.
+  TranslationUnitDecl *GetTranslationUnitDecl();
+
   /// \brief Resolve a type ID into a type, potentially building a new
   /// type.
   QualType GetType(pch::TypeID ID);
index 568d9ce77e6d5408e4fe5104c087fea1221ac84c..6acfdb29e4bfa5b2c77c8966f229eb113d6a33c1 100644 (file)
@@ -1702,7 +1702,7 @@ void PCHReader::InitializeContext(ASTContext &Ctx) {
   PP->setExternalSource(this);
 
   // Load the translation unit declaration
-  ReadDeclRecord(DeclOffsets[0], 0);
+  GetTranslationUnitDecl();
 
   // Load the special types.
   Context->setBuiltinVaListType(
@@ -2590,6 +2590,13 @@ Decl *PCHReader::GetExternalDecl(uint32_t ID) {
   return GetDecl(ID);
 }
 
+TranslationUnitDecl *PCHReader::GetTranslationUnitDecl() {
+  if (!DeclsLoaded[0])
+    ReadDeclRecord(DeclOffsets[0], 0);
+
+  return cast<TranslationUnitDecl>(DeclsLoaded[0]);
+}
+
 Decl *PCHReader::GetDecl(pch::DeclID ID) {
   if (ID == 0)
     return 0;