From: Richard Smith Date: Fri, 8 Apr 2016 20:53:26 +0000 (+0000) Subject: PR25501: Delay loading visible updates for a declaration until after we've X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7bcddb410f4af6c0a01018cb482e82c25756342b;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265848 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 47ac407675..efb7793ef6 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -3436,20 +3436,6 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) { } 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(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(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(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, ModuleFile &ModuleFile, case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { auto *RD = cast(D); - auto *OldDD = RD->DefinitionData.getNotUpdated(); + auto *OldDD = RD->getCanonicalDecl()->DefinitionData.getNotUpdated(); bool HadRealDefinition = OldDD && (OldDD->Definition != RD || !Reader.PendingFakeDefinitionData.count(OldDD)); diff --git a/test/Modules/Inputs/PR25501/Vector.h b/test/Modules/Inputs/PR25501/Vector.h new file mode 100644 index 0000000000..9da48303a3 --- /dev/null +++ b/test/Modules/Inputs/PR25501/Vector.h @@ -0,0 +1,5 @@ +template struct _Vector_base {}; +struct vector { + vector() {} + vector(_Vector_base); +}; diff --git a/test/Modules/Inputs/PR25501/a0.h b/test/Modules/Inputs/PR25501/a0.h new file mode 100644 index 0000000000..1a0d306ca7 --- /dev/null +++ b/test/Modules/Inputs/PR25501/a0.h @@ -0,0 +1 @@ +#include "Vector.h" diff --git a/test/Modules/Inputs/PR25501/a1.h b/test/Modules/Inputs/PR25501/a1.h new file mode 100644 index 0000000000..1a0d306ca7 --- /dev/null +++ b/test/Modules/Inputs/PR25501/a1.h @@ -0,0 +1 @@ +#include "Vector.h" diff --git a/test/Modules/Inputs/PR25501/a2.h b/test/Modules/Inputs/PR25501/a2.h new file mode 100644 index 0000000000..7876f310e8 --- /dev/null +++ b/test/Modules/Inputs/PR25501/a2.h @@ -0,0 +1,3 @@ +#include "a0.h" +vector aaa = vector(); +#include "a1.h" diff --git a/test/Modules/Inputs/PR25501/b.h b/test/Modules/Inputs/PR25501/b.h new file mode 100644 index 0000000000..7b51983695 --- /dev/null +++ b/test/Modules/Inputs/PR25501/b.h @@ -0,0 +1,2 @@ +#include "Vector.h" +vector aaa = vector(); diff --git a/test/Modules/Inputs/PR25501/module.modulemap b/test/Modules/Inputs/PR25501/module.modulemap new file mode 100644 index 0000000000..c6c8d5ca40 --- /dev/null +++ b/test/Modules/Inputs/PR25501/module.modulemap @@ -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 * } diff --git a/test/Modules/pr25501.cpp b/test/Modules/pr25501.cpp new file mode 100644 index 0000000000..18002d6dff --- /dev/null +++ b/test/Modules/pr25501.cpp @@ -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