Module Name:    src
Committed By:   rillig
Date:           Wed Apr  5 20:13:01 UTC 2023

Modified Files:
        src/tests/usr.bin/xlint/lint1: platform_ldbl128.c platform_ldbl64.c
            platform_ldbl96.c

Log Message:
tests/lint: demonstrate duplicate warning when parsing big floats


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/platform_ldbl128.c \
    src/tests/usr.bin/xlint/lint1/platform_ldbl64.c \
    src/tests/usr.bin/xlint/lint1/platform_ldbl96.c

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/platform_ldbl128.c
diff -u src/tests/usr.bin/xlint/lint1/platform_ldbl128.c:1.3 src/tests/usr.bin/xlint/lint1/platform_ldbl128.c:1.4
--- src/tests/usr.bin/xlint/lint1/platform_ldbl128.c:1.3	Wed Feb 22 22:12:35 2023
+++ src/tests/usr.bin/xlint/lint1/platform_ldbl128.c	Wed Apr  5 20:13:01 2023
@@ -1,13 +1,31 @@
-/*	$NetBSD: platform_ldbl128.c,v 1.3 2023/02/22 22:12:35 rillig Exp $	*/
+/*	$NetBSD: platform_ldbl128.c,v 1.4 2023/04/05 20:13:01 rillig Exp $	*/
 # 3 "platform_ldbl128.c"
 
 /*
  * Test features that only apply to platforms that have 128-bit long double.
  */
 
-/* lint1-extra-flags: -c -h -a -p -b -r -z */
+/* lint1-extra-flags: -c -h -a -p -b -r -z -X 351 */
 /* lint1-only-if: ldbl-128 */
 
 /* CONSTCOND */
 typedef int bits_per_byte[((unsigned char)-1) == 255 ? 1 : -1];
 typedef int bytes_per_long_double[sizeof(long double) == 16 ? 1 : -1];
+
+/*
+ * Platforms with 128-bit 'long double' typically use IEEE 754-2008, which has
+ * 1 bit sign + 15 bit exponent + 112 bit normalized mantissa. This means the
+ * maximum representable value is 1.1111111(bin) * 2^16383, which is about
+ * 1.189e4932. This is in the same range as for 96-bit 'long double', as the
+ * exponent range is the same.
+ */
+/* FIXME: remove the duplicate warning. */
+/* expect+2: warning: floating-point constant out of range [248] */
+/* expect+1: warning: floating-point constant out of range [248] */
+double larger_than_ldbl = 1e4933;
+/* expect+1: warning: floating-point constant out of range [248] */
+long double larger_than_ldbl_l = 1e4933L;
+/* expect+1: warning: floating-point constant out of range [248] */
+double larger_than_dbl = 1e4932;
+/* Fits in 'long double' but not in 'double'. */
+long double larger_than_dbl_l = 1e4932L;
Index: src/tests/usr.bin/xlint/lint1/platform_ldbl64.c
diff -u src/tests/usr.bin/xlint/lint1/platform_ldbl64.c:1.3 src/tests/usr.bin/xlint/lint1/platform_ldbl64.c:1.4
--- src/tests/usr.bin/xlint/lint1/platform_ldbl64.c:1.3	Wed Feb 22 22:12:35 2023
+++ src/tests/usr.bin/xlint/lint1/platform_ldbl64.c	Wed Apr  5 20:13:01 2023
@@ -1,13 +1,22 @@
-/*	$NetBSD: platform_ldbl64.c,v 1.3 2023/02/22 22:12:35 rillig Exp $	*/
+/*	$NetBSD: platform_ldbl64.c,v 1.4 2023/04/05 20:13:01 rillig Exp $	*/
 # 3 "platform_ldbl64.c"
 
 /*
  * Test features that only apply to platforms that have 64-bit long double.
  */
 
-/* lint1-extra-flags: -c -h -a -p -b -r -z */
+/* lint1-extra-flags: -c -h -a -p -b -r -z -X 351 */
 /* lint1-only-if: ldbl-64 */
 
 /* CONSTCOND */
 typedef int bits_per_byte[((unsigned char)-1) == 255 ? 1 : -1];
 typedef int bytes_per_long_double[sizeof(long double) == 8 ? 1 : -1];
+
+/* expect+1: warning: floating-point constant out of range [248] */
+double larger_than_ldbl = 1e310;
+/*
+ * Since 'long double' has the same size as 'double', there is no floating
+ * point constant that fits in 'long double' but not in 'double'.
+ */
+/* expect+1: warning: floating-point constant out of range [248] */
+long double larger_than_ldbl_l = 1e310L;
Index: src/tests/usr.bin/xlint/lint1/platform_ldbl96.c
diff -u src/tests/usr.bin/xlint/lint1/platform_ldbl96.c:1.3 src/tests/usr.bin/xlint/lint1/platform_ldbl96.c:1.4
--- src/tests/usr.bin/xlint/lint1/platform_ldbl96.c:1.3	Wed Feb 22 22:12:35 2023
+++ src/tests/usr.bin/xlint/lint1/platform_ldbl96.c	Wed Apr  5 20:13:01 2023
@@ -1,13 +1,30 @@
-/*	$NetBSD: platform_ldbl96.c,v 1.3 2023/02/22 22:12:35 rillig Exp $	*/
+/*	$NetBSD: platform_ldbl96.c,v 1.4 2023/04/05 20:13:01 rillig Exp $	*/
 # 3 "platform_ldbl96.c"
 
 /*
  * Test features that only apply to platforms that have 96-bit long double.
  */
 
-/* lint1-extra-flags: -c -h -a -p -b -r -z */
+/* lint1-extra-flags: -c -h -a -p -b -r -z -X 351 */
 /* lint1-only-if: ldbl-96 */
 
 /* CONSTCOND */
 typedef int bits_per_byte[((unsigned char)-1) == 255 ? 1 : -1];
 typedef int bytes_per_long_double[sizeof(long double) == 12 ? 1 : -1];
+
+/*
+ * Both i386 and m68k use the same floating point format for 'long double',
+ * which has 1 bit sign + 15 bit exponent + 64 bit unnormalized mantissa.
+ * This means the maximum representable value is 1.1111111(bin) * 2^16383,
+ * which is about 1.189e4932.
+ */
+/* FIXME: Remove the duplicate warning. */
+/* expect+2: warning: floating-point constant out of range [248] */
+/* expect+1: warning: floating-point constant out of range [248] */
+double larger_than_ldbl = 1e4933;
+/* expect+1: warning: floating-point constant out of range [248] */
+long double larger_than_ldbl_l = 1e4933L;
+/* expect+1: warning: floating-point constant out of range [248] */
+double larger_than_dbl = 1e4932;
+/* Fits in 'long double' but not in 'double'. */
+long double larger_than_dbl_l = 1e4932L;

Reply via email to