Uploaded image for project: 'Embedded Software & Tools'
  1. Embedded Software & Tools
  2. EXT_EP-9683

Excessive stack usage in compiler-generated function to initialize object containing a huge default-initialized member

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Implemented
    • Icon: Medium Medium
    • Code Generation Tools
    • CODEGEN-7229
    • Hide
      C6000_8.2.0
      C6000_8.3.0
      MSP430_20.2.0.LTS
      ARM_18.12.0.LTS
      PRU_2.3.0
      ARP32_1.1.0*
      ARM_20.2.0.LTS
      C2000_20.2.0.LTS
      C7000_1.4.0.LTS
      C2000_21.2.0.LTS
      PRU_2.4.0*
      MSP430_18.12.0.LTS
      MSP430_21.2.0.LTS
      C2000_18.12.0.LTS
      Show
      C6000_8.2.0 C6000_8.3.0 MSP430_20.2.0.LTS ARM_18.12.0.LTS PRU_2.3.0 ARP32_1.1.0* ARM_20.2.0.LTS C2000_20.2.0.LTS C7000_1.4.0.LTS C2000_21.2.0.LTS PRU_2.4.0* MSP430_18.12.0.LTS MSP430_21.2.0.LTS C2000_18.12.0.LTS
    • Hide
      MSP430_20.2.2.LTS
      ARM_20.2.2.LTS
      C2000_18.12.6.LTS
      MSP430_20.8.0.STS
      ARP32_1.1.0*
      C2000_20.2.2.LTS
      C7000_1.4.0.LTS
      C6000_8.2.10*
      PRU_2.4.0*
      C2000_20.8.0.STS
      PRU_2.3.4*
      MSP430_18.12.6.LTS
      C6000_8.3.7
      ARM_18.12.6.LTS
      Show
      MSP430_20.2.2.LTS ARM_20.2.2.LTS C2000_18.12.6.LTS MSP430_20.8.0.STS ARP32_1.1.0* C2000_20.2.2.LTS C7000_1.4.0.LTS C6000_8.2.10* PRU_2.4.0* C2000_20.8.0.STS PRU_2.3.4* MSP430_18.12.6.LTS C6000_8.3.7 ARM_18.12.6.LTS
    • default
    • Add an explicit constructor which calls memset to set the large array to zero instead of relying on default initializations. This will prevent the compiler from creating the local temporary.
    • Hide
      When given code that creates a class with a large array or other object as a default-initialised member of a class, the compiler may create a temporary function to initialise instances of that class that uses a correspondingly large temporary variable. If the temp is too large, it may exceed the maximum size of a stack frame and cause corruption when the code runs.
      Show
      When given code that creates a class with a large array or other object as a default-initialised member of a class, the compiler may create a temporary function to initialise instances of that class that uses a correspondingly large temporary variable. If the temp is too large, it may exceed the maximum size of a stack frame and cause corruption when the code runs.

      The attached C++ file uses a series of templates and structures to create an object which has a member with a large array. The generated code which constructs this object includes an auto-generated function with a very large local frame. Calling this function overflows the stack.

      Use the attached files.

      % cl6x -@options.txt main.cpp
      

      Inspect the resulting main.asm file. Look for the auto-generated function named $P$F0. The local frame is 40,816 bytes. The function main passes the address of $P$F0 to an internal RTS function. When it finally executes, the stack is overflowed.

      Please see the related forum thread for more context.

            syncuser TI User
            syncuser TI User
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: