Module Name:    src
Committed By:   rillig
Date:           Sat Jan 15 23:21:34 UTC 2022

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_193.c msg_193.exp msg_249.c
            msg_249.exp
        src/usr.bin/xlint/lint1: cgram.y

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/usr.bin/xlint/lint1/msg_193.c
cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/xlint/lint1/msg_193.exp
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_249.c
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_249.exp
cvs rdiff -u -r1.378 -r1.379 src/usr.bin/xlint/lint1/cgram.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/msg_193.c
diff -u src/tests/usr.bin/xlint/lint1/msg_193.c:1.15 src/tests/usr.bin/xlint/lint1/msg_193.c:1.16
--- src/tests/usr.bin/xlint/lint1/msg_193.c:1.15	Sat Jan 15 22:12:35 2022
+++ src/tests/usr.bin/xlint/lint1/msg_193.c	Sat Jan 15 23:21:34 2022
@@ -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 @@ lint_annotation_NOTREACHED(void)
 }
 
 /*
- * 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;;
 }

Index: src/tests/usr.bin/xlint/lint1/msg_193.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_193.exp:1.14 src/tests/usr.bin/xlint/lint1/msg_193.exp:1.15
--- src/tests/usr.bin/xlint/lint1/msg_193.exp:1.14	Sun Aug 15 21:51:56 2021
+++ src/tests/usr.bin/xlint/lint1/msg_193.exp	Sat Jan 15 23:21:34 2022
@@ -87,3 +87,4 @@ msg_193.c(597): warning: statement not r
 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]

Index: src/tests/usr.bin/xlint/lint1/msg_249.c
diff -u src/tests/usr.bin/xlint/lint1/msg_249.c:1.8 src/tests/usr.bin/xlint/lint1/msg_249.c:1.9
--- src/tests/usr.bin/xlint/lint1/msg_249.c:1.8	Sat Jul 10 17:35:54 2021
+++ src/tests/usr.bin/xlint/lint1/msg_249.c	Sat Jan 15 23:21:34 2022
@@ -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 @@ int recover_from_rbrace;
 void
 function(void)
 {
+	/* expect+2: warning: statement not reached [193] */
 	if (0)
 		;
 	);			/* expect: syntax error ')' */

Index: src/tests/usr.bin/xlint/lint1/msg_249.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_249.exp:1.6 src/tests/usr.bin/xlint/lint1/msg_249.exp:1.7
--- src/tests/usr.bin/xlint/lint1/msg_249.exp:1.6	Sat Jul 10 11:22:19 2021
+++ src/tests/usr.bin/xlint/lint1/msg_249.exp	Sat Jan 15 23:21:34 2022
@@ -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]

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.378 src/usr.bin/xlint/lint1/cgram.y:1.379
--- src/usr.bin/xlint/lint1/cgram.y:1.378	Sun Dec 26 18:16:41 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jan 15 23:21:34 2022
@@ -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 @@ expression_statement:		/* C99 6.8.3 */
 		seen_fallthrough = false;
 	  }
 	| T_SEMI {
+		check_statement_reachable();
 		seen_fallthrough = false;
 	  }
 	;

Reply via email to