C++ Operator new alignment requirements

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.

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?

I read that both Linux and Windows malloc return a 2sizeof(void) alignment, so maybe we’re the first that notice that requirement.

Regards,
Bernhard

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