[PATCH] Make attribute functions pure
Paul Brook
paul@codesourcery.com
Fri Jul 23 20:40:00 GMT 2004
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
More information about the Gcc-patches
mailing list