Module Name: src
Committed By: rillig
Date: Wed Nov 13 04:32:50 UTC 2024
Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_bool_strict.c
d_c99_bool_strict_syshdr.c expr_range.c msg_130.c msg_161.c
msg_193.c msg_207.c msg_217.c msg_249.c msg_333.c msg_379.c
src/usr.bin/xlint/lint1: cgram.y err.c externs1.h func.c init.c tree.c
Log Message:
lint: add more details to 'statement not reached' message
In lib/libcompat/regexp/regexp.c, the FAIL macro expands to a compound
statement containing a function call statement and a return statement,
and the macro invocation is followed by a semicolon, forming an extra
empty statement. Which of these statements is unreachable now becomes
clear from the diagnostic, without having to inspect the preprocessed
source code.
To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
cvs rdiff -u -r1.24 -r1.25 \
src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/expr_range.c
cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/xlint/lint1/msg_130.c
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/msg_161.c
cvs rdiff -u -r1.21 -r1.22 src/tests/usr.bin/xlint/lint1/msg_193.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_207.c
cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/xlint/lint1/msg_217.c
cvs rdiff -u -r1.15 -r1.16 src/tests/usr.bin/xlint/lint1/msg_249.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_333.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_379.c
cvs rdiff -u -r1.514 -r1.515 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.252 -r1.253 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.234 -r1.235 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.188 -r1.189 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.270 -r1.271 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.657 -r1.658 src/usr.bin/xlint/lint1/tree.c
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/d_c99_bool_strict.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.50 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.51
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.50 Sun May 12 12:28:35 2024
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c Wed Nov 13 04:32:49 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: d_c99_bool_strict.c,v 1.50 2024/05/12 12:28:35 rillig Exp $ */
+/* $NetBSD: d_c99_bool_strict.c,v 1.51 2024/11/13 04:32:49 rillig Exp $ */
# 3 "d_c99_bool_strict.c"
/*
@@ -409,8 +409,8 @@ strict_bool_controlling_expression(bool
{
/* expect+1: warning: constant in conditional context [161] */
if (__lint_false)
+ /* expect+1: warning: 'call' statement not reached [193] */
do_nothing();
- /* expect-1: warning: statement not reached [193] */
/* expect+1: warning: constant in conditional context [161] */
if (__lint_true)
@@ -421,8 +421,8 @@ strict_bool_controlling_expression(bool
/* expect+1: error: controlling expression must be bool, not 'int' [333] */
if (/*CONSTCOND*/0)
+ /* expect+1: warning: 'call' statement not reached [193] */
do_nothing();
- /* expect-1: warning: statement not reached [193] */
/* expect+1: error: controlling expression must be bool, not 'int' [333] */
if (/*CONSTCOND*/1)
Index: src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.24 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.25
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.24 Sun May 12 12:28:35 2024
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c Wed Nov 13 04:32:49 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: d_c99_bool_strict_syshdr.c,v 1.24 2024/05/12 12:28:35 rillig Exp $ */
+/* $NetBSD: d_c99_bool_strict_syshdr.c,v 1.25 2024/11/13 04:32:49 rillig Exp $ */
# 3 "d_c99_bool_strict_syshdr.c"
/*
@@ -266,8 +266,8 @@ if_pointer_or_int(void)
((void *)0)
# 268 "d_c99_bool_strict_syshdr.c"
)
+ /* expect+1: warning: 'return' statement not reached [193] */
return;
- /* expect-1: warning: statement not reached [193] */
/* if (EXIT_SUCCESS) */
if (
@@ -275,8 +275,8 @@ if_pointer_or_int(void)
0
# 277 "d_c99_bool_strict_syshdr.c"
)
+ /* expect+1: warning: 'return' statement not reached [193] */
return;
- /* expect-1: warning: statement not reached [193] */
/* if (errno) */
if (
Index: src/tests/usr.bin/xlint/lint1/expr_range.c
diff -u src/tests/usr.bin/xlint/lint1/expr_range.c:1.5 src/tests/usr.bin/xlint/lint1/expr_range.c:1.6
--- src/tests/usr.bin/xlint/lint1/expr_range.c:1.5 Tue Mar 28 14:44:34 2023
+++ src/tests/usr.bin/xlint/lint1/expr_range.c Wed Nov 13 04:32:49 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: expr_range.c,v 1.5 2023/03/28 14:44:34 rillig Exp $ */
+/* $NetBSD: expr_range.c,v 1.6 2024/11/13 04:32:49 rillig Exp $ */
# 3 "expr_range.c"
/*
@@ -28,7 +28,7 @@ example(unsigned x)
println("0 is reachable");
break;
case 1:
- /* expect-1: warning: statement not reached [193] */
+ /* expect-1: warning: 'case' statement not reached [193] */
println("1 is not reachable");
break;
case 2:
@@ -38,7 +38,7 @@ example(unsigned x)
println("6 is reachable");
break;
case 7:
- /* expect-1: warning: statement not reached [193] */
+ /* expect-1: warning: 'case' statement not reached [193] */
println("7 is not reachable");
break;
}
Index: src/tests/usr.bin/xlint/lint1/msg_130.c
diff -u src/tests/usr.bin/xlint/lint1/msg_130.c:1.16 src/tests/usr.bin/xlint/lint1/msg_130.c:1.17
--- src/tests/usr.bin/xlint/lint1/msg_130.c:1.16 Tue Mar 28 14:44:34 2023
+++ src/tests/usr.bin/xlint/lint1/msg_130.c Wed Nov 13 04:32:49 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_130.c,v 1.16 2023/03/28 14:44:34 rillig Exp $ */
+/* $NetBSD: msg_130.c,v 1.17 2024/11/13 04:32:49 rillig Exp $ */
# 3 "msg_130.c"
// Test for message: enum type mismatch: '%s' '%s' '%s' [130]
@@ -95,7 +95,7 @@ enum_constant_from_unnamed_type(int x)
if (sizeof_int == sizeof_uint)
return 6;
- /* expect+1: warning: statement not reached [193] */
+ /* expect+1: warning: 'return' statement not reached [193] */
return 0;
}
Index: src/tests/usr.bin/xlint/lint1/msg_161.c
diff -u src/tests/usr.bin/xlint/lint1/msg_161.c:1.11 src/tests/usr.bin/xlint/lint1/msg_161.c:1.12
--- src/tests/usr.bin/xlint/lint1/msg_161.c:1.11 Mon Jun 19 12:33:43 2023
+++ src/tests/usr.bin/xlint/lint1/msg_161.c Wed Nov 13 04:32:49 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_161.c,v 1.11 2023/06/19 12:33:43 rillig Exp $ */
+/* $NetBSD: msg_161.c,v 1.12 2024/11/13 04:32:49 rillig Exp $ */
# 3 "msg_161.c"
// Test for message: constant in conditional context [161]
@@ -18,7 +18,7 @@ while_0(void)
{
/* expect+1: warning: constant in conditional context [161] */
while (0) {
- /* expect+1: warning: statement not reached [193] */
+ /* expect+1: warning: 'continue' statement not reached [193] */
continue;
}
}
Index: src/tests/usr.bin/xlint/lint1/msg_193.c
diff -u src/tests/usr.bin/xlint/lint1/msg_193.c:1.21 src/tests/usr.bin/xlint/lint1/msg_193.c:1.22
--- src/tests/usr.bin/xlint/lint1/msg_193.c:1.21 Tue Mar 28 14:44:35 2023
+++ src/tests/usr.bin/xlint/lint1/msg_193.c Wed Nov 13 04:32:49 2024
@@ -1,7 +1,7 @@
-/* $NetBSD: msg_193.c,v 1.21 2023/03/28 14:44:35 rillig Exp $ */
+/* $NetBSD: msg_193.c,v 1.22 2024/11/13 04:32:49 rillig Exp $ */
# 3 "msg_193.c"
-// Test for message: statement not reached [193]
+// Test for message: '%s' statement not reached [193]
/* lint1-extra-flags: -X 351 */
@@ -626,7 +626,7 @@ void
lint_annotation_NOTREACHED(void)
{
if (0) {
- /* expect+1: warning: statement not reached [193] */
+ /* expect+1: warning: 'call' statement not reached [193] */
unreachable();
}
@@ -654,7 +654,7 @@ lint_annotation_NOTREACHED(void)
* marks that branch as not reached, which means that any following
* statement cannot be reached as well.
*/
- /* expect+1: warning: statement not reached [193] */
+ /* expect+1: warning: 'if' statement not reached [193] */
if (1)
/* NOTREACHED */
suppressed();
@@ -703,7 +703,7 @@ test_null_statement(void)
for (int i = 0; i < 10; i++)
;
- /* expect+1: warning: statement not reached [193] */
+ /* expect+1: warning: 'empty' statement not reached [193] */
return 0;;
}
Index: src/tests/usr.bin/xlint/lint1/msg_207.c
diff -u src/tests/usr.bin/xlint/lint1/msg_207.c:1.4 src/tests/usr.bin/xlint/lint1/msg_207.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_207.c:1.4 Fri Apr 19 20:59:18 2024
+++ src/tests/usr.bin/xlint/lint1/msg_207.c Wed Nov 13 04:32:49 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_207.c,v 1.4 2024/04/19 20:59:18 rillig Exp $ */
+/* $NetBSD: msg_207.c,v 1.5 2024/11/13 04:32:49 rillig Exp $ */
# 3 "msg_207.c"
// Test for message: loop not entered at top [207]
@@ -19,7 +19,7 @@ for_loop(void)
// XXX: Why is this different from the snippet above?
for (int i = 0; i < 10; i++)
if (0 == 1)
- /* expect+1: warning: statement not reached [193] */
+ /* expect+1: warning: 'init' statement not reached [193] */
for (int j = 0;
j < 5;
/* expect+1: warning: end-of-loop code not reached [223] */
Index: src/tests/usr.bin/xlint/lint1/msg_217.c
diff -u src/tests/usr.bin/xlint/lint1/msg_217.c:1.14 src/tests/usr.bin/xlint/lint1/msg_217.c:1.15
--- src/tests/usr.bin/xlint/lint1/msg_217.c:1.14 Wed Nov 13 03:43:00 2024
+++ src/tests/usr.bin/xlint/lint1/msg_217.c Wed Nov 13 04:32:49 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_217.c,v 1.14 2024/11/13 03:43:00 rillig Exp $ */
+/* $NetBSD: msg_217.c,v 1.15 2024/11/13 04:32:49 rillig Exp $ */
# 3 "msg_217.c"
// Test for message: function '%s' falls off bottom without returning value [217]
@@ -65,7 +65,7 @@ unreachable_continue_falls_through(void)
{
for (;;) {
if (0)
- /* expect+1: warning: statement not reached [193] */
+ /* expect+1: warning: 'continue' statement not reached [193] */
continue;
break;
}
Index: src/tests/usr.bin/xlint/lint1/msg_249.c
diff -u src/tests/usr.bin/xlint/lint1/msg_249.c:1.15 src/tests/usr.bin/xlint/lint1/msg_249.c:1.16
--- src/tests/usr.bin/xlint/lint1/msg_249.c:1.15 Sun Jan 28 08:17:27 2024
+++ src/tests/usr.bin/xlint/lint1/msg_249.c Wed Nov 13 04:32:49 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_249.c,v 1.15 2024/01/28 08:17:27 rillig Exp $ */
+/* $NetBSD: msg_249.c,v 1.16 2024/11/13 04:32:49 rillig Exp $ */
# 3 "msg_249.c"
// Test for message: syntax error '%s' [249]
@@ -31,7 +31,7 @@ void
function(void)
{
if (0)
- /* expect+1: warning: statement not reached [193] */
+ /* expect+1: warning: 'empty' statement not reached [193] */
;
/* expect+1: error: syntax error ')' [249] */
);
Index: src/tests/usr.bin/xlint/lint1/msg_333.c
diff -u src/tests/usr.bin/xlint/lint1/msg_333.c:1.7 src/tests/usr.bin/xlint/lint1/msg_333.c:1.8
--- src/tests/usr.bin/xlint/lint1/msg_333.c:1.7 Fri Jul 7 19:45:22 2023
+++ src/tests/usr.bin/xlint/lint1/msg_333.c Wed Nov 13 04:32:49 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_333.c,v 1.7 2023/07/07 19:45:22 rillig Exp $ */
+/* $NetBSD: msg_333.c,v 1.8 2024/11/13 04:32:49 rillig Exp $ */
# 3 "msg_333.c"
// Test for message: controlling expression must be bool, not '%s' [333]
@@ -41,13 +41,13 @@ example(bool b, int i, const char *p)
return "pointer";
if (__lint_false) {
- /* expect+1: warning: statement not reached [193] */
+ /* expect+1: warning: 'return' statement not reached [193] */
return "bool constant";
}
/* expect+1: error: controlling expression must be bool, not 'int' [333] */
if (0) {
- /* expect+1: warning: statement not reached [193] */
+ /* expect+1: warning: 'return' statement not reached [193] */
return "integer constant";
}
Index: src/tests/usr.bin/xlint/lint1/msg_379.c
diff -u src/tests/usr.bin/xlint/lint1/msg_379.c:1.1 src/tests/usr.bin/xlint/lint1/msg_379.c:1.2
--- src/tests/usr.bin/xlint/lint1/msg_379.c:1.1 Sat May 11 15:53:38 2024
+++ src/tests/usr.bin/xlint/lint1/msg_379.c Wed Nov 13 04:32:50 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_379.c,v 1.1 2024/05/11 15:53:38 rillig Exp $ */
+/* $NetBSD: msg_379.c,v 1.2 2024/11/13 04:32:50 rillig Exp $ */
# 3 "msg_379.c"
// Test for message: comparing integer '%s' to floating point constant %Lg [379]
@@ -18,7 +18,7 @@ int
comparisons(int x)
{
if (3 > 123.0)
- /* expect+1: warning: statement not reached [193] */
+ /* expect+1: warning: 'return' statement not reached [193] */
return 0;
/* expect+1: warning: comparing integer 'int' to floating point constant 123 [379] */
if (x > 123.0)
Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.514 src/usr.bin/xlint/lint1/cgram.y:1.515
--- src/usr.bin/xlint/lint1/cgram.y:1.514 Wed Nov 13 03:43:00 2024
+++ src/usr.bin/xlint/lint1/cgram.y Wed Nov 13 04:32:49 2024
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.514 2024/11/13 03:43:00 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.515 2024/11/13 04:32:49 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.514 2024/11/13 03:43:00 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.515 2024/11/13 04:32:49 rillig Exp $");
#endif
#include <limits.h>
@@ -712,7 +712,8 @@ gcc_statement_expr_item:
/* XXX: do that only on the last name */
if ($1->tn_op == NAME)
$1->u.sym->s_used = true;
- expr($1, true, false, false, false);
+ expr($1, true, false, false, false,
+ "statement expression");
suppress_fallthrough = false;
$$ = $1;
}
@@ -2137,25 +2138,39 @@ block_item:
/* C99 6.8.3, C23 6.8.4 */
expression_statement:
expression T_SEMI {
- expr($1, false, false, false, false);
+ /*
+ * Even though a "call statement" is not a formally defined
+ * term in the C standards, it occurs so often that it's
+ * helpful to have a distinguishable term for it.
+ */
+ expr($1, false, false, false, false,
+ $1 != NULL && $1->tn_op == CALL ? "call" : "expression");
suppress_fallthrough = false;
if ($1 != NULL && $1->tn_op == CALL
&& $1->u.call->func->tn_type->t_subt->t_noreturn)
stmt_call_noreturn();
}
| T_SEMI {
- check_statement_reachable();
+ check_statement_reachable("empty");
suppress_fallthrough = false;
}
| attribute_specifier_sequence expression T_SEMI {
debug_attribute_list(&$1);
- expr($2, false, false, false, false);
+ /*
+ * Even though a "call statement" is not a formally defined
+ * term in the C standards, it occurs so often that it's
+ * helpful to have a distinguishable term for it.
+ */
+ expr($2, false, false, false, false,
+ $2 != NULL && $2->tn_op == CALL ? "call" : "expression");
suppress_fallthrough = false;
}
| attribute_specifier_sequence T_SEMI {
+ bool is_fallthrough = attributes_contain(&$1, "fallthrough");
debug_attribute_list(&$1);
- check_statement_reachable();
- suppress_fallthrough = attributes_contain(&$1, "fallthrough");
+ check_statement_reachable(
+ is_fallthrough ? "fallthrough" : "empty");
+ suppress_fallthrough = is_fallthrough;
}
;
Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.252 src/usr.bin/xlint/lint1/err.c:1.253
--- src/usr.bin/xlint/lint1/err.c:1.252 Thu Oct 31 10:32:08 2024
+++ src/usr.bin/xlint/lint1/err.c Wed Nov 13 04:32:49 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: err.c,v 1.252 2024/10/31 10:32:08 rillig Exp $ */
+/* $NetBSD: err.c,v 1.253 2024/11/13 04:32:49 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: err.c,v 1.252 2024/10/31 10:32:08 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.253 2024/11/13 04:32:49 rillig Exp $");
#endif
#include <limits.h>
@@ -248,7 +248,7 @@ static const char *const msgs[] = {
"empty array declaration for '%s'", // 190
"'%s' set but not used in function '%s'", // 191
"'%s' unused in function '%s'", // 192
- "statement not reached", // 193
+ "'%s' statement not reached", // 193
"label '%s' redefined", // 194
"case not in switch", // 195
"case label affected by conversion", // 196
Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.234 src/usr.bin/xlint/lint1/externs1.h:1.235
--- src/usr.bin/xlint/lint1/externs1.h:1.234 Wed Nov 13 03:43:00 2024
+++ src/usr.bin/xlint/lint1/externs1.h Wed Nov 13 04:32:49 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.234 2024/11/13 03:43:00 rillig Exp $ */
+/* $NetBSD: externs1.h,v 1.235 2024/11/13 04:32:49 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -301,7 +301,7 @@ tnode_t *cast(tnode_t *, bool, type_t *)
void add_function_argument(function_call *, tnode_t *);
tnode_t *build_function_call(tnode_t *, bool, function_call *);
val_t *integer_constant(tnode_t *, bool);
-void expr(tnode_t *, bool, bool, bool, bool);
+void expr(tnode_t *, bool, bool, bool, bool, const char *);
void check_expr_misc(const tnode_t *, bool, bool, bool, bool, bool, bool);
bool constant_addr(const tnode_t *, const sym_t **, ptrdiff_t *);
buffer *cat_strings(buffer *, buffer *);
@@ -339,7 +339,7 @@ extern bool suppress_longlong;
void begin_control_statement(control_statement_kind);
void end_control_statement(control_statement_kind);
-void check_statement_reachable(void);
+void check_statement_reachable(const char *);
void begin_function(sym_t *);
void end_function(void);
void named_label(sym_t *);
Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.188 src/usr.bin/xlint/lint1/func.c:1.189
--- src/usr.bin/xlint/lint1/func.c:1.188 Wed Nov 13 03:43:00 2024
+++ src/usr.bin/xlint/lint1/func.c Wed Nov 13 04:32:49 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: func.c,v 1.188 2024/11/13 03:43:00 rillig Exp $ */
+/* $NetBSD: func.c,v 1.189 2024/11/13 04:32:49 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: func.c,v 1.188 2024/11/13 03:43:00 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.189 2024/11/13 04:32:49 rillig Exp $");
#endif
#include <stdlib.h>
@@ -181,11 +181,11 @@ set_reached(bool new_reached)
* Prints a warning if a statement cannot be reached.
*/
void
-check_statement_reachable(void)
+check_statement_reachable(const char *stmt_kind)
{
if (!reached && warn_about_unreachable) {
- /* statement not reached */
- warning(193);
+ /* '%s' statement not reached */
+ warning(193, stmt_kind);
warn_about_unreachable = false;
}
}
@@ -408,8 +408,8 @@ check_case_label_bitand(const tnode_t *c
uint64_t mask = (uint64_t)switch_expr->u.ops.right->u.value.u.integer;
if ((case_value & ~mask) != 0)
- /* statement not reached */
- warning(193);
+ /* '%s' statement not reached */
+ warning(193, "case");
}
static void
@@ -579,7 +579,7 @@ stmt_if_expr(tnode_t *tn)
if (tn != NULL)
tn = check_controlling_expression(tn, false);
if (tn != NULL)
- expr(tn, false, true, false, false);
+ expr(tn, false, true, false, false, "if");
begin_control_statement(CS_IF);
if (tn != NULL && tn->tn_op == CON && !tn->tn_system_dependent) {
@@ -648,7 +648,7 @@ stmt_switch_expr(tnode_t *tn)
(void)expr_save_memory();
check_getopt_begin_switch();
- expr(tn, true, false, false, false);
+ expr(tn, true, false, false, false, "switch");
begin_control_statement(CS_SWITCH);
cstmt->c_switch = true;
@@ -730,7 +730,7 @@ stmt_while_expr(tnode_t *tn)
bool body_reached = !is_zero(tn);
check_getopt_begin_while(tn);
- expr(tn, false, true, true, false);
+ expr(tn, false, true, true, false, "while");
set_reached(body_reached);
}
@@ -772,7 +772,7 @@ stmt_do_while_expr(tnode_t *tn)
error(323);
}
- expr(tn, false, true, true, true);
+ expr(tn, false, true, true, true, "do-while");
if (cstmt->c_maybe_endless)
set_reached(false);
@@ -809,12 +809,12 @@ stmt_for_exprs(tnode_t *tn1, tnode_t *tn
cstmt->c_for_expr3_csrc_pos = csrc_pos;
if (tn1 != NULL)
- expr(tn1, false, false, true, false);
+ expr(tn1, false, false, true, false, "for");
if (tn2 != NULL)
tn2 = check_controlling_expression(tn2, false);
if (tn2 != NULL)
- expr(tn2, false, true, true, false);
+ expr(tn2, false, true, true, false, "for");
cstmt->c_maybe_endless = tn2 == NULL || is_nonzero(tn2);
@@ -845,7 +845,7 @@ stmt_for_exprs_stmt(void)
}
if (tn3 != NULL)
- expr(tn3, false, false, true, false);
+ expr(tn3, false, false, true, false, "for continuation");
else
expr_free_all();
@@ -861,7 +861,7 @@ void
stmt_goto(sym_t *lab)
{
mark_as_used(lab, false, false);
- check_statement_reachable();
+ check_statement_reachable("goto");
set_reached(false);
}
@@ -879,7 +879,7 @@ stmt_break(void)
cs->c_break = true;
if (bflag)
- check_statement_reachable();
+ check_statement_reachable("break");
set_reached(false);
}
@@ -899,7 +899,7 @@ stmt_continue(void)
/* TODO: only if reachable, for symmetry with c_break */
cs->c_continue = true;
- check_statement_reachable();
+ check_statement_reachable("continue");
set_reached(false);
}
@@ -945,7 +945,7 @@ check_return_value(bool sys, tnode_t *tn
warning(302, funcsym->s_name);
}
- expr(retn, true, false, true, false);
+ expr(retn, true, false, true, false, "return");
}
void
@@ -986,7 +986,7 @@ stmt_return(bool sys, tnode_t *tn)
if (tn != NULL)
check_return_value(sys, tn);
else
- check_statement_reachable();
+ check_statement_reachable("return");
set_reached(false);
}
Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.270 src/usr.bin/xlint/lint1/init.c:1.271
--- src/usr.bin/xlint/lint1/init.c:1.270 Thu Aug 29 20:35:19 2024
+++ src/usr.bin/xlint/lint1/init.c Wed Nov 13 04:32:49 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.270 2024/08/29 20:35:19 rillig Exp $ */
+/* $NetBSD: init.c,v 1.271 2024/11/13 04:32:49 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: init.c,v 1.270 2024/08/29 20:35:19 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.271 2024/11/13 04:32:49 rillig Exp $");
#endif
#include <stdlib.h>
@@ -263,7 +263,7 @@ check_init_expr(const type_t *ltp, sym_t
return;
memory_pool saved_mem = expr_save_memory();
- expr(rn, true, false, true, false);
+ expr(rn, true, false, true, false, "init");
expr_restore_memory(saved_mem);
tspec_t lt = ln->tn_type->t_tspec;
@@ -833,7 +833,7 @@ initialization_expr_using_op(initializat
ln->tn_type = expr_unqualified_type(ln->tn_type);
tnode_t *tn = build_binary(ln, INIT, false /* XXX */, rn);
- expr(tn, false, false, false, false);
+ expr(tn, false, false, false, false, "init");
return true;
}
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.657 src/usr.bin/xlint/lint1/tree.c:1.658
--- src/usr.bin/xlint/lint1/tree.c:1.657 Thu Oct 31 10:32:08 2024
+++ src/usr.bin/xlint/lint1/tree.c Wed Nov 13 04:32:49 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.657 2024/10/31 10:32:08 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.658 2024/11/13 04:32:49 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.657 2024/10/31 10:32:08 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.658 2024/11/13 04:32:49 rillig Exp $");
#endif
#include <float.h>
@@ -4524,7 +4524,8 @@ is_constcond_false(const tnode_t *tn, ts
* memory which is used for the expression.
*/
void
-expr(tnode_t *tn, bool vctx, bool cond, bool dofreeblk, bool is_do_while)
+expr(tnode_t *tn, bool vctx, bool cond, bool dofreeblk, bool is_do_while,
+ const char *stmt_kind)
{
if (tn == NULL) { /* in case of errors */
@@ -4534,7 +4535,7 @@ expr(tnode_t *tn, bool vctx, bool cond,
/* expr() is also called in global initializations */
if (dcs->d_kind != DLK_EXTERN && !is_do_while)
- check_statement_reachable();
+ check_statement_reachable(stmt_kind);
check_expr_misc(tn, vctx, cond, !cond, false, false, false);
if (tn->tn_op == ASSIGN && !tn->tn_parenthesized) {