Module Name: src Committed By: rillig Date: Wed Jul 12 18:26:04 UTC 2023
Modified Files: src/tests/usr.bin/xlint/lint1: c11.c src/usr.bin/xlint/lint1: cgram.y debug.c lex.c lint1.h Log Message: lint: reject _Noreturn if it occurs in invalid places C11 introduced _Noreturn as a function-specifier, not as a type attribute. The latter may occur in more places. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/c11.c cvs rdiff -u -r1.456 -r1.457 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.50 -r1.51 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.176 -r1.177 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.186 -r1.187 src/usr.bin/xlint/lint1/lint1.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/c11.c diff -u src/tests/usr.bin/xlint/lint1/c11.c:1.1 src/tests/usr.bin/xlint/lint1/c11.c:1.2 --- src/tests/usr.bin/xlint/lint1/c11.c:1.1 Wed Jul 12 18:13:39 2023 +++ src/tests/usr.bin/xlint/lint1/c11.c Wed Jul 12 18:26:04 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: c11.c,v 1.1 2023/07/12 18:13:39 rillig Exp $ */ +/* $NetBSD: c11.c,v 1.2 2023/07/12 18:26:04 rillig Exp $ */ # 3 "c11.c" /* @@ -11,9 +11,6 @@ _Noreturn void exit(int); void _Noreturn exit(int); -/* XXX: Syntactically invalid, yet lint accepts it. */ -void _Noreturn exit(int) _Noreturn; - _Noreturn void noreturn_before_type(void) { @@ -44,3 +41,10 @@ three_times(void) { exit(0); } + +/* The '_Noreturn' must not appear after the declarator. */ +void _Noreturn exit(int) _Noreturn; +/* expect-1: error: formal parameter #1 lacks name [59] */ +/* expect-2: warning: empty declaration [2] */ +/* expect+2: error: syntax error '' [249] */ +/* expect+1: error: cannot recover from previous errors [224] */ Index: src/usr.bin/xlint/lint1/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.456 src/usr.bin/xlint/lint1/cgram.y:1.457 --- src/usr.bin/xlint/lint1/cgram.y:1.456 Wed Jul 12 16:07:35 2023 +++ src/usr.bin/xlint/lint1/cgram.y Wed Jul 12 18:26:04 2023 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.456 2023/07/12 16:07:35 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.457 2023/07/12 18:26:04 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.456 2023/07/12 16:07:35 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.457 2023/07/12 18:26:04 rillig Exp $"); #endif #include <limits.h> @@ -132,7 +132,7 @@ is_either(const char *s, const char *a, %} -%expect 132 +%expect 104 %union { val_t *y_val; @@ -223,7 +223,6 @@ is_either(const char *s, const char *a, %token T_REAL %token T_IMAG %token T_GENERIC -%token T_NORETURN /* storage classes (extern, static, auto, register and typedef) */ %token <y_scl> T_SCLASS @@ -932,7 +931,6 @@ type_attribute: /* See C11 6.7 declara | T_PACKED { dcs_add_packed(); } -| T_NORETURN ; begin_type: @@ -1969,7 +1967,7 @@ for_exprs: /* see C99 6.8.5 */ c99ism(325); stmt_for_exprs(NULL, $6, $8); clear_warning_flags(); - } + } | for_start expression_opt T_SEMI expression_opt T_SEMI Index: src/usr.bin/xlint/lint1/debug.c diff -u src/usr.bin/xlint/lint1/debug.c:1.50 src/usr.bin/xlint/lint1/debug.c:1.51 --- src/usr.bin/xlint/lint1/debug.c:1.50 Wed Jul 12 16:07:35 2023 +++ src/usr.bin/xlint/lint1/debug.c Wed Jul 12 18:26:04 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.50 2023/07/12 16:07:35 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.51 2023/07/12 18:26:04 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: debug.c,v 1.50 2023/07/12 16:07:35 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.51 2023/07/12 18:26:04 rillig Exp $"); #endif #include <stdlib.h> @@ -320,6 +320,7 @@ function_specifier_name(function_specifi { static const char *const name[] = { "inline", + "_Noreturn", }; return name[spec]; Index: src/usr.bin/xlint/lint1/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.176 src/usr.bin/xlint/lint1/lex.c:1.177 --- src/usr.bin/xlint/lint1/lex.c:1.176 Wed Jul 12 16:07:35 2023 +++ src/usr.bin/xlint/lint1/lex.c Wed Jul 12 18:26:04 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lex.c,v 1.176 2023/07/12 16:07:35 rillig Exp $ */ +/* $NetBSD: lex.c,v 1.177 2023/07/12 18:26:04 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: lex.c,v 1.176 2023/07/12 16:07:35 rillig Exp $"); +__RCSID("$NetBSD: lex.c,v 1.177 2023/07/12 18:26:04 rillig Exp $"); #endif #include <ctype.h> @@ -148,7 +148,7 @@ static const struct keyword { kwdef_type( "__int128_t", INT128, 99), #endif kwdef_type( "long", LONG, 78), - kwdef_token( "_Noreturn", T_NORETURN, 11,0,1), + kwdef("_Noreturn", T_FUNCTION_SPECIFIER, .u.kw_fs = FS_NORETURN, 11,0,1), kwdef_token( "__packed", T_PACKED, 78,0,1), kwdef_token( "__real__", T_REAL, 78,1,1), kwdef_sclass( "register", REG, 78,0,1), Index: src/usr.bin/xlint/lint1/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.186 src/usr.bin/xlint/lint1/lint1.h:1.187 --- src/usr.bin/xlint/lint1/lint1.h:1.186 Wed Jul 12 16:07:35 2023 +++ src/usr.bin/xlint/lint1/lint1.h Wed Jul 12 18:26:04 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.186 2023/07/12 16:07:35 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.187 2023/07/12 18:26:04 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -210,8 +210,8 @@ typedef enum { /* C23 6.7.4 */ typedef enum { - FS_INLINE, - // TODO: Add FS_NORETURN, for C23. + FS_INLINE, /* since C99 */ + FS_NORETURN, /* since C11 */ } function_specifier; /*