diff options
author | Anders Carlsson <andersca@mac.com> | 2009-12-13 20:10:12 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-12-13 20:10:12 +0000 |
commit | adbe4249d6a643a78720db059c946a608d7a8673 (patch) | |
tree | 9dad4cdcfc703b4aa5aca2ad74d3a1277dad2713 /clang/lib | |
parent | 21122cf657a37283eb7f5bf24cd92c0e2fd2ecc5 (diff) | |
download | bcm5719-llvm-adbe4249d6a643a78720db059c946a608d7a8673.tar.gz bcm5719-llvm-adbe4249d6a643a78720db059c946a608d7a8673.zip |
Fix regression in my last commit - if a struct has a trivial destructor but no usual deallocation function we don't need a cookie.
llvm-svn: 91249
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CGExprCXX.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp index c8b1c29f511..c12ec1437f5 100644 --- a/clang/lib/CodeGen/CGExprCXX.cpp +++ b/clang/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<CXXMethodDecl>(*Op); + const CXXMethodDecl *Delete = cast<CXXMethodDecl>(*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()), |