@@ -38,42 +38,44 @@ along with GCC; see the file COPYING3. If not see
38
38
* future.
39
39
*/
40
40
41
- extern const attribute_spec grs_langhook_common_attribute_table[];
41
+ extern const struct scoped_attribute_specs grs_langhook_gnu_attribute_table;
42
+ extern const struct scoped_attribute_specs grs_langhook_common_attribute_table;
43
+
44
+ /* clang-format off */
45
+ /* Disable clang-format because it insists in having the return type on a
46
+ single line (that's for definitions) */
42
47
43
48
/* Internal attribute handlers for built-in functions. */
44
- static tree
45
- handle_noreturn_attribute (tree *, tree, tree, int , bool *);
46
- static tree
47
- handle_leaf_attribute (tree *, tree, tree, int , bool *);
48
- static tree
49
- handle_const_attribute (tree *, tree, tree, int , bool *);
50
- static tree
51
- handle_malloc_attribute (tree *, tree, tree, int , bool *);
52
- static tree
53
- handle_pure_attribute (tree *, tree, tree, int , bool *);
54
- static tree
55
- handle_novops_attribute (tree *, tree, tree, int , bool *);
56
- static tree
57
- handle_nonnull_attribute (tree *, tree, tree, int , bool *);
58
- static tree
59
- handle_nothrow_attribute (tree *, tree, tree, int , bool *);
60
- static tree
61
- handle_type_generic_attribute (tree *, tree, tree, int , bool *);
62
- static tree
63
- handle_transaction_pure_attribute (tree *, tree, tree, int , bool *);
64
- static tree
65
- handle_returns_twice_attribute (tree *, tree, tree, int , bool *);
66
- static tree
67
- handle_fnspec_attribute (tree *, tree, tree, int , bool *);
68
- static tree
69
- handle_omp_declare_simd_attribute (tree *, tree, tree, int , bool *);
49
+ static tree handle_noreturn_attribute (tree *, tree, tree, int , bool *);
50
+ static tree handle_leaf_attribute (tree *, tree, tree, int , bool *);
51
+ static tree handle_const_attribute (tree *, tree, tree, int , bool *);
52
+ static tree handle_malloc_attribute (tree *, tree, tree, int , bool *);
53
+ static tree handle_pure_attribute (tree *, tree, tree, int , bool *);
54
+ static tree handle_novops_attribute (tree *, tree, tree, int , bool *);
55
+ static tree handle_nonnull_attribute (tree *, tree, tree, int , bool *);
56
+ static tree handle_nothrow_attribute (tree *, tree, tree, int , bool *);
57
+ static tree handle_type_generic_attribute (tree *, tree, tree, int , bool *);
58
+ static tree handle_transaction_pure_attribute (tree *, tree, tree, int , bool *);
59
+ static tree handle_returns_twice_attribute (tree *, tree, tree, int , bool *);
60
+ static tree handle_fnspec_attribute (tree *, tree, tree, int , bool *);
61
+ static tree handle_omp_declare_simd_attribute (tree *, tree, tree, int , bool *);
62
+
63
+ /* Rust attribute handlers for user defined attributes. */
64
+ static tree handle_cold_attribute (tree *, tree, tree, int , bool *);
65
+ static tree handle_hot_attribute (tree *, tree, tree, int , bool *);
66
+
67
+ /* clang-format on */
70
68
71
69
/* Helper to define attribute exclusions. */
72
70
#define ATTR_EXCL (name, function, type, variable ) \
73
71
{ \
74
72
name, function, type, variable \
75
73
}
76
74
75
+ // clang-format off
76
+ // Disabling clang-format because it insists in having several ATTR_EXCL() on a
77
+ // single line.
78
+
77
79
static const struct attribute_spec ::exclusions attr_noreturn_exclusions[] = {
78
80
// ATTR_EXCL ("alloc_size", true, true, true),
79
81
ATTR_EXCL (" const" , true , true , true ),
@@ -89,11 +91,22 @@ static const struct attribute_spec::exclusions attr_returns_twice_exclusions[]
89
91
ATTR_EXCL (NULL , false , false , false ),
90
92
};
91
93
94
+ extern const struct attribute_spec ::exclusions attr_cold_hot_exclusions[] = {
95
+
96
+ ATTR_EXCL (" cold" , true , true , true ),
97
+ ATTR_EXCL (" hot" , true , true , true ),
98
+ ATTR_EXCL (NULL , false , false , false )
99
+ };
100
+
92
101
static const struct attribute_spec ::exclusions attr_const_pure_exclusions[] = {
93
102
// ATTR_EXCL ("alloc_size", true, true, true),
94
103
ATTR_EXCL (" const" , true , true , true ),
95
104
ATTR_EXCL (" noreturn" , true , true , true ),
96
- ATTR_EXCL (" pure" , true , true , true ), ATTR_EXCL (NULL , false , false , false )};
105
+ ATTR_EXCL (" pure" , true , true , true ),
106
+ ATTR_EXCL (NULL , false , false , false )
107
+ };
108
+
109
+ // clang-format on
97
110
98
111
/* Helper to define an attribute. */
99
112
#define ATTR_SPEC (name, min_len, max_len, decl_req, type_req, fn_type_req, \
@@ -105,7 +118,7 @@ static const struct attribute_spec::exclusions attr_const_pure_exclusions[] = {
105
118
106
119
/* Table of machine-independent attributes.
107
120
For internal use (marking of built-ins) only. */
108
- const attribute_spec grs_langhook_common_attribute_table [] = {
121
+ static const attribute_spec grs_langhook_common_attributes [] = {
109
122
ATTR_SPEC (" noreturn" , 0 , 0 , true , false , false , false ,
110
123
handle_noreturn_attribute, attr_noreturn_exclusions),
111
124
ATTR_SPEC (" leaf" , 0 , 0 , true , false , false , false , handle_leaf_attribute,
@@ -132,9 +145,21 @@ const attribute_spec grs_langhook_common_attribute_table[] = {
132
145
NULL ),
133
146
ATTR_SPEC (" omp declare simd" , 0 , -1 , true , false , false , false ,
134
147
handle_omp_declare_simd_attribute, NULL ),
135
- ATTR_SPEC (NULL , 0 , 0 , false , false , false , false , NULL , NULL ),
136
148
};
137
149
150
+ const scoped_attribute_specs grs_langhook_common_attribute_table
151
+ = {" gnu" , {grs_langhook_common_attributes}};
152
+
153
+ static const attribute_spec grs_langhook_gnu_attributes[] = {
154
+ ATTR_SPEC (" cold" , 0 , 0 , true , false , false , false , handle_cold_attribute,
155
+ attr_cold_hot_exclusions),
156
+ ATTR_SPEC (" hot" , 0 , 0 , true , false , false , false , handle_hot_attribute,
157
+ attr_cold_hot_exclusions),
158
+ };
159
+
160
+ const scoped_attribute_specs grs_langhook_gnu_attribute_table
161
+ = {" gnu" , {grs_langhook_gnu_attributes}};
162
+
138
163
/* Built-in attribute handlers.
139
164
These functions take the arguments:
140
165
(tree *node, tree name, tree args, int flags, bool *no_add_attrs) */
@@ -204,7 +229,7 @@ handle_const_attribute (tree *node, tree, tree, int, bool *)
204
229
/* Handle a "malloc" attribute; arguments as in
205
230
struct attribute_spec.handler. */
206
231
207
- tree
232
+ static tree
208
233
handle_malloc_attribute (tree *node, tree, tree, int , bool *)
209
234
{
210
235
gcc_assert (TREE_CODE (*node) == FUNCTION_DECL
@@ -217,9 +242,14 @@ handle_malloc_attribute (tree *node, tree, tree, int, bool *)
217
242
struct attribute_spec.handler. */
218
243
219
244
static tree
220
- handle_pure_attribute (tree *node, tree, tree, int , bool *)
245
+ handle_pure_attribute (tree *node, tree name , tree, int , bool *no_add_attrs )
221
246
{
222
- gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
247
+ if (TREE_CODE (*node) != FUNCTION_DECL)
248
+ {
249
+ warning (OPT_Wattributes, " %qE attribute ignored" , name);
250
+ *no_add_attrs = true ;
251
+ }
252
+
223
253
DECL_PURE_P (*node) = 1 ;
224
254
return NULL_TREE;
225
255
}
@@ -228,9 +258,14 @@ handle_pure_attribute (tree *node, tree, tree, int, bool *)
228
258
struct attribute_spec.handler. */
229
259
230
260
static tree
231
- handle_novops_attribute (tree *node, tree, tree, int , bool *)
261
+ handle_novops_attribute (tree *node, tree name , tree, int , bool *no_add_attrs )
232
262
{
233
- gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
263
+ if (TREE_CODE (*node) != FUNCTION_DECL)
264
+ {
265
+ warning (OPT_Wattributes, " %qE attribute ignored" , name);
266
+ *no_add_attrs = true ;
267
+ }
268
+
234
269
DECL_IS_NOVOPS (*node) = 1 ;
235
270
return NULL_TREE;
236
271
}
@@ -301,9 +336,14 @@ handle_nonnull_attribute (tree *node, tree, tree args, int, bool *)
301
336
struct attribute_spec.handler. */
302
337
303
338
static tree
304
- handle_nothrow_attribute (tree *node, tree, tree, int , bool *)
339
+ handle_nothrow_attribute (tree *node, tree name , tree, int , bool *no_add_attrs )
305
340
{
306
- gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
341
+ if (TREE_CODE (*node) != FUNCTION_DECL)
342
+ {
343
+ warning (OPT_Wattributes, " %qE attribute ignored" , name);
344
+ *no_add_attrs = true ;
345
+ }
346
+
307
347
TREE_NOTHROW (*node) = 1 ;
308
348
return NULL_TREE;
309
349
}
@@ -339,9 +379,14 @@ handle_transaction_pure_attribute (tree *node, tree, tree, int, bool *)
339
379
struct attribute_spec.handler. */
340
380
341
381
static tree
342
- handle_returns_twice_attribute (tree *node, tree, tree, int , bool *)
382
+ handle_returns_twice_attribute (tree *node, tree name, tree, int ,
383
+ bool *no_add_attrs)
343
384
{
344
- gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
385
+ if (TREE_CODE (*node) != FUNCTION_DECL)
386
+ {
387
+ warning (OPT_Wattributes, " %qE attribute ignored" , name);
388
+ *no_add_attrs = true ;
389
+ }
345
390
346
391
DECL_IS_RETURNS_TWICE (*node) = 1 ;
347
392
@@ -351,7 +396,7 @@ handle_returns_twice_attribute (tree *node, tree, tree, int, bool *)
351
396
/* Handle a "fn spec" attribute; arguments as in
352
397
struct attribute_spec.handler. */
353
398
354
- tree
399
+ static tree
355
400
handle_fnspec_attribute (tree *, tree, tree args, int , bool *)
356
401
{
357
402
gcc_assert (args && TREE_CODE (TREE_VALUE (args)) == STRING_CST
@@ -362,9 +407,46 @@ handle_fnspec_attribute (tree *, tree, tree args, int, bool *)
362
407
/* Handle an "omp declare simd" attribute; arguments as in
363
408
struct attribute_spec.handler. */
364
409
365
- tree
366
- handle_omp_declare_simd_attribute (tree *node, tree, tree, int , bool *)
410
+ static tree
411
+ handle_omp_declare_simd_attribute (tree *node, tree name, tree, int ,
412
+ bool *no_add_attrs)
413
+ {
414
+ if (TREE_CODE (*node) != FUNCTION_DECL)
415
+ {
416
+ warning (OPT_Wattributes, " %qE attribute ignored" , name);
417
+ *no_add_attrs = true ;
418
+ }
419
+
420
+ return NULL_TREE;
421
+ }
422
+
423
+ /* Language specific attribute handlers.
424
+ These functions take the arguments:
425
+ (tree *node, tree name, tree args, int flags, bool *no_add_attrs) */
426
+
427
+ /* Handle a "cold" and attribute; arguments as in
428
+ struct attribute_spec.handler. */
429
+
430
+ static tree
431
+ handle_cold_attribute (tree *node, tree name, tree, int , bool *no_add_attrs)
367
432
{
368
- gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
433
+ if (TREE_CODE (*node) != FUNCTION_DECL)
434
+ {
435
+ warning (OPT_Wattributes, " %qE attribute ignored" , name);
436
+ *no_add_attrs = true ;
437
+ }
438
+
439
+ return NULL_TREE;
440
+ }
441
+
442
+ static tree
443
+ handle_hot_attribute (tree *node, tree name, tree, int , bool *no_add_attrs)
444
+ {
445
+ if (TREE_CODE (*node) != FUNCTION_DECL)
446
+ {
447
+ warning (OPT_Wattributes, " %qE attribute ignored" , name);
448
+ *no_add_attrs = true ;
449
+ }
450
+
369
451
return NULL_TREE;
370
452
}
0 commit comments