]> granicus.if.org Git - php/commitdiff
JIT: Fix SWITCH_LONG/STRING codegen with exact type
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 28 May 2019 13:25:19 +0000 (15:25 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 28 May 2019 13:25:19 +0000 (15:25 +0200)
We were not loading the operand if the type was known exactly.

ext/opcache/jit/zend_jit_x86.dasc
ext/opcache/tests/jit/switch_jumptable.phpt [new file with mode: 0644]

index 1cd59ffc860744ecad15e01cbf6755904b5e39cd..d74a350bf65d18ebea5eaf14a8c65acaa36b30bf 100644 (file)
@@ -9968,8 +9968,10 @@ static int zend_jit_switch(dasm_State **Dst, const zend_op *opline, zend_op_arra
                                        |       jmp >2
                                        |.code
                                        |2:
-                               } else if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)) {
-                                       |       IF_NOT_ZVAL_TYPE op1_addr, IS_LONG, >3
+                               } else {
+                                       if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)) {
+                                               |       IF_NOT_ZVAL_TYPE op1_addr, IS_LONG, >3
+                                       }
                                        |       GET_ZVAL_LVAL ZREG_FCARG2a, op1_addr
                                }
                                if (HT_IS_PACKED(jumptable)) {
@@ -10050,8 +10052,10 @@ static int zend_jit_switch(dasm_State **Dst, const zend_op *opline, zend_op_arra
                                        |       jmp >2
                                        |.code
                                        |2:
-                               } else if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_STRING)) {
-                                       |       IF_NOT_ZVAL_TYPE op1_addr, IS_STRING, >3
+                               } else {
+                                       if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_STRING)) {
+                                               |       IF_NOT_ZVAL_TYPE op1_addr, IS_STRING, >3
+                                       }
                                        |       GET_ZVAL_PTR FCARG2a, op1_addr
                                }
                                |       LOAD_ADDR FCARG1a, jumptable
diff --git a/ext/opcache/tests/jit/switch_jumptable.phpt b/ext/opcache/tests/jit/switch_jumptable.phpt
new file mode 100644 (file)
index 0000000..80df4ac
--- /dev/null
@@ -0,0 +1,38 @@
+--TEST--
+Switch jumptable generation
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.file_update_protection=0
+opcache.jit_buffer_size=1M
+--FILE--
+<?php
+
+function test1(string $val) {
+    switch ($val) {
+        case 'str1':
+        case 'str2':
+            echo "correct\n";
+            return;
+    }
+    echo "wrong\n";
+}
+function test2(int $val) {
+    switch ($val) {
+        case 1:
+        case 2:
+        case 3:
+        case 4:
+        case 5:
+            echo "correct\n";
+            return;
+    }
+    echo "wrong\n";
+}
+test1("str1");
+test2(1);
+
+?>
+--EXPECT--
+correct
+correct