Fri Apr 14 18:42:31 2023 UTC ()
lint: document suppressed LDBL_MAX warning more accurately

The crucial point is not that lint is cross-compiled but that tools/lint
is run on the usr.bin/xlint code, and in that situation, the platform
mismatch happens.


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

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

--- src/usr.bin/xlint/lint1/tree.c 2023/04/12 19:09:48 1.512
+++ src/usr.bin/xlint/lint1/tree.c 2023/04/14 18:42:31 1.513
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: tree.c,v 1.512 2023/04/12 19:09:48 rillig Exp $ */ 1/* $NetBSD: tree.c,v 1.513 2023/04/14 18:42:31 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.512 2023/04/12 19:09:48 rillig Exp $"); 40__RCSID("$NetBSD: tree.c,v 1.513 2023/04/14 18:42:31 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 {
@@ -1498,38 +1498,41 @@ fold_bool(tnode_t *tn) @@ -1498,38 +1498,41 @@ fold_bool(tnode_t *tn)
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 /* 1510 /*
1511 * When lint is compiled on x86_64 to check for sparc64, it uses the 1511 * When NetBSD is cross-built in MKLINT=yes mode on x86_64 for
1512 * type 'long double' from x86_64, which is the Intel 80-bit format. 1512 * sparc64, tools/lint checks this code while building usr.bin/xlint.
1513 * The constant LDBL_MAX comes from the sparc64 preprocessor though 1513 * In that situation, lint uses the preprocessor for sparc64, in which
1514 * and uses the IEEE-754-binary128 format, with the same exponent 1514 * the type 'long double' is IEEE-754-binary128, affecting the macro
1515 * range but a wider mantissa. 1515 * LDBL_MAX below. The type 'long double', as well as the strtold
 1516 * implementation, comes from the host platform x86_64 though, where
 1517 * 'long double' consumes 128 bits as well but only uses 80 of them.
 1518 * The exponent range of the two 'long double' types is the same, but
 1519 * the maximum finite value differs due to the extended precision on
 1520 * sparc64.
1516 * 1521 *
1517 * To properly handle this situation, lint would have to implement the 1522 * To properly handle the data types of the target platform, lint
1518 * floating-point types in a platform-independent way, which is not 1523 * would have to implement the floating-point types in a
1519 * worth the effort, given how few programs practically use 'long 1524 * platform-independent way, which is not worth the effort, given how
1520 * double'. 1525 * few programs practically use 'long double'.
1521 * 
1522 * This caveat only affects cross builds. 
1523 */ 1526 */
1524 /* LINTED 248: floating-point constant out of range */ 1527 /* LINTED 248: floating-point constant out of range */
1525 ldbl_t max = LDBL_MAX; 1528 ldbl_t max = LDBL_MAX;
1526 return lv < 0 ? -max : max; 1529 return lv < 0 ? -max : max;
1527} 1530}
1528 1531
1529/* 1532/*
1530 * Fold constant nodes having operands with floating point type. 1533 * Fold constant nodes having operands with floating point type.
1531 */ 1534 */
1532static tnode_t * 1535static tnode_t *
1533fold_float(tnode_t *tn) 1536fold_float(tnode_t *tn)
1534{ 1537{
1535 val_t *v; 1538 val_t *v;