Wed Jan 6 09:23:05 2021 UTC ()
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.


(rillig)
diff -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_324.c
diff -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_324.exp

cvs diff -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_324.c (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/msg_324.c 2021/01/05 23:20:53 1.3
+++ src/tests/usr.bin/xlint/lint1/msg_324.c 2021/01/06 09:23:04 1.4
@@ -1,52 +1,52 @@ @@ -1,52 +1,52 @@
1/* $NetBSD: msg_324.c,v 1.3 2021/01/05 23:20:53 rillig Exp $ */ 1/* $NetBSD: msg_324.c,v 1.4 2021/01/06 09:23:04 rillig Exp $ */
2# 3 "msg_324.c" 2# 3 "msg_324.c"
3 3
4// Test for message: suggest cast from '%s' to '%s' on op %s to avoid overflow [324] 4// Test for message: suggest cast from '%s' to '%s' on op %s to avoid overflow [324]
5 5
6/* 6/*
7 * This warning applies to binary operators if the result of the operator 7 * This warning applies to binary operators if the result of the operator
8 * is converted to a type that is bigger than the operands' result type 8 * is converted to a type that is bigger than the operands' result type
9 * after the usual arithmetic promotions. 9 * after the usual arithmetic promotions.
10 * 10 *
11 * In such a case, the operator's result would be truncated to the operator's 11 * In such a case, the operator's result would be truncated to the operator's
12 * result type (invoking undefined behavior for signed integers), and that 12 * result type (invoking undefined behavior for signed integers), and that
13 * truncated value would then be converted. At that point, a few bits may 13 * truncated value would then be converted. At that point, a few bits may
14 * have been lost. 14 * have been lost.
15 */ 15 */
16 16
17/* lint1-flags: -g -S -w -P */ 17/* lint1-flags: -g -S -w -P */
18 18
19void 19void
20example(char c, int i, unsigned u) 20example(char c, int i, unsigned u)
21{ 21{
22 long l; 22 long long ll;
23 unsigned long ul; 23 unsigned long long ull;
24 24
25 l = c + i; 25 ll = c + i;
26 l = i - c; 26 ll = i - c;
27 ul = c * u; 27 ull = c * u;
28 ul = u + c; 28 ull = u + c;
29 ul = i - u; 29 ull = i - u;
30 ul = u * i; 30 ull = u * i;
31 l = i << c; 31 ll = i << c;
32 32
33 /* 33 /*
34 * The operators SHR, DIV and MOD cannot produce an overflow, 34 * The operators SHR, DIV and MOD cannot produce an overflow,
35 * therefore no warning is necessary for them. 35 * therefore no warning is necessary for them.
36 */ 36 */
37 l = i >> c; 37 ll = i >> c;
38 ul = u / c; 38 ull = u / c;
39 ul = u % c; 39 ull = u % c;
40 40
41 /* 41 /*
42 * Assigning the result of an increment or decrement operator to a 42 * Assigning the result of an increment or decrement operator to a
43 * differently-sized type is no unusual that there is no need to warn 43 * differently-sized type is no unusual that there is no need to warn
44 * about it. It's also more unlikely that there is an actual loss 44 * about it. It's also more unlikely that there is an actual loss
45 * since this only happens for a single value of the old type, unlike 45 * since this only happens for a single value of the old type, unlike
46 * "ul = u * u", which has many more possibilities for overflowing. 46 * "ull = u * u", which has many more possibilities for overflowing.
47 */ 47 */
48 ul = u++; 48 ull = u++;
49 ul = ++u; 49 ull = ++u;
50 ul = u--; 50 ull = u--;
51 ul = --u; 51 ull = --u;
52} 52}

cvs diff -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/Attic/msg_324.exp (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/Attic/msg_324.exp 2021/01/05 22:38:51 1.2
+++ src/tests/usr.bin/xlint/lint1/Attic/msg_324.exp 2021/01/06 09:23:04 1.3
@@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
1msg_324.c(25): warning: suggest cast from 'int' to 'long' on op + to avoid overflow [324] 1msg_324.c(25): warning: suggest cast from 'int' to 'long long' on op + to avoid overflow [324]
2msg_324.c(26): warning: suggest cast from 'int' to 'long' on op - to avoid overflow [324] 2msg_324.c(26): warning: suggest cast from 'int' to 'long long' on op - to avoid overflow [324]
3msg_324.c(27): warning: suggest cast from 'unsigned int' to 'unsigned long' on op * to avoid overflow [324] 3msg_324.c(27): warning: suggest cast from 'unsigned int' to 'unsigned long long' on op * to avoid overflow [324]
4msg_324.c(28): warning: suggest cast from 'unsigned int' to 'unsigned long' on op + to avoid overflow [324] 4msg_324.c(28): warning: suggest cast from 'unsigned int' to 'unsigned long long' on op + to avoid overflow [324]
5msg_324.c(29): warning: suggest cast from 'unsigned int' to 'unsigned long' on op - to avoid overflow [324] 5msg_324.c(29): warning: suggest cast from 'unsigned int' to 'unsigned long long' on op - to avoid overflow [324]
6msg_324.c(30): warning: suggest cast from 'unsigned int' to 'unsigned long' on op * to avoid overflow [324] 6msg_324.c(30): warning: suggest cast from 'unsigned int' to 'unsigned long long' on op * to avoid overflow [324]
7msg_324.c(31): warning: suggest cast from 'int' to 'long' on op << to avoid overflow [324] 7msg_324.c(31): warning: suggest cast from 'int' to 'long long' on op << to avoid overflow [324]