> On 5 Sep 2025, at 10:07, Florian Weimer <fwei...@redhat.com> wrote:
>
> * Iain Sandoe:
>
>> diff --git a/gcc/testsuite/g++.dg/cpp26/observable-checkpoint.C
>> b/gcc/testsuite/g++.dg/cpp26/observable-checkpoint.C
>> new file mode 100644
>> index 00000000000..886cda7ae33
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.dg/cpp26/observable-checkpoint.C
>> @@ -0,0 +1,24 @@
>> +// P1494R5+P3641R0 - Partial program correctness.
>> +// { dg-do compile { target c++11 } }
>> +// { dg-additional-options "-fdump-tree-optimized -Wno-return-type -O" }
>> +// { dg-final { scan-tree-dump {\+\s42} "optimized" } }
>> +// { dg-final { scan-tree-dump {__builtin_observable_checkpoint}
>> "optimized" } }
>> +
>> +int x = 0;
>> +
>> +int
>> +here_b_ub ()
>> +{
>> + // missing return triggers UB (we must ignore the warning for this test).
>> +}
>> +
>> +int
>> +main ()
>> +{
>> + __builtin_printf (" start \n");
>> + x += 42;
>> + // Without this checkpoint the addition above is elided (along with the
>> rest
>> + // of main).
>> + __builtin_observable_checkpoint ();
>> + here_b_ub ();
>> +}
>
> What happens if you have this?
>
> static int x = 0;
>
> Does the linkage matter?
I don’t think it does.
The only purpose of that global is to provide a mechanism to have something that
we can (in the testsuite) detect that the checkpoint has worked. Without the
checkpoint
the UB from the inlined here_b_ub() causes the addition to be elided (we end up
with a
call to puts() and then fall off the end of main())
Iain
>
> Thanks,
> Florian
>