Module Name: src
Committed By: rillig
Date: Sun Mar 21 12:03:56 UTC 2021
Modified Files:
src/usr.bin/xlint/lint1: func.c lint1.h
Log Message:
lint: rename i_infinite to i_maybe_endless
Not every loop that has 'while (1)' is an endless loop. It may still
contain a 'return' somewhere.
To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/xlint/lint1/lint1.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.83 src/usr.bin/xlint/lint1/func.c:1.84
--- src/usr.bin/xlint/lint1/func.c:1.83 Sun Mar 21 11:55:59 2021
+++ src/usr.bin/xlint/lint1/func.c Sun Mar 21 12:03:56 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: func.c,v 1.83 2021/03/21 11:55:59 rillig Exp $ */
+/* $NetBSD: func.c,v 1.84 2021/03/21 12:03:56 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.83 2021/03/21 11:55:59 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.84 2021/03/21 12:03:56 rillig Exp $");
#endif
#include <stdlib.h>
@@ -761,7 +761,7 @@ while1(tnode_t *tn)
pushctrl(T_WHILE);
cstmt->c_loop = true;
if (tn != NULL && tn->tn_op == CON)
- cstmt->c_infinite = constant_is_nonzero(tn);
+ cstmt->c_maybe_endless = constant_is_nonzero(tn);
check_getopt_begin_while(tn);
expr(tn, false, true, true, false);
@@ -779,7 +779,7 @@ while2(void)
* The end of the loop can be reached if it is no endless loop
* or there was a break statement which was reached.
*/
- reached = !cstmt->c_infinite || cstmt->c_break;
+ reached = !cstmt->c_maybe_endless || cstmt->c_break;
rchflg = false;
check_getopt_end_while();
@@ -822,15 +822,15 @@ do2(tnode_t *tn)
tn = check_controlling_expression(tn);
if (tn != NULL && tn->tn_op == CON) {
- cstmt->c_infinite = constant_is_nonzero(tn);
- if (!cstmt->c_infinite && cstmt->c_cont)
+ cstmt->c_maybe_endless = constant_is_nonzero(tn);
+ if (!cstmt->c_maybe_endless && cstmt->c_cont)
/* continue in 'do ... while (0)' loop */
error(323);
}
expr(tn, false, true, true, true);
- if (cstmt->c_infinite)
+ if (cstmt->c_maybe_endless)
reached = false;
if (cstmt->c_break)
reached = true;
@@ -877,7 +877,7 @@ for1(tnode_t *tn1, tnode_t *tn2, tnode_t
if (tn2 != NULL)
expr(tn2, false, true, true, false);
- cstmt->c_infinite =
+ cstmt->c_maybe_endless =
tn2 == NULL || (tn2->tn_op == CON && constant_is_nonzero(tn2));
/* Checking the reinitialization expression is done in for2() */
@@ -924,7 +924,8 @@ for2(void)
csrc_pos = cspos;
/* An endless loop without break will never terminate */
- reached = cstmt->c_break || !cstmt->c_infinite;
+ /* TODO: What if the loop contains a 'return'? */
+ reached = cstmt->c_break || !cstmt->c_maybe_endless;
rchflg = false;
popctrl(T_FOR);
Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.81 src/usr.bin/xlint/lint1/lint1.h:1.82
--- src/usr.bin/xlint/lint1/lint1.h:1.81 Sun Mar 21 11:55:59 2021
+++ src/usr.bin/xlint/lint1/lint1.h Sun Mar 21 12:03:56 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.81 2021/03/21 11:55:59 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.82 2021/03/21 12:03:56 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -390,11 +390,10 @@ typedef struct control_statement {
* reachable? */
bool c_cont : 1; /* loop has continue */
bool c_default : 1; /* switch has default */
- bool c_infinite : 1; /* controlling expression always false
- * (as in for (;;) or while (1)),
- * there may be break statements
- * though.
- * TODO: rename to c_maybe_infinite */
+ bool c_maybe_endless : 1; /* the controlling expression is
+ * always true (as in 'for (;;)' or
+ * 'while (1)'), there may be break
+ * statements though */
bool c_rchif : 1; /* end of if-branch reached */
bool c_had_return_noval : 1; /* had "return;" */
bool c_had_return_value : 1; /* had "return (e);" */