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.

TM4C1292NCPDT: Compiler optimization - aggressive, omitting functional code

Part Number: TM4C1292NCPDT


A top-level handler function supports 6 cases.  One case is meant to enter a specific handler routine that contains a simple while(1){} trap.  With optimization, this specific handler is omitted from the code and the case condition likewise omitted from the top-level switch statement.

In building a simplified test scenario, I have represented the other 5 handler routines and under certain scenarios, all specific handlers are omitted from the final build with optimization turned on.  Without optimization, all cases are exercised in this test scenario and the while(1) trap functions as expected.

Optimization Level 2 - Global and 2 for speed/size.  However, all first-level settings other than optimization-off cause problems. No advanced optimization settings have been utilized.

What is the recommended response to this observation?  Any settings to the current compiler that would yield expected results?  Would an updated compiler revision yield expected results?

Please provide reference to this being expected behavior with optimization enabled.  The behavior is changing the nature of the natural code and providing unpredictable functionality.

Compiler: 

TI v18.12.4.LTS
ti-cgt-arm_18.12.4.LTS

  • If the linker sees no calls to a function, then it is removed.  To tell the linker to keep such a function, apply the retain function attribute to it.  For details, please search the TI ARM compiler manual for the sub-chapter titled Function Attributes.  I'm not certain this change will resolve all of your problems, but it is a good place to start.

    Thanks and regards,

    -George