131
|
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" } */
|
|
28 int b ATTR ((aligned (2), packed)); /* { dg-bogus "\\\[-Wattributes" } */
|
|
29
|
|
30 /* Avoid exercising this since the attribute has no effect yet
|
|
31 there is no warning.
|
|
32 int c ATTR ((aligned (2))); // missing warning? */
|
|
33 } s;
|
|
34
|
|
35 ASSERT (_Alignof (s.a) == 2);
|
|
36 ASSERT (_Alignof (s.b) == 2);
|
|
37
|
|
38 /* ASSERT (_Alignof (s.c) == 4); */
|