This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC] Modeling the behavior of function calls
- From: Joe Buck <Joe dot Buck at synopsys dot COM>
- To: Diego Novillo <dnovillo at google dot com>
- Cc: gcc at gcc dot gnu dot org, Xinliang David Li <davidxl at google dot com>, Robert Hundt <rhundt at google dot com>
- Date: Tue, 29 Apr 2008 10:31:55 -0700
- Subject: Re: [RFC] Modeling the behavior of function calls
- References: <48161FD8.4000302@google.com>
On Mon, Apr 28, 2008 at 03:04:56PM -0400, Diego Novillo wrote:
> [ Apologies if this comes out twice. I posted this message last week,
> but I think it was rejected because of a .pdf attachment. ]
>
> We have been bouncing ideas for a new mechanism to describe the behavior
> of function calls so that optimizers can be more aggressive at call
> sites. Currently, GCC supports the notion of pure/impure,
> const/non-const, but that is not enough for various cases.
>
> The main application for this would be stable library code like libc,
> that the compiler generally doesn't get to process.
...
> The main idea is to add a variety of attributes to describe contracts
> for function calls. When the optimizers read in the function
> declaration, they can take advantage of the attributes and adjust the
> clobbering effects of call sites.
Such a facility can have other uses, particularly for static analysis,
by allowing simple preconditions and postconditions to be specified.
For example:
* a returned pointer is guaranteed to be non-null.
* a supplied pointer is always dereferenced.
* a supplied pointer must be dereferenceable on input, and that pointer
is no longer dereferenceable after return, e.g. free().
Of course, there's a tradeoff between implementation complexity and
features, as always. While these facilities might help the optimizer,
the compiler could also issue warnings if it detects that a precondition
must be violated (and this can also be used to check the correctness
of any user-supplied annotations).