Module Name: src Committed By: rillig Date: Fri Aug 27 17:59:46 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: msg_117.c msg_117.exp Log Message: tests/lint: document correct lint warnings for '>>' The previous commit contained wrong assumptions. Upon closer inspection, the lint warning is correct. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_117.c cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_117.exp 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_117.c diff -u src/tests/usr.bin/xlint/lint1/msg_117.c:1.8 src/tests/usr.bin/xlint/lint1/msg_117.c:1.9 --- src/tests/usr.bin/xlint/lint1/msg_117.c:1.8 Fri Aug 27 17:49:31 2021 +++ src/tests/usr.bin/xlint/lint1/msg_117.c Fri Aug 27 17:59:46 2021 @@ -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 @@ shr_unsigned_char(unsigned char uc) } 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); +} Index: src/tests/usr.bin/xlint/lint1/msg_117.exp diff -u src/tests/usr.bin/xlint/lint1/msg_117.exp:1.7 src/tests/usr.bin/xlint/lint1/msg_117.exp:1.8 --- src/tests/usr.bin/xlint/lint1/msg_117.exp:1.7 Fri Aug 27 17:49:31 2021 +++ src/tests/usr.bin/xlint/lint1/msg_117.exp Fri Aug 27 17:59:46 2021 @@ -4,4 +4,4 @@ msg_117.c(29): warning: bitwise '>>' on 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]