]> granicus.if.org Git - php/commitdiff
Fix CE fetching for NEW object type inference
authorNikita Popov <nikic@php.net>
Thu, 7 Jan 2016 17:47:18 +0000 (18:47 +0100)
committerNikita Popov <nikic@php.net>
Thu, 7 Jan 2016 17:53:10 +0000 (18:53 +0100)
Create a common function for getting a class entry.

ext/opcache/Optimizer/zend_inference.c

index f87f6f529bcfe68582b567d105d6351df6d71d0b..6bc7fb7a5364c98200070e945c5be2e6fdfd6cec 100644 (file)
@@ -2174,6 +2174,20 @@ uint32_t zend_array_element_type(uint32_t t1, int write, int insert)
        return tmp;
 }
 
+static inline zend_class_entry *get_class_entry(const zend_script *script, zend_string *lcname) {
+       zend_class_entry *ce = zend_hash_find_ptr(&script->class_table, lcname);
+       if (ce) {
+               return ce;
+       }
+
+       ce = zend_hash_find_ptr(CG(class_table), lcname);
+       if (ce && ce->type == ZEND_INTERNAL_CLASS) {
+               return ce;
+       }
+
+       return NULL;
+}
+
 static void zend_update_type_info(const zend_op_array *op_array,
                                   zend_ssa            *ssa,
                                   const zend_script   *script,
@@ -3114,13 +3128,7 @@ static void zend_update_type_info(const zend_op_array *op_array,
                                        // class type hinting...
                                        zend_string *lcname = zend_string_tolower(arg_info->class_name);
                                        tmp |= MAY_BE_OBJECT;
-                                       ce = zend_hash_find_ptr(&script->class_table, lcname);
-                                       if (!ce) {
-                                               ce = zend_hash_find_ptr(CG(class_table), lcname);
-                                               if (ce && ce->type != ZEND_INTERNAL_CLASS) {
-                                                       ce = NULL;
-                                               }
-                                       }
+                                       ce = get_class_entry(script, lcname);
                                        zend_string_release(lcname);
                                } else if (arg_info->type_hint != IS_UNDEF) {
                                        if (arg_info->type_hint == IS_CALLABLE) {
@@ -3221,14 +3229,8 @@ static void zend_update_type_info(const zend_op_array *op_array,
                        } else if (opline->op2_type == IS_CONST) {
                                zval *zv = CRT_CONSTANT_EX(op_array, opline->op2, ssa->rt_constants);
                                if (Z_TYPE_P(zv) == IS_STRING) {
-                                       if ((ce = zend_hash_find_ptr(&script->class_table, Z_STR_P(zv+1))) != NULL) {
-                                               UPDATE_SSA_OBJ_TYPE(ce, 0, ssa_ops[i].result_def);
-                                       } else if ((ce = zend_hash_find_ptr(CG(class_table), Z_STR_P(zv+1))) != NULL &&
-                                                  ce->type == ZEND_INTERNAL_CLASS) {
-                                               UPDATE_SSA_OBJ_TYPE(ce, 0, ssa_ops[i].result_def);
-                                       } else {
-                                               UPDATE_SSA_OBJ_TYPE(NULL, 0, ssa_ops[i].result_def);
-                                       }
+                                       ce = get_class_entry(script, Z_STR_P(zv+1));
+                                       UPDATE_SSA_OBJ_TYPE(ce, 0, ssa_ops[i].result_def);
                                } else {
                                        UPDATE_SSA_OBJ_TYPE(NULL, 0, ssa_ops[i].result_def);
                                }
@@ -3243,7 +3245,7 @@ static void zend_update_type_info(const zend_op_array *op_array,
                case ZEND_NEW:
                        tmp = MAY_BE_RC1|MAY_BE_RCN|MAY_BE_OBJECT;
                        if (opline->op1_type == IS_CONST &&
-                           (ce = zend_hash_find_ptr(CG(class_table), Z_STR_P(CRT_CONSTANT_EX(op_array, opline->op1, ssa->rt_constants)+1))) != NULL) {
+                           (ce = get_class_entry(script, Z_STR_P(CRT_CONSTANT_EX(op_array, opline->op1, ssa->rt_constants)+1))) != NULL) {
                                UPDATE_SSA_OBJ_TYPE(ce, 0, ssa_ops[i].result_def);
                        } else if ((t1 & MAY_BE_CLASS) && ssa_ops[i].op1_use >= 0 && ssa_var_info[ssa_ops[i].op1_use].ce) {
                                UPDATE_SSA_OBJ_TYPE(ssa_var_info[ssa_ops[i].op1_use].ce, ssa_var_info[ssa_ops[i].op1_use].is_instanceof, ssa_ops[i].result_def);