blob: e4266cf5028ea8a4c47fd4e6150690de4b750ae4 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
Douglas Gregor01234bb2009-11-24 16:43:22 +00002void *f();
3
4template <typename T> T* g() {
5 if (T* t = f())
6 return t;
7
8 return 0;
9}
10
11void h() {
12 void *a = g<void>();
13}
14
15struct X {
16 X();
17 ~X();
18 operator bool();
19};
20
21struct Y {
22 Y();
23 ~Y();
24};
25
Douglas Gregor586596f2010-05-06 17:25:47 +000026X getX();
27
Douglas Gregor01234bb2009-11-24 16:43:22 +000028void if_destruct(int z) {
29 // Verify that the condition variable is destroyed at the end of the
30 // "if" statement.
31 // CHECK: call void @_ZN1XC1Ev
32 // CHECK: call zeroext i1 @_ZN1XcvbEv
33 if (X x = X()) {
34 // CHECK: store i32 18
35 z = 18;
36 }
37 // CHECK: call void @_ZN1XD1Ev
38 // CHECK: store i32 17
39 z = 17;
40
41 // CHECK: call void @_ZN1XC1Ev
42 if (X x = X())
43 Y y;
Mike Stumpedc95e72010-01-13 20:57:29 +000044 // CHECK: br
Douglas Gregor01234bb2009-11-24 16:43:22 +000045 // CHECK: call void @_ZN1YC1Ev
46 // CHECK: call void @_ZN1YD1Ev
Mike Stumpedc95e72010-01-13 20:57:29 +000047 // CHECK: br
Douglas Gregor01234bb2009-11-24 16:43:22 +000048 // CHECK: call void @_ZN1XD1Ev
Douglas Gregor586596f2010-05-06 17:25:47 +000049
50 // CHECK: call void @_Z4getXv
51 // CHECK: call zeroext i1 @_ZN1XcvbEv
52 // CHECK: call void @_ZN1XD1Ev
53 // CHECK: br
54 if (getX()) { }
55
56 // CHECK: ret
Douglas Gregor01234bb2009-11-24 16:43:22 +000057}
Douglas Gregord3d53012009-11-24 17:07:59 +000058
59struct ConvertibleToInt {
60 ConvertibleToInt();
61 ~ConvertibleToInt();
62 operator int();
63};
64
Douglas Gregor586596f2010-05-06 17:25:47 +000065ConvertibleToInt getConvToInt();
66
Douglas Gregord3d53012009-11-24 17:07:59 +000067void switch_destruct(int z) {
68 // CHECK: call void @_ZN16ConvertibleToIntC1Ev
69 switch (ConvertibleToInt conv = ConvertibleToInt()) {
70 case 0:
71 break;
72
73 default:
Douglas Gregor40e62992010-05-08 16:04:01 +000074 // CHECK: {{sw.default:|:5}}
Douglas Gregord3d53012009-11-24 17:07:59 +000075 // CHECK: store i32 19
76 z = 19;
77 break;
78 }
Douglas Gregor40e62992010-05-08 16:04:01 +000079 // CHECK: {{sw.epilog:|:6}}
Douglas Gregord3d53012009-11-24 17:07:59 +000080 // CHECK: call void @_ZN16ConvertibleToIntD1Ev
81 // CHECK: store i32 20
82 z = 20;
Douglas Gregor586596f2010-05-06 17:25:47 +000083
84 // CHECK: call void @_Z12getConvToIntv
85 // CHECK: call i32 @_ZN16ConvertibleToIntcviEv
86 // CHECK: call void @_ZN16ConvertibleToIntD1Ev
87 switch(getConvToInt()) {
88 case 0:
89 break;
90 }
91 // CHECK: store i32 27
92 z = 27;
93 // CHECK: ret
Douglas Gregord3d53012009-11-24 17:07:59 +000094}
Douglas Gregor5656e142009-11-24 21:15:44 +000095
96int foo();
97
98void while_destruct(int z) {
99 // CHECK: define void @_Z14while_destructi
Douglas Gregor40e62992010-05-08 16:04:01 +0000100 // CHECK: {{while.cond:|:3}}
Douglas Gregor5656e142009-11-24 21:15:44 +0000101 while (X x = X()) {
102 // CHECK: call void @_ZN1XC1Ev
103
Douglas Gregor40e62992010-05-08 16:04:01 +0000104 // CHECK: {{while.body:|:5}}
Douglas Gregor5656e142009-11-24 21:15:44 +0000105 // CHECK: store i32 21
106 z = 21;
107
Douglas Gregor40e62992010-05-08 16:04:01 +0000108 // CHECK: {{while.cleanup:|:6}}
Douglas Gregor5656e142009-11-24 21:15:44 +0000109 // CHECK: call void @_ZN1XD1Ev
110 }
Douglas Gregor40e62992010-05-08 16:04:01 +0000111 // CHECK: {{while.end|:8}}
Douglas Gregor5656e142009-11-24 21:15:44 +0000112 // CHECK: store i32 22
113 z = 22;
Douglas Gregor586596f2010-05-06 17:25:47 +0000114
115 // CHECK: call void @_Z4getXv
116 // CHECK: call zeroext i1 @_ZN1XcvbEv
117 // CHECK: call void @_ZN1XD1Ev
118 // CHECK: br
119 while(getX()) { }
120
121 // CHECK: store i32 25
122 z = 25;
123
124 // CHECK: ret
Douglas Gregor5656e142009-11-24 21:15:44 +0000125}
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000126
127void for_destruct(int z) {
128 // CHECK: define void @_Z12for_destruct
Douglas Gregor345e7d22009-11-25 00:29:29 +0000129 // CHECK: call void @_ZN1YC1Ev
130 for(Y y = Y(); X x = X(); ++z)
Douglas Gregor40e62992010-05-08 16:04:01 +0000131 // CHECK: {{for.cond:|:4}}
Douglas Gregord9752062009-11-25 01:51:31 +0000132 // CHECK: call void @_ZN1XC1Ev
Douglas Gregor40e62992010-05-08 16:04:01 +0000133 // CHECK: {{for.body:|:6}}
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000134 // CHECK: store i32 23
135 z = 23;
Douglas Gregor40e62992010-05-08 16:04:01 +0000136 // CHECK: {{for.inc:|:7}}
137 // CHECK: br label %{{for.cond.cleanup|10}}
138 // CHECK: {{for.cond.cleanup:|:10}}
Douglas Gregord9752062009-11-25 01:51:31 +0000139 // CHECK: call void @_ZN1XD1Ev
Douglas Gregor40e62992010-05-08 16:04:01 +0000140 // CHECK: {{for.end:|:12}}
Douglas Gregor345e7d22009-11-25 00:29:29 +0000141 // CHECK: call void @_ZN1YD1Ev
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000142 // CHECK: store i32 24
143 z = 24;
Douglas Gregor586596f2010-05-06 17:25:47 +0000144
145 // CHECK: call void @_Z4getXv
146 // CHECK: call zeroext i1 @_ZN1XcvbEv
147 // CHECK: call void @_ZN1XD1Ev
148 // CHECK: br
149 // CHECK: call void @_Z4getXv
150 // CHECK: load
151 // CHECK: add
152 // CHECK: call void @_ZN1XD1Ev
153 int i = 0;
154 for(; getX(); getX(), ++i) { }
155 z = 26;
156 // CHECK: store i32 26
157 // CHECK: ret
158}
159
160void do_destruct(int z) {
161 // CHECK: define void @_Z11do_destruct
162 do {
163 // CHECK: store i32 77
164 z = 77;
165 // CHECK: call void @_Z4getXv
166 // CHECK: call zeroext i1 @_ZN1XcvbEv
167 // CHECK: call void @_ZN1XD1Ev
168 // CHECK: br
169 } while (getX());
170 // CHECK: store i32 99
171 z = 99;
172 // CHECK: ret
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000173}