Skip to content

Commit d5c649b

Browse files
zend_compiler, ...: use uint8_t instead of zend_uchar (php#10621)
`zend_uchar` suggests that the value is an ASCII character, but here, it's about very small integers. This is misleading, so let's use a C99 integer instead. On all architectures currently supported by PHP, `zend_uchar` and `uint8_t` are identical. This change is only about code readability.
1 parent 0460420 commit d5c649b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+359
-338
lines changed

Zend/Optimizer/block_pass.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
519519
break;
520520
case ZEND_IS_SMALLER:
521521
if (opline->opcode == ZEND_BOOL_NOT) {
522-
zend_uchar tmp_type;
522+
uint8_t tmp_type;
523523
uint32_t tmp;
524524

525525
src->opcode = ZEND_IS_SMALLER_OR_EQUAL;
@@ -537,7 +537,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
537537
break;
538538
case ZEND_IS_SMALLER_OR_EQUAL:
539539
if (opline->opcode == ZEND_BOOL_NOT) {
540-
zend_uchar tmp_type;
540+
uint8_t tmp_type;
541541
uint32_t tmp;
542542

543543
src->opcode = ZEND_IS_SMALLER;

Zend/Optimizer/dce.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ static inline bool is_free_of_live_var(context *ctx, zend_op *opline, zend_ssa_o
413413
static bool dce_instr(context *ctx, zend_op *opline, zend_ssa_op *ssa_op) {
414414
zend_ssa *ssa = ctx->ssa;
415415
int free_var = -1;
416-
zend_uchar free_var_type;
416+
uint8_t free_var_type;
417417

418418
if (opline->opcode == ZEND_NOP) {
419419
return 0;

Zend/Optimizer/dfa_pass.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ static int zend_dfa_optimize_jmps(zend_op_array *op_array, zend_ssa *ssa)
932932
case ZEND_MATCH:
933933
if (opline->op1_type == IS_CONST) {
934934
zval *zv = CT_CONSTANT_EX(op_array, opline->op1.constant);
935-
zend_uchar type = Z_TYPE_P(zv);
935+
uint8_t type = Z_TYPE_P(zv);
936936
bool correct_type =
937937
(opline->opcode == ZEND_SWITCH_LONG && type == IS_LONG)
938938
|| (opline->opcode == ZEND_SWITCH_STRING && type == IS_STRING)

Zend/Optimizer/sccp.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ typedef struct _sccp_ctx {
8383
zval bot;
8484
} sccp_ctx;
8585

86-
#define TOP ((zend_uchar)-1)
87-
#define BOT ((zend_uchar)-2)
88-
#define PARTIAL_ARRAY ((zend_uchar)-3)
89-
#define PARTIAL_OBJECT ((zend_uchar)-4)
86+
#define TOP ((uint8_t)-1)
87+
#define BOT ((uint8_t)-2)
88+
#define PARTIAL_ARRAY ((uint8_t)-3)
89+
#define PARTIAL_OBJECT ((uint8_t)-4)
9090
#define IS_TOP(zv) (Z_TYPE_P(zv) == TOP)
9191
#define IS_BOT(zv) (Z_TYPE_P(zv) == BOT)
9292
#define IS_PARTIAL_ARRAY(zv) (Z_TYPE_P(zv) == PARTIAL_ARRAY)
@@ -314,7 +314,7 @@ static bool try_replace_op2(
314314
return 0;
315315
}
316316

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

665-
static inline zend_result ct_eval_incdec(zval *result, zend_uchar opcode, zval *op1) {
665+
static inline zend_result ct_eval_incdec(zval *result, uint8_t opcode, zval *op1) {
666666
if (Z_TYPE_P(op1) == IS_ARRAY || IS_PARTIAL_ARRAY(op1)) {
667667
return FAILURE;
668668
}
@@ -1843,7 +1843,7 @@ static void sccp_mark_feasible_successors(
18431843
case ZEND_MATCH:
18441844
{
18451845
bool strict_comparison = opline->opcode == ZEND_MATCH;
1846-
zend_uchar type = Z_TYPE_P(op1);
1846+
uint8_t type = Z_TYPE_P(op1);
18471847
bool correct_type =
18481848
(opline->opcode == ZEND_SWITCH_LONG && type == IS_LONG)
18491849
|| (opline->opcode == ZEND_SWITCH_STRING && type == IS_STRING)
@@ -2134,7 +2134,7 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
21342134
&& opline->opcode != ZEND_ADD_ARRAY_ELEMENT
21352135
&& opline->opcode != ZEND_ADD_ARRAY_UNPACK) {
21362136
/* Replace with QM_ASSIGN */
2137-
zend_uchar old_type = opline->result_type;
2137+
uint8_t old_type = opline->result_type;
21382138
uint32_t old_var = opline->result.var;
21392139

21402140
ssa_op->result_def = -1;

Zend/Optimizer/ssa_integrity.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static inline bool is_in_successors(zend_basic_block *block, int check) {
8585
return 0;
8686
}
8787

88-
static inline bool is_var_type(zend_uchar type) {
88+
static inline bool is_var_type(uint8_t type) {
8989
return (type & (IS_CV|IS_VAR|IS_TMP_VAR)) != 0;
9090
}
9191

Zend/Optimizer/zend_cfg.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static void zend_mark_reachable(zend_op *opcodes, zend_cfg *cfg, zend_basic_bloc
4141
zend_basic_block *succ = blocks + b->successors[i];
4242

4343
if (b->len != 0) {
44-
zend_uchar opcode = opcodes[b->start + b->len - 1].opcode;
44+
uint8_t opcode = opcodes[b->start + b->len - 1].opcode;
4545
if (opcode == ZEND_MATCH) {
4646
succ->flags |= ZEND_BB_TARGET;
4747
} else if (opcode == ZEND_SWITCH_LONG || opcode == ZEND_SWITCH_STRING) {

Zend/Optimizer/zend_dump.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static void zend_dump_unused_op(const zend_op *opline, znode_op op, uint32_t fla
132132
}
133133
}
134134

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

351-
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)
351+
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)
352352
{
353353
if (ssa_var_num >= 0) {
354354
fprintf(stderr, "#%d.", ssa_var_num);

Zend/Optimizer/zend_dump.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "zend_ssa.h"
2323
#include "zend_dfg.h"
2424

25+
#include <stdint.h>
26+
2527
#define ZEND_DUMP_HIDE_UNREACHABLE (1<<0)
2628
#define ZEND_DUMP_RC_INFERENCE (1<<1)
2729
#define ZEND_DUMP_CFG (1<<2)
@@ -39,8 +41,8 @@ void zend_dump_dfg(const zend_op_array *op_array, const zend_cfg *cfg, const zen
3941
void zend_dump_phi_placement(const zend_op_array *op_array, const zend_ssa *ssa);
4042
void zend_dump_variables(const zend_op_array *op_array);
4143
void zend_dump_ssa_variables(const zend_op_array *op_array, const zend_ssa *ssa, uint32_t dump_flags);
42-
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);
43-
ZEND_API void zend_dump_var(const zend_op_array *op_array, zend_uchar var_type, int var_num);
44+
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);
45+
ZEND_API void zend_dump_var(const zend_op_array *op_array, uint8_t var_type, int var_num);
4446
void zend_dump_op_array_name(const zend_op_array *op_array);
4547
void zend_dump_const(const zval *zv);
4648
void zend_dump_ht(HashTable *ht);

Zend/Optimizer/zend_inference.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ static void float_div(zend_long a, zend_long b, zend_long *r1, zend_long *r2) {
562562

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

568568
switch (opcode) {
@@ -1881,7 +1881,7 @@ ZEND_API uint32_t ZEND_FASTCALL zend_array_type_info(const zval *zv)
18811881
}
18821882

18831883

1884-
ZEND_API uint32_t zend_array_element_type(uint32_t t1, zend_uchar op_type, int write, int insert)
1884+
ZEND_API uint32_t zend_array_element_type(uint32_t t1, uint8_t op_type, int write, int insert)
18851885
{
18861886
uint32_t tmp = 0;
18871887

@@ -1943,7 +1943,7 @@ ZEND_API uint32_t zend_array_element_type(uint32_t t1, zend_uchar op_type, int w
19431943
}
19441944

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

19891989
static uint32_t assign_dim_result_type(
1990-
uint32_t arr_type, uint32_t dim_type, uint32_t value_type, zend_uchar dim_op_type) {
1990+
uint32_t arr_type, uint32_t dim_type, uint32_t value_type, uint8_t dim_op_type) {
19911991
uint32_t tmp = arr_type & ~(MAY_BE_RC1|MAY_BE_RCN);
19921992

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

20092009
/* For binary ops that have compound assignment operators */
20102010
static uint32_t binary_op_result_type(
2011-
zend_ssa *ssa, zend_uchar opcode, uint32_t t1, uint32_t t2, int result_var,
2011+
zend_ssa *ssa, uint8_t opcode, uint32_t t1, uint32_t t2, int result_var,
20122012
zend_long optimization_level) {
20132013
uint32_t tmp = 0;
20142014
uint32_t t1_type = (t1 & MAY_BE_ANY) | (t1 & MAY_BE_UNDEF ? MAY_BE_NULL : 0);
@@ -3335,7 +3335,7 @@ static zend_always_inline zend_result _zend_update_type_info(
33353335
tmp |= key_type | MAY_BE_ARRAY | MAY_BE_ARRAY_OF_NULL;
33363336
}
33373337
while (j >= 0) {
3338-
zend_uchar opcode;
3338+
uint8_t opcode;
33393339

33403340
if (!ssa_opcodes) {
33413341
ZEND_ASSERT(j == (opline - op_array->opcodes) + 1 && "Use must be in next opline");
@@ -3978,7 +3978,7 @@ static bool can_convert_to_double(
39783978
return 0;
39793979
}
39803980
} else {
3981-
zend_uchar opcode = opline->opcode;
3981+
uint8_t opcode = opline->opcode;
39823982

39833983
if (opcode == ZEND_ASSIGN_OP) {
39843984
opcode = opline->extended_value;

Zend/Optimizer/zend_inference.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
/* Bitmask for type inference (zend_ssa_var_info.type) */
2727
#include "zend_type_info.h"
2828

29+
#include <stdint.h>
30+
2931
#define MAY_BE_PACKED_GUARD (1<<27) /* needs packed array guard */
3032
#define MAY_BE_CLASS_GUARD (1<<27) /* needs class guard */
3133
#define MAY_BE_GUARD (1<<28) /* needs type guard */
@@ -220,7 +222,7 @@ ZEND_API void zend_ssa_find_false_dependencies(const zend_op_array *op_array, ze
220222
ZEND_API void zend_ssa_find_sccs(const zend_op_array *op_array, zend_ssa *ssa);
221223
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);
222224

223-
ZEND_API uint32_t zend_array_element_type(uint32_t t1, zend_uchar op_type, int write, int insert);
225+
ZEND_API uint32_t zend_array_element_type(uint32_t t1, uint8_t op_type, int write, int insert);
224226

225227
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);
226228

Zend/Optimizer/zend_optimizer.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void zend_optimizer_collect_constant(zend_optimizer_ctx *ctx, zval *name, zval*
5454
}
5555
}
5656

57-
zend_result zend_optimizer_eval_binary_op(zval *result, zend_uchar opcode, zval *op1, zval *op2) /* {{{ */
57+
zend_result zend_optimizer_eval_binary_op(zval *result, uint8_t opcode, zval *op1, zval *op2) /* {{{ */
5858
{
5959
if (zend_binary_op_produces_error(opcode, op1, op2)) {
6060
return FAILURE;
@@ -65,7 +65,7 @@ zend_result zend_optimizer_eval_binary_op(zval *result, zend_uchar opcode, zval
6565
}
6666
/* }}} */
6767

68-
zend_result zend_optimizer_eval_unary_op(zval *result, zend_uchar opcode, zval *op1) /* {{{ */
68+
zend_result zend_optimizer_eval_unary_op(zval *result, uint8_t opcode, zval *op1) /* {{{ */
6969
{
7070
unary_op_type unary_op = get_unary_op(opcode);
7171

@@ -620,7 +620,7 @@ bool zend_optimizer_update_op2_const(zend_op_array *op_array,
620620

621621
bool zend_optimizer_replace_by_const(zend_op_array *op_array,
622622
zend_op *opline,
623-
zend_uchar type,
623+
uint8_t type,
624624
uint32_t var,
625625
zval *val)
626626
{

Zend/Optimizer/zend_optimizer_internal.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "zend_ssa.h"
2626
#include "zend_func_info.h"
2727

28+
#include <stdint.h>
29+
2830
#define ZEND_OP1_LITERAL(opline) (op_array)->literals[(opline)->op1.constant]
2931
#define ZEND_OP1_JMP_ADDR(opline) OP_JMP_ADDR(opline, (opline)->op1)
3032
#define ZEND_OP2_LITERAL(opline) (op_array)->literals[(opline)->op2.constant]
@@ -81,8 +83,8 @@ int zend_optimizer_add_literal(zend_op_array *op_array, const zval *zv);
8183
bool zend_optimizer_get_persistent_constant(zend_string *name, zval *result, int copy);
8284
void zend_optimizer_collect_constant(zend_optimizer_ctx *ctx, zval *name, zval* value);
8385
bool zend_optimizer_get_collected_constant(HashTable *constants, zval *name, zval* value);
84-
zend_result zend_optimizer_eval_binary_op(zval *result, zend_uchar opcode, zval *op1, zval *op2);
85-
zend_result zend_optimizer_eval_unary_op(zval *result, zend_uchar opcode, zval *op1);
86+
zend_result zend_optimizer_eval_binary_op(zval *result, uint8_t opcode, zval *op1, zval *op2);
87+
zend_result zend_optimizer_eval_unary_op(zval *result, uint8_t opcode, zval *op1);
8688
zend_result zend_optimizer_eval_cast(zval *result, uint32_t type, zval *op1);
8789
zend_result zend_optimizer_eval_strlen(zval *result, const zval *op1);
8890
zend_result zend_optimizer_eval_special_func_call(
@@ -95,7 +97,7 @@ bool zend_optimizer_update_op2_const(zend_op_array *op_array,
9597
zval *val);
9698
bool zend_optimizer_replace_by_const(zend_op_array *op_array,
9799
zend_op *opline,
98-
zend_uchar type,
100+
uint8_t type,
99101
uint32_t var,
100102
zval *val);
101103
zend_op *zend_optimizer_get_loop_var_def(const zend_op_array *op_array, zend_op *free_opline);

Zend/zend_API.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_weak(const zval *arg, zend_long
552552
}
553553
} else if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
554554
double d;
555-
zend_uchar type;
555+
uint8_t type;
556556

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

618618
if (UNEXPECTED((type = is_numeric_str_function(Z_STR_P(arg), &l, dest)) != IS_DOUBLE)) {
619619
if (EXPECTED(type != 0)) {
@@ -660,7 +660,7 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_number_slow(zval *arg, zval **dest, u
660660
zend_string *str = Z_STR_P(arg);
661661
zend_long lval;
662662
double dval;
663-
zend_uchar type = is_numeric_str_function(str, &lval, &dval);
663+
uint8_t type = is_numeric_str_function(str, &lval, &dval);
664664
if (type == IS_LONG) {
665665
ZVAL_LONG(arg, lval);
666666
} else if (type == IS_DOUBLE) {

0 commit comments

Comments
 (0)