This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Slience compiler warnings for NV, [IU]V compare
authorKarl Williamson <khw@cpan.org>
Sun, 22 Nov 2020 16:36:20 +0000 (09:36 -0700)
committerKarl Williamson <khw@cpan.org>
Sun, 22 Nov 2020 16:47:15 +0000 (09:47 -0700)
These were occurring on FreeBSD smokes.

warning: implicit conversion from 'IV' (aka 'long') to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-int-float-conversion]

9223372036854775807 is IV_MAX.  What needed to be done here was to use
the NV containing IV_MAX+1, a value that already exists in perl.h

In other instances, simply casting to an NV before doing the comparison
with the NV was what was needed.

This fixes #18328

ext/POSIX/POSIX.xs
ext/POSIX/lib/POSIX.pm
inline.h
pp_ctl.c
sv.c

index ad5ca6c..cc67fd6 100644 (file)
@@ -1333,7 +1333,7 @@ static NV_PAYLOAD_TYPE S_getpayload(NV nv)
 #ifdef NV_PAYLOAD_DEBUG
     Perl_warn(aTHX_ "a[%d] = %" UVxf "\n", i, a[i]);
 #endif
-    payload *= UV_MAX;
+    payload *= (NV) UV_MAX;
     payload += a[i];
   }
 #ifdef NV_PAYLOAD_DEBUG
index 51a51a2..c374af6 100644 (file)
@@ -4,7 +4,7 @@ use warnings;
 
 our ($AUTOLOAD, %SIGRT);
 
-our $VERSION = '1.95';
+our $VERSION = '1.96';
 
 require XSLoader;
 
index 5ada155..3b34ad4 100644 (file)
--- a/inline.h
+++ b/inline.h
@@ -1980,7 +1980,7 @@ S_lossless_NV_to_IV(const NV nv, IV *ivp)
 
     /* Written this way so that with an always-false NaN comparison we
      * return false */
-    if (!(LIKELY(nv >= IV_MIN) && LIKELY(nv <= IV_MAX))) {
+    if (!(LIKELY(nv >= (NV) IV_MIN) && LIKELY(nv < IV_MAX_P1))) {
         return FALSE;
     }
 
index 5cb5a10..ed451c0 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1228,7 +1228,7 @@ PP(pp_flop)
            if ((SvOK(left) && !SvIOK(left) && SvNV_nomg(left) < IV_MIN) ||
                (SvOK(right) && (SvIOK(right)
                                 ? SvIsUV(right) && SvUV(right) > IV_MAX
-                                : SvNV_nomg(right) > IV_MAX)))
+                                : SvNV_nomg(right) > (NV) IV_MAX)))
                DIE(aTHX_ "Range iterator outside integer range");
            i = SvIV_nomg(left);
            j = SvIV_nomg(right);
diff --git a/sv.c b/sv.c
index f062cc2..5c4c355 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -2055,7 +2055,7 @@ S_sv_2iuv_non_preserve(pTHX_ SV *const sv
     (void)SvNOK_on(sv);
     /* Can't use strtol etc to convert this string.  (See truth table in
        sv_2iv  */
-    if (SvNVX(sv) <= (UV)IV_MAX) {
+    if (SvNVX(sv) < IV_MAX_P1) {
         SvIV_set(sv, I_V(SvNVX(sv)));
         if ((NV)(SvIVX(sv)) == SvNVX(sv)) {
             SvIOK_on(sv); /* Integer is precise. NOK, IOK */
@@ -11118,7 +11118,7 @@ S_F0convert(NV nv, char *const endbuf, STRLEN *const len)
     assert(!Perl_isinfnan(nv));
     if (neg)
        nv = -nv;
-    if (nv != 0.0 && nv < UV_MAX) {
+    if (nv != 0.0 && nv < (NV) UV_MAX) {
        char *p = endbuf;
        uv = (UV)nv;
        if (uv != nv) {