fix(TransPyV): 修正形参/字段链节点的注解为 llvmlite.ParamNode*

c 类(源码违规):这些变量由 new_param_node 构造、或取自 get_struct_fields /

param_list_append / function_get_param_head,实际是 llvmlite.ParamNode 链节点,

注解却写成 llvmlite.Function*。旧的无条件指针 bitcast 掩盖了该错误,严格指针规则下暴露。

涉及:VarGenMixin / CallGenVt / VpiReader / ClassGenEnum / ClassGenVTable /

ExprGenName / FuncGenMixin / FuncGenDef / TypeGenResolve / TypeSpec /

StmtGenCifMixin / AssignGenMixin(纯注解替换,零语义变化)。15 行。
This commit is contained in:
TermiNexus committed 2026-09-28 17:54:13 +08:00
1 parent 70448f4590
commit d579d70113
12 files changed
+41 -35

No files matched your search

+5 -3
View File
@@ -1419,8 +1419,10 @@ def _resolve_vpi_ret_annot_str(pool: memhub.MemBuddy*,
inner_len_t += 1 inner_len_t += 1
if ret_annot[6 + inner_len_t] != ']' or inner_len_t == 0: if ret_annot[6 + inner_len_t] != ']' or inner_len_t == 0:
return None return None
tup_head_t: llvmlite.Function* = None # tuple 返回类型的字段链表是 llvmlite.ParamNode(new_param_node / paramnode_set_next /
tup_tail_t: llvmlite.Function* = None # Struct 形参均为 rawptr[ParamNode])——原先误注解为 Function*。
tup_head_t: llvmlite.ParamNode* = None
tup_tail_t: llvmlite.ParamNode* = None
tup_count_t: int = 0 tup_count_t: int = 0
p_t: sizet = 0 p_t: sizet = 0
while p_t < inner_len_t: while p_t < inner_len_t:
@@ -1444,7 +1446,7 @@ def _resolve_vpi_ret_annot_str(pool: memhub.MemBuddy*,
stdlib.free(seg_buf_t) stdlib.free(seg_buf_t)
if seg_ty_t is None: if seg_ty_t is None:
return None return None
tup_node_t: llvmlite.Function* = llvmlite.new_param_node(pool, seg_ty_t) tup_node_t: llvmlite.ParamNode* = llvmlite.new_param_node(pool, seg_ty_t)
if tup_node_t is None: if tup_node_t is None:
return None return None
if tup_head_t is None: if tup_head_t is None:
+2 -2
View File
@@ -2829,8 +2829,8 @@ novirtual class AssignGenMixin:
tmp_s: llvmlite.Value* = llvmlite.build_alloca(builder, rhs_val.Ty) tmp_s: llvmlite.Value* = llvmlite.build_alloca(builder, rhs_val.Ty)
if tmp_s is not None: if tmp_s is not None:
llvmlite.build_store(builder, rhs_val, tmp_s) llvmlite.build_store(builder, rhs_val, tmp_s)
fchain: llvmlite.Function* = llvmlite.get_struct_fields(rhs_val.Ty) fchain: llvmlite.ParamNode* = llvmlite.get_struct_fields(rhs_val.Ty)
fcur: llvmlite.Function* = fchain fcur: llvmlite.ParamNode* = fchain
fti: sizet fti: sizet
for fti in range(tgt_n): for fti in range(tgt_n):
tgt_elt: ast.AST* = tgt_elts.get(fti) tgt_elt: ast.AST* = tgt_elts.get(fti)
+5 -3
View File
@@ -41,10 +41,12 @@ novirtual class CallGenVt(CallGenBase.CallGenBase):
method_count: int = self.Gen.StructGen.get_vtable_method_count(class_name) method_count: int = self.Gen.StructGen.get_vtable_method_count(class_name)
if method_count <= 0: return 0 if method_count <= 0: return 0
# 构造 vtable 类型 { i8*, i8*, ... } # 构造 vtable 类型 { i8*, i8*, ... }
vt_first: llvmlite.Function* = None # vtable 类型的字段链表是 llvmlite.ParamNode(new_param_node / paramnode_set_next /
vt_prev: llvmlite.Function* = None # Struct 形参均为 rawptr[ParamNode])——原先误注解为 Function*。
vt_first: llvmlite.ParamNode* = None
vt_prev: llvmlite.ParamNode* = None
for vi in range(method_count): for vi in range(method_count):
pn: llvmlite.Function* = llvmlite.new_param_node(pool, i8_ptr_ty) pn: llvmlite.ParamNode* = llvmlite.new_param_node(pool, i8_ptr_ty)
if pn is None: continue if pn is None: continue
if vt_first is None: if vt_first is None:
vt_first = pn vt_first = pn
+3 -3
View File
@@ -956,15 +956,15 @@ novirtual class ClassGenEnum(ClassGenBase.ClassGenBase):
i32_ty: llvmlite.LLVMType* = llvmlite.Int32(pool) i32_ty: llvmlite.LLVMType* = llvmlite.Int32(pool)
i64_ty: llvmlite.LLVMType* = llvmlite.Int64(pool) i64_ty: llvmlite.LLVMType* = llvmlite.Int64(pool)
first_node: llvmlite.Function* = None first_node: llvmlite.ParamNode* = None
tail_node: llvmlite.Function* = None tail_node: llvmlite.ParamNode* = None
for pos in range(total_positions): for pos in range(total_positions):
psize: int = position_max_sizes[pos] psize: int = position_max_sizes[pos]
field_ty: llvmlite.LLVMType* = i32_ty field_ty: llvmlite.LLVMType* = i32_ty
if psize > 4: if psize > 4:
field_ty = i64_ty field_ty = i64_ty
pnode: llvmlite.Function* = llvmlite.new_param_node(pool, field_ty) pnode: llvmlite.ParamNode* = llvmlite.new_param_node(pool, field_ty)
if pnode is None: if pnode is None:
continue continue
tail_node = llvmlite.param_list_append(first_node, tail_node, pnode) tail_node = llvmlite.param_list_append(first_node, tail_node, pnode)
+6 -6
View File
@@ -305,10 +305,10 @@ novirtual class ClassGenVTable(ClassGenBase.ClassGenBase):
i8_ty: llvmlite.LLVMType* = llvmlite.Int8(pool) i8_ty: llvmlite.LLVMType* = llvmlite.Int8(pool)
i8_ptr_ty: llvmlite.LLVMType* = llvmlite.Ptr(pool, i8_ty) i8_ptr_ty: llvmlite.LLVMType* = llvmlite.Ptr(pool, i8_ty)
first_node: llvmlite.Function* = None first_node: llvmlite.ParamNode* = None
tail_node: llvmlite.Function* = None tail_node: llvmlite.ParamNode* = None
for i in range(method_count): for i in range(method_count):
pnode: llvmlite.Function* = llvmlite.new_param_node(pool, i8_ptr_ty) pnode: llvmlite.ParamNode* = llvmlite.new_param_node(pool, i8_ptr_ty)
if pnode is None: if pnode is None:
continue continue
tail_node = llvmlite.param_list_append(first_node, tail_node, pnode) tail_node = llvmlite.param_list_append(first_node, tail_node, pnode)
@@ -1120,10 +1120,10 @@ novirtual class ClassGenVTable(ClassGenBase.ClassGenBase):
vt_i8_ty: llvmlite.LLVMType* = llvmlite.Int8(pool) vt_i8_ty: llvmlite.LLVMType* = llvmlite.Int8(pool)
vt_i8_ptr_ty: llvmlite.LLVMType* = llvmlite.Ptr(pool, vt_i8_ty) vt_i8_ptr_ty: llvmlite.LLVMType* = llvmlite.Ptr(pool, vt_i8_ty)
vt_first_node: llvmlite.Function* = None vt_first_node: llvmlite.ParamNode* = None
vt_prev_node: llvmlite.Function* = None vt_prev_node: llvmlite.ParamNode* = None
for vti in range(vt_method_count): for vti in range(vt_method_count):
vtnode: llvmlite.Function* = llvmlite.new_param_node(pool, vt_i8_ptr_ty) vtnode: llvmlite.ParamNode* = llvmlite.new_param_node(pool, vt_i8_ptr_ty)
if vtnode is None: if vtnode is None:
continue continue
if vt_first_node is None: if vt_first_node is None:
+3 -3
View File
@@ -256,12 +256,12 @@ novirtual class ExprGenName(ExprGenBase.ExprGenBase):
# fail-fast:函数返回类型缺失,无法构造函数指针(暴露上游根因) # fail-fast:函数返回类型缺失,无法构造函数指针(暴露上游根因)
self.Gen.TypeGenErr.fatal_error(node, f"函数 '{nm_id}' 返回类型缺失,无法构造函数指针", "TypeError") self.Gen.TypeGenErr.fatal_error(node, f"函数 '{nm_id}' 返回类型缺失,无法构造函数指针", "TypeError")
fn_pp: llvmlite.Param* = llvmlite.function_get_param_head(fn_ref) fn_pp: llvmlite.Param* = llvmlite.function_get_param_head(fn_ref)
fn_first_node: llvmlite.Function* = None fn_first_node: llvmlite.ParamNode* = None
fn_prev_node: llvmlite.Function* = None fn_prev_node: llvmlite.ParamNode* = None
fn_pcount: int = 0 fn_pcount: int = 0
while fn_pp is not None: while fn_pp is not None:
fn_pty: llvmlite.LLVMType* = llvmlite.param_get_ty(fn_pp) fn_pty: llvmlite.LLVMType* = llvmlite.param_get_ty(fn_pp)
fn_pn: llvmlite.Function* = llvmlite.new_param_node(pool, fn_pty) fn_pn: llvmlite.ParamNode* = llvmlite.new_param_node(pool, fn_pty)
if fn_pn is not None: if fn_pn is not None:
if fn_first_node is None: if fn_first_node is None:
fn_first_node = fn_pn fn_first_node = fn_pn
+2 -2
View File
@@ -1232,10 +1232,10 @@ novirtual class FuncGenDef(CallGenBase.CallGenBase):
args_alloca: llvmlite.Value* = None args_alloca: llvmlite.Value* = None
args_ptr: llvmlite.Value* = None args_ptr: llvmlite.Value* = None
if n_params > 0: if n_params > 0:
fields_head: llvmlite.Function* = None fields_head: llvmlite.ParamNode* = None
fk: int = 0 fk: int = 0
for fk in range(n_params - 1, -1, -1): for fk in range(n_params - 1, -1, -1):
pn_n: llvmlite.Function* = llvmlite.new_param_node(pool, (llvmlite.LLVMType*)(param_tys[fk])) pn_n: llvmlite.ParamNode* = llvmlite.new_param_node(pool, (llvmlite.LLVMType*)(param_tys[fk]))
if pn_n is not None: if pn_n is not None:
pn_n.Next = fields_head pn_n.Next = fields_head
fields_head = pn_n fields_head = pn_n
+2 -2
View File
@@ -378,7 +378,7 @@ novirtual class FuncGenMixin(CallGenBase.CallGenBase):
# 13c. 存储 fn_ptr 到 offset 0 # 13c. 存储 fn_ptr 到 offset 0
# 创建函数指针类型 i32(i8*)* # 创建函数指针类型 i32(i8*)*
fn_param_node: llvmlite.Function* = llvmlite.new_param_node(pool, i8_ptr_ty) fn_param_node: llvmlite.ParamNode* = llvmlite.new_param_node(pool, i8_ptr_ty)
fn_func_ty: llvmlite.LLVMType* = llvmlite.Func(pool, i32_ty, fn_param_node, 1) fn_func_ty: llvmlite.LLVMType* = llvmlite.Func(pool, i32_ty, fn_param_node, 1)
fn_func_ptr_ty: llvmlite.LLVMType* = llvmlite.Ptr(pool, fn_func_ty) fn_func_ptr_ty: llvmlite.LLVMType* = llvmlite.Ptr(pool, fn_func_ty)
@@ -1276,7 +1276,7 @@ novirtual class FuncGenMixin(CallGenBase.CallGenBase):
return None return None
# 15. [0] = fn_ptr(函数引用 bitcast 到 i8*) # 15. [0] = fn_ptr(函数引用 bitcast 到 i8*)
fn_param_node: llvmlite.Function* = llvmlite.new_param_node(pool, i8_ptr_ty) fn_param_node: llvmlite.ParamNode* = llvmlite.new_param_node(pool, i8_ptr_ty)
fn_func_ty: llvmlite.LLVMType* = llvmlite.Func(pool, i32_ty, fn_param_node, 1) fn_func_ty: llvmlite.LLVMType* = llvmlite.Func(pool, i32_ty, fn_param_node, 1)
fn_func_ptr_ty: llvmlite.LLVMType* = llvmlite.Ptr(pool, fn_func_ty) fn_func_ptr_ty: llvmlite.LLVMType* = llvmlite.Ptr(pool, fn_func_ty)
fn_ptr_name: str = pool.alloc(64) fn_ptr_name: str = pool.alloc(64)
+3 -3
View File
@@ -478,8 +478,8 @@ novirtual class StmtGenCifMixin:
rt_vals: sizet* = pool.alloc(8 * 16) rt_vals: sizet* = pool.alloc(8 * 16)
if rt_vals is not None: if rt_vals is not None:
rt_val_ok: int = 1 rt_val_ok: int = 1
rt_head: llvmlite.Function* = None rt_head: llvmlite.ParamNode* = None
rt_tail: llvmlite.Function* = None rt_tail: llvmlite.ParamNode* = None
rvi: sizet rvi: sizet
for rvi in range(rt_n): for rvi in range(rt_n):
ev_i: llvmlite.Value* = self.Gen.ExprGen.translate_value(builder, pool, mod, rtp_elts.get(rvi), ev_i: llvmlite.Value* = self.Gen.ExprGen.translate_value(builder, pool, mod, rtp_elts.get(rvi),
@@ -496,7 +496,7 @@ novirtual class StmtGenCifMixin:
if rv_i is None or rv_i.Ty is None: if rv_i is None or rv_i.Ty is None:
rt_val_ok = 0 rt_val_ok = 0
break break
rn: llvmlite.Function* = llvmlite.new_param_node(pool, rv_i.Ty) rn: llvmlite.ParamNode* = llvmlite.new_param_node(pool, rv_i.Ty)
if rn is None: if rn is None:
rt_val_ok = 0 rt_val_ok = 0
break break
+3 -3
View File
@@ -1935,8 +1935,8 @@ novirtual class TypeGenResolve(TypeGenBase.TypeGenBase):
tp_count = 1 tp_count = 1
if tp_count == 0 or tp_elts is None: if tp_count == 0 or tp_elts is None:
return None return None
tup_head: llvmlite.Function* = None tup_head: llvmlite.ParamNode* = None
tup_tail: llvmlite.Function* = None tup_tail: llvmlite.ParamNode* = None
tui: sizet tui: sizet
for tui in range(tp_count): for tui in range(tp_count):
tup_elt: ast.AST* = tp_elts.get(tui) tup_elt: ast.AST* = tp_elts.get(tui)
@@ -1945,7 +1945,7 @@ novirtual class TypeGenResolve(TypeGenBase.TypeGenBase):
tup_ety: llvmlite.LLVMType* = self.resolve_annotation_type(pool, tup_elt, imported_modules, from_imports, trans, depth + 1) tup_ety: llvmlite.LLVMType* = self.resolve_annotation_type(pool, tup_elt, imported_modules, from_imports, trans, depth + 1)
if tup_ety is None: if tup_ety is None:
return None return None
tup_node: llvmlite.Function* = llvmlite.new_param_node(pool, tup_ety) tup_node: llvmlite.ParamNode* = llvmlite.new_param_node(pool, tup_ety)
if tup_node is None: if tup_node is None:
return None return None
if tup_head is None: if tup_head is None:
+2 -2
View File
@@ -1326,7 +1326,7 @@ def _spec_from_array(arena: TypeSpecArena | t.CPtr,
def _spec_from_func(arena: TypeSpecArena | t.CPtr, def _spec_from_func(arena: TypeSpecArena | t.CPtr,
ret: llvmlite.LLVMType*, ret: llvmlite.LLVMType*,
params: llvmlite.Function*, params: llvmlite.ParamNode*,
pcount: int) -> TypeSpec*: pcount: int) -> TypeSpec*:
"""函数类型 → TypeSpec(形参沿 ParamNode 链表遍历;IsVarArg 恒 0,见上)""" """函数类型 → TypeSpec(形参沿 ParamNode 链表遍历;IsVarArg 恒 0,见上)"""
ret_s: TypeSpec* = SpecFromLLVMType(arena, ret) ret_s: TypeSpec* = SpecFromLLVMType(arena, ret)
@@ -1338,7 +1338,7 @@ def _spec_from_func(arena: TypeSpecArena | t.CPtr,
params_arr: sizet* = CompilerFactory.factory.PermPool.alloc(8 * pcount) params_arr: sizet* = CompilerFactory.factory.PermPool.alloc(8 * pcount)
if params_arr is None: if params_arr is None:
return None return None
node: llvmlite.Function* = params node: llvmlite.ParamNode* = params
i: int = 0 i: int = 0
while node is not None and i < pcount: while node is not None and i < pcount:
pty: llvmlite.LLVMType* = llvmlite.paramnode_get_ty(node) pty: llvmlite.LLVMType* = llvmlite.paramnode_get_ty(node)
+5 -3
View File
@@ -789,15 +789,17 @@ novirtual class VarGenMixin:
if ret_ty is None: if ret_ty is None:
self.Gen.TypeGenErr.fatal_error(node, f"REPL: 会话函数 '{func_name}' 的返回类型 token 不受支持(M3 支持 void/iN/float/double/i8*)", "TypeError") self.Gen.TypeGenErr.fatal_error(node, f"REPL: 会话函数 '{func_name}' 的返回类型 token 不受支持(M3 支持 void/iN/float/double/i8*)", "TypeError")
return None return None
fp_first: llvmlite.Function* = None # 形参链表节点是 llvmlite.ParamNode(new_param_node 返回 rawptr[ParamNode]、
fp_prev: llvmlite.Function* = None # paramnode_set_next / Func 形参同为 rawptr[ParamNode])——原先误注解为 Function*。
fp_first: llvmlite.ParamNode* = None
fp_prev: llvmlite.ParamNode* = None
pi: int pi: int
for pi in range(arg_count): for pi in range(arg_count):
cur_ty: llvmlite.LLVMType* = i8_ptr_ty cur_ty: llvmlite.LLVMType* = i8_ptr_ty
if pi > 0: if pi > 0:
pty_slot3: str | t.CPtr = (t.CPtr)(uint64(ptypes) + (pi - 1) * 8) pty_slot3: str | t.CPtr = (t.CPtr)(uint64(ptypes) + (pi - 1) * 8)
cur_ty = (llvmlite.LLVMType*)(pty_slot3[0]) cur_ty = (llvmlite.LLVMType*)(pty_slot3[0])
pn: llvmlite.Function* = llvmlite.new_param_node(pool, cur_ty) pn: llvmlite.ParamNode* = llvmlite.new_param_node(pool, cur_ty)
if pn is not None: if pn is not None:
if fp_first is None: if fp_first is None:
fp_first = pn fp_first = pn