Skip to content

Commit ba9c0b3

Browse files
committed
Export zend_unary_op_produces_error() and use in optimizer
Don't repeat this logic, as it's going to become more complex.
1 parent 0224cc8 commit ba9c0b3

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

Zend/Optimizer/zend_optimizer.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ int zend_optimizer_eval_unary_op(zval *result, zend_uchar opcode, zval *op1) /*
6464
unary_op_type unary_op = get_unary_op(opcode);
6565

6666
if (unary_op) {
67-
if (opcode == ZEND_BW_NOT
68-
&& Z_TYPE_P(op1) != IS_LONG
69-
&& Z_TYPE_P(op1) != IS_DOUBLE
70-
&& Z_TYPE_P(op1) != IS_STRING) {
71-
/* produces "Unsupported operand types" exception */
67+
if (zend_unary_op_produces_error(opcode, op1)) {
7268
return FAILURE;
7369
}
7470
return unary_op(result, op1);

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8223,7 +8223,7 @@ static inline bool zend_try_ct_eval_binary_op(zval *result, uint32_t opcode, zva
82238223
}
82248224
/* }}} */
82258225

8226-
bool zend_unary_op_produces_error(uint32_t opcode, zval *op)
8226+
ZEND_API bool zend_unary_op_produces_error(uint32_t opcode, zval *op)
82278227
{
82288228
if (opcode == ZEND_BW_NOT) {
82298229
return Z_TYPE_P(op) <= IS_TRUE || Z_TYPE_P(op) == IS_ARRAY;

Zend/zend_compile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,5 +1163,6 @@ END_EXTERN_C()
11631163
#define ZEND_COMPILE_DEFAULT_FOR_EVAL 0
11641164

11651165
ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, zval *op1, zval *op2);
1166+
ZEND_API bool zend_unary_op_produces_error(uint32_t opcode, zval *op);
11661167

11671168
#endif /* ZEND_COMPILE_H */

0 commit comments

Comments
 (0)