Menu

#261 icode: bad generation of assignments for arrays in structs

None
closed-accepted
None
5
2016-01-18
2016-01-17
No

Hello SDCC team,

I found this bug in one in some of my code:

struct
{
  funcType fpa[2];
} testS = {{NULL, NULL}};

static void *testPointer;

int main(void)
{
  testPointer = testS.fpa[1];
  return 0;
}

This does not produce proper code due a bug in the icode generator.

The emitted code is:

; ic:   4:  iTemp2 [k7 lr3:4 so:0]{ ia1 a2p1 re0 rm0 nos0 ru0 dp0}{int function ( ) __reentrant code* near* fixed}[xl xh ] = &[_testS [k3 lr0:0 so:0]{ ia1 a2p0 re0 rm0 nos0 ru0 dp0}{struct __00000000 fixed} , 0x2 {const-unsigned-char literal}]
    ldw x, #_testS+2
; ic:   5:  iTemp3 [k8 lr4:5 so:0]{ ia0 a2p0 re0 rm0 nos0 ru0 dp0}{void generic* fixed}[xl xh ] = (void generic* fixed)iTemp2 [k7 lr3:4 so:0]{ ia0 a2p0 re0 rm0 nos0 ru0 dp0}{int function ( ) __reentrant code* near* fixed}[xl xh ]
; ic:   7:  _testPointer [k2 lr0:0 so:0]{ ia1 a2p0 re0 rm0 nos0 ru0 dp0}{void generic* fixed} := iTemp3 [k8 lr4:5 so:0]{ ia0 a2p0 re0 rm0 nos0 ru0 dp0}{void generic* fixed}[xl xh ]
    ldw _testPointer+0, x

Alas, it is missing a dereference of the pointer.

I looks like the problem is in geniCodeRValue(), which does not expand this properly.

Allowing the code to follow the pointer like it should fixes the problem.

The following patches fixes it for me (+ tests).

Please review/accept/reject,

Thanks,

/pedro

Discussion

  • Peter Dons Tychsen

    Here is the patch for the change and tests.

    All tests seem to be OK with change.

     
  • Peter Dons Tychsen

    Missing a GPL header, here is another patch.

     
  • Philipp Klaus Krause

    • assigned_to: Philipp Klaus Krause
    • Group: -->
     
  • Philipp Klaus Krause

    • status: open --> closed-accepted
     
  • Ben Shi

    Ben Shi - 2016-01-18

    The original patches failed to handle

    testS.fpa[1] = testS.fpa[0];

    More work is needed in SDCCicode.c

     
  • Peter Dons Tychsen

    OK Ben, nicely spotted!

    Maybe open a new bug for this?

    Not sure the bug is in the same place.

    Thanks,

    /pedro

     
  • Ben Shi

    Ben Shi - 2016-01-18

    Needn't to do. I have fix it and will commit to svn later.

     
  • Peter Dons Tychsen

    OK, then please also commit the test case i made along with any changes you add.

     

Log in to post a comment.