Module Name: src Committed By: rillig Date: Thu Oct 31 10:32:09 UTC 2024
Modified Files: src/tests/usr.bin/xlint/lint1: msg_348.c src/usr.bin/xlint/lint1: err.c tree.c Log Message: lint: allow enum constant named 'N_*' to exceed the array index Seen in libxcb. While here, add the name of the enum constant to the message, to quickly decide whether the identifier is outside the range of expected enum values, thus marking the number of enum constants. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/msg_348.c cvs rdiff -u -r1.251 -r1.252 src/usr.bin/xlint/lint1/err.c cvs rdiff -u -r1.656 -r1.657 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/msg_348.c diff -u src/tests/usr.bin/xlint/lint1/msg_348.c:1.11 src/tests/usr.bin/xlint/lint1/msg_348.c:1.12 --- src/tests/usr.bin/xlint/lint1/msg_348.c:1.11 Tue Oct 29 20:48:31 2024 +++ src/tests/usr.bin/xlint/lint1/msg_348.c Thu Oct 31 10:32:08 2024 @@ -1,7 +1,7 @@ -/* $NetBSD: msg_348.c,v 1.11 2024/10/29 20:48:31 rillig Exp $ */ +/* $NetBSD: msg_348.c,v 1.12 2024/10/31 10:32:08 rillig Exp $ */ # 3 "msg_348.c" -// Test for message: maximum value %d of '%s' does not match maximum array index %d [348] +// Test for message: maximum value %d for '%s' of type '%s' does not match maximum array index %d [348] /* lint1-extra-flags: -r -X 351 */ @@ -24,7 +24,7 @@ color_name(enum color color) "green", "blue" }; - /* No warning since the maximum enum value matches the array size. */ + /* No warning since the maximum enum value equals the maximum array index. */ return name[color]; } @@ -35,7 +35,7 @@ color_name_too_few(enum color color) "red", "green" }; - /* expect+1: warning: maximum value 2 of 'enum color' does not match maximum array index 1 [348] */ + /* expect+1: warning: maximum value 2 for 'blue' of type 'enum color' does not match maximum array index 1 [348] */ return name[color]; } @@ -48,7 +48,7 @@ color_name_too_many(enum color color) "blue", "black" }; - /* expect+1: warning: maximum value 2 of 'enum color' does not match maximum array index 3 [348] */ + /* expect+1: warning: maximum value 2 for 'blue' of type 'enum color' does not match maximum array index 3 [348] */ return name[color]; } @@ -123,12 +123,12 @@ color_initial_letter(enum color color) return; /* FIXME: lint should not warn since the maximum usable array index is 2 */ - /* expect+1: warning: maximum value 2 of 'enum color' does not match maximum array index 3 [348] */ + /* expect+1: warning: maximum value 2 for 'blue' of type 'enum color' does not match maximum array index 3 [348] */ if (len_3_null[color] != '\0') return; /* FIXME: lint should not warn since the maximum usable array index is 3, not 4 */ - /* expect+1: warning: maximum value 2 of 'enum color' does not match maximum array index 4 [348] */ + /* expect+1: warning: maximum value 2 for 'blue' of type 'enum color' does not match maximum array index 4 [348] */ if (len_4_null[color] != '\0') return; @@ -143,7 +143,7 @@ color_initial_letter(enum color color) if (len_3_of_3[color] != '\0') return; - /* expect+1: warning: maximum value 2 of 'enum color' does not match maximum array index 3 [348] */ + /* expect+1: warning: maximum value 2 for 'blue' of type 'enum color' does not match maximum array index 3 [348] */ if (len_4_of_4[color]) return; } @@ -247,3 +247,16 @@ lowercase_max_name(enum lowercase_max x) static const char *const name[] = { "first", "second" }; return name[x]; } + +enum uppercase_n { + UPPERCASE_N_FIRST, + UPPERCASE_N_LAST, + N_UPPERCASE_N, +}; + +const char* +uppercase_n_name(enum uppercase_n x) +{ + static const char *const name[] = { "first", "last" }; + return name[x]; +} Index: src/usr.bin/xlint/lint1/err.c diff -u src/usr.bin/xlint/lint1/err.c:1.251 src/usr.bin/xlint/lint1/err.c:1.252 --- src/usr.bin/xlint/lint1/err.c:1.251 Tue Oct 29 20:48:31 2024 +++ src/usr.bin/xlint/lint1/err.c Thu Oct 31 10:32:08 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.251 2024/10/29 20:48:31 rillig Exp $ */ +/* $NetBSD: err.c,v 1.252 2024/10/31 10:32:08 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.251 2024/10/29 20:48:31 rillig Exp $"); +__RCSID("$NetBSD: err.c,v 1.252 2024/10/31 10:32:08 rillig Exp $"); #endif #include <limits.h> @@ -403,7 +403,7 @@ static const char *const msgs[] = { "generic selection requires C11 or later", // 345 "call to '%s' effectively discards 'const' from argument", // 346 "redeclaration of '%s' with type '%s', expected '%s'", // 347 - "maximum value %d of '%s' does not match maximum array index %d", // 348 + "maximum value %d for '%s' of type '%s' does not match maximum array index %d", // 348 "non type argument to alignof is a GCC extension", // 349 "'_Atomic' requires C11 or later", // 350 "missing%s header declaration for '%s'", // 351 Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.656 src/usr.bin/xlint/lint1/tree.c:1.657 --- src/usr.bin/xlint/lint1/tree.c:1.656 Sat Oct 12 09:45:25 2024 +++ src/usr.bin/xlint/lint1/tree.c Thu Oct 31 10:32:08 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.656 2024/10/12 09:45:25 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.657 2024/10/31 10:32:08 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.656 2024/10/12 09:45:25 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.657 2024/10/31 10:32:08 rillig Exp $"); #endif #include <float.h> @@ -1255,11 +1255,13 @@ check_enum_array_index(const tnode_t *ln (strstr(max_ec->s_name, "MAX") != NULL || strstr(max_ec->s_name, "max") != NULL || strstr(max_ec->s_name, "NUM") != NULL || - strstr(max_ec->s_name, "num") != NULL)) + strstr(max_ec->s_name, "num") != NULL || + strncmp(max_ec->s_name, "N_", 2) == 0)) return; - /* maximum value %d of '%s' does not match maximum array index %d */ - warning(348, (int)max_enum_value, type_name(rtp), max_array_index); + /* maximum value %d for '%s' of type '%s' does not match maximum array index %d */ + warning(348, (int)max_enum_value, max_ec->s_name, type_name(rtp), + max_array_index); print_previous_declaration(max_ec); }