2018-11-28 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / attr-copy-3.c
blob88e5e5ed21595da1b0eef78051c53549f10225c6
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" } */
6 #define ATTR(list) __attribute__ (list)
8 /* Verify that referencing a symbol with no attributes is accepted
9 with no diagnostics. */
11 int ref0;
13 ATTR ((copy (ref0))) long
14 var0;
16 /* Verify that referencing a symbol using the address-of and dereferencing
17 operators is also accepted with no diagnostics. */
19 ATTR ((copy (&ref0))) void* ptr0;
20 ATTR ((copy (*&ref0))) int arr[1];
22 /* Verify that referencing a symbol of a different kind than that
23 of the one the attribute is applied to is diagnosed. */
25 int ref1; /* { dg-message "previous declaration here" } */
27 ATTR ((copy (ref1))) int
28 ref1; /* { dg-warning ".copy. attribute ignored on a redeclaration of the referenced symbol " } */
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. */
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" } */
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. */
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;
59 /* Verify that attribute exclusions apply. */
61 ATTR ((common)) int common_var;
62 ATTR ((nocommon)) double nocommon_var;
64 ATTR ((copy (common_var), copy (nocommon_var))) long
65 common_copy; /* { dg-warning "ignoring attribute .nocommon. because it conflicts with attribute .common." } */
68 /* Verify that attribute deprecated isn't copied. */
70 ATTR ((deprecated)) char deprecated_var;
72 ATTR ((copy (deprecated_var))) int current_var; /* { dg-warning "\\\[-Wdeprecated-declarations]" } */
73 ATTR ((copy (current_var))) int current_var_2;
75 int return_current_vars (void) { return current_var + current_var_2; }