Skip to content

[clang][modules] Remove the workaround for the lambda issue. #142547

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
31 changes: 1 addition & 30 deletions clang/lib/AST/DeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1702,36 +1702,7 @@ static NamedDecl* getLambdaCallOperatorHelper(const CXXRecordDecl &RD) {

assert(allLookupResultsAreTheSame(Calls) &&
"More than one lambda call operator!");

// FIXME: If we have multiple call operators, we might be in a situation
// where we merged this lambda with one from another module; in that
// case, return our method (instead of that of the other lambda).
//
// This avoids situations where, given two modules A and B, if we
// try to instantiate A's call operator in a function in B, anything
// in the call operator that relies on local decls in the surrounding
// function will crash because it tries to find A's decls, but we only
// instantiated B's:
//
// template <typename>
// void f() {
// using T = int; // We only instantiate B's version of this.
// auto L = [](T) { }; // But A's call operator would want A's here.
// }
//
// Walk the call operator’s redecl chain to find the one that belongs
// to this module.
//
// TODO: We need to fix this properly (see
// https://github.com/llvm/llvm-project/issues/90154).
Module *M = RD.getOwningModule();
for (Decl *D : Calls.front()->redecls()) {
auto *MD = cast<NamedDecl>(D);
if (MD->getOwningModule() == M)
return MD;
}

llvm_unreachable("Couldn't find our call operator!");
return Calls.front();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add an assert that the call we returned comes from the same module with RD.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, adding assert(Calls.front()->getOwningModule() == RD.getOwningModule() I see two lambda-merging test breakages:

  • Modules/lambda-merge.cpp
  • Modules/pr102721.cppm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, then maybe we have to look at these failures before we land this ....

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I believe there is something wrong, and it needs a further look.

At the first glance, in Modules/lambda-merge.cpp, dumping the RD and Calls.front() here:

CXXRecordDecl 0x564c1efa6ff8 <workspace/llvm-project/build/tools/clang/test/Modules/A.map:10:12> col:12 imported in A implicit <undeserialized declarations> class definition
`-DefinitionData lambda pass_in_registers standard_layout trivially_copyable literal can_const_default_init
  |-DefaultConstructor
  |-CopyConstructor simple trivial has_const_param implicit_has_const_param
  |-MoveConstructor exists simple trivial
  |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param
  |-MoveAssignment
  `-Destructor simple irrelevant trivial

CXXMethodDecl 0x564c1efdd428 parent 0x564c1efa6ff8 <workspace/llvm-project/build/tools/clang/test/Modules/B.map:10:14, col:28> col:12 imported in B used constexpr operator() 'auto () const -> int' inline
`-CompoundStmt 0x564c1efdd8e0 <col:16, col:28>
  `-ReturnStmt 0x564c1efdd8d0 <col:18, col:25>
    `-ImplicitCastExpr 0x564c1efdd8b8 <col:25> 'int' <LValueToRValue>
      `-DeclRefExpr 0x564c1efdd898 <col:25> 'const int' lvalue Var 0x564c1efa78a0 'n' 'int' refers_to_enclosing_variable_or_capture

Here, the CXXMethodDecl's parent is 0x564c1efa6ff8, but this method is not listed in the corresponding CXXRecordDecl's dump, this looks suspicious.

}

FunctionTemplateDecl* CXXRecordDecl::getDependentLambdaCallOperator() const {
Expand Down
Loading