Skip to content

Commit c1f8f84

Browse files
committed
Apply obvious simplification
1 parent b2e7b73 commit c1f8f84

File tree

7 files changed

+10
-23
lines changed

7 files changed

+10
-23
lines changed

NEWS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ PHP NEWS
3030
. Fixed bug GH-14267 (opcache.jit=off does not allow enabling JIT at runtime).
3131
(ilutov)
3232
. Fixed TLS access in JIT on FreeBSD/amd64. (Arnaud)
33+
. Fixed bug GH-13817 (Segmentation fault for enabled observers after pass 4).
34+
(Bob)
3335

3436
- Soap:
3537
. Fixed bug #47925 (PHPClient can't decompress response). (nielsdos)
@@ -142,8 +144,6 @@ PHP NEWS
142144
- Opcache:
143145
. Fixed incorrect assumptions across compilation units for static calls.
144146
(ilutov)
145-
. Fixed bug GH-13817 (Segmentation fault for enabled observers after pass 4).
146-
(Bob)
147147

148148
- OpenSSL:
149149
. Fixed bug GH-10495 (feof on OpenSSL stream hangs indefinitely).

Zend/Optimizer/compact_vars.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "Optimizer/zend_optimizer_internal.h"
2020
#include "zend_bitset.h"
21+
#include "zend_observer.h"
2122

2223
/* This pass removes all CVs and temporaries that are completely unused. It does *not* merge any CVs or TMPs.
2324
* This pass does not operate on SSA form anymore. */
@@ -117,7 +118,7 @@ void zend_optimizer_compact_vars(zend_op_array *op_array) {
117118
op_array->last_var = num_cvs;
118119
}
119120

120-
op_array->T = num_tmps;
121+
op_array->T = num_tmps + ZEND_OBSERVER_ENABLED; // reserve last temporary for observers if enabled
121122

122123
free_alloca(vars_map, use_heap2);
123124
}

Zend/Optimizer/optimize_func_calls.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,15 @@ void zend_optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx)
195195
/* nothing to do */
196196
} else if (fcall->opcode == ZEND_INIT_FCALL_BY_NAME) {
197197
fcall->opcode = ZEND_INIT_FCALL;
198-
fcall->op1.num = zend_vm_calc_ct_used_stack(fcall->extended_value, call_stack[call].func);
198+
fcall->op1.num = zend_vm_calc_used_stack(fcall->extended_value, call_stack[call].func);
199199
literal_dtor(&ZEND_OP2_LITERAL(fcall));
200200
fcall->op2.constant = fcall->op2.constant + 1;
201201
if (opline->opcode != ZEND_CALLABLE_CONVERT) {
202202
opline->opcode = zend_get_call_op(fcall, call_stack[call].func);
203203
}
204204
} else if (fcall->opcode == ZEND_INIT_NS_FCALL_BY_NAME) {
205205
fcall->opcode = ZEND_INIT_FCALL;
206-
fcall->op1.num = zend_vm_calc_ct_used_stack(fcall->extended_value, call_stack[call].func);
206+
fcall->op1.num = zend_vm_calc_used_stack(fcall->extended_value, call_stack[call].func);
207207
literal_dtor(&op_array->literals[fcall->op2.constant]);
208208
literal_dtor(&op_array->literals[fcall->op2.constant + 2]);
209209
fcall->op2.constant = fcall->op2.constant + 1;

Zend/Optimizer/optimize_temp_vars_5.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "zend_execute.h"
2727
#include "zend_vm.h"
2828
#include "zend_bitset.h"
29+
#include "zend_observer.h"
2930

3031
#define INVALID_VAR ((uint32_t)-1)
3132
#define GET_AVAILABLE_T() \
@@ -173,5 +174,5 @@ void zend_optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_c
173174
}
174175

175176
zend_arena_release(&ctx->arena, checkpoint);
176-
op_array->T = max + 1;
177+
op_array->T = max + 1 + ZEND_OBSERVER_ENABLED; // reserve last temporary for observers if enabled
177178
}

Zend/Optimizer/zend_optimizer.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "zend_inference.h"
3232
#include "zend_dump.h"
3333
#include "php.h"
34-
#include "zend_observer.h"
3534

3635
#ifndef ZEND_OPTIMIZER_MAX_REGISTERED_PASSES
3736
# define ZEND_OPTIMIZER_MAX_REGISTERED_PASSES 32
@@ -1097,8 +1096,6 @@ static void zend_revert_pass_two(zend_op_array *op_array)
10971096
}
10981097
#endif
10991098

1100-
op_array->T -= ZEND_OBSERVER_ENABLED;
1101-
11021099
op_array->fn_flags &= ~ZEND_ACC_DONE_PASS_TWO;
11031100
}
11041101

@@ -1128,8 +1125,6 @@ static void zend_redo_pass_two(zend_op_array *op_array)
11281125
}
11291126
#endif
11301127

1131-
op_array->T += ZEND_OBSERVER_ENABLED; // reserve last temporary for observers if enabled
1132-
11331128
opline = op_array->opcodes;
11341129
end = opline + op_array->last;
11351130
while (opline < end) {
@@ -1238,8 +1233,6 @@ static void zend_redo_pass_two_ex(zend_op_array *op_array, zend_ssa *ssa)
12381233
}
12391234
#endif
12401235

1241-
op_array->T += ZEND_OBSERVER_ENABLED; // reserve last temporary for observers if enabled
1242-
12431236
opline = op_array->opcodes;
12441237
end = opline + op_array->last;
12451238
while (opline < end) {
@@ -1364,7 +1357,7 @@ static void zend_adjust_fcall_stack_size(zend_op_array *op_array, zend_optimizer
13641357
&ctx->script->function_table,
13651358
Z_STR_P(RT_CONSTANT(opline, opline->op2)));
13661359
if (func) {
1367-
opline->op1.num = zend_vm_calc_ct_used_stack(opline->extended_value, func);
1360+
opline->op1.num = zend_vm_calc_used_stack(opline->extended_value, func);
13681361
}
13691362
}
13701363
opline++;
@@ -1383,7 +1376,7 @@ static void zend_adjust_fcall_stack_size_graph(zend_op_array *op_array)
13831376

13841377
if (opline && call_info->callee_func && opline->opcode == ZEND_INIT_FCALL) {
13851378
ZEND_ASSERT(!call_info->is_prototype);
1386-
opline->op1.num = zend_vm_calc_ct_used_stack(opline->extended_value, call_info->callee_func);
1379+
opline->op1.num = zend_vm_calc_used_stack(opline->extended_value, call_info->callee_func);
13871380
}
13881381
call_info = call_info->next_callee;
13891382
}

Zend/zend_execute.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,6 @@ ZEND_API void* zend_vm_stack_extend(size_t size)
226226
return ptr;
227227
}
228228

229-
ZEND_API uint32_t zend_vm_calc_ct_used_stack(uint32_t num_args, zend_function *func)
230-
{
231-
return zend_vm_calc_used_stack(num_args, func) + ((func->common.fn_flags & ZEND_ACC_DONE_PASS_TWO) == 0 && ZEND_USER_CODE(func->type) ? ZEND_OBSERVER_ENABLED : 0) * sizeof(zval);
232-
}
233-
234229
ZEND_API zval* zend_get_compiled_variable_value(const zend_execute_data *execute_data, uint32_t var)
235230
{
236231
return EX_VAR(var);

Zend/zend_execute.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,6 @@ static zend_always_inline uint32_t zend_vm_calc_used_stack(uint32_t num_args, ze
255255
return used_stack * sizeof(zval);
256256
}
257257

258-
// Handle a possibly currently not applied pass_two
259-
ZEND_API uint32_t zend_vm_calc_ct_used_stack(uint32_t num_args, zend_function *func);
260-
261258
static zend_always_inline zend_execute_data *zend_vm_stack_push_call_frame(uint32_t call_info, zend_function *func, uint32_t num_args, void *object_or_called_scope)
262259
{
263260
uint32_t used_stack = zend_vm_calc_used_stack(num_args, func);

0 commit comments

Comments
 (0)