fix(llvmlite): create_block 块名与参数名冲突去重

LLVM 中块标签 entry 即值 percent-entry,与参数 percent-entry 重名导致 llc
unable to create block named entry(CallGenCall._field_byte_offset 的 entry
参数根因)。create_block 创建块时扫描函数参数值名(剥离百分号前缀),
冲突则追加 .1/.2 后缀,覆盖全部 7 处入口块创建点。
This commit is contained in:
TermiNexus committed 2026-08-19 05:54:11 +08:00
1 parent 915054495f
commit 73e5eea3f0
1 file changed
+30 -1
+30 -1
View File
@@ -93,7 +93,36 @@ def _str_dup(pool: memhub.MemBuddy | t.CPtr, src: t.CChar | t.CPtr) -> t.CChar |
def create_block(pool: memhub.MemBuddy | t.CPtr, func: Function | t.CPtr,
name: t.CChar | t.CPtr) -> BasicBlock | t.CPtr:
"""创建基本块并添加到函数"""
name_dup: t.CChar | t.CPtr = _str_dup(pool, name)
# 块名与函数参数值名冲突防护:LLVM 中块标签 "entry:" 即值 %entry,
# 与参数 %entry 重名 → llc "unable to create block named 'entry'"
# (CallGenCall._field_byte_offset(self, pool, entry, ...) 根因)。
# 冲突时追加 .1/.2/... 后缀去重(Param.Name 可能带 % 前缀,剥离比较)。
use_name: t.CChar | t.CPtr = name
if func is not None and func.Params is not None and name is not None \
and name[0] != '\0':
cb_len: t.CSizeT = string.strlen(name) + 16
cb_buf: str = pool.alloc(cb_len)
if cb_buf is not None:
cb_k: int = 1
cb_collide: int = 1
while cb_collide != 0:
cb_collide = 0
cb_p: Param | t.CPtr = function_get_param_head(func)
while cb_p is not None:
cb_pnm: str = param_get_name(cb_p)
if cb_pnm is not None:
cb_pv: str = cb_pnm
if cb_pv[0] == '%':
cb_pv = cb_pv + 1
if string.strcmp(cb_pv, use_name) == 0:
cb_collide = 1
break
cb_p = param_get_next(cb_p)
if cb_collide != 0:
viperlib.snprintf(cb_buf, cb_len, "%s.%d", name, cb_k)
use_name = cb_buf
cb_k += 1
name_dup: t.CChar | t.CPtr = _str_dup(pool, use_name)
blk: BasicBlock | t.CPtr = new_basic_block(pool, name_dup)
if blk is not None:
function_add_block(func, blk)