brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.8 KiB · 9cf5a7e Raw
144 lines · cpp
1// RUN: %clang_cc1 -std=c++23 %s -emit-llvm -triple x86_64-linux -o - | FileCheck %s2// RUN: %clang_cc1 -std=c++23 %s -emit-llvm -triple x86_64-windows-msvc -o - | FileCheck %s3 4struct Functor {5  static int operator()(int x, int y) {6    return x + y;7  }8};9 10auto GetALambda() {11  return [](int x, int y) static {12    return x + y;13  };14}15 16void CallsTheLambda() {17  GetALambda()(1, 2);18}19 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 void25// CHECK-NEXT: }26 27Functor GetAFunctor() {28  return {};29}30 31void 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);38}39 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 void49// CHECK-NEXT: }50 51struct FunctorConsteval {52  consteval static int operator()(int x, int y) {53      return x + y;54  }55};56 57struct FunctorConstexpr {58  constexpr static int operator()(int x, int y) {59      return x + y;60  }61};62 63constexpr auto my_lambda = []() constexpr {64  return 3;65};66 67void 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);72  73  static_assert(z1 == 4);74  static_assert(z2 == 4);75 76  constexpr auto my_lambda = []() constexpr static {77      return 3;78  };79  constexpr int (*f)(void) = my_lambda;80  constexpr int k = f();81  static_assert(k == 3);82}83 84template <class T>85struct DepFunctor {86  static int operator()(T t) {87    return int(t);88  }89};90 91template<class T>92auto dep_lambda1() {93  return [](T t) static -> int {94    return t;95  };96}97 98auto dep_lambda2() {99  return [](auto t) static -> int {100    return t;101  };102}103 104void test_dep_functors() {105  int x = DepFunctor<float>{}(1.0f);106  int y = DepFunctor<bool>{}(true);107 108  int a = dep_lambda1<float>()(1.0f);109  int b = dep_lambda1<bool>()(true);110 111  int h = dep_lambda2()(1.0f);112  int i = dep_lambda2()(true);113}114 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 void128// CHECK-NEXT: }129 130 131struct __unique {132    static constexpr auto operator()() { return 4; };133 134    using P = int();135    constexpr operator P*() { return operator(); }136};137 138__unique four{};139 140int test_four() {141  // Checks that overload resolution works.142  return four();143}144