Open GordonBGood opened 5 years ago
I think this is likely due to some interaction with the version of Clang used: version 7.0.0 (possibly only the MSYS2 version on windows?) but it might be helpful to know why and whether it will carry forward to newer versions...
The problem
TLDR; the following code compiles and runs both in debug and release modes with the gcc backend, and is fine with the clang backend in debug mode but crashes with a seg fault with clang and release mode.
Environment: Windows 10 64-bit, updated latest build up to the October update. Nim version 0.19 64-bit. Clang version 7.0.0 64-bit installed with MSYS2 64-bit.
Synopsis: I have been working with building lazy lists in Nim for years, but decided to convert the code to use object variants rather than testing for nil, as it logically seemed to make sense in the use case. The code comments pretty well say it all:
Example
Current Output
Error reported on crash:
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
The problem is entirely within the
Lazy
object variant, as it can even be created separately from theLazyList
container, as in the given test lines forLazy
, which won't run when compiled with clang in release mode even with the later lines commented out.Expected Output
Expected output is just to print "42" to the console.
Work around
The work around has been to go back to a version of the lazy list using nil/not nil or true/false testing for whether the lazy value has been evaluated yet, which works fine just not as elegantly.
The reason for using clang as a back end is that it compiles a little faster, as the quality of the generated code is generally good from either gcc or clang.