Skip to content

Commit 56b18d4

Browse files
committed
Don't convert binop operand types in opcache
This may produce different behavior if operator overloading is involved, and may change the error message. If there's strong interest, this could be done in the DFA pass with available type information. It does not look particularly practically useful to me though.
1 parent 2d8f9f3 commit 56b18d4

File tree

1 file changed

+8
-52
lines changed

1 file changed

+8
-52
lines changed

ext/opcache/Optimizer/pass1.c

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -45,58 +45,6 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
4545

4646
while (opline < end) {
4747
switch (opline->opcode) {
48-
case ZEND_ADD:
49-
case ZEND_SUB:
50-
case ZEND_MUL:
51-
case ZEND_DIV:
52-
case ZEND_POW:
53-
if (opline->op1_type == IS_CONST) {
54-
if (Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING) {
55-
/* don't optimise if it should produce a runtime numeric string error */
56-
if (is_numeric_string(Z_STRVAL(ZEND_OP1_LITERAL(opline)), Z_STRLEN(ZEND_OP1_LITERAL(opline)), NULL, NULL, 0)) {
57-
convert_scalar_to_number(&ZEND_OP1_LITERAL(opline));
58-
}
59-
}
60-
}
61-
if (opline->op2_type == IS_CONST) {
62-
if (Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_STRING) {
63-
/* don't optimise if it should produce a runtime numeric string error */
64-
if (is_numeric_string(Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)), NULL, NULL, 0)) {
65-
convert_scalar_to_number(&ZEND_OP2_LITERAL(opline));
66-
}
67-
}
68-
if (opline->op1_type == IS_CONST) {
69-
goto constant_binary_op;
70-
}
71-
}
72-
break;
73-
74-
case ZEND_MOD:
75-
case ZEND_SL:
76-
case ZEND_SR:
77-
if (opline->op1_type == IS_CONST) {
78-
if (Z_TYPE(ZEND_OP1_LITERAL(opline)) != IS_LONG) {
79-
/* don't optimise if it should produce a runtime numeric string error */
80-
if (!(Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING
81-
&& !is_numeric_string(Z_STRVAL(ZEND_OP1_LITERAL(opline)), Z_STRLEN(ZEND_OP1_LITERAL(opline)), NULL, NULL, 0))) {
82-
convert_to_long(&ZEND_OP1_LITERAL(opline));
83-
}
84-
}
85-
}
86-
if (opline->op2_type == IS_CONST) {
87-
if (Z_TYPE(ZEND_OP2_LITERAL(opline)) != IS_LONG) {
88-
/* don't optimise if it should produce a runtime numeric string error */
89-
if (!(Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_STRING
90-
&& !is_numeric_string(Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)), NULL, NULL, 0))) {
91-
convert_to_long(&ZEND_OP2_LITERAL(opline));
92-
}
93-
}
94-
if (opline->op1_type == IS_CONST) {
95-
goto constant_binary_op;
96-
}
97-
}
98-
break;
99-
10048
case ZEND_CONCAT:
10149
case ZEND_FAST_CONCAT:
10250
if (opline->op1_type == IS_CONST) {
@@ -114,6 +62,14 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
11462
}
11563
break;
11664

65+
case ZEND_ADD:
66+
case ZEND_SUB:
67+
case ZEND_MUL:
68+
case ZEND_DIV:
69+
case ZEND_POW:
70+
case ZEND_MOD:
71+
case ZEND_SL:
72+
case ZEND_SR:
11773
case ZEND_BW_OR:
11874
case ZEND_BW_AND:
11975
case ZEND_BW_XOR:

0 commit comments

Comments
 (0)