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 comparison 'unsi...



details:   https://anonhg.NetBSD.org/src/rev/d2e493b397fa
branches:  trunk
changeset: 1023393:d2e493b397fa
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Sep 05 17:49:55 2021 +0000

description:
lint: do not warn about comparison 'unsigned <= 0'

Seen in scanners generated by Flex, and about 50 occurrences in the
NetBSD src and xsrc tree, all of which are not suspicious of being bugs.

diffstat:

 tests/usr.bin/xlint/lint1/msg_162.c   |  21 ++++++++++++++-------
 tests/usr.bin/xlint/lint1/msg_162.exp |  13 +++++--------
 usr.bin/xlint/lint1/Makefile          |   3 +--
 usr.bin/xlint/lint1/tree.c            |   8 ++++----
 4 files changed, 24 insertions(+), 21 deletions(-)

diffs (130 lines):

diff -r 9681f029f172 -r d2e493b397fa tests/usr.bin/xlint/lint1/msg_162.c
--- a/tests/usr.bin/xlint/lint1/msg_162.c       Sun Sep 05 17:29:27 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_162.c       Sun Sep 05 17:49:55 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_162.c,v 1.5 2021/09/05 16:47:24 rillig Exp $       */
+/*     $NetBSD: msg_162.c,v 1.6 2021/09/05 17:49:55 rillig Exp $       */
 # 3 "msg_162.c"
 
 // Test for message: comparison of %s with %s, op %s [162]
@@ -23,7 +23,7 @@
        if (ui >= 0) {
        }
 
-       /* expect+1: warning: comparison of unsigned int with 0, op <= [162] */
+       /* before 2021-09-05: comparison of unsigned int with 0, op <= [162] */
        if (ui <= 0) {
        }
 }
@@ -47,7 +47,7 @@
        if (0 <= ui) {
        }
 
-       /* expect+1: warning: comparison of 0 with unsigned int, op >= [162] */
+       /* before 2021-09-05: comparison of 0 with unsigned int, op >= [162] */
        if (0 >= ui) {
        }
 }
@@ -97,11 +97,18 @@
        /* expect+1: warning: comparison of unsigned int with negative constant, op <= [162] */
        take_bool(x <= -1);
        /*
-        * XXX: The expression 'x <= 0' is equivalent to 'x < 1', so lint
-        * should not warn about it, just as it doesn't warn about the
-        * inverted condition, which is 'x > 0'.
+        * Before tree.c 1.379 from 2021-09-05, lint warned about
+        * 'unsigned <= 0' as well as '0 >= unsigned'.  In all cases where
+        * the programmer knows whether the underlying data type is signed or
+        * unsigned, it is clearer to express the same thought as
+        * 'unsigned == 0', but that's a stylistic issue only.
+        *
+        * Removing this particular case of the warning is not expected to
+        * miss any bugs.  The expression 'x <= 0' is equivalent to 'x < 1',
+        * so lint should not warn about it, just as it doesn't warn about
+        * the inverted condition, which is 'x > 0'.
         */
-       /* expect+1: warning: comparison of unsigned int with 0, op <= [162] */
+       /* before 2021-09-05: comparison of unsigned int with 0, op <= [162] */
        take_bool(x <= 0);
        take_bool(x <= 1);
 
diff -r 9681f029f172 -r d2e493b397fa tests/usr.bin/xlint/lint1/msg_162.exp
--- a/tests/usr.bin/xlint/lint1/msg_162.exp     Sun Sep 05 17:29:27 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_162.exp     Sun Sep 05 17:49:55 2021 +0000
@@ -1,18 +1,15 @@
 msg_162.c(15): warning: comparison of unsigned int with negative constant, op < [162]
 msg_162.c(19): warning: comparison of unsigned int with 0, op < [162]
 msg_162.c(23): warning: comparison of unsigned int with 0, op >= [162]
-msg_162.c(27): warning: comparison of unsigned int with 0, op <= [162]
 msg_162.c(39): warning: comparison of negative constant with unsigned int, op > [162]
 msg_162.c(43): warning: comparison of 0 with unsigned int, op > [162]
 msg_162.c(47): warning: comparison of 0 with unsigned int, op <= [162]
-msg_162.c(51): warning: comparison of 0 with unsigned int, op >= [162]
 msg_162.c(76): warning: comparison of unsigned char with negative constant, op == [162]
 msg_162.c(92): warning: comparison of unsigned int with negative constant, op < [162]
 msg_162.c(94): warning: comparison of unsigned int with 0, op < [162]
 msg_162.c(98): warning: comparison of unsigned int with negative constant, op <= [162]
-msg_162.c(105): warning: comparison of unsigned int with 0, op <= [162]
-msg_162.c(109): warning: comparison of unsigned int with negative constant, op > [162]
-msg_162.c(114): warning: comparison of unsigned int with negative constant, op >= [162]
-msg_162.c(116): warning: comparison of unsigned int with 0, op >= [162]
-msg_162.c(120): warning: comparison of unsigned int with negative constant, op == [162]
-msg_162.c(125): warning: comparison of unsigned int with negative constant, op != [162]
+msg_162.c(116): warning: comparison of unsigned int with negative constant, op > [162]
+msg_162.c(121): warning: comparison of unsigned int with negative constant, op >= [162]
+msg_162.c(123): warning: comparison of unsigned int with 0, op >= [162]
+msg_162.c(127): warning: comparison of unsigned int with negative constant, op == [162]
+msg_162.c(132): warning: comparison of unsigned int with negative constant, op != [162]
diff -r 9681f029f172 -r d2e493b397fa usr.bin/xlint/lint1/Makefile
--- a/usr.bin/xlint/lint1/Makefile      Sun Sep 05 17:29:27 2021 +0000
+++ b/usr.bin/xlint/lint1/Makefile      Sun Sep 05 17:49:55 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.86 2021/09/05 16:36:56 rillig Exp $
+#      $NetBSD: Makefile,v 1.87 2021/09/05 17:49:55 rillig Exp $
 
 .include <bsd.own.mk>
 
@@ -20,7 +20,6 @@
 LOBJS.${PROG}+=                ${SRCS:M*.y:.y=.ln}
 LOBJS.${PROG}+=                ${SRCS:M*.l:.l=.ln}
 LINTFLAGS.scan.c+=     -X 107,126,330,331,332,333      # strict bool mode
-LINTFLAGS.scan.c+=     -X 162          # comparison of 'unsigned <= 0'
 LINTFLAGS.scan.c+=     -X 192,214      # due to suppressed bool errors
 LINTFLAGS.scan.c+=     -X 307          # static variable unused
 
diff -r 9681f029f172 -r d2e493b397fa usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Sep 05 17:29:27 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Sep 05 17:49:55 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.378 2021/09/05 16:03:55 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.379 2021/09/05 17:49:55 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.378 2021/09/05 16:03:55 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.379 2021/09/05 17:49:55 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -4232,7 +4232,7 @@
                        /* comparison of %s with %s, op %s */
                        warning(162, type_name(ln->tn_type),
                            "negative constant", op_name(op));
-               } else if (op == LT || op == GE || (hflag && op == LE)) {
+               } else if (op == LT || op == GE) {
                        /* comparison of %s with %s, op %s */
                        warning(162, type_name(ln->tn_type), "0", op_name(op));
                }
@@ -4244,7 +4244,7 @@
                        /* comparison of %s with %s, op %s */
                        warning(162, "negative constant",
                            type_name(rn->tn_type), op_name(op));
-               } else if (op == GT || op == LE || (hflag && op == GE)) {
+               } else if (op == GT || op == LE) {
                        /* comparison of %s with %s, op %s */
                        warning(162, "0", type_name(rn->tn_type), op_name(op));
                }



Home | Main Index | Thread Index | Old Index