[cfe-commits] r120247 - in /cfe/trunk: lib/AST/Expr.cpp test/CodeGenCXX/copy-constructor-elim-2.cpp
Anders Carlsson
andersca at mac.com
Sun Nov 28 08:40:49 PST 2010
Author: andersca
Date: Sun Nov 28 10:40:49 2010
New Revision: 120247
URL: http://llvm.org/viewvc/llvm-project?rev=120247&view=rev
Log:
Look through parentheses when deciding whether an expr is a temporary object. Fixes PR8683.
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/test/CodeGenCXX/copy-constructor-elim-2.cpp
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=120247&r1=120246&r2=120247&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sun Nov 28 10:40:49 2010
@@ -1804,7 +1804,7 @@
/// \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<ImplicitCastExpr>(E)) {
if (ICE->getCastKind() == CK_NoOp)
E = ICE->getSubExpr();
@@ -1821,8 +1821,8 @@
else
break;
}
-
- return E;
+
+ return E->IgnoreParens();
}
/// isTemporaryObject - Determines if this expression produces a
@@ -1831,7 +1831,7 @@
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()) {
Modified: cfe/trunk/test/CodeGenCXX/copy-constructor-elim-2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/copy-constructor-elim-2.cpp?rev=120247&r1=120246&r2=120247&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/copy-constructor-elim-2.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/copy-constructor-elim-2.cpp Sun Nov 28 10:40:49 2010
@@ -31,3 +31,25 @@
// 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);
+}
+
+}
More information about the cfe-commits
mailing list