]> granicus.if.org Git - php/commitdiff
Revert "Revert "Expand optimizations regarding short-circuting a bit""
authorBob Weinand <bobwei9@hotmail.com>
Sun, 14 Jun 2015 13:46:11 +0000 (15:46 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Sun, 14 Jun 2015 13:46:11 +0000 (15:46 +0200)
This reverts commit 3770a5ac666cdd4ff4803743232125948140450b.
Fixes the bug which probably made make install fail on travis
(It never happened to me that all tests passed, but make install failed...)

Zend/tests/assert/expect_015.phpt
Zend/zend_compile.c

index 80f1bd8aa812a4058812d445111818513a93ade3..030913f7f9ce288d04aa6b753b0cdd8a49290978 100644 (file)
@@ -144,12 +144,6 @@ assert(0 && ($a = function () {
 
 ?>
 --EXPECTF--
-Warning: Unsupported declare 'A' in %sexpect_015.php on line %d
-
-Warning: Unsupported declare 'B' in %sexpect_015.php on line %d
-
-Warning: Unsupported declare 'C' in %sexpect_015.php on line %d
-
 Warning: assert(): assert(0 && ($a = function () {
     global $a;
     global $$b;
index f753af4483a4ebf31f45256e083c964322af8d32..2cb76a7618df106e54ff3413d90b81803da45fb5 100644 (file)
@@ -5840,32 +5840,66 @@ void zend_compile_short_circuiting(znode *result, zend_ast *ast) /* {{{ */
 
        zend_compile_expr(&left_node, left_ast);
 
+       if (left_node.op_type == IS_CONST) {
+               if (
+                      (ast->kind == ZEND_AST_AND && !zend_is_true(&left_node.u.constant))
+                   || (ast->kind == ZEND_AST_OR && zend_is_true(&left_node.u.constant))
+               ) {
+                       result->op_type = IS_CONST;
+                       ZVAL_BOOL(&result->u.constant, zend_is_true(&left_node.u.constant));
+               } else {
+                       zend_compile_expr(&right_node, right_ast);
+
+                       if (right_node.op_type == IS_CONST) {
+                               result->op_type = IS_CONST;
+                               ZVAL_BOOL(&result->u.constant, zend_is_true(&right_node.u.constant));
+
+                               zval_ptr_dtor(&right_node.u.constant);
+                       } else {
+                               zend_emit_op(result, ZEND_BOOL, &right_node, NULL);
+                       }
+               }
+
+               zval_ptr_dtor(&left_node.u.constant);
+               return;
+       }
+
        opnum_jmpz = get_next_op_number(CG(active_op_array));
        opline_jmpz = zend_emit_op(NULL, ast->kind == ZEND_AST_AND ? ZEND_JMPZ_EX : ZEND_JMPNZ_EX,
                &left_node, NULL);
 
        if (left_node.op_type == IS_TMP_VAR) {
                SET_NODE(opline_jmpz->result, &left_node);
-       } else {
+       }
+       if (left_node.op_type != IS_TMP_VAR) {
                opline_jmpz->result.var = get_temporary_variable(CG(active_op_array));
                opline_jmpz->result_type = IS_TMP_VAR;
        }
-       GET_NODE(result, opline_jmpz->result);
 
        zend_compile_expr(&right_node, right_ast);
 
-       if (right_node.op_type == IS_CONST && (
-              (ast->kind == ZEND_AST_AND && !zend_is_true(&right_node.u.constant))
-           || (ast->kind == ZEND_AST_OR && zend_is_true(&right_node.u.constant))
-       )) {
-               result->op_type = IS_CONST;
-               ZVAL_BOOL(&result->u.constant, zend_is_true(&right_node.u.constant));
+       if (right_node.op_type == IS_CONST && opnum_jmpz == CG(active_op_array)->last) {
+               if (
+                      (ast->kind == ZEND_AST_AND && !zend_is_true(&right_node.u.constant))
+                   || (ast->kind == ZEND_AST_OR && zend_is_true(&right_node.u.constant))
+               ) {
+                       CG(active_op_array)->last--;
+                       result->op_type = IS_CONST;
+                       ZVAL_BOOL(&result->u.constant, zend_is_true(&right_node.u.constant));
+               } else {
+                       opline_jmpz->opcode = ZEND_BOOL;
+                       zend_make_var_result(result, opline_jmpz);
+               }
+
                zval_ptr_dtor(&right_node.u.constant);
-       } else {
-               opline_bool = zend_emit_op(NULL, ZEND_BOOL, &right_node, NULL);
-               SET_NODE(opline_bool->result, result);
+               return;
        }
 
+       GET_NODE(result, opline_jmpz->result);
+
+       opline_bool = zend_emit_op(NULL, ZEND_BOOL, &right_node, NULL);
+       SET_NODE(opline_bool->result, result);
+
        zend_update_jump_target_to_next(opnum_jmpz);
 }
 /* }}} */