The minimized code is pretty simple. I know the code is pointless because the 8bit num will be 0, but the compiler should throw warning or error instead of signal 11: SIGSEGV,
Changing num to uint32_t can compile on 4.2
#include <stdint.h>
#define DAP_TRANSFER_RnW (1U << 1)
static uint8_t DAP_TransferBlock(const uint8_t *req, uint8_t *res)
{
uint8_t num;
num |= (4U + (((uint8_t)(*(req + 1)) | (uint8_t)(*(req + 2) << 8)) * 4)) << 16;
return (num);
}
sdcc-4.1.0/bin/sdcc -MMD -c -Ddouble=float -DUSE_STDINT -D__PROG_TYPES_COMPAT__ --less-pedantic -mmcs51 --model-small -Isdcc-4.1.0/share/sdcc/include DAP.c -o DAP.c.o
DAP.c:18: warning 84: 'auto' variable 'num' may be used before initialization
DAP.c:18: warning 85: in function DAP_TransferBlock unreferenced function argument : 'res'
sdcc-4.2.0/bin/sdcc -MMD -c -Ddouble=float -DUSE_STDINT -D__PROG_TYPES_COMPAT__ --less-pedantic -mmcs51 --model-small -Isdcc-4.2.0/share/sdcc/include DAP.c -o DAP.c.o
Caught signal 11: SIGSEGV
I can reproduce the issue in 4.2.2 #13492. [r13494] I added an assertion in AST decoration that triggers just before the segfault. So this is a frontend bug.
Related
Commit: [r13494]
Fixed in [r13588].
Related
Commit: [r13588]