diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-05-16 23:01:30 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-05-16 23:01:30 +0000 |
commit | 053f6c6c9e4d311e42e82ebb13b83d700080ba4c (patch) | |
tree | 1b6a14dd02fe58d435bc99bf79ebb44dfe28bdd0 /clang/lib/Serialization/ASTReader.cpp | |
parent | 7b12d773e36f738fc3c090e46a44b9a1544f1a9d (diff) | |
download | bcm5719-llvm-053f6c6c9e4d311e42e82ebb13b83d700080ba4c.tar.gz bcm5719-llvm-053f6c6c9e4d311e42e82ebb13b83d700080ba4c.zip |
If a declaration is loaded, and then a module import adds a redeclaration, then
ensure that querying the first declaration for its most recent declaration
checks for redeclarations from the imported module.
This works as follows:
* The 'most recent' pointer on a canonical declaration grows a pointer to the
external AST source and a generation number (space- and time-optimized for
the case where there is no external source).
* Each time the 'most recent' pointer is queried, if it has an external source,
we check whether it's up to date, and update it if not.
* The ancillary data stored on the canonical declaration is allocated lazily
to avoid filling it in for declarations that end up being non-canonical.
We'll still perform a redundant (ASTContext) allocation if someone asks for
the most recent declaration from a decl before setPreviousDecl is called,
but such cases are probably all bugs, and are now easy to find.
Some finessing is still in order here -- in particular, we use a very general
mechanism for handling the DefinitionData pointer on CXXRecordData, and a more
targeted approach would be more compact.
Also, the MayHaveOutOfDateDef mechanism should now be expunged, since it was
addressing only a corner of the full problem space here. That's not covered
by this patch.
Early performance benchmarks show that this makes no measurable difference to
Clang performance without modules enabled (and fixes a major correctness issue
with modules enabled). I'll revert if a full performance comparison shows any
problems.
llvm-svn: 209046
Diffstat (limited to 'clang/lib/Serialization/ASTReader.cpp')
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index d61372cc1bd..eb151ef16f6 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -1707,7 +1707,7 @@ void ASTReader::markIdentifierUpToDate(IdentifierInfo *II) { // Update the generation for this identifier. if (getContext().getLangOpts().Modules) - IdentifierGeneration[II] = CurrentGeneration; + IdentifierGeneration[II] = getGeneration(); } struct ASTReader::ModuleMacroInfo { @@ -3435,7 +3435,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, Deserializing AnASTFile(this); // Bump the generation number. - unsigned PreviousGeneration = CurrentGeneration++; + unsigned PreviousGeneration = incrementGeneration(Context); unsigned NumModules = ModuleMgr.size(); SmallVector<ImportedModule, 4> Loaded; @@ -3615,7 +3615,7 @@ ASTReader::ReadASTCore(StringRef FileName, std::string ErrorStr; ModuleManager::AddModuleResult AddResult = ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy, - CurrentGeneration, ExpectedSize, ExpectedModTime, + getGeneration(), ExpectedSize, ExpectedModTime, M, ErrorStr); switch (AddResult) { @@ -5939,6 +5939,37 @@ Decl *ASTReader::GetExternalDecl(uint32_t ID) { return GetDecl(ID); } +void ASTReader::CompleteRedeclChain(const Decl *D) { + const DeclContext *DC = D->getDeclContext()->getRedeclContext(); + + // Recursively ensure that the decl context itself is complete + // (in particular, this matters if the decl context is a namespace). + // + // FIXME: This should be performed by lookup instead of here. + cast<Decl>(DC)->getMostRecentDecl(); + + // If this is a named declaration, complete it by looking it up + // within its context. + // + // FIXME: We don't currently handle the cases where we can't do this; + // merging a class definition that contains unnamed entities should merge + // those entities. Likewise, merging a function definition should merge + // all mergeable entities within it. + if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC) || + isa<CXXRecordDecl>(DC) || isa<EnumDecl>(DC)) { + if (DeclarationName Name = cast<NamedDecl>(D)->getDeclName()) { + auto *II = Name.getAsIdentifierInfo(); + if (isa<TranslationUnitDecl>(DC) && II) { + // Outside of C++, we don't have a lookup table for the TU, so update + // the identifier instead. In C++, either way should work fine. + if (II->isOutOfDate()) + updateOutOfDateIdentifier(*II); + } else + DC->lookup(Name); + } + } +} + uint64_t ASTReader::readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record, unsigned &Idx) { @@ -6926,7 +6957,7 @@ void ASTReader::ReadMethodPool(Selector Sel) { // Get the selector generation and update it to the current generation. unsigned &Generation = SelectorGeneration[Sel]; unsigned PriorGeneration = Generation; - Generation = CurrentGeneration; + Generation = getGeneration(); // Search for methods defined with this selector. ++NumMethodPoolLookups; @@ -8114,7 +8145,6 @@ void ASTReader::finishPendingActions() { if (auto RD = dyn_cast<CXXRecordDecl>(*D)) { for (auto R : RD->redecls()) cast<CXXRecordDecl>(R)->DefinitionData = RD->DefinitionData; - } continue; @@ -8250,7 +8280,7 @@ ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot, AllowConfigurationMismatch(AllowConfigurationMismatch), ValidateSystemInputs(ValidateSystemInputs), UseGlobalIndex(UseGlobalIndex), TriedLoadingGlobalIndex(false), - CurrentGeneration(0), CurrSwitchCaseStmts(&SwitchCaseStmts), + CurrSwitchCaseStmts(&SwitchCaseStmts), NumSLocEntriesRead(0), TotalNumSLocEntries(0), NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0), NumIdentifierLookups(0), NumIdentifierLookupHits(0), NumSelectorsRead(0), |