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 while (0)



details:   https://anonhg.NetBSD.org/src/rev/ac9c4deb4613
branches:  trunk
changeset: 981809:ac9c4deb4613
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Mar 21 15:44:57 2021 +0000

description:
lint: fix reachability for while (0)

diffstat:

 tests/usr.bin/xlint/lint1/msg_161.c   |   4 ++--
 tests/usr.bin/xlint/lint1/msg_161.exp |   1 +
 tests/usr.bin/xlint/lint1/msg_193.c   |   4 ++--
 tests/usr.bin/xlint/lint1/msg_193.exp |   1 +
 usr.bin/xlint/lint1/func.c            |  11 +++++++----
 5 files changed, 13 insertions(+), 8 deletions(-)

diffs (97 lines):

diff -r 36f4edf15d81 -r ac9c4deb4613 tests/usr.bin/xlint/lint1/msg_161.c
--- a/tests/usr.bin/xlint/lint1/msg_161.c       Sun Mar 21 15:34:13 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_161.c       Sun Mar 21 15:44:57 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_161.c,v 1.6 2021/02/28 03:59:28 rillig Exp $       */
+/*     $NetBSD: msg_161.c,v 1.7 2021/03/21 15:44:57 rillig Exp $       */
 # 3 "msg_161.c"
 
 // Test for message: constant in conditional context [161]
@@ -16,7 +16,7 @@
 while_0(void)
 {
        while (0)               /* expect: 161 */
-               continue;
+               continue;       /* expect: statement not reached */
 }
 
 /*
diff -r 36f4edf15d81 -r ac9c4deb4613 tests/usr.bin/xlint/lint1/msg_161.exp
--- a/tests/usr.bin/xlint/lint1/msg_161.exp     Sun Mar 21 15:34:13 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_161.exp     Sun Mar 21 15:44:57 2021 +0000
@@ -1,3 +1,4 @@
 msg_161.c(11): warning: constant in conditional context [161]
 msg_161.c(18): warning: constant in conditional context [161]
+msg_161.c(19): warning: statement not reached [193]
 msg_161.c(41): warning: constant in conditional context [161]
diff -r 36f4edf15d81 -r ac9c4deb4613 tests/usr.bin/xlint/lint1/msg_193.c
--- a/tests/usr.bin/xlint/lint1/msg_193.c       Sun Mar 21 15:34:13 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_193.c       Sun Mar 21 15:44:57 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_193.c,v 1.6 2021/03/21 15:34:13 rillig Exp $       */
+/*     $NetBSD: msg_193.c,v 1.7 2021/03/21 15:44:57 rillig Exp $       */
 # 3 "msg_193.c"
 
 // Test for message: statement not reached [193]
@@ -282,7 +282,7 @@
 test_while_false(void)
 {
        while (0)
-               unreachable();          /* TODO: expect: 193 */
+               unreachable();          /* expect: 193 */
        reachable();
 }
 
diff -r 36f4edf15d81 -r ac9c4deb4613 tests/usr.bin/xlint/lint1/msg_193.exp
--- a/tests/usr.bin/xlint/lint1/msg_193.exp     Sun Mar 21 15:34:13 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_193.exp     Sun Mar 21 15:44:57 2021 +0000
@@ -32,6 +32,7 @@
 msg_193.c(266): warning: statement not reached [193]
 msg_193.c(270): warning: statement not reached [193]
 msg_193.c(278): warning: statement not reached [193]
+msg_193.c(285): warning: statement not reached [193]
 msg_193.c(295): warning: statement not reached [193]
 msg_193.c(306): warning: statement not reached [193]
 msg_193.c(308): warning: statement not reached [193]
diff -r 36f4edf15d81 -r ac9c4deb4613 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sun Mar 21 15:34:13 2021 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sun Mar 21 15:44:57 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.91 2021/03/21 15:34:13 rillig Exp $ */
+/*     $NetBSD: func.c,v 1.92 2021/03/21 15:44:57 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.91 2021/03/21 15:34:13 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.92 2021/03/21 15:44:57 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -754,6 +754,7 @@
 void
 while1(tnode_t *tn)
 {
+       bool body_reached;
 
        if (!reached) {
                /* loop not entered at top */
@@ -766,11 +767,13 @@
 
        pushctrl(T_WHILE);
        cstmt->c_loop = true;
-       if (tn != NULL && tn->tn_op == CON)
-               cstmt->c_maybe_endless = constant_is_nonzero(tn);
+       cstmt->c_maybe_endless = is_nonzero(tn);
+       body_reached = !is_zero(tn);
 
        check_getopt_begin_while(tn);
        expr(tn, false, true, true, false);
+
+       reached = body_reached;
 }
 
 /*



Home | Main Index | Thread Index | Old Index