Skip to content

$lexical = (index($x, y) == -1) optimization returns the right side #17739

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

Closed
tonycoz opened this issue Apr 22, 2020 · 0 comments · Fixed by #17740
Closed

$lexical = (index($x, y) == -1) optimization returns the right side #17739

tonycoz opened this issue Apr 22, 2020 · 0 comments · Fixed by #17740
Assignees

Comments

@tonycoz
Copy link
Contributor

tonycoz commented Apr 22, 2020

Module:

Description

7e8d786 optimized code like:

$lexical = (index(...) == -1);

into an index op with flags that makes it assign to $lexical. Unfortunately that new operation returns the result of the == rather than $lexical. For example with 5.18.3:

$ ~/perl/5.18.3-dbg/bin/perl5.18.3 -le 'my $x; ($x = (index($y, $z) == -1)) =~ s/^/x/; print $x'
x

but with blead:

$ ./perl -le 'my $x; ($x = (index($y, $z) == -1)) =~ s/^/x/; print $x'
Modification of a read-only value attempted at -e line 1.

Note that without the index this works as expected:

$ ./perl -le 'my $x; ($x = 1) =~ s/^/x/; print $x'
x1

Expected behavior

The assignment should return the modifiable lvalue for $lexical

Perl configuration

Summary of my perl5 (revision 5 version 31 subversion 11) configuration:
  Commit id: ece42804593a3366ce48ea404a2c0c60063eeb1e
  Platform:
    osname=linux
    osvers=4.19.0-6-amd64
    archname=x86_64-linux
    uname='linux mars 4.19.0-6-amd64 #1 smp debian 4.19.67-2+deb10u2 (2019-11-11) x86_64 gnulinux '
    config_args='-des -Dusedevel -DDEBUGGING'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-O2 -g'
    cppflags='-fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='8.3.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 =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/8/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /lib64 /usr/lib64
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.28.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.28'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -g -L/usr/local/lib -fstack-protector-strong'

Characteristics of this binary (from libperl): 
  Compile-time options:
    DEBUGGING
    HAS_TIMES
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_USE_DEVEL
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Built under linux
  Compiled at Apr 22 2020 14:46:25
  %ENV:
    PERLBREW_BASHRC_VERSION="0.43"
    PERLBREW_HOME="/home/tony/.perlbrew"
    PERLBREW_MANPATH=""
    PERLBREW_PATH="/home/tony/perl5/perlbrew/bin"
    PERLBREW_ROOT="/home/tony/perl5/perlbrew"
    PERLBREW_VERSION="0.67"
  @INC:
    lib
    /usr/local/lib/perl5/site_perl/5.31.11/x86_64-linux
    /usr/local/lib/perl5/site_perl/5.31.11
    /usr/local/lib/perl5/5.31.11/x86_64-linux
    /usr/local/lib/perl5/5.31.11

tonycoz added a commit to tonycoz/perl5 that referenced this issue Apr 22, 2020
tonycoz added a commit to tonycoz/perl5 that referenced this issue Apr 22, 2020
@tonycoz tonycoz self-assigned this Apr 23, 2020
tonycoz added a commit to tonycoz/perl5 that referenced this issue May 25, 2020
related to Perl#17737 and fixes Perl#17739

re-work of my original patch that only pushes the final result
xsawyerx pushed a commit that referenced this issue May 27, 2020
related to #17737 and fixes #17739

re-work of my original patch that only pushes the final result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant