1 /* PR middle-end/84108 - incorrect -Wattributes warning for packed/aligned
2 conflict on struct members
3 { dg-do compile }
4 { dg-options "-Wall -Wattributes" } */
5
6 #define ATTR(list) __attribute__ (list)
7 #define ASSERT(e) _Static_assert (e, #e)
8
9 /* GCC is inconsistent in how it treats attribute aligned between
10 variable and member declarations. Attribute aligned alone is
11 sufficient to reduce a variable's alignment requirement but
12 the attribute must be paired with packed to have the same
13 effect on a member. Worse, declaring a variable both aligned
14 and packed emits a warning. */
15
16 /* Avoid exercising this since emitting a warning for these given
17 the requirement for members seems like a misfeature:
18 int a ATTR ((packed, aligned (2))); // -Wattributes
19 int b ATTR ((aligned (2), packed)); // -Wattributes
20 ASSERT (_Alignof (a) == 2);
21 ASSERT (_Alignof (b) == 2); */
22
23 int c ATTR ((aligned (2))); // okay (reduces alignment)
24 ASSERT (_Alignof (c) == 2);
25
26 struct {
27 int a ATTR ((packed, aligned (2))); /* { dg-bogus "\\\[-Wattributes" "" { target { ! default_packed } } } */
28 /* { dg-warning "attribute ignored" "" { target { default_packed } } .-1 } */
29 int b ATTR ((aligned (2), packed)); /* { dg-bogus "\\\[-Wattributes" "" { target { ! default_packed } } } */
30 /* { dg-warning "attribute ignored" "" { target { default_packed } } .-1 } */
31
32 /* Avoid exercising this since the attribute has no effect yet
33 there is no warning.
34 int c ATTR ((aligned (2))); // missing warning? */
35 } s;
36
37 ASSERT (_Alignof (s.a) == 2);
38 ASSERT (_Alignof (s.b) == 2);
39
40 /* ASSERT (_Alignof (s.c) == 4); */