Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* fixes status-im/nimbus-eth2#1549 [backport:1.4]

* test fixup
  • Loading branch information
Araq authored and mildred committed Jan 11, 2021
1 parent 467367f commit 62113e5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
14 changes: 8 additions & 6 deletions compiler/ccgcalls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,15 @@ proc openArrayLoc(p: BProc, formalType: PType, n: PNode): Rope =
else: internalError(p.config, "openArrayLoc: " & typeToString(a.t))

proc withTmpIfNeeded(p: BProc, a: TLoc, needsTmp: bool): TLoc =
if needsTmp and a.lode.typ != nil:
var tmp: TLoc
getTemp(p, a.lode.typ, tmp, needsInit=false)
genAssignment(p, tmp, a, {})
tmp
# Bug https://github.com/status-im/nimbus-eth2/issues/1549
# Aliasing is preferred over stack overflows.
# Also don't regress for non ARC-builds, too risky.
if needsTmp and a.lode.typ != nil and p.config.selectedGC in {gcArc, gcOrc} and
getSize(p.config, a.lode.typ) < 1024:
getTemp(p, a.lode.typ, result, needsInit=false)
genAssignment(p, result, a, {})
else:
a
result = a

proc genArgStringToCString(p: BProc, n: PNode, needsTmp: bool): Rope {.inline.} =
var a: TLoc
Expand Down
8 changes: 8 additions & 0 deletions compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,14 @@ proc getTemp(p: BProc, t: PType, result: var TLoc; needsInit=false) =
result.storage = OnStack
result.flags = {}
constructLoc(p, result, not needsInit)
when false:
# XXX Introduce a compiler switch in order to detect these easily.
if getSize(p.config, t) > 1024 * 1024:
if p.prc != nil:
echo "ENORMOUS TEMPORARY! ", p.config $ p.prc.info
else:
echo "ENORMOUS TEMPORARY! ", p.config $ p.lastLineInfo
writeStackTrace()

proc getTempCpp(p: BProc, t: PType, result: var TLoc; value: Rope) =
inc(p.labels)
Expand Down
1 change: 1 addition & 0 deletions tests/ccgbugs/targ_lefttoright.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ discard """
2,2
1,2
'''
cmd: "nim c --gc:orc $file"
"""

template test =
Expand Down

0 comments on commit 62113e5

Please sign in to comment.