This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
rpeep(): silence compiler warning
authorDavid Mitchell <davem@iabyn.com>
Wed, 2 Dec 2015 11:49:04 +0000 (11:49 +0000)
committerDavid Mitchell <davem@iabyn.com>
Wed, 2 Dec 2015 12:08:48 +0000 (12:08 +0000)
op.c: In function ‘Perl_rpeep’:
op.c:13666:35: warning: comparison is always false due to limited range of data
type [-Wtype-limits]

This condition is always false if for example base is 32 bit and UVs are 64
bit:

    base >  (UV_MAX >> (OPpPADRANGE_COUNTSHIFT+SAVE_TIGHT_SHIFT)

silence the warning by replacing base with a constant-folded conditional

    (cond ? base : 0) > ....

where cond is false if sizeof(base) is small.

op.c

diff --git a/op.c b/op.c
index 168aef3..d8dfbd3 100644 (file)
--- a/op.c
+++ b/op.c
@@ -13662,9 +13662,17 @@ Perl_rpeep(pTHX_ OP *o)
                     break;
 
                 /* there's a biggest base we can fit into a
-                 * SAVEt_CLEARPADRANGE in pp_padrange */
-                if (intro && base >
-                        (UV_MAX >> (OPpPADRANGE_COUNTSHIFT+SAVE_TIGHT_SHIFT)))
+                 * SAVEt_CLEARPADRANGE in pp_padrange.
+                 * (The sizeof() stuff will be constant-folded, and is
+                 * intended to avoid getting "comparison is always false"
+                 * compiler warnings)
+                 */
+                if (   intro
+                    && (8*sizeof(base) >
+                        8*sizeof(UV)-OPpPADRANGE_COUNTSHIFT-SAVE_TIGHT_SHIFT
+                        ? base : 0) >
+                        (UV_MAX >> (OPpPADRANGE_COUNTSHIFT+SAVE_TIGHT_SHIFT))
+                )
                     break;
 
                 /* Success! We've got another valid pad op to optimise away */