This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/64463] New: Add warning: returns_nonnull attribute on a function compared against NULL
- From: "rurban at x-ray dot at" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 01 Jan 2015 12:16:22 +0000
- Subject: [Bug middle-end/64463] New: Add warning: returns_nonnull attribute on a function compared against NULL
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64463
Bug ID: 64463
Summary: Add warning: returns_nonnull attribute on a function
compared against NULL
Product: gcc
Version: 4.9.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: rurban@x-ray.at
feature request:
Working on gcc.gnu.org/bugzilla/show_bug.cgi?id=64459 I find it difficult to
find all occurrences of wrong returns_nonnull attributes.
We get those errors, which are fine:
error: returns_nonnull attribute on a function not returning a pointer
But I'm missing the diagnosis of nonnull return values when they are being
wrongly used.
Such as:
__attribute__((returns_nonnull))
char *myfunc() { ...}
if (!myfunc()) {
... /* optimized away */
}
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. 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