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 wrong 'falls off bottom' after...



details:   https://anonhg.NetBSD.org/src/rev/bd1b88f45ebd
branches:  trunk
changeset: 953812:bd1b88f45ebd
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Mar 21 11:55:59 2021 +0000

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

diffstat:

 tests/usr.bin/xlint/lint1/msg_217.c   |   7 +++++--
 tests/usr.bin/xlint/lint1/msg_217.exp |   1 -
 usr.bin/xlint/lint1/func.c            |  13 ++++++-------
 usr.bin/xlint/lint1/lint1.h           |  11 ++++++++---
 4 files changed, 19 insertions(+), 13 deletions(-)

diffs (95 lines):

diff -r 4773187fa91e -r bd1b88f45ebd tests/usr.bin/xlint/lint1/msg_217.c
--- a/tests/usr.bin/xlint/lint1/msg_217.c       Sun Mar 21 11:48:04 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_217.c       Sun Mar 21 11:55:59 2021 +0000
@@ -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 @@
  * '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 {
                return i;
        } while (0);
-}                                      /*FIXME*//* expect: 217 */
+}
 
 /*
  * C99 5.1.2.2.3 "Program termination" p1 defines that as a special exception,
diff -r 4773187fa91e -r bd1b88f45ebd tests/usr.bin/xlint/lint1/msg_217.exp
--- a/tests/usr.bin/xlint/lint1/msg_217.exp     Sun Mar 21 11:48:04 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_217.exp     Sun Mar 21 11:55:59 2021 +0000
@@ -1,2 +1,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]
diff -r 4773187fa91e -r bd1b88f45ebd usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sun Mar 21 11:48:04 2021 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sun Mar 21 11:55:59 2021 +0000
@@ -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 @@
 
        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);
diff -r 4773187fa91e -r bd1b88f45ebd usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sun Mar 21 11:48:04 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sun Mar 21 11:55:59 2021 +0000
@@ -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 @@
        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);" */



Home | Main Index | Thread Index | Old Index