aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Sema/SemaDecl.cpp3
-rw-r--r--test/CodeGenObjCXX/nrvo.mm21
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index e0b6981424..6a205786d6 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -6700,6 +6700,9 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
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 0000000000..d28d54addb
--- /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