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: reject _Noreturn if it occurs in i...
details: https://anonhg.NetBSD.org/src/rev/5ad606bf776b
branches: trunk
changeset: 377458:5ad606bf776b
user: rillig <rillig%NetBSD.org@localhost>
date: Wed Jul 12 18:26:04 2023 +0000
description:
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.
diffstat:
tests/usr.bin/xlint/lint1/c11.c | 12 ++++++++----
usr.bin/xlint/lint1/cgram.y | 10 ++++------
usr.bin/xlint/lint1/debug.c | 5 +++--
usr.bin/xlint/lint1/lex.c | 6 +++---
usr.bin/xlint/lint1/lint1.h | 6 +++---
5 files changed, 21 insertions(+), 18 deletions(-)
diffs (156 lines):
diff -r ac988a285f34 -r 5ad606bf776b tests/usr.bin/xlint/lint1/c11.c
--- a/tests/usr.bin/xlint/lint1/c11.c Wed Jul 12 18:13:39 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/c11.c Wed Jul 12 18:26:04 2023 +0000
@@ -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] */
diff -r ac988a285f34 -r 5ad606bf776b usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y Wed Jul 12 18:13:39 2023 +0000
+++ b/usr.bin/xlint/lint1/cgram.y Wed Jul 12 18:26:04 2023 +0000
@@ -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
diff -r ac988a285f34 -r 5ad606bf776b usr.bin/xlint/lint1/debug.c
--- a/usr.bin/xlint/lint1/debug.c Wed Jul 12 18:13:39 2023 +0000
+++ b/usr.bin/xlint/lint1/debug.c Wed Jul 12 18:26:04 2023 +0000
@@ -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];
diff -r ac988a285f34 -r 5ad606bf776b usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Wed Jul 12 18:13:39 2023 +0000
+++ b/usr.bin/xlint/lint1/lex.c Wed Jul 12 18:26:04 2023 +0000
@@ -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),
diff -r ac988a285f34 -r 5ad606bf776b usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h Wed Jul 12 18:13:39 2023 +0000
+++ b/usr.bin/xlint/lint1/lint1.h Wed Jul 12 18:26:04 2023 +0000
@@ -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;
/*
Home |
Main Index |
Thread Index |
Old Index