Wed Apr 5 20:17:30 2023 UTC ()
lint: fix duplicate warning when parsing big float constants


(rillig)
diff -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/platform_ldbl128.c
diff -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/platform_ldbl96.c
diff -r1.155 -r1.156 src/usr.bin/xlint/lint1/lex.c

cvs diff -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/platform_ldbl128.c (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/platform_ldbl128.c 2023/04/05 20:13:01 1.4
+++ src/tests/usr.bin/xlint/lint1/platform_ldbl128.c 2023/04/05 20:17:30 1.5
@@ -1,31 +1,29 @@ @@ -1,31 +1,29 @@
1/* $NetBSD: platform_ldbl128.c,v 1.4 2023/04/05 20:13:01 rillig Exp $ */ 1/* $NetBSD: platform_ldbl128.c,v 1.5 2023/04/05 20:17:30 rillig Exp $ */
2# 3 "platform_ldbl128.c" 2# 3 "platform_ldbl128.c"
3 3
4/* 4/*
5 * Test features that only apply to platforms that have 128-bit long double. 5 * Test features that only apply to platforms that have 128-bit long double.
6 */ 6 */
7 7
8/* lint1-extra-flags: -c -h -a -p -b -r -z -X 351 */ 8/* lint1-extra-flags: -c -h -a -p -b -r -z -X 351 */
9/* lint1-only-if: ldbl-128 */ 9/* lint1-only-if: ldbl-128 */
10 10
11/* CONSTCOND */ 11/* CONSTCOND */
12typedef int bits_per_byte[((unsigned char)-1) == 255 ? 1 : -1]; 12typedef int bits_per_byte[((unsigned char)-1) == 255 ? 1 : -1];
13typedef int bytes_per_long_double[sizeof(long double) == 16 ? 1 : -1]; 13typedef int bytes_per_long_double[sizeof(long double) == 16 ? 1 : -1];
14 14
15/* 15/*
16 * Platforms with 128-bit 'long double' typically use IEEE 754-2008, which has 16 * Platforms with 128-bit 'long double' typically use IEEE 754-2008, which has
17 * 1 bit sign + 15 bit exponent + 112 bit normalized mantissa. This means the 17 * 1 bit sign + 15 bit exponent + 112 bit normalized mantissa. This means the
18 * maximum representable value is 1.1111111(bin) * 2^16383, which is about 18 * maximum representable value is 1.1111111(bin) * 2^16383, which is about
19 * 1.189e4932. This is in the same range as for 96-bit 'long double', as the 19 * 1.189e4932. This is in the same range as for 96-bit 'long double', as the
20 * exponent range is the same. 20 * exponent range is the same.
21 */ 21 */
22/* FIXME: remove the duplicate warning. */ 
23/* expect+2: warning: floating-point constant out of range [248] */ 
24/* expect+1: warning: floating-point constant out of range [248] */ 22/* expect+1: warning: floating-point constant out of range [248] */
25double larger_than_ldbl = 1e4933; 23double larger_than_ldbl = 1e4933;
26/* expect+1: warning: floating-point constant out of range [248] */ 24/* expect+1: warning: floating-point constant out of range [248] */
27long double larger_than_ldbl_l = 1e4933L; 25long double larger_than_ldbl_l = 1e4933L;
28/* expect+1: warning: floating-point constant out of range [248] */ 26/* expect+1: warning: floating-point constant out of range [248] */
29double larger_than_dbl = 1e4932; 27double larger_than_dbl = 1e4932;
30/* Fits in 'long double' but not in 'double'. */ 28/* Fits in 'long double' but not in 'double'. */
31long double larger_than_dbl_l = 1e4932L; 29long double larger_than_dbl_l = 1e4932L;

cvs diff -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/platform_ldbl96.c (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/platform_ldbl96.c 2023/04/05 20:13:01 1.4
+++ src/tests/usr.bin/xlint/lint1/platform_ldbl96.c 2023/04/05 20:17:30 1.5
@@ -1,30 +1,28 @@ @@ -1,30 +1,28 @@
1/* $NetBSD: platform_ldbl96.c,v 1.4 2023/04/05 20:13:01 rillig Exp $ */ 1/* $NetBSD: platform_ldbl96.c,v 1.5 2023/04/05 20:17:30 rillig Exp $ */
2# 3 "platform_ldbl96.c" 2# 3 "platform_ldbl96.c"
3 3
4/* 4/*
5 * Test features that only apply to platforms that have 96-bit long double. 5 * Test features that only apply to platforms that have 96-bit long double.
6 */ 6 */
7 7
8/* lint1-extra-flags: -c -h -a -p -b -r -z -X 351 */ 8/* lint1-extra-flags: -c -h -a -p -b -r -z -X 351 */
9/* lint1-only-if: ldbl-96 */ 9/* lint1-only-if: ldbl-96 */
10 10
11/* CONSTCOND */ 11/* CONSTCOND */
12typedef int bits_per_byte[((unsigned char)-1) == 255 ? 1 : -1]; 12typedef int bits_per_byte[((unsigned char)-1) == 255 ? 1 : -1];
13typedef int bytes_per_long_double[sizeof(long double) == 12 ? 1 : -1]; 13typedef int bytes_per_long_double[sizeof(long double) == 12 ? 1 : -1];
14 14
15/* 15/*
16 * Both i386 and m68k use the same floating point format for 'long double', 16 * Both i386 and m68k use the same floating point format for 'long double',
17 * which has 1 bit sign + 15 bit exponent + 64 bit unnormalized mantissa. 17 * which has 1 bit sign + 15 bit exponent + 64 bit unnormalized mantissa.
18 * This means the maximum representable value is 1.1111111(bin) * 2^16383, 18 * This means the maximum representable value is 1.1111111(bin) * 2^16383,
19 * which is about 1.189e4932. 19 * which is about 1.189e4932.
20 */ 20 */
21/* FIXME: Remove the duplicate warning. */ 
22/* expect+2: warning: floating-point constant out of range [248] */ 
23/* expect+1: warning: floating-point constant out of range [248] */ 21/* expect+1: warning: floating-point constant out of range [248] */
24double larger_than_ldbl = 1e4933; 22double larger_than_ldbl = 1e4933;
25/* expect+1: warning: floating-point constant out of range [248] */ 23/* expect+1: warning: floating-point constant out of range [248] */
26long double larger_than_ldbl_l = 1e4933L; 24long double larger_than_ldbl_l = 1e4933L;
27/* expect+1: warning: floating-point constant out of range [248] */ 25/* expect+1: warning: floating-point constant out of range [248] */
28double larger_than_dbl = 1e4932; 26double larger_than_dbl = 1e4932;
29/* Fits in 'long double' but not in 'double'. */ 27/* Fits in 'long double' but not in 'double'. */
30long double larger_than_dbl_l = 1e4932L; 28long double larger_than_dbl_l = 1e4932L;

cvs diff -r1.155 -r1.156 src/usr.bin/xlint/lint1/lex.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/lex.c 2023/03/31 13:03:05 1.155
+++ src/usr.bin/xlint/lint1/lex.c 2023/04/05 20:17:30 1.156
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lex.c,v 1.155 2023/03/31 13:03:05 rillig Exp $ */ 1/* $NetBSD: lex.c,v 1.156 2023/04/05 20:17:30 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 * Copyright (c) 1994, 1995 Jochen Pohl 5 * Copyright (c) 1994, 1995 Jochen Pohl
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35#if HAVE_NBTOOL_CONFIG_H 35#if HAVE_NBTOOL_CONFIG_H
36#include "nbtool_config.h" 36#include "nbtool_config.h"
37#endif 37#endif
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40#if defined(__RCSID) 40#if defined(__RCSID)
41__RCSID("$NetBSD: lex.c,v 1.155 2023/03/31 13:03:05 rillig Exp $"); 41__RCSID("$NetBSD: lex.c,v 1.156 2023/04/05 20:17:30 rillig Exp $");
42#endif 42#endif
43 43
44#include <ctype.h> 44#include <ctype.h>
45#include <errno.h> 45#include <errno.h>
46#include <float.h> 46#include <float.h>
47#include <limits.h> 47#include <limits.h>
48#include <math.h> 48#include <math.h>
49#include <stdlib.h> 49#include <stdlib.h>
50#include <string.h> 50#include <string.h>
51 51
52#include "lint1.h" 52#include "lint1.h"
53#include "cgram.h" 53#include "cgram.h"
54 54
@@ -639,31 +639,30 @@ lex_floating_constant(const char *yytext @@ -639,31 +639,30 @@ lex_floating_constant(const char *yytext
639 len--; 639 len--;
640 } else 640 } else
641 typ = DOUBLE; 641 typ = DOUBLE;
642 642
643 if (!allow_c90 && typ != DOUBLE) { 643 if (!allow_c90 && typ != DOUBLE) {
644 /* suffixes F and L are illegal in traditional C */ 644 /* suffixes F and L are illegal in traditional C */
645 warning(98); 645 warning(98);
646 } 646 }
647 647
648 errno = 0; 648 errno = 0;
649 char *eptr; 649 char *eptr;
650 long double ld = strtold(cp, &eptr); 650 long double ld = strtold(cp, &eptr);
651 lint_assert(eptr == cp + len); 651 lint_assert(eptr == cp + len);
652 if (errno != 0) 652 if (errno != 0) {
653 /* floating-point constant out of range */ 653 /* floating-point constant out of range */
654 warning(248); 654 warning(248);
655 655 } else if (typ == FLOAT) {
656 if (typ == FLOAT) { 
657 ld = (float)ld; 656 ld = (float)ld;
658 if (isfinite(ld) == 0) { 657 if (isfinite(ld) == 0) {
659 /* floating-point constant out of range */ 658 /* floating-point constant out of range */
660 warning(248); 659 warning(248);
661 ld = ld > 0 ? FLT_MAX : -FLT_MAX; 660 ld = ld > 0 ? FLT_MAX : -FLT_MAX;
662 } 661 }
663 } else if (typ == DOUBLE) { 662 } else if (typ == DOUBLE) {
664 ld = (double)ld; 663 ld = (double)ld;
665 if (isfinite(ld) == 0) { 664 if (isfinite(ld) == 0) {
666 /* floating-point constant out of range */ 665 /* floating-point constant out of range */
667 warning(248); 666 warning(248);
668 ld = ld > 0 ? DBL_MAX : -DBL_MAX; 667 ld = ld > 0 ? DBL_MAX : -DBL_MAX;
669 } 668 }