Menu

#2455 arrays of functions in structs emits bad code

closed-fixed
Ben Shi
None
Front-end
5
2016-01-16
2016-01-13
No

Hello SDCC team,

I managed to lock down a broken scenario involving structs and function pointers.
If it affects all targets or just STM8 is unclear.

version: #9454

code:

typedef void (*t_func_type)(void);
static void test_func(void)
{
}

typedef struct
{
    t_func_type func[2];
}t_test_struct;

static t_test_struct g_test_struct = {{test_func}};
int main(void)
{
  g_test_struct.func[0]();
  return 0;
}

options:

--debug --disable-warning 110 --disable-warning 85 --Werror --std-sdcc89 --fverbose-asm --opt-code-size -mstm8 --std-sdcc89 --fverbose-asm

emitted code:

ldw x, #_g_test_struct+0
call (x)

problem:

It loads the correct address for "g_test_struct".
However it forgets to emit something like "ld (X),X" to derefence the pointer.

Changing just about anything makes it work.

2) 1) If you do not make it an array -> it works.
2) If you do not place the array in the struct -> it works.

But this specific combination does not work.

Any ideas?

Thanks,

/pedro

Discussion

  • Ben Shi

    Ben Shi - 2016-01-13

    It affect all backends. All backends return wrong assembly code.

     
  • Ben Shi

    Ben Shi - 2016-01-13
    • Category: other --> Front-end
     
  • Ben Shi

    Ben Shi - 2016-01-15
    • status: open --> closed-fixed
    • assigned_to: Ben Shi
    • Category: Front-end --> other
     
  • Maarten Brock

    Maarten Brock - 2016-01-16

    Any reason why you do not consider this to be a bug in the frontend? To me iCodes (and eBBlocks) are in the frontend.

    For the record: you fixed it in [r9456].

     
  • Ben Shi

    Ben Shi - 2016-01-16

    i thought only the ast is the frontend. however that is not important.
    :)

     
  • Ben Shi

    Ben Shi - 2016-01-16
    • Category: other --> Front-end
     
  • Maarten Brock

    Maarten Brock - 2016-01-16
    • summary: stm8 - arrays of functions in structs emits bad code --> arrays of functions in structs emits bad code
     

Log in to post a comment.