Skip Menu |
Report information
Id: 132683
Status: open
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: trizen [at] protonmail.com
Cc:
AdminCc:

Operating System: (no value)
PatchStatus: (no value)
Severity: low
Type: unknown
Perl Version: (no value)
Fixed In: (no value)



To: "perlbug [...] perl.org" <perlbug [...] perl.org>
Subject: "Use of uninitialized value" in warn() with constant folding and overloaded numbers
From: Trizen <trizen [...] protonmail.com>
Date: Fri, 05 Jan 2018 02:08:35 -0500
Download (untitled) / with headers
text/plain 4.7k
Download (untitled) / with headers
text/html 11.6k
Hi,

There seems to be a minor issue: when warn() is used in an overloaded built-in function which is subject to constant folding and the argument is an overloaded number (with overload::constant), it displays "Use of uninitialized value in warn", although no uninitialized value is passed to warn().

Example:

use strict;
use warnings;

package Foo;

use overload log => sub {
    warn "here\n";                  # Use of uninitialized value in warn
    CORE::log($_[0]->{value});
};

sub import {
    overload::constant
        integer => sub { __PACKAGE__->new($_[0]) };
}

sub new {
    my ($class, $value) = @_;
    bless {value => $value}, $class;
}

package main;

BEGIN { Foo->import }
print log(2), "\n";

The output is:

Use of uninitialized value in warn at bug.pl line 7.
here
0.693147180559945

This warning happens at compile-time, as can be illustrated with `perl -c`:

$ perl -c x.pl
Use of uninitialized value in warn at x.pl line 7.
here
x.pl syntax OK

The issue was reproduced with perl-5.18.4, perl-5.26.1 and perl-5.27.7.

Output of `perlbug -d`:

---
Flags:
    category=core
    severity=low
---
Site configuration information for perl 5.26.1:

Configured by builduser at Sat Sep 23 16:41:42 CEST 2017.

Summary of my perl5 (revision 5 version 26 subversion 1) configuration:
  
  Platform:
    osname=linux
    osvers=4.13.3-1-arch
    archname=x86_64-linux-thread-multi
    uname='linux flo-64 4.13.3-1-arch #1 smp preempt thu sep 21 20:33:16 cest 2017 x86_64 gnulinux '
    config_args='-des -Dusethreads -Duseshrplib -Doptimize=-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -Dprefix=/usr -Dvendorprefix=/usr -Dprivlib=/usr/share/perl5/core_perl -Darchlib=/usr/lib/perl5/5.26/core_perl -Dsitelib=/usr/share/perl5/site_perl -Dsitearch=/usr/lib/perl5/5.26/site_perl -Dvendorlib=/usr/share/perl5/vendor_perl -Dvendorarch=/usr/lib/perl5/5.26/vendor_perl -Dscriptdir=/usr/bin/core_perl -Dsitescript=/usr/bin/site_perl -Dvendorscript=/usr/bin/vendor_perl -Dinc_version_list=none -Dman1ext=1perl -Dman3ext=3perl -Dcccdlflags='-fPIC' -Dlddlflags=-shared -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -Dldflags=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt'
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='7.2.0'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags ='-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include-fixed /usr/lib /lib/../lib /usr/lib/../lib /lib /lib64 /usr/lib64
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.26.so
    so=so
    useshrplib=true
    libperl=libperl.so
    gnulibc_version='2.26'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.26/core_perl/CORE'
    cccdlflags='-fPIC'
    lddlflags='-shared -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -L/usr/local/lib -fstack-protector-strong'


---
@INC for perl 5.26.1:
    /usr/lib/perl5/5.26/site_perl
    /usr/share/perl5/site_perl
    /usr/lib/perl5/5.26/vendor_perl
    /usr/share/perl5/vendor_perl
    /usr/lib/perl5/5.26/core_perl
    /usr/share/perl5/core_perl

---
Environment for perl 5.26.1:
    HOME=/home/swampyx
    LANG=en_US.UTF-8
    LANGUAGE=
    LC_ADDRESS=
    LC_ALL=
    LC_COLLATE=
    LC_CTYPE=en_US.UTF-8
    LC_IDENTIFICATION=
    LC_MEASUREMENT=
    LC_MESSAGES=
    LC_MONETARY=
    LC_NAME=
    LC_NUMERIC=
    LC_PAPER=
    LC_TELEPHONE=
    LC_TIME=
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/lib/ccache/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/share/perl6/vendor/bin
    PERL_BADLANG (unset)
    SHELL=/usr/bin/zsh

Download x.pl
text/x-perl 403b

Message body is not shown because sender requested not to inline it.

RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 412b
On Thu, 04 Jan 2018 23:09:07 -0800, trizen@protonmail.com wrote: Show quoted text
> Hi, > > There seems to be a minor issue: when warn() is used in an overloaded > built-in function which is subject to constant folding and the > argument is an overloaded number (with overload::constant), it > displays "Use of uninitialized value in warn", although no > uninitialized value is passed to warn().
Try the attached. Thanks, Tony
Subject: 0001-perl-132683-don-t-try-to-convert-PL_sv_placeholder-i.patch
From 536b91a5640beba18185316f709279a8d2e588be Mon Sep 17 00:00:00 2001 From: Tony Cook <tony@develop-help.com> Date: Wed, 21 Feb 2018 16:24:08 +1100 Subject: (perl #132683) don't try to convert PL_sv_placeholder into a CV Constant folding sets PL_warnhook to PERL_WARNHOOK_FATAL, which is &PL_sv_placeholder, an undef SV. If warn() is called while constant folding, invoke_exception_hook() attempts to use the value of a non-NULL PL_warnhook as a CV, which caused an undefined value warning. invoke_exception_hook() now treats a PL_warnhook of PERL_WARNHOOK_FATAL the same as NULL, falling back to the normal warning handling which throws an exception to abort constant folding. --- t/lib/warnings/util | 29 +++++++++++++++++++++++++++++ util.c | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/t/lib/warnings/util b/t/lib/warnings/util index e82d6a6617..92be6efa73 100644 --- a/t/lib/warnings/util +++ b/t/lib/warnings/util @@ -106,3 +106,32 @@ no warnings 'portable' ; $a = oct "0047777777777" ; EXPECT Octal number > 037777777777 non-portable at - line 5. +######## +# util.c +# NAME 132683: Use of uninitialized value" in warn() with constant folding and overloaded numbers +use strict; +use warnings; + +package Foo; + +use overload log => sub { + warn "here\n"; # Use of uninitialized value in warn + CORE::log($_[0]->{value}); +}; + +sub import { + overload::constant + integer => sub { __PACKAGE__->new($_[0]) }; +} + +sub new { + my ($class, $value) = @_; + bless {value => $value}, $class; +} + +package main; + +BEGIN { Foo->import } +my $x = log(2); +EXPECT +here diff --git a/util.c b/util.c index 647f53307d..07ca5c7b1d 100644 --- a/util.c +++ b/util.c @@ -1534,7 +1534,7 @@ S_invoke_exception_hook(pTHX_ SV *ex, bool warn) /* sv_2cv might call Perl_croak() or Perl_warner() */ SV * const oldhook = *hook; - if (!oldhook) + if (!oldhook || oldhook == PERL_WARNHOOK_FATAL) return FALSE; ENTER; -- 2.11.0


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org