diff --git a/includes/llvmlite/__builder.vp b/includes/llvmlite/__builder.vp index 1b3737d..0de1afc 100644 --- a/includes/llvmlite/__builder.vp +++ b/includes/llvmlite/__builder.vp @@ -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