| 1 |
/* PR middle-end/81824 - Warn for missing attributes with function aliases |
| 2 |
Exercise attribute copy for variables. |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-O2 -Wall" } */ |
| 5 |
|
| 6 |
#define ATTR(list) __attribute__ (list) |
| 7 |
|
| 8 |
/* Verify that referencing a symbol with no attributes is accepted |
| 9 |
with no diagnostics. */ |
| 10 |
|
| 11 |
int ref0; |
| 12 |
|
| 13 |
ATTR ((copy (ref0))) long |
| 14 |
var0; |
| 15 |
|
| 16 |
/* Verify that referencing a symbol using the address-of and dereferencing |
| 17 |
operators is also accepted with no diagnostics. */ |
| 18 |
|
| 19 |
ATTR ((copy (&ref0))) void* ptr0; |
| 20 |
ATTR ((copy (*&ref0))) int arr[1]; |
| 21 |
|
| 22 |
/* Verify that referencing a symbol of a different kind than that |
| 23 |
of the one the attribute is applied to is diagnosed. */ |
| 24 |
|
| 25 |
int ref1; /* { dg-message "previous declaration here" } */ |
| 26 |
|
| 27 |
ATTR ((copy (ref1))) int |
| 28 |
ref1; /* { dg-warning ".copy. attribute ignored on a redeclaration of the referenced symbol " } */ |
| 29 |
|
| 30 |
|
| 31 |
/* Verify that circular references of the copy variable attribute |
| 32 |
are handled gracefully (i.e., not by getting into an infinite |
| 33 |
recursion) by issuing a diagnostic. */ |
| 34 |
|
| 35 |
char xref1; |
| 36 |
ATTR ((copy (xref1))) char |
| 37 |
xref1; /* { dg-warning ".copy. attribute ignored on a redeclaration of the referenced symbol" } */ |
| 38 |
ATTR ((copy (xref1))) char |
| 39 |
xref1; /* { dg-warning ".copy. attribute ignored on a redeclaration of the referenced symbol" } */ |
| 40 |
ATTR ((copy (xref1), copy (xref1))) char |
| 41 |
xref1; /* { dg-warning ".copy. attribute ignored on a redeclaration of the referenced symbol" } */ |
| 42 |
|
| 43 |
|
| 44 |
/* Use attribute unused to verify that circular references propagate |
| 45 |
atttibutes as expected (expect no warnings the circular reference |
| 46 |
or for any of the unused symbols). Also use the address-of operator |
| 47 |
to make sure it doesn't change anything. */ |
| 48 |
|
| 49 |
static ATTR ((unused)) int xref2; |
| 50 |
static ATTR ((copy (xref2))) int xref3; |
| 51 |
static ATTR ((copy (&xref3))) int xref4; |
| 52 |
static ATTR ((copy (xref4))) int xref5; |
| 53 |
static ATTR ((copy (&xref5))) int xref6; |
| 54 |
static ATTR ((copy (xref6))) int xref7; |
| 55 |
static ATTR ((copy (&xref7))) int xref8; |
| 56 |
static ATTR ((copy (xref8))) int xref9; |
| 57 |
static ATTR ((copy (&xref9))) int xref2; |
| 58 |
|
| 59 |
/* Verify that attribute exclusions apply. */ |
| 60 |
|
| 61 |
ATTR ((common)) int common_var; |
| 62 |
ATTR ((nocommon)) double nocommon_var; |
| 63 |
|
| 64 |
ATTR ((copy (common_var), copy (nocommon_var))) long |
| 65 |
common_copy; /* { dg-warning "ignoring attribute .nocommon. because it conflicts with attribute .common." } */ |
| 66 |
|
| 67 |
|
| 68 |
/* Verify that attribute deprecated isn't copied. */ |
| 69 |
|
| 70 |
ATTR ((deprecated)) char deprecated_var; |
| 71 |
|
| 72 |
ATTR ((copy (deprecated_var))) int current_var; /* { dg-warning "\\\[-Wdeprecated-declarations]" } */ |
| 73 |
ATTR ((copy (current_var))) int current_var_2; |
| 74 |
|
| 75 |
int return_current_vars (void) { return current_var + current_var_2; } |