The following code generates a segfault, so said EVELYN the modified DOG.
Also, the line number for the divide by zero warning appears to be incorrect.
// GPL 2.0
#include <stdlib.h>
#define tWidth 4
#define tHeight 4
void test() {
int h = 8;
int Y = 0;
int ScreenX = 0;
//calculate width of the
int Width = abs( (int)(h / (Y)));
int drawStartX = 0;
int drawEndX = 0;
int tX;
for(int stripe = drawStartX; stripe < drawEndX; stripe++)
{
tX = (int)(256 * (stripe - (-Width / 2 + ScreenX)) * tWidth / Width) / 256;
}
}
sdcc -mz80 ./segfault.c
./segfault.c:24: warning 122: dividing by 0
./segfault.c:26: warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG
Caught signal 11: SIGSEGV
sdcc -v
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/sm83/tlcs90/ez80_z80/z80n/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502 4.2.2 #13492 (Linux)
I simplified it a bit:
This simplified code triggers the bug for all but the MCS51/DS390.
It also (obviously) no longer has the division by 0 warning which seems unrelated.
--nogcse is a workaround.
Fixed in [r14060].
Related
Commit: [r14060]