From: Douglas Gregor Date: Tue, 6 Sep 2011 20:33:37 +0000 (+0000) Subject: Implement the Named Return Value Optimization (NRVO) for Objective-C++ X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f7603f6ca76aec055cbf1644c89ce0dca9fa2c03;p=clang Implement the Named Return Value Optimization (NRVO) for Objective-C++ methods. Fixes PR10835 / . 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 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 / +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