static uint64_t CalculateCookiePadding(ASTContext &Ctx, const CXXNewExpr *E) { if (!E->isArray()) return 0; QualType T = E->getAllocatedType(); const RecordType *RT = T->getAs<RecordType>(); if (!RT) return 0; const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()); if (!RD) return 0; // Check if the class has a trivial destructor. if (RD->hasTrivialDestructor()) { // FIXME: Check for a two-argument delete. return 0; } // Padding is the maximum of sizeof(size_t) and alignof(T) return std::max(Ctx.getTypeSize(Ctx.getSizeType()), static_cast<uint64_t>(Ctx.getTypeAlign(T))) / 8; }