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.

TMS320F28379D: C2000 compiler with optimization accidentally removing instructions

Part Number: TMS320F28379D


I believe there could be an optimization bug with the C2000 compiler, which is removing essential lines of code.

I can’t share the entire CCS project because the code is confidential, so I will post code snippets and share other screen shots to describe the problem.

The source of the problem is shown here. This static inline function is called from a function running at 100HZ on the second core of a TMS320F28379D microcontroller.

This function calls a couple of filter functions that take and structure and input float value and returns a float value that the is then stored in a global variable. For reference, the next following images shows the structure definition, and function call of filter1_input (which is a static inline function).

As shown in the screenshot above, the output of the ”filter_input” function is calculated based on the input float value, and the state parameters that are defined in the filter structure. The output is also stored into a parameter in the filter called "y_n1”, and which will be used in the next calculation that the filter performs. This means that the "y_n1” parameter in the filter structure should be updated every time "filter1_input" is called.

The problem is that the "yn_1" parameter is never being updated for the “lowpassAmpPhase2D" filter structure. When running through the “second_filter_dq_outputs” function continuously, the “yn_1” parameter never updates on “lowpassAmpPhase2D”, but does change on the other filters. The next screen shot shows how the structures look like from the memory viewer.

The red text indicates that that address in memory was recently updated. As shown in the cyan box, there are 32-bits of data that never get updated for lowpasAmpsPhase2D, which is where “y_n1” is. Putting a watchpoint at the address that stores "Y_n1”, it never goes off which indicates that memory value is never updated.

The strangest part of this problem was a fix was found by simply declaring these filter structures in a different order. If you declare lowpasAmpsPhase2D before the other filters, the memory view looks like this:

As shown, lowpassAmpsPhase2D was cleared first, and now its "yn_1” value is being updated. All the other filters are working too, so this simple swap around fixed the bug.

Based on what I have seen, I don’t think the “yn_1” value is being overwritten by a buffer-overflow or some other memory bug, as we should see it updated in the memory view, and a watchpoint to trigger when set to its address. It looks like the instructions for writing to that memory value are missing entirely, which makes me think this could be a compiler bug. Does this look like it could be a compiler bug, or could some other issue that I have not considered?

Additional Information:

Code Composer Studio Version: 12.1.0.00007

Here are the optimization settings used in the project:

  • Hello Eric,

    When optimizations are enabled, debugging the program is not very reliable. The reason for this is because some of the types of optimizations make it difficult to step through the code using an emulator. You can refer to the C28 Optimization Guide for more details about how variables get removed, rearrangement of generated assembly, etc.:

    If you're concerned with whether or not your code works, if possible try to run the code without any optimizations. To test whether the code functions with optimizations, you will have to load the program to the device (i.e. not debugging) and have some external method of monitoring the functionality of the program.

  • Hello Omer,

    Thank you for responding to my post. 

    This code has been tested outside of the CCS debugger, and it was found to not work properly (i.e the filter that I mentioned in the post was not producing the expected output).


    My concern and the reason I made this post was because I think this is a compiler bug. As I stated in my post, the code was fixed when changing the order of how the filters were declared. So this problem has technically been "fixed", but it looks like the underling cause of this issue could be an compiler issue. The debugger showed that when the filter wasn't working, it was because a specific memory address that should have been changing regularly was never changing.

    Based on these observations, do you think this could be a compiler bug? Again, the issue only appears when the filters variables were declared in a specific order, and was then fixed once they were re-ordered.

  • I believe there could be an optimization bug with the C2000 compiler, which is removing essential lines of code.

    The only way to advance this issue is for you to submit a test case that allows us to reproduce the behavior.

    You don't have to share the entire CCS project.  It appears the problem occurs in one source file.  For that source file, please follow the directions in the article How to Submit a Compiler Test Case.  Please note the details in the article about how you can submit the test case directly to me.

    Thanks and regards,

    -George

  • Thank you for submitting a test case via private message.  I am able to reproduce the same behavior.  I filed EXT_EP-11683 to have this investigated.  You are welcome to follow it with that link.

    Thanks and regards,

    -George