Debian Codegraph @

gcc/testsuite/gcc.target/aarch64/attr-aligned.c

raw
1 /* Verify that valid alignment on functions is accepted and results
2 in the alignment expected for the target and that alignment of
3 zero is ignored with a warning.
4 { dg-do compile }
5 { dg-options "-Wno-pedantic -ftrack-macro-expansion=0" } */
6
7 #define ASSERT(expr) _Static_assert (expr, #expr)
8 #define ALIGN(n) __attribute__ ((aligned (n)))
9 #define alignof(expr) __alignof__ (expr)
10 #define HAS_ALIGN(f, n) __builtin_has_attribute (f, __aligned__ (n))
11
12 #define MINALIGN(N) ((N) < 4 ? 4 : (N))
13 #define MAXALIGN 16
14
15 /* No alignment specified. */
16 void f (void) { }
17
18 /* Empty alignment means maximum. */
19 ALIGN () void f_ (void) { }
20
21 ALIGN (0) void f0 (void) { } /* { dg-warning "requested alignment .0. is not a positive power of 2" } */
22 ALIGN (1) void f1 (void) { }
23 ALIGN (2) void f2 (void) { }
24 ALIGN (4) void f4 (void) { }
25 ALIGN (8) void f8 (void) { }
26 ALIGN (16) void f16 (void) { }
27 ALIGN (32) void f32 (void) { }
28
29 ASSERT (alignof (f_) == MAXALIGN);
30 ASSERT (alignof (f0) == alignof (f));
31 ASSERT (alignof (f1) == MINALIGN (1));
32 ASSERT (alignof (f2) == MINALIGN (2));
33 ASSERT (alignof (f4) == MINALIGN (4));
34 ASSERT (alignof (f8) == MINALIGN (8));
35 ASSERT (alignof (f16) == MINALIGN (16));
36 ASSERT (alignof (f32) == MINALIGN (32));
37
38 ASSERT (!__builtin_has_attribute (f, aligned));
39 ASSERT (__builtin_has_attribute (f_, aligned));
40 ASSERT (!__builtin_has_attribute (f0, aligned));
41
42 ASSERT (!HAS_ALIGN (f_, MAXALIGN));
43
44 ASSERT (HAS_ALIGN (f1, 1));
45 ASSERT (!HAS_ALIGN (f1, 2));
46
47 ASSERT (!HAS_ALIGN (f2, 1));
48 ASSERT (HAS_ALIGN (f2, 2));
49 ASSERT (!HAS_ALIGN (f2, 4));
50
51 ASSERT (!HAS_ALIGN (f4, 2));
52 ASSERT (HAS_ALIGN (f4, 4));
53 ASSERT (!HAS_ALIGN (f4, 8));
54
55 ASSERT (!HAS_ALIGN (f8, 4));
56 ASSERT (HAS_ALIGN (f8, 8));
57 ASSERT (!HAS_ALIGN (f8, 16));
58
59 ASSERT (!HAS_ALIGN (f16, 8));
60 ASSERT (HAS_ALIGN (f16, 16));
61 ASSERT (!HAS_ALIGN (f16, 32));
62
63 ASSERT (!HAS_ALIGN (f32, 16));
64 ASSERT (HAS_ALIGN (f32, 32));
65 ASSERT (!HAS_ALIGN (f32, 64));