Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: in strict bool mode, check functio...



details:   https://anonhg.NetBSD.org/src/rev/f9758368e90c
branches:  trunk
changeset: 366234:f9758368e90c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu May 19 17:24:14 2022 +0000

description:
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.

diffstat:

 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(-)

diffs (54 lines):

diff -r 3535ae36a5bf -r f9758368e90c tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c      Thu May 19 17:10:50 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c      Thu May 19 17:24:14 2022 +0000
@@ -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 @@
 # 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 -r 3535ae36a5bf -r f9758368e90c tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp    Thu May 19 17:10:50 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp    Thu May 19 17:24:14 2022 +0000
@@ -5,3 +5,4 @@
 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 -r 3535ae36a5bf -r f9758368e90c usr.bin/xlint/lint1/ckbool.c
--- a/usr.bin/xlint/lint1/ckbool.c      Thu May 19 17:10:50 2022 +0000
+++ b/usr.bin/xlint/lint1/ckbool.c      Thu May 19 17:24:14 2022 +0000
@@ -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 @@
        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;



Home | Main Index | Thread Index | Old Index