[cfe-dev] C++ Operator new alignment requirements

Friedman, Eli via cfe-dev cfe-dev at lists.llvm.org
Fri Sep 29 14:19:30 PDT 2017


On 9/29/2017 8:11 AM, Bernhard Walle via cfe-dev wrote:
>
> Hello,
>
> to be honest, I'm not sure if this is the right list since it's not 
> the C/C++ parser but the machine code generator.
>

This list is fine; generating LLVM IR is part of clang.

> Background: We have our own overloaded operator new for some historic 
> reason. We saw that the pointer has a hard 16 byte alignment 
> requirement since the compiler uses SSE instructions to zero the 
> memory in some circumstances.
>
> Does the C++ standard require that alignment?
>

The standard says the storage allocated by operator new has to be 
"suitably aligned to represent any object of that size"... which 
basically means the required alignment is implementation-defined. If you 
want to check what alignment the compiler expects, there's a predefined 
macro "__STDCPP_DEFAULT_NEW_ALIGNMENT__". You can change the required 
alignment using the command-line option -fnew-alignment 
(https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fnew-alignment).

-Eli

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project




More information about the cfe-dev mailing list