diff options
| author | Jan Kokemüller <jan.kokemueller@gmail.com> | 2026-02-26 03:27:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-26 10:27:52 +0800 |
| commit | 765c4e6e8fb25ca999bc19654b5f324df62879ad (patch) | |
| tree | ce32ad7e726f6ead9ecb1faa8fa22f6e24962957 /clang/test | |
| parent | d7bd36d7e9f5ed493888672c46ff0ce405d627b0 (diff) | |
| download | llvm-main.zip llvm-main.tar.gz llvm-main.tar.bz2 | |
[clang] Don't use `VarDecl` of local variables as `ManglingContextDecl` for lambdas (#179035)HEADmain
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>
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/Modules/pr178893.cppm | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/clang/test/Modules/pr178893.cppm b/clang/test/Modules/pr178893.cppm new file mode 100644 index 0000000..e58e183 --- /dev/null +++ b/clang/test/Modules/pr178893.cppm @@ -0,0 +1,29 @@ +// 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); + } +} |
