Menu

#2004 temporary generated for initialization

closed-out-of-date
None
other
6
2020-08-05
2012-04-02
No

For the following code:

void *foo[]={(void *)&("X"[0])};

sdcc generates two casts and an assignment and iTemps. This is

1) Ineffcient, since all calculations could be done at compile time instead

2) Dangerous, since other parts of sdcc, i.e. register allocation and code generation do not expect iTemps outside of functions. The Z80 related ports can handle them if they go into registers, and I just added an assertion in case they go onto the stack (so there is more than just the SIGSEGV to the user).

I see this issue in revision #7530, and found it by using --max-allocs-per-node 10 in the gcc-torture-execute-921019-1.c regression test when compiling for gbz80. I hive this above-default priority, since I suspect, this can result in silent generation of bad code if we don't get a SIGSEGV in other ports.

Philipp

Related

Bugs: #3031

Discussion

  • Philipp Klaus Krause

    In current SDCC [r10516], this problem is no longer as common as it used to be. Now, it only happens for static local variables, e.g.

    void f(void)
    {
        static void *foo[]={(void *)&("X"[0])};
    }
    

    Philipp

     
  • Sergey Belyashov

    Currently code generated for Z80, GBZ80, eZ80 is valid: all computations are done on compile stage. I think, this bug can be closed.

     
    • Philipp Klaus Krause

      Yes, looks like it got fixed a while ago.

       
  • Philipp Klaus Krause

    • status: open --> closed-out-of-date
    • assigned_to: Philipp Klaus Krause
    • Category: --> other
     

Log in to post a comment.

MongoDB Logo MongoDB