Tue Apr 11 19:40:05 2023 UTC ()
lint: fix converting a complex floating-point constant

The complex '+' in msg_142 line 27 led to an invalid floating point
value when converting from 'double' to '_Complex double'.


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

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

--- src/usr.bin/xlint/lint1/tree.c 2023/04/11 19:07:08 1.510
+++ src/usr.bin/xlint/lint1/tree.c 2023/04/11 19:40:04 1.511
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: tree.c,v 1.510 2023/04/11 19:07:08 rillig Exp $ */ 1/* $NetBSD: tree.c,v 1.511 2023/04/11 19:40:04 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.510 2023/04/11 19:07:08 rillig Exp $"); 40__RCSID("$NetBSD: tree.c,v 1.511 2023/04/11 19:40:04 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 {
@@ -3636,31 +3636,31 @@ convert_constant_floating(op_t op, int a @@ -3636,31 +3636,31 @@ convert_constant_floating(op_t op, int a
3636 lint_assert(nt != LDOUBLE); 3636 lint_assert(nt != LDOUBLE);
3637 if (op == FARG) { 3637 if (op == FARG) {
3638 /* conversion of '%s' to '%s' is out of range, ... */ 3638 /* conversion of '%s' to '%s' is out of range, ... */
3639 warning(295, 3639 warning(295,
3640 type_name(gettyp(ot)), type_name(tp), arg); 3640 type_name(gettyp(ot)), type_name(tp), arg);
3641 } else { 3641 } else {
3642 /* conversion of '%s' to '%s' is out of range */ 3642 /* conversion of '%s' to '%s' is out of range */
3643 warning(119, 3643 warning(119,
3644 type_name(gettyp(ot)), type_name(tp)); 3644 type_name(gettyp(ot)), type_name(tp));
3645 } 3645 }
3646 v->v_ldbl = v->v_ldbl > 0 ? max : min; 3646 v->v_ldbl = v->v_ldbl > 0 ? max : min;
3647 } 3647 }
3648 3648
3649 if (nt == FLOAT) { 3649 if (nt == FLOAT || nt == FCOMPLEX) {
3650 nv->v_ldbl = (float)v->v_ldbl; 3650 nv->v_ldbl = (float)v->v_ldbl;
3651 } else if (nt == DOUBLE) { 3651 } else if (nt == DOUBLE || nt == DCOMPLEX) {
3652 nv->v_ldbl = (double)v->v_ldbl; 3652 nv->v_ldbl = (double)v->v_ldbl;
3653 } else if (nt == LDOUBLE) { 3653 } else if (nt == LDOUBLE || nt == LCOMPLEX) {
3654 nv->v_ldbl = v->v_ldbl; 3654 nv->v_ldbl = v->v_ldbl;
3655 } else { 3655 } else {
3656 nv->v_quad = (int64_t)v->v_ldbl; 3656 nv->v_quad = (int64_t)v->v_ldbl;
3657 } 3657 }
3658} 3658}
3659 3659
3660static bool 3660static bool
3661convert_constant_to_floating(tspec_t nt, val_t *nv, 3661convert_constant_to_floating(tspec_t nt, val_t *nv,
3662 tspec_t ot, const val_t *v) 3662 tspec_t ot, const val_t *v)
3663{ 3663{
3664 if (nt == FLOAT) { 3664 if (nt == FLOAT) {
3665 nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ? 3665 nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ?
3666 (float)(uint64_t)v->v_quad : (float)v->v_quad; 3666 (float)(uint64_t)v->v_quad : (float)v->v_quad;