On Thu, Oct 04, 2012 at 10:42:59AM +0200, Richard Guenther wrote:
> On Wed, Oct 3, 2012 at 9:00 PM, Jason Merrill <ja...@redhat.com> wrote:
> If the result is not needed, are we allowed to remove a call to this
> function?

No.  Unless you know the same function has been already called.

> So - what's wrong with using pure?  That it doesn't "feel" correct?

No, it can modify memory.
Consider:

a.h:
extern int g;
struct S
{
  S () { __atomic_add_fetch (&g, 1, __ATOMIC_RELAXED); s = 7; }
  int s;
};
extern thread_local S s;

liba.C:
#include "a.h"
thread_local S s;

libb.C:
#include "a.h"

int g;

void
foo (S *&p, S *&q, int &a, int &b)
{
  a = g;
  p = &s; // this runs S::S() in the current thread
  b = g;
  q = &s;
}

I think the plan was for these functions not to return any value,
so that they could be aliases for all thread_local vars defined in the same
TU.  Then you really can't DCE the first call, you can the second call.
If it returns void, CSEable is probably a bad word.
Even if it returns value and the value is unused, it still needs to be
called the first time in a function, and can modify anything the ctor(s)
can modify.

        Jakub

Reply via email to