This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/84202] New: missing -Wnonnull on a returns_nonnull function returning null
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 04 Feb 2018 23:04:05 +0000
- Subject: [Bug tree-optimization/84202] New: missing -Wnonnull on a returns_nonnull function returning null
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84202
Bug ID: 84202
Summary: missing -Wnonnull on a returns_nonnull function
returning null
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
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.
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
}