freebsd-nq/test/CodeGenCXX/nrvo.cpp

134 lines
3.1 KiB
C++
Raw Normal View History

2010-05-27 15:17:06 +00:00
// RUN: %clang_cc1 -emit-llvm -O1 -o - %s | FileCheck %s
2010-07-13 17:21:42 +00:00
// RUN: %clang_cc1 -emit-llvm -O1 -fexceptions -o - %s | FileCheck --check-prefix=CHECK-EH %s
2010-05-27 15:17:06 +00:00
// Test code generation for the named return value optimization.
class X {
public:
X();
X(const X&);
~X();
};
// CHECK: define void @_Z5test0v
// CHECK-EH: define void @_Z5test0v
X test0() {
X x;
2010-07-13 17:21:42 +00:00
// CHECK: call void @_ZN1XC1Ev
// CHECK-NEXT: ret void
// CHECK-EH: call void @_ZN1XC1Ev
// CHECK-EH-NEXT: ret void
2010-05-27 15:17:06 +00:00
return x;
}
// CHECK: define void @_Z5test1b(
2010-07-13 17:21:42 +00:00
// CHECK-EH: define void @_Z5test1b(
2010-05-27 15:17:06 +00:00
X test1(bool B) {
2010-07-13 17:21:42 +00:00
// CHECK: tail call void @_ZN1XC1Ev
// CHECK-NEXT: ret void
2010-05-27 15:17:06 +00:00
X x;
if (B)
return (x);
return x;
2010-07-13 17:21:42 +00:00
// CHECK-EH: tail call void @_ZN1XC1Ev
// CHECK-EH-NEXT: ret void
2010-05-27 15:17:06 +00:00
}
// CHECK: define void @_Z5test2b
// CHECK-EH: define void @_Z5test2b
X test2(bool B) {
2010-07-13 17:21:42 +00:00
// No NRVO.
2010-05-27 15:17:06 +00:00
X x;
X y;
if (B)
return y;
return x;
2010-07-13 17:21:42 +00:00
// CHECK: call void @_ZN1XC1Ev
// CHECK-NEXT: call void @_ZN1XC1Ev
// CHECK: call void @_ZN1XC1ERKS_
// CHECK: call void @_ZN1XC1ERKS_
2010-05-27 15:17:06 +00:00
// CHECK: call void @_ZN1XD1Ev
// CHECK: call void @_ZN1XD1Ev
// CHECK: ret void
2010-07-13 17:21:42 +00:00
// The block ordering in the -fexceptions IR is unfortunate.
// CHECK-EH: call void @_ZN1XC1Ev
// CHECK-EH-NEXT: invoke void @_ZN1XC1Ev
2010-07-15 17:07:12 +00:00
// -> %invoke.cont, %lpad
2010-07-13 17:21:42 +00:00
2010-07-15 17:07:12 +00:00
// %invoke.cont:
2010-07-13 17:21:42 +00:00
// CHECK-EH: br i1
// -> %if.then, %if.end
// %if.then: returning 'x'
// CHECK-EH: invoke void @_ZN1XC1ERKS_
2010-07-15 17:07:12 +00:00
// -> %cleanup, %lpad1
2010-07-13 17:21:42 +00: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-15 17:07:12 +00:00
// %lpad1: landing pad for return copy ctors, EH cleanup for 'y'
2010-07-13 17:21:42 +00:00
// CHECK-EH: invoke void @_ZN1XD1Ev
// -> %eh.cleanup, %terminate.lpad
// %if.end: returning 'y'
// CHECK-EH: invoke void @_ZN1XC1ERKS_
2010-07-15 17:07:12 +00:00
// -> %cleanup, %lpad1
2010-07-13 17:21:42 +00:00
// %cleanup: normal cleanup for 'y'
2010-05-27 15:17:06 +00:00
// CHECK-EH: invoke void @_ZN1XD1Ev
2010-07-15 17:07:12 +00:00
// -> %invoke.cont11, %lpad
// %invoke.cont11: normal cleanup for 'x'
// CHECK-EH: call void @_ZN1XD1Ev
// CHECK-EH-NEXT: ret void
2010-07-13 17:21:42 +00:00
// %eh.cleanup: EH cleanup for 'x'
2010-05-27 15:17:06 +00:00
// CHECK-EH: invoke void @_ZN1XD1Ev
2010-07-15 17:07:12 +00:00
// -> %invoke.cont17, %terminate.lpad
// %invoke.cont17: rethrow block for %eh.cleanup.
// This really should be elsewhere in the function.
// CHECK-EH: call void @_Unwind_Resume_or_Rethrow
// CHECK-EH-NEXT: unreachable
2010-07-13 17:21:42 +00: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-27 15:17:06 +00: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;
}
extern "C" void exit(int) throw();
// CHECK: define void @_Z5test4b
X test4(bool B) {
{
// CHECK: tail call void @_ZN1XC1Ev
X x;
// CHECK: br i1
if (B)
return x;
}
// CHECK: tail call void @_ZN1XD1Ev
// CHECK: tail call void @exit(i32 1)
exit(1);
}