Mercurial > hg > CbC > CbC_llvm
comparison clang/test/Modules/lambda-in-variable.cpp @ 252:1f2b6ac9f198 llvm-original
LLVM16-1
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 18 Aug 2023 09:04:13 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
237:c80f45b162ad | 252:1f2b6ac9f198 |
---|---|
1 // RUN: rm -rf %t | |
2 // RUN: mkdir -p %t | |
3 // RUN: split-file %s %t | |
4 // | |
5 // RUN: %clang_cc1 -std=c++20 -fmodules -fmodules-cache-path=%t -fmodule-map-file=%t/module.modulemap %t/use.cpp -emit-llvm -o - -triple x86_64-linux-gnu | FileCheck %s | |
6 // RUN: %clang_cc1 -DDEFINE_LOCALLY -std=c++20 -fmodules -fmodules-cache-path=%t -fmodule-map-file=%t/module.modulemap %t/use.cpp -emit-llvm -o - -triple x86_64-linux-gnu | FileCheck %s | |
7 | |
8 //--- module.modulemap | |
9 module a { header "a.h" export * } | |
10 module b { header "b.h" export * } | |
11 module c { header "c.h" export * } | |
12 | |
13 //--- nonmodular.h | |
14 void not_constant(); | |
15 | |
16 template<typename T> struct A { | |
17 template<T M> static inline T N = [] { not_constant(); return M; } (); | |
18 }; | |
19 | |
20 template<typename T, T M> inline T N = [] { not_constant(); return M; } (); | |
21 | |
22 template<typename T, T M> inline auto L = [] {}; | |
23 | |
24 template<typename T> int Z; | |
25 | |
26 // These lambdas should not be merged, despite having the same context decl and | |
27 // mangling number (but different signatures). | |
28 inline auto MultipleLambdas = ((void)[](int*) { return 1; }, [] { return 2; }); | |
29 | |
30 //--- a.h | |
31 #include "nonmodular.h" | |
32 | |
33 //--- b.h | |
34 #include "a.h" | |
35 | |
36 int b1() { return A<int>::N<1>; } | |
37 int b2() { return N<int, 1>; } | |
38 | |
39 inline auto x1 = L<int, 1>; | |
40 inline auto x2 = L<int, 2>; | |
41 | |
42 inline constexpr int *P = &Z<decltype([] { static int n; return &n; }())>; | |
43 inline constexpr int *xP = P; | |
44 | |
45 static_assert(!__is_same(decltype(x1), decltype(x2))); | |
46 | |
47 //--- c.h | |
48 #include "a.h" | |
49 | |
50 int c1() { return A<int>::N<2>; } | |
51 int c2() { return N<int, 2>; } | |
52 | |
53 inline auto y2 = L<int, 2>; | |
54 inline auto y1 = L<int, 1>; | |
55 | |
56 inline constexpr int *P = &Z<decltype([] { static int n; return &n; }())>; | |
57 inline constexpr int *yP = P; | |
58 | |
59 //--- use.cpp | |
60 #ifdef DEFINE_LOCALLY | |
61 #include "nonmodular.h" | |
62 | |
63 inline constexpr int *P = &Z<decltype([] { static int n; return &n; }())>; | |
64 inline constexpr int *zP = P; | |
65 | |
66 auto z0 = L<int, 0>; | |
67 auto z2 = L<int, 2>; | |
68 auto z1 = L<int, 1>; | |
69 #endif | |
70 | |
71 #include "b.h" | |
72 #include "c.h" | |
73 | |
74 int b1v = b1(); | |
75 int b2v = b2(); | |
76 int c1v = c1(); | |
77 int c2v = c2(); | |
78 | |
79 // We should merge together matching lambdas. | |
80 static_assert(__is_same(decltype(x1), decltype(y1))); | |
81 static_assert(__is_same(decltype(x2), decltype(y2))); | |
82 static_assert(!__is_same(decltype(x1), decltype(x2))); | |
83 static_assert(!__is_same(decltype(y1), decltype(y2))); | |
84 static_assert(!__is_same(decltype(x1), decltype(y2))); | |
85 static_assert(!__is_same(decltype(x2), decltype(y1))); | |
86 static_assert(xP == yP); | |
87 #ifdef DEFINE_LOCALLY | |
88 static_assert(!__is_same(decltype(x1), decltype(z0))); | |
89 static_assert(!__is_same(decltype(x2), decltype(z0))); | |
90 static_assert(__is_same(decltype(x1), decltype(z1))); | |
91 static_assert(__is_same(decltype(x2), decltype(z2))); | |
92 static_assert(xP == zP); | |
93 #endif | |
94 | |
95 static_assert(MultipleLambdas() == 2); | |
96 | |
97 // We should not merge the instantiated lambdas from `b.h` and `c.h` together, | |
98 // even though they will both have anonymous declaration number #1 within | |
99 // A<int> and within the TU, respectively. | |
100 | |
101 // CHECK-LABEL: define {{.*}}global_var_init{{.*}} comdat($_Z1NIiLi1EE) { | |
102 // CHECK: load i8, ptr @_ZGV1NIiLi1EE, align 8 | |
103 // CHECK: call {{.*}} i32 @_ZNK1NIiLi1EEMUlvE_clEv( | |
104 // CHECK: store i32 {{.*}}, ptr @_Z1NIiLi1EE | |
105 | |
106 // CHECK-LABEL: define {{.*}}global_var_init{{.*}} comdat($_ZN1AIiE1NILi1EEE) { | |
107 // CHECK: load i8, ptr @_ZGVN1AIiE1NILi1EEE, align 8 | |
108 // CHECK: call {{.*}} i32 @_ZNK1AIiE1NILi1EEMUlvE_clEv( | |
109 // CHECK: store i32 {{.*}}, ptr @_ZN1AIiE1NILi1EEE | |
110 | |
111 // CHECK-LABEL: define {{.*}}global_var_init{{.*}} comdat($_Z1NIiLi2EE) { | |
112 // CHECK: load i8, ptr @_ZGV1NIiLi2EE, align 8 | |
113 // CHECK: call {{.*}} i32 @_ZNK1NIiLi2EEMUlvE_clEv( | |
114 // CHECK: store i32 {{.*}}, ptr @_Z1NIiLi2EE | |
115 | |
116 // CHECK-LABEL: define {{.*}}global_var_init{{.*}} comdat($_ZN1AIiE1NILi2EEE) { | |
117 // CHECK: load i8, ptr @_ZGVN1AIiE1NILi2EEE, align 8 | |
118 // CHECK: call {{.*}} i32 @_ZNK1AIiE1NILi2EEMUlvE_clEv( | |
119 // CHECK: store i32 {{.*}}, ptr @_ZN1AIiE1NILi2EEE | |
120 |