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: in strict bool mode, continue afte...



details:   https://anonhg.NetBSD.org/src/rev/bce58d0183e4
branches:  trunk
changeset: 1022092:bce58d0183e4
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jul 04 07:09:39 2021 +0000

description:
lint: in strict bool mode, continue after error message

If a controlling expression is not of type bool but of any other scalar
type, keep the expression.  Its value is still useful for control flow
analysis.

This prevents an assertion failure when running lint on the generated
scan.c, which contains a "while (1)" that does not stem from a system
header.  If it did, lint would accept it, see tn_from_system_header. But
"scan.c" is not considered a system header.  Maybe lint's definition of
a system header needs to be revisited.

After fixing this, there is another assertion failure though, so scan.c
is not yet ready to be inspected by lint.

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c   |  12 ++++++------
 tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp |   1 +
 tests/usr.bin/xlint/lint1/msg_333.c             |  25 +++++++++++++++++++------
 tests/usr.bin/xlint/lint1/msg_333.exp           |   9 +++++----
 usr.bin/xlint/lint1/func.c                      |   5 ++---
 5 files changed, 33 insertions(+), 19 deletions(-)

diffs (121 lines):

diff -r 2a5313316766 -r bce58d0183e4 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Sun Jul 04 06:55:47 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Sun Jul 04 07:09:39 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_c99_bool_strict.c,v 1.29 2021/07/02 18:52:20 rillig Exp $    */
+/*     $NetBSD: d_c99_bool_strict.c,v 1.30 2021/07/04 07:09:39 rillig Exp $    */
 # 3 "d_c99_bool_strict.c"
 
 /*
@@ -373,13 +373,13 @@
        if (b)
                do_nothing();
 
-       if (0)                  /* expect: 333 */
+       if (/*CONSTCOND*/0)     /* expect: 333 */
+               do_nothing();   /* expect: statement not reached [193] */
+
+       if (/*CONSTCOND*/1)     /* expect: 333 */
                do_nothing();
 
-       if (1)                  /* expect: 333 */
-               do_nothing();
-
-       if (2)                  /* expect: 333 */
+       if (/*CONSTCOND*/2)     /* expect: 333 */
                do_nothing();
 
        /* Not allowed: There is no implicit conversion from scalar to bool. */
diff -r 2a5313316766 -r bce58d0183e4 tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp   Sun Jul 04 06:55:47 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp   Sun Jul 04 07:09:39 2021 +0000
@@ -58,6 +58,7 @@
 d_c99_bool_strict.c(368): warning: statement not reached [193]
 d_c99_bool_strict.c(370): warning: constant in conditional context [161]
 d_c99_bool_strict.c(376): error: controlling expression must be bool, not 'int' [333]
+d_c99_bool_strict.c(377): warning: statement not reached [193]
 d_c99_bool_strict.c(379): error: controlling expression must be bool, not 'int' [333]
 d_c99_bool_strict.c(382): error: controlling expression must be bool, not 'int' [333]
 d_c99_bool_strict.c(386): error: controlling expression must be bool, not 'int' [333]
diff -r 2a5313316766 -r bce58d0183e4 tests/usr.bin/xlint/lint1/msg_333.c
--- a/tests/usr.bin/xlint/lint1/msg_333.c       Sun Jul 04 06:55:47 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_333.c       Sun Jul 04 07:09:39 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_333.c,v 1.3 2021/03/21 14:36:59 rillig Exp $       */
+/*     $NetBSD: msg_333.c,v 1.4 2021/07/04 07:09:39 rillig Exp $       */
 # 3 "msg_333.c"
 
 // Test for message: controlling expression must be bool, not '%s' [333]
@@ -12,15 +12,28 @@
 const char *
 example(bool b, int i, const char *p)
 {
+
        if (b)
                return "bool";
-       if (i)                  /* expect: 333 */
+
+       /* expect+1: must be bool, not 'int' [333] */
+       if (i)
                return "int";
-       if (p)                  /* expect: 333 */
+
+       /* expect+1: must be bool, not 'pointer' [333] */
+       if (p)
                return "pointer";
-       if (__lint_false)
-               return "bool constant"; /* expect: statement not reached */
-       if (0)                  /* expect: 333 */
+
+       if (__lint_false) {
+               /* expect+1: warning: statement not reached [193] */
+               return "bool constant";
+       }
+
+       /* expect+1: controlling expression must be bool, not 'int' [333] */
+       if (0) {
+               /* expect+1: warning: statement not reached [193] */
                return "integer constant";
+       }
+
        return p + i;
 }
diff -r 2a5313316766 -r bce58d0183e4 tests/usr.bin/xlint/lint1/msg_333.exp
--- a/tests/usr.bin/xlint/lint1/msg_333.exp     Sun Jul 04 06:55:47 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_333.exp     Sun Jul 04 07:09:39 2021 +0000
@@ -1,4 +1,5 @@
-msg_333.c(17): error: controlling expression must be bool, not 'int' [333]
-msg_333.c(19): error: controlling expression must be bool, not 'pointer' [333]
-msg_333.c(22): warning: statement not reached [193]
-msg_333.c(23): error: controlling expression must be bool, not 'int' [333]
+msg_333.c(20): error: controlling expression must be bool, not 'int' [333]
+msg_333.c(24): error: controlling expression must be bool, not 'pointer' [333]
+msg_333.c(29): warning: statement not reached [193]
+msg_333.c(33): error: controlling expression must be bool, not 'int' [333]
+msg_333.c(35): warning: statement not reached [193]
diff -r 2a5313316766 -r bce58d0183e4 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sun Jul 04 06:55:47 2021 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sun Jul 04 07:09:39 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.112 2021/06/30 11:29:29 rillig Exp $        */
+/*     $NetBSD: func.c,v 1.113 2021/07/04 07:09:39 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.112 2021/06/30 11:29:29 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.113 2021/07/04 07:09:39 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -622,7 +622,6 @@
        if (tn != NULL && Tflag && !is_typeok_bool_operand(tn)) {
                /* controlling expression must be bool, not '%s' */
                error(333, tspec_name(tn->tn_type->t_tspec));
-               return NULL;
        }
 
        return tn;



Home | Main Index | Thread Index | Old Index