Description
This function is declared to have return value bool
ArduinoCore-renesas/libraries/RTC/src/RTC.cpp
Lines 606 to 613 in 0e9f4df
but there's not a single return
keyword in that function. It ought to do return is_initialized;
at the end.
This incorrect code causes some compilers (arm-none-eabi-gcc 10.3.1) to emit assembly that causes an infinite loop. Any sketch using RTC.begin();
deadlocks forever. Specifically, the assembly is
(Notice how there is no pop {..., pc}
to facilitate any returning in that function. After writing true
, the code immediately writes false
and jumps back to the beginingo of the code that writes false
, thus being stuck forever at that line of C++ code). When I fix the code
It does nicely return.
This code is undefined behavior which does happpen to work on the compiler version used in the Arduino IDE (7.0.1), however, the higher version one used in PlatformIO (10.3.1) breaks with it. (We upgraded it because, what could possible go wrong? Well, this). And of course, if this core ever decides to upgrade its compiler, this unfixed code is a ticking timebomb.