Open ScumCoder opened 9 months ago
Can confirm this unwanted behavior.
Stumbling on the same problem at the moment. The issue checklist actually prevented me from opening a duplicate :wink:
So the offending line is: https://github.com/espressif/esp-idf/blob/master/components/esp_hw_support/include/spinlock.h#L135
This is broken since IDF 5.0 (==the existence of the spinlock.h file) so it affects 5.0, 5.1, 5.2, 5.3, 5.4, develop.
the FreeRTOS source code itself
This is misleading: The spinlock.h is in 100% control and responsibility of Espressif. However, it has some interaction with FreeRTOS via the portable implementation. Intuitively I would say that timeout should be esp_cpu_cycle_count_t as well with SPINLOCK_WAIT_FOREVER=UINT32_MAX (==-1 ABI compatible) but this would be a bit more complicated.
So the easy fix - doing a cast before the compare - remains:
diff --git a/components/esp_hw_support/include/spinlock.h b/components/esp_hw_support/include/spinlock.h
index 7501faabea..fb4585b41e 100644
--- a/components/esp_hw_support/include/spinlock.h
+++ b/components/esp_hw_support/include/spinlock.h
@@ -132,7 +132,7 @@ static inline bool __attribute__((always_inline)) spinlock_acquire(spinlock_t *l
break;
}
// Keep looping if we are waiting forever, or check if we have timed out
- } while ((timeout == SPINLOCK_WAIT_FOREVER) || (esp_cpu_get_cycle_count() - start_count) <= timeout);
+ } while ((timeout == SPINLOCK_WAIT_FOREVER) || (esp_cpu_get_cycle_count() - start_count) <= ((esp_cpu_cycle_count_t) timeout));
exit:
if (lock_set) {
If you fix this can you please backport it to all 5.x versions? It would be great, if I don't need to weaken my build configuration for this header.
@Harshal5 you did such a great and fast job last time - do you think you can help out here as well?
Also linking https://github.com/espressif/esp-idf/pull/11239 which will fix the fact that the warning is not enabled in IDF by default in the first place.
Hi @ScumCoder @M-Bab! I will help to fix the warnings. Thanks for the report. Yes, I think we can backport it to v5.x as well.
Answers checklist.
General issue report
ESP-IDF version: Latest stable (5.1.2) Steps to reproduce: Try to build the following MWE:
with the following commands added to
CMakeLists.txt
:Expected result: The compilation process crashes with the following error:
Actual result: The program builds without any warnings. If flashed to an uC (ESP32), the monitor shows
This is already a very serious issue, because GCC documentation states that specifying both
-Wall
and-Wextra
must guarantee that-Wsign-compare
is going to be enabled both for C and C++. But that's not the worst part.Specifying
in
CMakeLists.txt
actually enables the proper warning behavior. However, then it becomes impossible to compile the project because the FreeRTOS source code itself contains violations of the comparison signedness correctness; the compilation process crashes with the following error: