fix(llvmlite): _type_str 增加 IR-FAIL 校验护栏,防 LLVMType 悬空生成垃圾 IR

LLVMType 类型对象可能被 MemBuddy 覆盖/悬空(跨遍 reset 回收后 pool 内存复用),TypePrint 输出首字符变为垃圾(如 't')或为空。现在 _type_str 对输出做首字符合法性校验,非法即打印 [IR-FAIL] + 类型地址并 exit(1)(fail-fast),防止生成 bitcast i8* null t 类垃圾 IR 导致 llc 报 expected 'to' after cast value 后难以定位根因。
This commit is contained in:
TermiNexus committed 2026-08-17 20:13:13 +08:00
1 parent e5af28fa93
commit 6b9186848b
1 file changed
+14
+14
View File
@@ -4,6 +4,7 @@ import string
import viperlib
import memhub
import stdio
import stdlib
from linkedlist import GSListNode, GSList
from .__types import LLVMType, TypePrint
from .__values import Value, new_value, SSAValue
@@ -58,6 +59,19 @@ class IRBuilder:
if buf is None: return None
buf[0] = '\0'
TypePrint(buf, 512, ty, pool)
# [IR-FAIL] 校验护栏:LLVMType 类型对象可能被 MemBuddy 覆盖/悬空
# (跨遍 reset 回收后 pool 内存复用),此时 TypePrint 输出首字符
# 变为垃圾(如 't')或为空。立即 fail-fast 终止,防止生成
# `bitcast i8* null t` 类垃圾 IR,避免 llc 报 "expected 'to' after
# cast value" 后难以定位根因。
c0: t.CInt = buf[0]
if c0 == 0 or (c0 != '%' and c0 != '[' and c0 != '{' and c0 != 'f' and
c0 != 'd' and c0 != 'h' and c0 != 'i' and c0 != 'l' and
c0 != 'm' and c0 != 'v' and c0 != '.'):
stdio.printf("[IR-FAIL] _type_str: LLVMType 对象已损坏 ty=0x%llx 首字符=%d 输出='%s'\n",
t.CUInt64T(ty), c0, buf)
stdlib.exit(1)
return None
return buf