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: fix test for message 324 on ...



details:   https://anonhg.NetBSD.org/src/rev/488767339c50
branches:  trunk
changeset: 949237:488767339c50
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Jan 06 09:23:04 2021 +0000

description:
lint: fix test for message 324 on i386

i386 is an ILP32 platform (arch/i386/targparam.h).  On these platforms,
int and long have the same size, and even with the -p option for
portability checks, INT_RSIZE in inittyp.c is defined to 4, not 3.

Because of this, in check_integer_conversion, psize(nt) was not greater
than psize(ot), and the warning was not issued.

To make the test behave the same on all platforms, changed the long
variables to long long, since long long is 64-bit on all platforms, and
int is 32-bit.

diffstat:

 tests/usr.bin/xlint/lint1/msg_324.c   |  36 +++++++++++++++++-----------------
 tests/usr.bin/xlint/lint1/msg_324.exp |  14 ++++++------
 2 files changed, 25 insertions(+), 25 deletions(-)

diffs (79 lines):

diff -r 4a3c9d320fc8 -r 488767339c50 tests/usr.bin/xlint/lint1/msg_324.c
--- a/tests/usr.bin/xlint/lint1/msg_324.c       Wed Jan 06 09:15:59 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_324.c       Wed Jan 06 09:23:04 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_324.c,v 1.3 2021/01/05 23:20:53 rillig Exp $       */
+/*     $NetBSD: msg_324.c,v 1.4 2021/01/06 09:23:04 rillig Exp $       */
 # 3 "msg_324.c"
 
 // Test for message: suggest cast from '%s' to '%s' on op %s to avoid overflow [324]
@@ -19,34 +19,34 @@
 void
 example(char c, int i, unsigned u)
 {
-       long l;
-       unsigned long ul;
+       long long ll;
+       unsigned long long ull;
 
-       l = c + i;
-       l = i - c;
-       ul = c * u;
-       ul = u + c;
-       ul = i - u;
-       ul = u * i;
-       l = i << c;
+       ll = c + i;
+       ll = i - c;
+       ull = c * u;
+       ull = u + c;
+       ull = i - u;
+       ull = u * i;
+       ll = i << c;
 
        /*
         * The operators SHR, DIV and MOD cannot produce an overflow,
         * therefore no warning is necessary for them.
         */
-       l = i >> c;
-       ul = u / c;
-       ul = u % c;
+       ll = i >> c;
+       ull = u / c;
+       ull = u % c;
 
        /*
         * Assigning the result of an increment or decrement operator to a
         * differently-sized type is no unusual that there is no need to warn
         * about it.  It's also more unlikely that there is an actual loss
         * since this only happens for a single value of the old type, unlike
-        * "ul = u * u", which has many more possibilities for overflowing.
+        * "ull = u * u", which has many more possibilities for overflowing.
         */
-       ul = u++;
-       ul = ++u;
-       ul = u--;
-       ul = --u;
+       ull = u++;
+       ull = ++u;
+       ull = u--;
+       ull = --u;
 }
diff -r 4a3c9d320fc8 -r 488767339c50 tests/usr.bin/xlint/lint1/msg_324.exp
--- a/tests/usr.bin/xlint/lint1/msg_324.exp     Wed Jan 06 09:15:59 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_324.exp     Wed Jan 06 09:23:04 2021 +0000
@@ -1,7 +1,7 @@
-msg_324.c(25): warning: suggest cast from 'int' to 'long' on op + to avoid overflow [324]
-msg_324.c(26): warning: suggest cast from 'int' to 'long' on op - to avoid overflow [324]
-msg_324.c(27): warning: suggest cast from 'unsigned int' to 'unsigned long' on op * to avoid overflow [324]
-msg_324.c(28): warning: suggest cast from 'unsigned int' to 'unsigned long' on op + to avoid overflow [324]
-msg_324.c(29): warning: suggest cast from 'unsigned int' to 'unsigned long' on op - to avoid overflow [324]
-msg_324.c(30): warning: suggest cast from 'unsigned int' to 'unsigned long' on op * to avoid overflow [324]
-msg_324.c(31): warning: suggest cast from 'int' to 'long' on op << to avoid overflow [324]
+msg_324.c(25): warning: suggest cast from 'int' to 'long long' on op + to avoid overflow [324]
+msg_324.c(26): warning: suggest cast from 'int' to 'long long' on op - to avoid overflow [324]
+msg_324.c(27): warning: suggest cast from 'unsigned int' to 'unsigned long long' on op * to avoid overflow [324]
+msg_324.c(28): warning: suggest cast from 'unsigned int' to 'unsigned long long' on op + to avoid overflow [324]
+msg_324.c(29): warning: suggest cast from 'unsigned int' to 'unsigned long long' on op - to avoid overflow [324]
+msg_324.c(30): warning: suggest cast from 'unsigned int' to 'unsigned long long' on op * to avoid overflow [324]
+msg_324.c(31): warning: suggest cast from 'int' to 'long long' on op << to avoid overflow [324]



Home | Main Index | Thread Index | Old Index