Generate ZEND_COUNT for sizeof()

sizeof() is an alias of count(), so we should generate the same
code for them.
This commit is contained in:
Nikita Popov 2019-04-11 10:48:52 +02:00
parent b213f13a26
commit 30df87f77d
3 changed files with 13 additions and 9 deletions

View file

@ -3551,16 +3551,19 @@ static int zend_compile_func_in_array(znode *result, zend_ast_list *args) /* {{{
}
/* }}} */
int zend_compile_func_count(znode *result, zend_ast_list *args) /* {{{ */
int zend_compile_func_count(znode *result, zend_ast_list *args, zend_string *lcname) /* {{{ */
{
znode arg_node;
zend_op *opline;
if (args->children != 1) {
return FAILURE;
}
zend_compile_expr(&arg_node, args->child[0]);
zend_emit_op_tmp(result, ZEND_COUNT, &arg_node, NULL);
opline = zend_emit_op_tmp(result, ZEND_COUNT, &arg_node, NULL);
opline->extended_value = zend_string_equals_literal(lcname, "sizeof");
return SUCCESS;
}
/* }}} */
@ -3739,8 +3742,9 @@ int zend_try_compile_special_func(znode *result, zend_string *lcname, zend_ast_l
return zend_compile_func_cuf(result, args, lcname);
} else if (zend_string_equals_literal(lcname, "in_array")) {
return zend_compile_func_in_array(result, args);
} else if (zend_string_equals_literal(lcname, "count")) {
return zend_compile_func_count(result, args);
} else if (zend_string_equals_literal(lcname, "count")
|| zend_string_equals_literal(lcname, "sizeof")) {
return zend_compile_func_count(result, args, lcname);
} else if (zend_string_equals_literal(lcname, "get_class")) {
return zend_compile_func_get_class(result, args);
} else if (zend_string_equals_literal(lcname, "get_called_class")) {

View file

@ -8379,7 +8379,7 @@ ZEND_VM_COLD_CONST_HANDLER(190, ZEND_COUNT, CONST|TMP|VAR|CV, UNUSED)
} else {
count = 1;
}
zend_error(E_WARNING, "count(): Parameter must be an array or an object that implements Countable");
zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count");
} while (0);
ZVAL_LONG(EX_VAR(opline->result.var), count);

View file

@ -9588,7 +9588,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CONST_
} else {
count = 1;
}
zend_error(E_WARNING, "count(): Parameter must be an array or an object that implements Countable");
zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count");
} while (0);
ZVAL_LONG(EX_VAR(opline->result.var), count);
@ -20293,7 +20293,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_TMP_UNUSED_HANDLER(
} else {
count = 1;
}
zend_error(E_WARNING, "count(): Parameter must be an array or an object that implements Countable");
zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count");
} while (0);
ZVAL_LONG(EX_VAR(opline->result.var), count);
@ -29522,7 +29522,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_VAR_UNUSED_HANDLER(
} else {
count = 1;
}
zend_error(E_WARNING, "count(): Parameter must be an array or an object that implements Countable");
zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count");
} while (0);
ZVAL_LONG(EX_VAR(opline->result.var), count);
@ -50779,7 +50779,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CV_UNUSED_HANDLER(Z
} else {
count = 1;
}
zend_error(E_WARNING, "count(): Parameter must be an array or an object that implements Countable");
zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count");
} while (0);
ZVAL_LONG(EX_VAR(opline->result.var), count);