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 reachability for constant cont...



details:   https://anonhg.NetBSD.org/src/rev/b3bd5ad3b413
branches:  trunk
changeset: 953825:b3bd5ad3b413
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Mar 21 15:34:13 2021 +0000

description:
lint: fix reachability for constant controlling expression in for loop

diffstat:

 tests/usr.bin/xlint/lint1/msg_193.c   |   4 ++--
 tests/usr.bin/xlint/lint1/msg_193.exp |   1 +
 usr.bin/xlint/lint1/func.c            |   9 ++++-----
 usr.bin/xlint/lint1/lint1.h           |  14 +++++++++++++-
 4 files changed, 20 insertions(+), 8 deletions(-)

diffs (87 lines):

diff -r 073d2a18b6a3 -r b3bd5ad3b413 tests/usr.bin/xlint/lint1/msg_193.c
--- a/tests/usr.bin/xlint/lint1/msg_193.c       Sun Mar 21 15:24:55 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_193.c       Sun Mar 21 15:34:13 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_193.c,v 1.5 2021/03/21 15:24:56 rillig Exp $       */
+/*     $NetBSD: msg_193.c,v 1.6 2021/03/21 15:34:13 rillig Exp $       */
 # 3 "msg_193.c"
 
 // Test for message: statement not reached [193]
@@ -173,7 +173,7 @@
 test_for_false(void)
 {
        for (; 0;)
-               unreachable();          /* TODO: expect: 193 */
+               unreachable();          /* expect: 193 */
        reachable();
 }
 
diff -r 073d2a18b6a3 -r b3bd5ad3b413 tests/usr.bin/xlint/lint1/msg_193.exp
--- a/tests/usr.bin/xlint/lint1/msg_193.exp     Sun Mar 21 15:24:55 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_193.exp     Sun Mar 21 15:34:13 2021 +0000
@@ -14,6 +14,7 @@
 msg_193.c(152): warning: statement not reached [193]
 msg_193.c(161): warning: statement not reached [193]
 msg_193.c(169): warning: statement not reached [193]
+msg_193.c(176): warning: statement not reached [193]
 msg_193.c(186): warning: statement not reached [193]
 msg_193.c(197): warning: statement not reached [193]
 msg_193.c(199): warning: statement not reached [193]
diff -r 073d2a18b6a3 -r b3bd5ad3b413 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sun Mar 21 15:24:55 2021 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sun Mar 21 15:34:13 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.90 2021/03/21 15:24:55 rillig Exp $ */
+/*     $NetBSD: func.c,v 1.91 2021/03/21 15:34:13 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.90 2021/03/21 15:24:55 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.91 2021/03/21 15:34:13 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -883,12 +883,11 @@
        if (tn2 != NULL)
                expr(tn2, false, true, true, false);
 
-       cstmt->c_maybe_endless =
-           tn2 == NULL || (tn2->tn_op == CON && constant_is_nonzero(tn2));
+       cstmt->c_maybe_endless = tn2 == NULL || is_nonzero(tn2);
 
        /* Checking the reinitialization expression is done in for2() */
 
-       reached = true;
+       reached = !is_zero(tn2);
 }
 
 /*
diff -r 073d2a18b6a3 -r b3bd5ad3b413 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sun Mar 21 15:24:55 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sun Mar 21 15:34:13 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.86 2021/03/21 14:36:59 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.87 2021/03/21 15:34:13 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -483,3 +483,15 @@
        lint_assert(tn->tn_type->t_tspec == tn->tn_val->v_tspec);
        return is_nonzero_val(tn->tn_val);
 }
+
+static inline bool
+is_zero(const tnode_t *tn)
+{
+       return tn != NULL && tn->tn_op == CON && !is_nonzero_val(tn->tn_val);
+}
+
+static inline bool
+is_nonzero(const tnode_t *tn)
+{
+       return tn != NULL && tn->tn_op == CON && is_nonzero_val(tn->tn_val);
+}



Home | Main Index | Thread Index | Old Index