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 warn about pointer casts to...



details:   https://anonhg.NetBSD.org/src/rev/32931b694441
branches:  trunk
changeset: 368118:32931b694441
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jun 24 21:22:11 2022 +0000

description:
lint: do not warn about pointer casts to array types

If the (recursive) element type of the array is compatible, that's good
enough.  Even after the previous commits, this warning is the one that
occurs most in a standard NetBSD build, and it is generally ignored.
For now, focus on reducing the number of false positives to an
acceptable level.

diffstat:

 tests/usr.bin/xlint/lint1/msg_247.c |  11 +++++++++--
 usr.bin/xlint/lint1/tree.c          |   9 +++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)

diffs (54 lines):

diff -r 0b0c6cf9eab9 -r 32931b694441 tests/usr.bin/xlint/lint1/msg_247.c
--- a/tests/usr.bin/xlint/lint1/msg_247.c       Fri Jun 24 21:02:10 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_247.c       Fri Jun 24 21:22:11 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_247.c,v 1.25 2022/06/24 21:02:10 rillig Exp $      */
+/*     $NetBSD: msg_247.c,v 1.26 2022/06/24 21:22:11 rillig Exp $      */
 # 3 "msg_247.c"
 
 // Test for message: pointer cast from '%s' to '%s' may be troublesome [247]
@@ -322,6 +322,13 @@
                /* expect+1: warning: illegal combination of 'pointer to double' and 'pointer to array[5] of double' [184] */
                return storage_2d;
 
-       /* expect+1: warning: pointer cast from 'pointer to array[5] of double' to 'pointer to double' may be troublesome [247] */
+       /*
+        * C11 6.3.2.1p3 says that an array is converted to a pointer to its
+        * first element.  That paragraph doesn't say 'recursively', that
+        * word is only used two paragraphs above, in 6.3.2.1p1.
+        */
+       if (dim == -2)
+               return storage_2d[0];
+
        return (double *)storage_2d;
 }
diff -r 0b0c6cf9eab9 -r 32931b694441 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Fri Jun 24 21:02:10 2022 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Fri Jun 24 21:22:11 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.462 2022/06/24 20:44:53 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.463 2022/06/24 21:22:11 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.462 2022/06/24 20:44:53 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.463 2022/06/24 21:22:11 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -2512,6 +2512,11 @@
                               const type_t *ostp, tspec_t ost)
 {
 
+       while (nst == ARRAY)
+               nstp = nstp->t_subt, nst = nstp->t_tspec;
+       while (ost == ARRAY)
+               ostp = ostp->t_subt, ost = ostp->t_tspec;
+
        if (nst == STRUCT && ost == STRUCT &&
            (struct_starts_with(nstp, ostp) ||
             struct_starts_with(ostp, nstp)))



Home | Main Index | Thread Index | Old Index