From 07ff906338785089ba503a36bfeb9d5535e924de Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Fri, 9 Oct 2026 11:12:31 +0800 Subject: [PATCH] =?UTF-8?q?chore(dbg):=20add=5Fvar=20=E9=80=90=E8=A1=8C?= =?UTF-8?q?=E6=8E=A2=E9=92=88=20a1..a8=EF=BC=88TEMP=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 崩点落在形参注册段,而这段里唯一的结构性改动是 VarEntry 加了字段。逐行埋点定位到具体哪一步(esz/cnt 也会打出来,可用于核对 sizeof 是否异常)。 --- App/lib/core/Gen/VarGenMixin.vp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/App/lib/core/Gen/VarGenMixin.vp b/App/lib/core/Gen/VarGenMixin.vp index 0402c6f..f092445 100644 --- a/App/lib/core/Gen/VarGenMixin.vp +++ b/App/lib/core/Gen/VarGenMixin.vp @@ -288,27 +288,30 @@ novirtual class VarGenMixin: """Add a variable to the variable table""" if name is None or alloca is None or vars_ptr is None: return 1 if var_count >= HT.MAX_VARS: return 1 + VLogger.info("dbg.a1.enter", "TR") entry_size: sizet = GenTypes.VarEntry.__sizeof__() entry_addr: uint64 = uint64(vars_ptr) + var_count * entry_size entry: GenTypes.VarEntry* = GenTypes.VarEntry*(entry_addr) - # Deep-copy the variable name into stdlib (survives pool reset): storing the AST Name.id pointer lets - # later allocations overwrite it, so find_var's strcmp silently misses and rebuilds a degenerate alloca. + VLogger.info(f"dbg.a2.entry esz={entry_size} cnt={var_count}", "TR") name_len: sizet = string.strlen(name) + VLogger.info(f"dbg.a3.namelen={name_len}", "TR") name_copy: bytes = stdlib.malloc(name_len + 1) if name_copy is None: return 1 string.strcpy(name_copy, name) + VLogger.info("dbg.a4.copied", "TR") entry.Name = name_copy + VLogger.info("dbg.a5.name", "TR") entry.Alloca = alloca entry.Used = 1 - # Explicitly zero the const flag (do not rely on the entry's zero initialization): set_var_const - # sets it to 1 only for real const objects, so zeroing avoids false positives. entry.IsConst = 0 - # 生命期标签显式初始化:未登记 = LIFE_UNKNOWN(保守放行)。 + VLogger.info("dbg.a6.const", "TR") entry.Life = GenTypes.LIFE_UNKNOWN + VLogger.info("dbg.a7.life", "TR") # P2 willFree 的 entry.Freed **不在这里写**:init_vars 已对整块 memset 清零(见 init_vars), # 逐个字段写末端偏移在"结构体刚加字段"时容易踩到;统一依赖整块清零。 # [S3 dual write] Value-type Spec (alloca.Ty is Ptr(value type), so take its pointee) entry.Spec = self._spec_of_var_alloca(alloca) + VLogger.info("dbg.a8.spec", "TR") return 0 def clear_var_freed(self, symtab: GenTypes.SymbolTable*, name: str) -> int: