From 9fc18c97991b1267221ee71d13d8fb2f036b387b Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 26 Aug 2011 21:23:06 +0000 Subject: [PATCH] When we're deserializing declarations lexically stored in a RecordDecl after having already deserialized the fields, clear out the fields first. This makes sure that we keep all of the declarations in the lexical context (including those implicitly added by later type-checking) within the same list. A test case for this behavior is coming as part of another commit; testing for this problem in isolation is a nightmare. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138661 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/DeclBase.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 8b1acb1996..cb5846fc83 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -841,6 +841,22 @@ DeclContext::LoadLexicalDeclsFromExternalStorage() const { // Notify that we have a DeclContext that is initializing. ExternalASTSource::Deserializing ADeclContext(Source); + // We may have already loaded just the fields of this record, in which case + // we remove all of the fields from the list. The fields will be reloaded + // from the external source as part of re-establishing the context. + if (const RecordDecl *RD = dyn_cast(this)) { + if (RD->LoadedFieldsFromExternalStorage) { + while (FirstDecl && isa(FirstDecl)) { + Decl *Next = FirstDecl->NextDeclInContext; + FirstDecl->NextDeclInContext = 0; + FirstDecl = Next; + } + + if (!FirstDecl) + LastDecl = 0; + } + } + // Load the external declarations, if any. SmallVector Decls; ExternalLexicalStorage = false; @@ -856,14 +872,6 @@ DeclContext::LoadLexicalDeclsFromExternalStorage() const { if (Decls.empty()) return; - // We may have already loaded just the fields of this record, in which case - // don't add the decls, just replace the FirstDecl/LastDecl chain. - if (const RecordDecl *RD = dyn_cast(this)) - if (RD->LoadedFieldsFromExternalStorage) { - llvm::tie(FirstDecl, LastDecl) = BuildDeclChain(Decls); - return; - } - // Splice the newly-read declarations into the beginning of the list // of declarations. Decl *ExternalFirst, *ExternalLast; -- 2.50.1