Module Name: src Committed By: rillig Date: Sat Aug 28 15:25:10 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: msg_230.c msg_230.exp msg_230_uchar.c msg_230_uchar.exp Log Message: tests/lint: align tests for unsigned char and signed char To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_230.c cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_230.exp cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_230_uchar.c cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_230_uchar.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_230.c diff -u src/tests/usr.bin/xlint/lint1/msg_230.c:1.7 src/tests/usr.bin/xlint/lint1/msg_230.c:1.8 --- src/tests/usr.bin/xlint/lint1/msg_230.c:1.7 Sat Aug 28 14:45:19 2021 +++ src/tests/usr.bin/xlint/lint1/msg_230.c Sat Aug 28 15:25:10 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_230.c,v 1.7 2021/08/28 14:45:19 rillig Exp $ */ +/* $NetBSD: msg_230.c,v 1.8 2021/08/28 15:25:10 rillig Exp $ */ # 3 "msg_230.c" // Test for message: nonportable character comparison, op %s [230] @@ -88,6 +88,10 @@ compare_lt(char c) /* expect+1: warning: nonportable character comparison, op > [230] */ if (c > -1) return; + /* + * On platforms where char is unsigned, lint warns that the + * comparison always evaluates to true; see msg_230_uchar.c. + */ if (c >= 0) return; Index: src/tests/usr.bin/xlint/lint1/msg_230.exp diff -u src/tests/usr.bin/xlint/lint1/msg_230.exp:1.6 src/tests/usr.bin/xlint/lint1/msg_230.exp:1.7 --- src/tests/usr.bin/xlint/lint1/msg_230.exp:1.6 Sat Aug 28 14:45:19 2021 +++ src/tests/usr.bin/xlint/lint1/msg_230.exp Sat Aug 28 15:25:10 2021 @@ -13,6 +13,6 @@ msg_230.c(69): warning: nonportable char msg_230.c(78): warning: nonportable character comparison, op > [230] msg_230.c(81): warning: nonportable character comparison, op >= [230] msg_230.c(89): warning: nonportable character comparison, op > [230] -msg_230.c(101): warning: nonportable character comparison, op >= [230] -msg_230.c(105): warning: nonportable character comparison, op > [230] -msg_230.c(108): warning: nonportable character comparison, op >= [230] +msg_230.c(105): warning: nonportable character comparison, op >= [230] +msg_230.c(109): warning: nonportable character comparison, op > [230] +msg_230.c(112): warning: nonportable character comparison, op >= [230] Index: src/tests/usr.bin/xlint/lint1/msg_230_uchar.c diff -u src/tests/usr.bin/xlint/lint1/msg_230_uchar.c:1.3 src/tests/usr.bin/xlint/lint1/msg_230_uchar.c:1.4 --- src/tests/usr.bin/xlint/lint1/msg_230_uchar.c:1.3 Sat Aug 28 14:45:19 2021 +++ src/tests/usr.bin/xlint/lint1/msg_230_uchar.c Sat Aug 28 15:25:10 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_230_uchar.c,v 1.3 2021/08/28 14:45:19 rillig Exp $ */ +/* $NetBSD: msg_230_uchar.c,v 1.4 2021/08/28 15:25:10 rillig Exp $ */ # 3 "msg_230_uchar.c" // Test for message: nonportable character comparison, op %s [230] @@ -6,30 +6,113 @@ /* lint1-flags: -S -g -p -w */ /* lint1-only-if: uchar */ -void example(char c, unsigned char uc, signed char sc) +/* + * C11 6.2.5p15 defines that 'char' has the same range, representation, and + * behavior as either 'signed char' or 'unsigned char'. + * + * The portable range of 'char' is from 0 to 127 since all lint platforms + * define CHAR_SIZE to be 8. + * + * See msg_162.c, which covers 'signed char' and 'unsigned char'. + */ + +void +compare_plain_char(char c) +{ + /* expect+1: warning: nonportable character comparison, op == [230] */ + if (c == -129) + return; + /* expect+1: warning: nonportable character comparison, op == [230] */ + if (c == -128) + return; + /* expect+1: warning: nonportable character comparison, op == [230] */ + if (c == -1) + return; + if (c == 0) + return; + if (c == 127) + return; + /* expect+1: warning: nonportable character comparison, op == [230] */ + if (c == 128) + return; + /* expect+1: warning: nonportable character comparison, op == [230] */ + if (c == 255) + return; + /* expect+1: warning: nonportable character comparison, op == [230] */ + if (c == 256) + return; +} + +void +compare_plain_char_yoda(char c) +{ + /* expect+1: warning: nonportable character comparison, op == [230] */ + if (-129 == c) + return; + /* expect+1: warning: nonportable character comparison, op == [230] */ + if (-128 == c) + return; + /* expect+1: warning: nonportable character comparison, op == [230] */ + if (-1 == c) + return; + if (0 == c) + return; + if (127 == c) + return; + /* expect+1: warning: nonportable character comparison, op == [230] */ + if (128 == c) + return; + /* expect+1: warning: nonportable character comparison, op == [230] */ + if (255 == c) + return; + /* expect+1: warning: nonportable character comparison, op == [230] */ + if (256 == c) + return; +} + +void +compare_lt(char c) { - /* expect+1: warning: comparison of char with 0, op < [162] */ - if (c < 0) + + /* expect+1: warning: nonportable character comparison, op > [230] */ + if (c > -2) return; - /* expect+1: warning: comparison of unsigned char with 0, op < [162] */ - if (uc < 0) + /* expect+1: warning: nonportable character comparison, op >= [230] */ + if (c >= -1) return; - if (sc < 0) + + /* + * XXX: The following two comparisons have the same effect, yet lint + * only warns about one of them. + */ + /* expect+1: warning: nonportable character comparison, op > [230] */ + if (c > -1) + return; + /* + * This warning only occurs on uchar platforms since on these + * platforms it is always true. Code that needs this ordered + * comparison on values of type plain char is questionable since it + * behaves differently depending on the platform. Such a comparison + * should never be needed. + */ + /* expect+1: warning: comparison of char with 0, op >= [162] */ + if (c >= 0) return; /* - * XXX: The comparison "<= -1" looks very similar to "< 0", - * nevertheless "< 0" does not generate a warning. - * - * The comparisons may actually differ subtly because of the usual - * arithmetic promotions. + * XXX: The following two comparisons have the same effect, yet lint + * only warns about one of them. */ - /* expect+1: warning: nonportable character comparison, op <= [230] */ - if (c <= -1) + if (c > 127) return; - /* expect+1: warning: comparison of unsigned char with negative constant, op <= [162] */ - if (uc <= -1) + /* expect+1: warning: nonportable character comparison, op >= [230] */ + if (c >= 128) + return; + + /* expect+1: warning: nonportable character comparison, op > [230] */ + if (c > 128) return; - if (sc <= -1) + /* expect+1: warning: nonportable character comparison, op >= [230] */ + if (c >= 129) return; } Index: src/tests/usr.bin/xlint/lint1/msg_230_uchar.exp diff -u src/tests/usr.bin/xlint/lint1/msg_230_uchar.exp:1.1 src/tests/usr.bin/xlint/lint1/msg_230_uchar.exp:1.2 --- src/tests/usr.bin/xlint/lint1/msg_230_uchar.exp:1.1 Sat Jul 3 19:31:22 2021 +++ src/tests/usr.bin/xlint/lint1/msg_230_uchar.exp Sat Aug 28 15:25:10 2021 @@ -1,4 +1,19 @@ -msg_230_uchar.c(12): warning: comparison of char with 0, op < [162] -msg_230_uchar.c(15): warning: comparison of unsigned char with 0, op < [162] -msg_230_uchar.c(28): warning: nonportable character comparison, op <= [230] -msg_230_uchar.c(31): warning: comparison of unsigned char with negative constant, op <= [162] +msg_230_uchar.c(23): warning: nonportable character comparison, op == [230] +msg_230_uchar.c(26): warning: nonportable character comparison, op == [230] +msg_230_uchar.c(29): warning: nonportable character comparison, op == [230] +msg_230_uchar.c(36): warning: nonportable character comparison, op == [230] +msg_230_uchar.c(39): warning: nonportable character comparison, op == [230] +msg_230_uchar.c(42): warning: nonportable character comparison, op == [230] +msg_230_uchar.c(50): warning: nonportable character comparison, op == [230] +msg_230_uchar.c(53): warning: nonportable character comparison, op == [230] +msg_230_uchar.c(56): warning: nonportable character comparison, op == [230] +msg_230_uchar.c(63): warning: nonportable character comparison, op == [230] +msg_230_uchar.c(66): warning: nonportable character comparison, op == [230] +msg_230_uchar.c(69): warning: nonportable character comparison, op == [230] +msg_230_uchar.c(78): warning: nonportable character comparison, op > [230] +msg_230_uchar.c(81): warning: nonportable character comparison, op >= [230] +msg_230_uchar.c(89): warning: nonportable character comparison, op > [230] +msg_230_uchar.c(99): warning: comparison of char with 0, op >= [162] +msg_230_uchar.c(109): warning: nonportable character comparison, op >= [230] +msg_230_uchar.c(113): warning: nonportable character comparison, op > [230] +msg_230_uchar.c(116): warning: nonportable character comparison, op >= [230]