|
@@ -491,12 +491,15 @@ namespace {
|
|
|
cast<CXXMethodDecl>(CGF.CurCodeDecl)->getParent();
|
|
|
|
|
|
const CXXDestructorDecl *D = BaseClass->getDestructor();
|
|
|
+ // We are already inside a destructor, so presumably the object being
|
|
|
+ // destroyed should have the expected type.
|
|
|
+ QualType ThisTy = D->getThisObjectType();
|
|
|
Address Addr =
|
|
|
CGF.GetAddressOfDirectBaseInCompleteClass(CGF.LoadCXXThisAddress(),
|
|
|
DerivedClass, BaseClass,
|
|
|
BaseIsVirtual);
|
|
|
CGF.EmitCXXDestructorCall(D, Dtor_Base, BaseIsVirtual,
|
|
|
- /*Delegating=*/false, Addr);
|
|
|
+ /*Delegating=*/false, Addr, ThisTy);
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -1440,9 +1443,11 @@ void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) {
|
|
|
if (DtorType == Dtor_Deleting) {
|
|
|
RunCleanupsScope DtorEpilogue(*this);
|
|
|
EnterDtorCleanups(Dtor, Dtor_Deleting);
|
|
|
- if (HaveInsertPoint())
|
|
|
+ if (HaveInsertPoint()) {
|
|
|
+ QualType ThisTy = Dtor->getThisObjectType();
|
|
|
EmitCXXDestructorCall(Dtor, Dtor_Complete, /*ForVirtualBase=*/false,
|
|
|
- /*Delegating=*/false, LoadCXXThisAddress());
|
|
|
+ /*Delegating=*/false, LoadCXXThisAddress(), ThisTy);
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -1473,8 +1478,9 @@ void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) {
|
|
|
EnterDtorCleanups(Dtor, Dtor_Complete);
|
|
|
|
|
|
if (!isTryBody) {
|
|
|
+ QualType ThisTy = Dtor->getThisObjectType();
|
|
|
EmitCXXDestructorCall(Dtor, Dtor_Base, /*ForVirtualBase=*/false,
|
|
|
- /*Delegating=*/false, LoadCXXThisAddress());
|
|
|
+ /*Delegating=*/false, LoadCXXThisAddress(), ThisTy);
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -2013,7 +2019,7 @@ void CodeGenFunction::destroyCXXObject(CodeGenFunction &CGF,
|
|
|
const CXXDestructorDecl *dtor = record->getDestructor();
|
|
|
assert(!dtor->isTrivial());
|
|
|
CGF.EmitCXXDestructorCall(dtor, Dtor_Complete, /*for vbase*/ false,
|
|
|
- /*Delegating=*/false, addr);
|
|
|
+ /*Delegating=*/false, addr, type);
|
|
|
}
|
|
|
|
|
|
void CodeGenFunction::EmitCXXConstructorCall(const CXXConstructorDecl *D,
|
|
@@ -2363,8 +2369,11 @@ namespace {
|
|
|
: Dtor(D), Addr(Addr), Type(Type) {}
|
|
|
|
|
|
void Emit(CodeGenFunction &CGF, Flags flags) override {
|
|
|
+ // We are calling the destructor from within the constructor.
|
|
|
+ // Therefore, "this" should have the expected type.
|
|
|
+ QualType ThisTy = Dtor->getThisObjectType();
|
|
|
CGF.EmitCXXDestructorCall(Dtor, Type, /*ForVirtualBase=*/false,
|
|
|
- /*Delegating=*/true, Addr);
|
|
|
+ /*Delegating=*/true, Addr, ThisTy);
|
|
|
}
|
|
|
};
|
|
|
} // end anonymous namespace
|
|
@@ -2402,31 +2411,32 @@ CodeGenFunction::EmitDelegatingCXXConstructorCall(const CXXConstructorDecl *Ctor
|
|
|
void CodeGenFunction::EmitCXXDestructorCall(const CXXDestructorDecl *DD,
|
|
|
CXXDtorType Type,
|
|
|
bool ForVirtualBase,
|
|
|
- bool Delegating,
|
|
|
- Address This) {
|
|
|
+ bool Delegating, Address This,
|
|
|
+ QualType ThisTy) {
|
|
|
CGM.getCXXABI().EmitDestructorCall(*this, DD, Type, ForVirtualBase,
|
|
|
- Delegating, This);
|
|
|
+ Delegating, This, ThisTy);
|
|
|
}
|
|
|
|
|
|
namespace {
|
|
|
struct CallLocalDtor final : EHScopeStack::Cleanup {
|
|
|
const CXXDestructorDecl *Dtor;
|
|
|
Address Addr;
|
|
|
+ QualType Ty;
|
|
|
|
|
|
- CallLocalDtor(const CXXDestructorDecl *D, Address Addr)
|
|
|
- : Dtor(D), Addr(Addr) {}
|
|
|
+ CallLocalDtor(const CXXDestructorDecl *D, Address Addr, QualType Ty)
|
|
|
+ : Dtor(D), Addr(Addr), Ty(Ty) {}
|
|
|
|
|
|
void Emit(CodeGenFunction &CGF, Flags flags) override {
|
|
|
CGF.EmitCXXDestructorCall(Dtor, Dtor_Complete,
|
|
|
/*ForVirtualBase=*/false,
|
|
|
- /*Delegating=*/false, Addr);
|
|
|
+ /*Delegating=*/false, Addr, Ty);
|
|
|
}
|
|
|
};
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
void CodeGenFunction::PushDestructorCleanup(const CXXDestructorDecl *D,
|
|
|
- Address Addr) {
|
|
|
- EHStack.pushCleanup<CallLocalDtor>(NormalAndEHCleanup, D, Addr);
|
|
|
+ QualType T, Address Addr) {
|
|
|
+ EHStack.pushCleanup<CallLocalDtor>(NormalAndEHCleanup, D, Addr, T);
|
|
|
}
|
|
|
|
|
|
void CodeGenFunction::PushDestructorCleanup(QualType T, Address Addr) {
|
|
@@ -2436,7 +2446,7 @@ void CodeGenFunction::PushDestructorCleanup(QualType T, Address Addr) {
|
|
|
|
|
|
const CXXDestructorDecl *D = ClassDecl->getDestructor();
|
|
|
assert(D && D->isUsed() && "destructor not marked as used!");
|
|
|
- PushDestructorCleanup(D, Addr);
|
|
|
+ PushDestructorCleanup(D, T, Addr);
|
|
|
}
|
|
|
|
|
|
void CodeGenFunction::InitializeVTablePointer(const VPtr &Vptr) {
|