This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/C2000-CGT: Local (auto) instance is being made global?

Part Number: C2000-CGT

Tool/software: TI C/C++ Compiler

The following code shows a case where a local variable that should be allocated in stack (0x400-0x800 memory range) is actually allocated out of stack (0xA80A, in RAMLS5, ebss).

#include <stdio.h>

struct Data
{
    int i;
};

void main()
{
    Data d = Data();
    size_t addr = (size_t)(&d);
    if(addr>0x800)
    {
        __asm("  ESTOP0"); // fail (stack is in 0x400-0x800 memory range).
    }
}

SFault.rar

It has been hard to reduce the case to a few lines. This bug caused a method used by 2 threads fail, because local variable was being changed by other thread (that's why it seems that local variable is actually global).

I've observed that removing the assignation in the initialization of 'd' avoids the problem. As far as i know, this initialization is legal, but now we have to find in our whole code if there are more initializations like this one, we cannot trust on our code compiled correctly if this bug is confirmed.

I've also observed that if Data struct defines a constructor, a compiler warning is thrown:

"warning #10210-D: creating ".esysmem" section with default size of 0x400; use the -heap option to change the default size".

It has no sense for me, it seems that compiler is inferring that heap is needed.

We can try to find and remove all initializations with such style ("Data d= Data();"), but we need to confirm that it has no more hidden implications.

Regards.