Menu

#2643 Initialization of anonymous union inside struct broken

closed-fixed
None
other
7
2023-02-01
2017-08-20
No

Apparently, there is an issue with the initialization of union inside struct for some backends (I saw the problem in stm8, z80 and hc08, but not mcs51-small).
An initialization of a union nested in a struct seems to result in initializations for other global variables being wrong.

I'm giving this higher-than-average priority, since bad code is generated silently.

Philipp

1 Attachments

Discussion

  • Philipp Klaus Krause

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,4 +1,4 @@
    -Apparently, there is an issue with theinitialization of union inside struct for some backends (I saw the problem in stm8, z80 and hc08, but not mcs51-small).
    +Apparently, there is an issue with the initialization of union inside struct for some backends (I saw the problem in stm8, z80 and hc08, but not mcs51-small).
     An initialization of a union nested in a struct seems to result in initializations for other global variables being wrong.
    
     I'm giving this higher-than-average priority, since bad code is generated silently.
    
     
  • Rajmund Szymański

    This bug applies to anonymous unions (stm8).

     

    Last edit: Rajmund Szymański 2017-08-21
  • Philipp Klaus Krause

    • summary: Initialization of union in struct broken --> Initialization of anonymous union inside struct broken
     
  • Philipp Klaus Krause

    It seems practically all backends are affected. So far mcs51 with the small memory model is the only exception I found.

    Affected are at least: mcs51 with large or huge memory model, stm8, z80, hc08 and ds390.
    Basically only backends that generate iCode for the initialization of global variables (as opposed to using some xinit/initializer/whatever copy mechanism) are not affected.

    In [r10206], I added a (disabled) regression test for this bug. If fixing the bug is too hard for 3.6.0, we should at least try to introduce some assertion that catches the issue in SDCC (basically emitting an initalizer that has more bytes than the size of the initialized type), so we no longer genrate bad code silently.

    Philipp

     
  • Philipp Klaus Krause

    It seems by the time the intializer bytes are emitted in printIvalStruct() in SDCCglue.c, the information that there is a union has been lost in case the union is anonymous.

    Philipp

     
  • Philipp Klaus Krause

    • assigned_to: Philipp Klaus Krause
     
  • Philipp Klaus Krause

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

    Fixed in [r10207].

    Philipp

     
  • Philipp Klaus Krause

    The fix for this bug broke structs where the first member is a zero-width bit-field: [bugs:#3542].

     

    Related

    Bugs: #3542


Log in to post a comment.

Auth0 Logo