blob: 92b41036027fc8ec14879e4fb617893cc665e2da [file] [log] [blame]
Douglas Gregor290c93e2010-05-15 06:46:45 +00001// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
Douglas Gregor17012562010-05-15 16:39:56 +00002// RUN: %clang_cc1 -emit-llvm -fexceptions -o - %s | FileCheck --check-prefix=CHECK-EH %s
Douglas Gregor290c93e2010-05-15 06:46:45 +00003
4// Test code generation for the named return value optimization.
5class X {
6public:
7 X();
8 X(const X&);
9 ~X();
10};
11
12// CHECK: define void @_Z5test0v
Douglas Gregor17012562010-05-15 16:39:56 +000013// CHECK-EH: define void @_Z5test0v
Douglas Gregor290c93e2010-05-15 06:46:45 +000014X test0() {
15 X x;
16 // CHECK-NOT: call void @_ZN1XD1Ev
17 // CHECK: ret void
Douglas Gregor17012562010-05-15 16:39:56 +000018 // CHECK-EH: ret void
Douglas Gregor290c93e2010-05-15 06:46:45 +000019 return x;
Douglas Gregor17012562010-05-15 16:39:56 +000020 // CHECK-EH: ehcleanup:
21 // CHECK-EH: invoke void @_ZN1XD1Ev
Douglas Gregor290c93e2010-05-15 06:46:45 +000022}
23
24// CHECK: define void @_Z5test1b(
25X test1(bool B) {
26 // CHECK: call void @_ZN1XC1Ev
27 X x;
28 // CHECK-NOT: call void @_ZN1XD1Ev
29 // CHECK: ret void
30 if (B)
31 return (x);
32 return x;
Douglas Gregor17012562010-05-15 16:39:56 +000033 // CHECK-EH: ehcleanup:
34 // CHECK-EH: invoke void @_ZN1XD1Ev
Douglas Gregor290c93e2010-05-15 06:46:45 +000035}
36
37// CHECK: define void @_Z5test2b
Douglas Gregor17012562010-05-15 16:39:56 +000038// CHECK-EH: define void @_Z5test2b
Douglas Gregor290c93e2010-05-15 06:46:45 +000039X test2(bool B) {
40 // No NRVO
41 // CHECK: call void @_ZN1XC1Ev
42 X x;
43 // CHECK: call void @_ZN1XC1Ev
44 X y;
45 // CHECK: call void @_ZN1XC1ERKS_
Douglas Gregor17012562010-05-15 16:39:56 +000046 // CHECK-EH: invoke void @_ZN1XC1ERKS_
Douglas Gregor290c93e2010-05-15 06:46:45 +000047 if (B)
48 return y;
49 // CHECK: call void @_ZN1XC1ERKS_
Douglas Gregor17012562010-05-15 16:39:56 +000050 // CHECK-EH: invoke void @_ZN1XC1ERKS_
Douglas Gregor290c93e2010-05-15 06:46:45 +000051 return x;
52 // CHECK: call void @_ZN1XD1Ev
53 // CHECK: call void @_ZN1XD1Ev
54 // CHECK: ret void
Douglas Gregor17012562010-05-15 16:39:56 +000055 // CHECK-EH: ehcleanup:
56 // CHECK-EH: invoke void @_ZN1XD1Ev
57 // CHECK-EH: invoke void @_ZN1XD1Ev
Douglas Gregor290c93e2010-05-15 06:46:45 +000058}
59
60X test3(bool B) {
61 // FIXME: We don't manage to apply NRVO here, although we could.
62 {
63 X y;
64 return y;
65 }
66 X x;
67 return x;
68}