Module Name: src
Committed By: rillig
Date: Sun Mar 21 20:08:21 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_193.c msg_193.exp
Log Message:
tests/lint: test reachability of goto and named labels
To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/msg_193.c \
src/tests/usr.bin/xlint/lint1/msg_193.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_193.c
diff -u src/tests/usr.bin/xlint/lint1/msg_193.c:1.10 src/tests/usr.bin/xlint/lint1/msg_193.c:1.11
--- src/tests/usr.bin/xlint/lint1/msg_193.c:1.10 Sun Mar 21 19:39:01 2021
+++ src/tests/usr.bin/xlint/lint1/msg_193.c Sun Mar 21 20:08:21 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_193.c,v 1.10 2021/03/21 19:39:01 rillig Exp $ */
+/* $NetBSD: msg_193.c,v 1.11 2021/03/21 20:08:21 rillig Exp $ */
# 3 "msg_193.c"
// Test for message: statement not reached [193]
@@ -555,8 +555,64 @@ test_if_maybe(void)
reachable();
}
-/* TODO: switch */
+/*
+ * To compute the reachability graph of this little monster, lint would have
+ * to keep all statements and their relations from the whole function in
+ * memory. It doesn't do that. Therefore it does not warn about any
+ * unreachable statements in this function.
+ */
+void
+test_goto_numbers_alphabetically(void)
+{
+ goto one;
+eight:
+ goto nine;
+five:
+ return;
+four:
+ goto five;
+nine:
+ goto ten;
+one:
+ goto two;
+seven:
+ goto eight;
+six: /* expect: warning: label six unused */
+ goto seven;
+ten:
+ return;
+three:
+ goto four;
+two:
+ goto three;
+}
-/* TODO: goto */
+void
+test_while_goto(void)
+{
+ while (1) {
+ goto out;
+ break; /* lint only warns with the -b option */
+ }
+ unreachable(); /* expect: 193 */
+out:
+ reachable();
+}
+
+void
+test_unreachable_label(void)
+{
+ if (0)
+ goto unreachable; /* expect: 193 */
+ goto reachable;
+
+ /* named_label assumes that any label is reachable. */
+unreachable:
+ unreachable();
+reachable:
+ reachable();
+}
+
+/* TODO: switch */
/* TODO: system-dependent constant expression (see tn_system_dependent) */
Index: src/tests/usr.bin/xlint/lint1/msg_193.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_193.exp:1.10 src/tests/usr.bin/xlint/lint1/msg_193.exp:1.11
--- src/tests/usr.bin/xlint/lint1/msg_193.exp:1.10 Sun Mar 21 19:39:01 2021
+++ src/tests/usr.bin/xlint/lint1/msg_193.exp Sun Mar 21 20:08:21 2021
@@ -82,3 +82,6 @@ msg_193.c(515): warning: statement not r
msg_193.c(518): warning: statement not reached [193]
msg_193.c(532): warning: statement not reached [193]
msg_193.c(540): warning: statement not reached [193]
+msg_193.c(580): warning: label six unused in function test_goto_numbers_alphabetically [232]
+msg_193.c(597): warning: statement not reached [193]
+msg_193.c(606): warning: statement not reached [193]