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.

Local C++ structure allocated statically depending on initializer list

We've discovered a problem where the C6000 C++ compiler places a local structure variable not on the stack but in the data segment, as if it was a static structure.  The problem is especially insidious because the issue will only have an impact on re-entrance.

The problem seems to occur only for C++ files, and only if the structure initializer list contains a variable.  Constant initializer lists do not trigger the issue. 

For example:

typedef struct  
{
  int unused1;
  int count;
} TEST_STRUCT;

int initValue = 42;

void TestStructure1(int count)
{
  TEST_STRUCT s = {42};
}

void TestStructure2(int count)
{
  TEST_STRUCT s = {initValue};
}

The structure in the first function will be allocated on the stack, but the structure in the second will be compiled as if it was declared static.

It has been tested with both the 7.3.9 and 7.4.7 versions of the C6000 compiler.

I've attached a trivial C++ main module that can be used to demonstrate the problem using recursion. 

6175.TestNonConstInitializer.cpp