Commit 83b8a895a5d for php.net

commit 83b8a895a5d914e24845eac0ca86ec8da89d9eaa
Author: Gina Peter Banyard <girgias@php.net>
Date:   Fri Mar 27 22:09:56 2026 +0000

    zend_cfg: use uint32_t type rather than int type (#21542)

    These are count values and thus should never be negative, more over their use site usually wants them to be uint32_t too.
    Aligning these types makes the intention clearer.

    I have also propagated those changes to use sites of these struct members.

diff --git a/Zend/Optimizer/block_pass.c b/Zend/Optimizer/block_pass.c
index 5a0af263039..61a69dae51e 100644
--- a/Zend/Optimizer/block_pass.c
+++ b/Zend/Optimizer/block_pass.c
@@ -1185,7 +1185,7 @@ static void assemble_code_blocks(const zend_cfg *cfg, zend_op_array *op_array, z

 	/* rebuild map (just for printing) */
 	memset(cfg->map, -1, sizeof(int) * op_array->last);
-	for (int n = 0; n < cfg->blocks_count; n++) {
+	for (uint32_t n = 0; n < cfg->blocks_count; n++) {
 		if (cfg->blocks[n].flags & (ZEND_BB_REACHABLE|ZEND_BB_UNREACHABLE_FREE)) {
 			cfg->map[cfg->blocks[n].start] = n;
 		}
@@ -1493,7 +1493,7 @@ static void zend_jmp_optimization(zend_basic_block *block, zend_op_array *op_arr
  * defined. We won't apply some optimization patterns for such variables. */
 static void zend_t_usage(const zend_cfg *cfg, const zend_op_array *op_array, zend_bitset used_ext, zend_optimizer_ctx *ctx)
 {
-	int n;
+	uint32_t n;
 	zend_basic_block *block, *next_block;
 	uint32_t var_num;
 	uint32_t bitset_len;
@@ -1697,11 +1697,10 @@ static void zend_t_usage(const zend_cfg *cfg, const zend_op_array *op_array, zen

 static void zend_merge_blocks(const zend_op_array *op_array, const zend_cfg *cfg, uint32_t *opt_count)
 {
-	int i;
 	zend_basic_block *b, *bb;
 	zend_basic_block *prev = NULL;

-	for (i = 0; i < cfg->blocks_count; i++) {
+	for (uint32_t i = 0; i < cfg->blocks_count; i++) {
 		b = cfg->blocks + i;
 		if (b->flags & ZEND_BB_REACHABLE) {
 			if ((b->flags & ZEND_BB_FOLLOW) &&
diff --git a/Zend/Optimizer/dce.c b/Zend/Optimizer/dce.c
index 6c5a885fba4..a529f5a1944 100644
--- a/Zend/Optimizer/dce.c
+++ b/Zend/Optimizer/dce.c
@@ -571,7 +571,7 @@ int dce_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *optimizer
 	} FOREACH_PHI_END();

 	/* Mark reachable instruction without side effects as dead */
-	int b = ssa->cfg.blocks_count;
+	uint32_t b = ssa->cfg.blocks_count;
 	while (b > 0) {
 		int	op_data = -1;

diff --git a/Zend/Optimizer/dfa_pass.c b/Zend/Optimizer/dfa_pass.c
index 796e998493d..a30367c343f 100644
--- a/Zend/Optimizer/dfa_pass.c
+++ b/Zend/Optimizer/dfa_pass.c
@@ -479,7 +479,7 @@ int zend_dfa_optimize_calls(zend_op_array *op_array, zend_ssa *ssa)
 	return removed_ops;
 }

-static zend_always_inline void take_successor_0(zend_ssa *ssa, int block_num, zend_basic_block *block)
+static zend_always_inline void take_successor_0(zend_ssa *ssa, uint32_t block_num, zend_basic_block *block)
 {
 	if (block->successors_count == 2) {
 		if (block->successors[1] != block->successors[0]) {
@@ -489,7 +489,7 @@ static zend_always_inline void take_successor_0(zend_ssa *ssa, int block_num, ze
 	}
 }

-static zend_always_inline void take_successor_1(zend_ssa *ssa, int block_num, zend_basic_block *block)
+static zend_always_inline void take_successor_1(zend_ssa *ssa, uint32_t block_num, zend_basic_block *block)
 {
 	if (block->successors_count == 2) {
 		if (block->successors[1] != block->successors[0]) {
@@ -500,11 +500,9 @@ static zend_always_inline void take_successor_1(zend_ssa *ssa, int block_num, ze
 	}
 }

-static zend_always_inline void take_successor_ex(zend_ssa *ssa, int block_num, zend_basic_block *block, int target_block)
+static zend_always_inline void take_successor_ex(zend_ssa *ssa, uint32_t block_num, zend_basic_block *block, int target_block)
 {
-	int i;
-
-	for (i = 0; i < block->successors_count; i++) {
+	for (uint32_t i = 0; i < block->successors_count; i++) {
 		if (block->successors[i] != target_block) {
 			zend_ssa_remove_predecessor(ssa, block_num, block->successors[i]);
 		}
@@ -531,10 +529,9 @@ static void replace_predecessor(zend_ssa *ssa, int block_id, int old_pred, int n
 	int *predecessors = &ssa->cfg.predecessors[block->predecessor_offset];
 	zend_ssa_phi *phi;

-	int i;
 	int old_pred_idx = -1;
 	int new_pred_idx = -1;
-	for (i = 0; i < block->predecessors_count; i++) {
+	for (uint32_t i = 0; i < block->predecessors_count; i++) {
 		if (predecessors[i] == old_pred) {
 			old_pred_idx = i;
 		}
@@ -582,10 +579,9 @@ static void zend_ssa_replace_control_link(zend_op_array *op_array, zend_ssa *ssa
 	zend_basic_block *src = &ssa->cfg.blocks[from];
 	zend_basic_block *old = &ssa->cfg.blocks[to];
 	zend_basic_block *dst = &ssa->cfg.blocks[new_to];
-	int i;
 	zend_op *opline;

-	for (i = 0; i < src->successors_count; i++) {
+	for (uint32_t i = 0; i < src->successors_count; i++) {
 		if (src->successors[i] == to) {
 			src->successors[i] = new_to;
 		}
@@ -650,10 +646,10 @@ static void zend_ssa_replace_control_link(zend_op_array *op_array, zend_ssa *ssa
 	replace_predecessor(ssa, new_to, to, from);
 }

-static void zend_ssa_unlink_block(zend_op_array *op_array, zend_ssa *ssa, zend_basic_block *block, int block_num)
+static void zend_ssa_unlink_block(zend_op_array *op_array, zend_ssa *ssa, zend_basic_block *block, uint32_t block_num)
 {
 	if (block->predecessors_count == 1 && ssa->blocks[block_num].phis == NULL) {
-		int *predecessors, i;
+		int *predecessors;
 		zend_basic_block *fe_fetch_block = NULL;

 		ZEND_ASSERT(block->successors_count == 1);
@@ -669,7 +665,7 @@ static void zend_ssa_unlink_block(zend_op_array *op_array, zend_ssa *ssa, zend_b
 			    }
 			}
 		}
-		for (i = 0; i < block->predecessors_count; i++) {
+		for (uint32_t i = 0; i < block->predecessors_count; i++) {
 			zend_ssa_replace_control_link(op_array, ssa, predecessors[i], block_num, block->successors[0]);
 		}
 		zend_ssa_remove_block(op_array, ssa, block_num);
@@ -686,7 +682,7 @@ static void zend_ssa_unlink_block(zend_op_array *op_array, zend_ssa *ssa, zend_b
 static int zend_dfa_optimize_jmps(zend_op_array *op_array, zend_ssa *ssa)
 {
 	int removed_ops = 0;
-	int block_num = 0;
+	uint32_t block_num = 0;

 	for (block_num = 1; block_num < ssa->cfg.blocks_count; block_num++) {
 		zend_basic_block *block = &ssa->cfg.blocks[block_num];
@@ -706,7 +702,7 @@ static int zend_dfa_optimize_jmps(zend_op_array *op_array, zend_ssa *ssa)
 		block_num++;
 	}
 	while (block_num < ssa->cfg.blocks_count) {
-		int next_block_num = block_num + 1;
+		uint32_t next_block_num = block_num + 1;
 		zend_basic_block *block = &ssa->cfg.blocks[block_num];
 		uint32_t op_num;
 		zend_op *opline;
@@ -941,11 +937,13 @@ static int zend_dfa_optimize_jmps(zend_op_array *op_array, zend_ssa *ssa)
 						if (block_num > 0) {
 							zend_ssa_unlink_block(op_array, ssa, block, block_num);
 							/* backtrack to previous basic block */
+							int backtracking_block_num = block_num;
 							do {
-								block_num--;
-							} while (block_num >= 0
-								&& !(ssa->cfg.blocks[block_num].flags & ZEND_BB_REACHABLE));
-							if (block_num >= 0) {
+								backtracking_block_num--;
+							} while (backtracking_block_num >= 0
+								&& !(ssa->cfg.blocks[backtracking_block_num].flags & ZEND_BB_REACHABLE));
+							if (backtracking_block_num >= 0) {
+								block_num = backtracking_block_num;
 								continue;
 							}
 						}
diff --git a/Zend/Optimizer/escape_analysis.c b/Zend/Optimizer/escape_analysis.c
index 00ee3298450..5ace81f3522 100644
--- a/Zend/Optimizer/escape_analysis.c
+++ b/Zend/Optimizer/escape_analysis.c
@@ -78,7 +78,7 @@ static zend_result zend_build_equi_escape_sets(int *parent, zend_op_array *op_ar
 	zend_ssa_var *ssa_vars = ssa->vars;
 	int ssa_vars_count = ssa->vars_count;
 	zend_ssa_phi *p;
-	int i, j;
+	int i;
 	int *size;
 	ALLOCA_FLAG(use_heap)

@@ -94,7 +94,7 @@ static zend_result zend_build_equi_escape_sets(int *parent, zend_op_array *op_ar
 			if (p->pi >= 0) {
 				union_find_unite(parent, size, i, p->sources[0]);
 			} else {
-				for (j = 0; j < ssa->cfg.blocks[p->block].predecessors_count; j++) {
+				for (uint32_t j = 0; j < ssa->cfg.blocks[p->block].predecessors_count; j++) {
 					union_find_unite(parent, size, i, p->sources[j]);
 				}
 			}
diff --git a/Zend/Optimizer/sccp.c b/Zend/Optimizer/sccp.c
index 60afe3165f7..1457e7467cf 100644
--- a/Zend/Optimizer/sccp.c
+++ b/Zend/Optimizer/sccp.c
@@ -1832,7 +1832,7 @@ static void sccp_mark_feasible_successors(
 		zend_op *opline, zend_ssa_op *ssa_op) {
 	sccp_ctx *ctx = (sccp_ctx *) scdf;
 	zval *op1, zv;
-	int s;
+	uint32_t s;

 	/* We can't determine the branch target at compile-time for these */
 	switch (opline->opcode) {
@@ -2049,7 +2049,6 @@ static void sccp_visit_phi(scdf_ctx *scdf, const zend_ssa_phi *phi) {
 		zend_basic_block *block = &ssa->cfg.blocks[phi->block];
 		int *predecessors = &ssa->cfg.predecessors[block->predecessor_offset];

-		int i;
 		zval result;
 		MAKE_TOP(&result);
 #if SCP_DEBUG
@@ -2061,7 +2060,7 @@ static void sccp_visit_phi(scdf_ctx *scdf, const zend_ssa_phi *phi) {
 				join_phi_values(&result, &ctx->values[phi->sources[0]], ssa->vars[phi->ssa_var].escape_state != ESCAPE_STATE_NO_ESCAPE);
 			}
 		} else {
-			for (i = 0; i < block->predecessors_count; i++) {
+			for (uint32_t i = 0; i < block->predecessors_count; i++) {
 				ZEND_ASSERT(phi->sources[i] >= 0);
 				if (scdf_is_edge_feasible(scdf, predecessors[i], phi->block)) {
 #if SCP_DEBUG
diff --git a/Zend/Optimizer/scdf.c b/Zend/Optimizer/scdf.c
index e5c40b8c90c..cf7b80bc866 100644
--- a/Zend/Optimizer/scdf.c
+++ b/Zend/Optimizer/scdf.c
@@ -254,9 +254,8 @@ static uint32_t cleanup_loop_var_free_block(const scdf_ctx *scdf, const zend_bas
  * unreachable. Blocks already marked unreachable are not removed. */
 uint32_t scdf_remove_unreachable_blocks(const scdf_ctx *scdf) {
 	zend_ssa *ssa = scdf->ssa;
-	int i;
 	uint32_t removed_ops = 0;
-	for (i = 0; i < ssa->cfg.blocks_count; i++) {
+	for (uint32_t i = 0; i < ssa->cfg.blocks_count; i++) {
 		const zend_basic_block *block = &ssa->cfg.blocks[i];
 		if (!zend_bitset_in(scdf->executable_blocks, i) && (block->flags & ZEND_BB_REACHABLE)) {
 			if (!kept_alive_by_loop_var_free(scdf, block)) {
diff --git a/Zend/Optimizer/scdf.h b/Zend/Optimizer/scdf.h
index 49222880f22..c3f1d8e885c 100644
--- a/Zend/Optimizer/scdf.h
+++ b/Zend/Optimizer/scdf.h
@@ -75,11 +75,10 @@ static inline void scdf_add_def_to_worklist(const scdf_ctx *scdf, int var_num) {
 	}
 }

-static inline uint32_t scdf_edge(const zend_cfg *cfg, int from, int to) {
+static inline uint32_t scdf_edge(const zend_cfg *cfg, int from, uint32_t to) {
 	const zend_basic_block *to_block = cfg->blocks + to;
-	int i;

-	for (i = 0; i < to_block->predecessors_count; i++) {
+	for (uint32_t i = 0; i < to_block->predecessors_count; i++) {
 		uint32_t edge = to_block->predecessor_offset + i;

 		if (cfg->predecessors[edge] == from) {
@@ -89,7 +88,7 @@ static inline uint32_t scdf_edge(const zend_cfg *cfg, int from, int to) {
 	ZEND_UNREACHABLE();
 }

-static inline bool scdf_is_edge_feasible(const scdf_ctx *scdf, int from, int to) {
+static inline bool scdf_is_edge_feasible(const scdf_ctx *scdf, int from, uint32_t to) {
 	uint32_t edge = scdf_edge(&scdf->ssa->cfg, from, to);
 	return zend_bitset_in(scdf->feasible_edges, edge);
 }
diff --git a/Zend/Optimizer/ssa_integrity.c b/Zend/Optimizer/ssa_integrity.c
index 793fb1c06c8..4c720714ca5 100644
--- a/Zend/Optimizer/ssa_integrity.c
+++ b/Zend/Optimizer/ssa_integrity.c
@@ -66,8 +66,8 @@ static inline bool is_in_phi_sources(zend_ssa *ssa, zend_ssa_phi *phi, int check
 }

 static inline bool is_in_predecessors(zend_cfg *cfg, zend_basic_block *block, int check) {
-	int i, *predecessors = &cfg->predecessors[block->predecessor_offset];
-	for (i = 0; i < block->predecessors_count; i++) {
+	int *predecessors = &cfg->predecessors[block->predecessor_offset];
+	for (uint32_t i = 0; i < block->predecessors_count; i++) {
 		if (predecessors[i] == check) {
 			return true;
 		}
@@ -76,8 +76,7 @@ static inline bool is_in_predecessors(zend_cfg *cfg, zend_basic_block *block, in
 }

 static inline bool is_in_successors(zend_basic_block *block, int check) {
-	int s;
-	for (s = 0; s < block->successors_count; s++) {
+	for (uint32_t s = 0; s < block->successors_count; s++) {
 		if (block->successors[s] == check) {
 			return true;
 		}
@@ -329,7 +328,7 @@ void ssa_verify_integrity(zend_op_array *op_array, zend_ssa *ssa, const char *ex

 	/* Phis */
 	FOREACH_PHI(phi) {
-		unsigned num_sources = NUM_PHI_SOURCES(phi);
+		uint32_t num_sources = NUM_PHI_SOURCES(phi);
 		for (i = 0; i < num_sources; i++) {
 			int source = phi->sources[i];
 			if (source < 0) {
@@ -360,7 +359,7 @@ void ssa_verify_integrity(zend_op_array *op_array, zend_ssa *ssa, const char *ex
 	for (i = 0; i < cfg->blocks_count; i++) {
 		zend_basic_block *block = &cfg->blocks[i];
 		int *predecessors = &cfg->predecessors[block->predecessor_offset];
-		int s, j;
+		uint32_t j;

 		if (i != 0 && block->start < (block-1)->start + (block-1)->len) {
 			FAIL("Block %d start %d smaller previous end %d\n",
@@ -384,7 +383,7 @@ void ssa_verify_integrity(zend_op_array *op_array, zend_ssa *ssa, const char *ex
 			continue;
 		}

-		for (s = 0; s < block->successors_count; s++) {
+		for (uint32_t s = 0; s < block->successors_count; s++) {
 			zend_basic_block *next_block;
 			if (block->successors[s] < 0) {
 				FAIL("Successor number %d of %d negative", s, i);
@@ -400,7 +399,6 @@ void ssa_verify_integrity(zend_op_array *op_array, zend_ssa *ssa, const char *ex

 		for (j = 0; j < block->predecessors_count; j++) {
 			if (predecessors[j] >= 0) {
-				int k;
 				zend_basic_block *prev_block = &cfg->blocks[predecessors[j]];
 				if (!(prev_block->flags & ZEND_BB_REACHABLE)) {
 					FAIL("Predecessor %d of %d not reachable\n", predecessors[j], i);
@@ -408,7 +406,7 @@ void ssa_verify_integrity(zend_op_array *op_array, zend_ssa *ssa, const char *ex
 				if (!is_in_successors(prev_block, i)) {
 					FAIL("Block %d successors missing %d\n", predecessors[j], i);
 				}
-				for (k = 0; k < block->predecessors_count; k++) {
+				for (uint32_t k = 0; k < block->predecessors_count; k++) {
 					if (k != j && predecessors[k] == predecessors[j]) {
 						FAIL("Block %d has duplicate predecessor %d\n", i, predecessors[j]);
 					}
diff --git a/Zend/Optimizer/zend_cfg.c b/Zend/Optimizer/zend_cfg.c
index 32d5f49ef7d..bdb3a057053 100644
--- a/Zend/Optimizer/zend_cfg.c
+++ b/Zend/Optimizer/zend_cfg.c
@@ -35,7 +35,6 @@ static void zend_mark_reachable(zend_op *opcodes, zend_cfg *cfg, zend_basic_bloc
 	zend_worklist_push(&work, b - cfg->blocks);

 	while (zend_worklist_len(&work)) {
-		int i;
 		b = cfg->blocks + zend_worklist_pop(&work);

 		b->flags |= ZEND_BB_REACHABLE;
@@ -44,7 +43,7 @@ static void zend_mark_reachable(zend_op *opcodes, zend_cfg *cfg, zend_basic_bloc
 			continue;
 		}

-		for (i = 0; i < b->successors_count; i++) {
+		for (uint32_t i = 0; i < b->successors_count; i++) {
 			zend_basic_block *succ = blocks + b->successors[i];

 			if (b->len != 0) {
@@ -104,7 +103,7 @@ static void zend_mark_reachable(zend_op *opcodes, zend_cfg *cfg, zend_basic_bloc
 }
 /* }}} */

-static void zend_mark_reachable_blocks(const zend_op_array *op_array, zend_cfg *cfg, int start) /* {{{ */
+static void zend_mark_reachable_blocks(const zend_op_array *op_array, zend_cfg *cfg, uint32_t start) /* {{{ */
 {
 	zend_basic_block *blocks = cfg->blocks;

@@ -113,14 +112,14 @@ static void zend_mark_reachable_blocks(const zend_op_array *op_array, zend_cfg *

 	if (op_array->last_try_catch) {
 		zend_basic_block *b;
-		int j, changed;
+		int changed;
 		uint32_t *block_map = cfg->map;

 		do {
 			changed = 0;

 			/* Add exception paths */
-			for (j = 0; j < op_array->last_try_catch; j++) {
+			for (uint32_t j = 0; j < op_array->last_try_catch; j++) {

 				/* check for jumps into the middle of try block */
 				b = blocks + block_map[op_array->try_catch_array[j].try_op];
@@ -202,7 +201,6 @@ static void zend_mark_reachable_blocks(const zend_op_array *op_array, zend_cfg *

 	if (cfg->flags & ZEND_FUNC_FREE_LOOP_VAR) {
 		zend_basic_block *b;
-		int j;
 		uint32_t *block_map = cfg->map;

 		/* Mark blocks that are unreachable, but free a loop var created in a reachable block. */
@@ -211,7 +209,7 @@ static void zend_mark_reachable_blocks(const zend_op_array *op_array, zend_cfg *
 				continue;
 			}

-			for (j = b->start; j < b->start + b->len; j++) {
+			for (uint32_t j = b->start; j < b->start + b->len; j++) {
 				zend_op *opline = &op_array->opcodes[j];
 				if (zend_optimizer_is_loop_var_free(opline)) {
 					zend_op *def_opline = zend_optimizer_get_loop_var_def(op_array, opline);
@@ -232,8 +230,8 @@ static void zend_mark_reachable_blocks(const zend_op_array *op_array, zend_cfg *
 void zend_cfg_remark_reachable_blocks(const zend_op_array *op_array, zend_cfg *cfg) /* {{{ */
 {
 	zend_basic_block *blocks = cfg->blocks;
-	int i;
-	int start = 0;
+	uint32_t i;
+	uint32_t start = 0;

 	for (i = 0; i < cfg->blocks_count; i++) {
 		if (blocks[i].flags & ZEND_BB_REACHABLE) {
@@ -593,13 +591,12 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array,

 ZEND_API void zend_cfg_build_predecessors(zend_arena **arena, zend_cfg *cfg) /* {{{ */
 {
-	int j, s, edges;
 	zend_basic_block *b;
 	zend_basic_block *blocks = cfg->blocks;
 	zend_basic_block *end = blocks + cfg->blocks_count;
+	uint32_t edges = 0;
 	int *predecessors;

-	edges = 0;
 	for (b = blocks; b < end; b++) {
 		b->predecessors_count = 0;
 	}
@@ -608,7 +605,7 @@ ZEND_API void zend_cfg_build_predecessors(zend_arena **arena, zend_cfg *cfg) /*
 			b->successors_count = 0;
 			b->predecessors_count = 0;
 		} else {
-			for (s = 0; s < b->successors_count; s++) {
+			for (uint32_t s = 0; s < b->successors_count; s++) {
 				edges++;
 				blocks[b->successors[s]].predecessors_count++;
 			}
@@ -627,14 +624,13 @@ ZEND_API void zend_cfg_build_predecessors(zend_arena **arena, zend_cfg *cfg) /*
 		}
 	}

-	for (j = 0; j < cfg->blocks_count; j++) {
+	for (uint32_t j = 0; j < cfg->blocks_count; j++) {
 		if (blocks[j].flags & ZEND_BB_REACHABLE) {
 			/* SWITCH_STRING/LONG may have few identical successors */
-			for (s = 0; s < blocks[j].successors_count; s++) {
+			for (uint32_t s = 0; s < blocks[j].successors_count; s++) {
 				int duplicate = 0;
-				int p;

-				for (p = 0; p < s; p++) {
+				for (uint32_t p = 0; p < s; p++) {
 					if (blocks[j].successors[p] == blocks[j].successors[s]) {
 						duplicate = 1;
 						break;
@@ -654,16 +650,15 @@ ZEND_API void zend_cfg_build_predecessors(zend_arena **arena, zend_cfg *cfg) /*

 /* Computes a postorder numbering of the CFG */
 static void compute_postnum_recursive(
-		int *postnum, int *cur, const zend_cfg *cfg, int block_num) /* {{{ */
+		int *postnum, uint32_t *cur, const zend_cfg *cfg, int block_num) /* {{{ */
 {
-	int s;
 	zend_basic_block *block = &cfg->blocks[block_num];
 	if (postnum[block_num] != -1) {
 		return;
 	}

 	postnum[block_num] = -2; /* Marker for "currently visiting" */
-	for (s = 0; s < block->successors_count; s++) {
+	for (uint32_t s = 0; s < block->successors_count; s++) {
 		compute_postnum_recursive(postnum, cur, cfg, block->successors[s]);
 	}
 	postnum[block_num] = (*cur)++;
@@ -675,8 +670,9 @@ static void compute_postnum_recursive(
 ZEND_API void zend_cfg_compute_dominators_tree(const zend_op_array *op_array, zend_cfg *cfg) /* {{{ */
 {
 	zend_basic_block *blocks = cfg->blocks;
-	int blocks_count = cfg->blocks_count;
-	int j, k, changed;
+	uint32_t blocks_count = cfg->blocks_count;
+	uint32_t j;
+	int changed;

 	if (cfg->blocks_count == 1) {
 		blocks[0].level = 0;
@@ -700,7 +696,7 @@ ZEND_API void zend_cfg_compute_dominators_tree(const zend_op_array *op_array, ze
 			if ((blocks[j].flags & ZEND_BB_REACHABLE) == 0) {
 				continue;
 			}
-			for (k = 0; k < blocks[j].predecessors_count; k++) {
+			for (uint32_t k = 0; k < blocks[j].predecessors_count; k++) {
 				int pred = cfg->predecessors[blocks[j].predecessor_offset + k];

 				if (blocks[pred].idom >= 0) {
@@ -776,7 +772,7 @@ static bool dominates(zend_basic_block *blocks, int a, int b) /* {{{ */

 ZEND_API void zend_cfg_identify_loops(const zend_op_array *op_array, zend_cfg *cfg) /* {{{ */
 {
-	int i, j, k, n;
+	int i, j, n;
 	int time;
 	zend_basic_block *blocks = cfg->blocks;
 	int *entry_times, *exit_times;
@@ -890,7 +886,7 @@ ZEND_API void zend_cfg_identify_loops(const zend_op_array *op_array, zend_cfg *c
 					continue;
 				}
 				blocks[j].loop_header = i;
-				for (k = 0; k < blocks[j].predecessors_count; k++) {
+				for (uint32_t k = 0; k < blocks[j].predecessors_count; k++) {
 					zend_worklist_push(&work, cfg->predecessors[blocks[j].predecessor_offset + k]);
 				}
 			}
diff --git a/Zend/Optimizer/zend_cfg.h b/Zend/Optimizer/zend_cfg.h
index 1f3885f511f..8096565e803 100644
--- a/Zend/Optimizer/zend_cfg.h
+++ b/Zend/Optimizer/zend_cfg.h
@@ -44,8 +44,8 @@ typedef struct _zend_basic_block {
 	uint32_t          flags;
 	uint32_t          start;              /* first opcode number         */
 	uint32_t          len;                /* number of opcodes           */
-	int               successors_count;   /* number of successors        */
-	int               predecessors_count; /* number of predecessors      */
+	uint32_t          successors_count;   /* number of successors        */
+	uint32_t          predecessors_count; /* number of predecessors      */
 	int               predecessor_offset; /* offset of 1-st predecessor, or -1 */
 	int               idom;               /* immediate dominator block, or -1  */
 	int               loop_header;        /* closest loop header, or -1  */
@@ -82,8 +82,8 @@ typedef struct _zend_basic_block {
 */

 typedef struct _zend_cfg {
-	int               blocks_count;       /* number of basic blocks      */
-	int               edges_count;        /* number of edges             */
+	uint32_t          blocks_count;       /* number of basic blocks      */
+	uint32_t          edges_count;        /* number of edges             */
 	zend_basic_block *blocks;             /* array of basic blocks       */
 	int              *predecessors;
 	uint32_t         *map;
diff --git a/Zend/Optimizer/zend_dfg.c b/Zend/Optimizer/zend_dfg.c
index c14d67e873a..b6c0e3d801b 100644
--- a/Zend/Optimizer/zend_dfg.c
+++ b/Zend/Optimizer/zend_dfg.c
@@ -253,10 +253,9 @@ void zend_build_dfg(const zend_op_array *op_array, const zend_cfg *cfg, const ze
 {
 	uint32_t set_size = dfg->size;
 	zend_basic_block *blocks = cfg->blocks;
-	int blocks_count = cfg->blocks_count;
+	uint32_t blocks_count = cfg->blocks_count;
 	zend_bitset tmp, def, use, in, out;
-	int k;
-	int j;
+	uint32_t j;

 	tmp = dfg->tmp;
 	def = dfg->def;
@@ -305,7 +304,7 @@ void zend_build_dfg(const zend_op_array *op_array, const zend_cfg *cfg, const ze
 			}
 			if (blocks[j].successors_count != 0) {
 				zend_bitset_copy(DFG_BITSET(out, set_size, j), DFG_BITSET(in, set_size, blocks[j].successors[0]), set_size);
-				for (k = 1; k < blocks[j].successors_count; k++) {
+				for (uint32_t k = 1; k < blocks[j].successors_count; k++) {
 					zend_bitset_union(DFG_BITSET(out, set_size, j), DFG_BITSET(in, set_size, blocks[j].successors[k]), set_size);
 				}
 			} else {
@@ -318,7 +317,7 @@ void zend_build_dfg(const zend_op_array *op_array, const zend_cfg *cfg, const ze
 				/* Add predecessors of changed block to worklist */
 				{
 					const int *predecessors = &cfg->predecessors[blocks[j].predecessor_offset];
-					for (k = 0; k < blocks[j].predecessors_count; k++) {
+					for (uint32_t k = 0; k < blocks[j].predecessors_count; k++) {
 						zend_bitset_incl(worklist, predecessors[k]);
 					}
 				}
diff --git a/Zend/Optimizer/zend_dump.c b/Zend/Optimizer/zend_dump.c
index 7557c315b9b..56a2f65d6fb 100644
--- a/Zend/Optimizer/zend_dump.c
+++ b/Zend/Optimizer/zend_dump.c
@@ -868,7 +868,7 @@ static void zend_dump_block_info(const zend_cfg *cfg, int n, uint32_t dump_flags

 	if (b->successors_count > 0) {
 		fprintf(stderr, "     ; to=(BB%d", b->successors[0]);
-		for (int s = 1; s < b->successors_count; s++) {
+		for (uint32_t s = 1; s < b->successors_count; s++) {
 			fprintf(stderr, ", BB%d", b->successors[s]);
 		}
 		fprintf(stderr, ")\n");
@@ -906,7 +906,7 @@ static void zend_dump_block_header(const zend_cfg *cfg, const zend_op_array *op_
 			zend_dump_ssa_var(op_array, ssa, p->ssa_var, 0, p->var, dump_flags);
 			if (p->pi < 0) {
 				fprintf(stderr, " = Phi(");
-				for (int j = 0; j < cfg->blocks[n].predecessors_count; j++) {
+				for (uint32_t j = 0; j < cfg->blocks[n].predecessors_count; j++) {
 					if (j > 0) {
 						fprintf(stderr, ", ");
 					}
@@ -1037,7 +1037,7 @@ ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_fl
 	}

 	if (cfg) {
-		for (int n = 0; n < cfg->blocks_count; n++) {
+		for (uint32_t n = 0; n < cfg->blocks_count; n++) {
 			const zend_basic_block *b = cfg->blocks + n;
 			if (!(dump_flags & ZEND_DUMP_HIDE_UNREACHABLE) || (b->flags & ZEND_BB_REACHABLE)) {
 				const zend_op *opline;
@@ -1177,7 +1177,7 @@ void zend_dump_dominators(const zend_op_array *op_array, const zend_cfg *cfg)
 	fprintf(stderr, "\nDOMINATORS-TREE for \"");
 	zend_dump_op_array_name(op_array);
 	fprintf(stderr, "\"\n");
-	for (int j = 0; j < cfg->blocks_count; j++) {
+	for (uint32_t j = 0; j < cfg->blocks_count; j++) {
 		const zend_basic_block *b = cfg->blocks + j;
 		if (b->flags & ZEND_BB_REACHABLE) {
 			zend_dump_block_info(cfg, j, 0);
@@ -1232,7 +1232,7 @@ void zend_dump_dfg(const zend_op_array *op_array, const zend_cfg *cfg, const zen
 	zend_dump_op_array_name(op_array);
 	fprintf(stderr, "\"\n");

-	for (int j = 0; j < cfg->blocks_count; j++) {
+	for (uint32_t j = 0; j < cfg->blocks_count; j++) {
 		fprintf(stderr, "  BB%d:\n", j);
 		zend_dump_var_set(op_array, "def", DFG_BITSET(dfg->def, dfg->size, j));
 		zend_dump_var_set(op_array, "use", DFG_BITSET(dfg->use, dfg->size, j));
@@ -1244,12 +1244,12 @@ void zend_dump_dfg(const zend_op_array *op_array, const zend_cfg *cfg, const zen
 void zend_dump_phi_placement(const zend_op_array *op_array, const zend_ssa *ssa)
 {
 	const zend_ssa_block *ssa_blocks = ssa->blocks;
-	int blocks_count = ssa->cfg.blocks_count;
+	uint32_t blocks_count = ssa->cfg.blocks_count;

 	fprintf(stderr, "\nSSA Phi() Placement for \"");
 	zend_dump_op_array_name(op_array);
 	fprintf(stderr, "\"\n");
-	for (int j = 0; j < blocks_count; j++) {
+	for (uint32_t j = 0; j < blocks_count; j++) {
 		if (ssa_blocks && ssa_blocks[j].phis) {
 			const zend_ssa_phi *p = ssa_blocks[j].phis;
 			bool first = true;
diff --git a/Zend/Optimizer/zend_inference.c b/Zend/Optimizer/zend_inference.c
index 6963fc63dd1..c19d864f1bd 100644
--- a/Zend/Optimizer/zend_inference.c
+++ b/Zend/Optimizer/zend_inference.c
@@ -493,7 +493,7 @@ ZEND_API void zend_ssa_find_false_dependencies(const zend_op_array *op_array, co
 	const zend_ssa_op *ssa_ops = ssa->ops;
 	int ssa_vars_count = ssa->vars_count;
 	zend_bitset worklist;
-	int i, j, use;
+	int i, use;
 	const zend_ssa_phi *p;
 	ALLOCA_FLAG(use_heap);

@@ -527,7 +527,7 @@ ZEND_API void zend_ssa_find_false_dependencies(const zend_op_array *op_array, co
 					zend_bitset_incl(worklist, p->sources[0]);
 				}
 			} else {
-				for (j = 0; j < ssa->cfg.blocks[p->block].predecessors_count; j++) {
+				for (uint32_t j = 0; j < ssa->cfg.blocks[p->block].predecessors_count; j++) {
 					ZEND_ASSERT(p->sources[j] >= 0);
 					if (ssa->vars[p->sources[j]].no_val) {
 						ssa_vars[p->sources[j]].no_val = 0; /* used indirectly */
@@ -1076,7 +1076,6 @@ static bool zend_inference_calc_range(const zend_op_array *op_array, const zend_

 	if (ssa->vars[var].definition_phi) {
 		const zend_ssa_phi *p = ssa->vars[var].definition_phi;
-		int i;

 		tmp->underflow = 0;
 		tmp->min = ZEND_LONG_MAX;
@@ -1222,7 +1221,7 @@ static bool zend_inference_calc_range(const zend_op_array *op_array, const zend_
 				}
 			}
 		} else {
-			for (i = 0; i < ssa->cfg.blocks[p->block].predecessors_count; i++) {
+			for (uint32_t i = 0; i < ssa->cfg.blocks[p->block].predecessors_count; i++) {
 				ZEND_ASSERT(p->sources[i] >= 0);
 				if (ssa->var_info[p->sources[i]].has_range) {
 					/* union */
@@ -4192,7 +4191,7 @@ static zend_result zend_infer_types_ex(const zend_op_array *op_array, const zend
 	zend_ssa_var *ssa_vars = ssa->vars;
 	zend_ssa_var_info *ssa_var_info = ssa->var_info;
 	int ssa_vars_count = ssa->vars_count;
-	int i, j;
+	int j;
 	uint32_t tmp, worklist_len = zend_bitset_len(ssa_vars_count);
 	bool update_worklist = 1;
 	const zend_op **ssa_opcodes = NULL;
@@ -4236,6 +4235,7 @@ static zend_result zend_infer_types_ex(const zend_op_array *op_array, const zend
 				bool first = true;
 				bool is_instanceof = false;
 				zend_class_entry *ce = NULL;
+				uint32_t i;

 				tmp = 0;
 				for (i = 0; i < blocks[p->block].predecessors_count; i++) {
@@ -4261,7 +4261,7 @@ static zend_result zend_infer_types_ex(const zend_op_array *op_array, const zend
 				UPDATE_SSA_OBJ_TYPE(ce, ce ? is_instanceof : 0, j);
 			}
 		} else if (ssa_vars[j].definition >= 0) {
-			i = ssa_vars[j].definition;
+			int i = ssa_vars[j].definition;
 			if (_zend_update_type_info(op_array, ssa, script, worklist, op_array->opcodes + i, ssa->ops + i, NULL, optimization_level, true) == FAILURE) {
 				return FAILURE;
 			}
@@ -4562,9 +4562,8 @@ static void zend_func_return_info(const zend_op_array   *op_array,
 {
 	const zend_func_info *info = ZEND_FUNC_INFO(op_array);
 	const zend_ssa *ssa = &info->ssa;
-	int blocks_count = info->ssa.cfg.blocks_count;
+	uint32_t blocks_count = info->ssa.cfg.blocks_count;
 	const zend_basic_block *blocks = info->ssa.cfg.blocks;
-	int j;
 	uint32_t t1;
 	uint32_t tmp = 0;
 	zend_class_entry *tmp_ce = NULL;
@@ -4589,7 +4588,7 @@ static void zend_func_return_info(const zend_op_array   *op_array,
 			| MAY_BE_RC1 | MAY_BE_RCN | MAY_BE_REF;
 	}

-	for (j = 0; j < blocks_count; j++) {
+	for (uint32_t j = 0; j < blocks_count; j++) {
 		if ((blocks[j].flags & ZEND_BB_REACHABLE) && blocks[j].len != 0) {
 			zend_op *opline = op_array->opcodes + blocks[j].start + blocks[j].len - 1;

diff --git a/Zend/Optimizer/zend_ssa.c b/Zend/Optimizer/zend_ssa.c
index 99978da9d7e..e30159f8f3c 100644
--- a/Zend/Optimizer/zend_ssa.c
+++ b/Zend/Optimizer/zend_ssa.c
@@ -35,8 +35,7 @@ static bool dominates(const zend_basic_block *blocks, int a, int b) {
 static bool will_rejoin(
 		const zend_cfg *cfg, const zend_dfg *dfg, const zend_basic_block *block,
 		int other_successor, int exclude, int var) {
-	int i;
-	for (i = 0; i < block->predecessors_count; i++) {
+	for (uint32_t i = 0; i < block->predecessors_count; i++) {
 		int predecessor = cfg->predecessors[block->predecessor_offset + i];
 		if (predecessor == exclude) {
 			continue;
@@ -243,8 +242,8 @@ static void place_essa_pis(
 		zend_arena **arena, const zend_script *script, const zend_op_array *op_array,
 		uint32_t build_flags, const zend_ssa *ssa, const zend_dfg *dfg) /* {{{ */ {
 	const zend_basic_block *blocks = ssa->cfg.blocks;
-	int j, blocks_count = ssa->cfg.blocks_count;
-	for (j = 0; j < blocks_count; j++) {
+	uint32_t blocks_count = ssa->cfg.blocks_count;
+	for (uint32_t j = 0; j < blocks_count; j++) {
 		zend_ssa_phi *pi;
 		zend_op *opline = op_array->opcodes + blocks[j].start + blocks[j].len - 1;
 		int bt; /* successor block number if a condition is true */
@@ -823,7 +822,6 @@ static void zend_ssa_rename_in_block(const zend_op_array *op_array, uint32_t bui
 	const zend_ssa_block *ssa_blocks = ssa->blocks;
 	zend_ssa_op *ssa_ops = ssa->ops;
 	int ssa_vars_count = ssa->vars_count;
-	int i, j;
 	const zend_op *opline, *end;

 	if (ssa_blocks[n].phis) {
@@ -853,7 +851,7 @@ static void zend_ssa_rename_in_block(const zend_op_array *op_array, uint32_t bui
 			&& ((end-1)->opcode == ZEND_FE_FETCH_R || (end-1)->opcode == ZEND_FE_FETCH_RW)
 			&& (end-1)->op2_type == IS_CV
 		? &ssa_ops[blocks[n].start + blocks[n].len - 1] : NULL;
-	for (i = 0; i < blocks[n].successors_count; i++) {
+	for (uint32_t i = 0; i < blocks[n].successors_count; i++) {
 		int succ = blocks[n].successors[i];
 		zend_ssa_phi *p;
 		for (p = ssa_blocks[succ].phis; p; p = p->next) {
@@ -867,7 +865,7 @@ static void zend_ssa_rename_in_block(const zend_op_array *op_array, uint32_t bui
 						p->constraint.range.max_ssa_var = var[p->constraint.range.max_var];
 					}
 				}
-				for (j = 0; j < blocks[succ].predecessors_count; j++) {
+				for (uint32_t j = 0; j < blocks[succ].predecessors_count; j++) {
 					p->sources[j] = var[p->var];
 				}
 				if (p->ssa_var < 0) {
@@ -876,6 +874,7 @@ static void zend_ssa_rename_in_block(const zend_op_array *op_array, uint32_t bui
 				}
 			} else if (p->pi < 0) {
 				/* Normal Phi */
+				uint32_t j;
 				for (j = 0; j < blocks[succ].predecessors_count; j++)
 					if (ssa->cfg.predecessors[blocks[succ].predecessor_offset + j] == n) {
 						break;
@@ -893,6 +892,7 @@ static void zend_ssa_rename_in_block(const zend_op_array *op_array, uint32_t bui
 				zend_ssa_phi *q = p->next;
 				while (q) {
 					if (q->pi < 0 && q->var == p->var) {
+						uint32_t j;
 						for (j = 0; j < blocks[succ].predecessors_count; j++) {
 							if (ssa->cfg.predecessors[blocks[succ].predecessor_offset + j] == n) {
 								break;
@@ -997,11 +997,11 @@ ZEND_API zend_result zend_build_ssa(zend_arena **arena, const zend_script *scrip
 {
 	const zend_basic_block *blocks = ssa->cfg.blocks;
 	zend_ssa_block *ssa_blocks;
-	int blocks_count = ssa->cfg.blocks_count;
+	uint32_t blocks_count = ssa->cfg.blocks_count;
 	uint32_t set_size;
 	zend_bitset def, in, phi;
 	int *var = NULL;
-	int i, j, k, changed;
+	int i, j, changed;
 	zend_dfg dfg;
 	ALLOCA_FLAG(dfg_use_heap)
 	ALLOCA_FLAG(var_use_heap)
@@ -1056,7 +1056,7 @@ ZEND_API zend_result zend_build_ssa(zend_arena **arena, const zend_script *scrip
 					   register allocator depends on this property.  */
 					zend_bitset_union(phi_j, in + (j * set_size), set_size);
 				} else {
-					for (k = 0; k < blocks[j].predecessors_count; k++) {
+					for (uint32_t k = 0; k < blocks[j].predecessors_count; k++) {
 						i = ssa->cfg.predecessors[blocks[j].predecessor_offset + k];
 						while (i != -1 && i != blocks[j].idom) {
 							zend_bitset_union_with_intersection(
@@ -1223,9 +1223,7 @@ ZEND_API void zend_ssa_compute_use_def_chains(zend_arena **arena, const zend_op_
 					}
 				}
 			} else {
-				int j;
-
-				for (j = 0; j < ssa->cfg.blocks[i].predecessors_count; j++) {
+				for (uint32_t j = 0; j < ssa->cfg.blocks[i].predecessors_count; j++) {
 					zend_ssa_phi *p;

 					ZEND_ASSERT(phi->sources[j] >= 0);
@@ -1374,8 +1372,7 @@ static inline zend_ssa_phi **zend_ssa_next_use_phi_ptr(const zend_ssa *ssa, int
 	if (p->pi >= 0) {
 		return &p->use_chains[0];
 	} else {
-		int j;
-		for (j = 0; j < ssa->cfg.blocks[p->block].predecessors_count; j++) {
+		for (uint32_t j = 0; j < ssa->cfg.blocks[p->block].predecessors_count; j++) {
 			if (p->sources[j] == var) {
 				return &p->use_chains[j];
 			}
@@ -1438,9 +1435,9 @@ void zend_ssa_remove_defs_of_instr(zend_ssa *ssa, zend_ssa_op *ssa_op) /* {{{ */
 }
 /* }}} */

-static inline void zend_ssa_remove_phi_source(const zend_ssa *ssa, const zend_ssa_phi *phi, int pred_offset, int predecessors_count) /* {{{ */
+static inline void zend_ssa_remove_phi_source(const zend_ssa *ssa, const zend_ssa_phi *phi, int pred_offset, uint32_t predecessors_count) /* {{{ */
 {
-	int j, var_num = phi->sources[pred_offset];
+	int var_num = phi->sources[pred_offset];
 	zend_ssa_phi *next_phi = phi->use_chains[pred_offset];

 	predecessors_count--;
@@ -1451,7 +1448,7 @@ static inline void zend_ssa_remove_phi_source(const zend_ssa *ssa, const zend_ss

 	/* Check if they same var is used in a different phi operand as well, in this case we don't
 	 * need to adjust the use chain (but may have to move the next pointer). */
-	for (j = 0; j < predecessors_count; j++) {
+	for (uint32_t j = 0; j < predecessors_count; j++) {
 		if (phi->sources[j] == var_num) {
 			if (j < pred_offset) {
 				ZEND_ASSERT(next_phi == NULL);
@@ -1485,8 +1482,8 @@ void zend_ssa_remove_uses_of_var(const zend_ssa *ssa, int var_num) /* {{{ */
 	zend_ssa_phi *phi;
 	int use;
 	FOREACH_PHI_USE(var, phi) {
-		int i, end = NUM_PHI_SOURCES(phi);
-		for (i = 0; i < end; i++) {
+		uint32_t end = NUM_PHI_SOURCES(phi);
+		for (uint32_t i = 0; i < end; i++) {
 			if (phi->sources[i] == var_num) {
 				phi->use_chains[i] = NULL;
 			}
@@ -1517,13 +1514,12 @@ void zend_ssa_remove_predecessor(zend_ssa *ssa, int from, int to) /* {{{ */
 	zend_basic_block *next_block = &ssa->cfg.blocks[to];
 	const zend_ssa_block *next_ssa_block = &ssa->blocks[to];
 	zend_ssa_phi *phi;
-	int j;

 	/* Find at which predecessor offset this block is referenced */
 	int pred_offset = -1;
 	int *predecessors = &ssa->cfg.predecessors[next_block->predecessor_offset];

-	for (j = 0; j < next_block->predecessors_count; j++) {
+	for (uint32_t j = 0; j < next_block->predecessors_count; j++) {
 		if (predecessors[j] == from) {
 			pred_offset = j;
 			break;
@@ -1558,7 +1554,7 @@ void zend_ssa_remove_predecessor(zend_ssa *ssa, int from, int to) /* {{{ */
 }
 /* }}} */

-void zend_ssa_remove_block(const zend_op_array *op_array, zend_ssa *ssa, int i) /* {{{ */
+void zend_ssa_remove_block(const zend_op_array *op_array, zend_ssa *ssa, uint32_t i) /* {{{ */
 {
 	zend_basic_block *block = &ssa->cfg.blocks[i];
 	const zend_ssa_block *ssa_block = &ssa->blocks[i];
@@ -1591,7 +1587,8 @@ void zend_ssa_remove_block_from_cfg(zend_ssa *ssa, int i) /* {{{ */
 {
 	zend_basic_block *block = &ssa->cfg.blocks[i];
 	int *predecessors;
-	int j, s;
+	int j;
+	uint32_t s;

 	for (s = 0; s < block->successors_count; s++) {
 		zend_ssa_remove_predecessor(ssa, i, block->successors[s]);
@@ -1722,7 +1719,7 @@ void zend_ssa_rename_var_uses(zend_ssa *ssa, int old, int new, bool update_types

 	/* Update phi use chains */
 	FOREACH_PHI_USE(old_var, phi) {
-		int j;
+		uint32_t j;
 		bool after_first_new_source = false;

 		/* If the phi already uses the new var, find its use chain, as we may
diff --git a/Zend/Optimizer/zend_ssa.h b/Zend/Optimizer/zend_ssa.h
index 0696d2bba86..4f591618750 100644
--- a/Zend/Optimizer/zend_ssa.h
+++ b/Zend/Optimizer/zend_ssa.h
@@ -66,7 +66,7 @@ struct _zend_ssa_phi {
 	zend_ssa_pi_constraint constraint;    /* e-SSA Pi constraint */
 	int                    var;           /* Original CV, VAR or TMP variable index */
 	int                    ssa_var;       /* SSA variable index */
-	int                    block;         /* current BB index */
+	uint32_t               block;         /* current BB index */
 	bool                   has_range_constraint;
 	zend_ssa_phi         **use_chains;
 	zend_ssa_phi          *sym_use_chain;
@@ -155,7 +155,7 @@ void zend_ssa_remove_defs_of_instr(zend_ssa *ssa, zend_ssa_op *ssa_op);
 void zend_ssa_remove_instr(const zend_ssa *ssa, zend_op *opline, zend_ssa_op *ssa_op);
 void zend_ssa_remove_phi(const zend_ssa *ssa, zend_ssa_phi *phi);
 void zend_ssa_remove_uses_of_var(const zend_ssa *ssa, int var_num);
-void zend_ssa_remove_block(const zend_op_array *op_array, zend_ssa *ssa, int b);
+void zend_ssa_remove_block(const zend_op_array *op_array, zend_ssa *ssa, uint32_t b);
 void zend_ssa_rename_var_uses(zend_ssa *ssa, int old_var, int new_var, bool update_types);
 void zend_ssa_remove_block_from_cfg(zend_ssa *ssa, int b);

@@ -207,8 +207,7 @@ static zend_always_inline zend_ssa_phi* zend_ssa_next_use_phi(const zend_ssa *ss
 	if (p->pi >= 0) {
 		return p->use_chains[0];
 	} else {
-		int j;
-		for (j = 0; j < ssa->cfg.blocks[p->block].predecessors_count; j++) {
+		for (uint32_t j = 0; j < ssa->cfg.blocks[p->block].predecessors_count; j++) {
 			if (p->sources[j] == var) {
 				return p->use_chains[j];
 			}
@@ -285,7 +284,7 @@ static zend_always_inline void zend_ssa_rename_defs_of_instr(zend_ssa *ssa, zend

 #define FOREACH_PHI_SOURCE(phi, source) do { \
 	zend_ssa_phi *_phi = (phi); \
-	int _i, _end = NUM_PHI_SOURCES(phi); \
+	uint32_t _i, _end = NUM_PHI_SOURCES(phi); \
 	for (_i = 0; _i < _end; _i++) { \
 		ZEND_ASSERT(_phi->sources[_i] >= 0); \
 		source = _phi->sources[_i];
@@ -294,8 +293,7 @@ static zend_always_inline void zend_ssa_rename_defs_of_instr(zend_ssa *ssa, zend
 } while (0)

 #define FOREACH_PHI(phi) do { \
-	int _i; \
-	for (_i = 0; _i < ssa->cfg.blocks_count; _i++) { \
+	for (uint32_t _i = 0; _i < ssa->cfg.blocks_count; _i++) { \
 		phi = ssa->blocks[_i].phis; \
 		for (; phi; phi = phi->next) {
 #define FOREACH_PHI_END() \
@@ -304,8 +302,7 @@ static zend_always_inline void zend_ssa_rename_defs_of_instr(zend_ssa *ssa, zend
 } while (0)

 #define FOREACH_BLOCK(block) do { \
-	int _i; \
-	for (_i = 0; _i < ssa->cfg.blocks_count; _i++) { \
+	for (uint32_t _i = 0; _i < ssa->cfg.blocks_count; _i++) { \
 		(block) = &ssa->cfg.blocks[_i]; \
 		if (!((block)->flags & ZEND_BB_REACHABLE)) { \
 			continue; \
diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c
index 81bbaec04cd..1d33b03b452 100644
--- a/ext/opcache/jit/zend_jit.c
+++ b/ext/opcache/jit/zend_jit.c
@@ -115,7 +115,7 @@ static zend_string *zend_jit_func_name(const zend_op_array *op_array);
 static bool zend_jit_needs_arg_dtor(const zend_function *func, uint32_t arg_num, zend_call_info *call_info);
 static bool zend_jit_supported_binary_op(uint8_t op, uint32_t op1_info, uint32_t op2_info);

-static bool dominates(const zend_basic_block *blocks, int a, int b) {
+static bool dominates(const zend_basic_block *blocks, uint32_t a, uint32_t b) {
 	while (blocks[b].level > blocks[a].level) {
 		b = blocks[b].idom;
 	}
@@ -138,9 +138,9 @@ static bool zend_ssa_is_last_use(const zend_op_array *op_array, const zend_ssa *

 	if (ssa->cfg.blocks[ssa->cfg.map[use]].loop_header > 0
 	 || (ssa->cfg.blocks[ssa->cfg.map[use]].flags & ZEND_BB_LOOP_HEADER)) {
-		int b = ssa->cfg.map[use];
+		uint32_t b = ssa->cfg.map[use];
 		int prev_use = ssa->vars[var].use_chain;
-		int def_block;
+		uint32_t def_block;

 		if (ssa->vars[var].definition >= 0) {
 			def_block =ssa->cfg.map[ssa->vars[var].definition];
@@ -1173,7 +1173,7 @@ static void zend_jit_allocate_registers(zend_jit_ctx *ctx, const zend_op_array *
 		for (i = 0; i < ssa->vars_count; i++) {
 			if (ssa->vars[i].definition_phi && !ssa->vars[i].no_val) {
 				zend_ssa_phi *phi = ssa->vars[i].definition_phi;
-				int k, src;
+				int src;

 				if (phi->pi >= 0) {
 					src = phi->sources[0];
@@ -1188,6 +1188,7 @@ static void zend_jit_allocate_registers(zend_jit_ctx *ctx, const zend_op_array *
 					}
 				} else {
 					int need_move = 0;
+					uint32_t k;

 					for (k = 0; k < ssa->cfg.blocks[phi->block].predecessors_count; k++) {
 						src = phi->sources[k];
@@ -1342,7 +1343,7 @@ static void zend_jit_allocate_registers(zend_jit_ctx *ctx, const zend_op_array *
 static int zend_jit_compute_post_order(zend_cfg *cfg, int start, int *post_order)
 {
 	int count = 0;
-	int b, n, *p;
+	int b, *p;
 	zend_basic_block *bb;
 	zend_worklist worklist;
 	ALLOCA_FLAG(use_heap)
@@ -1354,7 +1355,7 @@ static int zend_jit_compute_post_order(zend_cfg *cfg, int start, int *post_order
 next:
 		b = zend_worklist_peek(&worklist);
 		bb = &cfg->blocks[b];
-		n = bb->successors_count;
+		uint32_t n = bb->successors_count;
 		if (n > 0) {
 			p = bb->successors;
 			do {
diff --git a/ext/opcache/jit/zend_jit_ir.c b/ext/opcache/jit/zend_jit_ir.c
index 0d368ef11ce..3dab550187e 100644
--- a/ext/opcache/jit/zend_jit_ir.c
+++ b/ext/opcache/jit/zend_jit_ir.c
@@ -1478,8 +1478,7 @@ static void zend_jit_gen_phi(zend_jit_ctx *jit, zend_ssa_phi *phi)
 {
 	int dst_var = phi->ssa_var;
 	zend_basic_block *bb = &jit->ssa->cfg.blocks[phi->block];
-	int n = bb->predecessors_count;
-	int i;
+	uint32_t n = bb->predecessors_count;
 	ir_type type = (jit->ssa->var_info[phi->ssa_var].type & MAY_BE_LONG) ? IR_LONG : IR_DOUBLE;
 	ir_ref merge = jit->bb_start_ref[phi->block];
 	ir_ref ref;
@@ -1496,7 +1495,7 @@ static void zend_jit_gen_phi(zend_jit_ctx *jit, zend_ssa_phi *phi)
 	ref = ir_emit_N(&jit->ctx, IR_OPT(IR_PHI, type), n + 1);
 	ir_set_op(&jit->ctx, ref, 1, merge);

-	for (i = 0; i < n; i++) {
+	for (uint32_t i = 0; i < n; i++) {
 		int src_var = phi->sources[i];

 		ZEND_ASSERT(jit->ra[src_var].ref);
@@ -3497,7 +3496,7 @@ static void zend_jit_case_start(zend_jit_ctx *jit, int switch_b, int case_b, ir_

 static void _zend_jit_add_predecessor_ref(zend_jit_ctx *jit, int b, int pred, ir_ref ref)
 {
-	int i, *p;
+	int *p;
 	zend_basic_block *bb;
 	ir_ref *r, header;

@@ -3505,7 +3504,7 @@ static void _zend_jit_add_predecessor_ref(zend_jit_ctx *jit, int b, int pred, ir
 	bb = &jit->ssa->cfg.blocks[b];
 	p = &jit->ssa->cfg.predecessors[bb->predecessor_offset];
 	r = &jit->bb_edges[jit->bb_predecessors[b]];
-	for (i = 0; i < bb->predecessors_count; i++, p++, r++) {
+	for (uint32_t i = 0; i < bb->predecessors_count; i++, p++, r++) {
 		if (*p == pred) {
 			ZEND_ASSERT(*r == IR_UNUSED || *r == ref);
 			header = jit->bb_start_ref[b];
@@ -3720,14 +3719,14 @@ static void zend_jit_case_start(zend_jit_ctx *jit, int switch_b, int case_b, ir_
 static int zend_jit_bb_start(zend_jit_ctx *jit, int b)
 {
 	zend_basic_block *bb;
-	int i, n, *p, pred;
+	int *p, pred;
 	ir_ref ref, bb_start;

 	ZEND_ASSERT(JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE);
 	ZEND_ASSERT(b < jit->ssa->cfg.blocks_count);
 	bb = &jit->ssa->cfg.blocks[b];
 	ZEND_ASSERT((bb->flags & ZEND_BB_REACHABLE) != 0);
-	n = bb->predecessors_count;
+	uint32_t n = bb->predecessors_count;

 	if (n == 0) {
 		/* pass */
@@ -3797,6 +3796,7 @@ static int zend_jit_bb_start(zend_jit_ctx *jit, int b)
 			entry_path = ir_END();
 		}
 		pred_refs = (ir_ref *)do_alloca(sizeof(ir_ref) * n, use_heap);
+		uint32_t i;
 		for (i = 0, p = jit->ssa->cfg.predecessors + bb->predecessor_offset; i < n; p++, i++) {
 			pred = *p;
 			if (jit->bb_start_ref[pred]) {
@@ -16699,7 +16699,7 @@ static int zend_jit_switch(zend_jit_ctx *jit, const zend_op *opline, const zend_

 static int zend_jit_start(zend_jit_ctx *jit, const zend_op_array *op_array, zend_ssa *ssa)
 {
-	int i, count;
+	uint32_t i, count;
 	zend_basic_block *bb;

 	zend_jit_init_ctx(jit, (ZEND_VM_KIND == ZEND_VM_KIND_CALL || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) ? 0 : (IR_START_BR_TARGET|IR_ENTRY_BR_TARGET));
@@ -17692,7 +17692,9 @@ static bool zend_jit_may_be_in_reg(const zend_op_array *op_array, zend_ssa *ssa,
 	}

 	if (JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE) {
-		int def_block, use_block, b, use, j;
+		uint32_t def_block, use_block;
+		int b, use;
+		uint32_t j;
 		zend_basic_block *bb;
 		zend_ssa_phi *p;
 		bool ret = true;
diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c
index 3a676125b80..0aa294fdbff 100644
--- a/ext/opcache/jit/zend_jit_trace.c
+++ b/ext/opcache/jit/zend_jit_trace.c
@@ -3953,7 +3953,7 @@ static int zend_jit_find_ssa_var(const zend_op_array *op_array,
                                  uint32_t             opline_num,
                                  uint32_t             var_num)
 {
-	int ssa_var, j, b = ssa->cfg.map[opline_num];
+	int ssa_var, b = ssa->cfg.map[opline_num];
 	const zend_basic_block *bb = ssa->cfg.blocks + b;
 	const zend_ssa_phi *phi;
 	const zend_ssa_op *ssa_op;
@@ -3997,7 +3997,7 @@ static int zend_jit_find_ssa_var(const zend_op_array *op_array,

 	ZEND_WORKLIST_ALLOCA(&worklist, ssa->cfg.blocks_count, use_heap);

-	for (j = 0; j < bb->predecessors_count; j++) {
+	for (uint32_t j = 0; j < bb->predecessors_count; j++) {
 		b = ssa->cfg.predecessors[bb->predecessor_offset + j];
 		zend_worklist_push(&worklist, b);
 	}
@@ -4038,7 +4038,7 @@ static int zend_jit_find_ssa_var(const zend_op_array *op_array,
 		if (ssa_var >= 0) {
 			goto found;
 		}
-		for (j = 0; j < bb->predecessors_count; j++) {
+		for (uint32_t j = 0; j < bb->predecessors_count; j++) {
 			b = ssa->cfg.predecessors[bb->predecessor_offset + j];
 			zend_worklist_push(&worklist, b);
 		}