Implement the Named Return Value Optimization (NRVO) for Objective-C++
methods. Fixes PR10835 / <rdar://problem/10050178>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139175 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index e0b6981..6a20578 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -6700,6 +6700,9 @@
DiagnoseUnusedParameters(MD->param_begin(), MD->param_end());
DiagnoseSizeOfParametersAndReturnValue(MD->param_begin(), MD->param_end(),
MD->getResultType(), MD);
+
+ if (Body)
+ ComputeNRVO(Body, getCurFunction());
}
if (ObjCShouldCallSuperDealloc) {
Diag(MD->getLocEnd(), diag::warn_objc_missing_super_dealloc);
diff --git a/test/CodeGenObjCXX/nrvo.mm b/test/CodeGenObjCXX/nrvo.mm
new file mode 100644
index 0000000..d28d54a
--- /dev/null
+++ b/test/CodeGenObjCXX/nrvo.mm
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s -O1 -triple x86_64-apple-darwin10.0.0 | FileCheck %s
+
+// PR10835 / <rdar://problem/10050178>
+struct X {
+ X();
+ X(const X&);
+ ~X();
+};
+
+@interface NRVO
+@end
+
+@implementation NRVO
+// CHECK: define internal void @"\01-[NRVO getNRVO]"
+- (X)getNRVO {
+ X x;
+ // CHECK: tail call void @_ZN1XC1Ev
+ // CHECK-NEXT: ret void
+ return x;
+}
+@end