This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Make attribute functions pure
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Kenner <kenner at vlsi1 dot ultra dot nyu dot edu>
- Cc: paul at codesourcery dot com, gcc-patches at gcc dot gnu dot org, gcc at gcc dot gnu dot org
- Date: Fri, 23 Jul 2004 13:13:35 +0200
- Subject: Re: [PATCH] Make attribute functions pure
- References: <10407231255.AA27336@vlsi1.ultra.nyu.edu>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Fri, Jul 23, 2004 at 08:55:54AM -0400, Richard Kenner wrote:
> > Does doing that make it impure? I don't see how and would like an
> > example of how that can cause miscompilations.
>
> As you describe it, no. However if you store the inputs, outputs and *any
> global variables it or its children look at* in *static local* variables,
> that should be ok.
>
> All you have to do is define the usage of the function so that nothing
> is permitted to depend on anything it sets in global memory.
>
> recog_memoized certainly meets that requirement.
>
> So I don't see what's wrong with this patch.
recog_memoized is pure and you do:
recog_memoized (insn);
...
code = INSN_CODE (insn);
then the compiler is allowed to reorder these, so that INSN_CODE (insn)
is first read and then recog_memoized is called.
I believe if you don't use the return value of recog_memoized,
the compiler is allowed not to call the function at all.
Jakub