Fix a bug with binding l-values to elided temporaries, and leave a couple

helpful asserts behind.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114250 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
John McCall 2010-09-18 00:58:34 +00:00
Родитель 3ed3272a54
Коммит fc1e6c79bb
3 изменённых файлов: 30 добавлений и 7 удалений

Просмотреть файл

@ -1964,6 +1964,8 @@ LValue CodeGenFunction::EmitVAArgExprLValue(const VAArgExpr *E) {
}
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 @@ CodeGenFunction::EmitCXXTypeidLValue(const CXXTypeidExpr *E) {
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) {

Просмотреть файл

@ -280,10 +280,12 @@ CodeGenFunction::EmitCXXConstructExpr(const CXXConstructExpr *E,
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;

Просмотреть файл

@ -340,7 +340,11 @@ namespace PR7556 {
}
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 @@ namespace Elision {
// 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();
}
}