libc++ patch for max_align_t

Chandler Carruth chandlerc at google.com
Wed Feb 19 15:11:46 PST 2014


Attached in my patch to do this minimum of work to get std::max_align_t.
It's dirt simple, if deeply unfortunate in the specific definition in
provides on many platforms. I think it is no worse than the current
behavior.

If we want to support a host which is neither Clang nor GCC and does not
provide a ::max_align_t, we can do so incrementally atop this I think.

-Chandler


On Sun, Feb 16, 2014 at 12:14 AM, Chandler Carruth <chandlerc at google.com>wrote:

> FYI, i'm preparing patches to this effect.
>
>
> On Sat, Feb 15, 2014 at 11:13 PM, Richard Smith <richard at metafoo.co.uk>wrote:
>
>> This seems to be going in the wrong direction.
>>
>> * max_align_t needs to be in <stddef.h> as well as in <cstddef>
>> * <stddef.h> is provided by the compiler, not by the standard library
>> * max_align_t is de facto part of the platform's ABI. It's not enough to
>> get the alignment right, you also need to get the size and mangled name of
>> the type right (and possibly other things too).
>>
>> IMO, the right thing to do here is to add a definition to max_align_t to
>> Clang's lib/Headers/stddef.h, and add a using declaration to libc++'s
>> cstddef to pull it into namespace std.
>>
>>
>> On Mon, Feb 10, 2014 at 1:16 PM, Howard Hinnant <howard.hinnant at gmail.com
>> > wrote:
>>
>>> On Feb 10, 2014, at 2:25 PM, Howard Hinnant <howard.hinnant at gmail.com>
>>> wrote:
>>>
>>> >> It seems like the old behavior follows the standard more closely. If
>>> Len
>>> >> == 17, then _any_ c++ object with size no greater than Len includes
>>> >> objects of size 16 and some objects of size 16 maybe have an alignment
>>> >> requirement of 16.
>>> >
>>> > Ok, I'm convinced, thanks.
>>>
>>> I've enclosed a slightly updated patch.  I've added float as Kal
>>> suggested, but haven't added uintmax_t because of not wanting to couple
>>> <cstddef> to <cstddint>.  I have not modified the behavior, thanks to Kal.
>>>
>>> std::__find_max_align<std::__all_types, 1>::value = 1
>>> std::__find_max_align<std::__all_types, 2>::value = 2
>>> std::__find_max_align<std::__all_types, 3>::value = 2
>>> std::__find_max_align<std::__all_types, 4>::value = 4
>>> std::__find_max_align<std::__all_types, 5>::value = 4
>>> std::__find_max_align<std::__all_types, 6>::value = 4
>>> std::__find_max_align<std::__all_types, 7>::value = 4
>>> std::__find_max_align<std::__all_types, 8>::value = 8
>>> std::__find_max_align<std::__all_types, 9>::value = 8
>>> std::__find_max_align<std::__all_types, 10>::value = 8
>>> std::__find_max_align<std::__all_types, 11>::value = 8
>>> std::__find_max_align<std::__all_types, 12>::value = 8
>>> std::__find_max_align<std::__all_types, 13>::value = 8
>>> std::__find_max_align<std::__all_types, 14>::value = 8
>>> std::__find_max_align<std::__all_types, 15>::value = 8
>>> std::__find_max_align<std::__all_types, 16>::value = 16
>>> std::__find_max_align<std::__all_types, 17>::value = 16
>>> std::__find_max_align<std::__all_types, 18>::value = 16
>>> std::__find_max_align<std::__all_types, 19>::value = 16
>>> std::__find_max_align<std::__all_types, 20>::value = 16
>>> std::__find_max_align<std::__all_types, 21>::value = 16
>>> std::__find_max_align<std::__all_types, 22>::value = 16
>>> std::__find_max_align<std::__all_types, 23>::value = 16
>>> std::__find_max_align<std::__all_types, 24>::value = 16
>>> std::__find_max_align<std::__all_types, 25>::value = 16
>>> std::__find_max_align<std::__all_types, 26>::value = 16
>>> std::__find_max_align<std::__all_types, 27>::value = 16
>>> std::__find_max_align<std::__all_types, 28>::value = 16
>>> std::__find_max_align<std::__all_types, 29>::value = 16
>>> std::__find_max_align<std::__all_types, 30>::value = 16
>>> std::__find_max_align<std::__all_types, 31>::value = 16
>>> std::__find_max_align<std::__all_types, 32>::value = 16
>>> std::__find_max_align<std::__all_types, 33>::value = 16
>>> ...
>>>
>>> Howard
>>>
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>>
>>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140219/bc6f5bd5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-max-align-t.patch
Type: application/octet-stream
Size: 449 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140219/bc6f5bd5/attachment.obj>


More information about the cfe-commits mailing list