aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-12-13 20:10:12 +0000
committerAnders Carlsson <andersca@mac.com>2009-12-13 20:10:12 +0000
commit710f7058400e0e5accae0ce92e9c1fbfd0c15232 (patch)
treee4f49d581190724bb4b31c3aa3c829bcfb40f49e
parent871d078f5ae5505553c02deeabdd4b83b4820211 (diff)
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
-rw-r--r--lib/CodeGen/CGExprCXX.cpp26
1 files changed, 17 insertions, 9 deletions
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<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()),