Module Name:    src
Committed By:   rillig
Date:           Sun Mar 21 15:44:57 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_161.c msg_161.exp msg_193.c
            msg_193.exp
        src/usr.bin/xlint/lint1: func.c

Log Message:
lint: fix reachability for while (0)


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_161.c \
    src/tests/usr.bin/xlint/lint1/msg_193.c \
    src/tests/usr.bin/xlint/lint1/msg_193.exp
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_161.exp
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/xlint/lint1/func.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/msg_161.c
diff -u src/tests/usr.bin/xlint/lint1/msg_161.c:1.6 src/tests/usr.bin/xlint/lint1/msg_161.c:1.7
--- src/tests/usr.bin/xlint/lint1/msg_161.c:1.6	Sun Feb 28 03:59:28 2021
+++ src/tests/usr.bin/xlint/lint1/msg_161.c	Sun Mar 21 15:44:57 2021
@@ -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 @@ void
 while_0(void)
 {
 	while (0)		/* expect: 161 */
-		continue;
+		continue;	/* expect: statement not reached */
 }
 
 /*
Index: src/tests/usr.bin/xlint/lint1/msg_193.c
diff -u src/tests/usr.bin/xlint/lint1/msg_193.c:1.6 src/tests/usr.bin/xlint/lint1/msg_193.c:1.7
--- src/tests/usr.bin/xlint/lint1/msg_193.c:1.6	Sun Mar 21 15:34:13 2021
+++ src/tests/usr.bin/xlint/lint1/msg_193.c	Sun Mar 21 15:44:57 2021
@@ -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 @@ void
 test_while_false(void)
 {
 	while (0)
-		unreachable();		/* TODO: expect: 193 */
+		unreachable();		/* expect: 193 */
 	reachable();
 }
 
Index: src/tests/usr.bin/xlint/lint1/msg_193.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_193.exp:1.6 src/tests/usr.bin/xlint/lint1/msg_193.exp:1.7
--- src/tests/usr.bin/xlint/lint1/msg_193.exp:1.6	Sun Mar 21 15:34:13 2021
+++ src/tests/usr.bin/xlint/lint1/msg_193.exp	Sun Mar 21 15:44:57 2021
@@ -32,6 +32,7 @@ msg_193.c(261): warning: statement not r
 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]

Index: src/tests/usr.bin/xlint/lint1/msg_161.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_161.exp:1.5 src/tests/usr.bin/xlint/lint1/msg_161.exp:1.6
--- src/tests/usr.bin/xlint/lint1/msg_161.exp:1.5	Sun Feb 28 03:59:28 2021
+++ src/tests/usr.bin/xlint/lint1/msg_161.exp	Sun Mar 21 15:44:57 2021
@@ -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]

Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.91 src/usr.bin/xlint/lint1/func.c:1.92
--- src/usr.bin/xlint/lint1/func.c:1.91	Sun Mar 21 15:34:13 2021
+++ src/usr.bin/xlint/lint1/func.c	Sun Mar 21 15:44:57 2021
@@ -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 @@ switch2(void)
 void
 while1(tnode_t *tn)
 {
+	bool body_reached;
 
 	if (!reached) {
 		/* loop not entered at top */
@@ -766,11 +767,13 @@ while1(tnode_t *tn)
 
 	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;
 }
 
 /*

Reply via email to