From 8da4550d79e9c601ed4c0bac5d5f65c24eb4f3a0 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sat, 3 Oct 2026 11:08:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(vpi):=20=E5=85=A8=E5=B1=80=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E6=B3=A8=E5=85=A5=E8=A1=A5=E8=87=AA=E6=B3=A8=E5=85=A5?= =?UTF-8?q?=E5=AE=88=E5=8D=AB=EF=BC=8C=E6=B6=88=E9=99=A4=E5=90=8C=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=20external=20global=20=E4=B8=8E=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E9=87=8D=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 循环 import(os/__init__ 导入 os._win32/os._posix,而二者又导入包 os)使 imported_modules 含本模块包名 → LoadDepVpiIntoModule 命中本模块自身 sha1 → _inject_global_variable_declare 为本模块自己的模块级全局发射 @. = external global,随后定义端 handle_module_level_var 再发 = global … → llc redefinition of global(SysLibTest 根因)。补上 _inject_function_declare / _inject_method_declare 已有的同款自注入守卫(_declare_only==0 且 src_sha1==trans.ModuleSha1 时早退)。 --- App/lib/Stub/StubGen/VpiReader.vp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/App/lib/Stub/StubGen/VpiReader.vp b/App/lib/Stub/StubGen/VpiReader.vp index 2316e42..31489ef 100644 --- a/App/lib/Stub/StubGen/VpiReader.vp +++ b/App/lib/Stub/StubGen/VpiReader.vp @@ -3060,6 +3060,17 @@ def _inject_global_variable_declare(pool: memhub.MemBuddy*, gname_v: str = nm_v.id if gname_v[0] == '\0': return + # 自注入守卫(仅全量翻译阶段 _declare_only == 0):本模块自己定义的模块级全局, + # 其定义由 TranslatorGenMixin.handle_module_level_var 发射(@<本模块sha1>. = global …)。 + # 把本模块自己的 vpi 经依赖链反向注入(循环 import:os/__init__ 导入 os._win32/os._posix, + # 而二者又导入包 os,使 imported_modules 含 "os" → 命中本模块自身 sha1)会在同一模块 + # 先制造同名的 external global 声明,随后定义端再发射 global 定义 → llc: + # redefinition of global '@.'。与 _inject_function_declare / + # _inject_method_declare 的自注入守卫同因同构(那两处已修,全局此处此前遗漏)。 + if trans is not None and trans._declare_only == 0 and trans.ModuleSha1 is not None \ + and src_sha1 is not None: + if string.strcmp(src_sha1, trans.ModuleSha1) == 0: + return # mangled 名:带源模块 SHA1 前缀(对齐定义端 5f7a873 的 @. # 与查找端 from-import 精确查找三方一致;裸短名会退化为未定义)。 # 注:a42923c 曾把此处写成未定义变量 gv_name_m(笔误,mangle 未实现),