Skip to content

zend_compiler, ...: use uint8_t instead of zend_uchar #10621

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

Merged
merged 1 commit into from
Feb 23, 2023
Merged
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 @@ -519,7 +519,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
break;
case ZEND_IS_SMALLER:
if (opline->opcode == ZEND_BOOL_NOT) {
zend_uchar tmp_type;
uint8_t tmp_type;
uint32_t tmp;

src->opcode = ZEND_IS_SMALLER_OR_EQUAL;
Expand All @@ -537,7 +537,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
break;
case ZEND_IS_SMALLER_OR_EQUAL:
if (opline->opcode == ZEND_BOOL_NOT) {
zend_uchar tmp_type;
uint8_t tmp_type;
uint32_t tmp;

src->opcode = ZEND_IS_SMALLER;
Expand Down
2 changes: 1 addition & 1 deletion Zend/Optimizer/dce.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ static inline bool is_free_of_live_var(context *ctx, zend_op *opline, zend_ssa_o
static bool dce_instr(context *ctx, zend_op *opline, zend_ssa_op *ssa_op) {
zend_ssa *ssa = ctx->ssa;
int free_var = -1;
zend_uchar free_var_type;
uint8_t free_var_type;

if (opline->opcode == ZEND_NOP) {
return 0;
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 @@ -932,7 +932,7 @@ static int zend_dfa_optimize_jmps(zend_op_array *op_array, zend_ssa *ssa)
case ZEND_MATCH:
if (opline->op1_type == IS_CONST) {
zval *zv = CT_CONSTANT_EX(op_array, opline->op1.constant);
zend_uchar type = Z_TYPE_P(zv);
uint8_t type = Z_TYPE_P(zv);
bool correct_type =
(opline->opcode == ZEND_SWITCH_LONG && type == IS_LONG)
|| (opline->opcode == ZEND_SWITCH_STRING && type == IS_STRING)
Expand Down
16 changes: 8 additions & 8 deletions Zend/Optimizer/sccp.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ typedef struct _sccp_ctx {
zval bot;
} sccp_ctx;

#define TOP ((zend_uchar)-1)
#define BOT ((zend_uchar)-2)
#define PARTIAL_ARRAY ((zend_uchar)-3)
#define PARTIAL_OBJECT ((zend_uchar)-4)
#define TOP ((uint8_t)-1)
#define BOT ((uint8_t)-2)
#define PARTIAL_ARRAY ((uint8_t)-3)
#define PARTIAL_OBJECT ((uint8_t)-4)
#define IS_TOP(zv) (Z_TYPE_P(zv) == TOP)
#define IS_BOT(zv) (Z_TYPE_P(zv) == BOT)
#define IS_PARTIAL_ARRAY(zv) (Z_TYPE_P(zv) == PARTIAL_ARRAY)
Expand Down Expand Up @@ -314,7 +314,7 @@ static bool try_replace_op2(
return 0;
}

static inline zend_result ct_eval_binary_op(zval *result, zend_uchar binop, zval *op1, zval *op2) {
static inline zend_result ct_eval_binary_op(zval *result, uint8_t binop, zval *op1, zval *op2) {
/* TODO: We could implement support for evaluation of + on partial arrays. */
if (IS_PARTIAL_ARRAY(op1) || IS_PARTIAL_ARRAY(op2)) {
return FAILURE;
Expand Down Expand Up @@ -662,7 +662,7 @@ static inline zend_result ct_eval_assign_obj(zval *result, zval *value, const zv
}
}

static inline zend_result ct_eval_incdec(zval *result, zend_uchar opcode, zval *op1) {
static inline zend_result ct_eval_incdec(zval *result, uint8_t opcode, zval *op1) {
if (Z_TYPE_P(op1) == IS_ARRAY || IS_PARTIAL_ARRAY(op1)) {
return FAILURE;
}
Expand Down Expand Up @@ -1843,7 +1843,7 @@ static void sccp_mark_feasible_successors(
case ZEND_MATCH:
{
bool strict_comparison = opline->opcode == ZEND_MATCH;
zend_uchar type = Z_TYPE_P(op1);
uint8_t type = Z_TYPE_P(op1);
bool correct_type =
(opline->opcode == ZEND_SWITCH_LONG && type == IS_LONG)
|| (opline->opcode == ZEND_SWITCH_STRING && type == IS_STRING)
Expand Down Expand Up @@ -2134,7 +2134,7 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
&& opline->opcode != ZEND_ADD_ARRAY_ELEMENT
&& opline->opcode != ZEND_ADD_ARRAY_UNPACK) {
/* Replace with QM_ASSIGN */
zend_uchar old_type = opline->result_type;
uint8_t old_type = opline->result_type;
uint32_t old_var = opline->result.var;

ssa_op->result_def = -1;
Expand Down
2 changes: 1 addition & 1 deletion Zend/Optimizer/ssa_integrity.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static inline bool is_in_successors(zend_basic_block *block, int check) {
return 0;
}

static inline bool is_var_type(zend_uchar type) {
static inline bool is_var_type(uint8_t type) {
return (type & (IS_CV|IS_VAR|IS_TMP_VAR)) != 0;
}

Expand Down
2 changes: 1 addition & 1 deletion Zend/Optimizer/zend_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void zend_mark_reachable(zend_op *opcodes, zend_cfg *cfg, zend_basic_bloc
zend_basic_block *succ = blocks + b->successors[i];

if (b->len != 0) {
zend_uchar opcode = opcodes[b->start + b->len - 1].opcode;
uint8_t opcode = opcodes[b->start + b->len - 1].opcode;
if (opcode == ZEND_MATCH) {
succ->flags |= ZEND_BB_TARGET;
} else if (opcode == ZEND_SWITCH_LONG || opcode == ZEND_SWITCH_STRING) {
Expand Down
4 changes: 2 additions & 2 deletions Zend/Optimizer/zend_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static void zend_dump_unused_op(const zend_op *opline, znode_op op, uint32_t fla
}
}

ZEND_API void zend_dump_var(const zend_op_array *op_array, zend_uchar var_type, int var_num)
ZEND_API void zend_dump_var(const zend_op_array *op_array, uint8_t var_type, int var_num)
{
if (var_type == IS_CV && var_num < op_array->last_var) {
fprintf(stderr, "CV%d($%s)", var_num, op_array->vars[var_num]->val);
Expand Down Expand Up @@ -348,7 +348,7 @@ static void zend_dump_ssa_var_info(const zend_ssa *ssa, int ssa_var_num, uint32_
dump_flags);
}

ZEND_API void zend_dump_ssa_var(const zend_op_array *op_array, const zend_ssa *ssa, int ssa_var_num, zend_uchar var_type, int var_num, uint32_t dump_flags)
ZEND_API void zend_dump_ssa_var(const zend_op_array *op_array, const zend_ssa *ssa, int ssa_var_num, uint8_t var_type, int var_num, uint32_t dump_flags)
{
if (ssa_var_num >= 0) {
fprintf(stderr, "#%d.", ssa_var_num);
Expand Down
6 changes: 4 additions & 2 deletions Zend/Optimizer/zend_dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "zend_ssa.h"
#include "zend_dfg.h"

#include <stdint.h>

#define ZEND_DUMP_HIDE_UNREACHABLE (1<<0)
#define ZEND_DUMP_RC_INFERENCE (1<<1)
#define ZEND_DUMP_CFG (1<<2)
Expand All @@ -39,8 +41,8 @@ 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);
void zend_dump_variables(const zend_op_array *op_array);
void zend_dump_ssa_variables(const zend_op_array *op_array, const zend_ssa *ssa, uint32_t dump_flags);
ZEND_API void zend_dump_ssa_var(const zend_op_array *op_array, const zend_ssa *ssa, int ssa_var_num, zend_uchar var_type, int var_num, uint32_t dump_flags);
ZEND_API void zend_dump_var(const zend_op_array *op_array, zend_uchar var_type, int var_num);
ZEND_API void zend_dump_ssa_var(const zend_op_array *op_array, const zend_ssa *ssa, int ssa_var_num, uint8_t var_type, int var_num, uint32_t dump_flags);
ZEND_API void zend_dump_var(const zend_op_array *op_array, uint8_t var_type, int var_num);
void zend_dump_op_array_name(const zend_op_array *op_array);
void zend_dump_const(const zval *zv);
void zend_dump_ht(HashTable *ht);
Expand Down
14 changes: 7 additions & 7 deletions Zend/Optimizer/zend_inference.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ static void float_div(zend_long a, zend_long b, zend_long *r1, zend_long *r2) {

static bool zend_inference_calc_binary_op_range(
const zend_op_array *op_array, const zend_ssa *ssa,
const zend_op *opline, const zend_ssa_op *ssa_op, zend_uchar opcode, zend_ssa_range *tmp) {
const zend_op *opline, const zend_ssa_op *ssa_op, uint8_t opcode, zend_ssa_range *tmp) {
zend_long op1_min, op2_min, op1_max, op2_max, t1, t2, t3, t4;

switch (opcode) {
Expand Down Expand Up @@ -1881,7 +1881,7 @@ ZEND_API uint32_t ZEND_FASTCALL zend_array_type_info(const zval *zv)
}


ZEND_API uint32_t zend_array_element_type(uint32_t t1, zend_uchar op_type, int write, int insert)
ZEND_API uint32_t zend_array_element_type(uint32_t t1, uint8_t op_type, int write, int insert)
{
uint32_t tmp = 0;

Expand Down Expand Up @@ -1943,7 +1943,7 @@ ZEND_API uint32_t zend_array_element_type(uint32_t t1, zend_uchar op_type, int w
}

static uint32_t assign_dim_array_result_type(
uint32_t arr_type, uint32_t dim_type, uint32_t value_type, zend_uchar dim_op_type) {
uint32_t arr_type, uint32_t dim_type, uint32_t value_type, uint8_t dim_op_type) {
uint32_t tmp = 0;
/* Only add key type if we have a value type. We want to maintain the invariant that a
* key type exists iff a value type exists even in dead code that may use empty types. */
Expand Down Expand Up @@ -1987,7 +1987,7 @@ static uint32_t assign_dim_array_result_type(
}

static uint32_t assign_dim_result_type(
uint32_t arr_type, uint32_t dim_type, uint32_t value_type, zend_uchar dim_op_type) {
uint32_t arr_type, uint32_t dim_type, uint32_t value_type, uint8_t dim_op_type) {
uint32_t tmp = arr_type & ~(MAY_BE_RC1|MAY_BE_RCN);

if (arr_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) {
Expand All @@ -2008,7 +2008,7 @@ static uint32_t assign_dim_result_type(

/* For binary ops that have compound assignment operators */
static uint32_t binary_op_result_type(
zend_ssa *ssa, zend_uchar opcode, uint32_t t1, uint32_t t2, int result_var,
zend_ssa *ssa, uint8_t opcode, uint32_t t1, uint32_t t2, int result_var,
zend_long optimization_level) {
uint32_t tmp = 0;
uint32_t t1_type = (t1 & MAY_BE_ANY) | (t1 & MAY_BE_UNDEF ? MAY_BE_NULL : 0);
Expand Down Expand Up @@ -3335,7 +3335,7 @@ static zend_always_inline zend_result _zend_update_type_info(
tmp |= key_type | MAY_BE_ARRAY | MAY_BE_ARRAY_OF_NULL;
}
while (j >= 0) {
zend_uchar opcode;
uint8_t opcode;

if (!ssa_opcodes) {
ZEND_ASSERT(j == (opline - op_array->opcodes) + 1 && "Use must be in next opline");
Expand Down Expand Up @@ -3978,7 +3978,7 @@ static bool can_convert_to_double(
return 0;
}
} else {
zend_uchar opcode = opline->opcode;
uint8_t opcode = opline->opcode;

if (opcode == ZEND_ASSIGN_OP) {
opcode = opline->extended_value;
Expand Down
4 changes: 3 additions & 1 deletion Zend/Optimizer/zend_inference.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
/* Bitmask for type inference (zend_ssa_var_info.type) */
#include "zend_type_info.h"

#include <stdint.h>

#define MAY_BE_PACKED_GUARD (1<<27) /* needs packed array guard */
#define MAY_BE_CLASS_GUARD (1<<27) /* needs class guard */
#define MAY_BE_GUARD (1<<28) /* needs type guard */
Expand Down Expand Up @@ -220,7 +222,7 @@ ZEND_API void zend_ssa_find_false_dependencies(const zend_op_array *op_array, ze
ZEND_API void zend_ssa_find_sccs(const zend_op_array *op_array, zend_ssa *ssa);
ZEND_API int zend_ssa_inference(zend_arena **raena, const zend_op_array *op_array, const zend_script *script, zend_ssa *ssa, zend_long optimization_level);

ZEND_API uint32_t zend_array_element_type(uint32_t t1, zend_uchar op_type, int write, int insert);
ZEND_API uint32_t zend_array_element_type(uint32_t t1, uint8_t op_type, int write, int insert);

ZEND_API bool zend_inference_propagate_range(const zend_op_array *op_array, const zend_ssa *ssa, const zend_op *opline, const zend_ssa_op* ssa_op, int var, zend_ssa_range *tmp);

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 @@ -54,7 +54,7 @@ void zend_optimizer_collect_constant(zend_optimizer_ctx *ctx, zval *name, zval*
}
}

zend_result zend_optimizer_eval_binary_op(zval *result, zend_uchar opcode, zval *op1, zval *op2) /* {{{ */
zend_result zend_optimizer_eval_binary_op(zval *result, uint8_t opcode, zval *op1, zval *op2) /* {{{ */
{
if (zend_binary_op_produces_error(opcode, op1, op2)) {
return FAILURE;
Expand All @@ -65,7 +65,7 @@ zend_result zend_optimizer_eval_binary_op(zval *result, zend_uchar opcode, zval
}
/* }}} */

zend_result zend_optimizer_eval_unary_op(zval *result, zend_uchar opcode, zval *op1) /* {{{ */
zend_result zend_optimizer_eval_unary_op(zval *result, uint8_t opcode, zval *op1) /* {{{ */
{
unary_op_type unary_op = get_unary_op(opcode);

Expand Down Expand Up @@ -620,7 +620,7 @@ bool zend_optimizer_update_op2_const(zend_op_array *op_array,

bool zend_optimizer_replace_by_const(zend_op_array *op_array,
zend_op *opline,
zend_uchar type,
uint8_t type,
uint32_t var,
zval *val)
{
Expand Down
8 changes: 5 additions & 3 deletions Zend/Optimizer/zend_optimizer_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "zend_ssa.h"
#include "zend_func_info.h"

#include <stdint.h>

#define ZEND_OP1_LITERAL(opline) (op_array)->literals[(opline)->op1.constant]
#define ZEND_OP1_JMP_ADDR(opline) OP_JMP_ADDR(opline, (opline)->op1)
#define ZEND_OP2_LITERAL(opline) (op_array)->literals[(opline)->op2.constant]
Expand Down Expand Up @@ -81,8 +83,8 @@ 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_binary_op(zval *result, uint8_t opcode, zval *op1, zval *op2);
zend_result zend_optimizer_eval_unary_op(zval *result, uint8_t opcode, zval *op1);
zend_result zend_optimizer_eval_cast(zval *result, uint32_t type, zval *op1);
zend_result zend_optimizer_eval_strlen(zval *result, const zval *op1);
zend_result zend_optimizer_eval_special_func_call(
Expand All @@ -95,7 +97,7 @@ bool zend_optimizer_update_op2_const(zend_op_array *op_array,
zval *val);
bool zend_optimizer_replace_by_const(zend_op_array *op_array,
zend_op *opline,
zend_uchar type,
uint8_t type,
uint32_t var,
zval *val);
zend_op *zend_optimizer_get_loop_var_def(const zend_op_array *op_array, zend_op *free_opline);
Expand Down
6 changes: 3 additions & 3 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_weak(const zval *arg, zend_long
}
} else if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
double d;
zend_uchar type;
uint8_t type;

if (UNEXPECTED((type = is_numeric_str_function(Z_STR_P(arg), dest, &d)) != IS_LONG)) {
if (EXPECTED(type != 0)) {
Expand Down Expand Up @@ -613,7 +613,7 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_double_weak(const zval *arg, double *
*dest = (double)Z_LVAL_P(arg);
} else if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
zend_long l;
zend_uchar type;
uint8_t type;

if (UNEXPECTED((type = is_numeric_str_function(Z_STR_P(arg), &l, dest)) != IS_DOUBLE)) {
if (EXPECTED(type != 0)) {
Expand Down Expand Up @@ -660,7 +660,7 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_number_slow(zval *arg, zval **dest, u
zend_string *str = Z_STR_P(arg);
zend_long lval;
double dval;
zend_uchar type = is_numeric_str_function(str, &lval, &dval);
uint8_t type = is_numeric_str_function(str, &lval, &dval);
if (type == IS_LONG) {
ZVAL_LONG(arg, lval);
} else if (type == IS_DOUBLE) {
Expand Down
Loading