inlining a function that does not reference its parameters from C leads to incorrect code.
It seem the optimized is too greedy and if it does not see any reference to the parameters it optimizes them out.
#define kernal_entry(name, addr) __at addr void(*name)(unsigned char, unsigned char)
kernal_entry(PLOT, 0xfff0);
inline void gotoxy(unsigned char x, unsigned char y)
{
(void)x;
(void)y;
__asm__("tay");
__asm__("clc");
PLOT(0,0);
}
void textframexy (unsigned char x, unsigned char y,
unsigned char width, unsigned char height)
{
gotoxy(x,y+6);
}
removing inline works as expected.
making the gotoxy call PLOT(x,y) also works as expected.
declaring gotoxy parameters volatile works but generates tons of unecessary code.
I observed similar behavior in the z80 port as well.
I don't know what "works as expected" is meant to be here. There is no calling convention for inlined functions, so asm cannot expect the parameters t be stored in any particular location.
"Works as expected" means the registers are setup according to the ABI.
i.e. first 8-bit param in A, second in X.
The compiler follows this behavior even for inlined function.
This works perfectly if the variables are used in the C code.
The optimizer removes the parameters because it detects them as not used in the function.
the
(void)x;quiets the warning but the compiler still knows the variable is unused and optimizes it out.