This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pure and const functions


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)
      && expression_which_would_be_provably_false_if_it_had_been_written_first)
    {
      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.

zw


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]