Skip to content

perl: op.c:14769: Perl_find_lexical_cv: Assertion `PARENT_PAD_INDEX(name)' failed. #19857

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 Jun 13, 2022 · 5 comments · Fixed by #20199
Closed

perl: op.c:14769: Perl_find_lexical_cv: Assertion `PARENT_PAD_INDEX(name)' failed. #19857

tonycoz opened this issue Jun 13, 2022 · 5 comments · Fixed by #20199

Comments

@tonycoz
Copy link
Contributor

tonycoz commented Jun 13, 2022

Module:

Description

Running this code:

use builtin 'ceil';

my $x;
BEGIN {
    my $e = <<'EOS';
sub { ceil($_[0]) }
EOS
    $x = eval $e;
}

in a DEBUGGING build throws:

$ ./perl -Ilib ../ceilassert.pl 
perl: op.c:14769: Perl_find_lexical_cv: Assertion `PARENT_PAD_INDEX(name)' failed.
Aborted

Backtrace:

#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007ffff7c65537 in __GI_abort () at abort.c:79
#2  0x00007ffff7c6540f in __assert_fail_base (
    fmt=0x7ffff7dce128 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", 
    assertion=0x55555594579a "PARENT_PAD_INDEX(name)", 
    file=0x55555593e331 "op.c", line=14769, function=<optimized out>)
    at assert.c:92
#3  0x00007ffff7c74662 in __GI___assert_fail (
    assertion=0x55555594579a "PARENT_PAD_INDEX(name)", 
    file=0x55555593e331 "op.c", line=14769, 
    function=0x5555559482c0 <__PRETTY_FUNCTION__.33> "Perl_find_lexical_cv")
    at assert.c:101
#4  0x00005555555dd638 in Perl_find_lexical_cv (off=1) at op.c:14769
#5  0x0000555555660eee in yyl_keylookup (s=0x555555c09a2a "($_[0]) }\n\n;", 
    gv=0x0) at toke.c:8805
#6  0x0000555555663a6e in yyl_try (s=0x555555c09a26 "ceil($_[0]) }\n\n;")
    at toke.c:9319
#7  0x0000555555664ed9 in Perl_yylex () at toke.c:9621
#8  0x000055555567ab7e in Perl_yyparse (gramtype=258) at perly.c:357
#9  0x0000555555851412 in S_doeval_compile (gimme=2 '\002', 
    outside=0x555555bf6e08, seq=201, hh=0x0) at pp_ctl.c:3613
#10 0x0000555555858fd3 in Perl_pp_entereval () at pp_ctl.c:4580
#11 0x0000555555729e64 in Perl_runops_debug () at dump.c:2677
#12 0x00005555555f27de in Perl_call_sv (sv=0x555555bf6e08, flags=13)
    at perl.c:3077
#13 0x00005555555fc259 in Perl_call_list (oldscope=2, paramList=0x555555bf6e68)
    at perl.c:5148
#14 0x00005555555d1173 in S_process_special_blocks (floor=42, 
    fullname=0x555555c150f0 "\001", gv=0x555555bf6e80, cv=0x555555bf6e08)
    at op.c:12116
#15 0x00005555555d081a in Perl_newATTRSUB_x (floor=42, o=0x555555c00f60, 
    proto=0x0, attrs=0x0, block=0x555555c0eae0, o_is_gv=false) at op.c:12021
#16 0x000055555567b7d8 in Perl_yyparse (gramtype=258) at perly.y:330
#17 0x00005555555f01b5 in S_parse_body (env=0x0, 
    xsinit=0x5555555a31d2 <xs_init>) at perl.c:2556
#18 0x00005555555ee511 in perl_parse (my_perl=0x555555bd02a0, 
    xsinit=0x5555555a31d2 <xs_init>, argc=3, argv=0x7fffffffe7f8, env=0x0)
    at perl.c:1847
#19 0x00005555555a3118 in main (argc=3, argv=0x7fffffffe7f8, 
    env=0x7fffffffe818) at perlmain.c:106

Steps to Reproduce

Expected behavior

No assertion.

Perl configuration

Summary of my perl5 (revision 5 version 37 subversion 1) configuration:
  Commit id: 75111994648b802c88381a3cd338185fd1bbb6fa
  Platform:
    osname=linux
    osvers=5.10.0-14-amd64
    archname=x86_64-linux
    uname='linux venus 5.10.0-14-amd64 #1 smp debian 5.10.113-1 (2022-04-29) x86_64 gnulinux '
    config_args='-des -Dusedevel -DDEBUGGING -Doptimize=-O0 -g'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  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='-O0 -g'
    cppflags='-fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='10.2.1 20210110'
    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/x86_64-linux-gnu /usr/lib /usr/lib64
    libs=-lpthread -lnsl -lgdbm -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.31.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.31'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O0 -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
    PERL_USE_SAFE_PUTENV
    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 Jun 13 2022 14:25:47
  %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.37.1/x86_64-linux
    /usr/local/lib/perl5/site_perl/5.37.1
    /usr/local/lib/perl5/5.37.1/x86_64-linux
    /usr/local/lib/perl5/5.37.1

@jkeenan
Copy link
Contributor

jkeenan commented Jun 21, 2022

Running this code:

use builtin 'ceil';

my $x;
BEGIN {
    my $e = <<'EOS';
sub { ceil($_[0]) }
EOS
    $x = eval $e;
}

in a DEBUGGING build throws:

$ ./perl -Ilib ../ceilassert.pl 
perl: op.c:14769: Perl_find_lexical_cv: Assertion `PARENT_PAD_INDEX(name)' failed.
Aborted

As you might expect, this problem has been present since ceil was added to builtin. The first commit at which I was able to reproduce this was:

commit 17a8df707746ce70979d18c5b5f9e383c365bbff
Author:     James Raspass <[email protected]>
AuthorDate: Sat Jan 22 11:07:58 2022 +0000
Commit:     Paul "LeoNerd" Evans <[email protected]>
CommitDate: Mon Jan 24 00:35:51 2022 +0000

    Add ceil & floor to builtin

@JRaspass @leonerd , can you take a look?

Thank you very much.
Jim Keenan

@tonycoz
Copy link
Contributor Author

tonycoz commented Jun 22, 2022

I expect the problem is with the lexical import mechanism, rather than ceil() itself:

tony@venus:.../git/perl5$ ./perl -Ilib ../19857-import.pl 
perl: op.c:13404: Perl_find_lexical_cv: Assertion `PARENT_PAD_INDEX(name)' failed.
Aborted
tony@venus:.../git/perl5$ cat ../19857-import.pl
use builtin 'is_bool';

my ($x, $y);
BEGIN {
    $x = eval 'is_bool($y)';
}

@tonycoz
Copy link
Contributor Author

tonycoz commented Jun 23, 2022

Worse, it happens with plain lexical subs too:

tony@venus:.../git/perl5$ ./perl -e 'my sub foo {} BEGIN { eval "foo()" }'
perl: op.c:13404: Perl_find_lexical_cv: Assertion `PARENT_PAD_INDEX(name)' failed.
Aborted

@jkeenan
Copy link
Contributor

jkeenan commented Jul 10, 2022

./perl -e 'my sub foo {} BEGIN { eval "foo()" }'

Reproduced in a -DDEBUGGING build on FreeBSD-12:

$ ./perl -e 'my sub foo {} BEGIN { eval "foo()" }'
Assertion failed: (PARENT_PAD_INDEX(name)), function Perl_find_lexical_cv, file op.c, line 13421.
Abort trap (core dumped)

Should we consider making this into a TODO-ed test in the test suite?

@tonycoz
Copy link
Contributor Author

tonycoz commented Aug 24, 2022

We don't need the BEGIN:

$ ./perl -Ilib -le 'use builtin "ceil"; sub foo { eval "ceil(1.5)" or die $@ } foo()'
perl: op.c:13423: Perl_find_lexical_cv: Assertion `PARENT_PAD_INDEX(name)' failed.
Aborted

I have a fix for this assertion which I'll pretty up for a PR.

Of course, normal lexical subs have a different problem, even without eval:

$ ./perl -le 'my sub foo { print "Foo" } BEGIN { foo() }'
Undefined subroutine &foo called at -e line 1.
BEGIN failed--compilation aborted at -e line 1.

which means the normal lexical sub won't be available in BEGIN anyway. This isn't a problem for lexical imports since those set the definition at compile-time.

This happens because normal lexical subs don't actually get a definition until runtime, when the clonecv op is executed:

$ ./perl -Ilib -MO=Concise -le 'my $x; my sub foo { print "Foo" } foo()'
a  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter v ->2
-     <@> lineseq vK ->4
2        <0> introcv[&foo:4,5] v ->3
3        <0> clonecv[&foo:4,5] v ->4
4     <;> nextstate(main 1 -e:1) v:{ ->5
5     <0> padsv[$x:1,5] vM/LVINTRO ->6
6     <;> nextstate(main 5 -e:1) v:{ ->7
9     <1> entersub vKS ->a
-        <1> ex-list K ->9
7           <0> pushmark s ->8
-           <1> ex-rv2cv sK/1 ->-
8              <0> padcv[&foo:4,5] s ->9
-e syntax OK

I expect the fix for that is going to be moving the cloning for the first pad for a function rather than at runtime.

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.

2 participants