tests/lint: test comparison of 'unsigned <= 0'diff -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_162.c
(rillig)
--- src/tests/usr.bin/xlint/lint1/msg_162.c 2021/08/28 14:45:19 1.4
+++ src/tests/usr.bin/xlint/lint1/msg_162.c 2021/09/05 16:47:24 1.5
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: msg_162.c,v 1.4 2021/08/28 14:45:19 rillig Exp $ */ | 1 | /* $NetBSD: msg_162.c,v 1.5 2021/09/05 16:47:24 rillig Exp $ */ | |
2 | # 3 "msg_162.c" | 2 | # 3 "msg_162.c" | |
3 | 3 | |||
4 | // Test for message: comparison of %s with %s, op %s [162] | 4 | // Test for message: comparison of %s with %s, op %s [162] | |
5 | 5 | |||
6 | /* lint1-extra-flags: -hp */ | 6 | /* lint1-extra-flags: -hp */ | |
7 | 7 | |||
8 | void | 8 | void | |
9 | left_unsigned(unsigned int ui) | 9 | left_unsigned(unsigned int ui) | |
10 | { | 10 | { | |
11 | if (ui < -5.0) { | 11 | if (ui < -5.0) { | |
12 | } | 12 | } | |
13 | 13 | |||
14 | /* expect+1: warning: comparison of unsigned int with negative constant, op < [162] */ | 14 | /* expect+1: warning: comparison of unsigned int with negative constant, op < [162] */ | |
@@ -72,13 +72,57 @@ compare_signed_char(signed char sc) | @@ -72,13 +72,57 @@ compare_signed_char(signed char sc) | |||
72 | void | 72 | void | |
73 | compare_unsigned_char(unsigned char uc) | 73 | compare_unsigned_char(unsigned char uc) | |
74 | { | 74 | { | |
75 | /* expect+1: warning: comparison of unsigned char with negative constant, op == [162] */ | 75 | /* expect+1: warning: comparison of unsigned char with negative constant, op == [162] */ | |
76 | if (uc == -1) | 76 | if (uc == -1) | |
77 | return; | 77 | return; | |
78 | if (uc == 0) | 78 | if (uc == 0) | |
79 | return; | 79 | return; | |
80 | if (uc == 255) | 80 | if (uc == 255) | |
81 | return; | 81 | return; | |
82 | if (uc == 256) | 82 | if (uc == 256) | |
83 | return; | 83 | return; | |
84 | } | 84 | } | |
85 | ||||
86 | void take_bool(_Bool); | |||
87 | ||||
88 | void | |||
89 | compare_operators(unsigned int x) | |||
90 | { | |||
91 | /* expect+1: warning: comparison of unsigned int with negative constant, op < [162] */ | |||
92 | take_bool(x < -1); | |||
93 | /* expect+1: warning: comparison of unsigned int with 0, op < [162] */ | |||
94 | take_bool(x < 0); | |||
95 | take_bool(x < 1); | |||
96 | ||||
97 | /* expect+1: warning: comparison of unsigned int with negative constant, op <= [162] */ | |||
98 | take_bool(x <= -1); | |||
99 | /* | |||
100 | * XXX: The expression 'x <= 0' is equivalent to 'x < 1', so lint | |||
101 | * should not warn about it, just as it doesn't warn about the | |||
102 | * inverted condition, which is 'x > 0'. | |||
103 | */ | |||
104 | /* expect+1: warning: comparison of unsigned int with 0, op <= [162] */ | |||
105 | take_bool(x <= 0); | |||
106 | take_bool(x <= 1); | |||
107 | ||||
108 | /* expect+1: warning: comparison of unsigned int with negative constant, op > [162] */ | |||
109 | take_bool(x > -1); | |||
110 | take_bool(x > 0); | |||
111 | take_bool(x > 1); | |||
112 | ||||
113 | /* expect+1: warning: comparison of unsigned int with negative constant, op >= [162] */ | |||
114 | take_bool(x >= -1); | |||
115 | /* expect+1: warning: comparison of unsigned int with 0, op >= [162] */ | |||
116 | take_bool(x >= 0); | |||
117 | take_bool(x >= 1); | |||
118 | ||||
119 | /* expect+1: warning: comparison of unsigned int with negative constant, op == [162] */ | |||
120 | take_bool(x == -1); | |||
121 | take_bool(x == 0); | |||
122 | take_bool(x == 1); | |||
123 | ||||
124 | /* expect+1: warning: comparison of unsigned int with negative constant, op != [162] */ | |||
125 | take_bool(x != -1); | |||
126 | take_bool(x != 0); | |||
127 | take_bool(x != 1); | |||
128 | } |
--- src/tests/usr.bin/xlint/lint1/Attic/msg_162.exp 2021/08/28 14:45:19 1.4
+++ src/tests/usr.bin/xlint/lint1/Attic/msg_162.exp 2021/09/05 16:47:24 1.5
@@ -1,9 +1,18 @@ | @@ -1,9 +1,18 @@ | |||
1 | msg_162.c(15): warning: comparison of unsigned int with negative constant, op < [162] | 1 | msg_162.c(15): warning: comparison of unsigned int with negative constant, op < [162] | |
2 | msg_162.c(19): warning: comparison of unsigned int with 0, op < [162] | 2 | msg_162.c(19): warning: comparison of unsigned int with 0, op < [162] | |
3 | msg_162.c(23): warning: comparison of unsigned int with 0, op >= [162] | 3 | msg_162.c(23): warning: comparison of unsigned int with 0, op >= [162] | |
4 | msg_162.c(27): warning: comparison of unsigned int with 0, op <= [162] | 4 | msg_162.c(27): warning: comparison of unsigned int with 0, op <= [162] | |
5 | msg_162.c(39): warning: comparison of negative constant with unsigned int, op > [162] | 5 | msg_162.c(39): warning: comparison of negative constant with unsigned int, op > [162] | |
6 | msg_162.c(43): warning: comparison of 0 with unsigned int, op > [162] | 6 | msg_162.c(43): warning: comparison of 0 with unsigned int, op > [162] | |
7 | msg_162.c(47): warning: comparison of 0 with unsigned int, op <= [162] | 7 | msg_162.c(47): warning: comparison of 0 with unsigned int, op <= [162] | |
8 | msg_162.c(51): warning: comparison of 0 with unsigned int, op >= [162] | 8 | msg_162.c(51): warning: comparison of 0 with unsigned int, op >= [162] | |
9 | msg_162.c(76): warning: comparison of unsigned char with negative constant, op == [162] | 9 | msg_162.c(76): warning: comparison of unsigned char with negative constant, op == [162] | |
10 | msg_162.c(92): warning: comparison of unsigned int with negative constant, op < [162] | |||
11 | msg_162.c(94): warning: comparison of unsigned int with 0, op < [162] | |||
12 | msg_162.c(98): warning: comparison of unsigned int with negative constant, op <= [162] | |||
13 | msg_162.c(105): warning: comparison of unsigned int with 0, op <= [162] | |||
14 | msg_162.c(109): warning: comparison of unsigned int with negative constant, op > [162] | |||
15 | msg_162.c(114): warning: comparison of unsigned int with negative constant, op >= [162] | |||
16 | msg_162.c(116): warning: comparison of unsigned int with 0, op >= [162] | |||
17 | msg_162.c(120): warning: comparison of unsigned int with negative constant, op == [162] | |||
18 | msg_162.c(125): warning: comparison of unsigned int with negative constant, op != [162] |