Functions that are CSEable but not pure
Jason Merrill
jason@redhat.com
Thu Oct 4 18:02:00 GMT 2012
On 10/04/2012 01:42 PM, Richard Guenther wrote:
> So I suppose the testcase that would be "valid" but break with using
> pure would be instead
>
> int main()
> {
> int x = init_count;
> int *p = get_me();
> if (init_count == x)
> __builtin_abort();
> int *q = get_me();
> if (init_count == x)
> __builtin_abort();
> }
>
> here when get_me is pure we CSE init_count over the _first_ call of get_me.
That's OK for C++ thread_local semantics; the initialization is
specified to happen some time before the first use, so the testcase is
making an invalid assumption. This might not be desirable for
user-written singleton functions, though.
Jason
More information about the Gcc
mailing list