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: add tests for reachabi...
details: https://anonhg.NetBSD.org/src/rev/87c480777c0a
branches: trunk
changeset: 953820:87c480777c0a
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Mar 21 14:09:40 2021 +0000
description:
tests/lint: add tests for reachability of statements
Right now, reachability is only implemented for loops, but not for
selection statements.
diffstat:
tests/usr.bin/xlint/lint1/msg_193.c | 495 +++++++++++++++++++++++++++++++++-
tests/usr.bin/xlint/lint1/msg_193.exp | 44 ++-
2 files changed, 534 insertions(+), 5 deletions(-)
diffs (truncated from 553 to 300 lines):
diff -r 8ce9b300c9fb -r 87c480777c0a tests/usr.bin/xlint/lint1/msg_193.c
--- a/tests/usr.bin/xlint/lint1/msg_193.c Sun Mar 21 13:10:58 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_193.c Sun Mar 21 14:09:40 2021 +0000
@@ -1,10 +1,497 @@
-/* $NetBSD: msg_193.c,v 1.2 2021/01/30 17:56:29 rillig Exp $ */
+/* $NetBSD: msg_193.c,v 1.3 2021/03/21 14:09:40 rillig Exp $ */
# 3 "msg_193.c"
// Test for message: statement not reached [193]
-void example(void)
+/*
+ * Test the reachability of statements in a function.
+ *
+ * if
+ * if-else
+ * if-else-if-else
+ * for
+ * while
+ * do-while
+ * switch
+ * break
+ * continue
+ * goto
+ * return
+ *
+ * constant expression
+ * system-dependent constant expression
+ */
+
+extern void
+reachable(void);
+extern void
+unreachable(void);
+
+void
+test_statement(void)
+{
+ reachable();
+ reachable();
+}
+
+void
+test_compound_statement(void)
+{
+ reachable();
+ {
+ reachable();
+ reachable();
+ }
+ reachable();
+}
+
+void
+test_if_statement(void)
+{
+ if (1)
+ reachable();
+ reachable();
+ if (0)
+ unreachable(); /* TODO: expect: 193 */
+ reachable();
+}
+
+void
+test_if_compound_statement(void)
+{
+ if (1) {
+ reachable();
+ }
+ if (1) {
+ {
+ {
+ reachable();
+ }
+ }
+ }
+
+ if (0) {
+ unreachable(); /* TODO: expect: 193 */
+ }
+ if (0) {
+ {
+ {
+ unreachable(); /* TODO: expect: 193 */
+ }
+ }
+ }
+}
+
+void
+test_if_without_else(void)
+{
+ if (1)
+ reachable();
+ reachable();
+
+ if (0)
+ unreachable(); /* TODO: expect: 193 */
+ reachable();
+}
+
+void
+test_if_with_else(void)
+{
+ if (1)
+ reachable();
+ else
+ unreachable(); /* TODO: expect: 193 */
+ reachable();
+
+ if (0)
+ unreachable(); /* TODO: expect: 193 */
+ else
+ reachable();
+ reachable();
+}
+
+void
+test_if_else_if_else(void)
+{
+ if (1)
+ reachable();
+ else if (1)
+ unreachable(); /* TODO: expect: 193 */
+ else
+ unreachable(); /* TODO: expect: 193 */
+
+ if (0)
+ unreachable(); /* TODO: expect: 193 */
+ else if (1)
+ reachable();
+ else
+ unreachable(); /* TODO: expect: 193 */
+
+ if (0)
+ unreachable(); /* TODO: expect: 193 */
+ else if (0)
+ unreachable(); /* TODO: expect: 193 */
+ else
+ reachable();
+}
+
+void
+test_if_return(void)
+{
+ if (1)
+ return;
+ unreachable(); /* TODO: expect: 193 */
+}
+
+void
+test_if_else_return(void)
+{
+ if (1)
+ reachable();
+ else
+ return;
+ reachable();
+}
+
+void
+test_for_forever(void)
+{
+ for (;;)
+ reachable();
+ unreachable(); /* expect: 193 */
+}
+
+void
+test_for_true(void)
+{
+ for (; 1;)
+ reachable();
+ unreachable(); /* expect: 193 */
+}
+
+void
+test_for_false(void)
+{
+ for (; 0;)
+ unreachable(); /* TODO: expect: 193 */
+ reachable();
+}
+
+void
+test_for_break(void)
+{
+ for (;;) {
+ reachable();
+ break;
+ unreachable(); /* expect: 193 */
+ }
+ reachable();
+}
+
+void
+test_for_if_break(void)
+{
+ for (;;) {
+ reachable();
+ if (0) {
+ unreachable(); /* TODO: expect: 193 */
+ break;
+ unreachable(); /* expect: 193 */
+ }
+ if (1) {
+ reachable();
+ break;
+ unreachable(); /* expect: 193 */
+ }
+ unreachable(); /* TODO: expect: 193 */
+ }
+ reachable();
+}
+
+void
+test_for_continue(void)
+{
+ for (;;) {
+ reachable();
+ continue;
+ unreachable(); /* expect: 193 */
+ }
+ unreachable(); /* expect: 193 */
+}
+
+void
+test_for_if_continue(void)
+{
+ for (;;) {
+ reachable();
+ if (0) {
+ unreachable(); /* TODO: expect: 193 */
+ continue;
+ unreachable(); /* expect: 193 */
+ }
+ if (1) {
+ reachable();
+ continue;
+ unreachable(); /* expect: 193 */
+ }
+ unreachable(); /* TODO: expect: 193 */
+ }
+ unreachable(); /* expect: 193 */
+}
+
+void
+test_for_return(void)
{
- return;
- return; /* expect: 193 */
+ for (;;) {
+ reachable();
+ return;
+ unreachable(); /* expect: 193 */
+ }
+ unreachable(); /* expect: 193 */
+}
+
+void
+test_for_if_return(void)
+{
+ for (;;) {
+ reachable();
+ if (0) {
+ unreachable(); /* TODO: expect: 193 */
+ return;
+ unreachable(); /* expect: 193 */
+ }
+ if (1) {
+ reachable();
+ return;
+ unreachable(); /* expect: 193 */
+ }
+ unreachable(); /* TODO: expect: 193 */
+ }
+ unreachable(); /* expect: 193 */
+}
+
+void
+test_while_true(void)
+{
+ while (1)
+ reachable();
+ unreachable(); /* expect: 193 */
+}
+
+void
+test_while_false(void)
+{
+ while (0)
+ unreachable(); /* TODO: expect: 193 */
+ reachable();
+}
+
+void
+test_while_break(void)
+{
+ while (1) {
Home |
Main Index |
Thread Index |
Old Index