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: do not warn about 'do { ... } whil...



details:   https://anonhg.NetBSD.org/src/rev/c4d2556115b5
branches:  trunk
changeset: 980854:c4d2556115b5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Feb 20 18:55:10 2021 +0000

description:
lint: do not warn about 'do { ... } while (false)' in strict bool mode

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c   |   4 ++--
 tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp |   1 -
 usr.bin/xlint/lint1/tree.c                      |  13 ++++++++++---
 3 files changed, 12 insertions(+), 6 deletions(-)

diffs (68 lines):

diff -r a8e71039dde0 -r c4d2556115b5 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Sat Feb 20 18:52:58 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Sat Feb 20 18:55:10 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_c99_bool_strict.c,v 1.20 2021/02/20 18:52:58 rillig Exp $    */
+/*     $NetBSD: d_c99_bool_strict.c,v 1.21 2021/02/20 18:55:10 rillig Exp $    */
 # 3 "d_c99_bool_strict.c"
 
 /*
@@ -746,7 +746,7 @@
 {
        do {
 
-       } while (__lint_false); /*FIXME*//* expect: 161 */
+       } while (__lint_false);
 }
 
 void
diff -r a8e71039dde0 -r c4d2556115b5 tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp   Sat Feb 20 18:52:58 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp   Sat Feb 20 18:55:10 2021 +0000
@@ -162,5 +162,4 @@
 d_c99_bool_strict.c(716): operands of '==' have incompatible types (_Bool != int) [107]
 d_c99_bool_strict.c(728): warning: expression has null effect [129]
 d_c99_bool_strict.c(740): right operand of '+' must not be bool [337]
-d_c99_bool_strict.c(749): warning: constant in conditional context [161]
 d_c99_bool_strict.c(757): warning: constant in conditional context [161]
diff -r a8e71039dde0 -r c4d2556115b5 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sat Feb 20 18:52:58 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sat Feb 20 18:55:10 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.210 2021/02/20 16:34:57 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.211 2021/02/20 18:55:10 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.210 2021/02/20 16:34:57 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.211 2021/02/20 18:55:10 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -3727,6 +3727,13 @@
        return v;
 }
 
+static bool
+is_constcond_false(const tnode_t *tn, tspec_t t)
+{
+       return (t == BOOL || t == INT) &&
+              tn->tn_op == CON && tn->tn_val->v_quad == 0;
+}
+
 /*
  * Perform some tests on expressions which can't be done in build() and
  * functions called by build(). These tests must be done here because
@@ -3758,7 +3765,7 @@
        } else if (tn->tn_op == CON) {
                if (hflag && tctx && !constcond_flag &&
                    !(constcond_zero_ok &&
-                     is_int_constant_zero(tn, tn->tn_type->t_tspec)))
+                     is_constcond_false(tn, tn->tn_type->t_tspec)))
                        /* constant in conditional context */
                        warning(161);
        }



Home | Main Index | Thread Index | Old Index