Skip to content

Revert "[RFC][C++20][Modules] Fix crash when function and lambda insi… #108311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions clang/include/clang/Serialization/ASTReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -1188,15 +1188,6 @@ class ASTReader
/// once recursing loading has been completed.
llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks;

/// Lambdas that need to be loaded right after the function they belong to.
/// It is required to have canonical declaration for lambda class from the
/// same module as enclosing function. This is required to correctly resolve
/// captured variables in the lambda. Without this, due to lazy
/// deserialization canonical declarations for the function and lambdas can
/// be from different modules and DeclRefExprs may refer to the AST nodes
/// that don't exist in the function.
SmallVector<GlobalDeclID, 4> PendingLambdas;

using DataPointers =
std::pair<CXXRecordDecl *, struct CXXRecordDecl::DefinitionData *>;
using ObjCInterfaceDataPointers =
Expand Down
8 changes: 1 addition & 7 deletions clang/lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9782,8 +9782,7 @@ void ASTReader::finishPendingActions() {
!PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() ||
!PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
!PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
!PendingObjCExtensionIvarRedeclarations.empty() ||
!PendingLambdas.empty()) {
!PendingObjCExtensionIvarRedeclarations.empty()) {
// If any identifiers with corresponding top-level declarations have
// been loaded, load those declarations now.
using TopLevelDeclsMap =
Expand Down Expand Up @@ -9928,11 +9927,6 @@ void ASTReader::finishPendingActions() {
}
PendingObjCExtensionIvarRedeclarations.pop_back();
}

// Load any pendiong lambdas.
for (auto ID : PendingLambdas)
GetDecl(ID);
PendingLambdas.clear();
}

// At this point, all update records for loaded decls are in place, so any
Expand Down
10 changes: 0 additions & 10 deletions clang/lib/Serialization/ASTReaderDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,16 +1155,6 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
for (unsigned I = 0; I != NumParams; ++I)
Params.push_back(readDeclAs<ParmVarDecl>());
FD->setParams(Reader.getContext(), Params);

// For the first decl add all lambdas inside for loading them later,
// otherwise skip them.
unsigned NumLambdas = Record.readInt();
if (FD->isFirstDecl()) {
for (unsigned I = 0; I != NumLambdas; ++I)
Reader.PendingLambdas.push_back(Record.readDeclID());
} else {
Record.skipInts(NumLambdas);
}
}

void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Expand Down
42 changes: 0 additions & 42 deletions clang/lib/Serialization/ASTWriterDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "clang/AST/Expr.h"
#include "clang/AST/OpenMPClause.h"
#include "clang/AST/PrettyDeclStackTrace.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Serialization/ASTReader.h"
#include "clang/Serialization/ASTRecordWriter.h"
Expand Down Expand Up @@ -626,33 +625,6 @@ void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
: QualType());
}

static llvm::SmallVector<const Decl *, 2> collectLambdas(FunctionDecl *D) {
struct LambdaCollector : public ConstStmtVisitor<LambdaCollector> {
llvm::SmallVectorImpl<const Decl *> &Lambdas;

LambdaCollector(llvm::SmallVectorImpl<const Decl *> &Lambdas)
: Lambdas(Lambdas) {}

void VisitLambdaExpr(const LambdaExpr *E) {
VisitStmt(E);
Lambdas.push_back(E->getLambdaClass());
}

void VisitStmt(const Stmt *S) {
if (!S)
return;
for (const Stmt *Child : S->children())
if (Child)
Visit(Child);
}
};

llvm::SmallVector<const Decl *, 2> Lambdas;
if (D->hasBody())
LambdaCollector(Lambdas).VisitStmt(D->getBody());
return Lambdas;
}

void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
static_assert(DeclContext::NumFunctionDeclBits == 44,
"You need to update the serializer after you change the "
Expand Down Expand Up @@ -792,19 +764,6 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
Record.push_back(D->param_size());
for (auto *P : D->parameters())
Record.AddDeclRef(P);

// Store references to all lambda decls inside function to load them
// immediately after loading the function to make sure that canonical
// decls for lambdas will be from the same module.
if (D->isCanonicalDecl()) {
llvm::SmallVector<const Decl *, 2> Lambdas = collectLambdas(D);
Record.push_back(Lambdas.size());
for (const auto *L : Lambdas)
Record.AddDeclRef(L);
} else {
Record.push_back(0);
}

Code = serialization::DECL_FUNCTION;
}

Expand Down Expand Up @@ -2280,7 +2239,6 @@ getFunctionDeclAbbrev(serialization::DeclCode Code) {
//
// This is:
// NumParams and Params[] from FunctionDecl, and
// NumLambdas, Lambdas[] from FunctionDecl, and
// NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
//
// Add an AbbrevOp for 'size then elements' and use it here.
Expand Down
76 changes: 0 additions & 76 deletions clang/test/Headers/crash-instantiated-in-scope-cxx-modules.cpp

This file was deleted.

30 changes: 0 additions & 30 deletions clang/test/Headers/crash-instantiated-in-scope-cxx-modules2.cpp

This file was deleted.

Loading