Thu Mar 28 21:04:49 2024 UTC (66d)
lint: clean up


(rillig)
diff -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/lang_level_c99.c
diff -r1.16 -r1.17 src/usr.bin/xlint/lint1/README.md
diff -r1.234 -r1.235 src/usr.bin/xlint/lint1/err.c
diff -r1.219 -r1.220 src/usr.bin/xlint/lint1/externs1.h

cvs diff -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/lang_level_c99.c (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/lang_level_c99.c 2023/08/06 19:44:50 1.2
+++ src/tests/usr.bin/xlint/lint1/lang_level_c99.c 2024/03/28 21:04:48 1.3
@@ -1,26 +1,31 @@ @@ -1,26 +1,31 @@
1/* $NetBSD: lang_level_c99.c,v 1.2 2023/08/06 19:44:50 rillig Exp $ */ 1/* $NetBSD: lang_level_c99.c,v 1.3 2024/03/28 21:04:48 rillig Exp $ */
2# 3 "lang_level_c99.c" 2# 3 "lang_level_c99.c"
3 3
4/* 4/*
5 * Tests that are specific to the C99 language level, in particular, features 5 * Tests that are specific to the C99 language level, in particular:
6 * that were added in C99. 
7 * 6 *
8 * In the below comments, [-] means unsupported and [x] means supported. 7 * * syntax elements that were added in C99
 8 * * lint diagnostics that differ between the C90 and C99 language levels
 9 * * lint diagnostics that differ between the C99 and C11 language levels
9 */ 10 */
10 11
11/* lint1-flags: -S -w -X 351 */ 12/* lint1-flags: -S -w -X 351 */
12 13
13/* C99 Foreword */ 14/*
 15 * Features that were added in the C99 standard, as listed in the C99 foreword.
 16 *
 17 * In the below comments, [-] means unsupported and [x] means supported.
 18 */
14 19
15// [-] restricted character set support via digraphs and <iso646.h> 20// [-] restricted character set support via digraphs and <iso646.h>
16// 21//
17// Lint neither parses digraphs nor trigraphs. 22// Lint neither parses digraphs nor trigraphs.
18 23
19// [x] wide character library support in <wchar.h> and <wctype.h> 24// [x] wide character library support in <wchar.h> and <wctype.h>
20// 25//
21// On all supported platforms, 'wchar_t' == 'int'. 26// On all supported platforms, 'wchar_t' == 'int'.
22 27
23const int wide_string[] = L"wide"; 28const int wide_string[] = L"wide";
24 29
25// [x] more precise aliasing rules via effective type 30// [x] more precise aliasing rules via effective type
26// 31//

cvs diff -r1.16 -r1.17 src/usr.bin/xlint/lint1/README.md (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/README.md 2024/03/09 13:54:47 1.16
+++ src/usr.bin/xlint/lint1/README.md 2024/03/28 21:04:48 1.17
@@ -1,25 +1,25 @@ @@ -1,25 +1,25 @@
1[//]: # ($NetBSD: README.md,v 1.16 2024/03/09 13:54:47 rillig Exp $) 1[//]: # ($NetBSD: README.md,v 1.17 2024/03/28 21:04:48 rillig Exp $)
2 2
3# Introduction 3# Introduction
4 4
5Lint1 analyzes a single translation unit of C code. 5Lint1 analyzes a single translation unit of C code.
6 6
7* It reads the output of the C preprocessor, retaining the comments. 7* It reads the output of the C preprocessor, retaining the comments.
8* The lexer in `scan.l` and `lex.c` splits the input into tokens. 8* The lexer in `scan.l` and `lex.c` splits the input into tokens.
9* The parser in `cgram.y` creates types and expressions from the tokens. 9* The parser in `cgram.y` creates types and expressions from the tokens.
10* It checks declarations in `decl.c`. 10* The checks for declarations are in `decl.c`.
11* It checks initializations in `init.c`. 11* The checks for initializations are in `init.c`.
12* It checks types and expressions in `tree.c`. 12* The checks for types and expressions are in `tree.c`.
13 13
14To see how a specific lint message is triggered, read the corresponding unit 14To see how a specific lint message is triggered, read the corresponding unit
15test in `tests/usr.bin/xlint/lint1/msg_???.c`. 15test in `tests/usr.bin/xlint/lint1/msg_???.c`.
16 16
17# Features 17# Features
18 18
19## Type checking 19## Type checking
20 20
21Lint has stricter type checking than most C compilers. 21Lint has stricter type checking than most C compilers.
22 22
23In _strict bool mode_, lint treats `bool` as a type that is incompatible with 23In _strict bool mode_, lint treats `bool` as a type that is incompatible with
24other scalar types, like in C#, Go, Java. 24other scalar types, like in C#, Go, Java.
25See the test `d_c99_bool_strict.c` for details. 25See the test `d_c99_bool_strict.c` for details.
@@ -38,30 +38,31 @@ See the test `msg_193.c` for examples. @@ -38,30 +38,31 @@ See the test `msg_193.c` for examples.
38 38
39Lint tries to continue parsing and checking even after seeing errors. 39Lint tries to continue parsing and checking even after seeing errors.
40This part of lint is not robust though, so expect some crashes here, 40This part of lint is not robust though, so expect some crashes here,
41as variables may not be properly initialized or be null pointers. 41as variables may not be properly initialized or be null pointers.
42The cleanup after handling a parse error is often incomplete. 42The cleanup after handling a parse error is often incomplete.
43 43
44## Configurable diagnostic messages 44## Configurable diagnostic messages
45 45
46Whether lint prints a message and whether each message is an error, a warning 46Whether lint prints a message and whether each message is an error, a warning
47or just informational depends on several things: 47or just informational depends on several things:
48 48
49* The language level, with its possible values: 49* The language level, with its possible values:
50 * traditional C (`-t`) 50 * traditional C (`-t`)
51 * migration from traditional C and C90 (default) 51 * migration from traditional C to C90 (default)
52 * C90 (`-s`) 52 * C90 (`-s`)
53 * C99 (`-S`) 53 * C99 (`-S`)
54 * C11 (`-Ac11`) 54 * C11 (`-Ac11`)
 55 * C23 (`-Ac23`)
55* In GCC mode (`-g`), lint allows several GNU extensions, 56* In GCC mode (`-g`), lint allows several GNU extensions,
56 reducing the amount of printed messages. 57 reducing the amount of printed messages.
57* In strict bool mode (`-T`), lint issues errors when `bool` is mixed with 58* In strict bool mode (`-T`), lint issues errors when `bool` is mixed with
58 other scalar types, reusing the existing messages 107 and 211, while also 59 other scalar types, reusing the existing messages 107 and 211, while also
59 defining new messages that are specific to strict bool mode. 60 defining new messages that are specific to strict bool mode.
60* The option `-a` performs the check for lossy conversions from large integer 61* The option `-a` performs the check for lossy conversions from large integer
61 types, the option `-aa` extends this check to small integer types as well, 62 types, the option `-aa` extends this check to small integer types as well,
62 reusing the same message ID. 63 reusing the same message ID.
63* The option `-X` suppresses arbitrary messages by their message ID. 64* The option `-X` suppresses arbitrary messages by their message ID.
64* The option `-q` enables additional queries that are not suitable as regular 65* The option `-q` enables additional queries that are not suitable as regular
65 warnings but may be interesting to look at on a case-by-case basis. 66 warnings but may be interesting to look at on a case-by-case basis.
66 67
67# Limitations 68# Limitations

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

--- src/usr.bin/xlint/lint1/err.c 2024/03/27 19:28:20 1.234
+++ src/usr.bin/xlint/lint1/err.c 2024/03/28 21:04:48 1.235
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: err.c,v 1.234 2024/03/27 19:28:20 rillig Exp $ */ 1/* $NetBSD: err.c,v 1.235 2024/03/28 21:04:48 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.234 2024/03/27 19:28:20 rillig Exp $"); 40__RCSID("$NetBSD: err.c,v 1.235 2024/03/28 21:04:48 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
50bool seen_error; 50bool seen_error;
51bool seen_warning; 51bool seen_warning;
52 52
53/* number of syntax errors */ 53/* number of syntax errors */
@@ -729,27 +729,27 @@ static const char *queries[] = { @@ -729,27 +729,27 @@ static const char *queries[] = {
729 "pointer addition has integer on the left-hand side", // Q5 729 "pointer addition has integer on the left-hand side", // Q5
730 "no-op cast from '%s' to '%s'", // Q6 730 "no-op cast from '%s' to '%s'", // Q6
731 "redundant cast from '%s' to '%s' before assignment", // Q7 731 "redundant cast from '%s' to '%s' before assignment", // Q7
732 "octal number '%.*s'", // Q8 732 "octal number '%.*s'", // Q8
733 "parenthesized return value", // Q9 733 "parenthesized return value", // Q9
734 "chained assignment with '%s' and '%s'", // Q10 734 "chained assignment with '%s' and '%s'", // Q10
735 "static variable '%s' in function", // Q11 735 "static variable '%s' in function", // Q11
736 "comma operator with types '%s' and '%s'", // Q12 736 "comma operator with types '%s' and '%s'", // Q12
737 "redundant 'extern' in function declaration of '%s'", // Q13 737 "redundant 'extern' in function declaration of '%s'", // Q13
738 "comparison '%s' of 'char' with plain integer %d", // Q14 738 "comparison '%s' of 'char' with plain integer %d", // Q14
739 "implicit conversion from integer 0 to pointer '%s'", // Q15 739 "implicit conversion from integer 0 to pointer '%s'", // Q15
740 "'%s' was declared 'static', now non-'static'", // Q16 740 "'%s' was declared 'static', now non-'static'", // Q16
741 "invisible character U+%04X in %s", // Q17 741 "invisible character U+%04X in %s", // Q17
742 "const automatic variable '%s'", // Q18 742 "const automatic variable '%s'", // Q18
743}; 743};
744 744
745bool any_query_enabled; /* for optimizing non-query scenarios */ 745bool any_query_enabled; /* for optimizing non-query scenarios */
746bool is_query_enabled[sizeof(queries) / sizeof(queries[0])]; 746bool is_query_enabled[sizeof(queries) / sizeof(queries[0])];
747 747
748void 748void
749(query_message)(int query_id, ...) 749(query_message)(int query_id, ...)
750{ 750{
751 751
752 if (!is_query_enabled[query_id]) 752 if (!is_query_enabled[query_id])
753 return; 753 return;
754 754
755 va_list ap; 755 va_list ap;

cvs diff -r1.219 -r1.220 src/usr.bin/xlint/lint1/externs1.h (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/externs1.h 2024/03/09 10:41:11 1.219
+++ src/usr.bin/xlint/lint1/externs1.h 2024/03/28 21:04:48 1.220
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: externs1.h,v 1.219 2024/03/09 10:41:11 rillig Exp $ */ 1/* $NetBSD: externs1.h,v 1.220 2024/03/28 21:04:48 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.
@@ -26,65 +26,65 @@ @@ -26,65 +26,65 @@
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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#include <signal.h> 34#include <signal.h>
35 35
36/* 36/*
37 * main1.c 37 * main1.c
38 */ 38 */
 39extern bool Fflag;
 40extern bool Pflag;
 41extern bool Tflag;
39extern int aflag; 42extern int aflag;
40extern bool bflag; 43extern bool bflag;
41extern bool cflag; 44extern bool cflag;
42extern bool eflag; 45extern bool eflag;
43extern bool Fflag; 
44extern bool hflag; 46extern bool hflag;
45extern bool pflag; 47extern bool pflag;
46extern bool rflag; 48extern bool rflag;
47extern bool uflag; 49extern bool uflag;
48extern bool vflag; 50extern bool vflag;
49extern bool yflag; 
50extern bool wflag; 51extern bool wflag;
 52extern bool yflag;
51extern bool zflag; 53extern bool zflag;
52extern bool Tflag; 
53extern bool Pflag; 
54 54
55extern bool allow_trad; 55extern bool allow_trad;
56extern bool allow_c90; 56extern bool allow_c90;
57extern bool allow_c99; 57extern bool allow_c99;
58extern bool allow_c11; 58extern bool allow_c11;
59extern bool allow_c23; 59extern bool allow_c23;
60extern bool allow_gcc; 60extern bool allow_gcc;
61 61
62extern sig_atomic_t fpe; 62extern sig_atomic_t fpe;
63 63
64void norecover(void); 64void norecover(void);
65 65
66/* 66/*
67 * cgram.y 67 * cgram.y
68 */ 68 */
69extern int block_level; 69extern int block_level;
70extern size_t mem_block_level; 70extern size_t mem_block_level;
71extern int yydebug; 71extern int yydebug;
72 72
73int yyerror(const char *); 73int yyerror(const char *);
74int yyparse(void); 74int yyparse(void);
75 75
76/* 76/*
77 * scan.l 77 * lex.c
78 */ 78 */
79extern bool in_gcc_attribute; 79extern bool in_gcc_attribute;
80extern pos_t curr_pos; 80extern pos_t curr_pos;
81extern pos_t csrc_pos; 81extern pos_t csrc_pos;
82extern bool in_system_header; 82extern bool in_system_header;
83extern symbol_kind sym_kind; 83extern symbol_kind sym_kind;
84extern FILE *yyin; 84extern FILE *yyin;
85 85
86void init_lex(void); 86void init_lex(void);
87int64_t convert_integer(int64_t, tspec_t, unsigned int); 87int64_t convert_integer(int64_t, tspec_t, unsigned int);
88void clear_warn_flags(void); 88void clear_warn_flags(void);
89sym_t *getsym(sbuf_t *); 89sym_t *getsym(sbuf_t *);
90void clean_up_after_error(void); 90void clean_up_after_error(void);