Fri Jul 9 18:55:28 2021 UTC ()
tests/lint: ensure that GCC __attribute__ can be parsed


(rillig)
diff -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/gcc_attribute.c

cvs diff -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/gcc_attribute.c (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/gcc_attribute.c 2021/07/06 18:43:27 1.8
+++ src/tests/usr.bin/xlint/lint1/gcc_attribute.c 2021/07/09 18:55:28 1.9
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: gcc_attribute.c,v 1.8 2021/07/06 18:43:27 rillig Exp $ */ 1/* $NetBSD: gcc_attribute.c,v 1.9 2021/07/09 18:55:28 rillig Exp $ */
2# 3 "gcc_attribute.c" 2# 3 "gcc_attribute.c"
3 3
4/* 4/*
5 * Tests for the various attributes for functions, types, statements that are 5 * Tests for the various attributes for functions, types, statements that are
6 * provided by GCC. 6 * provided by GCC.
7 * 7 *
8 * https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html 8 * https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
9 */ 9 */
10 10
11void __attribute__((noinline)) 11void __attribute__((noinline))
12do_not_inline(void) 12do_not_inline(void)
13{ 13{
14} 14}
@@ -74,13 +74,46 @@ func( @@ -74,13 +74,46 @@ func(
74 * No matter whether this particular example is interpreted as an empty list 74 * No matter whether this particular example is interpreted as an empty list
75 * or a list containing a single empty attribute, the result is the same in 75 * or a list containing a single empty attribute, the result is the same in
76 * both cases. 76 * both cases.
77 */ 77 */
78void one_empty_attribute(void) 78void one_empty_attribute(void)
79 __attribute__((/* none */)); 79 __attribute__((/* none */));
80 80
81/* 81/*
82 * https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html further says that 82 * https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html further says that
83 * each individual attribute may be "Empty. Empty attributes are ignored". 83 * each individual attribute may be "Empty. Empty attributes are ignored".
84 */ 84 */
85void two_empty_attributes(void) 85void two_empty_attributes(void)
86 __attribute__((/* none */, /* still none */)); 86 __attribute__((/* none */, /* still none */));
 87
 88/*
 89 * Ensure that __attribute__ can be specified everywhere in a declaration.
 90 * This is the simplest possible requirement that covers all valid code.
 91 * It accepts invalid code as well, but these cases are covered by GCC and
 92 * Clang already.
 93 *
 94 * Since lint only parses the attributes but doesn't really relate them to
 95 * identifiers or other entities, ensuring that valid code can be parsed is
 96 * enough for now.
 97 *
 98 * To really associate __attribute__ with the corresponding entity, the
 99 * grammar needs to be rewritten, see the example with __noreturn__ above.
 100 */
 101__attribute__((deprecated("d1")))
 102const
 103__attribute__((deprecated("d2")))
 104int
 105__attribute__((deprecated("d3")))
 106*
 107// The below line would produce a syntax error.
 108// __attribute__((deprecated("d3")))
 109const
 110__attribute__((deprecated("d4")))
 111identifier
 112__attribute__((deprecated("d5")))
 113(
 114 __attribute__((deprecated("d6")))
 115 void
 116 __attribute__((deprecated("d7")))
 117 )
 118 __attribute__((deprecated("d8")))
 119;