2012-10-24 20:22:56 +08:00
|
|
|
// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -O1 -o - %s | FileCheck %s
|
|
|
|
// RUN: %clang_cc1 -triple i386-unknown-unknown -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();
|
|
|
|
};
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z5test0v
|
|
|
|
// CHECK-EH-LABEL: 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;
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z5test1b(
|
|
|
|
// CHECK-EH-LABEL: 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
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z5test2b
|
|
|
|
// CHECK-EH-LABEL: 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'
|
2011-09-20 04:31:14 +08:00
|
|
|
// CHECK-EH: [[CAUGHTVAL:%.*]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
|
|
|
|
// CHECK-EH-NEXT: cleanup
|
|
|
|
// CHECK-EH-NEXT: extractvalue { i8*, i32 } [[CAUGHTVAL]], 0
|
|
|
|
// CHECK-EH-NEXT: extractvalue { i8*, i32 } [[CAUGHTVAL]], 1
|
2010-07-06 09:34:17 +08:00
|
|
|
// 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-09-20 04:31:14 +08:00
|
|
|
// CHECK-EH: resume { i8*, i32 }
|
2010-07-06 09:34:17 +08:00
|
|
|
|
|
|
|
// %terminate.lpad: terminate landing pad.
|
2013-02-12 11:51:46 +08:00
|
|
|
// CHECK-EH: [[T0:%.*]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
|
2011-09-20 04:31:14 +08:00
|
|
|
// CHECK-EH-NEXT: catch i8* null
|
2013-02-12 11:51:46 +08:00
|
|
|
// CHECK-EH-NEXT: [[T1:%.*]] = extractvalue { i8*, i32 } [[T0]], 0
|
2013-02-22 17:10:20 +08:00
|
|
|
// CHECK-EH-NEXT: call void @__clang_call_terminate(i8* [[T1]]) [[NR_NUW:#[0-9]+]]
|
2010-07-06 09:34:17 +08:00
|
|
|
// 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();
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z5test4b
|
2010-05-17 23:52:46 +08:00
|
|
|
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
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-EH-LABEL: define void @_Z5test5
|
2011-01-22 02:05:27 +08:00
|
|
|
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
|
2011-11-11 11:57:31 +08:00
|
|
|
|
|
|
|
// rdar://problem/10430868
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z5test6v
|
2011-11-11 11:57:31 +08:00
|
|
|
X test6() {
|
|
|
|
X a __attribute__((aligned(8)));
|
|
|
|
return a;
|
|
|
|
// CHECK: [[A:%.*]] = alloca [[X:%.*]], align 8
|
2011-11-12 07:36:04 +08:00
|
|
|
// CHECK-NEXT: call {{.*}} @_ZN1XC1Ev([[X]]* [[A]])
|
|
|
|
// CHECK-NEXT: call {{.*}} @_ZN1XC1ERKS_([[X]]* {{%.*}}, [[X]]* [[A]])
|
|
|
|
// CHECK-NEXT: call {{.*}} @_ZN1XD1Ev([[X]]* [[A]])
|
2011-11-11 11:57:31 +08:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
}
|
2013-02-22 17:10:20 +08:00
|
|
|
|
|
|
|
// CHECK-EH: attributes [[NR_NUW]] = { noreturn nounwind }
|