Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / cxx2b-static-call-operator.cpp
blobfd53649c9b061867c88dbdb6671d5a7e604f174c
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-NEXT: %call = call noundef i32 {{.*}}(i32 noundef 1, i32 noundef 2)
23 // CHECK-NEXT: ret void
24 // CHECK-NEXT: }
26 void call_static_call_operator() {
27 Functor f;
28 f(101, 102);
29 f.operator()(201, 202);
30 Functor{}(301, 302);
31 Functor::operator()(401, 402);
34 // CHECK: define {{.*}}call_static_call_operator{{.*}}
35 // CHECK-NEXT: entry:
36 // CHECK: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 101, i32 noundef 102)
37 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 201, i32 noundef 202)
38 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 301, i32 noundef 302)
39 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 401, i32 noundef 402)
40 // CHECK-NEXT: ret void
41 // CHECK-NEXT: }
43 struct FunctorConsteval {
44 consteval static int operator()(int x, int y) {
45 return x + y;
49 struct FunctorConstexpr {
50 constexpr static int operator()(int x, int y) {
51 return x + y;
55 constexpr auto my_lambda = []() constexpr {
56 return 3;
59 void test_consteval_constexpr() {
60 int x = 0;
61 int y = FunctorConstexpr{}(x, 2);
62 constexpr int z1 = FunctorConsteval{}(2, 2);
63 constexpr int z2 = FunctorConstexpr{}(2, 2);
65 static_assert(z1 == 4);
66 static_assert(z2 == 4);
68 constexpr auto my_lambda = []() constexpr static {
69 return 3;
71 constexpr int (*f)(void) = my_lambda;
72 constexpr int k = f();
73 static_assert(k == 3);
76 template <class T>
77 struct DepFunctor {
78 static int operator()(T t) {
79 return int(t);
83 template<class T>
84 auto dep_lambda1() {
85 return [](T t) static -> int {
86 return t;
90 auto dep_lambda2() {
91 return [](auto t) static -> int {
92 return t;
96 void test_dep_functors() {
97 int x = DepFunctor<float>{}(1.0f);
98 int y = DepFunctor<bool>{}(true);
100 int a = dep_lambda1<float>()(1.0f);
101 int b = dep_lambda1<bool>()(true);
103 int h = dep_lambda2()(1.0f);
104 int i = dep_lambda2()(true);
107 // CHECK: define {{.*}}test_dep_functors{{.*}}
108 // CHECK-NEXT: entry:
109 // CHECK: %call = call noundef i32 {{.*}}DepFunctor{{.*}}(float noundef 1.000000e+00)
110 // CHECK: %call1 = call noundef i32 {{.*}}DepFunctor{{.*}}(i1 noundef zeroext true)
111 // CHECK: %call2 = call noundef i32 {{.*}}dep_lambda1{{.*}}(float noundef 1.000000e+00)
112 // CHECK: %call3 = call noundef i32 {{.*}}dep_lambda1{{.*}}(i1 noundef zeroext true)
113 // CHECK: %call4 = call noundef i32 {{.*}}dep_lambda2{{.*}}(float noundef 1.000000e+00)
114 // CHECK: %call5 = call noundef i32 {{.*}}dep_lambda2{{.*}}(i1 noundef zeroext true)
115 // CHECK: ret void
116 // CHECK-NEXT: }
119 struct __unique {
120 static constexpr auto operator()() { return 4; };
122 using P = int();
123 constexpr operator P*() { return operator(); }
126 __unique four{};
128 int test_four() {
129 // Checks that overload resolution works.
130 return four();