Module Name: src
Committed By: rillig
Date: Thu May 19 17:24:14 UTC 2022
Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_bool_strict_syshdr.c
d_c99_bool_strict_syshdr.exp
src/usr.bin/xlint/lint1: ckbool.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 \
src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c
cvs rdiff -u -r1.15 -r1.16 \
src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/xlint/lint1/ckbool.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_syshdr.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.13 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.14
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.13 Thu May 19 17:10:50 2022
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c Thu May 19 17:24:14 2022
@@ -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)
Index: src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp:1.15 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp:1.16
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp:1.15 Thu May 19 17:10:50 2022
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp Thu May 19 17:24:14 2022
@@ -5,3 +5,4 @@ d_c99_bool_strict_syshdr.c(157): error:
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]
Index: src/usr.bin/xlint/lint1/ckbool.c
diff -u src/usr.bin/xlint/lint1/ckbool.c:1.13 src/usr.bin/xlint/lint1/ckbool.c:1.14
--- src/usr.bin/xlint/lint1/ckbool.c:1.13 Sat Apr 16 22:21:10 2022
+++ src/usr.bin/xlint/lint1/ckbool.c Thu May 19 17:24:14 2022
@@ -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;