diff --git a/lib/core/Handles/HandlesFor.py b/lib/core/Handles/HandlesFor.py index 9bbcc72..1b9aae4 100644 --- a/lib/core/Handles/HandlesFor.py +++ b/lib/core/Handles/HandlesFor.py @@ -229,7 +229,12 @@ class ForHandle(BaseHandle): StepLoopVal: ir.Value = CachedLoopVal if TargetName in Gen._reg_values and Gen._reg_values[TargetName] is CachedLoopVal: del Gen._reg_values[TargetName] - else: + elif not Gen.builder.block.is_terminated: + # 死代码防御(2026-08-15):body 修改过循环变量时此处重新 load, + # 但该值实际未被使用(step 块 L237 会重新 load)。 + # 若 body 以 break/continue/return 终结,当前块已带 terminator, + # 再发射 load 会落在 terminator 之后 → opt 报 + # "expected instruction opcode" 非法 IR。 StepLoopVal = Gen._load(LoopVar, name=TargetName) if not Gen.builder.block.is_terminated: Gen.builder.branch(StepBB)