Menu

#3269 pdk code generation - copy from not initialized temporary variable

closed-fixed
Visenri
codegen (1)
PDK
5
2021-07-27
2021-07-27
Visenri
No

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).

Discussion

  • Visenri

    Visenri - 2021-07-27

    Found and fixed wrong code in src/pdk/gen.c

    genGetByte:

    -  cheapMove (ASMOP_A, 0, left->aop, offset, regDead (A_IDX, ic), regDead (P_IDX, ic), true);
    +  genMove_o (result->aop, 0, left->aop, offset, 1, regDead (A_IDX, ic), regDead (P_IDX, ic));
    

    I will commit after checking the tests.

     
  • Visenri

    Visenri - 2021-07-27

    Fixed in [r12566]

     
  • Visenri

    Visenri - 2021-07-27
    • status: open --> closed-fixed
     

Log in to post a comment.