nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.44k stars 1.47k forks source link

Minimal Example Produces invalid _setjmp call on Windows 10 #20991

Closed winrid closed 1 year ago

winrid commented 1 year ago

Description

Hello!

This is my first Nim bug report so thanks for any patience if I miss something.

Code snippet that fails to compile:

echo "test"

For some reason produces a call to _setjmp in generated code with a second NIM_NIL argument. Tried both C and C++ backends. AFAIK _setjmp should only take one argument.

Nim Version

$ nim -v
Nim Compiler Version 1.6.8 [Windows: i386]
Compiled at 2022-09-27
Copyright (c) 2006-2021 by Andreas Rumpf

active boot switches: -d:release

Current Output

Hint: used config file 'C:\Users\winrid\.choosenim\toolchains\nim-1.6.8\config\nim.cfg' [Conf]
Hint: used config file 'C:\Users\winrid\.choosenim\toolchains\nim-1.6.8\config\config.nims' [Conf]
.........................................................C:\Users\winrid\nimcache\jb_nimtest1\main.nim_d\@m..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem@sansi_c.nim.cpp: In function 'int c_setjmp__systemZansi95c_42(int*)':
C:\Users\winrid\nimcache\jb_nimtest1\main.nim_d\@m..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem@sansi_c.nim.cpp:27:32: error: too many arguments to function 'int _setjmp(int*)'
  result = _setjmp(jmpb, NIM_NIL);
                                ^
In file included from C:\Users\winrid\nimcache\jb_nimtest1\main.nim_d\@m..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem@sansi_c.nim.cpp:8:0:
c:\mingw\include\setjmp.h:39:37: note: declared here
 _CRTIMP int __cdecl __MINGW_NOTHROW _setjmp (jmp_buf);
                                     ^~~~~~~

CC: ../../.choosenim/toolchains/nim-1.6.8/lib/system/ansi_c.nim
CC: main.nim
Error: execution of an external compiler program 'g++.exe -c -std=gnu++14 -funsigned-char  -w -fmax-errors=3 -fpermissive -mno-ms-bitfields   -IC:\Users\winrid\.choosenim\toolchains\nim-1.6.8\lib -IC:\Users\winrid\Documents\nimtest1 -o C:\Users\winrid\nimcache\jb_nimtest1\main.nim_d\@m..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem@sansi_c.nim.cpp.o C:\Users\winrid\nimcache\jb_nimtest1\main.nim_d\@m..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem@sansi_c.nim.cpp' failed with exit code: 1

Expected Output

"test"

Possible Solution

Use WSL

Additional Information

I've tried deleting the nimcache folder (UserDir\nimcache).

Araq commented 1 year ago

Use 1.6.10 or mm:arc or a C compiler that supports _setjmp.

winrid commented 1 year ago

Hey @Araq ! Thanks for replying. I just finished looking through your book :)

--gc=arc does fix it.

I think, my C compiler does support _setjmp? I just updated my toolchain. I will also try 1.6.10....

winrid commented 1 year ago

Updated to 1.6.10 and issue is also gone.