Nim
Nim copied to clipboard
Regression from 2.0 to `version-2-2`/`devel` with `refc`, LTO and `-fstack-usage`
Nim Version
Nim Compiler Version 2.0.15 [Linux: amd64]
Compiled at 2025-03-04
Copyright (c) 2006-2023 by Andreas Rumpf
git hash: 41637db18f6a82df4a92f2e00a780e5815d17028
active boot switches: -d:release
Nim Compiler Version 2.2.3 [Linux: amd64]
Compiled at 2025-03-04
Copyright (c) 2006-2025 by Andreas Rumpf
git hash: 58f1e22db352ed3cff0f9303acf064a291c25d8d
active boot switches: -d:release
Nim Compiler Version 2.3.1 [Linux: amd64]
Compiled at 2025-03-04
Copyright (c) 2006-2025 by Andreas Rumpf
git hash: e39d152b89c5635c27dd4d8fc71c48747c5fc20b
active boot switches: -d:release
gcc (Debian 14.2.0-17) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Description
proc h(): array[524288, byte] =
# Other conditional-adjacent expressions (case, try, etc) also work here
if true:
result
else:
result
let v = h() # to make Nim 2.0 fail too, use discard h()
Build with
nim c --passC="-flto -fstack-usage -Werror=stack-usage=262144" --passL="-flto -fstack-usage -Werror=stack-usage=262144" --mm:refc s.nim
Current Output
Hint: used config file '/tmp/nimdevel/config/nim.cfg' [Conf]
Hint: used config file '/tmp/nimdevel/config/config.nims' [Conf]
........................................................................
CC: nimdevel/lib/system/exceptions.nim
CC: nimdevel/lib/std/private/digitsutils.nim
CC: nimdevel/lib/system/dollars.nim
CC: nimdevel/lib/std/typedthreads.nim
CC: nimdevel/lib/pure/collections/sharedlist.nim
CC: nimdevel/lib/system.nim
CC: s.nim
Hint: [Link]
/tmp/tmp.g0j3iBnZfH/@ms.nim.c: In function ‘h__s_u1’:
/tmp/tmp.g0j3iBnZfH/@ms.nim.c:91:15: error: stack usage is 1048656 bytes [-Werror=stack-usage=]
91 | N_LIB_PRIVATE N_NIMCALL(void, h__s_u1)(tyArray__msnM9cX4aNc7VxW6WzOqyjA Result) {
| ^
lto1: some warnings being treated as errors
lto-wrapper: fatal error: gcc returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
Error: execution of an external program failed: 'gcc -o /tmp/s /tmp/tmp.g0j3iBnZfH/@mnimdevel@slib@[email protected] /tmp/tmp.g0j3iBnZfH/@mnimdevel@slib@sstd@[email protected] /tmp/tmp.g0j3iBnZfH/@mnimdevel@slib@[email protected] /tmp/tmp.g0j3iBnZfH/@mnimdevel@slib@[email protected] /tmp/tmp.g0j3iBnZfH/@mnimdevel@slib@spure@[email protected] /tmp/tmp.g0j3iBnZfH/@mnimdevel@[email protected] /tmp/tmp.g0j3iBnZfH/@ms.nim.c.o -pthread -pthread -flto -fstack-usage -Werror=stack-usage=262144 -ldl'
Expected Output
Known Workarounds
No response
Additional Information
No response
A diff of the C source generated -- some variable name noise, but fairly clear superficially what changed:
@@ -90,41 +75,49 @@
}
static N_INLINE(void, nimFrame)(TFrame *s_p0) {
{
- if (!(framePtr__system_u2617 == ((TFrame *)NIM_NIL)))
+ if (!(framePtr__system_u2710 == ((TFrame *)NIM_NIL)))
goto LA3_;
(*s_p0).calldepth = ((NI16)0);
}
goto LA1_;
LA3_:;
{
- (*s_p0).calldepth = (NI16)((*framePtr__system_u2617).calldepth + ((NI16)1));
+ (*s_p0).calldepth = (NI16)((*framePtr__system_u2710).calldepth + ((NI16)1));
}
LA1_:;
- (*s_p0).prev = framePtr__system_u2617;
- framePtr__system_u2617 = s_p0;
+ (*s_p0).prev = framePtr__system_u2710;
+ framePtr__system_u2710 = s_p0;
{
if (!((*s_p0).calldepth == ((NI16)2000)))
goto LA8_;
- callDepthLimitReached__system_u3150();
+ callDepthLimitReached__system_u3256();
}
LA8_:;
}
static N_INLINE(void, popFrame)(void) {
- framePtr__system_u2617 = (*framePtr__system_u2617).prev;
+ framePtr__system_u2710 = (*framePtr__system_u2710).prev;
}
N_LIB_PRIVATE N_NIMCALL(void,
h__s_u1)(tyArray__msnM9cX4aNc7VxW6WzOqyjA Result) {
+ tyArray__msnM9cX4aNc7VxW6WzOqyjA colontmpD_;
+ tyArray__msnM9cX4aNc7VxW6WzOqyjA colontmpD__2;
nimZeroMem((void *)Result, sizeof(tyArray__msnM9cX4aNc7VxW6WzOqyjA));
+ nimZeroMem((void *)colontmpD_, sizeof(tyArray__msnM9cX4aNc7VxW6WzOqyjA));
+ nimZeroMem((void *)colontmpD__2, sizeof(tyArray__msnM9cX4aNc7VxW6WzOqyjA));
{
if (!NIM_TRUE)
goto LA3_;
- nimCopyMem((void *)Result, (NIM_CONST void *)Result,
+ nimCopyMem((void *)colontmpD_, (NIM_CONST void *)Result,
+ sizeof(tyArray__msnM9cX4aNc7VxW6WzOqyjA));
+ nimCopyMem((void *)Result, (NIM_CONST void *)colontmpD_,
sizeof(tyArray__msnM9cX4aNc7VxW6WzOqyjA));
}
goto LA1_;
LA3_:;
{
- nimCopyMem((void *)Result, (NIM_CONST void *)Result,
+ nimCopyMem((void *)colontmpD__2, (NIM_CONST void *)Result,
+ sizeof(tyArray__msnM9cX4aNc7VxW6WzOqyjA));
+ nimCopyMem((void *)Result, (NIM_CONST void *)colontmpD__2,
sizeof(tyArray__msnM9cX4aNc7VxW6WzOqyjA));
}
LA1_:;
It breaks with ORC as well, related to https://github.com/nim-lang/Nim/issues/18341