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


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


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