Skip to content

Commit 79dbde7

Browse files
committed
ext/opcache/jit/zend_jit_vm_helpers: declare variables where they are used (C99)
1 parent 9a70214 commit 79dbde7

File tree

1 file changed

+26
-47
lines changed

1 file changed

+26
-47
lines changed

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ register const zend_op* volatile opline __asm__("x28");
5353

5454
ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_leave_nested_func_helper(uint32_t call_info EXECUTE_DATA_DC)
5555
{
56-
zend_execute_data *old_execute_data;
57-
5856
if (UNEXPECTED(call_info & ZEND_CALL_HAS_SYMBOL_TABLE)) {
5957
zend_clean_and_cache_symbol_table(EX(symbol_table));
6058
}
@@ -69,7 +67,7 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_leave_nested_func_helper(uint32_t
6967
zend_free_extra_named_params(EX(extra_named_params));
7068
}
7169

72-
old_execute_data = execute_data;
70+
zend_execute_data *const old_execute_data = execute_data;
7371
execute_data = EX(prev_execute_data);
7472
zend_vm_stack_free_call_frame_ex(call_info, old_execute_data);
7573

@@ -132,7 +130,6 @@ void ZEND_FASTCALL zend_jit_copy_extra_args_helper(EXECUTE_DATA_D)
132130
if (EXPECTED(!(op_array->fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE))) {
133131
uint32_t first_extra_arg = op_array->num_args;
134132
uint32_t num_args = EX_NUM_ARGS();
135-
zval *end, *src, *dst;
136133
uint32_t type_flags = 0;
137134

138135
if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) {
@@ -145,9 +142,9 @@ void ZEND_FASTCALL zend_jit_copy_extra_args_helper(EXECUTE_DATA_D)
145142
}
146143

147144
/* move extra args into separate array after all CV and TMP vars */
148-
end = EX_VAR_NUM(first_extra_arg - 1);
149-
src = end + (num_args - first_extra_arg);
150-
dst = src + (op_array->last_var + op_array->T - first_extra_arg);
145+
zval *const end = EX_VAR_NUM(first_extra_arg - 1);
146+
zval *src = end + (num_args - first_extra_arg);
147+
zval *dst = src + (op_array->last_var + op_array->T - first_extra_arg);
151148
if (EXPECTED(src != dst)) {
152149
do {
153150
type_flags |= Z_TYPE_INFO_P(src);
@@ -256,11 +253,10 @@ static zend_always_inline zend_constant* _zend_quick_get_constant(
256253
zend_execute_data *execute_data = EG(current_execute_data);
257254
#endif
258255
const zend_op *opline = EX(opline);
259-
zval *zv;
260256
zend_constant *c = NULL;
261257

262258
/* null/true/false are resolved during compilation, so don't check for them here. */
263-
zv = zend_hash_find_known_hash(EG(zend_constants), Z_STR_P(key));
259+
zval *zv = zend_hash_find_known_hash(EG(zend_constants), Z_STR_P(key));
264260
if (zv) {
265261
c = (zend_constant*)Z_PTR_P(zv);
266262
} else if (flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE) {
@@ -395,21 +391,19 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_loop_trace_helper(ZEND_OPCODE_HAN
395391

396392
static int zend_jit_trace_recursive_call_count(const zend_op_array *op_array, const zend_op_array **unrolled_calls, int ret_level, int level)
397393
{
398-
int i;
399394
int count = 0;
400395

401-
for (i = ret_level; i < level; i++) {
396+
for (int i = ret_level; i < level; i++) {
402397
count += (unrolled_calls[i] == op_array);
403398
}
404399
return count;
405400
}
406401

407402
static int zend_jit_trace_recursive_ret_count(const zend_op_array *op_array, const zend_op_array **unrolled_calls, int ret_level)
408403
{
409-
int i;
410404
int count = 0;
411405

412-
for (i = 0; i < ret_level; i++) {
406+
for (int i = 0; i < ret_level; i++) {
413407
count += (unrolled_calls[i] == op_array);
414408
}
415409
return count;
@@ -432,12 +426,11 @@ static uint8_t zend_jit_trace_bad_stop_event(const zend_op *opline, int count)
432426
const zend_op **cache_opline = JIT_G(bad_root_cache_opline);
433427
uint8_t *cache_count = JIT_G(bad_root_cache_count);
434428
uint8_t *cache_stop = JIT_G(bad_root_cache_stop);
435-
uint32_t i;
436429

437430
if (count < 0) {
438431
count = 0;
439432
}
440-
for (i = 0; i < ZEND_JIT_TRACE_BAD_ROOT_SLOTS; i++) {
433+
for (uint32_t i = 0; i < ZEND_JIT_TRACE_BAD_ROOT_SLOTS; i++) {
441434
if (cache_opline[i] == opline) {
442435
if (cache_count[i] >= count) {
443436
return cache_stop[i];
@@ -455,17 +448,14 @@ static int zend_jit_trace_record_fake_init_call_ex(zend_execute_data *call, zend
455448
zend_jit_trace_stop stop ZEND_ATTRIBUTE_UNUSED = ZEND_JIT_TRACE_STOP_ERROR;
456449

457450
do {
458-
zend_function *func;
459-
zend_jit_op_array_trace_extension *jit_extension;
460-
461451
if (call->prev_execute_data) {
462452
idx = zend_jit_trace_record_fake_init_call_ex(call->prev_execute_data, trace_buffer, idx, is_megamorphic, init_level + 1);
463453
if (idx < 0) {
464454
return idx;
465455
}
466456
}
467457

468-
func = call->func;
458+
zend_function *func = call->func;
469459
if (func->common.fn_flags & (ZEND_ACC_CALL_VIA_TRAMPOLINE|ZEND_ACC_NEVER_CACHE)) {
470460
/* TODO: Can we continue recording ??? */
471461
return -1;
@@ -476,7 +466,7 @@ static int zend_jit_trace_record_fake_init_call_ex(zend_execute_data *call, zend
476466
}
477467
if (func->type == ZEND_USER_FUNCTION
478468
&& (func->op_array.fn_flags & ZEND_ACC_CLOSURE)) {
479-
jit_extension =
469+
zend_jit_op_array_trace_extension *const jit_extension =
480470
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(&func->op_array);
481471
if (UNEXPECTED(!jit_extension
482472
|| !(jit_extension->func_info.flags & ZEND_FUNC_JIT_ON_HOT_TRACE)
@@ -548,18 +538,11 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
548538
zend_execute_data *save_execute_data = execute_data;
549539
const zend_op *save_opline = opline;
550540
#endif
551-
const zend_op *orig_opline, *end_opline;
552541
zend_jit_trace_stop stop = ZEND_JIT_TRACE_STOP_ERROR;
553542
zend_jit_trace_stop halt = 0;
554543
int level = 0;
555544
int ret_level = 0;
556-
zend_vm_opcode_handler_t handler;
557-
const zend_op_array *op_array;
558-
zend_jit_op_array_trace_extension *jit_extension;
559-
size_t offset;
560-
int idx, count;
561-
uint8_t trace_flags, op1_type, op2_type, op3_type;
562-
zend_class_entry *ce1, *ce2;
545+
int idx;
563546
const zend_op *link_to_enter_opline = NULL;
564547
int backtrack_link_to_enter = -1;
565548
int backtrack_recursion = -1;
@@ -576,18 +559,17 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
576559
execute_data = ex;
577560
opline = EX(opline) = op;
578561
#else
579-
int rc;
580562
zend_execute_data *execute_data = ex;
581563
const zend_op *opline = EX(opline);
582564
#endif
583565
zend_execute_data *prev_call = EX(call);
584566

585-
orig_opline = opline;
567+
const zend_op *const orig_opline = opline;
586568

587-
op_array = &EX(func)->op_array;
588-
jit_extension =
569+
const zend_op_array *op_array = &EX(func)->op_array;
570+
zend_jit_op_array_trace_extension *const jit_extension =
589571
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
590-
offset = jit_extension->offset;
572+
size_t offset = jit_extension->offset;
591573
if (!op_array->function_name
592574
|| (op_array->fn_flags & ZEND_ACC_CLOSURE)) {
593575
op_array = jit_extension->op_array;
@@ -619,8 +601,8 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
619601
}
620602

621603
while (1) {
622-
ce1 = ce2 = NULL;
623-
op1_type = op2_type = op3_type = IS_UNKNOWN;
604+
zend_class_entry *ce1 = NULL, *ce2 = NULL;
605+
uint8_t op1_type = IS_UNKNOWN, op2_type = IS_UNKNOWN, op3_type = IS_UNKNOWN;
624606
if ((opline->op1_type & (IS_TMP_VAR|IS_VAR|IS_CV))
625607
&& opline->opcode != ZEND_ROPE_ADD
626608
&& opline->opcode != ZEND_ROPE_END
@@ -846,7 +828,7 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
846828
break;
847829
}
848830

849-
handler = (zend_vm_opcode_handler_t)ZEND_OP_TRACE_INFO(opline, offset)->call_handler;
831+
const zend_vm_opcode_handler_t handler = (zend_vm_opcode_handler_t)ZEND_OP_TRACE_INFO(opline, offset)->call_handler;
850832
#ifdef HAVE_GCC_GLOBAL_REGS
851833
handler();
852834
if (UNEXPECTED(opline == zend_jit_halt_op)) {
@@ -857,7 +839,7 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
857839
}
858840
if (UNEXPECTED(execute_data != prev_execute_data)) {
859841
#else
860-
rc = handler(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
842+
int rc = handler(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
861843
if (rc != 0) {
862844
if (rc < 0) {
863845
stop = ZEND_JIT_TRACE_STOP_RETURN;
@@ -873,7 +855,7 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
873855
#endif
874856

875857
op_array = &EX(func)->op_array;
876-
jit_extension =
858+
zend_jit_op_array_trace_extension *const jit_extension =
877859
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
878860
if (UNEXPECTED(!jit_extension)
879861
|| UNEXPECTED(!(jit_extension->func_info.flags & ZEND_FUNC_JIT_ON_HOT_TRACE))) {
@@ -910,7 +892,7 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
910892
EX(return_value) != NULL ? ZEND_JIT_TRACE_RETURN_VALUE_USED : 0,
911893
op_array);
912894

913-
count = zend_jit_trace_recursive_call_count(&EX(func)->op_array, unrolled_calls, ret_level, level);
895+
const int count = zend_jit_trace_recursive_call_count(&EX(func)->op_array, unrolled_calls, ret_level, level);
914896

915897
if (opline == orig_opline) {
916898
if (count + 1 >= JIT_G(max_recursive_calls)) {
@@ -940,7 +922,7 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
940922
break;
941923
}
942924
TRACE_RECORD(ZEND_JIT_TRACE_BACK, 0, op_array);
943-
count = zend_jit_trace_recursive_ret_count(&EX(func)->op_array, unrolled_calls, ret_level);
925+
const int count = zend_jit_trace_recursive_ret_count(&EX(func)->op_array, unrolled_calls, ret_level);
944926
if (opline == orig_opline) {
945927
if (count + 1 >= JIT_G(max_recursive_returns)) {
946928
stop = ZEND_JIT_TRACE_STOP_RECURSIVE_RET;
@@ -998,9 +980,6 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
998980
if (EX(call) != prev_call) {
999981
if (EX(call)
1000982
&& EX(call)->prev_execute_data == prev_call) {
1001-
zend_function *func;
1002-
zend_jit_op_array_trace_extension *jit_extension;
1003-
1004983
if (EX(call)->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
1005984
/* TODO: Can we continue recording ??? */
1006985
stop = ZEND_JIT_TRACE_STOP_TRAMPOLINE;
@@ -1010,15 +989,15 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
1010989
stop = ZEND_JIT_TRACE_STOP_BAD_FUNC;
1011990
break;
1012991
}
1013-
func = EX(call)->func;
992+
zend_function *func = EX(call)->func;
1014993
if (func->type == ZEND_INTERNAL_FUNCTION
1015994
&& (func->op_array.fn_flags & (ZEND_ACC_CLOSURE|ZEND_ACC_FAKE_CLOSURE))) {
1016995
stop = ZEND_JIT_TRACE_STOP_BAD_FUNC;
1017996
break;
1018997
}
1019998
if (func->type == ZEND_USER_FUNCTION
1020999
&& (func->op_array.fn_flags & ZEND_ACC_CLOSURE)) {
1021-
jit_extension =
1000+
zend_jit_op_array_trace_extension *const jit_extension =
10221001
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(&func->op_array);
10231002
if (UNEXPECTED(!jit_extension)
10241003
|| !(jit_extension->func_info.flags & ZEND_FUNC_JIT_ON_HOT_TRACE)
@@ -1059,7 +1038,7 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
10591038
break;
10601039
}
10611040

1062-
trace_flags = ZEND_OP_TRACE_INFO(opline, offset)->trace_flags;
1041+
const uint8_t trace_flags = ZEND_OP_TRACE_INFO(opline, offset)->trace_flags;
10631042
if (trace_flags) {
10641043
if (trace_flags & ZEND_JIT_TRACE_JITED) {
10651044
if (trace_flags & ZEND_JIT_TRACE_START_LOOP) {
@@ -1144,7 +1123,7 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
11441123
}
11451124
}
11461125

1147-
end_opline = opline;
1126+
const zend_op *end_opline = opline;
11481127
if (!ZEND_JIT_TRACE_STOP_OK(stop)) {
11491128
if (backtrack_recursion > 0) {
11501129
idx = backtrack_recursion;

0 commit comments

Comments
 (0)