diff --git a/tests/usr.bin/xlint/lint1/msg_193.c b/tests/usr.bin/xlint/lint1/msg_193.c index 6687b0d9b3cb..df77cff90ad8 100644 --- a/tests/usr.bin/xlint/lint1/msg_193.c +++ b/tests/usr.bin/xlint/lint1/msg_193.c @@ -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(); } +/* + * 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 --git a/tests/usr.bin/xlint/lint1/msg_193.exp b/tests/usr.bin/xlint/lint1/msg_193.exp index 286f340a215c..f54edf219734 100644 --- a/tests/usr.bin/xlint/lint1/msg_193.exp +++ b/tests/usr.bin/xlint/lint1/msg_193.exp @@ -82,3 +82,6 @@ msg_193.c(515): warning: statement not reached [193] 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]