C++ Operator new alignment requirements

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

C++ Operator new alignment requirements

David Chisnall via cfe-dev

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 2*sizeof(void*) alignment, so maybe we're the first that notice that requirement.

Regards,
Bernhard


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: C++ Operator new alignment requirements

David Chisnall via cfe-dev
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

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev