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

[PATCH] Include negative index of array in warnings about an unitialized value wen constant folding isn't done. #11630

Closed
p5pRT opened this issue Sep 4, 2011 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Sep 4, 2011

Migrated from rt.perl.org#98366 (status was 'resolved')

Searchable as RT98366$

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2011

From gerard@ggoossen.net

This is a bug report for perl from gerard@​ggoossen.net,
generated with the help of perlbug 1.39 running under perl 5.15.2.

From 15850133545e13d0450e92c1f2ec0cbb0891c085 Mon Sep 17 00​:00​:00 2001
From​: Gerard Goossen <gerard@​ggoossen.net>
Date​: Sat, 3 Sep 2011 12​:28​:45 +0200
Subject​: [PATCH] Include negative index of array in warnings about an
unitialized value wen constant folding isn't done.

When constant folding isn't done OP_NEGATE isn't merged with
a constant, and the index isn't detected when warning about
unintialized values. This patch adds special handling for OP_NEGATE to
the index detection.


sv.c | 27 +++++++++++++++++++++++----
1 files changed, 23 insertions(+), 4 deletions(-)

Inline Patch
diff --git a/sv.c b/sv.c
index ea78558..f555e44 100644
--- a/sv.c
+++ b/sv.c
@@ -13909,6 +13909,9 @@ S_find_uninit_var(pTHX_ const OP *const obase, const SV *const uninit_sv,
 
     case OP_AELEM:
     case OP_HELEM:
+    {
+	bool negate = FALSE;
+
 	if (PL_op == obase)
 	    /* $a[uninit_expr] or $h{uninit_expr} */
 	    return find_uninit_var(cBINOPx(obase)->op_last, uninit_sv, match);
@@ -13934,28 +13937,43 @@ S_find_uninit_var(pTHX_ const OP *const obase, const SV *const uninit_sv,
 	if (!sv)
 	    break;
 
+	if (kid && kid->op_type == OP_NEGATE) {
+	    negate = TRUE;
+	    kid = cUNOPx(kid)->op_first;
+	}
+
 	if (kid && kid->op_type == OP_CONST && SvOK(cSVOPx_sv(kid))) {
 	    /* index is constant */
+	    SV* kidsv;
+	    if (negate) {
+		kidsv = sv_2mortal(newSVpvs("-"));
+		sv_catsv(kidsv, cSVOPx_sv(kid));
+	    }
+	    else
+		kidsv = cSVOPx_sv(kid);
 	    if (match) {
 		if (SvMAGICAL(sv))
 		    break;
 		if (obase->op_type == OP_HELEM) {
-		    HE* he = hv_fetch_ent(MUTABLE_HV(sv), cSVOPx_sv(kid), 0, 0);
+		    HE* he = hv_fetch_ent(MUTABLE_HV(sv), kidsv, 0, 0);
 		    if (!he || HeVAL(he) != uninit_sv)
 			break;
 		}
 		else {
-		    SV * const * const svp = av_fetch(MUTABLE_AV(sv), SvIV(cSVOPx_sv(kid)), FALSE);
+		    SV * const * const svp = av_fetch(MUTABLE_AV(sv),
+			negate ? - SvIV(cSVOPx_sv(kid)) : SvIV(cSVOPx_sv(kid)),
+			FALSE);
 		    if (!svp || *svp != uninit_sv)
 			break;
 		}
 	    }
 	    if (obase->op_type == OP_HELEM)
 		return varname(gv, '%', o->op_targ,
-			    cSVOPx_sv(kid), 0, FUV_SUBSCRIPT_HASH);
+			    kidsv, 0, FUV_SUBSCRIPT_HASH);
 	    else
 		return varname(gv, '@', o->op_targ, NULL,
-			    SvIV(cSVOPx_sv(kid)), FUV_SUBSCRIPT_ARRAY);
+		    negate ? - SvIV(cSVOPx_sv(kid)) : SvIV(cSVOPx_sv(kid)),
+		    FUV_SUBSCRIPT_ARRAY);
 	}
 	else  {
 	    /* index is an expression;
@@ -13981,6 +13999,7 @@ S_find_uninit_var(pTHX_ const OP *const obase, const SV *const uninit_sv,
 		o->op_targ, NULL, 0, FUV_SUBSCRIPT_WITHIN);
 	}
 	break;
+    }
 
     case OP_AASSIGN:
 	/* only examine RHS */
-- 
1.7.5.4

Flags​:
  category=core
  severity=low


Site configuration information for perl 5.15.2​:

Configured by gerard at Sun Sep 4 13​:21​:43 CEST 2011.

Summary of my perl5 (revision 5 version 15 subversion 2) configuration​:
  Commit id​: 15850133545e13d0450e92c1f2ec0cbb0891c085
  Platform​:
  osname=linux, osvers=3.0.0-1-686-pae, archname=i686-linux-thread-multi
  uname='linux zeus 3.0.0-1-686-pae #1 smp sun jul 24 14​:27​:32 utc 2011 i686 gnulinux '
  config_args='-des -Dusethreads -Dnoextensions= -Doptimize=-O3 -g3 -DDEBUGGING -Dusedevel -Dprefix=/home/gerard/perl/inst/blead-codegen'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=define, usemultiplicity=define
  useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
  use64bitint=undef, use64bitall=undef, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-O3 -g3',
  cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
  ccversion='', gccversion='4.6.1', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=4, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib /usr/lib/i386-linux-gnu /usr/lib64
  libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
  perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
  libc=, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version='2.13'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
  cccdlflags='-fPIC', lddlflags='-shared -O3 -g3 -L/usr/local/lib -fstack-protector'

Locally applied patches​:
 


@​INC for perl 5.15.2​:
  lib
  /home/gerard/perl/inst/blead-codegen/lib/site_perl/5.15.2/i686-linux-thread-multi
  /home/gerard/perl/inst/blead-codegen/lib/site_perl/5.15.2
  /home/gerard/perl/inst/blead-codegen/lib/5.15.2/i686-linux-thread-multi
  /home/gerard/perl/inst/blead-codegen/lib/5.15.2
  /home/gerard/perl/inst/blead-codegen/lib/site_perl
  .


Environment for perl 5.15.2​:
  HOME=/home/gerard
  LANG=en_US.UTF-8
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/usr/lib/ccache​:/home/gerard/bin​:/usr/local/bin​:/usr/bin​:/bin​:/usr/games
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2011

From @cpansprout

On Sun Sep 04 04​:27​:02 2011, ggoossen wrote​:

This is a bug report for perl from gerard@​ggoossen.net,
generated with the help of perlbug 1.39 running under perl 5.15.2.

From 15850133545e13d0450e92c1f2ec0cbb0891c085 Mon Sep 17 00​:00​:00 2001
From​: Gerard Goossen <gerard@​ggoossen.net>
Date​: Sat, 3 Sep 2011 12​:28​:45 +0200
Subject​: [PATCH] Include negative index of array in warnings about an
unitialized value wen constant folding isn't done.

When constant folding isn't done OP_NEGATE isn't merged with
a constant, and the index isn't detected when warning about
unintialized values. This patch adds special handling for OP_NEGATE to
the index detection.

Thank you. Applied as e6c60e7.

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2011

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2011

@cpansprout - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant