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.
This commit is contained in:
rillig 2021-07-04 07:09:39 +00:00
parent 68a49f39f0
commit 8d5c9f256b
5 changed files with 33 additions and 19 deletions

View File

@ -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 b, int i, double d, const void *p)
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. */

View File

@ -58,6 +58,7 @@ d_c99_bool_strict.c(367): warning: constant in conditional context [161]
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]

View File

@ -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;
}

View File

@ -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]

View File

@ -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;