Module Name:    src
Committed By:   rillig
Date:           Sun Jan  8 18:37:12 UTC 2023

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

Log Message:
lint: do not report usual arithmetic conversions for constants


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/queries.c
cvs rdiff -u -r1.488 -r1.489 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/queries.c
diff -u src/tests/usr.bin/xlint/lint1/queries.c:1.7 src/tests/usr.bin/xlint/lint1/queries.c:1.8
--- src/tests/usr.bin/xlint/lint1/queries.c:1.7	Sun Jan  8 18:21:00 2023
+++ src/tests/usr.bin/xlint/lint1/queries.c	Sun Jan  8 18:37:12 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: queries.c,v 1.7 2023/01/08 18:21:00 rillig Exp $	*/
+/*	$NetBSD: queries.c,v 1.8 2023/01/08 18:37:12 rillig Exp $	*/
 # 3 "queries.c"
 
 /*
@@ -96,13 +96,22 @@ unsigned long long
 Q4(signed char *ptr, int i, unsigned long long ull)
 {
 
-	/* expect+1: usual arithmetic conversion for '&' from 'int' to 'unsigned int' [Q4] */
+	/*
+	 * For constants, the usual arithmetic conversions are usually not
+	 * interesting, so omit them.
+	 */
 	u32 = u32 & 0xff;
+	u32 &= 0xff;
+
+	/* expect+2: usual arithmetic conversion for '&' from 'int' to 'unsigned int' [Q4] */
+	/* expect+1: implicit conversion changes sign from 'int' to 'unsigned int' [Q3] */
+	u32 = u32 & s32;
 	/*
 	 * XXX: C99 5.6.16.2 says that the usual arithmetic conversions
 	 * happen for compound assignments as well.
 	 */
-	u32 &= 0xff;
+	/* expect+1: implicit conversion changes sign from 'int' to 'unsigned int' [Q3] */
+	u32 &= s32;
 
 	/* expect+3: implicit conversion changes sign from 'unsigned char' to 'int' [Q3] */
 	/* expect+2: usual arithmetic conversion for '&' from 'int' to 'unsigned int' [Q4] */

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.488 src/usr.bin/xlint/lint1/tree.c:1.489
--- src/usr.bin/xlint/lint1/tree.c:1.488	Sun Jan  8 18:29:21 2023
+++ src/usr.bin/xlint/lint1/tree.c	Sun Jan  8 18:37:12 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.488 2023/01/08 18:29:21 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.489 2023/01/08 18:37:12 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.488 2023/01/08 18:29:21 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.489 2023/01/08 18:37:12 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -2223,9 +2223,11 @@ apply_usual_arithmetic_conversions(op_t 
 {
 	type_t *ntp = expr_dup_type(tn->tn_type);
 	ntp->t_tspec = t;
-	/* usual arithmetic conversion for '%s' from '%s' to '%s' */
-	query_message(4, op_name(op),
-	    type_name(tn->tn_type), type_name(ntp));
+	if (tn->tn_op != CON) {
+		/* usual arithmetic conversion for '%s' from '%s' to '%s' */
+		query_message(4, op_name(op),
+		    type_name(tn->tn_type), type_name(ntp));
+	}
 	return convert(op, 0, ntp, tn);
 }
 

Reply via email to