On Mon, 8 Sept 2025 at 14:46, Richard Biener <richard.guent...@gmail.com> wrote:
> > It's not just to cater to FUD. I have seen Clang remove a complete CFG
> > edge that lead to a non-return from
> > a non-void function. If observable_checkpoint works correctly, the
> > debug prints my junior colleague added trying
> > to see how the execution flows would've worked when used with the
> > checkpoint, whereas clang happily
> > removed them along with everything else on that CFG edge proven to
> > lead to UB. I am unable to find
> > any specification rationale that would make such a transformation
> > incorrect, and with observable_checkpoint,
> > that situation changes.
>
> So the situation is sth like
>
> int foo ()
> {
>   printf ("what?");
> }
>
> that was optimized away completely by clang and you want to fix that with
>
> int foo ()
> {
>   printf ("what?");
>   std::observable_checkpoint ();
> }
>
> ?  But this is again a clang bug.  printf could call
> std::observable_checkpoint () itself, no?
> Even if clang can conclude that printf("what?") always will return
> normally there's a
> side-effect to be preserved (printing 'what?').
>
> If this isn't the actual testcase, can you share it?  I do not see
> clang (version 19)
> optimizing away the printf in the above testcase.

I don't have the exact testcase, because it wasn't ever a compiler
testcase, just an ad-hoc one that
was used to investigate https://codereview.qt-project.org/c/qt/qtbase/+/331906

But I can (more slowly) dig up what the other developer tried to use
for the prints. It isn't printf, printf doesn't trigger
the problem because optimizers know what printf is. The print function
was some android-specific logging
function that clang didn't recognize as an i/o function that should've
just effected<sic> the barrier automatically.

So, at the end of the day, even if it was some clang bug where it
over-eagerly nuked a whole CFG path even with
an opaque or a side-effectful call on it, such things happen in
practice, and *maybe* they happen less likely
if compilers recognize an observable_checkpoint(). Maybe.

Reply via email to