Skip to content

Commit 53d5420

Browse files
committed
Use more appropriate types in Optimizer
Mainly using zend_result and bool instead of int
1 parent 934eb55 commit 53d5420

23 files changed

+113
-112
lines changed

Zend/Optimizer/block_pass.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "zend_dump.h"
3131

3232
/* Checks if a constant (like "true") may be replaced by its value */
33-
int zend_optimizer_get_persistent_constant(zend_string *name, zval *result, int copy)
33+
bool zend_optimizer_get_persistent_constant(zend_string *name, zval *result, int copy)
3434
{
3535
zend_constant *c = zend_hash_find_ptr(EG(zend_constants), name);
3636
if (c) {
@@ -220,7 +220,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
220220
* Float to string conversion may be affected by current
221221
* locale setting.
222222
*/
223-
int l, old_len;
223+
size_t l, old_len;
224224

225225
if (Z_TYPE(ZEND_OP1_LITERAL(opline)) != IS_STRING) {
226226
convert_to_string(&ZEND_OP1_LITERAL(opline));
@@ -327,7 +327,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
327327
) {
328328
zval *arg = &OPLINE_OP1_LITERAL(sv);
329329
char *fname = FUNCTION_CACHE->funcs[Z_LVAL(ZEND_OP1_LITERAL(fcall))].function_name;
330-
int flen = FUNCTION_CACHE->funcs[Z_LVAL(ZEND_OP1_LITERAL(fcall))].name_len;
330+
size_t flen = FUNCTION_CACHE->funcs[Z_LVAL(ZEND_OP1_LITERAL(fcall))].name_len;
331331
if((flen == sizeof("function_exists")-1 && zend_binary_strcasecmp(fname, flen, "function_exists", sizeof("function_exists")-1) == 0) ||
332332
(flen == sizeof("is_callable")-1 && zend_binary_strcasecmp(fname, flen, "is_callable", sizeof("is_callable")-1) == 0)
333333
) {
@@ -341,7 +341,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
341341
}
342342
} else if(flen == sizeof("constant")-1 && zend_binary_strcasecmp(fname, flen, "constant", sizeof("constant")-1) == 0) {
343343
zval c;
344-
if(zend_optimizer_get_persistent_constant(Z_STR_P(arg), &c, 1 ELS_CC) != 0) {
344+
if (zend_optimizer_get_persistent_constant(Z_STR_P(arg), &c, 1 ELS_CC)) {
345345
literal_dtor(arg);
346346
MAKE_NOP(sv);
347347
MAKE_NOP(fcall);
@@ -712,7 +712,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
712712
src->opcode == ZEND_FAST_CONCAT) &&
713713
src->op2_type == IS_CONST) {
714714
/* compress consecutive CONCATs */
715-
int l, old_len;
715+
size_t l, old_len;
716716

717717
if (Z_TYPE(ZEND_OP2_LITERAL(opline)) != IS_STRING) {
718718
convert_to_string(&ZEND_OP2_LITERAL(opline));
@@ -960,7 +960,6 @@ static void assemble_code_blocks(zend_cfg *cfg, zend_op_array *op_array, zend_op
960960
zend_op *new_opcodes;
961961
zend_op *opline;
962962
uint32_t len = 0;
963-
int n;
964963

965964
for (b = blocks; b < end; b++) {
966965
if (b->len == 0) {
@@ -1129,7 +1128,7 @@ static void assemble_code_blocks(zend_cfg *cfg, zend_op_array *op_array, zend_op
11291128

11301129
/* rebuild map (just for printing) */
11311130
memset(cfg->map, -1, sizeof(int) * op_array->last);
1132-
for (n = 0; n < cfg->blocks_count; n++) {
1131+
for (int n = 0; n < cfg->blocks_count; n++) {
11331132
if (cfg->blocks[n].flags & (ZEND_BB_REACHABLE|ZEND_BB_UNREACHABLE_FREE)) {
11341133
cfg->map[cfg->blocks[n].start] = n;
11351134
}
@@ -1189,7 +1188,7 @@ static zend_always_inline zend_basic_block *get_next_block(const zend_cfg *cfg,
11891188

11901189

11911190
/* we use "jmp_hitlist" to avoid infinity loops during jmp optimization */
1192-
static zend_always_inline int in_hitlist(int target, int *jmp_hitlist, int jmp_hitlist_count)
1191+
static zend_always_inline bool in_hitlist(int target, int *jmp_hitlist, int jmp_hitlist_count)
11931192
{
11941193
int i;
11951194

@@ -1642,7 +1641,7 @@ static void zend_t_usage(zend_cfg *cfg, zend_op_array *op_array, zend_bitset use
16421641
}
16431642

16441643
if (ctx->debug_level & ZEND_DUMP_BLOCK_PASS_VARS) {
1645-
int printed = 0;
1644+
bool printed = 0;
16461645
uint32_t i;
16471646

16481647
for (i = op_array->last_var; i< op_array->T; i++) {

Zend/Optimizer/compact_literals.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static uint32_t add_static_slot(HashTable *hash,
8888
uint32_t op1,
8989
uint32_t op2,
9090
uint32_t kind,
91-
int *cache_size)
91+
uint32_t *cache_size)
9292
{
9393
uint32_t ret;
9494
zval *class_name = &op_array->literals[op1];
@@ -150,7 +150,8 @@ static zend_string *create_str_cache_key(zval *literal, uint32_t flags)
150150
void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx *ctx)
151151
{
152152
zend_op *opline, *end;
153-
int i, j, n, *map, cache_size;
153+
int i, j, n, *map;
154+
uint32_t cache_size;
154155
zval zv, *pos;
155156
literal_info *info;
156157
int l_null = -1;

Zend/Optimizer/dfa_pass.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
# include "ssa_integrity.c"
3939
#endif
4040

41-
int zend_dfa_analyze_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx, zend_ssa *ssa)
41+
zend_result zend_dfa_analyze_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx, zend_ssa *ssa)
4242
{
4343
uint32_t build_flags;
4444

@@ -410,7 +410,7 @@ int zend_dfa_optimize_calls(zend_op_array *op_array, zend_ssa *ssa)
410410
&& (send_needly->opcode == ZEND_SEND_VAL
411411
|| send_needly->opcode == ZEND_SEND_VAR)
412412
) {
413-
int ok = 1;
413+
bool ok = 1;
414414

415415
HashTable *src = Z_ARRVAL_P(CT_CONSTANT_EX(op_array, send_array->op1.constant));
416416
HashTable *dst;
@@ -996,7 +996,7 @@ static int zend_dfa_optimize_jmps(zend_op_array *op_array, zend_ssa *ssa)
996996
return removed_ops;
997997
}
998998

999-
static int zend_dfa_try_to_replace_result(zend_op_array *op_array, zend_ssa *ssa, int def, int cv_var)
999+
static bool zend_dfa_try_to_replace_result(zend_op_array *op_array, zend_ssa *ssa, int def, int cv_var)
10001000
{
10011001
int result_var = ssa->ops[def].result_def;
10021002
int cv = EX_NUM_TO_VAR(ssa->vars[cv_var].var);

Zend/Optimizer/escape_analysis.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static zend_always_inline void union_find_unite(int *parent, int *size, int i, i
7373
}
7474
/* }}} */
7575

76-
static int zend_build_equi_escape_sets(int *parent, zend_op_array *op_array, zend_ssa *ssa) /* {{{ */
76+
static zend_result zend_build_equi_escape_sets(int *parent, zend_op_array *op_array, zend_ssa *ssa) /* {{{ */
7777
{
7878
zend_ssa_var *ssa_vars = ssa->vars;
7979
int ssa_vars_count = ssa->vars_count;
@@ -147,7 +147,7 @@ static int zend_build_equi_escape_sets(int *parent, zend_op_array *op_array, zen
147147
}
148148
/* }}} */
149149

150-
static int is_allocation_def(zend_op_array *op_array, zend_ssa *ssa, int def, int var, const zend_script *script) /* {{{ */
150+
static bool is_allocation_def(zend_op_array *op_array, zend_ssa *ssa, int def, int var, const zend_script *script) /* {{{ */
151151
{
152152
zend_ssa_op *ssa_op = ssa->ops + def;
153153
zend_op *opline = op_array->opcodes + def;
@@ -212,7 +212,7 @@ static int is_allocation_def(zend_op_array *op_array, zend_ssa *ssa, int def, in
212212
}
213213
/* }}} */
214214

215-
static int is_local_def(zend_op_array *op_array, zend_ssa *ssa, int def, int var, const zend_script *script) /* {{{ */
215+
static bool is_local_def(zend_op_array *op_array, zend_ssa *ssa, int def, int var, const zend_script *script) /* {{{ */
216216
{
217217
zend_ssa_op *op = ssa->ops + def;
218218
zend_op *opline = op_array->opcodes + def;
@@ -256,7 +256,7 @@ static int is_local_def(zend_op_array *op_array, zend_ssa *ssa, int def, int var
256256
}
257257
/* }}} */
258258

259-
static int is_escape_use(zend_op_array *op_array, zend_ssa *ssa, int use, int var) /* {{{ */
259+
static bool is_escape_use(zend_op_array *op_array, zend_ssa *ssa, int use, int var) /* {{{ */
260260
{
261261
zend_ssa_op *ssa_op = ssa->ops + use;
262262
zend_op *opline = op_array->opcodes + use;
@@ -367,7 +367,7 @@ static int is_escape_use(zend_op_array *op_array, zend_ssa *ssa, int use, int va
367367
}
368368
/* }}} */
369369

370-
int zend_ssa_escape_analysis(const zend_script *script, zend_op_array *op_array, zend_ssa *ssa) /* {{{ */
370+
zend_result zend_ssa_escape_analysis(const zend_script *script, zend_op_array *op_array, zend_ssa *ssa) /* {{{ */
371371
{
372372
zend_ssa_var *ssa_vars = ssa->vars;
373373
int ssa_vars_count = ssa->vars_count;

Zend/Optimizer/optimize_temp_vars_5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
void zend_optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_ctx *ctx)
4242
{
43-
int T = op_array->T;
43+
uint32_t T = op_array->T;
4444
int offset = op_array->last_var;
4545
uint32_t bitset_len;
4646
zend_bitset taken_T; /* T index in use */

Zend/Optimizer/pass3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "zend_vm.h"
3232

3333
/* we use "jmp_hitlist" to avoid infinity loops during jmp optimization */
34-
static zend_always_inline int in_hitlist(zend_op *target, zend_op **jmp_hitlist, int jmp_hitlist_count)
34+
static zend_always_inline bool in_hitlist(zend_op *target, zend_op **jmp_hitlist, int jmp_hitlist_count)
3535
{
3636
int i;
3737

0 commit comments

Comments
 (0)