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 tests/lint: test reachability of g...



details:   https://anonhg.NetBSD.org/src/rev/c47b5ebab2a2
branches:  trunk
changeset: 953841:c47b5ebab2a2
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Mar 21 20:08:21 2021 +0000

description:
tests/lint: test reachability of goto and named labels

diffstat:

 tests/usr.bin/xlint/lint1/msg_193.c   |  62 +++++++++++++++++++++++++++++++++-
 tests/usr.bin/xlint/lint1/msg_193.exp |   3 +
 2 files changed, 62 insertions(+), 3 deletions(-)

diffs (86 lines):

diff -r b6dda0f7a495 -r c47b5ebab2a2 tests/usr.bin/xlint/lint1/msg_193.c
--- a/tests/usr.bin/xlint/lint1/msg_193.c       Sun Mar 21 19:39:01 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_193.c       Sun Mar 21 20:08:21 2021 +0000
@@ -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 @@
        reachable();
 }
 
+/*
+ * 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;
+}
+
+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: goto */
-
 /* TODO: system-dependent constant expression (see tn_system_dependent) */
diff -r b6dda0f7a495 -r c47b5ebab2a2 tests/usr.bin/xlint/lint1/msg_193.exp
--- a/tests/usr.bin/xlint/lint1/msg_193.exp     Sun Mar 21 19:39:01 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_193.exp     Sun Mar 21 20:08:21 2021 +0000
@@ -82,3 +82,6 @@
 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]



Home | Main Index | Thread Index | Old Index