]> granicus.if.org Git - php/commitdiff
Fixed bug #79888 (Incorrect execution with JIT enabled)
authorDmitry Stogov <dmitry@zend.com>
Wed, 29 Jul 2020 14:32:57 +0000 (17:32 +0300)
committerDmitry Stogov <dmitry@zend.com>
Wed, 29 Jul 2020 14:32:57 +0000 (17:32 +0300)
NEWS
ext/opcache/jit/zend_jit_x86.dasc
ext/opcache/tests/jit/bug79888.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 220f1890ac2fc8b1d920357977d2722c9c2476b1..e64b2efad818d44247f2472611ce7a2115d6ca5b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ PHP                                                                        NEWS
 
 - JIT:
   . Fixed bug #79864 (JIT segfault in Symfony OptionsResolver). (Dmitry)
+  . Fixed bug #79888 (Incorrect execution with JIT enabled). (Dmitry)
 
 - LDAP:
   . Fixed memory leaks. (ptomulik)
index a63db2ad9ae4ce1221dfbbf4c29696d0116a994a..d18c3ca2eca7af8fc4f2087997151b3d4ff39fef 100644 (file)
@@ -12576,7 +12576,10 @@ static zend_regset zend_jit_get_scratch_regset(const zend_op *opline, const zend
                                        }
                                } else {
                                        ZEND_REGSET_INCL(regset, ZREG_R0);
-                                       ZEND_REGSET_INCL(regset, ZREG_R1);
+                                       ZEND_REGSET_INCL(regset, ZREG_R2);
+                                       if (opline->op2_type == IS_CONST) {
+                                               ZEND_REGSET_INCL(regset, ZREG_R1);
+                                       }
                                }
                        }
                        break;
diff --git a/ext/opcache/tests/jit/bug79888.phpt b/ext/opcache/tests/jit/bug79888.phpt
new file mode 100644 (file)
index 0000000..02d4b62
--- /dev/null
@@ -0,0 +1,38 @@
+--TEST--
+Bug #79888 (Incorrect execution with JIT enabled)
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.file_update_protection=0
+opcache.jit_buffer_size=64
+opcache.jit=1205
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+function testPrime(int $a): bool {
+    if ($a < 2)  {
+        return false;
+    } else if ($a == 2) {
+        return true;
+    }
+    for ($j = 2; $j < $a; $j++) {
+        if (($a % $j) == 0) {
+            return false;
+        }
+    }
+    return true;
+}
+
+$max = 1000;
+$cnt = 0;
+echo "Testing Primes until: " . $max . "\n";
+for ($i = 2; $i <= $max; $i++)
+{
+        if (testPrime($i)) $cnt++;
+}
+echo "Primect: {$cnt}\n";
+?>
+--EXPECT--
+Testing Primes until: 1000
+Primect: 168