brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.8 KiB · 674ef88 Raw
117 lines · cpp
1// RUN: %clang_cc1 -std=c++1y -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s2 3struct S {4  S();5  S(S &&);6  ~S();7};8 9void f() {10  (void) [s(S{})] {};11}12 13// CHECK-LABEL: define{{.*}} void @_Z1fv(14// CHECK: call void @_ZN1SC1Ev(15// CHECK: call void @"_ZZ1fvEN3$_0D1Ev"(16 17// CHECK-LABEL: define internal void @"_ZZ1fvEN3$_0D1Ev"(18// CHECK: @"_ZZ1fvEN3$_0D2Ev"(19 20// D2 at end of file.21 22void g() {23  [a(1), b(2)] { return a + b; } ();24}25 26// CHECK-LABEL: define{{.*}} void @_Z1gv(27// CHECK: getelementptr inbounds {{.*}}, i32 0, i32 028// CHECK: store i32 1, ptr29// CHECK: getelementptr inbounds {{.*}}, i32 0, i32 130// CHECK: store i32 2, ptr31// CHECK: call noundef i32 @"_ZZ1gvENK3$_0clEv"(32 33// CHECK-LABEL: define internal noundef i32 @"_ZZ1gvENK3$_0clEv"(34// CHECK: getelementptr inbounds {{.*}}, i32 0, i32 035// CHECK: load i32, ptr36// CHECK: getelementptr inbounds {{.*}}, i32 0, i32 137// CHECK: load i32, ptr38 39// CHECK: add nsw i3240 41// CHECK-LABEL: define{{.*}} void @_Z18init_capture_dtorsv42void init_capture_dtors() {43  // Ensure that init-captures are not treated as separate full-expressions.44  struct HasDtor { ~HasDtor() {} };45  void some_function_call();46  void other_function_call();47  // CHECK: call {{.*}}some_function_call48  // CHECK: call {{.*}}HasDtorD49  ([x = (HasDtor(), 0)]{}, some_function_call());50  // CHECK: call {{.*}}other_function_call51  other_function_call();52}53 54int h(int a) {55  // CHECK-LABEL: define{{.*}} i32 @_Z1hi(56  // CHECK: %[[A_ADDR:.*]] = alloca i32,57  // CHECK: %[[OUTER:.*]] = alloca58  // CHECK: store i32 {{.*}}, ptr %[[A_ADDR]],59  //60  // Initialize init-capture 'b(a)' by reference.61  // CHECK: getelementptr inbounds {{.*}}, ptr %[[OUTER]], i32 0, i32 062  // CHECK: store ptr %[[A_ADDR]], ptr {{.*}},63  //64  // Initialize init-capture 'c(a)' by copy.65  // CHECK: getelementptr inbounds {{.*}}, ptr %[[OUTER]], i32 0, i32 166  // CHECK: load i32, ptr %[[A_ADDR]],67  // CHECK: store i3268  //69  // CHECK: call noundef i32 @"_ZZ1hiENK3$_0clEv"(ptr {{[^,]*}} %[[OUTER]])70  return [&b(a), c(a)] {71    // CHECK-LABEL: define internal noundef i32 @"_ZZ1hiENK3$_0clEv"(72    // CHECK: %[[OUTER_ADDR:.*]] = alloca73    // CHECK: %[[INNER:.*]] = alloca74    // CHECK: store {{.*}}, ptr %[[OUTER_ADDR]],75    //76    // Capture outer 'c' by reference.77    // CHECK: %[[OUTER:.*]] = load ptr, ptr %[[OUTER_ADDR]]78    // CHECK: getelementptr inbounds {{.*}}, ptr %[[INNER]], i32 0, i32 079    // CHECK-NEXT: getelementptr inbounds {{.*}}, ptr %[[OUTER]], i32 0, i32 180    // CHECK-NEXT: store ptr %81    //82    // Capture outer 'b' by copy.83    // CHECK: getelementptr inbounds {{.*}}, ptr %[[INNER]], i32 0, i32 184    // CHECK-NEXT: getelementptr inbounds {{.*}}, ptr %[[OUTER]], i32 0, i32 085    // CHECK-NEXT: load ptr, ptr %86    // CHECK-NEXT: load i32, ptr %87    // CHECK-NEXT: store i3288    //89    // CHECK: call noundef i32 @"_ZZZ1hiENK3$_0clEvENKUlvE_clEv"(ptr {{[^,]*}} %[[INNER]])90    return [=, &c] {91      // CHECK-LABEL: define internal void @"_ZZ1fvEN3$_0D2Ev"(92      // CHECK: call void @_ZN1SD1Ev(93 94      // CHECK-LABEL: define internal noundef i32 @"_ZZZ1hiENK3$_0clEvENKUlvE_clEv"(95      // CHECK: %[[INNER_ADDR:.*]] = alloca96      // CHECK: store {{.*}}, ptr %[[INNER_ADDR]],97      // CHECK: %[[INNER:.*]] = load ptr, ptr %[[INNER_ADDR]]98      //99      // Load capture of 'b'100      // CHECK: getelementptr inbounds {{.*}}, ptr %[[INNER]], i32 0, i32 1101      // CHECK: load i32, ptr %102      //103      // Load capture of 'c'104      // CHECK: getelementptr inbounds {{.*}}, ptr %[[INNER]], i32 0, i32 0105      // CHECK: load ptr, ptr %106      // CHECK: load i32, ptr %107      //108      // CHECK: add nsw i32109      return b + c;110    } ();111  } ();112}113 114// Ensure we can emit code for init-captures in global lambdas too.115auto global_lambda = [a = 0] () mutable { return ++a; };116int get_incremented() { return global_lambda(); }117