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: fix error message for relaxed bool...



details:   https://anonhg.NetBSD.org/src/rev/9461e0693082
branches:  trunk
changeset: 950272:9461e0693082
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 23 22:34:01 2021 +0000

description:
lint: fix error message for relaxed bool operations in system headers

In strict mode, allowing 1 as bool constant expression is probably not
needed in practice since most comparisons are != 0 instead of == 0.

Furthermore, in the expression (flags & 0x0002) == true, comparing with
true is misleading since the '==' operator can never evaluate to true in
this case.

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c   |   6 +++---
 tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp |   3 ---
 usr.bin/xlint/lint1/tree.c                             |  14 ++++++--------
 3 files changed, 9 insertions(+), 14 deletions(-)

diffs (76 lines):

diff -r 53963bd22d2c -r 9461e0693082 tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c      Sat Jan 23 22:24:49 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c      Sat Jan 23 22:34:01 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_c99_bool_strict_syshdr.c,v 1.4 2021/01/23 22:20:18 rillig Exp $      */
+/*     $NetBSD: d_c99_bool_strict_syshdr.c,v 1.5 2021/01/23 22:34:01 rillig Exp $      */
 # 3 "d_c99_bool_strict_syshdr.c"
 
 /*
@@ -112,11 +112,11 @@
  * does the comparison itself.
  */
 static inline _Bool
-ch_isspace_sys_bool(char c)    /*FIXME*//* expect: 231 */
+ch_isspace_sys_bool(char c)
 {
        return
 # 119 "d_c99_bool_strict_syshdr.c" 3 4
            ((ctype_table + 1)[(unsigned char)c] & 0x0040) != 0
 # 121 "d_c99_bool_strict_syshdr.c"
-           != 0;               /*FIXME*//* expect: 107, 214 */
+           != 0;
 }
diff -r 53963bd22d2c -r 9461e0693082 tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp    Sat Jan 23 22:24:49 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp    Sat Jan 23 22:34:01 2021 +0000
@@ -1,6 +1,3 @@
 d_c99_bool_strict_syshdr.c(32): controlling expression must be bool, not 'int' [333]
 d_c99_bool_strict_syshdr.c(42): controlling expression must be bool, not 'int' [333]
 d_c99_bool_strict_syshdr.c(76): operands of '=' have incompatible types (_Bool != int) [107]
-d_c99_bool_strict_syshdr.c(121): operands of '!=' have incompatible types (_Bool != int) [107]
-d_c99_bool_strict_syshdr.c(121): warning: function ch_isspace_sys_bool expects to return value [214]
-d_c99_bool_strict_syshdr.c(115): warning: argument c unused in function ch_isspace_sys_bool [231]
diff -r 53963bd22d2c -r 9461e0693082 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sat Jan 23 22:24:49 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sat Jan 23 22:34:01 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.183 2021/01/23 22:20:17 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.184 2021/01/23 22:34:01 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.183 2021/01/23 22:20:17 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.184 2021/01/23 22:34:01 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1120,12 +1120,9 @@
 }
 
 static bool
-is_bool_int_constant(const tnode_t *tn, tspec_t t)
+is_int_constant_zero(const tnode_t *tn, tspec_t t)
 {
-       return t == INT &&
-              tn->tn_from_system_header &&
-              tn->tn_op == CON &&
-              (tn->tn_val->v_quad == 0 || tn->tn_val->v_quad == 1);
+       return t == INT && tn->tn_op == CON && tn->tn_val->v_quad == 0;
 }
 
 static bool
@@ -1139,7 +1136,8 @@
        if ((lt == BOOL) == (rt == BOOL))
                return true;
 
-       if (is_bool_int_constant(ln, lt) || is_bool_int_constant(rn, rt))
+       if ((ln->tn_from_system_header || rn->tn_from_system_header) &&
+           (is_int_constant_zero(ln, lt) || is_int_constant_zero(rn, rt)))
                return true;
 
        if (is_assignment_bool_or_other(op)) {



Home | Main Index | Thread Index | Old Index