Skip to content

Zend: Convert certain fields to uint32_t #19479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Zend/Optimizer/block_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ static void assemble_code_blocks(zend_cfg *cfg, zend_op_array *op_array, zend_op

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

Expand Down Expand Up @@ -1157,7 +1157,7 @@ static void assemble_code_blocks(zend_cfg *cfg, zend_op_array *op_array, zend_op
while (opline < end) {
if (opline->opcode == ZEND_FAST_RET &&
opline->op2.num != (uint32_t)-1 &&
opline->op2.num < (uint32_t)j) {
opline->op2.num < j) {
opline->op2.num = map[opline->op2.num];
}
opline++;
Expand Down
13 changes: 7 additions & 6 deletions Zend/Optimizer/compact_literals.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static zend_string *create_str_cache_key(zval *literal, uint8_t num_related)
void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx *ctx)
{
zend_op *opline, *end;
int i, j, n, *map;
int n, *map;
uint32_t cache_size;
zval zv, *pos;
literal_info *info;
Expand All @@ -124,6 +124,7 @@ void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx
int *const_slot, *class_slot, *func_slot, *bind_var_slot, *property_slot, *method_slot, *jmp_slot;

if (op_array->last_literal) {
uint32_t j;
info = (literal_info*)zend_arena_calloc(&ctx->arena, op_array->last_literal, sizeof(literal_info));

/* Mark literals of specific types */
Expand Down Expand Up @@ -258,9 +259,9 @@ void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx
op_array->function_name ? op_array->function_name->val : "main");
fprintf(stderr, "Literals table size %d\n", op_array->last_literal);

for (int i = 0; i < op_array->last_literal; i++) {
for (uint32_t i = 0; i < op_array->last_literal; i++) {
zend_string *str = zval_get_string(op_array->literals + i);
fprintf(stderr, "Literal %d, val (%zu):%s\n", i, ZSTR_LEN(str), ZSTR_VAL(str));
fprintf(stderr, "Literal %" PRIu32 ", val (%zu):%s\n", i, ZSTR_LEN(str), ZSTR_VAL(str));
zend_string_release(str);
}
fflush(stderr);
Expand All @@ -272,7 +273,7 @@ void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx
zend_hash_init(&hash, op_array->last_literal, NULL, NULL, 0);
map = (int*)zend_arena_alloc(&ctx->arena, op_array->last_literal * sizeof(int));
memset(map, 0, op_array->last_literal * sizeof(int));
for (i = 0; i < op_array->last_literal; i++) {
for (uint32_t i = 0; i < op_array->last_literal; i++) {
if (!info[i].num_related) {
/* unset literal */
zval_ptr_dtor_nogc(&op_array->literals[i]);
Expand Down Expand Up @@ -770,9 +771,9 @@ void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx
{
fprintf(stderr, "Optimized literals table size %d\n", op_array->last_literal);

for (int i = 0; i < op_array->last_literal; i++) {
for (uint32_t i = 0; i < op_array->last_literal; i++) {
zend_string *str = zval_get_string(op_array->literals + i);
fprintf(stderr, "Literal %d, val (%zu):%s\n", i, ZSTR_LEN(str), ZSTR_VAL(str));
fprintf(stderr, "Literal %" PRIu32 ", val (%zu):%s\n", i, ZSTR_LEN(str), ZSTR_VAL(str));
zend_string_release(str);
}
fflush(stderr);
Expand Down
2 changes: 1 addition & 1 deletion Zend/Optimizer/dfa_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static void zend_ssa_remove_nops(zend_op_array *op_array, zend_ssa *ssa, zend_op
}

/* update try/catch array */
for (j = 0; j < op_array->last_try_catch; j++) {
for (uint32_t j = 0; j < op_array->last_try_catch; j++) {
op_array->try_catch_array[j].try_op -= shiftlist[op_array->try_catch_array[j].try_op];
op_array->try_catch_array[j].catch_op -= shiftlist[op_array->try_catch_array[j].catch_op];
if (op_array->try_catch_array[j].finally_op) {
Expand Down
3 changes: 1 addition & 2 deletions Zend/Optimizer/nop_removal.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ void zend_optimizer_nop_removal(zend_op_array *op_array, zend_optimizer_ctx *ctx
{
zend_op *end, *opline;
uint32_t new_count, i, shift;
int j;
uint32_t *shiftlist;
ALLOCA_FLAG(use_heap);

Expand Down Expand Up @@ -81,7 +80,7 @@ void zend_optimizer_nop_removal(zend_op_array *op_array, zend_optimizer_ctx *ctx
}

/* update try/catch array */
for (j = 0; j < op_array->last_try_catch; j++) {
for (uint32_t j = 0; j < op_array->last_try_catch; j++) {
op_array->try_catch_array[j].try_op -= shiftlist[op_array->try_catch_array[j].try_op];
op_array->try_catch_array[j].catch_op -= shiftlist[op_array->try_catch_array[j].catch_op];
if (op_array->try_catch_array[j].finally_op) {
Expand Down
5 changes: 2 additions & 3 deletions Zend/Optimizer/zend_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array,
{
uint32_t flags = 0;
uint32_t i;
int j;
uint32_t *block_map;
zend_function *fn;
int blocks_count = 0;
Expand Down Expand Up @@ -449,7 +448,7 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array,
}

if (op_array->last_try_catch) {
for (j = 0; j < op_array->last_try_catch; j++) {
for (uint32_t j = 0; j < op_array->last_try_catch; j++) {
BB_START(op_array->try_catch_array[j].try_op);
if (op_array->try_catch_array[j].catch_op) {
BB_START(op_array->try_catch_array[j].catch_op);
Expand Down Expand Up @@ -494,7 +493,7 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array,
blocks_count++;

/* Build CFG, Step 3: Calculate successors */
for (j = 0; j < blocks_count; j++) {
for (int j = 0; j < blocks_count; j++) {
zend_basic_block *block = &blocks[j];
zend_op *opline;
if (block->len == 0) {
Expand Down
8 changes: 4 additions & 4 deletions Zend/Optimizer/zend_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_fl
}
if (op_array->last_live_range && (dump_flags & ZEND_DUMP_LIVE_RANGES)) {
fprintf(stderr, "LIVE RANGES:\n");
for (int i = 0; i < op_array->last_live_range; i++) {
for (uint32_t i = 0; i < op_array->last_live_range; i++) {
fprintf(stderr,
" %u: %04u - %04u ",
EX_VAR_TO_NUM(op_array->live_range[i].var & ~ZEND_LIVE_MASK),
Expand All @@ -1083,7 +1083,7 @@ ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_fl
}
if (op_array->last_try_catch) {
fprintf(stderr, "EXCEPTION TABLE:\n");
for (int i = 0; i < op_array->last_try_catch; i++) {
for (uint32_t i = 0; i < op_array->last_try_catch; i++) {
fprintf(stderr, " BB%u",
cfg->map[op_array->try_catch_array[i].try_op]);
if (op_array->try_catch_array[i].catch_op) {
Expand Down Expand Up @@ -1116,7 +1116,7 @@ ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_fl
}
if (op_array->last_live_range && (dump_flags & ZEND_DUMP_LIVE_RANGES)) {
fprintf(stderr, "LIVE RANGES:\n");
for (int i = 0; i < op_array->last_live_range; i++) {
for (uint32_t i = 0; i < op_array->last_live_range; i++) {
fprintf(stderr,
" %u: %04u - %04u ",
EX_VAR_TO_NUM(op_array->live_range[i].var & ~ZEND_LIVE_MASK),
Expand All @@ -1143,7 +1143,7 @@ ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_fl
}
if (op_array->last_try_catch) {
fprintf(stderr, "EXCEPTION TABLE:\n");
for (int i = 0; i < op_array->last_try_catch; i++) {
for (uint32_t i = 0; i < op_array->last_try_catch; i++) {
fprintf(stderr,
" %04u",
op_array->try_catch_array[i].try_op);
Expand Down
6 changes: 3 additions & 3 deletions Zend/Optimizer/zend_optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,17 @@ void zend_optimizer_convert_to_free_op1(zend_op_array *op_array, zend_op *opline
}
}

int zend_optimizer_add_literal(zend_op_array *op_array, const zval *zv)
uint32_t zend_optimizer_add_literal(zend_op_array *op_array, const zval *zv)
{
int i = op_array->last_literal;
uint32_t i = op_array->last_literal;
op_array->last_literal++;
op_array->literals = (zval*)erealloc(op_array->literals, op_array->last_literal * sizeof(zval));
ZVAL_COPY_VALUE(&op_array->literals[i], zv);
Z_EXTRA(op_array->literals[i]) = 0;
return i;
}

static inline int zend_optimizer_add_literal_string(zend_op_array *op_array, zend_string *str) {
static inline uint32_t zend_optimizer_add_literal_string(zend_op_array *op_array, zend_string *str) {
zval zv;
ZVAL_STR(&zv, str);
zend_string_hash_val(str);
Expand Down
2 changes: 1 addition & 1 deletion Zend/Optimizer/zend_optimizer_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static inline bool zend_optimizer_is_loop_var_free(const zend_op *opline) {
}

void zend_optimizer_convert_to_free_op1(zend_op_array *op_array, zend_op *opline);
int zend_optimizer_add_literal(zend_op_array *op_array, const zval *zv);
uint32_t zend_optimizer_add_literal(zend_op_array *op_array, const zval *zv);
bool zend_optimizer_get_persistent_constant(zend_string *name, zval *result, int copy);
void zend_optimizer_collect_constant(zend_optimizer_ctx *ctx, zval *name, zval* value);
bool zend_optimizer_get_collected_constant(HashTable *constants, zval *name, zval* value);
Expand Down
8 changes: 4 additions & 4 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ static zend_always_inline uint32_t get_temporary_variable(void) /* {{{ */
}
/* }}} */

static int lookup_cv(zend_string *name) /* {{{ */{
static uint32_t lookup_cv(zend_string *name) /* {{{ */{
zend_op_array *op_array = CG(active_op_array);
int i = 0;
zend_ulong hash_value = zend_string_hash_val(name);
Expand Down Expand Up @@ -587,7 +587,7 @@ static inline void zend_insert_literal(zend_op_array *op_array, zval *zv, int li
static int zend_add_literal(zval *zv) /* {{{ */
{
zend_op_array *op_array = CG(active_op_array);
int i = op_array->last_literal;
uint32_t i = op_array->last_literal;
op_array->last_literal++;
if (i >= CG(context).literals_size) {
while (i >= CG(context).literals_size) {
Expand Down Expand Up @@ -5863,7 +5863,7 @@ static void zend_compile_break_continue(zend_ast *ast) /* {{{ */
void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline) /* {{{ */
{
zend_label *dest;
int current, remove_oplines = opline->op1.num;
int remove_oplines = opline->op1.num;
zval *label;
uint32_t opnum = opline - op_array->opcodes;

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

current = opline->extended_value;
uint32_t current = opline->extended_value;
for (; current != dest->brk_cont; current = CG(context).brk_cont_array[current].parent) {
if (current == -1) {
CG(in_compilation) = 1;
Expand Down
16 changes: 8 additions & 8 deletions Zend/zend_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ typedef struct _zend_oparray_context {
struct _zend_oparray_context *prev;
zend_op_array *op_array;
uint32_t opcodes_size;
int vars_size;
int literals_size;
uint32_t vars_size;
uint32_t literals_size;
uint32_t fast_call_var;
uint32_t try_catch_offset;
int current_brk_cont;
Expand Down Expand Up @@ -529,9 +529,9 @@ struct _zend_op_array {
const zend_property_info *prop_info; /* The corresponding prop_info if this is a hook. */
/* END of common elements */

int cache_size; /* number of run_time_cache_slots * sizeof(void*) */
int last_var; /* number of CV variables */
uint32_t last; /* number of opcodes */
uint32_t cache_size; /* number of run_time_cache_slots * sizeof(void*) */
int last_var; /* number of CV variables */
uint32_t last; /* number of opcodes */

zend_op *opcodes;
ZEND_MAP_PTR_DEF(HashTable *, static_variables_ptr);
Expand All @@ -540,16 +540,16 @@ struct _zend_op_array {

uint32_t *refcount;

int last_live_range;
int last_try_catch;
uint32_t last_live_range;
uint32_t last_try_catch;
zend_live_range *live_range;
zend_try_catch_element *try_catch_array;

zend_string *filename;
uint32_t line_start;
uint32_t line_end;

int last_literal;
uint32_t last_literal;
uint32_t num_dynamic_func_defs;
zval *literals;

Expand Down
3 changes: 1 addition & 2 deletions Zend/zend_generators.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */
zend_generator *current_generator = zend_generator_get_current(generator);
zend_execute_data *ex = generator->execute_data;
uint32_t op_num, try_catch_offset;
int i;

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

/* Find the innermost try/catch that we are inside of. */
for (i = 0; i < ex->func->op_array.last_try_catch; i++) {
for (uint32_t i = 0; i < ex->func->op_array.last_try_catch; i++) {
zend_try_catch_element *try_catch = &ex->func->op_array.try_catch_array[i];
if (op_num < try_catch->try_op) {
break;
Expand Down
4 changes: 1 addition & 3 deletions Zend/zend_opcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,7 @@ static void zend_extension_op_array_handler(zend_extension *extension, zend_op_a

static void zend_check_finally_breakout(zend_op_array *op_array, uint32_t op_num, uint32_t dst_num)
{
int i;

for (i = 0; i < op_array->last_try_catch; i++) {
for (uint32_t i = 0; i < op_array->last_try_catch; i++) {
if ((op_num < op_array->try_catch_array[i].finally_op ||
op_num >= op_array->try_catch_array[i].finally_end)
&& (dst_num >= op_array->try_catch_array[i].finally_op &&
Expand Down
8 changes: 5 additions & 3 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* php zend_vm_gen.php
*/

#include <stdint.h>
Copy link
Member

Choose a reason for hiding this comment

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

This change is ignored (it doesn't end up in zend_vm_execute.h). I would recommend to add this include to zend_vm_execute.skl instead. (stdint.h is probably already included where zend_vm_execute.h is included, but this is still useful when looking at this file independently.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I didn't even realize this header got added, will add to the skeleton


ZEND_VM_HELPER(zend_add_helper, ANY, ANY, zval *op_1, zval *op_2)
{
USE_OPLINE
Expand Down Expand Up @@ -8151,7 +8153,7 @@ ZEND_VM_HANDLER(149, ZEND_HANDLE_EXCEPTION, ANY, ANY)
}

uint32_t throw_op_num = throw_op - EX(func)->op_array.opcodes;
int i, current_try_catch_offset = -1;
uint32_t current_try_catch_offset = -1;

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

/* Find the innermost try/catch/finally the exception was thrown in */
for (i = 0; i < EX(func)->op_array.last_try_catch; i++) {
for (uint32_t i = 0; i < EX(func)->op_array.last_try_catch; i++) {
zend_try_catch_element *try_catch = &EX(func)->op_array.try_catch_array[i];
if (try_catch->try_op > throw_op_num) {
/* further blocks will not be relevant... */
Expand Down
6 changes: 3 additions & 3 deletions Zend/zend_vm_execute.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions ext/opcache/jit/zend_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1263,13 +1263,12 @@ static void zend_jit_allocate_registers(zend_jit_ctx *ctx, const zend_op_array *
&& ssa->vars[i].definition >= 0
&& ssa->ops[op_num].result_def == i) {
const zend_live_range *range = op_array->live_range;
int j;

op_num++;
if (op_array->opcodes[op_num].opcode == ZEND_OP_DATA) {
op_num++;
}
for (j = 0; j < op_array->last_live_range; range++, j++) {
for (uint32_t j = 0; j < op_array->last_live_range; range++, j++) {
if (range->start > op_num) {
/* further blocks will not be relevant... */
break;
Expand Down
3 changes: 1 addition & 2 deletions ext/opcache/jit/zend_jit_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -6564,10 +6564,9 @@ static zend_vm_opcode_handler_t zend_jit_trace(zend_jit_trace_rec *trace_buffer,
uint32_t var_num = opline->result.var;
uint32_t op_num = opline - op_array->opcodes;
const zend_live_range *range = op_array->live_range;
int j;

op_num += zend_jit_trace_op_len(opline);
for (j = 0; j < op_array->last_live_range; range++, j++) {
for (uint32_t j = 0; j < op_array->last_live_range; range++, j++) {
if (range->start > op_num) {
/* further blocks will not be relevant... */
break;
Expand Down
2 changes: 1 addition & 1 deletion sapi/phpdbg/phpdbg_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ PHPDBG_INFO(literal) /* {{{ */
bool in_executor = PHPDBG_G(in_execution) && EG(current_execute_data) && EG(current_execute_data)->func;
if (in_executor || PHPDBG_G(ops)) {
zend_op_array *ops = in_executor ? &EG(current_execute_data)->func->op_array : PHPDBG_G(ops);
int literal = 0, count = ops->last_literal - 1;
uint32_t literal = 0, count = ops->last_literal - 1;

if (ops->function_name) {
if (ops->scope) {
Expand Down
Loading