fix(TPC): range for 循环 body 以 break 终结时不再发射死代码 load(游离指令致 opt expected instruction opcode)
根因: HandlesFor.py L229-233 在 body 使 _reg_values[循环变量] 失效后, 于当前 builder 位置重新 load 循环变量(该值实际未被使用, 死代码)。 当 body 最后一条语句是 break 时当前块已带 terminator, load 落在 br for.end 之后 → 非法 IR → opt/llc 报 'expected instruction opcode'。 触发场景: 装饰器扫描循环 body 内 list[ASTptr].get 调用触发泛型特化 重入编译(_EmitFunctionLlvm L1647 整体清空 _reg_values 且不恢复)。 修复: else 分支加 is_terminated 守卫, 终结时跳过死 load(语义不变)。
This commit is contained in:
1 parent
8112e0d66f
commit
5844e6e725
1 file changed
+6
-1
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user