Files
TransPyC/debug-llvmtype-overwrite-crash.md
T
2026-08-22 02:35:30 +08:00

29 lines
2.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Debug Session: llvmtype-overwrite-crash
状态: [OPEN]
## 症状
- 编译 TransPyV(Projectrans.py)时,CallGenMixin.vp 的 `.ll`(7dcdb461407a420d.ll)在 `_inject_requires_fields` 的 `cur_func` 处理区域**确定性截断**:
- 第 1 次:L33698 `%100 = bitcast i8* null t`(缺 `to <type>`,目标类型打印为垃圾 `t`)
- 第 2 次:L33697 `store %"43ebf8d8c9837267.Function"* %98, %"43ebf8d`(类型名截断 + 文件尾)
- llc 报:`expected 'to' after cast value` / `end of file in global variable name`
- 两次崩溃位置相同(`cur_func: llvmlite.Function | t.CPtr = trans._cur_func` 声明 + `if cur_func is None: return 0` 检查区域),现象略变 → 内存破坏
## 关键源码
- 触发源码:`TransPyV/App/lib/core/Gen/CallGenMixin.vp` L4187-4189
- 生成崩溃 IR 的代码:`TransPyV/App/lib/core/Gen/ExprGenMixin.vp` L1993(None 检查指针对齐 bitcast)
- 联合类型变量声明:`TransPyV/App/lib/core/Handles/HandlesAnnAssign.vp` L633-677(translate_value + coerce_to_type + precise_rhs_ty 重建 alloca)
- IR 指令生成:`includes/llvmlite/__builder.vp` build_store/build_bitcast/_type_str
- 类型打印:`includes/llvmlite/__types.vp` TypePrint
## 假设(3-5 个,可证伪)
- H1: 联合类型 coerce(%97/%98 冗余同类型 bitcast)生成路径越界写,破坏后续类型对象/行缓冲
- H2: HandlesAnnAssign 的 precise_rhs_ty alloca 重建逻辑(L658-668)写越界(新建 alloca 或符号表更新破坏内存)
- H3: _type_str 的 alloc(512) 与 TypePrint 内部 alloc(256)(Ptr(Struct) 快速路径 sn_cp)在 MemBuddy buddy 碎片下重叠
- H4: 跨遍 reset_to 回收了函数翻译中创建的 LLVMType 类型对象(perm_pool 同类问题,类型对象未持久化)
- H5: 后续指令生成(icmp/br 或 dump_ir 写盘)在 cur_func 检查后崩溃(非 bitcast 本身)
## 插桩计划(第一处改动必须是插桩)
- 待用户确认配合运行编译后实施
- 观察点:build_bitcast/build_store 前打印 ty 地址 + TypePrint 结果;HandlesAnnAssign coerce 前后;dump_ir 写盘前缓冲大小