Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: document correct lint ...



details:   https://anonhg.NetBSD.org/src/rev/4e540b71af0c
branches:  trunk
changeset: 1023147:4e540b71af0c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Aug 27 17:59:46 2021 +0000

description:
tests/lint: document correct lint warnings for '>>'

The previous commit contained wrong assumptions.  Upon closer
inspection, the lint warning is correct.

diffstat:

 tests/usr.bin/xlint/lint1/msg_117.c   |  21 ++++++++++++++-------
 tests/usr.bin/xlint/lint1/msg_117.exp |   2 +-
 2 files changed, 15 insertions(+), 8 deletions(-)

diffs (47 lines):

diff -r 6aecf33272b5 -r 4e540b71af0c tests/usr.bin/xlint/lint1/msg_117.c
--- a/tests/usr.bin/xlint/lint1/msg_117.c       Fri Aug 27 17:53:13 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_117.c       Fri Aug 27 17:59:46 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_117.c,v 1.8 2021/08/27 17:49:31 rillig Exp $       */
+/*     $NetBSD: msg_117.c,v 1.9 2021/08/27 17:59:46 rillig Exp $       */
 # 3 "msg_117.c"
 
 // Test for message: bitwise '%s' on signed value possibly nonportable [117]
@@ -47,15 +47,22 @@
 }
 
 unsigned char
-shr_unsigned_char_promoted(unsigned char bit)
+shr_unsigned_char_promoted_signed(unsigned char bit)
 {
        /*
-        * Before TODO from TODO, lint wrongly warned that the bitwise shift
-        * might be on a signed value, which was wrong.  Even though the
-        * expression has type 'int', the value of the expression cannot be
-        * negative, as long as int is larger than char, which holds for all
-        * platforms supported by lint.
+        * The possible values for 'bit' range from 0 to 255.  Subtracting 1
+        * from 0 results in a negative expression value.
         */
        /* expect+1: warning: bitwise '>>' on signed value possibly nonportable [117] */
        return (unsigned char)((bit - 1) >> 5);
 }
+
+unsigned char
+shr_unsigned_char_promoted_unsigned(unsigned char bit)
+{
+       /*
+        * To prevent the above warning, the intermediate expression must be
+        * cast to 'unsigned char'.
+        */
+       return (unsigned char)((unsigned char)(bit - 1) >> 5);
+}
diff -r 6aecf33272b5 -r 4e540b71af0c tests/usr.bin/xlint/lint1/msg_117.exp
--- a/tests/usr.bin/xlint/lint1/msg_117.exp     Fri Aug 27 17:53:13 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_117.exp     Fri Aug 27 17:59:46 2021 +0000
@@ -4,4 +4,4 @@
 msg_117.c(29): warning: shift amount 4660 is greater than bit-size 32 of 'int' [122]
 msg_117.c(35): warning: bitwise '>>' on signed value possibly nonportable [117]
 msg_117.c(35): warning: negative shift [121]
-msg_117.c(60): warning: bitwise '>>' on signed value possibly nonportable [117]
+msg_117.c(57): warning: bitwise '>>' on signed value possibly nonportable [117]



Home | Main Index | Thread Index | Old Index