]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Implement P1494 and P3641 Partial program correctness [PR119060]
authorIain Sandoe <iain@sandoe.co.uk>
Thu, 4 Sep 2025 15:21:16 +0000 (16:21 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Sat, 18 Oct 2025 22:18:02 +0000 (23:18 +0100)
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 <iain@sandoe.co.uk>
libstdc++-v3/include/bits/version.def
libstdc++-v3/include/bits/version.h
libstdc++-v3/include/std/utility
libstdc++-v3/src/c++23/std.cc.in

index 1118da4b541ea9e77e63ae67f7bc2c769b0d3e68..f60a518b28d56f59385bf3aa5ee53f1cf57394df 100644 (file)
@@ -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 = {
index c452bbeec8e02bb14735e5a7c6b1bbd63fda1189..cbd82ff81e89c87fecf0952bdfa00a4c9313ad6c 100644 (file)
 #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
index 8a85ccfd09ba2dd042d45fb9952f4a7d5bc25a09..3ae1852426e8d433cd13e4ab1700650a8a54fd05 100644 (file)
@@ -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
 
index 9cf5fa7dcb62fac32a85ded5a60bfa55d747c14e..e849307f186a460248049b12b1800bcdfb1d4487 100644 (file)
@@ -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>