xref: /netbsd-src/tests/usr.bin/xlint/lint1/gcc_attribute.c (revision 53d1339bf7f9c7367b35a9e1ebe693f9b047a47b)
1 /*	$NetBSD: gcc_attribute.c,v 1.5 2021/05/03 07:08:54 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  * https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
10  * https://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html
11  * https://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html
12  * https://gcc.gnu.org/onlinedocs/gcc/Enumerator-Attributes.html
13  * https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html
14  * https://gcc.gnu.org/onlinedocs/gcc/Label-Attributes.html
15  */
16 
17 void __attribute__((noinline))
18 do_not_inline(void)
19 {
20 }
21 
22 /* All pointer arguments must be nonnull. */
23 void __attribute__((nonnull))
24 function_nonnull(void *, const void *, int);
25 
26 /*
27  * The documentation suggests that the argument list of nonnull be nonempty,
28  * but GCC 9.3.0 accepts an empty list as well, treating all parameters as
29  * nonnull.
30  */
31 void __attribute__((nonnull()))
32 function_nonnull_list(void *, const void *, int);
33 
34 /* Arguments 1 and 2 must be nonnull. */
35 void __attribute__((nonnull(1, 2)))
36 function_nonnull_list(void *, const void *, int);
37 
38 /* expect+1: syntax error 'unknown_attribute' */
39 void __attribute__((unknown_attribute))
40 function_with_unknown_attribute(void);
41 
42 /*
43  * There is an attribute called 'pcs', but that attribute must not prevent an
44  * ordinary variable from being named the same.  Starting with scan.l 1.77
45  * from 2017-01-07, that variable name generated a syntax error.  Fixed in
46  * lex.c 1.33 from 2021-05-03.
47  *
48  * Seen in yds.c, function yds_allocate_slots.
49  */
50 int
51 local_variable_pcs(void)
52 {
53 	int pcs = 3;
54 	return pcs;
55 }
56