-
Notifications
You must be signed in to change notification settings - Fork 561
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
crash with no warnings 'uninitialized'
and chained comparsion
#18380
Comments
This looks like a bug the way chained comparisons are handled which breaks constant folding. The code at op.c:5598 constant folds the right-hand part of the chain. The full op tree for the chained op looks like:
but it's just the:
being passed to fold_constants() in this case. This code underflows the stack, since with this isolated tree there's no left op for the lt op:
This is harmless for the first statement since we keep a This only happens with the |
I'm pretty sure #17917 has the same cause. |
This also has the consequence that chained comparisons aren't constant folded at all.: The original with &&
With chained operators:
|
This code would try to constant fold an op tree like relop +- null +- constant which would underflow the stack, potentially crashing perl. This is intended as a quick fix rather than as a complete solution. Fixes Perl#18380
I have a simple "fix" in #18390, but what would be a complete fix? A complete fix would need to:
I can see two possible solutions. 1. Build a normal op tree and optimize it in a ck functionRight now the grammar generates an op tree like:
which cmpchain_finish() massages into:
Instead, generate an optree like the equivalent pre-chain code might use:
which fold_constants() can already fold. For chain purposes the ops generated would need flags to indicate they were chained ops in terms of syntax. I expect any constant folding would have been done before we reach the ck function. The ck function would then need to transform that into the cmpchain form above. 2. Add specialized constant folding for cmpchainThe grammar generates an optree like:
Since we only need to resolve relative ops, we could lift the checks from fold_constants(), ie. that we're not doing locale sensitive comparisons, and that all of the operands are constants (2 and 4 for the first, 4 and 6 for the second), and build a new optree to pass to fold_constants() to attempt the fold. Both options will require some care in handling constant folded comparisons at different places in the chain. |
This code would try to constant fold an op tree like relop +- null +- constant which would underflow the stack, potentially crashing perl. This is intended as a quick fix rather than as a complete solution. Fixes #18380
Module: warnings
Description
Segfault
Steps to Reproduce
Expected behavior
Exit with code 0.
Perl configuration
The text was updated successfully, but these errors were encountered: