[PATCH 2/2 v2] libstdc++: Implement P1494 and P3641 Partial program correctness [PR119060]
Jonathan Wakely
jwakely@redhat.com
Mon Sep 8 12:31:28 GMT 2025
On Mon, 8 Sept 2025 at 07:42, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>
>
>
> On Sun, 7 Sept 2025, 20:46 Iain Sandoe, <iains.gcc@gmail.com> wrote:
>>
>> Thanks to reviewers for feedback.
>>
>> Version 2 changes;
>> use version.def to add the library versioning information.
>>
>> --- 8< ---
>>
>> This implements the library parts of P1494 as amended by P3641. For GCC the
>> compiler itself treats stdio operations as equivalent to the observable
>> checkpoint and thus it does not appear to be necessary to add calls to those
>> functions (it will not alter the outcome).
>>
>> This adds the facility for C++26, although there is no reason, in principle,
>> that it would not work back to C++11 at least.
>>
>> PR c++/119060
>>
>> libstdc++-v3/ChangeLog:
>>
>> * include/bits/version.def: Add observable_checkpoint at present
>> allowed from C++11.
>> * include/bits/version.h: Regenerate.
>> * include/std/utility: Add std::observable_checkpoint().
>>
>> Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
>> ---
>> libstdc++-v3/include/bits/version.def | 9 +++++++++
>> libstdc++-v3/include/bits/version.h | 10 ++++++++++
>> libstdc++-v3/include/std/utility | 19 +++++++++++++++++++
>> 3 files changed, 38 insertions(+)
>>
>> diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def
>> index 8707a123109..c085e3dfcd7 100644
>> --- a/libstdc++-v3/include/bits/version.def
>> +++ b/libstdc++-v3/include/bits/version.def
>> @@ -1899,6 +1899,15 @@ ftms = {
>> };
>> };
>>
>> +ftms = {
>> + name = observable_checkpoint;
>> + values = {
>> + v = 202506;
>> + cxxmin = 11;
>
>
> This affects when the macro is defined, which affects when the function is defined. But it's not a reserved name in C++11 so we shouldn't declare it.
>
> So this should be cxxmin = 26
>
>
>> + extra_cond = "__has_builtin(__builtin_observable_checkpoint)";
>> + };
>> +};
>> +
>> ftms = {
>> name = algorithm_default_value_type;
>> values = {
>> diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h
>> index c7569f42773..107646960f3 100644
>> --- a/libstdc++-v3/include/bits/version.h
>> +++ b/libstdc++-v3/include/bits/version.h
>> @@ -2123,6 +2123,16 @@
>> #endif /* !defined(__cpp_lib_unreachable) && defined(__glibcxx_want_unreachable) */
>> #undef __glibcxx_want_unreachable
>>
>> +#if !defined(__cpp_lib_observable_checkpoint)
>> +# if (__cplusplus >= 201103L) && (__has_builtin(__builtin_observable_checkpoint))
>> +# define __glibcxx_observable_checkpoint 202506L
>> +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_observable_checkpoint)
>> +# define __cpp_lib_observable_checkpoint 202506L
>> +# endif
>> +# endif
>> +#endif /* !defined(__cpp_lib_observable_checkpoint) && defined(__glibcxx_want_observable_checkpoint) */
>> +#undef __glibcxx_want_observable_checkpoint
>> +
>> #if !defined(__cpp_lib_algorithm_default_value_type)
>> # if (__cplusplus > 202302L)
>> # define __glibcxx_algorithm_default_value_type 202403L
>> diff --git a/libstdc++-v3/include/std/utility b/libstdc++-v3/include/std/utility
>> index 8a85ccfd09b..4a33a369f9c 100644
>> --- a/libstdc++-v3/include/std/utility
>> +++ b/libstdc++-v3/include/std/utility
>> @@ -98,6 +98,7 @@
>> #define __glibcxx_want_tuple_element_t
>> #define __glibcxx_want_tuples_by_type
>> #define __glibcxx_want_unreachable
>> +#define __glibcxx_want_observable_checkpoint
>> #define __glibcxx_want_tuple_like
>> #define __glibcxx_want_constrained_equality
>> #include <bits/version.h>
>> @@ -234,6 +235,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>> }
>> #endif
>>
>> +
>> +#ifdef __cpp_lib_observable_checkpoint // C++ >= 26
>> + /// Informs the compiler that prior actions are considered observable.
>> + /**
>> + * This may be used to limit the extent to which optimisations based on the
>> + * assumed unreachability of undefined behaviour can propagate to earlier
>> + * code.
>> + *
>> + * @since C++26
>> + */
>> + [[__gnu__::__always_inline__]]
>> + inline void
>> + observable_checkpoint() _GLIBCXX_NOTHROW
>
>
> This can be just noexcept because it doesn't need to be compiled as C++98.
>
> OK with those changes.
Oh we also need to add the new name to src/c++23/std.cc.in
--- a/libstdc++-v3/src/c++23/std.cc.in
+++ b/libstdc++-v3/src/c++23/std.cc.in
@@ -3327,6 +3327,9 @@ export namespace std
#if __cpp_lib_unreachable
using std::unreachable;
#endif
+#if __cpp_lib_observable_checkpoint
+ using std::observable_checkpoint;
+#endif
}
// <valarray>
More information about the Libstdc++
mailing list