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: no special check for unary operato...



details:   https://anonhg.NetBSD.org/src/rev/518877d9dd80
branches:  trunk
changeset: 380038:518877d9dd80
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jul 02 18:52:20 2021 +0000

description:
lint: no special check for unary operators in strict bool mode

All interesting constellations regarding unary operators are already
covered by the simple model from ops.def.

No functional change.

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c   |   10 +-
 tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp |  184 ++++++++++++------------
 usr.bin/xlint/lint1/ckbool.c                    |   25 +-
 3 files changed, 111 insertions(+), 108 deletions(-)

diffs (295 lines):

diff -r 10afb525cefe -r 518877d9dd80 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Fri Jul 02 18:22:09 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Fri Jul 02 18:52:20 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_c99_bool_strict.c,v 1.28 2021/04/05 01:35:34 rillig Exp $    */
+/*     $NetBSD: d_c99_bool_strict.c,v 1.29 2021/07/02 18:52:20 rillig Exp $    */
 # 3 "d_c99_bool_strict.c"
 
 /*
@@ -439,6 +439,8 @@ strict_bool_operand_unary_address(void)
        b = *bp;
 }
 
+/* see strict_bool_operand_unary_all below for the other unary operators. */
+
 /*
  * strict-bool-operand-binary:
  *     Operator        left:   bool?   other?  right:  bool?   other?
@@ -512,7 +514,7 @@ strict_bool_operand_binary(bool b, int i
 }
 
 void
-strict_bool_operand_binary_all(bool b, unsigned u)
+strict_bool_operand_unary_all(bool b)
 {
        b = !b;
        b = ~b;                 /* expect: 335 */
@@ -522,7 +524,11 @@ strict_bool_operand_binary_all(bool b, u
        b--;                    /* expect: 335 */
        b = +b;                 /* expect: 335 */
        b = -b;                 /* expect: 335 */
+}
 
+void
+strict_bool_operand_binary_all(bool b, unsigned u)
+{
        b = b * b;              /* expect: 336 *//* expect: 337 */
        b = b / b;              /* expect: 336 *//* expect: 337 */
        b = b % b;              /* expect: 336 *//* expect: 337 */
diff -r 10afb525cefe -r 518877d9dd80 tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp   Fri Jul 02 18:22:09 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp   Fri Jul 02 18:52:20 2021 +0000
@@ -71,98 +71,98 @@ d_c99_bool_strict.c(424): error: operand
 d_c99_bool_strict.c(425): error: operand of '!' must be bool, not 'int' [330]
 d_c99_bool_strict.c(426): error: operand of '!' must be bool, not 'int' [330]
 d_c99_bool_strict.c(427): error: operand of '!' must be bool, not 'int' [330]
-d_c99_bool_strict.c(480): error: operands of '=' have incompatible types (_Bool != int) [107]
-d_c99_bool_strict.c(486): error: operands of '=' have incompatible types (_Bool != int) [107]
-d_c99_bool_strict.c(502): error: operand of '!' must be bool, not 'int' [330]
-d_c99_bool_strict.c(503): error: left operand of '&&' must be bool, not 'int' [331]
-d_c99_bool_strict.c(503): error: right operand of '&&' must be bool, not 'int' [332]
-d_c99_bool_strict.c(504): error: left operand of '||' must be bool, not 'int' [331]
-d_c99_bool_strict.c(504): error: right operand of '||' must be bool, not 'int' [332]
-d_c99_bool_strict.c(506): error: right operand of '&&' must be bool, not 'int' [332]
-d_c99_bool_strict.c(507): error: left operand of '&&' must be bool, not 'int' [331]
-d_c99_bool_strict.c(508): error: right operand of '||' must be bool, not 'int' [332]
-d_c99_bool_strict.c(509): error: left operand of '||' must be bool, not 'int' [331]
-d_c99_bool_strict.c(518): error: operand of '~' must not be bool [335]
-d_c99_bool_strict.c(519): error: operand of '++x' must not be bool [335]
-d_c99_bool_strict.c(520): error: operand of '--x' must not be bool [335]
-d_c99_bool_strict.c(521): error: operand of 'x++' must not be bool [335]
-d_c99_bool_strict.c(522): error: operand of 'x--' must not be bool [335]
-d_c99_bool_strict.c(523): error: operand of '+' must not be bool [335]
-d_c99_bool_strict.c(524): error: operand of '-' must not be bool [335]
-d_c99_bool_strict.c(526): error: left operand of '*' must not be bool [336]
-d_c99_bool_strict.c(526): error: right operand of '*' must not be bool [337]
-d_c99_bool_strict.c(527): error: left operand of '/' must not be bool [336]
-d_c99_bool_strict.c(527): error: right operand of '/' must not be bool [337]
-d_c99_bool_strict.c(528): error: left operand of '%' must not be bool [336]
-d_c99_bool_strict.c(528): error: right operand of '%' must not be bool [337]
-d_c99_bool_strict.c(529): error: left operand of '+' must not be bool [336]
-d_c99_bool_strict.c(529): error: right operand of '+' must not be bool [337]
-d_c99_bool_strict.c(530): error: left operand of '-' must not be bool [336]
-d_c99_bool_strict.c(530): error: right operand of '-' must not be bool [337]
-d_c99_bool_strict.c(531): error: left operand of '<<' must not be bool [336]
-d_c99_bool_strict.c(531): error: right operand of '<<' must not be bool [337]
-d_c99_bool_strict.c(532): error: left operand of '>>' must not be bool [336]
-d_c99_bool_strict.c(532): error: right operand of '>>' must not be bool [337]
-d_c99_bool_strict.c(534): error: left operand of '<' must not be bool [336]
-d_c99_bool_strict.c(534): error: right operand of '<' must not be bool [337]
-d_c99_bool_strict.c(535): error: left operand of '<=' must not be bool [336]
-d_c99_bool_strict.c(535): error: right operand of '<=' must not be bool [337]
-d_c99_bool_strict.c(536): error: left operand of '>' must not be bool [336]
-d_c99_bool_strict.c(536): error: right operand of '>' must not be bool [337]
-d_c99_bool_strict.c(537): error: left operand of '>=' must not be bool [336]
-d_c99_bool_strict.c(537): error: right operand of '>=' must not be bool [337]
-d_c99_bool_strict.c(549): error: left operand of '*=' must not be bool [336]
-d_c99_bool_strict.c(549): error: right operand of '*=' must not be bool [337]
-d_c99_bool_strict.c(550): error: left operand of '/=' must not be bool [336]
-d_c99_bool_strict.c(550): error: right operand of '/=' must not be bool [337]
-d_c99_bool_strict.c(551): error: left operand of '%=' must not be bool [336]
-d_c99_bool_strict.c(551): error: right operand of '%=' must not be bool [337]
-d_c99_bool_strict.c(552): error: left operand of '+=' must not be bool [336]
-d_c99_bool_strict.c(552): error: right operand of '+=' must not be bool [337]
-d_c99_bool_strict.c(553): error: left operand of '-=' must not be bool [336]
-d_c99_bool_strict.c(553): error: right operand of '-=' must not be bool [337]
-d_c99_bool_strict.c(554): error: left operand of '<<=' must not be bool [336]
-d_c99_bool_strict.c(554): error: right operand of '<<=' must not be bool [337]
-d_c99_bool_strict.c(555): error: left operand of '>>=' must not be bool [336]
-d_c99_bool_strict.c(555): error: right operand of '>>=' must not be bool [337]
-d_c99_bool_strict.c(561): error: left operand of '*' must not be bool [336]
-d_c99_bool_strict.c(562): error: right operand of '*' must not be bool [337]
-d_c99_bool_strict.c(563): error: left operand of '/' must not be bool [336]
-d_c99_bool_strict.c(564): error: right operand of '/' must not be bool [337]
-d_c99_bool_strict.c(565): error: left operand of '%' must not be bool [336]
-d_c99_bool_strict.c(566): error: right operand of '%' must not be bool [337]
-d_c99_bool_strict.c(567): error: left operand of '+' must not be bool [336]
-d_c99_bool_strict.c(568): error: right operand of '+' must not be bool [337]
-d_c99_bool_strict.c(569): error: left operand of '-' must not be bool [336]
-d_c99_bool_strict.c(570): error: right operand of '-' must not be bool [337]
-d_c99_bool_strict.c(571): error: left operand of '<<' must not be bool [336]
-d_c99_bool_strict.c(572): error: right operand of '<<' must not be bool [337]
-d_c99_bool_strict.c(573): error: left operand of '>>' must not be bool [336]
-d_c99_bool_strict.c(574): error: right operand of '>>' must not be bool [337]
-d_c99_bool_strict.c(576): error: operands of ':' have incompatible types (_Bool != unsigned int) [107]
-d_c99_bool_strict.c(577): error: operands of ':' have incompatible types (unsigned int != _Bool) [107]
-d_c99_bool_strict.c(583): warning: expression has null effect [129]
-d_c99_bool_strict.c(584): warning: expression has null effect [129]
-d_c99_bool_strict.c(597): error: operands of '=' have incompatible types (char != _Bool) [107]
-d_c99_bool_strict.c(598): error: operands of '=' have incompatible types (int != _Bool) [107]
-d_c99_bool_strict.c(599): error: operands of '=' have incompatible types (double != _Bool) [107]
-d_c99_bool_strict.c(600): error: operands of '=' have incompatible types (pointer != _Bool) [107]
-d_c99_bool_strict.c(617): error: operands of '=' have incompatible types (int != _Bool) [107]
-d_c99_bool_strict.c(618): error: operands of '=' have incompatible types (int != _Bool) [107]
-d_c99_bool_strict.c(619): error: operands of '=' have incompatible types (int != _Bool) [107]
-d_c99_bool_strict.c(620): error: operands of '=' have incompatible types (int != _Bool) [107]
-d_c99_bool_strict.c(621): error: operands of '=' have incompatible types (int != _Bool) [107]
-d_c99_bool_strict.c(622): error: operands of '=' have incompatible types (int != _Bool) [107]
+d_c99_bool_strict.c(482): error: operands of '=' have incompatible types (_Bool != int) [107]
+d_c99_bool_strict.c(488): error: operands of '=' have incompatible types (_Bool != int) [107]
+d_c99_bool_strict.c(504): error: operand of '!' must be bool, not 'int' [330]
+d_c99_bool_strict.c(505): error: left operand of '&&' must be bool, not 'int' [331]
+d_c99_bool_strict.c(505): error: right operand of '&&' must be bool, not 'int' [332]
+d_c99_bool_strict.c(506): error: left operand of '||' must be bool, not 'int' [331]
+d_c99_bool_strict.c(506): error: right operand of '||' must be bool, not 'int' [332]
+d_c99_bool_strict.c(508): error: right operand of '&&' must be bool, not 'int' [332]
+d_c99_bool_strict.c(509): error: left operand of '&&' must be bool, not 'int' [331]
+d_c99_bool_strict.c(510): error: right operand of '||' must be bool, not 'int' [332]
+d_c99_bool_strict.c(511): error: left operand of '||' must be bool, not 'int' [331]
+d_c99_bool_strict.c(520): error: operand of '~' must not be bool [335]
+d_c99_bool_strict.c(521): error: operand of '++x' must not be bool [335]
+d_c99_bool_strict.c(522): error: operand of '--x' must not be bool [335]
+d_c99_bool_strict.c(523): error: operand of 'x++' must not be bool [335]
+d_c99_bool_strict.c(524): error: operand of 'x--' must not be bool [335]
+d_c99_bool_strict.c(525): error: operand of '+' must not be bool [335]
+d_c99_bool_strict.c(526): error: operand of '-' must not be bool [335]
+d_c99_bool_strict.c(532): error: left operand of '*' must not be bool [336]
+d_c99_bool_strict.c(532): error: right operand of '*' must not be bool [337]
+d_c99_bool_strict.c(533): error: left operand of '/' must not be bool [336]
+d_c99_bool_strict.c(533): error: right operand of '/' must not be bool [337]
+d_c99_bool_strict.c(534): error: left operand of '%' must not be bool [336]
+d_c99_bool_strict.c(534): error: right operand of '%' must not be bool [337]
+d_c99_bool_strict.c(535): error: left operand of '+' must not be bool [336]
+d_c99_bool_strict.c(535): error: right operand of '+' must not be bool [337]
+d_c99_bool_strict.c(536): error: left operand of '-' must not be bool [336]
+d_c99_bool_strict.c(536): error: right operand of '-' must not be bool [337]
+d_c99_bool_strict.c(537): error: left operand of '<<' must not be bool [336]
+d_c99_bool_strict.c(537): error: right operand of '<<' must not be bool [337]
+d_c99_bool_strict.c(538): error: left operand of '>>' must not be bool [336]
+d_c99_bool_strict.c(538): error: right operand of '>>' must not be bool [337]
+d_c99_bool_strict.c(540): error: left operand of '<' must not be bool [336]
+d_c99_bool_strict.c(540): error: right operand of '<' must not be bool [337]
+d_c99_bool_strict.c(541): error: left operand of '<=' must not be bool [336]
+d_c99_bool_strict.c(541): error: right operand of '<=' must not be bool [337]
+d_c99_bool_strict.c(542): error: left operand of '>' must not be bool [336]
+d_c99_bool_strict.c(542): error: right operand of '>' must not be bool [337]
+d_c99_bool_strict.c(543): error: left operand of '>=' must not be bool [336]
+d_c99_bool_strict.c(543): error: right operand of '>=' must not be bool [337]
+d_c99_bool_strict.c(555): error: left operand of '*=' must not be bool [336]
+d_c99_bool_strict.c(555): error: right operand of '*=' must not be bool [337]
+d_c99_bool_strict.c(556): error: left operand of '/=' must not be bool [336]
+d_c99_bool_strict.c(556): error: right operand of '/=' must not be bool [337]
+d_c99_bool_strict.c(557): error: left operand of '%=' must not be bool [336]
+d_c99_bool_strict.c(557): error: right operand of '%=' must not be bool [337]
+d_c99_bool_strict.c(558): error: left operand of '+=' must not be bool [336]
+d_c99_bool_strict.c(558): error: right operand of '+=' must not be bool [337]
+d_c99_bool_strict.c(559): error: left operand of '-=' must not be bool [336]
+d_c99_bool_strict.c(559): error: right operand of '-=' must not be bool [337]
+d_c99_bool_strict.c(560): error: left operand of '<<=' must not be bool [336]
+d_c99_bool_strict.c(560): error: right operand of '<<=' must not be bool [337]
+d_c99_bool_strict.c(561): error: left operand of '>>=' must not be bool [336]
+d_c99_bool_strict.c(561): error: right operand of '>>=' must not be bool [337]
+d_c99_bool_strict.c(567): error: left operand of '*' must not be bool [336]
+d_c99_bool_strict.c(568): error: right operand of '*' must not be bool [337]
+d_c99_bool_strict.c(569): error: left operand of '/' must not be bool [336]
+d_c99_bool_strict.c(570): error: right operand of '/' must not be bool [337]
+d_c99_bool_strict.c(571): error: left operand of '%' must not be bool [336]
+d_c99_bool_strict.c(572): error: right operand of '%' must not be bool [337]
+d_c99_bool_strict.c(573): error: left operand of '+' must not be bool [336]
+d_c99_bool_strict.c(574): error: right operand of '+' must not be bool [337]
+d_c99_bool_strict.c(575): error: left operand of '-' must not be bool [336]
+d_c99_bool_strict.c(576): error: right operand of '-' must not be bool [337]
+d_c99_bool_strict.c(577): error: left operand of '<<' must not be bool [336]
+d_c99_bool_strict.c(578): error: right operand of '<<' must not be bool [337]
+d_c99_bool_strict.c(579): error: left operand of '>>' must not be bool [336]
+d_c99_bool_strict.c(580): error: right operand of '>>' must not be bool [337]
+d_c99_bool_strict.c(582): error: operands of ':' have incompatible types (_Bool != unsigned int) [107]
+d_c99_bool_strict.c(583): error: operands of ':' have incompatible types (unsigned int != _Bool) [107]
+d_c99_bool_strict.c(589): warning: expression has null effect [129]
+d_c99_bool_strict.c(590): warning: expression has null effect [129]
+d_c99_bool_strict.c(603): error: operands of '=' have incompatible types (char != _Bool) [107]
+d_c99_bool_strict.c(604): error: operands of '=' have incompatible types (int != _Bool) [107]
+d_c99_bool_strict.c(605): error: operands of '=' have incompatible types (double != _Bool) [107]
+d_c99_bool_strict.c(606): error: operands of '=' have incompatible types (pointer != _Bool) [107]
 d_c99_bool_strict.c(623): error: operands of '=' have incompatible types (int != _Bool) [107]
 d_c99_bool_strict.c(624): error: operands of '=' have incompatible types (int != _Bool) [107]
 d_c99_bool_strict.c(625): error: operands of '=' have incompatible types (int != _Bool) [107]
-d_c99_bool_strict.c(663): error: operands of '=' have incompatible types (_Bool != int) [107]
-d_c99_bool_strict.c(671): error: operands of '=' have incompatible types (_Bool != int) [107]
-d_c99_bool_strict.c(678): error: operands of '=' have incompatible types (_Bool != int) [107]
-d_c99_bool_strict.c(653): warning: argument 'flags' unused in function 'strict_bool_bitwise_and_enum' [231]
-d_c99_bool_strict.c(717): error: operands of '==' have incompatible types (_Bool != int) [107]
-d_c99_bool_strict.c(729): warning: expression has null effect [129]
-d_c99_bool_strict.c(741): error: right operand of '+' must not be bool [337]
-d_c99_bool_strict.c(758): warning: constant in conditional context [161]
-d_c99_bool_strict.c(769): error: operands of 'init' have incompatible types (_Bool != int) [107]
-d_c99_bool_strict.c(770): error: operands of 'init' have incompatible types (_Bool != int) [107]
+d_c99_bool_strict.c(626): error: operands of '=' have incompatible types (int != _Bool) [107]
+d_c99_bool_strict.c(627): error: operands of '=' have incompatible types (int != _Bool) [107]
+d_c99_bool_strict.c(628): error: operands of '=' have incompatible types (int != _Bool) [107]
+d_c99_bool_strict.c(629): error: operands of '=' have incompatible types (int != _Bool) [107]
+d_c99_bool_strict.c(630): error: operands of '=' have incompatible types (int != _Bool) [107]
+d_c99_bool_strict.c(631): error: operands of '=' have incompatible types (int != _Bool) [107]
+d_c99_bool_strict.c(669): error: operands of '=' have incompatible types (_Bool != int) [107]
+d_c99_bool_strict.c(677): error: operands of '=' have incompatible types (_Bool != int) [107]
+d_c99_bool_strict.c(684): error: operands of '=' have incompatible types (_Bool != int) [107]
+d_c99_bool_strict.c(659): warning: argument 'flags' unused in function 'strict_bool_bitwise_and_enum' [231]
+d_c99_bool_strict.c(723): error: operands of '==' have incompatible types (_Bool != int) [107]
+d_c99_bool_strict.c(735): warning: expression has null effect [129]
+d_c99_bool_strict.c(747): error: right operand of '+' must not be bool [337]
+d_c99_bool_strict.c(764): warning: constant in conditional context [161]
+d_c99_bool_strict.c(775): error: operands of 'init' have incompatible types (_Bool != int) [107]
+d_c99_bool_strict.c(776): error: operands of 'init' have incompatible types (_Bool != int) [107]
diff -r 10afb525cefe -r 518877d9dd80 usr.bin/xlint/lint1/ckbool.c
--- a/usr.bin/xlint/lint1/ckbool.c      Fri Jul 02 18:22:09 2021 +0000
+++ b/usr.bin/xlint/lint1/ckbool.c      Fri Jul 02 18:52:20 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ckbool.c,v 1.4 2021/06/20 20:32:42 rillig Exp $ */
+/* $NetBSD: ckbool.c,v 1.5 2021/07/02 18:52:20 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.4 2021/06/20 20:32:42 rillig Exp $");
+__RCSID("$NetBSD: ckbool.c,v 1.5 2021/07/02 18:52:20 rillig Exp $");
 #endif
 
 #include <string.h>
@@ -82,13 +82,10 @@ is_int_constant_zero(const tnode_t *tn, 
 }
 
 static bool
-is_typeok_strict_bool(op_t op,
-                     const tnode_t *ln, tspec_t lt,
-                     const tnode_t *rn, tspec_t rt)
+is_typeok_strict_bool_binary(op_t op,
+                            const tnode_t *ln, tspec_t lt,
+                            const tnode_t *rn, tspec_t rt)
 {
-       if (rn == NULL)
-               return true;    /* TODO: check unary operators as well. */
-
        if ((lt == BOOL) == (rt == BOOL))
                return true;
 
@@ -113,12 +110,11 @@ is_typeok_strict_bool(op_t op,
  * behavior.
  */
 static bool
-typeok_strict_bool_compatible(op_t op, int arg,
-                             const tnode_t *ln, tspec_t lt,
-                             const tnode_t *rn, tspec_t rt)
+typeok_strict_bool_binary_compatible(op_t op, int arg,
+                                    const tnode_t *ln, tspec_t lt,
+                                    const tnode_t *rn, tspec_t rt)
 {
-
-       if (is_typeok_strict_bool(op, ln, lt, rn, rt))
+       if (is_typeok_strict_bool_binary(op, ln, lt, rn, rt))
                return true;
 
        if (op == FARG) {
@@ -157,7 +153,8 @@ typeok_scalar_strict_bool(op_t op, const
                rt = NOTSPEC;
        }
 
-       if (!typeok_strict_bool_compatible(op, arg, ln, lt, rn, rt))
+       if (rn != NULL &&
+           !typeok_strict_bool_binary_compatible(op, arg, ln, lt, rn, rt))
                return false;
 
        if (mp->m_requires_bool || op == QUEST) {



Home | Main Index | Thread Index | Old Index