gcc_attribute.c revision 1.7 1 /* $NetBSD: gcc_attribute.c,v 1.7 2021/07/06 17:33:07 rillig Exp $ */
2 # 3 "gcc_attribute.c"
3
4 /*
5 * Tests for the various attributes for functions, types, statements that are
6 * provided by GCC.
7 *
8 * https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
9 */
10
11 void __attribute__((noinline))
12 do_not_inline(void)
13 {
14 }
15
16 /* All pointer arguments must be nonnull. */
17 void __attribute__((nonnull))
18 function_nonnull(void *, const void *, int);
19
20 /*
21 * The documentation suggests that the argument list of nonnull be nonempty,
22 * but GCC 9.3.0 accepts an empty list as well, treating all parameters as
23 * nonnull.
24 */
25 void __attribute__((nonnull()))
26 function_nonnull_list(void *, const void *, int);
27
28 /* Arguments 1 and 2 must be nonnull. */
29 void __attribute__((nonnull(1, 2)))
30 function_nonnull_list(void *, const void *, int);
31
32 /* expect+1: syntax error 'unknown_attribute' */
33 void __attribute__((unknown_attribute))
34 function_with_unknown_attribute(void);
35
36 /*
37 * There is an attribute called 'pcs', but that attribute must not prevent an
38 * ordinary variable from being named the same. Starting with scan.l 1.77
39 * from 2017-01-07, that variable name generated a syntax error. Fixed in
40 * lex.c 1.33 from 2021-05-03.
41 *
42 * Seen in yds.c, function yds_allocate_slots.
43 */
44 int
45 local_variable_pcs(void)
46 {
47 int pcs = 3;
48 return pcs;
49 }
50
51 /*
52 * FIXME: The attributes are handled by different grammar rules even though
53 * they occur in the same syntactical position.
54 *
55 * Grammar rule abstract_decl_param_list handles the first attribute.
56 *
57 * Grammar rule direct_abstract_declarator handles all remaining attributes.
58 *
59 * Since abstract_decl_param_list contains type_attribute_opt, this could be
60 * the source of the many shift/reduce conflicts in the grammar.
61 */
62 int
63 func(
64 int(int)
65 __attribute__((__noreturn__))
66 __attribute__((__noreturn__))
67 );
68