This is the mail archive of the
mailing list for the GCC project.
Re: Attribute returns_null
- From: Jeff Law <law at redhat dot com>
- To: David Malcolm <dmalcolm at redhat dot com>
- Cc: Marc Glisse <marc dot glisse at inria dot fr>, gcc-patches at gcc dot gnu dot org
- Date: Mon, 07 Oct 2013 12:57:46 -0600
- Subject: Re: Attribute returns_null
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot DEB dot 2 dot 02 dot 1310071600430 dot 22663 at stedding dot saclay dot inria dot fr> <1381166322 dot 2732 dot 27 dot camel at surprise> <alpine dot DEB dot 2 dot 10 dot 1310071940290 dot 4148 at laptop-mg dot saclay dot inria dot fr> <1381171057 dot 2732 dot 46 dot camel at surprise>
On 10/07/13 12:37, David Malcolm wrote:
This seems to have dubious value to me -- ie, I don't think there's many
functions that always return NULL in practice and of those, I doubt
there's a lot of opportunity to optimize with that knowledge.
On Mon, 2013-10-07 at 19:51 +0200, Marc Glisse wrote:
On Mon, 7 Oct 2013, David Malcolm wrote:
On Mon, 2013-10-07 at 16:17 +0200, Marc Glisse wrote:
this patch adds an attribute to let the compiler know that a function
never returns NULL. I saw some ECF_* flags, but the attribute seems
sufficient. I considered using nonnull(0), but then it would have been
confusing that the version of nonnull without arguments applies only to
parameters and not the return value.
I can't comment on the patch itself, but could there also be an
attribute "returns_null", for functions that *always* return NULL?
This may sound weird, but I know of at least one API that exposes such
functions: CPython's exception-handling API: see e.g.
and various other functions that have "Return value: Always NULL."
This allows the user to write one-liners like:
I didn't think about it very long, so I probably missed the best reasons,
but it doesn't sound like such a good idea. If PyErr_NoMemory always
returns NULL, why not make that clear in the code? It could be an inline
function, or even a macro that expands to
To me, attributes are there for when the language is insufficient, kind of
a last resort. Could you explain why you think it would be the best option
No, I can't :) (that API predates my involvement in that project).
In contrast, knowing a function can not return null has a ton of value,
both for optimization purposes and for improving warnings.