diff options
author | John McCall <rjmccall@apple.com> | 2013-01-25 23:36:19 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2013-01-25 23:36:19 +0000 |
commit | f3bbb155beb69cdad1c6b0472bc0ca20cece6c50 (patch) | |
tree | 54a2c2d60c319cf3aa3cf73af349db1e084ba583 /lib/CodeGen | |
parent | 96fcde0b8ed8bdf99d326312ca7be6447b0fe5fc (diff) |
ARM says that the array cookie should always be eight bytes.
ARM is not thinking about over-aligned structures.
Overrule ARM in both our generic-ARM and iOS ABI implementations.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173531 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/ItaniumCXXABI.cpp | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp index 354887f446..52409929ee 100644 --- a/lib/CodeGen/ItaniumCXXABI.cpp +++ b/lib/CodeGen/ItaniumCXXABI.cpp @@ -890,50 +890,46 @@ llvm::Value *ItaniumCXXABI::readArrayCookieImpl(CodeGenFunction &CGF, } CharUnits ARMCXXABI::getArrayCookieSizeImpl(QualType elementType) { - // On ARM, the cookie is always: + // ARM says that the cookie is always: // struct array_cookie { // std::size_t element_size; // element_size != 0 // std::size_t element_count; // }; - // TODO: what should we do if the allocated type actually wants - // greater alignment? - return CharUnits::fromQuantity(2 * CGM.SizeSizeInBytes); + // But the base ABI doesn't give anything an alignment greater than + // 8, so we can dismiss this as typical ABI-author blindness to + // actual language complexity and round up to the element alignment. + return std::max(CharUnits::fromQuantity(2 * CGM.SizeSizeInBytes), + CGM.getContext().getTypeAlignInChars(elementType)); } llvm::Value *ARMCXXABI::InitializeArrayCookie(CodeGenFunction &CGF, - llvm::Value *NewPtr, - llvm::Value *NumElements, + llvm::Value *newPtr, + llvm::Value *numElements, const CXXNewExpr *expr, - QualType ElementType) { + QualType elementType) { assert(requiresArrayCookie(expr)); - // NewPtr is a char*. - - unsigned AS = NewPtr->getType()->getPointerAddressSpace(); - - ASTContext &Ctx = getContext(); - CharUnits SizeSize = Ctx.getTypeSizeInChars(Ctx.getSizeType()); - llvm::IntegerType *SizeTy = - cast<llvm::IntegerType>(CGF.ConvertType(Ctx.getSizeType())); + // NewPtr is a char*, but we generalize to arbitrary addrspaces. + unsigned AS = newPtr->getType()->getPointerAddressSpace(); // The cookie is always at the start of the buffer. - llvm::Value *CookiePtr = NewPtr; + llvm::Value *cookie = newPtr; // The first element is the element size. - CookiePtr = CGF.Builder.CreateBitCast(CookiePtr, SizeTy->getPointerTo(AS)); - llvm::Value *ElementSize = llvm::ConstantInt::get(SizeTy, - Ctx.getTypeSizeInChars(ElementType).getQuantity()); - CGF.Builder.CreateStore(ElementSize, CookiePtr); + cookie = CGF.Builder.CreateBitCast(cookie, CGF.SizeTy->getPointerTo(AS)); + llvm::Value *elementSize = llvm::ConstantInt::get(CGF.SizeTy, + getContext().getTypeSizeInChars(elementType).getQuantity()); + CGF.Builder.CreateStore(elementSize, cookie); // The second element is the element count. - CookiePtr = CGF.Builder.CreateConstInBoundsGEP1_32(CookiePtr, 1); - CGF.Builder.CreateStore(NumElements, CookiePtr); + cookie = CGF.Builder.CreateConstInBoundsGEP1_32(cookie, 1); + CGF.Builder.CreateStore(numElements, cookie); // Finally, compute a pointer to the actual data buffer by skipping // over the cookie completely. - CharUnits CookieSize = 2 * SizeSize; - return CGF.Builder.CreateConstInBoundsGEP1_64(NewPtr, - CookieSize.getQuantity()); + CharUnits cookieSize = ARMCXXABI::getArrayCookieSizeImpl(elementType); + return CGF.Builder.CreateConstInBoundsGEP1_64(newPtr, + cookieSize.getQuantity()); } llvm::Value *ARMCXXABI::readArrayCookieImpl(CodeGenFunction &CGF, |