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: fix wrong warning about signed int...



details:   https://anonhg.NetBSD.org/src/rev/2b104a9d4c50
branches:  trunk
changeset: 1023087:2b104a9d4c50
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Aug 23 06:10:26 2021 +0000

description:
lint: fix wrong warning about signed integer overflow in '-'

The newly added test cases in line 30 and 33 may or may not be worth a
warning since the expressions deal with unsigned integers, where the
behavior on overflow is well defined.

diffstat:

 tests/usr.bin/xlint/lint1/msg_141.c   |  20 +++++++++++++++-----
 tests/usr.bin/xlint/lint1/msg_141.exp |   8 ++++----
 usr.bin/xlint/lint1/tree.c            |  16 +++++++---------
 3 files changed, 26 insertions(+), 18 deletions(-)

diffs (89 lines):

diff -r 0f2017a1c2e7 -r 2b104a9d4c50 tests/usr.bin/xlint/lint1/msg_141.c
--- a/tests/usr.bin/xlint/lint1/msg_141.c       Mon Aug 23 05:52:04 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_141.c       Mon Aug 23 06:10:26 2021 +0000
@@ -1,16 +1,20 @@
-/*     $NetBSD: msg_141.c,v 1.3 2021/08/23 05:52:04 rillig Exp $       */
+/*     $NetBSD: msg_141.c,v 1.4 2021/08/23 06:10:27 rillig Exp $       */
 # 3 "msg_141.c"
 
 // Test for message: integer overflow detected, op %s [141]
 
 /* lint1-extra-flags: -h */
 
-/* FIXME */
-/* expect+1: warning: integer overflow detected, op - [141] */
+/*
+ * Before tree.c 1.347 from 2021-08-23, lint wrongly warned about integer
+ * overflow in '-'.
+ */
 int signed_int_max = (1u << 31) - 1;
 
-/* FIXME */
-/* expect+1: warning: integer overflow detected, op - [141] */
+/*
+ * Before tree.c 1.347 from 2021-08-23, lint wrongly warned about integer
+ * overflow in '-'.
+ */
 unsigned int unsigned_int_max = (1u << 31) - 1;
 
 /* expect+1: warning: integer overflow detected, op + [141] */
@@ -21,3 +25,9 @@
 unsigned int intermediate_overflow = (1 << 30) + (1 << 30);
 
 unsigned int no_overflow = (1U << 30) + (1 << 30);
+
+/* expect+1: warning: integer overflow detected, op - [141] */
+unsigned int unsigned_int_min = 0u - (1u << 31);
+
+/* expect+1: warning: integer overflow detected, op - [141] */
+unsigned int unsigned_int_min_unary = -(1u << 31);
diff -r 0f2017a1c2e7 -r 2b104a9d4c50 tests/usr.bin/xlint/lint1/msg_141.exp
--- a/tests/usr.bin/xlint/lint1/msg_141.exp     Mon Aug 23 05:52:04 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_141.exp     Mon Aug 23 06:10:26 2021 +0000
@@ -1,5 +1,5 @@
-msg_141.c(10): warning: integer overflow detected, op - [141]
-msg_141.c(14): warning: integer overflow detected, op - [141]
-msg_141.c(17): warning: integer overflow detected, op + [141]
 msg_141.c(21): warning: integer overflow detected, op + [141]
-msg_141.c(21): warning: initialization of unsigned with negative constant [221]
+msg_141.c(25): warning: integer overflow detected, op + [141]
+msg_141.c(25): warning: initialization of unsigned with negative constant [221]
+msg_141.c(30): warning: integer overflow detected, op - [141]
+msg_141.c(33): warning: integer overflow detected, op - [141]
diff -r 0f2017a1c2e7 -r 2b104a9d4c50 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Mon Aug 23 05:52:04 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Mon Aug 23 06:10:26 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.346 2021/08/22 21:27:15 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.347 2021/08/23 06:10:26 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.346 2021/08/22 21:27:15 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.347 2021/08/23 06:10:26 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -3094,13 +3094,11 @@
                break;
        case MINUS:
                q = utyp ? (int64_t)(ul - ur) : sl - sr;
-               if (msb(sl, t, -1) && !msb(sr, t, -1)) {
-                       if (!msb(q, t, -1))
-                               ovfl = true;
-               } else if (!msb(sl, t, -1) && msb(sr, t, -1)) {
-                       if (msb(q, t, -1))
-                               ovfl = true;
-               }
+               if (!utyp &&
+                   msb(sl, t, -1) && !msb(sr, t, -1) && !msb(q, t, -1))
+                       ovfl = true;
+               if (!msb(sl, t, -1) && msb(sr, t, -1) && msb(q, t, -1))
+                       ovfl = true;
                break;
        case SHL:
                q = utyp ? (int64_t)(ul << sr) : sl << sr;



Home | Main Index | Thread Index | Old Index