[llvm-commits] [patch] AlignAs fixes

David Blaikie dblaikie at gmail.com
Tue Aug 28 15:56:26 PDT 2012


Here's an attempt to fix the incorrect/non-portable code in AlignAs.h
and its unit test.

We were previously trying to align typedefs, which isn't valid in
C++11. Even attempting to use alignas correctly won't work on any
compiler other than Clang anyway, even those (such as GCC 4.7)
reporting C++11 compliance through the __cplusplus macro value.

So instead:
for __GNUC__, use __attribute__((aligned(x))) of a char
for __cplusplus == 201103L || __has_feature(cxx_alignas), use alignas
on a char (this code path isn't actually tested at the moment since
clang reports __GNUC__ so it hits the first case)
for _MSC_VER, use __declspec(align(x)) on a char

This doesn't try to align a typedef as we were doing before, so I cut
a few test cases & extra types out of the test file - this doesn't
change the implementation much because we were stuffing a variable of
the typedef'd type in an anonymous struct anyway - so now we just use
the template with the aligned member directly.

Yes/no/maybe? (I haven't actually looked at the code to see if this is
producing correct code - just updated the test cases fairly
mechanically & checked that they pass)

- David
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alignas.diff
Type: application/octet-stream
Size: 9397 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120828/a1a6c9c3/attachment.obj>


More information about the llvm-commits mailing list