Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src tests/lint: test bitwise mismatch in switch statement
details: https://anonhg.NetBSD.org/src/rev/5be84e55fe46
branches: trunk
changeset: 983298:5be84e55fe46
user: rillig <rillig%NetBSD.org@localhost>
date: Fri May 14 21:14:55 2021 +0000
description:
tests/lint: test bitwise mismatch in switch statement
diffstat:
distrib/sets/lists/tests/mi | 3 +-
tests/usr.bin/xlint/lint1/Makefile | 3 +-
tests/usr.bin/xlint/lint1/expr_range.c | 37 ++++++++++++++++++++++++++++++
tests/usr.bin/xlint/lint1/t_integration.sh | 3 +-
4 files changed, 43 insertions(+), 3 deletions(-)
diffs (92 lines):
diff -r c034726b233c -r 5be84e55fe46 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Fri May 14 19:37:16 2021 +0000
+++ b/distrib/sets/lists/tests/mi Fri May 14 21:14:55 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1049 2021/05/02 21:22:09 rillig Exp $
+# $NetBSD: mi,v 1.1050 2021/05/14 21:14:55 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -6189,6 +6189,7 @@
./usr/tests/usr.bin/xlint/lint1/emit.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/emit.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/emit.ln tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/expr_range.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/feat_stacktrace.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/feat_stacktrace.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/gcc_attribute.c tests-usr.bin-tests compattestfile,atf
diff -r c034726b233c -r 5be84e55fe46 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile Fri May 14 19:37:16 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile Fri May 14 21:14:55 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.55 2021/05/02 21:22:09 rillig Exp $
+# $NetBSD: Makefile,v 1.56 2021/05/14 21:14:55 rillig Exp $
NOMAN= # defined
MAX_MESSAGE= 343 # see lint1/err.c
@@ -103,6 +103,7 @@
FILES+= emit.c
FILES+= emit.exp
FILES+= emit.ln
+FILES+= expr_range.c
FILES+= feat_stacktrace.c
FILES+= feat_stacktrace.exp
FILES+= gcc_attribute.c
diff -r c034726b233c -r 5be84e55fe46 tests/usr.bin/xlint/lint1/expr_range.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_range.c Fri May 14 21:14:55 2021 +0000
@@ -0,0 +1,37 @@
+/* $NetBSD: expr_range.c,v 1.1 2021/05/14 21:14:55 rillig Exp $ */
+# 3 "expr_range.c"
+
+/*
+ * Test whether lint can detect switch branches that are impossible to reach.
+ * As of 2021-05-14, it cannot. To do this, it would need to keep track of
+ * the possible values of each variable or expression. To do this reliably,
+ * it would also need accurate control flow analysis, which as of 2021-05-14
+ * works only for functions without 'goto'.
+ *
+ * GCC 10 does not complain the unreachable branch. It knows that the branch
+ * is unreachable though since it doesn't generate any code for it. GCC once
+ * had the option -Wunreachable-code, but that option was made a no-op in
+ * 2011.
+ *
+ * Clang 10 does not complain about this either, and just like GCC it doesn't
+ * generate any code for this branch. The code for tracking an expression's
+ * possible values may be related to RangeConstraintManager, just guessing.
+ *
+ * There should be at least one static analysis tool that warns about this.
+ */
+
+/* lint1-extra-flags: -chap */
+
+void
+example(unsigned x)
+{
+ switch (x & 6) {
+ case 1:
+ /* This branch is unreachable. */
+ printf("one\n");
+ break;
+ case 2:
+ printf("two\n");
+ break;
+ }
+}
diff -r c034726b233c -r 5be84e55fe46 tests/usr.bin/xlint/lint1/t_integration.sh
--- a/tests/usr.bin/xlint/lint1/t_integration.sh Fri May 14 19:37:16 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/t_integration.sh Fri May 14 21:14:55 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.48 2021/05/03 03:50:43 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.49 2021/05/14 21:14:55 rillig Exp $
#
# Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -175,6 +175,7 @@
test_case d_long_double_int
test_case emit
+test_case expr_range
test_case gcc_attribute
test_case gcc_attribute_aligned
Home |
Main Index |
Thread Index |
Old Index