From f8b3015060096a946d91578d0f3b65d3097a4ebb Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sun, 28 Nov 2010 16:40:49 +0000 Subject: [PATCH] Look through parentheses when deciding whether an expr is a temporary object. Fixes PR8683. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120247 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Expr.cpp | 8 ++++---- test/CodeGenCXX/copy-constructor-elim-2.cpp | 22 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 3e3792e21f..3a112a7e07 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1804,7 +1804,7 @@ bool Expr::isDefaultArgument() const { /// \brief Skip over any no-op casts and any temporary-binding /// expressions. -static const Expr *skipTemporaryBindingsAndNoOpCasts(const Expr *E) { +static const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) { while (const ImplicitCastExpr *ICE = dyn_cast(E)) { if (ICE->getCastKind() == CK_NoOp) E = ICE->getSubExpr(); @@ -1821,8 +1821,8 @@ static const Expr *skipTemporaryBindingsAndNoOpCasts(const Expr *E) { else break; } - - return E; + + return E->IgnoreParens(); } /// isTemporaryObject - Determines if this expression produces a @@ -1831,7 +1831,7 @@ bool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const { if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy))) return false; - const Expr *E = skipTemporaryBindingsAndNoOpCasts(this); + const Expr *E = skipTemporaryBindingsNoOpCastsAndParens(this); // Temporaries are by definition pr-values of class type. if (!E->Classify(C).isPRValue()) { diff --git a/test/CodeGenCXX/copy-constructor-elim-2.cpp b/test/CodeGenCXX/copy-constructor-elim-2.cpp index 73e9b94bcd..563676f6e3 100644 --- a/test/CodeGenCXX/copy-constructor-elim-2.cpp +++ b/test/CodeGenCXX/copy-constructor-elim-2.cpp @@ -31,3 +31,25 @@ namespace no_elide_base { // CHECK: ret void } } + +// PR8683. + +namespace PR8683 { + +struct A { + A(); + A(const A&); + A& operator=(const A&); +}; + +struct B { + A a; +}; + +void f() { + // Verify that we don't mark the copy constructor in this expression as elidable. + // CHECK: call void @_ZN6PR86831AC1ERKS0_ + A a = (B().a); +} + +} -- 2.40.0