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

Dmitry Polukhin via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 9 08:16:02 PDT 2024


Valentin Clement =?utf-8?b?KOODkOODrOODsw==?=,Kyungwoo Lee <kyulee at meta.com>,Dmitry
 Polukhin <dmitry.polukhin at gmail.com>,Dmitry Polukhin
 <dmitry.polukhin at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/104512 at github.com>


================
@@ -764,6 +792,15 @@ 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.
+  llvm::SmallVector<const Decl *, 2> Lambdas = collectLambdas(D);
+  Record.push_back(Lambdas.size());
+  for (const auto *L : Lambdas)
+    Record.AddDeclRef(L);
----------------
dmpolukhin wrote:

it seems that it is not required but added comment there to clarify it.

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


More information about the cfe-commits mailing list