Skip to content

Commit 526344a

Browse files
committed
Add flag to disable jumptable optimization
This is useful for coverage. While it is currently safe to just skip over the SWITCH_* opcodes, this may not be true in the future due to opcache optimizations, so it's safer to disable emission of SWITCH_* opcodes entirely.
1 parent 66d7237 commit 526344a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Zend/zend_compile.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4907,6 +4907,10 @@ static zend_uchar determine_switch_jumptable_type(zend_ast_list *cases) {
49074907
}
49084908

49094909
static zend_bool should_use_jumptable(zend_ast_list *cases, zend_uchar jumptable_type) {
4910+
if (CG(compiler_options) & ZEND_COMPILE_NO_JUMPTABLES) {
4911+
return 0;
4912+
}
4913+
49104914
/* Thresholds are chosen based on when the average switch time for equidistributed
49114915
* input becomes smaller when using the jumptable optimization. */
49124916
if (jumptable_type == IS_LONG) {

Zend/zend_compile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,9 @@ END_EXTERN_C()
10401040
/* disable builtin special case function calls */
10411041
#define ZEND_COMPILE_NO_BUILTINS (1<<10)
10421042

1043+
/* disable jumptable optimization for switch statements */
1044+
#define ZEND_COMPILE_NO_JUMPTABLES (1<<11)
1045+
10431046
/* The default value for CG(compiler_options) */
10441047
#define ZEND_COMPILE_DEFAULT ZEND_COMPILE_HANDLE_OP_ARRAY
10451048

0 commit comments

Comments
 (0)