| 1 |
/* PR middle-end/81824 - Warn for missing attributes with function aliases |
| 2 |
Exercise attribute copy for types. |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */ |
| 5 |
|
| 6 |
#define Assert(expr) typedef char AssertExpr[2 * !!(expr) - 1] |
| 7 |
|
| 8 |
#define ATTR(list) __attribute__ (list) |
| 9 |
|
| 10 |
/* Use attribute packed to verify that type attributes are copied |
| 11 |
from one type to another. */ |
| 12 |
|
| 13 |
struct ATTR ((packed)) PackedA { int i; char c; }; |
| 14 |
|
| 15 |
Assert (__alignof (struct PackedA) == 1); |
| 16 |
|
| 17 |
struct ATTR ((copy ((struct PackedA*)0))) PackedB { long i; char c; }; |
| 18 |
|
| 19 |
Assert (__alignof (struct PackedA) == __alignof (struct PackedB)); |
| 20 |
|
| 21 |
struct PackedMember |
| 22 |
{ |
| 23 |
char c; |
| 24 |
ATTR ((copy ((struct PackedB*)0))) double packed_mem; |
| 25 |
/* { dg-warning "attribute ignored" "" { target default_packed } .-1 } */ |
| 26 |
}; |
| 27 |
|
| 28 |
Assert (__alignof (struct PackedMember) == 1); |
| 29 |
|
| 30 |
|
| 31 |
extern const struct PackedA packed; |
| 32 |
|
| 33 |
struct Unpacked { int i; char c; }; |
| 34 |
Assert (__alignof (struct Unpacked) > 1); |
| 35 |
/* { dg-error "size of array .* is negative" "" { target default_packed } .-1 } */ |
| 36 |
|
| 37 |
/* Verify that copying the packed attribute to the declaration |
| 38 |
of an object is ignored with a warning. (There should be |
| 39 |
a way to copy just the subset of attributes from a type that |
| 40 |
aren't ignored and won't cause a warning, maybe via attribute |
| 41 |
copy_except or something like that.) */ |
| 42 |
extern ATTR ((copy ((struct PackedA*)0))) const struct Unpacked |
| 43 |
unpacked; /* { dg-warning ".packed. attribute ignored" } */ |
| 44 |
|
| 45 |
Assert (__alignof (packed) == 1); |
| 46 |
Assert (__alignof (unpacked) == __alignof (struct Unpacked)); |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
/* Verify that attribute deprecated isn't copied (but referencing |
| 51 |
the deprecated type in the copy attribute still triggers a warning). */ |
| 52 |
|
| 53 |
struct ATTR ((aligned (8), deprecated)) |
| 54 |
AlignedDeprecated { char c; }; |
| 55 |
|
| 56 |
struct ATTR ((copy ((struct AlignedDeprecated *)0))) /* { dg-warning "\\\[-Wdeprecated-declarations]" } */ |
| 57 |
AlignedCopy { short s; }; |
| 58 |
|
| 59 |
Assert (__alignof (struct AlignedCopy) == 8); |
| 60 |
|
| 61 |
struct AlignedCopy aligned_copy; |
| 62 |
|
| 63 |
Assert (__alignof (aligned_copy) == 8); |