lint: in strict bool mode, check function arguments more strictly

When a system header defined the constant FALSE = 0, that constant could
be passed as a bool argument.  On the other hand, the constant TRUE = 1
could not be passed in the same way.  Remove this inconsistency.
This commit is contained in:
rillig 2022-05-19 17:24:14 +00:00
parent 28a6c50b89
commit 597c015f3b
3 changed files with 8 additions and 4 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: d_c99_bool_strict_syshdr.c,v 1.13 2022/05/19 17:10:50 rillig Exp $ */
/* $NetBSD: d_c99_bool_strict_syshdr.c,v 1.14 2022/05/19 17:24:14 rillig Exp $ */
# 3 "d_c99_bool_strict_syshdr.c"
/*
@ -234,7 +234,7 @@ pass_bool_to_function(void)
# 235 "d_c99_bool_strict_syshdr.c"
);
/* TODO: make this a type error */
/* expect+5: error: argument #1 expects '_Bool', gets passed 'int' [334] */
take_bool(
# 240 "d_c99_bool_strict_syshdr.c" 3 4
(/*CONSTCOND*/0)

View File

@ -5,3 +5,4 @@ d_c99_bool_strict_syshdr.c(157): error: return value type mismatch (_Bool) and (
d_c99_bool_strict_syshdr.c(172): error: operand of '!' must be bool, not 'int' [330]
d_c99_bool_strict_syshdr.c(172): warning: function 'str_equal_bad' expects to return value [214]
d_c99_bool_strict_syshdr.c(229): error: argument #1 expects '_Bool', gets passed 'int' [334]
d_c99_bool_strict_syshdr.c(242): error: argument #1 expects '_Bool', gets passed 'int' [334]

View File

@ -1,4 +1,4 @@
/* $NetBSD: ckbool.c,v 1.13 2022/04/16 22:21:10 rillig Exp $ */
/* $NetBSD: ckbool.c,v 1.14 2022/05/19 17:24:14 rillig Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@ -36,7 +36,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: ckbool.c,v 1.13 2022/04/16 22:21:10 rillig Exp $");
__RCSID("$NetBSD: ckbool.c,v 1.14 2022/05/19 17:24:14 rillig Exp $");
#endif
#include <string.h>
@ -90,6 +90,9 @@ is_typeok_strict_bool_binary(op_t op,
if ((lt == BOOL) == (rt == BOOL))
return true;
if (op == FARG && rn->tn_sys)
return false;
if ((ln->tn_sys || rn->tn_sys) &&
(is_int_constant_zero(ln, lt) || is_int_constant_zero(rn, rt)))
return true;