• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  // RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fblocks -emit-llvm -o - %s -fexceptions -std=c++11 | FileCheck %s
2  
3  // CHECK-NOT: @unused
__anon31301e0d0102(int i) 4  auto unused = [](int i) { return i+1; };
5  
6  // CHECK: @used = internal global
__anon31301e0d0202(int i) 7  auto used = [](int i) { return i+1; };
8  void *use = &used;
9  
10  // CHECK: @cvar = global
__anon31301e0d0302null11  extern "C" auto cvar = []{};
12  
13  // CHECK-LABEL: define i32 @_Z9ARBSizeOfi(i32
ARBSizeOf(int n)14  int ARBSizeOf(int n) {
15    typedef double(T)[8][n];
16    using TT = double[8][n];
17    return [&]() -> int {
18      typedef double(T1)[8][n];
19      using TT1 = double[8][n];
20      return [&n]() -> int {
21        typedef double(T2)[8][n];
22        using TT2 = double[8][n];
23        return sizeof(T) + sizeof(T1) + sizeof(T2) + sizeof(TT) + sizeof(TT1) + sizeof(TT2);
24      }();
25    }();
26  }
27  
28  // CHECK-LABEL: define internal i32 @"_ZZ9ARBSizeOfiENK3$_0clEv"
29  
a()30  int a() { return []{ return 1; }(); }
31  // CHECK-LABEL: define i32 @_Z1av
32  // CHECK: call i32 @"_ZZ1avENK3$_1clEv"
33  // CHECK-LABEL: define internal i32 @"_ZZ1avENK3$_1clEv"
34  // CHECK: ret i32 1
35  
b(int x)36  int b(int x) { return [x]{return x;}(); }
37  // CHECK-LABEL: define i32 @_Z1bi
38  // CHECK: store i32
39  // CHECK: load i32, i32*
40  // CHECK: store i32
41  // CHECK: call i32 @"_ZZ1biENK3$_2clEv"
42  // CHECK-LABEL: define internal i32 @"_ZZ1biENK3$_2clEv"
43  // CHECK: load i32, i32*
44  // CHECK: ret i32
45  
c(int x)46  int c(int x) { return [&x]{return x;}(); }
47  // CHECK-LABEL: define i32 @_Z1ci
48  // CHECK: store i32
49  // CHECK: store i32*
50  // CHECK: call i32 @"_ZZ1ciENK3$_3clEv"
51  // CHECK-LABEL: define internal i32 @"_ZZ1ciENK3$_3clEv"
52  // CHECK: load i32*, i32**
53  // CHECK: load i32, i32*
54  // CHECK: ret i32
55  
56  struct D { D(); D(const D&); int x; };
d(int x)57  int d(int x) { D y[10]; [x,y] { return y[x].x; }(); }
58  
59  // CHECK-LABEL: define i32 @_Z1di
60  // CHECK: call void @_ZN1DC1Ev
61  // CHECK: icmp ult i64 %{{.*}}, 10
62  // CHECK: call void @_ZN1DC1ERKS_
63  // CHECK: call i32 @"_ZZ1diENK3$_4clEv"
64  // CHECK-LABEL: define internal i32 @"_ZZ1diENK3$_4clEv"
65  // CHECK: load i32, i32*
66  // CHECK: load i32, i32*
67  // CHECK: ret i32
68  
69  struct E { E(); E(const E&); ~E(); int x; };
__anon31301e0d0a02()70  int e(E a, E b, bool cond) { [a,b,cond](){ return (cond ? a : b).x; }(); }
71  // CHECK-LABEL: define i32 @_Z1e1ES_b
72  // CHECK: call void @_ZN1EC1ERKS_
73  // CHECK: invoke void @_ZN1EC1ERKS_
74  // CHECK: invoke i32 @"_ZZ1e1ES_bENK3$_5clEv"
75  // CHECK: call void @"_ZZ1e1ES_bEN3$_5D1Ev"
76  // CHECK: call void @"_ZZ1e1ES_bEN3$_5D1Ev"
77  
78  // CHECK-LABEL: define internal i32 @"_ZZ1e1ES_bENK3$_5clEv"
79  // CHECK: trunc i8
80  // CHECK: load i32, i32*
81  // CHECK: ret i32
82  
f()83  void f() {
84    // CHECK-LABEL: define void @_Z1fv()
85    // CHECK: @"_ZZ1fvENK3$_6cvPFiiiEEv"
86    // CHECK-NEXT: store i32 (i32, i32)*
87    // CHECK-NEXT: ret void
88    int (*fp)(int, int) = [](int x, int y){ return x + y; };
89  }
90  
91  static int k;
g()92  int g() {
93    int &r = k;
94    // CHECK-LABEL: define internal i32 @"_ZZ1gvENK3$_7clEv"(
95    // CHECK-NOT: }
96    // CHECK: load i32, i32* @_ZL1k,
97    return [] { return r; } ();
98  };
99  
100  // PR14773
101  // CHECK: [[ARRVAL:%[0-9a-zA-Z]*]] = load i32, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @_ZZ14staticarrayrefvE5array, i64 0, i64 0), align 4
102  // CHECK-NEXT: store i32 [[ARRVAL]]
staticarrayref()103  void staticarrayref(){
104    static int array[] = {};
105    (void)[](){
106      int (&xxx)[0] = array;
107      int y = xxx[0];
108    }();
109  }
110  
111  // CHECK-LABEL: define internal i32* @"_ZZ11PR22071_funvENK3$_9clEv"
112  // CHECK: ret i32* @PR22071_var
113  int PR22071_var;
PR22071_fun()114  int *PR22071_fun() {
115    constexpr int &y = PR22071_var;
116    return [&] { return &y; }();
117  }
118  
119  // CHECK-LABEL: define internal void @"_ZZ1e1ES_bEN3$_5D2Ev"
120  
121  // CHECK-LABEL: define internal i32 @"_ZZ1fvEN3$_68__invokeEii"
122  // CHECK: store i32
123  // CHECK-NEXT: store i32
124  // CHECK-NEXT: load i32, i32*
125  // CHECK-NEXT: load i32, i32*
126  // CHECK-NEXT: call i32 @"_ZZ1fvENK3$_6clEii"
127  // CHECK-NEXT: ret i32
128  
129  // CHECK-LABEL: define internal void @"_ZZ1hvEN4$_108__invokeEv"(%struct.A* noalias sret %agg.result) {{.*}} {
130  // CHECK-NOT: =
131  // CHECK: call void @"_ZZ1hvENK4$_10clEv"(%struct.A* sret %agg.result,
132  // CHECK-NEXT: ret void
133  struct A { ~A(); };
h()134  void h() {
135    A (*h)() = [] { return A(); };
136  }
137  
138  // <rdar://problem/12778708>
139  struct XXX {};
nestedCapture()140  void nestedCapture () {
141    XXX localKey;
142    ^() {
143      [&]() {
144        ^{ XXX k = localKey; };
145      };
146    };
147  }
148  
149  // Ensure we don't assert here.
150  struct CaptureArrayAndThis {
CaptureArrayAndThisCaptureArrayAndThis151    CaptureArrayAndThis() {
152      char array[] = "floop";
153      [array, this] {};
154    }
155  } capture_array_and_this;
156  
157