]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
15 months agoDarwin: Use -platform_version when available [PR110624].
Iain Sandoe [Thu, 13 Jul 2023 06:36:51 +0000 (07:36 +0100)] 
Darwin: Use -platform_version when available [PR110624].

Later versions of the static linker support a more flexible flag to
describe the OS, OS version and SDK used to build the code.  This
replaces the functionality of '-mmacosx_version_min' (which is now
deprecated, leading to the diagnostic described in the PR).

We now use the platform_version flag when available which avoids the
diagnostic.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
PR target/110624

gcc/ChangeLog:

* config/darwin.h (DARWIN_PLATFORM_ID): New.
(LINK_COMMAND_A): Use DARWIN_PLATFORM_ID to pass OS, OS version
and SDK data to the static linker.

(cherry picked from commit 032b5da1fc781bd3c23d9caa72fb09439e7f6f3a)

15 months agolibphobos, testsuite: Disable forkgc2 on Darwin [PR103944]
Iain Sandoe [Sun, 26 Feb 2023 13:53:52 +0000 (13:53 +0000)] 
libphobos, testsuite: Disable forkgc2 on Darwin [PR103944]

It hangs the testsuite (requiring manual intervention to kill the
spawned processes) which breaks CI.  The reason for the hang id not
clear.  This skips the test for now (xfail does not work).

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
PR d/103944

libphobos/ChangeLog:

* testsuite/libphobos.gc/forkgc2.d: Skip for Darwin.

(cherry picked from commit fca6d9c12f5bf06469cf9f7db8c42f66ef792fd2)

15 months agoDaily bump.
GCC Administrator [Thu, 4 Apr 2024 00:19:29 +0000 (00:19 +0000)] 
Daily bump.

15 months agoDaily bump.
GCC Administrator [Wed, 3 Apr 2024 00:19:32 +0000 (00:19 +0000)] 
Daily bump.

15 months agoFix SSA corruption due to widening_mul opt on conflict across an abnormal edge [PR111407]
Qing Zhao [Thu, 29 Feb 2024 15:07:49 +0000 (15:07 +0000)] 
Fix SSA corruption due to widening_mul opt on conflict across an abnormal edge [PR111407]

This is a bug in tree-ssa-math-opts.cc, when applying the widening mul
optimization, the compiler needs to check whether the operand is in a
ABNORMAL PHI, if YES, we should avoid the transformation.

PR tree-optimization/111407

gcc/ChangeLog:

* tree-ssa-math-opts.cc (convert_mult_to_widen): Avoid the transform
when one of the operands is subject to abnormal coalescing.

gcc/testsuite/ChangeLog:

* gcc.dg/pr111407.c: New test.

(cherry picked from commit 4aca1cfd6235090e48a53dab734437740671bbf3)

15 months agofortran: Ignore use statements on error [PR107426]
Mikael Morin [Thu, 21 Mar 2024 16:27:54 +0000 (17:27 +0100)] 
fortran: Ignore use statements on error [PR107426]

This fixes an access to freed memory on the testcase from the PR.
The problem comes from an invalid subroutine statement in an interface,
which is ignored and causes the following statements forming the procedure
body to be rejected.  One of them use-associates the intrinsic ISO_C_BINDING
module, which imports new symbols in a namespace that is freed at the time
the statement is rejected.  However, this creates dangling pointers as
ISO_C_BINDING is special and its import creates a reference to the imported
C_PTR symbol in the return type of the global intrinsic symbol for C_LOC
(see the function create_intrinsic_function).

This change saves and restores the list of use statements, so that rejected
use statements are removed before they have a chance to be applied to the
current namespace and create dangling pointers.

PR fortran/107426

gcc/fortran/ChangeLog:

* gfortran.h (gfc_save_module_list, gfc_restore_old_module_list):
New declarations.
* module.cc (old_module_list_tail): New global variable.
(gfc_save_module_list, gfc_restore_old_module_list): New functions.
(gfc_use_modules): Set module_list and old_module_list_tail.
* parse.cc (next_statement): Save module_list before doing any work.
(reject_statement): Restore module_list to its saved value.

gcc/testsuite/ChangeLog:

* gfortran.dg/pr89943_3.f90: Update error pattern.
* gfortran.dg/pr89943_4.f90: Likewise.
* gfortran.dg/use_31.f90: New test.

(cherry picked from commit a44d7e8a52007c2d45217709ca02947c6600de87)

15 months agoDaily bump.
GCC Administrator [Tue, 2 Apr 2024 00:19:47 +0000 (00:19 +0000)] 
Daily bump.

16 months agoLoongArch: gcc12: Implement option save/restore.
Lulu Cheng [Fri, 15 Mar 2024 08:41:20 +0000 (16:41 +0800)] 
LoongArch: gcc12: Implement option save/restore.

LTO option streaming and target attributes both require per-function
target configuration, which is achieved via option save/restore.

We implement TARGET_OPTION_{SAVE,RESTORE} to switch the la_target
context in addition to other automatically maintained option states
(via the "Save" option property in the .opt files).

PR target/113233

gcc/ChangeLog:

* config/loongarch/genopts/loongarch.opt.in: Mark options with
the "Save" property.
* config/loongarch/loongarch-opts.cc
(loongarch_update_gcc_opt_status): Update the value of the
la_target to global_options.
* config/loongarch/loongarch-opts.h
(loongarch_update_gcc_opt_status): Add a function declaration.
* config/loongarch/loongarch.cc
(loongarch_option_override_internal): Call the function
loongarch_update_gcc_opt_status.
(loongarch_option_save): New functions.
(loongarch_option_restore): Likewise.
(TARGET_OPTION_SAVE): Define macro.
(TARGET_OPTION_RESTORE): Likewise.
* config/loongarch/loongarch.opt: Regenerate.

(cherry picked from commit ea2a9c76a1dcffbbec6e53655bef9236d3a8e691)

16 months agoDaily bump.
GCC Administrator [Mon, 1 Apr 2024 00:19:56 +0000 (00:19 +0000)] 
Daily bump.

16 months agoDaily bump.
GCC Administrator [Sun, 31 Mar 2024 00:20:35 +0000 (00:20 +0000)] 
Daily bump.

16 months agoDaily bump.
GCC Administrator [Sat, 30 Mar 2024 00:20:20 +0000 (00:20 +0000)] 
Daily bump.

16 months agoFortran: fix NULL pointer dereference on overlapping initialization [PR50410]
Harald Anlauf [Thu, 28 Mar 2024 21:34:40 +0000 (22:34 +0100)] 
Fortran: fix NULL pointer dereference on overlapping initialization [PR50410]

gcc/fortran/ChangeLog:

PR fortran/50410
* trans-expr.cc (gfc_conv_structure): Check for NULL pointer.

gcc/testsuite/ChangeLog:

PR fortran/50410
* gfortran.dg/data_initialized_4.f90: New test.

(cherry picked from commit 6fb253a25dff13253d63553f02e0fe72c5e3ab4e)

16 months agoDaily bump.
GCC Administrator [Fri, 29 Mar 2024 00:20:49 +0000 (00:20 +0000)] 
Daily bump.

16 months agoDaily bump.
GCC Administrator [Thu, 28 Mar 2024 00:20:54 +0000 (00:20 +0000)] 
Daily bump.

16 months agoasan: Handle poly-int sizes in ASAN_MARK [PR97696]
Richard Sandiford [Wed, 27 Mar 2024 17:38:09 +0000 (17:38 +0000)] 
asan: Handle poly-int sizes in ASAN_MARK [PR97696]

This patch makes the expansion of IFN_ASAN_MARK let through
poly-int-sized objects.  The expansion itself was already generic
enough, but the tests for the fast path were too strict.

gcc/
PR sanitizer/97696
* asan.cc (asan_expand_mark_ifn): Allow the length to be a poly_int.

gcc/testsuite/
PR sanitizer/97696
* gcc.target/aarch64/sve/pr97696.c: New test.

(cherry picked from commit fca6f6fddb22b8665e840f455a7d0318d4575227)

16 months agoDaily bump.
GCC Administrator [Wed, 27 Mar 2024 00:20:55 +0000 (00:20 +0000)] 
Daily bump.

16 months agotree-optimization/110838 - less aggressively fold out-of-bound shifts
Richard Biener [Fri, 4 Aug 2023 09:24:49 +0000 (11:24 +0200)] 
tree-optimization/110838 - less aggressively fold out-of-bound shifts

The following adjusts the shift simplification patterns to avoid
touching out-of-bound shift value arithmetic right shifts of
possibly negative values.  While simplifying those to zero isn't
wrong it's violating the principle of least surprise.

PR tree-optimization/110838
* match.pd (([rl]shift @0 out-of-bounds) -> zero): Restrict
the arithmetic right-shift case to non-negative operands.

(cherry picked from commit 04aa0edcace22a7815cfc57575f1f7b1f166ac10)

16 months agotree-optimization/91838 - fix FAIL of g++.dg/opt/pr91838.C
Richard Biener [Thu, 27 Jul 2023 11:08:32 +0000 (13:08 +0200)] 
tree-optimization/91838 - fix FAIL of g++.dg/opt/pr91838.C

The following fixes the lack of simplification of a vector shift
by an out-of-bounds shift value.  For scalars this is done both
by CCP and VRP but vectors are not handled there.  This results
in PR91838 differences in outcome dependent on whether a vector
shift ISA is available and thus vector lowering does or does not
expose scalar shifts here.

The following adds a match.pd pattern to catch uniform out-of-bound
shifts, simplifying them to zero when not sanitizing shift amounts.

PR tree-optimization/91838
* gimple-match-head.cc: Include attribs.h and asan.h.
* generic-match-head.cc: Likewise.
* match.pd (([rl]shift @0 out-of-bounds) -> zero): New pattern.

(cherry picked from commit d1c072a1c3411a6fe29900750b38210af8451eeb)

16 months agoDaily bump.
GCC Administrator [Tue, 26 Mar 2024 00:20:16 +0000 (00:20 +0000)] 
Daily bump.

16 months agoDaily bump.
GCC Administrator [Mon, 25 Mar 2024 00:19:47 +0000 (00:19 +0000)] 
Daily bump.

16 months agoDaily bump.
GCC Administrator [Sun, 24 Mar 2024 00:20:02 +0000 (00:20 +0000)] 
Daily bump.

16 months agoDaily bump.
GCC Administrator [Sat, 23 Mar 2024 00:20:53 +0000 (00:20 +0000)] 
Daily bump.

16 months agoDaily bump.
GCC Administrator [Fri, 22 Mar 2024 00:20:40 +0000 (00:20 +0000)] 
Daily bump.

16 months agoDaily bump.
GCC Administrator [Thu, 21 Mar 2024 00:22:04 +0000 (00:22 +0000)] 
Daily bump.

16 months agoFortran: error recovery in frontend optimization [PR103715]
Harald Anlauf [Mon, 18 Mar 2024 18:36:59 +0000 (19:36 +0100)] 
Fortran: error recovery in frontend optimization [PR103715]

gcc/fortran/ChangeLog:

PR fortran/103715
* frontend-passes.cc (check_externals_expr): Prevent invalid read
in case of mismatch of external subroutine with function.

gcc/testsuite/ChangeLog:

PR fortran/103715
* gfortran.dg/pr103715.f90: New test.

(cherry picked from commit 3be2b8f475f22c531d6cef1b041c0573b3ea5133)

16 months agoDaily bump.
GCC Administrator [Wed, 20 Mar 2024 00:21:33 +0000 (00:21 +0000)] 
Daily bump.

16 months agotestsuite/i386: Correct pr111822.C dg-do options [PR111822]
Uros Bizjak [Tue, 19 Mar 2024 15:57:50 +0000 (16:57 +0100)] 
testsuite/i386: Correct pr111822.C dg-do options [PR111822]

PR target/111822

gcc/testsuite/ChangeLog:

* g++.target/i386/pr111822.C (dg-do): Compile only for ia32 targets.
(dg-options): Add -march=x86-64.

16 months agoDaily bump.
GCC Administrator [Tue, 19 Mar 2024 00:21:05 +0000 (00:21 +0000)] 
Daily bump.

16 months agolibstdc++: Remove test dependency on _GLIBCXX_USE_C99_STDINT_TR1
Jonathan Wakely [Fri, 12 May 2023 12:44:21 +0000 (13:44 +0100)] 
libstdc++: Remove test dependency on _GLIBCXX_USE_C99_STDINT_TR1

This should have been done in r9-2028-g8ba7f29e3dd064 when
std::shared_mutex was changed to be defined without depending on
_GLIBCXX_USE_C99_STDINT_TR1.

libstdc++-v3/ChangeLog:

* testsuite/experimental/feat-cxx14.cc: Remove dependency on
_GLIBCXX_USE_C99_STDINT_TR1.

(cherry picked from commit 2c04284abe5d5f1148c709a769f3b83bee2485d0)

16 months agolibstdc++: Remove test dependencies on _GLIBCXX_USE_C99_STDINT_TR1
Jonathan Wakely [Fri, 12 May 2023 12:34:37 +0000 (13:34 +0100)] 
libstdc++: Remove test dependencies on _GLIBCXX_USE_C99_STDINT_TR1

These #ifdef checks should have been removed in r9-2029-g612c9c702e2c9e
when the u16string_view and u32string_view aliases were changed to be
defined unconditionally.

libstdc++-v3/ChangeLog:

* testsuite/21_strings/basic_string_view/typedefs.cc: Remove
dependency on _GLIBCXX_USE_C99_STDINT_TR1.
* testsuite/experimental/string_view/typedefs.cc: Likewise.

(cherry picked from commit fe0e3df6f3751a0164c8e92a0d6519f2e10527a8)

16 months agolibstdc++: Move __glibcxx_assert_fail to its own file
Jonathan Wakely [Mon, 11 Sep 2023 14:58:48 +0000 (15:58 +0100)] 
libstdc++: Move __glibcxx_assert_fail to its own file

This avoids a dependency on the other symbols in src/c++11/debug.o when
linking statically to libstdc++.a without using -Wl,--gc-sections.

libstdc++-v3/ChangeLog:

* src/c++11/Makefile.am: Add new file.
* src/c++11/Makefile.in: Regenerate.
* src/c++11/debug.cc (__glibcxx_assert_fail): Move to ...
* src/c++11/assert_fail.cc: New file.

(cherry picked from commit c7db9000fa7caceadb4e72dcc6226abebf7a6239)

16 months agolibstdc++: Implement P2538R1 ADL-proof std::projected
Jonathan Wakely [Fri, 23 Jun 2023 11:18:11 +0000 (12:18 +0100)] 
libstdc++: Implement P2538R1 ADL-proof std::projected

This was recently approved for C++26, but there's no harm in
implementing it unconditionally for C++20 and C++23. As it says in the
paper, it doesn't change the meaning of any valid code. It only enables
things that were previously ill-formed for questionable reasons.

libstdc++-v3/ChangeLog:

* include/bits/iterator_concepts.h (projected): Replace class
template with alias template denoting an ADL-proofed helper.
(incremental_traits<projected<Iter, Proj>>): Remove.
* testsuite/24_iterators/indirect_callable/projected-adl.cc:
New test.

(cherry picked from commit 6eafdfc73c21d7a5e59e18c9dee275af5bf6d979)

16 months agolibstdc++: Add @headerfile and @since to doxygen comments [PR40380]
Jonathan Wakely [Wed, 26 Apr 2023 21:48:35 +0000 (22:48 +0100)] 
libstdc++: Add @headerfile and @since to doxygen comments [PR40380]

libstdc++-v3/ChangeLog:

PR libstdc++/40380
* include/bits/basic_string.h: Improve doxygen comments.
* include/bits/cow_string.h: Likewise.
* include/bits/forward_list.h: Likewise.
* include/bits/fs_dir.h: Likewise.
* include/bits/fs_path.h: Likewise.
* include/bits/quoted_string.h: Likewise.
* include/bits/stl_bvector.h: Likewise.
* include/bits/stl_map.h: Likewise.
* include/bits/stl_multimap.h: Likewise.
* include/bits/stl_multiset.h: Likewise.
* include/bits/stl_set.h: Likewise.
* include/bits/stl_vector.h: Likewise.
* include/bits/unordered_map.h: Likewise.
* include/bits/unordered_set.h: Likewise.
* include/std/filesystem: Likewise.
* include/std/iomanip: Likewise.

(cherry picked from commit 865869dc6943eb5dee855bc1ea88b09b7dabc641)

16 months agolibstdc++: Fix Doxygen warning
Jonathan Wakely [Thu, 17 Nov 2022 10:20:50 +0000 (10:20 +0000)] 
libstdc++: Fix Doxygen warning

This fixes a Doxygen warning about a mismatched parameter name. The
standard uses 'r' here, like the Doxygen comment, so use '__r' instead
of '__e'.

libstdc++-v3/ChangeLog:

* include/bits/ptr_traits.h (pointer_traits::pointer_to): Rename
parameter.

(cherry picked from commit fca0f50b145048afda17f0f10ac968afe6be0fad)

16 months agolibstdc++: Improve Doxygen comments in <tuple>
Jonathan Wakely [Mon, 21 Nov 2022 14:12:52 +0000 (14:12 +0000)] 
libstdc++: Improve Doxygen comments in <tuple>

libstdc++-v3/ChangeLog:

* include/std/tuple: Add better Doxygen comments.

(cherry picked from commit 94f7baf2194e2d20108c9d34d2766e6b14e25cef)

16 months agolibstdc++: Fix -Wsystem-headers warnings in tests
Jonathan Wakely [Mon, 7 Nov 2022 15:00:34 +0000 (15:00 +0000)] 
libstdc++: Fix -Wsystem-headers warnings in tests

libstdc++-v3/ChangeLog:

* testsuite/18_support/new_nothrow.cc: Add missing noexcept
to operator delete replacements.
* testsuite/20_util/any/cons/92156.cc: Disable
-Winit-list-lifetime warnings from instantiating invalid
specialization of manager function.
* testsuite/20_util/any/modifiers/92156.cc: Likewise.
* testsuite/20_util/default_delete/void_neg.cc: Prune additional
diagnostics.
* testsuite/20_util/headers/memory/synopsis.cc: Add missing
noexcept.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Prune
additional diagnostic.
* testsuite/20_util/unique_ptr/creation/for_overwrite.cc: Add
missing noexcept to operator delete replacements.
* testsuite/21_strings/basic_string/cons/char/103919.cc:
Likewise.
* testsuite/23_containers/map/modifiers/emplace/92300.cc:
Likewise.
* testsuite/23_containers/map/modifiers/insert/92300.cc:
Likewise.
* testsuite/24_iterators/headers/iterator/range_access_c++11.cc:
Add missing noexcept to synopsis declarations.
* testsuite/24_iterators/headers/iterator/range_access_c++14.cc:
Likewise.
* testsuite/24_iterators/headers/iterator/range_access_c++17.cc:
Likewise.

(cherry picked from commit bbcb84bba0a21ff367c95d3d0970926992b20cdd)

16 months agolibstdc++: Update <memory> synopsis test for C++11 and later
Jonathan Wakely [Wed, 21 Sep 2022 08:29:39 +0000 (09:29 +0100)] 
libstdc++: Update <memory> synopsis test for C++11 and later

libstdc++-v3/ChangeLog:

* testsuite/20_util/headers/memory/synopsis.cc: Add declarations
from C++11 and later.

(cherry picked from commit 980aa91e9cefe64245b7c32ee81ba372b7229aeb)

16 months agolibstdc++: Fix -Wsystem-headers warnings
Jonathan Wakely [Sat, 5 Nov 2022 12:35:55 +0000 (12:35 +0000)] 
libstdc++: Fix -Wsystem-headers warnings

Fix some problems noticed with -Wsystem-headers.

libstdc++-v3/ChangeLog:

* include/bits/stl_tempbuf.h (_Temporary_buffer): Disable
warnings about get_temporary_buffer being deprecated.
* include/ext/functional (mem_fun1, mem_fun1_ref): Disable
warnings about mem_fun1_t, const_mem_fun1_t, mem_fun1_ref_t and
const_mem_fun1_ref_t being deprecated.
* include/std/spanstream (basic_spanbuf::setbuf): Add assertion
and adjust to avoid narrowing warning.
* libsupc++/exception_ptr.h [!__cpp_rtti && !__cpp_exceptions]
(make_exception_ptr): Add missing inline specifier.

(cherry picked from commit 8f6d25f19bae521c3d028bcdcd69019540b8c3b9)

16 months agolibstdc++: Improve doxygen docs for <mutex>
Jonathan Wakely [Thu, 12 May 2022 22:06:04 +0000 (23:06 +0100)] 
libstdc++: Improve doxygen docs for <mutex>

libstdc++-v3/ChangeLog:

* doc/doxygen/user.cfg.in (PREDEFINED): Define
_GTHREAD_USE_MUTEX_TIMEDLOCK macro.
* include/bits/std_mutex.h (mutex, lock_guard): Use @since and
@headerfile.
* include/bits/unique_lock.h (unique_lock): Likewise.
* include/std/mutex (recursive_mutex, timed_mutex)
(recursive_timed_mutex, scoped_lock): Likewise.

(cherry picked from commit b584cbdb0829bb0ad4e6ed7488a304ae4e76b870)

16 months agolibstdc++: Improve doxygen docs for some of <memory>
Jonathan Wakely [Thu, 12 May 2022 22:04:29 +0000 (23:04 +0100)] 
libstdc++: Improve doxygen docs for some of <memory>

libstdc++-v3/ChangeLog:

* doc/doxygen/user.cfg.in (PREDEFINED): Define
_GLIBCXX23_CONSTEXPR macro.
* include/backward/auto_ptr.h (auto_ptr): Use @deprecated.
* include/bits/unique_ptr.h (default_delete): Use @since and
@headerfile.
* include/std/scoped_allocator: Remove @ingroup from @file
block.

(cherry picked from commit a278402216e75d5d54e62d2cd2345ea130349f10)

16 months agolibstdc++: Improve doxygen docs for algorithms and more
Jonathan Wakely [Thu, 12 May 2022 13:13:37 +0000 (14:13 +0100)] 
libstdc++: Improve doxygen docs for algorithms and more

libstdc++-v3/ChangeLog:

* include/bits/ostream_insert.h: Mark helper functions as
undocumented by Doxygen.
* include/bits/stl_algo.h: Use markdown for formatting and mark
helper functions as undocumented.
* include/bits/stl_numeric.h:  Likewise.
* include/bits/stl_pair.h (pair): Add @headerfile.

(cherry picked from commit e61492549b95dff635395f69034b5fefa00e339a)

16 months agolibstdc++: Improve doxygen docs for std::allocator
Jonathan Wakely [Thu, 12 May 2022 12:44:52 +0000 (13:44 +0100)] 
libstdc++: Improve doxygen docs for std::allocator

libstdc++-v3/ChangeLog:

* doc/doxygen/user.cfg.in (PREDEFINED): Define __allocator_base
so that Doxygen shows the right base-class for std::allocator.
* include/bits/alloc_traits.h: Improve doxygen docs.
* include/bits/allocator.h: Likewise.
* include/bits/new_allocator.h: Likewise.
* include/ext/new_allocator.h: Likewise.

(cherry picked from commit 171f41f124bc1d5d80a395d27833a578cceba9e7)

16 months agolibstdc++: Improve doxygen docs for <regex>
Jonathan Wakely [Thu, 12 May 2022 11:16:17 +0000 (12:16 +0100)] 
libstdc++: Improve doxygen docs for <regex>

Add @headerfile and @since tags. Improve grouping of non-member
functions via @relates tags.

Mark the std::pair base class of std::sub_match as undocumented, so that
the docs don't show all the related non-member functions are part of the
sub_match API. Use a new macro to re-add the data members for Doxygen
only.

libstdc++-v3/ChangeLog:

* doc/doxygen/user.cfg.in (PREDEFINED): Define macro
_GLIBCXX_DOXYGEN_ONLY to expand its argument.
* include/bits/c++config (_GLIBCXX_DOXYGEN_ONLY): Define.
* include/bits/regex.h: Improve doxygen docs.
* include/bits/regex_constants.h: Likewise.
* include/bits/regex_error.h: Likewise.

(cherry picked from commit 1b01963a4ea87607f5af6578a49006c8fee4d527)

16 months agolibstdc++: Improve doxygen docs for <atomic>
Jonathan Wakely [Wed, 11 May 2022 22:52:20 +0000 (23:52 +0100)] 
libstdc++: Improve doxygen docs for <atomic>

libstdc++-v3/ChangeLog:

* include/std/atomic: Suppress doxygen docs for
implementation details.
* include/bits/atomic_base.h: Likewise.
* include/bits/shared_ptr_atomic.h: Use markdown. Fix grouping
so that std::atomic is not added to the pointer abstractions
group.

(cherry picked from commit 1566ca0969ac4a14f7434d710e75dd89da303e75)

16 months agolibstdc++: Stop defining C++0x compat symbols for versioned namespace
Jonathan Wakely [Mon, 16 May 2022 15:54:52 +0000 (16:54 +0100)] 
libstdc++: Stop defining C++0x compat symbols for versioned namespace

The src/c++11/compatibility*-c++0x.cc files define symbols that need to
be exported for ancient versions of libstdc++.so.6 due to changes
between C++0x and the final C++11 standard. Those symbols are not needed
in the libstdc++.so.8 library, and we can skip building them entirely.

This also fixes the build failure I introduced last week when making the
versioned namespace config not use the _V2 namespace for compat symbols.

libstdc++-v3/ChangeLog:

* src/Makefile.am [ENABLE_SYMVERS_GNU_NAMESPACE] (cxx11_sources):
Do not build the compatibility*-c++0x.cc objects.
* src/Makefile.in: Regenerate.
* src/c++11/compatibility-c++0x.cc [_GLIBCXX_INLINE_VERSION]:
Refuse to build for the versioned namespace.
* src/c++11/compatibility-chrono.cc: Likewise.
* src/c++11/compatibility-condvar.cc: Likewise.
* src/c++11/compatibility-thread-c++0x.cc: Likewise.
* src/c++11/chrono.cc (system_clock, steady_clock):
Use macros to define in inline namespace _V2, matching the
declarations in <system_error>.
* src/c++11/system_error.cc (system_category, generic_category):
Likewise.

(cherry picked from commit 357d6fcd41e771128226b7916166f537b2d53a29)

16 months agolibstdc++: Add macros for the inline namespace std::_V2
Jonathan Wakely [Wed, 11 May 2022 15:35:45 +0000 (16:35 +0100)] 
libstdc++: Add macros for the inline namespace std::_V2

Use macros to open and close the inline namespace _V2 that is used for
ABI versioning of individual components such as chrono::system_clock.

This allows the namespace to be hidden in the docs generated by Doxygen,
so that we document std::foo instead of std::_V2::foo.

This also makes it easy to remove that namespace entirely for the
gnu-versioned-namespace build, where everything is already versioned as
std::__8 and there are no backwards compatibility guarantees.

libstdc++-v3/ChangeLog:

* doc/doxygen/user.cfg.in (PREDEFINED): Expand new macros to
nothing.
* include/bits/c++config (_GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE)
(_GLIBCXX_END_INLINE_ABI_NAMESPACE): Define new macros.
* include/bits/algorithmfwd.h (_V2::__rotate): Use new macros
for the namespace.
* include/bits/chrono.h (chrono::_V2::system_clock): Likewise.
* include/bits/stl_algo.h (_V2::__rotate): Likewise.
* include/std/condition_variable (_V2::condition_variable_any):
Likewise.
* include/std/system_error (_V2::error_category): Likewise.

(cherry picked from commit e4905f11852d722cd711b53a5626245528ace1d2)

16 months agolibstdc++: Disable Doxygen GROUP_NESTED_COMPOUNDS config option
Jonathan Wakely [Wed, 11 May 2022 15:46:03 +0000 (16:46 +0100)] 
libstdc++: Disable Doxygen GROUP_NESTED_COMPOUNDS config option

Before Doxygen version 1.9.2 this option is broken (see
https://github.com/doxygen/doxygen/issues/8638 for more details) and
classes are not added to the correct groups by @ingroup and @addtogroup.

Also remove the obsolete CLASS_DIAGRAMS option that causes a warning.

libstdc++-v3/ChangeLog:

* doc/doxygen/user.cfg.in (GROUP_NESTED_COMPOUNDS): Set to NO.
(CLASS_DIAGRAMS): Remove obsolete option.

(cherry picked from commit 9c3a8fe34aeacabc2f62acef7f8f9108cb109238)

16 months agolibstdc++: Simplify fs::path construction using variable template
Jonathan Wakely [Thu, 23 Jun 2022 17:39:50 +0000 (18:39 +0100)] 
libstdc++: Simplify fs::path construction using variable template

libstdc++-v3/ChangeLog:

* include/bits/fs_path.h (__is_path_iter_src): Replace class
template with variable template.

(cherry picked from commit 6177f60d914abcb8520b87ae62658e70a7c13759)

16 months agolibstdc++: Update std::pointer_traits to match new LWG 3545 wording
Jonathan Wakely [Mon, 26 Sep 2022 17:59:45 +0000 (18:59 +0100)] 
libstdc++: Update std::pointer_traits to match new LWG 3545 wording

It was pointed out in recent LWG 3545 discussion that having a
constrained partial specialization of std::pointer_traits can cause
ambiguities with program-defined specializations. For example, the
addition to the testcase has:

template<typename P> requires std::derived_from<P, base_type
struct std::pointer_traits<P>;

This would be ambiguous with the library's own constrained partial
specialization:

template<typename Ptr> requires requires { typename Ptr::element_type; }
struct std::pointer_traits<Ptr>;

Neither specialization is more specialized than the other for a type
that is derived from base_type and also has an element_type member.

The solution is to remove the library's partial specialization, and do
the check for Ptr::element_type in the __ptr_traits_elem helper (which
is what we already do for !__cpp_concepts anyway).

libstdc++-v3/ChangeLog:

* include/bits/ptr_traits.h (__ptr_traits_elem) [__cpp_concepts]:
Also define the __ptr_traits_elem class template for the
concepts case.
(pointer_traits<Ptr>): Remove constrained partial
specialization.
* testsuite/20_util/pointer_traits/lwg3545.cc: Check for
ambiguitiy with program-defined partial specialization.

(cherry picked from commit 03cb9ed8dd603dbb77762ca948fc6381ba190731)

16 months agolibstdc++: Simplify detection idiom using concepts
Jonathan Wakely [Fri, 23 Sep 2022 22:16:30 +0000 (23:16 +0100)] 
libstdc++: Simplify detection idiom using concepts

Add a simpler definition of std::__detected_or using concepts.  This
also replaces the __detector::value_t member which should have been using
a reserved name.

Use __detected_or in pointer_traits.

libstdc++-v3/ChangeLog:

* include/bits/alloc_traits.h (allocator_traits::is_always_equal):
Only instantiate is_empty if needed.
* include/bits/ptr_traits.h (__ptr_traits_impl::difference_type)
(__ptr_traits_impl::rebind): Use __detected_or.
* include/experimental/type_traits (is_same_v): Add a partial
specialization instead of instantiating the std::is_same class
template.
(detected_t): Redefine in terms of detected_or_t.
(is_detected, is_detected_v): Redefine in terms of detected_t.
* include/std/type_traits [__cpp_concepts] (__detected_or): Add
new definition using concepts.
(__detector::value_t): Rename to __is_detected.
* testsuite/17_intro/names.cc: Check value_t isn't used.

(cherry picked from commit 2b667beba693e876322af7c6682f9bc885c5ec28)

16 months agolibstdc++: Improve doxygen docs for std::pointer_traits
Jonathan Wakely [Wed, 11 May 2022 15:13:16 +0000 (16:13 +0100)] 
libstdc++: Improve doxygen docs for std::pointer_traits

libstdc++-v3/ChangeLog:

* include/bits/ptr_traits.h: Add some doxygen comments.

(cherry picked from commit 757146fb1c82b49e78ee82c882677814f25c2429)

16 months agolibstdc++: use grep -E instead of egrep in scripts
Xi Ruoyao [Fri, 24 Jun 2022 07:02:23 +0000 (15:02 +0800)] 
libstdc++: use grep -E instead of egrep in scripts

egrep has been deprecated in favor of grep -E for a long time, and the
next grep release (3.8 or 4.0) will print a warning of egrep is used.
Stop using egrep so we won't see the warning.

grep's from GNU, BSD (including Mac OS X), AIX, BusyBox all support -E
and -F.  Solaris grep doesn't support -E, but extract_symvers.in already
contains a special case for Solaris and doxygen documentation generation
is already broken on non-GNU.

libstdc++-v3/ChangeLog:

* scripts/extract_symvers.in: Use grep -E instead of egrep.
* scripts/run_doxygen: Likewise.

(cherry picked from commit fa4e97907fc979f550c3f02cde03d9c35f99df9b)

16 months agolibstdc++: Fix allocator propagation in regex algorithms [PR107376]
Jonathan Wakely [Tue, 25 Oct 2022 12:03:12 +0000 (13:03 +0100)] 
libstdc++: Fix allocator propagation in regex algorithms [PR107376]

The PR points out that we assume the match_results allocator is default
constuctible, which might not be true. We also have a related issue with
unwanted propagation from an object that might have an unequal
allocator.

Ideally we use the same allocator type for _State_info::_M_match_queue
but that would be an ABI change now. We should investigate if that can
be done without breaking anything, which might be possible because the
_Executor object is short-lived and never leaks out of the regex_match,
regex_search, and regex_replace algorithms. If we change the mangled
name for _Executor then there would be no ODR violations when mixing old
and new definitions. This commit does not attempt that.

libstdc++-v3/ChangeLog:

PR libstdc++/107376
* include/bits/regex_executor.h (_Executor::_Executor): Use same
allocator for _M_cur_results and _M_results.
* include/bits/regex_executor.tcc (_Executor::_M_main_dispatch):
Prevent possibly incorrect allocator propagating to
_M_cur_results.
* testsuite/28_regex/algorithms/regex_match/107376.cc: New test.

(cherry picked from commit 988dd22ec6665117e8587389ac85389f1c321c45)

16 months agolibstdc++: Define std::basic_stringbuf::view() for old std::string ABI
Jonathan Wakely [Tue, 31 Jan 2023 22:32:15 +0000 (22:32 +0000)] 
libstdc++: Define std::basic_stringbuf::view() for old std::string ABI

Unlike the new str()&& members in <sstream>, there is no real difficulty
in supporting the new view() members for the old std::string ABI.
Enabling it fixes errors in <chrono> where std::ostringstream::view() is
used by ostream insertion operators for calendar types.

We just need to use [[gnu::always_inline]] on the view() members for the
old ABI, because the library doesn't contain instantiations of them for
the old ABI. Making them always inline avoids needing to add those
instantiations and export them.

libstdc++-v3/ChangeLog:

* include/std/sstream  (basic_stringbuf::view): Define for old
std::string ABI.
(basic_istringstream::view, basic_stringstream::view)
(basic_stringstream::view): Likewise.
* testsuite/27_io/basic_istringstream/view/char/1.cc: Remove
{ dg-require-effective-target cxx11_abi }.
* testsuite/27_io/basic_istringstream/view/wchar_t/1.cc:
Likewise.
* testsuite/27_io/basic_ostringstream/view/char/1.cc: Likewise.
* testsuite/27_io/basic_ostringstream/view/wchar_t/1.cc:
Likewise.
* testsuite/27_io/basic_stringbuf/view/char/1.cc: Likewise.
* testsuite/27_io/basic_stringbuf/view/wchar_t/1.cc: Likewise.
* testsuite/27_io/basic_stringstream/view/char/1.cc: Likewise.
* testsuite/27_io/basic_stringstream/view/wchar_t/1.cc:
Likewise.

(cherry picked from commit 331b4f168a06cd85fe40fd03b48b128cc8af399c)

16 months agolibstdc++: Add autoconf checks for mkdir, chmod, chdir, and getcwd
Jonathan Wakely [Thu, 7 Sep 2023 16:03:40 +0000 (17:03 +0100)] 
libstdc++: Add autoconf checks for mkdir, chmod, chdir, and getcwd

The filesystem code was using these functions without checking for their
existence, assuming that any UNIX-like libc with <unistd.h> would always
provide them. That's not true for some newlib targets like arm-eabi.

libstdc++-v3/ChangeLog:

* acinclude.m4 (GLIBCXX_CHECK_FILESYSTEM_DEPS): Check for mkdir,
chmod, chdir, and getcwd.
* config.h.in: Regenerate.
* configure: Regenerate.
* src/c++17/fs_ops.cc (create_dir): Use USE_MKDIR macro.
(fs::current_path): Use USE_GETCWD and USE_CHDIR macros.
(fs::permissions): Use USE_CHMOD macro.
* src/filesystem/ops-common.h [FILESYSTEM_IS_WINDOWS]
(chmod, mkdir, getcwd, chdir): Define new macros.
[FILESYSTEM_IS_WINDOWS] (chmod, mkdir, getcwd, chdir): Use
new macros.
* src/filesystem/ops.cc (create_dir): Use USE_MKDIR macro.
(fs::current_path): Use USE_GETCWD and USE_CHDIR macros.
(fs::permissions): Use USE_CHMOD macro.

(cherry picked from commit 5435449be0eb9ca41824eb16f774db3ccc2a593b)

16 months agolibstdc++: Explicitly default some copy ctors and assignments
Jonathan Wakely [Tue, 8 Aug 2023 15:24:31 +0000 (16:24 +0100)] 
libstdc++: Explicitly default some copy ctors and assignments

The standard says that the implicit copy assignment operator is
deprecated for classes that have a user-provided copy constructor, and
vice versa.

libstdc++-v3/ChangeLog:

* include/bits/new_allocator.h (__new_allocator): Define copy
assignment operator as defaulted.
* include/std/complex (complex<float>, complex<double>)
(complex<long double>): Define copy constructor as defaulted.

(cherry picked from commit 008e439f34d4b356825a6c9b70245143f00bd353)

16 months agolibstdc++: Add static_assert to std::integer_sequence [PR112473]
Jonathan Wakely [Fri, 10 Nov 2023 12:21:52 +0000 (12:21 +0000)] 
libstdc++: Add static_assert to std::integer_sequence [PR112473]

C++20 allows class types as non-type template parameters, but
std::integer_sequence explicitly disallows them. Enforce that.

libstdc++-v3/ChangeLog:

PR libstdc++/112473
* include/bits/utility.h (integer_sequence): Add static_assert.
* testsuite/20_util/integer_sequence/112473.cc: New test.

(cherry picked from commit 0953497a81f1e320989b9f2aaa7f56747eddd4a0)

16 months agolibstdc++: Remove non-void static assertions in variant's std::get [PR111172]
Jonathan Wakely [Tue, 12 Sep 2023 20:28:38 +0000 (21:28 +0100)] 
libstdc++: Remove non-void static assertions in variant's std::get [PR111172]

A void template argument would cause a substitution failure when trying
to form a reference for the return type, so the function body would
never be instantiated.

libstdc++-v3/ChangeLog:

PR libstdc++/111172
* include/std/variant (get<T>): Remove !is_void static
assertions.

(cherry picked from commit d19bdf8874059457fdfe50a9e14dad8f8b8cecbb)

16 months agolibstdc++: Fix exception thrown by std::shared_lock::unlock() [PR112089]
Jonathan Wakely [Thu, 26 Oct 2023 15:51:30 +0000 (16:51 +0100)] 
libstdc++: Fix exception thrown by std::shared_lock::unlock() [PR112089]

The incorrect errc constant here looks like a copy&paste error.

libstdc++-v3/ChangeLog:

PR libstdc++/112089
* include/std/shared_mutex (shared_lock::unlock): Change errc
constant to operation_not_permitted.
* testsuite/30_threads/shared_lock/locking/112089.cc: New test.

(cherry picked from commit 0c305f3dec9a992dd775a3b9607b7b1e8c051859)

16 months agolibstdc++: Fix conditions for using memcmp in std::lexicographical_compare_three_way...
Jonathan Wakely [Tue, 27 Feb 2024 17:50:34 +0000 (17:50 +0000)] 
libstdc++: Fix conditions for using memcmp in std::lexicographical_compare_three_way [PR113960]

The change in r11-2981-g2f983fa69005b6 meant that
std::lexicographical_compare_three_way started to use memcmp for
unsigned integers on big endian targets, but for that to be valid we
need the two value types to have the same size and we need to use that
size to compute the length passed to memcmp.

I already defined a __is_memcmp_ordered_with trait that does the right
checks, std::lexicographical_compare_three_way just needs to use it.

libstdc++-v3/ChangeLog:

PR libstdc++/113960
* include/bits/stl_algobase.h (__is_byte_iter): Replace with ...
(__memcmp_ordered_with): New concept.
(lexicographical_compare_three_way): Use __memcmp_ordered_with
instead of __is_byte_iter. Use correct length for memcmp.
* testsuite/25_algorithms/lexicographical_compare_three_way/113960.cc:
New test.

(cherry picked from commit f5cdda8acb06c20335855ed353ab9a441c12128a)

16 months agolibstdc++: Do not use memmove for 1-element ranges [PR108846]
Jonathan Wakely [Sat, 25 Feb 2023 14:28:36 +0000 (14:28 +0000)] 
libstdc++: Do not use memmove for 1-element ranges [PR108846]

This avoids overwriting tail padding when algorithms like std::copy are
used to write a single value through a pointer to a base subobject.

The pointer arithmetic on a Base* is valid for N==1, but the copy/move
operation needs to be done using assignment, not a memmove or memcpy of
sizeof(Base) bytes.

Instead of putting a check for N==1 in all of copy, copy_n, move etc.
this adds it to the __copy_move and __copy_move_backward partial
specializations used for trivially copyable types. When N==1 those
partial specializations dispatch to new static member functions of the
partial specializations for non-trivial types, so that a copy/move
assignment is done appropriately for the _IsMove constant.

libstdc++-v3/ChangeLog:

PR libstdc++/108846
* include/bits/stl_algobase.h (__copy_move<false, false, RA>)
Add __assign_one static member function.
(__copy_move<true, false, RA>): Likewise.
(__copy_move<IsMove, true, RA>): Do not use memmove for a single
value.
(__copy_move_backward<IsMove, true, RA>): Likewise.
* testsuite/25_algorithms/copy/108846.cc: New test.
* testsuite/25_algorithms/copy_backward/108846.cc: New test.
* testsuite/25_algorithms/copy_n/108846.cc: New test.
* testsuite/25_algorithms/move/108846.cc: New test.
* testsuite/25_algorithms/move_backward/108846.cc: New test.

(cherry picked from commit 822a11a1e642e0abe92a996e7033a5066905a447)

16 months agolibstdc++: Make std::istream_iterator copy ctor constexpr (LWG 3600)
Jonathan Wakely [Wed, 22 Mar 2023 11:10:38 +0000 (11:10 +0000)] 
libstdc++: Make std::istream_iterator copy ctor constexpr (LWG 3600)

As explained in LWG 3600, we never implemented a C++0x change that made
the copy constructor of std::istream_iterator defined as defaulted. That
would be an ABI break, so the resolution of LWG 3600 is to not require
it to be trivial, but just constexpr and conditionally noexcept. This
applies that resolution.

libstdc++-v3/ChangeLog:

* include/bits/stream_iterator.h (istream_iterator): Add
constexpr to copy constructor, as per LWG 3600.
* testsuite/24_iterators/istream_iterator/cons/constexpr.cc:
Check copy construction.

(cherry picked from commit ad0b9cf1a076fb9a802d9ba7fa2223aa3166dca2)

16 months agolibstdc++: Add allocator-extended constructors to std::match_results (LWG 2195)
Jonathan Wakely [Wed, 22 Mar 2023 11:36:06 +0000 (11:36 +0000)] 
libstdc++: Add allocator-extended constructors to std::match_results (LWG 2195)

This was approved in Issaquah last month.

libstdc++-v3/ChangeLog:

* include/bits/regex.h (match_results): Add allocator-extended
copy and move constructors, as per LWG 2195.
* testsuite/28_regex/match_results/ctors/char/alloc.cc: New test.

(cherry picked from commit 9ae1108196ed65647846a7c06052317e8fa4852d)

16 months agolibstdc++: Add likely/unlikely attributes to <codecvt> implementation
Jonathan Wakely [Fri, 24 Feb 2023 21:28:11 +0000 (21:28 +0000)] 
libstdc++: Add likely/unlikely attributes to <codecvt> implementation

For the common case of converting valid text this improves performance
significantly.

libstdc++-v3/ChangeLog:

* src/c++11/codecvt.cc: Add [[likely]] and [[unlikely]]
attributes.

(cherry picked from commit a41a56dee5c2d48337739d60c43cab5074bcc8e7)

16 months agolibstdc++: Fix Unicode codecvt and add tests [PR86419]
Dimitrij Mijoski [Tue, 10 Jan 2023 12:58:59 +0000 (13:58 +0100)] 
libstdc++: Fix Unicode codecvt and add tests [PR86419]

Fixes the conversion from UTF-8 to UTF-16 to properly return partial
instead ok.
Fixes the conversion from UTF-16 to UTF-8 to properly return partial
instead ok.
Fixes the conversion from UTF-8 to UCS-2 to properly return partial
instead error.
Fixes the conversion from UTF-8 to UCS-2 to treat 4-byte UTF-8 sequences
as error just by seeing the leading byte.
Fixes UTF-8 decoding for all codecvts so they detect error at the end of
the input range when the last code point is also incomplete.

libstdc++-v3/ChangeLog:

PR libstdc++/86419
* src/c++11/codecvt.cc (read_utf8_code_point): Correctly detect
errors in incomplete multibyte sequences.
(utf16_in): Remove surrogates parameter. Fix conditions for
returning partial.
(utf16_out): Fix condition for returning partial.
(ucs2_in): Do not pass surrogates argument to utf16_in.
* testsuite/22_locale/codecvt/codecvt_unicode.cc: New test.
* testsuite/22_locale/codecvt/codecvt_unicode.h: New header for
tests.
* testsuite/22_locale/codecvt/codecvt_unicode_wchar_t.cc: New
test.

(cherry picked from commit 02dab998665dda0f6df31740e8897c42de3d740f)

16 months agolibstdc++: Add deprecated attribute to std::random_shuffle declarations
Jonathan Wakely [Wed, 26 Jul 2023 13:05:58 +0000 (14:05 +0100)] 
libstdc++: Add deprecated attribute to std::random_shuffle declarations

We already have these attributes on the definitions in <bits/stl_algo.h>
but they don't work due to PR c++/84542. Add the attributes to the
declarations in <bits/algorithmfwd.h> as well, and add a test.

libstdc++-v3/ChangeLog:

* include/bits/algorithmfwd.h (random_shuffle): Add deprecated
attribute.
* include/bits/stl_algo.h (random_shuffle): Correct comments.
* testsuite/25_algorithms/random_shuffle/1.cc: Disable
deprecated warnings.
* testsuite/25_algorithms/random_shuffle/59603.cc: Likewise.
* testsuite/25_algorithms/random_shuffle/moveable.cc: Likewise.
* testsuite/25_algorithms/random_shuffle/deprecated.cc: New
test.

(cherry picked from commit c01b344e814001e07fd304ce98d013d811e90192)

16 months agolibstdc++: Fix std::abs(__float128) for -NaN and -0.0 [PR109758]
Jonathan Wakely [Wed, 10 May 2023 11:20:58 +0000 (12:20 +0100)] 
libstdc++: Fix std::abs(__float128) for -NaN and -0.0 [PR109758]

The current implementation of this non-standard overload of std::abs
incorrectly returns a negative value for negative NaNs and negative
zero, because x < 0 is false in both cases.

Use fabsl(long double) or fabsf128(_Float128) if those do the right
thing.  Otherwise, use __builtin_signbit(x) instead of x < 0 to detect
negative inputs. This assumes that __builtin_signbit handles __float128
correctly, but that seems to be true for all of GCC, clang and icc.

libstdc++-v3/ChangeLog:

PR libstdc++/109758
* include/bits/std_abs.h (abs(__float128)): Handle negative NaN
and negative zero correctly.
* testsuite/26_numerics/headers/cmath/109758.cc: New test.

(cherry picked from commit af595613acbd9863198ae69c7b1c9e856bca9e4f)

16 months agolibstdc++: Fix -Wnonnull warnings during configure
Jonathan Wakely [Fri, 12 May 2023 11:17:08 +0000 (12:17 +0100)] 
libstdc++: Fix -Wnonnull warnings during configure

We should not test for nan by passing it a null pointer, as this can
trigger -Wnonnull warnings.

Also fix an outdated comment about the default -std mode.

libstdc++-v3/ChangeLog:

* acinclude.m4 (GLIBCXX_CHECK_C99_TR1): Use a non-null pointer
to check for nan, nanf, and nanl.
* configure: Regenerate.

(cherry picked from commit 6190a74ebee69415b501996821c92f60d892fb81)

16 months agolibstdc++: Add missing noexcept to std::scoped_allocator_adaptor
Jonathan Wakely [Fri, 26 May 2023 20:33:58 +0000 (21:33 +0100)] 
libstdc++: Add missing noexcept to std::scoped_allocator_adaptor

The standard requires these constructors and accessors to be noexcept.

libstdc++-v3/ChangeLog:

* include/std/scoped_allocator (scoped_allocator_adaptor): Add
noexcept to all constructors except the default constructor.
(scoped_allocator_adaptor::inner_allocator): Add noexcept.
(scoped_allocator_adaptor::outer_allocator): Likewise.
* testsuite/20_util/scoped_allocator/noexcept.cc: New test.

(cherry picked from commit b960c253e988c68ed3f3829125bc267bdf169356)

16 months agolibstdc++: Fix PSTL test that fails in C++20
Jonathan Wakely [Thu, 1 Jun 2023 15:49:53 +0000 (16:49 +0100)] 
libstdc++: Fix PSTL test that fails in C++20

This test fails in C++20 and later due to a warning:

warning: C++20 says that these are ambiguous, even though the second is reversed:
note: candidate 1: 'bool MyClass::operator==(const MyClass&)'
note: candidate 2: 'bool MyClass::operator==(const MyClass&)' (reversed)
note: try making the operator a 'const' member function
FAIL: 26_numerics/pstl/numeric_ops/transform_reduce.cc (test for excess errors)

libstdc++-v3/ChangeLog:

* testsuite/26_numerics/pstl/numeric_ops/transform_reduce.cc:
Add const to equality operator.

(cherry picked from commit f8403c43045cd56b5f775e1cf12a3f22feca4b58)

16 months agolibstdc++: Improve tests for emplace member of sequence containers
Jonathan Wakely [Thu, 8 Jun 2023 11:19:26 +0000 (12:19 +0100)] 
libstdc++: Improve tests for emplace member of sequence containers

Our existing tests for std::deque::emplace, std::list::emplace and
std::vector::emplace are poor. We only have compile tests for PR 52799
and the equivalent for a const_iterator as the insertion point. This
fails to check that the value is actually inserted correctly and the
right iterator is returned.

Add new tests that cover the existing 52799.cc and const_iterator.cc
compile-only tests, as well as verifying the effects are correct.

libstdc++-v3/ChangeLog:

* testsuite/23_containers/deque/modifiers/emplace/52799.cc:
Removed.
* testsuite/23_containers/deque/modifiers/emplace/const_iterator.cc:
Removed.
* testsuite/23_containers/list/modifiers/emplace/52799.cc:
Removed.
* testsuite/23_containers/list/modifiers/emplace/const_iterator.cc:
Removed.
* testsuite/23_containers/vector/modifiers/emplace/52799.cc:
Removed.
* testsuite/23_containers/vector/modifiers/emplace/const_iterator.cc:
Removed.
* testsuite/23_containers/deque/modifiers/emplace/1.cc: New
test.
* testsuite/23_containers/list/modifiers/emplace/1.cc: New
test.
* testsuite/23_containers/vector/modifiers/emplace/1.cc: New
test.

(cherry picked from commit 3ec1d76a359542ed4c8370390efa9ee9e25e757f)

16 months agolibstdc++: Qualify calls to std::_Destroy and _Destroy_aux
Jonathan Wakely [Fri, 30 Jun 2023 20:09:01 +0000 (21:09 +0100)] 
libstdc++: Qualify calls to std::_Destroy and _Destroy_aux

These calls should be qualified to prevent ADL, which can cause errors
for incomplete types that are associated classes.

libstdc++-v3/ChangeLog:

* include/bits/alloc_traits.h (_Destroy): Qualify call.
* include/bits/stl_construct.h (_Destroy, _Destroy_n): Likewise.
* testsuite/23_containers/vector/cons/destroy-adl.cc: New test.

(cherry picked from commit 33245d6b87a284495304c9952813b6b83d5df99f)

16 months agolibstdc++: Check for std::ratio in arithmetic and comparisons [PR110593]
Jonathan Wakely [Wed, 19 Jul 2023 17:18:46 +0000 (18:18 +0100)] 
libstdc++: Check for std::ratio in arithmetic and comparisons [PR110593]

The standard says that it should be ill-formed to use std::ratio_equal
etc. with types which are not specializations of std::ratio. This
implements that requirement.

We don't need to add assertions to every one of the class templates,
because many of them are implemented in terms of other ones. For
example, ratio_divide and ratio_subtract can rely on the assertions in
ratio_multiply and ratio_add respectively.

libstdc++-v3/ChangeLog:

PR libstdc++/110593
* include/bits/chrono.h (duration): Improve static assert
messages.
(__is_ratio): Move to ...
* include/std/ratio (__is_ratio): ... here.
(__is_ratio_v): New variable template and partial
specialization.
(__are_both_ratios): New function template.
(__ratio_multiply, ratio_equal, ratio_less, __ratio_add):
Add static assertion.
* testsuite/20_util/ratio/requirements/type_constraints.cc:
New test.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc:
Adjust expected error.
* testsuite/20_util/duration/requirements/typedefs_neg2.cc:
Likewise.

(cherry picked from commit 2d614822e9ea2a3d8800045d66e3220743753d09)

16 months agolibstdc++: Remove unconditional use of atomics in Debug Mode
Jonathan Wakely [Mon, 11 Sep 2023 15:42:54 +0000 (16:42 +0100)] 
libstdc++: Remove unconditional use of atomics in Debug Mode

The fix for PR 91910 (r10-3426-gf7a3a382279585) introduced unconditional
uses of atomics into src/c++11/debug.cc, which causes linker errors for
arm4t where GCC emits an unresolved reference to __sync_synchronize.

By making the uses of atomics depend on _GLIBCXX_HAS_GTHREADS we can
avoid those unconditional references to __sync_synchronize for targets
where the atomics are unnecessary. As a minor performance optimization
we can also check the __gnu_cxx::__is_single_threaded function to avoid
atomics for single-threaded programs even where they don't cause linker
errors.

libstdc++-v3/ChangeLog:

* src/c++11/debug.cc (acquire_sequence_ptr_for_lock): New
function.
(reset_sequence_ptr): New function.
(_Safe_iterator_base::_M_detach)
(_Safe_local_iterator_base::_M_detach): Replace bare atomic_load
with acquire_sequence_ptr_for_lock.
(_Safe_iterator_base::_M_reset): Replace bare atomic_store with
reset_sequence_ptr.

(cherry picked from commit 4a2766ed00a47904dc8b85bf0538aa116d8e658b)

16 months agolibstdc++: Fix std::basic_string::resize_and_overwrite
Jonathan Wakely [Tue, 15 Aug 2023 12:48:23 +0000 (13:48 +0100)] 
libstdc++: Fix std::basic_string::resize_and_overwrite

The callable used for resize_and_overwrite was being passed the string's
expanded capacity, which might be greater than the new size being
requested. This is not conforming, as the standard requires the same n
to be passed to the callable that the user passed to
resize_and_overwrite.

The existing tests didn't catch this because they all used a value which
was more than twice the existing capacity, so the _M_create call
allocated exactly what was requested, and the value passed to the
callable was correct. But when the requested size is greater than the
current capacity but smaller than twice the current capacity, _M_create
will allocate twice the current capacity and then that value was being
passed to the callable.

I noticed this because std::format(L"{}", 0.25) was producing L"0.25XX"
where the XX characters were whatever happened to be on the stack before
the call. When std::format used resize_and_overwrite to widen a string
it was copying too many characters into the destination and setting the
result's length too long.

libstdc++-v3/ChangeLog:

* include/bits/basic_string.tcc (resize_and_overwrite): Invoke
the callable with the same size as resize_and_overwrite was
called with.
* testsuite/21_strings/basic_string/capacity/char/resize_and_overwrite.cc:
Check with small values for the new size.

(cherry picked from commit 4a2b262597e4a6bc5732d4564673c1e19381dcfa)

16 months agolibstdc++: Use rvalues in std::string::resize_and_overwrite (LWG 3645)
Jonathan Wakely [Wed, 22 Mar 2023 11:54:31 +0000 (11:54 +0000)] 
libstdc++: Use rvalues in std::string::resize_and_overwrite (LWG 3645)

Previously the C++23 draft required that the callback arguments were
lvalues, which was overvable by the callback. LWG 3645 removes that
overspecification, so we can pass rvalues and the user can't modify
our local variables. I've used auto(p) to produce rvalues, which is only
supported since Clang 15, but I think that's OK for a C++23 feature.

While making this change I noticed that we weren't correctly enforcing
the requirement that the callback returns an integer-like type. Add
better assertions for the type and value.

libstdc++-v3/ChangeLog:

* include/bits/basic_string.tcc (basic_string::resize_and_overwrite):
Pass rvalues to the callback, as now allowed by LWG 3645.
Enforce preconditions on the return value.
* testsuite/21_strings/basic_string/capacity/char/resize_and_overwrite.cc:
Adjust.

(cherry picked from commit ba4f5530c475eadd2a7edb46b6c1c9d5f9267501)

16 months agolibstdc++: Fix some -Wmismatched-tags warnings
Jonathan Wakely [Tue, 8 Aug 2023 21:07:29 +0000 (22:07 +0100)] 
libstdc++: Fix some -Wmismatched-tags warnings

libstdc++-v3/ChangeLog:

* include/bits/shared_ptr_atomic.h (atomic): Change class-head
to struct.
* include/bits/stl_tree.h (_Rb_tree_merge_helper): Change
class-head to struct in friend declaration.
* include/std/future (_Task_state_base, _Task_state): Likewise.
* include/std/scoped_allocator (__inner_type_impl): Likewise.
* include/std/valarray (_BinClos, _SClos, _GClos, _IClos)
(_ValFunClos, _RefFunClos): Change class-head to struct.

(cherry picked from commit 5b46eacc4949ec62ee718b172cf8eb056ff27654)

16 months agolibstdc++: Update outdated default -std in testing docs
Jonathan Wakely [Fri, 8 Sep 2023 15:28:06 +0000 (16:28 +0100)] 
libstdc++: Update outdated default -std in testing docs

libstdc++-v3/ChangeLog:

* doc/xml/manual/test.xml: Update reference to -std=gnu++14 as
the default.
* doc/html/manual/test.html: Regenerate.

(cherry picked from commit d8e351d8d656720f4037e0a86a4a6c73629e5307)

16 months agolibstdc++: Fix unconditional -Werror in libbacktrace directory
Alexey Lapshin [Fri, 8 Sep 2023 10:23:16 +0000 (11:23 +0100)] 
libstdc++: Fix unconditional -Werror in libbacktrace directory

The -Werror flag should depend on the --enable-werror configure option.

libstdc++-v3/ChangeLog:

* src/libbacktrace/Makefile.am: Remove -Werror.
* src/libbacktrace/Makefile.in: Regenerate.

(cherry picked from commit 1a0c6decd2112267c88438466df2e1c46b20248e)

16 months agolibstdc++: Ensure active union member is correctly set
Nathaniel Shead [Fri, 29 Sep 2023 09:30:41 +0000 (10:30 +0100)] 
libstdc++: Ensure active union member is correctly set

This patch ensures that the union members for std::string and
std::variant are always properly set when a change occurs.

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h: (basic_string(basic_string&&)):
Activate _M_local_buf when needed.
(basic_string(basic_string&&, const _Alloc&)): Likewise.
* include/bits/basic_string.tcc: (basic_string::swap): Likewise.
* include/std/variant: (__detail::__variant::__construct_n): New.
(__detail::__variant::__emplace): Use __construct_n.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
(cherry picked from commit 28adad7a32ed92a3c0906b38411c4ed686bbacc5)

16 months agolibstdc++: Fix warning during configure
Jonathan Wakely [Wed, 1 Nov 2023 14:20:33 +0000 (14:20 +0000)] 
libstdc++: Fix warning during configure

The checks for snprintf give a -Wformat warning due to a missing
argument.

libstdc++-v3/ChangeLog:

* acinclude.m4 (GLIBCXX_ENABLE_C99): Fix snprintf checks.
* configure: Regenerate.

(cherry picked from commit 8a4cde6319b40802a842a8fe71267524dd8af828)

16 months agolibstdc++: Fix std::tr2::dynamic_bitset support for alternate characters
Jonathan Wakely [Sat, 18 Nov 2023 21:09:53 +0000 (21:09 +0000)] 
libstdc++: Fix std::tr2::dynamic_bitset support for alternate characters

libstdc++-v3/ChangeLog:

* include/tr2/dynamic_bitset (dynamic_bitset): Pass zero and one
characters to _M_copy_from_string.
* testsuite/tr2/dynamic_bitset/string.cc: New test.

(cherry picked from commit 49f7620a12e35f40bb1f6088d16bde9b061dc819)

16 months agolibstdc++: Fix <charconv> uses of signed types with <bit> functions
Jonathan Wakely [Tue, 14 Nov 2023 10:56:57 +0000 (10:56 +0000)] 
libstdc++: Fix <charconv> uses of signed types with <bit> functions

In <charconv> we pass the int __base parameter to our internal versions
of <bit> functions, __bit_width and __countr_zero. Those functions are
only defined for unsigned types, so we need to convert the base to
unsigned. The base must be in the range [2,36] so we can mask off the
low bits and then convert that to unsigned, so that we don't need to
care about negative values becoming large unsigned values.

libstdc++-v3/ChangeLog:

* include/std/charconv (__from_chars_pow2_base): Convert base to
unsigned for call to __countr_zero.
(__from_chars_alnum): Likewise for call to __bit_width.

(cherry picked from commit 1c15303375f7089ff985b085ab877b11ebfbc4b7)

16 months agolibstdc++: Fix access error in __gnu_test::uneq_allocator
Jonathan Wakely [Thu, 23 Nov 2023 14:34:59 +0000 (14:34 +0000)] 
libstdc++: Fix access error in __gnu_test::uneq_allocator

The operator== function is only a friend of the LHS argument, so cannot
access the private member of the RHS argument. Use the public accessor
instead.

libstdc++-v3/ChangeLog:

* testsuite/util/testsuite_allocator.h (uneq_allocator): Fix
equality operator for heterogeneous comparisons.

(cherry picked from commit 0585daf7de0673ade9feca1be66a68178786b48d)

16 months agolibstdc++: Correct notes about std::call_once in manual [PR66146]
Jonathan Wakely [Thu, 14 Mar 2024 11:52:17 +0000 (11:52 +0000)] 
libstdc++: Correct notes about std::call_once in manual [PR66146]

The bug with exceptions thrown during a std::call_once call affects all
targets, so fix the docs that say it only affects non-Linux targets.

libstdc++-v3/ChangeLog:

PR libstdc++/66146
* doc/xml/manual/status_cxx2011.xml: Remove mention of Linux in
note about std::call_once.
* doc/xml/manual/status_cxx2014.xml: Likewise.
* doc/xml/manual/status_cxx2017.xml: Likewise.
* doc/html/manual/status.html: Regenerate.

(cherry picked from commit e6836bbbd7a01af0791c02087e568b4822418c0d)

16 months agolibstdc++: Move test error_category to global scope
Jonathan Wakely [Wed, 13 Mar 2024 10:02:12 +0000 (10:02 +0000)] 
libstdc++: Move test error_category to global scope

A recent GDB change causes this test to fail due to missing RTTI for the
custom_cast type. This is presumably because the custom_cat type was
defined as a local class, so has no linkage. Moving it to local scope
seems to fix the test regressions, and probably makes the test more
realistic as a local class with no linkage isn't practical to use as an
error category that almost certainly needs to be referred to in other
scopes.

libstdc++-v3/ChangeLog:

* testsuite/libstdc++-prettyprinters/cxx11.cc: Move custom_cat
to namespace scope.

(cherry picked from commit a8c7c3a40953e34f57278d224a07dc3698c64a84)

16 months agolibstdc++: Change some URLs in the manual to use https
Jonathan Wakely [Wed, 28 Feb 2024 14:36:28 +0000 (14:36 +0000)] 
libstdc++: Change some URLs in the manual to use https

libstdc++-v3/ChangeLog:

* doc/xml/manual/appendix_contributing.xml: Change URLs to use
https.
* doc/html/manual/*: Regenerate.

(cherry picked from commit 06866bc368f828fa4f3dad25588d038414944c2e)

16 months agolibstdc++: Update outdated docs on contributing
Jonathan Wakely [Wed, 28 Feb 2024 11:24:47 +0000 (11:24 +0000)] 
libstdc++: Update outdated docs on contributing

We don't want a separate ChangeLog submission now.

libstdc++-v3/ChangeLog:

* doc/xml/manual/appendix_contributing.xml: Replace outdated
info on ChangeLog entries.
* doc/html/manual/appendix_contributing.html: Regenerate.

(cherry picked from commit 7c7c937b5e71cf2b53f462cfa6a1df39b5538cee)

16 months agolibstdc++: Simplify lifetime of eh_globals variable [PR107500]
Jonathan Wakely [Thu, 3 Nov 2022 11:48:57 +0000 (11:48 +0000)] 
libstdc++: Simplify lifetime of eh_globals variable [PR107500]

Since this is a trivial type, we probably don't need to do anything to
ensure it's still accessible after other static dtors.

libstdc++-v3/ChangeLog:

PR libstdc++/107500
* libsupc++/eh_globals.cc (eh_globals): Remove immortalizing
wrapper.
(__cxxabiv1::__cxa_get_globals_fast): Adjust.
(__cxxabiv1::__cxa_get_globals): Adjust.

(cherry picked from commit 418999fe382c608facf57f96b53a9cb12d2fdd20)

16 months agolibstdc++: Add missing std::tuple constructor [PR114147]
Jonathan Wakely [Fri, 1 Mar 2024 11:16:58 +0000 (11:16 +0000)] 
libstdc++: Add missing std::tuple constructor [PR114147]

I caused a regression with commit r10-908 by adding a constraint to the
non-explicit allocator-extended default constructor, but seemingly
forgot to add an explicit overload with the corresponding constraint.

libstdc++-v3/ChangeLog:

PR libstdc++/114147
* include/std/tuple (tuple::tuple(allocator_arg_t, const Alloc&)):
Add missing overload of allocator-extended default constructor.
(tuple<T1,T2>::tuple(allocator_arg_t, const Alloc&)): Likewise.
* testsuite/20_util/tuple/cons/114147.cc: New test.

(cherry picked from commit 0a545ac7000501844670add0b3560ebdbcb123c6)

16 months agoDaily bump.
GCC Administrator [Mon, 18 Mar 2024 00:19:51 +0000 (00:19 +0000)] 
Daily bump.

16 months agoDarwin, Objective-C: Support -fconstant-cfstrings [PR108743].
Iain Sandoe [Sun, 2 Jul 2023 13:18:04 +0000 (14:18 +0100)] 
Darwin, Objective-C: Support -fconstant-cfstrings [PR108743].

This support the -fconstant-cfstrings option as used by clang (and
expect by some build scripts) as an alias to the target-specific
-mconstant-cfstrings.

The documentation is also updated to reflect that the 'f' option is
only available on Darwin, and to add the 'm' option to the Darwin
section of the invocation text.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
PR target/108743

gcc/ChangeLog:

* config/darwin.opt: Add fconstant-cfstrings alias to
mconstant-cfstrings.
* doc/invoke.texi: Amend invocation descriptions to reflect
that the fconstant-cfstrings is a target-option alias and to
add the missing mconstant-cfstrings option description to the
Darwin section.

(cherry picked from commit cdd4b3c0f0f428678c24de74b1f626628450799c)

16 months agoDarwin: Fix bootstrap break on X86.
Iain Sandoe [Sun, 17 Mar 2024 03:04:44 +0000 (03:04 +0000)] 
Darwin: Fix bootstrap break on X86.

The changes in r12-9536-gefcca6481eab18 mangled the whitespace in
the ENDFILE_SPEC i386/darwin.h leading to a bootstrap fail.

gcc/ChangeLog:

* config/i386/darwin.h (ENDFILE_SPEC): Fix whitespace.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
16 months agoDaily bump.
GCC Administrator [Sun, 17 Mar 2024 00:20:21 +0000 (00:20 +0000)] 
Daily bump.

16 months agoDaily bump.
GCC Administrator [Sat, 16 Mar 2024 00:20:33 +0000 (00:20 +0000)] 
Daily bump.

16 months agoDaily bump.
GCC Administrator [Fri, 15 Mar 2024 00:21:10 +0000 (00:21 +0000)] 
Daily bump.

16 months agoi386[stv]: Handle REG_EH_REGION note
liuhongt [Wed, 13 Mar 2024 02:40:01 +0000 (10:40 +0800)] 
i386[stv]: Handle REG_EH_REGION note

When we split
(insn 37 36 38 10 (set (reg:DI 104 [ _18 ])
        (mem:DI (reg/f:SI 98 [ CallNative_nclosure.0_1 ]) [6 MEM[(struct SQRefCounted *)CallNative_nclosure.0_1]._uiRef+0 S8 A32])) "test.C":22:42 84 {*movdi_internal}
     (expr_list:REG_EH_REGION (const_int -11 [0xfffffffffffffff5])

into

(insn 104 36 37 10 (set (subreg:V2DI (reg:DI 124) 0)
        (vec_concat:V2DI (mem:DI (reg/f:SI 98 [ CallNative_nclosure.0_1 ]) [6 MEM[(struct SQRefCounted *)CallNative_nclosure.0_1]._uiRef+0 S8 A32])
            (const_int 0 [0]))) "test.C":22:42 -1
        (nil)))
(insn 37 104 105 10 (set (subreg:V2DI (reg:DI 104 [ _18 ]) 0)
        (subreg:V2DI (reg:DI 124) 0)) "test.C":22:42 2024 {movv2di_internal}
     (expr_list:REG_EH_REGION (const_int -11 [0xfffffffffffffff5])
        (nil)))

we must copy the REG_EH_REGION note to the first insn and split the block
after the newly added insn.  The REG_EH_REGION on the second insn will be
removed later since it no longer traps.

gcc/ChangeLog:

* config/i386/i386-features.cc
(general_scalar_chain::convert_op): Handle REG_EH_REGION note.
(convert_scalars_to_vector): Ditto.
* config/i386/i386-features.h (class scalar_chain): New
memeber control_flow_insns.

gcc/testsuite/ChangeLog:

* g++.target/i386/pr111822.C: New test.

(cherry picked from commit 618e34d56cc38e9c3ae95a413228068e53ed76bb)

16 months agoDaily bump.
GCC Administrator [Thu, 14 Mar 2024 00:22:31 +0000 (00:22 +0000)] 
Daily bump.

16 months agolibstdc++: Remove UB from month and weekday additions and subtractions.
Cassio Neri [Sun, 10 Dec 2023 11:31:31 +0000 (11:31 +0000)] 
libstdc++: Remove UB from month and weekday additions and subtractions.

The following invoke signed integer overflow (UB) [1]:

  month   + months{MAX} // where MAX is the maximum value of months::rep
  month   + months{MIN} // where MIN is the maximum value of months::rep
  month   - months{MIN} // where MIN is the minimum value of months::rep
  weekday + days  {MAX} // where MAX is the maximum value of days::rep
  weekday - days  {MIN} // where MIN is the minimum value of days::rep

For the additions to MAX, the crux of the problem is that, in libstdc++,
months::rep and days::rep are int64_t. Other implementations use int32_t, cast
operands to int64_t and perform arithmetic operations without risk of
overflowing.

For month + months{MIN}, the implementation follows the Standard's "returns
clause" and evaluates:

   modulo(static_cast<long long>(unsigned{__x}) + (__y.count() - 1), 12);

Overflow occurs when MIN - 1 is evaluated. Casting to a larger type could help
but, unfortunately again, this is not possible for libstdc++.

For the subtraction of MIN, the problem is that -MIN is not representable.

It's fair to say that the intention is for these additions/subtractions to
be performed in modulus (12 or 7) arithmetic so that no overflow is expected.

To fix these UB, this patch implements:

  template <unsigned __d, typename _T>
  unsigned __add_modulo(unsigned __x, _T __y);

  template <unsigned __d, typename _T>
  unsigned __sub_modulo(unsigned __x, _T __y);

which respectively, returns the remainder of Euclidean division of, __x + __y
and __x - __y by __d without overflowing. These functions replace

  constexpr unsigned __modulo(long long __n, unsigned __d);

which also calculates the reminder of __n, where __n is the result of the
addition or subtraction. Hence, these operations might invoke UB before __modulo
is called and thus, __modulo can't do anything to remediate the issue.

In addition to solve the UB issues, __add_modulo and __sub_modulo allow better
codegen (shorter and branchless) on x86-64 and ARM [2].

[1] https://godbolt.org/z/a9YfWdn57
[2] https://godbolt.org/z/Gh36cr7E4

libstdc++-v3/ChangeLog:

* include/std/chrono: Fix + and - for months and weekdays.
* testsuite/std/time/month/1.cc: Add constexpr tests against overflow.
* testsuite/std/time/month/2.cc: New test for extreme values.
* testsuite/std/time/weekday/1.cc: Add constexpr tests against overflow.
* testsuite/std/time/weekday/2.cc: New test for extreme values.

(cherry picked from commit 2cb3d42d3f3e7a5345ee7a6f3676a10c84864d72)

16 months agolibstdc++: Improve operator-(weekday x, weekday y)
Cassio Neri [Tue, 14 Nov 2023 00:27:39 +0000 (00:27 +0000)] 
libstdc++: Improve operator-(weekday x, weekday y)

The current implementation calls __detail::__modulo which is relatively
expensive.

A better implementation is possible if we assume that x.ok() && y.ok() == true,
so that n = x.c_encoding() - y.c_encoding() is in [-6, 6]. In this case, it
suffices to return n >= 0 ? n : n + 7.

The above is allowed by [time.cal.wd.nonmembers]/5: the returned value is
unspecified when x.ok() || y.ok() == false.

The assembly emitted for x86-64 and ARM can be seen in:
https://godbolt.org/z/nMdc5vv9n.

libstdc++-v3/ChangeLog:

* include/std/chrono (operator-(const weekday&, const weekday&)):
Optimize.

(cherry picked from commit f71352c71d78ac977ea0e71a6900699a8cf09219)