Module Name: src
Committed By: rillig
Date: Sun Sep 26 14:52:37 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: platform_int.c platform_int.exp
platform_long.c platform_long.exp
src/usr.bin/xlint/lint1: tree.c
Log Message:
tests/lint: explain difference between i386 and sparc for 259
Seen in usr.bin/make/cond.c 1.278 from 2021-09-21, line 800, the call to
is_token, where unsigned char gets converted to unsigned int or unsigned
long, depending on the platform.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/platform_int.c \
src/tests/usr.bin/xlint/lint1/platform_long.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/platform_int.exp \
src/tests/usr.bin/xlint/lint1/platform_long.exp
cvs rdiff -u -r1.382 -r1.383 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/platform_int.c
diff -u src/tests/usr.bin/xlint/lint1/platform_int.c:1.2 src/tests/usr.bin/xlint/lint1/platform_int.c:1.3
--- src/tests/usr.bin/xlint/lint1/platform_int.c:1.2 Sun Sep 26 14:28:22 2021
+++ src/tests/usr.bin/xlint/lint1/platform_int.c Sun Sep 26 14:52:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: platform_int.c,v 1.2 2021/09/26 14:28:22 rillig Exp $ */
+/* $NetBSD: platform_int.c,v 1.3 2021/09/26 14:52:37 rillig Exp $ */
# 3 "platform_int.c"
/*
@@ -11,9 +11,16 @@
void to_size(typeof(sizeof(int)));
+/* See should_warn_about_prototype_conversion. */
void
convert_unsigned_char_to_size(unsigned char uc)
{
+ /*
+ * In this function call, uc is first promoted to INT. It is then
+ * converted to size_t, which is UINT. The portable bit size of INT
+ * and UINT is the same, 32, but the signedness changes, therefore
+ * the warning.
+ */
/* expect+1: warning: argument #1 is converted from 'unsigned char' to 'unsigned int' due to prototype [259] */
to_size(uc);
}
Index: src/tests/usr.bin/xlint/lint1/platform_long.c
diff -u src/tests/usr.bin/xlint/lint1/platform_long.c:1.2 src/tests/usr.bin/xlint/lint1/platform_long.c:1.3
--- src/tests/usr.bin/xlint/lint1/platform_long.c:1.2 Sun Sep 26 14:28:22 2021
+++ src/tests/usr.bin/xlint/lint1/platform_long.c Sun Sep 26 14:52:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: platform_long.c,v 1.2 2021/09/26 14:28:22 rillig Exp $ */
+/* $NetBSD: platform_long.c,v 1.3 2021/09/26 14:52:37 rillig Exp $ */
# 3 "platform_long.c"
/*
@@ -11,10 +11,22 @@
void to_size(typeof(sizeof(int)));
+/* See should_warn_about_prototype_conversion. */
void
convert_unsigned_char_to_size(unsigned char uc)
{
- /* no warning, unlike in platform_int */
+ /*
+ * In this function call, uc is first promoted to INT. It is then
+ * converted to size_t, which is ULONG. The portable bit size of INT
+ * is 24 (see INT_RSIZE in inittyp.c), which is less than the 32 of
+ * ULONG. Since the portable bit size increases from 24 to 32, there
+ * is no warning.
+ *
+ * XXX: Investigate whether this rule makes sense. Warning 259 is
+ * about prototype mismatch, not about lossy integer conversions,
+ * and there is a clear mismatch here between INT and LONG,
+ * therefore a warning makes sense.
+ */
to_size(uc);
}
Index: src/tests/usr.bin/xlint/lint1/platform_int.exp
diff -u src/tests/usr.bin/xlint/lint1/platform_int.exp:1.1 src/tests/usr.bin/xlint/lint1/platform_int.exp:1.2
--- src/tests/usr.bin/xlint/lint1/platform_int.exp:1.1 Sun Sep 26 03:17:59 2021
+++ src/tests/usr.bin/xlint/lint1/platform_int.exp Sun Sep 26 14:52:37 2021
@@ -1 +1 @@
-platform_int.c(18): warning: argument #1 is converted from 'unsigned char' to 'unsigned int' due to prototype [259]
+platform_int.c(25): warning: argument #1 is converted from 'unsigned char' to 'unsigned int' due to prototype [259]
Index: src/tests/usr.bin/xlint/lint1/platform_long.exp
diff -u src/tests/usr.bin/xlint/lint1/platform_long.exp:1.1 src/tests/usr.bin/xlint/lint1/platform_long.exp:1.2
--- src/tests/usr.bin/xlint/lint1/platform_long.exp:1.1 Sun Sep 26 03:17:59 2021
+++ src/tests/usr.bin/xlint/lint1/platform_long.exp Sun Sep 26 14:52:37 2021
@@ -1 +1 @@
-platform_long.c(22): warning: static variable unused_variable unused [226]
+platform_long.c(34): warning: static variable unused_variable unused [226]
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.382 src/usr.bin/xlint/lint1/tree.c:1.383
--- src/usr.bin/xlint/lint1/tree.c:1.382 Sat Sep 18 10:46:17 2021
+++ src/usr.bin/xlint/lint1/tree.c Sun Sep 26 14:52:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.382 2021/09/18 10:46:17 jmcneill Exp $ */
+/* $NetBSD: tree.c,v 1.383 2021/09/26 14:52:37 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.382 2021/09/18 10:46:17 jmcneill Exp $");
+__RCSID("$NetBSD: tree.c,v 1.383 2021/09/26 14:52:37 rillig Exp $");
#endif
#include <float.h>
@@ -2035,6 +2035,10 @@ should_warn_about_prototype_conversion(t
/* representation and/or width change */
if (!is_integer(ot))
return true;
+ /*
+ * XXX: Investigate whether this rule makes sense; see
+ * tests/usr.bin/xlint/lint1/platform_long.c.
+ */
return portable_size_in_bits(ot) > portable_size_in_bits(INT);
}