#include <stdlib.h>
wchar_t array[] = L"";
Compiling this with sdcc test.c results in Caught signal 11: SIGSEGV. Tested with commit 11647.
Wiki: NGI0-Entrust-SDCC
Wiki: SDCC 4.3.0 Release
Wiki: SDCC-STD-UX
This crashes in the mcs51 register allocator.
I've tried mcs51, z80, pdk14, stm8, hc08, ds390. Only mcs51 crashed for me, the other ports apparently generate good code.
This passes for --model-medium / --modem-large / --model-huge and also for --model-small --stack-auto. Only --model-small fails for which wchar is also not tested in regression test wchar.c due to memory restrictions.
Actually, this is not about strings at all. The following fails the same way:
Last edit: Philipp Klaus Krause 2022-03-20
Looks like another of those issues where too much iCode is generated for the initialization of a global, and codegen assumes it is inside a function when it is not.
What do you mean by too much iCode?
Codegen should not assume to be inside a function. Initialization of global/static __data variables does not happen inside a function. Instead code is generated for that in the GSINIT section.
Typically, we see issues if the iCode gets so complex that temporaries cannot be allocated to registers. Apparently codegen (and some other stuff) assumes that we are in a function at least as soon as some variables are spilt. And it looks like this is what happens here, too.
P.S.:
Last edit: Philipp Klaus Krause 2022-08-31
While that explains the symptoms (and the place where the crash happens - since [r14007], there is also an assertion for this), it doesn't explain why it only happens, if we have a header include followed by an initialized array, while the include alone and the array alone are fine. And even the include followed by the array is fine if they are followed by a function definition (a function declaration by itself won't help).
P.S.: From the include, we just needed an inline function with at least one parameter. The following code is by itself sufficient to trigger the bug:
Apparently, after the inline function definition, overlay->syms is nonempty, which results in this bug.
Related
Commit: [r14007]
Last edit: Philipp Klaus Krause 2023-04-12
In SDCCmem.c, we have this comment:
It looks like for inline functions, we never remove the thing from the overlay segment, so the overlay segment never gets cleaned up, resulting in this bug.
Last edit: Philipp Klaus Krause 2023-04-12
Fixed in [r14008].
Related
Commit: [r14008]