Skip to content

Commit 93cf649

Browse files
committed
Zend: Convert _zend_op_array.last_try_catch field to uint32_t
1 parent 49ff6e4 commit 93cf649

File tree

12 files changed

+23
-26
lines changed

12 files changed

+23
-26
lines changed

Zend/Optimizer/block_pass.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ static void assemble_code_blocks(zend_cfg *cfg, zend_op_array *op_array, zend_op
11171117

11181118
/* adjust exception jump targets & remove unused try_catch_array entries */
11191119
if (op_array->last_try_catch) {
1120-
int i, j;
1120+
uint32_t i, j;
11211121
uint32_t *map;
11221122
ALLOCA_FLAG(use_heap);
11231123

@@ -1157,7 +1157,7 @@ static void assemble_code_blocks(zend_cfg *cfg, zend_op_array *op_array, zend_op
11571157
while (opline < end) {
11581158
if (opline->opcode == ZEND_FAST_RET &&
11591159
opline->op2.num != (uint32_t)-1 &&
1160-
opline->op2.num < (uint32_t)j) {
1160+
opline->op2.num < j) {
11611161
opline->op2.num = map[opline->op2.num];
11621162
}
11631163
opline++;

Zend/Optimizer/dfa_pass.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static void zend_ssa_remove_nops(zend_op_array *op_array, zend_ssa *ssa, zend_op
226226
}
227227

228228
/* update try/catch array */
229-
for (j = 0; j < op_array->last_try_catch; j++) {
229+
for (uint32_t j = 0; j < op_array->last_try_catch; j++) {
230230
op_array->try_catch_array[j].try_op -= shiftlist[op_array->try_catch_array[j].try_op];
231231
op_array->try_catch_array[j].catch_op -= shiftlist[op_array->try_catch_array[j].catch_op];
232232
if (op_array->try_catch_array[j].finally_op) {

Zend/Optimizer/nop_removal.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ void zend_optimizer_nop_removal(zend_op_array *op_array, zend_optimizer_ctx *ctx
3434
{
3535
zend_op *end, *opline;
3636
uint32_t new_count, i, shift;
37-
int j;
3837
uint32_t *shiftlist;
3938
ALLOCA_FLAG(use_heap);
4039

@@ -81,7 +80,7 @@ void zend_optimizer_nop_removal(zend_op_array *op_array, zend_optimizer_ctx *ctx
8180
}
8281

8382
/* update try/catch array */
84-
for (j = 0; j < op_array->last_try_catch; j++) {
83+
for (uint32_t j = 0; j < op_array->last_try_catch; j++) {
8584
op_array->try_catch_array[j].try_op -= shiftlist[op_array->try_catch_array[j].try_op];
8685
op_array->try_catch_array[j].catch_op -= shiftlist[op_array->try_catch_array[j].catch_op];
8786
if (op_array->try_catch_array[j].finally_op) {

Zend/Optimizer/zend_cfg.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array,
274274
{
275275
uint32_t flags = 0;
276276
uint32_t i;
277-
int j;
278277
uint32_t *block_map;
279278
zend_function *fn;
280279
int blocks_count = 0;
@@ -449,7 +448,7 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array,
449448
}
450449

451450
if (op_array->last_try_catch) {
452-
for (j = 0; j < op_array->last_try_catch; j++) {
451+
for (uint32_t j = 0; j < op_array->last_try_catch; j++) {
453452
BB_START(op_array->try_catch_array[j].try_op);
454453
if (op_array->try_catch_array[j].catch_op) {
455454
BB_START(op_array->try_catch_array[j].catch_op);
@@ -494,7 +493,7 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array,
494493
blocks_count++;
495494

496495
/* Build CFG, Step 3: Calculate successors */
497-
for (j = 0; j < blocks_count; j++) {
496+
for (int j = 0; j < blocks_count; j++) {
498497
zend_basic_block *block = &blocks[j];
499498
zend_op *opline;
500499
if (block->len == 0) {

Zend/Optimizer/zend_dump.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_fl
10831083
}
10841084
if (op_array->last_try_catch) {
10851085
fprintf(stderr, "EXCEPTION TABLE:\n");
1086-
for (int i = 0; i < op_array->last_try_catch; i++) {
1086+
for (uint32_t i = 0; i < op_array->last_try_catch; i++) {
10871087
fprintf(stderr, " BB%u",
10881088
cfg->map[op_array->try_catch_array[i].try_op]);
10891089
if (op_array->try_catch_array[i].catch_op) {
@@ -1143,7 +1143,7 @@ ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_fl
11431143
}
11441144
if (op_array->last_try_catch) {
11451145
fprintf(stderr, "EXCEPTION TABLE:\n");
1146-
for (int i = 0; i < op_array->last_try_catch; i++) {
1146+
for (uint32_t i = 0; i < op_array->last_try_catch; i++) {
11471147
fprintf(stderr,
11481148
" %04u",
11491149
op_array->try_catch_array[i].try_op);

Zend/zend_compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5863,7 +5863,7 @@ static void zend_compile_break_continue(zend_ast *ast) /* {{{ */
58635863
void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline) /* {{{ */
58645864
{
58655865
zend_label *dest;
5866-
int current, remove_oplines = opline->op1.num;
5866+
int remove_oplines = opline->op1.num;
58675867
zval *label;
58685868
uint32_t opnum = opline - op_array->opcodes;
58695869

@@ -5880,7 +5880,7 @@ void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline) /* {{{ */
58805880
zval_ptr_dtor_str(label);
58815881
ZVAL_NULL(label);
58825882

5883-
current = opline->extended_value;
5883+
uint32_t current = opline->extended_value;
58845884
for (; current != dest->brk_cont; current = CG(context).brk_cont_array[current].parent) {
58855885
if (current == -1) {
58865886
CG(in_compilation) = 1;

Zend/zend_compile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ struct _zend_op_array {
541541
uint32_t *refcount;
542542

543543
uint32_t last_live_range;
544-
int last_try_catch;
544+
uint32_t last_try_catch;
545545
zend_live_range *live_range;
546546
zend_try_catch_element *try_catch_array;
547547

Zend/zend_generators.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */
244244
zend_generator *current_generator = zend_generator_get_current(generator);
245245
zend_execute_data *ex = generator->execute_data;
246246
uint32_t op_num, try_catch_offset;
247-
int i;
248247

249248
/* If current_generator is running in a fiber, there are 2 cases to consider:
250249
* - If generator is also marked with ZEND_GENERATOR_IN_FIBER, then the
@@ -289,7 +288,7 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */
289288
try_catch_offset = -1;
290289

291290
/* Find the innermost try/catch that we are inside of. */
292-
for (i = 0; i < ex->func->op_array.last_try_catch; i++) {
291+
for (uint32_t i = 0; i < ex->func->op_array.last_try_catch; i++) {
293292
zend_try_catch_element *try_catch = &ex->func->op_array.try_catch_array[i];
294293
if (op_num < try_catch->try_op) {
295294
break;

Zend/zend_opcode.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,7 @@ static void zend_extension_op_array_handler(zend_extension *extension, zend_op_a
686686

687687
static void zend_check_finally_breakout(zend_op_array *op_array, uint32_t op_num, uint32_t dst_num)
688688
{
689-
int i;
690-
691-
for (i = 0; i < op_array->last_try_catch; i++) {
689+
for (uint32_t i = 0; i < op_array->last_try_catch; i++) {
692690
if ((op_num < op_array->try_catch_array[i].finally_op ||
693691
op_num >= op_array->try_catch_array[i].finally_end)
694692
&& (dst_num >= op_array->try_catch_array[i].finally_op &&

Zend/zend_vm_def.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
* php zend_vm_gen.php
2424
*/
2525

26+
#include <stdint.h>
27+
2628
ZEND_VM_HELPER(zend_add_helper, ANY, ANY, zval *op_1, zval *op_2)
2729
{
2830
USE_OPLINE
@@ -8151,7 +8153,7 @@ ZEND_VM_HANDLER(149, ZEND_HANDLE_EXCEPTION, ANY, ANY)
81518153
}
81528154

81538155
uint32_t throw_op_num = throw_op - EX(func)->op_array.opcodes;
8154-
int i, current_try_catch_offset = -1;
8156+
uint32_t current_try_catch_offset = -1;
81558157

81568158
if ((throw_op->opcode == ZEND_FREE || throw_op->opcode == ZEND_FE_FREE)
81578159
&& throw_op->extended_value & ZEND_FREE_ON_RETURN) {
@@ -8162,7 +8164,7 @@ ZEND_VM_HANDLER(149, ZEND_HANDLE_EXCEPTION, ANY, ANY)
81628164
const zend_live_range *range = find_live_range(
81638165
&EX(func)->op_array, throw_op_num, throw_op->op1.var);
81648166
/* free op1 of the corresponding RETURN */
8165-
for (i = throw_op_num; i < range->end; i++) {
8167+
for (uint32_t i = throw_op_num; i < range->end; i++) {
81668168
if (EX(func)->op_array.opcodes[i].opcode == ZEND_FREE
81678169
|| EX(func)->op_array.opcodes[i].opcode == ZEND_FE_FREE) {
81688170
/* pass */
@@ -8178,7 +8180,7 @@ ZEND_VM_HANDLER(149, ZEND_HANDLE_EXCEPTION, ANY, ANY)
81788180
}
81798181

81808182
/* Find the innermost try/catch/finally the exception was thrown in */
8181-
for (i = 0; i < EX(func)->op_array.last_try_catch; i++) {
8183+
for (uint32_t i = 0; i < EX(func)->op_array.last_try_catch; i++) {
81828184
zend_try_catch_element *try_catch = &EX(func)->op_array.try_catch_array[i];
81838185
if (try_catch->try_op > throw_op_num) {
81848186
/* further blocks will not be relevant... */

0 commit comments

Comments
 (0)