]> granicus.if.org Git - php/commitdiff
Add flag to disable jumptable optimization
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 24 Jan 2019 09:56:04 +0000 (10:56 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 24 Jan 2019 09:56:04 +0000 (10:56 +0100)
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.

Zend/zend_compile.c
Zend/zend_compile.h

index d91b656182f4a4738a8835b7cafdd8ac737d2d60..28336130ccbf9c19ed066f2d47c0efde792b0925 100644 (file)
@@ -4907,6 +4907,10 @@ static zend_uchar determine_switch_jumptable_type(zend_ast_list *cases) {
 }
 
 static zend_bool should_use_jumptable(zend_ast_list *cases, zend_uchar jumptable_type) {
+       if (CG(compiler_options) & ZEND_COMPILE_NO_JUMPTABLES) {
+               return 0;
+       }
+
        /* Thresholds are chosen based on when the average switch time for equidistributed
         * input becomes smaller when using the jumptable optimization. */
        if (jumptable_type == IS_LONG) {
index b9345e43840309bf97b43d3871e3da8d865fece8..47430576ec11079d7b74ab62d3b8fbab0757c2a0 100644 (file)
@@ -1040,6 +1040,9 @@ END_EXTERN_C()
 /* disable builtin special case function calls */
 #define ZEND_COMPILE_NO_BUILTINS                               (1<<10)
 
+/* disable jumptable optimization for switch statements */
+#define ZEND_COMPILE_NO_JUMPTABLES                             (1<<11)
+
 /* The default value for CG(compiler_options) */
 #define ZEND_COMPILE_DEFAULT                                   ZEND_COMPILE_HANDLE_OP_ARRAY