tests/lint: sync tests for platform-dependent character comparisonsdiff -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/msg_230.c
(rillig)
--- src/tests/usr.bin/xlint/lint1/msg_230.c 2021/10/09 22:03:38 1.10
+++ src/tests/usr.bin/xlint/lint1/msg_230.c 2022/02/26 11:13:01 1.11
@@ -1,132 +1,132 @@ | @@ -1,132 +1,132 @@ | |||
1 | /* $NetBSD: msg_230.c,v 1.10 2021/10/09 22:03:38 rillig Exp $ */ | 1 | /* $NetBSD: msg_230.c,v 1.11 2022/02/26 11:13:01 rillig Exp $ */ | |
2 | # 3 "msg_230.c" | 2 | # 3 "msg_230.c" | |
3 | 3 | |||
4 | // Test for message: nonportable character comparison '%s %d' [230] | 4 | // Test for message: nonportable character comparison '%s %d' [230] | |
5 | 5 | |||
6 | /* lint1-flags: -S -g -p -w */ | 6 | /* lint1-flags: -S -g -p -w */ | |
7 | /* lint1-only-if: schar */ | 7 | /* lint1-only-if: schar */ | |
8 | 8 | |||
9 | /* | 9 | /* | |
10 | * C11 6.2.5p15 defines that 'char' has the same range, representation, and | 10 | * C11 6.2.5p15 defines that 'char' has the same range, representation, and | |
11 | * behavior as either 'signed char' or 'unsigned char'. | 11 | * behavior as either 'signed char' or 'unsigned char'. | |
12 | * | 12 | * | |
13 | * The portable range of 'char' is from 0 to 127 since all lint platforms | 13 | * The portable range of 'char' is from 0 to 127 since all lint platforms | |
14 | * define CHAR_SIZE to be 8. | 14 | * define CHAR_SIZE to be 8. | |
15 | * | 15 | * | |
16 | * See msg_162.c, which covers 'signed char' and 'unsigned char'. | 16 | * See msg_162.c, which covers 'signed char' and 'unsigned char'. | |
17 | */ | 17 | */ | |
18 | 18 | |||
19 | void | 19 | void | |
20 | compare_plain_char(char c) | 20 | compare_plain_char(char c) | |
21 | { | 21 | { | |
22 | /* expect+1: warning: nonportable character comparison '== -129' [230] */ | 22 | /* expect+1: warning: nonportable character comparison '== -129' [230] */ | |
23 | if (c == -129) | 23 | if (c == -129) | |
24 | return; | 24 | return; | |
25 | /* expect+1: warning: nonportable character comparison '== -128' [230] */ | 25 | /* expect+1: warning: nonportable character comparison '== -128' [230] */ | |
26 | if (c == -128) | 26 | if (c == -128) | |
27 | return; | 27 | return; | |
28 | /* expect+1: warning: nonportable character comparison '== -1' [230] */ | 28 | /* expect+1: warning: nonportable character comparison '== -1' [230] */ | |
29 | if (c == -1) | 29 | if (c == -1) | |
30 | return; | 30 | return; | |
31 | if (c == 0) | 31 | if (c == 0) | |
32 | return; | 32 | return; | |
33 | if (c == 127) | 33 | if (c == 127) | |
34 | return; | 34 | return; | |
35 | /* expect+1: warning: nonportable character comparison '== 128' [230] */ | 35 | /* expect+1: warning: nonportable character comparison '== 128' [230] */ | |
36 | if (c == 128) | 36 | if (c == 128) | |
37 | return; | 37 | return; | |
38 | /* expect+1: warning: nonportable character comparison '== 255' [230] */ | 38 | /* expect+1: warning: nonportable character comparison '== 255' [230] */ | |
39 | if (c == 255) | 39 | if (c == 255) | |
40 | return; | 40 | return; | |
41 | /* expect+1: warning: nonportable character comparison '== 256' [230] */ | 41 | /* expect+1: warning: nonportable character comparison '== 256' [230] */ | |
42 | if (c == 256) | 42 | if (c == 256) | |
43 | return; | 43 | return; | |
44 | } | 44 | } | |
45 | 45 | |||
46 | void | 46 | void | |
47 | compare_plain_char_yoda(char c) | 47 | compare_plain_char_yoda(char c) | |
48 | { | 48 | { | |
49 | /* expect+1: warning: nonportable character comparison '== -129' [230] */ | 49 | /* expect+1: warning: nonportable character comparison '== -129' [230] */ | |
50 | if (-129 == c) | 50 | if (-129 == c) | |
51 | return; | 51 | return; | |
52 | /* expect+1: warning: nonportable character comparison '== -128' [230] */ | 52 | /* expect+1: warning: nonportable character comparison '== -128' [230] */ | |
53 | if (-128 == c) | 53 | if (-128 == c) | |
54 | return; | 54 | return; | |
55 | /* expect+1: warning: nonportable character comparison '== -1' [230] */ | 55 | /* expect+1: warning: nonportable character comparison '== -1' [230] */ | |
56 | if (-1 == c) | 56 | if (-1 == c) | |
57 | return; | 57 | return; | |
58 | if (0 == c) | 58 | if (0 == c) | |
59 | return; | 59 | return; | |
60 | if (127 == c) | 60 | if (127 == c) | |
61 | return; | 61 | return; | |
62 | /* expect+1: warning: nonportable character comparison '== 128' [230] */ | 62 | /* expect+1: warning: nonportable character comparison '== 128' [230] */ | |
63 | if (128 == c) | 63 | if (128 == c) | |
64 | return; | 64 | return; | |
65 | /* expect+1: warning: nonportable character comparison '== 255' [230] */ | 65 | /* expect+1: warning: nonportable character comparison '== 255' [230] */ | |
66 | if (255 == c) | 66 | if (255 == c) | |
67 | return; | 67 | return; | |
68 | /* expect+1: warning: nonportable character comparison '== 256' [230] */ | 68 | /* expect+1: warning: nonportable character comparison '== 256' [230] */ | |
69 | if (256 == c) | 69 | if (256 == c) | |
70 | return; | 70 | return; | |
71 | } | 71 | } | |
72 | 72 | |||
73 | void | 73 | void | |
74 | compare_lt(char c) | 74 | compare_greater(char c) | |
75 | { | 75 | { | |
76 | 76 | |||
77 | /* expect+1: warning: nonportable character comparison '> -2' [230] */ | 77 | /* expect+1: warning: nonportable character comparison '> -2' [230] */ | |
78 | if (c > -2) | 78 | if (c > -2) | |
79 | return; | 79 | return; | |
80 | /* expect+1: warning: nonportable character comparison '>= -1' [230] */ | 80 | /* expect+1: warning: nonportable character comparison '>= -1' [230] */ | |
81 | if (c >= -1) | 81 | if (c >= -1) | |
82 | return; | 82 | return; | |
83 | 83 | |||
84 | /* | 84 | /* | |
85 | * XXX: The following two comparisons have the same effect, yet lint | 85 | * XXX: The following two comparisons have the same effect, yet lint | |
86 | * only warns about one of them. | 86 | * only warns about one of them. | |
87 | */ | 87 | */ | |
88 | /* expect+1: warning: nonportable character comparison '> -1' [230] */ | 88 | /* expect+1: warning: nonportable character comparison '> -1' [230] */ | |
89 | if (c > -1) | 89 | if (c > -1) | |
90 | return; | 90 | return; | |
91 | /* | 91 | /* | |
92 | * On platforms where char is unsigned, lint warns that the | 92 | * On platforms where char is unsigned, lint warns that the | |
93 | * comparison always evaluates to true; see msg_230_uchar.c. | 93 | * comparison always evaluates to true; see msg_230_uchar.c. | |
94 | */ | 94 | */ | |
95 | if (c >= 0) | 95 | if (c >= 0) | |
96 | return; | 96 | return; | |
97 | 97 | |||
98 | /* | 98 | /* | |
99 | * XXX: The following two comparisons have the same effect, yet lint | 99 | * XXX: The following two comparisons have the same effect, yet lint | |
100 | * only warns about one of them. | 100 | * only warns about one of them. | |
101 | */ | 101 | */ | |
102 | if (c > 127) | 102 | if (c > 127) | |
103 | return; | 103 | return; | |
104 | /* expect+1: warning: nonportable character comparison '>= 128' [230] */ | 104 | /* expect+1: warning: nonportable character comparison '>= 128' [230] */ | |
105 | if (c >= 128) | 105 | if (c >= 128) | |
106 | return; | 106 | return; | |
107 | 107 | |||
108 | /* expect+1: warning: nonportable character comparison '> 128' [230] */ | 108 | /* expect+1: warning: nonportable character comparison '> 128' [230] */ | |
109 | if (c > 128) | 109 | if (c > 128) | |
110 | return; | 110 | return; | |
111 | /* expect+1: warning: nonportable character comparison '>= 129' [230] */ | 111 | /* expect+1: warning: nonportable character comparison '>= 129' [230] */ | |
112 | if (c >= 129) | 112 | if (c >= 129) | |
113 | return; | 113 | return; | |
114 | } | 114 | } | |
115 | 115 | |||
116 | void | 116 | void | |
117 | compare_with_character_literal(char ch) | 117 | compare_with_character_literal(char ch) | |
118 | { | 118 | { | |
119 | /* | 119 | /* | |
120 | * FIXME: These comparisons are portable since the character constant | 120 | * FIXME: These comparisons are portable since the character constant | |
121 | * is interpreted using the type 'char' on the exact same platform | 121 | * is interpreted using the type 'char' on the exact same platform | |
122 | * as where the comparison takes place. | 122 | * as where the comparison takes place. | |
123 | */ | 123 | */ | |
124 | /* expect+1: warning: nonportable character comparison '== -128' [230] */ | 124 | /* expect+1: warning: nonportable character comparison '== -128' [230] */ | |
125 | if (ch == '\200') | 125 | if (ch == '\200') | |
126 | return; | 126 | return; | |
127 | /* expect+1: warning: nonportable character comparison '== -1' [230] */ | 127 | /* expect+1: warning: nonportable character comparison '== -1' [230] */ | |
128 | if (ch == '\377') | 128 | if (ch == '\377') | |
129 | return; | 129 | return; | |
130 | if (ch == '\000') | 130 | if (ch == '\000') | |
131 | return; | 131 | return; | |
132 | } | 132 | } |
--- src/tests/usr.bin/xlint/lint1/msg_230_uchar.c 2021/12/16 21:14:59 1.6
+++ src/tests/usr.bin/xlint/lint1/msg_230_uchar.c 2022/02/26 11:13:01 1.7
@@ -1,118 +1,134 @@ | @@ -1,118 +1,134 @@ | |||
1 | /* $NetBSD: msg_230_uchar.c,v 1.6 2021/12/16 21:14:59 rillig Exp $ */ | 1 | /* $NetBSD: msg_230_uchar.c,v 1.7 2022/02/26 11:13:01 rillig Exp $ */ | |
2 | # 3 "msg_230_uchar.c" | 2 | # 3 "msg_230_uchar.c" | |
3 | 3 | |||
4 | // Test for message: nonportable character comparison '%s %d' [230] | 4 | // Test for message: nonportable character comparison '%s %d' [230] | |
5 | 5 | |||
6 | /* lint1-flags: -S -g -p -w */ | 6 | /* lint1-flags: -S -g -p -w */ | |
7 | /* lint1-only-if: uchar */ | 7 | /* lint1-only-if: uchar */ | |
8 | 8 | |||
9 | /* | 9 | /* | |
10 | * C11 6.2.5p15 defines that 'char' has the same range, representation, and | 10 | * C11 6.2.5p15 defines that 'char' has the same range, representation, and | |
11 | * behavior as either 'signed char' or 'unsigned char'. | 11 | * behavior as either 'signed char' or 'unsigned char'. | |
12 | * | 12 | * | |
13 | * The portable range of 'char' is from 0 to 127 since all lint platforms | 13 | * The portable range of 'char' is from 0 to 127 since all lint platforms | |
14 | * define CHAR_SIZE to be 8. | 14 | * define CHAR_SIZE to be 8. | |
15 | * | 15 | * | |
16 | * See msg_162.c, which covers 'signed char' and 'unsigned char'. | 16 | * See msg_162.c, which covers 'signed char' and 'unsigned char'. | |
17 | */ | 17 | */ | |
18 | 18 | |||
19 | void | 19 | void | |
20 | compare_plain_char(char c) | 20 | compare_plain_char(char c) | |
21 | { | 21 | { | |
22 | /* expect+1: warning: nonportable character comparison '== -129' [230] */ | 22 | /* expect+1: warning: nonportable character comparison '== -129' [230] */ | |
23 | if (c == -129) | 23 | if (c == -129) | |
24 | return; | 24 | return; | |
25 | /* expect+1: warning: nonportable character comparison '== -128' [230] */ | 25 | /* expect+1: warning: nonportable character comparison '== -128' [230] */ | |
26 | if (c == -128) | 26 | if (c == -128) | |
27 | return; | 27 | return; | |
28 | /* expect+1: warning: nonportable character comparison '== -1' [230] */ | 28 | /* expect+1: warning: nonportable character comparison '== -1' [230] */ | |
29 | if (c == -1) | 29 | if (c == -1) | |
30 | return; | 30 | return; | |
31 | if (c == 0) | 31 | if (c == 0) | |
32 | return; | 32 | return; | |
33 | if (c == 127) | 33 | if (c == 127) | |
34 | return; | 34 | return; | |
35 | /* expect+1: warning: nonportable character comparison '== 128' [230] */ | 35 | /* expect+1: warning: nonportable character comparison '== 128' [230] */ | |
36 | if (c == 128) | 36 | if (c == 128) | |
37 | return; | 37 | return; | |
38 | /* expect+1: warning: nonportable character comparison '== 255' [230] */ | 38 | /* expect+1: warning: nonportable character comparison '== 255' [230] */ | |
39 | if (c == 255) | 39 | if (c == 255) | |
40 | return; | 40 | return; | |
41 | /* expect+1: warning: nonportable character comparison '== 256' [230] */ | 41 | /* expect+1: warning: nonportable character comparison '== 256' [230] */ | |
42 | if (c == 256) | 42 | if (c == 256) | |
43 | return; | 43 | return; | |
44 | } | 44 | } | |
45 | 45 | |||
46 | void | 46 | void | |
47 | compare_plain_char_yoda(char c) | 47 | compare_plain_char_yoda(char c) | |
48 | { | 48 | { | |
49 | /* expect+1: warning: nonportable character comparison '== -129' */ | 49 | /* expect+1: warning: nonportable character comparison '== -129' [230] */ | |
50 | if (-129 == c) | 50 | if (-129 == c) | |
51 | return; | 51 | return; | |
52 | /* expect+1: warning: nonportable character comparison '== -128' */ | 52 | /* expect+1: warning: nonportable character comparison '== -128' [230] */ | |
53 | if (-128 == c) | 53 | if (-128 == c) | |
54 | return; | 54 | return; | |
55 | /* expect+1: warning: nonportable character comparison '== -1' */ | 55 | /* expect+1: warning: nonportable character comparison '== -1' [230] */ | |
56 | if (-1 == c) | 56 | if (-1 == c) | |
57 | return; | 57 | return; | |
58 | if (0 == c) | 58 | if (0 == c) | |
59 | return; | 59 | return; | |
60 | if (127 == c) | 60 | if (127 == c) | |
61 | return; | 61 | return; | |
62 | /* expect+1: warning: nonportable character comparison '== 128' */ | 62 | /* expect+1: warning: nonportable character comparison '== 128' [230] */ | |
63 | if (128 == c) | 63 | if (128 == c) | |
64 | return; | 64 | return; | |
65 | /* expect+1: warning: nonportable character comparison '== 255' */ | 65 | /* expect+1: warning: nonportable character comparison '== 255' [230] */ | |
66 | if (255 == c) | 66 | if (255 == c) | |
67 | return; | 67 | return; | |
68 | /* expect+1: warning: nonportable character comparison '== 256' */ | 68 | /* expect+1: warning: nonportable character comparison '== 256' [230] */ | |
69 | if (256 == c) | 69 | if (256 == c) | |
70 | return; | 70 | return; | |
71 | } | 71 | } | |
72 | 72 | |||
73 | void | 73 | void | |
74 | compare_lt(char c) | 74 | compare_greater(char c) | |
75 | { | 75 | { | |
76 | 76 | |||
77 | /* expect+1: warning: nonportable character comparison '> -2' [230] */ | 77 | /* expect+1: warning: nonportable character comparison '> -2' [230] */ | |
78 | if (c > -2) | 78 | if (c > -2) | |
79 | return; | 79 | return; | |
80 | /* expect+1: warning: nonportable character comparison '>= -1' [230] */ | 80 | /* expect+1: warning: nonportable character comparison '>= -1' [230] */ | |
81 | if (c >= -1) | 81 | if (c >= -1) | |
82 | return; | 82 | return; | |
83 | 83 | |||
84 | /* | 84 | /* | |
85 | * XXX: The following two comparisons have the same effect, yet lint | 85 | * XXX: The following two comparisons have the same effect, yet lint | |
86 | * only warns about one of them. | 86 | * only warns about one of them. | |
87 | */ | 87 | */ | |
88 | /* expect+1: warning: nonportable character comparison '> -1' [230] */ | 88 | /* expect+1: warning: nonportable character comparison '> -1' [230] */ | |
89 | if (c > -1) | 89 | if (c > -1) | |
90 | return; | 90 | return; | |
91 | /* | 91 | /* | |
92 | * This warning only occurs on uchar platforms since on these | 92 | * This warning only occurs on uchar platforms since on these | |
93 | * platforms it is always true. Code that needs this ordered | 93 | * platforms it is always true. Code that needs this ordered | |
94 | * comparison on values of type plain char is questionable since it | 94 | * comparison on values of type plain char is questionable since it | |
95 | * behaves differently depending on the platform. Such a comparison | 95 | * behaves differently depending on the platform. Such a comparison | |
96 | * should never be needed. | 96 | * should never be needed. | |
97 | */ | 97 | */ | |
98 | /* expect+1: warning: comparison of char with 0, op >= [162] */ | 98 | /* expect+1: warning: comparison of char with 0, op >= [162] */ | |
99 | if (c >= 0) | 99 | if (c >= 0) | |
100 | return; | 100 | return; | |
101 | 101 | |||
102 | /* | 102 | /* | |
103 | * XXX: The following two comparisons have the same effect, yet lint | 103 | * XXX: The following two comparisons have the same effect, yet lint | |
104 | * only warns about one of them. | 104 | * only warns about one of them. | |
105 | */ | 105 | */ | |
106 | if (c > 127) | 106 | if (c > 127) | |
107 | return; | 107 | return; | |
108 | /* expect+1: warning: nonportable character comparison '>= 128' [230] */ | 108 | /* expect+1: warning: nonportable character comparison '>= 128' [230] */ | |
109 | if (c >= 128) | 109 | if (c >= 128) | |
110 | return; | 110 | return; | |
111 | 111 | |||
112 | /* expect+1: warning: nonportable character comparison '> 128' [230] */ | 112 | /* expect+1: warning: nonportable character comparison '> 128' [230] */ | |
113 | if (c > 128) | 113 | if (c > 128) | |
114 | return; | 114 | return; | |
115 | /* expect+1: warning: nonportable character comparison '>= 129' [230] */ | 115 | /* expect+1: warning: nonportable character comparison '>= 129' [230] */ | |
116 | if (c >= 129) | 116 | if (c >= 129) | |
117 | return; | 117 | return; | |
118 | } | 118 | } | |
119 | ||||
120 | void | |||
121 | compare_with_character_literal(char ch) | |||
122 | { | |||
123 | /* | |||
124 | * These comparisons are portable since the character constant is | |||
125 | * interpreted using the type 'char' on the exact same platform as | |||
126 | * where the comparison takes place. | |||
127 | */ | |||
128 | if (ch == '\200') | |||
129 | return; | |||
130 | if (ch == '\377') | |||
131 | return; | |||
132 | if (ch == '\000') | |||
133 | return; | |||
134 | } |