msg_259.c revision 1.17 1 /* $NetBSD: msg_259.c,v 1.17 2021/09/02 17:26:43 rillig Exp $ */
2 # 3 "msg_259.c"
3
4 // Test for message: argument #%d is converted from '%s' to '%s' due to prototype [259]
5
6 /*
7 * See also msg_297, but that requires the flags -a -p -P, which are not
8 * enabled in the default NetBSD build.
9 */
10
11 /* lint1-only-if: lp64 */
12 /* lint1-extra-flags: -h */
13
14 void plain_char(char);
15 void signed_char(signed char);
16 void unsigned_char(unsigned char);
17 void signed_short(signed short);
18 void unsigned_short(unsigned short);
19 void signed_int(int);
20 void unsigned_int(unsigned int);
21 void signed_long(long);
22 void unsigned_long(unsigned long);
23 void signed_long_long(long long);
24 void unsigned_long_long(unsigned long long);
25
26 void
27 change_in_type_width(char c, int i, long l)
28 {
29 plain_char(c);
30 signed_int(c);
31 /* No warning 259 on LP64, only on ILP32 */
32 signed_long(c);
33
34 plain_char(i); /* XXX: why no warning? */
35 signed_int(i);
36 /* No warning 259 on LP64, only on ILP32 */
37 signed_long(i);
38
39 plain_char(l); /* XXX: why no warning? */
40 /* expect+1: from 'long' to 'int' due to prototype [259] */
41 signed_int(l);
42 signed_long(l);
43 }
44
45 /*
46 * The default argument promotions convert any small integer type to at
47 * least 'int', and without function prototypes, it is not possible to
48 * declare a function that has a parameter smaller than int, therefore
49 * these conversions do not produce any warnings.
50 * FIXME: Remove the warnings for 'signed char'.
51 * There are lossless conversions though, but these are covered by warning
52 * 297 instead.
53 */
54 void
55 small_integer_types(char c, signed char sc, unsigned char uc,
56 signed short ss, unsigned short us,
57 signed int si, unsigned int ui,
58 signed long long sll, unsigned long long ull)
59 {
60 plain_char(c);
61 plain_char(sc);
62 plain_char(uc);
63 plain_char(ss);
64 plain_char(us);
65 plain_char(si);
66 plain_char(ui);
67 plain_char(sll);
68 plain_char(ull);
69
70 signed_char(c);
71 signed_char(sc);
72 signed_char(uc);
73 signed_char(ss);
74 signed_char(us);
75 signed_char(si);
76 signed_char(ui);
77 /* expect+1: warning: argument #1 is converted from 'long long' to 'signed char' due to prototype [259] */
78 signed_char(sll);
79 /* expect+1: warning: argument #1 is converted from 'unsigned long long' to 'signed char' due to prototype [259] */
80 signed_char(ull);
81
82 unsigned_char(c);
83 unsigned_char(sc);
84 unsigned_char(uc);
85 unsigned_char(ss);
86 unsigned_char(us);
87 unsigned_char(si);
88 unsigned_char(ui);
89 unsigned_char(sll);
90 unsigned_char(ull);
91
92 signed_short(c);
93 signed_short(sc);
94 signed_short(uc);
95 signed_short(ss);
96 signed_short(us);
97 signed_short(si);
98 signed_short(ui);
99 signed_short(sll);
100 signed_short(ull);
101
102 unsigned_short(c);
103 unsigned_short(sc);
104 unsigned_short(uc);
105 unsigned_short(ss);
106 unsigned_short(us);
107 unsigned_short(si);
108 unsigned_short(ui);
109 unsigned_short(sll);
110 unsigned_short(ull);
111 }
112
113 /*
114 * Converting a signed integer type to its corresponding unsigned integer
115 * type (C99 6.2.5p6) is usually not a problem since the actual values of the
116 * expressions are usually not anywhere near the maximum signed value. From
117 * a technical standpoint, it is correct to warn here since even small
118 * negative numbers may result in very large positive numbers.
119 *
120 * A common case where it occurs is when the difference of two pointers is
121 * converted to size_t. The type ptrdiff_t is defined to be signed, but in
122 * many practical cases, the expression is '(end - start)', which makes the
123 * resulting value necessarily positive.
124 */
125 void
126 signed_to_unsigned(int si, long sl, long long sll)
127 {
128 /* expect+1: warning: argument #1 is converted from 'int' to 'unsigned int' due to prototype [259] */
129 unsigned_int(si);
130
131 /* expect+1: warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259] */
132 unsigned_int(sl);
133
134 /* expect+1: warning: argument #1 is converted from 'long long' to 'unsigned int' due to prototype [259] */
135 unsigned_int(sll);
136
137 /*
138 * XXX: Why no warning? Even though 'unsigned long' is 64 bits
139 * wide, it cannot represent negative 32-bit values.
140 */
141 unsigned_long(si);
142
143 /* expect+1: warning: argument #1 is converted from 'long' to 'unsigned long' due to prototype [259] */
144 unsigned_long(sl);
145 /* expect+1: warning: argument #1 is converted from 'long long' to 'unsigned long' due to prototype [259] */
146 unsigned_long(sll);
147
148 /*
149 * XXX: Why no warning? Even though 'unsigned long long' is 64 bits
150 * wide, it cannot represent negative 32-bit values.
151 */
152 unsigned_long_long(si);
153
154 /* expect+1: warning: argument #1 is converted from 'long' to 'unsigned long long' due to prototype [259] */
155 unsigned_long_long(sl);
156
157 /* expect+1: warning: argument #1 is converted from 'long long' to 'unsigned long long' due to prototype [259] */
158 unsigned_long_long(sll);
159 }
160
161 void
162 unsigned_to_signed(unsigned int ui, unsigned long ul, unsigned long long ull)
163 {
164 /* expect+1: warning: argument #1 is converted from 'unsigned int' to 'int' due to prototype [259] */
165 signed_int(ui);
166 /* expect+1: warning: argument #1 is converted from 'unsigned long' to 'int' due to prototype [259] */
167 signed_int(ul);
168 /* expect+1: warning: argument #1 is converted from 'unsigned long long' to 'int' due to prototype [259] */
169 signed_int(ull);
170 signed_long(ui);
171 /* expect+1: warning: argument #1 is converted from 'unsigned long' to 'long' due to prototype [259] */
172 signed_long(ul);
173 /* expect+1: warning: argument #1 is converted from 'unsigned long long' to 'long' due to prototype [259] */
174 signed_long(ull);
175 signed_long_long(ui);
176 /* expect+1: warning: argument #1 is converted from 'unsigned long' to 'long long' due to prototype [259] */
177 signed_long_long(ul);
178 /* expect+1: warning: argument #1 is converted from 'unsigned long long' to 'long long' due to prototype [259] */
179 signed_long_long(ull);
180 }
181
182 void
183 signed_to_signed(signed int si, signed long sl, signed long long sll)
184 {
185 signed_int(si);
186 /* expect+1: warning: argument #1 is converted from 'long' to 'int' due to prototype [259] */
187 signed_int(sl);
188 /* expect+1: warning: argument #1 is converted from 'long long' to 'int' due to prototype [259] */
189 signed_int(sll);
190 signed_long(si);
191 signed_long(sl);
192 /* expect+1: warning: argument #1 is converted from 'long long' to 'long' due to prototype [259] */
193 signed_long(sll);
194 signed_long_long(si);
195 /* expect+1: warning: argument #1 is converted from 'long' to 'long long' due to prototype [259] */
196 signed_long_long(sl);
197 signed_long_long(sll);
198 }
199
200 void
201 unsigned_to_unsigned(unsigned int ui, unsigned long ul, unsigned long long ull)
202 {
203 unsigned_int(ui);
204 /* expect+1: warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259] */
205 unsigned_int(ul);
206 /* expect+1: warning: argument #1 is converted from 'unsigned long long' to 'unsigned int' due to prototype [259] */
207 unsigned_int(ull);
208 unsigned_long(ui);
209 unsigned_long(ul);
210 /* expect+1: warning: argument #1 is converted from 'unsigned long long' to 'unsigned long' due to prototype [259] */
211 unsigned_long(ull);
212 unsigned_long_long(ui);
213 /* expect+1: warning: argument #1 is converted from 'unsigned long' to 'unsigned long long' due to prototype [259] */
214 unsigned_long_long(ul);
215 unsigned_long_long(ull);
216 }
217
218 void
219 pass_sizeof_as_smaller_type(void)
220 {
221 /*
222 * XXX: Even though the expression has type size_t, it has a constant
223 * value that fits effortless into an 'unsigned int', it's so small
224 * that it would even fit into a 3-bit bit-field, so lint should not
225 * warn here.
226 */
227 /* expect+1: warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259] */
228 unsigned_int(sizeof(int));
229 }
230