[PATCH 1/2] c++: Implement P1494 and P3641 Partial program correctness [PR119060].
Florian Weimer
fweimer@redhat.com
Fri Sep 5 09:38:01 GMT 2025
* Iain Sandoe:
>> On 5 Sep 2025, at 10:07, Florian Weimer <fweimer@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.
Jakub and the compiler disagree. 8-)
I don't think the test case (without the static) is valid: the write to
x is not considered observable behavior by the standard. Even without a
closed-world assumption, there is no synchronization with other threads,
so if they produce observable behavior in relation to x, it does not
become part of the observable prefix.
Thanks,
Florian
More information about the Libstdc++
mailing list