[PATCH] D118804: Revert "[Clang] Propagate guaranteed alignment for malloc and others"

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 2 09:52:46 PST 2022


MaskRay added subscribers: urnathan, MaskRay.
MaskRay added a comment.

I agree that the original patch (c2297544c04764237cedc523083c7be2fb3833d4 <https://reviews.llvm.org/rGc2297544c04764237cedc523083c7be2fb3833d4>) should be reverted.

The `__STDCPP_DEFAULT_NEW_ALIGNMENT__==16` (on x86-64) thing is the glibc behavior.
It should be taken with a grain of salt since many malloc implementations don't provide the guarantee for allocations with smaller size (jemalloc/mimalloc/tcmalloc just guarantee 8 alignment on 64-bit systems).
And of course, this doesn't apply to to malloc and friends.

@urnathan mentioned this on https://github.com/llvm/llvm-project/issues/53540

> Notice the 'suitably-sized allocation' caveat. Either poor wording, or getNewAlign is not guaranteeing smaller alignment for smaller allocations. I have not audited all the uses of getNewAlign to see if they presume the value is a conditional guarantee or not.



> GCC also does same assumptions

If GCC makes use of  `__STDCPP_DEFAULT_NEW_ALIGNMENT__==16` for malloc or operator new with smaller allocations, looks like it is a bug that should be fixed as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118804/new/

https://reviews.llvm.org/D118804



More information about the cfe-commits mailing list