Skip to content

Remove UNEXPECTED from typed property checks #13143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properti
(property_info->flags & ZEND_ACC_STATIC) == 0) {
zval *slot = OBJ_PROP(object, property_info->offset);

if (UNEXPECTED(ZEND_TYPE_IS_SET(property_info->type))) {
if (ZEND_TYPE_IS_SET(property_info->type)) {
zval tmp;

ZVAL_COPY_VALUE(&tmp, prop);
Expand Down
12 changes: 6 additions & 6 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1999,7 +1999,7 @@ static void zend_pre_incdec_property_zval(zval *prop, zend_property_info *prop_i
} else {
fast_long_decrement_function(prop);
}
if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && UNEXPECTED(prop_info)
if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && prop_info
&& !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
zend_long val = zend_throw_incdec_prop_error(prop_info OPLINE_CC);
ZVAL_LONG(prop, val);
Expand All @@ -2015,7 +2015,7 @@ static void zend_pre_incdec_property_zval(zval *prop, zend_property_info *prop_i
}
}

if (UNEXPECTED(prop_info)) {
if (prop_info) {
zend_incdec_typed_prop(prop_info, prop, NULL OPLINE_CC EXECUTE_DATA_CC);
} else if (ZEND_IS_INCREMENT(opline->opcode)) {
increment_function(prop);
Expand All @@ -2038,7 +2038,7 @@ static void zend_post_incdec_property_zval(zval *prop, zend_property_info *prop_
} else {
fast_long_decrement_function(prop);
}
if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && UNEXPECTED(prop_info)
if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && prop_info
&& !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
zend_long val = zend_throw_incdec_prop_error(prop_info OPLINE_CC);
ZVAL_LONG(prop, val);
Expand All @@ -2053,7 +2053,7 @@ static void zend_post_incdec_property_zval(zval *prop, zend_property_info *prop_
}
}

if (UNEXPECTED(prop_info)) {
if (prop_info) {
zend_incdec_typed_prop(prop_info, prop, EX_VAR(opline->result.var) OPLINE_CC EXECUTE_DATA_CC);
} else {
ZVAL_COPY(EX_VAR(opline->result.var), prop);
Expand Down Expand Up @@ -3309,7 +3309,7 @@ static zend_always_inline void zend_assign_to_property_reference(zval *container
prop_info = zend_object_fetch_property_type_info(Z_OBJ_P(container), variable_ptr);
}

if (UNEXPECTED(prop_info)) {
if (prop_info) {
variable_ptr = zend_assign_to_typed_property_reference(prop_info, variable_ptr, value_ptr, &garbage EXECUTE_DATA_CC);
} else {
zend_assign_to_variable_reference(variable_ptr, value_ptr, &garbage);
Expand Down Expand Up @@ -3441,7 +3441,7 @@ static zend_always_inline zend_result zend_fetch_static_property_address(zval **

if ((fetch_type == BP_VAR_R || fetch_type == BP_VAR_RW)
&& UNEXPECTED(Z_TYPE_P(*retval) == IS_UNDEF)
&& UNEXPECTED(ZEND_TYPE_IS_SET(property_info->type))) {
&& ZEND_TYPE_IS_SET(property_info->type)) {
zend_throw_error(NULL, "Typed static property %s::$%s must not be accessed before initialization",
ZSTR_VAL(property_info->ce->name),
zend_get_unmangled_property_name(property_info->name));
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ static void do_inherit_property(zend_property_info *parent_info, zend_string *ke
child_info->offset = parent_info->offset;
}

if (UNEXPECTED(ZEND_TYPE_IS_SET(parent_info->type))) {
if (ZEND_TYPE_IS_SET(parent_info->type)) {
inheritance_status status = property_types_compatible(parent_info, child_info);
if (status == INHERITANCE_ERROR) {
emit_incompatible_property_error(child_info, parent_info);
Expand Down Expand Up @@ -1751,7 +1751,7 @@ static bool do_inherit_constant_check(
);
}

if (!(ZEND_CLASS_CONST_FLAGS(parent_constant) & ZEND_ACC_PRIVATE) && UNEXPECTED(ZEND_TYPE_IS_SET(parent_constant->type))) {
if (!(ZEND_CLASS_CONST_FLAGS(parent_constant) & ZEND_ACC_PRIVATE) && ZEND_TYPE_IS_SET(parent_constant->type)) {
inheritance_status status = class_constant_types_compatible(parent_constant, child_constant);
if (status == INHERITANCE_ERROR) {
emit_incompatible_class_constant_error(child_constant, parent_constant, name);
Expand Down
10 changes: 5 additions & 5 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ ZEND_API zval *zend_std_read_property(zend_object *zobj, zend_string *name, int
retval = &EG(uninitialized_zval);
}

if (UNEXPECTED(prop_info)) {
if (prop_info) {
zend_verify_prop_assignable_by_ref_ex(prop_info, retval, (zobj->ce->__get->common.fn_flags & ZEND_ACC_STRICT_TYPES) != 0, ZEND_VERIFY_PROP_ASSIGNABLE_BY_REF_CONTEXT_MAGIC_GET);
}

Expand All @@ -758,7 +758,7 @@ ZEND_API zval *zend_std_read_property(zend_object *zobj, zend_string *name, int

uninit_error:
if (type != BP_VAR_IS) {
if (UNEXPECTED(prop_info)) {
if (prop_info) {
zend_throw_error(NULL, "Typed property %s::$%s must not be accessed before initialization",
ZSTR_VAL(prop_info->ce->name),
ZSTR_VAL(name));
Expand Down Expand Up @@ -826,7 +826,7 @@ ZEND_API zval *zend_std_write_property(zend_object *zobj, zend_string *name, zva
if (Z_TYPE_P(variable_ptr) != IS_UNDEF) {
Z_TRY_ADDREF_P(value);

if (UNEXPECTED(prop_info)) {
if (prop_info) {
if (UNEXPECTED((prop_info->flags & ZEND_ACC_READONLY) && !(Z_PROP_FLAG_P(variable_ptr) & IS_PROP_REINITABLE))) {
Z_TRY_DELREF_P(value);
zend_readonly_property_modification_error(prop_info);
Expand Down Expand Up @@ -929,7 +929,7 @@ found:;
variable_ptr = OBJ_PROP(zobj, property_offset);

Z_TRY_ADDREF_P(value);
if (UNEXPECTED(prop_info)) {
if (prop_info) {
if (UNEXPECTED((prop_info->flags & ZEND_ACC_READONLY)
&& !verify_readonly_initialization_access(prop_info, zobj->ce, name, "initialize"))) {
Z_TRY_DELREF_P(value);
Expand Down Expand Up @@ -1110,7 +1110,7 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *nam
UNEXPECTED((*zend_get_property_guard(zobj, name)) & IN_GET) ||
UNEXPECTED(prop_info && (Z_PROP_FLAG_P(retval) & IS_PROP_UNINIT))) {
if (UNEXPECTED(type == BP_VAR_RW || type == BP_VAR_R)) {
if (UNEXPECTED(prop_info)) {
if (prop_info) {
zend_throw_error(NULL,
"Typed property %s::$%s must not be accessed before initialization",
ZSTR_VAL(prop_info->ce->name),
Expand Down
16 changes: 8 additions & 8 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ ZEND_VM_C_LABEL(assign_op_object):
} else {
prop_info = zend_object_fetch_property_type_info(Z_OBJ_P(object), orig_zptr);
}
if (UNEXPECTED(prop_info)) {
if (prop_info) {
/* special case for typed properties */
zend_binary_assign_op_typed_prop(prop_info, zptr, value OPLINE_CC EXECUTE_DATA_CC);
} else {
Expand Down Expand Up @@ -1131,7 +1131,7 @@ ZEND_VM_HANDLER(29, ZEND_ASSIGN_STATIC_PROP_OP, ANY, ANY, OP)
}
}

if (UNEXPECTED(ZEND_TYPE_IS_SET(prop_info->type))) {
if (ZEND_TYPE_IS_SET(prop_info->type)) {
/* special case for typed properties */
zend_binary_assign_op_typed_prop(prop_info, prop, value OPLINE_CC EXECUTE_DATA_CC);
} else {
Expand Down Expand Up @@ -2417,7 +2417,7 @@ ZEND_VM_C_LABEL(assign_object):
if (Z_TYPE_P(property_val) != IS_UNDEF) {
zend_property_info *prop_info = (zend_property_info*) CACHED_PTR_EX(cache_slot + 2);

if (UNEXPECTED(prop_info != NULL)) {
if (prop_info != NULL) {
value = zend_assign_to_typed_prop(prop_info, property_val, value, &garbage EXECUTE_DATA_CC);
ZEND_VM_C_GOTO(free_and_exit_assign_obj);
} else {
Expand Down Expand Up @@ -2533,7 +2533,7 @@ ZEND_VM_HANDLER(25, ZEND_ASSIGN_STATIC_PROP, ANY, ANY, CACHE_SLOT, SPEC(OP_DATA=

value = GET_OP_DATA_ZVAL_PTR(BP_VAR_R);

if (UNEXPECTED(ZEND_TYPE_IS_SET(prop_info->type))) {
if (ZEND_TYPE_IS_SET(prop_info->type)) {
value = zend_assign_to_typed_prop(prop_info, prop, value, &garbage EXECUTE_DATA_CC);
FREE_OP_DATA();
} else {
Expand Down Expand Up @@ -2831,7 +2831,7 @@ ZEND_VM_HANDLER(33, ZEND_ASSIGN_STATIC_PROP_REF, ANY, ANY, CACHE_SLOT|SRC)
if (UNEXPECTED(!zend_wrong_assign_to_variable_reference(prop, value_ptr, &garbage OPLINE_CC EXECUTE_DATA_CC))) {
prop = &EG(uninitialized_zval);
}
} else if (UNEXPECTED(ZEND_TYPE_IS_SET(prop_info->type))) {
} else if (ZEND_TYPE_IS_SET(prop_info->type)) {
prop = zend_assign_to_typed_property_reference(prop_info, prop, value_ptr, &garbage EXECUTE_DATA_CC);
} else {
zend_assign_to_variable_reference(prop, value_ptr, &garbage);
Expand Down Expand Up @@ -5580,7 +5580,7 @@ ZEND_VM_HOT_HANDLER(64, ZEND_RECV_INIT, NUM, CONST, CACHE_SLOT)
}
} else {
ZEND_VM_C_LABEL(recv_init_check_type):
if (UNEXPECTED((EX(func)->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0)) {
if ((EX(func)->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0) {
SAVE_OPLINE();
if (UNEXPECTED(!zend_verify_recv_arg_type(EX(func), arg_num, param, CACHE_ADDR(opline->extended_value)))) {
HANDLE_EXCEPTION();
Expand Down Expand Up @@ -5612,7 +5612,7 @@ ZEND_VM_HANDLER(164, ZEND_RECV_VARIADIC, NUM, UNUSED, CACHE_SLOT)
zend_hash_real_init_packed(Z_ARRVAL_P(params));
ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(params)) {
zval *param = EX_VAR_NUM(EX(func)->op_array.last_var + EX(func)->op_array.T);
if (UNEXPECTED(ZEND_TYPE_IS_SET(arg_info->type))) {
if (ZEND_TYPE_IS_SET(arg_info->type)) {
ZEND_ADD_CALL_FLAG(execute_data, ZEND_CALL_FREE_EXTRA_ARGS);
do {
if (UNEXPECTED(!zend_verify_variadic_arg_type(EX(func), arg_info, arg_num, param, CACHE_ADDR(opline->extended_value)))) {
Expand Down Expand Up @@ -7153,7 +7153,7 @@ ZEND_VM_HANDLER(126, ZEND_FE_FETCH_RW, VAR, ANY, JMP_ADDR)
if ((value_type & Z_TYPE_MASK) != IS_REFERENCE) {
zend_property_info *prop_info =
zend_get_property_info_for_slot(Z_OBJ_P(array), value);
if (UNEXPECTED(prop_info)) {
if (prop_info) {
if (UNEXPECTED(prop_info->flags & ZEND_ACC_READONLY)) {
zend_throw_error(NULL,
"Cannot acquire reference to readonly property %s::$%s",
Expand Down
Loading