[clang] [RFC][C++20][Modules] Fix crash when function and lambda inside loaded from different modules (PR #104512)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 19 20:47:35 PDT 2024


ChuanqiXu9 wrote:

Here is another example that merging lambdas are problematic: https://github.com/llvm/llvm-project/issues/102721. Although I think  we need to solve the problems separately. They are different problems.

> > I feel the change is somewhat odd to me. Since the description is about the lambda but the change is about VarDecls. I feel there is a mismatch and I feel this may not solve the underlying problem fundamentally. I feel it'll be better to make it more straight forward. e.g., load the context when loading the lambda (or only make it if there is captures.)
> 
> It was my initial approach to make sure that clang loads function and its lambdas from the same module. But I haven't found examples in clang how to make that canonical decls for two related things are always loaded from the same module. Clang starts loading function `tryTo` from `thrift_cpp2_base.h` module it follow links and via `declval` function specialization it discovers the lambda from `folly-conv.h` module that becomes canonical so by the time when it recursively returns to the lambda inside `thrift_cpp2_base.h` it just merged it to already known decl from `folly-conv.h`. I don't know how to make sure that deserialization won't intermix. As far as I understand code, clang solves this issue by merging identical decls so I implemented merging for VarDecls that cause this issue. But if there is a way to synchronize loading for a function and it's lambda, it should be more reliable but I failed to find the way. Help with solving this issue is very appreciated, clang seems to have other issues with merging lambdas too but I was not able to create small reproducers in other cases yet.

But the current patch still smells bad. Let's try to find a cleaner way to proceed. IIUC, the key of the current problem is that, the CXXRecordDecl of the lambda are assigned to the wrong FunctionDecl as the DeclContext? Or the LambdaExpr appears in the wrong FunctionDecl?

https://github.com/llvm/llvm-project/pull/104512


More information about the cfe-commits mailing list