Module Name: src
Committed By: rillig
Date: Thu Jul 15 21:22:19 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_135.c msg_135.exp msg_247.c
msg_247.exp
src/usr.bin/xlint/lint1: tree.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_135.c
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_135.exp
cvs rdiff -u -r1.15 -r1.16 src/tests/usr.bin/xlint/lint1/msg_247.c
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/msg_247.exp
cvs rdiff -u -r1.315 -r1.316 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_135.c
diff -u src/tests/usr.bin/xlint/lint1/msg_135.c:1.8 src/tests/usr.bin/xlint/lint1/msg_135.c:1.9
--- src/tests/usr.bin/xlint/lint1/msg_135.c:1.8 Thu Jul 15 21:12:46 2021
+++ src/tests/usr.bin/xlint/lint1/msg_135.c Thu Jul 15 21:22:19 2021
@@ -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 @@ pointer_to_structs(struct incomplete *in
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);
}
Index: src/tests/usr.bin/xlint/lint1/msg_135.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_135.exp:1.6 src/tests/usr.bin/xlint/lint1/msg_135.exp:1.7
--- src/tests/usr.bin/xlint/lint1/msg_135.exp:1.6 Thu Jul 15 21:12:46 2021
+++ src/tests/usr.bin/xlint/lint1/msg_135.exp Thu Jul 15 21:22:19 2021
@@ -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]
Index: src/tests/usr.bin/xlint/lint1/msg_247.c
diff -u src/tests/usr.bin/xlint/lint1/msg_247.c:1.15 src/tests/usr.bin/xlint/lint1/msg_247.c:1.16
--- src/tests/usr.bin/xlint/lint1/msg_247.c:1.15 Thu Jul 15 21:12:46 2021
+++ src/tests/usr.bin/xlint/lint1/msg_247.c Thu Jul 15 21:22:19 2021
@@ -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 @@ lh_OPENSSL_STRING_new(void)
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);
}
Index: src/tests/usr.bin/xlint/lint1/msg_247.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_247.exp:1.11 src/tests/usr.bin/xlint/lint1/msg_247.exp:1.12
--- src/tests/usr.bin/xlint/lint1/msg_247.exp:1.11 Thu Jul 15 21:12:46 2021
+++ src/tests/usr.bin/xlint/lint1/msg_247.exp Thu Jul 15 21:22:19 2021
@@ -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]
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.315 src/usr.bin/xlint/lint1/tree.c:1.316
--- src/usr.bin/xlint/lint1/tree.c:1.315 Thu Jul 15 17:03:50 2021
+++ src/usr.bin/xlint/lint1/tree.c Thu Jul 15 21:22:19 2021
@@ -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 @@ should_warn_about_pointer_cast(const typ
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 @@ check_pointer_conversion(tnode_t *tn, ty
}
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));