2010-05-17 23:52:46 +08:00
|
|
|
// RUN: %clang_cc1 -emit-llvm -O1 -o - %s | FileCheck %s
|
2011-02-28 08:40:07 +08:00
|
|
|
// RUN: %clang_cc1 -emit-llvm -O1 -fcxx-exceptions -fexceptions -o - %s | FileCheck --check-prefix=CHECK-EH %s
|
2010-05-15 14:46:45 +08:00
|
|
|
|
|
|
|
// Test code generation for the named return value optimization.
|
|
|
|
class X {
|
|
|
|
public:
|
|
|
|
X();
|
|
|
|
X(const X&);
|
|
|
|
~X();
|
|
|
|
};
|
|
|
|
|
|
|
|
// CHECK: define void @_Z5test0v
|
2010-05-16 00:39:56 +08:00
|
|
|
// CHECK-EH: define void @_Z5test0v
|
2010-05-15 14:46:45 +08:00
|
|
|
X test0() {
|
|
|
|
X x;
|
2011-06-15 05:20:53 +08:00
|
|
|
// CHECK: call {{.*}} @_ZN1XC1Ev
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
|
2011-06-15 05:20:53 +08:00
|
|
|
// CHECK-EH: call {{.*}} @_ZN1XC1Ev
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-EH-NEXT: ret void
|
2010-05-15 14:46:45 +08:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: define void @_Z5test1b(
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-EH: define void @_Z5test1b(
|
2010-05-15 14:46:45 +08:00
|
|
|
X test1(bool B) {
|
2011-06-15 05:20:53 +08:00
|
|
|
// CHECK: tail call {{.*}} @_ZN1XC1Ev
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-NEXT: ret void
|
2010-05-15 14:46:45 +08:00
|
|
|
X x;
|
|
|
|
if (B)
|
|
|
|
return (x);
|
|
|
|
return x;
|
2011-06-15 05:20:53 +08:00
|
|
|
// CHECK-EH: tail call {{.*}} @_ZN1XC1Ev
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-EH-NEXT: ret void
|
2010-05-15 14:46:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: define void @_Z5test2b
|
2010-05-16 00:39:56 +08:00
|
|
|
// CHECK-EH: define void @_Z5test2b
|
2010-05-15 14:46:45 +08:00
|
|
|
X test2(bool B) {
|
2010-07-06 09:34:17 +08:00
|
|
|
// No NRVO.
|
|
|
|
|
2010-05-15 14:46:45 +08:00
|
|
|
X x;
|
|
|
|
X y;
|
|
|
|
if (B)
|
|
|
|
return y;
|
|
|
|
return x;
|
2010-07-06 09:34:17 +08:00
|
|
|
|
2011-06-15 05:20:53 +08:00
|
|
|
// CHECK: call {{.*}} @_ZN1XC1Ev
|
|
|
|
// CHECK-NEXT: call {{.*}} @_ZN1XC1Ev
|
|
|
|
// CHECK: call {{.*}} @_ZN1XC1ERKS_
|
|
|
|
// CHECK: call {{.*}} @_ZN1XC1ERKS_
|
|
|
|
// CHECK: call {{.*}} @_ZN1XD1Ev
|
|
|
|
// CHECK: call {{.*}} @_ZN1XD1Ev
|
2010-05-15 14:46:45 +08:00
|
|
|
// CHECK: ret void
|
2010-07-06 09:34:17 +08:00
|
|
|
|
|
|
|
// The block ordering in the -fexceptions IR is unfortunate.
|
|
|
|
|
2011-06-15 05:20:53 +08:00
|
|
|
// CHECK-EH: call {{.*}} @_ZN1XC1Ev
|
|
|
|
// CHECK-EH-NEXT: invoke {{.*}} @_ZN1XC1Ev
|
2010-07-14 04:32:21 +08:00
|
|
|
// -> %invoke.cont, %lpad
|
2010-07-06 09:34:17 +08:00
|
|
|
|
2010-07-14 04:32:21 +08:00
|
|
|
// %invoke.cont:
|
2010-07-06 09:34:17 +08:00
|
|
|
// CHECK-EH: br i1
|
|
|
|
// -> %if.then, %if.end
|
|
|
|
|
|
|
|
// %if.then: returning 'x'
|
2011-06-15 05:20:53 +08:00
|
|
|
// CHECK-EH: invoke {{.*}} @_ZN1XC1ERKS_
|
2010-07-14 04:32:21 +08:00
|
|
|
// -> %cleanup, %lpad1
|
2010-07-06 09:34:17 +08:00
|
|
|
|
|
|
|
// %lpad: landing pad for ctor of 'y', dtor of 'y'
|
|
|
|
// CHECK-EH: call i8* @llvm.eh.exception()
|
|
|
|
// CHECK-EH: call i32 (i8*, i8*, ...)* @llvm.eh.selector
|
|
|
|
// CHECK-EH-NEXT: br label
|
|
|
|
// -> %eh.cleanup
|
|
|
|
|
2010-07-14 04:32:21 +08:00
|
|
|
// %lpad1: landing pad for return copy ctors, EH cleanup for 'y'
|
2011-06-15 05:20:53 +08:00
|
|
|
// CHECK-EH: invoke {{.*}} @_ZN1XD1Ev
|
2010-07-06 09:34:17 +08:00
|
|
|
// -> %eh.cleanup, %terminate.lpad
|
|
|
|
|
|
|
|
// %if.end: returning 'y'
|
2011-06-15 05:20:53 +08:00
|
|
|
// CHECK-EH: invoke {{.*}} @_ZN1XC1ERKS_
|
2010-07-14 04:32:21 +08:00
|
|
|
// -> %cleanup, %lpad1
|
2010-07-06 09:34:17 +08:00
|
|
|
|
|
|
|
// %cleanup: normal cleanup for 'y'
|
2011-06-15 05:20:53 +08:00
|
|
|
// CHECK-EH: invoke {{.*}} @_ZN1XD1Ev
|
2010-07-14 04:32:21 +08:00
|
|
|
// -> %invoke.cont11, %lpad
|
|
|
|
|
|
|
|
// %invoke.cont11: normal cleanup for 'x'
|
2011-06-15 05:20:53 +08:00
|
|
|
// CHECK-EH: call {{.*}} @_ZN1XD1Ev
|
2010-07-14 04:32:21 +08:00
|
|
|
// CHECK-EH-NEXT: ret void
|
2010-07-06 09:34:17 +08:00
|
|
|
|
|
|
|
// %eh.cleanup: EH cleanup for 'x'
|
2011-06-15 05:20:53 +08:00
|
|
|
// CHECK-EH: invoke {{.*}} @_ZN1XD1Ev
|
2010-07-14 04:32:21 +08:00
|
|
|
// -> %invoke.cont17, %terminate.lpad
|
|
|
|
|
|
|
|
// %invoke.cont17: rethrow block for %eh.cleanup.
|
|
|
|
// This really should be elsewhere in the function.
|
2011-05-29 05:13:02 +08:00
|
|
|
// CHECK-EH: call void @llvm.eh.resume(
|
2010-07-14 04:32:21 +08:00
|
|
|
// CHECK-EH-NEXT: unreachable
|
2010-07-06 09:34:17 +08:00
|
|
|
|
|
|
|
// %terminate.lpad: terminate landing pad.
|
|
|
|
// CHECK-EH: call i8* @llvm.eh.exception()
|
|
|
|
// CHECK-EH-NEXT: call i32 (i8*, i8*, ...)* @llvm.eh.selector
|
|
|
|
// CHECK-EH-NEXT: call void @_ZSt9terminatev()
|
|
|
|
// CHECK-EH-NEXT: unreachable
|
|
|
|
|
2010-05-15 14:46:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
X test3(bool B) {
|
|
|
|
// FIXME: We don't manage to apply NRVO here, although we could.
|
|
|
|
{
|
|
|
|
X y;
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
X x;
|
|
|
|
return x;
|
|
|
|
}
|
2010-05-17 23:52:46 +08:00
|
|
|
|
|
|
|
extern "C" void exit(int) throw();
|
|
|
|
|
|
|
|
// CHECK: define void @_Z5test4b
|
|
|
|
X test4(bool B) {
|
|
|
|
{
|
2011-06-15 05:20:53 +08:00
|
|
|
// CHECK: tail call {{.*}} @_ZN1XC1Ev
|
2010-05-17 23:52:46 +08:00
|
|
|
X x;
|
|
|
|
// CHECK: br i1
|
|
|
|
if (B)
|
|
|
|
return x;
|
|
|
|
}
|
2011-06-15 05:20:53 +08:00
|
|
|
// CHECK: tail call {{.*}} @_ZN1XD1Ev
|
2010-05-17 23:52:46 +08:00
|
|
|
// CHECK: tail call void @exit(i32 1)
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-01-22 02:05:27 +08:00
|
|
|
|
2011-02-20 03:23:03 +08:00
|
|
|
#ifdef __EXCEPTIONS
|
2011-01-22 02:05:27 +08:00
|
|
|
// CHECK-EH: define void @_Z5test5
|
|
|
|
void may_throw();
|
|
|
|
X test5() {
|
|
|
|
try {
|
|
|
|
may_throw();
|
|
|
|
} catch (X x) {
|
2011-06-15 05:20:53 +08:00
|
|
|
// CHECK-EH: invoke {{.*}} @_ZN1XC1ERKS_
|
2011-01-22 02:05:27 +08:00
|
|
|
// CHECK-EH: call void @__cxa_end_catch()
|
|
|
|
// CHECK-EH: ret void
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
2011-02-20 03:23:03 +08:00
|
|
|
#endif
|