Description
This is a bug report for perl from LorenzoTa,
generated with the help of perlbug 1.40 running under perl 5.26.0.
Hello esteemed ones,
it seems (in every version of perl and on every OS) that COW does not work as expected when the constant is the result of compile-time constant-folding.
In short:
my $x = 'a' x (2**30);
Allocates 2.104.612 K of OS memory while Devel::Size::total_size($x) reports 1.00 Gb
We spotted this wrong behaviour at perlmonks in the thread:
www.perlmonks.org/?node_id=11147727
where you can find many more details and test run on different envs, with the very same (unexpected) result, alongside comments of more experienced programmers: notably this one
More details:
# WRONG behaviour as it doubles the memory
my $x = 'a' x (2**30);
# RIGHT behaviour
foreach my $order ( qw(20 24 30 32) ) { my $x = 'a' x ( 2 ** $order ) }
# also RIGHT forcing RHS to runtime
$x = 'a' x (2**${\32})
Thanks for your work!
lorenzo
[Please do not change anything below this line]
Flags:
category=core
severity=medium
Site configuration information for perl 5.26.0:
Configured by strawberry-perl at Sat Sep 2 16:28:54 2017.
Summary of my perl5 (revision 5 version 26 subversion 0) configuration:
Platform:
osname=MSWin32
osvers=6.3
archname=MSWin32-x64-multi-thread
uname='Win32 strawberry-perl 5.26.0.2 #1 Sat Sep 2 16:25:32 2017 x64'
config_args='undef'
hint=recommended
useposix=true
d_sigaction=undef
useithreads=define
usemultiplicity=define
use64bitint=define
use64bitall=undef
uselongdouble=undef
usemymalloc=n
default_inc_excludes_dot=define
bincompat5005=undef
Compiler:
cc='gcc'
ccflags =' -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -D__USE_MINGW_ANSI_STDIO -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fwrapv -fno-strict-aliasing -mms-bitfields'
optimize='-s -O2'
cppflags='-DWIN32'
ccversion=''
gccversion='7.1.0'
gccosandvers=''
intsize=4
longsize=4
ptrsize=8
doublesize=8
byteorder=12345678
doublekind=3
d_longlong=define
longlongsize=8
d_longdbl=define
longdblsize=16
longdblkind=3
ivtype='long long'
ivsize=8
nvtype='double'
nvsize=8
Off_t='long long'
lseeksize=8
alignbytes=8
prototype=define
Linker and Libraries:
ld='g++.exe'
ldflags ='-s -L"C:\EX_D\ulisseDUE\perl5.26.64bit\perl\lib\CORE" -L"C:\EX_D\ulisseDUE\perl5.26.64bit\c\lib"'
libpth=C:\EX_D\ulisseDUE\perl5.26.64bit\c\lib C:\EX_D\ulisseDUE\perl5.26.64bit\c\x86_64-w64-mingw32\lib C:\EX_D\ulisseDUE\perl5.26.64bit\c\lib\gcc\x86_64-w64-mingw32\7.1.0
libs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
perllibs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
libc=
so=dll
useshrplib=true
libperl=libperl526.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_win32.xs
dlext=xs.dll
d_dlsymun=undef
ccdlflags=' '
cccdlflags=' '
lddlflags='-mdll -s -L"C:\EX_D\ulisseDUE\perl5.26.64bit\perl\lib\CORE" -L"C:\EX_D\ulisseDUE\perl5.26.64bit\c\lib"'
@inc for perl 5.26.0:
C:/EX_D/ulisseDUE/perl5.26.64bit/perl/site/lib/MSWin32-x64-multi-thread
C:/EX_D/ulisseDUE/perl5.26.64bit/perl/site/lib
C:/EX_D/ulisseDUE/perl5.26.64bit/perl/vendor/lib
C:/EX_D/ulisseDUE/perl5.26.64bit/perl/lib
Environment for perl 5.26.0:
HOME (unset)
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=C:\EX_D\ulisseDUE\perl5.26.64bit\perl\site\bin;C:\EX_D\ulisseDUE\perl5.26.64bit\perl\bin;C:\EX_D\ulisseDUE\perl5.26.64bit\c\bin;C:\EX_D\ulisseDUE\bin\UnxUtils\usr\local\wbin;C:\WINDOWS;C:\WINDOWS\system32;
PERL_BADLANG (unset)
PERL_JSON_BACKEND=JSON::XS
PERL_RL=Perl
PERL_YAML_BACKEND=YAML
SHELL (unset)