Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: only skip 'unused' warnings after ...



details:   https://anonhg.NetBSD.org/src/rev/543a0f00426e
branches:  trunk
changeset: 377312:543a0f00426e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jul 07 06:03:31 2023 +0000

description:
lint: only skip 'unused' warnings after errors, not other warnings

Previously, in -w mode, any warning suppressed further 'unused'
warnings, even though there was no need to do that.  This can be seen in
the test gcc_attribute_var.c, where only the last unused variable from a
function was marked as unused, the others slipped through.

Fixed by counting the errors and the warnings separately and only
combining them if actually desired.

diffstat:

 tests/usr.bin/xlint/lint1/d_init_array_using_string.c |   4 ++--
 tests/usr.bin/xlint/lint1/decl.c                      |   4 ++--
 tests/usr.bin/xlint/lint1/gcc_attribute_var.c         |   3 ++-
 tests/usr.bin/xlint/lint1/msg_011.c                   |   3 ++-
 tests/usr.bin/xlint/lint1/msg_083.c                   |   3 ++-
 tests/usr.bin/xlint/lint1/msg_090.c                   |   3 ++-
 tests/usr.bin/xlint/lint1/msg_092.c                   |   3 ++-
 tests/usr.bin/xlint/lint1/msg_095.c                   |   3 ++-
 tests/usr.bin/xlint/lint1/msg_097.c                   |   4 ++--
 tests/usr.bin/xlint/lint1/msg_124.c                   |   4 ++--
 tests/usr.bin/xlint/lint1/msg_128.c                   |   3 ++-
 tests/usr.bin/xlint/lint1/msg_165.c                   |   3 ++-
 tests/usr.bin/xlint/lint1/msg_169.c                   |   4 ++--
 tests/usr.bin/xlint/lint1/msg_182.c                   |   3 ++-
 tests/usr.bin/xlint/lint1/msg_188.c                   |   3 ++-
 tests/usr.bin/xlint/lint1/msg_240.c                   |   3 ++-
 tests/usr.bin/xlint/lint1/msg_247.c                   |   3 ++-
 tests/usr.bin/xlint/lint1/msg_277.c                   |   4 +++-
 tests/usr.bin/xlint/lint1/msg_324.c                   |   4 +++-
 tests/usr.bin/xlint/lint1/msg_327.c                   |   4 ++--
 usr.bin/xlint/lint1/decl.c                            |   6 +++---
 usr.bin/xlint/lint1/err.c                             |  13 ++++++-------
 usr.bin/xlint/lint1/externs1.h                        |   5 +++--
 usr.bin/xlint/lint1/main1.c                           |   6 +++---
 usr.bin/xlint/lint1/tree.c                            |   6 +++---
 25 files changed, 60 insertions(+), 44 deletions(-)

diffs (truncated from 488 to 300 lines):

diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/d_init_array_using_string.c
--- a/tests/usr.bin/xlint/lint1/d_init_array_using_string.c     Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/d_init_array_using_string.c     Fri Jul 07 06:03:31 2023 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: d_init_array_using_string.c,v 1.13 2023/03/28 14:44:34 rillig Exp $    */
+/*     $NetBSD: d_init_array_using_string.c,v 1.14 2023/07/07 06:03:31 rillig Exp $    */
 # 3 "d_init_array_using_string.c"
 
 /*
  * Test initialization of arrays and pointers by string literals.
  */
 
-/* lint1-extra-flags: -X 351 */
+/* lint1-extra-flags: -X 191,351 */
 
 void sink(const void *);
 
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/decl.c
--- a/tests/usr.bin/xlint/lint1/decl.c  Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/decl.c  Fri Jul 07 06:03:31 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: decl.c,v 1.21 2023/03/28 14:44:34 rillig Exp $ */
+/*     $NetBSD: decl.c,v 1.22 2023/07/07 06:03:31 rillig Exp $ */
 # 3 "decl.c"
 
 /*
@@ -6,7 +6,7 @@
  * declaration-specifiers and the declarators.
  */
 
-/* lint1-extra-flags: -X 351 */
+/* lint1-extra-flags: -X 191,351 */
 
 /*
  * Even though 'const' comes after 'char' and is therefore quite close to the
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/gcc_attribute_var.c
--- a/tests/usr.bin/xlint/lint1/gcc_attribute_var.c     Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_attribute_var.c     Fri Jul 07 06:03:31 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gcc_attribute_var.c,v 1.8 2023/03/28 14:44:34 rillig Exp $     */
+/*     $NetBSD: gcc_attribute_var.c,v 1.9 2023/07/07 06:03:31 rillig Exp $     */
 # 3 "gcc_attribute_var.c"
 
 /*
@@ -52,6 +52,7 @@ void println(void);
 void
 ambiguity_for_attribute(void)
 {
+       /* expect+1: warning: 'var1' unused in function 'ambiguity_for_attribute' [192] */
        __attribute__((unused)) _Bool var1;
 
        switch (1) {
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/msg_011.c
--- a/tests/usr.bin/xlint/lint1/msg_011.c       Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_011.c       Fri Jul 07 06:03:31 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_011.c,v 1.5 2021/08/26 19:23:25 rillig Exp $       */
+/*     $NetBSD: msg_011.c,v 1.6 2023/07/07 06:03:31 rillig Exp $       */
 # 3 "msg_011.c"
 
 // Test for message: bit-field initializer out of range [11]
@@ -9,6 +9,7 @@ example(void)
        struct {
                signed int si: 3;
                unsigned int ui: 3;
+       /* expect+1: warning: 's' set but not used in function 'example' [191] */
        } s[] = {
                /* expect+2: warning: bit-field initializer out of range [11] */
                /* expect+1: warning: initialization of unsigned with negative constant [221] */
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/msg_083.c
--- a/tests/usr.bin/xlint/lint1/msg_083.c       Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_083.c       Fri Jul 07 06:03:31 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_083.c,v 1.6 2023/03/28 14:44:34 rillig Exp $       */
+/*     $NetBSD: msg_083.c,v 1.7 2023/07/07 06:03:31 rillig Exp $       */
 # 3 "msg_083.c"
 
 // Test for message: storage class after type is obsolescent [83]
@@ -8,6 +8,7 @@
 void
 example(void)
 {
+       /* expect+2: warning: 'x' unused in function 'example' [192] */
        /* expect+1: warning: storage class after type is obsolescent [83] */
        int register x;
 }
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/msg_090.c
--- a/tests/usr.bin/xlint/lint1/msg_090.c       Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_090.c       Fri Jul 07 06:03:31 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_090.c,v 1.6 2023/03/28 20:04:52 rillig Exp $       */
+/*     $NetBSD: msg_090.c,v 1.7 2023/07/07 06:03:31 rillig Exp $       */
 # 3 "msg_090.c"
 
 // Test for message: inconsistent redeclaration of extern '%s' [90]
@@ -10,6 +10,7 @@ extern int random_number(void);
 void
 use(void)
 {
+       /* expect+3: warning: 'random_number' unused in function 'use' [192] */
        /* expect+2: warning: nested 'extern' declaration of 'random_number' [352] */
        /* expect+1: warning: inconsistent redeclaration of extern 'random_number' [90] */
        extern int random_number(int);
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/msg_092.c
--- a/tests/usr.bin/xlint/lint1/msg_092.c       Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_092.c       Fri Jul 07 06:03:31 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_092.c,v 1.4 2022/06/21 21:18:30 rillig Exp $       */
+/*     $NetBSD: msg_092.c,v 1.5 2023/07/07 06:03:31 rillig Exp $       */
 # 3 "msg_092.c"
 
 // Test for message: inconsistent redeclaration of static '%s' [92]
@@ -14,6 +14,7 @@ use_random(void)
 {
        random();
 
+       /* expect+3: warning: 'random' unused in function 'use_random' [192] */
        /* expect+2: warning: dubious static function 'random' at block level [93] */
        /* expect+1: warning: inconsistent redeclaration of static 'random' [92] */
        static double random(void);
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/msg_095.c
--- a/tests/usr.bin/xlint/lint1/msg_095.c       Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_095.c       Fri Jul 07 06:03:31 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_095.c,v 1.6 2023/03/28 14:44:34 rillig Exp $       */
+/*     $NetBSD: msg_095.c,v 1.7 2023/07/07 06:03:31 rillig Exp $       */
 # 3 "msg_095.c"
 
 // Test for message: declaration of '%s' hides earlier one [95]
@@ -12,6 +12,7 @@ example(int identifier)
 {
 
        {
+               /* expect+2: warning: 'identifier' set but not used in function 'example' [191] */
                /* expect+1: warning: declaration of 'identifier' hides earlier one [95] */
                int identifier = 3;
        }
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/msg_097.c
--- a/tests/usr.bin/xlint/lint1/msg_097.c       Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_097.c       Fri Jul 07 06:03:31 2023 +0000
@@ -1,9 +1,9 @@
-/*     $NetBSD: msg_097.c,v 1.4 2022/04/03 09:34:45 rillig Exp $       */
+/*     $NetBSD: msg_097.c,v 1.5 2023/07/07 06:03:31 rillig Exp $       */
 # 3 "msg_097.c"
 
 /* Test for message: suffix U is illegal in traditional C [97] */
 
-/* lint1-flags: -gtw */
+/* lint1-flags: -gtw -X 191 */
 
 void
 example()
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/msg_124.c
--- a/tests/usr.bin/xlint/lint1/msg_124.c       Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_124.c       Fri Jul 07 06:03:31 2023 +0000
@@ -1,9 +1,9 @@
-/*     $NetBSD: msg_124.c,v 1.13 2023/03/28 14:44:34 rillig Exp $      */
+/*     $NetBSD: msg_124.c,v 1.14 2023/07/07 06:03:31 rillig Exp $      */
 # 3 "msg_124.c"
 
 // Test for message: illegal combination of '%s' and '%s', op '%s' [124]
 
-/* lint1-extra-flags: -s -X 351 */
+/* lint1-extra-flags: -s -X 191,351 */
 
 typedef void(*signal_handler)(int);
 
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/msg_128.c
--- a/tests/usr.bin/xlint/lint1/msg_128.c       Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_128.c       Fri Jul 07 06:03:31 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_128.c,v 1.5 2022/06/22 19:23:18 rillig Exp $       */
+/*     $NetBSD: msg_128.c,v 1.6 2023/07/07 06:03:31 rillig Exp $       */
 # 3 "msg_128.c"
 
 // Test for message: operands of '%s' have incompatible pointer types to '%s' and '%s' [128]
@@ -7,6 +7,7 @@ void
 conversion_to_unconst(const char *cstr)
 {
        char *str;
+       /* expect+2: warning: 'str' set but not used in function 'conversion_to_unconst' [191] */
        /* expect+1: warning: operands of '=' have incompatible pointer types to 'char' and 'const char' [128] */
        str = cstr;
 }
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/msg_165.c
--- a/tests/usr.bin/xlint/lint1/msg_165.c       Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_165.c       Fri Jul 07 06:03:31 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_165.c,v 1.4 2022/06/16 16:58:36 rillig Exp $       */
+/*     $NetBSD: msg_165.c,v 1.5 2023/07/07 06:03:31 rillig Exp $       */
 # 3 "msg_165.c"
 
 // Test for message: constant truncated by assignment [165]
@@ -8,6 +8,7 @@ example(void)
 {
        unsigned char ch;
 
+       /* expect+2: warning: 'ch' set but not used in function 'example' [191] */
        /* expect+1: warning: constant truncated by assignment [165] */
        ch = 0x1234;
 }
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/msg_169.c
--- a/tests/usr.bin/xlint/lint1/msg_169.c       Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_169.c       Fri Jul 07 06:03:31 2023 +0000
@@ -1,9 +1,9 @@
-/*     $NetBSD: msg_169.c,v 1.7 2023/03/28 14:44:35 rillig Exp $       */
+/*     $NetBSD: msg_169.c,v 1.8 2023/07/07 06:03:31 rillig Exp $       */
 # 3 "msg_169.c"
 
 // Test for message: precedence confusion possible: parenthesize! [169]
 
-/* lint1-flags: -g -h -S -w -X 351 */
+/* lint1-flags: -g -h -S -w -X 191,351 */
 
 typedef _Bool bool;
 
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/msg_182.c
--- a/tests/usr.bin/xlint/lint1/msg_182.c       Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_182.c       Fri Jul 07 06:03:31 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_182.c,v 1.4 2022/06/22 19:23:18 rillig Exp $       */
+/*     $NetBSD: msg_182.c,v 1.5 2023/07/07 06:03:31 rillig Exp $       */
 # 3 "msg_182.c"
 
 // Test for message: incompatible pointer types to '%s' and '%s' [182]
@@ -13,6 +13,7 @@ return_discarding_volatile(volatile void
 void
 init_discarding_volatile(volatile void *arg)
 {
+       /* expect+2: warning: 'array' set but not used in function 'init_discarding_volatile' [191] */
        /* expect+1: warning: incompatible pointer types to 'void' and 'volatile void' [182] */
        void *array[] = { arg };
 }
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/msg_188.c
--- a/tests/usr.bin/xlint/lint1/msg_188.c       Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_188.c       Fri Jul 07 06:03:31 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_188.c,v 1.5 2023/03/28 14:44:35 rillig Exp $       */
+/*     $NetBSD: msg_188.c,v 1.6 2023/07/07 06:03:31 rillig Exp $       */
 # 3 "msg_188.c"
 
 /* Test for message: no automatic aggregate initialization in traditional C [188] */
@@ -18,6 +18,7 @@ struct point global = {
 void
 function()
 {
+       /* expect+2: warning: 'local' set but not used in function 'function' [191] */
        /* expect+1: warning: no automatic aggregate initialization in traditional C [188] */
        struct point local = {
                3,
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/msg_240.c
--- a/tests/usr.bin/xlint/lint1/msg_240.c       Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_240.c       Fri Jul 07 06:03:31 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_240.c,v 1.4 2022/07/01 20:53:13 rillig Exp $       */
+/*     $NetBSD: msg_240.c,v 1.5 2023/07/07 06:03:31 rillig Exp $       */
 # 3 "msg_240.c"
 
 // Test for message: assignment of different structures (%s != %s) [240]
@@ -32,6 +32,7 @@ return_other_struct(struct s_arg s_arg)
 void
 assign_other_struct(struct s_arg s_arg)
 {
+       /* expect+1: warning: 's_local' unused in function 'assign_other_struct' [192] */
        static struct s_local s_local;
        /* XXX: No warning? */
        s_local = s_arg;
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/msg_247.c
--- a/tests/usr.bin/xlint/lint1/msg_247.c       Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_247.c       Fri Jul 07 06:03:31 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_247.c,v 1.30 2023/07/05 11:36:56 rillig Exp $      */
+/*     $NetBSD: msg_247.c,v 1.31 2023/07/07 06:03:31 rillig Exp $      */
 # 3 "msg_247.c"
 
 // Test for message: pointer cast from '%s' to '%s' may be troublesome [247]
@@ -308,6 +308,7 @@ void *
 cast_between_first_member_struct(void *ptr)
 {
        /* Before tree.c 1.462 from 2022-06-24, lint warned about this cast. */
+       /* expect+1: warning: 't1' set but not used in function 'cast_between_first_member_struct' [191] */
        void *t1 = (ctl_node_t *)(ctl_named_node_t *)ptr;
 
        void *t2 = (ctl_named_node_t *)(ctl_node_t *)ptr;
diff -r 55d0c2be3da2 -r 543a0f00426e tests/usr.bin/xlint/lint1/msg_277.c
--- a/tests/usr.bin/xlint/lint1/msg_277.c       Fri Jul 07 04:43:15 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_277.c       Fri Jul 07 06:03:31 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_277.c,v 1.7 2023/03/28 14:44:35 rillig Exp $       */
+/*     $NetBSD: msg_277.c,v 1.8 2023/07/07 06:03:31 rillig Exp $       */
 # 3 "msg_277.c"
 
 // Test for message: initialization of '%s' with '%s' [277]
@@ -27,7 +27,9 @@ example(enum E e, int i)
        sink_int(i2);
        sink_int(i3);
 
+       /* expect+1: warning: 'init_0' set but not used in function 'example' [191] */
        enum E init_0 = 0;
+       /* expect+2: warning: 'init_1' set but not used in function 'example' [191] */



Home | Main Index | Thread Index | Old Index