Module Name: src
Committed By: rillig
Date: Sun Mar 21 15:34:13 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_193.c msg_193.exp
src/usr.bin/xlint/lint1: func.c lint1.h
Log Message:
lint: fix reachability for constant controlling expression in for loop
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_193.c \
src/tests/usr.bin/xlint/lint1/msg_193.exp
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/xlint/lint1/lint1.h
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.5 src/tests/usr.bin/xlint/lint1/msg_193.c:1.6
--- src/tests/usr.bin/xlint/lint1/msg_193.c:1.5 Sun Mar 21 15:24:56 2021
+++ src/tests/usr.bin/xlint/lint1/msg_193.c Sun Mar 21 15:34:13 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_193.c,v 1.5 2021/03/21 15:24:56 rillig Exp $ */
+/* $NetBSD: msg_193.c,v 1.6 2021/03/21 15:34:13 rillig Exp $ */
# 3 "msg_193.c"
// Test for message: statement not reached [193]
@@ -173,7 +173,7 @@ void
test_for_false(void)
{
for (; 0;)
- unreachable(); /* TODO: expect: 193 */
+ unreachable(); /* expect: 193 */
reachable();
}
Index: src/tests/usr.bin/xlint/lint1/msg_193.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_193.exp:1.5 src/tests/usr.bin/xlint/lint1/msg_193.exp:1.6
--- src/tests/usr.bin/xlint/lint1/msg_193.exp:1.5 Sun Mar 21 15:24:56 2021
+++ src/tests/usr.bin/xlint/lint1/msg_193.exp Sun Mar 21 15:34:13 2021
@@ -14,6 +14,7 @@ msg_193.c(143): warning: statement not r
msg_193.c(152): warning: statement not reached [193]
msg_193.c(161): warning: statement not reached [193]
msg_193.c(169): warning: statement not reached [193]
+msg_193.c(176): warning: statement not reached [193]
msg_193.c(186): warning: statement not reached [193]
msg_193.c(197): warning: statement not reached [193]
msg_193.c(199): warning: statement not reached [193]
Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.90 src/usr.bin/xlint/lint1/func.c:1.91
--- src/usr.bin/xlint/lint1/func.c:1.90 Sun Mar 21 15:24:55 2021
+++ src/usr.bin/xlint/lint1/func.c Sun Mar 21 15:34:13 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: func.c,v 1.90 2021/03/21 15:24:55 rillig Exp $ */
+/* $NetBSD: func.c,v 1.91 2021/03/21 15:34:13 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.90 2021/03/21 15:24:55 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.91 2021/03/21 15:34:13 rillig Exp $");
#endif
#include <stdlib.h>
@@ -883,12 +883,11 @@ for1(tnode_t *tn1, tnode_t *tn2, tnode_t
if (tn2 != NULL)
expr(tn2, false, true, true, false);
- cstmt->c_maybe_endless =
- tn2 == NULL || (tn2->tn_op == CON && constant_is_nonzero(tn2));
+ cstmt->c_maybe_endless = tn2 == NULL || is_nonzero(tn2);
/* Checking the reinitialization expression is done in for2() */
- reached = true;
+ reached = !is_zero(tn2);
}
/*
Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.86 src/usr.bin/xlint/lint1/lint1.h:1.87
--- src/usr.bin/xlint/lint1/lint1.h:1.86 Sun Mar 21 14:36:59 2021
+++ src/usr.bin/xlint/lint1/lint1.h Sun Mar 21 15:34:13 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.86 2021/03/21 14:36:59 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.87 2021/03/21 15:34:13 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -483,3 +483,15 @@ constant_is_nonzero(const tnode_t *tn)
lint_assert(tn->tn_type->t_tspec == tn->tn_val->v_tspec);
return is_nonzero_val(tn->tn_val);
}
+
+static inline bool
+is_zero(const tnode_t *tn)
+{
+ return tn != NULL && tn->tn_op == CON && !is_nonzero_val(tn->tn_val);
+}
+
+static inline bool
+is_nonzero(const tnode_t *tn)
+{
+ return tn != NULL && tn->tn_op == CON && is_nonzero_val(tn->tn_val);
+}