Skip to content

Commit

Permalink
Merging r366429:
Browse files Browse the repository at this point in the history
------------------------------------------------------------------------
r366429 | ibiryukov | 2019-07-18 13:55:33 +0200 (Thu, 18 Jul 2019) | 5 lines

Revert r366422: [OpenCL] Improve destructor support in C++ for OpenCL

Reason: this commit causes crashes in the clang compiler when building
LLVM Support with libc++, see https://bugs.llvm.org/show_bug.cgi?id=42665
for details.
------------------------------------------------------------------------

llvm-svn: 366552
  • Loading branch information
zmodem committed Jul 19, 2019
1 parent 24c2e53 commit eb482e5
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 234 deletions.
14 changes: 3 additions & 11 deletions clang/include/clang/AST/DeclCXX.h
Expand Up @@ -2232,38 +2232,30 @@ class CXXMethodDecl : public FunctionDecl {

overridden_method_range overridden_methods() const;

/// Return the parent of this method declaration, which
/// Returns the parent of this method declaration, which
/// is the class in which this method is defined.
const CXXRecordDecl *getParent() const {
return cast<CXXRecordDecl>(FunctionDecl::getParent());
}

/// Return the parent of this method declaration, which
/// Returns the parent of this method declaration, which
/// is the class in which this method is defined.
CXXRecordDecl *getParent() {
return const_cast<CXXRecordDecl *>(
cast<CXXRecordDecl>(FunctionDecl::getParent()));
}

/// Return the type of the \c this pointer.
/// Returns the type of the \c this pointer.
///
/// Should only be called for instance (i.e., non-static) methods. Note
/// that for the call operator of a lambda closure type, this returns the
/// desugared 'this' type (a pointer to the closure type), not the captured
/// 'this' type.
QualType getThisType() const;

/// Return the type of the object pointed by \c this.
///
/// See getThisType() for usage restriction.
QualType getThisObjectType() const;

static QualType getThisType(const FunctionProtoType *FPT,
const CXXRecordDecl *Decl);

static QualType getThisObjectType(const FunctionProtoType *FPT,
const CXXRecordDecl *Decl);

Qualifiers getMethodQualifiers() const {
return getType()->getAs<FunctionProtoType>()->getMethodQuals();
}
Expand Down
25 changes: 3 additions & 22 deletions clang/lib/AST/DeclCXX.cpp
Expand Up @@ -2253,23 +2253,12 @@ CXXMethodDecl::overridden_methods() const {
return getASTContext().overridden_methods(this);
}

static QualType getThisObjectType(ASTContext &C, const FunctionProtoType *FPT,
const CXXRecordDecl *Decl) {
QualType ClassTy = C.getTypeDeclType(Decl);
return C.getQualifiedType(ClassTy, FPT->getMethodQuals());
}

QualType CXXMethodDecl::getThisType(const FunctionProtoType *FPT,
const CXXRecordDecl *Decl) {
ASTContext &C = Decl->getASTContext();
QualType ObjectTy = ::getThisObjectType(C, FPT, Decl);
return C.getPointerType(ObjectTy);
}

QualType CXXMethodDecl::getThisObjectType(const FunctionProtoType *FPT,
const CXXRecordDecl *Decl) {
ASTContext &C = Decl->getASTContext();
return ::getThisObjectType(C, FPT, Decl);
QualType ClassTy = C.getTypeDeclType(Decl);
ClassTy = C.getQualifiedType(ClassTy, FPT->getMethodQuals());
return C.getPointerType(ClassTy);
}

QualType CXXMethodDecl::getThisType() const {
Expand All @@ -2284,14 +2273,6 @@ QualType CXXMethodDecl::getThisType() const {
getParent());
}

QualType CXXMethodDecl::getThisObjectType() const {
// Ditto getThisType.
assert(isInstance() && "No 'this' for static methods!");

return CXXMethodDecl::getThisObjectType(getType()->getAs<FunctionProtoType>(),
getParent());
}

bool CXXMethodDecl::hasInlineBody() const {
// If this function is a template instantiation, look at the template from
// which it was instantiated.
Expand Down
14 changes: 5 additions & 9 deletions clang/lib/CodeGen/CGCXXABI.h
Expand Up @@ -378,7 +378,7 @@ class CGCXXABI {
virtual void EmitDestructorCall(CodeGenFunction &CGF,
const CXXDestructorDecl *DD, CXXDtorType Type,
bool ForVirtualBase, bool Delegating,
Address This, QualType ThisTy) = 0;
Address This) = 0;

/// Emits the VTable definitions required for the given record type.
virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
Expand Down Expand Up @@ -421,15 +421,11 @@ class CGCXXABI {
llvm::Type *Ty,
SourceLocation Loc) = 0;

using DeleteOrMemberCallExpr =
llvm::PointerUnion<const CXXDeleteExpr *, const CXXMemberCallExpr *>;

/// Emit the ABI-specific virtual destructor call.
virtual llvm::Value *EmitVirtualDestructorCall(CodeGenFunction &CGF,
const CXXDestructorDecl *Dtor,
CXXDtorType DtorType,
Address This,
DeleteOrMemberCallExpr E) = 0;
virtual llvm::Value *
EmitVirtualDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *Dtor,
CXXDtorType DtorType, Address This,
const CXXMemberCallExpr *CE) = 0;

virtual void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF,
GlobalDecl GD,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGCall.cpp
Expand Up @@ -3502,7 +3502,7 @@ struct DestroyUnpassedArg final : EHScopeStack::Cleanup {
const CXXDestructorDecl *Dtor = Ty->getAsCXXRecordDecl()->getDestructor();
assert(!Dtor->isTrivial());
CGF.EmitCXXDestructorCall(Dtor, Dtor_Complete, /*for vbase*/ false,
/*Delegating=*/false, Addr, Ty);
/*Delegating=*/false, Addr);
} else {
CGF.callCStructDestructor(CGF.MakeAddrLValue(Addr, Ty));
}
Expand Down
40 changes: 15 additions & 25 deletions clang/lib/CodeGen/CGClass.cpp
Expand Up @@ -491,15 +491,12 @@ 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, ThisTy);
/*Delegating=*/false, Addr);
}
};

Expand Down Expand Up @@ -1443,11 +1440,9 @@ void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) {
if (DtorType == Dtor_Deleting) {
RunCleanupsScope DtorEpilogue(*this);
EnterDtorCleanups(Dtor, Dtor_Deleting);
if (HaveInsertPoint()) {
QualType ThisTy = Dtor->getThisObjectType();
if (HaveInsertPoint())
EmitCXXDestructorCall(Dtor, Dtor_Complete, /*ForVirtualBase=*/false,
/*Delegating=*/false, LoadCXXThisAddress(), ThisTy);
}
/*Delegating=*/false, LoadCXXThisAddress());
return;
}

Expand Down Expand Up @@ -1478,9 +1473,8 @@ void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) {
EnterDtorCleanups(Dtor, Dtor_Complete);

if (!isTryBody) {
QualType ThisTy = Dtor->getThisObjectType();
EmitCXXDestructorCall(Dtor, Dtor_Base, /*ForVirtualBase=*/false,
/*Delegating=*/false, LoadCXXThisAddress(), ThisTy);
/*Delegating=*/false, LoadCXXThisAddress());
break;
}

Expand Down Expand Up @@ -2019,7 +2013,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, type);
/*Delegating=*/false, addr);
}

void CodeGenFunction::EmitCXXConstructorCall(const CXXConstructorDecl *D,
Expand Down Expand Up @@ -2369,11 +2363,8 @@ 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, ThisTy);
/*Delegating=*/true, Addr);
}
};
} // end anonymous namespace
Expand Down Expand Up @@ -2411,32 +2402,31 @@ CodeGenFunction::EmitDelegatingCXXConstructorCall(const CXXConstructorDecl *Ctor
void CodeGenFunction::EmitCXXDestructorCall(const CXXDestructorDecl *DD,
CXXDtorType Type,
bool ForVirtualBase,
bool Delegating, Address This,
QualType ThisTy) {
bool Delegating,
Address This) {
CGM.getCXXABI().EmitDestructorCall(*this, DD, Type, ForVirtualBase,
Delegating, This, ThisTy);
Delegating, This);
}

namespace {
struct CallLocalDtor final : EHScopeStack::Cleanup {
const CXXDestructorDecl *Dtor;
Address Addr;
QualType Ty;

CallLocalDtor(const CXXDestructorDecl *D, Address Addr, QualType Ty)
: Dtor(D), Addr(Addr), Ty(Ty) {}
CallLocalDtor(const CXXDestructorDecl *D, Address Addr)
: Dtor(D), Addr(Addr) {}

void Emit(CodeGenFunction &CGF, Flags flags) override {
CGF.EmitCXXDestructorCall(Dtor, Dtor_Complete,
/*ForVirtualBase=*/false,
/*Delegating=*/false, Addr, Ty);
/*Delegating=*/false, Addr);
}
};
} // end anonymous namespace

void CodeGenFunction::PushDestructorCleanup(const CXXDestructorDecl *D,
QualType T, Address Addr) {
EHStack.pushCleanup<CallLocalDtor>(NormalAndEHCleanup, D, Addr, T);
Address Addr) {
EHStack.pushCleanup<CallLocalDtor>(NormalAndEHCleanup, D, Addr);
}

void CodeGenFunction::PushDestructorCleanup(QualType T, Address Addr) {
Expand All @@ -2446,7 +2436,7 @@ void CodeGenFunction::PushDestructorCleanup(QualType T, Address Addr) {

const CXXDestructorDecl *D = ClassDecl->getDestructor();
assert(D && D->isUsed() && "destructor not marked as used!");
PushDestructorCleanup(D, T, Addr);
PushDestructorCleanup(D, Addr);
}

void CodeGenFunction::InitializeVTablePointer(const VPtr &Vptr) {
Expand Down
21 changes: 11 additions & 10 deletions clang/lib/CodeGen/CGDecl.cpp
Expand Up @@ -480,12 +480,11 @@ namespace {

template <class Derived>
struct DestroyNRVOVariable : EHScopeStack::Cleanup {
DestroyNRVOVariable(Address addr, QualType type, llvm::Value *NRVOFlag)
: NRVOFlag(NRVOFlag), Loc(addr), Ty(type) {}
DestroyNRVOVariable(Address addr, llvm::Value *NRVOFlag)
: NRVOFlag(NRVOFlag), Loc(addr) {}

llvm::Value *NRVOFlag;
Address Loc;
QualType Ty;

void Emit(CodeGenFunction &CGF, Flags flags) override {
// Along the exceptions path we always execute the dtor.
Expand All @@ -512,24 +511,26 @@ namespace {

struct DestroyNRVOVariableCXX final
: DestroyNRVOVariable<DestroyNRVOVariableCXX> {
DestroyNRVOVariableCXX(Address addr, QualType type,
const CXXDestructorDecl *Dtor, llvm::Value *NRVOFlag)
: DestroyNRVOVariable<DestroyNRVOVariableCXX>(addr, type, NRVOFlag),
Dtor(Dtor) {}
DestroyNRVOVariableCXX(Address addr, const CXXDestructorDecl *Dtor,
llvm::Value *NRVOFlag)
: DestroyNRVOVariable<DestroyNRVOVariableCXX>(addr, NRVOFlag),
Dtor(Dtor) {}

const CXXDestructorDecl *Dtor;

void emitDestructorCall(CodeGenFunction &CGF) {
CGF.EmitCXXDestructorCall(Dtor, Dtor_Complete,
/*ForVirtualBase=*/false,
/*Delegating=*/false, Loc, Ty);
/*Delegating=*/false, Loc);
}
};

struct DestroyNRVOVariableC final
: DestroyNRVOVariable<DestroyNRVOVariableC> {
DestroyNRVOVariableC(Address addr, llvm::Value *NRVOFlag, QualType Ty)
: DestroyNRVOVariable<DestroyNRVOVariableC>(addr, Ty, NRVOFlag) {}
: DestroyNRVOVariable<DestroyNRVOVariableC>(addr, NRVOFlag), Ty(Ty) {}

QualType Ty;

void emitDestructorCall(CodeGenFunction &CGF) {
CGF.destroyNonTrivialCStruct(CGF, Loc, Ty);
Expand Down Expand Up @@ -1939,7 +1940,7 @@ void CodeGenFunction::emitAutoVarTypeCleanup(
if (emission.NRVOFlag) {
assert(!type->isArrayType());
CXXDestructorDecl *dtor = type->getAsCXXRecordDecl()->getDestructor();
EHStack.pushCleanup<DestroyNRVOVariableCXX>(cleanupKind, addr, type, dtor,
EHStack.pushCleanup<DestroyNRVOVariableCXX>(cleanupKind, addr, dtor,
emission.NRVOFlag);
return;
}
Expand Down
31 changes: 7 additions & 24 deletions clang/lib/CodeGen/CGExprCXX.cpp
Expand Up @@ -10,13 +10,12 @@
//
//===----------------------------------------------------------------------===//

#include "CodeGenFunction.h"
#include "CGCUDARuntime.h"
#include "CGCXXABI.h"
#include "CGDebugInfo.h"
#include "CGObjCRuntime.h"
#include "CodeGenFunction.h"
#include "ConstantEmitter.h"
#include "TargetInfo.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/CodeGen/CGFunctionInfo.h"
#include "llvm/IR/Intrinsics.h"
Expand Down Expand Up @@ -91,26 +90,12 @@ RValue CodeGenFunction::EmitCXXMemberOrOperatorCall(
}

RValue CodeGenFunction::EmitCXXDestructorCall(
GlobalDecl Dtor, const CGCallee &Callee, llvm::Value *This, QualType ThisTy,
GlobalDecl Dtor, const CGCallee &Callee, llvm::Value *This,
llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *CE) {
const CXXMethodDecl *DtorDecl = cast<CXXMethodDecl>(Dtor.getDecl());

assert(!ThisTy.isNull());
assert(ThisTy->getAsCXXRecordDecl() == DtorDecl->getParent() &&
"Pointer/Object mixup");

LangAS SrcAS = ThisTy.getAddressSpace();
LangAS DstAS = DtorDecl->getMethodQualifiers().getAddressSpace();
if (SrcAS != DstAS) {
QualType DstTy = DtorDecl->getThisType();
llvm::Type *NewType = CGM.getTypes().ConvertType(DstTy);
This = getTargetHooks().performAddrSpaceCast(*this, This, SrcAS, DstAS,
NewType);
}

CallArgList Args;
commonEmitCXXMemberOrOperatorCall(*this, DtorDecl, This, ImplicitParam,
ImplicitParamTy, CE, Args, nullptr);
commonEmitCXXMemberOrOperatorCall(*this, cast<CXXMethodDecl>(Dtor.getDecl()),
This, ImplicitParam, ImplicitParamTy, CE,
Args, nullptr);
return EmitCall(CGM.getTypes().arrangeCXXStructorDeclaration(Dtor), Callee,
ReturnValueSlot(), Args);
}
Expand Down Expand Up @@ -360,9 +345,7 @@ RValue CodeGenFunction::EmitCXXMemberOrOperatorMemberCallExpr(
Callee = CGCallee::forDirect(CGM.GetAddrOfFunction(GD, Ty), GD);
}

QualType ThisTy =
IsArrow ? Base->getType()->getPointeeType() : Base->getType();
EmitCXXDestructorCall(GD, Callee, This.getPointer(), ThisTy,
EmitCXXDestructorCall(GD, Callee, This.getPointer(),
/*ImplicitParam=*/nullptr,
/*ImplicitParamTy=*/QualType(), nullptr);
}
Expand Down Expand Up @@ -1900,7 +1883,7 @@ static void EmitObjectDelete(CodeGenFunction &CGF,
CGF.EmitCXXDestructorCall(Dtor, Dtor_Complete,
/*ForVirtualBase=*/false,
/*Delegating=*/false,
Ptr, ElementType);
Ptr);
else if (auto Lifetime = ElementType.getObjCLifetime()) {
switch (Lifetime) {
case Qualifiers::OCL_None:
Expand Down
13 changes: 6 additions & 7 deletions clang/lib/CodeGen/CodeGenFunction.h
Expand Up @@ -675,8 +675,7 @@ class CodeGenFunction : public CodeGenTypeCache {
/// PushDestructorCleanup - Push a cleanup to call the
/// complete-object variant of the given destructor on the object at
/// the given address.
void PushDestructorCleanup(const CXXDestructorDecl *Dtor, QualType T,
Address Addr);
void PushDestructorCleanup(const CXXDestructorDecl *Dtor, Address Addr);

/// PopCleanupBlock - Will pop the cleanup entry on the stack and
/// process all branch fixups.
Expand Down Expand Up @@ -2555,8 +2554,8 @@ class CodeGenFunction : public CodeGenTypeCache {
static Destroyer destroyCXXObject;

void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type,
bool ForVirtualBase, bool Delegating, Address This,
QualType ThisTy);
bool ForVirtualBase, bool Delegating,
Address This);

void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType,
llvm::Type *ElementTy, Address NewPtr,
Expand Down Expand Up @@ -3678,9 +3677,9 @@ class CodeGenFunction : public CodeGenTypeCache {
llvm::Value *ImplicitParam,
QualType ImplicitParamTy, const CallExpr *E,
CallArgList *RtlArgs);
RValue EmitCXXDestructorCall(GlobalDecl Dtor, const CGCallee &Callee,
llvm::Value *This, QualType ThisTy,
llvm::Value *ImplicitParam,
RValue EmitCXXDestructorCall(GlobalDecl Dtor,
const CGCallee &Callee,
llvm::Value *This, llvm::Value *ImplicitParam,
QualType ImplicitParamTy, const CallExpr *E);
RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E,
ReturnValueSlot ReturnValue);
Expand Down

0 comments on commit eb482e5

Please sign in to comment.