Skip to content

Commit ae837db

Browse files
committed
Handle overloaded GMP operators in type inference
1 parent 39974dd commit ae837db

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

ext/opcache/Optimizer/zend_inference.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,14 @@ static uint32_t binary_op_result_type(
20552055
uint32_t tmp = 0;
20562056
uint32_t t1_type = (t1 & MAY_BE_ANY) | (t1 & MAY_BE_UNDEF ? MAY_BE_NULL : 0);
20572057
uint32_t t2_type = (t2 & MAY_BE_ANY) | (t2 & MAY_BE_UNDEF ? MAY_BE_NULL : 0);
2058+
2059+
/* Handle potentially overloaded operators.
2060+
* This could be made more precise by checking the class type, if known. */
2061+
if ((t1_type & MAY_BE_OBJECT) || (t2_type & MAY_BE_OBJECT)) {
2062+
/* This is somewhat GMP specific. */
2063+
tmp |= MAY_BE_OBJECT | MAY_BE_FALSE | MAY_BE_RC1;
2064+
}
2065+
20582066
switch (opcode) {
20592067
case ZEND_ADD:
20602068
if (t1_type == MAY_BE_LONG && t2_type == MAY_BE_LONG) {
@@ -2109,7 +2117,7 @@ static uint32_t binary_op_result_type(
21092117
* handling */
21102118
break;
21112119
case ZEND_MOD:
2112-
tmp = MAY_BE_LONG;
2120+
tmp |= MAY_BE_LONG;
21132121
/* Division by zero results in an exception, so it doesn't need any special handling */
21142122
break;
21152123
case ZEND_BW_OR:
@@ -2124,7 +2132,7 @@ static uint32_t binary_op_result_type(
21242132
break;
21252133
case ZEND_SL:
21262134
case ZEND_SR:
2127-
tmp = MAY_BE_LONG;
2135+
tmp |= MAY_BE_LONG;
21282136
break;
21292137
case ZEND_CONCAT:
21302138
case ZEND_FAST_CONCAT:
@@ -2252,6 +2260,10 @@ static int zend_update_type_info(const zend_op_array *op_array,
22522260
if (t1 & (MAY_BE_ANY-MAY_BE_STRING)) {
22532261
tmp |= MAY_BE_LONG;
22542262
}
2263+
if (t1 & MAY_BE_OBJECT) {
2264+
/* Potentially overloaded operator. */
2265+
tmp |= MAY_BE_OBJECT | MAY_BE_RC1;
2266+
}
22552267
UPDATE_SSA_TYPE(tmp, ssa_ops[i].result_def);
22562268
break;
22572269
case ZEND_BEGIN_SILENCE:

0 commit comments

Comments
 (0)