This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Add check_result attribute
- From: Andrew Pinski <apinski at apple dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Andrew Pinski <apinski at apple dot com>, Richard Henderson <rth at redhat dot com>, gcc-patches at gcc dot gnu dot org
- Date: Fri, 12 Sep 2003 13:39:11 -0700
- Subject: Re: [PATCH] Add check_result attribute
On Friday, September 12, 2003, at 11:27 AM, Jakub Jelinek wrote:
Hi!
Some functions (e.g. in Linux kernel various uaccess.h
functions/macros or
realloc) callers should never ignore their return values, as it is
either
security problem or always a bug.
This patch adds a function attribute so that such function can be
marked
and gcc issue warnings whenever their results are discarded.
It is possible to even check result of statement expressions etc.,
assuming
their return type is known, e.g. by writing:
extern inline __attribute__((always_inline, check_result)) int
check_int_result (int arg) { return arg; }
#define get_user(val, addr) check_int_result (({ ... }))
Bootstrapped/regtested on i386-redhat-linux, no regressions.
Ok to commit?
I thought this one of the patches we did not want.
From <http://gcc.gnu.org/onlinedocs/gcc/Non-bugs.html>:
Warning when a non-void function value is ignored.
Coming as I do from a Lisp background, I balk at the idea that there is
something dangerous about discarding a value. There are functions that
return values which some callers may find useful; it makes no sense to
clutter the program with a cast to void whenever the value isn't useful.
Thanks,
Andrew Pinski