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 context 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,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.511 2023/04/11 19:40:04 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.512 2023/04/12 19:09:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.511 2023/04/11 19:40:04 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.512 2023/04/12 19:09:48 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1507,7 +1507,23 @@
 		return lv < 0 ? -FLT_MAX : FLT_MAX;
 	if (t == DOUBLE)
 		return lv < 0 ? -DBL_MAX : DBL_MAX;
-	return lv < 0 ? -LDBL_MAX : LDBL_MAX;
+	/*
+	 * When lint is compiled on x86_64 to check for sparc64, it uses the
+	 * type 'long double' from x86_64, which is the Intel 80-bit format.
+	 * The constant LDBL_MAX comes from the sparc64 preprocessor though
+	 * and uses the IEEE-754-binary128 format, with the same exponent
+	 * range but a wider mantissa.
+	 *
+	 * To properly handle this situation, lint would have to implement the
+	 * floating-point types in a platform-independent way, which is not
+	 * worth the effort, given how few programs practically use 'long
+	 * double'.
+	 *
+	 * This caveat only affects cross builds.
+	 */
+	/* LINTED 248: floating-point constant out of range */
+	ldbl_t max = LDBL_MAX;
+	return lv < 0 ? -max : max;
 }
 
 /*