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: do not warn about array size misma...



details:   https://anonhg.NetBSD.org/src/rev/25171e03ef41
branches:  trunk
changeset: 1024739:25171e03ef41
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Nov 01 18:11:25 2021 +0000

description:
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.

diffstat:

 tests/usr.bin/xlint/lint1/msg_348.c   |   5 ++---
 tests/usr.bin/xlint/lint1/msg_348.exp |  14 ++++++--------
 usr.bin/xlint/lint1/tree.c            |  11 +++++------
 3 files changed, 13 insertions(+), 17 deletions(-)

diffs (79 lines):

diff -r b62f3075b445 -r 25171e03ef41 tests/usr.bin/xlint/lint1/msg_348.c
--- a/tests/usr.bin/xlint/lint1/msg_348.c       Mon Nov 01 17:03:53 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_348.c       Mon Nov 01 18:11:25 2021 +0000
@@ -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 @@
            "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];
 }
 
diff -r b62f3075b445 -r 25171e03ef41 tests/usr.bin/xlint/lint1/msg_348.exp
--- a/tests/usr.bin/xlint/lint1/msg_348.exp     Mon Nov 01 17:03:53 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_348.exp     Mon Nov 01 18:11:25 2021 +0000
@@ -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]
diff -r b62f3075b445 -r 25171e03ef41 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Mon Nov 01 17:03:53 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Mon Nov 01 18:11:25 2021 +0000
@@ -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 @@
        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;
+       if (rn->tn_left->tn_op != LOAD)
                return;
 
        rt = rn->tn_left->tn_type;
-       if (rt->t_tspec != ENUM)
-               return;
-
        ec = rt->t_enum->en_first_enumerator;
        max_ec = ec;
        lint_assert(ec != NULL);



Home | Main Index | Thread Index | Old Index