r207603 - Defer loading any pending update records until we've finished deserializing.
Richard Smith
richard-llvm at metafoo.co.uk
Tue Apr 29 19:24:17 PDT 2014
Author: rsmith
Date: Tue Apr 29 21:24:17 2014
New Revision: 207603
URL: http://llvm.org/viewvc/llvm-project?rev=207603&view=rev
Log:
Defer loading any pending update records until we've finished deserializing.
This fixes a bug where an update record causes us to load an entity that refers
to an entity we've not finished loading yet, resulting in badness.
Modified:
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/test/Modules/Inputs/templates-left.h
cfe/trunk/test/Modules/Inputs/templates-top.h
cfe/trunk/test/Modules/templates.mm
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=207603&r1=207602&r2=207603&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Apr 29 21:24:17 2014
@@ -3430,6 +3430,9 @@ ASTReader::ASTReadResult ASTReader::Read
llvm::SaveAndRestore<SourceLocation>
SetCurImportLocRAII(CurrentImportLoc, ImportLoc);
+ // Defer any pending actions until we get to the end of reading the AST file.
+ Deserializing AnASTFile(this);
+
// Bump the generation number.
unsigned PreviousGeneration = CurrentGeneration++;
@@ -3742,24 +3745,6 @@ void ASTReader::InitializeContext() {
DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID,
Context.getTranslationUnitDecl());
- // For any declarations we have already loaded, load any update records.
- {
- // We're not back to a consistent state until all our pending update
- // records have been loaded. There can be interdependencies between them.
- Deserializing SomeUpdateRecords(this);
- ReadingKindTracker ReadingKind(Read_Decl, *this);
-
- // Make sure we load the declaration update records for the translation
- // unit, if there are any.
- // FIXME: Is this necessary any more?
- loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID,
- Context.getTranslationUnitDecl());
-
- for (auto &Update : PendingUpdateRecords)
- loadDeclUpdateRecords(Update.first, Update.second);
- PendingUpdateRecords.clear();
- }
-
// FIXME: Find a better way to deal with collisions between these
// built-in types. Right now, we just ignore the problem.
@@ -8057,6 +8042,13 @@ void ASTReader::finishPendingActions() {
Info.D->setDeclContextsImpl(SemaDC, LexicalDC, getContext());
}
+ // Perform any pending declaration updates.
+ while (!PendingUpdateRecords.empty()) {
+ auto Update = PendingUpdateRecords.pop_back_val();
+ ReadingKindTracker ReadingKind(Read_Decl, *this);
+ loadDeclUpdateRecords(Update.first, Update.second);
+ }
+
// Trigger the import of the full definition of each class that had any
// odr-merging problems, so we can produce better diagnostics for them.
for (auto &Merge : PendingOdrMergeFailures) {
Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=207603&r1=207602&r2=207603&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Tue Apr 29 21:24:17 2014
@@ -2801,7 +2801,7 @@ Decl *ASTReader::ReadDeclRecord(DeclID I
assert(Idx == Record.size());
// Load any relevant update records.
- loadDeclUpdateRecords(ID, D);
+ PendingUpdateRecords.push_back(std::make_pair(ID, D));
// Load the categories after recursive loading is finished.
if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(D))
Modified: cfe/trunk/test/Modules/Inputs/templates-left.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/templates-left.h?rev=207603&r1=207602&r2=207603&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/templates-left.h (original)
+++ cfe/trunk/test/Modules/Inputs/templates-left.h Tue Apr 29 21:24:17 2014
@@ -51,3 +51,8 @@ void useExplicitInstantiation() {
ExplicitInstantiation<true, false>().f();
ExplicitInstantiation<true, true>().f();
}
+
+template<typename> struct DelayUpdates;
+template<> struct DelayUpdates<int>;
+template<typename T> struct DelayUpdates<T*>;
+template<typename T> void testDelayUpdates(DelayUpdates<T> *p = 0) {}
Modified: cfe/trunk/test/Modules/Inputs/templates-top.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/templates-top.h?rev=207603&r1=207602&r2=207603&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/templates-top.h (original)
+++ cfe/trunk/test/Modules/Inputs/templates-top.h Tue Apr 29 21:24:17 2014
@@ -29,3 +29,5 @@ template<typename T> struct Outer {
template<bool, bool> struct ExplicitInstantiation {
void f() {}
};
+
+template<typename> struct DelayUpdates {};
Modified: cfe/trunk/test/Modules/templates.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/templates.mm?rev=207603&r1=207602&r2=207603&view=diff
==============================================================================
--- cfe/trunk/test/Modules/templates.mm (original)
+++ cfe/trunk/test/Modules/templates.mm Tue Apr 29 21:24:17 2014
@@ -84,3 +84,5 @@ template<typename T> void MergePatternDe
// CHECK: define {{.*}}@_ZN21ExplicitInstantiationILb0ELb1EE1fEv(
template struct ExplicitInstantiation<false, true>;
template struct ExplicitInstantiation<true, true>;
+
+void testDelayUpdatesImpl() { testDelayUpdates<int>(); }
More information about the cfe-commits
mailing list