Menu

#3641 Assignment omits least-significant byte of literal

closed-fixed
None
HC08
5
2023-09-05
2023-09-03
No

In the hc08 and s08 ports, sometimes the least-significant byte is not assignend when a literal is assigned to a local variable.
I originally discoverred this bug while experimenting with changes to generalized constant propagation, but was able to reproduce it in sdcc from trunk:

void loopm(unsigned char *a)
{
    for (unsigned long i = (1ul << 20); i < (1ul << 20) + 1; i++)
        a[i - (1ul << 20)] = 1;
}

// In both assignments to i, the least-significant byte gets omitted.
void loopm2(unsigned char *a)
{
    for (unsigned _BitInt(24) i = (1ul << 20); i < (1ul << 20) + 1; i = (1ul << 20) + 1)
        a[i - (1ul << 20)] = 1;
}

The generated asm looks like this:

; [---] ic:4:   _loopm2_i_131072_6 [k4 lr0:0 so:-5]{ ia1 a2p0 re0 rm0 nos0 ru0 dp0}{unsigned-_BitInt(24) auto} := 0x100000 {unsigned-_BitInt(24) literal}
;     genAssign
    tsx
    ldhx    #0x1000
    sthx    1,s

and this:

;test.c:9: for (unsigned _BitInt(24) i = (1ul << 20); i < (1ul << 20) + 1; i = (1ul << 20) + 1)
; [---] ic:12:  _loopm2_i_131072_6 [k4 lr0:0 so:-5]{ ia1 a2p0 re0 rm0 nos0 ru0 dp0}{unsigned-_BitInt(24) auto} := 0x100001 {unsigned-_BitInt(24) literal}
;     genAssign
    tsx
    ldhx    #0x1000
    sthx    1,s

Related

Bugs: #3643

Discussion

  • Erik Petrich

    Erik Petrich - 2023-09-05
    • status: open --> closed-fixed
    • assigned_to: Erik Petrich
     
  • Erik Petrich

    Erik Petrich - 2023-09-05

    Fixed in [r14342]

     

    Related

    Commit: [r14342]


Log in to post a comment.

MongoDB Logo MongoDB