While trying to squeeze the code for [#393] I found this bug.
pdk backend generates wrong code to copy from param to local temporary variable.
Code to reproduce:
void fDummy (unsigned char c) { } void testgetByte (unsigned int i) { unsigned char c; c = i >> 8; c++; fDummy(c); c = i >> 8; c++; fDummy(c); }
with:
sdcc -c -mpdk14 --verbose --fverbose-asm --opt-code-size "-osrc\swap_opt.rel" "..\src\swap_opt.c"
Generates:
testgetByte: ; ..\src\test_bug_pdk.c: 42: c = i >> 8; ; peephole 0 removed dead load into a from _testgetByte_PARM_1+1. ; genAssign mov a, _testgetByte_sloc0_1_0+0 ; ..\src\test_bug_pdk.c: 43: c++; ; genPlus add a, #0x01 mov _fDummy_PARM_1+0, a ; ..\src\test_bug_pdk.c: 44: fDummy(c); ; genCall call _fDummy
That is obviously discarting the value from "_testgetByte_PARM_1+1" and loading "a" from "_testgetByte_sloc0_1_0+0" (temp, not initialized).
Found and fixed wrong code in src/pdk/gen.c
genGetByte:
I will commit after checking the tests.
Fixed in [r12566]