Module Name: src Committed By: rillig Date: Mon Nov 1 18:11:26 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: msg_348.c msg_348.exp src/usr.bin/xlint/lint1: tree.c Log Message: lint: do not warn about array size mismatch in array[(int)enum] The cast to 'int' explicitly converts the type away from being an enum. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_348.c \ src/tests/usr.bin/xlint/lint1/msg_348.exp cvs rdiff -u -r1.390 -r1.391 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.3 src/tests/usr.bin/xlint/lint1/msg_348.c:1.4 --- src/tests/usr.bin/xlint/lint1/msg_348.c:1.3 Mon Nov 1 11:46:50 2021 +++ src/tests/usr.bin/xlint/lint1/msg_348.c Mon Nov 1 18:11:26 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_348.c,v 1.3 2021/11/01 11:46:50 rillig Exp $ */ +/* $NetBSD: msg_348.c,v 1.4 2021/11/01 18:11:26 rillig Exp $ */ # 3 "msg_348.c" // Test for message 348: maximum value %d of '%s' does not match maximum array index %d [348] @@ -8,7 +8,6 @@ enum color { red, green, - /* expect+3: previous declaration of blue [260] */ /* expect+2: previous declaration of blue [260] */ /* expect+1: previous declaration of blue [260] */ blue @@ -83,7 +82,7 @@ color_name_explicit_cast_to_int(enum col "red", "green", }; - /* expect+1: warning: maximum value 2 of 'enum color' does not match maximum array index 1 [348] */ + /* No warning due to the explicit cast. */ return name[(int)color]; } Index: src/tests/usr.bin/xlint/lint1/msg_348.exp diff -u src/tests/usr.bin/xlint/lint1/msg_348.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_348.exp:1.4 --- src/tests/usr.bin/xlint/lint1/msg_348.exp:1.3 Mon Nov 1 11:46:50 2021 +++ src/tests/usr.bin/xlint/lint1/msg_348.exp Mon Nov 1 18:11:26 2021 @@ -1,8 +1,6 @@ -msg_348.c(37): warning: maximum value 2 of 'enum color' does not match maximum array index 1 [348] -msg_348.c(14): previous declaration of blue [260] -msg_348.c(50): warning: maximum value 2 of 'enum color' does not match maximum array index 3 [348] -msg_348.c(14): previous declaration of blue [260] -msg_348.c(87): warning: maximum value 2 of 'enum color' does not match maximum array index 1 [348] -msg_348.c(14): previous declaration of blue [260] -msg_348.c(108): warning: integral constant too large [56] -msg_348.c(110): warning: integral constant too large [56] +msg_348.c(36): warning: maximum value 2 of 'enum color' does not match maximum array index 1 [348] +msg_348.c(13): previous declaration of blue [260] +msg_348.c(49): warning: maximum value 2 of 'enum color' does not match maximum array index 3 [348] +msg_348.c(13): previous declaration of blue [260] +msg_348.c(107): warning: integral constant too large [56] +msg_348.c(109): warning: integral constant too large [56] Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.390 src/usr.bin/xlint/lint1/tree.c:1.391 --- src/usr.bin/xlint/lint1/tree.c:1.390 Mon Nov 1 13:30:11 2021 +++ src/usr.bin/xlint/lint1/tree.c Mon Nov 1 18:11:25 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.390 2021/11/01 13:30:11 christos Exp $ */ +/* $NetBSD: tree.c,v 1.391 2021/11/01 18:11:25 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: tree.c,v 1.390 2021/11/01 13:30:11 christos Exp $"); +__RCSID("$NetBSD: tree.c,v 1.391 2021/11/01 18:11:25 rillig Exp $"); #endif #include <float.h> @@ -1788,13 +1788,12 @@ check_enum_array_index(const tnode_t *ln if (lt->t_tspec != ARRAY || lt->t_incomplete_array) return; - if (rn->tn_op != CVT || rn->tn_left->tn_op != LOAD) + if (rn->tn_op != CVT || !rn->tn_type->t_is_enum) return; - - rt = rn->tn_left->tn_type; - if (rt->t_tspec != ENUM) + if (rn->tn_left->tn_op != LOAD) return; + rt = rn->tn_left->tn_type; ec = rt->t_enum->en_first_enumerator; max_ec = ec; lint_assert(ec != NULL);