]> granicus.if.org Git - php/commitdiff
Fix incorrect propagation of ZEND_BOOL in pass 1
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 22 Jul 2017 15:21:48 +0000 (17:21 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 22 Jul 2017 15:23:50 +0000 (17:23 +0200)
BOOL (next to QM_ASSIGN) is one of the opcodes that can assign to
a temporary that is assigned in multiple branches. Pass 1 does
not check for this, so we should not try to handle it at that
point. Block pass and sccp will be able to treat this correctly.

ext/opcache/Optimizer/pass1_5.c
ext/opcache/tests/bool_cp_in_pass1.phpt [new file with mode: 0644]

index 5374a1887e404d88d18efb45371ea696d2ebe7e6..7697fb19433094ec26131f380be6078391bdab2f 100644 (file)
@@ -115,7 +115,6 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
 
                case ZEND_BW_NOT:
                case ZEND_BOOL_NOT:
-               case ZEND_BOOL:
                        if (opline->op1_type == IS_CONST) {
                                /* unary operation on constant operand */
                                zval result;
diff --git a/ext/opcache/tests/bool_cp_in_pass1.phpt b/ext/opcache/tests/bool_cp_in_pass1.phpt
new file mode 100644 (file)
index 0000000..3857c4d
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Incorrect constant propagation on BOOL in pass 1
+--FILE--
+<?php
+function test($foo) {
+    $bar = 0;
+    if ($bar === 1 && $foo && PHP_SAPI !== 'cgi') {
+        echo "bar\n";
+    }
+    echo "foo\n";
+}
+test(1);
+?>
+--EXPECT--
+foo