-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Spurious -Wmaybe-uninitialized warning #276
Comments
Hi @chrisjbillington - thanks for the detailed report! I agree with your assessment; I've seen that when doing an LTO link, GCC seems to "forget" the warning suppressions that come in from the command line. Perhaps it's a different code path or something :( I'd prefer option one (of the two you presented) in general for safety, tiptoeing around uninitialized memory doesn't make me feel great, despite it leading to small binaries. The last time I messed around with initialization, it caused a measurable size increase that I didn't really want to pay for, though. That was a few versions of GCC ago, though, and sometimes we can sneak things like that into the text stream without any impact, so it's worth a shot. Option two is interesting, though- I didn't realize that "assume" could suppress warnings like that; I thought it was just for code-gen! If it shuts GCC up, though, then I'm happy to pull it in. Do you have an appetite for exploring this stuff? I'd be happy to take a pull request. If not, I can probably get to playing with it in the next few days, perhaps this weekend sometime. |
A little bit of exploration, I checked to see how program size for my project with various optimisation options is affected by whether the struct is zero-initialised or not. The answer at least for my project is "not much": This is the file size of the .bin file as extracted with
And very similar results with an older gcc from Ubuntu 22.04:
This is just one project and I don't know how its use of nanoprintf differs from other projects - I'm only using it for debug printlines, which are all funnelled through a DEBUG function that wraps npf_vsnprintf. So it seems like initialising is perhaps fine. Pull request here: #277 |
Hi @chrisjbillington - could I ask you to try this PR and see if it fixes your issue? I'd rather make the smallest change possible; this one keeps the binary sizes the same because it just moves the specific initialization into a common path. If it works for you, I'll merge it and cut a release! If not, please let me know and we can brainstorm other solutions. |
Yep, that one works for me! Sounds like a good solution. |
Merged to main, cutting a new release now. |
https://github.com/charlesnicholson/nanoprintf/releases/tag/v0.5.4 Thanks for raising the issue! |
Thanks for the fix and release, much appreciated! |
I'm using nanoprintf 0.5.3 and gcc 14:
including nanoprintf in one of my .c files as:
and compiling with (includes and source files omitted):
I get this
-Wmaybe-uninitialized
warning:despite the fact that nanoprintf.h appears to contain directives to suppress this warning, which, it seems that due to aggressive optimisation, don't propagate to where they need to be to suppress the warning in all contexts.
Possible solutions:
The text was updated successfully, but these errors were encountered: