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: align tests for unsign...
details: https://anonhg.NetBSD.org/src/rev/e97205b0af67
branches: trunk
changeset: 1023170:e97205b0af67
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Aug 28 15:25:10 2021 +0000
description:
tests/lint: align tests for unsigned char and signed char
diffstat:
tests/usr.bin/xlint/lint1/msg_230.c | 6 +-
tests/usr.bin/xlint/lint1/msg_230.exp | 6 +-
tests/usr.bin/xlint/lint1/msg_230_uchar.c | 117 +++++++++++++++++++++++----
tests/usr.bin/xlint/lint1/msg_230_uchar.exp | 23 ++++-
4 files changed, 127 insertions(+), 25 deletions(-)
diffs (199 lines):
diff -r 824b52385e8b -r e97205b0af67 tests/usr.bin/xlint/lint1/msg_230.c
--- a/tests/usr.bin/xlint/lint1/msg_230.c Sat Aug 28 15:01:43 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_230.c Sat Aug 28 15:25:10 2021 +0000
@@ -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 @@
/* 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;
diff -r 824b52385e8b -r e97205b0af67 tests/usr.bin/xlint/lint1/msg_230.exp
--- a/tests/usr.bin/xlint/lint1/msg_230.exp Sat Aug 28 15:01:43 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_230.exp Sat Aug 28 15:25:10 2021 +0000
@@ -13,6 +13,6 @@
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]
diff -r 824b52385e8b -r e97205b0af67 tests/usr.bin/xlint/lint1/msg_230_uchar.c
--- a/tests/usr.bin/xlint/lint1/msg_230_uchar.c Sat Aug 28 15:01:43 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_230_uchar.c Sat Aug 28 15:25:10 2021 +0000
@@ -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: comparison of char with 0, op < [162] */
- 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)
+ 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: nonportable character comparison, op <= [230] */
- if (c <= -1)
+ /* expect+1: warning: comparison of char with 0, op >= [162] */
+ if (c >= 0)
+ return;
+
+ /*
+ * XXX: The following two comparisons have the same effect, yet lint
+ * only warns about one of them.
+ */
+ 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;
- if (sc <= -1)
+
+ /* 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 824b52385e8b -r e97205b0af67 tests/usr.bin/xlint/lint1/msg_230_uchar.exp
--- a/tests/usr.bin/xlint/lint1/msg_230_uchar.exp Sat Aug 28 15:01:43 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_230_uchar.exp Sat Aug 28 15:25:10 2021 +0000
@@ -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]
Home |
Main Index |
Thread Index |
Old Index