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