Hi all,
first and foremost: thanks for providing and maintaining sdcc.
I've been using the stm8 port for a while and it works great.
After upgrading to sdcc 4.2, I noticed the following problem, though:
#define __PB_ODR *(volatile unsigned char *)0x5005
static inline void toggle_a_gpio(void)
{
__PB_ODR |= 0x1;
}
static void sub_func(bool my_sub_flag)
{
printf("%s(): my_sub_flag %d\n", __func__, my_sub_flag);
}
static void sdcc42_bug(bool my_flag)
{
printf("%s(): my_flag %d\n", __func__, my_flag);
if (my_flag)
toggle_a_gpio();
else
toggle_a_gpio();
sub_func(true);
}
The output of sdcc42_bug(false) with sdcc 4.1 is, not surprisingly:
sdcc42_bug(): my_flag 0
sub_func(): my_sub_flag 1
But sdcc 4.2 seems to relay the my_flag parameter to sub_func. The output of sdcc42_bug(false) is
sdcc42_bug(): my_flag 0
sub_func(): my_sub_flag 0
I played around with this. Triggering the bug requires and if-else statement (no else -> no bug) and a function call in if and else. Of course, my original code called two different functions. Calling printf("blabla\n") instead of toggle_a_gpio does not trigger the bug.
sdcc 4.1 generates this assembler code
790 ; main.c: 107: sub_func(true);
000233 4B 01 [ 1] 791 push #0x01
000235 CDr01rFD [ 4] 792 call _sub_func
000238 84 [ 1] 793 pop a
794 ; main.c: 108: }
and sdcc 4.2 generates
00021D 771 00103$:
772 ; main.c: 107: sub_func(true);
00021D A6 01 [ 1] 773 ld a, #0x01
00021F 84 [ 1] 774 pop a
000220 CCr01rE6 [ 2] 775 jp _sub_func
776 ; main.c: 108: }
Shouldn't this be push a to store the parameter on the stack for sub_func to pick it up?
Needless to say, I'm happy to provide further infos or to do some more testing with my setup.
Thanks,
Martin
I can reproduce the issue on my Debian GNU/Linux testing system using SDCC 4.2.2 #13377.
Fixed in [r13380].
Related
Commit: [r13380]