Skip to content

Commit b5f6a30

Browse files
committed
Delay loading lambdas
1 parent db65f69 commit b5f6a30

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

clang/include/clang/Serialization/ASTReader.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,11 @@ class ASTReader
11881188
/// once recursing loading has been completed.
11891189
llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks;
11901190

1191+
/// Lambdas that need to be loaded right after the function they belong to.
1192+
/// It is required to have the right canonical declaration for lambda class
1193+
/// from the same module as the function.
1194+
SmallVector<GlobalDeclID, 4> PendingLambdas;
1195+
11911196
using DataPointers =
11921197
std::pair<CXXRecordDecl *, struct CXXRecordDecl::DefinitionData *>;
11931198
using ObjCInterfaceDataPointers =

clang/lib/Serialization/ASTReader.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9782,7 +9782,8 @@ void ASTReader::finishPendingActions() {
97829782
!PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() ||
97839783
!PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
97849784
!PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
9785-
!PendingObjCExtensionIvarRedeclarations.empty()) {
9785+
!PendingObjCExtensionIvarRedeclarations.empty() ||
9786+
!PendingLambdas.empty()) {
97869787
// If any identifiers with corresponding top-level declarations have
97879788
// been loaded, load those declarations now.
97889789
using TopLevelDeclsMap =
@@ -9927,6 +9928,11 @@ void ASTReader::finishPendingActions() {
99279928
}
99289929
PendingObjCExtensionIvarRedeclarations.pop_back();
99299930
}
9931+
9932+
// Load any pendiong lambdas.
9933+
for (auto ID : PendingLambdas)
9934+
GetDecl(ID);
9935+
PendingLambdas.clear();
99309936
}
99319937

99329938
// At this point, all update records for loaded decls are in place, so any

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,11 +1156,12 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
11561156
Params.push_back(readDeclAs<ParmVarDecl>());
11571157
FD->setParams(Reader.getContext(), Params);
11581158

1159-
// For the first decl read all lambdas inside, otherwise skip them.
1159+
// For the first decl add all lambdas inside for loading them later,
1160+
// otherwise skip them.
11601161
unsigned NumLambdas = Record.readInt();
11611162
if (FD->isFirstDecl()) {
11621163
for (unsigned I = 0; I != NumLambdas; ++I)
1163-
readDecl();
1164+
Reader.PendingLambdas.push_back(Record.readDeclID());
11641165
} else {
11651166
(void)Record.readIntArray(NumLambdas);
11661167
}

clang/test/Headers/crash-instantiated-in-scope-cxx-modules2.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ struct B {
2323
});
2424
}
2525
};
26-
2726
// expected-no-diagnostics
2827

2928
//--- main.cpp

0 commit comments

Comments
 (0)