[cfe-dev] libc++ max_align_t bug

Kal b17c0de at gmail.com
Fri Feb 7 16:24:52 PST 2014


Hi Marshall,
This actually doesn't work. But perhaps it should. I don't know what the
correct interpretation of the standard is here. Note the following:

-------------------------
#include <stdio.h>

typedef struct { 
  long double __x;
  long long __y;
} max_align_t;

typedef struct{ long long __x; } ll_t;

#define CHECK_ALIGN(Ty) \
  printf("alignof(" #Ty ")=%i\n", alignof(Ty))

int main() {
  CHECK_ALIGN(max_align_t);
  CHECK_ALIGN(long long);
  CHECK_ALIGN(ll_t);
  return 0;
}
-------------------------

Outputs (x86) clang 3.4:

alignof(max_align_t)=4                                                                                                                                                

alignof(long
long)=8                                                                                                                                                     

alignof(ll_t)=4

So putting a primitive type in a struct can relax the alignment
requirements. It looks like the GCC folks recently changed the behavior
of C11 _Alignof to always return 4 here. See
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023. What should clang be
doing here??

Maybe best not to use a struct/union to accomplish this in libc++ ??

Thanks!
Kal


Am 06.02.14 05:09, schrieb Marshall Clow:
> On Nov 28, 2013, at 6:42 AM, Kal <b17c0de at gmail.com> wrote:
>
>> Hi,
>> Running libc++ 3.4 rc1 "testit" on 32-bit Linux fails for test:
>>
>> test/language.support/support.types/max_align_t.pass.cpp
>>
>> max_align_t is typedef'd to "long double" type in <cstddef>. But…
> Kal —
>
> If you replace 
> typedef long double max_align_t; 
>
> with 
>
> typedef struct {
> 	long double __x;
> 	long long __y;
> 	} max_align_t;
>
> does the test pass for you?
>
>
>> alignment_of(long double)=4, sizeof(long double)=12
>> alignment_of(long long)=8, sizeof(long long)=8
> And I’m really sorry that I misplaced this for three months.
>
> — Marshall
>
>




More information about the cfe-dev mailing list