This is the mail archive of the
mailing list for the GCC project.
Re: pure and const functions
- From: Zack Weinberg <zack at codesourcery dot com>
- To: Chris Lattner <sabre at nondot dot org>
- Cc: Tim Hollebeek <tim at hollebeek dot com>, gcc at gcc dot gnu dot org
- Date: Fri, 30 Aug 2002 23:02:18 -0700
- Subject: Re: pure and const functions
- References: <20020426175546.GN26266@codesourcery.com> <Pine.LNX.email@example.com>
On Fri, Apr 26, 2002 at 12:55:51PM -0500, Chris Lattner wrote:
> On Fri, 26 Apr 2002, Zack Weinberg wrote:
> > > Sure, but are there any good examples of a function that would be _useful_
> > > to be marked as pure or const, but which might not return?
> > The examples being kicked around earlier were of routines that were
> > pure except for assertions to enforce data structure integrity. We
> > would like the compiler to optimize on the basis that the data
> > structure is correct and therefore the pure function will always
> > return.
> Ok, now I'm more confused than before. :) When optimizing, do you
> consider it ok for the compiler to drop the assertions in a pure function,
> if it decides to elide the call to the function?
Yes. Generally this comes up in code of the form
if (pure_function_which_contains_assertions (structure)
huge block of code which does something with structure
where 'predicate' contains some assertions. We want GCC to realize
that the entire block is dead code. Losing the assertions is a minor
price to pay.