Skip to content

newFOROP: fix crash when optimizing 2-var for over builtin::indexed #23429

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

Open
wants to merge 3 commits into
base: blead
Choose a base branch
from

Conversation

mauke
Copy link
Contributor

@mauke mauke commented Jul 11, 2025

OP_ENTERSUB isn't necessarily a LISTOP, apparently, so we can't just grab its op_last. Instead, copy/paste logic from elsewhere in op.c to find the cvop.

Also, avoid crashing on "fake" pad entries that represent lexical subs from outer scopes by climbing up the scope chain until we reach a real pad entry.

Fixes #23405.


  • This set of changes requires a perldelta entry, and it is included.

@mauke mauke requested a review from leonerd July 11, 2025 07:14
@mauke mauke force-pushed the fix-23405-segfault-for branch from f5e4805 to 1731242 Compare July 12, 2025 22:12
@jkeenan
Copy link
Contributor

jkeenan commented Jul 13, 2025

When I apply the changes in the two test files to blead, configure and build, then run the two test files, they FAIL with segfaults. When I then apply the code changes, the test files PASS. So from a TDD perspective, this p.r. is good. Someone else will have to look at the concept and the C-code.

Comment on lines +701 to +705
use builtin qw(
blessed
ceil
false
floor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the changes in this file seem like they belong in a separate commit - they have nothing to do with fixing the builtin::indexed optimization

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The builtin::indexed optimization works fine on builtin::indexed(...), but may crash on use builtin qw(indexed); ... indexed(...) because the call optrees look different. I wanted to make sure both cases are optimized correctly (for all builtins).

This change is now a separate commit.

mauke added 3 commits July 17, 2025 07:24
OP_ENTERSUB isn't necessarily a LISTOP, apparently, so we can't just
grab its op_last. Instead, copy/paste logic from elsewhere in op.c to
find the cvop.

Also, avoid crashing on "fake" pad entries that represent lexical subs
from outer scopes by climbing up the scope chain until we reach a real
pad entry.

Fixes Perl#23405.
When I saw (in Perl#23429) that

    use builtin qw(indexed);
    sub { for my ($x, $y) (indexed) {} }

crashes, but

    sub { for my ($x, $y) (builtin::indexed) {} }

works fine, I realized that optrees for calls to lexically imported subs
look different from calls to package subs.

This commit make sure both call variants are optimized to direct ops.
@mauke mauke force-pushed the fix-23405-segfault-for branch from 1731242 to 8eda65e Compare July 17, 2025 05:26
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 this pull request may close these issues.

Perl 5.42 segfault during compilation
3 participants