Boriel Basic Forum
Yet another optimized bug - Printable Version

+- Boriel Basic Forum (https://forum.boriel.com)
+-- Forum: Compilers and Computer Languages (https://forum.boriel.com/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://forum.boriel.com/forumdisplay.php?fid=11)
+---- Forum: Bug Reports (https://forum.boriel.com/forumdisplay.php?fid=15)
+---- Thread: Yet another optimized bug (/showthread.php?tid=707)



Yet another optimized bug - einar - 2015-12-17

Sample program test.bas:

Code:
GOTO 10 sub FASTCALL proc1() asm start: ld hl,(stuff) ld (23672),hl ret stuff: defw 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 defw 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 defw 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 defw 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 end asm end sub sub FASTCALL proc2(a AS UBYTE) asm cp 10 jr nz, skip dec a skip: jp start end asm end sub 10 proc1() proc2(0)

Compiling it using -O2 works correctly and produces the following code for routine proc2:

Code:
_proc2: #line 17 cp 10 jr nz, skip dec a skip: jp start #line 22 _proc2__leave: ret

Compiling it using -O3 produces error "Relative jump out of range" and produces the following code for routine proc2:

Code:
_proc2: #line 17 cp 10 jr nz, start dec a skip: jp start #line 22 _proc2__leave: ret

Again, the optimizer is supposed to try to optimize its own generated code only, not someone else's assembly code!