TeensyThreads causes errors building in Platform.IO

impcc

Active member
The code is as simple as this:

Code:
#include <TeensyThreads.h>

And what I see when I go to build, I get all these warnings. I'm one of those "no warnings" people, so while it compiles successfully, I'm left left a little twitchy.

Code:
.pio/libdeps/teensy41/TeensyThreads/TeensyThreads.cpp: In member function 'void Threads::idle()':
.pio/libdeps/teensy41/TeensyThreads/TeensyThreads.cpp:682:7: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  682 |       if (! threadp[i]) continue;
      |       ^~
.pio/libdeps/teensy41/TeensyThreads/TeensyThreads.cpp:683:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  683 |                         if (threadp[i]->sleep_time_till_end_tick > threadp[j]->sleep_time_till_end_tick) {
      |                         ^~
.pio/libdeps/teensy41/TeensyThreads/TeensyThreads.cpp:715:7: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  715 |       if (! threadp[i]) continue;
      |       ^~
.pio/libdeps/teensy41/TeensyThreads/TeensyThreads.cpp:716:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  716 |                         if (needs_run[i]) {
      |                         ^~
.pio/libdeps/teensy41/TeensyThreads/TeensyThreads.cpp: At global scope:
.pio/libdeps/teensy41/TeensyThreads/TeensyThreads.cpp:371:13: warning: 'void context_pit_empty()' defined but not used [-Wunused-function]
  371 | static void context_pit_empty() {}
      |             ^~~~~~~~~~~~~~~~~
.pio/libdeps/teensy41/TeensyThreads/TeensyThreads.cpp: In constructor 'Threads::Threads()':
.pio/libdeps/teensy41/TeensyThreads/TeensyThreads.cpp:262:42: warning: array subscript -2560 is outside array bounds of 'long unsigned int [1]' [-Warray-bounds]
  262 |   threadp[0]->stack = (uint8_t*)&_estack - DEFAULT_STACK0_SIZE;
      |                       ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
.pio/libdeps/teensy41/TeensyThreads/TeensyThreads.cpp:66:22: note: while referencing '_estack'
   66 | extern unsigned long _estack;   // the main thread 0 stack
      |                      ^~~~~~~
.pio/libdeps/teensy41/TeensyThreads/TeensyThreads.cpp:482:6: warning: array subscript -2560 is outside array bounds of 'long unsigned int [1]' [-Warray-bounds]
  482 |   *m = thread_marker;
      |   ~~~^~~~~~~~~~~~~~~
.pio/libdeps/teensy41/TeensyThreads/TeensyThreads.cpp:66:22: note: while referencing '_estack'
   66 | extern unsigned long _estack;   // the main thread 0 stack
      |                      ^~~~~~~

Any ideas on how to get these to go away, even if it's just using some sort of #pragma to suppress the warning?

Thanks for helping!

-Ian
 
Are you sure that you are using the version of TeensyThreads installed by TD (1.59 - using the latest ??) ??

Mark J Culross
KD5RXT

P.S. I don't use PlatformIO for building, so as a comparison, I tested the compilation using the Arduino IDE (1.8.19 w/ TD 1.59). No errors/warnings are generated, no matter the optimization selection. Maybe your question might be better posted to PlatformIO.

Your single-line is not a valid Arduino sketch. Here's the test sketch that I used (you didn't post a complete sketch, but this is probably a safe assumption, and is included here for completeness):

Code:
#include <TeensyThreads.h>

void setup() {
   // put your setup code here, to run once:

}

void loop() {
   // put your main code here, to run repeatedly:

}
 
Your single-line is not a valid Arduino sketch.
I think this is just down to the differences between the Arduino IDE and PlatformIO.

Maybe it's just me, but I find the Arduino IDE absolutely infuriating to even try to use. PlatformIO, when it works, is a much more familiar experience. That said, I realize it's a minority experience, so I'm not trying to be indignant, just trying to figure out how to move forward. (I'm also stunned that PlatformIO is still using GCC and not Clang, but that's a topic for another day.)

I had to edit files in TeensyThreads with stuff like:

Code:
#pragma GCC diagnostic ignored "-Warray-bounds"
...
#pragma GCC diagnostic pop

#pragma GCC diagnostic ignored "-Wunused-function"
...
#pragma GCC diagnostic pop

And so on. It's solved my issue for the moment, but it'll make it that much harder to stay up to date as libraries change.

-Ian
 
Back
Top