When compiling with the latest nightly build for mos6502, the compiler sometimes generates an .asm file which has an out-of-range branch address.
In these cases it would be expected to add an unconditional jmp instruction, and a branch with the opposite condition.
Tested with 4.6.0 #16555 (MINGW64)
(sdcc-snapshot-x86_64-w64-mingw32-20260602-16555)
Building with:
sdcc -mmos6502 -c out_of_range_branch_codegen.c
Error
out_of_range_branch_codegen.asm:147: Error: <a> machine specific addressing or addressing mode error
Minimal example to reproduce:
//
// Generates a codegen error for 6502: A branch instruction trying to jump beyond a signed 8-bit relative PC value
//
#include <stdint.h>
uint16_t X, Y;
int16_t Z;
uint8_t f(uint16_t x)
{
return x + 42;
}
void main(void)
{
uint16_t x = X >> 4;
if(Z > 0)
{
if(f(x) || f(x+1) || f(x+2) || f(x+3) || f(x+4) || f(x+5) || f(x+6))
{
return;
}
}
}
I can reproduce the issue on my Debian GNU/Linux testing system using sdcc built from current trunk.
Just subscribing to this ticket
bug is confirmed. I have a fix. I'll send a mail to the devel list to confirm it's ok to check-in before 4.6.0 release.
quick description:
There was a logic bug in the original code.
ifx_jmp_lblwas used instead ofskiplblmove
skiplbldefinition at the beginning of the function.rename
skiplbltoskiplbl1for the first byte.use
skiplblinstead ofifx_jmp_lblfixed in [r16601]
Related
Commit: [r16601]