Skip to content

Remove leftover ZEND_CAST code for (unset) cast. #5042

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 1 commit 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
8 changes: 2 additions & 6 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -5730,12 +5730,6 @@ ZEND_VM_COLD_CONST_HANDLER(51, ZEND_CAST, CONST|TMP|VAR|CV, ANY, TYPE)
expr = GET_OP1_ZVAL_PTR(BP_VAR_R);

switch (opline->extended_value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an assert along the lines of ZEND_ASSERT(opline->extended_value != _IS_BOOL && "Must use ZEND_BOOL instead"); here.

Copy link
Contributor Author

@TysonAndre TysonAndre Jan 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ZEND_ASSERT(opline->extended_value == IS_OBJECT); I added would also fail for that same assertion, just later in the program execution. There weren't any early returns I saw.

Added anyway to default:

case IS_NULL:
ZVAL_NULL(result);
break;
case _IS_BOOL:
ZVAL_BOOL(result, zend_is_true(expr));
break;
case IS_LONG:
ZVAL_LONG(result, zval_get_long(expr));
break;
Expand All @@ -5746,6 +5740,7 @@ ZEND_VM_COLD_CONST_HANDLER(51, ZEND_CAST, CONST|TMP|VAR|CV, ANY, TYPE)
ZVAL_STR(result, zval_get_string(expr));
break;
default:
ZEND_ASSERT(opline->extended_value != _IS_BOOL && "Must use ZEND_BOOL instead");
if (OP1_TYPE & (IS_VAR|IS_CV)) {
ZVAL_DEREF(expr);
}
Expand Down Expand Up @@ -5789,6 +5784,7 @@ ZEND_VM_COLD_CONST_HANDLER(51, ZEND_CAST, CONST|TMP|VAR|CV, ANY, TYPE)
}
}
} else {
ZEND_ASSERT(opline->extended_value == IS_OBJECT);
ZVAL_OBJ(result, zend_objects_new(zend_standard_class_def));
if (Z_TYPE_P(expr) == IS_ARRAY) {
ht = zend_symtable_to_proptable(Z_ARR_P(expr));
Expand Down
32 changes: 8 additions & 24 deletions Zend/zend_vm_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -3882,12 +3882,6 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_CONST_H
expr = RT_CONSTANT(opline, opline->op1);

switch (opline->extended_value) {
case IS_NULL:
ZVAL_NULL(result);
break;
case _IS_BOOL:
ZVAL_BOOL(result, zend_is_true(expr));
break;
case IS_LONG:
ZVAL_LONG(result, zval_get_long(expr));
break;
Expand All @@ -3898,6 +3892,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_CONST_H
ZVAL_STR(result, zval_get_string(expr));
break;
default:
ZEND_ASSERT(opline->extended_value != _IS_BOOL && "Must use ZEND_BOOL instead");
if (IS_CONST & (IS_VAR|IS_CV)) {
ZVAL_DEREF(expr);
}
Expand Down Expand Up @@ -3940,6 +3935,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_CONST_H
}
}
} else {
ZEND_ASSERT(opline->extended_value == IS_OBJECT);
ZVAL_OBJ(result, zend_objects_new(zend_standard_class_def));
if (Z_TYPE_P(expr) == IS_ARRAY) {
ht = zend_symtable_to_proptable(Z_ARR_P(expr));
Expand Down Expand Up @@ -17489,12 +17485,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_TMP_HANDLER(ZEND_OPC
expr = _get_zval_ptr_tmp(opline->op1.var EXECUTE_DATA_CC);

switch (opline->extended_value) {
case IS_NULL:
ZVAL_NULL(result);
break;
case _IS_BOOL:
ZVAL_BOOL(result, zend_is_true(expr));
break;
case IS_LONG:
ZVAL_LONG(result, zval_get_long(expr));
break;
Expand All @@ -17505,6 +17495,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_TMP_HANDLER(ZEND_OPC
ZVAL_STR(result, zval_get_string(expr));
break;
default:
ZEND_ASSERT(opline->extended_value != _IS_BOOL && "Must use ZEND_BOOL instead");
if (IS_TMP_VAR & (IS_VAR|IS_CV)) {
ZVAL_DEREF(expr);
}
Expand Down Expand Up @@ -17547,6 +17538,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_TMP_HANDLER(ZEND_OPC
}
}
} else {
ZEND_ASSERT(opline->extended_value == IS_OBJECT);
ZVAL_OBJ(result, zend_objects_new(zend_standard_class_def));
if (Z_TYPE_P(expr) == IS_ARRAY) {
ht = zend_symtable_to_proptable(Z_ARR_P(expr));
Expand Down Expand Up @@ -20150,12 +20142,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_VAR_HANDLER(ZEND_OPC
expr = _get_zval_ptr_var(opline->op1.var EXECUTE_DATA_CC);

switch (opline->extended_value) {
case IS_NULL:
ZVAL_NULL(result);
break;
case _IS_BOOL:
ZVAL_BOOL(result, zend_is_true(expr));
break;
case IS_LONG:
ZVAL_LONG(result, zval_get_long(expr));
break;
Expand All @@ -20166,6 +20152,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_VAR_HANDLER(ZEND_OPC
ZVAL_STR(result, zval_get_string(expr));
break;
default:
ZEND_ASSERT(opline->extended_value != _IS_BOOL && "Must use ZEND_BOOL instead");
if (IS_VAR & (IS_VAR|IS_CV)) {
ZVAL_DEREF(expr);
}
Expand Down Expand Up @@ -20209,6 +20196,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_VAR_HANDLER(ZEND_OPC
}
}
} else {
ZEND_ASSERT(opline->extended_value == IS_OBJECT);
ZVAL_OBJ(result, zend_objects_new(zend_standard_class_def));
if (Z_TYPE_P(expr) == IS_ARRAY) {
ht = zend_symtable_to_proptable(Z_ARR_P(expr));
Expand Down Expand Up @@ -36083,12 +36071,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_CV_HANDLER(ZEND_OPCO
expr = _get_zval_ptr_cv_BP_VAR_R(opline->op1.var EXECUTE_DATA_CC);

switch (opline->extended_value) {
case IS_NULL:
ZVAL_NULL(result);
break;
case _IS_BOOL:
ZVAL_BOOL(result, zend_is_true(expr));
break;
case IS_LONG:
ZVAL_LONG(result, zval_get_long(expr));
break;
Expand All @@ -36099,6 +36081,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_CV_HANDLER(ZEND_OPCO
ZVAL_STR(result, zval_get_string(expr));
break;
default:
ZEND_ASSERT(opline->extended_value != _IS_BOOL && "Must use ZEND_BOOL instead");
if (IS_CV & (IS_VAR|IS_CV)) {
ZVAL_DEREF(expr);
}
Expand Down Expand Up @@ -36141,6 +36124,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_CV_HANDLER(ZEND_OPCO
}
}
} else {
ZEND_ASSERT(opline->extended_value == IS_OBJECT);
ZVAL_OBJ(result, zend_objects_new(zend_standard_class_def));
if (Z_TYPE_P(expr) == IS_ARRAY) {
ht = zend_symtable_to_proptable(Z_ARR_P(expr));
Expand Down
56 changes: 15 additions & 41 deletions ext/opcache/Optimizer/zend_inference.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,23 +1030,7 @@ int zend_inference_calc_range(const zend_op_array *op_array, zend_ssa *ssa, int
}
}
} else if (ssa->ops[line].result_def == var) {
if (opline->extended_value == IS_NULL) {
tmp->min = 0;
tmp->max = 0;
return 1;
} else if (opline->extended_value == _IS_BOOL) {
if (OP1_HAS_RANGE()) {
op1_min = OP1_MIN_RANGE();
op1_max = OP1_MAX_RANGE();
tmp->min = (op1_min > 0 || op1_max < 0);
tmp->max = (op1_min != 0 || op1_max != 0);
return 1;
} else {
tmp->min = 0;
tmp->max = 1;
return 1;
}
} else if (opline->extended_value == IS_LONG) {
if (opline->extended_value == IS_LONG) {
if (OP1_HAS_RANGE()) {
tmp->min = OP1_MIN_RANGE();
tmp->max = OP1_MAX_RANGE();
Expand Down Expand Up @@ -2499,24 +2483,19 @@ static int zend_update_type_info(const zend_op_array *op_array,
UPDATE_SSA_TYPE(tmp, ssa_ops[i].op1_def);
COPY_SSA_OBJ_TYPE(ssa_ops[i].op1_use, ssa_ops[i].op1_def);
}
tmp = 0;
if (opline->extended_value == _IS_BOOL) {
tmp |= MAY_BE_TRUE|MAY_BE_FALSE;
} else {
tmp |= 1 << opline->extended_value;
if (tmp & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) {
if ((tmp & MAY_BE_ANY) == (t1 & MAY_BE_ANY)) {
tmp |= (t1 & MAY_BE_RC1) | MAY_BE_RCN;
} else if ((opline->extended_value == IS_ARRAY ||
opline->extended_value == IS_OBJECT) &&
(t1 & (MAY_BE_ARRAY|MAY_BE_OBJECT))) {
tmp |= MAY_BE_RC1 | MAY_BE_RCN;
} else if (opline->extended_value == IS_STRING &&
(t1 & (MAY_BE_STRING|MAY_BE_OBJECT))) {
tmp = 1 << opline->extended_value;
if (tmp & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) {
if ((tmp & MAY_BE_ANY) == (t1 & MAY_BE_ANY)) {
tmp |= (t1 & MAY_BE_RC1) | MAY_BE_RCN;
} else if ((opline->extended_value == IS_ARRAY ||
opline->extended_value == IS_OBJECT) &&
(t1 & (MAY_BE_ARRAY|MAY_BE_OBJECT))) {
tmp |= MAY_BE_RC1 | MAY_BE_RCN;
} else {
tmp |= MAY_BE_RC1;
}
} else if (opline->extended_value == IS_STRING &&
(t1 & (MAY_BE_STRING|MAY_BE_OBJECT))) {
tmp |= MAY_BE_RC1 | MAY_BE_RCN;
} else {
tmp |= MAY_BE_RC1;
}
}
if (opline->extended_value == IS_ARRAY) {
Expand Down Expand Up @@ -4618,10 +4597,6 @@ int zend_may_throw(const zend_op *opline, const zend_op_array *op_array, zend_ss
return (t1 & MAY_BE_OBJECT) || (t2 & (MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE));
case ZEND_CAST:
switch (opline->extended_value) {
case IS_NULL:
return 0;
case _IS_BOOL:
return (t1 & MAY_BE_OBJECT);
case IS_LONG:
case IS_DOUBLE:
return (t1 & MAY_BE_OBJECT);
Expand All @@ -4630,9 +4605,8 @@ int zend_may_throw(const zend_op *opline, const zend_op_array *op_array, zend_ss
case IS_ARRAY:
return (t1 & MAY_BE_OBJECT);
case IS_OBJECT:
return (t1 & MAY_BE_ARRAY);
default:
return 1;
return 0;
EMPTY_SWITCH_DEFAULT_CASE()
}
case ZEND_ARRAY_KEY_EXISTS:
if ((t2 & MAY_BE_ANY) != MAY_BE_ARRAY) {
Expand Down