Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue "Use of uninitialized value" warnings in left-to-right order #23108

Open
wants to merge 2 commits into
base: blead
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pod/perldelta.pod
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ is an lvalue reference to an untied hash element where the key was
undefined. This warning is still produced at the point of call. [GH
#22423]

=item *

L<Use of uninitialized value%s|perldiag/"Use of uninitialized value%s">

This warning was issued in the reverse order (right-to-left) when both
operands of a binary operator are uninitialized values. This is now
fixed to be consistent with evaluation order of operands.

=back

=head1 Utility Changes
Expand Down
54 changes: 26 additions & 28 deletions pp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1483,8 +1483,8 @@ PP(pp_multiply)
} /* SvIOK(svr) */
#endif
{
NV right = SvNV_nomg(svr);
NV left = SvNV_nomg(svl);
NV right = SvNV_nomg(svr);
NV result = left * right;

#if defined(__sgi) && defined(USE_LONG_DOUBLE) && LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE && NVSIZE == 16
Expand Down Expand Up @@ -1611,8 +1611,8 @@ PP(pp_divide)
} /* one operand wasn't SvIOK */
#endif /* PERL_TRY_UV_DIVIDE */
{
NV right = SvNV_nomg(svr);
NV left = SvNV_nomg(svl);
NV right = SvNV_nomg(svr);
#if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan)
if (! Perl_isnan(right) && right == 0.0)
#else
Expand Down Expand Up @@ -1918,7 +1918,7 @@ PP(pp_subtract)

SV *svr = PL_stack_sp[0];
SV *svl = PL_stack_sp[-1];

NV nv;

#ifdef PERL_PRESERVE_IVUV

Expand Down Expand Up @@ -2049,7 +2049,8 @@ PP(pp_subtract)
TARGi(NEGATE_2IV(result), 1);
else {
/* result valid, but out of range for IV. */
TARGn(-(NV)result, 1);
nv = -(NV)result;
goto ret_nv;
}
}
goto ret;
Expand All @@ -2059,17 +2060,14 @@ PP(pp_subtract)
#else
useleft = USE_LEFT(svl);
#endif
{
NV value = SvNV_nomg(svr);

if (!useleft) {
/* left operand is undef, treat as zero - value */
TARGn(-value, 1);
goto ret;
}
TARGn(SvNV_nomg(svl) - value, 1);
goto ret;
}
/* If left operand is undef, treat as zero - value */
nv = useleft ? SvNV_nomg(svl) : 0.0;
/* Separate statements here to ensue SvNV_nomg(svl) is evaluated
before SvNV_nomg(svr) */
nv -= SvNV_nomg(svr);
ret_nv:
TARGn(nv, 1);

ret:
rpp_replace_2_1_NN(targ);
Expand Down Expand Up @@ -2355,8 +2353,8 @@ Perl_do_ncmp(pTHX_ SV* const left, SV * const right)
}
#endif
{
NV const rnv = SvNV_nomg(right);
NV const lnv = SvNV_nomg(left);
NV const rnv = SvNV_nomg(right);

#if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan)
if (Perl_isnan(lnv) || Perl_isnan(rnv)) {
Expand Down Expand Up @@ -2887,8 +2885,8 @@ PP(pp_i_multiply)
if (rpp_try_AMAGIC_2(mult_amg, AMGf_assign))
return NORMAL;

IV right = SvIV_nomg(PL_stack_sp[0]);
IV left = SvIV_nomg(PL_stack_sp[-1]);
IV right = SvIV_nomg(PL_stack_sp[0]);

TARGi((IV)((UV)left * (UV)right), 1);
rpp_replace_2_1_NN(targ);
Expand All @@ -2909,10 +2907,10 @@ PP(pp_i_divide)
SV *left = PL_stack_sp[-1];

{
IV num = SvIV_nomg(left);
IV value = SvIV_nomg(right);
if (value == 0)
DIE(aTHX_ "Illegal division by zero");
IV num = SvIV_nomg(left);

/* avoid FPE_INTOVF on some platforms when num is IV_MIN */
if (value == -1)
Expand All @@ -2935,8 +2933,8 @@ PP(pp_i_modulo)
if (rpp_try_AMAGIC_2(modulo_amg, AMGf_assign))
return NORMAL;

IV right = SvIV_nomg(PL_stack_sp[0]);
IV left = SvIV_nomg(PL_stack_sp[-1]);
IV right = SvIV_nomg(PL_stack_sp[0]);

{
if (!right)
Expand All @@ -2961,9 +2959,9 @@ PP(pp_i_add)
if (rpp_try_AMAGIC_2(add_amg, AMGf_assign))
return NORMAL;

IV right = SvIV_nomg(PL_stack_sp[0]);
SV *leftsv = PL_stack_sp[-1];
IV left = USE_LEFT(leftsv) ? SvIV_nomg(leftsv) : 0;
IV right = SvIV_nomg(PL_stack_sp[0]);

TARGi((IV)((UV)left + (UV)right), 1);
rpp_replace_2_1_NN(targ);
Expand All @@ -2980,9 +2978,9 @@ PP(pp_i_subtract)
if (rpp_try_AMAGIC_2(subtr_amg, AMGf_assign))
return NORMAL;

IV right = SvIV_nomg(PL_stack_sp[0]);
SV *leftsv = PL_stack_sp[-1];
IV left = USE_LEFT(leftsv) ? SvIV_nomg(leftsv) : 0;
IV right = SvIV_nomg(PL_stack_sp[0]);

TARGi((IV)((UV)left - (UV)right), 1);
rpp_replace_2_1_NN(targ);
Expand All @@ -2995,8 +2993,8 @@ PP(pp_i_lt)
if (rpp_try_AMAGIC_2(lt_amg, 0))
return NORMAL;

IV right = SvIV_nomg(PL_stack_sp[0]);
IV left = SvIV_nomg(PL_stack_sp[-1]);
IV right = SvIV_nomg(PL_stack_sp[0]);

rpp_replace_2_IMM_NN(boolSV(left < right));
return NORMAL;
Expand All @@ -3008,8 +3006,8 @@ PP(pp_i_gt)
if (rpp_try_AMAGIC_2(gt_amg, 0))
return NORMAL;

IV right = SvIV_nomg(PL_stack_sp[0]);
IV left = SvIV_nomg(PL_stack_sp[-1]);
IV right = SvIV_nomg(PL_stack_sp[0]);

rpp_replace_2_IMM_NN(boolSV(left > right));
return NORMAL;
Expand All @@ -3021,8 +3019,8 @@ PP(pp_i_le)
if (rpp_try_AMAGIC_2(le_amg, 0))
return NORMAL;

IV right = SvIV_nomg(PL_stack_sp[0]);
IV left = SvIV_nomg(PL_stack_sp[-1]);
IV right = SvIV_nomg(PL_stack_sp[0]);

rpp_replace_2_IMM_NN(boolSV(left <= right));
return NORMAL;
Expand All @@ -3034,8 +3032,8 @@ PP(pp_i_ge)
if (rpp_try_AMAGIC_2(ge_amg, 0))
return NORMAL;

IV right = SvIV_nomg(PL_stack_sp[0]);
IV left = SvIV_nomg(PL_stack_sp[-1]);
IV right = SvIV_nomg(PL_stack_sp[0]);

rpp_replace_2_IMM_NN(boolSV(left >= right));
return NORMAL;
Expand All @@ -3047,8 +3045,8 @@ PP(pp_i_eq)
if (rpp_try_AMAGIC_2(eq_amg, 0))
return NORMAL;

IV right = SvIV_nomg(PL_stack_sp[0]);
IV left = SvIV_nomg(PL_stack_sp[-1]);
IV right = SvIV_nomg(PL_stack_sp[0]);

rpp_replace_2_IMM_NN(boolSV(left == right));
return NORMAL;
Expand All @@ -3060,8 +3058,8 @@ PP(pp_i_ne)
if (rpp_try_AMAGIC_2(ne_amg, 0))
return NORMAL;

IV right = SvIV_nomg(PL_stack_sp[0]);
IV left = SvIV_nomg(PL_stack_sp[-1]);
IV right = SvIV_nomg(PL_stack_sp[0]);

rpp_replace_2_IMM_NN(boolSV(left != right));
return NORMAL;
Expand All @@ -3074,8 +3072,8 @@ PP(pp_i_ncmp)
if (rpp_try_AMAGIC_2(ncmp_amg, 0))
return NORMAL;

IV right = SvIV_nomg(PL_stack_sp[0]);
IV left = SvIV_nomg(PL_stack_sp[-1]);
IV right = SvIV_nomg(PL_stack_sp[0]);


{
Expand Down Expand Up @@ -3121,8 +3119,8 @@ PP(pp_atan2)
if (rpp_try_AMAGIC_2(atan2_amg, 0))
return NORMAL;

NV right = SvNV_nomg(PL_stack_sp[0]);
NV left = SvNV_nomg(PL_stack_sp[-1]);
NV right = SvNV_nomg(PL_stack_sp[0]);

TARGn(Perl_atan2(left, right), 1);
rpp_replace_2_1_NN(targ);
Expand Down
21 changes: 10 additions & 11 deletions pp_hot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,7 @@ PP(pp_add)
SV *targ = (PL_op->op_flags & OPf_STACKED)
? PL_stack_sp[-1]
: PAD_SV(PL_op->op_targ);
NV nv;

if (rpp_try_AMAGIC_2(add_amg, AMGf_assign|AMGf_numeric))
return NORMAL;
Expand Down Expand Up @@ -1998,7 +1999,8 @@ PP(pp_add)
TARGi(NEGATE_2IV(result), 1);
else {
/* result valid, but out of range for IV. */
TARGn(-(NV)result, 1);
nv = -(NV)result;
goto ret_nv;
}
}
goto ret;
Expand All @@ -2010,16 +2012,13 @@ PP(pp_add)
useleft = USE_LEFT(svl);
#endif

{
NV value = SvNV_nomg(svr);
if (!useleft) {
/* left operand is undef, treat as zero. + 0.0 is identity. */
TARGn(value, 1);
}
else {
TARGn(value + SvNV_nomg(svl), 1);
}
}
/* If left operand is undef, treat as zero. */
nv = useleft ? SvNV_nomg(svl) : 0.0;
/* Separate statements here to ensue SvNV_nomg(svl) is evaluated
before SvNV_nomg(svr) */
nv += SvNV_nomg(svr);
ret_nv:
TARGn(nv, 1);

ret:
rpp_replace_2_1_NN(targ);
Expand Down
Loading
Loading