]> granicus.if.org Git - php/commitdiff
Fixed SCCP rewinding on partial_array|object phi
authorXinchen Hui <laruence@gmail.com>
Sat, 2 Sep 2017 13:28:33 +0000 (21:28 +0800)
committerXinchen Hui <laruence@gmail.com>
Sat, 2 Sep 2017 13:28:33 +0000 (21:28 +0800)
ext/opcache/Optimizer/sccp.c
ext/opcache/tests/opt/sccp_013.phpt
ext/opcache/tests/opt/sccp_014.phpt
ext/opcache/tests/opt/sccp_015.phpt [new file with mode: 0644]

index 991a5010830b0b9ba465e9647d893277bef8d474..a0ed22e9d7365da5b3abd52db07e02f04a55c371 100644 (file)
@@ -146,9 +146,12 @@ static void set_value(scdf_ctx *scdf, sccp_ctx *ctx, int var, zval *new) {
 
        /* Always replace PARTIAL_(ARRAY|OBJECT), as new maybe changed by join_partial_(arrays|object) */
        if (IS_PARTIAL_ARRAY(new) || IS_PARTIAL_OBJECT(new)) {
-               zval_ptr_dtor_nogc(value);
-               ZVAL_COPY(value, new);
-               /*?? scdf_add_to_worklist(scdf, var); */
+               if (Z_TYPE_P(value) != Z_TYPE_P(new)
+                       || zend_hash_num_elements(Z_ARR_P(new)) != zend_hash_num_elements(Z_ARR_P(value))) {
+                       zval_ptr_dtor_nogc(value);
+                       ZVAL_COPY(value, new);
+                       scdf_add_to_worklist(scdf, var);
+               }
                return;
        }
 
index 052e92ff2c175462072ce1ce2c476c88f4cf6e61..d421743e18c0a77d00f66c59fecfd524d5fe09fe 100644 (file)
@@ -17,5 +17,6 @@ function loadEntities($entity_information) {
 }
 
 loadEntities(array("first", "second")); 
+?>
 --EXPECT--
 bool(true)
index 0e5ccd032c50b47b21766387d5aa0850c41d71a1..ffa9dc3baf081fe9a7741d2030fdf79201b61514 100644 (file)
@@ -18,5 +18,6 @@ function loadEntities($entity_information) {
 }
 
 loadEntities(array("first", "second")); 
+?>
 --EXPECT--
 bool(false)
diff --git a/ext/opcache/tests/opt/sccp_015.phpt b/ext/opcache/tests/opt/sccp_015.phpt
new file mode 100644 (file)
index 0000000..ce53a97
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+SCCP 013: Conditional Constant Propagation of non-escaping object properties on PHI and Rewinding
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+function loadEntities($entity_information) {
+       $entity_types = new StdClass();
+       $entity_types->b = 0;
+       foreach ($entity_information as $ex) {
+               var_dump((bool)$entity_types->b);
+               foreach ($entity_information as $info) {
+                       $entity_types->b = 1;
+               }
+       }
+}
+
+loadEntities(array("first", "second")); 
+?>
+--EXPECT--
+bool(false)
+bool(true)