https://gcc.gnu.org/g:1e84849cb2a1d777b38b45dab8c6e5ecd49b6b77

commit r16-4486-g1e84849cb2a1d777b38b45dab8c6e5ecd49b6b77
Author: Iain Sandoe <[email protected]>
Date:   Thu Sep 4 16:21:16 2025 +0100

    libstdc++: Implement P1494 and P3641 Partial program correctness [PR119060]
    
    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++26.
            * include/bits/version.h: Regenerate.
            * include/std/utility: Add std::observable_checkpoint().
            * src/c++23/std.cc.in: Add obervable_checkpoint () to utility.
    
    Signed-off-by: Iain Sandoe <[email protected]>

Diff:
---
 libstdc++-v3/include/bits/version.def |  9 +++++++++
 libstdc++-v3/include/bits/version.h   | 10 ++++++++++
 libstdc++-v3/include/std/utility      | 19 +++++++++++++++++++
 libstdc++-v3/src/c++23/std.cc.in      |  3 +++
 4 files changed, 41 insertions(+)

diff --git a/libstdc++-v3/include/bits/version.def 
b/libstdc++-v3/include/bits/version.def
index 1118da4b541e..f60a518b28d5 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -1950,6 +1950,15 @@ ftms = {
   };
 };
 
+ftms = {
+  name = observable_checkpoint;
+  values = {
+    v = 202506;
+    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 c452bbeec8e0..cbd82ff81e89 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -2181,6 +2181,16 @@
 #endif /* !defined(__cpp_lib_unreachable) */
 #undef __glibcxx_want_unreachable
 
+#if !defined(__cpp_lib_observable_checkpoint)
+# if (__cplusplus >  202302L) && 
(__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 8a85ccfd09ba..3ae1852426e8 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() noexcept
+  {
+    return __builtin_observable_checkpoint();
+  }
+#endif
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
 
diff --git a/libstdc++-v3/src/c++23/std.cc.in b/libstdc++-v3/src/c++23/std.cc.in
index 9cf5fa7dcb62..e849307f186a 100644
--- a/libstdc++-v3/src/c++23/std.cc.in
+++ b/libstdc++-v3/src/c++23/std.cc.in
@@ -3337,6 +3337,9 @@ export namespace std
 #if __cpp_lib_unreachable
   using std::unreachable;
 #endif
+#if __cpp_lib_observable_checkpoint
+  using std::observable_checkpoint;
+#endif
 }
 
 // <valarray>

Reply via email to