Menu

#3675 Parameter sent to wrong function

closed-fixed
None
Front-end
5
2023-11-19
2023-11-16
No

Looking at the mcs51 asm generated for tests/gcc-torture-execute-20180131-1.c, in the function testTortureExecute, there are two function calls. One to f, one to memcpy (as a helper function used for copying a struct).
However the SEND iCode that should send the first parameter to f ends up before memcpy.

Related

Wiki: SDCC 4.4.0 Release

Discussion

  • Philipp Klaus Krause

    Apparently, tests/gcc-torture-execute-pr67226.c is also affected. I guess this bug might affect mcs51 for all calls, where a struct parameter follows an integer parameter.

     
  • Philipp Klaus Krause

     
  • Philipp Klaus Krause

    In [r14440] I added a regression test for this (for now disabled for the ports where it fails).

    Apparently affected ports: mcs51, hc08, s08, mos6502.
    Apparently unaffected ports: pdk, stm8, z80 and related.
    Test fails to link: ds390.

    P.S.: Apparently, the bug does not happen when using --stack-auto.

     

    Related

    Commit: [r14440]


    Last edit: Philipp Klaus Krause 2023-11-18
  • Philipp Klaus Krause

    The code looks already wrong in dumpraw0, i.e. when iCode is first generated; apparently the bug happens in the conversion from AST to iCode.

    P.S.: I think in src/SDCCicode.c, in geniCodeParms, this case:

          if (!(options.stackAuto || IFFUNC_ISREENT (ftype)))
            {
              if (is_structparm) // Passing the parameter requires a memcpy.
    

    Is the one where we run into the bug. I suspect that iCodes for the memcpy helper function call are inserted in the wrong place.

    P.P.S.: At that point the iCode chain does only exist as an SDCCset (created via ADDTOCHAIN), making it harder to insert iCodes at a specific place.

     

    Last edit: Philipp Klaus Krause 2023-11-18
  • Philipp Klaus Krause

    • status: open --> closed-fixed
    • assigned_to: Philipp Klaus Krause
    • Category: other --> Front-end
     
  • Philipp Klaus Krause

    Fixed in [r14443]. Quite a hackish fix, but apparently, it works. Maybe we can find a cleaner solution one day.

     

    Related

    Commit: [r14443]


Log in to post a comment.