fix: 无条件 JMP 后继位置切成块头,修复跳转边丢失

Pass 1 仅对条件跳转切 fallthrough 后继,无条件 JMP 与其后指令
融块导致块尾判定错、Jump 边丢失,DCE 可达性误删 break 出口块
(label 悬空报 'Label not found')。JMP 后继同样置块头。
This commit is contained in:
2026-08-06 12:16:58 +08:00
parent 27b7f28726
commit 63cec1d448
+7 -2
View File
@@ -22,8 +22,13 @@ pub(super) fn partition_blocks(f: &IRFunction) -> Vec<bool> {
None => debug_assert!(false, "unresolved label {l}"),
}
}
// 条件跳转的 fallthrough 后继是块头(否则 cond+then 融块、条件边丢失)。
if matches!(inst.op, OpCode::JMP_IF_TRUE | OpCode::JMP_IF_FALSE | OpCode::JMP_IF_NULLISH) {
// 跳转的 fallthrough 后继是块头:条件跳转否则 cond+then 融块、条件边丢失;
// 无条件 JMP 同样必须切块头——JMP 不 fallthrough,但其后继位置需成块边界,
// 否则 JMP 与后续指令融块、块尾判定错、Jump 边丢失(DCE 可达性误删目标块)。
if matches!(
inst.op,
OpCode::JMP | OpCode::JMP_IF_TRUE | OpCode::JMP_IF_FALSE | OpCode::JMP_IF_NULLISH
) {
heads[i + 1] = true;
}
}