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: [PATCH] Make attribute functions pure


[Moved from gcc-patches to gcc.]

    > I don't see how.  It's usually accepted that pure functions can be
    > memoized. Can you give an example of the sort of miscompilation you're
    > worried about?

    $ cat impure.c

Sorry, I obviously must not have been clear. I perfectly well understand that
pure functions can't have side effects of the sort you show.

But what was I asking for are examples of miscompilations caused by
*memoization* in pure functions.

To be clear, by "memoization" I mean the storing of the result that the
function returns so that it can return the same value in a later invokation
with the same parameters.

In other words, suppose I have a version of sqrt that stores its last input
and output in a global variable and checks to see if its next input was the
same as its last input and, if so, returns the last output.

Does doing that make it impure?  I don't see how and would like an example of
how that can cause miscompilations.


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