[cfe-dev] c++11's alignas() ignored inside #pragma pack

Richard Smith richard at metafoo.co.uk
Wed Jul 23 12:49:06 PDT 2014


On Wed, Jul 23, 2014 at 10:18 AM, Erik Schwiebert <eriksc at microsoft.com>
wrote:

>  Would it be possible to have clang support the alignas inside a pragma
> pack directive, if the structure in question is also inside a
> pragma ms_struct directive?  There are some teams at Microsoft using clang
> to target non-Windows platforms but sharing code that expects MSVC
> structure layout.  Using the Microsoft C++ ABI isn’t feasible as the
> platform in question is not a Microsoft Windows platform.
>

Our documentation says:

"clang supports the Microsoft #pragma pack feature for controlling record
layout. GCC also contains support for this feature, however where MSVC and
GCC are incompatible clang follows the MSVC definition."

... so I think we should do the obviously sane thing here in all cases
(that is, alignas on a field should beat #pragma pack).

Thanks,
> Schwieb
> Microsoft Mac Team
>
>  On Jul 23, 2014, at 9:48 AM, jahanian <fjahanian at apple.com> wrote:
>
>
> On Jul 23, 2014, at 9:45 AM, jahanian <fjahanian at apple.com> wrote:
>
>
>  On Jul 22, 2014, at 5:26 PM, Reid Kleckner <rnk at google.com> wrote:
>
>
>
>  Presumably they handle alignas the same way they handle
> __declspec(align(N)), which overrides packing.  MSVC appears to have two
> notions of alignment, required and advisory, while the C++ standard, Clang,
> and GCC only have one.  One way to observe this is to see that they will
> align an int64 to 8 bytes in a struct, but they will not realign the stack
> to 8 bytes when that struct is stack allocated.
>
>  Also, Clang does respect alignas in this case when targeting the
> Microsoft C++ ABI.
>
>
>  I tried the test case with these options for MS ABI:
>
>  clang -cc1 -triple x86_64-windows-msvc -std=c++11 -S t.cpp
>
>  Assembly indicates that it does not seem to respect alignas. Should I be
> using other options?
>
>  main:
> movl $28, %eax
> movl $0, -4(%rsp)
> retq
>
>
>
>  Oops. I was using an old clang. Sorry for the noise.
>
>  main:
> movl $64, %eax
> retq
>
>    - Fariborz
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140723/cd1c8c34/attachment.html>


More information about the cfe-dev mailing list