-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Digital(Read/Write)Fast works under -0s, but fails to compile under -03 or -02. #190
Comments
Not really. I've only tested the source code using -Os. The MegaCoreX Arduino IDE addon doesn't let the user change the optimization. |
Gotcha. I'm using PlatformIO, so I'll look into options for changing the build flag for the wiring_digital.c file specifically. Thanks! |
Yes, PlatformIO is really neat, and gives you a whole new level of freedom! |
Yes, I've been quite happy with it! The flexibility and the reproducibility is so much nicer than trying to work with Arduino in my (limited) experience with Arduino. Yeah, it does seem rather odd. I tried experimenting with removing the check, and that seems to work fine as a workaround. Cool, thanks for the tip! |
So this is really strange, I tried to reproduce this but I can only do so when link time optimization is turned off. But in the original post it is turned on... The builtin is a strange one so I decided to look at the gcc docs on __builtin_constant_p and found something very interesting:
...
My guess is that somehow -Os works fine but is buggy for -O2 and -O3 on the original poster's machine with LTO enabled. On my machine, it is buggy without LTO... that smells like a compiler bug of some kind. |
My experience attempting to make digitalWriteFast and it's ilk work under -O3 and -O2 was entirely unsuccessful. They also don't work if you turn off LTO. |
I'm a bit baffled as to what the compiler is optimizing that would cause this.
it fails even with a very basic test case,
I have also tried using
#DEFINE
s andconstexpr
s, but to no avail.Any ideas?
The text was updated successfully, but these errors were encountered: