On Thu, 4 Sept 2025, 18:02 Iain Sandoe, <[email protected]> wrote:
> The facility (with the original shorter name) has been in use on the
> contracts development branch for almost a year, and has been tested in
> isolation on x86_64-darwin and powerpc64le-linux.
> OK for trunk?
> thanks
> Iain
>
> --- 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.h (__glibcxx_observable_checkpoint,
> __cpp_lib_observable_checkpoint,
> __glibcxx_want_observable_checkpoint): New.
>
This file is auto-generated from bits/version.def
* include/std/utility: Add std::observable_checkpoint().
>
> Signed-off-by: Iain Sandoe <[email protected]>
> ---
> libstdc++-v3/include/bits/version.h | 10 ++++++++++
> libstdc++-v3/include/std/utility | 19 +++++++++++++++++++
> 2 files changed, 29 insertions(+)
>
> diff --git a/libstdc++-v3/include/bits/version.h
> b/libstdc++-v3/include/bits/version.h
> index c7569f42773..a1afbf44c8e 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 >= 202400L) &&
> (__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
> + {
> + return __builtin_observable_checkpoint();
> + }
> +#endif
> +
> _GLIBCXX_END_NAMESPACE_VERSION
> } // namespace
>
> --
> 2.39.2 (Apple Git-143)
>
>