Module Name: src
Committed By: rillig
Date: Sun Jan 31 13:33:11 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_217.c msg_217.exp
Log Message:
lint: demonstrate wrong and misleading warnings about reachability
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_217.c \
src/tests/usr.bin/xlint/lint1/msg_217.exp
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.2 src/tests/usr.bin/xlint/lint1/msg_217.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_217.c:1.2 Sat Jan 30 17:02:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_217.c Sun Jan 31 13:33:10 2021
@@ -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 @@ random(int n)
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 */
Index: src/tests/usr.bin/xlint/lint1/msg_217.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_217.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_217.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_217.exp:1.2 Sat Jan 30 17:02:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_217.exp Sun Jan 31 13:33:10 2021
@@ -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]