Tool/software: TI C/C++ Compiler
The TI compiler (in this case, ARM compiler 17.6.0 STS) sometimes generates a call to "malloc" to allocate storage for a local array. For example in the following code, notice the call to "vla_alloc":
You can see why this happens - the compiler isn't sure of the array size at compile time (even though the size variable is const) so it can't fix the function's stack frame size and instead does it at run-time. However, in my application I don't have a heap, so this code fails.
For comparison, I tried similar code in Microsoft Visual Studio - this is "smart" enough to see that the size is const and thus allocates space in the stack frame. In fact, the compiler will raise an error not generate code if the array size is not constant.
My questions are:
1. Are there any other cases where the TI compiler will generate a hidden call to malloc (or vla_alloc)?
2. Is it possible to disable this behaviour?
3. Can the compiler be updated to raise a warning or error if it is unable to put local variables on the stack? It feels like the TI compiler is trying to be helpful, but the behaviour is counter-intuitive as most users would expect local variables to live on the stack, and it fails entirely if the application has no heap (which is common in safety-critical systems).