mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-05-14 01:46:41 +00:00

Different versions of a lambda will in general refer to different enclosing variable declarations, because we do not merge most block-scope declarations, such as local variables. Keep track of all the declarations that correspond to a lambda's capture fields so that we can rewrite the name of any of those variables to the lambda capture, regardless of which copy of the body of `operator()` we look at.
60 lines
1.0 KiB
C++
60 lines
1.0 KiB
C++
// RUN: %clang_cc1 -fmodules -std=c++17 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
|
|
|
|
#pragma clang module build A
|
|
module A {}
|
|
#pragma clang module contents
|
|
#pragma clang module begin A
|
|
template<typename T> T f(T v) {
|
|
v();
|
|
return v;
|
|
}
|
|
inline auto g() {
|
|
int n = 0;
|
|
return f([=] { return n; });
|
|
}
|
|
|
|
template<typename T> constexpr T f2(T v) {
|
|
v();
|
|
return v;
|
|
}
|
|
constexpr auto g2() {
|
|
int n = 0;
|
|
return f2([=] { return n; });
|
|
}
|
|
#pragma clang module end
|
|
#pragma clang module endbuild
|
|
|
|
#pragma clang module build B
|
|
module B {}
|
|
#pragma clang module contents
|
|
#pragma clang module begin B
|
|
template<typename T> T f(T v) {
|
|
v();
|
|
return v;
|
|
}
|
|
inline auto g() {
|
|
int n = 0;
|
|
return f([=] { return n; });
|
|
}
|
|
|
|
template<typename T> constexpr T f2(T v) {
|
|
v();
|
|
return v;
|
|
}
|
|
constexpr auto g2() {
|
|
int n = 0;
|
|
return f2([=] { return n; });
|
|
}
|
|
#pragma clang module end
|
|
#pragma clang module endbuild
|
|
|
|
#pragma clang module import A
|
|
#pragma clang module import B
|
|
|
|
// CHECK: define {{.*}}use_g
|
|
int use_g() {
|
|
return g()();
|
|
}
|
|
|
|
static_assert(g2()() == 0);
|