feat(codegen): TPC 模块级 t.State 全局只声明不定义(external linkage)
extern 名字: 类型的展开产物(名字: 类型 | t.State):本模块生成 @名字 = external global T,不写定义(否则 duplicate symbol) 位置早于「已存在则升级 common 定义」分支,避免 extern 被反向升级成定义;与 import 侧 _EmitExternalGlobalDeclLlvm 同名分支同口径 export(t.CExport)侧无需改动:TPC 模块级全局本就用裸名(_mangle_name 不作用于全局变量),裸名导出语义天然满足
This commit is contained in:
1 parent
6fce79d531
commit
f9957787a0
1 file changed
+14
@@ -1707,6 +1707,20 @@ class AssignHandle(BaseHandle):
|
||||
VarType: ir.Type = Gen._ctype_to_llvm(TypeInfo)
|
||||
if isinstance(VarType, ir.VoidType):
|
||||
VarType = ir.IntType(32)
|
||||
# t.State 标记的模块级全局(`extern 名字: 类型` 的展开产物,见
|
||||
# SymbolUtils._ExpandExportExternVar):**只声明不定义**(external linkage),
|
||||
# 符号定义在外部(C 库 / 汇编 / 其它翻译单元),本模块不得再生成定义
|
||||
# (否则 ld.lld duplicate symbol)。与 import 侧
|
||||
# _EmitExternalGlobalDeclLlvm 的同名分支(HandlesImports.py:1211-1217)同口径。
|
||||
# 位置必须早于下方「VarName 已在 module.globals → 升级 common 定义」分支:
|
||||
# 否则 extern 会被反向升级成定义,抵消 external 声明语义。
|
||||
if TypeInfo is not None and TypeInfo.IsState:
|
||||
if VarName not in Gen.module.globals:
|
||||
_ext_gv: ir.GlobalVariable = ir.GlobalVariable(Gen.module, VarType, name=VarName)
|
||||
_ext_gv.linkage = 'external'
|
||||
Gen._export_funcs.add(VarName)
|
||||
Gen.variables[VarName] = Gen.module.globals[VarName]
|
||||
return
|
||||
# const / volatile 模块级全局登记(统一登记入口,持久层 global_*)。
|
||||
# 局限(明确记录,见 Debugger/type-descriptors.md 已知差异):本分支只覆盖
|
||||
# 标量/指针型全局;数组(t.CArray[...])与结构体型全局在更早的分支
|
||||
|
||||
Reference in new issue
Block a user