From 597c015f3beba8b74c4068a099c75c5db469df7c Mon Sep 17 00:00:00 2001 From: rillig Date: Thu, 19 May 2022 17:24:14 +0000 Subject: [PATCH] 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. --- tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c | 4 ++-- tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp | 1 + usr.bin/xlint/lint1/ckbool.c | 7 +++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c b/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c index 7864bf3e2901..7c61e1b5b9b3 100644 --- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c +++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c @@ -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) diff --git a/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp b/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp index 2aaca9f3efae..896c041b0eba 100644 --- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp +++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp @@ -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] diff --git a/usr.bin/xlint/lint1/ckbool.c b/usr.bin/xlint/lint1/ckbool.c index 1f8a55a71ff0..485ee627b866 100644 --- a/usr.bin/xlint/lint1/ckbool.c +++ b/usr.bin/xlint/lint1/ckbool.c @@ -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 #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 @@ -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;