This commit is contained in:
flywind 2021-03-30 16:27:24 +08:00 • committed by GitHub
commit 3715fc41d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -259,6 +259,10 @@ proc withTmpIfNeeded(p: BProc, a: TLoc, needsTmp: bool): TLoc =
else: else:
result = a result = a
proc literalsNeedsTmp(p: BProc, a: TLoc): TLoc =
getTemp(p, a.lode.typ, result, needsInit=false)
genAssignment(p, result, a, {})
proc genArgStringToCString(p: BProc, n: PNode, needsTmp: bool): Rope {.inline.} = proc genArgStringToCString(p: BProc, n: PNode, needsTmp: bool): Rope {.inline.} =
var a: TLoc var a: TLoc
initLocExpr(p, n[0], a) initLocExpr(p, n[0], a)
@ -273,6 +277,9 @@ proc genArg(p: BProc, n: PNode, param: PSym; call: PNode, needsTmp = false): Rop
result = openArrayLoc(p, param.typ, n) result = openArrayLoc(p, param.typ, n)
elif ccgIntroducedPtr(p.config, param, call[0].typ[0]): elif ccgIntroducedPtr(p.config, param, call[0].typ[0]):
initLocExpr(p, n, a) initLocExpr(p, n, a)
if n.kind in {nkCharLit..nkNilLit}:
result = addrLoc(p.config, literalsNeedsTmp(p, a))
else:
result = addrLoc(p.config, withTmpIfNeeded(p, a, needsTmp)) result = addrLoc(p.config, withTmpIfNeeded(p, a, needsTmp))
elif p.module.compileToCpp and param.typ.kind in {tyVar} and elif p.module.compileToCpp and param.typ.kind in {tyVar} and
n.kind == nkHiddenAddr: n.kind == nkHiddenAddr: