Module Name:    src
Committed By:   rillig
Date:           Sun Jan 29 17:13:10 UTC 2023

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

Log Message:
lint: don't warn about negative '>>' when the actual value is positive


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/xlint/lint1/msg_117.c
cvs rdiff -u -r1.501 -r1.502 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_117.c
diff -u src/tests/usr.bin/xlint/lint1/msg_117.c:1.12 src/tests/usr.bin/xlint/lint1/msg_117.c:1.13
--- src/tests/usr.bin/xlint/lint1/msg_117.c:1.12	Sun Jan 29 17:02:09 2023
+++ src/tests/usr.bin/xlint/lint1/msg_117.c	Sun Jan 29 17:13:10 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_117.c,v 1.12 2023/01/29 17:02:09 rillig Exp $	*/
+/*	$NetBSD: msg_117.c,v 1.13 2023/01/29 17:13:10 rillig Exp $	*/
 # 3 "msg_117.c"
 
 // Test for message: bitwise '%s' on signed value possibly nonportable [117]
@@ -139,9 +139,10 @@ shr_signed_ignoring_high_bits(int x)
 	if (((x >> 31) & 2) != 0)
 		return;
 
-	/* The result of '&' is guaranteed to be positive. */
-	/* XXX: Don't warn here. */
-	/* expect+1: warning: bitwise '>>' on signed value possibly nonportable [117] */
+	/*
+	 * The result of '&' is guaranteed to be positive, so don't warn.
+	 * Code like this typically occurs in hexdump functions.
+	 */
 	if ((x & 0xf0) >> 4 != 0)
 		return;
 }

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.501 src/usr.bin/xlint/lint1/tree.c:1.502
--- src/usr.bin/xlint/lint1/tree.c:1.501	Sun Jan 29 13:57:35 2023
+++ src/usr.bin/xlint/lint1/tree.c	Sun Jan 29 17:13:10 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.501 2023/01/29 13:57:35 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.502 2023/01/29 17:13:10 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.501 2023/01/29 13:57:35 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.502 2023/01/29 17:13:10 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1161,6 +1161,10 @@ typeok_shr(const mod_t *mp,
 
 	/* operands have integer types (checked in typeok) */
 	if (pflag && !is_uinteger(olt)) {
+		integer_constraints lc = ic_expr(ln);
+		if (!ic_maybe_signed(ln->tn_type, &lc))
+			return;
+
 		/*
 		 * The left operand is signed. This means that
 		 * the operation is (possibly) nonportable.

Reply via email to