Module Name: src Committed By: rillig Date: Tue Jun 15 18:23:39 UTC 2021
Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: extract convert_constant_to_floating To generate a diff of this commit: cvs rdiff -u -r1.285 -r1.286 src/usr.bin/xlint/lint1/tree.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.285 src/usr.bin/xlint/lint1/tree.c:1.286 --- src/usr.bin/xlint/lint1/tree.c:1.285 Tue Jun 15 18:16:11 2021 +++ src/usr.bin/xlint/lint1/tree.c Tue Jun 15 18:23:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.285 2021/06/15 18:16:11 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.286 2021/06/15 18:23:39 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: tree.c,v 1.285 2021/06/15 18:16:11 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.286 2021/06/15 18:23:39 rillig Exp $"); #endif #include <float.h> @@ -2159,6 +2159,24 @@ convert_constant_floating(op_t op, int a } } +static bool +convert_constant_to_floating(tspec_t nt, val_t *nv, + tspec_t ot, const val_t *v) +{ + if (nt == FLOAT) { + nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ? + (float)(uint64_t)v->v_quad : (float)v->v_quad; + } else if (nt == DOUBLE) { + nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ? + (double)(uint64_t)v->v_quad : (double)v->v_quad; + } else if (nt == LDOUBLE) { + nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ? + (ldbl_t)(uint64_t)v->v_quad : (ldbl_t)v->v_quad; + } else + return false; + return true; +} + /* * Print a warning if bits which were set are lost due to the conversion. * This can happen with operator ORASS only. @@ -2353,20 +2371,9 @@ convert_constant(op_t op, int arg, const if (ot == FLOAT || ot == DOUBLE || ot == LDOUBLE) { convert_constant_floating(op, arg, ot, tp, nt, v, nv); - } else { - if (nt == FLOAT) { - nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ? - (float)(uint64_t)v->v_quad : (float)v->v_quad; - } else if (nt == DOUBLE) { - nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ? - (double)(uint64_t)v->v_quad : (double)v->v_quad; - } else if (nt == LDOUBLE) { - nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ? - (ldbl_t)(uint64_t)v->v_quad : (ldbl_t)v->v_quad; - } else { - range_check = true; /* Check for lost precision. */ - nv->v_quad = v->v_quad; - } + } else if (!convert_constant_to_floating(nt, nv, ot, v)) { + range_check = true; /* Check for lost precision. */ + nv->v_quad = v->v_quad; } if ((v->v_ansiu && is_floating(nt)) ||