php-src/Zend/Optimizer
Niels Dossche 9b86533ce4
Fix GH-19065: Long match statement can segfault compiler during recursive SSA renaming
On some systems, like Alpine, the thread stack size is small by default.
The last step of SSA construction involves variable renaming that is
recursive, and also makes copies of their version of the renamed
variables on the stack. This combination causes a stack overflow during
compilation on Alpine. Triggerable for example with very long match
statements.

A stop-gap solution would be to use heap allocated arrays for the
renamed variable list, but that would only delay the error as increasing
the number of match arms increases the depth of the dominator tree, and
will eventually run into the same issue.

This patch transforms the algorithm into an iterative one.
There are two states stored in a worklist stack: positive numbers
indicate that the block still needs to undergo variable renaming.
Negative numbers indicate that the block and its dominated children are
already renamed. Because 0 is also a valid block number, we bias the
block numbers by adding 1.
To restore to the right variant when backtracking the "recursive" step,
we index into an array pointing to the different variable renaming
variants.

Closes GH-19083.
2025-08-11 23:05:21 +02:00
..
block_pass.c Merge branch 'PHP-8.2' into PHP-8.3 2023-11-01 09:55:37 +03:00
compact_literals.c Fix comp-time and constant evaluation of dynamic class constant fetch 2023-02-02 19:18:17 +01:00
compact_vars.c Fix GH-13817: Segmentation fault for enabled observers after pass 4 2024-07-22 18:28:03 +02:00
dce.c Allow arbitrary expressions in static variable initializer 2023-05-24 20:17:31 +02:00
dfa_pass.c Allow arbitrary expressions in static variable initializer 2023-05-24 20:17:31 +02:00
escape_analysis.c Merge branch 'PHP-8.2' into PHP-8.3 2024-07-19 14:59:44 +02:00
nop_removal.c
optimize_func_calls.c Merge branch 'PHP-8.1' into PHP-8.2 2023-09-07 14:25:43 +02:00
optimize_temp_vars_5.c Fix GH-13817: Segmentation fault for enabled observers after pass 4 2024-07-22 18:28:03 +02:00
pass1.c Fix array to string conversion warning emitted in optimizer 2024-10-14 13:24:05 +02:00
pass3.c
sccp.c [RFC] Path to Saner Increment/Decrement operators (#10358) 2023-07-17 15:51:24 +01:00
scdf.c Revert GH-10279 2023-01-16 12:25:59 +01:00
scdf.h Make various pointers const in Zend/ (#10608) 2023-02-20 14:00:59 +00:00
ssa_integrity.c Merge branch 'PHP-8.2' into PHP-8.3 2023-12-18 13:15:19 +01:00
zend_call_graph.c Revert GH-10279 2023-01-16 12:25:59 +01:00
zend_call_graph.h [ci skip] Add a comment to clarify the value of zend_call_info->num_args (#10812) 2023-03-09 13:00:21 +00:00
zend_cfg.c Fix GH-18107: Opcache CFG jmp optimization with try-finally breaks the exception table 2025-03-21 13:56:31 +01:00
zend_cfg.h Revert GH-10279 2023-01-16 12:25:59 +01:00
zend_dfg.c Allow arbitrary expressions in static variable initializer 2023-05-24 20:17:31 +02:00
zend_dfg.h
zend_dump.c Merge branch 'PHP-8.2' into PHP-8.3 2023-11-03 10:58:32 +03:00
zend_dump.h zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_func_info.c Fix range inference since "proper-range-semantics" RFC 2024-01-17 15:42:17 +01:00
zend_func_info.h
zend_func_infos.h Fix RCN violations in array functions 2025-06-24 23:29:00 +02:00
zend_inference.c Merge branch 'PHP-8.2' into PHP-8.3 2024-10-21 14:51:31 +03:00
zend_inference.h Merge branch 'PHP-8.2' into PHP-8.3 2023-11-03 10:55:33 +03:00
zend_optimizer.c Fix ZEND_MATCH_ERROR misoptimization 2024-12-12 13:10:34 +01:00
zend_optimizer.h Revert GH-10279 2023-01-16 12:25:59 +01:00
zend_optimizer_internal.h zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_ssa.c Fix GH-19065: Long match statement can segfault compiler during recursive SSA renaming 2025-08-11 23:05:21 +02:00
zend_ssa.h Fix clang warning 2023-07-18 00:49:13 +02:00
zend_worklist.h Make various pointers const in Zend/ (#10608) 2023-02-20 14:00:59 +00:00