blob: 797cbf43a787f7b280519357cef414bee8c945f4 [file] [log] [blame]
Eli Friedman86568552012-02-14 03:07:59 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s -fexceptions -std=c++11 | FileCheck %s
2
Douglas Gregoree188032012-02-20 20:05:29 +00003// CHECK: @var = internal global
4auto var = [](int i) { return i+1; };
5
Douglas Gregorfa07ab52012-02-20 20:47:06 +00006// CHECK: @cvar = global
7extern "C" auto cvar = []{};
8
Eli Friedman86568552012-02-14 03:07:59 +00009int a() { return []{ return 1; }(); }
10// CHECK: define i32 @_Z1av
Douglas Gregor5878cbc2012-02-21 04:17:39 +000011// CHECK: call i32 @"_ZZ1avENK3$_0clEv"
12// CHECK: define internal i32 @"_ZZ1avENK3$_0clEv"
Eli Friedman86568552012-02-14 03:07:59 +000013// CHECK: ret i32 1
14
15int b(int x) { return [x]{return x;}(); }
16// CHECK: define i32 @_Z1bi
17// CHECK: store i32
18// CHECK: load i32*
19// CHECK: store i32
Douglas Gregor5878cbc2012-02-21 04:17:39 +000020// CHECK: call i32 @"_ZZ1biENK3$_1clEv"
21// CHECK: define internal i32 @"_ZZ1biENK3$_1clEv"
Eli Friedman86568552012-02-14 03:07:59 +000022// CHECK: load i32*
23// CHECK: ret i32
24
25int c(int x) { return [&x]{return x;}(); }
26// CHECK: define i32 @_Z1ci
27// CHECK: store i32
28// CHECK: store i32*
Douglas Gregor5878cbc2012-02-21 04:17:39 +000029// CHECK: call i32 @"_ZZ1ciENK3$_2clEv"
30// CHECK: define internal i32 @"_ZZ1ciENK3$_2clEv"
Eli Friedman86568552012-02-14 03:07:59 +000031// CHECK: load i32**
32// CHECK: load i32*
33// CHECK: ret i32
34
35struct D { D(); D(const D&); int x; };
36int d(int x) { D y[10]; [x,y] { return y[x].x; }(); }
37
38// CHECK: define i32 @_Z1di
39// CHECK: call void @_ZN1DC1Ev
40// CHECK: icmp ult i64 %{{.*}}, 10
41// CHECK: call void @_ZN1DC1ERKS_
Douglas Gregor5878cbc2012-02-21 04:17:39 +000042// CHECK: call i32 @"_ZZ1diENK3$_3clEv"
43// CHECK: define internal i32 @"_ZZ1diENK3$_3clEv"
Eli Friedman86568552012-02-14 03:07:59 +000044// CHECK: load i32*
45// CHECK: load i32*
46// CHECK: ret i32
47
48struct E { E(); E(const E&); ~E(); int x; };
49int e(E a, E b, bool cond) { [a,b,cond](){ return (cond ? a : b).x; }(); }
50// CHECK: define i32 @_Z1e1ES_b
51// CHECK: call void @_ZN1EC1ERKS_
52// CHECK: invoke void @_ZN1EC1ERKS_
Douglas Gregor5878cbc2012-02-21 04:17:39 +000053// CHECK: invoke i32 @"_ZZ1e1ES_bENK3$_4clEv"
54// CHECK: call void @"_ZZ1e1ES_bEN3$_4D1Ev"
55// CHECK: call void @"_ZZ1e1ES_bEN3$_4D1Ev"
Douglas Gregor27dd7d92012-02-17 03:02:34 +000056
Douglas Gregor5878cbc2012-02-21 04:17:39 +000057// CHECK: define internal i32 @"_ZZ1e1ES_bENK3$_4clEv"
Eli Friedman86568552012-02-14 03:07:59 +000058// CHECK: trunc i8
59// CHECK: load i32*
60// CHECK: ret i32
Douglas Gregor27dd7d92012-02-17 03:02:34 +000061
62void f() {
63 // CHECK: define void @_Z1fv()
Douglas Gregor5878cbc2012-02-21 04:17:39 +000064 // CHECK: @"_ZZ1fvENK3$_5cvPFiiiEEv"
Douglas Gregor27dd7d92012-02-17 03:02:34 +000065 // CHECK-NEXT: store i32 (i32, i32)*
66 // CHECK-NEXT: ret void
67 int (*fp)(int, int) = [](int x, int y){ return x + y; };
68}
69
Douglas Gregor5878cbc2012-02-21 04:17:39 +000070// CHECK: define internal i32 @"_ZZ1fvEN3$_58__invokeEii"
Douglas Gregor27dd7d92012-02-17 03:02:34 +000071// CHECK: store i32
72// CHECK-NEXT: store i32
73// CHECK-NEXT: load i32*
74// CHECK-NEXT: load i32*
Douglas Gregor5878cbc2012-02-21 04:17:39 +000075// CHECK-NEXT: call i32 @"_ZZ1fvENK3$_5clEii"
Douglas Gregor27dd7d92012-02-17 03:02:34 +000076// CHECK-NEXT: ret i32
77
Douglas Gregor5878cbc2012-02-21 04:17:39 +000078// CHECK: define internal void @"_ZZ1e1ES_bEN3$_4D2Ev"