From 2fbb9a882bf92656255df99e6db9b3a8bf3a8517 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 17 Feb 2023 09:46:19 +0100 Subject: [PATCH 1/7] Zend/zend_operators: pass const pointers to zend_is_identical() --- Zend/zend_operators.c | 2 +- Zend/zend_operators.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index f520b833bc333..1234f2d0ccca6 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -2304,7 +2304,7 @@ static int hash_zval_identical_function(zval *z1, zval *z2) /* {{{ */ } /* }}} */ -ZEND_API bool ZEND_FASTCALL zend_is_identical(zval *op1, zval *op2) /* {{{ */ +ZEND_API bool ZEND_FASTCALL zend_is_identical(const zval *op1, const zval *op2) /* {{{ */ { if (Z_TYPE_P(op1) != Z_TYPE_P(op2)) { return 0; diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index 506c27fc50eb3..58084f6dbe1aa 100644 --- a/Zend/zend_operators.h +++ b/Zend/zend_operators.h @@ -54,7 +54,7 @@ ZEND_API zend_result ZEND_FASTCALL shift_left_function(zval *result, zval *op1, ZEND_API zend_result ZEND_FASTCALL shift_right_function(zval *result, zval *op1, zval *op2); ZEND_API zend_result ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2); -ZEND_API bool ZEND_FASTCALL zend_is_identical(zval *op1, zval *op2); +ZEND_API bool ZEND_FASTCALL zend_is_identical(const zval *op1, const zval *op2); ZEND_API zend_result ZEND_FASTCALL is_equal_function(zval *result, zval *op1, zval *op2); ZEND_API zend_result ZEND_FASTCALL is_identical_function(zval *result, zval *op1, zval *op2); From 52ff70afafa5529aad59ef37888b558cf0788b09 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 18 Feb 2023 21:04:17 +0100 Subject: [PATCH 2/7] Zend/zend_operators: pass const pointers to zend_get_{long,double}() --- Zend/zend_operators.c | 4 ++-- Zend/zend_operators.h | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 1234f2d0ccca6..6ffe6e36b1f7f 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -865,7 +865,7 @@ ZEND_API void ZEND_COLD zend_incompatible_string_to_long_error(const zend_string zend_error(E_DEPRECATED, "Implicit conversion from float-string \"%s\" to int loses precision", ZSTR_VAL(s)); } -ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_strict) /* {{{ */ +ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(const zval *op, bool is_strict) /* {{{ */ { try_again: switch (Z_TYPE_P(op)) { @@ -935,7 +935,7 @@ ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_strict) /* } /* }}} */ -ZEND_API double ZEND_FASTCALL zval_get_double_func(zval *op) /* {{{ */ +ZEND_API double ZEND_FASTCALL zval_get_double_func(const zval *op) /* {{{ */ { try_again: switch (Z_TYPE_P(op)) { diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index 58084f6dbe1aa..d2cf73011418a 100644 --- a/Zend/zend_operators.h +++ b/Zend/zend_operators.h @@ -273,18 +273,18 @@ ZEND_API void ZEND_FASTCALL convert_to_boolean(zval *op); ZEND_API void ZEND_FASTCALL convert_to_array(zval *op); ZEND_API void ZEND_FASTCALL convert_to_object(zval *op); -ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_strict); -ZEND_API double ZEND_FASTCALL zval_get_double_func(zval *op); +ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(const zval *op, bool is_strict); +ZEND_API double ZEND_FASTCALL zval_get_double_func(const zval *op); ZEND_API zend_string* ZEND_FASTCALL zval_get_string_func(zval *op); ZEND_API zend_string* ZEND_FASTCALL zval_try_get_string_func(zval *op); -static zend_always_inline zend_long zval_get_long(zval *op) { +static zend_always_inline zend_long zval_get_long(const zval *op) { return EXPECTED(Z_TYPE_P(op) == IS_LONG) ? Z_LVAL_P(op) : zval_get_long_func(op, false); } -static zend_always_inline zend_long zval_get_long_ex(zval *op, bool is_strict) { +static zend_always_inline zend_long zval_get_long_ex(const zval *op, bool is_strict) { return EXPECTED(Z_TYPE_P(op) == IS_LONG) ? Z_LVAL_P(op) : zval_get_long_func(op, is_strict); } -static zend_always_inline double zval_get_double(zval *op) { +static zend_always_inline double zval_get_double(const zval *op) { return EXPECTED(Z_TYPE_P(op) == IS_DOUBLE) ? Z_DVAL_P(op) : zval_get_double_func(op); } static zend_always_inline zend_string *zval_get_string(zval *op) { From caf98ee69096b240e252acf2dfe2a2c12c97b8ac Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 17 Feb 2023 09:45:13 +0100 Subject: [PATCH 3/7] Zend/Optimizer/sccp: make pointers const --- Zend/Optimizer/sccp.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Zend/Optimizer/sccp.c b/Zend/Optimizer/sccp.c index 9373ad2adc63d..ff27c2941b268 100644 --- a/Zend/Optimizer/sccp.c +++ b/Zend/Optimizer/sccp.c @@ -122,7 +122,7 @@ static void empty_partial_array(zval *zv) Z_ARR_P(zv) = zend_new_array(8); } -static void dup_partial_array(zval *dst, zval *src) +static void dup_partial_array(zval *dst, const zval *src) { MAKE_PARTIAL_ARRAY(dst); Z_ARR_P(dst) = zend_array_dup(Z_ARR_P(src)); @@ -134,7 +134,7 @@ static void empty_partial_object(zval *zv) Z_ARR_P(zv) = zend_new_array(8); } -static void dup_partial_object(zval *dst, zval *src) +static void dup_partial_object(zval *dst, const zval *src) { MAKE_PARTIAL_OBJECT(dst); Z_ARR_P(dst) = zend_array_dup(Z_ARR_P(src)); @@ -146,7 +146,7 @@ static inline bool value_known(zval *zv) { /* Sets new value for variable and ensures that it is lower or equal * the previous one in the constant propagation lattice. */ -static void set_value(scdf_ctx *scdf, sccp_ctx *ctx, int var, zval *new) { +static void set_value(scdf_ctx *scdf, sccp_ctx *ctx, int var, const zval *new) { zval *value = &ctx->values[var]; if (IS_BOT(value) || IS_TOP(new)) { return; @@ -186,7 +186,7 @@ static void set_value(scdf_ctx *scdf, sccp_ctx *ctx, int var, zval *new) { #endif } -static zval *get_op1_value(sccp_ctx *ctx, zend_op *opline, zend_ssa_op *ssa_op) { +static zval *get_op1_value(sccp_ctx *ctx, zend_op *opline, const zend_ssa_op *ssa_op) { if (opline->op1_type == IS_CONST) { return CT_CONSTANT_EX(ctx->scdf.op_array, opline->op1.constant); } else if (ssa_op->op1_use != -1) { @@ -196,7 +196,7 @@ static zval *get_op1_value(sccp_ctx *ctx, zend_op *opline, zend_ssa_op *ssa_op) } } -static zval *get_op2_value(sccp_ctx *ctx, zend_op *opline, zend_ssa_op *ssa_op) { +static zval *get_op2_value(sccp_ctx *ctx, const zend_op *opline, const zend_ssa_op *ssa_op) { if (opline->op2_type == IS_CONST) { return CT_CONSTANT_EX(ctx->scdf.op_array, opline->op2.constant); } else if (ssa_op->op2_use != -1) { @@ -207,7 +207,7 @@ static zval *get_op2_value(sccp_ctx *ctx, zend_op *opline, zend_ssa_op *ssa_op) } static bool can_replace_op1( - const zend_op_array *op_array, zend_op *opline, zend_ssa_op *ssa_op) { + const zend_op_array *op_array, const zend_op *opline, const zend_ssa_op *ssa_op) { switch (opline->opcode) { case ZEND_PRE_INC: case ZEND_PRE_DEC: @@ -441,7 +441,7 @@ static inline zend_result ct_eval_isset_dim(zval *result, uint32_t extended_valu } } -static inline zend_result ct_eval_del_array_elem(zval *result, zval *key) { +static inline zend_result ct_eval_del_array_elem(zval *result, const zval *key) { ZEND_ASSERT(IS_PARTIAL_ARRAY(result)); switch (Z_TYPE_P(key)) { @@ -475,7 +475,7 @@ static inline zend_result ct_eval_del_array_elem(zval *result, zval *key) { return SUCCESS; } -static inline zend_result ct_eval_add_array_elem(zval *result, zval *value, zval *key) { +static inline zend_result ct_eval_add_array_elem(zval *result, zval *value, const zval *key) { if (!key) { SEPARATE_ARRAY(result); if ((value = zend_hash_next_index_insert(Z_ARR_P(result), value))) { @@ -546,7 +546,7 @@ static inline zend_result ct_eval_add_array_unpack(zval *result, zval *array) { return SUCCESS; } -static inline zend_result ct_eval_assign_dim(zval *result, zval *value, zval *key) { +static inline zend_result ct_eval_assign_dim(zval *result, zval *value, const zval *key) { switch (Z_TYPE_P(result)) { case IS_NULL: case IS_FALSE: @@ -622,7 +622,7 @@ static inline zend_result ct_eval_isset_obj(zval *result, uint32_t extended_valu } } -static inline zend_result ct_eval_del_obj_prop(zval *result, zval *key) { +static inline zend_result ct_eval_del_obj_prop(zval *result, const zval *key) { ZEND_ASSERT(IS_PARTIAL_OBJECT(result)); switch (Z_TYPE_P(key)) { @@ -636,7 +636,7 @@ static inline zend_result ct_eval_del_obj_prop(zval *result, zval *key) { return SUCCESS; } -static inline zend_result ct_eval_add_obj_prop(zval *result, zval *value, zval *key) { +static inline zend_result ct_eval_add_obj_prop(zval *result, zval *value, const zval *key) { switch (Z_TYPE_P(key)) { case IS_STRING: value = zend_symtable_update(Z_ARR_P(result), Z_STR_P(key), value); @@ -649,7 +649,7 @@ static inline zend_result ct_eval_add_obj_prop(zval *result, zval *value, zval * return SUCCESS; } -static inline zend_result ct_eval_assign_obj(zval *result, zval *value, zval *key) { +static inline zend_result ct_eval_assign_obj(zval *result, zval *value, const zval *key) { switch (Z_TYPE_P(result)) { case IS_NULL: case IS_FALSE: From 77e3fd0c908c3b8d297f866ec41cdf1de6e08268 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 17 Feb 2023 10:56:16 +0100 Subject: [PATCH 4/7] Zend/Optimizer/scdf: make pointers const --- Zend/Optimizer/scdf.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Zend/Optimizer/scdf.h b/Zend/Optimizer/scdf.h index 840a99065bcb0..0d90147e84cb1 100644 --- a/Zend/Optimizer/scdf.h +++ b/Zend/Optimizer/scdf.h @@ -53,8 +53,8 @@ uint32_t scdf_remove_unreachable_blocks(scdf_ctx *scdf); /* Add uses to worklist */ static inline void scdf_add_to_worklist(scdf_ctx *scdf, int var_num) { - zend_ssa *ssa = scdf->ssa; - zend_ssa_var *var = &ssa->vars[var_num]; + const zend_ssa *ssa = scdf->ssa; + const zend_ssa_var *var = &ssa->vars[var_num]; int use; zend_ssa_phi *phi; FOREACH_USE(var, use) { @@ -67,7 +67,7 @@ static inline void scdf_add_to_worklist(scdf_ctx *scdf, int var_num) { /* This should usually not be necessary, however it's used for type narrowing. */ static inline void scdf_add_def_to_worklist(scdf_ctx *scdf, int var_num) { - zend_ssa_var *var = &scdf->ssa->vars[var_num]; + const zend_ssa_var *var = &scdf->ssa->vars[var_num]; if (var->definition >= 0) { zend_bitset_incl(scdf->instr_worklist, var->definition); } else if (var->definition_phi) { @@ -75,8 +75,8 @@ static inline void scdf_add_def_to_worklist(scdf_ctx *scdf, int var_num) { } } -static inline uint32_t scdf_edge(zend_cfg *cfg, int from, int to) { - zend_basic_block *to_block = cfg->blocks + to; +static inline uint32_t scdf_edge(const zend_cfg *cfg, int from, int to) { + const zend_basic_block *to_block = cfg->blocks + to; int i; for (i = 0; i < to_block->predecessors_count; i++) { @@ -89,7 +89,7 @@ static inline uint32_t scdf_edge(zend_cfg *cfg, int from, int to) { ZEND_UNREACHABLE(); } -static inline bool scdf_is_edge_feasible(scdf_ctx *scdf, int from, int to) { +static inline bool scdf_is_edge_feasible(const scdf_ctx *scdf, int from, int to) { uint32_t edge = scdf_edge(&scdf->ssa->cfg, from, to); return zend_bitset_in(scdf->feasible_edges, edge); } From 2f8912d0064efdbf2599b912e0161c0423965cd2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 17 Feb 2023 10:59:08 +0100 Subject: [PATCH 5/7] Zend/Optimizer/zend_worklist: make pointers const --- Zend/Optimizer/zend_worklist.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Zend/Optimizer/zend_worklist.h b/Zend/Optimizer/zend_worklist.h index 69cc41c437af7..f47d01bd1579b 100644 --- a/Zend/Optimizer/zend_worklist.h +++ b/Zend/Optimizer/zend_worklist.h @@ -52,7 +52,7 @@ static inline void zend_worklist_stack_push(zend_worklist_stack *stack, int i) stack->buf[stack->len++] = i; } -static inline int zend_worklist_stack_peek(zend_worklist_stack *stack) +static inline int zend_worklist_stack_peek(const zend_worklist_stack *stack) { ZEND_ASSERT(stack->len); return stack->buf[stack->len - 1]; @@ -87,7 +87,7 @@ static inline void zend_worklist_prepare(zend_arena **arena, zend_worklist *work zend_worklist_stack_prepare(arena, &worklist->stack, len); } -static inline int zend_worklist_len(zend_worklist *worklist) +static inline int zend_worklist_len(const zend_worklist *worklist) { return worklist->stack.len; } @@ -105,7 +105,7 @@ static inline bool zend_worklist_push(zend_worklist *worklist, int i) return 1; } -static inline int zend_worklist_peek(zend_worklist *worklist) +static inline int zend_worklist_peek(const zend_worklist *worklist) { return zend_worklist_stack_peek(&worklist->stack); } From a308a0beb375c7a452c6d598a80413348f4080ba Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 17 Feb 2023 11:00:29 +0100 Subject: [PATCH 6/7] Zend/Optimizer/zend_optimizer: make pointers const --- Zend/Optimizer/zend_optimizer.c | 4 ++-- Zend/Optimizer/zend_optimizer_internal.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Zend/Optimizer/zend_optimizer.c b/Zend/Optimizer/zend_optimizer.c index b5841159bf12c..4043914de34c9 100644 --- a/Zend/Optimizer/zend_optimizer.c +++ b/Zend/Optimizer/zend_optimizer.c @@ -113,7 +113,7 @@ zend_result zend_optimizer_eval_cast(zval *result, uint32_t type, zval *op1) /* } /* }}} */ -zend_result zend_optimizer_eval_strlen(zval *result, zval *op1) /* {{{ */ +zend_result zend_optimizer_eval_strlen(zval *result, const zval *op1) /* {{{ */ { if (Z_TYPE_P(op1) != IS_STRING) { return FAILURE; @@ -231,7 +231,7 @@ 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, zval *zv) +int zend_optimizer_add_literal(zend_op_array *op_array, const zval *zv) { int i = op_array->last_literal; op_array->last_literal++; diff --git a/Zend/Optimizer/zend_optimizer_internal.h b/Zend/Optimizer/zend_optimizer_internal.h index 92410c18bf86b..769db6357bcf7 100644 --- a/Zend/Optimizer/zend_optimizer_internal.h +++ b/Zend/Optimizer/zend_optimizer_internal.h @@ -77,14 +77,14 @@ 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, zval *zv); +int 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); zend_result zend_optimizer_eval_binary_op(zval *result, zend_uchar opcode, zval *op1, zval *op2); zend_result zend_optimizer_eval_unary_op(zval *result, zend_uchar opcode, zval *op1); zend_result zend_optimizer_eval_cast(zval *result, uint32_t type, zval *op1); -zend_result zend_optimizer_eval_strlen(zval *result, zval *op1); +zend_result zend_optimizer_eval_strlen(zval *result, const zval *op1); zend_result zend_optimizer_eval_special_func_call( zval *result, zend_string *name, zend_string *arg); bool zend_optimizer_update_op1_const(zend_op_array *op_array, From b9912d23267a8f0f6083b03835e7b228389a8558 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 17 Feb 2023 11:02:29 +0100 Subject: [PATCH 7/7] Zend/zend_compile: make pointers const --- Zend/zend_compile.c | 8 ++++---- Zend/zend_compile.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index eb74893886ab4..90df8ad5ae971 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1592,7 +1592,7 @@ static inline bool class_name_refers_to_active_ce(zend_string *class_name, uint3 } /* }}} */ -uint32_t zend_get_class_fetch_type(zend_string *name) /* {{{ */ +uint32_t zend_get_class_fetch_type(const zend_string *name) /* {{{ */ { if (zend_string_equals_literal_ci(name, "self")) { return ZEND_FETCH_CLASS_SELF; @@ -8500,7 +8500,7 @@ static bool zend_try_ct_eval_magic_const(zval *zv, zend_ast *ast) /* {{{ */ } /* }}} */ -ZEND_API bool zend_is_op_long_compatible(zval *op) +ZEND_API bool zend_is_op_long_compatible(const zval *op) { if (Z_TYPE_P(op) == IS_ARRAY) { return false; @@ -8522,7 +8522,7 @@ ZEND_API bool zend_is_op_long_compatible(zval *op) return true; } -ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, zval *op1, zval *op2) /* {{{ */ +ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, const zval *op1, const zval *op2) /* {{{ */ { if ((opcode == ZEND_CONCAT || opcode == ZEND_FAST_CONCAT)) { /* Array to string warning. */ @@ -8595,7 +8595,7 @@ static inline bool zend_try_ct_eval_binary_op(zval *result, uint32_t opcode, zva } /* }}} */ -ZEND_API bool zend_unary_op_produces_error(uint32_t opcode, zval *op) +ZEND_API bool zend_unary_op_produces_error(uint32_t opcode, const zval *op) { if (opcode == ZEND_BW_NOT) { /* BW_NOT on string does not convert the string into an integer. */ diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 0f54d8cd4f4ea..74d1058739911 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -895,7 +895,7 @@ ZEND_API void pass_two(zend_op_array *op_array); ZEND_API bool zend_is_compiling(void); ZEND_API char *zend_make_compiled_string_description(const char *name); ZEND_API void zend_initialize_class_data(zend_class_entry *ce, bool nullify_handlers); -uint32_t zend_get_class_fetch_type(zend_string *name); +uint32_t zend_get_class_fetch_type(const zend_string *name); ZEND_API zend_uchar zend_get_call_op(const zend_op *init_op, zend_function *fbc); ZEND_API bool zend_is_smart_branch(const zend_op *opline); @@ -1204,8 +1204,8 @@ END_EXTERN_C() /* The default value for CG(compiler_options) during eval() */ #define ZEND_COMPILE_DEFAULT_FOR_EVAL 0 -ZEND_API bool zend_is_op_long_compatible(zval *op); -ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, zval *op1, zval *op2); -ZEND_API bool zend_unary_op_produces_error(uint32_t opcode, zval *op); +ZEND_API bool zend_is_op_long_compatible(const zval *op); +ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, const zval *op1, const zval *op2); +ZEND_API bool zend_unary_op_produces_error(uint32_t opcode, const zval *op); #endif /* ZEND_COMPILE_H */