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: extend test for nonpor...
details: https://anonhg.NetBSD.org/src/rev/216b49577387
branches: trunk
changeset: 985492:216b49577387
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Aug 28 14:45:19 2021 +0000
description:
tests/lint: extend test for nonportable character comparison
diffstat:
tests/usr.bin/xlint/lint1/msg_162.c | 33 ++++++++-
tests/usr.bin/xlint/lint1/msg_162.exp | 1 +
tests/usr.bin/xlint/lint1/msg_230.c | 111 ++++++++++++++++++++++++-----
tests/usr.bin/xlint/lint1/msg_230.exp | 23 ++++-
tests/usr.bin/xlint/lint1/msg_230_uchar.c | 4 +-
5 files changed, 143 insertions(+), 29 deletions(-)
diffs (232 lines):
diff -r e2c420e2baa5 -r 216b49577387 tests/usr.bin/xlint/lint1/msg_162.c
--- a/tests/usr.bin/xlint/lint1/msg_162.c Sat Aug 28 14:42:29 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_162.c Sat Aug 28 14:45:19 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_162.c,v 1.3 2021/08/23 17:47:34 rillig Exp $ */
+/* $NetBSD: msg_162.c,v 1.4 2021/08/28 14:45:19 rillig Exp $ */
# 3 "msg_162.c"
// Test for message: comparison of %s with %s, op %s [162]
@@ -51,3 +51,34 @@
if (0 >= ui) {
}
}
+
+/*
+ * Lint does not care about these comparisons, even though they are obviously
+ * out of range.
+ */
+void
+compare_signed_char(signed char sc)
+{
+ if (sc == -129)
+ return;
+ if (sc == -128)
+ return;
+ if (sc == 127)
+ return;
+ if (sc == 128)
+ return;
+}
+
+void
+compare_unsigned_char(unsigned char uc)
+{
+ /* expect+1: warning: comparison of unsigned char with negative constant, op == [162] */
+ if (uc == -1)
+ return;
+ if (uc == 0)
+ return;
+ if (uc == 255)
+ return;
+ if (uc == 256)
+ return;
+}
diff -r e2c420e2baa5 -r 216b49577387 tests/usr.bin/xlint/lint1/msg_162.exp
--- a/tests/usr.bin/xlint/lint1/msg_162.exp Sat Aug 28 14:42:29 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_162.exp Sat Aug 28 14:45:19 2021 +0000
@@ -6,3 +6,4 @@
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]
diff -r e2c420e2baa5 -r 216b49577387 tests/usr.bin/xlint/lint1/msg_230.c
--- a/tests/usr.bin/xlint/lint1/msg_230.c Sat Aug 28 14:42:29 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_230.c Sat Aug 28 14:45:19 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_230.c,v 1.6 2021/08/23 17:47:34 rillig Exp $ */
+/* $NetBSD: msg_230.c,v 1.7 2021/08/28 14:45:19 rillig Exp $ */
# 3 "msg_230.c"
// Test for message: nonportable character comparison, op %s [230]
@@ -6,36 +6,105 @@
/* lint1-flags: -S -g -p -w */
/* lint1-only-if: schar */
-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)
{
- if (c < 0)
+ /* 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;
- /* expect+1: warning: comparison of unsigned char with 0, op < [162] */
- if (uc < 0)
+}
+
+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;
- if (sc < 0)
+ /* 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: nonportable character comparison, op > [230] */
+ if (c > -2)
+ return;
+ /* expect+1: warning: nonportable character comparison, op >= [230] */
+ if (c >= -1)
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)
+ /* expect+1: warning: nonportable character comparison, op > [230] */
+ if (c > -1)
return;
- /* expect+1: warning: comparison of unsigned char with negative constant, op <= [162] */
- if (uc <= -1)
- return;
- if (sc <= -1)
+ if (c >= 0)
return;
- /* expect+1: warning: nonportable character comparison, op <= [230] */
- if (-1 <= c)
+ /*
+ * XXX: The following two comparisons have the same effect, yet lint
+ * only warns about one of them.
+ */
+ if (c > 127)
return;
- /* expect+1: warning: nonportable character comparison, op <= [230] */
- if (256 <= c)
+ /* expect+1: warning: nonportable character comparison, op >= [230] */
+ if (c >= 128)
+ return;
+
+ /* expect+1: warning: nonportable character comparison, op > [230] */
+ if (c > 128)
+ return;
+ /* expect+1: warning: nonportable character comparison, op >= [230] */
+ if (c >= 129)
return;
}
diff -r e2c420e2baa5 -r 216b49577387 tests/usr.bin/xlint/lint1/msg_230.exp
--- a/tests/usr.bin/xlint/lint1/msg_230.exp Sat Aug 28 14:42:29 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_230.exp Sat Aug 28 14:45:19 2021 +0000
@@ -1,5 +1,18 @@
-msg_230.c(14): warning: comparison of unsigned char with 0, op < [162]
-msg_230.c(27): warning: nonportable character comparison, op <= [230]
-msg_230.c(30): warning: comparison of unsigned char with negative constant, op <= [162]
-msg_230.c(36): warning: nonportable character comparison, op <= [230]
-msg_230.c(39): warning: nonportable character comparison, op <= [230]
+msg_230.c(23): warning: nonportable character comparison, op == [230]
+msg_230.c(26): warning: nonportable character comparison, op == [230]
+msg_230.c(29): warning: nonportable character comparison, op == [230]
+msg_230.c(36): warning: nonportable character comparison, op == [230]
+msg_230.c(39): warning: nonportable character comparison, op == [230]
+msg_230.c(42): warning: nonportable character comparison, op == [230]
+msg_230.c(50): warning: nonportable character comparison, op == [230]
+msg_230.c(53): warning: nonportable character comparison, op == [230]
+msg_230.c(56): warning: nonportable character comparison, op == [230]
+msg_230.c(63): warning: nonportable character comparison, op == [230]
+msg_230.c(66): warning: nonportable character comparison, op == [230]
+msg_230.c(69): warning: nonportable character comparison, op == [230]
+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]
diff -r e2c420e2baa5 -r 216b49577387 tests/usr.bin/xlint/lint1/msg_230_uchar.c
--- a/tests/usr.bin/xlint/lint1/msg_230_uchar.c Sat Aug 28 14:42:29 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_230_uchar.c Sat Aug 28 14:45:19 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_230_uchar.c,v 1.2 2021/08/21 11:50:57 rillig Exp $ */
+/* $NetBSD: msg_230_uchar.c,v 1.3 2021/08/28 14:45:19 rillig Exp $ */
# 3 "msg_230_uchar.c"
// Test for message: nonportable character comparison, op %s [230]
@@ -23,7 +23,7 @@
*
* The comparisons may actually differ subtly because of the usual
* arithmetic promotions.
- * */
+ */
/* expect+1: warning: nonportable character comparison, op <= [230] */
if (c <= -1)
return;
Home |
Main Index |
Thread Index |
Old Index