Skip to content

Commit 3134ad3

Browse files
committed
[clang][modules] Only update the generation number if the update was not delayed.
1 parent e3aebf1 commit 3134ad3

File tree

8 files changed

+32
-25
lines changed

8 files changed

+32
-25
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3730,7 +3730,7 @@ inline void operator delete[](void *Ptr, const clang::ASTContext &C, size_t) {
37303730

37313731
/// Create the representation of a LazyGenerationalUpdatePtr.
37323732
template <typename Owner, typename T,
3733-
void (clang::ExternalASTSource::*Update)(Owner)>
3733+
bool (clang::ExternalASTSource::*Update)(Owner)>
37343734
typename clang::LazyGenerationalUpdatePtr<Owner, T, Update>::ValueType
37353735
clang::LazyGenerationalUpdatePtr<Owner, T, Update>::makeValue(
37363736
const clang::ASTContext &Ctx, T Value) {

clang/include/clang/AST/ExternalASTSource.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,9 @@ class ExternalASTSource : public RefCountedBase<ExternalASTSource> {
220220
/// Gives the external AST source an opportunity to complete
221221
/// the redeclaration chain for a declaration. Called each time we
222222
/// need the most recent declaration of a declaration after the
223-
/// generation count is incremented.
224-
virtual void CompleteRedeclChain(const Decl *D);
223+
/// generation count is incremented. Returns true if the redeclaration
224+
/// chain completion was completed.
225+
virtual bool CompleteRedeclChain(const Decl *D);
225226

226227
/// Gives the external AST source an opportunity to complete
227228
/// an incomplete type.
@@ -437,7 +438,7 @@ struct LazyOffsetPtr {
437438
/// A lazy value (of type T) that is within an AST node of type Owner,
438439
/// where the value might change in later generations of the external AST
439440
/// source.
440-
template<typename Owner, typename T, void (ExternalASTSource::*Update)(Owner)>
441+
template<typename Owner, typename T, bool (ExternalASTSource::*Update)(Owner)>
441442
struct LazyGenerationalUpdatePtr {
442443
/// A cache of the value of this pointer, in the most recent generation in
443444
/// which we queried it.
@@ -487,9 +488,9 @@ struct LazyGenerationalUpdatePtr {
487488
/// Get the value of this pointer, updating its owner if necessary.
488489
T get(Owner O) {
489490
if (auto *LazyVal = Value.template dyn_cast<LazyData *>()) {
490-
if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) {
491+
if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration() &&
492+
(LazyVal->ExternalSource->*Update)(O)) {
491493
LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration();
492-
(LazyVal->ExternalSource->*Update)(O);
493494
}
494495
return LazyVal->LastValue;
495496
}
@@ -516,7 +517,7 @@ namespace llvm {
516517
/// Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be
517518
/// placed into a PointerUnion.
518519
template<typename Owner, typename T,
519-
void (clang::ExternalASTSource::*Update)(Owner)>
520+
bool (clang::ExternalASTSource::*Update)(Owner)>
520521
struct PointerLikeTypeTraits<
521522
clang::LazyGenerationalUpdatePtr<Owner, T, Update>> {
522523
using Ptr = clang::LazyGenerationalUpdatePtr<Owner, T, Update>;

clang/include/clang/Sema/MultiplexExternalSemaSource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class MultiplexExternalSemaSource : public ExternalSemaSource {
6969

7070
/// Complete the redeclaration chain if it's been extended since the
7171
/// previous generation of the AST source.
72-
void CompleteRedeclChain(const Decl *D) override;
72+
bool CompleteRedeclChain(const Decl *D) override;
7373

7474
/// Resolve a selector ID into a selector.
7575
Selector GetExternalSelector(uint32_t ID) override;

clang/include/clang/Serialization/ASTReader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ class ASTReader
12261226

12271227
/// The list of canonical declarations whose redeclaration chains
12281228
/// need to be marked as incomplete once we're done deserializing things.
1229-
SmallVector<Decl *, 16> PendingIncompleteDeclChains;
1229+
llvm::SmallPtrSet<Decl *, 16> PendingIncompleteDeclChains;
12301230

12311231
/// The Decl IDs for the Sema/Lexical DeclContext of a Decl that has
12321232
/// been loaded but its DeclContext was not set yet.
@@ -2135,7 +2135,7 @@ class ASTReader
21352135
/// If any redeclarations of \p D have been imported since it was
21362136
/// last checked, this digs out those redeclarations and adds them to the
21372137
/// redeclaration chain for \p D.
2138-
void CompleteRedeclChain(const Decl *D) override;
2138+
bool CompleteRedeclChain(const Decl *D) override;
21392139

21402140
CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
21412141

clang/lib/AST/ExternalASTSource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void ExternalASTSource::FindFileRegionDecls(FileID File, unsigned Offset,
4242
unsigned Length,
4343
SmallVectorImpl<Decl *> &Decls) {}
4444

45-
void ExternalASTSource::CompleteRedeclChain(const Decl *D) {}
45+
bool ExternalASTSource::CompleteRedeclChain(const Decl *D) { return true; }
4646

4747
void ExternalASTSource::CompleteType(TagDecl *Tag) {}
4848

clang/lib/Sema/MultiplexExternalSemaSource.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ Decl *MultiplexExternalSemaSource::GetExternalDecl(GlobalDeclID ID) {
5353
return nullptr;
5454
}
5555

56-
void MultiplexExternalSemaSource::CompleteRedeclChain(const Decl *D) {
57-
for (size_t i = 0; i < Sources.size(); ++i)
58-
Sources[i]->CompleteRedeclChain(D);
56+
bool MultiplexExternalSemaSource::CompleteRedeclChain(const Decl *D) {
57+
bool Result = true;
58+
for (ExternalSemaSource *Source : Sources)
59+
Result &= Source->CompleteRedeclChain(D);
60+
return Result;
5961
}
6062

6163
Selector MultiplexExternalSemaSource::GetExternalSelector(uint32_t ID) {

clang/lib/Serialization/ASTReader.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7825,19 +7825,19 @@ ASTRecordReader::readASTTemplateArgumentListInfo() {
78257825

78267826
Decl *ASTReader::GetExternalDecl(GlobalDeclID ID) { return GetDecl(ID); }
78277827

7828-
void ASTReader::CompleteRedeclChain(const Decl *D) {
7828+
bool ASTReader::CompleteRedeclChain(const Decl *D) {
78297829
if (NumCurrentElementsDeserializing) {
78307830
// We arrange to not care about the complete redeclaration chain while we're
78317831
// deserializing. Just remember that the AST has marked this one as complete
78327832
// but that it's not actually complete yet, so we know we still need to
78337833
// complete it later.
7834-
PendingIncompleteDeclChains.push_back(const_cast<Decl*>(D));
7835-
return;
7834+
PendingIncompleteDeclChains.insert(const_cast<Decl*>(D));
7835+
return false;
78367836
}
78377837

78387838
if (!D->getDeclContext()) {
78397839
assert(isa<TranslationUnitDecl>(D) && "Not a TU?");
7840-
return;
7840+
return true;
78417841
}
78427842

78437843
const DeclContext *DC = D->getDeclContext()->getRedeclContext();
@@ -7894,6 +7894,8 @@ void ASTReader::CompleteRedeclChain(const Decl *D) {
78947894
else
78957895
Template->loadLazySpecializationsImpl(Args);
78967896
}
7897+
7898+
return true;
78977899
}
78987900

78997901
CXXCtorInitializer **
@@ -10233,8 +10235,8 @@ void ASTReader::finishPendingActions() {
1023310235

1023410236
// For each decl chain that we wanted to complete while deserializing, mark
1023510237
// it as "still needs to be completed".
10236-
for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
10237-
markIncompleteDeclChain(PendingIncompleteDeclChains[I]);
10238+
for (Decl* D : PendingIncompleteDeclChains) {
10239+
markIncompleteDeclChain(D);
1023810240
}
1023910241
PendingIncompleteDeclChains.clear();
1024010242

lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ class ExternalASTSourceWrapper : public clang::ExternalSemaSource {
117117
m_Source->FindFileRegionDecls(File, Offset, Length, Decls);
118118
}
119119

120-
void CompleteRedeclChain(const clang::Decl *D) override {
121-
m_Source->CompleteRedeclChain(D);
120+
bool CompleteRedeclChain(const clang::Decl *D) override {
121+
return m_Source->CompleteRedeclChain(D);
122122
}
123123

124124
void CompleteType(clang::TagDecl *Tag) override {
@@ -334,9 +334,11 @@ class SemaSourceWithPriorities : public clang::ExternalSemaSource {
334334
return newDeclFound;
335335
}
336336

337-
void CompleteRedeclChain(const clang::Decl *D) override {
338-
for (size_t i = 0; i < Sources.size(); ++i)
339-
Sources[i]->CompleteRedeclChain(D);
337+
bool CompleteRedeclChain(const clang::Decl *D) override {
338+
bool Result = true;
339+
for (clang::ExternalSemaSource *Source : Sources)
340+
Result &= Source->CompleteRedeclChain(D);
341+
return Result;
340342
}
341343

342344
clang::Selector GetExternalSelector(uint32_t ID) override {

0 commit comments

Comments
 (0)