[LoongArch][Clang] Make the parameters and return value of {x,}vorn.v builti ns ...
[llvm-project.git] / clang / test / CodeGenCXX / cxx2b-static-call-operator.cpp
blob9cf5a7e00e7b4ef093c0ed3af91425f60582ed6f
1 // RUN: %clang_cc1 -std=c++23 %s -emit-llvm -triple x86_64-linux -o - | FileCheck %s
2 // RUN: %clang_cc1 -std=c++23 %s -emit-llvm -triple x86_64-windows-msvc -o - | FileCheck %s
4 struct Functor {
5 static int operator()(int x, int y) {
6 return x + y;
8 };
10 auto GetALambda() {
11 return [](int x, int y) static {
12 return x + y;
16 void CallsTheLambda() {
17 GetALambda()(1, 2);
20 // CHECK: define {{.*}}CallsTheLambda{{.*}}
21 // CHECK-NEXT: entry:
22 // CHECK: {{.*}}call {{.*}}GetALambda{{.*}}()
23 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}(i32 noundef 1, i32 noundef 2)
24 // CHECK-NEXT: ret void
25 // CHECK-NEXT: }
27 Functor GetAFunctor() {
28 return {};
31 void call_static_call_operator() {
32 Functor f;
33 f(101, 102);
34 f.operator()(201, 202);
35 Functor{}(301, 302);
36 Functor::operator()(401, 402);
37 GetAFunctor()(501, 502);
40 // CHECK: define {{.*}}call_static_call_operator{{.*}}
41 // CHECK-NEXT: entry:
42 // CHECK: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 101, i32 noundef 102)
43 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 201, i32 noundef 202)
44 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 301, i32 noundef 302)
45 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 401, i32 noundef 402)
46 // CHECK: {{.*}}call {{.*}}GetAFunctor{{.*}}()
47 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 501, i32 noundef 502)
48 // CHECK-NEXT: ret void
49 // CHECK-NEXT: }
51 struct FunctorConsteval {
52 consteval static int operator()(int x, int y) {
53 return x + y;
57 struct FunctorConstexpr {
58 constexpr static int operator()(int x, int y) {
59 return x + y;
63 constexpr auto my_lambda = []() constexpr {
64 return 3;
67 void test_consteval_constexpr() {
68 int x = 0;
69 int y = FunctorConstexpr{}(x, 2);
70 constexpr int z1 = FunctorConsteval{}(2, 2);
71 constexpr int z2 = FunctorConstexpr{}(2, 2);
73 static_assert(z1 == 4);
74 static_assert(z2 == 4);
76 constexpr auto my_lambda = []() constexpr static {
77 return 3;
79 constexpr int (*f)(void) = my_lambda;
80 constexpr int k = f();
81 static_assert(k == 3);
84 template <class T>
85 struct DepFunctor {
86 static int operator()(T t) {
87 return int(t);
91 template<class T>
92 auto dep_lambda1() {
93 return [](T t) static -> int {
94 return t;
98 auto dep_lambda2() {
99 return [](auto t) static -> int {
100 return t;
104 void test_dep_functors() {
105 int x = DepFunctor<float>{}(1.0f);
106 int y = DepFunctor<bool>{}(true);
108 int a = dep_lambda1<float>()(1.0f);
109 int b = dep_lambda1<bool>()(true);
111 int h = dep_lambda2()(1.0f);
112 int i = dep_lambda2()(true);
115 // CHECK: define {{.*}}test_dep_functors{{.*}}
116 // CHECK-NEXT: entry:
117 // CHECK: {{.*}} = call noundef i32 {{.*}}DepFunctor{{.*}}(float noundef 1.000000e+00)
118 // CHECK: {{.*}} = call noundef i32 {{.*}}DepFunctor{{.*}}(i1 noundef zeroext true)
119 // CHECK: {{.*}}call {{.*}}dep_lambda1{{.*}}()
120 // CHECK: {{.*}} = call noundef i32 {{.*}}dep_lambda1{{.*}}(float noundef 1.000000e+00)
121 // CHECK: {{.*}}call {{.*}}dep_lambda1{{.*}}()
122 // CHECK: {{.*}} = call noundef i32 {{.*}}dep_lambda1{{.*}}(i1 noundef zeroext true)
123 // CHECK: {{.*}}call {{.*}}dep_lambda2{{.*}}()
124 // CHECK: {{.*}} = call noundef i32 {{.*}}dep_lambda2{{.*}}(float noundef 1.000000e+00)
125 // CHECK: {{.*}}call {{.*}}dep_lambda2{{.*}}()
126 // CHECK: {{.*}} = call noundef i32 {{.*}}dep_lambda2{{.*}}(i1 noundef zeroext true)
127 // CHECK: ret void
128 // CHECK-NEXT: }
131 struct __unique {
132 static constexpr auto operator()() { return 4; };
134 using P = int();
135 constexpr operator P*() { return operator(); }
138 __unique four{};
140 int test_four() {
141 // Checks that overload resolution works.
142 return four();