Module Name:    src
Committed By:   rillig
Date:           Thu Sep  2 17:55:27 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_259.c msg_259.exp msg_259_c90.c
            msg_259_c90.exp msg_259_ilp32.c msg_259_ilp32.exp

Log Message:
lint: align tests for message 259, clarify its purpose


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/tests/usr.bin/xlint/lint1/msg_259.c
cvs rdiff -u -r1.15 -r1.16 src/tests/usr.bin/xlint/lint1/msg_259.exp
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_259_c90.c \
    src/tests/usr.bin/xlint/lint1/msg_259_c90.exp \
    src/tests/usr.bin/xlint/lint1/msg_259_ilp32.exp
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_259_ilp32.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_259.c
diff -u src/tests/usr.bin/xlint/lint1/msg_259.c:1.18 src/tests/usr.bin/xlint/lint1/msg_259.c:1.19
--- src/tests/usr.bin/xlint/lint1/msg_259.c:1.18	Thu Sep  2 17:29:19 2021
+++ src/tests/usr.bin/xlint/lint1/msg_259.c	Thu Sep  2 17:55:27 2021
@@ -1,11 +1,22 @@
-/*	$NetBSD: msg_259.c,v 1.18 2021/09/02 17:29:19 rillig Exp $	*/
+/*	$NetBSD: msg_259.c,v 1.19 2021/09/02 17:55:27 rillig Exp $	*/
 # 3 "msg_259.c"
 
 // Test for message: argument #%d is converted from '%s' to '%s' due to prototype [259]
 
 /*
- * See also msg_297, but that requires the flags -a -p -P, which are not
- * enabled in the default NetBSD build.
+ * This warning detects function calls that are translated in very different
+ * translation environments, one where prototypes are omitted, and one where
+ * prototypes are active.  It is possible to make such code interoperable,
+ * but that requires that each argument is converted to its proper type by
+ * the caller of the function.
+ *
+ * When lint is run with the '-s' flag, it no longer warns about code with
+ * incompatibilities between traditional C and C90, therefore this test omits
+ * all of the options '-t', '-s', '-S' and '-Ac11'.
+ *
+ * See also msg_297, which is about lossy integer conversions, but that
+ * requires the flags -a -p -P, which are not enabled in the default NetBSD
+ * build.
  */
 
 /* lint1-only-if: lp64 */
@@ -43,13 +54,16 @@ change_in_type_width(char c, int i, long
 }
 
 /*
- * The default argument promotions convert any small integer type to at
- * least 'int', and without function prototypes, it is not possible to
- * declare a function that has a parameter smaller than int, therefore
- * these conversions do not produce any warnings.
- * FIXME: Remove the warnings for 'signed char'.
- * There are lossless conversions though, but these are covered by warning
- * 297 instead.
+ * Converting a signed integer type to its corresponding unsigned integer
+ * type (C99 6.2.5p6) is usually not a problem since the actual values of the
+ * expressions are usually not anywhere near the maximum signed value.  From
+ * a technical standpoint, it is correct to warn here since even small
+ * negative numbers may result in very large positive numbers.
+ *
+ * A common case where it occurs is when the difference of two pointers is
+ * converted to size_t.  The type ptrdiff_t is defined to be signed, but in
+ * many practical cases, the expression is '(end - start)', which makes the
+ * resulting value necessarily positive.
  */
 void
 small_integer_types(char c, signed char sc, unsigned char uc,
@@ -109,16 +123,15 @@ small_integer_types(char c, signed char 
 }
 
 /*
- * Converting a signed integer type to its corresponding unsigned integer
- * type (C99 6.2.5p6) is usually not a problem since the actual values of the
- * expressions are usually not anywhere near the maximum signed value.  From
- * a technical standpoint, it is correct to warn here since even small
- * negative numbers may result in very large positive numbers.
+ * This function tests, among others, the conversion from a signed integer
+ * type to its corresponding unsigned integer type.  Warning 259 is not
+ * about lossy integer conversions but about ABI calling conventions.
  *
- * A common case where it occurs is when the difference of two pointers is
- * converted to size_t.  The type ptrdiff_t is defined to be signed, but in
- * many practical cases, the expression is '(end - start)', which makes the
- * resulting value necessarily positive.
+ * A common case where a conversion from a signed integer type to its
+ * corresponding unsigned integer type occurs is when the difference of two
+ * pointers is converted to size_t.  The type ptrdiff_t is defined to be
+ * signed, but in many practical cases, the expression is '(end - start)',
+ * which makes the resulting value necessarily positive.
  */
 void
 signed_to_unsigned(int si, long sl, long long sll)
@@ -133,8 +146,9 @@ signed_to_unsigned(int si, long sl, long
 	unsigned_int(sll);
 
 	/*
-	 * XXX: Why no warning?  Even though 'unsigned long' is 64 bits
-	 * wide, it cannot represent negative 32-bit values.
+	 * No warning here.  Even though 'unsigned long' is 64 bits wide, it
+	 * cannot represent negative 32-bit values.  This lossy conversion is
+	 * covered by message 297 instead, which requires nonstandard flags.
 	 */
 	unsigned_long(si);
 
@@ -144,8 +158,10 @@ signed_to_unsigned(int si, long sl, long
 	unsigned_long(sll);
 
 	/*
-	 * XXX: Why no warning?  Even though 'unsigned long long' is 64 bits
-	 * wide, it cannot represent negative 32-bit values.
+	 * No warning here.  Even though 'unsigned long long' is 64 bits
+	 * wide, it cannot represent negative 32-bit values.  This lossy
+	 * conversion is covered by message 297 instead, which requires
+	 * nonstandard flags.
 	 */
 	unsigned_long_long(si);
 
@@ -217,10 +233,16 @@ void
 pass_sizeof_as_smaller_type(void)
 {
 	/*
-	 * XXX: Even though the expression has type size_t, it has a constant
+	 * Even though the expression has type size_t, it has a constant
 	 * value that fits effortless into an 'unsigned int', it's so small
-	 * that it would even fit into a 3-bit bit-field, so lint should not
-	 * warn here.
+	 * that it would even fit into a 3-bit bit-field, so lint's warning
+	 * may seem wrong here.
+	 *
+	 * This warning 259 is not about lossy integer conversion though but
+	 * instead covers calling conventions that may differ between integer
+	 * types of different sizes, and from that point of view, the
+	 * constant, even though its value would fit in an unsigned int, is
+	 * still passed as size_t.
 	 */
 	/* expect+1: warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259] */
 	unsigned_int(sizeof(int));

Index: src/tests/usr.bin/xlint/lint1/msg_259.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_259.exp:1.15 src/tests/usr.bin/xlint/lint1/msg_259.exp:1.16
--- src/tests/usr.bin/xlint/lint1/msg_259.exp:1.15	Thu Sep  2 17:29:19 2021
+++ src/tests/usr.bin/xlint/lint1/msg_259.exp	Thu Sep  2 17:55:27 2021
@@ -1,24 +1,24 @@
-msg_259.c(41): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
-msg_259.c(127): warning: argument #1 is converted from 'int' to 'unsigned int' due to prototype [259]
-msg_259.c(130): warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259]
-msg_259.c(133): warning: argument #1 is converted from 'long long' to 'unsigned int' due to prototype [259]
-msg_259.c(142): warning: argument #1 is converted from 'long' to 'unsigned long' due to prototype [259]
-msg_259.c(144): warning: argument #1 is converted from 'long long' to 'unsigned long' due to prototype [259]
-msg_259.c(153): warning: argument #1 is converted from 'long' to 'unsigned long long' due to prototype [259]
-msg_259.c(156): warning: argument #1 is converted from 'long long' to 'unsigned long long' due to prototype [259]
-msg_259.c(163): warning: argument #1 is converted from 'unsigned int' to 'int' due to prototype [259]
-msg_259.c(165): warning: argument #1 is converted from 'unsigned long' to 'int' due to prototype [259]
-msg_259.c(167): warning: argument #1 is converted from 'unsigned long long' to 'int' due to prototype [259]
-msg_259.c(170): warning: argument #1 is converted from 'unsigned long' to 'long' due to prototype [259]
-msg_259.c(172): warning: argument #1 is converted from 'unsigned long long' to 'long' due to prototype [259]
-msg_259.c(175): warning: argument #1 is converted from 'unsigned long' to 'long long' due to prototype [259]
-msg_259.c(177): warning: argument #1 is converted from 'unsigned long long' to 'long long' due to prototype [259]
-msg_259.c(185): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
-msg_259.c(187): warning: argument #1 is converted from 'long long' to 'int' due to prototype [259]
-msg_259.c(191): warning: argument #1 is converted from 'long long' to 'long' due to prototype [259]
-msg_259.c(194): warning: argument #1 is converted from 'long' to 'long long' due to prototype [259]
-msg_259.c(203): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259]
-msg_259.c(205): warning: argument #1 is converted from 'unsigned long long' to 'unsigned int' due to prototype [259]
-msg_259.c(209): warning: argument #1 is converted from 'unsigned long long' to 'unsigned long' due to prototype [259]
-msg_259.c(212): warning: argument #1 is converted from 'unsigned long' to 'unsigned long long' due to prototype [259]
-msg_259.c(226): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259]
+msg_259.c(52): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
+msg_259.c(140): warning: argument #1 is converted from 'int' to 'unsigned int' due to prototype [259]
+msg_259.c(143): warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259]
+msg_259.c(146): warning: argument #1 is converted from 'long long' to 'unsigned int' due to prototype [259]
+msg_259.c(156): warning: argument #1 is converted from 'long' to 'unsigned long' due to prototype [259]
+msg_259.c(158): warning: argument #1 is converted from 'long long' to 'unsigned long' due to prototype [259]
+msg_259.c(169): warning: argument #1 is converted from 'long' to 'unsigned long long' due to prototype [259]
+msg_259.c(172): warning: argument #1 is converted from 'long long' to 'unsigned long long' due to prototype [259]
+msg_259.c(179): warning: argument #1 is converted from 'unsigned int' to 'int' due to prototype [259]
+msg_259.c(181): warning: argument #1 is converted from 'unsigned long' to 'int' due to prototype [259]
+msg_259.c(183): warning: argument #1 is converted from 'unsigned long long' to 'int' due to prototype [259]
+msg_259.c(186): warning: argument #1 is converted from 'unsigned long' to 'long' due to prototype [259]
+msg_259.c(188): warning: argument #1 is converted from 'unsigned long long' to 'long' due to prototype [259]
+msg_259.c(191): warning: argument #1 is converted from 'unsigned long' to 'long long' due to prototype [259]
+msg_259.c(193): warning: argument #1 is converted from 'unsigned long long' to 'long long' due to prototype [259]
+msg_259.c(201): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
+msg_259.c(203): warning: argument #1 is converted from 'long long' to 'int' due to prototype [259]
+msg_259.c(207): warning: argument #1 is converted from 'long long' to 'long' due to prototype [259]
+msg_259.c(210): warning: argument #1 is converted from 'long' to 'long long' due to prototype [259]
+msg_259.c(219): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259]
+msg_259.c(221): warning: argument #1 is converted from 'unsigned long long' to 'unsigned int' due to prototype [259]
+msg_259.c(225): warning: argument #1 is converted from 'unsigned long long' to 'unsigned long' due to prototype [259]
+msg_259.c(228): warning: argument #1 is converted from 'unsigned long' to 'unsigned long long' due to prototype [259]
+msg_259.c(248): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259]

Index: src/tests/usr.bin/xlint/lint1/msg_259_c90.c
diff -u src/tests/usr.bin/xlint/lint1/msg_259_c90.c:1.2 src/tests/usr.bin/xlint/lint1/msg_259_c90.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_259_c90.c:1.2	Tue Aug 31 19:26:23 2021
+++ src/tests/usr.bin/xlint/lint1/msg_259_c90.c	Thu Sep  2 17:55:27 2021
@@ -1,18 +1,32 @@
-/*	$NetBSD: msg_259_c90.c,v 1.2 2021/08/31 19:26:23 rillig Exp $	*/
+/*	$NetBSD: msg_259_c90.c,v 1.3 2021/09/02 17:55:27 rillig Exp $	*/
 # 3 "msg_259_c90.c"
 
 /* Test for message: argument #%d is converted from '%s' to '%s' due to prototype [259] */
 
 /*
- * See also msg_297, but that requires the flags -a -p -P, which are not
- * enabled in the default NetBSD build.
+ * This warning detects function calls that are translated in very different
+ * translation environments, one where prototypes are omitted, and one where
+ * prototypes are active.  It is possible to make such code interoperable,
+ * but that requires that each argument is converted to its proper type by
+ * the caller of the function.
+ *
+ * When lint is run with the '-s' flag, it no longer warns about code with
+ * incompatibilities between traditional C and C90, therefore this test omits
+ * all of the options '-t', '-s', '-S' and '-Ac11'.
+ *
+ * See also msg_297, which is about lossy integer conversions, but that
+ * requires the flags -a -p -P, which are not enabled in the default NetBSD
+ * build.
  */
 
 /* lint1-only-if: lp64 */
-/* XXX: The flag '-s' suppresses all warnings.  Why? */
 /* lint1-flags: -h -w */
 
 void plain_char(char);
+void signed_char(signed char);
+void unsigned_char(unsigned char);
+void signed_short(signed short);
+void unsigned_short(unsigned short);
 void signed_int(int);
 void unsigned_int(unsigned int);
 void signed_long(long);
@@ -51,6 +65,74 @@ change_in_type_width(char c, int i, long
  * resulting value necessarily positive.
  */
 void
+small_integer_types(char c, signed char sc, unsigned char uc,
+		    signed short ss, unsigned short us,
+		    signed int si, unsigned int ui,
+		    signed long sl, unsigned long ul)
+{
+	plain_char(c);
+	plain_char(sc);
+	plain_char(uc);
+	plain_char(ss);
+	plain_char(us);
+	plain_char(si);
+	plain_char(ui);
+	plain_char(sl);
+	plain_char(ul);
+
+	signed_char(c);
+	signed_char(sc);
+	signed_char(uc);
+	signed_char(ss);
+	signed_char(us);
+	signed_char(si);
+	signed_char(ui);
+	signed_char(sl);
+	signed_char(ul);
+
+	unsigned_char(c);
+	unsigned_char(sc);
+	unsigned_char(uc);
+	unsigned_char(ss);
+	unsigned_char(us);
+	unsigned_char(si);
+	unsigned_char(ui);
+	unsigned_char(sl);
+	unsigned_char(ul);
+
+	signed_short(c);
+	signed_short(sc);
+	signed_short(uc);
+	signed_short(ss);
+	signed_short(us);
+	signed_short(si);
+	signed_short(ui);
+	signed_short(sl);
+	signed_short(ul);
+
+	unsigned_short(c);
+	unsigned_short(sc);
+	unsigned_short(uc);
+	unsigned_short(ss);
+	unsigned_short(us);
+	unsigned_short(si);
+	unsigned_short(ui);
+	unsigned_short(sl);
+	unsigned_short(ul);
+}
+
+/*
+ * This function tests, among others, the conversion from a signed integer
+ * type to its corresponding unsigned integer type.  Warning 259 is not
+ * about lossy integer conversions but about ABI calling conventions.
+ *
+ * A common case where a conversion from a signed integer type to its
+ * corresponding unsigned integer type occurs is when the difference of two
+ * pointers is converted to size_t.  The type ptrdiff_t is defined to be
+ * signed, but in many practical cases, the expression is '(end - start)',
+ * which makes the resulting value necessarily positive.
+ */
+void
 signed_to_unsigned(int si, long sl)
 {
 	/* expect+1: warning: argument #1 is converted from 'int' to 'unsigned int' due to prototype [259] */
@@ -60,8 +142,9 @@ signed_to_unsigned(int si, long sl)
 	unsigned_int(sl);
 
 	/*
-	 * XXX: Why no warning?  Even though 'unsigned long' is 64 bits
-	 * wide, it cannot represent negative 32-bit values.
+	 * No warning here.  Even though 'unsigned long' is 64 bits wide, it
+	 * cannot represent negative 32-bit values.  This lossy conversion is
+	 * covered by message 297 instead, which requires nonstandard flags.
 	 */
 	unsigned_long(si);
 
@@ -105,10 +188,16 @@ void
 pass_sizeof_as_smaller_type(void)
 {
 	/*
-	 * XXX: Even though the expression has type size_t, it has a constant
+	 * Even though the expression has type size_t, it has a constant
 	 * value that fits effortless into an 'unsigned int', it's so small
-	 * that it would even fit into a 3-bit bit-field, so lint should not
-	 * warn here.
+	 * that it would even fit into a 3-bit bit-field, so lint's warning
+	 * may seem wrong here.
+	 *
+	 * This warning 259 is not about lossy integer conversion though but
+	 * instead covers calling conventions that may differ between integer
+	 * types of different sizes, and from that point of view, the
+	 * constant, even though its value would fit in an unsigned int, is
+	 * still passed as size_t.
 	 */
 	/* expect+1: warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259] */
 	unsigned_int(sizeof(int));
Index: src/tests/usr.bin/xlint/lint1/msg_259_c90.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_259_c90.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_259_c90.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_259_c90.exp:1.2	Tue Aug 31 19:26:23 2021
+++ src/tests/usr.bin/xlint/lint1/msg_259_c90.exp	Thu Sep  2 17:55:27 2021
@@ -1,10 +1,10 @@
-msg_259_c90.c(37): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
-msg_259_c90.c(57): warning: argument #1 is converted from 'int' to 'unsigned int' due to prototype [259]
-msg_259_c90.c(60): warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259]
-msg_259_c90.c(69): warning: argument #1 is converted from 'long' to 'unsigned long' due to prototype [259]
-msg_259_c90.c(76): warning: argument #1 is converted from 'unsigned int' to 'int' due to prototype [259]
-msg_259_c90.c(78): warning: argument #1 is converted from 'unsigned long' to 'int' due to prototype [259]
-msg_259_c90.c(81): warning: argument #1 is converted from 'unsigned long' to 'long' due to prototype [259]
-msg_259_c90.c(89): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
-msg_259_c90.c(99): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259]
-msg_259_c90.c(114): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259]
+msg_259_c90.c(51): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
+msg_259_c90.c(139): warning: argument #1 is converted from 'int' to 'unsigned int' due to prototype [259]
+msg_259_c90.c(142): warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259]
+msg_259_c90.c(152): warning: argument #1 is converted from 'long' to 'unsigned long' due to prototype [259]
+msg_259_c90.c(159): warning: argument #1 is converted from 'unsigned int' to 'int' due to prototype [259]
+msg_259_c90.c(161): warning: argument #1 is converted from 'unsigned long' to 'int' due to prototype [259]
+msg_259_c90.c(164): warning: argument #1 is converted from 'unsigned long' to 'long' due to prototype [259]
+msg_259_c90.c(172): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
+msg_259_c90.c(182): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259]
+msg_259_c90.c(203): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259]
Index: src/tests/usr.bin/xlint/lint1/msg_259_ilp32.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_259_ilp32.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_259_ilp32.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_259_ilp32.exp:1.2	Tue Aug 31 19:26:23 2021
+++ src/tests/usr.bin/xlint/lint1/msg_259_ilp32.exp	Thu Sep  2 17:55:27 2021
@@ -1,3 +1,3 @@
-msg_259_ilp32.c(24): warning: argument #1 is converted from 'char' to 'long' due to prototype [259]
-msg_259_ilp32.c(29): warning: argument #1 is converted from 'int' to 'long' due to prototype [259]
-msg_259_ilp32.c(33): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
+msg_259_ilp32.c(26): warning: argument #1 is converted from 'char' to 'long' due to prototype [259]
+msg_259_ilp32.c(31): warning: argument #1 is converted from 'int' to 'long' due to prototype [259]
+msg_259_ilp32.c(35): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]

Index: src/tests/usr.bin/xlint/lint1/msg_259_ilp32.c
diff -u src/tests/usr.bin/xlint/lint1/msg_259_ilp32.c:1.4 src/tests/usr.bin/xlint/lint1/msg_259_ilp32.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_259_ilp32.c:1.4	Tue Aug 31 19:26:23 2021
+++ src/tests/usr.bin/xlint/lint1/msg_259_ilp32.c	Thu Sep  2 17:55:27 2021
@@ -1,9 +1,11 @@
-/*	$NetBSD: msg_259_ilp32.c,v 1.4 2021/08/31 19:26:23 rillig Exp $	*/
+/*	$NetBSD: msg_259_ilp32.c,v 1.5 2021/09/02 17:55:27 rillig Exp $	*/
 # 3 "msg_259_ilp32.c"
 
 // Test for message: argument #%d is converted from '%s' to '%s' due to prototype [259]
 
 /*
+ * See also msg_259, which contains more examples for this warning.
+ *
  * See also msg_297, but that requires the flags -a -p -P, which are not
  * enabled in the default NetBSD build.
  */
@@ -11,25 +13,25 @@
 /* lint1-only-if: ilp32 */
 /* lint1-extra-flags: -h */
 
-void farg_char(char);
-void farg_int(int);
-void farg_long(long);
+void plain_char(char);
+void signed_int(int);
+void signed_long(long);
 
 void
 example(char c, int i, long l)
 {
-	farg_char(c);
-	farg_int(c);
+	plain_char(c);
+	signed_int(c);
 	/* expect+1: from 'char' to 'long' due to prototype [259] */
-	farg_long(c);
+	signed_long(c);
 
-	farg_char(i);		/* XXX: why no warning? */
-	farg_int(i);
+	plain_char(i);
+	signed_int(i);
 	/* expect+1: from 'int' to 'long' due to prototype [259] */
-	farg_long(i);
+	signed_long(i);
 
-	farg_char(l);		/* XXX: why no warning? */
+	plain_char(l);
 	/* expect+1: from 'long' to 'int' due to prototype [259] */
-	farg_int(l);
-	farg_long(l);
+	signed_int(l);
+	signed_long(l);
 }

Reply via email to