configLIST_VOLATILE required - Missing configASSERT in listREMOVE_ITEM

Using the provided sample code for the PIC32 platform and FreeRTOS v202112.00. I ran into an issue in tasks.c when enabling the compiler optimizations (XC32 v4.00 compiler, -O2 optimization).

The exception happens in xTaskResumeAll() when the listREMOVE_ITEM macro tries to remove an item with a null pointer as the container. The macro creates a pointer pxList and de-references it without checking if it is NULL, causing an exception.

In my case, it seemed to be caused by an aggressive compiler and the fix was to add #define configLIST_VOLATILE volatile in FreeRTOSConfig.h

I think nevertheless the pointer should be checked for non-null in the macro to gracefully handle exceptions.

Thanks for posting the query.
There are some similar posts in the following threads:

  1. Stuck in xTaskResumeAll() - Interrupt Priorities? Stack?
  2. Endless loop in 10.4.6 with -Os flag
    Please check if any of the suggested options help in your scenario.

As described in this comment block, the solution you mentioned is right. Thank you for reporting it.

This list is not a general purpose list and meant for internal use only. Wherever we call remove item, it is ensured that the list is not empty. So I am not sure that we need to add an extra NULL check here.

Just ran into this issue with PIC32MZ using XC32 3.01 and -O3

Is the #define volatile still the suggested fix with the latest LTS FreeRTOS?

Thank you,

Yes, does that not work for you?

Limited testing suggests that it does solve the problem - I only asked because you said a null check should be added, which made me think you didn’t feel the volatile was the best solution.

Apologies. What I meant in my above response was not adding the check as we always ensure that list is not empty before calling the macro. I have updated my response above.