[Bug middle-end/64463] Add warning: returns_nonnull attribute on a function compared against NULL
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64463 Martin Sebor changed: What|Removed |Added Last reconfirmed|2015-07-25 00:00:00 |2021-4-8 Blocks||87403 --- Comment #6 from Martin Sebor --- No progress in GCC 11. Clang issues -Wpointer-bool-conversion for these cases: $ cat pr64463.c && clang -S -Wall pr64463.c __attribute__ ((returns_nonnull)) char* f (void); void g (void) { if (!f ()) __builtin_abort (); } pr64463.c:5:8: warning: nonnull function call 'f()' will evaluate to 'true' on first encounter [-Wpointer-bool-conversion] if (!f ()) ~^~~~ pr64463.c:1:17: note: declared 'returns_nonnull' here __attribute__ ((returns_nonnull)) char* f (void); ^ 1 warning generated. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403 [Bug 87403] [Meta-bug] Issues that suggest a new warning
[Bug middle-end/64463] Add warning: returns_nonnull attribute on a function compared against NULL
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64463 --- Comment #5 from Jonathan Wakely --- (In reply to Jonathan Wakely from comment #4) > Incorrectly putting the attribute on the function is likely to be much rarer > than unnecessarily checking the result. And PR 84202 would address the problem of incorrectly placing the attribute, and would be based on the definition, not how the callers use it.
[Bug middle-end/64463] Add warning: returns_nonnull attribute on a function compared against NULL
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64463 --- Comment #4 from Jonathan Wakely --- (In reply to Reini Urban from comment #0) > I would like to see a warning when a returns_nonnull function is compared > against a NULL value, and then actual code is removed or skipped based on > that attribute. I don't care if any code is removed or skipped, I want the warning anyway. If the code isn't removed then it means you're performing unnecessary work, pessimising your code. > Which is either a difficult to diagnose declaration error, > or a logical error in the usage. > > warning: returns_nonnull attribute on a function compared against NULL This wording seems to be aimed at the author of the function, suggesting that the attribute might be misplaced. I think the warning should instead be aimed at the caller, telling them to remove the redundant check. Incorrectly putting the attribute on the function is likely to be much rarer than unnecessarily checking the result.
[Bug middle-end/64463] Add warning: returns_nonnull attribute on a function compared against NULL
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64463 --- Comment #3 from Jonathan Wakely --- I created the very similar PR 86879 for the C++ front-end (it also covers an additional case, where a function returns a reference and the address is compared to null).
[Bug middle-end/64463] Add warning: returns_nonnull attribute on a function compared against NULL
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64463 Andrew Pinski changed: What|Removed |Added Keywords||diagnostic Severity|normal |enhancement
[Bug middle-end/64463] Add warning: returns_nonnull attribute on a function compared against NULL
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64463 Manuel López-Ibáñez manu at gcc dot gnu.org changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2015-07-25 CC||manu at gcc dot gnu.org Blocks||58689 Ever confirmed|0 |1 --- Comment #1 from Manuel López-Ibáñez manu at gcc dot gnu.org --- Confirmed. Related to PR17308. This is one of the things requested in PR58689. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58689 [Bug 58689] Enhance returns_nonnull
[Bug middle-end/64463] Add warning: returns_nonnull attribute on a function compared against NULL
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64463 --- Comment #2 from Manuel López-Ibáñez manu at gcc dot gnu.org --- This is handled before reaching the middle-end, thus it would need to be detected in the FE.