Module Name:    src
Committed By:   rillig
Date:           Sun Jul  4 07:09:39 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: d_c99_bool_strict.c
            d_c99_bool_strict.exp msg_333.c msg_333.exp
        src/usr.bin/xlint/lint1: func.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
cvs rdiff -u -r1.26 -r1.27 \
    src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_333.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_333.exp
cvs rdiff -u -r1.112 -r1.113 src/usr.bin/xlint/lint1/func.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.29 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.30
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.29	Fri Jul  2 18:52:20 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c	Sun Jul  4 07:09:39 2021
@@ -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 @@ strict_bool_controlling_expression(bool 
 	if (b)
 		do_nothing();
 
-	if (0)			/* expect: 333 */
-		do_nothing();
+	if (/*CONSTCOND*/0)	/* expect: 333 */
+		do_nothing();	/* expect: statement not reached [193] */
 
-	if (1)			/* expect: 333 */
+	if (/*CONSTCOND*/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. */

Index: src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.26 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.27
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.26	Fri Jul  2 18:52:20 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp	Sun Jul  4 07:09:39 2021
@@ -58,6 +58,7 @@ d_c99_bool_strict.c(367): warning: const
 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]

Index: src/tests/usr.bin/xlint/lint1/msg_333.c
diff -u src/tests/usr.bin/xlint/lint1/msg_333.c:1.3 src/tests/usr.bin/xlint/lint1/msg_333.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_333.c:1.3	Sun Mar 21 14:36:59 2021
+++ src/tests/usr.bin/xlint/lint1/msg_333.c	Sun Jul  4 07:09:39 2021
@@ -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 @@ typedef _Bool bool;
 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;
 }

Index: src/tests/usr.bin/xlint/lint1/msg_333.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_333.exp:1.4 src/tests/usr.bin/xlint/lint1/msg_333.exp:1.5
--- src/tests/usr.bin/xlint/lint1/msg_333.exp:1.4	Sun Mar 21 20:45:00 2021
+++ src/tests/usr.bin/xlint/lint1/msg_333.exp	Sun Jul  4 07:09:39 2021
@@ -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]

Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.112 src/usr.bin/xlint/lint1/func.c:1.113
--- src/usr.bin/xlint/lint1/func.c:1.112	Wed Jun 30 11:29:29 2021
+++ src/usr.bin/xlint/lint1/func.c	Sun Jul  4 07:09:39 2021
@@ -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 @@ check_controlling_expression(tnode_t *tn
 	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;

Reply via email to