Skip to content

Test fails to start with build option -ffast-math #85

@Foaly

Description

@Foaly

Hey there!

I am observing some weird behaviour that looks like a bug to me.
I have a main.cpp and a test.cpp file, which both compile and execute fine on my Teensy 4.1. They both produce the expected output. As soon as I add the line build_flags = -ffast-math to my platformio.ini my test breaks, while my main file still executes as expected (I can even measure the expected performance increase). Now the way the test breaks is what strikes me as odd. It compiles and uploads just fine. But then the Teensy seems to be just dead. It does not connect to the serial monitor or produce any other sort of output. I can still press the button and set it into bootloader mode and flash a new firmware, but other than that there is no response.

I know -ffast-math is considered an unsafe option, but what makes me wonder is that the behaviour between compile+upload and compile+upload+test is so different. It feel a lot like a weird bug.

Does anybody have an idea what could be causing this?


I did some more testing and here are my findings.
For my setup I am running a minimal example like this:
test/test.cpp

#include <Arduino.h>
void setup() {
    Serial.println("Hello!");
}
void loop() {
    Serial.println("Weeeeeeehhh");
}

platformio.ini

[env:teensy41]
platform = teensy
board = teensy41
framework = arduino
upload_protocol = teensy-cli

As discribed the above example works fine. If I add the line build_flags = -ffast-math to the bottom of the platformio.ini the described breakage occures when running the test using pio test -v.
Since according to the GCC Optimize Options -ffast-math is a combination of flags I tested the individual flags and this is the result:

Flag Result
-fno-math-errno causes the error
-funsafe-math-optimizations causes the error
-ffinite-math-only causes the error
-fno-rounding-math good
-fno-signaling-nans good
-fcx-limited-range good
-fexcess-precision=fast good

Thanks a lot to maxgerhardt who helped me on the platformio community forum. For more info see this thread: https://community.platformio.org/t/test-fails-to-start-with-build-option-ffast-math/25342

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions