Flexible array of structs does not correctly initialize last element with implicitly initialized struct members.

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Medium
    • Code Generation Tools
    • CODEGEN-9407
    • Show
      https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1054823/launchxl-f28069m-wrong-value-in-flexible-array-member
    • Hide
      C7000_2.1.0.LTS
      MSP430_21.6.0.LTS
      C7000_3.1.0.LTS
      C7000_4.1.0.LTS
      C7000_1.4.0.LTS
      C6000_8.3.11
      C6000_8.2.0
      C2000_18.1.0.LTS
      C6000_8.1.2
      C6000_8.3.0
      MSP430_20.2.0.LTS
      ARP32_1.0.0
      ARM_18.12.0.LTS
      C7000_5.0.0.LTS
      C2000_21.6.0.LTS
      PRU_2.3.0
      PRU_2.2.0
      PRU_2.1.0
      ARM_20.2.0.LTS
      C2000_20.2.0.LTS
      ARM_18.1.0.LTS
      MSP430_18.1.0.LTS
      C2000_22.6.0.LTS
      MSP430_18.12.0.LTS
      C2000_18.12.0.LTS
      Show
      C7000_2.1.0.LTS MSP430_21.6.0.LTS C7000_3.1.0.LTS C7000_4.1.0.LTS C7000_1.4.0.LTS C6000_8.3.11 C6000_8.2.0 C2000_18.1.0.LTS C6000_8.1.2 C6000_8.3.0 MSP430_20.2.0.LTS ARP32_1.0.0 ARM_18.12.0.LTS C7000_5.0.0.LTS C2000_21.6.0.LTS PRU_2.3.0 PRU_2.2.0 PRU_2.1.0 ARM_20.2.0.LTS C2000_20.2.0.LTS ARM_18.1.0.LTS MSP430_18.1.0.LTS C2000_22.6.0.LTS MSP430_18.12.0.LTS C2000_18.12.0.LTS
    • Hide
      C2000_25.3.0.LTS*
      MSP430_NEXT*
      MSP430_21.6.2.LTS*
      C7000_4.1.2.LTS*
      C2000_22.6.3.LTS*
      C7000_6.0.0.LTS*
      C2000_21.6.2.LTS*
      C7000_5.0.1.LTS*
      MSP430_20.2.8.LTS*
      ARM_20.2.8.LTS*
      PRU_2.4.0*
      PRU_2.3.4*
      C6000_8.3.15*
      Show
      C2000_25.3.0.LTS* MSP430_NEXT* MSP430_21.6.2.LTS* C7000_4.1.2.LTS* C2000_22.6.3.LTS* C7000_6.0.0.LTS* C2000_21.6.2.LTS* C7000_5.0.1.LTS* MSP430_20.2.8.LTS* ARM_20.2.8.LTS* PRU_2.4.0* PRU_2.3.4* C6000_8.3.15*
    • default
    • Explicitly initializing the last array element's struct's members will avoid the issue.

      For flexible array's of structs, if the last array element has implicitly initialized struct members, then the generated code incorrectly handles the last array element's initialization.  No space is allocated for the implicitly initialized portion of the last element.  Other variables may get allocated over that location.

      The attached file.c has these lines ...

      typedef struct {
          unsigned a;
          unsigned b;
      } entry_t;
      
      typedef struct {
          unsigned len;
          entry_t entries[];
      } array_t;
      
      const array_t array = {
        .len = 3,
        .entries = {
                  { .a = 1,},
                  { .a = 2},
                  { .a = 3},
        },
      };
      

      Build it ...

      % cl2000 -s file.c
      

      Inspect the resulting assembly file ...

      _array:
              .bits           0x3,16
                              ; _array._len @ 0
              .bits           0x1,16
                              ; _array[0]._a @ 16
              .space  16
              .bits           0x2,16
                              ; _array[1]._a @ 48
              .space  16
              .bits           0x3,16
                              ; _array[2]._a @ 80
      

      There should be one more line of ".space 16", so that array[3].b is set to 0. Instead it ends up having the value of whatever is next in memory.

            Assignee:
            TI User
            Reporter:
            TI User
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                Connection: Intermediate to External PROD System
                EXTSYNC-3184 - Flexible array of structs does not ...
                SYNCHRONIZED
                • Last Sync Date: