Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 lint: remove explicit list of known GCC ...
details: https://anonhg.NetBSD.org/src/rev/8ad701677b24
branches: trunk
changeset: 369638:8ad701677b24
user: rillig <rillig%NetBSD.org@localhost>
date: Thu Aug 25 19:03:47 2022 +0000
description:
lint: remove explicit list of known GCC attributes
Most GCC attributes consist of a single identifier. Up to now, it was
necessary to list each of these identifiers in the grammar, even those
that only apply to a single target architecture.
Instead, parse the general form of attributes, matching the few
attributes that lint handles by name instead. While here, rename the
grammar rules to use the GCC terms.
To avoid conflicts between the global function 'printf' and the GCC
attribute of the same name, do not add GCC attributes to the symbol
table, and don't make these symbols 'extern' either.
ok christos@.
diffstat:
tests/usr.bin/xlint/lint1/expr_precedence.c | 3 +-
tests/usr.bin/xlint/lint1/gcc_attribute.c | 7 +-
tests/usr.bin/xlint/lint1/gcc_attribute_type.c | 4 +-
tests/usr.bin/xlint/lint1/gcc_attribute_var.c | 4 +-
usr.bin/xlint/lint1/cgram.y | 216 +++++-------------------
usr.bin/xlint/lint1/lex.c | 96 ++---------
usr.bin/xlint/lint1/tree.c | 6 +-
7 files changed, 82 insertions(+), 254 deletions(-)
diffs (truncated from 614 to 300 lines):
diff -r 67ceef79cf17 -r 8ad701677b24 tests/usr.bin/xlint/lint1/expr_precedence.c
--- a/tests/usr.bin/xlint/lint1/expr_precedence.c Thu Aug 25 11:16:33 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_precedence.c Thu Aug 25 19:03:47 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: expr_precedence.c,v 1.9 2022/06/17 18:54:53 rillig Exp $ */
+/* $NetBSD: expr_precedence.c,v 1.10 2022/08/25 19:03:48 rillig Exp $ */
# 3 "expr_precedence.c"
/*
@@ -30,7 +30,6 @@
*
* See lex.c, function 'search', keyword 'in_gcc_attribute'.
*/
- /* expect+2: error: 'var' undefined [99] */
/* expect+1: error: syntax error '=' [249] */
var = 1,
/* Syntactically ok, must be a constant expression though. */
diff -r 67ceef79cf17 -r 8ad701677b24 tests/usr.bin/xlint/lint1/gcc_attribute.c
--- a/tests/usr.bin/xlint/lint1/gcc_attribute.c Thu Aug 25 11:16:33 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_attribute.c Thu Aug 25 19:03:47 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gcc_attribute.c,v 1.11 2022/06/17 18:54:53 rillig Exp $ */
+/* $NetBSD: gcc_attribute.c,v 1.12 2022/08/25 19:03:48 rillig Exp $ */
# 3 "gcc_attribute.c"
/*
@@ -29,7 +29,10 @@
void __attribute__((nonnull(1, 2)))
function_nonnull_list(void *, const void *, int);
-/* expect+1: error: syntax error 'unknown_attribute' [249] */
+/*
+ * Unknown attributes are skipped, as lint does not have a list of all known
+ * GCC attributes.
+ */
void __attribute__((unknown_attribute))
function_with_unknown_attribute(void);
diff -r 67ceef79cf17 -r 8ad701677b24 tests/usr.bin/xlint/lint1/gcc_attribute_type.c
--- a/tests/usr.bin/xlint/lint1/gcc_attribute_type.c Thu Aug 25 11:16:33 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_attribute_type.c Thu Aug 25 19:03:47 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gcc_attribute_type.c,v 1.2 2021/07/25 19:05:27 rillig Exp $ */
+/* $NetBSD: gcc_attribute_type.c,v 1.3 2022/08/25 19:03:48 rillig Exp $ */
# 3 "gcc_attribute_type.c"
/*
@@ -27,5 +27,5 @@
};
/* just to trigger _some_ error, to keep the .exp file */
-/* expect+1: error: syntax error 'syntax_error' [249] */
+/* expect+1: error: syntax error ';' [249] */
__attribute__((syntax_error));
diff -r 67ceef79cf17 -r 8ad701677b24 tests/usr.bin/xlint/lint1/gcc_attribute_var.c
--- a/tests/usr.bin/xlint/lint1/gcc_attribute_var.c Thu Aug 25 11:16:33 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_attribute_var.c Thu Aug 25 19:03:47 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gcc_attribute_var.c,v 1.5 2021/08/11 05:19:33 rillig Exp $ */
+/* $NetBSD: gcc_attribute_var.c,v 1.6 2022/08/25 19:03:48 rillig Exp $ */
# 3 "gcc_attribute_var.c"
/*
@@ -71,5 +71,5 @@
}
/* just to trigger _some_ error, to keep the .exp file */
-/* expect+1: error: syntax error 'syntax_error' [249] */
+/* expect+1: error: syntax error ';' [249] */
__attribute__((syntax_error));
diff -r 67ceef79cf17 -r 8ad701677b24 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y Thu Aug 25 11:16:33 2022 +0000
+++ b/usr.bin/xlint/lint1/cgram.y Thu Aug 25 19:03:47 2022 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.420 2022/06/20 21:13:35 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.421 2022/08/25 19:03:47 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.420 2022/06/20 21:13:35 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.421 2022/08/25 19:03:47 rillig Exp $");
#endif
#include <limits.h>
@@ -128,6 +128,12 @@
s->u.s_member.sm_sou_type = NULL;
}
+static bool
+is_either(const char *s, const char *a, const char *b)
+{
+ return strcmp(s, a) == 0 || strcmp(s, b) == 0;
+}
+
#if YYDEBUG && (YYBYACC || YYBISON)
#define YYSTYPE_TOSTRING cgram_to_string
#endif
@@ -226,60 +232,6 @@
%token T_STATIC_ASSERT
%token T_ATTRIBUTE
-%token T_AT_ALIAS
-%token T_AT_ALIGNED
-%token T_AT_ALLOC_SIZE
-%token T_AT_ALWAYS_INLINE
-%token T_AT_BOUNDED
-%token T_AT_BUFFER
-%token T_AT_COLD
-%token T_AT_COMMON
-%token T_AT_CONSTRUCTOR
-%token T_AT_DEPRECATED
-%token T_AT_DESTRUCTOR
-%token T_AT_DISABLE_SANITIZER_INSTRUMENTATION
-%token T_AT_FALLTHROUGH
-%token T_AT_FORMAT
-%token T_AT_FORMAT_ARG
-%token T_AT_FORMAT_GNU_PRINTF
-%token T_AT_FORMAT_PRINTF
-%token T_AT_FORMAT_SCANF
-%token T_AT_FORMAT_STRFMON
-%token T_AT_FORMAT_STRFTIME
-%token T_AT_FORMAT_SYSLOG
-%token T_AT_GNU_INLINE
-%token T_AT_HOT
-%token T_AT_MALLOC
-%token T_AT_MAY_ALIAS
-%token T_AT_MINBYTES
-%token T_AT_MODE
-%token T_AT_NO_SANITIZE
-%token T_AT_NO_SANITIZE_THREAD
-%token T_AT_NOINLINE
-%token T_AT_NONNULL
-%token T_AT_NONSTRING
-%token T_AT_NORETURN
-%token T_AT_NOTHROW
-%token T_AT_NO_INSTRUMENT_FUNCTION
-%token T_AT_OPTIMIZE
-%token T_AT_OPTNONE
-%token T_AT_PACKED
-%token T_AT_PCS
-%token T_AT_PURE
-%token T_AT_REGPARM
-%token T_AT_RETURNS_NONNULL
-%token T_AT_RETURNS_TWICE
-%token T_AT_SECTION
-%token T_AT_SENTINEL
-%token T_AT_STRING
-%token T_AT_TARGET
-%token T_AT_TLS_MODEL
-%token T_AT_TUNION
-%token T_AT_UNUSED
-%token T_AT_USED
-%token T_AT_VISIBILITY
-%token T_AT_WARN_UNUSED_RESULT
-%token T_AT_WEAK
%left T_THEN
%left T_ELSE
@@ -734,16 +686,6 @@
}
;
-constant_expr_list_opt: /* helper for gcc_attribute */
- /* empty */
- | constant_expr_list
- ;
-
-constant_expr_list: /* helper for gcc_attribute */
- constant_expr
- | constant_expr_list T_COMMA constant_expr
- ;
-
constant_expr: /* C99 6.6 */
conditional_expression
;
@@ -875,7 +817,7 @@
;
type_attribute: /* See C11 6.7 declaration-specifiers */
- gcc_attribute
+ gcc_attribute_specifier
| T_ALIGNAS T_LPAREN type_specifier T_RPAREN /* C11 6.7.5 */
| T_ALIGNAS T_LPAREN constant_expr T_RPAREN /* C11 6.7.5 */
| T_PACKED {
@@ -1079,17 +1021,17 @@
/* K&R ---, C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2 */
enum_specifier: /* C99 6.7.2.2 */
- enum gcc_attribute_list_opt identifier_sym {
+ enum gcc_attribute_specifier_list_opt identifier_sym {
$$ = mktag($3, ENUM, false, false);
}
- | enum gcc_attribute_list_opt identifier_sym {
+ | enum gcc_attribute_specifier_list_opt identifier_sym {
dcs->d_tagtyp = mktag($3, ENUM, true, false);
- } enum_declaration /*gcc_attribute_list_opt*/ {
+ } enum_declaration /*gcc_attribute_specifier_list_opt*/ {
$$ = complete_tag_enum(dcs->d_tagtyp, $5);
}
- | enum gcc_attribute_list_opt {
+ | enum gcc_attribute_specifier_list_opt {
dcs->d_tagtyp = mktag(NULL, ENUM, true, false);
- } enum_declaration /*gcc_attribute_list_opt*/ {
+ } enum_declaration /*gcc_attribute_specifier_list_opt*/ {
$$ = complete_tag_enum(dcs->d_tagtyp, $4);
}
| enum error {
@@ -1143,10 +1085,11 @@
;
enumerator: /* C99 6.7.2.2 */
- identifier_sym gcc_attribute_list_opt {
+ identifier_sym gcc_attribute_specifier_list_opt {
$$ = enumeration_constant($1, enumval, true);
}
- | identifier_sym gcc_attribute_list_opt T_ASSIGN constant_expr {
+ | identifier_sym gcc_attribute_specifier_list_opt
+ T_ASSIGN constant_expr {
$$ = enumeration_constant($1, to_int_constant($4, true),
false);
}
@@ -1318,7 +1261,7 @@
$$ = $2;
}
| direct_param_declarator T_LBRACK array_size_opt T_RBRACK
- gcc_attribute_list_opt {
+ gcc_attribute_specifier_list_opt {
$$ = add_array($1, $3.has_dim, $3.dim);
}
| direct_param_declarator param_list asm_or_symbolrename_opt {
@@ -1645,11 +1588,12 @@
/* empty */ {
$$ = NULL;
}
- | T_ASM T_LPAREN T_STRING T_RPAREN gcc_attribute_list_opt {
+ | T_ASM T_LPAREN T_STRING T_RPAREN gcc_attribute_specifier_list_opt {
freeyyv(&$3, T_STRING);
$$ = NULL;
}
- | T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN gcc_attribute_list_opt {
+ | T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN
+ gcc_attribute_specifier_list_opt {
$$ = $3;
}
;
@@ -1660,7 +1604,7 @@
;
non_expr_statement: /* helper for C99 6.8 */
- gcc_attribute /* ((__fallthrough__)) */ T_SEMI
+ gcc_attribute_specifier /* ((__fallthrough__)) */ T_SEMI
| labeled_statement
| compound_statement
| selection_statement
@@ -1672,7 +1616,7 @@
;
labeled_statement: /* C99 6.8.1 */
- label gcc_attribute_list_opt statement
+ label gcc_attribute_specifier_list_opt statement
;
label:
@@ -2072,112 +2016,54 @@
| begin_type_declaration_specifiers error
;
-gcc_attribute_list_opt:
+/* https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html */
+gcc_attribute_specifier_list_opt:
/* empty */
- | gcc_attribute_list
+ | gcc_attribute_specifier_list
;
-gcc_attribute_list:
- gcc_attribute
- | gcc_attribute_list gcc_attribute
+gcc_attribute_specifier_list:
+ gcc_attribute_specifier
+ | gcc_attribute_specifier_list gcc_attribute_specifier
;
-gcc_attribute:
+gcc_attribute_specifier:
T_ATTRIBUTE T_LPAREN T_LPAREN {
in_gcc_attribute = true;
- } gcc_attribute_spec_list {
+ } gcc_attribute_list {
in_gcc_attribute = false;
} T_RPAREN T_RPAREN
;
-gcc_attribute_spec_list:
- gcc_attribute_spec
Home |
Main Index |
Thread Index |
Old Index