Author: rsmith Date: Fri Apr 8 15:53:26 2016 New Revision: 265848 URL: http://llvm.org/viewvc/llvm-project?rev=265848&view=rev Log: PR25501: Delay loading visible updates for a declaration until after we've processed update records. If an update record adds a definition, we need to merge that with any pre-existing definition to determine which the canonical definition is before we apply the visible update, otherwise we wouldn't know where to apply it.
Thanks to Vassil Vassilev for help reducing this and tracking down the problem. Added: cfe/trunk/test/Modules/Inputs/PR25501/ cfe/trunk/test/Modules/Inputs/PR25501/Vector.h cfe/trunk/test/Modules/Inputs/PR25501/a0.h cfe/trunk/test/Modules/Inputs/PR25501/a1.h cfe/trunk/test/Modules/Inputs/PR25501/a2.h cfe/trunk/test/Modules/Inputs/PR25501/b.h cfe/trunk/test/Modules/Inputs/PR25501/module.modulemap cfe/trunk/test/Modules/pr25501.cpp Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=265848&r1=265847&r2=265848&view=diff ============================================================================== --- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original) +++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Fri Apr 8 15:53:26 2016 @@ -3436,20 +3436,6 @@ Decl *ASTReader::ReadDeclRecord(DeclID I } void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) { - // Load the pending visible updates for this decl context, if it has any. - auto I = PendingVisibleUpdates.find(ID); - if (I != PendingVisibleUpdates.end()) { - auto VisibleUpdates = std::move(I->second); - PendingVisibleUpdates.erase(I); - - auto *DC = cast<DeclContext>(D)->getPrimaryContext(); - for (const PendingVisibleUpdate &Update : VisibleUpdates) - Lookups[DC].Table.add( - Update.Mod, Update.Data, - reader::ASTDeclContextNameLookupTrait(*this, *Update.Mod)); - DC->setHasExternalVisibleStorage(true); - } - // The declaration may have been modified by files later in the chain. // If this is the case, read the record containing the updates from each file // and pass it to ASTDeclReader to make the modifications. @@ -3485,6 +3471,20 @@ void ASTReader::loadDeclUpdateRecords(se } } } + + // Load the pending visible updates for this decl context, if it has any. + auto I = PendingVisibleUpdates.find(ID); + if (I != PendingVisibleUpdates.end()) { + auto VisibleUpdates = std::move(I->second); + PendingVisibleUpdates.erase(I); + + auto *DC = cast<DeclContext>(D)->getPrimaryContext(); + for (const PendingVisibleUpdate &Update : VisibleUpdates) + Lookups[DC].Table.add( + Update.Mod, Update.Data, + reader::ASTDeclContextNameLookupTrait(*this, *Update.Mod)); + DC->setHasExternalVisibleStorage(true); + } } void ASTReader::loadPendingDeclChain(Decl *FirstLocal, uint64_t LocalOffset) { @@ -3757,7 +3757,7 @@ void ASTDeclReader::UpdateDecl(Decl *D, case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { auto *RD = cast<CXXRecordDecl>(D); - auto *OldDD = RD->DefinitionData.getNotUpdated(); + auto *OldDD = RD->getCanonicalDecl()->DefinitionData.getNotUpdated(); bool HadRealDefinition = OldDD && (OldDD->Definition != RD || !Reader.PendingFakeDefinitionData.count(OldDD)); Added: cfe/trunk/test/Modules/Inputs/PR25501/Vector.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR25501/Vector.h?rev=265848&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/PR25501/Vector.h (added) +++ cfe/trunk/test/Modules/Inputs/PR25501/Vector.h Fri Apr 8 15:53:26 2016 @@ -0,0 +1,5 @@ +template <typename> struct _Vector_base {}; +struct vector { + vector() {} + vector(_Vector_base<int>); +}; Added: cfe/trunk/test/Modules/Inputs/PR25501/a0.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR25501/a0.h?rev=265848&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/PR25501/a0.h (added) +++ cfe/trunk/test/Modules/Inputs/PR25501/a0.h Fri Apr 8 15:53:26 2016 @@ -0,0 +1 @@ +#include "Vector.h" Added: cfe/trunk/test/Modules/Inputs/PR25501/a1.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR25501/a1.h?rev=265848&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/PR25501/a1.h (added) +++ cfe/trunk/test/Modules/Inputs/PR25501/a1.h Fri Apr 8 15:53:26 2016 @@ -0,0 +1 @@ +#include "Vector.h" Added: cfe/trunk/test/Modules/Inputs/PR25501/a2.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR25501/a2.h?rev=265848&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/PR25501/a2.h (added) +++ cfe/trunk/test/Modules/Inputs/PR25501/a2.h Fri Apr 8 15:53:26 2016 @@ -0,0 +1,3 @@ +#include "a0.h" +vector aaa = vector(); +#include "a1.h" Added: cfe/trunk/test/Modules/Inputs/PR25501/b.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR25501/b.h?rev=265848&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/PR25501/b.h (added) +++ cfe/trunk/test/Modules/Inputs/PR25501/b.h Fri Apr 8 15:53:26 2016 @@ -0,0 +1,2 @@ +#include "Vector.h" +vector aaa = vector(); Added: cfe/trunk/test/Modules/Inputs/PR25501/module.modulemap URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR25501/module.modulemap?rev=265848&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/PR25501/module.modulemap (added) +++ cfe/trunk/test/Modules/Inputs/PR25501/module.modulemap Fri Apr 8 15:53:26 2016 @@ -0,0 +1,4 @@ +module "a0" { header "a0.h" export * } +module "a1" { header "a1.h" export * } +module "a2" { header "a2.h" export * } +module "b" { header "b.h" export * } Added: cfe/trunk/test/Modules/pr25501.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/pr25501.cpp?rev=265848&view=auto ============================================================================== --- cfe/trunk/test/Modules/pr25501.cpp (added) +++ cfe/trunk/test/Modules/pr25501.cpp Fri Apr 8 15:53:26 2016 @@ -0,0 +1,9 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -std=c++11 -fmodules -fmodule-map-file=%S/Inputs/PR25501/module.modulemap -fmodules-cache-path=%t -I%S/Inputs/PR25501 -verify %s + +#include "a2.h" +#include "b.h" + +auto use = aaa; + +// expected-no-diagnostics _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits