From 6b9186848bf14fd5c5d1fd833f7102f6b6003165 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Mon, 17 Aug 2026 20:13:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(llvmlite):=20=5Ftype=5Fstr=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20IR-FAIL=20=E6=A0=A1=E9=AA=8C=E6=8A=A4=E6=A0=8F?= =?UTF-8?q?=EF=BC=8C=E9=98=B2=20LLVMType=20=E6=82=AC=E7=A9=BA=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=9E=83=E5=9C=BE=20IR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 后难以定位根因。 --- includes/llvmlite/__builder.vp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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