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: allow pointer casts from 'char *' ...



details:   https://anonhg.NetBSD.org/src/rev/7a2f0db8e675
branches:  trunk
changeset: 984669:7a2f0db8e675
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Jul 15 21:22:19 2021 +0000

description:
lint: allow pointer casts from 'char *' and 'unsigned char *'

For the sake of traditional code that did not yet migrate to using 'void
*' for arbitrary pointers.

In the standard NetBSD build, this reduces the number of lint warnings
by around 7000, of 57000 total.

diffstat:

 tests/usr.bin/xlint/lint1/msg_135.c   |  23 ++++++++++++++++-------
 tests/usr.bin/xlint/lint1/msg_135.exp |   6 ++----
 tests/usr.bin/xlint/lint1/msg_247.c   |  18 +++++++++++++-----
 tests/usr.bin/xlint/lint1/msg_247.exp |   2 --
 usr.bin/xlint/lint1/tree.c            |   7 +++++--
 5 files changed, 36 insertions(+), 20 deletions(-)

diffs (161 lines):

diff -r 4a9317ae6de6 -r 7a2f0db8e675 tests/usr.bin/xlint/lint1/msg_135.c
--- a/tests/usr.bin/xlint/lint1/msg_135.c       Thu Jul 15 21:12:46 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_135.c       Thu Jul 15 21:22:19 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_135.c,v 1.8 2021/07/15 21:12:46 rillig Exp $       */
+/*     $NetBSD: msg_135.c,v 1.9 2021/07/15 21:22:19 rillig Exp $       */
 # 3 "msg_135.c"
 
 // Test for message: converting '%s' to '%s' may cause alignment problem [135]
@@ -8,11 +8,12 @@
 void sink(const void *);
 
 unsigned
-read_uint(const unsigned char **pp)
+read_uint(const unsigned short **pp)
 {
        unsigned val;
 
-       val = *(const unsigned *)(*pp); /* expect: 135 */
+       /* expect+1: warning: converting 'pointer to const unsigned short' to 'pointer to const unsigned int' may cause alignment problem [135] */
+       val = *(const unsigned *)(*pp);
        pp += sizeof(unsigned);
        return val;
 }
@@ -43,24 +44,32 @@
        sink(complete);
 }
 
+/*
+ * Before tree.c 1.316 from 2021-07-15, lint warned about pointer casts from
+ * unsigned char or plain char to another type.  These casts often occur in
+ * traditional code that does not use void pointers, even 30 years after C90
+ * introduced 'void'.
+ */
 void
 unsigned_char_to_unsigned_type(unsigned char *ucp)
 {
        unsigned short *usp;
 
-       /* FIXME */
-       /* expect+1: warning: converting 'pointer to unsigned char' to 'pointer to unsigned short' may cause alignment problem [135] */
        usp = (unsigned short *)ucp;
        sink(usp);
 }
 
+/*
+ * Before tree.c 1.316 from 2021-07-15, lint warned about pointer casts from
+ * unsigned char or plain char to another type.  These casts often occur in
+ * traditional code that does not use void pointers, even 30 years after C90
+ * introduced 'void'.
+ */
 void
 plain_char_to_unsigned_type(char *cp)
 {
        unsigned short *usp;
 
-       /* FIXME */
-       /* expect+1: warning: converting 'pointer to char' to 'pointer to unsigned short' may cause alignment problem [135] */
        usp = (unsigned short *)cp;
        sink(usp);
 }
diff -r 4a9317ae6de6 -r 7a2f0db8e675 tests/usr.bin/xlint/lint1/msg_135.exp
--- a/tests/usr.bin/xlint/lint1/msg_135.exp     Thu Jul 15 21:12:46 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_135.exp     Thu Jul 15 21:22:19 2021 +0000
@@ -1,4 +1,2 @@
-msg_135.c(15): warning: converting 'pointer to const unsigned char' to 'pointer to const unsigned int' may cause alignment problem [135]
-msg_135.c(53): warning: converting 'pointer to unsigned char' to 'pointer to unsigned short' may cause alignment problem [135]
-msg_135.c(64): warning: converting 'pointer to char' to 'pointer to unsigned short' may cause alignment problem [135]
-msg_135.c(20): warning: struct incomplete never defined [233]
+msg_135.c(16): warning: converting 'pointer to const unsigned short' to 'pointer to const unsigned int' may cause alignment problem [135]
+msg_135.c(21): warning: struct incomplete never defined [233]
diff -r 4a9317ae6de6 -r 7a2f0db8e675 tests/usr.bin/xlint/lint1/msg_247.c
--- a/tests/usr.bin/xlint/lint1/msg_247.c       Thu Jul 15 21:12:46 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_247.c       Thu Jul 15 21:22:19 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_247.c,v 1.15 2021/07/15 21:12:46 rillig Exp $      */
+/*     $NetBSD: msg_247.c,v 1.16 2021/07/15 21:22:19 rillig Exp $      */
 # 3 "msg_247.c"
 
 // Test for message: pointer cast from '%s' to '%s' may be troublesome [247]
@@ -157,24 +157,32 @@
 
 void sink(const void *);
 
+/*
+ * Before tree.c 1.316 from 2021-07-15, lint warned about pointer casts from
+ * unsigned char or plain char to another type.  These casts often occur in
+ * traditional code that does not use void pointers, even 30 years after C90
+ * introduced 'void'.
+ */
 void
 unsigned_char_to_unsigned_type(unsigned char *ucp)
 {
        unsigned short *usp;
 
-       /* FIXME */
-       /* expect+1: warning: pointer cast from 'pointer to unsigned char' to 'pointer to unsigned short' may be troublesome [247] */
        usp = (unsigned short *)ucp;
        sink(usp);
 }
 
+/*
+ * Before tree.c 1.316 from 2021-07-15, lint warned about pointer casts from
+ * unsigned char or plain char to another type.  These casts often occur in
+ * traditional code that does not use void pointers, even 30 years after C90
+ * introduced 'void'.
+ */
 void
 plain_char_to_unsigned_type(char *cp)
 {
        unsigned short *usp;
 
-       /* FIXME */
-       /* expect+1: warning: pointer cast from 'pointer to char' to 'pointer to unsigned short' may be troublesome [247] */
        usp = (unsigned short *)cp;
        sink(usp);
 }
diff -r 4a9317ae6de6 -r 7a2f0db8e675 tests/usr.bin/xlint/lint1/msg_247.exp
--- a/tests/usr.bin/xlint/lint1/msg_247.exp     Thu Jul 15 21:12:46 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_247.exp     Thu Jul 15 21:22:19 2021 +0000
@@ -1,5 +1,3 @@
 msg_247.c(31): warning: pointer cast from 'pointer to struct Other' to 'pointer to struct <unnamed>' may be troublesome [247]
 msg_247.c(70): warning: pointer cast from 'pointer to struct Other' to 'pointer to signed char' may be troublesome [247]
-msg_247.c(167): warning: pointer cast from 'pointer to unsigned char' to 'pointer to unsigned short' may be troublesome [247]
-msg_247.c(178): warning: pointer cast from 'pointer to char' to 'pointer to unsigned short' may be troublesome [247]
 msg_247.c(134): warning: struct lhash_st never defined [233]
diff -r 4a9317ae6de6 -r 7a2f0db8e675 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Thu Jul 15 21:12:46 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Thu Jul 15 21:22:19 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.315 2021/07/15 17:03:50 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.316 2021/07/15 21:22:19 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.315 2021/07/15 17:03:50 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.316 2021/07/15 21:22:19 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -2080,6 +2080,8 @@
 
        if (nst == CHAR || nst == UCHAR)
                return false;   /* for the sake of traditional C code */
+       if (ost == CHAR || ost == UCHAR)
+               return false;   /* for the sake of traditional C code */
 
        return portable_size_in_bits(nst) != portable_size_in_bits(ost);
 }
@@ -2118,6 +2120,7 @@
        }
 
        if (hflag && alignment_in_bits(nstp) > alignment_in_bits(ostp) &&
+           ost != CHAR && ost != UCHAR &&
            !is_incomplete(ostp)) {
                /* converting '%s' to '%s' may cause alignment problem */
                warning(135, type_name(otp), type_name(ntp));



Home | Main Index | Thread Index | Old Index