Module Name: src Committed By: rillig Date: Sat Jan 23 22:34:01 UTC 2021
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: tree.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 \ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c \ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp cvs rdiff -u -r1.183 -r1.184 src/usr.bin/xlint/lint1/tree.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.4 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.5 --- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.4 Sat Jan 23 22:20:18 2021 +++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c Sat Jan 23 22:34:01 2021 @@ -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 @@ ch_isspace_sys_int(char c) * 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; } 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.4 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp:1.5 --- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp:1.4 Sat Jan 23 22:20:18 2021 +++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp Sat Jan 23 22:34:01 2021 @@ -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] Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.183 src/usr.bin/xlint/lint1/tree.c:1.184 --- src/usr.bin/xlint/lint1/tree.c:1.183 Sat Jan 23 22:20:17 2021 +++ src/usr.bin/xlint/lint1/tree.c Sat Jan 23 22:34:01 2021 @@ -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 @@ is_symmetric_bool_or_other(op_t op) } 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 @@ is_typeok_strict_bool(op_t op, 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)) {