Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: do not report usual arithmetic con...



details:   https://anonhg.NetBSD.org/src/rev/ace3f20c201a
branches:  trunk
changeset: 372975:ace3f20c201a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 08 18:37:12 2023 +0000

description:
lint: do not report usual arithmetic conversions for constants

diffstat:

 tests/usr.bin/xlint/lint1/queries.c |  15 ++++++++++++---
 usr.bin/xlint/lint1/tree.c          |  12 +++++++-----
 2 files changed, 19 insertions(+), 8 deletions(-)

diffs (67 lines):

diff -r 13784f6551f5 -r ace3f20c201a tests/usr.bin/xlint/lint1/queries.c
--- a/tests/usr.bin/xlint/lint1/queries.c       Sun Jan 08 18:29:21 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/queries.c       Sun Jan 08 18:37:12 2023 +0000
@@ -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 @@
 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] */
diff -r 13784f6551f5 -r ace3f20c201a usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Jan 08 18:29:21 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Jan 08 18:37:12 2023 +0000
@@ -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 @@
 {
        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);
 }
 



Home | Main Index | Thread Index | Old Index