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 c8b1c29..c12ec14 100644
--- a/lib/CodeGen/CGExprCXX.cpp
+++ b/lib/CodeGen/CGExprCXX.cpp
@@ -27,25 +27,33 @@
// 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()),