Module Name: src Committed By: rillig Date: Wed Jan 6 09:23:05 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: msg_324.c msg_324.exp Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_324.c cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_324.exp 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_324.c diff -u src/tests/usr.bin/xlint/lint1/msg_324.c:1.3 src/tests/usr.bin/xlint/lint1/msg_324.c:1.4 --- src/tests/usr.bin/xlint/lint1/msg_324.c:1.3 Tue Jan 5 23:20:53 2021 +++ src/tests/usr.bin/xlint/lint1/msg_324.c Wed Jan 6 09:23:04 2021 @@ -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; } Index: src/tests/usr.bin/xlint/lint1/msg_324.exp diff -u src/tests/usr.bin/xlint/lint1/msg_324.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_324.exp:1.3 --- src/tests/usr.bin/xlint/lint1/msg_324.exp:1.2 Tue Jan 5 22:38:51 2021 +++ src/tests/usr.bin/xlint/lint1/msg_324.exp Wed Jan 6 09:23:04 2021 @@ -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]