summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGenCXX/nrvo.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-05-15 06:46:45 +0000
committerDouglas Gregor <dgregor@apple.com>2010-05-15 06:46:45 +0000
commit290c93ec0dea0188c4478a3d73ff48ae5b693498 (patch)
treef30376d4018b61f86e7dde8bdfe167eb3876762f /clang/test/CodeGenCXX/nrvo.cpp
parent84ce2908220832675999a0d5be9f9b914c26ea66 (diff)
downloadbcm5719-llvm-290c93ec0dea0188c4478a3d73ff48ae5b693498.tar.gz
bcm5719-llvm-290c93ec0dea0188c4478a3d73ff48ae5b693498.zip
Implement a simple form of the C++ named return value optimization for
return statements. We perform NRVO only when all of the return statements in the function return the same variable. Fixes some link failures in Boost.Interprocess (which is relying on NRVO), and probably improves performance for some C++ applications. llvm-svn: 103867
Diffstat (limited to 'clang/test/CodeGenCXX/nrvo.cpp')
-rw-r--r--clang/test/CodeGenCXX/nrvo.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/clang/test/CodeGenCXX/nrvo.cpp b/clang/test/CodeGenCXX/nrvo.cpp
new file mode 100644
index 00000000000..7b4f20398d8
--- /dev/null
+++ b/clang/test/CodeGenCXX/nrvo.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+
+// Test code generation for the named return value optimization.
+class X {
+public:
+ X();
+ X(const X&);
+ ~X();
+};
+
+// CHECK: define void @_Z5test0v
+X test0() {
+ X x;
+ // CHECK-NOT: call void @_ZN1XD1Ev
+ // CHECK: ret void
+ return x;
+}
+
+// CHECK: define void @_Z5test1b(
+X test1(bool B) {
+ // CHECK: call void @_ZN1XC1Ev
+ X x;
+ // CHECK-NOT: call void @_ZN1XD1Ev
+ // CHECK: ret void
+ if (B)
+ return (x);
+ return x;
+}
+
+// CHECK: define void @_Z5test2b
+X test2(bool B) {
+ // No NRVO
+ // CHECK: call void @_ZN1XC1Ev
+ X x;
+ // CHECK: call void @_ZN1XC1Ev
+ X y;
+ // CHECK: call void @_ZN1XC1ERKS_
+ if (B)
+ return y;
+ // CHECK: call void @_ZN1XC1ERKS_
+ return x;
+ // CHECK: call void @_ZN1XD1Ev
+ // CHECK: call void @_ZN1XD1Ev
+ // CHECK: ret void
+}
+
+X test3(bool B) {
+ // FIXME: We don't manage to apply NRVO here, although we could.
+ {
+ X y;
+ return y;
+ }
+ X x;
+ return x;
+}
OpenPOWER on IntegriCloud