Menu

#2846 Incorrect code for call to function returning struct / union

closed-fixed
None
other
5
2022-04-15
2018-11-29
No

SDCC doesn't support functions that return struct yet. But it does not give an error on calling such a function either.

However, the generated code is incorrect. It assumes that the function returns a pointer to a struct. However, this can't work, since the lifetime of any object in the callee that pointer might point to has ended.

Instead, this should be handled like functions returning long long are handled in at least stm8 and z80-related backends: The caller passes a pointer as extra hidden parameter, so the callee can write the result there.

Philipp

Related

Wiki: SDCC-STD-UX

Discussion

  • Philipp Klaus Krause

    The main problem here is not the code generation for the call itself (that was an easy fix, for stm8 done in [r10680]), but the iCode reaching the backend. Just after the call I already see wrong iCode treating the struct as pointer to struct.

    Philipp

     

    Last edit: Philipp Klaus Krause 2018-11-29
  • Philipp Klaus Krause

    • status: open --> closed-fixed
    • assigned_to: Philipp Klaus Krause
     
  • Philipp Klaus Krause

    struct / union return support is now working for most ports. For the exceptions, there is an error message.

     

Log in to post a comment.

MongoDB Logo MongoDB