Quick actions

cmd+k|ctrl+k

Navigation

Languages

the MWE of the segmentation fault caused by --stacktrace:off

Snippet info

Language

Nim

Visibility

public

Author

7sdream

Created

2018-06-19T18:01:56Z

Updated

2018-06-19T18:04:02Z

proc toIter(it: seq[bool]): iterator: bool =
  return iterator: bool =
    for x in it:
      yield x

proc realCountIt(it: iterator: bool, current: int): int =
  discard it()
  return if finished(it):
    current
  else:
    realCountIt(it, current + 1)

proc count(it: seq[bool]): int = realCountIt(it.toIter, 0)

let arr1 = newSeq[bool](1_000)
let arr2 = newSeq[bool](100_000)

echo arr1.count # this line works file
echo arr2.count # this line Segmentation fault

# due to main.nims, it will run as:
# nim c --stacktrace:off -r main.nim
# 
# or if you uncomment the line in main.nims script, it will run as:
# nim c --stacktrace:off -t:-foptimize-sibling-calls -r main.nim
#
# but both of them will cause a Segmentation fault in line 19
# 
INFO