Module Name:    src
Committed By:   rillig
Date:           Sun Mar 21 11:55:59 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_217.c msg_217.exp
        src/usr.bin/xlint/lint1: func.c lint1.h

Log Message:
lint: fix wrong 'falls off bottom' after return in do-while


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_217.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_217.exp
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.80 -r1.81 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/tests/usr.bin/xlint/lint1/msg_217.c
diff -u src/tests/usr.bin/xlint/lint1/msg_217.c:1.5 src/tests/usr.bin/xlint/lint1/msg_217.c:1.6
--- src/tests/usr.bin/xlint/lint1/msg_217.c:1.5	Sun Mar 21 11:48:04 2021
+++ src/tests/usr.bin/xlint/lint1/msg_217.c	Sun Mar 21 11:55:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_217.c,v 1.5 2021/03/21 11:48:04 rillig Exp $	*/
+/*	$NetBSD: msg_217.c,v 1.6 2021/03/21 11:55:59 rillig Exp $	*/
 # 3 "msg_217.c"
 
 // Test for message: function %s falls off bottom without returning value [217]
@@ -23,6 +23,9 @@ random(int n)
  * '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.
+ *
+ * Before func.c 1.83 from 2021-03-21, lint wrongly reported that the function
+ * would fall off the bottom.
  */
 int
 do_while_return(int i)
@@ -30,7 +33,7 @@ do_while_return(int i)
 	do {
 		return i;
 	} while (0);
-}					/*FIXME*//* expect: 217 */
+}
 
 /*
  * C99 5.1.2.2.3 "Program termination" p1 defines that as a special exception,

Index: src/tests/usr.bin/xlint/lint1/msg_217.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_217.exp:1.4 src/tests/usr.bin/xlint/lint1/msg_217.exp:1.5
--- src/tests/usr.bin/xlint/lint1/msg_217.exp:1.4	Sun Mar 21 11:48:04 2021
+++ src/tests/usr.bin/xlint/lint1/msg_217.exp	Sun Mar 21 11:55:59 2021
@@ -1,2 +1 @@
 msg_217.c(11): warning: function random 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/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.82 src/usr.bin/xlint/lint1/func.c:1.83
--- src/usr.bin/xlint/lint1/func.c:1.82	Sun Mar 21 11:38:24 2021
+++ src/usr.bin/xlint/lint1/func.c	Sun Mar 21 11:55:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: func.c,v 1.82 2021/03/21 11:38:24 rillig Exp $	*/
+/*	$NetBSD: func.c,v 1.83 2021/03/21 11:55:59 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.82 2021/03/21 11:38:24 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.83 2021/03/21 11:55:59 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -830,11 +830,10 @@ do2(tnode_t *tn)
 
 	expr(tn, false, true, true, true);
 
-	/*
-	 * The end of the loop is only reached if it is no endless loop
-	 * or there was a break statement which could be reached.
-	 */
-	reached = !cstmt->c_infinite || cstmt->c_break;
+	if (cstmt->c_infinite)
+		reached = false;
+	if (cstmt->c_break)
+		reached = true;
 	rchflg = false;
 
 	popctrl(T_DO);

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.80 src/usr.bin/xlint/lint1/lint1.h:1.81
--- src/usr.bin/xlint/lint1/lint1.h:1.80	Sun Mar 21 10:30:28 2021
+++ src/usr.bin/xlint/lint1/lint1.h	Sun Mar 21 11:55:59 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.80 2021/03/21 10:30:28 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.81 2021/03/21 11:55:59 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -386,10 +386,15 @@ typedef struct control_statement {
 	bool	c_loop : 1;		/* continue && break are valid */
 	bool	c_switch : 1;		/* case && break are valid */
 	bool	c_break : 1;		/* loop/switch has break */
+					/* TODO: is the break guaranteed to be
+					 * reachable? */
 	bool	c_cont : 1;		/* loop has continue */
 	bool	c_default : 1;		/* switch has default */
-	bool	c_infinite : 1;		/* break condition always false
-					   (for (;;), while (1)) */
+	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_rchif : 1;		/* end of if-branch reached */
 	bool	c_had_return_noval : 1;	/* had "return;" */
 	bool	c_had_return_value : 1;	/* had "return (e);" */

Reply via email to