Module Name: src Committed By: rillig Date: Tue Aug 31 18:59:26 UTC 2021
Modified Files: src/distrib/sets/lists/tests: mi src/tests/usr.bin/xlint/lint1: Makefile msg_259.c msg_259.exp Added Files: src/tests/usr.bin/xlint/lint1: msg_259_c90.c msg_259_c90.exp Log Message: tests/lint: add test for prototype conversions in C90 The purpose of warning 259 is to find function calls that differ in the ABI. The warning's original purpose was not to warn about lossy conversions, that's just a side effect. Warning 259 had been implemented before C99 was published, which is more than 20 years ago. In the meantime, almost all code has migrated to using function prototypes. With the default lint flags from NetBSD's <sys.mk>, it would rather make sense to focus on lossy conversions now. To prepare for potentially upcoming differences in lint's C90 and C99 modes, clone the test now as far as possible. The test for C90 mode is smaller than for C99 mode, since 'long long' was not available back then. To generate a diff of this commit: cvs rdiff -u -r1.1120 -r1.1121 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.107 -r1.108 src/tests/usr.bin/xlint/lint1/Makefile cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/xlint/lint1/msg_259.c cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/msg_259.exp cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/msg_259_c90.c \ src/tests/usr.bin/xlint/lint1/msg_259_c90.exp Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1120 src/distrib/sets/lists/tests/mi:1.1121 --- src/distrib/sets/lists/tests/mi:1.1120 Mon Aug 30 17:08:13 2021 +++ src/distrib/sets/lists/tests/mi Tue Aug 31 18:59:26 2021 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1120 2021/08/30 17:08:13 rillig Exp $ +# $NetBSD: mi,v 1.1121 2021/08/31 18:59:26 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -6844,6 +6844,8 @@ ./usr/tests/usr.bin/xlint/lint1/msg_258.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/msg_259.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/msg_259.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/msg_259_c90.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/msg_259_c90.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/msg_259_ilp32.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/msg_259_ilp32.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/msg_260.c tests-usr.bin-tests compattestfile,atf Index: src/tests/usr.bin/xlint/lint1/Makefile diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.107 src/tests/usr.bin/xlint/lint1/Makefile:1.108 --- src/tests/usr.bin/xlint/lint1/Makefile:1.107 Wed Aug 25 22:04:52 2021 +++ src/tests/usr.bin/xlint/lint1/Makefile Tue Aug 31 18:59:26 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.107 2021/08/25 22:04:52 rillig Exp $ +# $NetBSD: Makefile,v 1.108 2021/08/31 18:59:26 rillig Exp $ NOMAN= # defined MAX_MESSAGE= 346 # see lint1/err.c @@ -16,6 +16,8 @@ archsubdir.sh: @echo archsubdir=${ARCHSUBDIR} >${.TARGET} FILESDIR= ${TESTSDIR} +FILES+= msg_259_c90.c +FILES+= msg_259_c90.exp FILES+= c11_generic_expression.c FILES+= c11_generic_expression.exp FILES+= c90.c Index: src/tests/usr.bin/xlint/lint1/msg_259.c diff -u src/tests/usr.bin/xlint/lint1/msg_259.c:1.14 src/tests/usr.bin/xlint/lint1/msg_259.c:1.15 --- src/tests/usr.bin/xlint/lint1/msg_259.c:1.14 Tue Aug 31 18:15:56 2021 +++ src/tests/usr.bin/xlint/lint1/msg_259.c Tue Aug 31 18:59:26 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_259.c,v 1.14 2021/08/31 18:15:56 rillig Exp $ */ +/* $NetBSD: msg_259.c,v 1.15 2021/08/31 18:59:26 rillig Exp $ */ # 3 "msg_259.c" // Test for message: argument #%d is converted from '%s' to '%s' due to prototype [259] @@ -65,8 +65,8 @@ signed_to_unsigned(int si, long sl, long /* expect+1: warning: argument #1 is converted from 'long' to 'unsigned long' due to prototype [259] */ unsigned_long(sl); - - unsigned_long(si); + /* expect+1: warning: argument #1 is converted from 'long long' to 'unsigned long' due to prototype [259] */ + unsigned_long(sll); /* * XXX: Why no warning? Even though 'unsigned long long' is 64 bits @@ -93,7 +93,8 @@ unsigned_to_signed(unsigned int ui, unsi signed_long(ui); /* expect+1: warning: argument #1 is converted from 'unsigned long' to 'long' due to prototype [259] */ signed_long(ul); - signed_long(ui); + /* expect+1: warning: argument #1 is converted from 'unsigned long long' to 'long' due to prototype [259] */ + signed_long(ull); signed_long_long(ui); /* expect+1: warning: argument #1 is converted from 'unsigned long' to 'long long' due to prototype [259] */ signed_long_long(ul); @@ -111,7 +112,8 @@ signed_to_signed(signed int si, signed l signed_int(sll); signed_long(si); signed_long(sl); - signed_long(si); + /* expect+1: warning: argument #1 is converted from 'long long' to 'long' due to prototype [259] */ + signed_long(sll); signed_long_long(si); /* expect+1: warning: argument #1 is converted from 'long' to 'long long' due to prototype [259] */ signed_long_long(sl); @@ -128,7 +130,8 @@ unsigned_to_unsigned(unsigned int ui, un unsigned_int(ull); unsigned_long(ui); unsigned_long(ul); - unsigned_long(ui); + /* expect+1: warning: argument #1 is converted from 'unsigned long long' to 'unsigned long' due to prototype [259] */ + unsigned_long(ull); unsigned_long_long(ui); /* expect+1: warning: argument #1 is converted from 'unsigned long' to 'unsigned long long' due to prototype [259] */ unsigned_long_long(ul); @@ -141,7 +144,8 @@ pass_sizeof_as_smaller_type(void) /* * XXX: 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. + * that it would even fit into a 3-bit bit-field, so lint should not + * warn here. */ /* 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.11 src/tests/usr.bin/xlint/lint1/msg_259.exp:1.12 --- src/tests/usr.bin/xlint/lint1/msg_259.exp:1.11 Tue Aug 31 18:15:56 2021 +++ src/tests/usr.bin/xlint/lint1/msg_259.exp Tue Aug 31 18:59:26 2021 @@ -3,18 +3,22 @@ msg_259.c(52): warning: argument #1 is c msg_259.c(55): warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259] msg_259.c(58): warning: argument #1 is converted from 'long long' to 'unsigned int' due to prototype [259] msg_259.c(67): warning: argument #1 is converted from 'long' to 'unsigned long' due to prototype [259] +msg_259.c(69): warning: argument #1 is converted from 'long long' to 'unsigned long' due to prototype [259] msg_259.c(78): warning: argument #1 is converted from 'long' to 'unsigned long long' due to prototype [259] msg_259.c(81): warning: argument #1 is converted from 'long long' to 'unsigned long long' due to prototype [259] msg_259.c(88): warning: argument #1 is converted from 'unsigned int' to 'int' due to prototype [259] msg_259.c(90): warning: argument #1 is converted from 'unsigned long' to 'int' due to prototype [259] msg_259.c(92): warning: argument #1 is converted from 'unsigned long long' to 'int' due to prototype [259] msg_259.c(95): warning: argument #1 is converted from 'unsigned long' to 'long' due to prototype [259] -msg_259.c(99): warning: argument #1 is converted from 'unsigned long' to 'long long' due to prototype [259] -msg_259.c(101): warning: argument #1 is converted from 'unsigned long long' to 'long long' due to prototype [259] -msg_259.c(109): warning: argument #1 is converted from 'long' to 'int' due to prototype [259] -msg_259.c(111): warning: argument #1 is converted from 'long long' to 'int' due to prototype [259] -msg_259.c(117): warning: argument #1 is converted from 'long' to 'long long' due to prototype [259] -msg_259.c(126): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259] -msg_259.c(128): warning: argument #1 is converted from 'unsigned long long' to 'unsigned int' due to prototype [259] -msg_259.c(134): warning: argument #1 is converted from 'unsigned long' to 'unsigned long long' due to prototype [259] -msg_259.c(147): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259] +msg_259.c(97): warning: argument #1 is converted from 'unsigned long long' to 'long' due to prototype [259] +msg_259.c(100): warning: argument #1 is converted from 'unsigned long' to 'long long' due to prototype [259] +msg_259.c(102): warning: argument #1 is converted from 'unsigned long long' to 'long long' due to prototype [259] +msg_259.c(110): warning: argument #1 is converted from 'long' to 'int' due to prototype [259] +msg_259.c(112): warning: argument #1 is converted from 'long long' to 'int' due to prototype [259] +msg_259.c(116): warning: argument #1 is converted from 'long long' to 'long' due to prototype [259] +msg_259.c(119): warning: argument #1 is converted from 'long' to 'long long' due to prototype [259] +msg_259.c(128): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259] +msg_259.c(130): warning: argument #1 is converted from 'unsigned long long' to 'unsigned int' due to prototype [259] +msg_259.c(134): warning: argument #1 is converted from 'unsigned long long' to 'unsigned long' due to prototype [259] +msg_259.c(137): warning: argument #1 is converted from 'unsigned long' to 'unsigned long long' due to prototype [259] +msg_259.c(151): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259] Added files: Index: src/tests/usr.bin/xlint/lint1/msg_259_c90.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/msg_259_c90.c:1.1 --- /dev/null Tue Aug 31 18:59:26 2021 +++ src/tests/usr.bin/xlint/lint1/msg_259_c90.c Tue Aug 31 18:59:26 2021 @@ -0,0 +1,110 @@ +/* $NetBSD: msg_259_c90.c,v 1.1 2021/08/31 18:59:26 rillig Exp $ */ +# 3 "msg_259_c90.c" + +/* Test for message: argument #%d is converted from '%s' to '%s' due to prototype [259] */ + +/* lint1-only-if: lp64 */ +/* XXX: The flag '-s' suppresses all warnings. Why? */ +/* lint1-flags: -h -w */ + +void plain_char(char); +void signed_int(int); +void unsigned_int(unsigned int); +void signed_long(long); +void unsigned_long(unsigned long); +/* No 'long long' since it requires C99. */ + +void +change_in_type_width(char c, int i, long l) +{ + plain_char(c); + signed_int(c); + /* No warning 259 on LP64, only on ILP32 */ + signed_long(c); + + plain_char(i); /* XXX: why no warning? */ + signed_int(i); + /* No warning 259 on LP64, only on ILP32 */ + signed_long(i); + + plain_char(l); /* XXX: why no warning? */ + /* expect+1: from 'long' to 'int' due to prototype [259] */ + signed_int(l); + signed_long(l); +} + +/* + * 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 +signed_to_unsigned(int si, long sl) +{ + /* expect+1: warning: argument #1 is converted from 'int' to 'unsigned int' due to prototype [259] */ + unsigned_int(si); + + /* expect+1: warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259] */ + unsigned_int(sl); + + /* + * XXX: Why no warning? Even though 'unsigned long' is 64 bits + * wide, it cannot represent negative 32-bit values. + */ + unsigned_long(si); + + /* expect+1: warning: argument #1 is converted from 'long' to 'unsigned long' due to prototype [259] */ + unsigned_long(sl); +} + +void +unsigned_to_signed(unsigned int ui, unsigned long ul) +{ + /* expect+1: warning: argument #1 is converted from 'unsigned int' to 'int' due to prototype [259] */ + signed_int(ui); + /* expect+1: warning: argument #1 is converted from 'unsigned long' to 'int' due to prototype [259] */ + signed_int(ul); + signed_long(ui); + /* expect+1: warning: argument #1 is converted from 'unsigned long' to 'long' due to prototype [259] */ + signed_long(ul); +} + +void +signed_to_signed(signed int si, signed long sl) +{ + signed_int(si); + /* expect+1: warning: argument #1 is converted from 'long' to 'int' due to prototype [259] */ + signed_int(sl); + signed_long(si); + signed_long(sl); +} + +void +unsigned_to_unsigned(unsigned int ui, unsigned long ul) +{ + unsigned_int(ui); + /* expect+1: warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259] */ + unsigned_int(ul); + unsigned_long(ui); + unsigned_long(ul); +} + +void +pass_sizeof_as_smaller_type(void) +{ + /* + * XXX: 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. + */ + /* 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 /dev/null src/tests/usr.bin/xlint/lint1/msg_259_c90.exp:1.1 --- /dev/null Tue Aug 31 18:59:26 2021 +++ src/tests/usr.bin/xlint/lint1/msg_259_c90.exp Tue Aug 31 18:59:26 2021 @@ -0,0 +1,10 @@ +msg_259_c90.c(32): warning: argument #1 is converted from 'long' to 'int' due to prototype [259] +msg_259_c90.c(52): warning: argument #1 is converted from 'int' to 'unsigned int' due to prototype [259] +msg_259_c90.c(55): warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259] +msg_259_c90.c(64): warning: argument #1 is converted from 'long' to 'unsigned long' due to prototype [259] +msg_259_c90.c(71): warning: argument #1 is converted from 'unsigned int' to 'int' due to prototype [259] +msg_259_c90.c(73): warning: argument #1 is converted from 'unsigned long' to 'int' due to prototype [259] +msg_259_c90.c(76): warning: argument #1 is converted from 'unsigned long' to 'long' due to prototype [259] +msg_259_c90.c(84): warning: argument #1 is converted from 'long' to 'int' due to prototype [259] +msg_259_c90.c(94): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259] +msg_259_c90.c(109): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259]