Skip to content

Commit b916567

Browse files
committed
Verify that used SSA variables are defined
There should either be a defining instruction, defining phi, or it should be an undef entry variable.
1 parent 4b9a4c4 commit b916567

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Zend/Optimizer/ssa_integrity.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ static inline bool is_var_type(zend_uchar type) {
8989
return (type & (IS_CV|IS_VAR|IS_TMP_VAR)) != 0;
9090
}
9191

92+
static inline bool is_defined(const zend_ssa *ssa, const zend_op_array *op_array, int var) {
93+
const zend_ssa_var *ssa_var = &ssa->vars[var];
94+
return ssa_var->definition >= 0 || ssa_var->definition_phi || var < op_array->last_var;
95+
}
96+
9297
#define FAIL(...) do { \
9398
if (status == SUCCESS) { \
9499
fprintf(stderr, "\nIn function %s::%s (%s):\n", \
@@ -209,6 +214,10 @@ void ssa_verify_integrity(zend_op_array *op_array, zend_ssa *ssa, const char *ex
209214
if (ssa_op->op1_use >= ssa->vars_count) {
210215
FAIL("op1 use %d out of range\n", ssa_op->op1_use);
211216
}
217+
if (!is_defined(ssa, op_array, ssa_op->op1_use)) {
218+
FAIL("op1 use of " VARFMT " in " INSTRFMT " is not defined\n",
219+
VAR(ssa_op->op1_use), INSTR(i));
220+
}
212221
if (!is_in_use_chain(ssa, ssa_op->op1_use, i)) {
213222
FAIL("op1 use of " VARFMT " in " INSTRFMT " not in use chain\n",
214223
VAR(ssa_op->op1_use), INSTR(i));
@@ -222,6 +231,10 @@ void ssa_verify_integrity(zend_op_array *op_array, zend_ssa *ssa, const char *ex
222231
if (ssa_op->op2_use >= ssa->vars_count) {
223232
FAIL("op2 use %d out of range\n", ssa_op->op2_use);
224233
}
234+
if (!is_defined(ssa, op_array, ssa_op->op2_use)) {
235+
FAIL("op2 use of " VARFMT " in " INSTRFMT " is not defined\n",
236+
VAR(ssa_op->op2_use), INSTR(i));
237+
}
225238
if (!is_in_use_chain(ssa, ssa_op->op2_use, i)) {
226239
FAIL("op2 use of " VARFMT " in " INSTRFMT " not in use chain\n",
227240
VAR(ssa_op->op2_use), INSTR(i));
@@ -235,6 +248,10 @@ void ssa_verify_integrity(zend_op_array *op_array, zend_ssa *ssa, const char *ex
235248
if (ssa_op->result_use >= ssa->vars_count) {
236249
FAIL("result use %d out of range\n", ssa_op->result_use);
237250
}
251+
if (!is_defined(ssa, op_array, ssa_op->result_use)) {
252+
FAIL("result use of " VARFMT " in " INSTRFMT " is not defined\n",
253+
VAR(ssa_op->result_use), INSTR(i));
254+
}
238255
if (!is_in_use_chain(ssa, ssa_op->result_use, i)) {
239256
FAIL("result use of " VARFMT " in " INSTRFMT " not in use chain\n",
240257
VAR(ssa_op->result_use), INSTR(i));

0 commit comments

Comments
 (0)