diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-07-02 11:55:01 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-07-02 11:55:01 +0000 |
commit | d8a0c6f92c13b06f24ef894099b9fca1004d445b (patch) | |
tree | e3f973e1829eae684cda58767adafa95ec082ab5 /lib/Frontend/PCHReaderDecl.cpp | |
parent | b8b03e6df1cc89e701a809c6a47c41f31b7a9e50 (diff) |
Generally types expect an initialized TypeDecl; its safer and less complicated to delay PCH reading the type of a TypeDecl.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107469 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/PCHReaderDecl.cpp')
-rw-r--r-- | lib/Frontend/PCHReaderDecl.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp index 2bdf1662d5..443842d342 100644 --- a/lib/Frontend/PCHReaderDecl.cpp +++ b/lib/Frontend/PCHReaderDecl.cpp @@ -32,14 +32,17 @@ namespace clang { 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 @@ namespace clang { }; } +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::VisitNamedDecl(NamedDecl *ND) { 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) { |