Skip to content

[C++20] [Modules] Merge lambdas from Sema to imported one #103036

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

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 0 additions & 11 deletions clang/lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8962,17 +8962,6 @@ void ASTReader::ReadLateParsedTemplates(
LateParsedTemplates.clear();
}

void ASTReader::AssignedLambdaNumbering(const CXXRecordDecl *Lambda) {
if (Lambda->getLambdaContextDecl()) {
// Keep track of this lambda so it can be merged with another lambda that
// is loaded later.
LambdaDeclarationsForMerging.insert(
{{Lambda->getLambdaContextDecl()->getCanonicalDecl(),
Lambda->getLambdaIndexInContext()},
const_cast<CXXRecordDecl *>(Lambda)});
}
}

void ASTReader::LoadSelector(Selector Sel) {
// It would be complicated to avoid reading the methods anyway. So don't.
ReadMethodPool(Sel);
Expand Down
28 changes: 28 additions & 0 deletions clang/lib/Serialization/ASTReaderDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4506,6 +4506,34 @@ void ASTReader::loadObjCCategories(GlobalDeclID ID, ObjCInterfaceDecl *D,
ModuleMgr.visit(Visitor);
}

void ASTReader::AssignedLambdaNumbering(const CXXRecordDecl *Lambda) {
if (Lambda->getLambdaContextDecl()) {
auto ContextAndIndexPair = std::make_pair<const Decl *, unsigned>(
Lambda->getLambdaContextDecl()->getCanonicalDecl(),
Lambda->getLambdaIndexInContext());

auto Iter = LambdaDeclarationsForMerging.find(ContextAndIndexPair);
// If we import first and then include second, try to merge the second
// one with the first one.
if (Iter != LambdaDeclarationsForMerging.end() &&
Iter->second->isFromASTFile()) {
NamedDecl *Slot = Iter->second;
ASTDeclMerger Merger(*this);
// The lambda shouldn't be a key declaration as the lambda wouldn't
// be a canonical decl for its owning module.
Merger.mergeRedeclarableImpl(const_cast<CXXRecordDecl *>(Lambda),
cast<TagDecl>(Slot),
/*KeyDeclID*/ GlobalDeclID());
return;
}

// Keep track of this lambda so it can be merged with another lambda that
// is loaded later.
LambdaDeclarationsForMerging.insert(
{ContextAndIndexPair, const_cast<CXXRecordDecl *>(Lambda)});
}
}

template<typename DeclT, typename Fn>
static void forAllLaterRedecls(DeclT *D, Fn F) {
F(D);
Expand Down
33 changes: 33 additions & 0 deletions clang/test/Modules/pr102721.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: split-file %s %t
//
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
// RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-module-interface -o %t/b.pcm \
// RUN: -fprebuilt-module-path=%t
// RUN: %clang_cc1 -std=c++20 %t/test.cc -fsyntax-only -verify \
// RUN: -fprebuilt-module-path=%t

//--- foo.h
inline auto x = []{};

//--- a.cppm
module;
#include "foo.h"
export module a;
export using ::x;

//--- b.cppm
module;
import a;
#include "foo.h"
export module b;
export using ::x;

//--- test.cc
// expected-no-diagnostics
import a;
import b;
void test() {
x();
}
Loading