fix(gen): translate_subscript 支持 Slice 切片表达式(a[start:end])——此前返回 None 导致函数实参被丢弃(create_process(path[n:],entry) 丢 name、entry 错位 → p.entry 垃圾 → 用户进程 iretq 垃圾地址 PF)

This commit is contained in:
TermiNexus committed 2026-08-27 00:45:22 +08:00
1 parent ee6d78bbb1
commit f185241a71
1 file changed
+28
+28
View File
@@ -634,6 +634,34 @@ class ExprGenName(ExprGenBase.ExprGenBase):
if sub is None:
return None
# 切片形式 a[start:end](如 path[n:]):返回 i8* 基指针 + start 偏移。
# 此前 Slice AST 被当作单索引 translate_value → 无 Slice 分支返回 None →
# 作为函数实参时整个参数被丢弃(spawn_elf 的
# create_process(path[n:], entry) 丢 name → entry 错位成第一参数 →
# p.entry 垃圾 → 用户进程 iretq 到垃圾地址 → PF)。
if sub.slice is not None and sub.slice.kind() == ast.ASTKind.Slice:
slc: ast.Slice | t.CPtr = (ast.Slice | t.CPtr)(sub.slice)
base_v: llvmlite.Value | t.CPtr = self.Gen.ExprGen.translate_value(
builder, pool, mod, sub.value, None, 0, trans)
if base_v is None:
return None
if slc.lower is None:
return base_v
start_v: llvmlite.Value | t.CPtr = self.Gen.ExprGen.translate_value(
builder, pool, mod, slc.lower, None, 0, trans)
if start_v is None:
return None
i64_sc: llvmlite.LLVMType | t.CPtr = llvmlite.Int64(pool)
start_w: llvmlite.Value | t.CPtr = start_v
if start_v.Ty is not None:
bt_sc: int = self.Gen.ExprGenBase.get_llvm_type_bits(start_v.Ty)
if bt_sc != 0 and bt_sc < 64:
start_w = llvmlite.build_sext(builder, start_v, i64_sc)
if start_w is None:
return None
i8_sc: llvmlite.LLVMType | t.CPtr = llvmlite.Int8(pool)
return llvmlite.build_gep(builder, i8_sc, base_v, start_w)
# 翻译索引
idx_val: llvmlite.Value | t.CPtr = self.Gen.ExprGen.translate_value(
builder, pool, mod, sub.slice, None, 0, trans)