Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/xlint/lint1 lint: demonstrate wrong and mislea...



details:   https://anonhg.NetBSD.org/src/rev/7731f6de1d73
branches:  trunk
changeset: 1018353:7731f6de1d73
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 31 13:33:10 2021 +0000

description:
lint: demonstrate wrong and misleading warnings about reachability

diffstat:

 tests/usr.bin/xlint/lint1/msg_217.c   |  23 ++++++++++++++++++++++-
 tests/usr.bin/xlint/lint1/msg_217.exp |   2 ++
 2 files changed, 24 insertions(+), 1 deletions(-)

diffs (41 lines):

diff -r 453ea357b52a -r 7731f6de1d73 tests/usr.bin/xlint/lint1/msg_217.c
--- a/tests/usr.bin/xlint/lint1/msg_217.c       Sun Jan 31 13:11:08 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_217.c       Sun Jan 31 13:33:10 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_217.c,v 1.2 2021/01/30 17:02:58 rillig Exp $       */
+/*     $NetBSD: msg_217.c,v 1.3 2021/01/31 13:33:10 rillig Exp $       */
 # 3 "msg_217.c"
 
 // Test for message: function %s falls off bottom without returning value [217]
@@ -9,3 +9,24 @@
        if (n < 0)
                return -3;
 }                              /* expect: 217 */
+
+/*
+ * The pattern 'do { } while (0)' is often used in statement macros.
+ * Putting a 'return' at the end of such a macro is legitimate, the embracing
+ * 'do { } while (0)' is probably there to conform to a coding standard or
+ * to otherwise reduce confusion.
+ *
+ * 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'.
+ */
+int
+do_while_return(int i)
+{
+       do {
+               return i;
+       } while (/*CONSTCOND*/0);       /*FIXME*//* expect: 193 */
+}                                      /*FIXME*//* expect: 217 */
diff -r 453ea357b52a -r 7731f6de1d73 tests/usr.bin/xlint/lint1/msg_217.exp
--- a/tests/usr.bin/xlint/lint1/msg_217.exp     Sun Jan 31 13:11:08 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_217.exp     Sun Jan 31 13:33:10 2021 +0000
@@ -1,1 +1,3 @@
 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]



Home | Main Index | Thread Index | Old Index