Skip to content

Commit e638725

Browse files
committed
Trigger assertion failure on SSA verification failure
To make sure this is automatically detectable as a PHP bug, e.g. during fuzzing. Also dump the current opcodes/SSA as we may no longer reach a following dump.
1 parent 45d8170 commit e638725

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Zend/Optimizer/ssa_integrity.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static inline bool is_var_type(zend_uchar type) {
108108
#define INSTR(i) \
109109
(i), (zend_get_opcode_name(op_array->opcodes[i].opcode))
110110

111-
int ssa_verify_integrity(zend_op_array *op_array, zend_ssa *ssa, const char *extra) {
111+
void ssa_verify_integrity(zend_op_array *op_array, zend_ssa *ssa, const char *extra) {
112112
zend_cfg *cfg = &ssa->cfg;
113113
zend_ssa_phi *phi;
114114
int i, status = SUCCESS;
@@ -146,7 +146,7 @@ int ssa_verify_integrity(zend_op_array *op_array, zend_ssa *ssa, const char *ext
146146
FOREACH_USE(var, use) {
147147
if (++c > 10000) {
148148
FAIL("cycle in uses of " VARFMT "\n", VAR(i));
149-
return status;
149+
goto finish;
150150
}
151151
if (!is_used_by_op(ssa, use, i)) {
152152
fprintf(stderr, "var " VARFMT " not in uses of op %d\n", VAR(i), use);
@@ -157,7 +157,7 @@ int ssa_verify_integrity(zend_op_array *op_array, zend_ssa *ssa, const char *ext
157157
FOREACH_PHI_USE(var, phi) {
158158
if (++c > 10000) {
159159
FAIL("cycle in phi uses of " VARFMT "\n", VAR(i));
160-
return status;
160+
goto finish;
161161
}
162162
if (!is_in_phi_sources(ssa, phi, i)) {
163163
FAIL("var " VARFMT " not in phi sources of %d\n", VAR(i), phi->ssa_var);
@@ -374,5 +374,9 @@ int ssa_verify_integrity(zend_op_array *op_array, zend_ssa *ssa, const char *ext
374374
}
375375
}
376376

377-
return status;
377+
finish:
378+
if (status == FAILURE) {
379+
zend_dump_op_array(op_array, ZEND_DUMP_SSA, "at SSA integrity verification", ssa);
380+
ZEND_ASSERT(0 && "SSA integrity verification failed");
381+
}
378382
}

0 commit comments

Comments
 (0)