Module Name: src
Committed By: rillig
Date: Sun Mar 21 11:48:04 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_217.c msg_217.exp
src/usr.bin/xlint/lint1: tree.c
Log Message:
lint: fix wrong 'statement not reached' in do-while loop
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_217.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_217.exp
cvs rdiff -u -r1.242 -r1.243 src/usr.bin/xlint/lint1/tree.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_217.c
diff -u src/tests/usr.bin/xlint/lint1/msg_217.c:1.4 src/tests/usr.bin/xlint/lint1/msg_217.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_217.c:1.4 Sun Feb 21 09:17:55 2021
+++ src/tests/usr.bin/xlint/lint1/msg_217.c Sun Mar 21 11:48:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_217.c,v 1.4 2021/02/21 09:17:55 rillig Exp $ */
+/* $NetBSD: msg_217.c,v 1.5 2021/03/21 11:48:04 rillig Exp $ */
# 3 "msg_217.c"
// Test for message: function %s falls off bottom without returning value [217]
@@ -19,16 +19,17 @@ random(int n)
* Seen in external/bsd/libevent/dist/event_tagging.c, function
* encode_int_internal.
*
- * As of 2021-01-31, lint wrongly reports that the function would fall off
- * the bottom, but it cannot reach the bottom since every path contains the
- * 'return i'.
+ * Before tree.c 1.243 from 2021-03-21, lint wrongly reported that the
+ * 'while 0' was unreachable. This has been fixed by allowing the 'while 0'
+ * in a do-while-false loop to be unreachable. The same could be useful for a
+ * do-while-true.
*/
int
do_while_return(int i)
{
do {
return i;
- } while (/*CONSTCOND*/0); /*FIXME*//* expect: 193 */
+ } while (0);
} /*FIXME*//* expect: 217 */
/*
Index: src/tests/usr.bin/xlint/lint1/msg_217.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_217.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_217.exp:1.4
--- src/tests/usr.bin/xlint/lint1/msg_217.exp:1.3 Sun Jan 31 13:33:10 2021
+++ src/tests/usr.bin/xlint/lint1/msg_217.exp Sun Mar 21 11:48:04 2021
@@ -1,3 +1,2 @@
msg_217.c(11): warning: function random falls off bottom without returning value [217]
-msg_217.c(31): warning: statement not reached [193]
-msg_217.c(32): warning: function do_while_return falls off bottom without returning value [217]
+msg_217.c(33): warning: function do_while_return falls off bottom without returning value [217]
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.242 src/usr.bin/xlint/lint1/tree.c:1.243
--- src/usr.bin/xlint/lint1/tree.c:1.242 Sat Mar 20 21:08:09 2021
+++ src/usr.bin/xlint/lint1/tree.c Sun Mar 21 11:48:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.242 2021/03/20 21:08:09 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.243 2021/03/21 11:48:04 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.242 2021/03/20 21:08:09 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.243 2021/03/21 11:48:04 rillig Exp $");
#endif
#include <float.h>
@@ -3777,7 +3777,8 @@ expr(tnode_t *tn, bool vctx, bool tctx,
}
/* expr() is also called in global initializations */
- if (dcs->d_ctx != EXTERN)
+ /* TODO: rename constcond_false_ok */
+ if (dcs->d_ctx != EXTERN && !constcond_false_ok)
check_statement_reachable();
check_expr_misc(tn, vctx, tctx, !tctx, false, false, false);