1 // Output file should have no calls to error() with folding.
2 // RUN: %clang_cc1 -triple i386-unknown-unknown -mllvm -inline-threshold=1024 -O3 -emit-llvm -o %t %s
3 // RUN: FileCheck %s < %t
5 static unsigned pow(unsigned Base
, unsigned Power
) {
13 unsigned Product
, Index
;
15 TempTracker() : Product(1), Index(0) {}
19 // FIXME: This can be used to check elision as well, if P = 0 hacks are removed.
25 A(TempTracker
&_TT
, unsigned _P
, bool _Truth
= true)
26 : TT(_TT
), P(_P
), Truth(_Truth
) {}
27 A(const A
&RHS
) : TT(RHS
.TT
), P(RHS
.P
), Truth(RHS
.Truth
) { RHS
.P
= 0; }
30 TT
.Product
*= pow(P
, ++TT
.Index
);
33 A
&operator=(const A
&RHS
) {
41 operator bool () { return Truth
; }
45 static unsigned f0(bool val
= false) {
57 static unsigned f1(bool val
= true) {
69 static unsigned f2() {
81 static unsigned f3() {
85 if (A b
= A(tt
, 3, false))
95 static unsigned f4() {
99 while (A b
= A(tt
, 3, false))
107 static unsigned f5() {
111 while (A b
= A(tt
, 3, true)) {
120 // 3, 7, 11, 5, 13, 2
121 static unsigned f6() {
125 for (A b
= (A(tt
, 3), A(tt
, 5)), c
= (A(tt
, 7), A(tt
, 11));;)
133 static unsigned f7() {
136 (void)((A(tt
, 2, false) && A(tt
, 3, false)) || A(tt
, 5, false));
142 static unsigned f8() {
146 (void)((A(tt
, 2) || A(tt
, 3)) && A(tt
, 5));
151 extern "C" void error();
152 extern "C" void print(const char *Name
, unsigned N
);
154 #define ORDER2(a, b) (pow(a, 1) * pow(b, 2))
155 #define ORDER3(a, b, c) (ORDER2(a, b) * pow(c, 3))
156 #define ORDER4(a, b, c, d) (ORDER3(a, b, c) * pow(d, 4))
157 #define ORDER5(a, b, c, d, e) (ORDER4(a, b, c, d) * pow(e, 5))
158 #define ORDER6(a, b, c, d, e, f) (ORDER5(a, b, c, d, e) * pow(f, 6))
160 // CHECK: call void @print(i8* noundef {{.*}}, i32 noundef 1176)
162 if (f0() != ORDER3(3, 7, 2))
165 // CHECK: call void @print(i8* noundef {{.*}}, i32 noundef 411600)
167 if (f1() != ORDER4(3, 5, 7, 2))
170 // CHECK: call void @print(i8* noundef {{.*}}, i32 noundef 246960)
172 if (f2() != ORDER4(5, 3, 7, 2))
175 // CHECK: call void @print(i8* noundef {{.*}}, i32 noundef 1341648)
177 if (f3() != ORDER4(7, 3, 11, 2))
180 // CHECK: call void @print(i8* noundef {{.*}}, i32 noundef 1176)
182 if (f4() != ORDER3(3, 7, 2))
185 // CHECK: call void @print(i8* noundef {{.*}}, i32 noundef 246960)
187 if (f5() != ORDER4(5, 3, 7, 2))
190 // CHECK: call void @print(i8* noundef {{.*}}, i32 noundef 1251552576)
192 if (f6() != ORDER6(3, 7, 11, 5, 13, 2))
195 // CHECK: call void @print(i8* noundef {{.*}}, i32 noundef 20)
197 if (f7() != ORDER2(5, 2))
200 // CHECK: call void @print(i8* noundef {{.*}}, i32 noundef 20)
202 if (f8() != ORDER2(5, 2))
213 extern "C" void error() {
217 extern "C" void print(const char *name
, unsigned N
) {
218 printf("%s: %d\n", name
, N
);