Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 lint: warn about unreachable null statem...
details: https://anonhg.NetBSD.org/src/rev/9a5527c848fb
branches: trunk
changeset: 359667:9a5527c848fb
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jan 15 23:21:34 2022 +0000
description:
lint: warn about unreachable null statements
This warning flags the second semicolon of 'return;;' as being
unreachable. It does not warn about these superfluous semicolons in
general though.
Seen in usr.bin/make/bmake_malloc.c.
diffstat:
tests/usr.bin/xlint/lint1/msg_193.c | 27 +++++++++++++++++++++------
tests/usr.bin/xlint/lint1/msg_193.exp | 1 +
tests/usr.bin/xlint/lint1/msg_249.c | 3 ++-
tests/usr.bin/xlint/lint1/msg_249.exp | 5 +++--
usr.bin/xlint/lint1/cgram.y | 5 +++--
5 files changed, 30 insertions(+), 11 deletions(-)
diffs (105 lines):
diff -r 10a7e9970621 -r 9a5527c848fb tests/usr.bin/xlint/lint1/msg_193.c
--- a/tests/usr.bin/xlint/lint1/msg_193.c Sat Jan 15 22:18:04 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_193.c Sat Jan 15 23:21:34 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_193.c,v 1.15 2022/01/15 22:12:35 rillig Exp $ */
+/* $NetBSD: msg_193.c,v 1.16 2022/01/15 23:21:34 rillig Exp $ */
# 3 "msg_193.c"
// Test for message: statement not reached [193]
@@ -658,12 +658,27 @@
}
/*
- * Since at least 2002, lint does not detect a double semicolon. See
- * cgram.y, expression_statement, T_SEMI.
+ * Since at least 2002 and before cgram.y 1.379 from 2022-01-16, lint did not
+ * detect a double semicolon. See cgram.y, expression_statement, T_SEMI.
*/
int
-test_empty_statement(int x)
+test_null_statement(void)
{
- /* TODO: expect+1: warning: statement not reachable [193] */
- return x > 0 ? x : -x;;
+ /*
+ * The following 2 semicolons are superfluous but lint doesn't warn
+ * about them. Probably it should. A null statement as part of a
+ * block-list has no use.
+ */
+ ;;
+
+ /*
+ * A stand-alone null statement, on the other hand, has its purpose.
+ * Without it, the 'for' loop would not be complete. The NetBSD
+ * style is to use 'continue;' instead of a simple ';'.
+ */
+ for (int i = 0; i < 10; i++)
+ ;
+
+ /* expect+1: warning: statement not reached [193] */
+ return 0;;
}
diff -r 10a7e9970621 -r 9a5527c848fb tests/usr.bin/xlint/lint1/msg_193.exp
--- a/tests/usr.bin/xlint/lint1/msg_193.exp Sat Jan 15 22:18:04 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_193.exp Sat Jan 15 23:21:34 2022 +0000
@@ -87,3 +87,4 @@
msg_193.c(606): warning: statement not reached [193]
msg_193.c(627): warning: statement not reached [193]
msg_193.c(655): warning: statement not reached [193]
+msg_193.c(683): warning: statement not reached [193]
diff -r 10a7e9970621 -r 9a5527c848fb tests/usr.bin/xlint/lint1/msg_249.c
--- a/tests/usr.bin/xlint/lint1/msg_249.c Sat Jan 15 22:18:04 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_249.c Sat Jan 15 23:21:34 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_249.c,v 1.8 2021/07/10 17:35:54 rillig Exp $ */
+/* $NetBSD: msg_249.c,v 1.9 2022/01/15 23:21:34 rillig Exp $ */
# 3 "msg_249.c"
// Test for message: syntax error '%s' [249]
@@ -28,6 +28,7 @@
void
function(void)
{
+ /* expect+2: warning: statement not reached [193] */
if (0)
;
); /* expect: syntax error ')' */
diff -r 10a7e9970621 -r 9a5527c848fb tests/usr.bin/xlint/lint1/msg_249.exp
--- a/tests/usr.bin/xlint/lint1/msg_249.exp Sat Jan 15 22:18:04 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_249.exp Sat Jan 15 23:21:34 2022 +0000
@@ -1,4 +1,5 @@
msg_249.c(10): error: syntax error '"' [249]
msg_249.c(19): error: syntax error '"' [249]
-msg_249.c(33): error: syntax error ')' [249]
-msg_249.c(58): error: syntax error 'member without type' [249]
+msg_249.c(33): warning: statement not reached [193]
+msg_249.c(34): error: syntax error ')' [249]
+msg_249.c(59): error: syntax error 'member without type' [249]
diff -r 10a7e9970621 -r 9a5527c848fb usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y Sat Jan 15 22:18:04 2022 +0000
+++ b/usr.bin/xlint/lint1/cgram.y Sat Jan 15 23:21:34 2022 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.378 2021/12/26 18:16:41 christos Exp $ */
+/* $NetBSD: cgram.y,v 1.379 2022/01/15 23:21:34 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.378 2021/12/26 18:16:41 christos Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.379 2022/01/15 23:21:34 rillig Exp $");
#endif
#include <limits.h>
@@ -1731,6 +1731,7 @@
seen_fallthrough = false;
}
| T_SEMI {
+ check_statement_reachable();
seen_fallthrough = false;
}
;
Home |
Main Index |
Thread Index |
Old Index