From: Anders Carlsson Date: Sun, 13 Dec 2009 20:10:12 +0000 (+0000) Subject: Fix regression in my last commit - if a struct has a trivial destructor but no usual... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=710f7058400e0e5accae0ce92e9c1fbfd0c15232;p=clang Fix regression in my last commit - if a struct has a trivial destructor but no usual deallocation function we don't need a cookie. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91249 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp index c8b1c29f51..c12ec1437f 100644 --- a/lib/CodeGen/CGExprCXX.cpp +++ b/lib/CodeGen/CGExprCXX.cpp @@ -27,25 +27,33 @@ static uint64_t CalculateCookiePadding(ASTContext &Ctx, QualType ElementType) { // Check if the class has a trivial destructor. if (RD->hasTrivialDestructor()) { // Check if the usual deallocation function takes two arguments. + const CXXMethodDecl *UsualDeallocationFunction = 0; + DeclarationName OpName = Ctx.DeclarationNames.getCXXOperatorName(OO_Array_Delete); - DeclContext::lookup_const_iterator Op, OpEnd; for (llvm::tie(Op, OpEnd) = RD->lookup(OpName); Op != OpEnd; ++Op) { - CXXMethodDecl *Delete = cast(*Op); + const CXXMethodDecl *Delete = cast(*Op); if (Delete->isUsualDeallocationFunction()) { - // We don't need a cookie. - if (Delete->getNumParams() == 1) - return 0; - - assert(Delete->getNumParams() == 2 && - "Unexpected deallocation function type!"); + UsualDeallocationFunction = Delete; break; } } - } + + // No usual deallocation function, we don't need a cookie. + if (!UsualDeallocationFunction) + return 0; + + // The usual deallocation function doesn't take a size_t argument, so we + // don't need a cookie. + if (UsualDeallocationFunction->getNumParams() == 1) + return 0; + + assert(UsualDeallocationFunction->getNumParams() == 2 && + "Unexpected deallocation function type!"); + } // Padding is the maximum of sizeof(size_t) and alignof(ElementType) return std::max(Ctx.getTypeSize(Ctx.getSizeType()),