This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Make attribute functions pure
- From: kenner at vlsi1 dot ultra dot nyu dot edu (Richard Kenner)
- To: paul at codesourcery dot com
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 23 Jul 04 08:42:25 EDT
- Subject: 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.