Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/xlint/lint1 lint: align tests for message 259,...



details:   https://anonhg.NetBSD.org/src/rev/55b817fd0f2b
branches:  trunk
changeset: 985642:55b817fd0f2b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Sep 02 17:55:27 2021 +0000

description:
lint: align tests for message 259, clarify its purpose

diffstat:

 tests/usr.bin/xlint/lint1/msg_259.c         |   74 ++++++++++++------
 tests/usr.bin/xlint/lint1/msg_259.exp       |   48 ++++++------
 tests/usr.bin/xlint/lint1/msg_259_c90.c     |  107 +++++++++++++++++++++++++--
 tests/usr.bin/xlint/lint1/msg_259_c90.exp   |   20 ++--
 tests/usr.bin/xlint/lint1/msg_259_ilp32.c   |   28 +++---
 tests/usr.bin/xlint/lint1/msg_259_ilp32.exp |    6 +-
 6 files changed, 198 insertions(+), 85 deletions(-)

diffs (truncated from 410 to 300 lines):

diff -r 88d9ac05e7d8 -r 55b817fd0f2b tests/usr.bin/xlint/lint1/msg_259.c
--- a/tests/usr.bin/xlint/lint1/msg_259.c       Thu Sep 02 17:29:19 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_259.c       Thu Sep 02 17:55:27 2021 +0000
@@ -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 @@
 }
 
 /*
- * 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 @@
 }
 
 /*
- * 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 @@
        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 @@
        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 @@
 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));
diff -r 88d9ac05e7d8 -r 55b817fd0f2b tests/usr.bin/xlint/lint1/msg_259.exp
--- a/tests/usr.bin/xlint/lint1/msg_259.exp     Thu Sep 02 17:29:19 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_259.exp     Thu Sep 02 17:55:27 2021 +0000
@@ -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]
diff -r 88d9ac05e7d8 -r 55b817fd0f2b tests/usr.bin/xlint/lint1/msg_259_c90.c
--- a/tests/usr.bin/xlint/lint1/msg_259_c90.c   Thu Sep 02 17:29:19 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_259_c90.c   Thu Sep 02 17:55:27 2021 +0000
@@ -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 @@
  * 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 @@
        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.
         */



Home | Main Index | Thread Index | Old Index