This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Make attribute functions pure
- From: Paul Brook <paul at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: kenner at vlsi1 dot ultra dot nyu dot edu (Richard Kenner), rsandifo at redhat dot com
- Date: Fri, 23 Jul 2004 13:34:30 +0100
- Subject: Re: [PATCH] Make attribute functions pure
- Organization: CodeSourcery
- References: <10407231213.AA26347@vlsi1.ultra.nyu.edu>
On Friday 23 July 2004 13:13, Richard Kenner wrote:
> GCC assumes that pure functions don't modify memory. And even
> though recog_memoized() conceptually depends only on PATTERN (insn),
> the implementation really does modify insn. Saying that it's pure
> could lead to some subtle miscompilation later.
>
> 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
int i = 0;
int __attribute__((pure))
foo (int n)
{
i = n + 1; /* Illegal - Pure functions shouldn't have side effects. */
return n;
}
int main()
{
int a, b;
a = i;
b = foo(a);
if (a + i + b != 1) abort();
return 0;
}
$ gcc -O2 test.c
$ ./a.out
Aborted
Paul