Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: split platform-specific test for l...



details:   https://anonhg.NetBSD.org/src/rev/311b2239fd29
branches:  trunk
changeset: 373775:311b2239fd29
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Feb 27 23:07:53 2023 +0000

description:
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.

diffstat:

 distrib/sets/lists/tests/mi                     |   4 ++-
 tests/usr.bin/xlint/lint1/platform_ilp32.c      |  24 ++++------------
 tests/usr.bin/xlint/lint1/platform_ilp32_int.c  |  29 ++++++++++++++++++++
 tests/usr.bin/xlint/lint1/platform_ilp32_long.c |  35 +++++++++++++++++++++++++
 usr.bin/xlint/lint1/Makefile                    |   7 +----
 5 files changed, 74 insertions(+), 25 deletions(-)

diffs (149 lines):

diff -r 5ddfb19ed07b -r 311b2239fd29 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Mon Feb 27 22:00:25 2023 +0000
+++ b/distrib/sets/lists/tests/mi       Mon Feb 27 23:07:53 2023 +0000
@@ -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
diff -r 5ddfb19ed07b -r 311b2239fd29 tests/usr.bin/xlint/lint1/platform_ilp32.c
--- a/tests/usr.bin/xlint/lint1/platform_ilp32.c        Mon Feb 27 22:00:25 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/platform_ilp32.c        Mon Feb 27 23:07:53 2023 +0000
@@ -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;
diff -r 5ddfb19ed07b -r 311b2239fd29 tests/usr.bin/xlint/lint1/platform_ilp32_int.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/platform_ilp32_int.c    Mon Feb 27 23:07:53 2023 +0000
@@ -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;
+}
diff -r 5ddfb19ed07b -r 311b2239fd29 tests/usr.bin/xlint/lint1/platform_ilp32_long.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/platform_ilp32_long.c   Mon Feb 27 23:07:53 2023 +0000
@@ -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;
+}
diff -r 5ddfb19ed07b -r 311b2239fd29 usr.bin/xlint/lint1/Makefile
--- a/usr.bin/xlint/lint1/Makefile      Mon Feb 27 22:00:25 2023 +0000
+++ b/usr.bin/xlint/lint1/Makefile      Mon Feb 27 23:07:53 2023 +0000
@@ -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 @@
                '// 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>



Home | Main Index | Thread Index | Old Index