Module Name: src Committed By: rillig Date: Fri May 14 21:14:55 UTC 2021
Modified Files: src/distrib/sets/lists/tests: mi src/tests/usr.bin/xlint/lint1: Makefile t_integration.sh Added Files: src/tests/usr.bin/xlint/lint1: expr_range.c Log Message: tests/lint: test bitwise mismatch in switch statement To generate a diff of this commit: cvs rdiff -u -r1.1049 -r1.1050 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.55 -r1.56 src/tests/usr.bin/xlint/lint1/Makefile cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/expr_range.c cvs rdiff -u -r1.48 -r1.49 src/tests/usr.bin/xlint/lint1/t_integration.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1049 src/distrib/sets/lists/tests/mi:1.1050 --- src/distrib/sets/lists/tests/mi:1.1049 Sun May 2 21:22:09 2021 +++ src/distrib/sets/lists/tests/mi Fri May 14 21:14:55 2021 @@ -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 Index: src/tests/usr.bin/xlint/lint1/Makefile diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.55 src/tests/usr.bin/xlint/lint1/Makefile:1.56 --- src/tests/usr.bin/xlint/lint1/Makefile:1.55 Sun May 2 21:22:09 2021 +++ src/tests/usr.bin/xlint/lint1/Makefile Fri May 14 21:14:55 2021 @@ -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+= d_zero_sized_arrays.c 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 Index: src/tests/usr.bin/xlint/lint1/t_integration.sh diff -u src/tests/usr.bin/xlint/lint1/t_integration.sh:1.48 src/tests/usr.bin/xlint/lint1/t_integration.sh:1.49 --- src/tests/usr.bin/xlint/lint1/t_integration.sh:1.48 Mon May 3 03:50:43 2021 +++ src/tests/usr.bin/xlint/lint1/t_integration.sh Fri May 14 21:14:55 2021 @@ -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_incorrect_array_size test_case d_long_double_int test_case emit +test_case expr_range test_case gcc_attribute test_case gcc_attribute_aligned Added files: Index: src/tests/usr.bin/xlint/lint1/expr_range.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/expr_range.c:1.1 --- /dev/null Fri May 14 21:14:56 2021 +++ src/tests/usr.bin/xlint/lint1/expr_range.c Fri May 14 21:14:55 2021 @@ -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; + } +}