Reland [MS][clang] Add support for vector deleting destructors (#170337)
This reverts commit
54a4da9df6.
MSVC supports an extension allowing to delete an array of objects via
pointer whose static type doesn't match its dynamic type. This is done
via generation of special destructors - vector deleting destructors.
MSVC's virtual tables always contain a pointer to the vector deleting
destructor for classes with virtual destructors, so not having this
extension implemented causes clang to generate code that is not
compatible with the code generated by MSVC, because clang always puts a
pointer to a scalar deleting destructor to the vtable. As a bonus the
deletion of an array of polymorphic object will work just like it does
with MSVC - no memory leaks and correct destructors are called.
This patch will cause clang to emit code that is compatible with code
produced by MSVC but not compatible with code produced with clang of
older versions, so the new behavior can be disabled via passing
-fclang-abi-compat=21 (or lower).
Fixes https://github.com/llvm/llvm-project/issues/19772
This commit is contained in:
parent
a318c50110
commit
d714a6c210
@ -86,6 +86,12 @@ Potentially Breaking Changes
|
||||
options-related code has been moved out of the Driver into a separate library.
|
||||
- The ``clangFrontend`` library no longer depends on ``clangDriver``, which may
|
||||
break downstream projects that relied on this transitive dependency.
|
||||
- Clang now supports MSVC vector deleting destructors when targeting Windows.
|
||||
This means that vtables of classes with virtual destructors will contain a
|
||||
pointer to vector deleting destructor (instead of scalar deleting destructor)
|
||||
which in fact is a different symbol with different name and linkage. This
|
||||
may cause runtime failures if two binaries using the same class defining a
|
||||
virtual destructor are compiled with different versions of clang.
|
||||
|
||||
C/C++ Language Potentially Breaking Changes
|
||||
-------------------------------------------
|
||||
@ -654,6 +660,8 @@ Windows Support
|
||||
- clang-cl now supports /arch:AVX10.1 and /arch:AVX10.2.
|
||||
- clang-cl now supports /vlen, /vlen=256 and /vlen=512.
|
||||
|
||||
- Clang now supports MSVC vector deleting destructors (GH19772).
|
||||
|
||||
LoongArch Support
|
||||
^^^^^^^^^^^^^^^^^
|
||||
- Enable linker relaxation by default for loongarch64.
|
||||
|
||||
@ -370,6 +370,21 @@ class ASTContext : public RefCountedBase<ASTContext> {
|
||||
mutable llvm::DenseSet<const FunctionDecl *> DestroyingOperatorDeletes;
|
||||
mutable llvm::DenseSet<const FunctionDecl *> TypeAwareOperatorNewAndDeletes;
|
||||
|
||||
/// Global and array operators delete are only required for MSVC deleting
|
||||
/// destructors support. Store them here to avoid keeping 4 pointers that are
|
||||
/// not always used in each redeclaration of the destructor.
|
||||
mutable llvm::DenseMap<const CXXDestructorDecl *, FunctionDecl *>
|
||||
OperatorDeletesForVirtualDtor;
|
||||
mutable llvm::DenseMap<const CXXDestructorDecl *, FunctionDecl *>
|
||||
GlobalOperatorDeletesForVirtualDtor;
|
||||
mutable llvm::DenseMap<const CXXDestructorDecl *, FunctionDecl *>
|
||||
ArrayOperatorDeletesForVirtualDtor;
|
||||
mutable llvm::DenseMap<const CXXDestructorDecl *, FunctionDecl *>
|
||||
GlobalArrayOperatorDeletesForVirtualDtor;
|
||||
|
||||
/// To remember which types did require a vector deleting dtor.
|
||||
llvm::DenseSet<const CXXRecordDecl *> RequireVectorDeletingDtor;
|
||||
|
||||
/// The next string literal "version" to allocate during constant evaluation.
|
||||
/// This is used to distinguish between repeated evaluations of the same
|
||||
/// string literal.
|
||||
@ -3489,6 +3504,18 @@ public:
|
||||
bool IsTypeAware);
|
||||
bool isTypeAwareOperatorNewOrDelete(const FunctionDecl *FD) const;
|
||||
|
||||
enum OperatorDeleteKind { Regular, GlobalRegular, Array, ArrayGlobal };
|
||||
|
||||
void addOperatorDeleteForVDtor(const CXXDestructorDecl *Dtor,
|
||||
FunctionDecl *OperatorDelete,
|
||||
OperatorDeleteKind K) const;
|
||||
FunctionDecl *getOperatorDeleteForVDtor(const CXXDestructorDecl *Dtor,
|
||||
OperatorDeleteKind K) const;
|
||||
bool dtorHasOperatorDelete(const CXXDestructorDecl *Dtor,
|
||||
OperatorDeleteKind K) const;
|
||||
void setClassNeedsVectorDeletingDestructor(const CXXRecordDecl *RD);
|
||||
bool classNeedsVectorDeletingDestructor(const CXXRecordDecl *RD);
|
||||
|
||||
/// Retrieve the context for computing mangling numbers in the given
|
||||
/// DeclContext.
|
||||
MangleNumberingContext &getManglingNumberContext(const DeclContext *DC);
|
||||
|
||||
@ -90,6 +90,15 @@ public:
|
||||
virtual void ResolvedOperatorGlobDelete(const CXXDestructorDecl *DD,
|
||||
const FunctionDecl *GlobDelete) {}
|
||||
|
||||
/// A virtual destructor's operator array delete has been resolved.
|
||||
virtual void ResolvedOperatorArrayDelete(const CXXDestructorDecl *DD,
|
||||
const FunctionDecl *ArrayDelete) {}
|
||||
|
||||
/// A virtual destructor's operator global array delete has been resolved.
|
||||
virtual void
|
||||
ResolvedOperatorGlobArrayDelete(const CXXDestructorDecl *DD,
|
||||
const FunctionDecl *GlobArrayDelete) {}
|
||||
|
||||
/// An implicit member got a definition.
|
||||
virtual void CompletedImplicitDefinition(const FunctionDecl *D) {}
|
||||
|
||||
|
||||
@ -2872,8 +2872,6 @@ class CXXDestructorDecl : public CXXMethodDecl {
|
||||
|
||||
// FIXME: Don't allocate storage for these except in the first declaration
|
||||
// of a virtual destructor.
|
||||
FunctionDecl *OperatorDelete = nullptr;
|
||||
FunctionDecl *OperatorGlobalDelete = nullptr;
|
||||
Expr *OperatorDeleteThisArg = nullptr;
|
||||
|
||||
CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
|
||||
@ -2900,14 +2898,12 @@ public:
|
||||
|
||||
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg);
|
||||
void setOperatorGlobalDelete(FunctionDecl *OD);
|
||||
|
||||
const FunctionDecl *getOperatorDelete() const {
|
||||
return getCanonicalDecl()->OperatorDelete;
|
||||
}
|
||||
|
||||
const FunctionDecl *getOperatorGlobalDelete() const {
|
||||
return getCanonicalDecl()->OperatorGlobalDelete;
|
||||
}
|
||||
void setOperatorArrayDelete(FunctionDecl *OD);
|
||||
void setGlobalOperatorArrayDelete(FunctionDecl *OD);
|
||||
const FunctionDecl *getOperatorDelete() const;
|
||||
const FunctionDecl *getOperatorGlobalDelete() const;
|
||||
const FunctionDecl *getArrayOperatorDelete() const;
|
||||
const FunctionDecl *getGlobalArrayOperatorDelete() const;
|
||||
|
||||
Expr *getOperatorDeleteThisArg() const {
|
||||
return getCanonicalDecl()->OperatorDeleteThisArg;
|
||||
|
||||
@ -150,7 +150,7 @@ public:
|
||||
|
||||
bool isRTTIKind() const { return isRTTIKind(getKind()); }
|
||||
|
||||
GlobalDecl getGlobalDecl() const {
|
||||
GlobalDecl getGlobalDecl(bool HasVectorDeletingDtors) const {
|
||||
assert(isUsedFunctionPointerKind() &&
|
||||
"GlobalDecl can be created only from virtual function");
|
||||
|
||||
@ -161,7 +161,9 @@ public:
|
||||
case CK_CompleteDtorPointer:
|
||||
return GlobalDecl(DtorDecl, CXXDtorType::Dtor_Complete);
|
||||
case CK_DeletingDtorPointer:
|
||||
return GlobalDecl(DtorDecl, CXXDtorType::Dtor_Deleting);
|
||||
return GlobalDecl(DtorDecl, (HasVectorDeletingDtors)
|
||||
? CXXDtorType::Dtor_VectorDeleting
|
||||
: CXXDtorType::Dtor_Deleting);
|
||||
case CK_VCallOffset:
|
||||
case CK_VBaseOffset:
|
||||
case CK_OffsetToTop:
|
||||
|
||||
@ -32,11 +32,12 @@ enum CXXCtorType {
|
||||
|
||||
/// C++ destructor types.
|
||||
enum CXXDtorType {
|
||||
Dtor_Deleting, ///< Deleting dtor
|
||||
Dtor_Complete, ///< Complete object dtor
|
||||
Dtor_Base, ///< Base object dtor
|
||||
Dtor_Comdat, ///< The COMDAT used for dtors
|
||||
Dtor_Unified, ///< GCC-style unified dtor
|
||||
Dtor_Deleting, ///< Deleting dtor
|
||||
Dtor_Complete, ///< Complete object dtor
|
||||
Dtor_Base, ///< Base object dtor
|
||||
Dtor_Comdat, ///< The COMDAT used for dtors
|
||||
Dtor_Unified, ///< GCC-style unified dtor
|
||||
Dtor_VectorDeleting, ///< Vector deleting dtor
|
||||
};
|
||||
|
||||
} // end namespace clang
|
||||
|
||||
@ -1798,6 +1798,11 @@ public:
|
||||
/// destructor body.
|
||||
virtual bool callGlobalDeleteInDeletingDtor(const LangOptions &) const;
|
||||
|
||||
/// Controls whether to emit MSVC vector deleting destructors. The support for
|
||||
/// vector deleting affects vtable layout and therefore is an ABI breaking
|
||||
/// change. The support was only implemented at Clang 22 timeframe.
|
||||
virtual bool emitVectorDeletingDtors(const LangOptions &) const;
|
||||
|
||||
/// Controls if __builtin_longjmp / __builtin_setjmp can be lowered to
|
||||
/// llvm.eh.sjlj.longjmp / llvm.eh.sjlj.setjmp.
|
||||
virtual bool hasSjLjLowering() const {
|
||||
|
||||
@ -8586,7 +8586,8 @@ public:
|
||||
FunctionDecl *FindDeallocationFunctionForDestructor(SourceLocation StartLoc,
|
||||
CXXRecordDecl *RD,
|
||||
bool Diagnose,
|
||||
bool LookForGlobal);
|
||||
bool LookForGlobal,
|
||||
DeclarationName Name);
|
||||
|
||||
/// ActOnCXXDelete - Parsed a C++ 'delete' expression (C++ 5.3.5), as in:
|
||||
/// @code ::delete ptr; @endcode
|
||||
|
||||
@ -955,6 +955,10 @@ private:
|
||||
Expr *ThisArg) override;
|
||||
void ResolvedOperatorGlobDelete(const CXXDestructorDecl *DD,
|
||||
const FunctionDecl *Delete) override;
|
||||
void ResolvedOperatorArrayDelete(const CXXDestructorDecl *DD,
|
||||
const FunctionDecl *Delete) override;
|
||||
void ResolvedOperatorGlobArrayDelete(const CXXDestructorDecl *DD,
|
||||
const FunctionDecl *Delete) override;
|
||||
void CompletedImplicitDefinition(const FunctionDecl *D) override;
|
||||
void InstantiationRequested(const ValueDecl *D) override;
|
||||
void VariableDefinitionInstantiated(const VarDecl *D) override;
|
||||
|
||||
@ -13348,6 +13348,91 @@ bool ASTContext::isTypeAwareOperatorNewOrDelete(const FunctionDecl *FD) const {
|
||||
return TypeAwareOperatorNewAndDeletes.contains(FD->getCanonicalDecl());
|
||||
}
|
||||
|
||||
void ASTContext::addOperatorDeleteForVDtor(const CXXDestructorDecl *Dtor,
|
||||
FunctionDecl *OperatorDelete,
|
||||
OperatorDeleteKind K) const {
|
||||
switch (K) {
|
||||
case OperatorDeleteKind::Regular:
|
||||
OperatorDeletesForVirtualDtor[Dtor->getCanonicalDecl()] = OperatorDelete;
|
||||
break;
|
||||
case OperatorDeleteKind::GlobalRegular:
|
||||
GlobalOperatorDeletesForVirtualDtor[Dtor->getCanonicalDecl()] =
|
||||
OperatorDelete;
|
||||
break;
|
||||
case OperatorDeleteKind::Array:
|
||||
ArrayOperatorDeletesForVirtualDtor[Dtor->getCanonicalDecl()] =
|
||||
OperatorDelete;
|
||||
break;
|
||||
case OperatorDeleteKind::ArrayGlobal:
|
||||
GlobalArrayOperatorDeletesForVirtualDtor[Dtor->getCanonicalDecl()] =
|
||||
OperatorDelete;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool ASTContext::dtorHasOperatorDelete(const CXXDestructorDecl *Dtor,
|
||||
OperatorDeleteKind K) const {
|
||||
switch (K) {
|
||||
case OperatorDeleteKind::Regular:
|
||||
return OperatorDeletesForVirtualDtor.contains(Dtor->getCanonicalDecl());
|
||||
case OperatorDeleteKind::GlobalRegular:
|
||||
return GlobalOperatorDeletesForVirtualDtor.contains(
|
||||
Dtor->getCanonicalDecl());
|
||||
case OperatorDeleteKind::Array:
|
||||
return ArrayOperatorDeletesForVirtualDtor.contains(
|
||||
Dtor->getCanonicalDecl());
|
||||
case OperatorDeleteKind::ArrayGlobal:
|
||||
return GlobalArrayOperatorDeletesForVirtualDtor.contains(
|
||||
Dtor->getCanonicalDecl());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
FunctionDecl *
|
||||
ASTContext::getOperatorDeleteForVDtor(const CXXDestructorDecl *Dtor,
|
||||
OperatorDeleteKind K) const {
|
||||
const CXXDestructorDecl *Canon = Dtor->getCanonicalDecl();
|
||||
switch (K) {
|
||||
case OperatorDeleteKind::Regular:
|
||||
if (OperatorDeletesForVirtualDtor.contains(Canon))
|
||||
return OperatorDeletesForVirtualDtor[Canon];
|
||||
return nullptr;
|
||||
case OperatorDeleteKind::GlobalRegular:
|
||||
if (GlobalOperatorDeletesForVirtualDtor.contains(Canon))
|
||||
return GlobalOperatorDeletesForVirtualDtor[Canon];
|
||||
return nullptr;
|
||||
case OperatorDeleteKind::Array:
|
||||
if (ArrayOperatorDeletesForVirtualDtor.contains(Canon))
|
||||
return ArrayOperatorDeletesForVirtualDtor[Canon];
|
||||
return nullptr;
|
||||
case OperatorDeleteKind::ArrayGlobal:
|
||||
if (GlobalArrayOperatorDeletesForVirtualDtor.contains(Canon))
|
||||
return GlobalArrayOperatorDeletesForVirtualDtor[Canon];
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ASTContext::classNeedsVectorDeletingDestructor(const CXXRecordDecl *RD) {
|
||||
if (!getTargetInfo().emitVectorDeletingDtors(getLangOpts()))
|
||||
return false;
|
||||
CXXDestructorDecl *Dtor = RD->getDestructor();
|
||||
// The compiler can't know if new[]/delete[] will be used outside of the DLL,
|
||||
// so just force vector deleting destructor emission if dllexport is present.
|
||||
// This matches MSVC behavior.
|
||||
if (Dtor && Dtor->isVirtual() && Dtor->hasAttr<DLLExportAttr>())
|
||||
return true;
|
||||
|
||||
return RequireVectorDeletingDtor.count(RD);
|
||||
}
|
||||
|
||||
void ASTContext::setClassNeedsVectorDeletingDestructor(
|
||||
const CXXRecordDecl *RD) {
|
||||
if (!getTargetInfo().emitVectorDeletingDtors(getLangOpts()))
|
||||
return;
|
||||
RequireVectorDeletingDtor.insert(RD);
|
||||
}
|
||||
|
||||
MangleNumberingContext &
|
||||
ASTContext::getManglingNumberContext(const DeclContext *DC) {
|
||||
assert(LangOpts.CPlusPlus); // We don't need mangling numbers for plain C.
|
||||
|
||||
@ -3110,12 +3110,15 @@ CXXDestructorDecl *CXXDestructorDecl::Create(
|
||||
}
|
||||
|
||||
void CXXDestructorDecl::setOperatorDelete(FunctionDecl *OD, Expr *ThisArg) {
|
||||
auto *First = cast<CXXDestructorDecl>(getFirstDecl());
|
||||
if (OD && !First->OperatorDelete) {
|
||||
First->OperatorDelete = OD;
|
||||
First->OperatorDeleteThisArg = ThisArg;
|
||||
assert(!OD || (OD->getDeclName().getCXXOverloadedOperator() == OO_Delete));
|
||||
if (OD && !getASTContext().dtorHasOperatorDelete(
|
||||
this, ASTContext::OperatorDeleteKind::Regular)) {
|
||||
getASTContext().addOperatorDeleteForVDtor(
|
||||
this, OD, ASTContext::OperatorDeleteKind::Regular);
|
||||
getCanonicalDecl()->OperatorDeleteThisArg = ThisArg;
|
||||
if (auto *L = getASTMutationListener())
|
||||
L->ResolvedOperatorDelete(First, OD, ThisArg);
|
||||
L->ResolvedOperatorDelete(cast<CXXDestructorDecl>(getCanonicalDecl()), OD,
|
||||
ThisArg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3127,14 +3130,63 @@ void CXXDestructorDecl::setOperatorGlobalDelete(FunctionDecl *OD) {
|
||||
assert(!OD ||
|
||||
(OD->getDeclName().getCXXOverloadedOperator() == OO_Delete &&
|
||||
OD->getDeclContext()->getRedeclContext()->isTranslationUnit()));
|
||||
auto *Canonical = cast<CXXDestructorDecl>(getCanonicalDecl());
|
||||
if (!Canonical->OperatorGlobalDelete) {
|
||||
Canonical->OperatorGlobalDelete = OD;
|
||||
if (OD && !getASTContext().dtorHasOperatorDelete(
|
||||
this, ASTContext::OperatorDeleteKind::GlobalRegular)) {
|
||||
getASTContext().addOperatorDeleteForVDtor(
|
||||
this, OD, ASTContext::OperatorDeleteKind::GlobalRegular);
|
||||
if (auto *L = getASTMutationListener())
|
||||
L->ResolvedOperatorGlobDelete(Canonical, OD);
|
||||
L->ResolvedOperatorGlobDelete(cast<CXXDestructorDecl>(getCanonicalDecl()),
|
||||
OD);
|
||||
}
|
||||
}
|
||||
|
||||
void CXXDestructorDecl::setOperatorArrayDelete(FunctionDecl *OD) {
|
||||
assert(!OD ||
|
||||
(OD->getDeclName().getCXXOverloadedOperator() == OO_Array_Delete));
|
||||
if (OD && !getASTContext().dtorHasOperatorDelete(
|
||||
this, ASTContext::OperatorDeleteKind::Array)) {
|
||||
getASTContext().addOperatorDeleteForVDtor(
|
||||
this, OD, ASTContext::OperatorDeleteKind::Array);
|
||||
if (auto *L = getASTMutationListener())
|
||||
L->ResolvedOperatorArrayDelete(
|
||||
cast<CXXDestructorDecl>(getCanonicalDecl()), OD);
|
||||
}
|
||||
}
|
||||
|
||||
void CXXDestructorDecl::setGlobalOperatorArrayDelete(FunctionDecl *OD) {
|
||||
assert(!OD ||
|
||||
(OD->getDeclName().getCXXOverloadedOperator() == OO_Array_Delete &&
|
||||
OD->getDeclContext()->getRedeclContext()->isTranslationUnit()));
|
||||
if (OD && !getASTContext().dtorHasOperatorDelete(
|
||||
this, ASTContext::OperatorDeleteKind::ArrayGlobal)) {
|
||||
getASTContext().addOperatorDeleteForVDtor(
|
||||
this, OD, ASTContext::OperatorDeleteKind::ArrayGlobal);
|
||||
if (auto *L = getASTMutationListener())
|
||||
L->ResolvedOperatorGlobArrayDelete(
|
||||
cast<CXXDestructorDecl>(getCanonicalDecl()), OD);
|
||||
}
|
||||
}
|
||||
|
||||
const FunctionDecl *CXXDestructorDecl::getOperatorDelete() const {
|
||||
return getASTContext().getOperatorDeleteForVDtor(
|
||||
this, ASTContext::OperatorDeleteKind::Regular);
|
||||
}
|
||||
|
||||
const FunctionDecl *CXXDestructorDecl::getOperatorGlobalDelete() const {
|
||||
return getASTContext().getOperatorDeleteForVDtor(
|
||||
this, ASTContext::OperatorDeleteKind::GlobalRegular);
|
||||
}
|
||||
|
||||
const FunctionDecl *CXXDestructorDecl::getArrayOperatorDelete() const {
|
||||
return getASTContext().getOperatorDeleteForVDtor(
|
||||
this, ASTContext::OperatorDeleteKind::Array);
|
||||
}
|
||||
|
||||
const FunctionDecl *CXXDestructorDecl::getGlobalArrayOperatorDelete() const {
|
||||
return getASTContext().getOperatorDeleteForVDtor(
|
||||
this, ASTContext::OperatorDeleteKind::ArrayGlobal);
|
||||
}
|
||||
|
||||
bool CXXDestructorDecl::isCalledByDelete(const FunctionDecl *OpDel) const {
|
||||
// C++20 [expr.delete]p6: If the value of the operand of the delete-
|
||||
// expression is not a null pointer value and the selected deallocation
|
||||
@ -3146,7 +3198,8 @@ bool CXXDestructorDecl::isCalledByDelete(const FunctionDecl *OpDel) const {
|
||||
// delete operator, as that destructor is never called, unless the
|
||||
// destructor is virtual (see [expr.delete]p8.1) because then the
|
||||
// selected operator depends on the dynamic type of the pointer.
|
||||
const FunctionDecl *SelectedOperatorDelete = OpDel ? OpDel : OperatorDelete;
|
||||
const FunctionDecl *SelectedOperatorDelete =
|
||||
OpDel ? OpDel : getOperatorDelete();
|
||||
if (!SelectedOperatorDelete)
|
||||
return true;
|
||||
|
||||
|
||||
@ -71,6 +71,9 @@ const CXXRecordDecl *Expr::getBestDynamicClassType() const {
|
||||
if (const PointerType *PTy = DerivedType->getAs<PointerType>())
|
||||
DerivedType = PTy->getPointeeType();
|
||||
|
||||
while (const ArrayType *ATy = DerivedType->getAsArrayTypeUnsafe())
|
||||
DerivedType = ATy->getElementType();
|
||||
|
||||
if (DerivedType->isDependentType())
|
||||
return nullptr;
|
||||
|
||||
|
||||
@ -6040,6 +6040,8 @@ void CXXNameMangler::mangleCXXDtorType(CXXDtorType T) {
|
||||
case Dtor_Comdat:
|
||||
Out << "D5";
|
||||
break;
|
||||
case Dtor_VectorDeleting:
|
||||
llvm_unreachable("Itanium ABI does not use vector deleting dtors");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1492,8 +1492,9 @@ void MicrosoftCXXNameMangler::mangleCXXDtorType(CXXDtorType T) {
|
||||
// <operator-name> ::= ?_G # scalar deleting destructor
|
||||
case Dtor_Deleting: Out << "?_G"; return;
|
||||
// <operator-name> ::= ?_E # vector deleting destructor
|
||||
// FIXME: Add a vector deleting dtor type. It goes in the vtable, so we need
|
||||
// it.
|
||||
case Dtor_VectorDeleting:
|
||||
Out << "?_E";
|
||||
return;
|
||||
case Dtor_Comdat:
|
||||
llvm_unreachable("not expecting a COMDAT");
|
||||
case Dtor_Unified:
|
||||
@ -2913,9 +2914,12 @@ void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T,
|
||||
// ::= @ # structors (they have no declared return type)
|
||||
if (IsStructor) {
|
||||
if (isa<CXXDestructorDecl>(D) && isStructorDecl(D)) {
|
||||
// The scalar deleting destructor takes an extra int argument which is not
|
||||
// reflected in the AST.
|
||||
if (StructorType == Dtor_Deleting) {
|
||||
// The deleting destructors take an extra argument of type int that
|
||||
// indicates whether the storage for the object should be deleted and
|
||||
// whether a single object or an array of objects is being destroyed. This
|
||||
// extra argument is not reflected in the AST.
|
||||
if (StructorType == Dtor_Deleting ||
|
||||
StructorType == Dtor_VectorDeleting) {
|
||||
Out << (PointersAre64Bit ? "PEAXI@Z" : "PAXI@Z");
|
||||
return;
|
||||
}
|
||||
@ -3911,10 +3915,10 @@ void MicrosoftMangleContextImpl::mangleCXXDtorThunk(const CXXDestructorDecl *DD,
|
||||
const ThunkInfo &Thunk,
|
||||
bool /*ElideOverrideInfo*/,
|
||||
raw_ostream &Out) {
|
||||
// FIXME: Actually, the dtor thunk should be emitted for vector deleting
|
||||
// dtors rather than scalar deleting dtors. Just use the vector deleting dtor
|
||||
// mangling manually until we support both deleting dtor types.
|
||||
assert(Type == Dtor_Deleting);
|
||||
// The dtor thunk should use vector deleting dtor mangling, however as an
|
||||
// optimization we may end up emitting only scalar deleting dtor body, so just
|
||||
// use the vector deleting dtor mangling manually.
|
||||
assert(Type == Dtor_Deleting || Type == Dtor_VectorDeleting);
|
||||
msvc_hashing_ostream MHO(Out);
|
||||
MicrosoftCXXNameMangler Mangler(*this, MHO, DD, Type);
|
||||
Mangler.getStream() << "??_E";
|
||||
|
||||
@ -2658,7 +2658,12 @@ private:
|
||||
MethodVFTableLocation Loc(MI.VBTableIndex, WhichVFPtr.getVBaseWithVPtr(),
|
||||
WhichVFPtr.NonVirtualOffset, MI.VFTableIndex);
|
||||
if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) {
|
||||
MethodVFTableLocations[GlobalDecl(DD, Dtor_Deleting)] = Loc;
|
||||
// In Microsoft ABI vftable always references vector deleting dtor.
|
||||
CXXDtorType DtorTy = Context.getTargetInfo().emitVectorDeletingDtors(
|
||||
Context.getLangOpts())
|
||||
? Dtor_VectorDeleting
|
||||
: Dtor_Deleting;
|
||||
MethodVFTableLocations[GlobalDecl(DD, DtorTy)] = Loc;
|
||||
} else {
|
||||
MethodVFTableLocations[MD] = Loc;
|
||||
}
|
||||
@ -3288,7 +3293,11 @@ void VFTableBuilder::dumpLayout(raw_ostream &Out) {
|
||||
const CXXDestructorDecl *DD = Component.getDestructorDecl();
|
||||
|
||||
DD->printQualifiedName(Out);
|
||||
Out << "() [scalar deleting]";
|
||||
if (Context.getTargetInfo().emitVectorDeletingDtors(
|
||||
Context.getLangOpts()))
|
||||
Out << "() [vector deleting]";
|
||||
else
|
||||
Out << "() [scalar deleting]";
|
||||
|
||||
if (DD->isPureVirtual())
|
||||
Out << " [pure]";
|
||||
@ -3758,7 +3767,7 @@ void MicrosoftVTableContext::dumpMethodLocations(
|
||||
PredefinedIdentKind::PrettyFunctionNoVirtual, MD);
|
||||
|
||||
if (isa<CXXDestructorDecl>(MD)) {
|
||||
IndicesMap[I.second] = MethodName + " [scalar deleting]";
|
||||
IndicesMap[I.second] = MethodName + " [vector deleting]";
|
||||
} else {
|
||||
IndicesMap[I.second] = MethodName;
|
||||
}
|
||||
@ -3874,7 +3883,8 @@ MicrosoftVTableContext::getMethodVFTableLocation(GlobalDecl GD) {
|
||||
assert(hasVtableSlot(cast<CXXMethodDecl>(GD.getDecl())) &&
|
||||
"Only use this method for virtual methods or dtors");
|
||||
if (isa<CXXDestructorDecl>(GD.getDecl()))
|
||||
assert(GD.getDtorType() == Dtor_Deleting);
|
||||
assert(GD.getDtorType() == Dtor_VectorDeleting ||
|
||||
GD.getDtorType() == Dtor_Deleting);
|
||||
|
||||
GD = GD.getCanonicalDecl();
|
||||
|
||||
|
||||
@ -637,6 +637,13 @@ bool TargetInfo::callGlobalDeleteInDeletingDtor(
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TargetInfo::emitVectorDeletingDtors(const LangOptions &LangOpts) const {
|
||||
if (getCXXABI() == TargetCXXABI::Microsoft &&
|
||||
LangOpts.getClangABICompat() > LangOptions::ClangABI::Ver21)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TargetInfo::areDefaultedSMFStillPOD(const LangOptions &LangOpts) const {
|
||||
return LangOpts.getClangABICompat() > LangOptions::ClangABI::Ver15;
|
||||
}
|
||||
|
||||
@ -777,6 +777,13 @@ void CIRGenFunction::emitCXXDeleteExpr(const CXXDeleteExpr *e) {
|
||||
deleteTy = getContext().getBaseElementType(deleteTy);
|
||||
ptr = ptr.withElementType(builder, convertTypeForMem(deleteTy));
|
||||
|
||||
if (e->isArrayForm() &&
|
||||
cgm.getASTContext().getTargetInfo().emitVectorDeletingDtors(
|
||||
cgm.getASTContext().getLangOpts())) {
|
||||
cgm.errorNYI(e->getSourceRange(),
|
||||
"emitCXXDeleteExpr: emitVectorDeletingDtors");
|
||||
}
|
||||
|
||||
if (e->isArrayForm()) {
|
||||
assert(!cir::MissingFeatures::deleteArray());
|
||||
cgm.errorNYI(e->getSourceRange(), "emitCXXDeleteExpr: array delete");
|
||||
|
||||
@ -847,7 +847,9 @@ void CIRGenFunction::emitDestructorBody(FunctionArgList &args) {
|
||||
// outside of the function-try-block, which means it's always
|
||||
// possible to delegate the destructor body to the complete
|
||||
// destructor. Do so.
|
||||
if (dtorType == Dtor_Deleting) {
|
||||
if (dtorType == Dtor_Deleting || dtorType == Dtor_VectorDeleting) {
|
||||
if (cxxStructorImplicitParamValue && dtorType == Dtor_VectorDeleting)
|
||||
cgm.errorNYI(dtor->getSourceRange(), "emitConditionalArrayDtorCall");
|
||||
RunCleanupsScope dtorEpilogue(*this);
|
||||
enterDtorCleanups(dtor, Dtor_Deleting);
|
||||
if (haveInsertPoint()) {
|
||||
@ -880,6 +882,7 @@ void CIRGenFunction::emitDestructorBody(FunctionArgList &args) {
|
||||
case Dtor_Comdat:
|
||||
llvm_unreachable("not expecting a COMDAT");
|
||||
case Dtor_Deleting:
|
||||
case Dtor_VectorDeleting:
|
||||
llvm_unreachable("already handled deleting case");
|
||||
|
||||
case Dtor_Complete:
|
||||
|
||||
@ -145,7 +145,9 @@ mlir::Attribute CIRGenVTables::getVTableComponent(
|
||||
case VTableComponent::CK_FunctionPointer:
|
||||
case VTableComponent::CK_CompleteDtorPointer:
|
||||
case VTableComponent::CK_DeletingDtorPointer: {
|
||||
GlobalDecl gd = component.getGlobalDecl();
|
||||
GlobalDecl gd = component.getGlobalDecl(
|
||||
cgm.getASTContext().getTargetInfo().emitVectorDeletingDtors(
|
||||
cgm.getASTContext().getLangOpts()));
|
||||
|
||||
assert(!cir::MissingFeatures::cudaSupport());
|
||||
|
||||
|
||||
@ -174,7 +174,6 @@ bool CodeGenModule::TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) {
|
||||
// requires explicit comdat support in the IL.
|
||||
if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
|
||||
return true;
|
||||
|
||||
// Create the alias with no name.
|
||||
auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0, Linkage, "",
|
||||
Aliasee, &getModule());
|
||||
@ -200,6 +199,42 @@ bool CodeGenModule::TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Emit a definition as a global alias for another definition, unconditionally.
|
||||
void CodeGenModule::EmitDefinitionAsAlias(GlobalDecl AliasDecl,
|
||||
GlobalDecl TargetDecl) {
|
||||
|
||||
llvm::Type *AliasValueType = getTypes().GetFunctionType(AliasDecl);
|
||||
|
||||
StringRef MangledName = getMangledName(AliasDecl);
|
||||
llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
|
||||
if (Entry && !Entry->isDeclaration())
|
||||
return;
|
||||
auto *Aliasee = cast<llvm::GlobalValue>(GetAddrOfGlobal(TargetDecl));
|
||||
|
||||
// Determine the linkage type for the alias.
|
||||
llvm::GlobalValue::LinkageTypes Linkage = getFunctionLinkage(AliasDecl);
|
||||
|
||||
// Create the alias with no name.
|
||||
auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0, Linkage, "",
|
||||
Aliasee, &getModule());
|
||||
// Destructors are always unnamed_addr.
|
||||
Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
|
||||
|
||||
if (Entry) {
|
||||
assert(Entry->getValueType() == AliasValueType &&
|
||||
Entry->getAddressSpace() == Alias->getAddressSpace() &&
|
||||
"declaration exists with different type");
|
||||
Alias->takeName(Entry);
|
||||
Entry->replaceAllUsesWith(Alias);
|
||||
Entry->eraseFromParent();
|
||||
} else {
|
||||
Alias->setName(MangledName);
|
||||
}
|
||||
|
||||
// Set any additional necessary attributes for the alias.
|
||||
SetCommonAttributes(AliasDecl, Alias);
|
||||
}
|
||||
|
||||
llvm::Function *CodeGenModule::codegenCXXStructor(GlobalDecl GD) {
|
||||
const CGFunctionInfo &FnInfo = getTypes().arrangeCXXStructorDeclaration(GD);
|
||||
auto *Fn = cast<llvm::Function>(
|
||||
|
||||
@ -268,6 +268,20 @@ void CGCXXABI::ReadArrayCookie(CodeGenFunction &CGF, Address ptr,
|
||||
numElements = readArrayCookieImpl(CGF, allocAddr, cookieSize);
|
||||
}
|
||||
|
||||
void CGCXXABI::ReadArrayCookie(CodeGenFunction &CGF, Address ptr,
|
||||
QualType eltTy, llvm::Value *&numElements,
|
||||
llvm::Value *&allocPtr, CharUnits &cookieSize) {
|
||||
assert(eltTy.isDestructedType());
|
||||
|
||||
// Derive a char* in the same address space as the pointer.
|
||||
ptr = ptr.withElementType(CGF.Int8Ty);
|
||||
|
||||
cookieSize = getArrayCookieSizeImpl(eltTy);
|
||||
Address allocAddr = CGF.Builder.CreateConstInBoundsByteGEP(ptr, -cookieSize);
|
||||
allocPtr = allocAddr.emitRawPointer(CGF);
|
||||
numElements = readArrayCookieImpl(CGF, allocAddr, cookieSize);
|
||||
}
|
||||
|
||||
llvm::Value *CGCXXABI::readArrayCookieImpl(CodeGenFunction &CGF,
|
||||
Address ptr,
|
||||
CharUnits cookieSize) {
|
||||
|
||||
@ -583,6 +583,12 @@ public:
|
||||
QualType ElementType, llvm::Value *&NumElements,
|
||||
llvm::Value *&AllocPtr, CharUnits &CookieSize);
|
||||
|
||||
/// Reads the array cookie associated with the given pointer,
|
||||
/// that should have one.
|
||||
void ReadArrayCookie(CodeGenFunction &CGF, Address Ptr, QualType ElementType,
|
||||
llvm::Value *&NumElements, llvm::Value *&AllocPtr,
|
||||
CharUnits &CookieSize);
|
||||
|
||||
/// Return whether the given global decl needs a VTT parameter.
|
||||
virtual bool NeedsVTTParameter(GlobalDecl GD);
|
||||
|
||||
|
||||
@ -1442,6 +1442,103 @@ static bool CanSkipVTablePointerInitialization(CodeGenFunction &CGF,
|
||||
return true;
|
||||
}
|
||||
|
||||
static void EmitConditionalArrayDtorCall(const CXXDestructorDecl *DD,
|
||||
CodeGenFunction &CGF,
|
||||
llvm::Value *ShouldDeleteCondition) {
|
||||
Address ThisPtr = CGF.LoadCXXThisAddress();
|
||||
llvm::BasicBlock *ScalarBB = CGF.createBasicBlock("dtor.scalar");
|
||||
llvm::BasicBlock *callDeleteBB =
|
||||
CGF.createBasicBlock("dtor.call_delete_after_array_destroy");
|
||||
llvm::BasicBlock *VectorBB = CGF.createBasicBlock("dtor.vector");
|
||||
auto *CondTy = cast<llvm::IntegerType>(ShouldDeleteCondition->getType());
|
||||
llvm::Value *CheckTheBitForArrayDestroy = CGF.Builder.CreateAnd(
|
||||
ShouldDeleteCondition, llvm::ConstantInt::get(CondTy, 2));
|
||||
llvm::Value *ShouldDestroyArray =
|
||||
CGF.Builder.CreateIsNull(CheckTheBitForArrayDestroy);
|
||||
CGF.Builder.CreateCondBr(ShouldDestroyArray, ScalarBB, VectorBB);
|
||||
|
||||
CGF.EmitBlock(VectorBB);
|
||||
|
||||
llvm::Value *numElements = nullptr;
|
||||
llvm::Value *allocatedPtr = nullptr;
|
||||
CharUnits cookieSize;
|
||||
QualType EltTy = DD->getThisType()->getPointeeType();
|
||||
CGF.CGM.getCXXABI().ReadArrayCookie(CGF, ThisPtr, EltTy, numElements,
|
||||
allocatedPtr, cookieSize);
|
||||
|
||||
// Destroy the elements.
|
||||
QualType::DestructionKind dtorKind = EltTy.isDestructedType();
|
||||
|
||||
assert(dtorKind);
|
||||
assert(numElements && "no element count for a type with a destructor!");
|
||||
|
||||
CharUnits elementSize = CGF.getContext().getTypeSizeInChars(EltTy);
|
||||
CharUnits elementAlign =
|
||||
ThisPtr.getAlignment().alignmentOfArrayElement(elementSize);
|
||||
|
||||
llvm::Value *arrayBegin = ThisPtr.emitRawPointer(CGF);
|
||||
llvm::Value *arrayEnd = CGF.Builder.CreateInBoundsGEP(
|
||||
ThisPtr.getElementType(), arrayBegin, numElements, "delete.end");
|
||||
|
||||
// We already checked that the array is not 0-length before entering vector
|
||||
// deleting dtor.
|
||||
CGF.emitArrayDestroy(arrayBegin, arrayEnd, EltTy, elementAlign,
|
||||
CGF.getDestroyer(dtorKind),
|
||||
/*checkZeroLength*/ false, CGF.needsEHCleanup(dtorKind));
|
||||
|
||||
llvm::BasicBlock *VectorBBCont = CGF.createBasicBlock("dtor.vector.cont");
|
||||
CGF.EmitBlock(VectorBBCont);
|
||||
|
||||
llvm::Value *CheckTheBitForDeleteCall = CGF.Builder.CreateAnd(
|
||||
ShouldDeleteCondition, llvm::ConstantInt::get(CondTy, 1));
|
||||
|
||||
llvm::Value *ShouldCallDelete =
|
||||
CGF.Builder.CreateIsNull(CheckTheBitForDeleteCall);
|
||||
CGF.Builder.CreateCondBr(ShouldCallDelete, CGF.ReturnBlock.getBlock(),
|
||||
callDeleteBB);
|
||||
CGF.EmitBlock(callDeleteBB);
|
||||
const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(CGF.CurCodeDecl);
|
||||
const CXXRecordDecl *ClassDecl = Dtor->getParent();
|
||||
if (Dtor->getArrayOperatorDelete()) {
|
||||
if (!Dtor->getGlobalArrayOperatorDelete()) {
|
||||
CGF.EmitDeleteCall(Dtor->getArrayOperatorDelete(), allocatedPtr,
|
||||
CGF.getContext().getCanonicalTagType(ClassDecl));
|
||||
} else {
|
||||
// If global operator[] is set, the class had its own operator delete[].
|
||||
// In that case, check the 4th bit. If it is set, we need to call
|
||||
// ::delete[].
|
||||
llvm::Value *CheckTheBitForGlobDeleteCall = CGF.Builder.CreateAnd(
|
||||
ShouldDeleteCondition, llvm::ConstantInt::get(CondTy, 4));
|
||||
|
||||
llvm::Value *ShouldCallGlobDelete =
|
||||
CGF.Builder.CreateIsNull(CheckTheBitForGlobDeleteCall);
|
||||
llvm::BasicBlock *GlobDelete =
|
||||
CGF.createBasicBlock("dtor.call_glob_delete_after_array_destroy");
|
||||
llvm::BasicBlock *ClassDelete =
|
||||
CGF.createBasicBlock("dtor.call_class_delete_after_array_destroy");
|
||||
CGF.Builder.CreateCondBr(ShouldCallGlobDelete, ClassDelete, GlobDelete);
|
||||
CGF.EmitBlock(ClassDelete);
|
||||
CGF.EmitDeleteCall(Dtor->getArrayOperatorDelete(), allocatedPtr,
|
||||
CGF.getContext().getCanonicalTagType(ClassDecl));
|
||||
CGF.EmitBranchThroughCleanup(CGF.ReturnBlock);
|
||||
|
||||
CGF.EmitBlock(GlobDelete);
|
||||
CGF.EmitDeleteCall(Dtor->getGlobalArrayOperatorDelete(), allocatedPtr,
|
||||
CGF.getContext().getCanonicalTagType(ClassDecl));
|
||||
}
|
||||
} else {
|
||||
// No operators delete[] were found, so emit a trap.
|
||||
llvm::CallInst *TrapCall = CGF.EmitTrapCall(llvm::Intrinsic::trap);
|
||||
TrapCall->setDoesNotReturn();
|
||||
TrapCall->setDoesNotThrow();
|
||||
CGF.Builder.CreateUnreachable();
|
||||
CGF.Builder.ClearInsertionPoint();
|
||||
}
|
||||
|
||||
CGF.EmitBranchThroughCleanup(CGF.ReturnBlock);
|
||||
CGF.EmitBlock(ScalarBB);
|
||||
}
|
||||
|
||||
/// EmitDestructorBody - Emits the body of the current destructor.
|
||||
void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) {
|
||||
const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(CurGD.getDecl());
|
||||
@ -1471,7 +1568,9 @@ void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) {
|
||||
// outside of the function-try-block, which means it's always
|
||||
// possible to delegate the destructor body to the complete
|
||||
// destructor. Do so.
|
||||
if (DtorType == Dtor_Deleting) {
|
||||
if (DtorType == Dtor_Deleting || DtorType == Dtor_VectorDeleting) {
|
||||
if (CXXStructorImplicitParamValue && DtorType == Dtor_VectorDeleting)
|
||||
EmitConditionalArrayDtorCall(Dtor, *this, CXXStructorImplicitParamValue);
|
||||
RunCleanupsScope DtorEpilogue(*this);
|
||||
EnterDtorCleanups(Dtor, Dtor_Deleting);
|
||||
if (HaveInsertPoint()) {
|
||||
@ -1502,6 +1601,8 @@ void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) {
|
||||
llvm_unreachable("not expecting a unified dtor");
|
||||
case Dtor_Comdat: llvm_unreachable("not expecting a COMDAT");
|
||||
case Dtor_Deleting: llvm_unreachable("already handled deleting case");
|
||||
case Dtor_VectorDeleting:
|
||||
llvm_unreachable("already handled vector deleting case");
|
||||
|
||||
case Dtor_Complete:
|
||||
assert((Body || getTarget().getCXXABI().isMicrosoft()) &&
|
||||
|
||||
@ -2363,7 +2363,13 @@ llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
|
||||
// Emit MS ABI vftable information. There is only one entry for the
|
||||
// deleting dtor.
|
||||
const auto *DD = dyn_cast<CXXDestructorDecl>(Method);
|
||||
GlobalDecl GD = DD ? GlobalDecl(DD, Dtor_Deleting) : GlobalDecl(Method);
|
||||
GlobalDecl GD =
|
||||
DD ? GlobalDecl(
|
||||
DD, CGM.getContext().getTargetInfo().emitVectorDeletingDtors(
|
||||
CGM.getContext().getLangOpts())
|
||||
? Dtor_VectorDeleting
|
||||
: Dtor_Deleting)
|
||||
: GlobalDecl(Method);
|
||||
MethodVFTableLocation ML =
|
||||
CGM.getMicrosoftVTableContext().getMethodVFTableLocation(GD);
|
||||
VIndex = ML.Index;
|
||||
|
||||
@ -1916,10 +1916,8 @@ static void EmitDestroyingObjectDelete(CodeGenFunction &CGF,
|
||||
/// Emit the code for deleting a single object.
|
||||
/// \return \c true if we started emitting UnconditionalDeleteBlock, \c false
|
||||
/// if not.
|
||||
static bool EmitObjectDelete(CodeGenFunction &CGF,
|
||||
const CXXDeleteExpr *DE,
|
||||
Address Ptr,
|
||||
QualType ElementType,
|
||||
static bool EmitObjectDelete(CodeGenFunction &CGF, const CXXDeleteExpr *DE,
|
||||
Address Ptr, QualType ElementType,
|
||||
llvm::BasicBlock *UnconditionalDeleteBlock) {
|
||||
// C++11 [expr.delete]p3:
|
||||
// If the static type of the object to be deleted is different from its
|
||||
@ -2113,6 +2111,42 @@ void CodeGenFunction::EmitCXXDeleteExpr(const CXXDeleteExpr *E) {
|
||||
DeleteTy = getContext().getBaseElementType(DeleteTy);
|
||||
Ptr = Ptr.withElementType(ConvertTypeForMem(DeleteTy));
|
||||
|
||||
if (E->isArrayForm() &&
|
||||
CGM.getContext().getTargetInfo().emitVectorDeletingDtors(
|
||||
CGM.getContext().getLangOpts())) {
|
||||
if (auto *RD = DeleteTy->getAsCXXRecordDecl()) {
|
||||
auto *Dtor = RD->getDestructor();
|
||||
if (Dtor && Dtor->isVirtual()) {
|
||||
llvm::Value *NumElements = nullptr;
|
||||
llvm::Value *AllocatedPtr = nullptr;
|
||||
CharUnits CookieSize;
|
||||
llvm::BasicBlock *BodyBB = createBasicBlock("vdtor.call");
|
||||
llvm::BasicBlock *DoneBB = createBasicBlock("vdtor.nocall");
|
||||
// Check array cookie to see if the array has length 0. Don't call
|
||||
// the destructor in that case.
|
||||
CGM.getCXXABI().ReadArrayCookie(*this, Ptr, E, DeleteTy, NumElements,
|
||||
AllocatedPtr, CookieSize);
|
||||
|
||||
auto *CondTy = cast<llvm::IntegerType>(NumElements->getType());
|
||||
llvm::Value *IsEmpty = Builder.CreateICmpEQ(
|
||||
NumElements, llvm::ConstantInt::get(CondTy, 0));
|
||||
Builder.CreateCondBr(IsEmpty, DoneBB, BodyBB);
|
||||
|
||||
// Delete cookie for empty array.
|
||||
const FunctionDecl *OperatorDelete = E->getOperatorDelete();
|
||||
EmitBlock(DoneBB);
|
||||
EmitDeleteCall(OperatorDelete, AllocatedPtr, DeleteTy, NumElements,
|
||||
CookieSize);
|
||||
EmitBranch(DeleteEnd);
|
||||
|
||||
EmitBlock(BodyBB);
|
||||
if (!EmitObjectDelete(*this, E, Ptr, DeleteTy, DeleteEnd))
|
||||
EmitBlock(DeleteEnd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (E->isArrayForm()) {
|
||||
EmitArrayDelete(*this, E, Ptr, DeleteTy);
|
||||
EmitBlock(DeleteEnd);
|
||||
|
||||
@ -775,7 +775,9 @@ void CodeGenVTables::addVTableComponent(ConstantArrayBuilder &builder,
|
||||
case VTableComponent::CK_FunctionPointer:
|
||||
case VTableComponent::CK_CompleteDtorPointer:
|
||||
case VTableComponent::CK_DeletingDtorPointer: {
|
||||
GlobalDecl GD = component.getGlobalDecl();
|
||||
GlobalDecl GD = component.getGlobalDecl(
|
||||
CGM.getContext().getTargetInfo().emitVectorDeletingDtors(
|
||||
CGM.getContext().getLangOpts()));
|
||||
|
||||
const bool IsThunk =
|
||||
nextVTableThunkIndex < layout.vtable_thunks().size() &&
|
||||
|
||||
@ -1547,6 +1547,7 @@ public:
|
||||
void EmitGlobal(GlobalDecl D);
|
||||
|
||||
bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
|
||||
void EmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target);
|
||||
|
||||
llvm::GlobalValue *GetGlobalValue(StringRef Ref);
|
||||
|
||||
|
||||
@ -93,6 +93,8 @@ public:
|
||||
llvm_unreachable("emitting dtor comdat as function?");
|
||||
case Dtor_Unified:
|
||||
llvm_unreachable("emitting unified dtor as function?");
|
||||
case Dtor_VectorDeleting:
|
||||
llvm_unreachable("unexpected dtor kind for this ABI");
|
||||
}
|
||||
llvm_unreachable("bad dtor kind");
|
||||
}
|
||||
@ -458,7 +460,8 @@ public:
|
||||
if (!IsInlined)
|
||||
continue;
|
||||
|
||||
StringRef Name = CGM.getMangledName(VtableComponent.getGlobalDecl());
|
||||
StringRef Name = CGM.getMangledName(
|
||||
VtableComponent.getGlobalDecl(/*HasVectorDeletingDtors=*/false));
|
||||
auto *Entry = CGM.GetGlobalValue(Name);
|
||||
// This checks if virtual inline function has already been emitted.
|
||||
// Note that it is possible that this inline function would be emitted
|
||||
|
||||
@ -71,8 +71,8 @@ public:
|
||||
switch (GD.getDtorType()) {
|
||||
case Dtor_Complete:
|
||||
case Dtor_Deleting:
|
||||
case Dtor_VectorDeleting:
|
||||
return true;
|
||||
|
||||
case Dtor_Base:
|
||||
return false;
|
||||
|
||||
@ -269,7 +269,11 @@ public:
|
||||
|
||||
// There's only Dtor_Deleting in vftable but it shares the this
|
||||
// adjustment with the base one, so look up the deleting one instead.
|
||||
LookupGD = GlobalDecl(DD, Dtor_Deleting);
|
||||
LookupGD = GlobalDecl(
|
||||
DD, CGM.getContext().getTargetInfo().emitVectorDeletingDtors(
|
||||
CGM.getContext().getLangOpts())
|
||||
? Dtor_VectorDeleting
|
||||
: Dtor_Deleting);
|
||||
}
|
||||
MethodVFTableLocation ML =
|
||||
CGM.getMicrosoftVTableContext().getMethodVFTableLocation(LookupGD);
|
||||
@ -351,8 +355,9 @@ public:
|
||||
|
||||
void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF, GlobalDecl GD,
|
||||
CallArgList &CallArgs) override {
|
||||
assert(GD.getDtorType() == Dtor_Deleting &&
|
||||
"Only deleting destructor thunks are available in this ABI");
|
||||
assert((GD.getDtorType() == Dtor_VectorDeleting ||
|
||||
GD.getDtorType() == Dtor_Deleting) &&
|
||||
"Only vector deleting destructor thunks are available in this ABI");
|
||||
CallArgs.add(RValue::get(getStructorImplicitParamValue(CGF)),
|
||||
getContext().IntTy);
|
||||
}
|
||||
@ -1107,7 +1112,8 @@ bool MicrosoftCXXABI::HasThisReturn(GlobalDecl GD) const {
|
||||
|
||||
static bool isDeletingDtor(GlobalDecl GD) {
|
||||
return isa<CXXDestructorDecl>(GD.getDecl()) &&
|
||||
GD.getDtorType() == Dtor_Deleting;
|
||||
(GD.getDtorType() == Dtor_Deleting ||
|
||||
GD.getDtorType() == Dtor_VectorDeleting);
|
||||
}
|
||||
|
||||
bool MicrosoftCXXABI::hasMostDerivedReturn(GlobalDecl GD) const {
|
||||
@ -1360,7 +1366,8 @@ MicrosoftCXXABI::buildStructorSignature(GlobalDecl GD,
|
||||
AddedStructorArgCounts Added;
|
||||
// TODO: 'for base' flag
|
||||
if (isa<CXXDestructorDecl>(GD.getDecl()) &&
|
||||
GD.getDtorType() == Dtor_Deleting) {
|
||||
(GD.getDtorType() == Dtor_Deleting ||
|
||||
GD.getDtorType() == Dtor_VectorDeleting)) {
|
||||
// The scalar deleting destructor takes an implicit int parameter.
|
||||
ArgTys.push_back(getContext().IntTy);
|
||||
++Added.Suffix;
|
||||
@ -1392,7 +1399,7 @@ void MicrosoftCXXABI::setCXXDestructorDLLStorage(llvm::GlobalValue *GV,
|
||||
CXXDtorType DT) const {
|
||||
// Deleting destructor variants are never imported or exported. Give them the
|
||||
// default storage class.
|
||||
if (DT == Dtor_Deleting) {
|
||||
if (DT == Dtor_Deleting || DT == Dtor_VectorDeleting) {
|
||||
GV->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
|
||||
} else {
|
||||
const NamedDecl *ND = Dtor;
|
||||
@ -1428,6 +1435,12 @@ llvm::GlobalValue::LinkageTypes MicrosoftCXXABI::getCXXDestructorLinkage(
|
||||
return llvm::GlobalValue::LinkOnceODRLinkage;
|
||||
case Dtor_Unified:
|
||||
llvm_unreachable("MS C++ ABI does not support unified dtors");
|
||||
case Dtor_VectorDeleting:
|
||||
// Use the weak, non-ODR linkage for vector deleting destructors to block
|
||||
// inlining. This enables an MS ABI code-size saving optimization that
|
||||
// allows us to avoid emitting array deletion code when arrays of a given
|
||||
// type are not allocated within the final linkage unit.
|
||||
return llvm::GlobalValue::WeakAnyLinkage;
|
||||
case Dtor_Comdat:
|
||||
llvm_unreachable("MS C++ ABI does not support comdat dtors");
|
||||
}
|
||||
@ -1459,7 +1472,11 @@ MicrosoftCXXABI::getVirtualFunctionPrologueThisAdjustment(GlobalDecl GD) {
|
||||
|
||||
// There's no Dtor_Base in vftable but it shares the this adjustment with
|
||||
// the deleting one, so look it up instead.
|
||||
GD = GlobalDecl(DD, Dtor_Deleting);
|
||||
GD =
|
||||
GlobalDecl(DD, CGM.getContext().getTargetInfo().emitVectorDeletingDtors(
|
||||
CGM.getContext().getLangOpts())
|
||||
? Dtor_VectorDeleting
|
||||
: Dtor_Deleting);
|
||||
}
|
||||
|
||||
MethodVFTableLocation ML =
|
||||
@ -1508,7 +1525,11 @@ Address MicrosoftCXXABI::adjustThisArgumentForVirtualFunctionCall(
|
||||
|
||||
// There's only Dtor_Deleting in vftable but it shares the this adjustment
|
||||
// with the base one, so look up the deleting one instead.
|
||||
LookupGD = GlobalDecl(DD, Dtor_Deleting);
|
||||
LookupGD =
|
||||
GlobalDecl(DD, CGM.getContext().getTargetInfo().emitVectorDeletingDtors(
|
||||
CGM.getContext().getLangOpts())
|
||||
? Dtor_VectorDeleting
|
||||
: Dtor_Deleting);
|
||||
}
|
||||
MethodVFTableLocation ML =
|
||||
CGM.getMicrosoftVTableContext().getMethodVFTableLocation(LookupGD);
|
||||
@ -2018,24 +2039,30 @@ llvm::Value *MicrosoftCXXABI::EmitVirtualDestructorCall(
|
||||
auto *CE = dyn_cast<const CXXMemberCallExpr *>(E);
|
||||
auto *D = dyn_cast<const CXXDeleteExpr *>(E);
|
||||
assert((CE != nullptr) ^ (D != nullptr));
|
||||
assert(CE == nullptr || CE->arguments().empty());
|
||||
assert(DtorType == Dtor_Deleting || DtorType == Dtor_Complete);
|
||||
assert(CE == nullptr || CE->arg_begin() == CE->arg_end());
|
||||
assert(DtorType == Dtor_VectorDeleting || DtorType == Dtor_Complete ||
|
||||
DtorType == Dtor_Deleting);
|
||||
|
||||
// We have only one destructor in the vftable but can get both behaviors
|
||||
// by passing an implicit int parameter.
|
||||
GlobalDecl GD(Dtor, Dtor_Deleting);
|
||||
ASTContext &Context = getContext();
|
||||
bool VectorDeletingDtorsEnabled =
|
||||
Context.getTargetInfo().emitVectorDeletingDtors(Context.getLangOpts());
|
||||
GlobalDecl GD(Dtor, VectorDeletingDtorsEnabled ? Dtor_VectorDeleting
|
||||
: Dtor_Deleting);
|
||||
const CGFunctionInfo *FInfo =
|
||||
&CGM.getTypes().arrangeCXXStructorDeclaration(GD);
|
||||
llvm::FunctionType *Ty = CGF.CGM.getTypes().GetFunctionType(*FInfo);
|
||||
CGCallee Callee = CGCallee::forVirtual(CE, GD, This, Ty);
|
||||
|
||||
ASTContext &Context = getContext();
|
||||
bool IsDeleting = DtorType == Dtor_Deleting;
|
||||
bool IsArrayDelete = D && D->isArrayForm() && VectorDeletingDtorsEnabled;
|
||||
bool IsGlobalDelete = D && D->isGlobalDelete() &&
|
||||
Context.getTargetInfo().callGlobalDeleteInDeletingDtor(
|
||||
Context.getLangOpts());
|
||||
llvm::Value *ImplicitParam =
|
||||
CGF.Builder.getInt32((IsDeleting ? 1 : 0) | (IsGlobalDelete ? 4 : 0));
|
||||
CGF.Builder.getInt32((IsDeleting ? 1 : 0) | (IsGlobalDelete ? 4 : 0) |
|
||||
(IsArrayDelete ? 2 : 0));
|
||||
|
||||
QualType ThisTy;
|
||||
if (CE) {
|
||||
@ -2044,6 +2071,9 @@ llvm::Value *MicrosoftCXXABI::EmitVirtualDestructorCall(
|
||||
ThisTy = D->getDestroyedType();
|
||||
}
|
||||
|
||||
while (const ArrayType *ATy = Context.getAsArrayType(ThisTy))
|
||||
ThisTy = ATy->getElementType();
|
||||
|
||||
This = adjustThisArgumentForVirtualFunctionCall(CGF, GD, This, true);
|
||||
RValue RV =
|
||||
CGF.EmitCXXDestructorCall(GD, Callee, This.emitRawPointer(CGF), ThisTy,
|
||||
@ -4074,6 +4104,18 @@ void MicrosoftCXXABI::emitCXXStructor(GlobalDecl GD) {
|
||||
if (GD.getDtorType() == Dtor_Base && !CGM.TryEmitBaseDestructorAsAlias(dtor))
|
||||
return;
|
||||
|
||||
if (GD.getDtorType() == Dtor_VectorDeleting &&
|
||||
!getContext().classNeedsVectorDeletingDestructor(dtor->getParent())) {
|
||||
// Create GlobalDecl object with the correct type for the scalar
|
||||
// deleting destructor.
|
||||
GlobalDecl ScalarDtorGD(dtor, Dtor_Deleting);
|
||||
|
||||
// Emit an alias from the vector deleting destructor to the scalar deleting
|
||||
// destructor.
|
||||
CGM.EmitDefinitionAsAlias(GD, ScalarDtorGD);
|
||||
return;
|
||||
}
|
||||
|
||||
llvm::Function *Fn = CGM.codegenCXXStructor(GD);
|
||||
if (Fn->isWeakForLinker())
|
||||
Fn->setComdat(CGM.getModule().getOrInsertComdat(Fn->getName()));
|
||||
|
||||
@ -11136,9 +11136,11 @@ bool Sema::CheckDestructor(CXXDestructorDecl *Destructor) {
|
||||
else
|
||||
Loc = RD->getLocation();
|
||||
|
||||
DeclarationName Name =
|
||||
Context.DeclarationNames.getCXXOperatorName(OO_Delete);
|
||||
// If we have a virtual destructor, look up the deallocation function
|
||||
if (FunctionDecl *OperatorDelete = FindDeallocationFunctionForDestructor(
|
||||
Loc, RD, /*Diagnose=*/true, /*LookForGlobal=*/false)) {
|
||||
Loc, RD, /*Diagnose=*/true, /*LookForGlobal=*/false, Name)) {
|
||||
Expr *ThisArg = nullptr;
|
||||
|
||||
// If the notional 'delete this' expression requires a non-trivial
|
||||
@ -11186,8 +11188,38 @@ bool Sema::CheckDestructor(CXXDestructorDecl *Destructor) {
|
||||
// delete calls that require it.
|
||||
FunctionDecl *GlobalOperatorDelete =
|
||||
FindDeallocationFunctionForDestructor(Loc, RD, /*Diagnose*/ false,
|
||||
/*LookForGlobal*/ true);
|
||||
Destructor->setOperatorGlobalDelete(GlobalOperatorDelete);
|
||||
/*LookForGlobal*/ true, Name);
|
||||
if (GlobalOperatorDelete) {
|
||||
MarkFunctionReferenced(Loc, GlobalOperatorDelete);
|
||||
Destructor->setOperatorGlobalDelete(GlobalOperatorDelete);
|
||||
}
|
||||
}
|
||||
|
||||
if (Context.getTargetInfo().emitVectorDeletingDtors(
|
||||
Context.getLangOpts())) {
|
||||
// Lookup delete[] too in case we have to emit a vector deleting dtor.
|
||||
DeclarationName VDeleteName =
|
||||
Context.DeclarationNames.getCXXOperatorName(OO_Array_Delete);
|
||||
FunctionDecl *ArrOperatorDelete = FindDeallocationFunctionForDestructor(
|
||||
Loc, RD, /*Diagnose*/ false,
|
||||
/*LookForGlobal*/ false, VDeleteName);
|
||||
if (ArrOperatorDelete && isa<CXXMethodDecl>(ArrOperatorDelete)) {
|
||||
FunctionDecl *GlobalArrOperatorDelete =
|
||||
FindDeallocationFunctionForDestructor(Loc, RD, /*Diagnose*/ false,
|
||||
/*LookForGlobal*/ true,
|
||||
VDeleteName);
|
||||
Destructor->setGlobalOperatorArrayDelete(GlobalArrOperatorDelete);
|
||||
if (GlobalArrOperatorDelete &&
|
||||
Context.classNeedsVectorDeletingDestructor(RD))
|
||||
MarkFunctionReferenced(Loc, GlobalArrOperatorDelete);
|
||||
} else if (!ArrOperatorDelete) {
|
||||
ArrOperatorDelete = FindDeallocationFunctionForDestructor(
|
||||
Loc, RD, /*Diagnose*/ false,
|
||||
/*LookForGlobal*/ true, VDeleteName);
|
||||
}
|
||||
Destructor->setOperatorArrayDelete(ArrOperatorDelete);
|
||||
if (ArrOperatorDelete && Context.classNeedsVectorDeletingDestructor(RD))
|
||||
MarkFunctionReferenced(Loc, ArrOperatorDelete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2631,6 +2631,19 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool UseGlobal,
|
||||
MarkFunctionReferenced(StartLoc, OperatorDelete);
|
||||
}
|
||||
|
||||
// For MSVC vector deleting destructors support we record that for the class
|
||||
// new[] was called. We try to optimize the code size and only emit vector
|
||||
// deleting destructors when they are required. Vector deleting destructors
|
||||
// are required for delete[] call but MSVC triggers emission of them
|
||||
// whenever new[] is called for an object of the class and we do the same
|
||||
// for compatibility.
|
||||
if (const CXXConstructExpr *CCE =
|
||||
dyn_cast_or_null<CXXConstructExpr>(Initializer);
|
||||
CCE && ArraySize) {
|
||||
Context.setClassNeedsVectorDeletingDestructor(
|
||||
CCE->getConstructor()->getParent());
|
||||
}
|
||||
|
||||
return CXXNewExpr::Create(Context, UseGlobal, OperatorNew, OperatorDelete,
|
||||
IAP, UsualArrayDeleteWantsSize, PlacementArgs,
|
||||
TypeIdParens, ArraySize, InitStyle, Initializer,
|
||||
@ -3612,11 +3625,9 @@ Sema::FindUsualDeallocationFunction(SourceLocation StartLoc,
|
||||
return Result.FD;
|
||||
}
|
||||
|
||||
FunctionDecl *Sema::FindDeallocationFunctionForDestructor(SourceLocation Loc,
|
||||
CXXRecordDecl *RD,
|
||||
bool Diagnose,
|
||||
bool LookForGlobal) {
|
||||
DeclarationName Name = Context.DeclarationNames.getCXXOperatorName(OO_Delete);
|
||||
FunctionDecl *Sema::FindDeallocationFunctionForDestructor(
|
||||
SourceLocation Loc, CXXRecordDecl *RD, bool Diagnose, bool LookForGlobal,
|
||||
DeclarationName Name) {
|
||||
|
||||
FunctionDecl *OperatorDelete = nullptr;
|
||||
CanQualType DeallocType = Context.getCanonicalTagType(RD);
|
||||
@ -3649,8 +3660,11 @@ bool Sema::FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
|
||||
// Try to find operator delete/operator delete[] in class scope.
|
||||
LookupQualifiedName(Found, RD);
|
||||
|
||||
if (Found.isAmbiguous())
|
||||
if (Found.isAmbiguous()) {
|
||||
if (!Diagnose)
|
||||
Found.suppressDiagnostics();
|
||||
return true;
|
||||
}
|
||||
|
||||
Found.suppressDiagnostics();
|
||||
|
||||
|
||||
@ -42,7 +42,9 @@ enum class DeclUpdateKind {
|
||||
DeclMarkedOpenMPDeclareTarget,
|
||||
DeclExported,
|
||||
AddedAttrToRecord,
|
||||
CXXResolvedDtorGlobDelete
|
||||
CXXResolvedDtorGlobDelete,
|
||||
CXXResolvedDtorArrayDelete,
|
||||
CXXResolvedDtorGlobArrayDelete
|
||||
};
|
||||
|
||||
TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT);
|
||||
|
||||
@ -2339,19 +2339,33 @@ void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
|
||||
void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
|
||||
VisitCXXMethodDecl(D);
|
||||
|
||||
CXXDestructorDecl *Canon = D->getCanonicalDecl();
|
||||
ASTContext &C = Reader.getContext();
|
||||
CXXDestructorDecl *Canon = cast<CXXDestructorDecl>(D->getCanonicalDecl());
|
||||
if (auto *OperatorDelete = readDeclAs<FunctionDecl>()) {
|
||||
auto *ThisArg = Record.readExpr();
|
||||
// FIXME: Check consistency if we have an old and new operator delete.
|
||||
if (!Canon->OperatorDelete) {
|
||||
Canon->OperatorDelete = OperatorDelete;
|
||||
if (!C.dtorHasOperatorDelete(D, ASTContext::OperatorDeleteKind::Regular)) {
|
||||
C.addOperatorDeleteForVDtor(D, OperatorDelete,
|
||||
ASTContext::OperatorDeleteKind::Regular);
|
||||
Canon->OperatorDeleteThisArg = ThisArg;
|
||||
}
|
||||
}
|
||||
if (auto *OperatorGlobDelete = readDeclAs<FunctionDecl>()) {
|
||||
if (!Canon->OperatorGlobalDelete) {
|
||||
Canon->OperatorGlobalDelete = OperatorGlobDelete;
|
||||
}
|
||||
if (!C.dtorHasOperatorDelete(D,
|
||||
ASTContext::OperatorDeleteKind::GlobalRegular))
|
||||
C.addOperatorDeleteForVDtor(
|
||||
D, OperatorGlobDelete, ASTContext::OperatorDeleteKind::GlobalRegular);
|
||||
}
|
||||
if (auto *OperatorArrayDelete = readDeclAs<FunctionDecl>()) {
|
||||
if (!C.dtorHasOperatorDelete(D, ASTContext::OperatorDeleteKind::Array))
|
||||
C.addOperatorDeleteForVDtor(D, OperatorArrayDelete,
|
||||
ASTContext::OperatorDeleteKind::Array);
|
||||
}
|
||||
if (auto *OperatorGlobArrayDelete = readDeclAs<FunctionDecl>()) {
|
||||
if (!C.dtorHasOperatorDelete(D,
|
||||
ASTContext::OperatorDeleteKind::ArrayGlobal))
|
||||
C.addOperatorDeleteForVDtor(D, OperatorGlobArrayDelete,
|
||||
ASTContext::OperatorDeleteKind::ArrayGlobal);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4852,22 +4866,48 @@ void ASTDeclReader::UpdateDecl(Decl *D) {
|
||||
case DeclUpdateKind::CXXResolvedDtorDelete: {
|
||||
// Set the 'operator delete' directly to avoid emitting another update
|
||||
// record.
|
||||
CXXDestructorDecl *Canon = cast<CXXDestructorDecl>(D->getCanonicalDecl());
|
||||
ASTContext &C = Reader.getContext();
|
||||
auto *Del = readDeclAs<FunctionDecl>();
|
||||
auto *First = cast<CXXDestructorDecl>(D->getCanonicalDecl());
|
||||
auto *ThisArg = Record.readExpr();
|
||||
auto *Dtor = cast<CXXDestructorDecl>(D);
|
||||
// FIXME: Check consistency if we have an old and new operator delete.
|
||||
if (!First->OperatorDelete) {
|
||||
First->OperatorDelete = Del;
|
||||
First->OperatorDeleteThisArg = ThisArg;
|
||||
if (!C.dtorHasOperatorDelete(Dtor,
|
||||
ASTContext::OperatorDeleteKind::Regular)) {
|
||||
C.addOperatorDeleteForVDtor(Dtor, Del,
|
||||
ASTContext::OperatorDeleteKind::Regular);
|
||||
Canon->OperatorDeleteThisArg = ThisArg;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case DeclUpdateKind::CXXResolvedDtorGlobDelete: {
|
||||
auto *Del = readDeclAs<FunctionDecl>();
|
||||
auto *Canon = cast<CXXDestructorDecl>(D->getCanonicalDecl());
|
||||
if (!Canon->OperatorGlobalDelete)
|
||||
Canon->OperatorGlobalDelete = Del;
|
||||
auto *Dtor = cast<CXXDestructorDecl>(D);
|
||||
ASTContext &C = Reader.getContext();
|
||||
if (!C.dtorHasOperatorDelete(
|
||||
Dtor, ASTContext::OperatorDeleteKind::GlobalRegular))
|
||||
C.addOperatorDeleteForVDtor(
|
||||
Dtor, Del, ASTContext::OperatorDeleteKind::GlobalRegular);
|
||||
break;
|
||||
}
|
||||
case DeclUpdateKind::CXXResolvedDtorArrayDelete: {
|
||||
auto *Del = readDeclAs<FunctionDecl>();
|
||||
auto *Dtor = cast<CXXDestructorDecl>(D);
|
||||
ASTContext &C = Reader.getContext();
|
||||
if (!C.dtorHasOperatorDelete(Dtor, ASTContext::OperatorDeleteKind::Array))
|
||||
C.addOperatorDeleteForVDtor(Dtor, Del,
|
||||
ASTContext::OperatorDeleteKind::Array);
|
||||
break;
|
||||
}
|
||||
case DeclUpdateKind::CXXResolvedDtorGlobArrayDelete: {
|
||||
auto *Del = readDeclAs<FunctionDecl>();
|
||||
auto *Dtor = cast<CXXDestructorDecl>(D);
|
||||
ASTContext &C = Reader.getContext();
|
||||
if (!C.dtorHasOperatorDelete(Dtor,
|
||||
ASTContext::OperatorDeleteKind::ArrayGlobal))
|
||||
C.addOperatorDeleteForVDtor(
|
||||
Dtor, Del, ASTContext::OperatorDeleteKind::ArrayGlobal);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@ -6540,6 +6540,14 @@ void ASTWriter::WriteDeclUpdatesBlocks(ASTContext &Context,
|
||||
Record.AddDeclRef(Update.getDecl());
|
||||
break;
|
||||
|
||||
case DeclUpdateKind::CXXResolvedDtorArrayDelete:
|
||||
Record.AddDeclRef(Update.getDecl());
|
||||
break;
|
||||
|
||||
case DeclUpdateKind::CXXResolvedDtorGlobArrayDelete:
|
||||
Record.AddDeclRef(Update.getDecl());
|
||||
break;
|
||||
|
||||
case DeclUpdateKind::CXXResolvedExceptionSpec: {
|
||||
auto prototype =
|
||||
cast<FunctionDecl>(D)->getType()->castAs<FunctionProtoType>();
|
||||
@ -7613,6 +7621,34 @@ void ASTWriter::ResolvedOperatorGlobDelete(const CXXDestructorDecl *DD,
|
||||
});
|
||||
}
|
||||
|
||||
void ASTWriter::ResolvedOperatorArrayDelete(const CXXDestructorDecl *DD,
|
||||
const FunctionDecl *ArrayDelete) {
|
||||
if (Chain && Chain->isProcessingUpdateRecords())
|
||||
return;
|
||||
assert(!WritingAST && "Already writing the AST!");
|
||||
assert(ArrayDelete && "Not given an operator delete");
|
||||
if (!Chain)
|
||||
return;
|
||||
Chain->forEachImportedKeyDecl(DD, [&](const Decl *D) {
|
||||
DeclUpdates[D].push_back(
|
||||
DeclUpdate(DeclUpdateKind::CXXResolvedDtorArrayDelete, ArrayDelete));
|
||||
});
|
||||
}
|
||||
|
||||
void ASTWriter::ResolvedOperatorGlobArrayDelete(
|
||||
const CXXDestructorDecl *DD, const FunctionDecl *GlobArrayDelete) {
|
||||
if (Chain && Chain->isProcessingUpdateRecords())
|
||||
return;
|
||||
assert(!WritingAST && "Already writing the AST!");
|
||||
assert(GlobArrayDelete && "Not given an operator delete");
|
||||
if (!Chain)
|
||||
return;
|
||||
Chain->forEachImportedKeyDecl(DD, [&](const Decl *D) {
|
||||
DeclUpdates[D].push_back(DeclUpdate(
|
||||
DeclUpdateKind::CXXResolvedDtorGlobArrayDelete, GlobArrayDelete));
|
||||
});
|
||||
}
|
||||
|
||||
void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) {
|
||||
if (Chain && Chain->isProcessingUpdateRecords()) return;
|
||||
assert(!WritingAST && "Already writing the AST!");
|
||||
|
||||
@ -1794,6 +1794,8 @@ void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
|
||||
if (D->getOperatorDelete())
|
||||
Record.AddStmt(D->getOperatorDeleteThisArg());
|
||||
Record.AddDeclRef(D->getOperatorGlobalDelete());
|
||||
Record.AddDeclRef(D->getArrayOperatorDelete());
|
||||
Record.AddDeclRef(D->getGlobalArrayOperatorDelete());
|
||||
|
||||
Code = serialization::DECL_CXX_DESTRUCTOR;
|
||||
}
|
||||
|
||||
@ -633,8 +633,9 @@ struct __declspec(dllexport) Y {
|
||||
};
|
||||
|
||||
struct __declspec(dllexport) Z { virtual ~Z() {} };
|
||||
// The scalar deleting dtor does not get exported:
|
||||
// M32-DAG: define linkonce_odr dso_local x86_thiscallcc ptr @"??_GZ@@UAEPAXI@Z"
|
||||
// The deleting dtor does not get exported, but we emit body of vector deleting
|
||||
// destructor:
|
||||
// M32-DAG: define weak dso_local x86_thiscallcc ptr @"??_EZ@@UAEPAXI@Z"
|
||||
|
||||
|
||||
// The user-defined dtor does get exported:
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
// own copy the vftable when emitting the available externally constructor.
|
||||
|
||||
// CHECK: @"??_7?$Foo@H@@6B@" = linkonce_odr unnamed_addr constant { [1 x ptr] } { [1 x ptr] [
|
||||
// CHECK-SAME: ptr @"??_G?$Foo@H@@UEAAPEAXI@Z"
|
||||
// CHECK-SAME: ptr @"??_E?$Foo@H@@UEAAPEAXI@Z"
|
||||
// CHECK-SAME: ] }, comdat
|
||||
|
||||
// CHECK-LABEL: define dso_local noundef ptr @"?f@@YAPEAU?$Foo@H@@XZ"()
|
||||
|
||||
@ -169,7 +169,7 @@ void foo() {
|
||||
// DTORS2-LABEL: define linkonce_odr dso_local x86_thiscallcc ptr @"??_EC@dtor_in_second_nvbase@@W3AEPAXI@Z"(ptr %this, i32 %should_call_delete)
|
||||
// Do an adjustment from B* to C*.
|
||||
// DTORS2: getelementptr i8, ptr %{{.*}}, i32 -4
|
||||
// DTORS2: %[[CALL:.*]] = tail call x86_thiscallcc ptr @"??_GC@dtor_in_second_nvbase@@UAEPAXI@Z"
|
||||
// DTORS2: %[[CALL:.*]] = tail call x86_thiscallcc ptr @"??_EC@dtor_in_second_nvbase@@UAEPAXI@Z"
|
||||
// DTORS2: ret ptr %[[CALL]]
|
||||
}
|
||||
|
||||
|
||||
@ -63,8 +63,7 @@ C::C() {} // Emits vftable and forces thunk generation.
|
||||
|
||||
// CODEGEN-LABEL: define linkonce_odr dso_local x86_thiscallcc noundef ptr @"??_EC@@W3AEPAXI@Z"(ptr noundef %this, i32 noundef %should_call_delete) {{.*}} comdat
|
||||
// CODEGEN: getelementptr i8, ptr {{.*}}, i32 -4
|
||||
// FIXME: should actually call _EC, not _GC.
|
||||
// CODEGEN: call x86_thiscallcc noundef ptr @"??_GC@@UAEPAXI@Z"
|
||||
// CODEGEN: call x86_thiscallcc noundef ptr @"??_EC@@UAEPAXI@Z"
|
||||
// CODEGEN: ret
|
||||
|
||||
// CODEGEN-LABEL: define linkonce_odr dso_local x86_thiscallcc void @"?public_f@C@@W3AEXXZ"(ptr
|
||||
|
||||
@ -8,38 +8,38 @@ struct S {
|
||||
virtual ~S();
|
||||
} s;
|
||||
|
||||
// RTTI-DAG: [[VTABLE_S:@.*]] = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4S@@6B@", ptr @"??_GS@@UAEPAXI@Z"] }, comdat($"??_7S@@6B@")
|
||||
// RTTI-DAG: [[VTABLE_S:@.*]] = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4S@@6B@", ptr @"??_ES@@UAEPAXI@Z"] }, comdat($"??_7S@@6B@")
|
||||
// RTTI-DAG: @"??_7S@@6B@" = unnamed_addr alias ptr, getelementptr inbounds ({ [2 x ptr] }, ptr [[VTABLE_S]], i32 0, i32 0, i32 1)
|
||||
|
||||
// NO-RTTI-DAG: @"??_7S@@6B@" = linkonce_odr unnamed_addr constant { [1 x ptr] } { [1 x ptr] [ptr @"??_GS@@UAEPAXI@Z"] }
|
||||
// NO-RTTI-DAG: @"??_7S@@6B@" = linkonce_odr unnamed_addr constant { [1 x ptr] } { [1 x ptr] [ptr @"??_ES@@UAEPAXI@Z"] }
|
||||
|
||||
struct __declspec(dllimport) U {
|
||||
virtual ~U();
|
||||
} u;
|
||||
|
||||
// RTTI-DAG: [[VTABLE_U:@.*]] = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4U@@6B@", ptr @"??_GU@@UAEPAXI@Z"] }
|
||||
// RTTI-DAG: [[VTABLE_U:@.*]] = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4U@@6B@", ptr @"??_EU@@UAEPAXI@Z"] }
|
||||
// RTTI-DAG: @"??_SU@@6B@" = unnamed_addr alias ptr, getelementptr inbounds ({ [2 x ptr] }, ptr [[VTABLE_U]], i32 0, i32 0, i32 1)
|
||||
|
||||
// NO-RTTI-DAG: @"??_SU@@6B@" = linkonce_odr unnamed_addr constant { [1 x ptr] } { [1 x ptr] [ptr @"??_GU@@UAEPAXI@Z"] }
|
||||
// NO-RTTI-DAG: @"??_SU@@6B@" = linkonce_odr unnamed_addr constant { [1 x ptr] } { [1 x ptr] [ptr @"??_EU@@UAEPAXI@Z"] }
|
||||
|
||||
struct __declspec(dllexport) V {
|
||||
virtual ~V();
|
||||
} v;
|
||||
|
||||
// RTTI-DAG: [[VTABLE_V:@.*]] = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4V@@6B@", ptr @"??_GV@@UAEPAXI@Z"] }, comdat($"??_7V@@6B@")
|
||||
// RTTI-DAG: [[VTABLE_V:@.*]] = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4V@@6B@", ptr @"??_EV@@UAEPAXI@Z"] }, comdat($"??_7V@@6B@")
|
||||
// RTTI-DAG: @"??_7V@@6B@" = dllexport unnamed_addr alias ptr, getelementptr inbounds ({ [2 x ptr] }, ptr [[VTABLE_V]], i32 0, i32 0, i32 1)
|
||||
|
||||
// NO-RTTI-DAG: @"??_7V@@6B@" = weak_odr dllexport unnamed_addr constant { [1 x ptr] } { [1 x ptr] [ptr @"??_GV@@UAEPAXI@Z"] }
|
||||
// NO-RTTI-DAG: @"??_7V@@6B@" = weak_odr dllexport unnamed_addr constant { [1 x ptr] } { [1 x ptr] [ptr @"??_EV@@UAEPAXI@Z"] }
|
||||
|
||||
namespace {
|
||||
struct W {
|
||||
virtual ~W() {}
|
||||
} w;
|
||||
}
|
||||
// RTTI-DAG: [[VTABLE_W:@.*]] = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4W@?A0x{{[^@]*}}@@6B@", ptr @"??_GW@?A0x{{[^@]*}}@@UAEPAXI@Z"] }
|
||||
// RTTI-DAG: [[VTABLE_W:@.*]] = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4W@?A0x{{[^@]*}}@@6B@", ptr @"??_EW@?A0x{{[^@]*}}@@UAEPAXI@Z"] }
|
||||
// RTTI-DAG: @"??_7W@?A0x{{[^@]*}}@@6B@" = internal unnamed_addr alias ptr, getelementptr inbounds ({ [2 x ptr] }, ptr [[VTABLE_W]], i32 0, i32 0, i32 1)
|
||||
|
||||
// NO-RTTI-DAG: @"??_7W@?A0x{{[^@]*}}@@6B@" = internal unnamed_addr constant { [1 x ptr] } { [1 x ptr] [ptr @"??_GW@?A0x{{[^@]*}}@@UAEPAXI@Z"] }
|
||||
// NO-RTTI-DAG: @"??_7W@?A0x{{[^@]*}}@@6B@" = internal unnamed_addr constant { [1 x ptr] } { [1 x ptr] [ptr @"??_EW@?A0x{{[^@]*}}@@UAEPAXI@Z"] }
|
||||
|
||||
struct X {};
|
||||
template <class> struct Y : virtual X {
|
||||
@ -49,7 +49,7 @@ template <class> struct Y : virtual X {
|
||||
|
||||
extern template class Y<int>;
|
||||
template Y<int>::Y();
|
||||
// RTTI-DAG: [[VTABLE_Y:@.*]] = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4?$Y@H@@6B@", ptr @"??_G?$Y@H@@UAEPAXI@Z"] }, comdat($"??_7?$Y@H@@6B@")
|
||||
// RTTI-DAG: [[VTABLE_Y:@.*]] = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4?$Y@H@@6B@", ptr @"??_E?$Y@H@@UAEPAXI@Z"] }, comdat($"??_7?$Y@H@@6B@")
|
||||
// RTTI-DAG: @"??_7?$Y@H@@6B@" = unnamed_addr alias ptr, getelementptr inbounds ({ [2 x ptr] }, ptr [[VTABLE_Y]], i32 0, i32 0, i32 1)
|
||||
|
||||
// NO-RTTI-DAG: @"??_7?$Y@H@@6B@" = linkonce_odr unnamed_addr constant { [1 x ptr] } { [1 x ptr] [ptr @"??_G?$Y@H@@UAEPAXI@Z"] }, comdat
|
||||
// NO-RTTI-DAG: @"??_7?$Y@H@@6B@" = linkonce_odr unnamed_addr constant { [1 x ptr] } { [1 x ptr] [ptr @"??_E?$Y@H@@UAEPAXI@Z"] }, comdat
|
||||
|
||||
@ -80,6 +80,15 @@ B::~B() {
|
||||
// CHECK2: call x86_thiscallcc void @"??1VBase@@UAE@XZ"(ptr {{[^,]*}} %[[VBASE_i8]])
|
||||
// CHECK2: ret
|
||||
|
||||
// CHECK2-LABEL: define linkonce_odr dso_local x86_thiscallcc noundef ptr @"??0B@test2@@QAE@XZ"
|
||||
// CHECK2: (ptr {{[^,]*}} returned align 4 dereferenceable(4) %this, i32 noundef %is_most_derived)
|
||||
// CHECK2: call x86_thiscallcc noundef ptr @"??0A@test2@@QAE@XZ"(ptr {{[^,]*}} %{{.*}})
|
||||
// CHECK2: ret
|
||||
|
||||
// CHECK2-LABEL: define linkonce_odr dso_local x86_thiscallcc noundef ptr @"??_GD@pr36921@@UAEPAXI@Z"(
|
||||
// CHECK2: %[[THIS_RELOAD:.*]] = load ptr, ptr
|
||||
// CHECK2: %[[THIS_ADJ_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS_RELOAD]], i32 -4
|
||||
|
||||
// CHECK2-LABEL: define linkonce_odr dso_local x86_thiscallcc noundef ptr @"??_GB@@UAEPAXI@Z"
|
||||
// CHECK2: store ptr %{{.*}}, ptr %[[THIS_ADDR:.*]], align 4
|
||||
// CHECK2: %[[THIS_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS_PARAM_i8:.*]], i32 -8
|
||||
@ -293,11 +302,6 @@ void callC() { C x; }
|
||||
// CHECK: call x86_thiscallcc noundef ptr @"??0A@test2@@QAE@XZ"(ptr {{[^,]*}} %{{.*}})
|
||||
// CHECK: ret
|
||||
|
||||
// CHECK2-LABEL: define linkonce_odr dso_local x86_thiscallcc noundef ptr @"??0B@test2@@QAE@XZ"
|
||||
// CHECK2: (ptr {{[^,]*}} returned align 4 dereferenceable(4) %this, i32 noundef %is_most_derived)
|
||||
// CHECK2: call x86_thiscallcc noundef ptr @"??0A@test2@@QAE@XZ"(ptr {{[^,]*}} %{{.*}})
|
||||
// CHECK2: ret
|
||||
|
||||
}
|
||||
|
||||
namespace test3 {
|
||||
@ -480,9 +484,6 @@ struct B {
|
||||
struct C : virtual B {};
|
||||
struct D : virtual A, C {};
|
||||
D d;
|
||||
// CHECK2-LABEL: define linkonce_odr dso_local x86_thiscallcc noundef ptr @"??_GD@pr36921@@UAEPAXI@Z"(
|
||||
// CHECK2: %[[THIS_RELOAD:.*]] = load ptr, ptr
|
||||
// CHECK2: %[[THIS_ADJ_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS_RELOAD]], i32 -4
|
||||
}
|
||||
|
||||
namespace issue_60465 {
|
||||
|
||||
@ -12,18 +12,18 @@ struct B {
|
||||
|
||||
struct C : A, B {
|
||||
// CHECK-LABEL: VFTable for 'A' in 'C' (2 entries).
|
||||
// CHECK-NEXT: 0 | C::~C() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | C::~C() [vector deleting]
|
||||
// CHECK-NEXT: 1 | void A::z1()
|
||||
|
||||
// CHECK-LABEL: VFTable for 'B' in 'C' (1 entry).
|
||||
// CHECK-NEXT: 0 | C::~C() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | C::~C() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: -4 non-virtual]
|
||||
|
||||
// CHECK-LABEL: Thunks for 'C::~C()' (1 entry).
|
||||
// CHECK-NEXT: 0 | [this adjustment: -4 non-virtual]
|
||||
|
||||
// CHECK-LABEL: VFTable indices for 'C' (1 entry).
|
||||
// CHECK-NEXT: 0 | C::~C() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | C::~C() [vector deleting]
|
||||
virtual ~C();
|
||||
};
|
||||
|
||||
@ -41,7 +41,7 @@ struct E : D, B {
|
||||
// CHECK-NEXT: 0 | void D::z4()
|
||||
|
||||
// CHECK-LABEL: VFTable for 'B' in 'E' (1 entry).
|
||||
// CHECK-NEXT: 0 | E::~E() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | E::~E() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: -4 non-virtual]
|
||||
|
||||
// CHECK-LABEL: Thunks for 'E::~E()' (1 entry).
|
||||
@ -49,7 +49,7 @@ struct E : D, B {
|
||||
|
||||
// CHECK-LABEL: VFTable indices for 'E' (1 entry).
|
||||
// CHECK-NEXT: -- accessible via vfptr at offset 4 --
|
||||
// CHECK-NEXT: 0 | E::~E() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | E::~E() [vector deleting]
|
||||
};
|
||||
|
||||
void build_vftable(E *obj) { delete obj; }
|
||||
@ -61,7 +61,7 @@ struct F : D, B {
|
||||
// CHECK-NEXT: 0 | void D::z4()
|
||||
|
||||
// CHECK-LABEL: VFTable for 'B' in 'F' (1 entry).
|
||||
// CHECK-NEXT: 0 | F::~F() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | F::~F() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: -4 non-virtual]
|
||||
|
||||
// CHECK-LABEL: Thunks for 'F::~F()' (1 entry).
|
||||
@ -69,7 +69,7 @@ struct F : D, B {
|
||||
|
||||
// CHECK-LABEL: VFTable indices for 'F' (1 entry).
|
||||
// CHECK-NEXT: -- accessible via vfptr at offset 4 --
|
||||
// CHECK-NEXT: 0 | F::~F() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | F::~F() [vector deleting]
|
||||
};
|
||||
|
||||
void build_vftable(F *obj) { delete obj; }
|
||||
@ -79,7 +79,7 @@ struct G : F {
|
||||
// CHECK-NEXT: 0 | void D::z4()
|
||||
|
||||
// CHECK-LABEL: VFTable for 'B' in 'F' in 'G' (1 entry).
|
||||
// CHECK-NEXT: 0 | G::~G() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | G::~G() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: -4 non-virtual]
|
||||
|
||||
// CHECK-LABEL: Thunks for 'G::~G()' (1 entry).
|
||||
@ -87,7 +87,7 @@ struct G : F {
|
||||
|
||||
// CHECK-LABEL: VFTable indices for 'G' (1 entry).
|
||||
// CHECK-NEXT: -- accessible via vfptr at offset 4 --
|
||||
// CHECK-NEXT: 0 | G::~G() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | G::~G() [vector deleting]
|
||||
virtual ~G();
|
||||
};
|
||||
|
||||
|
||||
@ -213,6 +213,6 @@ struct C : virtual B { C *f(); };
|
||||
C c;
|
||||
// VFTABLES-LABEL: VFTable indices for 'pr34302::C' (2 entries).
|
||||
// VFTABLES-NEXT: -- accessible via vbtable index 1, vfptr at offset 0 --
|
||||
// VFTABLES-NEXT: 0 | pr34302::C::~C() [scalar deleting]
|
||||
// VFTABLES-NEXT: 0 | pr34302::C::~C() [vector deleting]
|
||||
// VFTABLES-NEXT: 2 | C *pr34302::C::f()
|
||||
}
|
||||
|
||||
@ -44,10 +44,10 @@ void use(B *obj) { obj->f(); }
|
||||
|
||||
struct C {
|
||||
// CHECK-LABEL: VFTable for 'C' (2 entries)
|
||||
// CHECK-NEXT: 0 | C::~C() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | C::~C() [vector deleting]
|
||||
// CHECK-NEXT: 1 | void C::f()
|
||||
// CHECK-LABEL: VFTable indices for 'C' (2 entries).
|
||||
// CHECK-NEXT: 0 | C::~C() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | C::~C() [vector deleting]
|
||||
// CHECK-NEXT: 1 | void C::f()
|
||||
|
||||
virtual ~C();
|
||||
@ -60,10 +60,10 @@ void use(C *obj) { obj->f(); }
|
||||
struct D {
|
||||
// CHECK-LABEL: VFTable for 'D' (2 entries)
|
||||
// CHECK-NEXT: 0 | void D::f()
|
||||
// CHECK-NEXT: 1 | D::~D() [scalar deleting]
|
||||
// CHECK-NEXT: 1 | D::~D() [vector deleting]
|
||||
// CHECK-LABEL: VFTable indices for 'D' (2 entries)
|
||||
// CHECK-NEXT: 0 | void D::f()
|
||||
// CHECK-NEXT: 1 | D::~D() [scalar deleting]
|
||||
// CHECK-NEXT: 1 | D::~D() [vector deleting]
|
||||
|
||||
virtual void f();
|
||||
virtual ~D();
|
||||
@ -77,10 +77,10 @@ struct E : A {
|
||||
// CHECK-NEXT: 0 | void A::f()
|
||||
// CHECK-NEXT: 1 | void A::g()
|
||||
// CHECK-NEXT: 2 | void A::h()
|
||||
// CHECK-NEXT: 3 | E::~E() [scalar deleting]
|
||||
// CHECK-NEXT: 3 | E::~E() [vector deleting]
|
||||
// CHECK-NEXT: 4 | void E::i()
|
||||
// CHECK-LABEL: VFTable indices for 'E' (2 entries).
|
||||
// CHECK-NEXT: 3 | E::~E() [scalar deleting]
|
||||
// CHECK-NEXT: 3 | E::~E() [vector deleting]
|
||||
// CHECK-NEXT: 4 | void E::i()
|
||||
|
||||
// ~E would be the key method, but it isn't used, and MS ABI has no key
|
||||
@ -98,10 +98,10 @@ struct F : A {
|
||||
// CHECK-NEXT: 1 | void A::g()
|
||||
// CHECK-NEXT: 2 | void A::h()
|
||||
// CHECK-NEXT: 3 | void F::i()
|
||||
// CHECK-NEXT: 4 | F::~F() [scalar deleting]
|
||||
// CHECK-NEXT: 4 | F::~F() [vector deleting]
|
||||
// CHECK-LABEL: VFTable indices for 'F' (2 entries).
|
||||
// CHECK-NEXT: 3 | void F::i()
|
||||
// CHECK-NEXT: 4 | F::~F() [scalar deleting]
|
||||
// CHECK-NEXT: 4 | F::~F() [vector deleting]
|
||||
|
||||
virtual void i();
|
||||
virtual ~F();
|
||||
@ -115,12 +115,12 @@ struct G : E {
|
||||
// CHECK-NEXT: 0 | void G::f()
|
||||
// CHECK-NEXT: 1 | void A::g()
|
||||
// CHECK-NEXT: 2 | void A::h()
|
||||
// CHECK-NEXT: 3 | G::~G() [scalar deleting]
|
||||
// CHECK-NEXT: 3 | G::~G() [vector deleting]
|
||||
// CHECK-NEXT: 4 | void E::i()
|
||||
// CHECK-NEXT: 5 | void G::j()
|
||||
// CHECK-LABEL: VFTable indices for 'G' (3 entries).
|
||||
// CHECK-NEXT: 0 | void G::f()
|
||||
// CHECK-NEXT: 3 | G::~G() [scalar deleting]
|
||||
// CHECK-NEXT: 3 | G::~G() [vector deleting]
|
||||
// CHECK-NEXT: 5 | void G::j()
|
||||
|
||||
virtual void f(); // overrides A::f()
|
||||
|
||||
@ -57,7 +57,7 @@ struct A : virtual V1 {
|
||||
// CHECK-LABEL: VFTable for 'V1' in 'simple::A' (2 entries).
|
||||
// CHECK-NEXT: 0 | void simple::A::f()
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -4, 0 non-virtual]
|
||||
// CHECK-NEXT: 1 | simple::A::~A() [scalar deleting]
|
||||
// CHECK-NEXT: 1 | simple::A::~A() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -4, 0 non-virtual]
|
||||
|
||||
// CHECK-LABEL: Thunks for 'simple::A::~A()' (1 entry).
|
||||
@ -79,7 +79,7 @@ void use(A *obj) { obj->f(); }
|
||||
struct B : virtual V3 {
|
||||
// CHECK-LABEL: VFTable for 'Z' in 'V3' in 'simple::B' (2 entries).
|
||||
// CHECK-NEXT: 0 | void Z::g()
|
||||
// CHECK-NEXT: 1 | simple::B::~B() [scalar deleting]
|
||||
// CHECK-NEXT: 1 | simple::B::~B() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -4, 0 non-virtual]
|
||||
|
||||
// CHECK-LABEL: Thunks for 'simple::B::~B()' (1 entry).
|
||||
@ -88,7 +88,7 @@ struct B : virtual V3 {
|
||||
// CHECK-LABEL: VFTable for 'V2' in 'V3' in 'simple::B' (2 entries).
|
||||
// CHECK-NEXT: 0 | void simple::B::f()
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -12, 0 non-virtual]
|
||||
// CHECK-NEXT: 1 | simple::B::~B() [scalar deleting]
|
||||
// CHECK-NEXT: 1 | simple::B::~B() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -12, -8 non-virtual]
|
||||
|
||||
// CHECK-LABEL: Thunks for 'simple::B::~B()' (1 entry).
|
||||
@ -115,7 +115,7 @@ void use(B *obj) { obj->f(); }
|
||||
struct C : virtual V4 {
|
||||
// CHECK-LABEL: VFTable for 'Z' in 'V4' in 'simple::C' (2 entries).
|
||||
// CHECK-NEXT: 0 | void Z::g()
|
||||
// CHECK-NEXT: 1 | simple::C::~C() [scalar deleting]
|
||||
// CHECK-NEXT: 1 | simple::C::~C() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -4, 0 non-virtual]
|
||||
|
||||
// CHECK-LABEL: Thunks for 'simple::C::~C()' (1 entry).
|
||||
@ -124,7 +124,7 @@ struct C : virtual V4 {
|
||||
// CHECK-LABEL: VFTable for 'V1' in 'V4' in 'simple::C' (2 entries).
|
||||
// CHECK-NEXT: 0 | void simple::C::f()
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -12, 0 non-virtual]
|
||||
// CHECK-NEXT: 1 | simple::C::~C() [scalar deleting]
|
||||
// CHECK-NEXT: 1 | simple::C::~C() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -12, -8 non-virtual]
|
||||
|
||||
// CHECK-LABEL: Thunks for 'simple::C::~C()' (1 entry).
|
||||
@ -136,7 +136,7 @@ struct C : virtual V4 {
|
||||
// CHECK-LABEL: VFTable for 'V2' in 'V4' in 'simple::C' (2 entries).
|
||||
// CHECK-NEXT: 0 | void simple::C::f()
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -16, -4 non-virtual]
|
||||
// CHECK-NEXT: 1 | simple::C::~C() [scalar deleting]
|
||||
// CHECK-NEXT: 1 | simple::C::~C() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -16, -12 non-virtual]
|
||||
|
||||
// CHECK-LABEL: Thunks for 'simple::C::~C()' (1 entry).
|
||||
@ -162,7 +162,7 @@ class D : B {
|
||||
// CHECK-LABEL: VFTable for 'V2' in 'V3' in 'simple::B' in 'simple::D' (2 entries).
|
||||
// CHECK-NEXT: 0 | void simple::B::f()
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -12, -4 non-virtual]
|
||||
// CHECK-NEXT: 1 | simple::D::~D() [scalar deleting]
|
||||
// CHECK-NEXT: 1 | simple::D::~D() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -12, -8 non-virtual]
|
||||
D();
|
||||
int z;
|
||||
@ -180,12 +180,12 @@ struct F : virtual E {
|
||||
// CHECK-LABEL: VFTable for 'Z' in 'V3' in 'simple::E' in 'simple::F' (2 entries).
|
||||
// CHECK-NEXT: 0 | void simple::F::g()
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -4, 0 non-virtual]
|
||||
// CHECK-NEXT: 1 | simple::F::~F() [scalar deleting]
|
||||
// CHECK-NEXT: 1 | simple::F::~F() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -4, 0 non-virtual]
|
||||
|
||||
// CHECK-LABEL: VFTable for 'V2' in 'V3' in 'simple::E' in 'simple::F' (2 entries).
|
||||
// CHECK-NEXT: 0 | void simple::E::f()
|
||||
// CHECK-NEXT: 1 | simple::F::~F() [scalar deleting]
|
||||
// CHECK-NEXT: 1 | simple::F::~F() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -12, -8 non-virtual]
|
||||
|
||||
F();
|
||||
@ -202,12 +202,12 @@ struct G : F {
|
||||
// CHECK-LABEL: VFTable for 'Z' in 'V3' in 'simple::E' in 'simple::F' in 'simple::G' (2 entries).
|
||||
// CHECK-NEXT: 0 | void simple::F::g()
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -4, -4 non-virtual]
|
||||
// CHECK-NEXT: 1 | simple::G::~G() [scalar deleting]
|
||||
// CHECK-NEXT: 1 | simple::G::~G() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -4, 0 non-virtual]
|
||||
|
||||
// CHECK-LABEL: VFTable for 'V2' in 'V3' in 'simple::E' in 'simple::F' in 'simple::G' (2 entries).
|
||||
// CHECK-NEXT: 0 | void simple::E::f()
|
||||
// CHECK-NEXT: 1 | simple::G::~G() [scalar deleting]
|
||||
// CHECK-NEXT: 1 | simple::G::~G() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -12, -8 non-virtual]
|
||||
|
||||
G();
|
||||
@ -240,7 +240,7 @@ struct A : virtual simple::A {
|
||||
// CHECK-NEXT: 0 | void simple::A::f()
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -4, vbptr at 8 to the left,
|
||||
// CHECK-NEXT: vboffset at 8 in the vbtable, 8 non-virtual]
|
||||
// CHECK-NEXT: 1 | extended::A::~A() [scalar deleting]
|
||||
// CHECK-NEXT: 1 | extended::A::~A() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -4, 0 non-virtual]
|
||||
|
||||
// CHECK-LABEL: Thunks for 'void simple::A::f()' (1 entry).
|
||||
@ -265,7 +265,7 @@ struct B : virtual simple::A {
|
||||
|
||||
// CHECK-LABEL: VFTable for 'V1' in 'simple::A' in 'extended::B' (2 entries).
|
||||
// ...
|
||||
// CHECK: 1 | extended::B::~B() [scalar deleting]
|
||||
// CHECK: 1 | extended::B::~B() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -4, 0 non-virtual]
|
||||
|
||||
// CHECK-LABEL: Thunks for 'void simple::A::f()' (1 entry).
|
||||
@ -353,7 +353,7 @@ struct G : virtual simple::A {
|
||||
// CHECK-NEXT: 0 | void simple::A::f()
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -4, vbptr at 8 to the left,
|
||||
// CHECK-NEXT: vboffset at 8 in the vbtable, 8 non-virtual]
|
||||
// CHECK-NEXT: 1 | extended::G::~G() [scalar deleting]
|
||||
// CHECK-NEXT: 1 | extended::G::~G() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: vtordisp at -4, 0 non-virtual]
|
||||
|
||||
// CHECK-LABEL: Thunks for 'void simple::A::f()' (1 entry).
|
||||
@ -374,7 +374,7 @@ void use(G *obj) { obj->g(); }
|
||||
struct H : Z, A {
|
||||
// CHECK-LABEL: VFTable for 'Z' in 'extended::H' (2 entries).
|
||||
// CHECK-NEXT: 0 | void Z::g()
|
||||
// CHECK-NEXT: 1 | extended::H::~H() [scalar deleting]
|
||||
// CHECK-NEXT: 1 | extended::H::~H() [vector deleting]
|
||||
|
||||
// CHECK-LABEL: VFTable for 'V1' in 'simple::A' in 'extended::A' in 'extended::H' (2 entries).
|
||||
// CHECK-NEXT: 0 | void simple::A::f()
|
||||
|
||||
@ -492,7 +492,7 @@ struct X {
|
||||
|
||||
struct Y : virtual X {
|
||||
// CHECK-LABEL: VFTable for 'vdtors::X' in 'vdtors::Y' (2 entries).
|
||||
// CHECK-NEXT: 0 | vdtors::Y::~Y() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | vdtors::Y::~Y() [vector deleting]
|
||||
// CHECK-NEXT: 1 | void vdtors::X::zzz()
|
||||
|
||||
// CHECK-NOT: Thunks for 'vdtors::Y::~Y()'
|
||||
@ -515,7 +515,7 @@ struct U : virtual W {
|
||||
// CHECK-NEXT: 0 | void vdtors::Z::z()
|
||||
|
||||
// CHECK-LABEL: VFTable for 'vdtors::X' in 'vdtors::W' in 'vdtors::U' (2 entries).
|
||||
// CHECK-NEXT: 0 | vdtors::U::~U() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | vdtors::U::~U() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: -4 non-virtual]
|
||||
// CHECK-NEXT: 1 | void vdtors::X::zzz()
|
||||
|
||||
@ -524,7 +524,7 @@ struct U : virtual W {
|
||||
|
||||
// CHECK-LABEL: VFTable indices for 'vdtors::U' (1 entry).
|
||||
// CHECK-NEXT: -- accessible via vbtable index 1, vfptr at offset 4 --
|
||||
// CHECK-NEXT: 0 | vdtors::U::~U() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | vdtors::U::~U() [vector deleting]
|
||||
virtual ~U();
|
||||
};
|
||||
|
||||
@ -536,7 +536,7 @@ struct V : virtual W {
|
||||
// CHECK-NEXT: 0 | void vdtors::Z::z()
|
||||
|
||||
// CHECK-LABEL: VFTable for 'vdtors::X' in 'vdtors::W' in 'vdtors::V' (2 entries).
|
||||
// CHECK-NEXT: 0 | vdtors::V::~V() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | vdtors::V::~V() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: -4 non-virtual]
|
||||
// CHECK-NEXT: 1 | void vdtors::X::zzz()
|
||||
|
||||
@ -545,7 +545,7 @@ struct V : virtual W {
|
||||
|
||||
// CHECK-LABEL: VFTable indices for 'vdtors::V' (1 entry).
|
||||
// CHECK-NEXT: -- accessible via vbtable index 1, vfptr at offset 4 --
|
||||
// CHECK-NEXT: 0 | vdtors::V::~V() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | vdtors::V::~V() [vector deleting]
|
||||
};
|
||||
|
||||
V v;
|
||||
@ -557,7 +557,7 @@ struct T : virtual X {
|
||||
|
||||
struct P : T, Y {
|
||||
// CHECK-LABEL: VFTable for 'vdtors::X' in 'vdtors::T' in 'vdtors::P' (2 entries).
|
||||
// CHECK-NEXT: 0 | vdtors::P::~P() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | vdtors::P::~P() [vector deleting]
|
||||
// CHECK-NEXT: 1 | void vdtors::X::zzz()
|
||||
|
||||
// CHECK-NOT: Thunks for 'vdtors::P::~P()'
|
||||
@ -574,18 +574,18 @@ struct Q {
|
||||
// PR19172: Yet another diamond we miscompiled.
|
||||
struct R : virtual Q, X {
|
||||
// CHECK-LABEL: VFTable for 'vdtors::Q' in 'vdtors::R' (1 entry).
|
||||
// CHECK-NEXT: 0 | vdtors::R::~R() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | vdtors::R::~R() [vector deleting]
|
||||
// CHECK-NEXT: [this adjustment: -8 non-virtual]
|
||||
|
||||
// CHECK-LABEL: Thunks for 'vdtors::R::~R()' (1 entry).
|
||||
// CHECK-NEXT: 0 | [this adjustment: -8 non-virtual]
|
||||
|
||||
// CHECK-LABEL: VFTable for 'vdtors::X' in 'vdtors::R' (2 entries).
|
||||
// CHECK-NEXT: 0 | vdtors::R::~R() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | vdtors::R::~R() [vector deleting]
|
||||
// CHECK-NEXT: 1 | void vdtors::X::zzz()
|
||||
|
||||
// CHECK-LABEL: VFTable indices for 'vdtors::R' (1 entry).
|
||||
// CHECK-NEXT: 0 | vdtors::R::~R() [scalar deleting]
|
||||
// CHECK-NEXT: 0 | vdtors::R::~R() [vector deleting]
|
||||
virtual ~R();
|
||||
};
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
// vftable shouldn't have RTTI data in it.
|
||||
// CHECK-NOT: @"??_R4S@@6B@"
|
||||
// CHECK: @"??_7S@@6B@" = linkonce_odr unnamed_addr constant { [1 x ptr] } { [1 x ptr] [ptr @"??_GS@@UAEPAXI@Z"] }, comdat
|
||||
// CHECK: @"??_7S@@6B@" = linkonce_odr unnamed_addr constant { [1 x ptr] } { [1 x ptr] [ptr @"??_ES@@UAEPAXI@Z"] }, comdat
|
||||
|
||||
struct type_info;
|
||||
namespace std { using ::type_info; }
|
||||
|
||||
336
clang/test/CodeGenCXX/microsoft-vector-deleting-dtors.cpp
Normal file
336
clang/test/CodeGenCXX/microsoft-vector-deleting-dtors.cpp
Normal file
@ -0,0 +1,336 @@
|
||||
// RUN: %clang_cc1 -emit-llvm -fms-extensions %s -triple=x86_64-pc-windows-msvc -o - | FileCheck --check-prefixes=X64,CHECK %s
|
||||
// RUN: %clang_cc1 -emit-llvm -fms-extensions %s -triple=i386-pc-windows-msvc -o - | FileCheck --check-prefixes=X86,CHECK %s
|
||||
// RUN: %clang_cc1 -emit-llvm -fms-extensions %s -triple=x86_64-pc-windows-msvc -fclang-abi-compat=21 -o - | FileCheck --check-prefixes=CLANG21 %s
|
||||
|
||||
struct Bird {
|
||||
virtual ~Bird();
|
||||
};
|
||||
|
||||
struct Parrot : public Bird {
|
||||
// X64: @[[ParrotVtable:[0-9]+]] = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4Parrot@@6B@", ptr @"??_EParrot@@UEAAPEAXI@Z"] }, comdat($"??_7Parrot@@6B@")
|
||||
// X86: @[[ParrotVtable:[0-9]+]] = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4Parrot@@6B@", ptr @"??_EParrot@@UAEPAXI@Z"] }, comdat($"??_7Parrot@@6B@")
|
||||
// CLANG21: @[[ParrotVtable:[0-9]+]] = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4Parrot@@6B@", ptr @"??_GParrot@@UEAAPEAXI@Z"] }, comdat($"??_7Parrot@@6B@")
|
||||
// X64: @[[Bird:[0-9]+]] = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4Bird@@6B@", ptr @"??_EBird@@UEAAPEAXI@Z"] }, comdat($"??_7Bird@@6B@")
|
||||
// X86: @[[Bird:[0-9]+]] = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4Bird@@6B@", ptr @"??_EBird@@UAEPAXI@Z"] }, comdat($"??_7Bird@@6B@")
|
||||
// CLANG21: @[[Bird:[0-9]+]] = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4Bird@@6B@", ptr @"??_GBird@@UEAAPEAXI@Z"] }, comdat($"??_7Bird@@6B@")
|
||||
virtual ~Parrot() {}
|
||||
};
|
||||
|
||||
Bird::~Bird() {}
|
||||
|
||||
// For the weird bird we first emit scalar deleting destructor, then find out
|
||||
// that we need vector deleting destructor and remove the alias.
|
||||
struct JustAWeirdBird {
|
||||
virtual ~JustAWeirdBird() {}
|
||||
|
||||
bool doSmth(int n) {
|
||||
JustAWeirdBird *c = new JustAWeirdBird[n];
|
||||
|
||||
delete[] c;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
int i = 0;
|
||||
struct HasOperatorDelete : public Bird{
|
||||
~HasOperatorDelete() { }
|
||||
void operator delete(void *p) { i-=2; }
|
||||
void operator delete[](void *p) { i--; }
|
||||
};
|
||||
|
||||
struct AllocatedAsArray : public Bird {
|
||||
|
||||
};
|
||||
|
||||
// Vector deleting dtor for Bird is an alias because no new Bird[] expressions
|
||||
// in the TU.
|
||||
// X64: @"??_EBird@@UEAAPEAXI@Z" = weak dso_local unnamed_addr alias ptr (ptr, i32), ptr @"??_GBird@@UEAAPEAXI@Z"
|
||||
// X86: @"??_EBird@@UAEPAXI@Z" = weak dso_local unnamed_addr alias ptr (ptr, i32), ptr @"??_GBird@@UAEPAXI@Z"
|
||||
// No scalar destructor for Parrot.
|
||||
// CHECK-NOT: @"??_GParrot"
|
||||
// No vector destructor definition for Bird.
|
||||
// CHECK-NOT: define{{.*}}@"??_EBird"
|
||||
// No scalar deleting dtor for JustAWeirdBird.
|
||||
// CHECK-NOT: @"??_GJustAWeirdBird"
|
||||
// CLANG21-NOT: @"??_E
|
||||
|
||||
void dealloc(Bird *p) {
|
||||
delete[] p;
|
||||
}
|
||||
|
||||
Bird* alloc() {
|
||||
Parrot* P = new Parrot[38];
|
||||
return P;
|
||||
}
|
||||
|
||||
|
||||
template<class C>
|
||||
struct S {
|
||||
void foo() { void *p = new C(); delete (C *)p; }
|
||||
};
|
||||
|
||||
S<AllocatedAsArray[1][3]> sp;
|
||||
|
||||
void bar() {
|
||||
dealloc(alloc());
|
||||
|
||||
JustAWeirdBird B;
|
||||
B.doSmth(38);
|
||||
|
||||
Bird *p = new HasOperatorDelete[2];
|
||||
dealloc(p);
|
||||
|
||||
sp.foo();
|
||||
}
|
||||
|
||||
// CHECK-LABEL: define dso_local void @{{.*}}dealloc{{.*}}(
|
||||
// CHECK-SAME: ptr noundef %[[PTR:.*]])
|
||||
// CHECK: entry:
|
||||
// CHECK-NEXT: %[[PTRADDR:.*]] = alloca ptr
|
||||
// CHECK-NEXT: store ptr %[[PTR]], ptr %[[PTRADDR]]
|
||||
// CHECK-NEXT: %[[LPTR:.*]] = load ptr, ptr %[[PTRADDR]]
|
||||
// CHECK-NEXT: %[[ISNULL:.*]] = icmp eq ptr %[[LPTR]], null
|
||||
// CHECK-NEXT: br i1 %[[ISNULL]], label %delete.end, label %delete.notnull
|
||||
// CHECK: delete.notnull:
|
||||
// X64-NEXT: %[[COOKIEGEP:.*]] = getelementptr inbounds i8, ptr %[[LPTR]], i64 -8
|
||||
// X86-NEXT: %[[COOKIEGEP:.*]] = getelementptr inbounds i8, ptr %[[LPTR]], i32 -4
|
||||
// X64-NEXT: %[[HOWMANY:.*]] = load i64, ptr %[[COOKIEGEP]]
|
||||
// X86-NEXT: %[[HOWMANY:.*]] = load i32, ptr %[[COOKIEGEP]]
|
||||
// X64-NEXT: %[[ISNOELEM:.*]] = icmp eq i64 %2, 0
|
||||
// X86-NEXT: %[[ISNOELEM:.*]] = icmp eq i32 %2, 0
|
||||
// CHECK-NEXT: br i1 %[[ISNOELEM]], label %vdtor.nocall, label %vdtor.call
|
||||
// CHECK: vdtor.nocall:
|
||||
// X64-NEXT: %[[HOWMANYBYTES:.*]] = mul i64 8, %[[HOWMANY]]
|
||||
// X86-NEXT: %[[HOWMANYBYTES:.*]] = mul i32 4, %[[HOWMANY]]
|
||||
// X64-NEXT: %[[ADDCOOKIESIZE:.*]] = add i64 %[[HOWMANYBYTES]], 8
|
||||
// X86-NEXT: %[[ADDCOOKIESIZE:.*]] = add i32 %[[HOWMANYBYTES]], 4
|
||||
// X64-NEXT: call void @"??_V@YAXPEAX_K@Z"(ptr noundef %[[COOKIEGEP]], i64 noundef %[[ADDCOOKIESIZE]])
|
||||
// X86-NEXT: call void @"??_V@YAXPAXI@Z"(ptr noundef %[[COOKIEGEP]], i32 noundef %[[ADDCOOKIESIZE]])
|
||||
// CHECK-NEXT: br label %delete.end
|
||||
// CHECK: vdtor.call:
|
||||
// CHECK-NEXT: %[[VTABLE:.*]] = load ptr, ptr %[[LPTR]]
|
||||
// CHECK-NEXT: %[[FPGEP:.*]] = getelementptr inbounds ptr, ptr %[[VTABLE]], i64 0
|
||||
// CHECK-NEXT: %[[FPLOAD:.*]] = load ptr, ptr %[[FPGEP]]
|
||||
// X64-NEXT: %[[CALL:.*]] = call noundef ptr %[[FPLOAD]](ptr noundef nonnull align 8 dereferenceable(8) %[[LPTR]], i32 noundef 3)
|
||||
// X86-NEXT: %[[CALL:.*]] = call x86_thiscallcc noundef ptr %[[FPLOAD]](ptr noundef nonnull align 4 dereferenceable(4) %[[LPTR]], i32 noundef 3)
|
||||
// CHECK-NEXT: br label %delete.end
|
||||
// CHECK: delete.end:
|
||||
// CHECK-NEXT: ret void
|
||||
|
||||
// Normal loop over the array elements for clang21 ABI
|
||||
// CLANG21-LABEL: define dso_local void @"?dealloc@@YAXPEAUBird@@@Z"
|
||||
// CLANG21: %p.addr = alloca ptr
|
||||
// CLANG21-NEXT: store ptr %p, ptr %p.addr
|
||||
// CLANG21-NEXT: %0 = load ptr, ptr %p.addr
|
||||
// CLANG21-NEXT: %isnull = icmp eq ptr %0, null
|
||||
// CLANG21-NEXT: br i1 %isnull, label %delete.end2, label %delete.notnull
|
||||
// CLANG21: delete.notnull:
|
||||
// CLANG21-NEXT: %1 = getelementptr inbounds i8, ptr %0, i64 -8
|
||||
// CLANG21-NEXT: %2 = load i64, ptr %1
|
||||
// CLANG21-NEXT: %delete.end = getelementptr inbounds %struct.Bird, ptr %0, i64 %2
|
||||
// CLANG21-NEXT: %arraydestroy.isempty = icmp eq ptr %0, %delete.end
|
||||
// CLANG21-NEXT: br i1 %arraydestroy.isempty, label %arraydestroy.done1, label %arraydestroy.body
|
||||
// CLANG21: arraydestroy.body:
|
||||
// CLANG21-NEXT: %arraydestroy.elementPast = phi ptr [ %delete.end, %delete.notnull ], [ %arraydestroy.element, %arraydestroy.body ]
|
||||
// CLANG21-NEXT: %arraydestroy.element = getelementptr inbounds %struct.Bird, ptr %arraydestroy.elementPast, i64 -1
|
||||
// CLANG21-NEXT: call void @"??1Bird@@UEAA@XZ"(ptr noundef nonnull align 8 dereferenceable(8) %arraydestroy.element)
|
||||
// CLANG21-NEXT: %arraydestroy.done = icmp eq ptr %arraydestroy.element, %0
|
||||
// CLANG21-NEXT: br i1 %arraydestroy.done, label %arraydestroy.done1, label %arraydestroy.body
|
||||
// CLANG21: arraydestroy.done1:
|
||||
// CLANG21-NEXT: %3 = mul i64 8, %2
|
||||
// CLANG21-NEXT: %4 = add i64 %3, 8
|
||||
// CLANG21-NEXT: call void @"??_V@YAXPEAX_K@Z"(ptr noundef %1, i64 noundef %4)
|
||||
// CLANG21-NEXT: br label %delete.end2
|
||||
|
||||
// Definition of S::foo, check that it has vector deleting destructor call
|
||||
// X64-LABEL: define linkonce_odr dso_local void @"?foo@?$S@$$BY102UAllocatedAsArray@@@@QEAAXXZ"
|
||||
// X86-LABEL: define linkonce_odr dso_local x86_thiscallcc void @"?foo@?$S@$$BY102UAllocatedAsArray@@@@QAEXXZ"
|
||||
// X64: %[[NEWCALL:.*]] = call noalias noundef nonnull ptr @"??_U@YAPEAX_K@Z"(i64 noundef 32)
|
||||
// X86: %[[NEWCALL:.*]] = call noalias noundef nonnull ptr @"??_U@YAPAXI@Z"(i32 noundef 16)
|
||||
// X64: %[[ARR:.*]] = getelementptr inbounds i8, ptr %[[NEWCALL]], i64 8
|
||||
// X86: %[[ARR:.*]] = getelementptr inbounds i8, ptr %[[NEWCALL]], i32 4
|
||||
// CHECK: store ptr %[[ARR]], ptr %[[DP:.*]]
|
||||
// CHECK: %[[DEL_PTR:.*]] = load ptr, ptr %[[DP:.*]]
|
||||
// CHECK: delete.notnull:
|
||||
// X64-NEXT: %[[COOKIEGEP:.*]] = getelementptr inbounds i8, ptr %[[DEL_PTR]], i64 -8
|
||||
// X86-NEXT: %[[COOKIEGEP:.*]] = getelementptr inbounds i8, ptr %[[DEL_PTR]], i32 -4
|
||||
// X64-NEXT: %[[HOWMANY:.*]] = load i64, ptr %[[COOKIEGEP]]
|
||||
// X86-NEXT: %[[HOWMANY:.*]] = load i32, ptr %[[COOKIEGEP]]
|
||||
// X64-NEXT: %[[ISNOELEM:.*]] = icmp eq i64 %[[HOWMANY]], 0
|
||||
// X86-NEXT: %[[ISNOELEM:.*]] = icmp eq i32 %[[HOWMANY]], 0
|
||||
// CHECK-NEXT: br i1 %[[ISNOELEM]], label %vdtor.nocall, label %vdtor.call
|
||||
// CHECK: vdtor.nocall: ; preds = %delete.notnull
|
||||
// X64-NEXT: %[[HOWMANYBYTES:.*]] = mul i64 8, %[[HOWMANY]]
|
||||
// X86-NEXT: %[[HOWMANYBYTES:.*]] = mul i32 4, %[[HOWMANY]]
|
||||
// X64-NEXT: %[[ADDCOOKIESIZE:.*]] = add i64 %[[HOWMANYBYTES]], 8
|
||||
// X86-NEXT: %[[ADDCOOKIESIZE:.*]] = add i32 %[[HOWMANYBYTES]], 4
|
||||
// X64-NEXT: call void @"??_V@YAXPEAX_K@Z"(ptr noundef %[[COOKIEGEP]], i64 noundef %[[ADDCOOKIESIZE]])
|
||||
// X86-NEXT: call void @"??_V@YAXPAXI@Z"(ptr noundef %[[COOKIEGEP]], i32 noundef %[[ADDCOOKIESIZE]])
|
||||
// CHECK-NEXT: br label %delete.end
|
||||
// CHECK: vdtor.call: ; preds = %delete.notnull
|
||||
// CHECK-NEXT: %[[VTABLE:.*]] = load ptr, ptr %[[DEL_PTR]]
|
||||
// CHECK-NEXT: %[[FPGEP:.*]] = getelementptr inbounds ptr, ptr %[[VTABLE]], i64 0
|
||||
// CHECK-NEXT: %[[FPLOAD:.*]] = load ptr, ptr %[[FPGEP]]
|
||||
// X64-NEXT: %[[CALL:.*]] = call noundef ptr %[[FPLOAD]](ptr noundef nonnull align 8 dereferenceable(8) %[[DEL_PTR]], i32 noundef 3)
|
||||
// X86-NEXT: %[[CALL:.*]] = call x86_thiscallcc noundef ptr %[[FPLOAD]](ptr noundef nonnull align 4 dereferenceable(4) %[[DEL_PTR]], i32 noundef 3)
|
||||
// CHECK-NEXT: br label %delete.end
|
||||
// CHECK: delete.end:
|
||||
// CHECK-NEXT: ret void
|
||||
|
||||
// Vector dtor definition for Parrot.
|
||||
// X64-LABEL: define weak dso_local noundef ptr @"??_EParrot@@UEAAPEAXI@Z"(
|
||||
// X64-SAME: ptr {{.*}} %[[THIS:.*]], i32 {{.*}} %[[IMPLICIT_PARAM:.*]]) unnamed_addr
|
||||
// X86-LABEL: define weak dso_local x86_thiscallcc noundef ptr @"??_EParrot@@UAEPAXI@Z"(
|
||||
// X86-SAME: ptr noundef nonnull align 4 dereferenceable(4) %[[THIS:.*]], i32 noundef %[[IMPLICIT_PARAM:.*]]) unnamed_addr
|
||||
// CHECK: entry:
|
||||
// CHECK-NEXT: %[[RET:.*]] = alloca ptr
|
||||
// CHECK-NEXT: %[[IPADDR:.*]] = alloca i32
|
||||
// CHECK-NEXT: %[[THISADDR:.*]] = alloca ptr
|
||||
// CHECK-NEXT: store i32 %[[IMPLICIT_PARAM]], ptr %[[IPADDR]]
|
||||
// CHECK-NEXT: store ptr %[[THIS]], ptr %[[THISADDR]]
|
||||
// CHECK-NEXT: %[[LTHIS:.*]] = load ptr, ptr %[[THISADDR]]
|
||||
// CHECK-NEXT: store ptr %[[LTHIS]], ptr %[[RET]]
|
||||
// CHECK-NEXT: %[[LIP:.*]] = load i32, ptr %[[IPADDR]]
|
||||
// CHECK-NEXT: %[[SECONDBIT:.*]] = and i32 %[[LIP]], 2
|
||||
// CHECK-NEXT: %[[ISSECONDBITZERO:.*]] = icmp eq i32 %[[SECONDBIT]], 0
|
||||
// CHECK-NEXT: br i1 %[[ISSECONDBITZERO:.*]], label %dtor.scalar, label %dtor.vector
|
||||
// CHECK: dtor.vector:
|
||||
// X64-NEXT: %[[COOKIEGEP:.*]] = getelementptr inbounds i8, ptr %[[LTHIS]], i64 -8
|
||||
// X86-NEXT: %[[COOKIEGEP:.*]] = getelementptr inbounds i8, ptr %[[LTHIS]], i32 -4
|
||||
// X64-NEXT: %[[HOWMANY:.*]] = load i64, ptr %[[COOKIEGEP]]
|
||||
// X86-NEXT: %[[HOWMANY:.*]] = load i32, ptr %[[COOKIEGEP]]
|
||||
// X64-NEXT: %[[END:.*]] = getelementptr inbounds %struct.Parrot, ptr %[[LTHIS]], i64 %[[HOWMANY]]
|
||||
// X86-NEXT: %[[END:.*]] = getelementptr inbounds %struct.Parrot, ptr %[[LTHIS]], i32 %[[HOWMANY]]
|
||||
// CHECK-NEXT: br label %arraydestroy.body
|
||||
// CHECK: arraydestroy.body:
|
||||
// CHECK-NEXT: %[[PASTELEM:.*]] = phi ptr [ %delete.end, %dtor.vector ], [ %arraydestroy.element, %arraydestroy.body ]
|
||||
// X64-NEXT: %[[CURELEM:.*]] = getelementptr inbounds %struct.Parrot, ptr %[[PASTELEM]], i64 -1
|
||||
// X86-NEXT: %[[CURELEM:.*]] = getelementptr inbounds %struct.Parrot, ptr %[[PASTELEM]], i32 -1
|
||||
// X64-NEXT: call void @"??1Parrot@@UEAA@XZ"(ptr noundef nonnull align 8 dereferenceable(8) %[[CURELEM]])
|
||||
// X86-NEXT: call x86_thiscallcc void @"??1Parrot@@UAE@XZ"(ptr noundef nonnull align 4 dereferenceable(4) %[[CURELEM]])
|
||||
// CHECK-NEXT: %[[DONE:.*]] = icmp eq ptr %[[CURELEM]], %[[LTHIS]]
|
||||
// CHECK-NEXT: br i1 %[[DONE]], label %arraydestroy.done3, label %arraydestroy.body
|
||||
// CHECK: arraydestroy.done3:
|
||||
// CHECK-NEXT: br label %dtor.vector.cont
|
||||
// CHECK: dtor.vector.cont:
|
||||
// CHECK-NEXT: %[[FIRSTBIT:.*]] = and i32 %[[LIP]], 1
|
||||
// CHECK-NEXT: %[[ISFIRSTBITZERO:.*]] = icmp eq i32 %[[FIRSTBIT]], 0
|
||||
// CHECK-NEXT: br i1 %[[ISFIRSTBITZERO]], label %dtor.continue, label %dtor.call_delete_after_array_destroy
|
||||
// CHECK: dtor.call_delete_after_array_destroy:
|
||||
// X64-NEXT: call void @"??_V@YAXPEAX_K@Z"(ptr noundef %[[COOKIEGEP]], i64 noundef 8)
|
||||
// X86-NEXT: call void @"??_V@YAXPAXI@Z"(ptr noundef %[[COOKIEGEP]], i32 noundef 4)
|
||||
// CHECK-NEXT: br label %dtor.continue
|
||||
// CHECK: dtor.scalar:
|
||||
// X64-NEXT: call void @"??1Parrot@@UEAA@XZ"(ptr noundef nonnull align 8 dereferenceable(8) %[[LTHIS]])
|
||||
// X86-NEXT: call x86_thiscallcc void @"??1Parrot@@UAE@XZ"(ptr noundef nonnull align 4 dereferenceable(4) %[[LTHIS]])
|
||||
// CHECK-NEXT: %[[FIRSTBIT:.*]] = and i32 %[[LIP]], 1
|
||||
// CHECK-NEXT: %[[ISFIRSTBITZERO:.*]] = icmp eq i32 %[[FIRSTBIT]], 0
|
||||
// CHECK-NEXT: br i1 %[[ISFIRSTBITZERO]], label %dtor.continue, label %dtor.call_delete
|
||||
// CHECK: dtor.call_delete:
|
||||
// X64-NEXT: call void @"??3@YAXPEAX_K@Z"(ptr noundef %[[LTHIS]], i64 noundef 8)
|
||||
// X86-NEXT: call void @"??3@YAXPAXI@Z"(ptr noundef %[[LTHIS]], i32 noundef 4)
|
||||
// CHECK-NEXT: br label %dtor.continue
|
||||
// CHECK: dtor.continue:
|
||||
// CHECK-NEXT: %[[LOADRET:.*]] = load ptr, ptr %[[RET]]
|
||||
// CHECK-NEXT: ret ptr %[[LOADRET]]
|
||||
|
||||
// X64: define weak dso_local noundef ptr @"??_EJustAWeirdBird@@UEAAPEAXI@Z"(
|
||||
// X64-SAME: ptr noundef nonnull align 8 dereferenceable(8) %this, i32 noundef %should_call_delete)
|
||||
// CLANG21: define linkonce_odr dso_local noundef ptr @"??_GJustAWeirdBird@@UEAAPEAXI@Z"(
|
||||
// X86: define weak dso_local x86_thiscallcc noundef ptr @"??_EJustAWeirdBird@@UAEPAXI@Z"(
|
||||
// X86-SAME: ptr noundef nonnull align 4 dereferenceable(4) %this, i32 noundef %should_call_delete) unnamed_addr
|
||||
|
||||
// X64-LABEL: define weak dso_local noundef ptr @"??_EHasOperatorDelete@@UEAAPEAXI@Z"
|
||||
// X86-LABEL: define weak dso_local x86_thiscallcc noundef ptr @"??_EHasOperatorDelete@@UAEPAXI@Z"
|
||||
// CLANG21: define linkonce_odr dso_local noundef ptr @"??_GHasOperatorDelete@@UEAAPEAXI@Z"
|
||||
// CHECK: dtor.call_delete_after_array_destroy:
|
||||
// CHECK-NEXT: %[[SHOULD_CALL_GLOB_DELETE:.*]] = and i32 %should_call_delete2, 4
|
||||
// CHECK-NEXT: %[[CHK:.*]] = icmp eq i32 %[[SHOULD_CALL_GLOB_DELETE]], 0
|
||||
// CHECK-NEXT: br i1 %[[CHK]], label %dtor.call_class_delete_after_array_destroy, label %dtor.call_glob_delete_after_array_destroy
|
||||
// CHECK: dtor.call_class_delete_after_array_destroy:
|
||||
// X64-NEXT: call void @"??_VHasOperatorDelete@@SAXPEAX@Z"(ptr noundef %2)
|
||||
// X86-NEXT: call void @"??_VHasOperatorDelete@@SAXPAX@Z"
|
||||
// CHECK-NEXT: br label %dtor.continue
|
||||
// CHECK: dtor.call_glob_delete_after_array_destroy:
|
||||
// X64-NEXT: call void @"??_V@YAXPEAX_K@Z"(ptr noundef %2, i64 noundef 8)
|
||||
// X86-NEXT: call void @"??_V@YAXPAXI@Z"(ptr noundef %2, i32 noundef 4)
|
||||
// CHECK-NEXT: br label %dtor.continue
|
||||
|
||||
|
||||
|
||||
struct BaseDelete1 {
|
||||
void operator delete[](void *);
|
||||
};
|
||||
struct BaseDelete2 {
|
||||
void operator delete[](void *);
|
||||
};
|
||||
struct BaseDestructor {
|
||||
BaseDestructor() {}
|
||||
virtual ~BaseDestructor() = default;
|
||||
};
|
||||
|
||||
struct Derived : BaseDelete1, BaseDelete2, BaseDestructor {
|
||||
Derived() {}
|
||||
};
|
||||
|
||||
void foobartest() {
|
||||
Derived *a = new Derived[10]();
|
||||
::delete[] a;
|
||||
}
|
||||
|
||||
// X64-LABEL: define weak dso_local noundef ptr @"??_EDerived@@UEAAPEAXI@Z"(ptr {{.*}} %this, i32 noundef %should_call_delete)
|
||||
// X86-LABEL: define weak dso_local x86_thiscallcc noundef ptr @"??_EDerived@@UAEPAXI@Z"(ptr {{.*}} %this, i32 noundef %should_call_delete)
|
||||
// CHECK: %retval = alloca ptr
|
||||
// CHECK-NEXT: %should_call_delete.addr = alloca i32, align 4
|
||||
// CHECK-NEXT: %this.addr = alloca ptr
|
||||
// CHECK-NEXT: store i32 %should_call_delete, ptr %should_call_delete.addr, align 4
|
||||
// CHECK-NEXT: store ptr %this, ptr %this.addr
|
||||
// CHECK-NEXT: %this1 = load ptr, ptr %this.addr
|
||||
// CHECK-NEXT: store ptr %this1, ptr %retval
|
||||
// CHECK-NEXT: %should_call_delete2 = load i32, ptr %should_call_delete.addr, align 4
|
||||
// CHECK-NEXT: %0 = and i32 %should_call_delete2, 2
|
||||
// CHECK-NEXT: %1 = icmp eq i32 %0, 0
|
||||
// CHECK-NEXT: br i1 %1, label %dtor.scalar, label %dtor.vector
|
||||
// CHECK: dtor.vector:
|
||||
// X64-NEXT: %2 = getelementptr inbounds i8, ptr %this1, i64 -8
|
||||
// X86-NEXT: %2 = getelementptr inbounds i8, ptr %this1, i32 -4
|
||||
// X64-NEXT: %3 = load i64, ptr %2
|
||||
// X86-NEXT: %3 = load i32, ptr %2
|
||||
// X64-NEXT: %delete.end = getelementptr inbounds %struct.Derived, ptr %this1, i64 %3
|
||||
// X86-NEXT: %delete.end = getelementptr inbounds %struct.Derived, ptr %this1, i32 %3
|
||||
// CHECK-NEXT: br label %arraydestroy.body
|
||||
// CHECK: arraydestroy.body:
|
||||
// CHECK-NEXT: %arraydestroy.elementPast = phi ptr [ %delete.end, %dtor.vector ], [ %arraydestroy.element, %arraydestroy.body ]
|
||||
// X64-NEXT: %arraydestroy.element = getelementptr inbounds %struct.Derived, ptr %arraydestroy.elementPast, i64 -1
|
||||
// X86-NEXT: %arraydestroy.element = getelementptr inbounds %struct.Derived, ptr %arraydestroy.elementPast, i32 -1
|
||||
// X64-NEXT: call void @"??1Derived@@UEAA@XZ"(ptr noundef nonnull align 8 dereferenceable(16) %arraydestroy.element)
|
||||
// X86-NEXT: call x86_thiscallcc void @"??1Derived@@UAE@XZ"(ptr noundef nonnull align 4 dereferenceable(8) %arraydestroy.element)
|
||||
// CHECK-NEXT: %arraydestroy.done = icmp eq ptr %arraydestroy.element, %this1
|
||||
// CHECK-NEXT: br i1 %arraydestroy.done, label %arraydestroy.done3, label %arraydestroy.body
|
||||
// CHECK: arraydestroy.done3:
|
||||
// CHECK-NEXT: br label %dtor.vector.cont
|
||||
// CHECK: dtor.vector.cont:
|
||||
// CHECK-NEXT: %4 = and i32 %should_call_delete2, 1
|
||||
// CHECK-NEXT: %5 = icmp eq i32 %4, 0
|
||||
// CHECK-NEXT: br i1 %5, label %dtor.continue, label %dtor.call_delete_after_array_destroy
|
||||
// CHECK: dtor.call_delete_after_array_destroy:
|
||||
// X64-NEXT: call void @"??_V@YAXPEAX_K@Z"(ptr noundef %2, i64 noundef 16)
|
||||
// X86-NEXT: call void @"??_V@YAXPAXI@Z"(ptr noundef %2, i32 noundef 8)
|
||||
// CHECK-NEXT: br label %dtor.continue
|
||||
// CHECK: dtor.scalar:
|
||||
// X64-NEXT: call void @"??1Derived@@UEAA@XZ"(ptr noundef nonnull align 8 dereferenceable(16) %this1)
|
||||
// X86-NEXT: call x86_thiscallcc void @"??1Derived@@UAE@XZ"(ptr noundef nonnull align 4 dereferenceable(8) %this1)
|
||||
// CHECK-NEXT: %6 = and i32 %should_call_delete2, 1
|
||||
// CHECK-NEXT: %7 = icmp eq i32 %6, 0
|
||||
// CHECK-NEXT: br i1 %7, label %dtor.continue, label %dtor.call_delete
|
||||
// CHECK: dtor.call_delete:
|
||||
// X64-NEXT: call void @"??3@YAXPEAX_K@Z"(ptr noundef %this1, i64 noundef 16)
|
||||
// X86-NEXT: call void @"??3@YAXPAXI@Z"(ptr noundef %this1, i32 noundef 8)
|
||||
// CHECK-NEXT: br label %dtor.continue
|
||||
// CHECK: dtor.continue:
|
||||
// CHECK-NEXT: %8 = load ptr, ptr %retval
|
||||
// CHECK-NEXT: ret ptr %8
|
||||
|
||||
// X64: define weak dso_local noundef ptr @"??_EAllocatedAsArray@@UEAAPEAXI@Z"
|
||||
// X86: define weak dso_local x86_thiscallcc noundef ptr @"??_EAllocatedAsArray@@UAEPAXI@Z"
|
||||
// CLANG21: define linkonce_odr dso_local noundef ptr @"??_GAllocatedAsArray@@UEAAPEAXI@Z"
|
||||
99
clang/test/CodeGenCXX/microsoft-vector-deleting-dtors2.cpp
Normal file
99
clang/test/CodeGenCXX/microsoft-vector-deleting-dtors2.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
// RUN: %clang_cc1 -emit-llvm -fms-extensions -fms-compatibility -fno-dllexport-inlines %s -triple=x86_64-pc-windows-msvc -o - | FileCheck --check-prefixes=X64,CHECK %s
|
||||
// RUN: %clang_cc1 -emit-llvm -fms-extensions -fms-compatibility -fno-dllexport-inlines %s -triple=i386-pc-windows-msvc -o - | FileCheck --check-prefixes=X86,CHECK %s
|
||||
|
||||
// Check that vector deleting destructor does not reference undefined symbols.
|
||||
// Check that when there is no suitable operators delete for vector deleting
|
||||
// destructor, we still emit it without errors.
|
||||
|
||||
void operator delete(void*, size_t) {}
|
||||
void operator delete[](void*, size_t) {}
|
||||
|
||||
template <typename T> struct RefCounted {
|
||||
void operator delete[](void *p) { }
|
||||
};
|
||||
|
||||
struct __declspec(dllexport) DrawingBuffer : public RefCounted<DrawingBuffer> {
|
||||
DrawingBuffer();
|
||||
virtual ~DrawingBuffer();
|
||||
};
|
||||
|
||||
DrawingBuffer::DrawingBuffer() {}
|
||||
DrawingBuffer::~DrawingBuffer() {}
|
||||
|
||||
struct NoExport : public RefCounted<NoExport> {
|
||||
NoExport();
|
||||
virtual ~NoExport();
|
||||
};
|
||||
|
||||
NoExport::NoExport() {}
|
||||
NoExport::~NoExport() {}
|
||||
|
||||
namespace std {
|
||||
template <class T> struct type_identity {
|
||||
typedef T type;
|
||||
};
|
||||
enum class align_val_t : __SIZE_TYPE__ {};
|
||||
struct destroying_delete_t { explicit destroying_delete_t() = default; };
|
||||
}
|
||||
using size_t = __SIZE_TYPE__;
|
||||
|
||||
struct Test {
|
||||
void operator delete(void *) ;
|
||||
virtual ~Test();
|
||||
};
|
||||
|
||||
void *operator new(std::type_identity<Test>, size_t, std::align_val_t) throw();
|
||||
void operator delete(std::type_identity<Test>, void*, size_t, std::align_val_t) = delete;
|
||||
void *operator new[](std::type_identity<Test>, size_t, std::align_val_t) throw();
|
||||
void operator delete[](std::type_identity<Test>, void*, size_t, std::align_val_t) = delete;
|
||||
|
||||
void TesttheTest() {
|
||||
|
||||
Test *a = new Test[30];
|
||||
}
|
||||
|
||||
// X64: define dso_local void @"??3@YAXPEAX_K@Z"(ptr noundef %0, i64 noundef %1)
|
||||
// X64: define dso_local void @"??_V@YAXPEAX_K@Z"(ptr noundef %0, i64 noundef %1)
|
||||
// X64: define dso_local dllexport void @"??1DrawingBuffer@@UEAA@XZ"(ptr noundef nonnull align 8 dereferenceable(8) %this)
|
||||
|
||||
// X64: define weak dso_local noundef ptr @"??_EDrawingBuffer@@UEAAPEAXI@Z"
|
||||
// X64: call void @"??1DrawingBuffer@@UEAA@XZ"(ptr noundef nonnull align 8 dereferenceable(8) %arraydestroy.element)
|
||||
// X64: call void @"??_V?$RefCounted@UDrawingBuffer@@@@SAXPEAX@Z"(ptr noundef %2)
|
||||
// X64: call void @"??_V@YAXPEAX_K@Z"(ptr noundef %2, i64 noundef 8)
|
||||
// X64: call void @"??1DrawingBuffer@@UEAA@XZ"(ptr noundef nonnull align 8 dereferenceable(8) %this1)
|
||||
// X64: call void @"??3@YAXPEAX_K@Z"(ptr noundef %this1, i64 noundef 8)
|
||||
|
||||
|
||||
// X86: define dso_local void @"??3@YAXPAXI@Z"(ptr noundef %0, i32 noundef %1)
|
||||
// X86: define dso_local void @"??_V@YAXPAXI@Z"(ptr noundef %0, i32 noundef %1)
|
||||
|
||||
// X86: define weak dso_local x86_thiscallcc noundef ptr @"??_EDrawingBuffer@@UAEPAXI@Z"
|
||||
// X86: call x86_thiscallcc void @"??1DrawingBuffer@@UAE@XZ"(ptr noundef nonnull align 4 dereferenceable(4) %arraydestroy.element)
|
||||
// X86: call void @"??_V?$RefCounted@UDrawingBuffer@@@@SAXPAX@Z"(ptr noundef %2)
|
||||
// X86: call void @"??_V@YAXPAXI@Z"(ptr noundef %2, i32 noundef 4)
|
||||
// X86 call x86_thiscallcc void @"??1DrawingBuffer@@UAE@XZ"(ptr noundef nonnull align 4 dereferenceable(4) %this1)
|
||||
// X86: call void @"??3@YAXPAXI@Z"(ptr noundef %this1, i32 noundef 4)
|
||||
|
||||
|
||||
// X64: define weak dso_local noundef ptr @"??_ETest@@UEAAPEAXI@Z"(ptr noundef nonnull align 8 dereferenceable(8) %this, i32 noundef %should_call_delete)
|
||||
// X86: define weak dso_local x86_thiscallcc noundef ptr @"??_ETest@@UAEPAXI@Z"(ptr noundef nonnull align 4 dereferenceable(4) %this, i32 noundef %should_call_delete)
|
||||
// CHECK: dtor.call_delete_after_array_destroy:
|
||||
// CHECK-NEXT: call void @llvm.trap()
|
||||
// CHECK-NEXT: unreachable
|
||||
// CHECK: dtor.scalar:
|
||||
// X64-NEXT: call void @"??1Test@@UEAA@XZ"(ptr noundef nonnull align 8 dereferenceable(8) %this1)
|
||||
// X86-NEXT: call x86_thiscallcc void @"??1Test@@UAE@XZ"(ptr noundef nonnull align 4 dereferenceable(4) %this1)
|
||||
// CHECK-NEXT: %6 = and i32 %should_call_delete2, 1
|
||||
// CHECK-NEXT: %7 = icmp eq i32 %6, 0
|
||||
// CHECK-NEXT: br i1 %7, label %dtor.continue, label %dtor.call_delete
|
||||
// CHECK: dtor.call_delete:
|
||||
// X64-NEXT: call void @"??3Test@@SAXPEAX@Z"(ptr noundef %this1)
|
||||
// X86-NEXT: call void @"??3Test@@SAXPAX@Z"(ptr noundef %this1)
|
||||
// CHECK-NEXT: br label %dtor.continue
|
||||
|
||||
// X64: define linkonce_odr dso_local void @"??_V?$RefCounted@UDrawingBuffer@@@@SAXPEAX@Z"(ptr noundef %p)
|
||||
// X86: define linkonce_odr dso_local void @"??_V?$RefCounted@UDrawingBuffer@@@@SAXPAX@Z"(ptr noundef %p)
|
||||
|
||||
// X86: define linkonce_odr dso_local x86_thiscallcc noundef ptr @"??_GNoExport@@UAEPAXI@Z"(ptr noundef nonnull align 4 dereferenceable(4) %this, i32 noundef %should_call_delete)
|
||||
// X64: define linkonce_odr dso_local noundef ptr @"??_GNoExport@@UEAAPEAXI@Z"(ptr noundef nonnull align 8 dereferenceable(8) %this, i32 noundef %should_call_delete)
|
||||
// CHECK-NOT: define {{.*}}_V{{.*}}NoExport
|
||||
@ -26,7 +26,7 @@ struct B {
|
||||
B b;
|
||||
|
||||
// ITANIUM-DAG: @_ZTV1C = {{.*}} constant { [4 x ptr] } {{.*}} null, ptr @_ZTI1C, ptr @_ZN1CD1Ev, ptr @_ZN1CD0Ev
|
||||
// MSABI-DAG: @[[C_VFTABLE:.*]] = {{.*}} constant { [2 x ptr] } {{.*}} @"??_R4C@@6B@", ptr @"??_GC@@UEAAPEAXI@Z"
|
||||
// MSABI-DAG: @[[C_VFTABLE:.*]] = {{.*}} constant { [2 x ptr] } {{.*}} @"??_R4C@@6B@", ptr @"??_EC@@UEAAPEAXI@Z"
|
||||
struct C {
|
||||
virtual ~C() = default;
|
||||
virtual consteval C &operator=(const C&) = default;
|
||||
@ -36,7 +36,7 @@ struct C {
|
||||
C c;
|
||||
|
||||
// ITANIUM-DAG: @_ZTV1D = {{.*}} constant { [4 x ptr] } {{.*}} null, ptr @_ZTI1D, ptr @_ZN1DD1Ev, ptr @_ZN1DD0Ev
|
||||
// MSABI-DAG: @[[D_VFTABLE:.*]] = {{.*}} constant { [2 x ptr] } {{.*}} @"??_R4D@@6B@", ptr @"??_GD@@UEAAPEAXI@Z"
|
||||
// MSABI-DAG: @[[D_VFTABLE:.*]] = {{.*}} constant { [2 x ptr] } {{.*}} @"??_R4D@@6B@", ptr @"??_ED@@UEAAPEAXI@Z"
|
||||
struct D : C {};
|
||||
// ITANIUM-DAG: @d = {{.*}}global { ptr } { {{.*}} @_ZTV1D,
|
||||
// MSABI-DAG: @"?d@@3UD@@A" = {{.*}}global { ptr } { ptr @"??_7D@@6B@" }
|
||||
|
||||
@ -5,11 +5,11 @@ struct __declspec(dllexport) S { virtual ~S(); };
|
||||
struct __declspec(dllexport) T { virtual ~T(); };
|
||||
struct __declspec(dllexport) U : S, T { virtual ~U(); };
|
||||
|
||||
// CHECK-LABEL: define {{.*}} @"??_GS@@UAEPAXI@Z"
|
||||
// CHECK-LABEL: define {{.*}} @"??_ES@@UAEPAXI@Z"
|
||||
// CHECK: call x86_thiscallcc void @"??1S@@UAE@XZ"(ptr {{[^,]*}} %this1){{.*}}!dbg !{{[0-9]+}}
|
||||
|
||||
// CHECK-LABEL: define {{.*}} @"??_GT@@UAEPAXI@Z"
|
||||
// CHECK-LABEL: define {{.*}} @"??_ET@@UAEPAXI@Z"
|
||||
// CHECK: call x86_thiscallcc void @"??1T@@UAE@XZ"(ptr {{[^,]*}} %this1){{.*}}!dbg !{{[0-9]+}}
|
||||
|
||||
// CHECK-LABEL: define {{.*}} @"??_GU@@UAEPAXI@Z"
|
||||
// CHECK-LABEL: define {{.*}} @"??_EU@@UAEPAXI@Z"
|
||||
// CHECK: call x86_thiscallcc void @"??1U@@UAE@XZ"(ptr {{[^,]*}} %this1){{.*}}!dbg !{{[0-9]+}}
|
||||
|
||||
@ -16,7 +16,7 @@ struct AB: A, B {
|
||||
template struct AB<int>;
|
||||
|
||||
// CHECK: define {{.*}}@"??_E?$AB@H@@W3AEPAXI@Z"({{.*}} !dbg [[THUNK_VEC_DEL_DTOR:![0-9]*]]
|
||||
// CHECK: call {{.*}}@"??_G?$AB@H@@UAEPAXI@Z"({{.*}}) #{{[0-9]*}}, !dbg [[THUNK_LOC:![0-9]*]]
|
||||
// CHECK: call {{.*}}@"??_E?$AB@H@@UAEPAXI@Z"({{.*}}) #{{[0-9]*}}, !dbg [[THUNK_LOC:![0-9]*]]
|
||||
// CHECK: define
|
||||
|
||||
// CHECK: [[THUNK_VEC_DEL_DTOR]] = distinct !DISubprogram
|
||||
|
||||
@ -0,0 +1 @@
|
||||
module msvc_vector_deleting_destructors { header "msvc-vector-deleting-dtors.h" export * }
|
||||
@ -0,0 +1,16 @@
|
||||
class Base1 {
|
||||
public:
|
||||
void operator delete[](void *);
|
||||
};
|
||||
class Base2 {
|
||||
public:
|
||||
void operator delete(void *);
|
||||
};
|
||||
struct Derived : Base1, Base2 {
|
||||
virtual ~Derived() {}
|
||||
};
|
||||
void in_h_tests(Derived *p, Derived *p1) {
|
||||
::delete[] p;
|
||||
|
||||
delete[] p1;
|
||||
}
|
||||
30
clang/test/Modules/msvc-vector-deleting-destructors.cpp
Normal file
30
clang/test/Modules/msvc-vector-deleting-destructors.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
// RUN: rm -rf %t
|
||||
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps %s -x c++ -fmodules-cache-path=%t -I %S/Inputs/msvc-vector-deleting-dtors -emit-llvm -triple=i386-pc-win32 -o - | FileCheck %s --check-prefixes CHECK,CHECK32
|
||||
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps %s -x c++ -fmodules-cache-path=%t -I %S/Inputs/msvc-vector-deleting-dtors -emit-llvm -triple=x86_64-pc-win32 -o - | FileCheck %s --check-prefixes CHECK,CHECK64
|
||||
|
||||
#include "msvc-vector-deleting-dtors.h"
|
||||
|
||||
void call_in_module_function(void) {
|
||||
in_h_tests(new Derived[2], new Derived[3]);
|
||||
}
|
||||
|
||||
void out_of_module_tests(Derived *p, Derived *p1) {
|
||||
::delete[] p;
|
||||
|
||||
delete[] p1;
|
||||
}
|
||||
|
||||
// CHECK32-LABEL: define weak dso_local x86_thiscallcc noundef ptr @"??_EDerived@@UAEPAXI@Z"
|
||||
// CHECK64-LABEL: define weak dso_local noundef ptr @"??_EDerived@@UEAAPEAXI@Z"
|
||||
// CHECK: dtor.call_class_delete_after_array_destroy:
|
||||
// CHECK32-NEXT: call void @"??_VBase1@@SAXPAX@Z"(ptr noundef %2)
|
||||
// CHECK64-NEXT: call void @"??_VBase1@@SAXPEAX@Z"(ptr noundef %2)
|
||||
// CHECK: dtor.call_glob_delete_after_array_destroy:
|
||||
// CHECK32-NEXT: call void @"??_V@YAXPAXI@Z"(ptr noundef %2, i32 noundef 8)
|
||||
// CHECK64-NEXT: call void @"??_V@YAXPEAX_K@Z"(ptr noundef %2, i64 noundef 16)
|
||||
// CHECK: dtor.call_glob_delete:
|
||||
// CHECK32-NEXT: call void @"??3@YAXPAXI@Z"(ptr noundef %this1, i32 noundef 8)
|
||||
// CHECK64-NEXT: call void @"??3@YAXPEAX_K@Z"(ptr noundef %this1, i64 noundef 16)
|
||||
// CHECK: dtor.call_class_delete:
|
||||
// CHECK32-NEXT: call void @"??3Base2@@SAXPAX@Z"(ptr noundef %this1)
|
||||
// CHECK64-NEXT: call void @"??3Base2@@SAXPEAX@Z"(ptr noundef %this1)
|
||||
@ -23,4 +23,4 @@ void test() {
|
||||
|
||||
// Check that the virtual table is an unnamed_addr constant in comdat that can
|
||||
// be merged with the virtual table with other TUs.
|
||||
// CHECK: unnamed_addr constant {{.*}}[ptr @"??_R4Fruit@@6B@", ptr @"??_GFruit@@UAEPAXI@Z", ptr @"?eval@Fruit@@UAEXXZ"{{.*}}comdat($"??_7Fruit@@6B@")
|
||||
// CHECK: unnamed_addr constant {{.*}}[ptr @"??_R4Fruit@@6B@", ptr @"??_EFruit@@UAEPAXI@Z", ptr @"?eval@Fruit@@UAEXXZ"{{.*}}comdat($"??_7Fruit@@6B@")
|
||||
|
||||
16
clang/test/PCH/Inputs/msvc-vector-deleting-dtors.h
Normal file
16
clang/test/PCH/Inputs/msvc-vector-deleting-dtors.h
Normal file
@ -0,0 +1,16 @@
|
||||
class Base1 {
|
||||
public:
|
||||
void operator delete[](void *);
|
||||
};
|
||||
class Base2 {
|
||||
public:
|
||||
void operator delete(void *);
|
||||
};
|
||||
struct Derived : Base1, Base2 {
|
||||
virtual ~Derived() {}
|
||||
};
|
||||
void in_h_tests(Derived *p, Derived *p1) {
|
||||
::delete[] p;
|
||||
|
||||
delete[] p1;
|
||||
}
|
||||
34
clang/test/PCH/msvc-vector-deleting-destructors.cpp
Normal file
34
clang/test/PCH/msvc-vector-deleting-destructors.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
// Test this without pch.
|
||||
// RUN: %clang_cc1 -x c++ -include %S/Inputs/msvc-vector-deleting-dtors.h -emit-llvm -o - %s -triple=i386-pc-win32 | FileCheck %s --check-prefixes CHECK,CHECK32
|
||||
// RUN: %clang_cc1 -x c++ -include %S/Inputs/msvc-vector-deleting-dtors.h -emit-llvm -o - %s -triple=x86_64-pc-win32 | FileCheck %s --check-prefixes CHECK,CHECK64
|
||||
|
||||
// Test with pch.
|
||||
// RUN: %clang_cc1 -x c++ -emit-pch -o %t -triple=i386-pc-win32 %S/Inputs/msvc-vector-deleting-dtors.h
|
||||
// RUN: %clang_cc1 -x c++ -include-pch %t -emit-llvm -triple=i386-pc-win32 -o - %s | FileCheck %s --check-prefixes CHECK,CHECK32
|
||||
// RUN: %clang_cc1 -x c++ -emit-pch -o %t -triple=x86_64-pc-win32 %S/Inputs/msvc-vector-deleting-dtors.h
|
||||
// RUN: %clang_cc1 -x c++ -include-pch %t -emit-llvm -triple=x86_64-pc-win32 -o - %s | FileCheck %s --check-prefixes CHECK,CHECK64
|
||||
|
||||
void call_in_module_function(void) {
|
||||
in_h_tests(new Derived[2], new Derived[3]);
|
||||
}
|
||||
|
||||
void out_of_module_tests(Derived *p, Derived *p1) {
|
||||
::delete[] p;
|
||||
|
||||
delete[] p1;
|
||||
}
|
||||
|
||||
// CHECK32-LABEL: define weak dso_local x86_thiscallcc noundef ptr @"??_EDerived@@UAEPAXI@Z"
|
||||
// CHECK64-LABEL: define weak dso_local noundef ptr @"??_EDerived@@UEAAPEAXI@Z"
|
||||
// CHECK: dtor.call_class_delete_after_array_destroy:
|
||||
// CHECK32-NEXT: call void @"??_VBase1@@SAXPAX@Z"(ptr noundef %2)
|
||||
// CHECK64-NEXT: call void @"??_VBase1@@SAXPEAX@Z"(ptr noundef %2)
|
||||
// CHECK: dtor.call_glob_delete_after_array_destroy:
|
||||
// CHECK32-NEXT: call void @"??_V@YAXPAXI@Z"(ptr noundef %2, i32 noundef 8)
|
||||
// CHECK64-NEXT: call void @"??_V@YAXPEAX_K@Z"(ptr noundef %2, i64 noundef 16)
|
||||
// CHECK: dtor.call_glob_delete:
|
||||
// CHECK32-NEXT: call void @"??3@YAXPAXI@Z"(ptr noundef %this1, i32 noundef 8)
|
||||
// CHECK64-NEXT: call void @"??3@YAXPEAX_K@Z"(ptr noundef %this1, i64 noundef 16)
|
||||
// CHECK: dtor.call_class_delete:
|
||||
// CHECK32-NEXT: call void @"??3Base2@@SAXPAX@Z"(ptr noundef %this1)
|
||||
// CHECK64-NEXT: call void @"??3Base2@@SAXPEAX@Z"(ptr noundef %this1)
|
||||
@ -24,16 +24,15 @@ DerivedABC *useABCVTable() { return new DerivedABC(); }
|
||||
// MSVC: @"__profn_??1ABC@@{{.*}}" =
|
||||
// MSVC-NOT: @"__profn_??_G{{.*}}" =
|
||||
|
||||
// MSVC-LABEL: define linkonce_odr dso_local noundef ptr @"??_GDerivedABC@@UEAAPEAXI@Z"(ptr {{[^,]*}} %this, {{.*}})
|
||||
// MSVC-NOT: call void @llvm.instrprof.increment({{.*}})
|
||||
// MSVC: call void @"??1DerivedABC@@UEAA@XZ"({{.*}})
|
||||
// MSVC: ret void
|
||||
|
||||
// MSVC-LABEL: define linkonce_odr dso_local noundef ptr @"??_GABC@@UEAAPEAXI@Z"(ptr {{[^,]*}} %this, {{.*}})
|
||||
// MSVC-NOT: call void @llvm.instrprof.increment({{.*}})
|
||||
// MSVC: call void @llvm.trap()
|
||||
// MSVC-NEXT: unreachable
|
||||
|
||||
// MSVC-LABEL: define linkonce_odr dso_local noundef ptr @"??_GDerivedABC@@UEAAPEAXI@Z"(ptr {{[^,]*}} %this, {{.*}})
|
||||
// MSVC-NOT: call void @llvm.instrprof.increment({{.*}})
|
||||
// MSVC: call void @"??1DerivedABC@@UEAA@XZ"({{.*}})
|
||||
|
||||
// MSVC-LABEL: define linkonce_odr dso_local void @"??1DerivedABC@@UEAA@XZ"({{.*}})
|
||||
// MSVC: call void @llvm.instrprof.increment({{.*}})
|
||||
// MSVC: call void @"??1ABC@@UEAA@XZ"({{.*}})
|
||||
|
||||
62
clang/test/SemaCXX/gh134265.cpp
Normal file
62
clang/test/SemaCXX/gh134265.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
// RUN: %clang_cc1 %s -verify=expected -fsyntax-only -triple=x86_64-unknown-linux-gnu
|
||||
// RUN: %clang_cc1 %s -verify=expected -fsyntax-only -triple=x86_64-unknown-linux-gnu -std=c++20
|
||||
// RUN: %clang_cc1 %s -verify=expected,ms -fms-extensions -fms-compatibility -triple=x86_64-pc-windows-msvc -DMS
|
||||
|
||||
// Verify that clang doesn't emit additional errors when searching for
|
||||
// additional operators delete for vector deleting destructors support.
|
||||
|
||||
struct Foo {
|
||||
virtual ~Foo() {} // expected-error {{attempt to use a deleted function}}
|
||||
static void operator delete(void* ptr) = delete; // expected-note {{explicitly marked deleted here}}
|
||||
};
|
||||
|
||||
|
||||
struct Bar {
|
||||
virtual ~Bar() {}
|
||||
static void operator delete[](void* ptr) = delete;
|
||||
};
|
||||
|
||||
struct Baz {
|
||||
virtual ~Baz() {}
|
||||
static void operator delete[](void* ptr) = delete; // expected-note {{explicitly marked deleted here}}
|
||||
};
|
||||
|
||||
struct BarBaz {
|
||||
~BarBaz() {}
|
||||
static void operator delete[](void* ptr) = delete;
|
||||
};
|
||||
|
||||
void foobar() {
|
||||
Baz *B = new Baz[10]();
|
||||
delete [] B; // expected-error {{attempt to use a deleted function}}
|
||||
BarBaz *BB = new BarBaz[10]();
|
||||
}
|
||||
|
||||
struct BaseDelete1 {
|
||||
void operator delete[](void *);
|
||||
};
|
||||
struct BaseDelete2 {
|
||||
void operator delete[](void *);
|
||||
};
|
||||
struct BaseDestructor {
|
||||
BaseDestructor() {}
|
||||
virtual ~BaseDestructor() = default;
|
||||
};
|
||||
struct Final : BaseDelete1, BaseDelete2, BaseDestructor {
|
||||
Final() {}
|
||||
};
|
||||
struct FinalExplicit : BaseDelete1, BaseDelete2, BaseDestructor {
|
||||
FinalExplicit() {}
|
||||
inline ~FinalExplicit() {}
|
||||
};
|
||||
|
||||
#ifdef MS
|
||||
struct Final1 : BaseDelete1, BaseDelete2, BaseDestructor {
|
||||
__declspec(dllexport) ~Final1() {}
|
||||
};
|
||||
#endif // MS
|
||||
|
||||
void foo() {
|
||||
Final* a = new Final[10]();
|
||||
FinalExplicit* b = new FinalExplicit[10]();
|
||||
}
|
||||
@ -2515,6 +2515,7 @@ static llvm::StringRef ClangToItaniumDtorKind(clang::CXXDtorType kind) {
|
||||
case clang::CXXDtorType::Dtor_Unified:
|
||||
return "D4";
|
||||
case clang::CXXDtorType::Dtor_Comdat:
|
||||
case clang::CXXDtorType::Dtor_VectorDeleting:
|
||||
llvm_unreachable("Unexpected destructor kind.");
|
||||
}
|
||||
llvm_unreachable("Fully covered switch above");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user