Skip to content

Commit 3cd0137

Browse files
authored
Revert "[RFC][C++20][Modules] Fix crash when function and lambda insi… (#108311)
…de loaded from different modules (#104512)" This reverts commit d778689.
1 parent 8287831 commit 3cd0137

File tree

6 files changed

+1
-174
lines changed

6 files changed

+1
-174
lines changed

clang/include/clang/Serialization/ASTReader.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,15 +1188,6 @@ 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 canonical declaration for lambda class from the
1193-
/// same module as enclosing function. This is required to correctly resolve
1194-
/// captured variables in the lambda. Without this, due to lazy
1195-
/// deserialization canonical declarations for the function and lambdas can
1196-
/// be from different modules and DeclRefExprs may refer to the AST nodes
1197-
/// that don't exist in the function.
1198-
SmallVector<GlobalDeclID, 4> PendingLambdas;
1199-
12001191
using DataPointers =
12011192
std::pair<CXXRecordDecl *, struct CXXRecordDecl::DefinitionData *>;
12021193
using ObjCInterfaceDataPointers =

clang/lib/Serialization/ASTReader.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9782,8 +9782,7 @@ void ASTReader::finishPendingActions() {
97829782
!PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() ||
97839783
!PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
97849784
!PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
9785-
!PendingObjCExtensionIvarRedeclarations.empty() ||
9786-
!PendingLambdas.empty()) {
9785+
!PendingObjCExtensionIvarRedeclarations.empty()) {
97879786
// If any identifiers with corresponding top-level declarations have
97889787
// been loaded, load those declarations now.
97899788
using TopLevelDeclsMap =
@@ -9928,11 +9927,6 @@ void ASTReader::finishPendingActions() {
99289927
}
99299928
PendingObjCExtensionIvarRedeclarations.pop_back();
99309929
}
9931-
9932-
// Load any pendiong lambdas.
9933-
for (auto ID : PendingLambdas)
9934-
GetDecl(ID);
9935-
PendingLambdas.clear();
99369930
}
99379931

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

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,16 +1155,6 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
11551155
for (unsigned I = 0; I != NumParams; ++I)
11561156
Params.push_back(readDeclAs<ParmVarDecl>());
11571157
FD->setParams(Reader.getContext(), Params);
1158-
1159-
// For the first decl add all lambdas inside for loading them later,
1160-
// otherwise skip them.
1161-
unsigned NumLambdas = Record.readInt();
1162-
if (FD->isFirstDecl()) {
1163-
for (unsigned I = 0; I != NumLambdas; ++I)
1164-
Reader.PendingLambdas.push_back(Record.readDeclID());
1165-
} else {
1166-
Record.skipInts(NumLambdas);
1167-
}
11681158
}
11691159

11701160
void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "clang/AST/Expr.h"
1919
#include "clang/AST/OpenMPClause.h"
2020
#include "clang/AST/PrettyDeclStackTrace.h"
21-
#include "clang/AST/StmtVisitor.h"
2221
#include "clang/Basic/SourceManager.h"
2322
#include "clang/Serialization/ASTReader.h"
2423
#include "clang/Serialization/ASTRecordWriter.h"
@@ -626,33 +625,6 @@ void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
626625
: QualType());
627626
}
628627

629-
static llvm::SmallVector<const Decl *, 2> collectLambdas(FunctionDecl *D) {
630-
struct LambdaCollector : public ConstStmtVisitor<LambdaCollector> {
631-
llvm::SmallVectorImpl<const Decl *> &Lambdas;
632-
633-
LambdaCollector(llvm::SmallVectorImpl<const Decl *> &Lambdas)
634-
: Lambdas(Lambdas) {}
635-
636-
void VisitLambdaExpr(const LambdaExpr *E) {
637-
VisitStmt(E);
638-
Lambdas.push_back(E->getLambdaClass());
639-
}
640-
641-
void VisitStmt(const Stmt *S) {
642-
if (!S)
643-
return;
644-
for (const Stmt *Child : S->children())
645-
if (Child)
646-
Visit(Child);
647-
}
648-
};
649-
650-
llvm::SmallVector<const Decl *, 2> Lambdas;
651-
if (D->hasBody())
652-
LambdaCollector(Lambdas).VisitStmt(D->getBody());
653-
return Lambdas;
654-
}
655-
656628
void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
657629
static_assert(DeclContext::NumFunctionDeclBits == 44,
658630
"You need to update the serializer after you change the "
@@ -792,19 +764,6 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
792764
Record.push_back(D->param_size());
793765
for (auto *P : D->parameters())
794766
Record.AddDeclRef(P);
795-
796-
// Store references to all lambda decls inside function to load them
797-
// immediately after loading the function to make sure that canonical
798-
// decls for lambdas will be from the same module.
799-
if (D->isCanonicalDecl()) {
800-
llvm::SmallVector<const Decl *, 2> Lambdas = collectLambdas(D);
801-
Record.push_back(Lambdas.size());
802-
for (const auto *L : Lambdas)
803-
Record.AddDeclRef(L);
804-
} else {
805-
Record.push_back(0);
806-
}
807-
808767
Code = serialization::DECL_FUNCTION;
809768
}
810769

@@ -2280,7 +2239,6 @@ getFunctionDeclAbbrev(serialization::DeclCode Code) {
22802239
//
22812240
// This is:
22822241
// NumParams and Params[] from FunctionDecl, and
2283-
// NumLambdas, Lambdas[] from FunctionDecl, and
22842242
// NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
22852243
//
22862244
// Add an AbbrevOp for 'size then elements' and use it here.

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

Lines changed: 0 additions & 76 deletions
This file was deleted.

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

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)