依据 T97 决定性结果,修复了 CVoid 严格验证,other_ty 有效性验证,fallback 不依赖 kind() 实现

This commit is contained in:
TermiNexus committed 2026-08-06 23:00:01 +08:00
1 parent f440bda421
commit c876df7907
2 files changed
+85 -2

No files matched your search

+40 -1
View File
@@ -152,8 +152,25 @@ def ParseVpiIntoModule(pool: memhub.MemBuddy | t.CPtr,
ast._lexer_init(lx, vpi_buf, pool)
tokens: ast.Token | t.CPtr = ast.tokenize(lx)
tree: ast.AST | t.CPtr = ast.parse_tokens(pool, tokens)
stdlib.free(vpi_buf)
# vpi_buf 延迟释放:AST 字符串字段可能引用 vpi_buf 内部(token 零拷贝),
# 提前 free 会导致 Name.id/Attribute.attr 等悬空 → 后续解析返回错误类型。
# 在 ParseVpiIntoModule 末尾统一释放。
# [DBG-T96] 临时诊断:定位 vpi AST 有效性(定位后移除)
k96: int = -1
if tree is not None:
k96 = tree.kind()
stdio.printf("[DBG-T96] vpi tree kind=%d children=", k96)
if tree is not None and tree.children is not None:
n96: t.CSizeT = tree.children.__len__()
stdio.printf("%d\n", n96)
if n96 > 0:
c96: ast.AST | t.CPtr = tree.children.get(0)
if c96 is not None:
stdio.printf("[DBG-T96] child0 kind=%d\n", c96.kind())
else:
stdio.printf("0\n")
if tree is None:
stdlib.free(vpi_buf)
return 0
# 提取源模块 SHA1(用于函数名混淆,在 AST 解析成功后提取避免提前返回时泄漏)
@@ -234,6 +251,8 @@ def ParseVpiIntoModule(pool: memhub.MemBuddy | t.CPtr,
# 释放 SHA1 缓冲区(_extract_sha1_from_path 用 stdlib.malloc 分配)
if src_sha1 is not None:
stdlib.free(src_sha1)
# vpi_buf 延迟到全部 tree 处理完成后释放(见解析处注释)
stdlib.free(vpi_buf)
return 1
@@ -420,6 +439,26 @@ def _inject_method_declare(pool: memhub.MemBuddy | t.CPtr,
if ret_ty is None:
ret_ty = i32_ty
# [DBG-T97] 临时诊断:定位 args.get_str 类型退化(定位后移除)
if string.strcmp(m_fd.name, "parse_args") == 0:
vis97: int = HandlesStruct.is_struct_visible("ParsedArgs")
gst97: t.CChar | t.CPtr = stdlib.malloc(128)
if gst97 is not None:
gty97: llvmlite.LLVMType | t.CPtr = HandlesStruct.get_struct_type("ParsedArgs")
if gty97 is not None:
llvmlite.TypePrint(gst97, 128, gty97, pool)
else:
viperlib.snprintf(gst97, 128, "NULL")
ot97: t.CChar | t.CPtr = stdlib.malloc(128)
if ot97 is not None:
if ret_ty is not None:
llvmlite.TypePrint(ot97, 128, ret_ty, pool)
else:
viperlib.snprintf(ot97, 128, "NULL")
stdio.printf("[DBG-T97] vis=%d gst=%s ret=%s\n", vis97, gst97, ot97)
stdlib.free(ot97)
stdlib.free(gst97)
# 创建 declare
func: llvmlite.Function | t.CPtr = llvmlite.create_declare(
pool, mod, mangled_name, ret_ty)