> Am 26.10.2024 um 17:30 schrieb Iain Sandoe <i...@sandoe.co.uk>:
>
> Hi,
>
> The background here is that I made a trial implementation of P1494r4 -
> std::observable() - and want to produce testcases.
>
> —— so …..
>
> I am looking for either examples where GCC produces time-travel optimisation
> (or alternately some evidence that these are not expected).
>
> (In case someone is not familiar with the time-travel analogy) a simple
> example from P1494:
>
> void b(int &r, int *p) {
> if (!p) std::fprintf(stderr, "count: %d\n", ++r);
> if (!p) std::fprintf(stderr, "p is null\n");
> *p += r; // p may be assumed non-null
> }
>
> Since dereferencing p is UB, the compiler may assume that p is non-null - and
> therefore elide the check(s) before (thus time-travel).
>
> In practice, (at least on the platform I am testing on) GCC trunk does not
> do this - it does reorder code to eliminate the second null test - but it
> still prints both sets of output.
I think we at least do not optimistically propagate backwards - that is, the
conditional code may not exit or infinitely loop. Printf due to callbacks
might, so I suggest to rework to tell GCC the conditional code will still make
sure the dereference is reached.
Richard
> TIA
> Iain
>