Module Name:    src
Committed By:   rillig
Date:           Tue Sep 12 22:01:05 UTC 2023

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_192.c
        src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: mark unreachable function call arguments as used as well

Previously, in a '?:' expression with a constant condition, the branch
that is not taken was skipped but any identifiers in there were intended
to be marked as used.  In function call expressions, this only worked
for the last argument, as the PUSH operator is not a binary operator
(see ops.def).  Cover this case as well.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_192.c
cvs rdiff -u -r1.579 -r1.580 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/msg_192.c
diff -u src/tests/usr.bin/xlint/lint1/msg_192.c:1.8 src/tests/usr.bin/xlint/lint1/msg_192.c:1.9
--- src/tests/usr.bin/xlint/lint1/msg_192.c:1.8	Tue Sep 12 07:23:27 2023
+++ src/tests/usr.bin/xlint/lint1/msg_192.c	Tue Sep 12 22:01:05 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_192.c,v 1.8 2023/09/12 07:23:27 rillig Exp $	*/
+/*	$NetBSD: msg_192.c,v 1.9 2023/09/12 22:01:05 rillig Exp $	*/
 # 3 "msg_192.c"
 
 // Test for message: '%s' unused in function '%s' [192]
@@ -14,7 +14,7 @@ example(int param)
 }
 
 
-void assertion_failed(const char *);
+void assertion_failed(const char *, int, const char *, const char *);
 
 /*
  * The symbol '__func__' only occurs in an unreachable branch.  It is
@@ -25,7 +25,7 @@ assert_true(void)
 {
 	sizeof(char) == 1
 	    ? (void)0
-	    : assertion_failed(__func__);
+	    : assertion_failed("file", 26, __func__, "sizeof(char) == 1");
 }
 
 void
@@ -33,7 +33,7 @@ assert_false(void)
 {
 	sizeof(char) == 0
 	    ? (void)0
-	    : assertion_failed(__func__);
+	    : assertion_failed("file", 34, __func__, "sizeof(char) == 0");
 }
 
 void
@@ -41,5 +41,5 @@ assert_unknown(_Bool cond)
 {
 	cond
 	    ? (void)0
-	    : assertion_failed(__func__);
+	    : assertion_failed("file", 42, __func__, "cond");
 }

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.579 src/usr.bin/xlint/lint1/tree.c:1.580
--- src/usr.bin/xlint/lint1/tree.c:1.579	Tue Sep 12 07:23:27 2023
+++ src/usr.bin/xlint/lint1/tree.c	Tue Sep 12 22:01:05 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.579 2023/09/12 07:23:27 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.580 2023/09/12 22:01:05 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.579 2023/09/12 07:23:27 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.580 2023/09/12 22:01:05 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1649,7 +1649,7 @@ use(const tnode_t *tn)
 		break;
 	default:
 		use(tn->tn_left);
-		if (is_binary(tn))
+		if (is_binary(tn) || tn->tn_op == PUSH)
 			use(tn->tn_right);
 	}
 }

Reply via email to