xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/attr-aligned.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc int x __attribute__((aligned(3))); // expected-error {{requested alignment is not a power of 2}}
4*0a6a1f1dSLionel Sambuc int y __attribute__((aligned(1 << 29))); // expected-error {{requested alignment must be 268435456 bytes or smaller}}
5f4a2713aSLionel Sambuc 
6f4a2713aSLionel Sambuc // PR3254
7f4a2713aSLionel Sambuc short g0[3] __attribute__((aligned));
8f4a2713aSLionel Sambuc short g0_chk[__alignof__(g0) == 16 ? 1 : -1];
9f4a2713aSLionel Sambuc 
10f4a2713aSLionel Sambuc // <rdar://problem/6840045>
11f4a2713aSLionel Sambuc typedef char ueber_aligned_char __attribute__((aligned(8)));
12f4a2713aSLionel Sambuc 
13f4a2713aSLionel Sambuc struct struct_with_ueber_char {
14f4a2713aSLionel Sambuc   ueber_aligned_char c;
15f4a2713aSLionel Sambuc };
16f4a2713aSLionel Sambuc 
17f4a2713aSLionel Sambuc char a = 0;
18f4a2713aSLionel Sambuc 
19f4a2713aSLionel Sambuc char a0[__alignof__(ueber_aligned_char) == 8? 1 : -1] = { 0 };
20f4a2713aSLionel Sambuc char a1[__alignof__(struct struct_with_ueber_char) == 8? 1 : -1] = { 0 };
21f4a2713aSLionel Sambuc char a2[__alignof__(a) == 1? : -1] = { 0 };
22f4a2713aSLionel Sambuc char a3[sizeof(a) == 1? : -1] = { 0 };
23f4a2713aSLionel Sambuc 
24*0a6a1f1dSLionel Sambuc typedef long long __attribute__((aligned(1))) underaligned_longlong;
25*0a6a1f1dSLionel Sambuc char a4[__alignof__(underaligned_longlong) == 1 ?: -1] = {0};
26*0a6a1f1dSLionel Sambuc 
27*0a6a1f1dSLionel Sambuc typedef long long __attribute__((aligned(1))) underaligned_complex_longlong;
28*0a6a1f1dSLionel Sambuc char a5[__alignof__(underaligned_complex_longlong) == 1 ?: -1] = {0};
29*0a6a1f1dSLionel Sambuc 
30f4a2713aSLionel Sambuc // rdar://problem/8335865
31f4a2713aSLionel Sambuc int b __attribute__((aligned(2)));
32f4a2713aSLionel Sambuc char b1[__alignof__(b) == 2 ?: -1] = {0};
33f4a2713aSLionel Sambuc 
34f4a2713aSLionel Sambuc struct C { int member __attribute__((aligned(2))); } c;
35f4a2713aSLionel Sambuc char c1[__alignof__(c) == 4 ?: -1] = {0};
36f4a2713aSLionel Sambuc char c2[__alignof__(c.member) == 4 ?: -1] = {0};
37f4a2713aSLionel Sambuc 
38f4a2713aSLionel Sambuc struct D { int member __attribute__((aligned(2))) __attribute__((packed)); } d;
39f4a2713aSLionel Sambuc char d1[__alignof__(d) == 2 ?: -1] = {0};
40f4a2713aSLionel Sambuc char d2[__alignof__(d.member) == 2 ?: -1] = {0};
41f4a2713aSLionel Sambuc 
42*0a6a1f1dSLionel Sambuc struct E { int member __attribute__((aligned(2))); } __attribute__((packed));
43f4a2713aSLionel Sambuc struct E e;
44f4a2713aSLionel Sambuc char e1[__alignof__(e) == 2 ?: -1] = {0};
45f4a2713aSLionel Sambuc char e2[__alignof__(e.member) == 2 ?: -1] = {0};
46*0a6a1f1dSLionel Sambuc 
47*0a6a1f1dSLionel Sambuc typedef char overaligned_char __attribute__((aligned(16)));
48*0a6a1f1dSLionel Sambuc typedef overaligned_char array_with_overaligned_char[11];
49*0a6a1f1dSLionel Sambuc typedef char array_with_align_attr[11] __attribute__((aligned(16)));
50*0a6a1f1dSLionel Sambuc 
51*0a6a1f1dSLionel Sambuc char f0[__alignof__(array_with_overaligned_char) == 16 ? 1 : -1] = { 0 };
52*0a6a1f1dSLionel Sambuc char f1[__alignof__(array_with_align_attr) == 16 ? 1 : -1] = { 0 };
53*0a6a1f1dSLionel Sambuc array_with_overaligned_char F2;
54*0a6a1f1dSLionel Sambuc char f2[__alignof__(F2) == 16 ? 1 : -1] = { 0 };
55*0a6a1f1dSLionel Sambuc array_with_align_attr F3;
56*0a6a1f1dSLionel Sambuc char f3[__alignof__(F3) == 16 ? 1 : -1] = { 0 };
57