[Bug tree-optimization/84202] missing -Wnonnull on a returns_nonnull function returning null
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84202 Martin Sebor changed: What|Removed |Added Last reconfirmed|2018-08-05 00:00:00 |2021-4-8 --- Comment #4 from Martin Sebor --- No progress in GCC 11. Clang diagnoses the first test case: $ cat pr84202.c && clang -S -Wall pr84202.c void* __attribute__ ((returns_nonnull)) f () { return 0; // missing -Wnonnull } pr84202.c:4:3: warning: null returned from function that requires a non-null return value [-Wnonnull] return 0; // missing -Wnonnull ^ ~ 1 warning generated.
[Bug tree-optimization/84202] missing -Wnonnull on a returns_nonnull function returning null
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84202 --- Comment #3 from Eric Gallager --- (In reply to Martin Sebor from comment #0) > GCC silently accepts definitions of functions such as f() below declared > with attribute returns_nonnull. Clang issues -Wnonnull on functions that > trivially violate that guarantee. > > void* __attribute__ ((returns_nonnull)) f () > { > return 0; // missing -Wnonnull > } > > Diagnosing trivial mistakes like the one above is only of very limited > usefulness. GCC can do much better by also diagnosing functions that might > return null such as the two below. Clang doesn't diagnose these. Maybe split it into a separate -Wmaybe-nonnull for the tougher cases. > > void* __attribute__ ((returns_nonnull)) g (unsigned n) > { > return __builtin_malloc (n); // missing -Wnonnull > } > > void* __attribute__ ((returns_nonnull)) h (unsigned n) > { > static char buf[256]; > > return n < sizeof buf ? buf : __builtin_malloc (n); // missing -Wnonnull > }
[Bug tree-optimization/84202] missing -Wnonnull on a returns_nonnull function returning null
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84202 Eric Gallager changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2018-08-05 CC||egallager at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #2 from Eric Gallager --- Confirmed.
[Bug tree-optimization/84202] missing -Wnonnull on a returns_nonnull function returning null
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84202 Martin Sebor changed: What|Removed |Added Blocks||58689 --- Comment #1 from Martin Sebor --- After some searching I came across bug 58689 that suggests the same thing (among other returns_nonnull enhancements). I'm not sure it makes more sense to resolve this bug as a duplicate of it or to treat bug 58689 as a meta-bug and link this and any other smaller reports/requests having to do with returns_nonnull to it. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58689 [Bug 58689] Enhance returns_nonnull