]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Guard use of sized deallocation [PR114940]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 22 May 2024 09:32:43 +0000 (10:32 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 22 May 2024 22:10:05 +0000 (23:10 +0100)
Clang does not enable -fsized-deallocation by default, which means it
can't compile our <stacktrace> and <generator> headers.

Make the __cpp_lib_generator macro depend on the compiler-defined
__cpp_sized_deallocation macro, and change <stacktrace> to use unsized
deallocation when __cpp_sized_deallocation isn't defined.

libstdc++-v3/ChangeLog:

PR libstdc++/114940
* include/bits/version.def (generator): Depend on
__cpp_sized_deallocation.
* include/bits/version.h: Regenerate.
* include/std/stacktrace (_GLIBCXX_SIZED_DELETE): New macro.
(basic_stacktrace::_Impl::_M_deallocate): Use it.

libstdc++-v3/include/bits/version.def
libstdc++-v3/include/bits/version.h
libstdc++-v3/include/std/stacktrace

index f0ba4f2bb3d9c628604328603cb11a9269586a9e..5cbc9d1a8d85654c588ba5aaf5c796026f919e68 100644 (file)
@@ -1651,7 +1651,7 @@ ftms = {
   values = {
     v = 202207;
     cxxmin = 23;
-    extra_cond = "__glibcxx_coroutine";
+    extra_cond = "__glibcxx_coroutine && __cpp_sized_deallocation";
   };
 };
 
index f30f51dcedce4197274ce8fdbd752bbd5fb5e395..164ebed4983499183cd45bcd982dd7a1ffd77d3f 100644 (file)
 #undef __glibcxx_want_forward_like
 
 #if !defined(__cpp_lib_generator)
-# if (__cplusplus >= 202100L) && (__glibcxx_coroutine)
+# if (__cplusplus >= 202100L) && (__glibcxx_coroutine && __cpp_sized_deallocation)
 #  define __glibcxx_generator 202207L
 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_generator)
 #   define __cpp_lib_generator 202207L
index d217d63af3bb4420811391f81f959c53a2fd3814..962dbed7a41b21655a594c6c53d58afb32b19772 100644 (file)
@@ -551,6 +551,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #else
 # define _GLIBCXX_OPERATOR_NEW ::operator new
 # define _GLIBCXX_OPERATOR_DELETE ::operator delete
+#endif
+
+#if __cpp_sized_deallocation
+# define _GLIBCXX_SIZED_DELETE(T, p, n) \
+  _GLIBCXX_OPERATOR_DELETE((p), (n) * sizeof(T))
+#else
+# define _GLIBCXX_SIZED_DELETE(T, p, n) _GLIBCXX_OPERATOR_DELETE(p)
 #endif
 
        // Precondition: _M_frames == nullptr && __n != 0
@@ -592,8 +599,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          if (_M_capacity)
            {
              if constexpr (is_same_v<allocator_type, allocator<value_type>>)
-               _GLIBCXX_OPERATOR_DELETE (static_cast<void*>(_M_frames),
-                                         _M_capacity * sizeof(value_type));
+               _GLIBCXX_SIZED_DELETE(value_type,
+                                     static_cast<void*>(_M_frames),
+                                     _M_capacity);
              else
                __alloc.deallocate(_M_frames, _M_capacity);
              _M_frames = nullptr;
@@ -601,6 +609,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
            }
        }
 
+#undef _GLIBCXX_SIZED_DELETE
 #undef _GLIBCXX_OPERATOR_DELETE
 #undef _GLIBCXX_OPERATOR_NEW