[cfe-commits] r114250 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/CodeGen/CGExprCXX.cpp test/CodeGenCXX/temporaries.cpp
John McCall
rjmccall at apple.com
Fri Sep 17 17:58:34 PDT 2010
Author: rjmccall
Date: Fri Sep 17 19:58:34 2010
New Revision: 114250
URL: http://llvm.org/viewvc/llvm-project?rev=114250&view=rev
Log:
Fix a bug with binding l-values to elided temporaries, and leave a couple
helpful asserts behind.
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/test/CodeGenCXX/temporaries.cpp
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=114250&r1=114249&r2=114250&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Sep 17 19:58:34 2010
@@ -1964,6 +1964,8 @@
}
LValue CodeGenFunction::EmitCXXConstructLValue(const CXXConstructExpr *E) {
+ assert(E->getType()->getAsCXXRecordDecl()->hasTrivialDestructor()
+ && "binding l-value to type which needs a temporary");
AggValueSlot Slot = CreateAggTemp(E->getType(), "tmp");
EmitCXXConstructExpr(E, Slot);
return MakeAddrLValue(Slot.getAddr(), E->getType());
@@ -1976,9 +1978,11 @@
LValue
CodeGenFunction::EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E) {
- LValue LV = EmitLValue(E->getSubExpr());
- EmitCXXTemporary(E->getTemporary(), LV.getAddress());
- return LV;
+ AggValueSlot Slot = CreateAggTemp(E->getType(), "temp.lvalue");
+ Slot.setLifetimeExternallyManaged();
+ EmitAggExpr(E->getSubExpr(), Slot);
+ EmitCXXTemporary(E->getTemporary(), Slot.getAddr());
+ return MakeAddrLValue(Slot.getAddr(), E->getType());
}
LValue CodeGenFunction::EmitObjCMessageExprLValue(const ObjCMessageExpr *E) {
Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=114250&r1=114249&r2=114250&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Fri Sep 17 19:58:34 2010
@@ -280,10 +280,12 @@
if (CD->isTrivial() && CD->isDefaultConstructor())
return;
- // Code gen optimization to eliminate copy constructor and return
- // its first argument instead, if in fact that argument is a temporary
- // object.
+ // Elide the constructor if we're constructing from a temporary.
+ // The temporary check is required because Sema sets this on NRVO
+ // returns.
if (getContext().getLangOptions().ElideConstructors && E->isElidable()) {
+ assert(getContext().hasSameUnqualifiedType(E->getType(),
+ E->getArg(0)->getType()));
if (E->getArg(0)->isTemporaryObject(getContext(), CD->getParent())) {
EmitAggExpr(E->getArg(0), Dest);
return;
Modified: cfe/trunk/test/CodeGenCXX/temporaries.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/temporaries.cpp?rev=114250&r1=114249&r2=114250&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/temporaries.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/temporaries.cpp Fri Sep 17 19:58:34 2010
@@ -340,7 +340,11 @@
}
namespace Elision {
- struct A { A(); A(const A &); ~A(); void *p; };
+ struct A {
+ A(); A(const A &); ~A();
+ void *p;
+ void foo() const;
+ };
void foo();
A fooA();
@@ -475,4 +479,17 @@
// CHECK: call void @_ZN7Elision1AD1Ev([[A]]* [[X]])
}
+
+ // Reduced from webkit.
+ // CHECK: define void @_ZN7Elision5test6EPKNS_1CE([[C:%.*]]*
+ struct C { operator A() const; };
+ void test6(const C *x) {
+ // CHECK: [[T0:%.*]] = alloca [[A]], align 8
+ // CHECK: [[X:%.*]] = load [[C]]** {{%.*}}, align 8
+ // CHECK-NEXT: call void @_ZNK7Elision1CcvNS_1AEEv([[A]]* sret [[T0]], [[C]]* [[X]])
+ // CHECK-NEXT: call void @_ZNK7Elision1A3fooEv([[A]]* [[T0]])
+ // CHECK-NEXT: call void @_ZN7Elision1AD1Ev([[A]]* [[T0]])
+ // CHECK-NEXT: ret void
+ A(*x).foo();
+ }
}
More information about the cfe-commits
mailing list