summaryrefslogtreecommitdiffstats
path: root/clang/lib/Serialization/ASTReaderDecl.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2014-05-16 23:01:30 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2014-05-16 23:01:30 +0000
commit053f6c6c9e4d311e42e82ebb13b83d700080ba4c (patch)
tree1b6a14dd02fe58d435bc99bf79ebb44dfe28bdd0 /clang/lib/Serialization/ASTReaderDecl.cpp
parent7b12d773e36f738fc3c090e46a44b9a1544f1a9d (diff)
downloadbcm5719-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/ASTReaderDecl.cpp')
-rw-r--r--clang/lib/Serialization/ASTReaderDecl.cpp52
1 files changed, 27 insertions, 25 deletions
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index d2219d49812..719d56edf2c 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -1289,8 +1289,9 @@ void ASTDeclReader::ReadCXXDefinitionData(
void ASTDeclReader::MergeDefinitionData(
CXXRecordDecl *D, struct CXXRecordDecl::DefinitionData &MergeDD) {
- assert(D->DefinitionData && "merging class definition into non-definition");
- auto &DD = *D->DefinitionData;
+ assert(D->DefinitionData.getNotUpdated() &&
+ "merging class definition into non-definition");
+ auto &DD = *D->DefinitionData.getNotUpdated();
// If the new definition has new special members, let the name lookup
// code know that it needs to look in the new definition too.
@@ -1390,7 +1391,7 @@ void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D) {
// If we're reading an update record, we might already have a definition for
// this record. If so, just merge into it.
- if (D->DefinitionData) {
+ if (D->DefinitionData.getNotUpdated()) {
MergeDefinitionData(D, *DD);
return;
}
@@ -1399,25 +1400,26 @@ void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D) {
// that all other deserialized declarations will see it.
CXXRecordDecl *Canon = D->getCanonicalDecl();
if (Canon == D) {
- D->DefinitionData = DD;
+ D->DefinitionData.setNotUpdated(DD);
D->IsCompleteDefinition = true;
- } else if (!Canon->DefinitionData) {
- Canon->DefinitionData = D->DefinitionData = DD;
- D->IsCompleteDefinition = true;
-
- // Note that we have deserialized a definition. Any declarations
- // deserialized before this one will be be given the DefinitionData
- // pointer at the end.
- Reader.PendingDefinitions.insert(D);
- } else {
+ } else if (auto *CanonDD = Canon->DefinitionData.getNotUpdated()) {
// We have already deserialized a definition of this record. This
// definition is no longer really a definition. Note that the pre-existing
// definition is the *real* definition.
Reader.MergedDeclContexts.insert(
- std::make_pair(D, Canon->DefinitionData->Definition));
- D->DefinitionData = D->getCanonicalDecl()->DefinitionData;
+ std::make_pair(D, CanonDD->Definition));
+ D->DefinitionData = Canon->DefinitionData;
D->IsCompleteDefinition = false;
MergeDefinitionData(D, *DD);
+ } else {
+ Canon->DefinitionData.setNotUpdated(DD);
+ D->DefinitionData = Canon->DefinitionData;
+ D->IsCompleteDefinition = true;
+
+ // Note that we have deserialized a definition. Any declarations
+ // deserialized before this one will be be given the DefinitionData
+ // pointer at the end.
+ Reader.PendingDefinitions.insert(D);
}
}
@@ -1741,16 +1743,16 @@ ASTDeclReader::VisitClassTemplateSpecializationDeclImpl(
// This declaration might be a definition. Merge with any existing
// definition.
- if (D->DefinitionData) {
- if (!CanonSpec->DefinitionData) {
- CanonSpec->DefinitionData = D->DefinitionData;
- } else {
- MergeDefinitionData(CanonSpec, *D->DefinitionData);
+ if (auto *DDD = D->DefinitionData.getNotUpdated()) {
+ if (auto *CanonDD = CanonSpec->DefinitionData.getNotUpdated()) {
+ MergeDefinitionData(CanonSpec, *DDD);
Reader.PendingDefinitions.erase(D);
Reader.MergedDeclContexts.insert(
- std::make_pair(D, CanonSpec->DefinitionData->Definition));
+ std::make_pair(D, CanonDD->Definition));
D->IsCompleteDefinition = false;
D->DefinitionData = CanonSpec->DefinitionData;
+ } else {
+ CanonSpec->DefinitionData = D->DefinitionData;
}
}
}
@@ -2459,7 +2461,7 @@ ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) {
template<typename DeclT>
void ASTDeclReader::attachPreviousDeclImpl(Redeclarable<DeclT> *D,
Decl *Previous) {
- D->RedeclLink.setNext(cast<DeclT>(Previous));
+ D->RedeclLink.setPrevious(cast<DeclT>(Previous));
}
void ASTDeclReader::attachPreviousDeclImpl(...) {
llvm_unreachable("attachPreviousDecl on non-redeclarable declaration");
@@ -2489,7 +2491,7 @@ void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *Previous) {
template<typename DeclT>
void ASTDeclReader::attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest) {
- D->RedeclLink = Redeclarable<DeclT>::LatestDeclLink(cast<DeclT>(Latest));
+ D->RedeclLink.setLatest(cast<DeclT>(Latest));
}
void ASTDeclReader::attachLatestDeclImpl(...) {
llvm_unreachable("attachLatestDecl on non-redeclarable declaration");
@@ -2500,8 +2502,8 @@ void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) {
switch (D->getKind()) {
#define ABSTRACT_DECL(TYPE)
-#define DECL(TYPE, BASE) \
- case Decl::TYPE: \
+#define DECL(TYPE, BASE) \
+ case Decl::TYPE: \
attachLatestDeclImpl(cast<TYPE##Decl>(D), Latest); \
break;
#include "clang/AST/DeclNodes.inc"
OpenPOWER on IntegriCloud