diff options
| author | rillig <rillig@NetBSD.org> | 2023-07-02 23:40:23 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2023-07-02 23:40:23 +0000 |
| commit | 369d3f5ede350876c7202bf19e3d8152d6ef607e (patch) | |
| tree | e3489f08a6d3f18b8a30f0ceca9302e5d0b8ef3e /usr.bin | |
| parent | 98b3ac66e0307baac83f3e28ac02ed2f1da2f29a (diff) | |
lint: add initial support for C23
Required by xsrc/external/mit/MesaLib.old, brw_eu_validate.c, which
initializes a struct using empty braces: 'return (struct string){};'.
Diffstat (limited to 'usr.bin')
| -rw-r--r-- | usr.bin/xlint/lint1/cgram.y | 16 | ||||
| -rw-r--r-- | usr.bin/xlint/lint1/check-msgs.lua | 3 | ||||
| -rw-r--r-- | usr.bin/xlint/lint1/err.c | 17 | ||||
| -rw-r--r-- | usr.bin/xlint/lint1/externs1.h | 4 | ||||
| -rw-r--r-- | usr.bin/xlint/lint1/lint1.h | 3 | ||||
| -rw-r--r-- | usr.bin/xlint/lint1/main1.c | 17 | ||||
| -rw-r--r-- | usr.bin/xlint/xlint/lint.1 | 12 |
7 files changed, 56 insertions, 16 deletions
diff --git a/usr.bin/xlint/lint1/cgram.y b/usr.bin/xlint/lint1/cgram.y index 56aec6013b8..257de50c2fc 100644 --- a/usr.bin/xlint/lint1/cgram.y +++ b/usr.bin/xlint/lint1/cgram.y @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.445 2023/07/02 22:56:13 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.446 2023/07/02 23:40:23 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.445 2023/07/02 22:56:13 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.446 2023/07/02 23:40:23 rillig Exp $"); #endif #include <limits.h> @@ -459,7 +459,7 @@ postfix_expression: sym_t *tmp = mktempsym($2); begin_initialization(tmp); cgram_declare(tmp, true, NULL); - } init_lbrace initializer_list comma_opt init_rbrace { + } braced_initializer { if (!allow_c99) /* compound literals are a C99/GCC extension */ gnuism(319); @@ -1519,6 +1519,16 @@ parameter_declaration: } ; +braced_initializer: + /* K&R ---, C90 ---, C99 ---, C11 ---, C23 6.7.10 */ + init_lbrace init_rbrace { + /* empty initializer braces require C23 or later */ + c23ism(353); + } + /* K&R ---, C90 ---, C99 6.7.8, C11 6.7.9, C23 6.7.10 */ + | init_lbrace initializer_list comma_opt init_rbrace + ; + initializer: /* C99 6.7.8 "Initialization" */ assignment_expression { init_expr($1); diff --git a/usr.bin/xlint/lint1/check-msgs.lua b/usr.bin/xlint/lint1/check-msgs.lua index e16635eedf2..b8262c5a750 100644 --- a/usr.bin/xlint/lint1/check-msgs.lua +++ b/usr.bin/xlint/lint1/check-msgs.lua @@ -1,5 +1,5 @@ #! /usr/bin/lua --- $NetBSD: check-msgs.lua,v 1.17 2022/07/05 22:50:41 rillig Exp $ +-- $NetBSD: check-msgs.lua,v 1.18 2023/07/02 23:40:23 rillig Exp $ --[[ @@ -69,6 +69,7 @@ local message_prefix = { query_message = "Q", c99ism = "", c11ism = "", + c23ism = "", gnuism = "", } diff --git a/usr.bin/xlint/lint1/err.c b/usr.bin/xlint/lint1/err.c index 21786a21d2b..db6a1891e09 100644 --- a/usr.bin/xlint/lint1/err.c +++ b/usr.bin/xlint/lint1/err.c @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.203 2023/06/30 08:45:22 rillig Exp $ */ +/* $NetBSD: err.c,v 1.204 2023/07/02 23:40:23 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: err.c,v 1.203 2023/06/30 08:45:22 rillig Exp $"); +__RCSID("$NetBSD: err.c,v 1.204 2023/07/02 23:40:23 rillig Exp $"); #endif #include <limits.h> @@ -408,6 +408,7 @@ static const char *const msgs[] = { "'_Atomic' requires C11 or later", /* 350 */ "missing%s header declaration for '%s'", /* 351 */ "nested 'extern' declaration of '%s'", /* 352 */ + "empty initializer braces require C23 or later", /* 353 */ }; static bool is_suppressed[sizeof(msgs) / sizeof(msgs[0])]; @@ -677,6 +678,18 @@ void va_end(ap); } +void +(c23ism)(int msgid, ...) +{ + va_list ap; + + if (allow_c23) + return; + va_start(ap, msgid); + verror_at(msgid, &curr_pos, ap); + va_end(ap); +} + bool (gnuism)(int msgid, ...) { diff --git a/usr.bin/xlint/lint1/externs1.h b/usr.bin/xlint/lint1/externs1.h index 3344e014290..712b7a4dc32 100644 --- a/usr.bin/xlint/lint1/externs1.h +++ b/usr.bin/xlint/lint1/externs1.h @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.187 2023/07/02 18:14:44 rillig Exp $ */ +/* $NetBSD: externs1.h,v 1.188 2023/07/02 23:40:23 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -56,6 +56,7 @@ extern bool allow_trad; extern bool allow_c90; extern bool allow_c99; extern bool allow_c11; +extern bool allow_c23; extern bool allow_gcc; extern sig_atomic_t fpe; @@ -168,6 +169,7 @@ void warning(int, ...); bool gnuism(int, ...); void c99ism(int, ...); void c11ism(int, ...); +void c23ism(int, ...); void assert_failed(const char *, int, const char *, const char *) __attribute__((__noreturn__)); void update_location(const char *, int, bool, bool); diff --git a/usr.bin/xlint/lint1/lint1.h b/usr.bin/xlint/lint1/lint1.h index fd941ff76d3..a0267d73a8a 100644 --- a/usr.bin/xlint/lint1/lint1.h +++ b/usr.bin/xlint/lint1/lint1.h @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.178 2023/07/02 18:28:15 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.179 2023/07/02 23:40:23 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -492,6 +492,7 @@ check_printf(const char *fmt, ...) # define gnuism(msgid, args...) wrap_check_printf(gnuism, !allow_gcc || (!allow_trad && !allow_c99), msgid, ##args) # define c99ism(msgid, args...) wrap_check_printf(c99ism, !allow_c99 && (!allow_gcc || !allow_trad), msgid, ##args) # define c11ism(msgid, args...) wrap_check_printf(c11ism, !allow_c11 && !allow_gcc, msgid, ##args) +# define c23ism(msgid, args...) wrap_check_printf(c23ism, !allow_c23, msgid, ##args) #endif #ifdef DEBUG diff --git a/usr.bin/xlint/lint1/main1.c b/usr.bin/xlint/lint1/main1.c index 92a95fe61c4..98ca9154a35 100644 --- a/usr.bin/xlint/lint1/main1.c +++ b/usr.bin/xlint/lint1/main1.c @@ -1,4 +1,4 @@ -/* $NetBSD: main1.c,v 1.66 2023/01/13 19:41:50 rillig Exp $ */ +/* $NetBSD: main1.c,v 1.67 2023/07/02 23:40:23 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: main1.c,v 1.66 2023/01/13 19:41:50 rillig Exp $"); +__RCSID("$NetBSD: main1.c,v 1.67 2023/07/02 23:40:23 rillig Exp $"); #endif #include <sys/types.h> @@ -116,6 +116,7 @@ bool allow_trad = true; bool allow_c90 = true; bool allow_c99; bool allow_c11; +bool allow_c23; bool allow_gcc; sig_atomic_t fpe; @@ -195,12 +196,14 @@ main(int argc, char *argv[]) allow_c90 = true; allow_c99 = false; allow_c11 = false; + allow_c23 = false; break; case 'S': allow_trad = false; allow_c90 = true; allow_c99 = true; allow_c11 = false; + allow_c23 = false; break; case 'T': Tflag = true; break; case 't': @@ -208,6 +211,7 @@ main(int argc, char *argv[]) allow_c90 = false; allow_c99 = false; allow_c11 = false; + allow_c23 = false; break; case 'u': uflag = false; break; case 'w': wflag = true; break; @@ -216,11 +220,18 @@ main(int argc, char *argv[]) case 'z': zflag = false; break; case 'A': - if (strcmp(optarg, "c11") == 0) { + if (strcmp(optarg, "c23") == 0) { allow_trad = false; allow_c90 = true; allow_c99 = true; allow_c11 = true; + allow_c23 = true; + } else if (strcmp(optarg, "c11") == 0) { + allow_trad = false; + allow_c90 = true; + allow_c99 = true; + allow_c11 = true; + allow_c23 = true; } else usage(); break; diff --git a/usr.bin/xlint/xlint/lint.1 b/usr.bin/xlint/xlint/lint.1 index f697ba73e7f..c8850c69a9e 100644 --- a/usr.bin/xlint/xlint/lint.1 +++ b/usr.bin/xlint/xlint/lint.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: lint.1,v 1.59 2023/06/28 13:50:47 rillig Exp $ +.\" $NetBSD: lint.1,v 1.60 2023/07/02 23:40:23 rillig Exp $ .\" .\" Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. .\" Copyright (c) 1994, 1995 Jochen Pohl @@ -30,7 +30,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd June 28, 2023 +.Dd July 3, 2023 .Dt LINT 1 .Os .Sh NAME @@ -40,7 +40,7 @@ .Nm .Op Fl abceFgHhPprTVvwxz .Op Fl i | Fl nu -.Op Fl S | Fl s | Fl t | Fl Ac11 +.Op Fl S | Fl s | Fl t | Fl Ac11 | Fl Ac23 .Op Fl B Ar directory .Op Fl D Ar name Ns Op =def .Op Fl d Ar directory @@ -57,7 +57,7 @@ .Ar .Nm lint .Op Fl abceFgHhprTVvwz -.Op Fl S | Fl s | Fl t | Fl Ac11 +.Op Fl S | Fl s | Fl t | Fl Ac11 | Fl Ac23 .Fl C Ar library .Op Fl B Ar directory .Op Fl D Ar name Ns Op =def @@ -182,6 +182,8 @@ printed followed by a question mark. .Bl -tag -width XXoutputfile .It Fl Ac11 Allow features from C11, C99 and C90. +.It Fl Ac23 +Allow features from C23, C17, C11, C99 and C90. .It Fl a Report assignments of .Sy long @@ -655,7 +657,7 @@ and strict bool mode. .An Jochen Pohl (1995) .An Roland Illig -(2021) +(2021 to 2023) .\" .Sh CAVEATS .Sh BUGS The routines |
