Fri Jun 9 15:36:31 2023 UTC ()
lint: miscellaneous clean-ups

No binary change, except for line numbers in assertions.


(rillig)
diff -r1.10 -r1.11 src/usr.bin/xlint/common/param.h
diff -r1.316 -r1.317 src/usr.bin/xlint/lint1/decl.c
diff -r1.67 -r1.68 src/usr.bin/xlint/lint1/emit1.c
diff -r1.198 -r1.199 src/usr.bin/xlint/lint1/err.c
diff -r1.155 -r1.156 src/usr.bin/xlint/lint1/func.c
diff -r1.159 -r1.160 src/usr.bin/xlint/lint1/lex.c
diff -r1.164 -r1.165 src/usr.bin/xlint/lint1/lint1.h
diff -r1.526 -r1.527 src/usr.bin/xlint/lint1/tree.c

cvs diff -r1.10 -r1.11 src/usr.bin/xlint/common/param.h (expand / switch to unified diff)

--- src/usr.bin/xlint/common/param.h 2023/01/14 09:21:58 1.10
+++ src/usr.bin/xlint/common/param.h 2023/06/09 15:36:31 1.11
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: param.h,v 1.10 2023/01/14 09:21:58 rillig Exp $ */ 1/* $NetBSD: param.h,v 1.11 2023/06/09 15:36:31 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl 4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved. 5 * All Rights Reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -43,22 +43,13 @@ @@ -43,22 +43,13 @@
43#define HSHSIZ1 503 43#define HSHSIZ1 503
44#define HSHSIZ2 1009 44#define HSHSIZ2 1009
45#define THSHSIZ2 1009 45#define THSHSIZ2 1009
46 46
47/* 47/*
48 * Pull in target-specific parameters. 48 * Pull in target-specific parameters.
49 */ 49 */
50#include "targparam.h" 50#include "targparam.h"
51 51
52/* 52/*
53 * Make sure this matches wchar_t. 53 * Make sure this matches wchar_t.
54 */ 54 */
55#define WCHAR INT 55#define WCHAR INT
56 
57/* 
58 * The sparc64 long double code generation is broken in old gcc. 
59 */ 
60#if !(defined(__sparc64__) && defined(__GNUC__) && __GNUC__ <= 2) 
61typedef long double ldbl_t; 
62#else 
63typedef double ldbl_t; 
64#endif 

cvs diff -r1.316 -r1.317 src/usr.bin/xlint/lint1/decl.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/decl.c 2023/06/09 13:03:49 1.316
+++ src/usr.bin/xlint/lint1/decl.c 2023/06/09 15:36:31 1.317
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: decl.c,v 1.316 2023/06/09 13:03:49 rillig Exp $ */ 1/* $NetBSD: decl.c,v 1.317 2023/06/09 15:36:31 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 * Copyright (c) 1994, 1995 Jochen Pohl 5 * Copyright (c) 1994, 1995 Jochen Pohl
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35#if HAVE_NBTOOL_CONFIG_H 35#if HAVE_NBTOOL_CONFIG_H
36#include "nbtool_config.h" 36#include "nbtool_config.h"
37#endif 37#endif
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40#if defined(__RCSID) 40#if defined(__RCSID)
41__RCSID("$NetBSD: decl.c,v 1.316 2023/06/09 13:03:49 rillig Exp $"); 41__RCSID("$NetBSD: decl.c,v 1.317 2023/06/09 15:36:31 rillig Exp $");
42#endif 42#endif
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <limits.h> 45#include <limits.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <string.h> 47#include <string.h>
48 48
49#include "lint1.h" 49#include "lint1.h"
50 50
51const char unnamed[] = "<unnamed>"; 51const char unnamed[] = "<unnamed>";
52 52
53/* shared type structures for arithmetic types and void */ 53/* shared type structures for arithmetic types and void */
54static type_t typetab[NTSPEC]; 54static type_t typetab[NTSPEC];
@@ -1591,27 +1591,27 @@ declarator_name(sym_t *sym) @@ -1591,27 +1591,27 @@ declarator_name(sym_t *sym)
1591 case DK_OLD_STYLE_ARG: 1591 case DK_OLD_STYLE_ARG:
1592 if ((sc = dcs->d_scl) == NOSCL) 1592 if ((sc = dcs->d_scl) == NOSCL)
1593 sc = AUTO; 1593 sc = AUTO;
1594 else { 1594 else {
1595 lint_assert(sc == REG); 1595 lint_assert(sc == REG);
1596 sym->s_register = true; 1596 sym->s_register = true;
1597 sc = AUTO; 1597 sc = AUTO;
1598 } 1598 }
1599 sym->s_def = DEF; 1599 sym->s_def = DEF;
1600 break; 1600 break;
1601 case DK_AUTO: 1601 case DK_AUTO:
1602 if ((sc = dcs->d_scl) == NOSCL) { 1602 if ((sc = dcs->d_scl) == NOSCL) {
1603 /* 1603 /*
1604 * XXX somewhat ugly because we dont know whether 1604 * XXX somewhat ugly because we don't know whether
1605 * this is AUTO or EXTERN (functions). If we are 1605 * this is AUTO or EXTERN (functions). If we are
1606 * wrong it must be corrected in declare_local(), 1606 * wrong it must be corrected in declare_local(),
1607 * where we have the necessary type information. 1607 * where we have the necessary type information.
1608 */ 1608 */
1609 sc = AUTO; 1609 sc = AUTO;
1610 sym->s_def = DEF; 1610 sym->s_def = DEF;
1611 } else if (sc == AUTO || sc == STATIC || sc == TYPEDEF) 1611 } else if (sc == AUTO || sc == STATIC || sc == TYPEDEF)
1612 sym->s_def = DEF; 1612 sym->s_def = DEF;
1613 else if (sc == REG) { 1613 else if (sc == REG) {
1614 sym->s_register = true; 1614 sym->s_register = true;
1615 sc = AUTO; 1615 sc = AUTO;
1616 sym->s_def = DEF; 1616 sym->s_def = DEF;
1617 } else { 1617 } else {
@@ -1883,27 +1883,27 @@ sym_t * @@ -1883,27 +1883,27 @@ sym_t *
1883enumeration_constant(sym_t *sym, int val, bool impl) 1883enumeration_constant(sym_t *sym, int val, bool impl)
1884{ 1884{
1885 1885
1886 if (sym->s_scl != NOSCL) { 1886 if (sym->s_scl != NOSCL) {
1887 if (sym->s_block_level == block_level) { 1887 if (sym->s_block_level == block_level) {
1888 /* no hflag, because this is illegal */ 1888 /* no hflag, because this is illegal */
1889 if (sym->s_arg) { 1889 if (sym->s_arg) {
1890 /* enumeration constant '%s' hides parameter */ 1890 /* enumeration constant '%s' hides parameter */
1891 warning(57, sym->s_name); 1891 warning(57, sym->s_name);
1892 } else { 1892 } else {
1893 /* redeclaration of '%s' */ 1893 /* redeclaration of '%s' */
1894 error(27, sym->s_name); 1894 error(27, sym->s_name);
1895 /* 1895 /*
1896 * inside blocks it should not be too 1896 * Inside blocks, it should not be too
1897 * complicated to find the position of the 1897 * complicated to find the position of the
1898 * previous declaration 1898 * previous declaration
1899 */ 1899 */
1900 if (block_level == 0) 1900 if (block_level == 0)
1901 print_previous_declaration(sym); 1901 print_previous_declaration(sym);
1902 } 1902 }
1903 } else { 1903 } else {
1904 if (hflag) 1904 if (hflag)
1905 /* redefinition of '%s' hides earlier one */ 1905 /* redefinition of '%s' hides earlier one */
1906 warning(43, sym->s_name); 1906 warning(43, sym->s_name);
1907 } 1907 }
1908 sym = pushdown(sym); 1908 sym = pushdown(sym);
1909 } 1909 }
@@ -2835,27 +2835,27 @@ declare_external_in_block(sym_t *dsym) @@ -2835,27 +2835,27 @@ declare_external_in_block(sym_t *dsym)
2835 if (esym->s_scl == EXTERN) { 2835 if (esym->s_scl == EXTERN) {
2836 /* inconsistent redeclaration of extern '%s' */ 2836 /* inconsistent redeclaration of extern '%s' */
2837 warning(90, dsym->s_name); 2837 warning(90, dsym->s_name);
2838 print_previous_declaration(esym); 2838 print_previous_declaration(esym);
2839 } else { 2839 } else {
2840 /* inconsistent redeclaration of static '%s' */ 2840 /* inconsistent redeclaration of static '%s' */
2841 warning(92, dsym->s_name); 2841 warning(92, dsym->s_name);
2842 print_previous_declaration(esym); 2842 print_previous_declaration(esym);
2843 } 2843 }
2844 } 2844 }
2845 2845
2846 if (compatible) { 2846 if (compatible) {
2847 /* 2847 /*
2848 * Remember the external symbol so we can update usage 2848 * Remember the external symbol, so we can update usage
2849 * information at the end of the block. 2849 * information at the end of the block.
2850 */ 2850 */
2851 dsym->s_ext_sym = esym; 2851 dsym->s_ext_sym = esym;
2852 } 2852 }
2853} 2853}
2854 2854
2855/* 2855/*
2856 * Print an error or a warning if the symbol cannot be initialized due 2856 * Print an error or a warning if the symbol cannot be initialized due
2857 * to type/storage class. Return whether an error has been detected. 2857 * to type/storage class. Return whether an error has been detected.
2858 */ 2858 */
2859static bool 2859static bool
2860check_init(sym_t *sym) 2860check_init(sym_t *sym)
2861{ 2861{

cvs diff -r1.67 -r1.68 src/usr.bin/xlint/lint1/emit1.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/emit1.c 2023/06/09 13:03:49 1.67
+++ src/usr.bin/xlint/lint1/emit1.c 2023/06/09 15:36:31 1.68
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: emit1.c,v 1.67 2023/06/09 13:03:49 rillig Exp $ */ 1/* $NetBSD: emit1.c,v 1.68 2023/06/09 15:36:31 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 * Copyright (c) 1994, 1995 Jochen Pohl 5 * Copyright (c) 1994, 1995 Jochen Pohl
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35#if HAVE_NBTOOL_CONFIG_H 35#if HAVE_NBTOOL_CONFIG_H
36#include "nbtool_config.h" 36#include "nbtool_config.h"
37#endif 37#endif
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40#if defined(__RCSID) 40#if defined(__RCSID)
41__RCSID("$NetBSD: emit1.c,v 1.67 2023/06/09 13:03:49 rillig Exp $"); 41__RCSID("$NetBSD: emit1.c,v 1.68 2023/06/09 15:36:31 rillig Exp $");
42#endif 42#endif
43 43
44#include "lint1.h" 44#include "lint1.h"
45 45
46static void outtt(sym_t *, sym_t *); 46static void outtt(sym_t *, sym_t *);
47static void outfstrg(strg_t *); 47static void outfstrg(strg_t *);
48 48
49/* 49/*
50 * Write type into the output buffer. 50 * Write type into the output buffer.
51 * The type is written as a sequence of substrings, each of which describes a 51 * The type is written as a sequence of substrings, each of which describes a
52 * node of type type_t 52 * node of type type_t
53 * a node is encoded as follows: 53 * a node is encoded as follows:
54 * _Bool B 54 * _Bool B
@@ -183,32 +183,28 @@ outsym(const sym_t *sym, scl_t sc, def_t @@ -183,32 +183,28 @@ outsym(const sym_t *sym, scl_t sc, def_t
183 * file. Compatibility of function declarations (for both static 183 * file. Compatibility of function declarations (for both static
184 * and extern functions) must be checked in lint2. Lint1 can't do 184 * and extern functions) must be checked in lint2. Lint1 can't do
185 * this, especially not if functions are declared at block level 185 * this, especially not if functions are declared at block level
186 * before their first declaration at level 0. 186 * before their first declaration at level 0.
187 */ 187 */
188 if (sc != EXTERN && !(sc == STATIC && sym->s_type->t_tspec == FUNC)) 188 if (sc != EXTERN && !(sc == STATIC && sym->s_type->t_tspec == FUNC))
189 return; 189 return;
190 if (ch_isdigit(sym->s_name[0])) /* 00000000_tmp */ 190 if (ch_isdigit(sym->s_name[0])) /* 00000000_tmp */
191 return; 191 return;
192 192
193 /* reset buffer */ 193 /* reset buffer */
194 outclr(); 194 outclr();
195 195
196 /* 
197 * line number of .c source, 'd' for declaration, Id of current 
198 * source (.c or .h), and line in current source. 
199 */ 
200 outint(csrc_pos.p_line); 196 outint(csrc_pos.p_line);
201 outchar('d'); 197 outchar('d'); /* declaration */
202 outint(get_filename_id(sym->s_def_pos.p_file)); 198 outint(get_filename_id(sym->s_def_pos.p_file));
203 outchar('.'); 199 outchar('.');
204 outint(sym->s_def_pos.p_line); 200 outint(sym->s_def_pos.p_line);
205 201
206 /* flags */ 202 /* flags */
207 203
208 if (def == DEF) 204 if (def == DEF)
209 outchar('d'); /* defined */ 205 outchar('d'); /* defined */
210 else if (def == TDEF) 206 else if (def == TDEF)
211 outchar('t'); /* tentative defined */ 207 outchar('t'); /* tentative defined */
212 else { 208 else {
213 lint_assert(def == DECL); 209 lint_assert(def == DECL);
214 outchar('e'); /* declared */ 210 outchar('e'); /* declared */
@@ -229,55 +225,45 @@ outsym(const sym_t *sym, scl_t sc, def_t @@ -229,55 +225,45 @@ outsym(const sym_t *sym, scl_t sc, def_t
229 outname(sym->s_name); 225 outname(sym->s_name);
230 226
231 /* renamed name of symbol, if necessary */ 227 /* renamed name of symbol, if necessary */
232 if (sym->s_rename != NULL) { 228 if (sym->s_rename != NULL) {
233 outchar('r'); 229 outchar('r');
234 outname(sym->s_rename); 230 outname(sym->s_rename);
235 } 231 }
236 232
237 /* type of the symbol */ 233 /* type of the symbol */
238 outtype(sym->s_type); 234 outtype(sym->s_type);
239} 235}
240 236
241/* 237/*
242 * write information about function definition 238 * Write information about a function definition. This is also done for static
243 * 239 * functions, to later check if they are called with proper argument types.
244 * this is also done for static functions so we are able to check if 
245 * they are called with proper argument types 
246 */ 240 */
247void 241void
248outfdef(const sym_t *fsym, const pos_t *posp, bool rval, bool osdef, 242outfdef(const sym_t *fsym, const pos_t *posp, bool rval, bool osdef,
249 const sym_t *args) 243 const sym_t *args)
250{ 244{
251 int narg; 245 int narg;
252 const sym_t *arg; 246 const sym_t *arg;
253 247
254 /* reset the buffer */ 248 /* reset the buffer */
255 outclr(); 249 outclr();
256 250
257 /* 
258 * line number of .c source, 'd' for declaration, Id of current 
259 * source (.c or .h), and line in current source 
260 * 
261 * we are already at the end of the function. If we are in the 
262 * .c source, posp->p_line is correct, otherwise csrc_pos.p_line 
263 * (for functions defined in header files). 
264 */ 
265 if (posp->p_file == csrc_pos.p_file) { 251 if (posp->p_file == csrc_pos.p_file) {
266 outint(posp->p_line); 252 outint(posp->p_line);
267 } else { 253 } else {
268 outint(csrc_pos.p_line); 254 outint(csrc_pos.p_line);
269 } 255 }
270 outchar('d'); 256 outchar('d'); /* declaration */
271 outint(get_filename_id(posp->p_file)); 257 outint(get_filename_id(posp->p_file));
272 outchar('.'); 258 outchar('.');
273 outint(posp->p_line); 259 outint(posp->p_line);
274 260
275 /* flags */ 261 /* flags */
276 262
277 /* both SCANFLIKE and PRINTFLIKE imply VARARGS */ 263 /* both SCANFLIKE and PRINTFLIKE imply VARARGS */
278 if (printflike_argnum != -1) { 264 if (printflike_argnum != -1) {
279 nvararg = printflike_argnum; 265 nvararg = printflike_argnum;
280 } else if (scanflike_argnum != -1) { 266 } else if (scanflike_argnum != -1) {
281 nvararg = scanflike_argnum; 267 nvararg = scanflike_argnum;
282 } 268 }
283 269
@@ -349,32 +335,28 @@ outfdef(const sym_t *fsym, const pos_t * @@ -349,32 +335,28 @@ outfdef(const sym_t *fsym, const pos_t *
349 * (that is, cast to void) 335 * (that is, cast to void)
350 */ 336 */
351void 337void
352outcall(const tnode_t *tn, bool retval_used, bool retval_discarded) 338outcall(const tnode_t *tn, bool retval_used, bool retval_discarded)
353{ 339{
354 tnode_t *args, *arg; 340 tnode_t *args, *arg;
355 int narg, n, i; 341 int narg, n, i;
356 int64_t q; 342 int64_t q;
357 tspec_t t; 343 tspec_t t;
358 344
359 /* reset buffer */ 345 /* reset buffer */
360 outclr(); 346 outclr();
361 347
362 /* 
363 * line number of .c source, 'c' for function call, Id of current 
364 * source (.c or .h), and line in current source 
365 */ 
366 outint(csrc_pos.p_line); 348 outint(csrc_pos.p_line);
367 outchar('c'); 349 outchar('c'); /* function call */
368 outint(get_filename_id(curr_pos.p_file)); 350 outint(get_filename_id(curr_pos.p_file));
369 outchar('.'); 351 outchar('.');
370 outint(curr_pos.p_line); 352 outint(curr_pos.p_line);
371 353
372 /* 354 /*
373 * flags; 'u' and 'i' must be last to make sure a letter 355 * flags; 'u' and 'i' must be last to make sure a letter
374 * is between the numeric argument of a flag and the name of 356 * is between the numeric argument of a flag and the name of
375 * the function 357 * the function
376 */ 358 */
377 narg = 0; 359 narg = 0;
378 args = tn->tn_right; 360 args = tn->tn_right;
379 for (arg = args; arg != NULL; arg = arg->tn_right) 361 for (arg = args; arg != NULL; arg = arg->tn_right)
380 narg++; 362 narg++;
@@ -577,34 +559,30 @@ outfstrg(strg_t *strg) @@ -577,34 +559,30 @@ outfstrg(strg_t *strg)
577 } 559 }
578 560
579 } 561 }
580 562
581 outchar('"'); 563 outchar('"');
582} 564}
583 565
584/* 566/*
585 * writes a record if sym was used 567 * writes a record if sym was used
586 */ 568 */
587void 569void
588outusg(const sym_t *sym) 570outusg(const sym_t *sym)
589{ 571{
590 if (ch_isdigit(sym->s_name[0])) /* 00000000_tmp */ 572 if (ch_isdigit(sym->s_name[0])) /* 00000000_tmp, from mktempsym */
591 return; 573 return;
592 574
593 /* reset buffer */ 575 /* reset buffer */
594 outclr(); 576 outclr();
595 577
596 /* 
597 * line number of .c source, 'u' for used, Id of current 
598 * source (.c or .h), and line in current source 
599 */ 
600 outint(csrc_pos.p_line); 578 outint(csrc_pos.p_line);
601 outchar('u'); 579 outchar('u'); /* used */
602 outint(get_filename_id(curr_pos.p_file)); 580 outint(get_filename_id(curr_pos.p_file));
603 outchar('.'); 581 outchar('.');
604 outint(curr_pos.p_line); 582 outint(curr_pos.p_line);
605 583
606 /* necessary to delimit both numbers */ 584 /* necessary to delimit both numbers */
607 outchar('x'); 585 outchar('x');
608 586
609 outname(sym->s_name); 587 outname(sym->s_name);
610} 588}

cvs diff -r1.198 -r1.199 src/usr.bin/xlint/lint1/err.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/err.c 2023/06/09 13:03:49 1.198
+++ src/usr.bin/xlint/lint1/err.c 2023/06/09 15:36:31 1.199
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: err.c,v 1.198 2023/06/09 13:03:49 rillig Exp $ */ 1/* $NetBSD: err.c,v 1.199 2023/06/09 15:36:31 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl 4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved. 5 * All Rights Reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#if HAVE_NBTOOL_CONFIG_H 34#if HAVE_NBTOOL_CONFIG_H
35#include "nbtool_config.h" 35#include "nbtool_config.h"
36#endif 36#endif
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39#if defined(__RCSID) 39#if defined(__RCSID)
40__RCSID("$NetBSD: err.c,v 1.198 2023/06/09 13:03:49 rillig Exp $"); 40__RCSID("$NetBSD: err.c,v 1.199 2023/06/09 15:36:31 rillig Exp $");
41#endif 41#endif
42 42
43#include <limits.h> 43#include <limits.h>
44#include <stdarg.h> 44#include <stdarg.h>
45#include <stdlib.h> 45#include <stdlib.h>
46#include <string.h> 46#include <string.h>
47 47
48#include "lint1.h" 48#include "lint1.h"
49 49
50/* number of errors found */ 50/* number of errors found */
51int nerr; 51int nerr;
52 52
53/* number of syntax errors */ 53/* number of syntax errors */
@@ -425,27 +425,27 @@ suppress_messages(const char *p) @@ -425,27 +425,27 @@ suppress_messages(const char *p)
425 425
426 for (; ch_isdigit(*p); p = end + 1) { 426 for (; ch_isdigit(*p); p = end + 1) {
427 unsigned long id = strtoul(p, &end, 10); 427 unsigned long id = strtoul(p, &end, 10);
428 if ((*end != '\0' && *end != ',') || 428 if ((*end != '\0' && *end != ',') ||
429 id >= sizeof(msgs) / sizeof(msgs[0]) || 429 id >= sizeof(msgs) / sizeof(msgs[0]) ||
430 msgs[id][0] == '\0') 430 msgs[id][0] == '\0')
431 break; 431 break;
432 432
433 is_suppressed[id] = true; 433 is_suppressed[id] = true;
434 434
435 if (*end == '\0') 435 if (*end == '\0')
436 return; 436 return;
437 } 437 }
438 errx(1, "invalid message ID '%.*s'", (int)(strcspn(p, ",")), p); 438 errx(1, "invalid message ID '%.*s'", (int)strcspn(p, ","), p);
439} 439}
440 440
441void 441void
442update_location(const char *filename, int lineno, bool is_begin, bool is_end) 442update_location(const char *filename, int lineno, bool is_begin, bool is_end)
443{ 443{
444 struct include_level *top; 444 struct include_level *top;
445 445
446 top = includes; 446 top = includes;
447 if (is_begin && top != NULL) 447 if (is_begin && top != NULL)
448 top->lineno = curr_pos.p_line; 448 top->lineno = curr_pos.p_line;
449 449
450 if (top == NULL || is_begin) { 450 if (top == NULL || is_begin) {
451 top = xmalloc(sizeof(*top)); 451 top = xmalloc(sizeof(*top));
@@ -736,15 +736,15 @@ enable_queries(const char *p) @@ -736,15 +736,15 @@ enable_queries(const char *p)
736 for (; ch_isdigit(*p); p = end + 1) { 736 for (; ch_isdigit(*p); p = end + 1) {
737 unsigned long id = strtoul(p, &end, 10); 737 unsigned long id = strtoul(p, &end, 10);
738 if ((*end != '\0' && *end != ',') || 738 if ((*end != '\0' && *end != ',') ||
739 id >= sizeof(queries) / sizeof(queries[0]) || 739 id >= sizeof(queries) / sizeof(queries[0]) ||
740 queries[id][0] == '\0') 740 queries[id][0] == '\0')
741 break; 741 break;
742 742
743 any_query_enabled = true; 743 any_query_enabled = true;
744 is_query_enabled[id] = true; 744 is_query_enabled[id] = true;
745 745
746 if (*end == '\0') 746 if (*end == '\0')
747 return; 747 return;
748 } 748 }
749 errx(1, "invalid query ID '%.*s'", (int)(strcspn(p, ",")), p); 749 errx(1, "invalid query ID '%.*s'", (int)strcspn(p, ","), p);
750} 750}

cvs diff -r1.155 -r1.156 src/usr.bin/xlint/lint1/func.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/func.c 2023/06/09 13:03:49 1.155
+++ src/usr.bin/xlint/lint1/func.c 2023/06/09 15:36:31 1.156
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: func.c,v 1.155 2023/06/09 13:03:49 rillig Exp $ */ 1/* $NetBSD: func.c,v 1.156 2023/06/09 15:36:31 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl 4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved. 5 * All Rights Reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#if HAVE_NBTOOL_CONFIG_H 34#if HAVE_NBTOOL_CONFIG_H
35#include "nbtool_config.h" 35#include "nbtool_config.h"
36#endif 36#endif
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39#if defined(__RCSID) 39#if defined(__RCSID)
40__RCSID("$NetBSD: func.c,v 1.155 2023/06/09 13:03:49 rillig Exp $"); 40__RCSID("$NetBSD: func.c,v 1.156 2023/06/09 15:36:31 rillig Exp $");
41#endif 41#endif
42 42
43#include <stdlib.h> 43#include <stdlib.h>
44#include <string.h> 44#include <string.h>
45 45
46#include "lint1.h" 46#include "lint1.h"
47#include "cgram.h" 47#include "cgram.h"
48 48
49/* 49/*
50 * Contains a pointer to the symbol table entry of the current function 50 * Contains a pointer to the symbol table entry of the current function
51 * definition. 51 * definition.
52 */ 52 */
53sym_t *funcsym; 53sym_t *funcsym;
@@ -277,28 +277,27 @@ begin_function(sym_t *fsym) @@ -277,28 +277,27 @@ begin_function(sym_t *fsym)
277 for (arg = fsym->s_type->t_args; arg != NULL; arg = arg->s_next) { 277 for (arg = fsym->s_type->t_args; arg != NULL; arg = arg->s_next) {
278 if (arg->s_scl == ABSTRACT) { 278 if (arg->s_scl == ABSTRACT) {
279 lint_assert(arg->s_name == unnamed); 279 lint_assert(arg->s_name == unnamed);
280 /* formal parameter #%d lacks name */ 280 /* formal parameter #%d lacks name */
281 error(59, n); 281 error(59, n);
282 } else { 282 } else {
283 lint_assert(arg->s_name != unnamed); 283 lint_assert(arg->s_name != unnamed);
284 } 284 }
285 n++; 285 n++;
286 } 286 }
287 287
288 /* 288 /*
289 * We must also remember the position. s_def_pos is overwritten 289 * We must also remember the position. s_def_pos is overwritten
290 * if this is an old-style definition and we had already a 290 * if this is an old-style definition, and we had already a prototype.
291 * prototype. 
292 */ 291 */
293 dcs->d_func_def_pos = fsym->s_def_pos; 292 dcs->d_func_def_pos = fsym->s_def_pos;
294 293
295 if ((rdsym = dcs->d_redeclared_symbol) != NULL) { 294 if ((rdsym = dcs->d_redeclared_symbol) != NULL) {
296 295
297 if (!check_redeclaration(fsym, (dowarn = false, &dowarn))) { 296 if (!check_redeclaration(fsym, (dowarn = false, &dowarn))) {
298 297
299 /* 298 /*
300 * Print nothing if the newly defined function 299 * Print nothing if the newly defined function
301 * is defined in old style. A better warning will 300 * is defined in old style. A better warning will
302 * be printed in check_func_lint_directives(). 301 * be printed in check_func_lint_directives().
303 */ 302 */
304 if (dowarn && !fsym->s_osdef) { 303 if (dowarn && !fsym->s_osdef) {
@@ -370,27 +369,27 @@ check_missing_return_value(void) @@ -370,27 +369,27 @@ check_missing_return_value(void)
370void 369void
371end_function(void) 370end_function(void)
372{ 371{
373 sym_t *arg; 372 sym_t *arg;
374 int n; 373 int n;
375 374
376 if (reached) { 375 if (reached) {
377 cstmt->c_had_return_noval = true; 376 cstmt->c_had_return_noval = true;
378 check_missing_return_value(); 377 check_missing_return_value();
379 } 378 }
380 379
381 /* 380 /*
382 * This warning is printed only if the return value was implicitly 381 * This warning is printed only if the return value was implicitly
383 * declared to be int. Otherwise the wrong return statement 382 * declared to be int. Otherwise, the wrong return statement
384 * has already printed a warning. 383 * has already printed a warning.
385 */ 384 */
386 if (cstmt->c_had_return_noval && cstmt->c_had_return_value && 385 if (cstmt->c_had_return_noval && cstmt->c_had_return_value &&
387 funcsym->s_return_type_implicit_int) 386 funcsym->s_return_type_implicit_int)
388 /* function '%s' has 'return expr' and 'return' */ 387 /* function '%s' has 'return expr' and 'return' */
389 warning(216, funcsym->s_name); 388 warning(216, funcsym->s_name);
390 389
391 /* Print warnings for unused arguments */ 390 /* Print warnings for unused arguments */
392 arg = dcs->d_func_args; 391 arg = dcs->d_func_args;
393 n = 0; 392 n = 0;
394 while (arg != NULL && (nargusg == -1 || n < nargusg)) { 393 while (arg != NULL && (nargusg == -1 || n < nargusg)) {
395 check_usage_sym(dcs->d_asm, arg); 394 check_usage_sym(dcs->d_asm, arg);
396 arg = arg->s_next; 395 arg = arg->s_next;
@@ -1353,27 +1352,27 @@ linted(int n) @@ -1353,27 +1352,27 @@ linted(int n)
1353/* ARGSUSED */ 1352/* ARGSUSED */
1354void 1353void
1355bitfieldtype(int n) 1354bitfieldtype(int n)
1356{ 1355{
1357 1356
1358 debug_step("%s, %d: bitfieldtype_ok = true", 1357 debug_step("%s, %d: bitfieldtype_ok = true",
1359 curr_pos.p_file, curr_pos.p_line); 1358 curr_pos.p_file, curr_pos.p_line);
1360 bitfieldtype_ok = true; 1359 bitfieldtype_ok = true;
1361} 1360}
1362 1361
1363/* 1362/*
1364 * PROTOLIB in conjunction with LINTLIBRARY can be used to handle 1363 * PROTOLIB in conjunction with LINTLIBRARY can be used to handle
1365 * prototypes like function definitions. This is done if the argument 1364 * prototypes like function definitions. This is done if the argument
1366 * to PROTOLIB is nonzero. Otherwise prototypes are handled normally. 1365 * to PROTOLIB is nonzero. Otherwise, prototypes are handled normally.
1367 */ 1366 */
1368void 1367void
1369protolib(int n) 1368protolib(int n)
1370{ 1369{
1371 1370
1372 if (dcs->d_kind != DK_EXTERN) { 1371 if (dcs->d_kind != DK_EXTERN) {
1373 /* comment ** %s ** must be outside function */ 1372 /* comment ** %s ** must be outside function */
1374 warning(280, "PROTOLIB"); 1373 warning(280, "PROTOLIB");
1375 return; 1374 return;
1376 } 1375 }
1377 plibflg = n != 0; 1376 plibflg = n != 0;
1378} 1377}
1379 1378

cvs diff -r1.159 -r1.160 src/usr.bin/xlint/lint1/lex.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/lex.c 2023/06/09 13:03:49 1.159
+++ src/usr.bin/xlint/lint1/lex.c 2023/06/09 15:36:31 1.160
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lex.c,v 1.159 2023/06/09 13:03:49 rillig Exp $ */ 1/* $NetBSD: lex.c,v 1.160 2023/06/09 15:36:31 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 * Copyright (c) 1994, 1995 Jochen Pohl 5 * Copyright (c) 1994, 1995 Jochen Pohl
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35#if HAVE_NBTOOL_CONFIG_H 35#if HAVE_NBTOOL_CONFIG_H
36#include "nbtool_config.h" 36#include "nbtool_config.h"
37#endif 37#endif
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40#if defined(__RCSID) 40#if defined(__RCSID)
41__RCSID("$NetBSD: lex.c,v 1.159 2023/06/09 13:03:49 rillig Exp $"); 41__RCSID("$NetBSD: lex.c,v 1.160 2023/06/09 15:36:31 rillig Exp $");
42#endif 42#endif
43 43
44#include <ctype.h> 44#include <ctype.h>
45#include <errno.h> 45#include <errno.h>
46#include <float.h> 46#include <float.h>
47#include <limits.h> 47#include <limits.h>
48#include <math.h> 48#include <math.h>
49#include <stdlib.h> 49#include <stdlib.h>
50#include <string.h> 50#include <string.h>
51 51
52#include "lint1.h" 52#include "lint1.h"
53#include "cgram.h" 53#include "cgram.h"
54 54
@@ -1105,27 +1105,27 @@ lex_comment(void) @@ -1105,27 +1105,27 @@ lex_comment(void)
1105 /* skip whitespace after the keyword */ 1105 /* skip whitespace after the keyword */
1106 while (isspace(c)) 1106 while (isspace(c))
1107 c = read_byte(); 1107 c = read_byte();
1108 1108
1109 /* read the argument, if the keyword accepts one and there is one */ 1109 /* read the argument, if the keyword accepts one and there is one */
1110 l = 0; 1110 l = 0;
1111 if (keywtab[i].arg) { 1111 if (keywtab[i].arg) {
1112 while (isdigit(c) && l < sizeof(arg) - 1) { 1112 while (isdigit(c) && l < sizeof(arg) - 1) {
1113 arg[l++] = (char)c; 1113 arg[l++] = (char)c;
1114 c = read_byte(); 1114 c = read_byte();
1115 } 1115 }
1116 } 1116 }
1117 arg[l] = '\0'; 1117 arg[l] = '\0';
1118 a = l != 0 ? atoi(arg) : -1; 1118 a = l != 0 ? (int)atoi(arg) : -1;
1119 1119
1120 /* skip whitespace after the argument */ 1120 /* skip whitespace after the argument */
1121 while (isspace(c)) 1121 while (isspace(c))
1122 c = read_byte(); 1122 c = read_byte();
1123 1123
1124 seen_end_of_comment = c == '*' && (c = read_byte()) == '/'; 1124 seen_end_of_comment = c == '*' && (c = read_byte()) == '/';
1125 if (!seen_end_of_comment && keywtab[i].func != linted) 1125 if (!seen_end_of_comment && keywtab[i].func != linted)
1126 /* extra characters in lint comment */ 1126 /* extra characters in lint comment */
1127 warning(257); 1127 warning(257);
1128 1128
1129 if (keywtab[i].func != NULL) 1129 if (keywtab[i].func != NULL)
1130 keywtab[i].func(a); 1130 keywtab[i].func(a);
1131 1131

cvs diff -r1.164 -r1.165 src/usr.bin/xlint/lint1/lint1.h (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/lint1.h 2023/04/22 17:49:15 1.164
+++ src/usr.bin/xlint/lint1/lint1.h 2023/06/09 15:36:31 1.165
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lint1.h,v 1.164 2023/04/22 17:49:15 rillig Exp $ */ 1/* $NetBSD: lint1.h,v 1.165 2023/06/09 15:36:31 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 * Copyright (c) 1994, 1995 Jochen Pohl 5 * Copyright (c) 1994, 1995 Jochen Pohl
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -100,28 +100,28 @@ typedef enum { @@ -100,28 +100,28 @@ typedef enum {
100} tqual_t; 100} tqual_t;
101 101
102/* An integer or floating-point value. */ 102/* An integer or floating-point value. */
103typedef struct { 103typedef struct {
104 tspec_t v_tspec; 104 tspec_t v_tspec;
105 /* 105 /*
106 * Set if an integer constant is unsigned only in C90 and later, but 106 * Set if an integer constant is unsigned only in C90 and later, but
107 * not in traditional C. 107 * not in traditional C.
108 * 108 *
109 * See the operators table in ops.def, columns "l r". 109 * See the operators table in ops.def, columns "l r".
110 */ 110 */
111 bool v_unsigned_since_c90; 111 bool v_unsigned_since_c90;
112 union { 112 union {
113 int64_t _v_quad; /* integers */ 113 int64_t _v_quad; /* integers */
114 ldbl_t _v_ldbl; /* floats */ 114 long double _v_ldbl; /* floats */
115 } v_u; 115 } v_u;
116} val_t; 116} val_t;
117 117
118#define v_quad v_u._v_quad 118#define v_quad v_u._v_quad
119#define v_ldbl v_u._v_ldbl 119#define v_ldbl v_u._v_ldbl
120 120
121/* 121/*
122 * Structures of type struct_or_union uniquely identify structures. This can't 122 * Structures of type struct_or_union uniquely identify structures. This can't
123 * be done in structures of type type_t, because these are copied 123 * be done in structures of type type_t, because these are copied
124 * if they must be modified. So it would not be possible to check 124 * if they must be modified. So it would not be possible to check
125 * if two structures are identical by comparing the pointers to 125 * if two structures are identical by comparing the pointers to
126 * the type structures. 126 * the type structures.
127 * 127 *
@@ -365,27 +365,27 @@ typedef struct dinfo { @@ -365,27 +365,27 @@ typedef struct dinfo {
365 for all declarators */ 365 for all declarators */
366 sym_t *d_redeclared_symbol; 366 sym_t *d_redeclared_symbol;
367 unsigned int d_offset_in_bits; /* offset of next structure member */ 367 unsigned int d_offset_in_bits; /* offset of next structure member */
368 unsigned short d_sou_align_in_bits; /* alignment required for current 368 unsigned short d_sou_align_in_bits; /* alignment required for current
369 * structure */ 369 * structure */
370 bool d_const:1; /* const in declaration specifiers */ 370 bool d_const:1; /* const in declaration specifiers */
371 bool d_volatile:1; /* volatile in declaration specifiers */ 371 bool d_volatile:1; /* volatile in declaration specifiers */
372 bool d_inline:1; /* inline in declaration specifiers */ 372 bool d_inline:1; /* inline in declaration specifiers */
373 bool d_multiple_storage_classes:1; /* reported in dcs_end_type */ 373 bool d_multiple_storage_classes:1; /* reported in dcs_end_type */
374 bool d_invalid_type_combination:1; 374 bool d_invalid_type_combination:1;
375 bool d_nonempty_decl:1; /* if at least one tag is declared 375 bool d_nonempty_decl:1; /* if at least one tag is declared
376 * ... in the current function decl. */ 376 * ... in the current function decl. */
377 bool d_vararg:1; 377 bool d_vararg:1;
378 bool d_proto:1; /* current function decl. is prototype */ 378 bool d_proto:1; /* current function decl. is a prototype */
379 bool d_notyp:1; /* set if no type specifier was present */ 379 bool d_notyp:1; /* set if no type specifier was present */
380 bool d_asm:1; /* set if d_ctx == AUTO and asm() present */ 380 bool d_asm:1; /* set if d_ctx == AUTO and asm() present */
381 bool d_packed:1; 381 bool d_packed:1;
382 bool d_used:1; 382 bool d_used:1;
383 type_t *d_tagtyp; /* tag during member declaration */ 383 type_t *d_tagtyp; /* tag during member declaration */
384 sym_t *d_func_args; /* list of arguments during function def. */ 384 sym_t *d_func_args; /* list of arguments during function def. */
385 pos_t d_func_def_pos; /* position of function definition */ 385 pos_t d_func_def_pos; /* position of function definition */
386 sym_t *d_dlsyms; /* first symbol declared at this level */ 386 sym_t *d_dlsyms; /* first symbol declared at this level */
387 sym_t **d_ldlsym; /* points to s_level_next in the last symbol 387 sym_t **d_ldlsym; /* points to s_level_next in the last symbol
388 declaration at this level */ 388 declaration at this level */
389 sym_t *d_func_proto_syms; /* symbols defined in prototype */ 389 sym_t *d_func_proto_syms; /* symbols defined in prototype */
390 struct dinfo *d_enclosing; /* the enclosing declaration level */ 390 struct dinfo *d_enclosing; /* the enclosing declaration level */
391} dinfo_t; 391} dinfo_t;

cvs diff -r1.526 -r1.527 src/usr.bin/xlint/lint1/tree.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/tree.c 2023/06/09 13:03:49 1.526
+++ src/usr.bin/xlint/lint1/tree.c 2023/06/09 15:36:31 1.527
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: tree.c,v 1.526 2023/06/09 13:03:49 rillig Exp $ */ 1/* $NetBSD: tree.c,v 1.527 2023/06/09 15:36:31 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl 4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved. 5 * All Rights Reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#if HAVE_NBTOOL_CONFIG_H 34#if HAVE_NBTOOL_CONFIG_H
35#include "nbtool_config.h" 35#include "nbtool_config.h"
36#endif 36#endif
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39#if defined(__RCSID) 39#if defined(__RCSID)
40__RCSID("$NetBSD: tree.c,v 1.526 2023/06/09 13:03:49 rillig Exp $"); 40__RCSID("$NetBSD: tree.c,v 1.527 2023/06/09 15:36:31 rillig Exp $");
41#endif 41#endif
42 42
43#include <float.h> 43#include <float.h>
44#include <limits.h> 44#include <limits.h>
45#include <math.h> 45#include <math.h>
46#include <signal.h> 46#include <signal.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <string.h> 48#include <string.h>
49 49
50#include "lint1.h" 50#include "lint1.h"
51 51
52 52
53typedef struct integer_constraints { 53typedef struct integer_constraints {
@@ -792,44 +792,44 @@ fold(tnode_t *tn) @@ -792,44 +792,44 @@ fold(tnode_t *tn)
792 int64_t sl, sr = 0, q = 0, mask; 792 int64_t sl, sr = 0, q = 0, mask;
793 uint64_t ul, ur = 0; 793 uint64_t ul, ur = 0;
794 tnode_t *cn; 794 tnode_t *cn;
795 795
796 v = xcalloc(1, sizeof(*v)); 796 v = xcalloc(1, sizeof(*v));
797 v->v_tspec = tn->tn_type->t_tspec; 797 v->v_tspec = tn->tn_type->t_tspec;
798 798
799 t = tn->tn_left->tn_type->t_tspec; 799 t = tn->tn_left->tn_type->t_tspec;
800 utyp = !is_integer(t) || is_uinteger(t); 800 utyp = !is_integer(t) || is_uinteger(t);
801 ul = sl = tn->tn_left->tn_val->v_quad; 801 ul = sl = tn->tn_left->tn_val->v_quad;
802 if (is_binary(tn)) 802 if (is_binary(tn))
803 ur = sr = tn->tn_right->tn_val->v_quad; 803 ur = sr = tn->tn_right->tn_val->v_quad;
804 804
805 mask = value_bits(size_in_bits(t)); 805 mask = (int64_t)value_bits(size_in_bits(t));
806 ovfl = false; 806 ovfl = false;
807 807
808 switch (tn->tn_op) { 808 switch (tn->tn_op) {
809 case UPLUS: 809 case UPLUS:
810 q = sl; 810 q = sl;
811 break; 811 break;
812 case UMINUS: 812 case UMINUS:
813 q = sl == INT64_MIN ? sl : -sl; 813 q = sl == INT64_MIN ? sl : -sl;
814 if (sl != 0 && msb(q, t) == msb(sl, t)) 814 if (sl != 0 && msb(q, t) == msb(sl, t))
815 ovfl = true; 815 ovfl = true;
816 break; 816 break;
817 case COMPL: 817 case COMPL:
818 q = ~sl; 818 q = ~sl;
819 break; 819 break;
820 case MULT: 820 case MULT:
821 if (utyp) { 821 if (utyp) {
822 q = ul * ur; 822 q = (int64_t)(ul * ur);
823 if (q != (q & mask)) 823 if (q != (q & mask))
824 ovfl = true; 824 ovfl = true;
825 else if ((ul != 0) && ((q / ul) != ur)) 825 else if ((ul != 0) && ((q / ul) != ur))
826 ovfl = true; 826 ovfl = true;
827 } else { 827 } else {
828 q = sl * sr; 828 q = sl * sr;
829 if (msb(q, t) != (msb(sl, t) ^ msb(sr, t))) 829 if (msb(q, t) != (msb(sl, t) ^ msb(sr, t)))
830 ovfl = true; 830 ovfl = true;
831 } 831 }
832 break; 832 break;
833 case DIV: 833 case DIV:
834 if (sr == 0) { 834 if (sr == 0) {
835 /* division by 0 */ 835 /* division by 0 */
@@ -863,27 +863,27 @@ fold(tnode_t *tn) @@ -863,27 +863,27 @@ fold(tnode_t *tn)
863 ovfl = true; 863 ovfl = true;
864 break; 864 break;
865 case SHL: 865 case SHL:
866 /* TODO: warn about out-of-bounds 'sr'. */ 866 /* TODO: warn about out-of-bounds 'sr'. */
867 /* TODO: warn about overflow in signed '<<'. */ 867 /* TODO: warn about overflow in signed '<<'. */
868 q = utyp ? (int64_t)(ul << (sr & 63)) : sl << (sr & 63); 868 q = utyp ? (int64_t)(ul << (sr & 63)) : sl << (sr & 63);
869 break; 869 break;
870 case SHR: 870 case SHR:
871 /* 871 /*
872 * The sign must be explicitly extended because 872 * The sign must be explicitly extended because
873 * shifts of signed values are implementation dependent. 873 * shifts of signed values are implementation dependent.
874 */ 874 */
875 /* TODO: warn about out-of-bounds 'sr'. */ 875 /* TODO: warn about out-of-bounds 'sr'. */
876 q = ul >> (sr & 63); 876 q = (int64_t)(ul >> (sr & 63));
877 q = convert_integer(q, t, size_in_bits(t) - (int)sr); 877 q = convert_integer(q, t, size_in_bits(t) - (int)sr);
878 break; 878 break;
879 case LT: 879 case LT:
880 q = (utyp ? ul < ur : sl < sr) ? 1 : 0; 880 q = (utyp ? ul < ur : sl < sr) ? 1 : 0;
881 break; 881 break;
882 case LE: 882 case LE:
883 q = (utyp ? ul <= ur : sl <= sr) ? 1 : 0; 883 q = (utyp ? ul <= ur : sl <= sr) ? 1 : 0;
884 break; 884 break;
885 case GE: 885 case GE:
886 q = (utyp ? ul >= ur : sl >= sr) ? 1 : 0; 886 q = (utyp ? ul >= ur : sl >= sr) ? 1 : 0;
887 break; 887 break;
888 case GT: 888 case GT:
889 q = (utyp ? ul > ur : sl > sr) ? 1 : 0; 889 q = (utyp ? ul > ur : sl > sr) ? 1 : 0;
@@ -993,27 +993,27 @@ subt_size_in_bytes(type_t *tp) @@ -993,27 +993,27 @@ subt_size_in_bytes(type_t *tp)
993 } 993 }
994 994
995 switch (tp->t_tspec) { 995 switch (tp->t_tspec) {
996 case FUNC: 996 case FUNC:
997 /* pointer to function is not allowed here */ 997 /* pointer to function is not allowed here */
998 error(110); 998 error(110);
999 break; 999 break;
1000 case VOID: 1000 case VOID:
1001 /* cannot do pointer arithmetic on operand of unknown size */ 1001 /* cannot do pointer arithmetic on operand of unknown size */
1002 gnuism(136); 1002 gnuism(136);
1003 break; 1003 break;
1004 case STRUCT: 1004 case STRUCT:
1005 case UNION: 1005 case UNION:
1006 if ((elsz_in_bits = tp->t_sou->sou_size_in_bits) == 0) 1006 if ((elsz_in_bits = (int)tp->t_sou->sou_size_in_bits) == 0)
1007 /* cannot do pointer arithmetic on operand of ... */ 1007 /* cannot do pointer arithmetic on operand of ... */
1008 error(136); 1008 error(136);
1009 break; 1009 break;
1010 case ENUM: 1010 case ENUM:
1011 if (is_incomplete(tp)) { 1011 if (is_incomplete(tp)) {
1012 /* cannot do pointer arithmetic on operand of ... */ 1012 /* cannot do pointer arithmetic on operand of ... */
1013 warning(136); 1013 warning(136);
1014 } 1014 }
1015 /* FALLTHROUGH */ 1015 /* FALLTHROUGH */
1016 default: 1016 default:
1017 if ((elsz_in_bits = size_in_bits(tp->t_tspec)) == 0) { 1017 if ((elsz_in_bits = size_in_bits(tp->t_tspec)) == 0) {
1018 /* cannot do pointer arithmetic on operand of ... */ 1018 /* cannot do pointer arithmetic on operand of ... */
1019 error(136); 1019 error(136);
@@ -1531,64 +1531,64 @@ fold_bool(tnode_t *tn) @@ -1531,64 +1531,64 @@ fold_bool(tnode_t *tn)
1531 case LOGAND: 1531 case LOGAND:
1532 v->v_quad = l && r ? 1 : 0; 1532 v->v_quad = l && r ? 1 : 0;
1533 break; 1533 break;
1534 case LOGOR: 1534 case LOGOR:
1535 v->v_quad = l || r ? 1 : 0; 1535 v->v_quad = l || r ? 1 : 0;
1536 break; 1536 break;
1537 default: 1537 default:
1538 lint_assert(/*CONSTCOND*/false); 1538 lint_assert(/*CONSTCOND*/false);
1539 } 1539 }
1540 1540
1541 return build_constant(tn->tn_type, v); 1541 return build_constant(tn->tn_type, v);
1542} 1542}
1543 1543
1544static ldbl_t 1544static long double
1545floating_error_value(tspec_t t, ldbl_t lv) 1545floating_error_value(tspec_t t, long double lv)
1546{ 1546{
1547 if (t == FLOAT) 1547 if (t == FLOAT)
1548 return lv < 0 ? -FLT_MAX : FLT_MAX; 1548 return lv < 0 ? -FLT_MAX : FLT_MAX;
1549 if (t == DOUBLE) 1549 if (t == DOUBLE)
1550 return lv < 0 ? -DBL_MAX : DBL_MAX; 1550 return lv < 0 ? -DBL_MAX : DBL_MAX;
1551 /* 1551 /*
1552 * When NetBSD is cross-built in MKLINT=yes mode on x86_64 for 1552 * When NetBSD is cross-built in MKLINT=yes mode on x86_64 for
1553 * sparc64, tools/lint checks this code while building usr.bin/xlint. 1553 * sparc64, tools/lint checks this code while building usr.bin/xlint.
1554 * In that situation, lint uses the preprocessor for sparc64, in which 1554 * In that situation, lint uses the preprocessor for sparc64, in which
1555 * the type 'long double' is IEEE-754-binary128, affecting the macro 1555 * the type 'long double' is IEEE-754-binary128, affecting the macro
1556 * LDBL_MAX below. The type 'long double', as well as the strtold 1556 * LDBL_MAX below. The type 'long double', as well as the strtold
1557 * implementation, comes from the host platform x86_64 though, where 1557 * implementation, comes from the host platform x86_64 though, where
1558 * 'long double' consumes 128 bits as well but only uses 80 of them. 1558 * 'long double' consumes 128 bits as well but only uses 80 of them.
1559 * The exponent range of the two 'long double' types is the same, but 1559 * The exponent range of the two 'long double' types is the same, but
1560 * the maximum finite value differs due to the extended precision on 1560 * the maximum finite value differs due to the extended precision on
1561 * sparc64. 1561 * sparc64.
1562 * 1562 *
1563 * To properly handle the data types of the target platform, lint 1563 * To properly handle the data types of the target platform, lint
1564 * would have to implement the floating-point types in a 1564 * would have to implement the floating-point types in a
1565 * platform-independent way, which is not worth the effort, given how 1565 * platform-independent way, which is not worth the effort, given how
1566 * few programs practically use 'long double'. 1566 * few programs practically use 'long double'.
1567 */ 1567 */
1568 /* LINTED 248: floating-point constant out of range */ 1568 /* LINTED 248: floating-point constant out of range */
1569 ldbl_t max = LDBL_MAX; 1569 long double max = LDBL_MAX;
1570 return lv < 0 ? -max : max; 1570 return lv < 0 ? -max : max;
1571} 1571}
1572 1572
1573/* 1573/*
1574 * Fold constant nodes having operands with floating point type. 1574 * Fold constant nodes having operands with floating point type.
1575 */ 1575 */
1576static tnode_t * 1576static tnode_t *
1577fold_float(tnode_t *tn) 1577fold_float(tnode_t *tn)
1578{ 1578{
1579 val_t *v; 1579 val_t *v;
1580 tspec_t t; 1580 tspec_t t;
1581 ldbl_t lv, rv = 0; 1581 long double lv, rv = 0;
1582 1582
1583 fpe = 0; 1583 fpe = 0;
1584 v = xcalloc(1, sizeof(*v)); 1584 v = xcalloc(1, sizeof(*v));
1585 v->v_tspec = t = tn->tn_type->t_tspec; 1585 v->v_tspec = t = tn->tn_type->t_tspec;
1586 1586
1587 lint_assert(is_floating(t)); 1587 lint_assert(is_floating(t));
1588 lint_assert(t == tn->tn_left->tn_type->t_tspec); 1588 lint_assert(t == tn->tn_left->tn_type->t_tspec);
1589 lint_assert(!is_binary(tn) || t == tn->tn_right->tn_type->t_tspec); 1589 lint_assert(!is_binary(tn) || t == tn->tn_right->tn_type->t_tspec);
1590 1590
1591 lv = tn->tn_left->tn_val->v_ldbl; 1591 lv = tn->tn_left->tn_val->v_ldbl;
1592 if (is_binary(tn)) 1592 if (is_binary(tn))
1593 rv = tn->tn_right->tn_val->v_ldbl; 1593 rv = tn->tn_right->tn_val->v_ldbl;
1594 1594
@@ -1671,27 +1671,27 @@ build_binary(tnode_t *ln, op_t op, bool  @@ -1671,27 +1671,27 @@ build_binary(tnode_t *ln, op_t op, bool
1671{ 1671{
1672 const mod_t *mp; 1672 const mod_t *mp;
1673 tnode_t *ntn; 1673 tnode_t *ntn;
1674 type_t *rettp; 1674 type_t *rettp;
1675 1675
1676 mp = &modtab[op]; 1676 mp = &modtab[op];
1677 1677
1678 /* If there was an error in one of the operands, return. */ 1678 /* If there was an error in one of the operands, return. */
1679 if (ln == NULL || (mp->m_binary && rn == NULL)) 1679 if (ln == NULL || (mp->m_binary && rn == NULL))
1680 return NULL; 1680 return NULL;
1681 1681
1682 /* 1682 /*
1683 * Apply class conversions to the left operand, but only if its 1683 * Apply class conversions to the left operand, but only if its
1684 * value is needed or it is compared with zero. 1684 * value is needed or compared with zero.
1685 */ 1685 */
1686 if (mp->m_value_context || mp->m_compares_with_zero) 1686 if (mp->m_value_context || mp->m_compares_with_zero)
1687 ln = cconv(ln); 1687 ln = cconv(ln);
1688 /* 1688 /*
1689 * The right operand is almost always in a test or value context, 1689 * The right operand is almost always in a test or value context,
1690 * except if it is a struct or union member. 1690 * except if it is a struct or union member.
1691 */ 1691 */
1692 if (mp->m_binary && op != ARROW && op != POINT) 1692 if (mp->m_binary && op != ARROW && op != POINT)
1693 rn = cconv(rn); 1693 rn = cconv(rn);
1694 1694
1695 /* 1695 /*
1696 * Print some warnings for comparisons of unsigned values with 1696 * Print some warnings for comparisons of unsigned values with
1697 * constants lower than or equal to null. This must be done 1697 * constants lower than or equal to null. This must be done
@@ -3666,27 +3666,27 @@ convert(op_t op, int arg, type_t *tp, tn @@ -3666,27 +3666,27 @@ convert(op_t op, int arg, type_t *tp, tn
3666 ntn->tn_op = CON; 3666 ntn->tn_op = CON;
3667 ntn->tn_val = expr_zero_alloc(sizeof(*ntn->tn_val)); 3667 ntn->tn_val = expr_zero_alloc(sizeof(*ntn->tn_val));
3668 convert_constant(op, arg, ntn->tn_type, ntn->tn_val, 3668 convert_constant(op, arg, ntn->tn_type, ntn->tn_val,
3669 tn->tn_val); 3669 tn->tn_val);
3670 } 3670 }
3671 3671
3672 return ntn; 3672 return ntn;
3673} 3673}
3674 3674
3675static void 3675static void
3676convert_constant_floating(op_t op, int arg, tspec_t ot, const type_t *tp, 3676convert_constant_floating(op_t op, int arg, tspec_t ot, const type_t *tp,
3677 tspec_t nt, val_t *v, val_t *nv) 3677 tspec_t nt, val_t *v, val_t *nv)
3678{ 3678{
3679 ldbl_t max = 0.0, min = 0.0; 3679 long double max = 0.0, min = 0.0;
3680 3680
3681 switch (nt) { 3681 switch (nt) {
3682 case CHAR: 3682 case CHAR:
3683 max = TARG_CHAR_MAX; min = TARG_CHAR_MIN; break; 3683 max = TARG_CHAR_MAX; min = TARG_CHAR_MIN; break;
3684 case UCHAR: 3684 case UCHAR:
3685 max = TARG_UCHAR_MAX; min = 0; break; 3685 max = TARG_UCHAR_MAX; min = 0; break;
3686 case SCHAR: 3686 case SCHAR:
3687 max = TARG_SCHAR_MAX; min = TARG_SCHAR_MIN; break; 3687 max = TARG_SCHAR_MAX; min = TARG_SCHAR_MIN; break;
3688 case SHORT: 3688 case SHORT:
3689 max = TARG_SHRT_MAX; min = TARG_SHRT_MIN; break; 3689 max = TARG_SHRT_MAX; min = TARG_SHRT_MIN; break;
3690 case USHORT: 3690 case USHORT:
3691 max = TARG_USHRT_MAX; min = 0; break; 3691 max = TARG_USHRT_MAX; min = 0; break;
3692 case ENUM: 3692 case ENUM:
@@ -3744,27 +3744,27 @@ convert_constant_floating(op_t op, int a @@ -3744,27 +3744,27 @@ convert_constant_floating(op_t op, int a
3744 3744
3745static bool 3745static bool
3746convert_constant_to_floating(tspec_t nt, val_t *nv, 3746convert_constant_to_floating(tspec_t nt, val_t *nv,
3747 tspec_t ot, const val_t *v) 3747 tspec_t ot, const val_t *v)
3748{ 3748{
3749 if (nt == FLOAT) { 3749 if (nt == FLOAT) {
3750 nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ? 3750 nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ?
3751 (float)(uint64_t)v->v_quad : (float)v->v_quad; 3751 (float)(uint64_t)v->v_quad : (float)v->v_quad;
3752 } else if (nt == DOUBLE) { 3752 } else if (nt == DOUBLE) {
3753 nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ? 3753 nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ?
3754 (double)(uint64_t)v->v_quad : (double)v->v_quad; 3754 (double)(uint64_t)v->v_quad : (double)v->v_quad;
3755 } else if (nt == LDOUBLE) { 3755 } else if (nt == LDOUBLE) {
3756 nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ? 3756 nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ?
3757 (ldbl_t)(uint64_t)v->v_quad : (ldbl_t)v->v_quad; 3757 (long double)(uint64_t)v->v_quad : (long double)v->v_quad;
3758 } else 3758 } else
3759 return false; 3759 return false;
3760 return true; 3760 return true;
3761} 3761}
3762 3762
3763/* 3763/*
3764 * Print a warning if bits which were set are lost due to the conversion. 3764 * Print a warning if bits which were set are lost due to the conversion.
3765 * This can happen with operator ORASS only. 3765 * This can happen with operator ORASS only.
3766 */ 3766 */
3767static void 3767static void
3768convert_constant_check_range_bitor(size_t nsz, size_t osz, const val_t *v, 3768convert_constant_check_range_bitor(size_t nsz, size_t osz, const val_t *v,
3769 uint64_t xmask, op_t op) 3769 uint64_t xmask, op_t op)
3770{ 3770{
@@ -3816,27 +3816,27 @@ convert_constant_check_range_signed(op_t @@ -3816,27 +3816,27 @@ convert_constant_check_range_signed(op_t
3816 } else { 3816 } else {
3817 /* conversion of negative constant to unsigned type */ 3817 /* conversion of negative constant to unsigned type */
3818 warning(222); 3818 warning(222);
3819 } 3819 }
3820} 3820}
3821 3821
3822/* 3822/*
3823 * Loss of significant bit(s). All truncated bits of unsigned types or all 3823 * Loss of significant bit(s). All truncated bits of unsigned types or all
3824 * truncated bits plus the msb of the target for signed types are considered 3824 * truncated bits plus the msb of the target for signed types are considered
3825 * to be significant bits. Loss of significant bits means that at least one 3825 * to be significant bits. Loss of significant bits means that at least one
3826 * of the bits was set in an unsigned type or that at least one but not all 3826 * of the bits was set in an unsigned type or that at least one but not all
3827 * of the bits was set in a signed type. Loss of significant bits means that 3827 * of the bits was set in a signed type. Loss of significant bits means that
3828 * it is not possible, also not with necessary casts, to convert back to the 3828 * it is not possible, also not with necessary casts, to convert back to the
3829 * original type. A example for a necessary cast is: 3829 * original type. An example for a necessary cast is:
3830 * char c; int i; c = 128; 3830 * char c; int i; c = 128;
3831 * i = c; ** yields -128 ** 3831 * i = c; ** yields -128 **
3832 * i = (unsigned char)c; ** yields 128 ** 3832 * i = (unsigned char)c; ** yields 128 **
3833 */ 3833 */
3834static void 3834static void
3835convert_constant_check_range_truncated(op_t op, int arg, const type_t *tp, 3835convert_constant_check_range_truncated(op_t op, int arg, const type_t *tp,
3836 tspec_t ot) 3836 tspec_t ot)
3837{ 3837{
3838 if (op == ASSIGN && tp->t_bitfield) { 3838 if (op == ASSIGN && tp->t_bitfield) {
3839 /* precision lost in bit-field assignment */ 3839 /* precision lost in bit-field assignment */
3840 warning(166); 3840 warning(166);
3841 } else if (op == ASSIGN) { 3841 } else if (op == ASSIGN) {
3842 /* constant truncated by assignment */ 3842 /* constant truncated by assignment */
@@ -4382,27 +4382,27 @@ constant(tnode_t *tn, bool required) @@ -4382,27 +4382,27 @@ constant(tnode_t *tn, bool required)
4382 return v; 4382 return v;
4383 } 4383 }
4384 4384
4385 v->v_tspec = tn->tn_type->t_tspec; 4385 v->v_tspec = tn->tn_type->t_tspec;
4386 4386
4387 if (tn->tn_op == CON) { 4387 if (tn->tn_op == CON) {
4388 lint_assert(tn->tn_type->t_tspec == tn->tn_val->v_tspec); 4388 lint_assert(tn->tn_type->t_tspec == tn->tn_val->v_tspec);
4389 if (is_integer(tn->tn_val->v_tspec)) { 4389 if (is_integer(tn->tn_val->v_tspec)) {
4390 v->v_unsigned_since_c90 = 4390 v->v_unsigned_since_c90 =
4391 tn->tn_val->v_unsigned_since_c90; 4391 tn->tn_val->v_unsigned_since_c90;
4392 v->v_quad = tn->tn_val->v_quad; 4392 v->v_quad = tn->tn_val->v_quad;
4393 return v; 4393 return v;
4394 } 4394 }
4395 v->v_quad = tn->tn_val->v_ldbl; 4395 v->v_quad = (int64_t)tn->tn_val->v_ldbl;
4396 } else { 4396 } else {
4397 v->v_quad = 1; 4397 v->v_quad = 1;
4398 } 4398 }
4399 4399
4400 if (required) 4400 if (required)
4401 /* integral constant expression expected */ 4401 /* integral constant expression expected */
4402 error(55); 4402 error(55);
4403 else 4403 else
4404 /* variable array dimension is a C99/GCC extension */ 4404 /* variable array dimension is a C99/GCC extension */
4405 c99ism(318); 4405 c99ism(318);
4406 4406
4407 if (!is_integer(v->v_tspec)) 4407 if (!is_integer(v->v_tspec))
4408 v->v_tspec = INT; 4408 v->v_tspec = INT;
@@ -4540,27 +4540,27 @@ check_expr_load(const tnode_t *ln) @@ -4540,27 +4540,27 @@ check_expr_load(const tnode_t *ln)
4540 /* check the range of array indices */ 4540 /* check the range of array indices */
4541 check_array_index(ln->tn_left, false); 4541 check_array_index(ln->tn_left, false);
4542} 4542}
4543 4543
4544static void 4544static void
4545check_expr_side_effect(const tnode_t *ln, bool szof) 4545check_expr_side_effect(const tnode_t *ln, bool szof)
4546{ 4546{
4547 dinfo_t *di; 4547 dinfo_t *di;
4548 4548
4549 /* XXX: Taking warn_about_unreachable into account here feels wrong. */ 4549 /* XXX: Taking warn_about_unreachable into account here feels wrong. */
4550 if (ln->tn_op == NAME && (reached || !warn_about_unreachable)) { 4550 if (ln->tn_op == NAME && (reached || !warn_about_unreachable)) {
4551 scl_t sc = ln->tn_sym->s_scl; 4551 scl_t sc = ln->tn_sym->s_scl;
4552 /* 4552 /*
4553 * Look if there was a asm statement in one of the 4553 * Look if there was an asm statement in one of the
4554 * compound statements we are in. If not, we don't 4554 * compound statements we are in. If not, we don't
4555 * print a warning. 4555 * print a warning.
4556 */ 4556 */
4557 for (di = dcs; di != NULL; di = di->d_enclosing) { 4557 for (di = dcs; di != NULL; di = di->d_enclosing) {
4558 if (di->d_asm) 4558 if (di->d_asm)
4559 break; 4559 break;
4560 } 4560 }
4561 if (sc != EXTERN && sc != STATIC && 4561 if (sc != EXTERN && sc != STATIC &&
4562 !ln->tn_sym->s_set && !szof && di == NULL) { 4562 !ln->tn_sym->s_set && !szof && di == NULL) {
4563 /* '%s' may be used before set */ 4563 /* '%s' may be used before set */
4564 warning(158, ln->tn_sym->s_name); 4564 warning(158, ln->tn_sym->s_name);
4565 mark_as_set(ln->tn_sym); 4565 mark_as_set(ln->tn_sym);
4566 } 4566 }
@@ -4764,27 +4764,27 @@ constant_addr(const tnode_t *tn, const s @@ -4764,27 +4764,27 @@ constant_addr(const tnode_t *tn, const s
4764 } else { 4764 } else {
4765 return false; 4765 return false;
4766 } 4766 }
4767 *symp = sym; 4767 *symp = sym;
4768 *offsp = offs1 + offs2; 4768 *offsp = offs1 + offs2;
4769 return true; 4769 return true;
4770 case ADDR: 4770 case ADDR:
4771 if (tn->tn_left->tn_op == NAME) { 4771 if (tn->tn_left->tn_op == NAME) {
4772 *symp = tn->tn_left->tn_sym; 4772 *symp = tn->tn_left->tn_sym;
4773 *offsp = 0; 4773 *offsp = 0;
4774 return true; 4774 return true;
4775 } else { 4775 } else {
4776 /* 4776 /*
4777 * If this would be the front end of a compiler we 4777 * If this were the front end of a compiler, we
4778 * would return a label instead of 0, at least if 4778 * would return a label instead of 0, at least if
4779 * 'tn->tn_left->tn_op == STRING'. 4779 * 'tn->tn_left->tn_op == STRING'.
4780 */ 4780 */
4781 *symp = NULL; 4781 *symp = NULL;
4782 *offsp = 0; 4782 *offsp = 0;
4783 return true; 4783 return true;
4784 } 4784 }
4785 case CVT: 4785 case CVT:
4786 t = tn->tn_type->t_tspec; 4786 t = tn->tn_type->t_tspec;
4787 ot = tn->tn_left->tn_type->t_tspec; 4787 ot = tn->tn_left->tn_type->t_tspec;
4788 if ((!is_integer(t) && t != PTR) || 4788 if ((!is_integer(t) && t != PTR) ||
4789 (!is_integer(ot) && ot != PTR)) { 4789 (!is_integer(ot) && ot != PTR)) {
4790 return false; 4790 return false;