blob: 0f35dda737feb8f9db5cb6dbce4b059200d12e26 [file] [log] [blame]
Richard Smith762bb9d2011-10-13 22:29:44 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - %s | opt -instnamer -S | FileCheck %s
Richard Smithad762fc2011-04-14 22:09:26 +00002
3struct A {
4 A();
5 A(const A&);
6 ~A();
7};
8
9struct B {
10 B();
11 B(const B&);
12 ~B();
13};
14
15struct C {
16 C();
17 C(const C&);
18 ~C();
19};
20
21struct D {
22 D();
23 D(const D&);
24 ~D();
25
26 B *begin();
27 B *end();
28};
29
30namespace std {
31 B *begin(C&);
32 B *end(C&);
33}
34
35extern B array[5];
36
37// CHECK: define void @_Z9for_arrayv(
38void for_array() {
39 // CHECK: call void @_ZN1AC1Ev(%struct.A* [[A:.*]])
40 A a;
41 for (B b : array) {
42 // CHECK-NOT: 5begin
43 // CHECK-NOT: 3end
44 // CHECK: getelementptr {{.*}}, i32 0
45 // CHECK: getelementptr {{.*}}, i64 5
46 // CHECK: br label %[[COND:.*]]
47
48 // CHECK: [[COND]]:
49 // CHECK: %[[CMP:.*]] = icmp ne
50 // CHECK: br i1 %[[CMP]], label %[[BODY:.*]], label %[[END:.*]]
51
52 // CHECK: [[BODY]]:
53 // CHECK: call void @_ZN1BC1ERKS_(
54 // CHECK: call void @_ZN1BD1Ev(
55 // CHECK: br label %[[INC:.*]]
56
57 // CHECK: [[INC]]:
58 // CHECK: getelementptr {{.*}} i32 1
59 // CHECK: br label %[[COND]]
60 }
61 // CHECK: [[END]]:
62 // CHECK: call void @_ZN1AD1Ev(%struct.A* [[A]])
63 // CHECK: ret void
64}
65
66// CHECK: define void @_Z9for_rangev(
67void for_range() {
68 // CHECK: call void @_ZN1AC1Ev(%struct.A* [[A:.*]])
69 A a;
70 for (B b : C()) {
71 // CHECK: call void @_ZN1CC1Ev(
Chris Lattner9cbe4f02011-07-09 17:41:47 +000072 // CHECK: = call %struct.B* @_ZSt5beginR1C(
73 // CHECK: = call %struct.B* @_ZSt3endR1C(
Richard Smithad762fc2011-04-14 22:09:26 +000074 // CHECK: br label %[[COND:.*]]
75
76 // CHECK: [[COND]]:
77 // CHECK: %[[CMP:.*]] = icmp ne
78 // CHECK: br i1 %[[CMP]], label %[[BODY:.*]], label %[[CLEANUP:.*]]
79
80 // CHECK: [[CLEANUP]]:
81 // CHECK: call void @_ZN1CD1Ev(
82 // CHECK: br label %[[END:.*]]
83
84 // CHECK: [[BODY]]:
85 // CHECK: call void @_ZN1BC1ERKS_(
86 // CHECK: call void @_ZN1BD1Ev(
87 // CHECK: br label %[[INC:.*]]
88
89 // CHECK: [[INC]]:
90 // CHECK: getelementptr {{.*}} i32 1
91 // CHECK: br label %[[COND]]
92 }
93 // CHECK: [[END]]:
94 // CHECK: call void @_ZN1AD1Ev(%struct.A* [[A]])
95 // CHECK: ret void
96}
97
98// CHECK: define void @_Z16for_member_rangev(
99void for_member_range() {
100 // CHECK: call void @_ZN1AC1Ev(%struct.A* [[A:.*]])
101 A a;
102 for (B b : D()) {
103 // CHECK: call void @_ZN1DC1Ev(
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000104 // CHECK: = call %struct.B* @_ZN1D5beginEv(
105 // CHECK: = call %struct.B* @_ZN1D3endEv(
Richard Smithad762fc2011-04-14 22:09:26 +0000106 // CHECK: br label %[[COND:.*]]
107
108 // CHECK: [[COND]]:
109 // CHECK: %[[CMP:.*]] = icmp ne
110 // CHECK: br i1 %[[CMP]], label %[[BODY:.*]], label %[[CLEANUP:.*]]
111
112 // CHECK: [[CLEANUP]]:
113 // CHECK: call void @_ZN1DD1Ev(
114 // CHECK: br label %[[END:.*]]
115
116 // CHECK: [[BODY]]:
117 // CHECK: call void @_ZN1BC1ERKS_(
118 // CHECK: call void @_ZN1BD1Ev(
119 // CHECK: br label %[[INC:.*]]
120
121 // CHECK: [[INC]]:
122 // CHECK: getelementptr {{.*}} i32 1
123 // CHECK: br label %[[COND]]
124 }
125 // CHECK: [[END]]:
126 // CHECK: call void @_ZN1AD1Ev(%struct.A* [[A]])
127 // CHECK: ret void
128}