I have ran into the following problem when switching from TI CGT ARM 18.1.4 to 20.2.7. I assume that this applies for all 18.1.x versions and all 20.2.x versions.
We experienced massive increases in function stack sizes when switching to the newer version of the compiler.
I've created an example code which reproduces the errors in our code.
The only compiler flag set was "-O0".
After compilation, I analyzed the .obj file with armofd.exe to see the function stack sizes, but I also compared the generated assembly codes to ensure that this is not a bug in the armofd.exe but really in the compiler itself.
With 18.1x version, the stack size of 'dummyFunctionWithSwitchInside' is 0x198, with the 20.2.x version, it increases to 0x968. (Almost six times bigger stack size, the multiplier is close to six, because of the six cases of the switch.)
I think this has to do with calculating the "worst-case" stack size for a function incorrectly in the new version, because this version calculates as if it was possible to fall through each case of the switch even though there are breaks in each case.
Example code:
typedef struct
{
int dummy[100];
}dummyStruct;
int dummyFunction(int * x, dummyStruct * value)
{
return (*x);
}
static void dummyFunctionWithSwitchInside(int * x)
{
int switchInput;
switch (switchInput)
{
case 1:
{
dummyStruct dummyInstance;
dummyFunction(x, &dummyInstance);
break;
}
case 2:
{
dummyStruct dummyInstance;
dummyFunction(x, &dummyInstance);
break;
}
case 3:
{
dummyStruct dummyInstance;
dummyFunction(x, &dummyInstance);
break;
}
case 4:
{
dummyStruct dummyInstance;
dummyFunction(x, &dummyInstance);
break;
}
case 5:
{
dummyStruct dummyInstance;
dummyFunction(x, &dummyInstance);
break;
}
case 6:
{
dummyStruct dummyInstance;
dummyFunction(x, &dummyInstance);
break;
}
}
}
void main()
{
int varAgainstOptimization;
dummyFunctionWithSwitchInside(&varAgainstOptimization);
}