Module Name: src
Committed By: rillig
Date: Mon Jun 17 17:06:48 UTC 2024
Modified Files:
src/tests/usr.bin/xlint/lint1: c23.c
src/usr.bin/xlint/lint1: cgram.y externs1.h tree.c
Log Message:
lint: accept C23 [[fallthrough]] statements
Needed by bind9/getaddresses.c:137.
To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/xlint/lint1/c23.c
cvs rdiff -u -r1.504 -r1.505 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.229 -r1.230 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.647 -r1.648 src/usr.bin/xlint/lint1/tree.c
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/c23.c
diff -u src/tests/usr.bin/xlint/lint1/c23.c:1.14 src/tests/usr.bin/xlint/lint1/c23.c:1.15
--- src/tests/usr.bin/xlint/lint1/c23.c:1.14 Mon Jun 17 04:14:02 2024
+++ src/tests/usr.bin/xlint/lint1/c23.c Mon Jun 17 17:06:48 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: c23.c,v 1.14 2024/06/17 04:14:02 rillig Exp $ */
+/* $NetBSD: c23.c,v 1.15 2024/06/17 17:06:48 rillig Exp $ */
# 3 "c23.c"
// Tests for the option -Ac23, which allows features from C23 and all earlier
@@ -8,7 +8,7 @@
// c11.c
// msg_353.c for empty initializer braces
-/* lint1-flags: -Ac23 -w -X 351 */
+/* lint1-flags: -Ac23 -hw -X 351 */
int
@@ -178,3 +178,22 @@ attributes_in_parameter_declaration(
[[maybe_unused]] const number const_typedef_param)
{
}
+
+int
+attribute_in_switch_statement(int n)
+{
+ switch (n) {
+ case 1:
+ n++;
+ /* expect+1: warning: fallthrough on case statement [220] */
+ case 2:
+ n++;
+ [[fallthrough]];
+ case 3:
+ n++;
+ [[fallthrough]];
+ default:
+ n++;
+ }
+ return n;
+}
Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.504 src/usr.bin/xlint/lint1/cgram.y:1.505
--- src/usr.bin/xlint/lint1/cgram.y:1.504 Mon Jun 17 04:14:02 2024
+++ src/usr.bin/xlint/lint1/cgram.y Mon Jun 17 17:06:47 2024
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.504 2024/06/17 04:14:02 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.505 2024/06/17 17:06: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.504 2024/06/17 04:14:02 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.505 2024/06/17 17:06:47 rillig Exp $");
#endif
#include <limits.h>
@@ -2112,6 +2112,11 @@ expression_statement:
expr($2, false, false, false, false);
suppress_fallthrough = false;
}
+| attribute_specifier_sequence T_SEMI {
+ debug_attribute_list(&$1);
+ check_statement_reachable();
+ suppress_fallthrough = attributes_contain(&$1, "fallthrough");
+ }
;
/* C99 6.8.4, C23 6.8.5.1 */
Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.229 src/usr.bin/xlint/lint1/externs1.h:1.230
--- src/usr.bin/xlint/lint1/externs1.h:1.229 Sun May 12 18:00:58 2024
+++ src/usr.bin/xlint/lint1/externs1.h Mon Jun 17 17:06:47 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.229 2024/05/12 18:00:58 rillig Exp $ */
+/* $NetBSD: externs1.h,v 1.230 2024/06/17 17:06:47 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -306,6 +306,7 @@ buffer *cat_strings(buffer *, buffer *);
unsigned int type_size_in_bits(const type_t *);
sym_t *find_member(const struct_or_union *, const char *);
uint64_t possible_bits(const tnode_t *);
+bool attributes_contain(const attribute_list *, const char *);
void begin_statement_expr(void);
void do_statement_expr(tnode_t *);
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.647 src/usr.bin/xlint/lint1/tree.c:1.648
--- src/usr.bin/xlint/lint1/tree.c:1.647 Sun Jun 9 16:53:06 2024
+++ src/usr.bin/xlint/lint1/tree.c Mon Jun 17 17:06:47 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.647 2024/06/09 16:53:06 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.648 2024/06/17 17:06:47 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.647 2024/06/09 16:53:06 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.648 2024/06/17 17:06:47 rillig Exp $");
#endif
#include <float.h>
@@ -323,6 +323,17 @@ possible_bits(const tnode_t *tn)
return ~ic_expr(tn).bclr;
}
+bool
+attributes_contain(const attribute_list *attrs, const char *str)
+{
+ for (size_t i = 0, n = attrs->len; i < n; i++) {
+ const attribute *attr = attrs->attrs + i;
+ if (attr->prefix == NULL && strcmp(attr->name, str) == 0)
+ return true;
+ }
+ return false;
+}
+
/* Build 'pointer to tp', 'array of tp' or 'function returning tp'. */
type_t *
block_derive_type(type_t *tp, tspec_t t)