mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-02 21:49:02 +00:00
fixes #26015; Multiple definition error when using codegenDecl regression
This commit is contained in:
@@ -1854,10 +1854,20 @@ proc genVarPrototype(m: BModule, n: PNode) =
|
||||
typ = ptrType(typ)
|
||||
if lfDynamicLib in sym.loc.flags:
|
||||
typ = ptrType(typ)
|
||||
m.s[cfsVars].addVar(m, sym,
|
||||
name = sym.loc.snippet,
|
||||
typ = typ,
|
||||
visibility = vis)
|
||||
if sfCodegenDecl in sym.flags:
|
||||
# `codegenDecl` customizes the definition, but a reference from a
|
||||
# different module still needs a plain declaration. Applying the
|
||||
# custom format here can turn the declaration into a tentative
|
||||
# definition (and thus cause duplicate symbols at link time).
|
||||
m.s[cfsVars].addDeclWithVisibility(vis):
|
||||
m.s[cfsVars].addVar(kind = Local,
|
||||
name = sym.loc.snippet,
|
||||
typ = typ)
|
||||
else:
|
||||
m.s[cfsVars].addVar(m, sym,
|
||||
name = sym.loc.snippet,
|
||||
typ = typ,
|
||||
visibility = vis)
|
||||
if m.hcrOn:
|
||||
m.initProc.procSec(cpsLocals).add('\t')
|
||||
m.initProc.procSec(cpsLocals).addAssignment(sym.loc.snippet,
|
||||
|
||||
4
tests/ccgbugs/mcodegendeclglobal.nim
Normal file
4
tests/ccgbugs/mcodegendeclglobal.nim
Normal file
@@ -0,0 +1,4 @@
|
||||
var codegenDeclGlobal* {.codegenDecl: "$# /* custom declaration */ $#".} = 123
|
||||
|
||||
proc readCodegenDeclGlobal*(): int {.inline.} =
|
||||
codegenDeclGlobal
|
||||
12
tests/ccgbugs/tcodegendeclglobal.nim
Normal file
12
tests/ccgbugs/tcodegendeclglobal.nim
Normal file
@@ -0,0 +1,12 @@
|
||||
discard """
|
||||
output: '''
|
||||
123
|
||||
123
|
||||
'''
|
||||
targets: "c cpp"
|
||||
"""
|
||||
|
||||
import ./mcodegendeclglobal
|
||||
|
||||
echo codegenDeclGlobal
|
||||
echo readCodegenDeclGlobal()
|
||||
Reference in New Issue
Block a user