2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
|
2009-11-25 00:43:22 +08:00
|
|
|
void *f();
|
|
|
|
|
|
|
|
template <typename T> T* g() {
|
|
|
|
if (T* t = f())
|
|
|
|
return t;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void h() {
|
|
|
|
void *a = g<void>();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct X {
|
|
|
|
X();
|
2010-05-09 06:20:28 +08:00
|
|
|
X(const X&);
|
2009-11-25 00:43:22 +08:00
|
|
|
~X();
|
|
|
|
operator bool();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Y {
|
|
|
|
Y();
|
|
|
|
~Y();
|
|
|
|
};
|
|
|
|
|
2010-05-07 01:25:47 +08:00
|
|
|
X getX();
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z11if_destructi(
|
2009-11-25 00:43:22 +08:00
|
|
|
void if_destruct(int z) {
|
|
|
|
// Verify that the condition variable is destroyed at the end of the
|
|
|
|
// "if" statement.
|
|
|
|
// CHECK: call void @_ZN1XC1Ev
|
|
|
|
// CHECK: call zeroext i1 @_ZN1XcvbEv
|
|
|
|
if (X x = X()) {
|
|
|
|
// CHECK: store i32 18
|
|
|
|
z = 18;
|
|
|
|
}
|
|
|
|
// CHECK: call void @_ZN1XD1Ev
|
|
|
|
// CHECK: store i32 17
|
|
|
|
z = 17;
|
|
|
|
|
|
|
|
// CHECK: call void @_ZN1XC1Ev
|
|
|
|
if (X x = X())
|
|
|
|
Y y;
|
2010-01-14 04:57:29 +08:00
|
|
|
// CHECK: br
|
2009-11-25 00:43:22 +08:00
|
|
|
// CHECK: call void @_ZN1YC1Ev
|
|
|
|
// CHECK: call void @_ZN1YD1Ev
|
2010-01-14 04:57:29 +08:00
|
|
|
// CHECK: br
|
2009-11-25 00:43:22 +08:00
|
|
|
// CHECK: call void @_ZN1XD1Ev
|
2010-05-07 01:25:47 +08:00
|
|
|
|
|
|
|
// CHECK: call void @_Z4getXv
|
|
|
|
// CHECK: call zeroext i1 @_ZN1XcvbEv
|
|
|
|
// CHECK: call void @_ZN1XD1Ev
|
|
|
|
// CHECK: br
|
|
|
|
if (getX()) { }
|
|
|
|
|
|
|
|
// CHECK: ret
|
2009-11-25 00:43:22 +08:00
|
|
|
}
|
2009-11-25 01:07:59 +08:00
|
|
|
|
|
|
|
struct ConvertibleToInt {
|
|
|
|
ConvertibleToInt();
|
|
|
|
~ConvertibleToInt();
|
|
|
|
operator int();
|
|
|
|
};
|
|
|
|
|
2010-05-07 01:25:47 +08:00
|
|
|
ConvertibleToInt getConvToInt();
|
|
|
|
|
2009-11-25 01:07:59 +08:00
|
|
|
void switch_destruct(int z) {
|
|
|
|
// CHECK: call void @_ZN16ConvertibleToIntC1Ev
|
|
|
|
switch (ConvertibleToInt conv = ConvertibleToInt()) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// CHECK: store i32 19
|
|
|
|
z = 19;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// CHECK: call void @_ZN16ConvertibleToIntD1Ev
|
|
|
|
// CHECK: store i32 20
|
|
|
|
z = 20;
|
2010-05-07 01:25:47 +08:00
|
|
|
|
|
|
|
// CHECK: call void @_Z12getConvToIntv
|
|
|
|
// CHECK: call i32 @_ZN16ConvertibleToIntcviEv
|
|
|
|
// CHECK: call void @_ZN16ConvertibleToIntD1Ev
|
|
|
|
switch(getConvToInt()) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// CHECK: store i32 27
|
|
|
|
z = 27;
|
|
|
|
// CHECK: ret
|
2009-11-25 01:07:59 +08:00
|
|
|
}
|
2009-11-25 05:15:44 +08:00
|
|
|
|
|
|
|
int foo();
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z14while_destructi
|
2009-11-25 05:15:44 +08:00
|
|
|
void while_destruct(int z) {
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK: [[Z:%.*]] = alloca i32
|
|
|
|
// CHECK: [[CLEANUPDEST:%.*]] = alloca i32
|
2009-11-25 05:15:44 +08:00
|
|
|
while (X x = X()) {
|
|
|
|
// CHECK: call void @_ZN1XC1Ev
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-NEXT: [[COND:%.*]] = call zeroext i1 @_ZN1XcvbEv
|
|
|
|
// CHECK-NEXT: br i1 [[COND]]
|
2009-11-25 05:15:44 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
// Loop-exit staging block.
|
2010-07-24 05:56:41 +08:00
|
|
|
// CHECK: store i32 3, i32* [[CLEANUPDEST]]
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-NEXT: br
|
|
|
|
|
|
|
|
// While body.
|
|
|
|
// CHECK: store i32 21, i32* [[Z]]
|
2010-07-24 05:56:41 +08:00
|
|
|
// CHECK: store i32 0, i32* [[CLEANUPDEST]]
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-NEXT: br
|
2009-11-25 05:15:44 +08:00
|
|
|
z = 21;
|
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
// Cleanup.
|
2009-11-25 05:15:44 +08:00
|
|
|
// CHECK: call void @_ZN1XD1Ev
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-NEXT: [[DEST:%.*]] = load i32* [[CLEANUPDEST]]
|
|
|
|
// CHECK-NEXT: switch i32 [[DEST]]
|
2009-11-25 05:15:44 +08:00
|
|
|
}
|
2010-07-06 09:34:17 +08:00
|
|
|
|
|
|
|
// CHECK: store i32 22, i32* [[Z]]
|
2009-11-25 05:15:44 +08:00
|
|
|
z = 22;
|
2010-05-07 01:25:47 +08:00
|
|
|
|
|
|
|
// CHECK: call void @_Z4getXv
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-NEXT: call zeroext i1 @_ZN1XcvbEv
|
|
|
|
// CHECK-NEXT: call void @_ZN1XD1Ev
|
|
|
|
// CHECK-NEXT: br
|
2010-05-07 01:25:47 +08:00
|
|
|
while(getX()) { }
|
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK: store i32 25, i32* [[Z]]
|
2010-05-07 01:25:47 +08:00
|
|
|
z = 25;
|
|
|
|
|
|
|
|
// CHECK: ret
|
2009-11-25 05:15:44 +08:00
|
|
|
}
|
2009-11-25 08:27:52 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z12for_destructi(
|
2009-11-25 08:27:52 +08:00
|
|
|
void for_destruct(int z) {
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK: [[Z:%.*]] = alloca i32
|
2010-07-24 05:56:41 +08:00
|
|
|
// CHECK: [[CLEANUPDEST:%.*]] = alloca i32
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK: [[I:%.*]] = alloca i32
|
2009-11-25 08:29:29 +08:00
|
|
|
// CHECK: call void @_ZN1YC1Ev
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-NEXT: br
|
|
|
|
// -> %for.cond
|
|
|
|
|
|
|
|
for(Y y = Y(); X x = X(); ++z) {
|
|
|
|
// %for.cond: The loop condition.
|
2009-11-25 09:51:31 +08:00
|
|
|
// CHECK: call void @_ZN1XC1Ev
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-NEXT: [[COND:%.*]] = call zeroext i1 @_ZN1XcvbEv(
|
|
|
|
// CHECK-NEXT: br i1 [[COND]]
|
|
|
|
// -> %for.body, %for.cond.cleanup
|
|
|
|
|
|
|
|
// %for.cond.cleanup: Exit cleanup staging.
|
2010-07-24 05:56:41 +08:00
|
|
|
// CHECK: store i32 2, i32* [[CLEANUPDEST]]
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-NEXT: br
|
|
|
|
// -> %cleanup
|
|
|
|
|
|
|
|
// %for.body:
|
|
|
|
// CHECK: store i32 23, i32* [[Z]]
|
|
|
|
// CHECK-NEXT: br
|
|
|
|
// -> %for.inc
|
2009-11-25 08:27:52 +08:00
|
|
|
z = 23;
|
2010-07-06 09:34:17 +08:00
|
|
|
|
|
|
|
// %for.inc:
|
|
|
|
// CHECK: [[TMP:%.*]] = load i32* [[Z]]
|
|
|
|
// CHECK-NEXT: [[INC:%.*]] = add nsw i32 [[TMP]], 1
|
|
|
|
// CHECK-NEXT: store i32 [[INC]], i32* [[Z]]
|
2010-07-24 05:56:41 +08:00
|
|
|
// CHECK-NEXT: store i32 0, i32* [[CLEANUPDEST]]
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-NEXT: br
|
|
|
|
// -> %cleanup
|
|
|
|
|
|
|
|
// %cleanup: Destroys X.
|
2009-11-25 09:51:31 +08:00
|
|
|
// CHECK: call void @_ZN1XD1Ev
|
2010-07-24 05:56:41 +08:00
|
|
|
// CHECK-NEXT: [[YDESTTMP:%.*]] = load i32* [[CLEANUPDEST]]
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-NEXT: switch i32 [[YDESTTMP]]
|
2010-07-24 05:56:41 +08:00
|
|
|
// 0 -> %cleanup.cont, default -> %cleanup1
|
2010-07-06 09:34:17 +08:00
|
|
|
|
|
|
|
// %cleanup.cont: (eliminable)
|
|
|
|
// CHECK: br
|
|
|
|
// -> %for.cond
|
|
|
|
|
2010-07-24 05:56:41 +08:00
|
|
|
// %cleanup1: Destroys Y.
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK: call void @_ZN1YD1Ev(
|
|
|
|
// CHECK-NEXT: br
|
|
|
|
// -> %for.end
|
|
|
|
}
|
|
|
|
|
|
|
|
// %for.end:
|
2009-11-25 08:27:52 +08:00
|
|
|
// CHECK: store i32 24
|
|
|
|
z = 24;
|
2010-05-07 01:25:47 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-NEXT: store i32 0, i32* [[I]]
|
|
|
|
// CHECK-NEXT: br
|
|
|
|
// -> %for.cond6
|
|
|
|
|
|
|
|
// %for.cond6:
|
2010-05-07 01:25:47 +08:00
|
|
|
// CHECK: call void @_Z4getXv
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-NEXT: call zeroext i1 @_ZN1XcvbEv
|
|
|
|
// CHECK-NEXT: call void @_ZN1XD1Ev
|
|
|
|
// CHECK-NEXT: br
|
|
|
|
// -> %for.body10, %for.end16
|
|
|
|
|
|
|
|
// %for.body10:
|
2010-05-07 01:25:47 +08:00
|
|
|
// CHECK: br
|
2010-07-06 09:34:17 +08:00
|
|
|
// -> %for.inc11
|
|
|
|
|
|
|
|
// %for.inc11:
|
2010-05-07 01:25:47 +08:00
|
|
|
// CHECK: call void @_Z4getXv
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-NEXT: load i32* [[I]]
|
|
|
|
// CHECK-NEXT: add
|
|
|
|
// CHECK-NEXT: store
|
|
|
|
// CHECK-NEXT: call void @_ZN1XD1Ev
|
|
|
|
// CHECK-NEXT: br
|
|
|
|
// -> %for.cond6
|
2010-05-07 01:25:47 +08:00
|
|
|
int i = 0;
|
|
|
|
for(; getX(); getX(), ++i) { }
|
2010-07-06 09:34:17 +08:00
|
|
|
|
|
|
|
// %for.end16
|
2010-05-07 01:25:47 +08:00
|
|
|
// CHECK: store i32 26
|
2010-07-06 09:34:17 +08:00
|
|
|
z = 26;
|
|
|
|
|
|
|
|
// CHECK-NEXT: ret void
|
2010-05-07 01:25:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void do_destruct(int z) {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z11do_destruct
|
2010-05-07 01:25:47 +08:00
|
|
|
do {
|
|
|
|
// CHECK: store i32 77
|
|
|
|
z = 77;
|
|
|
|
// CHECK: call void @_Z4getXv
|
|
|
|
// CHECK: call zeroext i1 @_ZN1XcvbEv
|
|
|
|
// CHECK: call void @_ZN1XD1Ev
|
|
|
|
// CHECK: br
|
|
|
|
} while (getX());
|
|
|
|
// CHECK: store i32 99
|
|
|
|
z = 99;
|
|
|
|
// CHECK: ret
|
2009-11-25 08:27:52 +08:00
|
|
|
}
|
2010-05-09 06:20:28 +08:00
|
|
|
|
|
|
|
int f(X);
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
int instantiated(T x) {
|
|
|
|
int result;
|
|
|
|
|
|
|
|
// CHECK: call void @_ZN1XC1ERKS_
|
|
|
|
// CHECK: call i32 @_Z1f1X
|
|
|
|
// CHECK: call void @_ZN1XD1Ev
|
|
|
|
// CHECK: br
|
|
|
|
// CHECK: store i32 2
|
|
|
|
// CHECK: br
|
|
|
|
// CHECK: store i32 3
|
|
|
|
if (f(x)) { result = 2; } else { result = 3; }
|
|
|
|
|
|
|
|
// CHECK: call void @_ZN1XC1ERKS_
|
|
|
|
// CHECK: call i32 @_Z1f1X
|
|
|
|
// CHECK: call void @_ZN1XD1Ev
|
|
|
|
// CHECK: br
|
|
|
|
// CHECK: store i32 4
|
|
|
|
// CHECK: br
|
|
|
|
while (f(x)) { result = 4; }
|
|
|
|
|
|
|
|
// CHECK: call void @_ZN1XC1ERKS_
|
|
|
|
// CHECK: call i32 @_Z1f1X
|
|
|
|
// CHECK: call void @_ZN1XD1Ev
|
|
|
|
// CHECK: br
|
|
|
|
// CHECK: store i32 6
|
|
|
|
// CHECK: br
|
|
|
|
// CHECK: call void @_ZN1XC1ERKS_
|
|
|
|
// CHECK: call i32 @_Z1f1X
|
|
|
|
// CHECK: store i32 5
|
|
|
|
// CHECK: call void @_ZN1XD1Ev
|
|
|
|
// CHECK: br
|
|
|
|
for (; f(x); f(x), result = 5) {
|
|
|
|
result = 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: call void @_ZN1XC1ERKS_
|
|
|
|
// CHECK: call i32 @_Z1f1X
|
|
|
|
// CHECK: call void @_ZN1XD1Ev
|
|
|
|
// CHECK: switch i32
|
|
|
|
// CHECK: store i32 7
|
|
|
|
// CHECK: store i32 8
|
|
|
|
switch (f(x)) {
|
|
|
|
case 0:
|
|
|
|
result = 7;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
result = 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: store i32 9
|
|
|
|
// CHECK: br
|
|
|
|
// CHECK: call void @_ZN1XC1ERKS_
|
|
|
|
// CHECK: call i32 @_Z1f1X
|
|
|
|
// CHECK: call void @_ZN1XD1Ev
|
|
|
|
// CHECK: br
|
|
|
|
do {
|
|
|
|
result = 9;
|
|
|
|
} while (f(x));
|
|
|
|
|
|
|
|
// CHECK: store i32 10
|
|
|
|
// CHECK: call void @_ZN1XC1ERKS_
|
|
|
|
// CHECK: call zeroext i1 @_ZN1XcvbEv
|
|
|
|
// CHECK: call void @_ZN1XD1Ev
|
|
|
|
// CHECK: br
|
|
|
|
do {
|
|
|
|
result = 10;
|
|
|
|
} while (X(x));
|
|
|
|
|
|
|
|
// CHECK: ret i32
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template int instantiated(X);
|