From bca23ffa06f60c6dd695e66f4dd2f41e2f57cb4e Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Mon, 12 Oct 2026 13:18:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(mlirlite):=20MLIR=20=E9=97=B4=E6=8E=A5?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E7=82=B9=E4=B9=9F=E8=BF=87=20alias=20?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=EF=BC=8Ccallee=20=E4=B8=8D=E5=86=8D=E6=82=AC?= =?UTF-8?q?=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no-op bitcast(含函数指针 bitcast)被 alias 机制省略后,参数用法会改写成别名目标, 但 llvm.call 的 callee 位置原样写出 → 悬空 %N,mlir-opt 报 use of undeclared SSA value / definition of SSA value has type 'i8' but previously used here with type '!llvm.ptr'。 - _MlirCall:callee 走 _MlirResolve,并用解析后的名字判断直接/间接调用 (别名解析可能把 callee 指到 @符号,那就成了直接调用,不能再写 !llvm.ptr) --- mlirlite/__function.vp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mlirlite/__function.vp b/mlirlite/__function.vp index 654d088..4ba6cd2 100644 --- a/mlirlite/__function.vp +++ b/mlirlite/__function.vp @@ -2611,7 +2611,12 @@ def _MlirCall(p: str, resname: str, out: str, outsz: sizet): else: _MlirEmitRes(out, outsz, resname) _append_cstr(out, outsz, "llvm.call ") - _append_cstr(out, outsz, calb) + # callee 也必须过 alias 解析:no-op bitcast(含函数指针 bitcast)被省略后,间接调用点 + # 必须改写成别名目标,否则 %N 悬空 → mlir-opt 报 use of undeclared SSA value + # / definition has type 'i8' but previously used here with type '!llvm.ptr'。 + calb_r: str = _MlirResolve(calb) + if calb_r is None: calb_r = calb + _append_cstr(out, outsz, calb_r) _append_cstr(out, outsz, "(") _append_cstr(out, outsz, args) _append_cstr(out, outsz, ")") @@ -2629,8 +2634,9 @@ def _MlirCall(p: str, resname: str, out: str, outsz: sizet): # (omitting vararg's `)` made mlir-opt 22.1.8 report "expected ')'" verbatim) _append_cstr(out, outsz, ")>)") _append_cstr(out, outsz, " : ") - if calb[0] != '@': + if calb_r[0] != '@': # Indirect call: the callee is a !llvm.ptr operand + # (用解析后的名字判断:别名解析可能把 callee 指到一个 @符号,那就成了直接调用) _append_cstr(out, outsz, "!llvm.ptr, ") _append_cstr(out, outsz, "(") _append_cstr(out, outsz, argts)