Wed Apr 12 19:09:48 2023 UTC ()
lint: suppress warnings about LDBL_MAX in cross-build mode

This fixes the cross build for sparc64 on x86_64, in which lint
complained:
	warning: floating-point constant out of range [248]
	warning: floating point overflow on operator '-' [142]
	warning: floating-point constant out of range [248]


(rillig)
diff -r1.511 -r1.512 src/usr.bin/xlint/lint1/tree.c

cvs diff -r1.511 -r1.512 src/usr.bin/xlint/lint1/tree.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/tree.c 2023/04/11 19:40:04 1.511
+++ src/usr.bin/xlint/lint1/tree.c 2023/04/12 19:09:48 1.512
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: tree.c,v 1.511 2023/04/11 19:40:04 rillig Exp $ */ 1/* $NetBSD: tree.c,v 1.512 2023/04/12 19:09:48 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl 4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved. 5 * All Rights Reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#if HAVE_NBTOOL_CONFIG_H 34#if HAVE_NBTOOL_CONFIG_H
35#include "nbtool_config.h" 35#include "nbtool_config.h"
36#endif 36#endif
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39#if defined(__RCSID) 39#if defined(__RCSID)
40__RCSID("$NetBSD: tree.c,v 1.511 2023/04/11 19:40:04 rillig Exp $"); 40__RCSID("$NetBSD: tree.c,v 1.512 2023/04/12 19:09:48 rillig Exp $");
41#endif 41#endif
42 42
43#include <float.h> 43#include <float.h>
44#include <limits.h> 44#include <limits.h>
45#include <math.h> 45#include <math.h>
46#include <signal.h> 46#include <signal.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <string.h> 48#include <string.h>
49 49
50#include "lint1.h" 50#include "lint1.h"
51 51
52 52
53typedef struct integer_constraints { 53typedef struct integer_constraints {
@@ -1497,27 +1497,43 @@ fold_bool(tnode_t *tn) @@ -1497,27 +1497,43 @@ fold_bool(tnode_t *tn)
1497 lint_assert(/*CONSTCOND*/false); 1497 lint_assert(/*CONSTCOND*/false);
1498 } 1498 }
1499 1499
1500 return build_constant(tn->tn_type, v); 1500 return build_constant(tn->tn_type, v);
1501} 1501}
1502 1502
1503static ldbl_t 1503static ldbl_t
1504floating_error_value(tspec_t t, ldbl_t lv) 1504floating_error_value(tspec_t t, ldbl_t lv)
1505{ 1505{
1506 if (t == FLOAT) 1506 if (t == FLOAT)
1507 return lv < 0 ? -FLT_MAX : FLT_MAX; 1507 return lv < 0 ? -FLT_MAX : FLT_MAX;
1508 if (t == DOUBLE) 1508 if (t == DOUBLE)
1509 return lv < 0 ? -DBL_MAX : DBL_MAX; 1509 return lv < 0 ? -DBL_MAX : DBL_MAX;
1510 return lv < 0 ? -LDBL_MAX : LDBL_MAX; 1510 /*
 1511 * When lint is compiled on x86_64 to check for sparc64, it uses the
 1512 * type 'long double' from x86_64, which is the Intel 80-bit format.
 1513 * The constant LDBL_MAX comes from the sparc64 preprocessor though
 1514 * and uses the IEEE-754-binary128 format, with the same exponent
 1515 * range but a wider mantissa.
 1516 *
 1517 * To properly handle this situation, lint would have to implement the
 1518 * floating-point types in a platform-independent way, which is not
 1519 * worth the effort, given how few programs practically use 'long
 1520 * double'.
 1521 *
 1522 * This caveat only affects cross builds.
 1523 */
 1524 /* LINTED 248: floating-point constant out of range */
 1525 ldbl_t max = LDBL_MAX;
 1526 return lv < 0 ? -max : max;
1511} 1527}
1512 1528
1513/* 1529/*
1514 * Fold constant nodes having operands with floating point type. 1530 * Fold constant nodes having operands with floating point type.
1515 */ 1531 */
1516static tnode_t * 1532static tnode_t *
1517fold_float(tnode_t *tn) 1533fold_float(tnode_t *tn)
1518{ 1534{
1519 val_t *v; 1535 val_t *v;
1520 tspec_t t; 1536 tspec_t t;
1521 ldbl_t lv, rv = 0; 1537 ldbl_t lv, rv = 0;
1522 1538
1523 fpe = 0; 1539 fpe = 0;