Skip to content

Commit

Permalink
Replace ZEND_ASSIGN_ADD (and others) by ZEND_ASSIGN_OP, ZEND_ASSIGN_D…
Browse files Browse the repository at this point in the history
…IM_OP, ZEND_ASSGIN_OBJ_OP and ZEND_ASSIGN_STATIC_PROP_OP
  • Loading branch information
dstogov committed Jul 5, 2019
1 parent 24ecfcc commit 48ca5a1
Show file tree
Hide file tree
Showing 27 changed files with 2,563 additions and 8,404 deletions.
8 changes: 8 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ PHP 7.4 INTERNALS UPGRADE NOTES
s. Typed references support
t. Exceptions thrown by string conversions.
u. Removed uint and ulong typedefs
v. Compound assignment opcodes

2. Build system changes
a. Abstract
Expand Down Expand Up @@ -212,6 +213,13 @@ PHP 7.4 INTERNALS UPGRADE NOTES
u. The Windows typedefs uint and ulong are no longer available, and have to be
replaced with standard types.

v. Compound assignment opcodes were changed. Instead of ZEND_ASSIGN_ADD (and
others) with 0, ZEND_ASSIGN_DIM, ZEND_ASSIGN_OBJ or
ZEND_ASSIGN_STATIC_PROP in extended value, now we use ZEND_ASSIGN_OP,
ZEND_ASSIGN_DIM_OP, ZEND_ASSIGN_OBJ_OP and ZEND_ASSIGN_STATIC_PROP_OP with
ZEND_ADD (or other) in extended_value.


========================
2. Build system changes
========================
Expand Down
24 changes: 12 additions & 12 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1713,18 +1713,18 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
case ZEND_AST_ASSIGN_REF: BINARY_OP(" =& ", 90, 91, 90);
case ZEND_AST_ASSIGN_OP:
switch (ast->attr) {
case ZEND_ASSIGN_ADD: BINARY_OP(" += ", 90, 91, 90);
case ZEND_ASSIGN_SUB: BINARY_OP(" -= ", 90, 91, 90);
case ZEND_ASSIGN_MUL: BINARY_OP(" *= ", 90, 91, 90);
case ZEND_ASSIGN_DIV: BINARY_OP(" /= ", 90, 91, 90);
case ZEND_ASSIGN_MOD: BINARY_OP(" %= ", 90, 91, 90);
case ZEND_ASSIGN_SL: BINARY_OP(" <<= ", 90, 91, 90);
case ZEND_ASSIGN_SR: BINARY_OP(" >>= ", 90, 91, 90);
case ZEND_ASSIGN_CONCAT: BINARY_OP(" .= ", 90, 91, 90);
case ZEND_ASSIGN_BW_OR: BINARY_OP(" |= ", 90, 91, 90);
case ZEND_ASSIGN_BW_AND: BINARY_OP(" &= ", 90, 91, 90);
case ZEND_ASSIGN_BW_XOR: BINARY_OP(" ^= ", 90, 91, 90);
case ZEND_ASSIGN_POW: BINARY_OP(" **= ", 90, 91, 90);
case ZEND_ADD: BINARY_OP(" += ", 90, 91, 90);
case ZEND_SUB: BINARY_OP(" -= ", 90, 91, 90);
case ZEND_MUL: BINARY_OP(" *= ", 90, 91, 90);
case ZEND_DIV: BINARY_OP(" /= ", 90, 91, 90);
case ZEND_MOD: BINARY_OP(" %= ", 90, 91, 90);
case ZEND_SL: BINARY_OP(" <<= ", 90, 91, 90);
case ZEND_SR: BINARY_OP(" >>= ", 90, 91, 90);
case ZEND_CONCAT: BINARY_OP(" .= ", 90, 91, 90);
case ZEND_BW_OR: BINARY_OP(" |= ", 90, 91, 90);
case ZEND_BW_AND: BINARY_OP(" &= ", 90, 91, 90);
case ZEND_BW_XOR: BINARY_OP(" ^= ", 90, 91, 90);
case ZEND_POW: BINARY_OP(" **= ", 90, 91, 90);
EMPTY_SWITCH_DEFAULT_CASE();
}
break;
Expand Down
15 changes: 8 additions & 7 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2849,7 +2849,8 @@ void zend_compile_compound_assign(znode *result, zend_ast *ast) /* {{{ */
zend_delayed_compile_var(&var_node, var_ast, BP_VAR_RW, 0);
zend_compile_expr(&expr_node, expr_ast);
zend_delayed_compile_end(offset);
zend_emit_op(result, opcode, &var_node, &expr_node);
opline = zend_emit_op(result, ZEND_ASSIGN_OP, &var_node, &expr_node);
opline->extended_value = opcode;
return;
case ZEND_AST_STATIC_PROP:
offset = zend_delayed_compile_begin();
Expand All @@ -2858,8 +2859,8 @@ void zend_compile_compound_assign(znode *result, zend_ast *ast) /* {{{ */

opline = zend_delayed_compile_end(offset);
cache_slot = opline->extended_value;
opline->opcode = opcode;
opline->extended_value = ZEND_ASSIGN_STATIC_PROP;
opline->opcode = ZEND_ASSIGN_STATIC_PROP_OP;
opline->extended_value = opcode;

opline = zend_emit_op_data(&expr_node);
opline->extended_value = cache_slot;
Expand All @@ -2870,8 +2871,8 @@ void zend_compile_compound_assign(znode *result, zend_ast *ast) /* {{{ */
zend_compile_expr(&expr_node, expr_ast);

opline = zend_delayed_compile_end(offset);
opline->opcode = opcode;
opline->extended_value = ZEND_ASSIGN_DIM;
opline->opcode = ZEND_ASSIGN_DIM_OP;
opline->extended_value = opcode;

zend_emit_op_data(&expr_node);
return;
Expand All @@ -2882,8 +2883,8 @@ void zend_compile_compound_assign(znode *result, zend_ast *ast) /* {{{ */

opline = zend_delayed_compile_end(offset);
cache_slot = opline->extended_value;
opline->opcode = opcode;
opline->extended_value = ZEND_ASSIGN_OBJ;
opline->opcode = ZEND_ASSIGN_OBJ_OP;
opline->extended_value = opcode;

opline = zend_emit_op_data(&expr_node);
opline->extended_value = cache_slot;
Expand Down
3 changes: 3 additions & 0 deletions Zend/zend_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,9 @@ static zend_always_inline int zend_check_arg_send_type(const zend_function *zf,
/* All increment opcodes are even (decrement are odd) */
#define ZEND_IS_INCREMENT(opcode) (((opcode) & 1) == 0)

#define ZEND_IS_BINARY_ASSIGN_OP_OPCODE(opcode) \
(((opcode) >= ZEND_ADD) && ((opcode) <= ZEND_POW))

/* Pseudo-opcodes that are used only temporarily during compilation */
#define ZEND_PARENTHESIZED_CONCAT 252 /* removed with PHP 8 */
#define ZEND_GOTO 253
Expand Down
48 changes: 15 additions & 33 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1318,9 +1318,9 @@ static zend_always_inline int zend_binary_op(zval *ret, zval *op1, zval *op2 OPL
pow_function
};
/* size_t cast makes GCC to better optimize 64-bit PIC code */
size_t opcode = (size_t)opline->opcode;
size_t opcode = (size_t)opline->extended_value;

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

static zend_never_inline void zend_binary_assign_op_obj_dim(zval *object, zval *property, zval *value OPLINE_DC EXECUTE_DATA_DC)
Expand Down Expand Up @@ -1434,18 +1434,10 @@ static zend_never_inline ZEND_COLD void zend_wrong_string_offset(EXECUTE_DATA_D)
}

switch (opline->opcode) {
case ZEND_ASSIGN_ADD:
case ZEND_ASSIGN_SUB:
case ZEND_ASSIGN_MUL:
case ZEND_ASSIGN_DIV:
case ZEND_ASSIGN_MOD:
case ZEND_ASSIGN_SL:
case ZEND_ASSIGN_SR:
case ZEND_ASSIGN_CONCAT:
case ZEND_ASSIGN_BW_OR:
case ZEND_ASSIGN_BW_AND:
case ZEND_ASSIGN_BW_XOR:
case ZEND_ASSIGN_POW:
case ZEND_ASSIGN_OP:
case ZEND_ASSIGN_DIM_OP:
case ZEND_ASSIGN_OBJ_OP:
case ZEND_ASSIGN_STATIC_PROP_OP:
msg = "Cannot use assign-op operators with string offsets";
break;
case ZEND_FETCH_DIM_W:
Expand All @@ -1461,25 +1453,15 @@ static zend_never_inline ZEND_COLD void zend_wrong_string_offset(EXECUTE_DATA_D)
while (opline < end) {
if (opline->op1_type == IS_VAR && opline->op1.var == var) {
switch (opline->opcode) {
case ZEND_ASSIGN_ADD:
case ZEND_ASSIGN_SUB:
case ZEND_ASSIGN_MUL:
case ZEND_ASSIGN_DIV:
case ZEND_ASSIGN_MOD:
case ZEND_ASSIGN_SL:
case ZEND_ASSIGN_SR:
case ZEND_ASSIGN_CONCAT:
case ZEND_ASSIGN_BW_OR:
case ZEND_ASSIGN_BW_AND:
case ZEND_ASSIGN_BW_XOR:
case ZEND_ASSIGN_POW:
if (opline->extended_value == ZEND_ASSIGN_OBJ) {
msg = "Cannot use string offset as an object";
} else if (opline->extended_value == ZEND_ASSIGN_DIM) {
msg = "Cannot use string offset as an array";
} else {
msg = "Cannot use assign-op operators with string offsets";
}
case ZEND_ASSIGN_OBJ_OP:
msg = "Cannot use string offset as an object";
break;
case ZEND_ASSIGN_DIM_OP:
msg = "Cannot use string offset as an array";
break;
case ZEND_ASSIGN_STATIC_PROP_OP:
case ZEND_ASSIGN_OP:
msg = "Cannot use assign-op operators with string offsets";
break;
case ZEND_PRE_INC_OBJ:
case ZEND_PRE_DEC_OBJ:
Expand Down
24 changes: 12 additions & 12 deletions Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -886,29 +886,29 @@ expr:
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_REF, $1, $4); }
| T_CLONE expr { $$ = zend_ast_create(ZEND_AST_CLONE, $2); }
| variable T_PLUS_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_ADD, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_ADD, $1, $3); }
| variable T_MINUS_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_SUB, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_SUB, $1, $3); }
| variable T_MUL_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_MUL, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_MUL, $1, $3); }
| variable T_POW_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_POW, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_POW, $1, $3); }
| variable T_DIV_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_DIV, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_DIV, $1, $3); }
| variable T_CONCAT_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_CONCAT, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_CONCAT, $1, $3); }
| variable T_MOD_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_MOD, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_MOD, $1, $3); }
| variable T_AND_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_BW_AND, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_BW_AND, $1, $3); }
| variable T_OR_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_BW_OR, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_BW_OR, $1, $3); }
| variable T_XOR_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_BW_XOR, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_BW_XOR, $1, $3); }
| variable T_SL_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_SL, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_SL, $1, $3); }
| variable T_SR_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_SR, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_SR, $1, $3); }
| variable T_COALESCE_EQUAL expr
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_COALESCE, $1, $3); }
| variable T_INC { $$ = zend_ast_create(ZEND_AST_POST_INC, $1); }
Expand Down
13 changes: 1 addition & 12 deletions Zend/zend_opcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,33 +1028,24 @@ ZEND_API binary_op_type get_binary_op(int opcode)
{
switch (opcode) {
case ZEND_ADD:
case ZEND_ASSIGN_ADD:
return (binary_op_type) add_function;
case ZEND_SUB:
case ZEND_ASSIGN_SUB:
return (binary_op_type) sub_function;
case ZEND_MUL:
case ZEND_ASSIGN_MUL:
return (binary_op_type) mul_function;
case ZEND_POW:
case ZEND_ASSIGN_POW:
return (binary_op_type) pow_function;
case ZEND_DIV:
case ZEND_ASSIGN_DIV:
return (binary_op_type) div_function;
case ZEND_MOD:
case ZEND_ASSIGN_MOD:
return (binary_op_type) mod_function;
case ZEND_SL:
case ZEND_ASSIGN_SL:
return (binary_op_type) shift_left_function;
case ZEND_SR:
case ZEND_ASSIGN_SR:
return (binary_op_type) shift_right_function;
case ZEND_PARENTHESIZED_CONCAT:
case ZEND_FAST_CONCAT:
case ZEND_CONCAT:
case ZEND_ASSIGN_CONCAT:
return (binary_op_type) concat_function;
case ZEND_IS_IDENTICAL:
return (binary_op_type) is_identical_function;
Expand All @@ -1072,17 +1063,15 @@ ZEND_API binary_op_type get_binary_op(int opcode)
case ZEND_SPACESHIP:
return (binary_op_type) compare_function;
case ZEND_BW_OR:
case ZEND_ASSIGN_BW_OR:
return (binary_op_type) bitwise_or_function;
case ZEND_BW_AND:
case ZEND_ASSIGN_BW_AND:
return (binary_op_type) bitwise_and_function;
case ZEND_BW_XOR:
case ZEND_ASSIGN_BW_XOR:
return (binary_op_type) bitwise_xor_function;
case ZEND_BOOL_XOR:
return (binary_op_type) boolean_xor_function;
default:
ZEND_ASSERT(0);
return (binary_op_type) NULL;
}
}
Loading

3 comments on commit 48ca5a1

@Jan-E
Copy link
Contributor

@Jan-E Jan-E commented on 48ca5a1 Jul 9, 2019

Choose a reason for hiding this comment

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

@nikic @laruence @derickr
This commit breaks compiliation of the ast, taint and xdebug extensions with PHP 7.4.0 Alpha 3

@derickr
Copy link
Member

@derickr derickr commented on 48ca5a1 Jul 9, 2019

Choose a reason for hiding this comment

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

@nikic
Copy link
Member

@nikic nikic commented on 48ca5a1 Jul 9, 2019

Choose a reason for hiding this comment

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

@Jan-E Thanks for the ping, I've fixed php-ast in nikic/php-ast@2d8fd58.

Please sign in to comment.