2000-10-11 07:43:26 +08:00
|
|
|
// The -*- C++ -*- dynamic memory management header.
|
2001-02-08 04:26:24 +08:00
|
|
|
|
2022-01-03 17:42:10 +08:00
|
|
|
// Copyright (C) 1994-2022 Free Software Foundation, Inc.
|
2000-10-11 07:43:26 +08:00
|
|
|
|
Makefile.am, [...]: Replace "GNU CC" with "GCC".
2003-05-24 Nathanael Nerode <neroden@gcc.gnu.org>
* libsupc++/Makefile.am, libsupc++/cxxabi.h, libsupc++/del_op.cc,
libsupc++/del_opnt.cc, libsupc++/del_opv.cc, libsupc++/del_opvnt.cc,
libsupc++/eh_alloc.cc, libsupc++/eh_aux_runtime.cc,
libsupc++/eh_catch.cc, libsupc++/eh_exception.cc,
libsupc++/eh_globals.cc, libsupc++/eh_personality.cc,
libsupc++/eh_term_handler.cc, libsupc++/eh_terminate.cc,
libsupc++/eh_throw.cc, libsupc++/eh_type.cc,
libsupc++/eh_unex_handler.cc, libsupc++/exception,
libsupc++/new, libsupc++/new_handler.cc, libsupc++/new_op.cc,
libsupc++/new_opnt.cc, libsupc++/new_opv.cc, libsupc++/new_opvnt.cc,
libsupc++/pure.cc, libsupc++/tinfo.cc, libsupc++/tinfo2.cc,
libsupc++/typeinfo, libsupc++/unwind-cxx.h, libsupc++/vec.cc:
Replace "GNU CC" with "GCC".
From-SVN: r67155
2003-05-25 00:22:03 +08:00
|
|
|
// This file is part of GCC.
|
2000-10-11 07:43:26 +08:00
|
|
|
//
|
Makefile.am, [...]: Replace "GNU CC" with "GCC".
2003-05-24 Nathanael Nerode <neroden@gcc.gnu.org>
* libsupc++/Makefile.am, libsupc++/cxxabi.h, libsupc++/del_op.cc,
libsupc++/del_opnt.cc, libsupc++/del_opv.cc, libsupc++/del_opvnt.cc,
libsupc++/eh_alloc.cc, libsupc++/eh_aux_runtime.cc,
libsupc++/eh_catch.cc, libsupc++/eh_exception.cc,
libsupc++/eh_globals.cc, libsupc++/eh_personality.cc,
libsupc++/eh_term_handler.cc, libsupc++/eh_terminate.cc,
libsupc++/eh_throw.cc, libsupc++/eh_type.cc,
libsupc++/eh_unex_handler.cc, libsupc++/exception,
libsupc++/new, libsupc++/new_handler.cc, libsupc++/new_op.cc,
libsupc++/new_opnt.cc, libsupc++/new_opv.cc, libsupc++/new_opvnt.cc,
libsupc++/pure.cc, libsupc++/tinfo.cc, libsupc++/tinfo2.cc,
libsupc++/typeinfo, libsupc++/unwind-cxx.h, libsupc++/vec.cc:
Replace "GNU CC" with "GCC".
From-SVN: r67155
2003-05-25 00:22:03 +08:00
|
|
|
// GCC is free software; you can redistribute it and/or modify
|
2000-10-11 07:43:26 +08:00
|
|
|
// it under the terms of the GNU General Public License as published by
|
2009-04-09 23:00:19 +08:00
|
|
|
// the Free Software Foundation; either version 3, or (at your option)
|
2000-10-11 07:43:26 +08:00
|
|
|
// any later version.
|
|
|
|
//
|
Makefile.am, [...]: Replace "GNU CC" with "GCC".
2003-05-24 Nathanael Nerode <neroden@gcc.gnu.org>
* libsupc++/Makefile.am, libsupc++/cxxabi.h, libsupc++/del_op.cc,
libsupc++/del_opnt.cc, libsupc++/del_opv.cc, libsupc++/del_opvnt.cc,
libsupc++/eh_alloc.cc, libsupc++/eh_aux_runtime.cc,
libsupc++/eh_catch.cc, libsupc++/eh_exception.cc,
libsupc++/eh_globals.cc, libsupc++/eh_personality.cc,
libsupc++/eh_term_handler.cc, libsupc++/eh_terminate.cc,
libsupc++/eh_throw.cc, libsupc++/eh_type.cc,
libsupc++/eh_unex_handler.cc, libsupc++/exception,
libsupc++/new, libsupc++/new_handler.cc, libsupc++/new_op.cc,
libsupc++/new_opnt.cc, libsupc++/new_opv.cc, libsupc++/new_opvnt.cc,
libsupc++/pure.cc, libsupc++/tinfo.cc, libsupc++/tinfo2.cc,
libsupc++/typeinfo, libsupc++/unwind-cxx.h, libsupc++/vec.cc:
Replace "GNU CC" with "GCC".
From-SVN: r67155
2003-05-25 00:22:03 +08:00
|
|
|
// GCC is distributed in the hope that it will be useful,
|
2000-10-11 07:43:26 +08:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
2009-04-09 23:00:19 +08:00
|
|
|
// Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
// permissions described in the GCC Runtime Library Exception, version
|
|
|
|
// 3.1, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License and
|
|
|
|
// a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
2000-10-11 07:43:26 +08:00
|
|
|
|
2001-07-12 03:35:49 +08:00
|
|
|
/** @file new
|
2006-11-30 04:59:22 +08:00
|
|
|
* This is a Standard C++ Library header.
|
|
|
|
*
|
Makefile.am (doxygen, [...]): Tweak targets.
2002-01-28 Phil Edwards <pme@gcc.gnu.org>
* Makefile.am (doxygen, doxygen-maint, doxygen-man): Tweak targets.
* Makefile.in: Regenerate.
* docs/doxygen/run_doxygen: Update, mostly for man pages.
* docs/doxygen/Intro.3: Update.
* docs/doxygen/TODO: Update.
* docs/doxygen/doxygroups.cc: Add namespace hook for __gnu_cxx.
* docs/doxygen/mainpage.doxy: Update.
* docs/doxygen/user.cfg.in: Update for header rename. Also
regenerate comments and variables with 1.2.12.
* docs/doxygen/maint.cfg.in: Remove file.
* include/bits/stl_relops.h: Doxygenate.
* include/bits/stl_tempbuf.h (std::_Temporary_buffer): Likewise.
* include/c_std/std_cassert.h, include/c_std/std_cctype.h,
include/c_std/std_cerrno.h, include/c_std/std_cfloat.h,
include/c_std/std_ciso646.h, include/c_std/std_climits.h,
include/c_std/std_clocale.h, include/c_std/std_cmath.h,
include/c_std/std_csetjmp.h, include/c_std/std_csignal.h,
include/c_std/std_cstdarg.h, include/c_std/std_cstddef.h,
include/c_std/std_cstdio.h, include/c_std/std_cstdlib.h,
include/c_std/std_cstring.h, include/c_std/std_ctime.h,
include/c_std/std_cwchar.h, include/c_std/std_cwctype.h,
include/ext/algorithm, include/ext/functional, include/ext/hash_map,
include/ext/hash_set, include/ext/iterator, include/ext/memory,
include/ext/numeric, include/ext/rb_tree, include/ext/rope,
include/ext/ropeimpl.h, include/ext/slist, include/ext/stl_hash_fun.h,
include/ext/stl_hashtable.h, include/ext/stl_rope.h,
include/std/std_algorithm.h, include/std/std_bitset.h,
include/std/std_complex.h, include/std/std_deque.h,
include/std/std_fstream.h, include/std/std_functional.h,
include/std/std_iomanip.h, include/std/std_ios.h,
include/std/std_iosfwd.h, include/std/std_iostream.h,
include/std/std_istream.h, include/std/std_iterator.h,
include/std/std_limits.h, include/std/std_list.h,
include/std/std_locale.h, include/std/std_map.h,
include/std/std_memory.h, include/std/std_numeric.h,
include/std/std_ostream.h, include/std/std_queue.h,
include/std/std_set.h, include/std/std_sstream.h,
include/std/std_stack.h, include/std/std_stdexcept.h,
include/std/std_streambuf.h, include/std/std_string.h,
include/std/std_utility.h, include/std/std_valarray.h,
include/std/std_vector.h: Add/correct @file doxygen hook.
* include/ext/memory: Doxygenate most of rest of file.
* libsupc++/exception: Doxygen output formatting.
* libsupc++/new: Say which header it is.
* testsuite/lib/libstdc++-v3-dg.exp: Fix spacing.
* docs/html/19_diagnostics/howto.html: Describe concept-checks switch.
* docs/html/23_containers/howto.html: Describe O(n) list::size().
* docs/html/27_io/howto.html: Also link to Langer and Kreft text.
From-SVN: r49300
2002-01-29 06:13:12 +08:00
|
|
|
* The header @c new defines several functions to manage dynamic memory and
|
2001-07-12 03:35:49 +08:00
|
|
|
* handling memory allocation errors; see
|
2019-05-11 05:41:11 +08:00
|
|
|
* https://gcc.gnu.org/onlinedocs/libstdc++/manual/dynamic_memory.html
|
|
|
|
* for more.
|
2001-07-12 03:35:49 +08:00
|
|
|
*/
|
|
|
|
|
2003-07-05 12:05:45 +08:00
|
|
|
#ifndef _NEW
|
|
|
|
#define _NEW
|
2000-10-11 07:43:26 +08:00
|
|
|
|
2010-02-19 01:58:53 +08:00
|
|
|
#pragma GCC system_header
|
|
|
|
|
2010-06-04 03:15:56 +08:00
|
|
|
#include <bits/c++config.h>
|
2020-09-02 20:27:57 +08:00
|
|
|
#include <bits/exception.h>
|
2000-10-11 07:43:26 +08:00
|
|
|
|
2004-08-03 14:45:54 +08:00
|
|
|
#pragma GCC visibility push(default)
|
|
|
|
|
2000-10-11 07:43:26 +08:00
|
|
|
extern "C++" {
|
|
|
|
|
2001-02-08 04:26:24 +08:00
|
|
|
namespace std
|
|
|
|
{
|
abi.txt: New file.
2002-07-20 Phil Edwards <pme@gcc.gnu.org>
* docs/html/abi.txt: New file.
* docs/html/23_containers/howto.html: Tweak vector-overhead text.
* docs/html/ext/lwg-active.html, docs/html/ext/lwg-defects.html:
Import from upstream, R22.
* include/bits/char_traits.h, include/bits/stl_iterator.h,
include/bits/stl_iterator_base_types.h, libsupc++/exception,
libsupc++/new, libsupc++/typeinfo: Use @brief markup.
* include/bits/deque.tcc, include/bits/stl_alloc.h,
include/bits/stl_deque.h, include/bits/stl_list.h: Postpone removal
of deprecated functions until 3.4. (Same timeframe, different text.)
* include/bits/stl_vector.h: Ditto. Also do the same cleanups that
the other sequence classes received.
From-SVN: r55602
2002-07-20 14:26:27 +08:00
|
|
|
/**
|
|
|
|
* @brief Exception possibly thrown by @c new.
|
2009-02-21 08:45:21 +08:00
|
|
|
* @ingroup exceptions
|
abi.txt: New file.
2002-07-20 Phil Edwards <pme@gcc.gnu.org>
* docs/html/abi.txt: New file.
* docs/html/23_containers/howto.html: Tweak vector-overhead text.
* docs/html/ext/lwg-active.html, docs/html/ext/lwg-defects.html:
Import from upstream, R22.
* include/bits/char_traits.h, include/bits/stl_iterator.h,
include/bits/stl_iterator_base_types.h, libsupc++/exception,
libsupc++/new, libsupc++/typeinfo: Use @brief markup.
* include/bits/deque.tcc, include/bits/stl_alloc.h,
include/bits/stl_deque.h, include/bits/stl_list.h: Postpone removal
of deprecated functions until 3.4. (Same timeframe, different text.)
* include/bits/stl_vector.h: Ditto. Also do the same cleanups that
the other sequence classes received.
From-SVN: r55602
2002-07-20 14:26:27 +08:00
|
|
|
*
|
|
|
|
* @c bad_alloc (or classes derived from it) is used to report allocation
|
2001-07-12 03:35:49 +08:00
|
|
|
* errors from the throwing forms of @c new. */
|
2020-09-02 20:27:57 +08:00
|
|
|
class bad_alloc : public exception
|
2001-02-08 04:26:24 +08:00
|
|
|
{
|
2000-10-11 07:43:26 +08:00
|
|
|
public:
|
2001-03-14 03:32:00 +08:00
|
|
|
bad_alloc() throw() { }
|
2007-06-26 19:01:15 +08:00
|
|
|
|
2018-05-19 04:02:14 +08:00
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
bad_alloc(const bad_alloc&) = default;
|
|
|
|
bad_alloc& operator=(const bad_alloc&) = default;
|
|
|
|
#endif
|
|
|
|
|
2002-01-10 07:31:57 +08:00
|
|
|
// This declaration is not useless:
|
|
|
|
// http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
|
2002-01-10 04:39:27 +08:00
|
|
|
virtual ~bad_alloc() throw();
|
2007-06-26 19:01:15 +08:00
|
|
|
|
2007-02-01 21:36:51 +08:00
|
|
|
// See comment in eh_exception.cc.
|
|
|
|
virtual const char* what() const throw();
|
2000-10-11 07:43:26 +08:00
|
|
|
};
|
|
|
|
|
2013-05-09 11:58:00 +08:00
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
class bad_array_new_length : public bad_alloc
|
|
|
|
{
|
|
|
|
public:
|
2017-07-20 00:59:00 +08:00
|
|
|
bad_array_new_length() throw() { }
|
2013-05-09 11:58:00 +08:00
|
|
|
|
|
|
|
// This declaration is not useless:
|
|
|
|
// http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
|
|
|
|
virtual ~bad_array_new_length() throw();
|
|
|
|
|
|
|
|
// See comment in eh_exception.cc.
|
|
|
|
virtual const char* what() const throw();
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2016-09-10 05:22:15 +08:00
|
|
|
#if __cpp_aligned_new
|
|
|
|
enum class align_val_t: size_t {};
|
|
|
|
#endif
|
|
|
|
|
2015-11-11 22:47:19 +08:00
|
|
|
struct nothrow_t
|
|
|
|
{
|
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
explicit nothrow_t() = default;
|
|
|
|
#endif
|
|
|
|
};
|
2007-06-26 19:01:15 +08:00
|
|
|
|
2000-10-11 07:43:26 +08:00
|
|
|
extern const nothrow_t nothrow;
|
2007-06-26 19:01:15 +08:00
|
|
|
|
2001-07-12 03:35:49 +08:00
|
|
|
/** If you write your own error handler to be called by @c new, it must
|
|
|
|
* be of this type. */
|
2000-10-11 07:43:26 +08:00
|
|
|
typedef void (*new_handler)();
|
2007-06-26 19:01:15 +08:00
|
|
|
|
|
|
|
/// Takes a replacement handler as the argument, returns the
|
|
|
|
/// previous handler.
|
2002-07-16 16:28:40 +08:00
|
|
|
new_handler set_new_handler(new_handler) throw();
|
2013-04-03 08:08:54 +08:00
|
|
|
|
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
/// Return the current new handler.
|
|
|
|
new_handler get_new_handler() noexcept;
|
|
|
|
#endif
|
2000-10-11 07:43:26 +08:00
|
|
|
} // namespace std
|
|
|
|
|
2001-07-12 03:35:49 +08:00
|
|
|
//@{
|
|
|
|
/** These are replaceable signatures:
|
|
|
|
* - normal single new and delete (no arguments, throw @c bad_alloc on error)
|
|
|
|
* - normal array new and delete (same)
|
|
|
|
* - @c nothrow single new and delete (take a @c nothrow argument, return
|
|
|
|
* @c NULL on error)
|
|
|
|
* - @c nothrow array new and delete (same)
|
|
|
|
*
|
|
|
|
* Placement new and delete signatures (take a memory address argument,
|
|
|
|
* does nothing) may not be replaced by a user's program.
|
|
|
|
*/
|
2019-01-21 19:47:30 +08:00
|
|
|
_GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
|
2011-10-13 02:40:58 +08:00
|
|
|
__attribute__((__externally_visible__));
|
2019-01-21 19:47:30 +08:00
|
|
|
_GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
|
2011-10-13 02:40:58 +08:00
|
|
|
__attribute__((__externally_visible__));
|
|
|
|
void operator delete(void*) _GLIBCXX_USE_NOEXCEPT
|
|
|
|
__attribute__((__externally_visible__));
|
|
|
|
void operator delete[](void*) _GLIBCXX_USE_NOEXCEPT
|
|
|
|
__attribute__((__externally_visible__));
|
2015-11-04 00:43:54 +08:00
|
|
|
#if __cpp_sized_deallocation
|
|
|
|
void operator delete(void*, std::size_t) _GLIBCXX_USE_NOEXCEPT
|
|
|
|
__attribute__((__externally_visible__));
|
|
|
|
void operator delete[](void*, std::size_t) _GLIBCXX_USE_NOEXCEPT
|
|
|
|
__attribute__((__externally_visible__));
|
|
|
|
#endif
|
2019-01-21 19:47:30 +08:00
|
|
|
_GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
|
2020-10-12 23:35:02 +08:00
|
|
|
__attribute__((__externally_visible__, __alloc_size__ (1), __malloc__));
|
2019-01-21 19:47:30 +08:00
|
|
|
_GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
|
2020-10-12 23:35:02 +08:00
|
|
|
__attribute__((__externally_visible__, __alloc_size__ (1), __malloc__));
|
2011-10-13 02:40:58 +08:00
|
|
|
void operator delete(void*, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
|
|
|
|
__attribute__((__externally_visible__));
|
|
|
|
void operator delete[](void*, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
|
|
|
|
__attribute__((__externally_visible__));
|
2016-09-10 05:22:15 +08:00
|
|
|
#if __cpp_aligned_new
|
2019-01-21 19:47:30 +08:00
|
|
|
_GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t)
|
2020-10-12 23:35:02 +08:00
|
|
|
__attribute__((__externally_visible__, __alloc_size__ (1), __malloc__));
|
2019-01-21 19:47:30 +08:00
|
|
|
_GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
|
2020-10-12 23:35:02 +08:00
|
|
|
_GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__));
|
2016-09-10 05:22:15 +08:00
|
|
|
void operator delete(void*, std::align_val_t)
|
|
|
|
_GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__));
|
|
|
|
void operator delete(void*, std::align_val_t, const std::nothrow_t&)
|
|
|
|
_GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__));
|
2019-01-21 19:47:30 +08:00
|
|
|
_GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t)
|
2020-10-12 23:35:02 +08:00
|
|
|
__attribute__((__externally_visible__, __alloc_size__ (1), __malloc__));
|
2019-01-21 19:47:30 +08:00
|
|
|
_GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&)
|
2020-10-12 23:35:02 +08:00
|
|
|
_GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__));
|
2016-09-10 05:22:15 +08:00
|
|
|
void operator delete[](void*, std::align_val_t)
|
|
|
|
_GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__));
|
|
|
|
void operator delete[](void*, std::align_val_t, const std::nothrow_t&)
|
|
|
|
_GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__));
|
|
|
|
#if __cpp_sized_deallocation
|
|
|
|
void operator delete(void*, std::size_t, std::align_val_t)
|
|
|
|
_GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__));
|
|
|
|
void operator delete[](void*, std::size_t, std::align_val_t)
|
|
|
|
_GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__));
|
|
|
|
#endif // __cpp_sized_deallocation
|
|
|
|
#endif // __cpp_aligned_new
|
2000-10-11 07:43:26 +08:00
|
|
|
|
2001-02-08 04:26:24 +08:00
|
|
|
// Default placement versions of operator new.
|
2019-01-21 19:47:30 +08:00
|
|
|
_GLIBCXX_NODISCARD inline void* operator new(std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
|
2011-10-13 02:40:58 +08:00
|
|
|
{ return __p; }
|
2019-01-21 19:47:30 +08:00
|
|
|
_GLIBCXX_NODISCARD inline void* operator new[](std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
|
2011-10-13 02:40:58 +08:00
|
|
|
{ return __p; }
|
2002-07-25 03:49:21 +08:00
|
|
|
|
|
|
|
// Default placement versions of operator delete.
|
2011-10-13 02:40:58 +08:00
|
|
|
inline void operator delete (void*, void*) _GLIBCXX_USE_NOEXCEPT { }
|
|
|
|
inline void operator delete[](void*, void*) _GLIBCXX_USE_NOEXCEPT { }
|
2001-07-12 03:35:49 +08:00
|
|
|
//@}
|
2000-10-11 07:43:26 +08:00
|
|
|
} // extern "C++"
|
|
|
|
|
2017-11-24 08:00:46 +08:00
|
|
|
#if __cplusplus >= 201703L
|
2016-10-28 22:09:33 +08:00
|
|
|
namespace std
|
|
|
|
{
|
c++: implement C++17 hardware interference size
The last missing piece of the C++17 standard library is the hardware
intereference size constants. Much of the delay in implementing these has
been due to uncertainty about what the right values are, and even whether
there is a single constant value that is suitable; the destructive
interference size is intended to be used in structure layout, so program
ABIs will depend on it.
In principle, both of these values should be the same as the target's L1
cache line size. When compiling for a generic target that is intended to
support a range of target CPUs with different cache line sizes, the
constructive size should probably be the minimum size, and the destructive
size the maximum, unless you are constrained by ABI compatibility with
previous code.
From discussion on gcc-patches, I've come to the conclusion that the
solution to the difficulty of choosing stable values is to give up on it,
and instead encourage only uses where ABI stability is unimportant: in
particular, uses where the ABI is shared at most between translation units
built at the same time with the same flags.
To that end, I've added a warning for any use of the constant value of
std::hardware_destructive_interference_size in a header or module export.
Appropriate uses within a project can disable the warning.
A previous iteration of this patch included an -finterference-tune flag to
make the value vary with -mtune; this iteration makes that the default
behavior, which should be appropriate for all reasonable uses of the
variable. The previous default of "stable-ish" seems to me likely to have
been more of an attractive nuisance; since we can't promise actual
stability, we should instead make proper uses more convenient.
JF Bastien's implementation proposal is summarized at
https://github.com/itanium-cxx-abi/cxx-abi/issues/74
I implement this by adding new --params for the two sizes. Targets can
override these values in targetm.target_option.override() to support a range
of values for the generic target; otherwise, both will default to the L1
cache line size.
64 bytes still seems correct for all x86.
I'm not sure why he proposed 64/64 for generic 32-bit ARM, since the Cortex
A9 has a 32-byte cache line, so I'd think 32/64 would make more sense.
He proposed 64/128 for generic AArch64, but since the A64FX now has a 256B
cache line, I've changed that to 64/256.
Other arch maintainers are invited to set ranges for their generic targets
if that seems better than using the default cache line size for both values.
With the above choice to reject stability as a goal, getting these values
"right" is now just a matter of what we want the default optimization to be,
and we can feel free to adjust them as CPUs with different cache lines
become more and less common.
gcc/ChangeLog:
* params.opt: Add destructive-interference-size and
constructive-interference-size.
* doc/invoke.texi: Document them.
* config/aarch64/aarch64.c (aarch64_override_options_internal):
Set them.
* config/arm/arm.c (arm_option_override): Set them.
* config/i386/i386-options.c (ix86_option_override_internal):
Set them.
gcc/c-family/ChangeLog:
* c.opt: Add -Winterference-size.
* c-cppbuiltin.c (cpp_atomic_builtins): Add __GCC_DESTRUCTIVE_SIZE
and __GCC_CONSTRUCTIVE_SIZE.
gcc/cp/ChangeLog:
* constexpr.c (maybe_warn_about_constant_value):
Complain about std::hardware_destructive_interference_size.
(cxx_eval_constant_expression): Call it.
* decl.c (cxx_init_decl_processing): Check
--param *-interference-size values.
libstdc++-v3/ChangeLog:
* include/std/version: Define __cpp_lib_hardware_interference_size.
* libsupc++/new: Define hardware interference size variables.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Winterference.H: New file.
* g++.dg/warn/Winterference.C: New test.
* g++.target/aarch64/interference.C: New test.
* g++.target/arm/interference.C: New test.
* g++.target/i386/interference.C: New test.
2021-07-16 03:30:17 +08:00
|
|
|
#ifdef _GLIBCXX_HAVE_BUILTIN_LAUNDER
|
2022-01-21 22:22:23 +08:00
|
|
|
#define __cpp_lib_launder 201606L
|
2016-10-28 22:09:33 +08:00
|
|
|
/// Pointer optimization barrier [ptr.launder]
|
|
|
|
template<typename _Tp>
|
2017-11-24 08:00:46 +08:00
|
|
|
[[nodiscard]] constexpr _Tp*
|
2016-10-28 22:09:33 +08:00
|
|
|
launder(_Tp* __p) noexcept
|
|
|
|
{ return __builtin_launder(__p); }
|
|
|
|
|
|
|
|
// The program is ill-formed if T is a function type or
|
|
|
|
// (possibly cv-qualified) void.
|
|
|
|
|
Implement P0012R1, Make exception specifications part of the type system.
gcc/cp/
* cp-tree.h (enum tsubst_flags): Add tf_fndecl_type.
(flag_noexcept_type, ce_type): New.
* call.c (build_conv): Add ck_fnptr.
(enum conversion_kind): Change ck_tsafe to ck_fnptr.
(convert_like_real): Likewise.
(standard_conversion): Likewise. Allow function pointer
conversions for pointers to member functions.
(reference_compatible_p): Allow function pointer conversions.
(direct_reference_binding): Likewise.
(reference_binding): Reference-compatible is no longer a subset of
reference-related.
(is_subseq): Also strip ck_lvalue after next_conversion.
* class.c (instantiate_type): Check fnptr_conv_p.
(resolve_address_of_overloaded_function): Likewise.
* cvt.c (can_convert_tx_safety): Now static.
(noexcept_conv_p, fnptr_conv_p, strip_fnptr_conv): New.
* decl.c (flag_noexcept_type): Define.
(cxx_init_decl_processing): Set it.
(bad_specifiers): Check it.
(grokdeclarator) [cdk_function]: Add exception-spec to type here.
* lambda.c (maybe_add_lambda_conv_op): Add exception-spec to
returned pointer.
* mangle.c (struct globals): Add need_cxx1z_warning.
(mangle_decl): Check it.
(write_exception_spec): New.
(write_function_type): Call it.
(canonicalize_for_substitution): Handle exception spec.
(write_type): Likewise.
(write_encoding): Set processing_template_decl across mangling of
partially-instantiated type.
* pt.c (determine_specialization): Pass tf_fndecl_type.
(tsubst_decl, fn_type_unification): Likewise.
(tsubst): Strip tf_fndecl_type, pass it to
tsubst_exception_specification.
(convert_nontype_argument_function): Handle function pointer
conversion.
(convert_nontype_argument): Likewise.
(unify, for_each_template_parm_r): Walk into noexcept-specifier.
* rtti.c (ptr_initializer): Encode noexcept.
* tree.c (canonical_eh_spec): New.
(build_exception_variant): Use it.
* typeck.c (composite_pointer_type): Handle fnptr conversion.
(comp_except_specs): Compare canonical EH specs.
(structural_comptypes): Call it.
gcc/c-family/
* c.opt (Wc++1z-compat): New.
* c-cppbuiltin.c (c_cpp_builtins): Add __cpp_noexcept_function_type.
libstdc++-v3/
* include/bits/c++config (_GLIBCXX_NOEXCEPT_PARM)
(_GLIBCXX_NOEXCEPT_QUAL): New.
* include/std/type_traits (is_function): Use them.
* libsubc++/new (launder): Likewise.
* libsupc++/cxxabi.h (__pbase_type_info::__masks): Add
__noexcept_mask.
* libsupc++/pbase_type_info.cc (__do_catch): Handle function
pointer conversion.
libiberty/
* cp-demangle.c (is_fnqual_component_type): New.
(d_encoding, d_print_comp_inner, d_print_mod_list): Use it.
(FNQUAL_COMPONENT_CASE): New.
(d_make_comp, has_return_type, d_print_comp_inner)
(d_print_function_type): Use it.
(next_is_type_qual): New.
(d_cv_qualifiers, d_print_mod): Handle noexcept and throw-spec.
include/
* demangle.h (enum demangle_component_type): Add
DEMANGLE_COMPONENT_NOEXCEPT, DEMANGLE_COMPONENT_THROW_SPEC.
From-SVN: r241944
2016-11-08 07:09:29 +08:00
|
|
|
template<typename _Ret, typename... _Args _GLIBCXX_NOEXCEPT_PARM>
|
|
|
|
void launder(_Ret (*)(_Args...) _GLIBCXX_NOEXCEPT_QUAL) = delete;
|
|
|
|
template<typename _Ret, typename... _Args _GLIBCXX_NOEXCEPT_PARM>
|
|
|
|
void launder(_Ret (*)(_Args......) _GLIBCXX_NOEXCEPT_QUAL) = delete;
|
2016-10-28 22:09:33 +08:00
|
|
|
|
|
|
|
void launder(void*) = delete;
|
|
|
|
void launder(const void*) = delete;
|
|
|
|
void launder(volatile void*) = delete;
|
|
|
|
void launder(const volatile void*) = delete;
|
2017-04-19 23:18:24 +08:00
|
|
|
#endif // _GLIBCXX_HAVE_BUILTIN_LAUNDER
|
c++: implement C++17 hardware interference size
The last missing piece of the C++17 standard library is the hardware
intereference size constants. Much of the delay in implementing these has
been due to uncertainty about what the right values are, and even whether
there is a single constant value that is suitable; the destructive
interference size is intended to be used in structure layout, so program
ABIs will depend on it.
In principle, both of these values should be the same as the target's L1
cache line size. When compiling for a generic target that is intended to
support a range of target CPUs with different cache line sizes, the
constructive size should probably be the minimum size, and the destructive
size the maximum, unless you are constrained by ABI compatibility with
previous code.
From discussion on gcc-patches, I've come to the conclusion that the
solution to the difficulty of choosing stable values is to give up on it,
and instead encourage only uses where ABI stability is unimportant: in
particular, uses where the ABI is shared at most between translation units
built at the same time with the same flags.
To that end, I've added a warning for any use of the constant value of
std::hardware_destructive_interference_size in a header or module export.
Appropriate uses within a project can disable the warning.
A previous iteration of this patch included an -finterference-tune flag to
make the value vary with -mtune; this iteration makes that the default
behavior, which should be appropriate for all reasonable uses of the
variable. The previous default of "stable-ish" seems to me likely to have
been more of an attractive nuisance; since we can't promise actual
stability, we should instead make proper uses more convenient.
JF Bastien's implementation proposal is summarized at
https://github.com/itanium-cxx-abi/cxx-abi/issues/74
I implement this by adding new --params for the two sizes. Targets can
override these values in targetm.target_option.override() to support a range
of values for the generic target; otherwise, both will default to the L1
cache line size.
64 bytes still seems correct for all x86.
I'm not sure why he proposed 64/64 for generic 32-bit ARM, since the Cortex
A9 has a 32-byte cache line, so I'd think 32/64 would make more sense.
He proposed 64/128 for generic AArch64, but since the A64FX now has a 256B
cache line, I've changed that to 64/256.
Other arch maintainers are invited to set ranges for their generic targets
if that seems better than using the default cache line size for both values.
With the above choice to reject stability as a goal, getting these values
"right" is now just a matter of what we want the default optimization to be,
and we can feel free to adjust them as CPUs with different cache lines
become more and less common.
gcc/ChangeLog:
* params.opt: Add destructive-interference-size and
constructive-interference-size.
* doc/invoke.texi: Document them.
* config/aarch64/aarch64.c (aarch64_override_options_internal):
Set them.
* config/arm/arm.c (arm_option_override): Set them.
* config/i386/i386-options.c (ix86_option_override_internal):
Set them.
gcc/c-family/ChangeLog:
* c.opt: Add -Winterference-size.
* c-cppbuiltin.c (cpp_atomic_builtins): Add __GCC_DESTRUCTIVE_SIZE
and __GCC_CONSTRUCTIVE_SIZE.
gcc/cp/ChangeLog:
* constexpr.c (maybe_warn_about_constant_value):
Complain about std::hardware_destructive_interference_size.
(cxx_eval_constant_expression): Call it.
* decl.c (cxx_init_decl_processing): Check
--param *-interference-size values.
libstdc++-v3/ChangeLog:
* include/std/version: Define __cpp_lib_hardware_interference_size.
* libsupc++/new: Define hardware interference size variables.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Winterference.H: New file.
* g++.dg/warn/Winterference.C: New test.
* g++.target/aarch64/interference.C: New test.
* g++.target/arm/interference.C: New test.
* g++.target/i386/interference.C: New test.
2021-07-16 03:30:17 +08:00
|
|
|
|
|
|
|
#ifdef __GCC_DESTRUCTIVE_SIZE
|
|
|
|
# define __cpp_lib_hardware_interference_size 201703L
|
|
|
|
inline constexpr size_t hardware_destructive_interference_size = __GCC_DESTRUCTIVE_SIZE;
|
|
|
|
inline constexpr size_t hardware_constructive_interference_size = __GCC_CONSTRUCTIVE_SIZE;
|
|
|
|
#endif // __GCC_DESTRUCTIVE_SIZE
|
|
|
|
}
|
2016-10-28 22:09:33 +08:00
|
|
|
#endif // C++17
|
|
|
|
|
2019-02-14 06:13:45 +08:00
|
|
|
#if __cplusplus > 201703L
|
2018-11-13 12:40:01 +08:00
|
|
|
namespace std
|
|
|
|
{
|
2019-05-11 05:41:11 +08:00
|
|
|
/// Tag type used to declare a class-specific operator delete that can
|
|
|
|
/// invoke the destructor before deallocating the memory.
|
2018-11-13 12:40:01 +08:00
|
|
|
struct destroying_delete_t
|
|
|
|
{
|
|
|
|
explicit destroying_delete_t() = default;
|
|
|
|
};
|
2019-05-11 05:41:11 +08:00
|
|
|
/// Tag variable of type destroying_delete_t.
|
2018-11-13 12:40:01 +08:00
|
|
|
inline constexpr destroying_delete_t destroying_delete{};
|
|
|
|
}
|
2019-02-14 06:13:45 +08:00
|
|
|
// Only define the feature test macro if the compiler supports the feature:
|
|
|
|
#if __cpp_impl_destroying_delete
|
|
|
|
# define __cpp_lib_destroying_delete 201806L
|
|
|
|
#endif
|
|
|
|
#endif // C++20
|
2018-11-13 12:40:01 +08:00
|
|
|
|
2004-08-03 14:45:54 +08:00
|
|
|
#pragma GCC visibility pop
|
|
|
|
|
2000-10-11 07:43:26 +08:00
|
|
|
#endif
|