Skip to content

Commit 1b5b817

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Replace ZEND_ASSIGN_ADD (and others) by ZEND_ASSIGN_OP, ZEND_ASSIGN_DIM_OP, ZEND_ASSGIN_OBJ_OP and ZEND_ASSIGN_STATIC_PROP_OP
2 parents 215e9d0 + 48ca5a1 commit 1b5b817

29 files changed

+2800
-8741
lines changed

Zend/zend_ast.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,18 +1714,18 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
17141714
case ZEND_AST_ASSIGN_REF: BINARY_OP(" =& ", 90, 91, 90);
17151715
case ZEND_AST_ASSIGN_OP:
17161716
switch (ast->attr) {
1717-
case ZEND_ASSIGN_ADD: BINARY_OP(" += ", 90, 91, 90);
1718-
case ZEND_ASSIGN_SUB: BINARY_OP(" -= ", 90, 91, 90);
1719-
case ZEND_ASSIGN_MUL: BINARY_OP(" *= ", 90, 91, 90);
1720-
case ZEND_ASSIGN_DIV: BINARY_OP(" /= ", 90, 91, 90);
1721-
case ZEND_ASSIGN_MOD: BINARY_OP(" %= ", 90, 91, 90);
1722-
case ZEND_ASSIGN_SL: BINARY_OP(" <<= ", 90, 91, 90);
1723-
case ZEND_ASSIGN_SR: BINARY_OP(" >>= ", 90, 91, 90);
1724-
case ZEND_ASSIGN_CONCAT: BINARY_OP(" .= ", 90, 91, 90);
1725-
case ZEND_ASSIGN_BW_OR: BINARY_OP(" |= ", 90, 91, 90);
1726-
case ZEND_ASSIGN_BW_AND: BINARY_OP(" &= ", 90, 91, 90);
1727-
case ZEND_ASSIGN_BW_XOR: BINARY_OP(" ^= ", 90, 91, 90);
1728-
case ZEND_ASSIGN_POW: BINARY_OP(" **= ", 90, 91, 90);
1717+
case ZEND_ADD: BINARY_OP(" += ", 90, 91, 90);
1718+
case ZEND_SUB: BINARY_OP(" -= ", 90, 91, 90);
1719+
case ZEND_MUL: BINARY_OP(" *= ", 90, 91, 90);
1720+
case ZEND_DIV: BINARY_OP(" /= ", 90, 91, 90);
1721+
case ZEND_MOD: BINARY_OP(" %= ", 90, 91, 90);
1722+
case ZEND_SL: BINARY_OP(" <<= ", 90, 91, 90);
1723+
case ZEND_SR: BINARY_OP(" >>= ", 90, 91, 90);
1724+
case ZEND_CONCAT: BINARY_OP(" .= ", 90, 91, 90);
1725+
case ZEND_BW_OR: BINARY_OP(" |= ", 90, 91, 90);
1726+
case ZEND_BW_AND: BINARY_OP(" &= ", 90, 91, 90);
1727+
case ZEND_BW_XOR: BINARY_OP(" ^= ", 90, 91, 90);
1728+
case ZEND_POW: BINARY_OP(" **= ", 90, 91, 90);
17291729
EMPTY_SWITCH_DEFAULT_CASE();
17301730
}
17311731
break;

Zend/zend_compile.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,7 +2826,8 @@ void zend_compile_compound_assign(znode *result, zend_ast *ast) /* {{{ */
28262826
zend_delayed_compile_var(&var_node, var_ast, BP_VAR_RW, 0);
28272827
zend_compile_expr(&expr_node, expr_ast);
28282828
zend_delayed_compile_end(offset);
2829-
zend_emit_op(result, opcode, &var_node, &expr_node);
2829+
opline = zend_emit_op(result, ZEND_ASSIGN_OP, &var_node, &expr_node);
2830+
opline->extended_value = opcode;
28302831
return;
28312832
case ZEND_AST_STATIC_PROP:
28322833
offset = zend_delayed_compile_begin();
@@ -2835,8 +2836,8 @@ void zend_compile_compound_assign(znode *result, zend_ast *ast) /* {{{ */
28352836

28362837
opline = zend_delayed_compile_end(offset);
28372838
cache_slot = opline->extended_value;
2838-
opline->opcode = opcode;
2839-
opline->extended_value = ZEND_ASSIGN_STATIC_PROP;
2839+
opline->opcode = ZEND_ASSIGN_STATIC_PROP_OP;
2840+
opline->extended_value = opcode;
28402841

28412842
opline = zend_emit_op_data(&expr_node);
28422843
opline->extended_value = cache_slot;
@@ -2847,8 +2848,8 @@ void zend_compile_compound_assign(znode *result, zend_ast *ast) /* {{{ */
28472848
zend_compile_expr(&expr_node, expr_ast);
28482849

28492850
opline = zend_delayed_compile_end(offset);
2850-
opline->opcode = opcode;
2851-
opline->extended_value = ZEND_ASSIGN_DIM;
2851+
opline->opcode = ZEND_ASSIGN_DIM_OP;
2852+
opline->extended_value = opcode;
28522853

28532854
zend_emit_op_data(&expr_node);
28542855
return;
@@ -2859,8 +2860,8 @@ void zend_compile_compound_assign(znode *result, zend_ast *ast) /* {{{ */
28592860

28602861
opline = zend_delayed_compile_end(offset);
28612862
cache_slot = opline->extended_value;
2862-
opline->opcode = opcode;
2863-
opline->extended_value = ZEND_ASSIGN_OBJ;
2863+
opline->opcode = ZEND_ASSIGN_OBJ_OP;
2864+
opline->extended_value = opcode;
28642865

28652866
opline = zend_emit_op_data(&expr_node);
28662867
opline->extended_value = cache_slot;

Zend/zend_compile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,9 @@ static zend_always_inline int zend_check_arg_send_type(const zend_function *zf,
995995
/* All increment opcodes are even (decrement are odd) */
996996
#define ZEND_IS_INCREMENT(opcode) (((opcode) & 1) == 0)
997997

998+
#define ZEND_IS_BINARY_ASSIGN_OP_OPCODE(opcode) \
999+
(((opcode) >= ZEND_ADD) && ((opcode) <= ZEND_POW))
1000+
9981001
/* Pseudo-opcodes that are used only temporarily during compilation */
9991002
#define ZEND_GOTO 253
10001003
#define ZEND_BRK 254

Zend/zend_execute.c

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,9 +1342,9 @@ static zend_always_inline int zend_binary_op(zval *ret, zval *op1, zval *op2 OPL
13421342
pow_function
13431343
};
13441344
/* size_t cast makes GCC to better optimize 64-bit PIC code */
1345-
size_t opcode = (size_t)opline->opcode;
1345+
size_t opcode = (size_t)opline->extended_value;
13461346

1347-
return zend_binary_ops[opcode - ZEND_ASSIGN_ADD](ret, op1, op2);
1347+
return zend_binary_ops[opcode - ZEND_ADD](ret, op1, op2);
13481348
}
13491349

13501350
static zend_never_inline void zend_binary_assign_op_obj_dim(zval *object, zval *property, zval *value OPLINE_DC EXECUTE_DATA_DC)
@@ -1449,18 +1449,10 @@ static zend_never_inline ZEND_COLD void zend_wrong_string_offset(EXECUTE_DATA_D)
14491449
}
14501450

14511451
switch (opline->opcode) {
1452-
case ZEND_ASSIGN_ADD:
1453-
case ZEND_ASSIGN_SUB:
1454-
case ZEND_ASSIGN_MUL:
1455-
case ZEND_ASSIGN_DIV:
1456-
case ZEND_ASSIGN_MOD:
1457-
case ZEND_ASSIGN_SL:
1458-
case ZEND_ASSIGN_SR:
1459-
case ZEND_ASSIGN_CONCAT:
1460-
case ZEND_ASSIGN_BW_OR:
1461-
case ZEND_ASSIGN_BW_AND:
1462-
case ZEND_ASSIGN_BW_XOR:
1463-
case ZEND_ASSIGN_POW:
1452+
case ZEND_ASSIGN_OP:
1453+
case ZEND_ASSIGN_DIM_OP:
1454+
case ZEND_ASSIGN_OBJ_OP:
1455+
case ZEND_ASSIGN_STATIC_PROP_OP:
14641456
msg = "Cannot use assign-op operators with string offsets";
14651457
break;
14661458
case ZEND_FETCH_DIM_W:
@@ -1476,25 +1468,15 @@ static zend_never_inline ZEND_COLD void zend_wrong_string_offset(EXECUTE_DATA_D)
14761468
while (opline < end) {
14771469
if (opline->op1_type == IS_VAR && opline->op1.var == var) {
14781470
switch (opline->opcode) {
1479-
case ZEND_ASSIGN_ADD:
1480-
case ZEND_ASSIGN_SUB:
1481-
case ZEND_ASSIGN_MUL:
1482-
case ZEND_ASSIGN_DIV:
1483-
case ZEND_ASSIGN_MOD:
1484-
case ZEND_ASSIGN_SL:
1485-
case ZEND_ASSIGN_SR:
1486-
case ZEND_ASSIGN_CONCAT:
1487-
case ZEND_ASSIGN_BW_OR:
1488-
case ZEND_ASSIGN_BW_AND:
1489-
case ZEND_ASSIGN_BW_XOR:
1490-
case ZEND_ASSIGN_POW:
1491-
if (opline->extended_value == ZEND_ASSIGN_OBJ) {
1492-
msg = "Cannot use string offset as an object";
1493-
} else if (opline->extended_value == ZEND_ASSIGN_DIM) {
1494-
msg = "Cannot use string offset as an array";
1495-
} else {
1496-
msg = "Cannot use assign-op operators with string offsets";
1497-
}
1471+
case ZEND_ASSIGN_OBJ_OP:
1472+
msg = "Cannot use string offset as an object";
1473+
break;
1474+
case ZEND_ASSIGN_DIM_OP:
1475+
msg = "Cannot use string offset as an array";
1476+
break;
1477+
case ZEND_ASSIGN_STATIC_PROP_OP:
1478+
case ZEND_ASSIGN_OP:
1479+
msg = "Cannot use assign-op operators with string offsets";
14981480
break;
14991481
case ZEND_PRE_INC_OBJ:
15001482
case ZEND_PRE_DEC_OBJ:

Zend/zend_language_parser.y

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -887,29 +887,29 @@ expr:
887887
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_REF, $1, $4); }
888888
| T_CLONE expr { $$ = zend_ast_create(ZEND_AST_CLONE, $2); }
889889
| variable T_PLUS_EQUAL expr
890-
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_ADD, $1, $3); }
890+
{ $$ = zend_ast_create_assign_op(ZEND_ADD, $1, $3); }
891891
| variable T_MINUS_EQUAL expr
892-
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_SUB, $1, $3); }
892+
{ $$ = zend_ast_create_assign_op(ZEND_SUB, $1, $3); }
893893
| variable T_MUL_EQUAL expr
894-
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_MUL, $1, $3); }
894+
{ $$ = zend_ast_create_assign_op(ZEND_MUL, $1, $3); }
895895
| variable T_POW_EQUAL expr
896-
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_POW, $1, $3); }
896+
{ $$ = zend_ast_create_assign_op(ZEND_POW, $1, $3); }
897897
| variable T_DIV_EQUAL expr
898-
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_DIV, $1, $3); }
898+
{ $$ = zend_ast_create_assign_op(ZEND_DIV, $1, $3); }
899899
| variable T_CONCAT_EQUAL expr
900-
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_CONCAT, $1, $3); }
900+
{ $$ = zend_ast_create_assign_op(ZEND_CONCAT, $1, $3); }
901901
| variable T_MOD_EQUAL expr
902-
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_MOD, $1, $3); }
902+
{ $$ = zend_ast_create_assign_op(ZEND_MOD, $1, $3); }
903903
| variable T_AND_EQUAL expr
904-
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_BW_AND, $1, $3); }
904+
{ $$ = zend_ast_create_assign_op(ZEND_BW_AND, $1, $3); }
905905
| variable T_OR_EQUAL expr
906-
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_BW_OR, $1, $3); }
906+
{ $$ = zend_ast_create_assign_op(ZEND_BW_OR, $1, $3); }
907907
| variable T_XOR_EQUAL expr
908-
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_BW_XOR, $1, $3); }
908+
{ $$ = zend_ast_create_assign_op(ZEND_BW_XOR, $1, $3); }
909909
| variable T_SL_EQUAL expr
910-
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_SL, $1, $3); }
910+
{ $$ = zend_ast_create_assign_op(ZEND_SL, $1, $3); }
911911
| variable T_SR_EQUAL expr
912-
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_SR, $1, $3); }
912+
{ $$ = zend_ast_create_assign_op(ZEND_SR, $1, $3); }
913913
| variable T_COALESCE_EQUAL expr
914914
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_COALESCE, $1, $3); }
915915
| variable T_INC { $$ = zend_ast_create(ZEND_AST_POST_INC, $1); }

Zend/zend_opcode.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,32 +1028,23 @@ ZEND_API binary_op_type get_binary_op(int opcode)
10281028
{
10291029
switch (opcode) {
10301030
case ZEND_ADD:
1031-
case ZEND_ASSIGN_ADD:
10321031
return (binary_op_type) add_function;
10331032
case ZEND_SUB:
1034-
case ZEND_ASSIGN_SUB:
10351033
return (binary_op_type) sub_function;
10361034
case ZEND_MUL:
1037-
case ZEND_ASSIGN_MUL:
10381035
return (binary_op_type) mul_function;
10391036
case ZEND_POW:
1040-
case ZEND_ASSIGN_POW:
10411037
return (binary_op_type) pow_function;
10421038
case ZEND_DIV:
1043-
case ZEND_ASSIGN_DIV:
10441039
return (binary_op_type) div_function;
10451040
case ZEND_MOD:
1046-
case ZEND_ASSIGN_MOD:
10471041
return (binary_op_type) mod_function;
10481042
case ZEND_SL:
1049-
case ZEND_ASSIGN_SL:
10501043
return (binary_op_type) shift_left_function;
10511044
case ZEND_SR:
1052-
case ZEND_ASSIGN_SR:
10531045
return (binary_op_type) shift_right_function;
10541046
case ZEND_FAST_CONCAT:
10551047
case ZEND_CONCAT:
1056-
case ZEND_ASSIGN_CONCAT:
10571048
return (binary_op_type) concat_function;
10581049
case ZEND_IS_IDENTICAL:
10591050
return (binary_op_type) is_identical_function;
@@ -1071,17 +1062,15 @@ ZEND_API binary_op_type get_binary_op(int opcode)
10711062
case ZEND_SPACESHIP:
10721063
return (binary_op_type) compare_function;
10731064
case ZEND_BW_OR:
1074-
case ZEND_ASSIGN_BW_OR:
10751065
return (binary_op_type) bitwise_or_function;
10761066
case ZEND_BW_AND:
1077-
case ZEND_ASSIGN_BW_AND:
10781067
return (binary_op_type) bitwise_and_function;
10791068
case ZEND_BW_XOR:
1080-
case ZEND_ASSIGN_BW_XOR:
10811069
return (binary_op_type) bitwise_xor_function;
10821070
case ZEND_BOOL_XOR:
10831071
return (binary_op_type) boolean_xor_function;
10841072
default:
1073+
ZEND_ASSERT(0);
10851074
return (binary_op_type) NULL;
10861075
}
10871076
}

0 commit comments

Comments
 (0)