source: tests/attributes.cfa @ 62b5940

Last change on this file since 62b5940 was cd28605, checked in by Peter A. Buhr <pabuhr@…>, 7 weeks ago

first attempt at generalizing attributes to statements

  • Property mode set to 100644
File size: 11.6 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// attributes.cfa --
8//
9// Author           : Peter A. Buhr
10// Created On       : Mon Feb  6 16:07:02 2017
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Thu Feb  6 12:06:22 2025
13// Update Count     : 117
14//
15
16#pragma GCC diagnostic ignored "-Wattributes"
17
18// label attribute
19int la() {
20  L: __attribute__(( unused )) 1;
21  return 1;
22}
23
24
25// aggregate_name
26static struct __attribute__(( unused )) {} Dummy;
27struct __attribute__(( unused )) Agn1;
28struct __attribute__(( unused )) Agn2 {};
29enum __attribute__(( unused )) { E1 };
30enum __attribute__(( unused )) Agn3;
31enum __attribute__(( packed )) Agn3 { E2 };
32#ifdef __CFA__
33struct __attribute__(( unused )) {} ( int );
34struct __attribute__(( unused )) Agn4 {} ( int );
35#endif // __CFA__
36
37
38// field_declaring_list
39typedef short int shint;
40struct Fdl {
41    int f1 __attribute__(( unused ));
42    int __attribute__(( unused )) f2;
43    int __attribute__(( unused )) f3 __attribute__(( unused ));
44    __attribute__(( unused )) int f4;
45    __attribute__(( unused )) int f5 __attribute__(( unused ));
46    __attribute__(( used )) int f6 __attribute__(( packed )), f7 __attribute__(( unused )) __attribute__(( unused )), __attribute__(( used )) f8 __attribute__(( unused ));
47    int * f9 __attribute__(( unused ));
48    __attribute__(( used )) int __attribute__(( unused )) * f10;
49    int ( ( * f11 __attribute__(( unused )) ) __attribute__(( unused )) );
50    int ( ( __attribute__(( unused )) * f12  __attribute__(( unused )) ) __attribute__(( unused )) );
51    int ( ( __attribute__(( unused )) * (f13)  __attribute__(( unused )) ) __attribute__(( unused )) );
52    int ( ( ( __attribute__(( unused )) * (f14) )  __attribute__(( unused )) ) __attribute__(( unused )) );
53//      shint __attribute__(( used )) shi1;
54//      shint __attribute__(( used )) shi2 __attribute__(( used ));
55        __attribute__(( used )) shint shi3;
56        __attribute__(( used )) shint shi4 __attribute__(( used ));
57//      __attribute__(( used )) shint __attribute__(( used )) shi5 __attribute__(( used ));
58};
59
60
61// asm_name_opt
62int f() asm( "xyz" ) __attribute__(( unused ));
63
64
65// variable_declarator
66const __attribute__(( used )) int vd1 __attribute__(( used )), __attribute__(( unused )) vd2;
67const __attribute__(( used )) int __attribute__(( used )) * __attribute__(( used )) vd3 __attribute__(( used )), __attribute__(( unused )) (* __attribute__(( unused )) (vd4)) __attribute__(( used ));
68const __attribute__(( used )) int __attribute__(( used )) vd5[5] __attribute__(( used )), __attribute__(( unused )) ((vd6)[5]) __attribute__(( used ));
69const __attribute__(( used )) int __attribute__(( used )) (* __attribute__(( used )) vd7)() __attribute__(( used )), __attribute__(( unused )) ((* __attribute__(( used )) vd8)()) __attribute__(( used ));
70const __attribute__(( used )) int __attribute__(( used )) ( __attribute__(( used )) * vd9)() __attribute__(( used )), __attribute__(( unused )) (( __attribute__(( used )) * vd10)()) __attribute__(( used ));
71
72
73// function_declarator
74__attribute__(( unused )) int f1() __attribute__(( used ));
75__attribute__(( unused )) int f1() { return 1; }
76__attribute__(( unused )) int * __attribute__(( unused )) * const __attribute__(( unused )) f2() __attribute__(( used ));
77__attribute__(( unused )) int * __attribute__(( unused )) * const __attribute__(( unused )) f2() { return 0p; }
78__attribute__(( unused )) int (* __attribute__(( unused )) f3(int))[] __attribute__(( used ));
79__attribute__(( unused )) int ( __attribute__(( unused )) * __attribute__(( unused )) f4(int))[] __attribute__(( used ));
80__attribute__(( unused )) int (* __attribute__(( unused )) f5(int p))[] { (void)p; return 0p; }
81__attribute__(( unused )) int ( __attribute__(( unused )) * (f6)(int p))[] { (void)p; return 0p; }
82__attribute__(( unused )) int (* __attribute__(( unused )) f7())(int) __attribute__(( used ));
83__attribute__(( unused )) int (* __attribute__(( unused )) f8())(int) { return 0p; }
84__attribute__(( unused )) int ( __attribute__(( unused )) * f9())(int) { return 0p; }
85__attribute__(( unused )) int ( __attribute__(( unused )) * (f10)())(int) { return 0p; }
86
87
88// variable_type_redeclarator
89typedef int t1, t2, t3, t4, t5, t6, t7, t8;
90void vtr() {
91    // redefine typedef name in new scope
92    __attribute__(( unused )) int __attribute__(( unused )) t1 __attribute__(( used ));
93    __attribute__(( unused )) int __attribute__(( unused )) (* (* t2 __attribute__(( unused )) ) __attribute__(( unused )) ) __attribute__(( unused ));
94    __attribute__(( unused )) int __attribute__(( unused )) t3[5] __attribute__(( unused ));
95    __attribute__(( unused )) int __attribute__(( unused )) (* (* __attribute__(( unused )) t4[5]) __attribute__(( unused )) ) __attribute__(( unused ));
96    __attribute__(( unused )) int __attribute__(( unused )) ( __attribute__(( unused )) * ( __attribute__(( unused )) * t5[5]) __attribute__(( unused )) ) __attribute__(( unused ));
97    __attribute__(( unused )) int __attribute__(( unused )) t6() __attribute__(( unused ));
98    __attribute__(( unused )) int __attribute__(( unused )) * __attribute__(( unused )) ((t6))() __attribute__(( unused ));
99}
100
101// identifier_parameter_declarator
102void ipd1( __attribute__(( unused )) int __attribute__(( unused )) p __attribute__(( unused )),
103          __attribute__(( unused )) int __attribute__(( unused )) q __attribute__(( unused )) );
104void ipd1( __attribute__(( unused )) int __attribute__(( unused )) p __attribute__(( unused )),
105          __attribute__(( unused )) int __attribute__(( unused )) q __attribute__(( unused )) ) {}
106void ipd2( __attribute__(( unused )) int __attribute__(( unused )) * __attribute__(( unused )) p __attribute__(( unused )),
107          __attribute__(( unused )) int __attribute__(( unused )) (* (q)) __attribute__(( unused )) );
108void ipd2( __attribute__(( unused )) int __attribute__(( unused )) * __attribute__(( unused )) p __attribute__(( unused )),
109          __attribute__(( unused )) int __attribute__(( unused )) (* (q)) __attribute__(( unused )) ) {}
110void ipd3( __attribute__(( unused )) int __attribute__(( unused )) p[] __attribute__(( unused )),
111          __attribute__(( unused )) int __attribute__(( unused )) ((q)[]) __attribute__(( unused )) );
112void ipd3( __attribute__(( unused )) int __attribute__(( unused )) p[] __attribute__(( unused )),
113          __attribute__(( unused )) int __attribute__(( unused )) ((q)[]) __attribute__(( unused )) ) {}
114void ipd4( __attribute__(( unused )) int __attribute__(( unused )) p() __attribute__(( unused )),
115          __attribute__(( unused )) int __attribute__(( unused )) ((q)()) __attribute__(( unused )) );
116void ipd4( __attribute__(( unused )) int __attribute__(( unused )) p() __attribute__(( unused )),
117          __attribute__(( unused )) int __attribute__(( unused )) ((q)()) __attribute__(( unused )) ) {}
118
119
120// type_parameter_redeclarator
121typedef int Foo;
122int tpr1( __attribute__(( unused )) int __attribute__(( unused )) Foo __attribute__(( unused )) );
123int tpr2( __attribute__(( unused )) int __attribute__(( unused )) (* __attribute__(( unused )) (* __attribute__(( unused )) Foo) __attribute__(( unused )) ) __attribute__(( unused )) );
124int tpr3( __attribute__(( unused )) int __attribute__(( unused )) Foo[]  __attribute__(( unused )));
125int tpr4( __attribute__(( unused )) int __attribute__(( unused )) ( __attribute__(( unused )) Foo[5] __attribute__(( unused )) ) );
126int tpr5( __attribute__(( unused )) int __attribute__(( unused )) (*Foo)() __attribute__(( unused )) );
127int tpr6( __attribute__(( unused )) int __attribute__(( unused )) Foo() __attribute__(( unused )) );
128int tpr7( __attribute__(( unused )) int __attribute__(( unused )) ( __attribute__(( unused )) Foo( __attribute__(( unused )) int __attribute__(( unused )) ) ) );
129
130
131// abstract_declarator
132void ad() {
133    typeof( int __attribute__(( used )) ) ad1 __attribute__(( unused ));
134    typeof( int __attribute__(( unused )) * __attribute__(( unused )) ) ad2 __attribute__(( unused ));
135    typeof( int __attribute__(( unused )) [5] ) __attribute__(( unused )) ad3 __attribute__(( unused ));
136    typeof( __attribute__(( unused )) int __attribute__(( unused )) (*)[10] __attribute__(( unused )) ) __attribute__(( unused )) ad4 __attribute__(( unused )), ad5 __attribute__(( used ));
137    typeof( __attribute__(( unused )) int __attribute__(( unused )) () __attribute__(( unused )) ) __attribute__(( unused )) ad6 __attribute__(( unused ));
138    sizeof( __attribute__(( unused )) int __attribute__(( unused )) );
139    sizeof( __attribute__(( unused )) int __attribute__(( unused )) (* __attribute__(( unused )) (* __attribute__(( unused )) ) ) );
140    sizeof( __attribute__(( unused )) int __attribute__(( unused )) [5] __attribute__(( unused )) );
141    sizeof( __attribute__(( unused )) int __attribute__(( unused )) (*)[10] __attribute__(( unused )) );
142    sizeof( __attribute__(( unused )) int __attribute__(( unused )) () __attribute__(( unused )) );
143    sizeof( struct { int i; } __attribute__(( unused )) );
144    sizeof( enum { R } __attribute__(( unused )) );
145}
146
147
148// abstract_parameter_declarator
149int apd1( __attribute__(( unused )) int __attribute__(( unused )) * __attribute__(( unused )),
150        __attribute__(( unused )) int __attribute__(( unused )) * __attribute__(( unused )) );
151int apd2( __attribute__(( unused )) int __attribute__(( unused )) (* (* __attribute__(( unused )) ) __attribute__(( unused )) ),
152        __attribute__(( unused )) int __attribute__(( unused )) (* (* __attribute__(( unused )) ) __attribute__(( unused )) ) );
153int apd3( __attribute__(( unused )) int __attribute__(( unused )) ([]) __attribute__(( unused )),
154        __attribute__(( unused )) int __attribute__(( unused )) ([]) __attribute__(( unused )) );
155int apd4( __attribute__(( unused )) int __attribute__(( unused )) ()  __attribute__(( unused )),
156        __attribute__(( unused )) int __attribute__(( unused )) ()  __attribute__(( unused )) );
157int apd5( __attribute__(( unused )) int __attribute__(( unused )) (( __attribute__(( unused )) int )) __attribute__(( unused )),
158        __attribute__(( unused )) int __attribute__(( unused )) ( __attribute__(( unused )) int ) __attribute__(( unused )) );
159int apd6( __attribute__(( unused )) int __attribute__(( unused )) (*)()  __attribute__(( unused )),
160        __attribute__(( unused )) int __attribute__(( unused )) (*)()  __attribute__(( unused )) );
161int apd7( __attribute__(( unused )) int __attribute__(( unused )) ((*)( __attribute__(( unused )) int ) ) __attribute__(( unused )),
162        __attribute__(( unused )) int __attribute__(( unused )) ((*)( __attribute__(( unused )) int ) ) __attribute__(( unused )) );
163
164
165// variable_abstract_declarator
166struct Vad {
167    int __attribute__(( unused )) x;
168    int __attribute__(( unused )) :4;
169    int __attribute__(( unused )) :4, __attribute__(( unused )) :6;
170};
171
172
173// statments
174void fred() {
175        int [[unused]] i;
176        // C23 attributes are parsed but not pushed through the compiler.
177        // int [[gnu::xxx]] j;
178        switch ( 3 ) {
179                __attribute__((unused)) int ret;
180          case 2:
181                4;
182                __attribute__(( fallthrough ));
183                [[fallthrough]];
184          case 1:
185                3;
186        }
187  L : __attribute__(( unused )) goto L;
188  L1 : [[ unused ]] L2 : [[ unused ]] goto L2;
189        __attribute__(( unused )) return;
190        [[ noreturn ]] return;
191        __attribute__(( noreturn )) return;
192        [[ GNU::fred ]] i += 1;
193}
194
195void mary() {
196        @[aligned(64)] struct S { int i; };
197        int @[unused] i;
198        switch ( 3 ) {
199          case 2:
200                4;
201                __attribute__(( fallthrough ));
202                @[fallthrough];
203          case 1:
204                3;
205        }
206  L : __attribute__(( unused )) goto L;
207  L1 : @[ unused ] L2 : @[ unused ] goto L2;
208        __attribute__(( unused )) return;
209        @[ noreturn ] return;
210        __attribute__(( noreturn )) return;
211}
212
213[[ noreturn ]] void jack() {
214        exit( -1 );
215}
216
217// Local Variables: //
218// tab-width: 4 //
219// compile-command: "cfa attributes.cfa" //
220// End: //
Note: See TracBrowser for help on using the repository browser.