From 2b4679073e947d5e20f18bf23c5cb4be62a664d3 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sat, 17 Oct 2026 23:27:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E5=9F=BA=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Projectrans/Phase2Translator.py | 23 ++++++++++++++++++++++- lib/core/Handles/HandlesExprAsm.py | 4 ---- lib/core/LLVMCG/FuncGen.py | 9 +++++---- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/Projectrans/Phase2Translator.py b/lib/Projectrans/Phase2Translator.py index 702e6f1..9f65031 100644 --- a/lib/Projectrans/Phase2Translator.py +++ b/lib/Projectrans/Phase2Translator.py @@ -298,6 +298,26 @@ _RE_DEFINE_HEAD: re.Pattern[str] = re.compile( _RE_DEFINE_LINE: re.Pattern[str] = re.compile(r'^define ', re.MULTILINE) +def _SourceHasRealDef(src_path: str) -> bool: + """模块是否含有真正的 `def`(而不是只有 `extern def`)。 + + extern-only 模块(如 includes/win32/win32console.vp)里的 define 是编译器合成的转发体, + 没有源级函数体,本来就不会有 DWARF 行表;对它们发 "--traceback 未携带 DWARF" 属于误报。 + 读不到源码时返回 True,保持旧行为(宁可多提示,不漏提示)。 + """ + try: + content, _ = parse_python_file(src_path) + except Exception: + return True + if not content: + return True + for raw in content.splitlines(): + s: str = raw.lstrip() + if s.startswith('def ') or s.startswith('async def '): + return True + return False + + def _ParseDwarfLineRows(dump_text: str) -> list[tuple[int, str, int]]: """从 llvm-dwarfdump 输出解析出 [(地址, 文件绝对路径, 行号)]。 @@ -3869,7 +3889,8 @@ class Phase2Translator: # (由 extern/sugar 派生、无 .vp 函数体),本就不会有源级 DI —— 按 fail-fast # 报错会把这类模块全部误杀;而"行号缺失"只降低可读性,不是编译正确性问题。 if self.traceback_enabled and _RE_DEFINE_LINE.search(ll_content) \ - and '!llvm.dbg.cu' not in ll_content: + and '!llvm.dbg.cu' not in ll_content \ + and _SourceHasRealDef(src_path): _vlog().warning( f"--traceback: include 模块 {module_name}.py 发射了 define 但 IR 未携带 " f"DWARF (!llvm.dbg.cu)——该模块内联帧在 Ctrl+C 栈里将只显示地址: {ll_path}") diff --git a/lib/core/Handles/HandlesExprAsm.py b/lib/core/Handles/HandlesExprAsm.py index 61622cd..53f222a 100644 --- a/lib/core/Handles/HandlesExprAsm.py +++ b/lib/core/Handles/HandlesExprAsm.py @@ -63,10 +63,6 @@ class ExprAsmHandle(BaseHandle): def _HandleAsmLlvm(self, Node: ast.Call) -> ir.Value | None: Gen: LlvmCodeGenerator = self.Trans.LlvmGen - # DEBUG: 验证 _HandleAsmLlvm 是否被调用 - import sys as _dbg_sys - print(f"[DEBUG_ASM] _HandleAsmLlvm called, Node.args={len(Node.args)}, keywords={[kw.arg for kw in Node.keywords]}", file=_dbg_sys.stderr) - op_arg: Any = None input_arg: Any = None output_arg: Any = None diff --git a/lib/core/LLVMCG/FuncGen.py b/lib/core/LLVMCG/FuncGen.py index 6bc8e43..4b94098 100644 --- a/lib/core/LLVMCG/FuncGen.py +++ b/lib/core/LLVMCG/FuncGen.py @@ -209,10 +209,11 @@ class FuncGenMixin: f"(callee={func.name} 实参{len(args)}个/形参{len(func.args)}个;" f"逐项: {_diag})") elif isinstance(arg.type, ir.PointerType) and isinstance(param.type, ir.PointerType): - if isinstance(arg.type.pointee, ir.PointerType) and isinstance(param.type.pointee, ir.IntType): - Loaded: ir.Value = self._load(arg, name=f"Load_arg_{i}") - adjusted.append(Loaded) - elif isinstance(arg.type.pointee, ir.ArrayType) and isinstance(param.type.pointee, (ir.IntType, ir.FloatType, ir.DoubleType)): + # 不在此处特判 T** -> i8*/T*:ViperC 的 _ptr_cast_reason 对「级数不同」 + # 一律拒绝(单级指针才可与 void* 双向隐式互转),TPC 此前在这里悄悄 + # load 一层(str* 当 str 用、&p 传 i8* 形参),静默改变语义。 + # 交给下方通用的 _ClassifyPtrImplicitConvert 判据,结果同样是 FailFastError。 + if isinstance(arg.type.pointee, ir.ArrayType) and isinstance(param.type.pointee, (ir.IntType, ir.FloatType, ir.DoubleType)): zero: ir.Constant = ir.Constant(ir.IntType(32), 0) elem_ptr: ir.Value = self.builder.gep(arg, [zero, zero], name=f"array_decay_arg_{i}") if elem_ptr.type != param.type: