Jan Kokemüller 765c4e6e8f
[clang] Don't use VarDecl of local variables as ManglingContextDecl for lambdas (#179035)
Currently, in a C++20 modules context, a `VarDecl` of a local variable
can wrongly end up as a `ManglingContextDecl` for a lambda.

Fix this by removing `ContextKind::NonInlineInModulePurview` in
`Sema::getCurrentMangleNumberContext` and add
`IsExternallyVisibleInModulePurview` checks in the appropriate places:

- For externally visible functions defined in a module purview, add a
check to `isInInlineFunction`, renaming it to
`IsInFunctionThatRequiresMangling`
- For externally visible variables defined in a module purview, add a
new `ContextKind::ExternallyVisibleVariableInModulePurview` and an
appropriate check to the `VarDecl` case

Fixes #178893

---------

Co-authored-by: Corentin Jabot <corentinjabot@gmail.com>
Co-authored-by: Chuanqi Xu <yedeng.yd@linux.alibaba.com>
2026-02-26 10:27:52 +08:00

30 lines
725 B
C++

// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple -xc++ -emit-llvm -o - %s -w | FileCheck %s
// CHECK-LABEL: define {{.*}}@_ZZN8PR178893W3mod6format5parseEPiENKUlvE_clEv
// CHECK-LABEL: define {{.*}}@_ZZN8PR178893W3mod6format5parseEPiENKUlvE0_clEv
export module mod;
namespace PR178893 {
struct format {
static inline int parse(int* i)
{
int number;
number = [&]() -> int { return i[0]; }();
volatile bool b = true;
if (b) {
auto identifier = [&]() -> int { return i[1]; }();
return identifier;
}
return number;
}
};
int test_format() {
int n[2] = {1, 0};
return format::parse(n);
}
}