<div dir="ltr">Whenever possible, do include context for why a patch is being reverted in the commit message - buildbot links, but also potentially describing/copy-pasting inline whatever the problem(s) are. This makes it easier for people tracking the state of upstream to know whether they may need to pull in this patch revert/whether it might be the source of a bug they're investigating. (& also in the future if someone else is interested in pulling this patch back in, they'll have an idea of where to start, in terms of fixing the issue before recommitting)</div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jun 18, 2018 at 10:39 PM Taiju Tsuiki via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: tzik<br>
Date: Mon Jun 18 22:35:30 2018<br>
New Revision: 335022<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=335022&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=335022&view=rev</a><br>
Log:<br>
Revert r335019 "Update NRVO logic to support early return (Attempt 2)"<br>
<br>
Removed:<br>
cfe/trunk/test/CodeGenCXX/nrvo-noopt.cpp<br>
cfe/trunk/test/SemaCXX/nrvo-ast.cpp<br>
Modified:<br>
cfe/trunk/include/clang/AST/Decl.h<br>
cfe/trunk/include/clang/Sema/Scope.h<br>
cfe/trunk/lib/Sema/Scope.cpp<br>
cfe/trunk/lib/Sema/SemaDecl.cpp<br>
cfe/trunk/lib/Sema/SemaExpr.cpp<br>
cfe/trunk/lib/Sema/SemaStmt.cpp<br>
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp<br>
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp<br>
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp<br>
cfe/trunk/test/CodeGenCXX/nrvo.cpp<br>
<br>
Modified: cfe/trunk/include/clang/AST/Decl.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=335022&r1=335021&r2=335022&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=335022&r1=335021&r2=335022&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/Decl.h (original)<br>
+++ cfe/trunk/include/clang/AST/Decl.h Mon Jun 18 22:35:30 2018<br>
@@ -879,12 +879,6 @@ protected:<br>
DAK_Normal<br>
};<br>
<br>
- enum NRVOMode {<br>
- NRVO_Candidate,<br>
- NRVO_Disabled,<br>
- NRVO_Enabled,<br>
- };<br>
-<br>
class ParmVarDeclBitfields {<br>
friend class ASTDeclReader;<br>
friend class ParmVarDecl;<br>
@@ -937,7 +931,7 @@ protected:<br>
/// Whether this local variable could be allocated in the return<br>
/// slot of its function, enabling the named return value optimization<br>
/// (NRVO).<br>
- unsigned NRVOMode : 2;<br>
+ unsigned NRVOVariable : 1;<br>
<br>
/// Whether this variable is the for-range-declaration in a C++0x<br>
/// for-range statement.<br>
@@ -1325,20 +1319,12 @@ public:<br>
/// return slot when returning from the function. Within the function body,<br>
/// each return that returns the NRVO object will have this variable as its<br>
/// NRVO candidate.<br>
- NRVOMode getNRVOMode() const {<br>
- if (isa<ParmVarDecl>(this))<br>
- return NRVO_Disabled;<br>
- return static_cast<NRVOMode>(NonParmVarDeclBits.NRVOMode);<br>
- }<br>
- bool isNRVOCandidate() const {<br>
- return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.NRVOMode == NRVO_Candidate;<br>
- }<br>
bool isNRVOVariable() const {<br>
- return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.NRVOMode == NRVO_Enabled;<br>
+ return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.NRVOVariable;<br>
}<br>
void setNRVOVariable(bool NRVO) {<br>
assert(!isa<ParmVarDecl>(this));<br>
- NonParmVarDeclBits.NRVOMode = NRVO ? NRVO_Enabled : NRVO_Disabled;<br>
+ NonParmVarDeclBits.NRVOVariable = NRVO;<br>
}<br>
<br>
/// Determine whether this variable is the for-range-declaration in<br>
<br>
Modified: cfe/trunk/include/clang/Sema/Scope.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Scope.h?rev=335022&r1=335021&r2=335022&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Scope.h?rev=335022&r1=335021&r2=335022&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Sema/Scope.h (original)<br>
+++ cfe/trunk/include/clang/Sema/Scope.h Mon Jun 18 22:35:30 2018<br>
@@ -201,6 +201,10 @@ private:<br>
/// Used to determine if errors occurred in this scope.<br>
DiagnosticErrorTrap ErrorTrap;<br>
<br>
+ /// A lattice consisting of undefined, a single NRVO candidate variable in<br>
+ /// this scope, or over-defined. The bit is true when over-defined.<br>
+ llvm::PointerIntPair<VarDecl *, 1, bool> NRVO;<br>
+<br>
void setFlags(Scope *Parent, unsigned F);<br>
<br>
public:<br>
@@ -462,7 +466,23 @@ public:<br>
UsingDirectives.end());<br>
}<br>
<br>
- void setNRVOCandidate(VarDecl *Candidate);<br>
+ void addNRVOCandidate(VarDecl *VD) {<br>
+ if (NRVO.getInt())<br>
+ return;<br>
+ if (NRVO.getPointer() == nullptr) {<br>
+ NRVO.setPointer(VD);<br>
+ return;<br>
+ }<br>
+ if (NRVO.getPointer() != VD)<br>
+ setNoNRVO();<br>
+ }<br>
+<br>
+ void setNoNRVO() {<br>
+ NRVO.setInt(true);<br>
+ NRVO.setPointer(nullptr);<br>
+ }<br>
+<br>
+ void mergeNRVOIntoParent();<br>
<br>
/// Init - This is used by the parser to implement scope caching.<br>
void Init(Scope *parent, unsigned flags);<br>
<br>
Modified: cfe/trunk/lib/Sema/Scope.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Scope.cpp?rev=335022&r1=335021&r2=335022&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Scope.cpp?rev=335022&r1=335021&r2=335022&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/Scope.cpp (original)<br>
+++ cfe/trunk/lib/Sema/Scope.cpp Mon Jun 18 22:35:30 2018<br>
@@ -92,6 +92,7 @@ void Scope::Init(Scope *parent, unsigned<br>
UsingDirectives.clear();<br>
Entity = nullptr;<br>
ErrorTrap.reset();<br>
+ NRVO.setPointerAndInt(nullptr, 0);<br>
}<br>
<br>
bool Scope::containedInPrototypeScope() const {<br>
@@ -118,15 +119,19 @@ void Scope::AddFlags(unsigned FlagsToSet<br>
Flags |= FlagsToSet;<br>
}<br>
<br>
-void Scope::setNRVOCandidate(VarDecl *Candidate) {<br>
- for (Decl *D : DeclsInScope) {<br>
- VarDecl *VD = dyn_cast<VarDecl>(D);<br>
- if (VD && VD != Candidate && VD->isNRVOCandidate())<br>
- VD->setNRVOVariable(false);<br>
+void Scope::mergeNRVOIntoParent() {<br>
+ if (VarDecl *Candidate = NRVO.getPointer()) {<br>
+ if (isDeclScope(Candidate))<br>
+ Candidate->setNRVOVariable(true);<br>
}<br>
<br>
- if (Scope *parent = getParent())<br>
- parent->setNRVOCandidate(Candidate);<br>
+ if (getEntity())<br>
+ return;<br>
+<br>
+ if (NRVO.getInt())<br>
+ getParent()->setNoNRVO();<br>
+ else if (NRVO.getPointer())<br>
+ getParent()->addNRVOCandidate(NRVO.getPointer());<br>
}<br>
<br>
LLVM_DUMP_METHOD void Scope::dump() const { dumpImpl(llvm::errs()); }<br>
@@ -186,4 +191,9 @@ void Scope::dumpImpl(raw_ostream &OS) co<br>
OS << "MSCurManglingNumber: " << getMSCurManglingNumber() << '\n';<br>
if (const DeclContext *DC = getEntity())<br>
OS << "Entity : (clang::DeclContext*)" << DC << '\n';<br>
+<br>
+ if (NRVO.getInt())<br>
+ OS << "NRVO not allowed\n";<br>
+ else if (NRVO.getPointer())<br>
+ OS << "NRVO candidate : (clang::VarDecl*)" << NRVO.getPointer() << '\n';<br>
}<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=335022&r1=335021&r2=335022&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=335022&r1=335021&r2=335022&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jun 18 22:35:30 2018<br>
@@ -1798,6 +1798,8 @@ static void CheckPoppedLabel(LabelDecl *<br>
}<br>
<br>
void Sema::ActOnPopScope(SourceLocation Loc, Scope *S) {<br>
+ S->mergeNRVOIntoParent();<br>
+<br>
if (S->decl_empty()) return;<br>
assert((S->getFlags() & (Scope::DeclScope | Scope::TemplateParamScope)) &&<br>
"Scope shouldn't contain decls!");<br>
@@ -12561,24 +12563,21 @@ Decl *Sema::ActOnStartOfFunctionDef(Scop<br>
/// optimization.<br>
///<br>
/// Each of the variables that is subject to the named return value<br>
-/// optimization will be marked as NRVO variable candidates in the AST, and any<br>
+/// optimization will be marked as NRVO variables in the AST, and any<br>
/// return statement that has a marked NRVO variable as its NRVO candidate can<br>
/// use the named return value optimization.<br>
///<br>
-/// This function applies a very simplistic algorithm for NRVO: if every<br>
-/// reachable return statement in the scope of a variable has the same NRVO<br>
-/// candidate, that candidate is an NRVO variable.<br>
+/// This function applies a very simplistic algorithm for NRVO: if every return<br>
+/// statement in the scope of a variable has the same NRVO candidate, that<br>
+/// candidate is an NRVO variable.<br>
void Sema::computeNRVO(Stmt *Body, FunctionScopeInfo *Scope) {<br>
- for (ReturnStmt *Return : Scope->Returns) {<br>
- const VarDecl *Candidate = Return->getNRVOCandidate();<br>
- if (!Candidate)<br>
- continue;<br>
+ ReturnStmt **Returns = Scope->Returns.data();<br>
<br>
- if (Candidate->isNRVOCandidate())<br>
- const_cast<VarDecl*>(Candidate)->setNRVOVariable(true);<br>
-<br>
- if (!Candidate->isNRVOVariable())<br>
- Return->setNRVOCandidate(nullptr);<br>
+ for (unsigned I = 0, E = Scope->Returns.size(); I != E; ++I) {<br>
+ if (const VarDecl *NRVOCandidate = Returns[I]->getNRVOCandidate()) {<br>
+ if (!NRVOCandidate->isNRVOVariable())<br>
+ Returns[I]->setNRVOCandidate(nullptr);<br>
+ }<br>
}<br>
}<br>
<br>
@@ -12713,8 +12712,12 @@ Decl *Sema::ActOnFinishFunctionBody(Decl<br>
else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(FD))<br>
MarkVTableUsed(FD->getLocation(), Destructor->getParent());<br>
<br>
- // Try to apply the named return value optimization.<br>
- computeNRVO(Body, getCurFunction());<br>
+ // Try to apply the named return value optimization. We have to check<br>
+ // if we can do this here because lambdas keep return statements around<br>
+ // to deduce an implicit return type.<br>
+ if (FD->getReturnType()->isRecordType() &&<br>
+ (!getLangOpts().CPlusPlus || !FD->isDependentContext()))<br>
+ computeNRVO(Body, getCurFunction());<br>
}<br>
<br>
// GNU warning -Wmissing-prototypes:<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=335022&r1=335021&r2=335022&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=335022&r1=335021&r2=335022&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Jun 18 22:35:30 2018<br>
@@ -13385,9 +13385,13 @@ ExprResult Sema::ActOnBlockStmtExpr(Sour<br>
if (Body && getCurFunction()->HasPotentialAvailabilityViolations)<br>
DiagnoseUnguardedAvailabilityViolations(BSI->TheDecl);<br>
<br>
- // Try to apply the named return value optimization.<br>
- computeNRVO(Body, BSI);<br>
-<br>
+ // Try to apply the named return value optimization. We have to check again<br>
+ // if we can do this, though, because blocks keep return statements around<br>
+ // to deduce an implicit return type.<br>
+ if (getLangOpts().CPlusPlus && RetTy->isRecordType() &&<br>
+ !BSI->TheDecl->isDependentContext())<br>
+ computeNRVO(Body, BSI);<br>
+ <br>
BlockExpr *Result = new (Context) BlockExpr(BSI->TheDecl, BlockTy);<br>
AnalysisBasedWarnings::Policy WP = AnalysisWarnings.getDefaultPolicy();<br>
PopFunctionScopeInfo(&WP, Result->getBlockDecl(), Result);<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=335022&r1=335021&r2=335022&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=335022&r1=335021&r2=335022&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Mon Jun 18 22:35:30 2018<br>
@@ -3455,9 +3455,12 @@ Sema::ActOnReturnStmt(SourceLocation Ret<br>
ExpressionEvaluationContext::DiscardedStatement)<br>
return R;<br>
<br>
- VarDecl *VD =<br>
- const_cast<VarDecl*>(cast<ReturnStmt>(R.get())->getNRVOCandidate());<br>
- CurScope->setNRVOCandidate(VD);<br>
+ if (VarDecl *VD =<br>
+ const_cast<VarDecl*>(cast<ReturnStmt>(R.get())->getNRVOCandidate())) {<br>
+ CurScope->addNRVOCandidate(VD);<br>
+ } else {<br>
+ CurScope->setNoNRVO();<br>
+ }<br>
<br>
CheckJumpOutOfSEHFinally(*this, ReturnLoc, *CurScope->getFnParent());<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=335022&r1=335021&r2=335022&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=335022&r1=335021&r2=335022&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon Jun 18 22:35:30 2018<br>
@@ -740,13 +740,12 @@ Decl *TemplateDeclInstantiator::VisitVar<br>
SemaRef.BuildVariableInstantiation(Var, D, TemplateArgs, LateAttrs, Owner,<br>
StartingScope, InstantiatingVarTemplate);<br>
<br>
- bool NRVO = false;<br>
if (D->isNRVOVariable()) {<br>
QualType ReturnType = cast<FunctionDecl>(DC)->getReturnType();<br>
if (SemaRef.isCopyElisionCandidate(ReturnType, Var, Sema::CES_Strict))<br>
- NRVO = true;<br>
+ Var->setNRVOVariable(true);<br>
}<br>
- Var->setNRVOVariable(NRVO);<br>
+<br>
Var->setImplicit(D->isImplicit());<br>
<br>
return Var;<br>
<br>
Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=335022&r1=335021&r2=335022&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=335022&r1=335021&r2=335022&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)<br>
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Mon Jun 18 22:35:30 2018<br>
@@ -1326,7 +1326,7 @@ ASTDeclReader::RedeclarableResult ASTDec<br>
VD->NonParmVarDeclBits.IsThisDeclarationADemotedDefinition =<br>
Record.readInt();<br>
VD->NonParmVarDeclBits.ExceptionVar = Record.readInt();<br>
- VD->NonParmVarDeclBits.NRVOMode = Record.readInt();<br>
+ VD->NonParmVarDeclBits.NRVOVariable = Record.readInt();<br>
VD->NonParmVarDeclBits.CXXForRangeDecl = Record.readInt();<br>
VD->NonParmVarDeclBits.ObjCForDecl = Record.readInt();<br>
VD->NonParmVarDeclBits.ARCPseudoStrong = Record.readInt();<br>
<br>
Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=335022&r1=335021&r2=335022&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=335022&r1=335021&r2=335022&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)<br>
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Mon Jun 18 22:35:30 2018<br>
@@ -918,7 +918,7 @@ void ASTDeclWriter::VisitVarDecl(VarDecl<br>
if (!isa<ParmVarDecl>(D)) {<br>
Record.push_back(D->isThisDeclarationADemotedDefinition());<br>
Record.push_back(D->isExceptionVariable());<br>
- Record.push_back(D->getNRVOMode());<br>
+ Record.push_back(D->isNRVOVariable());<br>
Record.push_back(D->isCXXForRangeDecl());<br>
Record.push_back(D->isObjCForDecl());<br>
Record.push_back(D->isARCPseudoStrong());<br>
@@ -2031,7 +2031,7 @@ void ASTWriter::WriteDeclAbbrevs() {<br>
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // InitStyle<br>
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsThisDeclarationADemotedDefinition<br>
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable<br>
- Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // NRVOMode<br>
+ Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable<br>
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCXXForRangeDecl<br>
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isObjCForDecl<br>
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong<br>
<br>
Removed: cfe/trunk/test/CodeGenCXX/nrvo-noopt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/nrvo-noopt.cpp?rev=335021&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/nrvo-noopt.cpp?rev=335021&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/nrvo-noopt.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/nrvo-noopt.cpp (removed)<br>
@@ -1,58 +0,0 @@<br>
-// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s<br>
-<br>
-struct X {<br>
- X();<br>
- X(X&&);<br>
-};<br>
-<br>
-// CHECK-LABEL: define void @_Z7test_00b<br>
-X test_00(bool b) {<br>
- if (b) {<br>
- // CHECK-NOT: call void @_ZN1XC1EOS_<br>
- // CHECK: call void @_ZN1XC1Ev<br>
- // CHECK-NEXT: br label %return<br>
- X x;<br>
- return x;<br>
- } else {<br>
- // CHECK-NOT: call void @_ZN1XC1EOS_<br>
- // CHECK: call void @_ZN1XC1Ev<br>
- // CHECK-NEXT: br label %return<br>
- X x;<br>
- return x;<br>
- }<br>
-}<br>
-<br>
-// CHECK-LABEL: define void @_Z7test_01b<br>
-X test_01(bool b) {<br>
- if (b) {<br>
- // CHECK-NOT: call void @_ZN1XC1EOS_<br>
- // CHECK: call void @_ZN1XC1Ev<br>
- // CHECK-NEXT: br label %return<br>
- X x;<br>
- return x;<br>
- }<br>
- // CHECK-NOT: call void @_ZN1XC1EOS_<br>
- // CHECK: call void @_ZN1XC1Ev<br>
- // CHECK-NEXT: br label %return<br>
- X x;<br>
- return x;<br>
-}<br>
-<br>
-// CHECK-LABEL: define void @_Z7test_02b<br>
-X test_02(bool b) {<br>
- // CHECK: call void @_ZN1XC1Ev<br>
- X x;<br>
-<br>
- if (b) {<br>
- // CHECK-NOT: call void @_ZN1XC1EOS_<br>
- // CHECK: call void @_ZN1XC1Ev<br>
- // CHECK-NEXT: br label %return<br>
- X y;<br>
- return y;<br>
- }<br>
-<br>
- // CHECK-NOT: call void @_ZN1XC1Ev<br>
- // CHECK: call void @_ZN1XC1EOS_<br>
- // CHECK-NEXT: br label %return<br>
- return x;<br>
-}<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/nrvo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/nrvo.cpp?rev=335022&r1=335021&r2=335022&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/nrvo.cpp?rev=335022&r1=335021&r2=335022&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/nrvo.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/nrvo.cpp Mon Jun 18 22:35:30 2018<br>
@@ -130,13 +130,17 @@ X test2(bool B) {<br>
}<br>
<br>
// CHECK-LABEL: define void @_Z5test3b<br>
-X test3(bool B, X x) {<br>
+X test3(bool B) {<br>
// CHECK: tail call {{.*}} @_ZN1XC1Ev<br>
+ // CHECK-NOT: call {{.*}} @_ZN1XC1ERKS_<br>
+ // CHECK: call {{.*}} @_ZN1XC1Ev<br>
+ // CHECK: call {{.*}} @_ZN1XC1ERKS_<br>
if (B) {<br>
X y;<br>
return y;<br>
}<br>
- // CHECK: tail call {{.*}} @_ZN1XC1ERKS_<br>
+ // FIXME: we should NRVO this variable too.<br>
+ X x;<br>
return x;<br>
}<br>
<br>
@@ -187,13 +191,9 @@ X test6() {<br>
}<br>
<br>
// CHECK-LABEL: define void @_Z5test7b<br>
-// CHECK-EH-LABEL: define void @_Z5test7b<br>
X test7(bool b) {<br>
// CHECK: tail call {{.*}} @_ZN1XC1Ev<br>
// CHECK-NEXT: ret<br>
-<br>
- // CHECK-EH: tail call {{.*}} @_ZN1XC1Ev<br>
- // CHECK-EH-NEXT: ret<br>
if (b) {<br>
X x;<br>
return x;<br>
@@ -202,14 +202,10 @@ X test7(bool b) {<br>
}<br>
<br>
// CHECK-LABEL: define void @_Z5test8b<br>
-// CHECK-EH-LABEL: define void @_Z5test8b<br>
X test8(bool b) {<br>
// CHECK: tail call {{.*}} @_ZN1XC1Ev<br>
// CHECK-NEXT: ret<br>
-<br>
- // CHECK-EH: tail call {{.*}} @_ZN1XC1Ev<br>
- // CHECK-EH-NEXT: ret<br>
-if (b) {<br>
+ if (b) {<br>
X x;<br>
return x;<br>
} else {<br>
@@ -225,37 +221,4 @@ Y<int> test9() {<br>
// CHECK-LABEL: define linkonce_odr void @_ZN1YIiE1fEv<br>
// CHECK: tail call {{.*}} @_ZN1YIiEC1Ev<br>
<br>
-// CHECK-LABEL: define void @_Z6test10b<br>
-X test10(bool B, X x) {<br>
- if (B) {<br>
- // CHECK: tail call {{.*}} @_ZN1XC1ERKS_<br>
- // CHECK-EH: tail call {{.*}} @_ZN1XC1ERKS_<br>
- return x;<br>
- }<br>
- // CHECK: tail call {{.*}} @_ZN1XC1Ev<br>
- // CHECK-NOT: call {{.*}} @_ZN1XC1ERKS_<br>
-<br>
- // CHECK-EH: tail call {{.*}} @_ZN1XC1Ev<br>
- // CHECK-EH-NOT: call {{.*}} @_ZN1XC1ERKS_<br>
- X y;<br>
- return y;<br>
-}<br>
-<br>
-// CHECK-LABEL: define {{.*}} void @_Z6test11I1XET_v<br>
-// CHECK-EH-LABEL: define {{.*}} void @_Z6test11I1XET_v<br>
-template <typename T><br>
-T test11() {<br>
- // CHECK: tail call {{.*}} @_ZN1XC1Ev<br>
- // CHECK-NEXT: ret void<br>
-<br>
- // CHECK-EH: tail call {{.*}} @_ZN1XC1Ev<br>
- // CHECK-EH-NEXT: ret void<br>
- T t;<br>
- return t;<br>
-}<br>
-<br>
-void test12() {<br>
- test11<X>();<br>
-}<br>
-<br>
// CHECK-EH-03: attributes [[NR_NUW]] = { noreturn nounwind }<br>
<br>
Removed: cfe/trunk/test/SemaCXX/nrvo-ast.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nrvo-ast.cpp?rev=335021&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nrvo-ast.cpp?rev=335021&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/nrvo-ast.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/nrvo-ast.cpp (removed)<br>
@@ -1,153 +0,0 @@<br>
-// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -ast-dump -o - %s | FileCheck %s<br>
-<br>
-struct X {<br>
- X();<br>
- X(const X&);<br>
- X(X&&);<br>
-};<br>
-<br>
-// CHECK-LABEL: FunctionDecl {{.*}} test_00<br>
-X test_00() {<br>
- // CHECK: VarDecl {{.*}} x {{.*}} nrvo<br>
- X x;<br>
- return x;<br>
-}<br>
-<br>
-// CHECK-LABEL: FunctionDecl {{.*}} test_01<br>
-X test_01(bool b) {<br>
- // CHECK: VarDecl {{.*}} x {{.*}} nrvo<br>
- X x;<br>
- if (b)<br>
- return x;<br>
- return x;<br>
-}<br>
-<br>
-// CHECK-LABEL: FunctionDecl {{.*}} test_02<br>
-X test_02(bool b) {<br>
- // CHECK-NOT: VarDecl {{.*}} x {{.*}} nrvo<br>
- X x;<br>
- // CHECK-NOT: VarDecl {{.*}} y {{.*}} nrvo<br>
- X y;<br>
- if (b)<br>
- return y;<br>
- return x;<br>
-}<br>
-<br>
-// CHECK-LABEL: FunctionDecl {{.*}} test_03<br>
-X test_03(bool b) {<br>
- if (b) {<br>
- // CHECK: VarDecl {{.*}} y {{.*}} nrvo<br>
- X y;<br>
- return y;<br>
- }<br>
- // CHECK: VarDecl {{.*}} x {{.*}} nrvo<br>
- X x;<br>
- return x;<br>
-}<br>
-<br>
-extern "C" _Noreturn void exit(int) throw();<br>
-<br>
-// CHECK-LABEL: FunctionDecl {{.*}} test_04<br>
-X test_04(bool b) {<br>
- {<br>
- // CHECK: VarDecl {{.*}} x {{.*}} nrvo<br>
- X x;<br>
- if (b)<br>
- return x;<br>
- }<br>
- exit(1);<br>
-}<br>
-<br>
-void may_throw();<br>
-// CHECK-LABEL: FunctionDecl {{.*}} test_05<br>
-X test_05() {<br>
- try {<br>
- may_throw();<br>
- return X();<br>
- } catch (X x) {<br>
- // CHECK-NOT: VarDecl {{.*}} x {{.*}} nrvo<br>
- return x;<br>
- }<br>
-}<br>
-<br>
-// CHECK-LABEL: FunctionDecl {{.*}} test_06<br>
-X test_06() {<br>
- // CHECK-NOT: VarDecl {{.*}} x {{.*}} nrvo<br>
- X x __attribute__((aligned(8)));<br>
- return x;<br>
-}<br>
-<br>
-// CHECK-LABEL: FunctionDecl {{.*}} test_07<br>
-X test_07(bool b) {<br>
- if (b) {<br>
- // CHECK: VarDecl {{.*}} x {{.*}} nrvo<br>
- X x;<br>
- return x;<br>
- }<br>
- return X();<br>
-}<br>
-<br>
-// CHECK-LABEL: FunctionDecl {{.*}} test_08<br>
-X test_08(bool b) {<br>
- if (b) {<br>
- // CHECK: VarDecl {{.*}} x {{.*}} nrvo<br>
- X x;<br>
- return x;<br>
- } else {<br>
- // CHECK: VarDecl {{.*}} y {{.*}} nrvo<br>
- X y;<br>
- return y;<br>
- }<br>
-}<br>
-<br>
-template <typename T><br>
-struct Y {<br>
- Y();<br>
- // CHECK-LABEL: CXXMethodDecl {{.*}} test_09 'Y<T> ()'<br>
- // CHECK: VarDecl {{.*}} y 'Y<T>' nrvo<br>
-<br>
- // CHECK-LABEL: CXXMethodDecl {{.*}} test_09 'Y<int> ()'<br>
- // CHECK: VarDecl {{.*}} y 'Y<int>' nrvo<br>
- static Y test_09() {<br>
- Y y;<br>
- return y;<br>
- }<br>
-};<br>
-<br>
-struct Z {<br>
- Z(const X&);<br>
-};<br>
-<br>
-// CHECK-LABEL: FunctionDecl {{.*}} test_10 'A ()'<br>
-// CHECK: VarDecl {{.*}} b 'B' nrvo<br>
-<br>
-// CHECK-LABEL: FunctionDecl {{.*}} test_10 'X ()'<br>
-// CHECK: VarDecl {{.*}} b {{.*}} nrvo<br>
-<br>
-// CHECK-LABEL: FunctionDecl {{.*}} test_10 'Z ()'<br>
-// CHECK-NOT: VarDecl {{.*}} b {{.*}} nrvo<br>
-template <typename A, typename B><br>
-A test_10() {<br>
- B b;<br>
- return b;<br>
-}<br>
-<br>
-// CHECK-LABEL: FunctionDecl {{.*}} test_11 'A (bool)'<br>
-// CHECK-NOT: VarDecl {{.*}} a {{.*}} nrvo<br>
-<br>
-// CHECK-LABEL: FunctionDecl {{.*}} test_11 'X (bool)'<br>
-// CHECK-NOT: VarDecl {{.*}} a {{.*}} nrvo<br>
-template <typename A><br>
-A test_11(bool b) {<br>
- A a;<br>
- if (b)<br>
- return A();<br>
- return a;<br>
-}<br>
-<br>
-void instantiate() {<br>
- Y<int>::test_09();<br>
- test_10<X, X>();<br>
- test_10<Z, X>();<br>
- test_11<X>(true);<br>
-}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>