develooper Front page | perl.perl5.porters | Postings from November 2014

Avoid gcc warning op.c

Thread Next
From:
Martijn Lievaart
Date:
November 15, 2014 18:32
Subject:
Avoid gcc warning op.c
Message ID:
54679C2F.3040504@rtij.nl
Hi,

First post to this mailing list and first stab at fighting the warnings. 
Please flame me if anything is inappropriate.

In op.c, gcc is not smart enough to figure out that `start` is always 
set if `block` is true. The following compile-tested patch avoids the 
warning by being more explicit. `const_sv` can now be set to NULL in two 
code paths, so I just hope the optimizer is smart enough to generate the 
same code as before.

Alternative is to set `const_sv` to NULL before the `if (block)`, but 
this seems less efficient, I doubt it optimizes as well.

Questions
- Is micro optimising here needed? Looking at the original code suggests 
it is.
- Is this patch the correct way to address these kinds of warnings?

TIA,
Martijn M4 Lievaart

Author: Martijn Lievaart <m@rtij.nl>
Date:   Sat Nov 15 17:51:44 2014 +0100

     Avoid gcc warning "‘start’ may be used uninitialized in this function"

diff --git a/op.c b/op.c
index 8a0c7fa..46b0420 100644
--- a/op.c
+++ b/op.c
@@ -7937,14 +7937,14 @@ Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, 
OP *attrs, OP *block)
                    : newUNOP(OP_LEAVESUB, 0, scalarseq(block));
         start = LINKLIST(block);
         block->op_next = 0;
+        if (ps && !*ps && !attrs && !CvLVALUE(compcv))
+            const_sv = S_op_const_sv(aTHX_ start, compcv, FALSE);
+        else
+            const_sv = NULL;
      }
-
-    if (!block || !ps || *ps || attrs
-       || CvLVALUE(compcv)
-       )
-       const_sv = NULL;
      else
-       const_sv = S_op_const_sv(aTHX_ start, compcv, FALSE);
+        const_sv = NULL;
+

      if (cv) {
          const bool exists = CvROOT(cv) || CvXSUB(cv);
@@ -8341,15 +8341,14 @@ Perl_newATTRSUB_x(pTHX_ I32 floor, OP *o, OP 
*proto, OP *attrs,
                    : newUNOP(OP_LEAVESUB, 0, scalarseq(block));
         start = LINKLIST(block);
         block->op_next = 0;
+        if (ps && !*ps && !attrs && !CvLVALUE(PL_compcv))
+            const_sv =
+                S_op_const_sv(aTHX_ start, PL_compcv, CvCLONE(PL_compcv));
+        else
+            const_sv = NULL;
      }
-
-    if (!block || !ps || *ps || attrs
-       || CvLVALUE(PL_compcv)
-       )
-       const_sv = NULL;
      else
-       const_sv =
-           S_op_const_sv(aTHX_ start, PL_compcv, CvCLONE(PL_compcv));
+        const_sv = NULL;

      if (SvPOK(gv) || (SvROK(gv) && SvTYPE(SvRV(gv)) != SVt_PVCV)) {
         assert (block);


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About