Module Name: src Committed By: rillig Date: Mon Feb 27 23:07:53 UTC 2023
Modified Files: src/distrib/sets/lists/tests: mi src/tests/usr.bin/xlint/lint1: platform_ilp32.c src/usr.bin/xlint/lint1: Makefile Added Files: src/tests/usr.bin/xlint/lint1: platform_ilp32_int.c platform_ilp32_long.c Log Message: lint: split platform-specific test for loss of accuracy Lint distinguishes between platforms where size_t is unsigned int and platforms where size_t is unsigned long. To generate a diff of this commit: cvs rdiff -u -r1.1253 -r1.1254 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/platform_ilp32.c cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c \ src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c cvs rdiff -u -r1.93 -r1.94 src/usr.bin/xlint/lint1/Makefile 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.1253 src/distrib/sets/lists/tests/mi:1.1254 --- src/distrib/sets/lists/tests/mi:1.1253 Fri Feb 24 12:47:23 2023 +++ src/distrib/sets/lists/tests/mi Mon Feb 27 23:07:53 2023 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1253 2023/02/24 12:47:23 martin Exp $ +# $NetBSD: mi,v 1.1254 2023/02/27 23:07:53 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -7355,6 +7355,8 @@ ./usr/tests/usr.bin/xlint/lint1/parse_type_name.exp tests-obsolete obsolete,atf ./usr/tests/usr.bin/xlint/lint1/platform_ilp32.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/platform_ilp32.exp tests-obsolete obsolete,atf +./usr/tests/usr.bin/xlint/lint1/platform_ilp32_int.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/platform_ilp32_long.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/platform_int.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/platform_int.exp tests-obsolete obsolete,atf ./usr/tests/usr.bin/xlint/lint1/platform_ldbl128.c tests-usr.bin-tests compattestfile,atf Index: src/tests/usr.bin/xlint/lint1/platform_ilp32.c diff -u src/tests/usr.bin/xlint/lint1/platform_ilp32.c:1.3 src/tests/usr.bin/xlint/lint1/platform_ilp32.c:1.4 --- src/tests/usr.bin/xlint/lint1/platform_ilp32.c:1.3 Wed Feb 22 22:12:35 2023 +++ src/tests/usr.bin/xlint/lint1/platform_ilp32.c Mon Feb 27 23:07:53 2023 @@ -1,28 +1,16 @@ -/* $NetBSD: platform_ilp32.c,v 1.3 2023/02/22 22:12:35 rillig Exp $ */ +/* $NetBSD: platform_ilp32.c,v 1.4 2023/02/27 23:07:53 rillig Exp $ */ # 3 "platform_ilp32.c" /* * Test features that only apply to platforms that have 32-bit int, long and * pointer types. + * + * See also: + * platform_ilp32_int.c + * platform_ilp32_long.c */ /* lint1-extra-flags: -c -h -a -p -b -r -z */ /* lint1-only-if: ilp32 */ -int s32; -unsigned int u32; -long sl32; -unsigned long ul32; - -void -convert_between_int_and_long(void) -{ - /* - * No warning about possible loss of accuracy, as the types have the - * same size. - */ - s32 = sl32; - sl32 = s32; - u32 = ul32; - ul32 = u32; -} +typedef int do_not_warn_about_empty_translation_unit; Index: src/usr.bin/xlint/lint1/Makefile diff -u src/usr.bin/xlint/lint1/Makefile:1.93 src/usr.bin/xlint/lint1/Makefile:1.94 --- src/usr.bin/xlint/lint1/Makefile:1.93 Mon Feb 6 20:26:05 2023 +++ src/usr.bin/xlint/lint1/Makefile Mon Feb 27 23:07:53 2023 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.93 2023/02/06 20:26:05 rillig Exp $ +# $NetBSD: Makefile,v 1.94 2023/02/27 23:07:53 rillig Exp $ .include <bsd.own.mk> @@ -122,11 +122,6 @@ add-test: .PHONY '// TODO: Add some code that fails.' \ > "$$test.c"; \ cvs add "$$test.c"; \ - printf '%s\n' \ - '/^FILES+=/i' \ - "FILES+= $$test.c" \ - '.' 'w' 'q' \ - | ed Makefile; \ ${MAKE} sync-mi .include <bsd.prog.mk> Added files: Index: src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.1 --- /dev/null Mon Feb 27 23:07:53 2023 +++ src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c Mon Feb 27 23:07:53 2023 @@ -0,0 +1,29 @@ +/* $NetBSD: platform_ilp32_int.c,v 1.1 2023/02/27 23:07:53 rillig Exp $ */ +# 3 "platform_ilp32_int.c" + +/* + * Test features that only apply to platforms that have 32-bit int, long and + * pointer types and where size_t is unsigned int, not unsigned long. + */ + +/* lint1-extra-flags: -c -h -a -p -b -r -z */ +/* lint1-only-if: ilp32 int */ + +int s32; +unsigned int u32; +long sl32; +unsigned long ul32; + +void +convert_between_int_and_long(void) +{ + /* + * No warning about possible loss of accuracy, as the types have the + * same size, both in target platform mode as well as in portable + * mode. + */ + s32 = sl32; + sl32 = s32; + u32 = ul32; + ul32 = u32; +} Index: src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c:1.1 --- /dev/null Mon Feb 27 23:07:53 2023 +++ src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c Mon Feb 27 23:07:53 2023 @@ -0,0 +1,35 @@ +/* $NetBSD: platform_ilp32_long.c,v 1.1 2023/02/27 23:07:53 rillig Exp $ */ +# 3 "platform_ilp32_long.c" + +/* + * Test features that only apply to platforms that have 32-bit int, long and + * pointer types and where size_t is unsigned long, not unsigned int. + * + * On these platforms, in portable mode (-p), the type 'int' is in some cases + * assumed to be only 24 bits wide, in order to detect conversions from + * 'long' (or more probably 'size_t') to 'int', which can lose accuracy. + */ + +/* lint1-extra-flags: -c -h -a -p -b -r -z */ +/* lint1-only-if: ilp32 long */ + +int s32; +unsigned int u32; +long sl32; +unsigned long ul32; + +void +convert_between_int_and_long(void) +{ + /* + * Even though 'long' and 'int' have the same size on this platform, + * the option '-p' enables additional portability checks that assume + * a 24-bit int and a 32-bit long type, to proactively detect loss of + * accuracy on potential other platforms. + */ + /* expect+1: warning: conversion from 'long' to 'int' may lose accuracy [132] */ + s32 = sl32; + sl32 = s32; + u32 = ul32; + ul32 = u32; +}