aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog115
-rw-r--r--gcc/DATESTAMP2
-rw-r--r--gcc/auto-profile.cc10
-rw-r--r--gcc/bb-reorder.cc6
-rw-r--r--gcc/c-family/ChangeLog16
-rw-r--r--gcc/c-family/c.opt48
-rw-r--r--gcc/cfghooks.cc2
-rw-r--r--gcc/common/config/i386/cpuinfo.h2
-rw-r--r--gcc/common/config/i386/i386-common.cc2
-rw-r--r--gcc/config/i386/i386.h4
-rw-r--r--gcc/config/riscv/autovec-opt.md4
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/parser.cc2
-rw-r--r--gcc/doc/invoke.texi18
-rw-r--r--gcc/ipa-fnsummary.cc3
-rw-r--r--gcc/ipa-inline-transform.cc3
-rw-r--r--gcc/predict.cc10
-rw-r--r--gcc/profile-count.h39
-rw-r--r--gcc/testsuite/ChangeLog62
-rw-r--r--gcc/testsuite/g++.dg/template/dependent-base6.C4
-rw-r--r--gcc/testsuite/gcc.dg/vect/pr120687-1.c2
-rw-r--r--gcc/testsuite/gcc.dg/vect/pr120687-2.c2
-rw-r--r--gcc/testsuite/gcc.dg/vect/pr120687-3.c2
-rw-r--r--gcc/testsuite/gcc.dg/vect/pr121949_1.c45
-rw-r--r--gcc/testsuite/gcc.dg/vect/pr121949_2.c45
-rw-r--r--gcc/testsuite/gcc.dg/vect/pr121949_3.c45
-rw-r--r--gcc/tree-ssa-loop-unswitch.cc3
-rw-r--r--gcc/tree-vect-loop.cc251
-rw-r--r--gcc/tree-vect-patterns.cc19
-rw-r--r--gcc/tree-vect-slp.cc432
-rw-r--r--gcc/tree-vect-stmts.cc175
-rw-r--r--gcc/tree-vectorizer.h19
-rw-r--r--libstdc++-v3/ChangeLog151
-rw-r--r--libstdc++-v3/include/bits/atomic_base.h2
-rw-r--r--libstdc++-v3/include/bits/chrono.h72
-rw-r--r--libstdc++-v3/include/bits/hashtable.h18
-rw-r--r--libstdc++-v3/include/bits/shared_ptr_atomic.h57
-rw-r--r--libstdc++-v3/include/bits/std_mutex.h26
-rw-r--r--libstdc++-v3/include/bits/stl_map.h20
-rw-r--r--libstdc++-v3/include/bits/stl_multimap.h20
-rw-r--r--libstdc++-v3/include/bits/stl_multiset.h12
-rw-r--r--libstdc++-v3/include/bits/stl_set.h12
-rw-r--r--libstdc++-v3/include/bits/stl_tree.h4
-rw-r--r--libstdc++-v3/include/bits/this_thread_sleep.h20
-rw-r--r--libstdc++-v3/include/bits/unordered_map.h20
-rw-r--r--libstdc++-v3/include/bits/unordered_set.h20
-rw-r--r--libstdc++-v3/include/debug/map.h18
-rw-r--r--libstdc++-v3/include/debug/multimap.h18
-rw-r--r--libstdc++-v3/include/debug/multiset.h10
-rw-r--r--libstdc++-v3/include/debug/set.h10
-rw-r--r--libstdc++-v3/include/debug/unordered_map24
-rw-r--r--libstdc++-v3/include/debug/unordered_set24
-rw-r--r--libstdc++-v3/include/std/condition_variable20
-rw-r--r--libstdc++-v3/include/std/format198
-rw-r--r--libstdc++-v3/include/std/mutex18
-rw-r--r--libstdc++-v3/include/std/shared_mutex39
-rw-r--r--libstdc++-v3/python/libstdcxx/v6/printers.py6
-rw-r--r--libstdc++-v3/src/c++11/thread.cc48
-rw-r--r--libstdc++-v3/src/c++17/fs_path.cc74
-rw-r--r--libstdc++-v3/src/c++20/atomic.cc18
-rw-r--r--libstdc++-v3/testsuite/20_util/shared_ptr/atomic/pr118757.cc29
-rw-r--r--libstdc++-v3/testsuite/20_util/weak_ptr/pr118757.cc30
-rw-r--r--libstdc++-v3/testsuite/30_threads/condition_variable/members/116586.cc60
-rw-r--r--libstdc++-v3/testsuite/30_threads/future/members/116586.cc55
-rw-r--r--libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/116586.cc72
-rw-r--r--libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_for.cc22
-rw-r--r--libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_until.cc24
-rw-r--r--libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock_until/116586.cc97
-rw-r--r--libstdc++-v3/testsuite/30_threads/this_thread/113327.cc29
-rw-r--r--libstdc++-v3/testsuite/30_threads/this_thread/sleep_for.cc13
-rw-r--r--libstdc++-v3/testsuite/30_threads/this_thread/sleep_until.cc26
-rw-r--r--libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/116586.cc57
-rw-r--r--libstdc++-v3/testsuite/std/format/ranges/string.cc89
-rw-r--r--libstdc++-v3/testsuite/std/time/month_day/io.cc41
-rw-r--r--libstdc++-v3/testsuite/std/time/month_day_last/io.cc41
-rw-r--r--libstdc++-v3/testsuite/std/time/month_weekday/io.cc41
-rw-r--r--libstdc++-v3/testsuite/std/time/month_weekday_last/io.cc41
-rw-r--r--libstdc++-v3/testsuite/std/time/weekday_indexed/io.cc41
-rw-r--r--libstdc++-v3/testsuite/std/time/weekday_last/io.cc41
-rw-r--r--libstdc++-v3/testsuite/std/time/year_month/io.cc41
80 files changed, 2348 insertions, 920 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 19c28f1..8a7cb97 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,118 @@
+2025-10-14 Richard Biener <rguenther@suse.de>
+
+ * tree-vectorizer.h (REDUC_GROUP_FIRST_ELEMENT,
+ REDUC_GROUP_NEXT_ELEMENT, REDUC_GROUP_SIZE): Remove.
+ * tree-vect-slp.cc (REDUC_GROUP_FIRST_ELEMENT): Re-instantiate
+ here.
+
+2025-10-14 Richard Biener <rguenther@suse.de>
+
+ * tree-vect-slp.cc (vect_analyze_slp_reduction): Move
+ reduction chain discovery ...
+ (vect_analyze_slp_reduc_chain): ... here.
+
+2025-10-14 Richard Biener <rguenther@suse.de>
+
+ * tree-vect-loop.cc (vect_create_epilog_for_reduction): Move
+ bitsize compute down to where it is used and consistently
+ use vectype1 for element extraction.
+
+2025-10-14 Tamar Christina <tamar.christina@arm.com>
+
+ PR tree-optimization/121949
+ * tree-vect-patterns.cc (vect_recog_vector_vector_shift_pattern): Remove
+ restriction on internal_def.
+
+2025-10-14 Robin Dapp <rdapp@ventanamicro.com>
+
+ * tree-vect-stmts.cc (get_load_store_type): Add load-permutation
+ checks and setting of slp_perm.
+ (vectorizable_store): Remove perm_ok argument.
+ (vectorizable_load): Ditto and replace slp_perm by ls.slp_perm.
+ * tree-vectorizer.h (struct vect_load_store_data): Add slp_perm.
+
+2025-10-14 Richard Biener <rguenther@suse.de>
+
+ * tree-vectorizer.h (vect_reduc_info_s::is_reduc_chain): New.
+ (_loop_vec_info::reduction_chains): Remove.
+ (LOOP_VINFO_REDUCTION_CHAINS): Likewise.
+ * tree-vect-patterns.cc (vect_reassociating_reduction_p):
+ Do not special-case reduction group stmts.
+ * tree-vect-loop.cc (vect_is_simple_reduction): Remove
+ reduction chain handling.
+ (vect_analyze_scalar_cycles_1): Remove slp parameter and adjust.
+ (vect_analyze_scalar_cycles): Likewise.
+ (vect_fixup_reduc_chain): Remove.
+ (vect_fixup_scalar_cycles_with_patterns): Likewise.
+ (vect_analyze_loop_2): Adjust.
+ (vect_create_epilog_for_reduction): Check the reduction info
+ for whether this is a reduction chain.
+ (vect_transform_cycle_phi): Likewise.
+ (vectorizable_reduction): Likewise. Simplify code for all-SLP.
+ * tree-vect-slp.cc (vect_analyze_slp_reduc_chain): Simplify.
+ (vect_analyze_slp_reduction): New function, perform reduction
+ chain discovery here.
+ (vect_analyze_slp): Remove reduction chain handling.
+ Use vect_analyze_slp_reduction for possible reduction chain
+ processing.
+
+2025-10-14 Haochen Jiang <haochen.jiang@intel.com>
+
+ * common/config/i386/cpuinfo.h
+ (get_available_features): Remove AMX-TRANSPOSE.
+ * common/config/i386/i386-common.cc
+ (OPTION_MASK_ISA2_AMX_TRANSPOSE_SET): Removed.
+ (OPTION_MASK_ISA2_AMX_TRANSPOSE_UNSET): Ditto.
+ (ix86_handle_option): Remove amx-transpose handle.
+ * common/config/i386/i386-cpuinfo.h
+ (enum processor_features): Remove FEATURE_AMX_TRANSPOSE.
+ Set FEATURE_AMX_MOVRS value.
+ * common/config/i386/i386-isas.h: Remove AMX-TRANSPOSE.
+ * config.gcc: Do not include amxtransposeintrin.h.
+ * config/i386/amxmovrsintrin.h: Remove AMX-TRANSPOSE intrins.
+ * config/i386/amxtransposeintrin.h: Ditto.
+ * config/i386/cpuid.h (bit_AMX_TRANSPOSE): Removed.
+ * config/i386/i386.h (PTA_DIAMONDRAPIDS): Remove AMX-TRANSPOSE.
+ * config/i386/i386-c.cc (ix86_target_macros_internal): Remove
+ AMX_TRANSPOSE.
+ * config/i386/i386-isa.def (AMX_TRANSPOSE): Removed.
+ * config/i386/i386-options.cc
+ (ix86_valid_target_attribute_inner_p): Remove AMX-TRANSPOSE.
+ * config/i386/i386.opt: Ditto.
+ * config/i386/i386.opt.urls: Ditto.
+ * config/i386/immintrin.h: Remove amxtransposeintrin.h.
+ * doc/extend.texi: Remove amx-transpose.
+ * doc/invoke.texi: Ditto.
+ * doc/sourcebuild.texi: Ditto.
+
+2025-10-14 Andrew Pinski <andrew.pinski@oss.qualcomm.com>
+
+ * tree-ssa-phiopt.cc (pass_phiopt::execute): Disable
+ cselim-limited and factor out operations for -Og.
+
+2025-10-14 Andrew Pinski <andrew.pinski@oss.qualcomm.com>
+
+ PR tree-optimization/122178
+ * tree-ssa-phiopt.cc (cond_if_else_store_replacement_1): Handle
+ clobber statements.
+
+2025-10-14 Andrew Pinski <andrew.pinski@oss.qualcomm.com>
+
+ PR tree-optimization/122182
+ * tree-ssa-dom.cc (cprop_operand): Don't check may_propagate_copy_into_asm.
+ * tree-ssa-propagate.cc (substitute_and_fold_engine::replace_uses_in): Don't
+ check may_propagate_copy_into_asm.
+ (may_propagate_copy_into_asm): Remove.
+ * tree-ssa-propagate.h (may_propagate_copy_into_asm): Remove.
+
+2025-10-14 Zhongyao Chen <chenzhongyao.hit@gmail.com>
+
+ * common/config/riscv/riscv-common.cc (riscv_subset_list::get_profile_name):
+ New function.
+ * config/riscv/riscv-c.cc (riscv_cpu_cpp_builtins): Define
+ profile macro if a profile is detected.
+ * config/riscv/riscv-subset.h (riscv_subset_list::get_profile_name): Declare.
+
2025-10-13 Shreya Munnangi <smunnangi1@ventanamicro.com>
PR target/120811
diff --git a/gcc/DATESTAMP b/gcc/DATESTAMP
index 75df97b..0535efa 100644
--- a/gcc/DATESTAMP
+++ b/gcc/DATESTAMP
@@ -1 +1 @@
-20251014
+20251015
diff --git a/gcc/auto-profile.cc b/gcc/auto-profile.cc
index 6971204..cf7a219 100644
--- a/gcc/auto-profile.cc
+++ b/gcc/auto-profile.cc
@@ -3600,11 +3600,12 @@ scale_bb_profile ()
{
profile_count cnt = bb->count;
bbs.safe_push (bb);
- max_count = max_count.max (bb->count);
+ max_count = profile_count::max_prefer_initialized (max_count, cnt);
if (afdo_set_bb_count (bb, zero_bbs))
{
std::swap (cnt, bb->count);
- max_count_in_fn = max_count_in_fn.max (cnt);
+ max_count_in_fn
+ = profile_count::max_prefer_initialized (max_count_in_fn, cnt);
add_scale (&scales, cnt, bb->count);
}
}
@@ -3646,7 +3647,8 @@ afdo_adjust_guessed_profile (bb_set *annotated_bb)
if (is_bb_annotated (seed_bb, *annotated_bb))
{
component[seed_bb->index] = 1;
- max_count_in_fn = max_count_in_fn.max (seed_bb->count);
+ max_count_in_fn
+ = profile_count::max_prefer_initialized (max_count_in_fn, seed_bb->count);
}
else
component[seed_bb->index] = 0;
@@ -3669,7 +3671,7 @@ afdo_adjust_guessed_profile (bb_set *annotated_bb)
basic_block b = stack.pop ();
bbs.quick_push (b);
- max_count = max_count.max (b->count);
+ max_count = profile_count::max_prefer_initialized (max_count, b->count);
for (edge e: b->preds)
if (!component[e->src->index])
diff --git a/gcc/bb-reorder.cc b/gcc/bb-reorder.cc
index 641b492..e4efdee 100644
--- a/gcc/bb-reorder.cc
+++ b/gcc/bb-reorder.cc
@@ -2389,8 +2389,10 @@ edge_order (const void *ve1, const void *ve2)
/* Since profile_count::operator< does not establish a strict weak order
in presence of uninitialized counts, use 'max': this makes them appear
as if having execution frequency less than any initialized count. */
- profile_count m = c1.max (c2);
- return (m == c2) - (m == c1);
+ gcov_type gc1 = c1.initialized_p () ? c1.to_gcov_type () : 0;
+ gcov_type gc2 = c2.initialized_p () ? c2.to_gcov_type () : 0;
+ gcov_type m = MAX (gc1, gc2);
+ return (m == gc1) - (m == gc2);
}
/* Reorder basic blocks using the "simple" algorithm. This tries to
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 07ea6aa..16cdcf3 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,19 @@
+2025-10-14 Jakub Jelinek <jakub@redhat.com>
+
+ * c.opt (Wflex-array-member-not-at-end, Wignored-qualifiers,
+ Wopenacc-parallelism, Wstrict-flex-arrays, Wsync-nand,
+ fstrict-flex-arrays, fstrict-flex-arrays=): Enable also for ObjC and
+ ObjC++ next to C and C++.
+ (Wmisleading-indentation, Wopenmp-simd): Likewise. Also change
+ LangEnabledBy from just C C++ to C ObjC C++ ObjC++.
+ (Wplacement-new, Wplacement-new=, fcontract-assumption-mode=,
+ fcontract-build-level=, fcontract-strict-declarations=,
+ fcontract-mode=, fcontract-continuation-mode=, fcontract-role=,
+ fcontract-semantic=, fcoroutines, flang-info-include-translate,
+ flang-info-include-translate-not, flang-info-include-translate=,
+ flang-info-module-cmi, flang-info-module-cmi=): Enable also
+ for ObjC++ next to C++.
+
2025-10-13 Iain Sandoe <iain@sandoe.co.uk>
* c.opt: Enable Wignored-attributes for Objective-C and
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index a7fd14a..b7ce67a 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -774,7 +774,7 @@ C++ ObjC++ Var(warn_extra_semi) Init(-1) Warning
Warn about semicolon after in-class function definition.
Wflex-array-member-not-at-end
-C C++ Var(warn_flex_array_member_not_at_end) Warning
+C ObjC C++ ObjC++ Var(warn_flex_array_member_not_at_end) Warning
Warn when a structure containing a C99 flexible array member as the last
field is not at the end of another structure.
@@ -866,7 +866,7 @@ C ObjC C++ ObjC++ Var(warn_if_not_aligned) Init(1) Warning
Warn when the field in a struct is not aligned.
Wignored-qualifiers
-C C++ Var(warn_ignored_qualifiers) Warning EnabledBy(Wextra)
+C ObjC C++ ObjC++ Var(warn_ignored_qualifiers) Warning EnabledBy(Wextra)
Warn whenever type qualifiers are ignored.
Wignored-attributes
@@ -1013,7 +1013,7 @@ C ObjC C++ ObjC++ Var(warn_memset_transposed_args) Warning LangEnabledBy(C ObjC
Warn about suspicious calls to memset where the third argument is constant literal zero and the second is not.
Wmisleading-indentation
-C C++ Common Var(warn_misleading_indentation) Warning LangEnabledBy(C C++,Wall)
+C ObjC C++ ObjC++ Common Var(warn_misleading_indentation) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
Warn when the indentation of the code does not reflect the block structure.
Wmismatched-dealloc
@@ -1187,7 +1187,7 @@ C ObjC Var(warn_old_style_definition) Init(-1) Warning
Warn if an old-style parameter definition is used.
Wopenacc-parallelism
-C C++ Var(warn_openacc_parallelism) Warning
+C ObjC C++ ObjC++ Var(warn_openacc_parallelism) Warning
Warn about potentially suboptimal choices related to OpenACC parallelism.
Wopenmp
@@ -1195,7 +1195,7 @@ C ObjC C++ ObjC++ Warning Var(warn_openmp) Init(1)
Warn about suspicious OpenMP code.
Wopenmp-simd
-C C++ Var(warn_openmp_simd) Warning LangEnabledBy(C C++,Wall)
+C ObjC C++ ObjC++ Var(warn_openmp_simd) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
Warn if a simd directive is overridden by the vectorizer cost model.
Woverlength-strings
@@ -1243,11 +1243,11 @@ C++ ObjC++ Var(warn_pessimizing_move) Warning LangEnabledBy(C++ ObjC++, Wall)
Warn about calling std::move on a local object in a return statement preventing copy elision.
Wplacement-new
-C++ Warning Alias(Wplacement-new=, 1, 0)
+C++ ObjC++ Warning Alias(Wplacement-new=, 1, 0)
Warn for placement new expressions with undefined behavior.
Wplacement-new=
-C++ Joined RejectNegative UInteger Var(warn_placement_new) Init(-1) Warning IntegerRange(0, 2)
+C++ ObjC++ Joined RejectNegative UInteger Var(warn_placement_new) Init(-1) Warning IntegerRange(0, 2)
Warn for placement new expressions with undefined behavior.
Wpmf-conversions
@@ -1417,7 +1417,7 @@ C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wall, 3, 0) IntegerRange(0, 3)
;
Wstrict-flex-arrays
-C C++ Var(warn_strict_flex_arrays) Warning
+C ObjC C++ ObjC++ Var(warn_strict_flex_arrays) Warning
Warn about improper usages of flexible array members
according to the level of -fstrict-flex-arrays.
@@ -1495,7 +1495,7 @@ C ObjC C++ ObjC++ Var(warn_switch_outside_range) Warning Init(1)
Warn about switch values that are outside of the switch's type range.
Wsync-nand
-C C++ Var(warn_sync_nand) Init(1) Warning
+C ObjC C++ ObjC++ Var(warn_sync_nand) Init(1) Warning
Warn when __sync_fetch_and_nand and __sync_nand_and_fetch built-in functions are used.
Wsynth
@@ -1900,35 +1900,35 @@ EnumValue
Enum(on_off) String(on) Value(1)
fcontract-assumption-mode=
-C++ Joined RejectNegative
+C++ ObjC++ Joined RejectNegative
-fcontract-assumption-mode=[on|off] Enable or disable treating axiom level contracts as assumptions (default on).
fcontract-build-level=
-C++ Joined RejectNegative
+C++ ObjC++ Joined RejectNegative
-fcontract-build-level=[off|default|audit] Specify max contract level to generate runtime checks for.
fcontract-strict-declarations=
-C++ Var(flag_contract_strict_declarations) Enum(on_off) Joined Init(0) RejectNegative
+C++ ObjC++ Var(flag_contract_strict_declarations) Enum(on_off) Joined Init(0) RejectNegative
-fcontract-strict-declarations=[on|off] Enable or disable warnings on generalized redeclaration of functions with contracts (default off).
fcontract-mode=
-C++ Var(flag_contract_mode) Enum(on_off) Joined Init(1) RejectNegative
+C++ ObjC++ Var(flag_contract_mode) Enum(on_off) Joined Init(1) RejectNegative
-fcontract-mode=[on|off] Enable or disable all contract facilities (default on).
fcontract-continuation-mode=
-C++ Joined RejectNegative
+C++ ObjC++ Joined RejectNegative
-fcontract-continuation-mode=[on|off] Enable or disable contract continuation mode (default off).
fcontract-role=
-C++ Joined RejectNegative
+C++ ObjC++ Joined RejectNegative
-fcontract-role=<name>:<semantics> Specify the semantics for all levels in a role (default, review), or a custom contract role with given semantics (ex: opt:assume,assume,assume).
fcontract-semantic=
-C++ Joined RejectNegative
+C++ ObjC++ Joined RejectNegative
-fcontract-semantic=<level>:<semantic> Specify the concrete semantics for level.
fcoroutines
-C++ LTO Var(flag_coroutines)
+C++ ObjC++ LTO Var(flag_coroutines)
Enable C++ coroutines (experimental).
fdebug-cpp
@@ -2130,23 +2130,23 @@ C ObjC Var(warn_compare_distinct_pointer_types) Warning Init(1)
Warn if pointers of distinct types are compared without a cast.
flang-info-include-translate
-C++ Var(note_include_translate_yes)
+C++ ObjC++ Var(note_include_translate_yes)
Note #include directives translated to import declarations.
flang-info-include-translate-not
-C++ Var(note_include_translate_no)
+C++ ObjC++ Var(note_include_translate_no)
Note #include directives not translated to import declarations, and not known to be textual.
flang-info-include-translate=
-C++ Joined RejectNegative MissingArgError(missing header name)
+C++ ObjC++ Joined RejectNegative MissingArgError(missing header name)
Note a #include translation of a specific header.
flang-info-module-cmi
-C++ Var(note_module_cmi_yes)
+C++ ObjC++ Var(note_module_cmi_yes)
Note Compiled Module Interface pathnames.
flang-info-module-cmi=
-C++ Joined RejectNegative MissingArgError(missing module name)
+C++ ObjC++ Joined RejectNegative MissingArgError(missing module name)
Note Compiled Module Interface pathname of a specific module or header-unit.
fmax-include-depth=
@@ -2357,10 +2357,10 @@ C++ ObjC++ Var(flag_sized_deallocation) Init(-1)
Enable C++14 sized deallocation support.
fstrict-flex-arrays
-C C++ Common Alias(fstrict-flex-arrays=,3,0)
+C ObjC C++ ObjC++ Common Alias(fstrict-flex-arrays=,3,0)
fstrict-flex-arrays=
-C C++ Common Joined RejectNegative UInteger Var(flag_strict_flex_arrays) Init(0) IntegerRange(0,3)
+C ObjC C++ ObjC++ Common Joined RejectNegative UInteger Var(flag_strict_flex_arrays) Init(0) IntegerRange(0,3)
-fstrict-flex-arrays=<level> Control when to treat the trailing array of a structure as a flexible array member for the purposes of accessing the elements of such an array. The default is treating all trailing arrays of structures as flexible array members.
fsquangle
diff --git a/gcc/cfghooks.cc b/gcc/cfghooks.cc
index 25bc5d4..01169e2 100644
--- a/gcc/cfghooks.cc
+++ b/gcc/cfghooks.cc
@@ -824,7 +824,7 @@ merge_blocks (basic_block a, basic_block b)
else if (a->count.quality () < b->count.quality ())
a->count = b->count;
else if (a->count.quality () == b->count.quality ())
- a->count = a->count.max (b->count);
+ a->count = profile_count::max_prefer_initialized (a->count, b->count);
cfg_hooks->merge_blocks (a, b);
diff --git a/gcc/common/config/i386/cpuinfo.h b/gcc/common/config/i386/cpuinfo.h
index 4efa2c0..9c18c04 100644
--- a/gcc/common/config/i386/cpuinfo.h
+++ b/gcc/common/config/i386/cpuinfo.h
@@ -628,6 +628,8 @@ get_intel_cpu (struct __processor_model *cpu_model,
break;
case 0xcc:
/* Panther Lake. */
+ case 0xd5:
+ /* Wildcat Lake. */
cpu = "pantherlake";
CHECK___builtin_cpu_is ("corei7");
CHECK___builtin_cpu_is ("pantherlake");
diff --git a/gcc/common/config/i386/i386-common.cc b/gcc/common/config/i386/i386-common.cc
index d3509e1..c71f2c1 100644
--- a/gcc/common/config/i386/i386-common.cc
+++ b/gcc/common/config/i386/i386-common.cc
@@ -2270,6 +2270,8 @@ const pta processor_alias_table[] =
M_CPU_SUBTYPE (INTEL_COREI7_PANTHERLAKE), P_PROC_AVX2},
{"diamondrapids", PROCESSOR_DIAMONDRAPIDS, CPU_HASWELL, PTA_DIAMONDRAPIDS,
M_CPU_SUBTYPE (INTEL_COREI7_DIAMONDRAPIDS), P_PROC_AVX10_1},
+ {"wildcatlake", PROCESSOR_PANTHERLAKE, CPU_HASWELL, PTA_PANTHERLAKE,
+ M_CPU_SUBTYPE (INTEL_COREI7_PANTHERLAKE), P_PROC_AVX2},
{"bonnell", PROCESSOR_BONNELL, CPU_ATOM, PTA_BONNELL,
M_CPU_TYPE (INTEL_BONNELL), P_PROC_SSSE3},
{"atom", PROCESSOR_BONNELL, CPU_ATOM, PTA_BONNELL,
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index fbd8d9a..3a66d78 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2481,12 +2481,12 @@ constexpr wide_int_bitmask PTA_CLEARWATERFOREST =
(PTA_SIERRAFOREST & (~(PTA_KL | PTA_WIDEKL))) | PTA_AVXVNNIINT16 | PTA_SHA512
| PTA_SM3 | PTA_SM4 | PTA_USER_MSR | PTA_PREFETCHI;
constexpr wide_int_bitmask PTA_PANTHERLAKE =
- (PTA_ARROWLAKE_S & (~(PTA_KL | PTA_WIDEKL))) | PTA_PREFETCHI;
+ (PTA_ARROWLAKE_S & (~(PTA_KL | PTA_WIDEKL)));
constexpr wide_int_bitmask PTA_DIAMONDRAPIDS = PTA_GRANITERAPIDS_D
| PTA_AVXIFMA | PTA_AVXNECONVERT | PTA_AVXVNNIINT16 | PTA_AVXVNNIINT8
| PTA_CMPCCXADD | PTA_SHA512 | PTA_SM3 | PTA_SM4 | PTA_AVX10_2
| PTA_APX_F | PTA_AMX_AVX512 | PTA_AMX_FP8 | PTA_AMX_TF32 | PTA_MOVRS
- | PTA_AMX_MOVRS | PTA_USER_MSR;
+ | PTA_AMX_MOVRS;
constexpr wide_int_bitmask PTA_BDVER1 = PTA_64BIT | PTA_MMX | PTA_SSE
| PTA_SSE2 | PTA_SSE3 | PTA_SSE4A | PTA_CX16 | PTA_POPCNT | PTA_LZCNT
diff --git a/gcc/config/riscv/autovec-opt.md b/gcc/config/riscv/autovec-opt.md
index 3d6e0a1..d2705cf 100644
--- a/gcc/config/riscv/autovec-opt.md
+++ b/gcc/config/riscv/autovec-opt.md
@@ -1913,7 +1913,7 @@
(define_insn_and_split "*widen_waddu_wx_<mode>"
[(set (match_operand:VWEXTI_D 0 "register_operand")
- (any_widen_binop:VWEXTI_D
+ (plus:VWEXTI_D
(vec_duplicate:VWEXTI_D
(any_extend:<VEL>
(match_operand:<VSUBEL> 2 "register_operand")))
@@ -1933,7 +1933,7 @@
(define_insn_and_split "*widen_wsubu_wx_<mode>"
[(set (match_operand:VWEXTI_D 0 "register_operand")
- (any_widen_binop:VWEXTI_D
+ (minus:VWEXTI_D
(match_operand:VWEXTI_D 1 "register_operand")
(vec_duplicate:VWEXTI_D
(any_extend:<VEL>
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 4e41b69..ecf3986 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2025-10-14 Patrick Palka <ppalka@redhat.com>
+
+ PR c++/122192
+ * parser.cc (cp_parser_mem_initializer_id): Pass class_type
+ instead of typename_type to cp_parser_class_name in the
+ nested-name-specifier case.
+
2025-10-13 Jakub Jelinek <jakub@redhat.com>
PR c++/122228
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 1ed2f37..9280632 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -19091,7 +19091,7 @@ cp_parser_mem_initializer_id (cp_parser* parser)
return cp_parser_class_name (parser,
/*typename_keyword_p=*/true,
/*template_keyword_p=*/template_p,
- typename_type,
+ class_type,
/*check_dependency_p=*/true,
/*class_head_p=*/false,
/*is_declaration=*/true);
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 6bd5128..ddbcbf0 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -35143,13 +35143,14 @@ AVXIFMA, AVXVNNIINT8, AVXNECONVERT, CMPCCXADD, AVXVNNIINT16, SHA512, SM3 and
SM4 instruction set support.
@item pantherlake
-Intel Panther Lake CPU with 64-bit extensions, MOVBE, MMX, SSE, SSE2, SSE3,
-SSSE3, SSE4.1, SSE4.2, POPCNT, AES, PREFETCHW, PCLMUL, RDRND, XSAVE, XSAVEC,
-XSAVES, XSAVEOPT, FSGSBASE, PTWRITE, RDPID, SGX, GFNI-SSE, CLWB, MOVDIRI,
-MOVDIR64B, WAITPKG, ADCX, AVX, AVX2, BMI, BMI2, F16C, FMA, LZCNT, PCONFIG, PKU,
-VAES, VPCLMULQDQ, SERIALIZE, HRESET, AVX-VNNI, UINTR, AVXIFMA, AVXVNNIINT8,
-AVXNECONVERT, CMPCCXADD, AVXVNNIINT16, SHA512, SM3, SM4 and PREFETCHI
-instruction set support.
+@itemx wildcatlake
+Intel Panther Lake/Wildcat Lake CPU with 64-bit extensions, MOVBE, MMX, SSE,
+SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, POPCNT, AES, PREFETCHW, PCLMUL, RDRND,
+XSAVE, XSAVEC, XSAVES, XSAVEOPT, FSGSBASE, PTWRITE, RDPID, SGX, GFNI-SSE,
+CLWB, MOVDIRI, MOVDIR64B, WAITPKG, ADCX, AVX, AVX2, BMI, BMI2, F16C, FMA,
+LZCNT, PCONFIG, PKU, VAES, VPCLMULQDQ, SERIALIZE, HRESET, AVX-VNNI, UINTR,
+AVXIFMA, AVXVNNIINT8, AVXNECONVERT, CMPCCXADD, AVXVNNIINT16, SHA512, SM3 and
+SM4 instruction set support.
@item sapphirerapids
@itemx emeraldrapids
@@ -35196,8 +35197,7 @@ MOVDIRI, MOVDIR64B, ENQCMD, CLDEMOTE, PTWRITE, WAITPKG, SERIALIZE, TSXLDTRK,
UINTR, AMX-BF16, AMX-TILE, AMX-INT8, AVX-VNNI, AVX512FP16, AVX512BF16, AMX-FP16,
PREFETCHI, AMX-COMPLEX, AVX10.1-512, AVX-IFMA, AVX-NE-CONVERT, AVX-VNNI-INT16,
AVX-VNNI-INT8, CMPccXADD, SHA512, SM3, SM4, AVX10.2-512, APX_F, AMX-AVX512,
-AMX-FP8, AMX-TF32, AMX-TRANSPOSE, MOVRS, AMX-MOVRS and USER_MSR instruction set
-support.
+AMX-FP8, AMX-TF32, MOVRS and AMX-MOVRS instruction set support.
@item bonnell
@itemx atom
diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc
index dd41de9..28f79aa 100644
--- a/gcc/ipa-fnsummary.cc
+++ b/gcc/ipa-fnsummary.cc
@@ -2356,7 +2356,8 @@ param_change_prob (ipa_func_body_info *fbi, gimple *stmt, int i)
/* Lookup the most frequent update of the value and believe that
it dominates all the other; precise analysis here is difficult. */
EXECUTE_IF_SET_IN_BITMAP (info.bb_set, 0, index, bi)
- max = max.max (BASIC_BLOCK_FOR_FN (cfun, index)->count);
+ max = profile_count::max_prefer_initialized
+ (max, BASIC_BLOCK_FOR_FN (cfun, index)->count);
if (dump_file)
{
fprintf (dump_file, " Set with count ");
diff --git a/gcc/ipa-inline-transform.cc b/gcc/ipa-inline-transform.cc
index a204854..99969aa 100644
--- a/gcc/ipa-inline-transform.cc
+++ b/gcc/ipa-inline-transform.cc
@@ -833,7 +833,8 @@ inline_transform (struct cgraph_node *node)
FOR_ALL_BB_FN (bb, cfun)
{
bb->count = bb->count.apply_scale (num, den);
- cfun->cfg->count_max = cfun->cfg->count_max.max (bb->count);
+ cfun->cfg->count_max = profile_count::max_prefer_initialized
+ (cfun->cfg->count_max, bb->count);
}
ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = node->count;
}
diff --git a/gcc/predict.cc b/gcc/predict.cc
index 895c5f9..d937cc6 100644
--- a/gcc/predict.cc
+++ b/gcc/predict.cc
@@ -3849,7 +3849,7 @@ update_max_bb_count (void)
basic_block bb;
FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
- true_count_max = true_count_max.max (bb->count);
+ true_count_max = profile_count::max_prefer_initialized (true_count_max, bb->count);
cfun->cfg->count_max = true_count_max;
@@ -4162,7 +4162,9 @@ estimate_bb_frequencies ()
executed, then preserve this info. */
if (!(bb->count == profile_count::zero ()))
bb->count = count.guessed_local ().combine_with_ipa_count (ipa_count);
- cfun->cfg->count_max = cfun->cfg->count_max.max (bb->count);
+ cfun->cfg->count_max
+ = profile_count::max_prefer_initialized (cfun->cfg->count_max,
+ bb->count);
}
free_aux_for_blocks ();
@@ -4473,7 +4475,9 @@ rebuild_frequencies (void)
cfun->cfg->count_max = profile_count::uninitialized ();
FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
{
- cfun->cfg->count_max = cfun->cfg->count_max.max (bb->count);
+ cfun->cfg->count_max
+ = profile_count::max_prefer_initialized (cfun->cfg->count_max,
+ bb->count);
if (bb->count.nonzero_p () && bb->count.quality () >= AFDO)
feedback_found = true;
/* Uninitialized count may be result of inlining or an omision in an
diff --git a/gcc/profile-count.h b/gcc/profile-count.h
index 89746c6..85e601e 100644
--- a/gcc/profile-count.h
+++ b/gcc/profile-count.h
@@ -1109,30 +1109,23 @@ public:
/* Make counter forcibly nonzero. */
profile_count force_nonzero () const;
- profile_count max (profile_count other) const
- {
- profile_count val = *this;
- /* Always prefer nonzero IPA counts over local counts. */
- if (ipa ().nonzero_p () || other.ipa ().nonzero_p ())
- {
- val = ipa ();
- other = other.ipa ();
- }
- if (!initialized_p ())
- return other;
- if (!other.initialized_p ())
- return *this;
- if (*this == zero ())
- return other;
- if (other == zero ())
- return *this;
- gcc_checking_assert (compatible_p (other));
- if (val.m_val < other.m_val || (m_val == other.m_val
- && val.m_quality < other.m_quality))
- return other;
- return *this;
- }
+ /* Return maximum of A and B. If one of values is uninitialized return the
+ other. */
+
+ static profile_count
+ max_prefer_initialized (const profile_count a, const profile_count b)
+ {
+ if (!a.initialized_p ())
+ return b;
+ if (!b.initialized_p ())
+ return a;
+ profile_count ret;
+ gcc_checking_assert (a.compatible_p (b));
+ ret.m_val = MAX (a.m_val, b.m_val);
+ ret.m_quality = MIN (a.m_quality, b.m_quality);
+ return ret;
+ }
/* PROB is a probability in scale 0...REG_BR_PROB_BASE. Scale counter
accordingly. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7b857ec..ca170a1 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,65 @@
+2025-10-14 Patrick Palka <ppalka@redhat.com>
+
+ PR c++/122192
+ * g++.dg/template/dependent-base6.C: Verify mem-initializer-id
+ qualified name lookup is type-only too.
+
+2025-10-14 Tamar Christina <tamar.christina@arm.com>
+
+ PR tree-optimization/121949
+ * gcc.dg/vect/pr121949_1.c: New test.
+ * gcc.dg/vect/pr121949_2.c: New test.
+ * gcc.dg/vect/pr121949_3.c: New test.
+
+2025-10-14 Richard Biener <rguenther@suse.de>
+
+ * gcc.dg/vect/pr120687-1.c: Adjust.
+ * gcc.dg/vect/pr120687-2.c: Likewise.
+ * gcc.dg/vect/pr120687-3.c: Likewise.
+
+2025-10-14 Haochen Jiang <haochen.jiang@intel.com>
+
+ * g++.dg/other/i386-2.C: Remove AMX-TRANSPOSE test.
+ * g++.dg/other/i386-3.C: Ditto.
+ * gcc.target/i386/amx-check.h: Ditto.
+ * gcc.target/i386/amxmovrs-asmatt-1.c: Ditto.
+ * gcc.target/i386/amxmovrs-asmintel-1.c: Ditto.
+ * gcc.target/i386/funcspec-56.inc: Ditto.
+ * gcc.target/i386/sse-12.c: Ditto.
+ * gcc.target/i386/sse-13.c: Ditto.
+ * gcc.target/i386/sse-14.c: Ditto.
+ * gcc.target/i386/sse-22.c: Ditto.
+ * gcc.target/i386/sse-23.c: Ditto.
+ * lib/target-supports.exp: Ditto.
+ * gcc.target/i386/amxmovrs-2rpntlvwrs-2.c: Removed.
+ * gcc.target/i386/amxtranspose-2rpntlvw-2.c: Removed.
+ * gcc.target/i386/amxtranspose-asmatt-1.c: Removed.
+ * gcc.target/i386/amxtranspose-asmintel-1.c: Removed.
+ * gcc.target/i386/amxtranspose-conjtcmmimfp16ps-2.c: Removed.
+ * gcc.target/i386/amxtranspose-conjtfp16-2.c: Removed.
+ * gcc.target/i386/amxtranspose-tcmmimfp16ps-2.c: Removed.
+ * gcc.target/i386/amxtranspose-tcmmrlfp16ps-2.c: Removed.
+ * gcc.target/i386/amxtranspose-tdpbf16ps-2.c: Removed.
+ * gcc.target/i386/amxtranspose-tdpfp16ps-2.c: Removed.
+ * gcc.target/i386/amxtranspose-tmmultf32ps-2.c: Removed.
+ * gcc.target/i386/amxtranspose-transposed-2.c: Removed.
+
+2025-10-14 Andrew Pinski <andrew.pinski@oss.qualcomm.com>
+
+ PR tree-optimization/122178
+ * g++.dg/tree-ssa/cselim-1.C: New test.
+
+2025-10-14 Zhongyao Chen <chenzhongyao.hit@gmail.com>
+
+ * gcc.target/riscv/predef-profiles-1.c: New test for __riscv_rvi20u64.
+ * gcc.target/riscv/predef-profiles-2.c: New test for __riscv_rvi20u32.
+ * gcc.target/riscv/predef-profiles-3.c: New test for __riscv_rva20u64.
+ * gcc.target/riscv/predef-profiles-4.c: New test for __riscv_rva22u64.
+ * gcc.target/riscv/predef-profiles-5.c: New test for __riscv_rva23u64.
+ * gcc.target/riscv/predef-profiles-6.c: New test for __riscv_rva23s64.
+ * gcc.target/riscv/predef-profiles-7.c: New test for __riscv_rvb23u64.
+ * gcc.target/riscv/predef-profiles-8.c: New test for __riscv_rvb23s64.
+
2025-10-13 Eric Botcazou <ebotcazou@adacore.com>
* gcc.dg/cpp/cpp.exp: Process .i files.
diff --git a/gcc/testsuite/g++.dg/template/dependent-base6.C b/gcc/testsuite/g++.dg/template/dependent-base6.C
index b4bc5c2..9f2a7a2 100644
--- a/gcc/testsuite/g++.dg/template/dependent-base6.C
+++ b/gcc/testsuite/g++.dg/template/dependent-base6.C
@@ -8,5 +8,7 @@ struct A {
struct S1 : A::B { }; // OK
-template<class T> struct S2 : T::B { }; // OK, used to fail
+template<class T> struct S2 : T::B { // OK, used to fail
+ S2() : T::B() { } // Also OK
+};
template struct S2<A>;
diff --git a/gcc/testsuite/gcc.dg/vect/pr120687-1.c b/gcc/testsuite/gcc.dg/vect/pr120687-1.c
index ce9cf63..ac684c0 100644
--- a/gcc/testsuite/gcc.dg/vect/pr120687-1.c
+++ b/gcc/testsuite/gcc.dg/vect/pr120687-1.c
@@ -11,6 +11,6 @@ frd (unsigned *p, unsigned *lastone)
return sum;
}
-/* { dg-final { scan-tree-dump "reduction: detected reduction chain" "vect" } } */
+/* { dg-final { scan-tree-dump "Starting SLP discovery of reduction chain" "vect" } } */
/* { dg-final { scan-tree-dump-not "SLP discovery of reduction chain failed" "vect" } } */
/* { dg-final { scan-tree-dump "optimized: loop vectorized" "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/pr120687-2.c b/gcc/testsuite/gcc.dg/vect/pr120687-2.c
index dfc6dc7..25f0355 100644
--- a/gcc/testsuite/gcc.dg/vect/pr120687-2.c
+++ b/gcc/testsuite/gcc.dg/vect/pr120687-2.c
@@ -12,6 +12,6 @@ frd (float *p, float *lastone)
return sum;
}
-/* { dg-final { scan-tree-dump "reduction: detected reduction chain" "vect" } } */
+/* { dg-final { scan-tree-dump "Starting SLP discovery of reduction chain" "vect" } } */
/* { dg-final { scan-tree-dump-not "SLP discovery of reduction chain failed" "vect" } } */
/* { dg-final { scan-tree-dump "optimized: loop vectorized" "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/pr120687-3.c b/gcc/testsuite/gcc.dg/vect/pr120687-3.c
index f20a66a..31a6c94 100644
--- a/gcc/testsuite/gcc.dg/vect/pr120687-3.c
+++ b/gcc/testsuite/gcc.dg/vect/pr120687-3.c
@@ -11,6 +11,6 @@ frd (float *p, float *lastone)
return sum;
}
-/* { dg-final { scan-tree-dump "reduction: detected reduction chain" "vect" } } */
+/* { dg-final { scan-tree-dump "Starting SLP discovery of reduction chain" "vect" } } */
/* { dg-final { scan-tree-dump-not "SLP discovery of reduction chain failed" "vect" } } */
/* { dg-final { scan-tree-dump "optimized: loop vectorized" "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/pr121949_1.c b/gcc/testsuite/gcc.dg/vect/pr121949_1.c
new file mode 100644
index 0000000..9e8d41e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr121949_1.c
@@ -0,0 +1,45 @@
+#ifndef TYPE
+#define TYPE short
+#define MAX 16
+#define IV_TYPE char
+#endif
+
+#include "tree-vect.h"
+
+__attribute__((noipa))
+void f(TYPE* acc)
+{
+ for (IV_TYPE row = 0; row < MAX; ++row)
+ acc[row] = acc[row] << row;
+}
+
+__attribute__((noipa))
+void g(TYPE* acc)
+{
+#pragma GCC novector
+ for (IV_TYPE row = 0; row < MAX; ++row)
+ acc[row] = acc[row] << row;
+}
+
+int main ()
+{
+
+ check_vect ();
+
+ TYPE acc1[MAX] = {};
+ TYPE acc2[MAX] = {};
+#pragma GCC novector
+ for (int i = 0; i < MAX; i++)
+ acc1[i] = acc2[i] = i;
+
+ f (acc1);
+ f (acc2);
+
+#pragma GCC novector
+ for (int i = 0; i < MAX; i++)
+ if (acc1[i] != acc2[i])
+ __builtin_abort ();
+}
+
+/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" { target { vect_var_shift && vect_int } } } } */
+/* { dg-final { scan-tree-dump "vect_recog_over_widening_pattern: detected" "vect" { target { vect_var_shift && vect_int } } } } */
diff --git a/gcc/testsuite/gcc.dg/vect/pr121949_2.c b/gcc/testsuite/gcc.dg/vect/pr121949_2.c
new file mode 100644
index 0000000..f448eb6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr121949_2.c
@@ -0,0 +1,45 @@
+#ifndef TYPE
+#define TYPE int
+#define MAX 32
+#define IV_TYPE short
+#endif
+
+#include "tree-vect.h"
+
+__attribute__((noipa))
+void f(TYPE* acc)
+{
+ for (IV_TYPE row = 0; row < MAX; ++row)
+ acc[row] = acc[row] << row;
+}
+
+__attribute__((noipa))
+void g(TYPE* acc)
+{
+#pragma GCC novector
+ for (IV_TYPE row = 0; row < MAX; ++row)
+ acc[row] = acc[row] << row;
+}
+
+int main ()
+{
+
+ check_vect ();
+
+ TYPE acc1[MAX] = {};
+ TYPE acc2[MAX] = {};
+#pragma GCC novector
+ for (int i = 0; i < MAX; i++)
+ acc1[i] = acc2[i] = i;
+
+ f (acc1);
+ f (acc2);
+
+#pragma GCC novector
+ for (int i = 0; i < MAX; i++)
+ if (acc1[i] != acc2[i])
+ __builtin_abort ();
+}
+
+/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" { target { vect_var_shift && vect_int } } } } */
+/* { dg-final { scan-tree-dump-not "vect_recog_over_widening_pattern: detected" "vect" { target { vect_var_shift && vect_int } } } } */
diff --git a/gcc/testsuite/gcc.dg/vect/pr121949_3.c b/gcc/testsuite/gcc.dg/vect/pr121949_3.c
new file mode 100644
index 0000000..b7e6a3d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr121949_3.c
@@ -0,0 +1,45 @@
+#ifndef TYPE
+#define TYPE long long
+#define MAX 64
+#define IV_TYPE int
+#endif
+
+#include "tree-vect.h"
+
+__attribute__((noipa))
+void f(TYPE* acc)
+{
+ for (IV_TYPE row = 0; row < MAX; ++row)
+ acc[row] = acc[row] << row;
+}
+
+__attribute__((noipa))
+void g(TYPE* acc)
+{
+#pragma GCC novector
+ for (IV_TYPE row = 0; row < MAX; ++row)
+ acc[row] = acc[row] << row;
+}
+
+int main ()
+{
+
+ check_vect ();
+
+ TYPE acc1[MAX] = {};
+ TYPE acc2[MAX] = {};
+#pragma GCC novector
+ for (int i = 0; i < MAX; i++)
+ acc1[i] = acc2[i] = i;
+
+ f (acc1);
+ f (acc2);
+
+#pragma GCC novector
+ for (int i = 0; i < MAX; i++)
+ if (acc1[i] != acc2[i])
+ __builtin_abort ();
+}
+
+/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" { target { vect_var_shift && vect_int } } } } */
+/* { dg-final { scan-tree-dump "vect_recog_vector_vector_shift_pattern: detected" "vect" { target { vect_var_shift && vect_int } } } } */
diff --git a/gcc/tree-ssa-loop-unswitch.cc b/gcc/tree-ssa-loop-unswitch.cc
index c5ca4ff..dc0cb24 100644
--- a/gcc/tree-ssa-loop-unswitch.cc
+++ b/gcc/tree-ssa-loop-unswitch.cc
@@ -136,7 +136,8 @@ struct unswitch_predicate
tree rhs = gimple_cond_rhs (stmt);
enum tree_code code = gimple_cond_code (stmt);
condition = build2 (code, boolean_type_node, lhs, rhs);
- count = EDGE_SUCC (bb, 0)->count ().max (EDGE_SUCC (bb, 1)->count ());
+ count = profile_count::max_prefer_initialized (EDGE_SUCC (bb, 0)->count (),
+ EDGE_SUCC (bb, 1)->count ());
if (irange::supports_p (TREE_TYPE (lhs)))
{
auto range_op = range_op_handler (code);
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 73398e5..97c1bf0 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -161,7 +161,7 @@ along with GCC; see the file COPYING3. If not see
static void vect_estimate_min_profitable_iters (loop_vec_info, int *, int *,
unsigned *);
static stmt_vec_info vect_is_simple_reduction (loop_vec_info, stmt_vec_info,
- gphi **, bool *, bool);
+ gphi **);
/* Function vect_is_simple_iv_evolution.
@@ -341,8 +341,7 @@ vect_phi_first_order_recurrence_p (loop_vec_info loop_vinfo, class loop *loop,
slp analyses or not. */
static void
-vect_analyze_scalar_cycles_1 (loop_vec_info loop_vinfo, class loop *loop,
- bool slp)
+vect_analyze_scalar_cycles_1 (loop_vec_info loop_vinfo, class loop *loop)
{
basic_block bb = loop->header;
auto_vec<stmt_vec_info, 64> worklist;
@@ -425,19 +424,15 @@ vect_analyze_scalar_cycles_1 (loop_vec_info loop_vinfo, class loop *loop,
&& STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_unknown_def_type);
gphi *double_reduc;
- bool reduc_chain;
stmt_vec_info reduc_stmt_info
- = vect_is_simple_reduction (loop_vinfo, stmt_vinfo, &double_reduc,
- &reduc_chain, slp);
+ = vect_is_simple_reduction (loop_vinfo, stmt_vinfo, &double_reduc);
if (reduc_stmt_info && double_reduc)
{
- bool inner_chain;
stmt_vec_info inner_phi_info
= loop_vinfo->lookup_stmt (double_reduc);
/* ??? Pass down flag we're the inner loop of a double reduc. */
stmt_vec_info inner_reduc_info
- = vect_is_simple_reduction (loop_vinfo, inner_phi_info,
- NULL, &inner_chain, slp);
+ = vect_is_simple_reduction (loop_vinfo, inner_phi_info, NULL);
if (inner_reduc_info)
{
STMT_VINFO_REDUC_DEF (stmt_vinfo) = reduc_stmt_info;
@@ -478,12 +473,7 @@ vect_analyze_scalar_cycles_1 (loop_vec_info loop_vinfo, class loop *loop,
STMT_VINFO_DEF_TYPE (stmt_vinfo) = vect_reduction_def;
STMT_VINFO_DEF_TYPE (reduc_stmt_info) = vect_reduction_def;
- /* Store the reduction cycles for possible vectorization in
- loop-aware SLP if it was not detected as reduction
- chain. */
- if (! reduc_chain)
- LOOP_VINFO_REDUCTIONS (loop_vinfo).safe_push
- (reduc_stmt_info);
+ LOOP_VINFO_REDUCTIONS (loop_vinfo).safe_push (reduc_stmt_info);
}
}
else if (vect_phi_first_order_recurrence_p (loop_vinfo, loop, phi))
@@ -518,11 +508,11 @@ vect_analyze_scalar_cycles_1 (loop_vec_info loop_vinfo, class loop *loop,
a[i] = i; */
static void
-vect_analyze_scalar_cycles (loop_vec_info loop_vinfo, bool slp)
+vect_analyze_scalar_cycles (loop_vec_info loop_vinfo)
{
class loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
- vect_analyze_scalar_cycles_1 (loop_vinfo, loop, slp);
+ vect_analyze_scalar_cycles_1 (loop_vinfo, loop);
/* When vectorizing an outer-loop, the inner-loop is executed sequentially.
Reductions in such inner-loop therefore have different properties than
@@ -534,87 +524,7 @@ vect_analyze_scalar_cycles (loop_vec_info loop_vinfo, bool slp)
current checks are too strict. */
if (loop->inner)
- vect_analyze_scalar_cycles_1 (loop_vinfo, loop->inner, slp);
-}
-
-/* Transfer group and reduction information from STMT_INFO to its
- pattern stmt. */
-
-static void
-vect_fixup_reduc_chain (stmt_vec_info stmt_info)
-{
- stmt_vec_info firstp = STMT_VINFO_RELATED_STMT (stmt_info);
- stmt_vec_info stmtp;
- gcc_assert (!REDUC_GROUP_FIRST_ELEMENT (firstp)
- && REDUC_GROUP_FIRST_ELEMENT (stmt_info));
- REDUC_GROUP_SIZE (firstp) = REDUC_GROUP_SIZE (stmt_info);
- do
- {
- stmtp = STMT_VINFO_RELATED_STMT (stmt_info);
- gcc_checking_assert (STMT_VINFO_DEF_TYPE (stmtp)
- == STMT_VINFO_DEF_TYPE (stmt_info));
- REDUC_GROUP_FIRST_ELEMENT (stmtp) = firstp;
- stmt_info = REDUC_GROUP_NEXT_ELEMENT (stmt_info);
- if (stmt_info)
- REDUC_GROUP_NEXT_ELEMENT (stmtp)
- = STMT_VINFO_RELATED_STMT (stmt_info);
- }
- while (stmt_info);
-}
-
-/* Fixup scalar cycles that now have their stmts detected as patterns. */
-
-static void
-vect_fixup_scalar_cycles_with_patterns (loop_vec_info loop_vinfo)
-{
- stmt_vec_info first;
- unsigned i;
-
- FOR_EACH_VEC_ELT (LOOP_VINFO_REDUCTION_CHAINS (loop_vinfo), i, first)
- {
- stmt_vec_info next = REDUC_GROUP_NEXT_ELEMENT (first);
- while (next)
- {
- if ((STMT_VINFO_IN_PATTERN_P (next)
- != STMT_VINFO_IN_PATTERN_P (first))
- || STMT_VINFO_REDUC_IDX (vect_stmt_to_vectorize (next)) == -1)
- break;
- next = REDUC_GROUP_NEXT_ELEMENT (next);
- }
- /* If all reduction chain members are well-formed patterns adjust
- the group to group the pattern stmts instead. */
- if (! next
- && STMT_VINFO_REDUC_IDX (vect_stmt_to_vectorize (first)) != -1)
- {
- if (STMT_VINFO_IN_PATTERN_P (first))
- {
- vect_fixup_reduc_chain (first);
- LOOP_VINFO_REDUCTION_CHAINS (loop_vinfo)[i]
- = STMT_VINFO_RELATED_STMT (first);
- }
- }
- /* If not all stmt in the chain are patterns or if we failed
- to update STMT_VINFO_REDUC_IDX dissolve the chain and handle
- it as regular reduction instead. */
- else
- {
- stmt_vec_info vinfo = first;
- stmt_vec_info last = NULL;
- while (vinfo)
- {
- next = REDUC_GROUP_NEXT_ELEMENT (vinfo);
- REDUC_GROUP_FIRST_ELEMENT (vinfo) = NULL;
- REDUC_GROUP_NEXT_ELEMENT (vinfo) = NULL;
- last = vinfo;
- vinfo = next;
- }
- STMT_VINFO_DEF_TYPE (vect_stmt_to_vectorize (first))
- = vect_internal_def;
- loop_vinfo->reductions.safe_push (vect_stmt_to_vectorize (last));
- LOOP_VINFO_REDUCTION_CHAINS (loop_vinfo).unordered_remove (i);
- --i;
- }
- }
+ vect_analyze_scalar_cycles_1 (loop_vinfo, loop->inner);
}
/* Function vect_get_loop_niters.
@@ -2264,12 +2174,10 @@ vect_analyze_loop_2 (loop_vec_info loop_vinfo, bool &fatal,
/* Classify all cross-iteration scalar data-flow cycles.
Cross-iteration cycles caused by virtual phis are analyzed separately. */
- vect_analyze_scalar_cycles (loop_vinfo, !force_single_lane);
+ vect_analyze_scalar_cycles (loop_vinfo);
vect_pattern_recog (loop_vinfo);
- vect_fixup_scalar_cycles_with_patterns (loop_vinfo);
-
/* Analyze the access patterns of the data-refs in the loop (consecutive,
complex, etc.). FORNOW: Only handle consecutive access pattern. */
@@ -2678,10 +2586,6 @@ again:
if (applying_suggested_uf)
return ok;
- /* If there are reduction chains re-trying will fail anyway. */
- if (! LOOP_VINFO_REDUCTION_CHAINS (loop_vinfo).is_empty ())
- return ok;
-
/* Likewise if the grouped loads or stores in the SLP cannot be handled
via interleaving or lane instructions. */
slp_instance instance;
@@ -3756,7 +3660,7 @@ check_reduction_path (dump_user_location_t loc, loop_p loop, gphi *phi,
static stmt_vec_info
vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info,
- gphi **double_reduc, bool *reduc_chain_p, bool slp)
+ gphi **double_reduc)
{
gphi *phi = as_a <gphi *> (phi_info->stmt);
gimple *phi_use_stmt = NULL;
@@ -3768,7 +3672,6 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info,
bool inner_loop_of_double_reduc = double_reduc == NULL;
if (double_reduc)
*double_reduc = NULL;
- *reduc_chain_p = false;
STMT_VINFO_REDUC_TYPE (phi_info) = TREE_CODE_REDUCTION;
tree phi_name = PHI_RESULT (phi);
@@ -3918,12 +3821,8 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info,
if (code == COND_EXPR && !nested_in_vect_loop)
STMT_VINFO_REDUC_TYPE (phi_info) = COND_REDUCTION;
- /* Fill in STMT_VINFO_REDUC_IDX and gather stmts for an SLP
- reduction chain for which the additional restriction is that
- all operations in the chain are the same. */
- auto_vec<stmt_vec_info, 8> reduc_chain;
+ /* Fill in STMT_VINFO_REDUC_IDX. */
unsigned i;
- bool is_slp_reduc = !nested_in_vect_loop && code != COND_EXPR;
for (i = path.length () - 1; i >= 1; --i)
{
gimple *stmt = USE_STMT (path[i].second);
@@ -3940,39 +3839,8 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info,
STMT_VINFO_REDUC_IDX (stmt_info)
= path[i].second->use - gimple_call_arg_ptr (call, 0);
}
- bool leading_conversion = (CONVERT_EXPR_CODE_P (op.code)
- && (i == 1 || i == path.length () - 1));
- if ((op.code != code && !leading_conversion)
- /* We can only handle the final value in epilogue
- generation for reduction chains. */
- || (i != 1 && !has_single_use (gimple_get_lhs (stmt))))
- is_slp_reduc = false;
- /* For reduction chains we support a trailing/leading
- conversions. We do not store those in the actual chain. */
- if (leading_conversion)
- continue;
- reduc_chain.safe_push (stmt_info);
}
- if (slp && is_slp_reduc && reduc_chain.length () > 1)
- {
- for (unsigned i = 0; i < reduc_chain.length () - 1; ++i)
- {
- REDUC_GROUP_FIRST_ELEMENT (reduc_chain[i]) = reduc_chain[0];
- REDUC_GROUP_NEXT_ELEMENT (reduc_chain[i]) = reduc_chain[i+1];
- }
- REDUC_GROUP_FIRST_ELEMENT (reduc_chain.last ()) = reduc_chain[0];
- REDUC_GROUP_NEXT_ELEMENT (reduc_chain.last ()) = NULL;
-
- /* Save the chain for further analysis in SLP detection. */
- LOOP_VINFO_REDUCTION_CHAINS (loop_info).safe_push (reduc_chain[0]);
- REDUC_GROUP_SIZE (reduc_chain[0]) = reduc_chain.length ();
-
- *reduc_chain_p = true;
- if (dump_enabled_p ())
- dump_printf_loc (MSG_NOTE, vect_location,
- "reduction: detected reduction chain\n");
- }
- else if (dump_enabled_p ())
+ if (dump_enabled_p ())
dump_printf_loc (MSG_NOTE, vect_location,
"reduction: detected reduction\n");
@@ -5390,7 +5258,6 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
tree new_temp = NULL_TREE, new_name, new_scalar_dest;
gimple *epilog_stmt = NULL;
gimple *exit_phi;
- tree bitsize;
tree def;
tree orig_name, scalar_result;
imm_use_iterator imm_iter;
@@ -5405,8 +5272,7 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
# b1 = phi <b2, b0>
a2 = operation (a1)
b2 = operation (b1) */
- const bool slp_reduc
- = SLP_INSTANCE_KIND (slp_node_instance) != slp_inst_kind_reduc_chain;
+ const bool slp_reduc = !reduc_info->is_reduc_chain;
tree induction_index = NULL_TREE;
unsigned int group_size = SLP_TREE_LANES (slp_node);
@@ -5608,7 +5474,6 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
scalar_results.truncate (0);
scalar_results.reserve_exact (group_size);
new_scalar_dest = vect_create_destination_var (scalar_dest, NULL);
- bitsize = TYPE_SIZE (scalar_type);
/* True if we should implement SLP_REDUC using native reduction operations
instead of scalar operations. */
@@ -6030,6 +5895,7 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
if (reduce_with_shift && (!slp_reduc || group_size == 1))
{
+ tree bitsize = TYPE_SIZE (TREE_TYPE (vectype1));
int element_bitsize = tree_to_uhwi (bitsize);
/* Enforced by vectorizable_reduction, which disallows SLP reductions
for variable-length vectors and also requires direct target support
@@ -6098,9 +5964,10 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
dump_printf_loc (MSG_NOTE, vect_location,
"Reduce using scalar code.\n");
+ tree compute_type = TREE_TYPE (vectype1);
+ tree bitsize = TYPE_SIZE (compute_type);
int vec_size_in_bits = tree_to_uhwi (TYPE_SIZE (vectype1));
int element_bitsize = tree_to_uhwi (bitsize);
- tree compute_type = TREE_TYPE (vectype);
gimple_seq stmts = NULL;
FOR_EACH_VEC_ELT (reduc_inputs, i, vec_temp)
{
@@ -6956,8 +6823,6 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
bool single_defuse_cycle = false;
tree cr_index_scalar_type = NULL_TREE, cr_index_vector_type = NULL_TREE;
tree cond_reduc_val = NULL_TREE;
- const bool reduc_chain
- = SLP_INSTANCE_KIND (slp_node_instance) == slp_inst_kind_reduc_chain;
/* Make sure it was already recognized as a reduction computation. */
if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_reduction_def
@@ -7019,6 +6884,7 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
double_reduc = true;
}
+ const bool reduc_chain = reduc_info->is_reduc_chain;
slp_node_instance->reduc_phis = slp_node;
/* ??? We're leaving slp_node to point to the PHIs, we only
need it to get at the number of vector stmts which wasn't
@@ -7030,33 +6896,28 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
/* Verify following REDUC_IDX from the latch def leads us back to the PHI
and compute the reduction chain length. Discover the real
- reduction operation stmt on the way (stmt_info and slp_for_stmt_info). */
- tree reduc_def
- = PHI_ARG_DEF_FROM_EDGE (reduc_def_phi, loop_latch_edge (loop));
+ reduction operation stmt on the way (slp_for_stmt_info). */
unsigned reduc_chain_length = 0;
- bool only_slp_reduc_chain = true;
stmt_info = NULL;
slp_tree slp_for_stmt_info = NULL;
slp_tree vdef_slp = slp_node_instance->root;
- /* For double-reductions we start SLP analysis at the inner loop LC PHI
- which is the def of the outer loop live stmt. */
- if (double_reduc)
- vdef_slp = SLP_TREE_CHILDREN (vdef_slp)[0];
- while (reduc_def != PHI_RESULT (reduc_def_phi))
+ while (vdef_slp != slp_node)
{
- stmt_vec_info def = loop_vinfo->lookup_def (reduc_def);
- stmt_vec_info vdef = vect_stmt_to_vectorize (def);
- int reduc_idx = STMT_VINFO_REDUC_IDX (vdef);
- if (STMT_VINFO_REDUC_IDX (vdef) == -1
- || SLP_TREE_REDUC_IDX (vdef_slp) == -1)
+ int reduc_idx = SLP_TREE_REDUC_IDX (vdef_slp);
+ if (reduc_idx == -1)
{
if (dump_enabled_p ())
dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
"reduction chain broken by patterns.\n");
return false;
}
- if (!REDUC_GROUP_FIRST_ELEMENT (vdef))
- only_slp_reduc_chain = false;
+ stmt_vec_info vdef = SLP_TREE_REPRESENTATIVE (vdef_slp);
+ if (is_a <gphi *> (vdef->stmt))
+ {
+ vdef_slp = SLP_TREE_CHILDREN (vdef_slp)[reduc_idx];
+ /* Do not count PHIs towards the chain length. */
+ continue;
+ }
gimple_match_op op;
if (!gimple_extract_op (vdef->stmt, &op))
{
@@ -7080,11 +6941,8 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
else
{
/* First non-conversion stmt. */
- if (!stmt_info)
- {
- stmt_info = vdef;
- slp_for_stmt_info = vdef_slp;
- }
+ if (!slp_for_stmt_info)
+ slp_for_stmt_info = vdef_slp;
if (lane_reducing_op_p (op.code))
{
@@ -7116,29 +6974,15 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
}
else if (!vectype_in)
vectype_in = SLP_TREE_VECTYPE (slp_node);
- if (!REDUC_GROUP_FIRST_ELEMENT (vdef))
- {
- gcc_assert (reduc_idx == SLP_TREE_REDUC_IDX (vdef_slp));
- vdef_slp = SLP_TREE_CHILDREN (vdef_slp)[reduc_idx];
- }
+ vdef_slp = SLP_TREE_CHILDREN (vdef_slp)[reduc_idx];
}
-
- reduc_def = op.ops[reduc_idx];
reduc_chain_length++;
}
+ stmt_info = SLP_TREE_REPRESENTATIVE (slp_for_stmt_info);
+
/* PHIs should not participate in patterns. */
gcc_assert (!STMT_VINFO_RELATED_STMT (phi_info));
- /* STMT_VINFO_REDUC_DEF doesn't point to the first but the last
- element. */
- if (REDUC_GROUP_FIRST_ELEMENT (stmt_info))
- {
- gcc_assert (!REDUC_GROUP_NEXT_ELEMENT (stmt_info));
- stmt_info = REDUC_GROUP_FIRST_ELEMENT (stmt_info);
- }
- if (REDUC_GROUP_FIRST_ELEMENT (stmt_info))
- gcc_assert (REDUC_GROUP_FIRST_ELEMENT (stmt_info) == stmt_info);
-
/* 1. Is vectorizable reduction? */
/* Not supportable if the reduction variable is used in the loop, unless
it's a reduction chain. */
@@ -7453,8 +7297,7 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
{
/* When vectorizing a reduction chain w/o SLP the reduction PHI
is not directy used in stmt. */
- if (!only_slp_reduc_chain
- && reduc_chain_length != 1)
+ if (reduc_chain_length != 1)
{
if (dump_enabled_p ())
dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
@@ -7789,22 +7632,18 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
/* All but single defuse-cycle optimized and fold-left reductions go
through their own vectorizable_* routines. */
+ stmt_vec_info tem
+ = SLP_TREE_REPRESENTATIVE (SLP_INSTANCE_TREE (slp_node_instance));
if (!single_defuse_cycle && reduction_type != FOLD_LEFT_REDUCTION)
+ STMT_VINFO_DEF_TYPE (tem) = vect_internal_def;
+ else
{
- stmt_vec_info tem
- = vect_stmt_to_vectorize (STMT_VINFO_REDUC_DEF (phi_info));
- if (REDUC_GROUP_FIRST_ELEMENT (tem))
- {
- gcc_assert (!REDUC_GROUP_NEXT_ELEMENT (tem));
- tem = REDUC_GROUP_FIRST_ELEMENT (tem);
- }
- STMT_VINFO_DEF_TYPE (vect_orig_stmt (tem)) = vect_internal_def;
- STMT_VINFO_DEF_TYPE (tem) = vect_internal_def;
+ STMT_VINFO_DEF_TYPE (tem) = vect_reduction_def;
+ if (LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
+ vect_reduction_update_partial_vector_usage (loop_vinfo, reduc_info,
+ slp_node, op.code, op.type,
+ vectype_in);
}
- else if (LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
- vect_reduction_update_partial_vector_usage (loop_vinfo, reduc_info,
- slp_node, op.code, op.type,
- vectype_in);
return true;
}
@@ -8238,8 +8077,6 @@ vect_transform_cycle_phi (loop_vec_info loop_vinfo,
int i;
bool nested_cycle = false;
int vec_num;
- const bool reduc_chain
- = SLP_INSTANCE_KIND (slp_node_instance) == slp_inst_kind_reduc_chain;
if (nested_in_vect_loop_p (loop, stmt_info))
{
@@ -8308,7 +8145,7 @@ vect_transform_cycle_phi (loop_vec_info loop_vinfo,
vec<stmt_vec_info> &stmts = SLP_TREE_SCALAR_STMTS (slp_node);
unsigned int num_phis = stmts.length ();
- if (reduc_chain)
+ if (reduc_info->is_reduc_chain)
num_phis = 1;
initial_values.reserve (num_phis);
for (unsigned int i = 0; i < num_phis; ++i)
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index 74a9a19..becee62 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -1022,13 +1022,11 @@ vect_reassociating_reduction_p (vec_info *vinfo,
if (loop && nested_in_vect_loop_p (loop, stmt_info))
return false;
- if (STMT_VINFO_DEF_TYPE (stmt_info) == vect_reduction_def)
- {
- if (needs_fold_left_reduction_p (TREE_TYPE (gimple_assign_lhs (assign)),
- code))
- return false;
- }
- else if (REDUC_GROUP_FIRST_ELEMENT (stmt_info) == NULL)
+ if (!vect_is_reduction (stmt_info))
+ return false;
+
+ if (needs_fold_left_reduction_p (TREE_TYPE (gimple_assign_lhs (assign)),
+ code))
return false;
*op0_out = gimple_assign_rhs1 (assign);
@@ -4087,10 +4085,13 @@ vect_recog_vector_vector_shift_pattern (vec_info *vinfo,
!= TYPE_PRECISION (TREE_TYPE (oprnd0)))
return NULL;
- stmt_vec_info def_vinfo = vect_get_internal_def (vinfo, oprnd1);
- if (!def_vinfo)
+ stmt_vec_info def_vinfo = vinfo->lookup_def (oprnd1);
+ if (!def_vinfo || STMT_VINFO_DEF_TYPE (def_vinfo) == vect_external_def)
return NULL;
+ def_vinfo = vect_stmt_to_vectorize (def_vinfo);
+ gcc_assert (def_vinfo);
+
*type_out = get_vectype_for_scalar_type (vinfo, TREE_TYPE (oprnd0));
if (*type_out == NULL_TREE)
return NULL;
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index f553e8f..13a2995 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -53,6 +53,9 @@ along with GCC; see the file COPYING3. If not see
#include "sreal.h"
#include "predict.h"
+#define REDUC_GROUP_FIRST_ELEMENT(S) \
+ (gcc_checking_assert (!(S)->dr_aux.dr), (S)->first_element)
+
static bool vect_transform_slp_perm_load_1 (vec_info *, slp_tree,
load_permutation_t &,
const vec<tree> &,
@@ -4187,41 +4190,60 @@ vect_build_slp_instance (vec_info *vinfo,
Return FALSE if SLP build fails. */
static bool
-vect_analyze_slp_reduc_chain (vec_info *vinfo,
+vect_analyze_slp_reduc_chain (loop_vec_info vinfo,
scalar_stmts_to_slp_tree_map_t *bst_map,
- stmt_vec_info stmt_info,
+ stmt_vec_info scalar_stmt,
unsigned max_tree_size, unsigned *limit)
{
- vec<stmt_vec_info> scalar_stmts;
+ vec<stmt_vec_info> scalar_stmts = vNULL;
- /* Collect the reduction stmts and store them in scalar_stmts. */
- scalar_stmts.create (REDUC_GROUP_SIZE (stmt_info));
- stmt_vec_info next_info = stmt_info;
- while (next_info)
+ bool fail = false;
+ /* ??? We could leave operation code checking to SLP discovery. */
+ code_helper code = STMT_VINFO_REDUC_CODE (STMT_VINFO_REDUC_DEF
+ (vect_orig_stmt (scalar_stmt)));
+ bool first = true;
+ stmt_vec_info next_stmt = scalar_stmt;
+ do
{
- scalar_stmts.quick_push (vect_stmt_to_vectorize (next_info));
- next_info = REDUC_GROUP_NEXT_ELEMENT (next_info);
+ stmt_vec_info stmt = next_stmt;
+ gimple_match_op op;
+ if (!gimple_extract_op (STMT_VINFO_STMT (stmt), &op))
+ gcc_unreachable ();
+ tree reduc_def = gimple_arg (STMT_VINFO_STMT (stmt),
+ STMT_VINFO_REDUC_IDX (stmt));
+ next_stmt = vect_stmt_to_vectorize (vinfo->lookup_def (reduc_def));
+ gcc_assert (is_a <gphi *> (STMT_VINFO_STMT (next_stmt))
+ || STMT_VINFO_REDUC_IDX (next_stmt) != -1);
+ if (!gimple_extract_op (STMT_VINFO_STMT (vect_orig_stmt (stmt)), &op))
+ gcc_unreachable ();
+ if (CONVERT_EXPR_CODE_P (op.code)
+ && (first
+ || is_a <gphi *> (STMT_VINFO_STMT (next_stmt))))
+ ;
+ else if (code != op.code)
+ {
+ fail = true;
+ break;
+ }
+ else
+ scalar_stmts.safe_push (stmt);
+ first = false;
}
- /* Mark the first element of the reduction chain as reduction to properly
- transform the node. In the reduction analysis phase only the last
- element of the chain is marked as reduction. */
- STMT_VINFO_DEF_TYPE (stmt_info)
- = STMT_VINFO_DEF_TYPE (scalar_stmts.last ());
- STMT_VINFO_REDUC_DEF (vect_orig_stmt (stmt_info))
- = STMT_VINFO_REDUC_DEF (vect_orig_stmt (scalar_stmts.last ()));
+ while (!is_a <gphi *> (STMT_VINFO_STMT (next_stmt)));
+ if (fail || scalar_stmts.length () <= 1)
+ return false;
+
+ scalar_stmts.reverse ();
+ stmt_vec_info reduc_phi_info = next_stmt;
/* Build the tree for the SLP instance. */
vec<stmt_vec_info> root_stmt_infos = vNULL;
vec<tree> remain = vNULL;
- /* If there's no budget left bail out early. */
- if (*limit == 0)
- return false;
-
if (dump_enabled_p ())
{
dump_printf_loc (MSG_NOTE, vect_location,
- "Starting SLP discovery for\n");
+ "Starting SLP discovery of reduction chain for\n");
for (unsigned i = 0; i < scalar_stmts.length (); ++i)
dump_printf_loc (MSG_NOTE, vect_location,
" %G", scalar_stmts[i]->stmt);
@@ -4233,136 +4255,195 @@ vect_analyze_slp_reduc_chain (vec_info *vinfo,
poly_uint64 max_nunits = 1;
unsigned tree_size = 0;
+ /* ??? We need this only for SLP discovery. */
+ for (unsigned i = 0; i < scalar_stmts.length (); ++i)
+ REDUC_GROUP_FIRST_ELEMENT (scalar_stmts[i]) = scalar_stmts[0];
+
slp_tree node = vect_build_slp_tree (vinfo, scalar_stmts, group_size,
&max_nunits, matches, limit,
&tree_size, bst_map);
+
+ for (unsigned i = 0; i < scalar_stmts.length (); ++i)
+ REDUC_GROUP_FIRST_ELEMENT (scalar_stmts[i]) = NULL;
+
if (node != NULL)
{
- /* Calculate the unrolling factor based on the smallest type. */
- poly_uint64 unrolling_factor
- = calculate_unrolling_factor (max_nunits, group_size);
+ /* Create a new SLP instance. */
+ slp_instance new_instance = XNEW (class _slp_instance);
+ SLP_INSTANCE_TREE (new_instance) = node;
+ SLP_INSTANCE_LOADS (new_instance) = vNULL;
+ SLP_INSTANCE_ROOT_STMTS (new_instance) = root_stmt_infos;
+ SLP_INSTANCE_REMAIN_DEFS (new_instance) = remain;
+ SLP_INSTANCE_KIND (new_instance) = slp_inst_kind_reduc_chain;
+ new_instance->reduc_phis = NULL;
+ new_instance->cost_vec = vNULL;
+ new_instance->subgraph_entries = vNULL;
- if (maybe_ne (unrolling_factor, 1U)
- && is_a <bb_vec_info> (vinfo))
+ vect_reduc_info reduc_info = info_for_reduction (vinfo, node);
+ reduc_info->is_reduc_chain = true;
+
+ if (dump_enabled_p ())
+ dump_printf_loc (MSG_NOTE, vect_location,
+ "SLP size %u vs. limit %u.\n",
+ tree_size, max_tree_size);
+
+ /* Fixup SLP reduction chains. If this is a reduction chain with
+ a conversion in front amend the SLP tree with a node for that. */
+ gimple *scalar_def = STMT_VINFO_REDUC_DEF (reduc_phi_info)->stmt;
+ if (is_gimple_assign (scalar_def)
+ && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (scalar_def)))
+ {
+ stmt_vec_info conv_info = vect_stmt_to_vectorize
+ (STMT_VINFO_REDUC_DEF (reduc_phi_info));
+ scalar_stmts = vNULL;
+ scalar_stmts.create (group_size);
+ for (unsigned i = 0; i < group_size; ++i)
+ scalar_stmts.quick_push (conv_info);
+ slp_tree conv = vect_create_new_slp_node (scalar_stmts, 1);
+ SLP_TREE_VECTYPE (conv)
+ = get_vectype_for_scalar_type (vinfo,
+ TREE_TYPE
+ (gimple_assign_lhs (scalar_def)),
+ group_size);
+ SLP_TREE_REDUC_IDX (conv) = 0;
+ conv->cycle_info.id = node->cycle_info.id;
+ SLP_TREE_CHILDREN (conv).quick_push (node);
+ SLP_INSTANCE_TREE (new_instance) = conv;
+ }
+ /* Fill the backedge child of the PHI SLP node. The
+ general matching code cannot find it because the
+ scalar code does not reflect how we vectorize the
+ reduction. */
+ use_operand_p use_p;
+ imm_use_iterator imm_iter;
+ class loop *loop = LOOP_VINFO_LOOP (vinfo);
+ FOR_EACH_IMM_USE_FAST (use_p, imm_iter,
+ gimple_get_lhs (scalar_def))
+ /* There are exactly two non-debug uses, the reduction
+ PHI and the loop-closed PHI node. */
+ if (!is_gimple_debug (USE_STMT (use_p))
+ && gimple_bb (USE_STMT (use_p)) == loop->header)
+ {
+ auto_vec<stmt_vec_info, 64> phis (group_size);
+ stmt_vec_info phi_info = vinfo->lookup_stmt (USE_STMT (use_p));
+ for (unsigned i = 0; i < group_size; ++i)
+ phis.quick_push (phi_info);
+ slp_tree *phi_node = bst_map->get (phis);
+ unsigned dest_idx = loop_latch_edge (loop)->dest_idx;
+ SLP_TREE_CHILDREN (*phi_node)[dest_idx]
+ = SLP_INSTANCE_TREE (new_instance);
+ SLP_INSTANCE_TREE (new_instance)->refcnt++;
+ }
+
+ vinfo->slp_instances.safe_push (new_instance);
+
+ /* ??? We've replaced the old SLP_INSTANCE_GROUP_SIZE with
+ the number of scalar stmts in the root in a few places.
+ Verify that assumption holds. */
+ gcc_assert (SLP_TREE_SCALAR_STMTS (SLP_INSTANCE_TREE (new_instance))
+ .length () == group_size);
+
+ if (dump_enabled_p ())
{
- unsigned HOST_WIDE_INT const_max_nunits;
- if (!max_nunits.is_constant (&const_max_nunits)
- || const_max_nunits > group_size)
- {
- if (dump_enabled_p ())
- dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
- "Build SLP failed: store group "
- "size not a multiple of the vector size "
- "in basic block SLP\n");
- vect_free_slp_tree (node);
- return false;
- }
- /* Fatal mismatch. */
- if (dump_enabled_p ())
- dump_printf_loc (MSG_NOTE, vect_location,
- "SLP discovery succeeded but node needs "
- "splitting\n");
- memset (matches, true, group_size);
- matches[group_size / const_max_nunits * const_max_nunits] = false;
- vect_free_slp_tree (node);
+ dump_printf_loc (MSG_NOTE, vect_location,
+ "Final SLP tree for instance %p:\n",
+ (void *) new_instance);
+ vect_print_slp_graph (MSG_NOTE, vect_location,
+ SLP_INSTANCE_TREE (new_instance));
}
- else
- {
- /* Create a new SLP instance. */
- slp_instance new_instance = XNEW (class _slp_instance);
- SLP_INSTANCE_TREE (new_instance) = node;
- SLP_INSTANCE_LOADS (new_instance) = vNULL;
- SLP_INSTANCE_ROOT_STMTS (new_instance) = root_stmt_infos;
- SLP_INSTANCE_REMAIN_DEFS (new_instance) = remain;
- SLP_INSTANCE_KIND (new_instance) = slp_inst_kind_reduc_chain;
- new_instance->reduc_phis = NULL;
- new_instance->cost_vec = vNULL;
- new_instance->subgraph_entries = vNULL;
- if (dump_enabled_p ())
- dump_printf_loc (MSG_NOTE, vect_location,
- "SLP size %u vs. limit %u.\n",
- tree_size, max_tree_size);
+ return true;
+ }
- /* Fixup SLP reduction chains. If this is a reduction chain with
- a conversion in front amend the SLP tree with a node for that. */
- gimple *scalar_def
- = vect_orig_stmt (scalar_stmts[group_size - 1])->stmt;
- if (STMT_VINFO_DEF_TYPE (scalar_stmts[0]) != vect_reduction_def)
- {
- /* Get at the conversion stmt - we know it's the single use
- of the last stmt of the reduction chain. */
- use_operand_p use_p;
- bool r = single_imm_use (gimple_assign_lhs (scalar_def),
- &use_p, &scalar_def);
- gcc_assert (r);
- stmt_vec_info next_info = vinfo->lookup_stmt (scalar_def);
- next_info = vect_stmt_to_vectorize (next_info);
- scalar_stmts = vNULL;
- scalar_stmts.create (group_size);
- for (unsigned i = 0; i < group_size; ++i)
- scalar_stmts.quick_push (next_info);
- slp_tree conv = vect_create_new_slp_node (scalar_stmts, 1);
- SLP_TREE_VECTYPE (conv)
- = get_vectype_for_scalar_type (vinfo,
- TREE_TYPE
- (gimple_assign_lhs (scalar_def)),
- group_size);
- SLP_TREE_REDUC_IDX (conv) = 0;
- conv->cycle_info.id = node->cycle_info.id;
- SLP_TREE_CHILDREN (conv).quick_push (node);
- SLP_INSTANCE_TREE (new_instance) = conv;
- /* We also have to fake this conversion stmt as SLP reduction
- group so we don't have to mess with too much code
- elsewhere. */
- REDUC_GROUP_FIRST_ELEMENT (next_info) = next_info;
- REDUC_GROUP_NEXT_ELEMENT (next_info) = NULL;
- }
- /* Fill the backedge child of the PHI SLP node. The
- general matching code cannot find it because the
- scalar code does not reflect how we vectorize the
- reduction. */
- use_operand_p use_p;
- imm_use_iterator imm_iter;
- class loop *loop = LOOP_VINFO_LOOP (as_a <loop_vec_info> (vinfo));
- FOR_EACH_IMM_USE_FAST (use_p, imm_iter,
- gimple_get_lhs (scalar_def))
- /* There are exactly two non-debug uses, the reduction
- PHI and the loop-closed PHI node. */
- if (!is_gimple_debug (USE_STMT (use_p))
- && gimple_bb (USE_STMT (use_p)) == loop->header)
- {
- auto_vec<stmt_vec_info, 64> phis (group_size);
- stmt_vec_info phi_info
- = vinfo->lookup_stmt (USE_STMT (use_p));
- for (unsigned i = 0; i < group_size; ++i)
- phis.quick_push (phi_info);
- slp_tree *phi_node = bst_map->get (phis);
- unsigned dest_idx = loop_latch_edge (loop)->dest_idx;
- SLP_TREE_CHILDREN (*phi_node)[dest_idx]
- = SLP_INSTANCE_TREE (new_instance);
- SLP_INSTANCE_TREE (new_instance)->refcnt++;
- }
+ /* Failed to SLP. */
+ scalar_stmts.release ();
+ if (dump_enabled_p ())
+ dump_printf_loc (MSG_NOTE, vect_location,
+ "SLP discovery of reduction chain failed\n");
+ return false;
+}
- vinfo->slp_instances.safe_push (new_instance);
+/* Analyze an SLP instance starting from SCALAR_STMTS which are a group
+ of KIND. Return true if successful. */
- /* ??? We've replaced the old SLP_INSTANCE_GROUP_SIZE with
- the number of scalar stmts in the root in a few places.
- Verify that assumption holds. */
- gcc_assert (SLP_TREE_SCALAR_STMTS (SLP_INSTANCE_TREE (new_instance))
- .length () == group_size);
+static bool
+vect_analyze_slp_reduction (loop_vec_info vinfo,
+ stmt_vec_info scalar_stmt,
+ unsigned max_tree_size, unsigned *limit,
+ scalar_stmts_to_slp_tree_map_t *bst_map,
+ bool force_single_lane)
+{
+ slp_instance_kind kind = slp_inst_kind_reduc_group;
- if (dump_enabled_p ())
- {
- dump_printf_loc (MSG_NOTE, vect_location,
- "Final SLP tree for instance %p:\n",
- (void *) new_instance);
- vect_print_slp_graph (MSG_NOTE, vect_location,
- SLP_INSTANCE_TREE (new_instance));
- }
+ /* If there's no budget left bail out early. */
+ if (*limit == 0)
+ return false;
- return true;
+ /* Try to gather a reduction chain. */
+ if (! force_single_lane
+ && STMT_VINFO_DEF_TYPE (scalar_stmt) == vect_reduction_def
+ && vect_analyze_slp_reduc_chain (vinfo, bst_map, scalar_stmt,
+ max_tree_size, limit))
+ return true;
+
+ vec<stmt_vec_info> scalar_stmts;
+ scalar_stmts.create (1);
+ scalar_stmts.quick_push (scalar_stmt);
+
+ if (dump_enabled_p ())
+ {
+ dump_printf_loc (MSG_NOTE, vect_location,
+ "Starting SLP discovery for\n");
+ for (unsigned i = 0; i < scalar_stmts.length (); ++i)
+ dump_printf_loc (MSG_NOTE, vect_location,
+ " %G", scalar_stmts[i]->stmt);
+ }
+
+ /* Build the tree for the SLP instance. */
+ unsigned int group_size = scalar_stmts.length ();
+ bool *matches = XALLOCAVEC (bool, group_size);
+ poly_uint64 max_nunits = 1;
+ unsigned tree_size = 0;
+
+ slp_tree node = vect_build_slp_tree (vinfo, scalar_stmts, group_size,
+ &max_nunits, matches, limit,
+ &tree_size, bst_map);
+ if (node != NULL)
+ {
+ /* Create a new SLP instance. */
+ slp_instance new_instance = XNEW (class _slp_instance);
+ SLP_INSTANCE_TREE (new_instance) = node;
+ SLP_INSTANCE_LOADS (new_instance) = vNULL;
+ SLP_INSTANCE_ROOT_STMTS (new_instance) = vNULL;
+ SLP_INSTANCE_REMAIN_DEFS (new_instance) = vNULL;
+ SLP_INSTANCE_KIND (new_instance) = kind;
+ new_instance->reduc_phis = NULL;
+ new_instance->cost_vec = vNULL;
+ new_instance->subgraph_entries = vNULL;
+
+ if (dump_enabled_p ())
+ dump_printf_loc (MSG_NOTE, vect_location,
+ "SLP size %u vs. limit %u.\n",
+ tree_size, max_tree_size);
+
+ vinfo->slp_instances.safe_push (new_instance);
+
+ /* ??? We've replaced the old SLP_INSTANCE_GROUP_SIZE with
+ the number of scalar stmts in the root in a few places.
+ Verify that assumption holds. */
+ gcc_assert (SLP_TREE_SCALAR_STMTS (SLP_INSTANCE_TREE (new_instance))
+ .length () == group_size);
+
+ if (dump_enabled_p ())
+ {
+ dump_printf_loc (MSG_NOTE, vect_location,
+ "Final SLP tree for instance %p:\n",
+ (void *) new_instance);
+ vect_print_slp_graph (MSG_NOTE, vect_location,
+ SLP_INSTANCE_TREE (new_instance));
}
+
+ return true;
}
/* Failed to SLP. */
@@ -5256,40 +5337,6 @@ vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size,
if (loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo))
{
- /* Find SLP sequences starting from reduction chains. */
- FOR_EACH_VEC_ELT (loop_vinfo->reduction_chains, i, first_element)
- if (! STMT_VINFO_RELEVANT_P (first_element)
- && ! STMT_VINFO_LIVE_P (first_element))
- ;
- else if (force_single_lane
- || ! vect_analyze_slp_reduc_chain (vinfo, bst_map,
- first_element,
- max_tree_size, &limit))
- {
- if (dump_enabled_p ())
- dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
- "SLP discovery of reduction chain failed\n");
- /* Dissolve reduction chain group. */
- stmt_vec_info vinfo = first_element;
- stmt_vec_info last = NULL;
- while (vinfo)
- {
- stmt_vec_info next = REDUC_GROUP_NEXT_ELEMENT (vinfo);
- REDUC_GROUP_FIRST_ELEMENT (vinfo) = NULL;
- REDUC_GROUP_NEXT_ELEMENT (vinfo) = NULL;
- last = vinfo;
- vinfo = next;
- }
- STMT_VINFO_DEF_TYPE (first_element) = vect_internal_def;
- /* ??? When there's a conversion around the reduction
- chain 'last' isn't the entry of the reduction. */
- if (STMT_VINFO_DEF_TYPE (last) != vect_reduction_def)
- return opt_result::failure_at (vect_location,
- "SLP build failed.\n");
- /* It can be still vectorized as part of an SLP reduction. */
- loop_vinfo->reductions.safe_push (last);
- }
-
/* Find SLP sequences starting from groups of reductions. */
if (loop_vinfo->reductions.length () > 0)
{
@@ -5315,23 +5362,13 @@ vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size,
if (!force_single_lane
&& !lane_reducing_stmt_p (STMT_VINFO_STMT (next_info)))
scalar_stmts.quick_push (next_info);
- else
- {
- /* Do SLP discovery for single-lane reductions. */
- vec<stmt_vec_info> stmts;
- vec<stmt_vec_info> roots = vNULL;
- vec<tree> remain = vNULL;
- stmts.create (1);
- stmts.quick_push (next_info);
- if (! vect_build_slp_instance (vinfo,
- slp_inst_kind_reduc_group,
- stmts, roots, remain,
- max_tree_size, &limit,
- bst_map,
- force_single_lane))
- return opt_result::failure_at (vect_location,
- "SLP build failed.\n");
- }
+ /* Do SLP discovery for single-lane reductions. */
+ else if (! vect_analyze_slp_reduction (loop_vinfo, next_info,
+ max_tree_size, &limit,
+ bst_map,
+ force_single_lane))
+ return opt_result::failure_at (vect_location,
+ "SLP build failed.\n");
}
}
/* Save for re-processing on failure. */
@@ -5349,20 +5386,13 @@ vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size,
scalar_stmts.release ();
/* Do SLP discovery for single-lane reductions. */
for (auto stmt_info : saved_stmts)
- {
- vec<stmt_vec_info> stmts;
- vec<stmt_vec_info> roots = vNULL;
- vec<tree> remain = vNULL;
- stmts.create (1);
- stmts.quick_push (vect_stmt_to_vectorize (stmt_info));
- if (! vect_build_slp_instance (vinfo,
- slp_inst_kind_reduc_group,
- stmts, roots, remain,
- max_tree_size, &limit,
- bst_map, force_single_lane))
- return opt_result::failure_at (vect_location,
- "SLP build failed.\n");
- }
+ if (! vect_analyze_slp_reduction (loop_vinfo,
+ vect_stmt_to_vectorize
+ (stmt_info),
+ max_tree_size, &limit,
+ bst_map, force_single_lane))
+ return opt_result::failure_at (vect_location,
+ "SLP build failed.\n");
}
saved_stmts.release ();
}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index dcb2522..83acbb3 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -2062,16 +2062,13 @@ vector_vector_composition_type (tree vtype, poly_uint64 nelts, tree *ptype,
VECTYPE is the vector type that the vectorized statements will use.
If ELSVALS is nonzero the supported else values will be stored in the
- vector ELSVALS points to.
-
- For loads PERM_OK indicates whether we can code generate a
- SLP_TREE_LOAD_PERMUTATION on the node. */
+ vector ELSVALS points to. */
static bool
get_load_store_type (vec_info *vinfo, stmt_vec_info stmt_info,
tree vectype, slp_tree slp_node,
bool masked_p, vec_load_store_type vls_type,
- bool perm_ok, vect_load_store_data *ls)
+ vect_load_store_data *ls)
{
vect_memory_access_type *memory_access_type = &ls->memory_access_type;
poly_int64 *poffset = &ls->poffset;
@@ -2081,6 +2078,8 @@ get_load_store_type (vec_info *vinfo, stmt_vec_info stmt_info,
internal_fn *lanes_ifn = &ls->lanes_ifn;
vec<int> *elsvals = &ls->elsvals;
tree *ls_type = &ls->ls_type;
+ bool *slp_perm = &ls->slp_perm;
+ unsigned *n_perms = &ls->n_perms;
loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
class loop *loop = loop_vinfo ? LOOP_VINFO_LOOP (loop_vinfo) : NULL;
@@ -2093,6 +2092,15 @@ get_load_store_type (vec_info *vinfo, stmt_vec_info stmt_info,
*misalignment = DR_MISALIGNMENT_UNKNOWN;
*poffset = 0;
*ls_type = NULL_TREE;
+ *slp_perm = false;
+ *n_perms = -1U;
+
+ bool perm_ok = true;
+ poly_int64 vf = loop_vinfo ? LOOP_VINFO_VECT_FACTOR (loop_vinfo) : 1;
+
+ if (SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
+ perm_ok = vect_transform_slp_perm_load (vinfo, slp_node, vNULL, NULL,
+ vf, true, n_perms);
if (STMT_VINFO_GROUPED_ACCESS (stmt_info))
{
@@ -2534,7 +2542,7 @@ get_load_store_type (vec_info *vinfo, stmt_vec_info stmt_info,
poly_uint64 read_amount
= vf * TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype)));
if (STMT_VINFO_GROUPED_ACCESS (stmt_info))
- read_amount *= DR_GROUP_SIZE (DR_GROUP_FIRST_ELEMENT (stmt_info));
+ read_amount *= group_size;
auto target_alignment
= DR_TARGET_ALIGNMENT (STMT_VINFO_DR_INFO (stmt_info));
@@ -2627,6 +2635,60 @@ get_load_store_type (vec_info *vinfo, stmt_vec_info stmt_info,
if (!loop_vinfo && *memory_access_type == VMAT_ELEMENTWISE)
return false;
+ /* Some loads need to explicitly permute the loaded data if there
+ is a load permutation. Among those are:
+ - VMAT_ELEMENTWISE.
+ - VMAT_STRIDED_SLP.
+ - VMAT_GATHER_SCATTER:
+ - Strided gather (fallback for VMAT_STRIDED_SLP if #lanes == 1).
+ - Grouped strided gather (ditto but for #lanes > 1).
+
+ For VMAT_ELEMENTWISE we can fold the load permutation into the
+ individual indices we access directly, eliding the permutation.
+ Strided gather only allows load permutations for the
+ single-element case. */
+
+ if (SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()
+ && !(*memory_access_type == VMAT_ELEMENTWISE
+ || (mat_gather_scatter_p (*memory_access_type)
+ && SLP_TREE_LANES (slp_node) == 1
+ && single_element_p)))
+ {
+ if (!loop_vinfo)
+ {
+ /* In BB vectorization we may not actually use a loaded vector
+ accessing elements in excess of DR_GROUP_SIZE. */
+ stmt_vec_info group_info = SLP_TREE_SCALAR_STMTS (slp_node)[0];
+ group_info = DR_GROUP_FIRST_ELEMENT (group_info);
+ unsigned HOST_WIDE_INT nunits;
+ unsigned j, k, maxk = 0;
+ FOR_EACH_VEC_ELT (SLP_TREE_LOAD_PERMUTATION (slp_node), j, k)
+ if (k > maxk)
+ maxk = k;
+ tree vectype = SLP_TREE_VECTYPE (slp_node);
+ if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits)
+ || maxk >= (DR_GROUP_SIZE (group_info) & ~(nunits - 1)))
+ {
+ if (dump_enabled_p ())
+ dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+ "BB vectorization with gaps at the end of "
+ "a load is not supported\n");
+ return false;
+ }
+ }
+
+ if (!perm_ok)
+ {
+ if (dump_enabled_p ())
+ dump_printf_loc (MSG_MISSED_OPTIMIZATION,
+ vect_location,
+ "unsupported load permutation\n");
+ return false;
+ }
+
+ *slp_perm = true;
+ }
+
return true;
}
@@ -8009,7 +8071,7 @@ vectorizable_store (vec_info *vinfo,
vect_load_store_data &ls = slp_node->get_data (_ls_data);
if (cost_vec
&& !get_load_store_type (vinfo, stmt_info, vectype, slp_node, mask_node,
- vls_type, false, &_ls_data))
+ vls_type, &_ls_data))
return false;
/* Temporary aliases to analysis data, should not be modified through
these. */
@@ -9454,7 +9516,6 @@ vectorizable_load (vec_info *vinfo,
bool compute_in_loop = false;
class loop *at_loop;
int vec_num;
- bool slp_perm = false;
bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
poly_uint64 vf;
tree aggr_type;
@@ -9592,17 +9653,11 @@ vectorizable_load (vec_info *vinfo,
else
group_size = 1;
- bool perm_ok = true;
- unsigned n_perms = -1U;
- if (cost_vec && SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
- perm_ok = vect_transform_slp_perm_load (vinfo, slp_node, vNULL, NULL, vf,
- true, &n_perms);
-
vect_load_store_data _ls_data{};
vect_load_store_data &ls = slp_node->get_data (_ls_data);
if (cost_vec
&& !get_load_store_type (vinfo, stmt_info, vectype, slp_node, mask_node,
- VLS_LOAD, perm_ok, &ls))
+ VLS_LOAD, &ls))
return false;
/* Temporary aliases to analysis data, should not be modified through
these. */
@@ -9623,56 +9678,6 @@ vectorizable_load (vec_info *vinfo,
bool type_mode_padding_p
= TYPE_PRECISION (scalar_type) < GET_MODE_PRECISION (GET_MODE_INNER (mode));
- /* ??? The following checks should really be part of
- get_load_store_type. */
- if (SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()
- && !(memory_access_type == VMAT_ELEMENTWISE
- || (mat_gather_scatter_p (memory_access_type)
- && SLP_TREE_LANES (slp_node) == 1
- && (!grouped_load
- || !DR_GROUP_NEXT_ELEMENT (first_stmt_info)))))
- {
- slp_perm = true;
-
- if (!loop_vinfo && cost_vec)
- {
- /* In BB vectorization we may not actually use a loaded vector
- accessing elements in excess of DR_GROUP_SIZE. */
- stmt_vec_info group_info = SLP_TREE_SCALAR_STMTS (slp_node)[0];
- group_info = DR_GROUP_FIRST_ELEMENT (group_info);
- unsigned HOST_WIDE_INT nunits;
- unsigned j, k, maxk = 0;
- FOR_EACH_VEC_ELT (SLP_TREE_LOAD_PERMUTATION (slp_node), j, k)
- if (k > maxk)
- maxk = k;
- tree vectype = SLP_TREE_VECTYPE (slp_node);
- if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits)
- || maxk >= (DR_GROUP_SIZE (group_info) & ~(nunits - 1)))
- {
- if (dump_enabled_p ())
- dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
- "BB vectorization with gaps at the end of "
- "a load is not supported\n");
- return false;
- }
- }
-
- if (cost_vec)
- {
- if (!perm_ok)
- {
- if (dump_enabled_p ())
- dump_printf_loc (MSG_MISSED_OPTIMIZATION,
- vect_location,
- "unsupported load permutation\n");
- return false;
- }
- ls.n_perms = n_perms;
- }
- else
- n_perms = ls.n_perms;
- }
-
if (slp_node->ldst_lanes
&& memory_access_type != VMAT_LOAD_STORE_LANES)
{
@@ -10027,7 +10032,7 @@ vectorizable_load (vec_info *vinfo,
not only the number of vector stmts the permutation result
fits in. */
int ncopies;
- if (slp_perm)
+ if (ls.slp_perm)
{
gcc_assert (memory_access_type != VMAT_ELEMENTWISE);
/* We don't yet generate SLP_TREE_LOAD_PERMUTATIONs for
@@ -10135,18 +10140,18 @@ vectorizable_load (vec_info *vinfo,
if (!costing_p)
{
- if (slp_perm)
+ if (ls.slp_perm)
dr_chain.quick_push (gimple_assign_lhs (new_stmt));
else
slp_node->push_vec_def (new_stmt);
}
}
- if (slp_perm)
+ if (ls.slp_perm)
{
if (costing_p)
{
- gcc_assert (n_perms != -1U);
- inside_cost += record_stmt_cost (cost_vec, n_perms, vec_perm,
+ gcc_assert (ls.n_perms != -1U);
+ inside_cost += record_stmt_cost (cost_vec, ls.n_perms, vec_perm,
slp_node, 0, vect_body);
}
else
@@ -10154,7 +10159,7 @@ vectorizable_load (vec_info *vinfo,
unsigned n_perms2;
vect_transform_slp_perm_load (vinfo, slp_node, dr_chain, gsi, vf,
false, &n_perms2);
- gcc_assert (n_perms == n_perms2);
+ gcc_assert (ls.n_perms == n_perms2);
}
}
@@ -10219,7 +10224,7 @@ vectorizable_load (vec_info *vinfo,
instead the access is contiguous but it might be
permuted. No gap adjustment is needed though. */
;
- else if (slp_perm
+ else if (ls.slp_perm
&& (group_size != scalar_lanes
|| !multiple_p (nunits, group_size)))
{
@@ -10568,7 +10573,7 @@ vectorizable_load (vec_info *vinfo,
if (mat_gather_scatter_p (memory_access_type))
{
- gcc_assert ((!grouped_load && !slp_perm) || ls.ls_type);
+ gcc_assert ((!grouped_load && !ls.slp_perm) || ls.ls_type);
/* If we pun the original vectype the loads as well as costing, length,
etc. is performed with the new type. After loading we VIEW_CONVERT
@@ -10930,14 +10935,14 @@ vectorizable_load (vec_info *vinfo,
/* Store vector loads in the corresponding SLP_NODE. */
if (!costing_p)
{
- if (slp_perm)
+ if (ls.slp_perm)
dr_chain.quick_push (gimple_assign_lhs (new_stmt));
else
slp_node->push_vec_def (new_stmt);
}
}
- if (slp_perm)
+ if (ls.slp_perm)
{
if (costing_p)
{
@@ -11034,7 +11039,7 @@ vectorizable_load (vec_info *vinfo,
stmt_info, bump);
}
- if (grouped_load || slp_perm)
+ if (grouped_load || ls.slp_perm)
dr_chain.create (vec_num);
gimple *new_stmt = NULL;
@@ -11531,11 +11536,11 @@ vectorizable_load (vec_info *vinfo,
/* Collect vector loads and later create their permutation in
vect_transform_slp_perm_load. */
- if (!costing_p && (grouped_load || slp_perm))
+ if (!costing_p && (grouped_load || ls.slp_perm))
dr_chain.quick_push (new_temp);
/* Store vector loads in the corresponding SLP_NODE. */
- if (!costing_p && !slp_perm)
+ if (!costing_p && !ls.slp_perm)
slp_node->push_vec_def (new_stmt);
/* With SLP permutation we load the gaps as well, without
@@ -11544,7 +11549,7 @@ vectorizable_load (vec_info *vinfo,
group_elt += nunits;
if (!costing_p
&& maybe_ne (group_gap_adj, 0U)
- && !slp_perm
+ && !ls.slp_perm
&& known_eq (group_elt, group_size - group_gap_adj))
{
poly_wide_int bump_val
@@ -11561,7 +11566,7 @@ vectorizable_load (vec_info *vinfo,
elements loaded for a permuted SLP load. */
if (!costing_p
&& maybe_ne (group_gap_adj, 0U)
- && slp_perm)
+ && ls.slp_perm)
{
poly_wide_int bump_val
= (wi::to_wide (TYPE_SIZE_UNIT (elem_type)) * group_gap_adj);
@@ -11572,7 +11577,7 @@ vectorizable_load (vec_info *vinfo,
stmt_info, bump);
}
- if (slp_perm)
+ if (ls.slp_perm)
{
/* For SLP we know we've seen all possible uses of dr_chain so
direct vect_transform_slp_perm_load to DCE the unused parts.
@@ -11580,9 +11585,9 @@ vectorizable_load (vec_info *vinfo,
in PR101120 and friends. */
if (costing_p)
{
- gcc_assert (n_perms != -1U);
- if (n_perms != 0)
- inside_cost = record_stmt_cost (cost_vec, n_perms, vec_perm,
+ gcc_assert (ls.n_perms != -1U);
+ if (ls.n_perms != 0)
+ inside_cost = record_stmt_cost (cost_vec, ls.n_perms, vec_perm,
slp_node, 0, vect_body);
}
else
@@ -11591,7 +11596,7 @@ vectorizable_load (vec_info *vinfo,
bool ok = vect_transform_slp_perm_load (vinfo, slp_node, dr_chain,
gsi, vf, false, &n_perms2,
nullptr, true);
- gcc_assert (ok && n_perms == n_perms2);
+ gcc_assert (ok && ls.n_perms == n_perms2);
}
dr_chain.release ();
}
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 52bc0d6..4785cbd 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -290,6 +290,8 @@ struct vect_load_store_data : vect_data {
tree strided_offset_vectype; // VMAT_GATHER_SCATTER_IFN, originally strided
tree ls_type; // VMAT_GATHER_SCATTER_IFN
auto_vec<int> elsvals;
+ /* True if the load requires a load permutation. */
+ bool slp_perm; // SLP_TREE_LOAD_PERMUTATION
unsigned n_perms; // SLP_TREE_LOAD_PERMUTATION
};
@@ -844,6 +846,9 @@ public:
following land-reducing operation would be assigned to. */
unsigned int reduc_result_pos;
+ /* Whether this represents a reduction chain. */
+ bool is_reduc_chain;
+
/* Whether we force a single cycle PHI during reduction vectorization. */
bool force_single_cycle;
@@ -1066,10 +1071,6 @@ public:
/* Reduction cycles detected in the loop. Used in loop-aware SLP. */
auto_vec<stmt_vec_info> reductions;
- /* All reduction chains in the loop, represented by the first
- stmt in the chain. */
- auto_vec<stmt_vec_info> reduction_chains;
-
/* Defs that could not be analyzed such as OMP SIMD calls without
a LHS. */
auto_vec<stmt_vec_info> alternate_defs;
@@ -1290,7 +1291,6 @@ public:
#define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
#define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
#define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
-#define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains
#define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps
#define LOOP_VINFO_PEELING_FOR_NITER(L) (L)->peeling_for_niter
#define LOOP_VINFO_EARLY_BREAKS(L) (L)->early_breaks
@@ -1538,7 +1538,7 @@ public:
/* Whether the stmt is SLPed, loop-based vectorized, or both. */
enum slp_vect_type slp_type;
- /* Interleaving and reduction chains info. */
+ /* Interleaving chains info. */
/* First element in the group. */
stmt_vec_info first_element;
/* Pointer to the next element in the group. */
@@ -1711,13 +1711,6 @@ struct gather_scatter_info {
#define DR_GROUP_GAP(S) \
(gcc_checking_assert ((S)->dr_aux.dr), (S)->gap)
-#define REDUC_GROUP_FIRST_ELEMENT(S) \
- (gcc_checking_assert (!(S)->dr_aux.dr), (S)->first_element)
-#define REDUC_GROUP_NEXT_ELEMENT(S) \
- (gcc_checking_assert (!(S)->dr_aux.dr), (S)->next_element)
-#define REDUC_GROUP_SIZE(S) \
- (gcc_checking_assert (!(S)->dr_aux.dr), (S)->size)
-
#define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
#define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index c1221fb..c216147 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,154 @@
+2025-10-14 Mike Crowe <mac@mcrowe.com>
+
+ PR libstdc++/116586
+ * testsuite/30_threads/this_thread/sleep_for.cc: Add
+ test_negative() test.
+ * testsuite/30_threads/this_thread/sleep_until.cc: Make existing
+ test use both system_clock and steady_clock. Add test_negative()
+ test.
+
+2025-10-14 Mike Crowe <mac@mcrowe.com>
+
+ PR libstdc++/116586
+ * testsuite/30_threads/timed_mutex/try_lock_until/116586.cc: New
+ test.
+
+2025-10-14 Mike Crowe <mac@mcrowe.com>
+
+ PR libstdc++/116586
+ * testsuite/30_threads/recursive_timed_mutex/try_lock_until/116586.cc:
+ New test.
+
+2025-10-14 Mike Crowe <mac@mcrowe.com>
+
+ PR libstdc++/116586
+ * testsuite/30_threads/future/members/116586.cc: New test.
+
+2025-10-14 Mike Crowe <mac@mcrowe.com>
+
+ PR libstdc++/116586
+ * testsuite/30_threads/condition_variable/members/116586.cc: New
+ test.
+
+2025-10-14 Jonathan Wakely <jwakely@redhat.com>
+
+ PR libstdc++/116586
+ * testsuite/30_threads/shared_timed_mutex/try_lock_until/116586.cc:
+ New test.
+
+2025-10-14 Mike Crowe <mac@mcrowe.com>
+
+ PR libstdc++/116586
+ * testsuite/30_threads/semaphore/try_acquire_for.cc: Add tests.
+ * testsuite/30_threads/semaphore/try_acquire_until.cc: Add
+ tests.
+
+2025-10-14 Jonathan Wakely <jwakely@redhat.com>
+
+ PR libstdc++/113327
+ PR libstdc++/116586
+ PR libstdc++/119258
+ PR libstdc++/58931
+ * include/bits/chrono.h (__to_timeout_timespec): New overloaded
+ function templates for converting chrono types to timespec.
+ * include/bits/std_mutex.h (__to_timeout_gthread_time_t): New
+ function template for converting time_point to __gthread_time_t.
+ * include/bits/this_thread_sleep.h (sleep_for): Use
+ __to_timeout_timespec.
+ (__sleep_for): Remove namespace-scope declaration.
+ * include/std/condition_variable: Likewise.
+ * include/std/mutex: Likewise.
+ * include/std/shared_mutex: Likewise.
+ * src/c++11/thread.cc (limit): New helper function.
+ (__sleep_for): Use limit to prevent overflow when converting
+ chrono::seconds to time_t, unsigned, or chrono::milliseconds.
+ * src/c++20/atomic.cc: Use __to_timeout_timespec and
+ __to_timeout_gthread_time_t for timeouts.
+ * testsuite/30_threads/this_thread/113327.cc: New test.
+
+2025-10-14 Luc Grosheintz <luc.grosheintz@gmail.com>
+
+ * include/std/format (_M_format_range): Remove unused local type
+ alias _String.
+
+2025-10-14 Jonathan Wakely <jwakely@redhat.com>
+
+ * include/bits/hashtable.h: Check specific feature test macros
+ instead of checking thevalue of __cplusplus.
+ * 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_tree.h: Likewise.
+ * include/bits/unordered_map.h: Likewise.
+ * include/bits/unordered_set.h: Likewise.
+ * include/debug/map.h: Likewise.
+ * include/debug/multimap.h: Likewise.
+ * include/debug/multiset.h: Likewise.
+ * include/debug/set.h: Likewise.
+ * include/debug/unordered_map: Likewise.
+ * include/debug/unordered_set: Likewise.
+
+2025-10-14 Jonathan Wakely <jwakely@redhat.com>
+
+ PR libstdc++/122255
+ * src/c++17/fs_path.cc (path::_List::_Impl::~_Impl): Define
+ destructor.
+ (path::_List::_Impl::copy): Use create_unchecked.
+ (path::_List::_Impl): Add static assertions.
+ (path::_List::_Impl::create): New static member function.
+ (path::_List::_Impl::create_unchecked): Likewise.
+ (path::_List::_Impl_deleter::operator()): Use destructor.
+ (path::_List::reserve): Use create.
+
+2025-10-14 Tomasz Kamiński <tkaminsk@redhat.com>
+
+ * include/std/format (__format::__write_escape_seqs)
+ (__format::_Escaping_sink): Define.
+ (__format::__write_escaped_unicode_part): Extract from
+ __format::__write_escaped_unicode.
+ (__format::__write_escaped_unicode): Forward to
+ __write_escaped_unicode_part.
+ (__formatter_str::_M_format_range): Use _Escaping sink.
+ * testsuite/std/format/ranges/string.cc: New tests for
+ character which codepoints will be split in buffer and
+ escaping. Invoked test_padding.
+
+2025-10-14 Tomasz Kamiński <tkaminsk@redhat.com>
+
+ PR libstdc++/118757
+ * include/bits/shared_ptr_atomic.h (_Atomic_count::_M_wait_unlock):
+ Add parameter capturing reference to _M_ptr. Reimplement in terms
+ of __atomic_wait_address.
+ (_Atomic_count::~_Atomic_count, _Atomic_count::lock)
+ (_Atomic_count::unlock, _Atomic_count::_M_swap_unlock): Replace
+ invocation of atomic member funcitons with __atomic builtins.
+ (_Atomic_count::notify_one, _Atomic_count::notify_all):
+ Use __atomic_notify_address.
+ (_Sp_atomic::element_type): Define.
+ (_Sp_atomic::_M_val): Change type to uintptr_t.
+ (_Sp_atomic::wait): Pass _M_ptr to _M_wait_unlock.
+ * python/libstdcxx/v6/printers.py:
+ * testsuite/20_util/shared_ptr/atomic/pr118757.cc: New test.
+ * testsuite/20_util/weak_ptr/pr118757.cc: New test.
+
+2025-10-14 Tomasz Kamiński <tkaminsk@redhat.com>
+
+ PR libstdc++/122267
+ * include/bits/atomic_base.h
+ (__atomic_ref_base<const _Tp>::_S_required_alignment):
+ Use __alignof__ instead of alignof.
+
+2025-10-14 Tomasz Kamiński <tkaminsk@redhat.com>
+
+ * testsuite/std/time/month_day/io.cc: New formatting tests.
+ * testsuite/std/time/month_day_last/io.cc: Likewise.
+ * testsuite/std/time/month_weekday/io.cc: Likewise.
+ * testsuite/std/time/month_weekday_last/io.cc: Likewise.
+ * testsuite/std/time/weekday_indexed/io.cc: Likewise.
+ * testsuite/std/time/weekday_last/io.cc: Likewise.
+ * testsuite/std/time/year_month/io.cc: Likewise.
+
2025-10-13 Jonathan Wakely <jwakely@redhat.com>
* include/bits/stl_iterator_base_funcs.h (advance): Fix comment.
diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 0f3f6b1..7e4ad2b 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -1538,7 +1538,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_S_required_aligment()
{
if constexpr (is_floating_point_v<_Vt> || is_pointer_v<_Vt>)
- return alignof(_Vt);
+ return __alignof__(_Vt);
else if constexpr ((sizeof(_Vt) & (sizeof(_Vt) - 1)) || sizeof(_Vt) > 16)
return alignof(_Vt);
else
diff --git a/libstdc++-v3/include/bits/chrono.h b/libstdc++-v3/include/bits/chrono.h
index 8de8e75..7f505aa 100644
--- a/libstdc++-v3/include/bits/chrono.h
+++ b/libstdc++-v3/include/bits/chrono.h
@@ -1515,6 +1515,78 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
} // namespace filesystem
#endif // C++17 && HOSTED
+#if defined _GLIBCXX_USE_NANOSLEEP || defined _GLIBCXX_USE_CLOCK_REALTIME \
+ || defined _GLIBCXX_HAS_GTHREADS
+namespace chrono
+{
+/// @cond undocumented
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wc++17-extensions"
+ // Convert a chrono::duration to a relative time represented as timespec
+ // (e.g. for use with nanosleep).
+ template<typename _Rep, typename _Period>
+ [[__nodiscard__]] _GLIBCXX14_CONSTEXPR inline
+ struct ::timespec
+ __to_timeout_timespec(const duration<_Rep, _Period>& __d)
+ {
+ struct ::timespec __ts{};
+
+ if (__d < __d.zero()) // Negative timeouts don't make sense.
+ return __ts;
+
+ if constexpr (ratio_greater<_Period, ratio<1>>::value
+ || treat_as_floating_point<_Rep>::value)
+ {
+ // Converting from e.g. chrono::hours::max() to chrono::seconds
+ // would evaluate LLONG_MAX * 3600 which would overflow.
+ // Limit to chrono::seconds::max().
+ chrono::duration<double> __fmax(chrono::seconds::max());
+ if (__d > __fmax) [[__unlikely__]]
+ return chrono::__to_timeout_timespec(chrono::seconds::max());
+ }
+
+ auto __s = chrono::duration_cast<chrono::seconds>(__d);
+
+ if constexpr (is_integral<time_t>::value) // POSIX.1-2001 allows floating
+ {
+ // Also limit to time_t maximum (only relevant for 32-bit time_t).
+ constexpr auto __tmax = numeric_limits<time_t>::max();
+ if (__s.count() > __tmax) [[__unlikely__]]
+ {
+ __ts.tv_sec = __tmax;
+ return __ts;
+ }
+ }
+
+ auto __ns = chrono::duration_cast<chrono::nanoseconds>(__d - __s);
+
+ if constexpr (treat_as_floating_point<_Rep>::value)
+ if (__ns.count() > 999999999) [[__unlikely__]]
+ __ns = chrono::nanoseconds(999999999);
+
+ __ts.tv_sec = static_cast<time_t>(__s.count());
+ __ts.tv_nsec = static_cast<long>(__ns.count());
+ return __ts;
+ }
+#pragma GCC diagnostic pop
+
+ // Convert a chrono::time_point to an absolute time represented as timespec.
+ // All times before the epoch get converted to the epoch, so this assumes
+ // that we only use it for clocks where that's true.
+ // It should be safe to use this for system_clock and steady_clock.
+ template<typename _Clock, typename _Dur>
+ [[__nodiscard__]] _GLIBCXX14_CONSTEXPR inline
+ struct ::timespec
+ __to_timeout_timespec(const time_point<_Clock, _Dur>& __t)
+ {
+ return chrono::__to_timeout_timespec(__t.time_since_epoch());
+ }
+
+/// @endcond
+} // namespace chrono
+#endif // USE_NANOSLEEP || USE_CLOCK_REALTIME || HAS_GTHREADS
+
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h
index b5a71f5..06cc51a 100644
--- a/libstdc++-v3/include/bits/hashtable.h
+++ b/libstdc++-v3/include/bits/hashtable.h
@@ -38,7 +38,7 @@
#include <bits/enable_special_members.h>
#include <bits/stl_algobase.h> // fill_n, is_permutation
#include <bits/stl_function.h> // __has_is_transparent_t
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
# include <bits/node_handle.h>
#endif
@@ -349,7 +349,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
using size_type = typename __hashtable_base::size_type;
using difference_type = typename __hashtable_base::difference_type;
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
using node_type = _Node_handle<_Key, _Value, __node_alloc_type>;
using insert_return_type = _Node_insert_return<iterator, node_type>;
#endif
@@ -1931,7 +1931,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
-> const_iterator
{ return const_iterator(_M_locate(__k)); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Key, typename _Value, typename _Alloc,
typename _ExtractKey, typename _Equal,
typename _Hash, typename _RangeHash, typename _Unused,
@@ -1979,7 +1979,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::size_t __bkt = _M_bucket_index(__code);
return const_iterator(_M_find_node_tr(__bkt, __k, __code));
}
-#endif
+#endif // C++20 __glibcxx_generic_unordered_lookup
template<typename _Key, typename _Value, typename _Alloc,
typename _ExtractKey, typename _Equal,
@@ -2007,7 +2007,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __result;
}
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Key, typename _Value, typename _Alloc,
typename _ExtractKey, typename _Equal,
typename _Hash, typename _RangeHash, typename _Unused,
@@ -2052,7 +2052,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __result;
}
-#endif
+#endif // C++20 __glibcxx_generic_unordered_lookup
template<typename _Key, typename _Value, typename _Alloc,
typename _ExtractKey, typename _Equal,
@@ -2102,7 +2102,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return { __beg, __ite };
}
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Key, typename _Value, typename _Alloc,
typename _ExtractKey, typename _Equal,
typename _Hash, typename _RangeHash, typename _Unused,
@@ -2190,7 +2190,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return { __beg, __ite };
}
-#endif
+#endif // C++20 __glibcxx_generic_unordered_lookup
// Find the node before the one whose key compares equal to k in the bucket
// bkt. Return nullptr if no node is found.
@@ -2966,7 +2966,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
#pragma GCC diagnostic pop
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
template<typename, typename, typename> class _Hash_merge_helper { };
#endif // C++17
diff --git a/libstdc++-v3/include/bits/shared_ptr_atomic.h b/libstdc++-v3/include/bits/shared_ptr_atomic.h
index cc7841a..cbc4bf6 100644
--- a/libstdc++-v3/include/bits/shared_ptr_atomic.h
+++ b/libstdc++-v3/include/bits/shared_ptr_atomic.h
@@ -392,6 +392,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
class _Sp_atomic
{
using value_type = _Tp;
+ using element_type = typename _Tp::element_type;
friend struct atomic<_Tp>;
@@ -420,7 +421,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
~_Atomic_count()
{
- auto __val = _M_val.load(memory_order_relaxed);
+ auto __val = _AtomicRef(_M_val).load(memory_order_relaxed);
_GLIBCXX_TSAN_MUTEX_DESTROY(&_M_val);
__glibcxx_assert(!(__val & _S_lock_bit));
if (auto __pi = reinterpret_cast<pointer>(__val))
@@ -442,18 +443,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
// To acquire the lock we flip the LSB from 0 to 1.
- auto __current = _M_val.load(memory_order_relaxed);
+ _AtomicRef __aref(_M_val);
+ auto __current = __aref.load(memory_order_relaxed);
while (__current & _S_lock_bit)
{
#if __glibcxx_atomic_wait
__detail::__thread_relax();
#endif
- __current = _M_val.load(memory_order_relaxed);
+ __current = __aref.load(memory_order_relaxed);
}
_GLIBCXX_TSAN_MUTEX_TRY_LOCK(&_M_val);
- while (!_M_val.compare_exchange_strong(__current,
+ while (!__aref.compare_exchange_strong(__current,
__current | _S_lock_bit,
__o,
memory_order_relaxed))
@@ -474,7 +476,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
unlock(memory_order __o) const noexcept
{
_GLIBCXX_TSAN_MUTEX_PRE_UNLOCK(&_M_val);
- _M_val.fetch_sub(1, __o);
+ _AtomicRef(_M_val).fetch_sub(1, __o);
_GLIBCXX_TSAN_MUTEX_POST_UNLOCK(&_M_val);
}
@@ -487,7 +489,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__o = memory_order_release;
auto __x = reinterpret_cast<uintptr_t>(__c._M_pi);
_GLIBCXX_TSAN_MUTEX_PRE_UNLOCK(&_M_val);
- __x = _M_val.exchange(__x, __o);
+ __x = _AtomicRef(_M_val).exchange(__x, __o);
_GLIBCXX_TSAN_MUTEX_POST_UNLOCK(&_M_val);
__c._M_pi = reinterpret_cast<pointer>(__x & ~_S_lock_bit);
}
@@ -495,19 +497,45 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __glibcxx_atomic_wait
// Precondition: caller holds lock!
void
- _M_wait_unlock(memory_order __o) const noexcept
+ _M_wait_unlock(const element_type* const& __ptr, memory_order __o) const noexcept
{
+ auto __old_ptr = __ptr;
_GLIBCXX_TSAN_MUTEX_PRE_UNLOCK(&_M_val);
- auto __v = _M_val.fetch_sub(1, memory_order_relaxed);
+ uintptr_t __old_pi
+ = _AtomicRef(_M_val).fetch_sub(1, memory_order_relaxed) - 1u;
_GLIBCXX_TSAN_MUTEX_POST_UNLOCK(&_M_val);
- _M_val.wait(__v & ~_S_lock_bit, __o);
+
+ // Ensure that the correct value of _M_ptr is visible after locking,
+ // by upgrading relaxed or consume to acquire.
+ auto __lo = __o;
+ if (__o != memory_order_seq_cst)
+ __lo = memory_order_acquire;
+
+ std::__atomic_wait_address(
+ &_M_val,
+ [=, &__ptr, this](uintptr_t __new_pi)
+ {
+ if (__old_pi != (__new_pi & ~_S_lock_bit))
+ // control block changed, we can wake up
+ return true;
+
+ // control block is same, we need to check if ptr changed,
+ // the lock needs to be taken first, the value of pi may have
+ // also been updated in meantime, so reload it
+ __new_pi = reinterpret_cast<uintptr_t>(this->lock(__lo));
+ auto __new_ptr = __ptr;
+ this->unlock(memory_order_relaxed);
+ // wake up if either of the values changed
+ return __new_pi != __old_pi || __new_ptr != __old_ptr;
+ },
+ [__o, this] { return _AtomicRef(_M_val).load(__o); });
}
void
notify_one() noexcept
{
_GLIBCXX_TSAN_MUTEX_PRE_SIGNAL(&_M_val);
- _M_val.notify_one();
+ _AtomicRef(_M_val).notify_one();
_GLIBCXX_TSAN_MUTEX_POST_SIGNAL(&_M_val);
}
@@ -515,17 +543,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
notify_all() noexcept
{
_GLIBCXX_TSAN_MUTEX_PRE_SIGNAL(&_M_val);
- _M_val.notify_all();
+ _AtomicRef(_M_val).notify_all();
_GLIBCXX_TSAN_MUTEX_POST_SIGNAL(&_M_val);
}
#endif
private:
- mutable __atomic_base<uintptr_t> _M_val{0};
+ using _AtomicRef = __atomic_ref<uintptr_t>;
+ alignas(_AtomicRef::required_alignment) mutable uintptr_t _M_val{0};
static constexpr uintptr_t _S_lock_bit{1};
};
- typename _Tp::element_type* _M_ptr = nullptr;
+ element_type* _M_ptr = nullptr;
_Atomic_count _M_refcount;
static typename _Atomic_count::pointer
@@ -608,7 +637,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
auto __pi = _M_refcount.lock(memory_order_acquire);
if (_M_ptr == __old._M_ptr && __pi == __old._M_refcount._M_pi)
- _M_refcount._M_wait_unlock(__o);
+ _M_refcount._M_wait_unlock(_M_ptr, __o);
else
_M_refcount.unlock(memory_order_relaxed);
}
diff --git a/libstdc++-v3/include/bits/std_mutex.h b/libstdc++-v3/include/bits/std_mutex.h
index 777097b..5f9f154 100644
--- a/libstdc++-v3/include/bits/std_mutex.h
+++ b/libstdc++-v3/include/bits/std_mutex.h
@@ -39,6 +39,7 @@
#else
#include <errno.h> // EBUSY
+#include <bits/chrono.h>
#include <bits/functexcept.h>
#include <bits/gthr.h>
@@ -210,8 +211,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__gthread_cond_t _M_cond;
#endif
};
- /// @endcond
+namespace chrono
+{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wc++17-extensions"
+ // Convert a time_point to an absolute time represented as __gthread_time_t
+ // (which is typically just a typedef for struct timespec).
+ template<typename _Clock, typename _Dur>
+ [[__nodiscard__]] _GLIBCXX14_CONSTEXPR inline
+ __gthread_time_t
+ __to_timeout_gthread_time_t(const time_point<_Clock, _Dur>& __t)
+ {
+ auto __ts = chrono::__to_timeout_timespec(__t.time_since_epoch());
+ if constexpr (is_same<::timespec, __gthread_time_t>::value)
+ return __ts;
+ else if constexpr (is_convertible<::timespec, __gthread_time_t>::value)
+ return __ts;
+ else if constexpr (is_scalar<__gthread_time_t>::value) // Assume seconds:
+ return static_cast<__gthread_time_t>(__ts.tv_sec);
+ else // Assume this works and the members are in the correct order:
+ return __gthread_time_t{ __ts.tv_sec, __ts.tv_nsec };
+ }
+#pragma GCC diagnostic pop
+}
+ /// @endcond
#endif // _GLIBCXX_HAS_GTHREADS
/// Do not acquire ownership of the mutex.
diff --git a/libstdc++-v3/include/bits/stl_map.h b/libstdc++-v3/include/bits/stl_map.h
index 68c23b8..62d66ce 100644
--- a/libstdc++-v3/include/bits/stl_map.h
+++ b/libstdc++-v3/include/bits/stl_map.h
@@ -1259,7 +1259,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
find(const key_type& __x)
{ return _M_t.find(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
find(const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
@@ -1284,7 +1284,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
find(const key_type& __x) const
{ return _M_t.find(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
find(const _Kt& __x) const -> decltype(_M_t._M_find_tr(__x))
@@ -1305,7 +1305,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
count(const key_type& __x) const
{ return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
@@ -1348,7 +1348,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
lower_bound(const key_type& __x)
{ return _M_t.lower_bound(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
lower_bound(const _Kt& __x)
@@ -1373,7 +1373,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
lower_bound(const key_type& __x) const
{ return _M_t.lower_bound(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
lower_bound(const _Kt& __x) const
@@ -1393,7 +1393,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
upper_bound(const key_type& __x)
{ return _M_t.upper_bound(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
upper_bound(const _Kt& __x)
@@ -1413,7 +1413,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
upper_bound(const key_type& __x) const
{ return _M_t.upper_bound(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
upper_bound(const _Kt& __x) const
@@ -1442,7 +1442,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
equal_range(const key_type& __x)
{ return _M_t.equal_range(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
equal_range(const _Kt& __x)
@@ -1471,7 +1471,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
equal_range(const key_type& __x) const
{ return _M_t.equal_range(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
equal_range(const _Kt& __x) const
@@ -1649,7 +1649,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_GLIBCXX_END_NAMESPACE_CONTAINER
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
// Allow std::map access to internals of compatible maps.
template<typename _Key, typename _Val, typename _Cmp1, typename _Alloc,
typename _Cmp2>
diff --git a/libstdc++-v3/include/bits/stl_multimap.h b/libstdc++-v3/include/bits/stl_multimap.h
index 4ee4a84..b2ae2ba 100644
--- a/libstdc++-v3/include/bits/stl_multimap.h
+++ b/libstdc++-v3/include/bits/stl_multimap.h
@@ -891,7 +891,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
find(const key_type& __x)
{ return _M_t.find(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
find(const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
@@ -915,7 +915,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
find(const key_type& __x) const
{ return _M_t.find(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
find(const _Kt& __x) const -> decltype(_M_t._M_find_tr(__x))
@@ -933,7 +933,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
count(const key_type& __x) const
{ return _M_t.count(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
@@ -976,7 +976,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
lower_bound(const key_type& __x)
{ return _M_t.lower_bound(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
lower_bound(const _Kt& __x)
@@ -1001,7 +1001,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
lower_bound(const key_type& __x) const
{ return _M_t.lower_bound(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
lower_bound(const _Kt& __x) const
@@ -1021,7 +1021,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
upper_bound(const key_type& __x)
{ return _M_t.upper_bound(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
upper_bound(const _Kt& __x)
@@ -1041,7 +1041,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
upper_bound(const key_type& __x) const
{ return _M_t.upper_bound(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
upper_bound(const _Kt& __x) const
@@ -1068,7 +1068,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
equal_range(const key_type& __x)
{ return _M_t.equal_range(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
equal_range(const _Kt& __x)
@@ -1095,7 +1095,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
equal_range(const key_type& __x) const
{ return _M_t.equal_range(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
equal_range(const _Kt& __x) const
@@ -1272,7 +1272,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_GLIBCXX_END_NAMESPACE_CONTAINER
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
// Allow std::multimap access to internals of compatible maps.
template<typename _Key, typename _Val, typename _Cmp1, typename _Alloc,
typename _Cmp2>
diff --git a/libstdc++-v3/include/bits/stl_multiset.h b/libstdc++-v3/include/bits/stl_multiset.h
index 31451ab..b6e1bfc 100644
--- a/libstdc++-v3/include/bits/stl_multiset.h
+++ b/libstdc++-v3/include/bits/stl_multiset.h
@@ -773,7 +773,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
count(const key_type& __x) const
{ return _M_t.count(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
@@ -822,7 +822,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
find(const key_type& __x) const
{ return _M_t.find(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
find(const _Kt& __x)
@@ -857,7 +857,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
lower_bound(const key_type& __x) const
{ return _M_t.lower_bound(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
lower_bound(const _Kt& __x)
@@ -887,7 +887,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
upper_bound(const key_type& __x) const
{ return _M_t.upper_bound(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
upper_bound(const _Kt& __x)
@@ -926,7 +926,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
equal_range(const key_type& __x) const
{ return _M_t.equal_range(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
equal_range(const _Kt& __x)
@@ -1103,7 +1103,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_GLIBCXX_END_NAMESPACE_CONTAINER
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
// Allow std::multiset access to internals of compatible sets.
template<typename _Val, typename _Cmp1, typename _Alloc, typename _Cmp2>
struct
diff --git a/libstdc++-v3/include/bits/stl_set.h b/libstdc++-v3/include/bits/stl_set.h
index b65d631..f03d9e5 100644
--- a/libstdc++-v3/include/bits/stl_set.h
+++ b/libstdc++-v3/include/bits/stl_set.h
@@ -794,7 +794,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
count(const key_type& __x) const
{ return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
count(const _Kt& __x) const
@@ -844,7 +844,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
find(const key_type& __x) const
{ return _M_t.find(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
find(const _Kt& __x)
@@ -879,7 +879,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
lower_bound(const key_type& __x) const
{ return _M_t.lower_bound(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
lower_bound(const _Kt& __x)
@@ -909,7 +909,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
upper_bound(const key_type& __x) const
{ return _M_t.upper_bound(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
upper_bound(const _Kt& __x)
@@ -948,7 +948,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
equal_range(const key_type& __x) const
{ return _M_t.equal_range(__x); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt>
auto
equal_range(const _Kt& __x)
@@ -1119,7 +1119,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_GLIBCXX_END_NAMESPACE_CONTAINER
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
// Allow std::set access to internals of compatible sets.
template<typename _Val, typename _Cmp1, typename _Alloc, typename _Cmp2>
struct
diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h
index 4b7f482..e78fa1d 100644
--- a/libstdc++-v3/include/bits/stl_tree.h
+++ b/libstdc++-v3/include/bits/stl_tree.h
@@ -1918,7 +1918,7 @@ namespace __rb_tree
pair<const_iterator, const_iterator>
equal_range(const key_type& __k) const;
-#if __cplusplus >= 201402L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req = __has_is_transparent_t<_Compare, _Kt>>
iterator
@@ -2007,7 +2007,7 @@ namespace __rb_tree
++__high;
return { __low, __high };
}
-#endif
+#endif // __glibcxx_generic_associative_lookup
// Debugging.
bool
diff --git a/libstdc++-v3/include/bits/this_thread_sleep.h b/libstdc++-v3/include/bits/this_thread_sleep.h
index 57f89f8..01f25dd 100644
--- a/libstdc++-v3/include/bits/this_thread_sleep.h
+++ b/libstdc++-v3/include/bits/this_thread_sleep.h
@@ -36,6 +36,7 @@
#if __cplusplus >= 201103L
#include <bits/chrono.h> // std::chrono::*
+#include <ext/numeric_traits.h> // __int_traits
#ifdef _GLIBCXX_USE_NANOSLEEP
# include <cerrno> // errno, EINTR
@@ -59,11 +60,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
#ifndef _GLIBCXX_NO_SLEEP
-#ifndef _GLIBCXX_USE_NANOSLEEP
- void
- __sleep_for(chrono::seconds, chrono::nanoseconds);
-#endif
-
/// this_thread::sleep_for
template<typename _Rep, typename _Period>
inline void
@@ -71,18 +67,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
if (__rtime <= __rtime.zero())
return;
- auto __s = chrono::duration_cast<chrono::seconds>(__rtime);
- auto __ns = chrono::duration_cast<chrono::nanoseconds>(__rtime - __s);
+
+ struct timespec __ts = chrono::__to_timeout_timespec(__rtime);
#ifdef _GLIBCXX_USE_NANOSLEEP
- struct ::timespec __ts =
- {
- static_cast<std::time_t>(__s.count()),
- static_cast<long>(__ns.count())
- };
while (::nanosleep(&__ts, &__ts) == -1 && errno == EINTR)
{ }
#else
- __sleep_for(__s, __ns);
+ using chrono::seconds;
+ using chrono::nanoseconds;
+ void __sleep_for(seconds __s, nanoseconds __ns);
+ __sleep_for(seconds(__ts.tv_sec), nanoseconds(__ts.tv_nsec));
#endif
}
diff --git a/libstdc++-v3/include/bits/unordered_map.h b/libstdc++-v3/include/bits/unordered_map.h
index cc9e2c4..b9b2772 100644
--- a/libstdc++-v3/include/bits/unordered_map.h
+++ b/libstdc++-v3/include/bits/unordered_map.h
@@ -961,7 +961,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
find(const key_type& __x)
{ return _M_h.find(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
find(const _Kt& __x) -> decltype(_M_h._M_find_tr(__x))
@@ -972,7 +972,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
find(const key_type& __x) const
{ return _M_h.find(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
find(const _Kt& __x) const -> decltype(_M_h._M_find_tr(__x))
@@ -994,7 +994,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
count(const key_type& __x) const
{ return _M_h.count(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
count(const _Kt& __x) const -> decltype(_M_h._M_count_tr(__x))
@@ -1034,7 +1034,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
equal_range(const key_type& __x)
{ return _M_h.equal_range(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
equal_range(const _Kt& __x)
@@ -1046,7 +1046,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
equal_range(const key_type& __x) const
{ return _M_h.equal_range(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
equal_range(const _Kt& __x) const
@@ -2039,7 +2039,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
find(const key_type& __x)
{ return _M_h.find(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
find(const _Kt& __x) -> decltype(_M_h._M_find_tr(__x))
@@ -2050,7 +2050,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
find(const key_type& __x) const
{ return _M_h.find(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
find(const _Kt& __x) const -> decltype(_M_h._M_find_tr(__x))
@@ -2068,7 +2068,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
count(const key_type& __x) const
{ return _M_h.count(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
count(const _Kt& __x) const -> decltype(_M_h._M_count_tr(__x))
@@ -2106,7 +2106,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
equal_range(const key_type& __x)
{ return _M_h.equal_range(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
equal_range(const _Kt& __x)
@@ -2118,7 +2118,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
equal_range(const key_type& __x) const
{ return _M_h.equal_range(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
equal_range(const _Kt& __x) const
diff --git a/libstdc++-v3/include/bits/unordered_set.h b/libstdc++-v3/include/bits/unordered_set.h
index 5649dd7..29bc49a 100644
--- a/libstdc++-v3/include/bits/unordered_set.h
+++ b/libstdc++-v3/include/bits/unordered_set.h
@@ -744,7 +744,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
find(const key_type& __x)
{ return _M_h.find(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
find(const _Kt& __k)
@@ -756,7 +756,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
find(const key_type& __x) const
{ return _M_h.find(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
find(const _Kt& __k) const
@@ -779,7 +779,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
count(const key_type& __x) const
{ return _M_h.count(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
count(const _Kt& __k) const
@@ -820,7 +820,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
equal_range(const key_type& __x)
{ return _M_h.equal_range(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
equal_range(const _Kt& __k)
@@ -832,7 +832,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
equal_range(const key_type& __x) const
{ return _M_h.equal_range(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
equal_range(const _Kt& __k) const
@@ -1745,7 +1745,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
find(const key_type& __x)
{ return _M_h.find(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
find(const _Kt& __x)
@@ -1757,7 +1757,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
find(const key_type& __x) const
{ return _M_h.find(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
find(const _Kt& __x) const
@@ -1776,7 +1776,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
count(const key_type& __x) const
{ return _M_h.count(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
count(const _Kt& __x) const -> decltype(_M_h._M_count_tr(__x))
@@ -1814,7 +1814,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
equal_range(const key_type& __x)
{ return _M_h.equal_range(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
equal_range(const _Kt& __x)
@@ -1826,7 +1826,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
equal_range(const key_type& __x) const
{ return _M_h.equal_range(__x); }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt>
auto
equal_range(const _Kt& __x) const
diff --git a/libstdc++-v3/include/debug/map.h b/libstdc++-v3/include/debug/map.h
index 985a7ac..30469b0 100644
--- a/libstdc++-v3/include/debug/map.h
+++ b/libstdc++-v3/include/debug/map.h
@@ -455,7 +455,7 @@ namespace __debug
}
#endif // C++17
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
using node_type = typename _Base::node_type;
using insert_return_type = _Node_insert_return<iterator, node_type>;
@@ -601,7 +601,7 @@ namespace __debug
find(const key_type& __x)
{ return iterator(_Base::find(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -614,7 +614,7 @@ namespace __debug
find(const key_type& __x) const
{ return const_iterator(_Base::find(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -629,7 +629,7 @@ namespace __debug
lower_bound(const key_type& __x)
{ return iterator(_Base::lower_bound(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -642,7 +642,7 @@ namespace __debug
lower_bound(const key_type& __x) const
{ return const_iterator(_Base::lower_bound(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -655,7 +655,7 @@ namespace __debug
upper_bound(const key_type& __x)
{ return iterator(_Base::upper_bound(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -668,7 +668,7 @@ namespace __debug
upper_bound(const key_type& __x) const
{ return const_iterator(_Base::upper_bound(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -686,7 +686,7 @@ namespace __debug
iterator(__res.second, this));
}
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -707,7 +707,7 @@ namespace __debug
const_iterator(__res.second, this));
}
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
diff --git a/libstdc++-v3/include/debug/multimap.h b/libstdc++-v3/include/debug/multimap.h
index c187e51..db9e246 100644
--- a/libstdc++-v3/include/debug/multimap.h
+++ b/libstdc++-v3/include/debug/multimap.h
@@ -340,7 +340,7 @@ namespace __debug
_Base::insert(__first, __last);
}
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
using node_type = typename _Base::node_type;
node_type
@@ -483,7 +483,7 @@ namespace __debug
find(const key_type& __x)
{ return iterator(_Base::find(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -496,7 +496,7 @@ namespace __debug
find(const key_type& __x) const
{ return const_iterator(_Base::find(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -511,7 +511,7 @@ namespace __debug
lower_bound(const key_type& __x)
{ return iterator(_Base::lower_bound(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -524,7 +524,7 @@ namespace __debug
lower_bound(const key_type& __x) const
{ return const_iterator(_Base::lower_bound(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -537,7 +537,7 @@ namespace __debug
upper_bound(const key_type& __x)
{ return iterator(_Base::upper_bound(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -550,7 +550,7 @@ namespace __debug
upper_bound(const key_type& __x) const
{ return const_iterator(_Base::upper_bound(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -568,7 +568,7 @@ namespace __debug
iterator(__res.second, this));
}
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -589,7 +589,7 @@ namespace __debug
const_iterator(__res.second, this));
}
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
diff --git a/libstdc++-v3/include/debug/multiset.h b/libstdc++-v3/include/debug/multiset.h
index 41bf78d..156378a 100644
--- a/libstdc++-v3/include/debug/multiset.h
+++ b/libstdc++-v3/include/debug/multiset.h
@@ -311,7 +311,7 @@ namespace __debug
{ _Base::insert(__l); }
#endif
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
using node_type = typename _Base::node_type;
node_type
@@ -457,7 +457,7 @@ namespace __debug
find(const key_type& __x) const
{ return const_iterator(_Base::find(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -485,7 +485,7 @@ namespace __debug
lower_bound(const key_type& __x) const
{ return const_iterator(_Base::lower_bound(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -511,7 +511,7 @@ namespace __debug
upper_bound(const key_type& __x) const
{ return const_iterator(_Base::upper_bound(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -547,7 +547,7 @@ namespace __debug
const_iterator(__res.second, this));
}
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
diff --git a/libstdc++-v3/include/debug/set.h b/libstdc++-v3/include/debug/set.h
index 6ec8338..9b42862 100644
--- a/libstdc++-v3/include/debug/set.h
+++ b/libstdc++-v3/include/debug/set.h
@@ -319,7 +319,7 @@ namespace __debug
{ _Base::insert(__l); }
#endif
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
using node_type = typename _Base::node_type;
using insert_return_type = _Node_insert_return<iterator, node_type>;
@@ -468,7 +468,7 @@ namespace __debug
find(const key_type& __x) const
{ return const_iterator(_Base::find(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -496,7 +496,7 @@ namespace __debug
lower_bound(const key_type& __x) const
{ return const_iterator(_Base::lower_bound(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -522,7 +522,7 @@ namespace __debug
upper_bound(const key_type& __x) const
{ return const_iterator(_Base::upper_bound(__x), this); }
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
@@ -558,7 +558,7 @@ namespace __debug
const_iterator(__res.second, this));
}
-#if __cplusplus > 201103L
+#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
template<typename _Kt,
typename _Req =
typename __has_is_transparent<_Compare, _Kt>::type>
diff --git a/libstdc++-v3/include/debug/unordered_map b/libstdc++-v3/include/debug/unordered_map
index 7673db1..c90e44a 100644
--- a/libstdc++-v3/include/debug/unordered_map
+++ b/libstdc++-v3/include/debug/unordered_map
@@ -561,7 +561,7 @@ namespace __debug
}
#endif // C++17
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
using node_type = typename _Base::node_type;
using insert_return_type = _Node_insert_return<iterator, node_type>;
@@ -632,7 +632,7 @@ namespace __debug
find(const key_type& __key)
{ return { _Base::find(__key), this }; }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt,
typename = std::__has_is_transparent_t<_Hash, _Kt>,
typename = std::__has_is_transparent_t<_Pred, _Kt>>
@@ -645,7 +645,7 @@ namespace __debug
find(const key_type& __key) const
{ return { _Base::find(__key), this }; }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt,
typename = std::__has_is_transparent_t<_Hash, _Kt>,
typename = std::__has_is_transparent_t<_Pred, _Kt>>
@@ -666,7 +666,7 @@ namespace __debug
return { { __res.first, this }, { __res.second, this } };
}
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt,
typename = std::__has_is_transparent_t<_Hash, _Kt>,
typename = std::__has_is_transparent_t<_Pred, _Kt>>
@@ -685,7 +685,7 @@ namespace __debug
return { { __res.first, this }, { __res.second, this } };
}
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt,
typename = std::__has_is_transparent_t<_Hash, _Kt>,
typename = std::__has_is_transparent_t<_Pred, _Kt>>
@@ -790,7 +790,7 @@ namespace __debug
return __next;
}
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
node_type
_M_extract(_Base_const_iterator __victim)
{
@@ -1362,7 +1362,7 @@ namespace __debug
_M_check_rehashed(__bucket_count);
}
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
using node_type = typename _Base::node_type;
node_type
@@ -1428,7 +1428,7 @@ namespace __debug
find(const key_type& __key)
{ return { _Base::find(__key), this }; }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt,
typename = std::__has_is_transparent_t<_Hash, _Kt>,
typename = std::__has_is_transparent_t<_Pred, _Kt>>
@@ -1441,7 +1441,7 @@ namespace __debug
find(const key_type& __key) const
{ return { _Base::find(__key), this }; }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt,
typename = std::__has_is_transparent_t<_Hash, _Kt>,
typename = std::__has_is_transparent_t<_Pred, _Kt>>
@@ -1462,7 +1462,7 @@ namespace __debug
return { { __res.first, this }, { __res.second, this } };
}
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt,
typename = std::__has_is_transparent_t<_Hash, _Kt>,
typename = std::__has_is_transparent_t<_Pred, _Kt>>
@@ -1481,7 +1481,7 @@ namespace __debug
return { { __res.first, this }, { __res.second, this } };
}
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt,
typename = std::__has_is_transparent_t<_Hash, _Kt>,
typename = std::__has_is_transparent_t<_Pred, _Kt>>
@@ -1587,7 +1587,7 @@ namespace __debug
return __next;
}
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
node_type
_M_extract(_Base_const_iterator __victim)
{
diff --git a/libstdc++-v3/include/debug/unordered_set b/libstdc++-v3/include/debug/unordered_set
index 932600d..7fc4146 100644
--- a/libstdc++-v3/include/debug/unordered_set
+++ b/libstdc++-v3/include/debug/unordered_set
@@ -448,7 +448,7 @@ namespace __debug
_M_check_rehashed(__bucket_count);
}
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
using node_type = typename _Base::node_type;
using insert_return_type = _Node_insert_return<iterator, node_type>;
@@ -519,7 +519,7 @@ namespace __debug
find(const key_type& __key)
{ return { _Base::find(__key), this }; }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt,
typename = std::__has_is_transparent_t<_Hash, _Kt>,
typename = std::__has_is_transparent_t<_Pred, _Kt>>
@@ -532,7 +532,7 @@ namespace __debug
find(const key_type& __key) const
{ return { _Base::find(__key), this }; }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt,
typename = std::__has_is_transparent_t<_Hash, _Kt>,
typename = std::__has_is_transparent_t<_Pred, _Kt>>
@@ -554,7 +554,7 @@ namespace __debug
return { { __res.first, this }, { __res.second, this } };
}
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt,
typename = std::__has_is_transparent_t<_Hash, _Kt>,
typename = std::__has_is_transparent_t<_Pred, _Kt>>
@@ -573,7 +573,7 @@ namespace __debug
return { { __res.first, this }, { __res.second, this } };
}
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt,
typename = std::__has_is_transparent_t<_Hash, _Kt>,
typename = std::__has_is_transparent_t<_Pred, _Kt>>
@@ -672,7 +672,7 @@ namespace __debug
return __next;
}
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
node_type
_M_extract(_Base_const_iterator __victim)
{
@@ -1183,7 +1183,7 @@ namespace __debug
_M_check_rehashed(__bucket_count);
}
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
using node_type = typename _Base::node_type;
node_type
@@ -1249,7 +1249,7 @@ namespace __debug
find(const key_type& __key)
{ return { _Base::find(__key), this }; }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt,
typename = std::__has_is_transparent_t<_Hash, _Kt>,
typename = std::__has_is_transparent_t<_Pred, _Kt>>
@@ -1262,7 +1262,7 @@ namespace __debug
find(const key_type& __key) const
{ return { _Base::find(__key), this }; }
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt,
typename = std::__has_is_transparent_t<_Hash, _Kt>,
typename = std::__has_is_transparent_t<_Pred, _Kt>>
@@ -1284,7 +1284,7 @@ namespace __debug
return { { __res.first, this }, { __res.second, this } };
}
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt,
typename = std::__has_is_transparent_t<_Hash, _Kt>,
typename = std::__has_is_transparent_t<_Pred, _Kt>>
@@ -1303,7 +1303,7 @@ namespace __debug
return { { __res.first, this }, { __res.second, this } };
}
-#if __cplusplus > 201703L
+#ifdef __glibcxx_generic_unordered_lookup // C++ >= 20 && HOSTED
template<typename _Kt,
typename = std::__has_is_transparent_t<_Hash, _Kt>,
typename = std::__has_is_transparent_t<_Pred, _Kt>>
@@ -1400,7 +1400,7 @@ namespace __debug
return __next;
}
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
node_type
_M_extract(_Base_const_iterator __victim)
{
diff --git a/libstdc++-v3/include/std/condition_variable b/libstdc++-v3/include/std/condition_variable
index 3525ff3..dcf0b92 100644
--- a/libstdc++-v3/include/std/condition_variable
+++ b/libstdc++-v3/include/std/condition_variable
@@ -193,15 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__wait_until_impl(unique_lock<mutex>& __lock,
const chrono::time_point<steady_clock, _Dur>& __atime)
{
- auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
- auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
-
- __gthread_time_t __ts =
- {
- static_cast<std::time_t>(__s.time_since_epoch().count()),
- static_cast<long>(__ns.count())
- };
-
+ __gthread_time_t __ts = chrono::__to_timeout_gthread_time_t(__atime);
_M_cond.wait_until(*__lock.mutex(), CLOCK_MONOTONIC, __ts);
return (steady_clock::now() < __atime
@@ -214,15 +206,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__wait_until_impl(unique_lock<mutex>& __lock,
const chrono::time_point<system_clock, _Dur>& __atime)
{
- auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
- auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
-
- __gthread_time_t __ts =
- {
- static_cast<std::time_t>(__s.time_since_epoch().count()),
- static_cast<long>(__ns.count())
- };
-
+ __gthread_time_t __ts = chrono::__to_timeout_gthread_time_t(__atime);
_M_cond.wait_until(*__lock.mutex(), __ts);
return (system_clock::now() < __atime
diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 281c038..1102ac8 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -105,6 +105,7 @@ namespace __format
template<typename _CharT> class _Sink;
template<typename _CharT> class _Fixedbuf_sink;
template<typename _Out, typename _CharT> class _Padding_sink;
+ template<typename _Out, typename _CharT> class _Escaping_sink;
// Output iterator that writes to a type-erase character sink.
template<typename _CharT>
@@ -1068,6 +1069,17 @@ namespace __format
template<typename _Out, typename _CharT>
_Out
+ __write_escape_seqs(_Out __out, basic_string_view<_CharT> __units)
+ {
+ using _UChar = make_unsigned_t<_CharT>;
+ for (_CharT __c : __units)
+ __out = __format::__write_escape_seq(
+ __out, static_cast<_UChar>(__c), _Escapes<_CharT>::_S_x());
+ return __out;
+ }
+
+ template<typename _Out, typename _CharT>
+ _Out
__write_escaped_char(_Out __out, _CharT __c)
{
using _UChar = make_unsigned_t<_CharT>;
@@ -1124,12 +1136,10 @@ namespace __format
template<typename _CharT, typename _Out>
_Out
- __write_escaped_unicode(_Out __out,
- basic_string_view<_CharT> __str,
- _Term_char __term)
+ __write_escaped_unicode_part(_Out __out, basic_string_view<_CharT>& __str,
+ bool& __prev_esc, _Term_char __term)
{
using _Str_view = basic_string_view<_CharT>;
- using _UChar = make_unsigned_t<_CharT>;
using _Esc = _Escapes<_CharT>;
static constexpr char32_t __replace = U'\uFFFD';
@@ -1143,10 +1153,10 @@ namespace __format
}();
__unicode::_Utf_view<char32_t, _Str_view> __v(std::move(__str));
+ __str = {};
+
auto __first = __v.begin();
auto const __last = __v.end();
-
- bool __prev_esc = true;
while (__first != __last)
{
bool __esc_ascii = false;
@@ -1185,15 +1195,32 @@ namespace __format
__out = __format::__write_escaped_char(__out, *__first.base());
else if (__esc_unicode)
__out = __format::__write_escape_seq(__out, *__first, _Esc::_S_u());
- else // __esc_replace
- for (_CharT __c : _Str_view(__first.base(), __first._M_units()))
- __out = __format::__write_escape_seq(__out,
- static_cast<_UChar>(__c),
- _Esc::_S_x());
+ // __esc_replace
+ else if (_Str_view __units(__first.base(), __first._M_units());
+ __units.end() != __last.base())
+ __out = __format::__write_escape_seqs(__out, __units);
+ else
+ {
+ __str = __units;
+ return __out;
+ }
+
__prev_esc = true;
++__first;
-
}
+
+ return __out;
+ }
+
+ template<typename _CharT, typename _Out>
+ _Out
+ __write_escaped_unicode(_Out __out, basic_string_view<_CharT> __str,
+ _Term_char __term)
+ {
+ bool __prev_escape = true;
+ __out = __format::__write_escaped_unicode_part(__out, __str,
+ __prev_escape, __term);
+ __out = __format::__write_escape_seqs(__out, __str);
return __out;
}
@@ -1399,7 +1426,6 @@ namespace __format
_M_format_range(_Rg&& __rg, basic_format_context<_Out, _CharT>& __fc) const
{
using _Range = remove_reference_t<_Rg>;
- using _String = basic_string<_CharT>;
using _String_view = basic_string_view<_CharT>;
if constexpr (!is_lvalue_reference_v<_Rg>)
return _M_format_range<_Range&>(__rg, __fc);
@@ -1412,55 +1438,28 @@ namespace __format
size_t(ranges::distance(__rg)));
return format(__str, __fc);
}
- else if (!_M_spec._M_debug)
+ else
{
+ auto __handle_debug = [this, &__rg]<typename _NOut>(_NOut __nout)
+ {
+ if (!_M_spec._M_debug)
+ return ranges::copy(__rg, std::move(__nout)).out;
+
+ _Escaping_sink<_NOut, _CharT>
+ __sink(std::move(__nout), _Term_quote);
+ ranges::copy(__rg, __sink.out());
+ return __sink._M_finish();
+ };
+
const size_t __padwidth = _M_spec._M_get_width(__fc);
if (__padwidth == 0 && _M_spec._M_prec_kind == _WP_none)
- return ranges::copy(__rg, __fc.out()).out;
+ return __handle_debug(__fc.out());
- _Padding_sink<_Out, _CharT> __sink(__fc.out(), __padwidth,
- _M_spec._M_get_precision(__fc));
- ranges::copy(__rg, __sink.out());
+ _Padding_sink<_Out, _CharT>
+ __sink(__fc.out(), __padwidth, _M_spec._M_get_precision(__fc));
+ __handle_debug(__sink.out());
return __sink._M_finish(_M_spec._M_align, _M_spec._M_fill);
}
- else if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>)
- {
- const size_t __n(ranges::distance(__rg));
- size_t __w = __n;
- if constexpr (!__unicode::__literal_encoding_is_unicode<_CharT>())
- if (size_t __max = _M_spec._M_get_precision(__fc); __n > __max)
- __w == __max;
-
- if (__w <= __format::__stackbuf_size<_CharT>)
- {
- _CharT __buf[__format::__stackbuf_size<_CharT>];
- ranges::copy_n(ranges::begin(__rg), __w, __buf);
- return _M_format_escaped(_String_view(__buf, __n), __fc);
- }
- else if constexpr (ranges::random_access_range<_Rg>)
- {
- ranges::iterator_t<_Rg> __first = ranges::begin(__rg);
- ranges::subrange __sub(__first, ranges::next(__first, __w));
- return _M_format_escaped(_String(from_range, __sub), __fc);
- }
- else if (__w <= __n)
- {
- ranges::subrange __sub(
- counted_iterator(ranges::begin(__rg), __w),
- default_sentinel);
- return _M_format_escaped(_String(from_range, __sub), __fc);
- }
- else if constexpr (ranges::sized_range<_Rg>)
- return _M_format_escaped(_String(from_range, __rg), __fc);
- else
- {
- // N.B. preserve the computed size
- ranges::subrange __sub(__rg, __n);
- return _M_format_escaped(_String(from_range, __sub), __fc);
- }
- }
- else
- return _M_format_escaped(_String(from_range, __rg), __fc);
}
constexpr void
@@ -3997,6 +3996,93 @@ namespace __format
}
};
+ template<typename _Out, typename _CharT>
+ class _Escaping_sink : public _Buf_sink<_CharT>
+ {
+ using _Esc = _Escapes<_CharT>;
+
+ _Out _M_out;
+ _Term_char _M_term : 2;
+ unsigned _M_prev_escape : 1;
+ unsigned _M_out_discards : 1;
+
+ void
+ _M_sync_discarding()
+ {
+ if constexpr (is_same_v<_Out, _Sink_iter<_CharT>>)
+ _M_out_discards = _M_out._M_discarding();
+ }
+
+ void
+ _M_write()
+ {
+ span<_CharT> __bytes = this->_M_used();
+ basic_string_view<_CharT> __str(__bytes.data(), __bytes.size());
+
+ size_t __rem = 0;
+ if constexpr (__unicode::__literal_encoding_is_unicode<_CharT>())
+ {
+ bool __prev_escape = _M_prev_escape;
+ _M_out = __format::__write_escaped_unicode_part(
+ std::move(_M_out), __str, __prev_escape, _M_term);
+ _M_prev_escape = __prev_escape;
+
+ __rem = __str.size();
+ if (__rem > 0 && __str.data() != this->_M_buf) [[unlikely]]
+ ranges::move(__str, this->_M_buf);
+ }
+ else
+ _M_out = __format::__write_escaped_ascii(
+ std::move(_M_out), __str, _M_term);
+
+ this->_M_reset(this->_M_buf, __rem);
+ _M_sync_discarding();
+ }
+
+ void
+ _M_overflow() override
+ {
+ if (_M_out_discards)
+ this->_M_rewind();
+ else
+ _M_write();
+ }
+
+ bool
+ _M_discarding() const override
+ { return _M_out_discards; }
+
+ public:
+ [[__gnu__::__always_inline__]]
+ explicit
+ _Escaping_sink(_Out __out, _Term_char __term)
+ : _M_out(std::move(__out)), _M_term(__term),
+ _M_prev_escape(true), _M_out_discards(false)
+ {
+ _M_out = __format::__write(std::move(_M_out), _Esc::_S_term(_M_term));
+ _M_sync_discarding();
+ }
+
+ _Out
+ _M_finish()
+ {
+ if (_M_out_discards)
+ return std::move(_M_out);
+
+ if (!this->_M_used().empty())
+ {
+ _M_write();
+ if constexpr (__unicode::__literal_encoding_is_unicode<_CharT>())
+ if (auto __rem = this->_M_used(); !__rem.empty())
+ {
+ basic_string_view<_CharT> __str(__rem.data(), __rem.size());
+ _M_out = __format::__write_escape_seqs(std::move(_M_out), __str);
+ }
+ }
+ return __format::__write(std::move(_M_out), _Esc::_S_term(_M_term));
+ }
+ };
+
enum class _Arg_t : unsigned char {
_Arg_none, _Arg_bool, _Arg_c, _Arg_i, _Arg_u, _Arg_ll, _Arg_ull,
_Arg_flt, _Arg_dbl, _Arg_ldbl, _Arg_str, _Arg_sv, _Arg_ptr, _Arg_handle,
diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
index 631c380..d4fc4c6 100644
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -179,14 +179,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_try_lock_until(const chrono::time_point<chrono::system_clock,
_Duration>& __atime)
{
- auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
- auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
-
- __gthread_time_t __ts = {
- static_cast<std::time_t>(__s.time_since_epoch().count()),
- static_cast<long>(__ns.count())
- };
-
+ __gthread_time_t __ts = chrono::__to_timeout_gthread_time_t(__atime);
return static_cast<_Derived*>(this)->_M_timedlock(__ts);
}
@@ -196,14 +189,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_try_lock_until(const chrono::time_point<chrono::steady_clock,
_Duration>& __atime)
{
- auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
- auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
-
- __gthread_time_t __ts = {
- static_cast<std::time_t>(__s.time_since_epoch().count()),
- static_cast<long>(__ns.count())
- };
-
+ __gthread_time_t __ts = chrono::__to_timeout_gthread_time_t(__atime);
return static_cast<_Derived*>(this)->_M_clocklock(CLOCK_MONOTONIC,
__ts);
}
diff --git a/libstdc++-v3/include/std/shared_mutex b/libstdc++-v3/include/std/shared_mutex
index 94c8532..a267ad7 100644
--- a/libstdc++-v3/include/std/shared_mutex
+++ b/libstdc++-v3/include/std/shared_mutex
@@ -520,15 +520,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
try_lock_until(const chrono::time_point<chrono::system_clock,
_Duration>& __atime)
{
- auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
- auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
-
- __gthread_time_t __ts =
- {
- static_cast<std::time_t>(__s.time_since_epoch().count()),
- static_cast<long>(__ns.count())
- };
-
+ struct timespec __ts = chrono::__to_timeout_timespec(__atime);
int __ret = __glibcxx_rwlock_timedwrlock(&_M_rwlock, &__ts);
// On self-deadlock, we just fail to acquire the lock. Technically,
// the program violated the precondition.
@@ -546,15 +538,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
try_lock_until(const chrono::time_point<chrono::steady_clock,
_Duration>& __atime)
{
- auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
- auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
-
- __gthread_time_t __ts =
- {
- static_cast<std::time_t>(__s.time_since_epoch().count()),
- static_cast<long>(__ns.count())
- };
-
+ struct timespec __ts = chrono::__to_timeout_timespec(__atime);
int __ret = pthread_rwlock_clockwrlock(&_M_rwlock, CLOCK_MONOTONIC,
&__ts);
// On self-deadlock, we just fail to acquire the lock. Technically,
@@ -596,14 +580,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
try_lock_shared_until(const chrono::time_point<chrono::system_clock,
_Duration>& __atime)
{
- auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
- auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
-
- __gthread_time_t __ts =
- {
- static_cast<std::time_t>(__s.time_since_epoch().count()),
- static_cast<long>(__ns.count())
- };
+ struct timespec __ts = chrono::__to_timeout_timespec(__atime);
int __ret;
// Unlike for lock(), we are not allowed to throw an exception so if
@@ -636,15 +613,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
try_lock_shared_until(const chrono::time_point<chrono::steady_clock,
_Duration>& __atime)
{
- auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
- auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
-
- __gthread_time_t __ts =
- {
- static_cast<std::time_t>(__s.time_since_epoch().count()),
- static_cast<long>(__ns.count())
- };
-
+ struct timespec __ts = chrono::__to_timeout_timespec(__atime);
int __ret = pthread_rwlock_clockrdlock(&_M_rwlock, CLOCK_MONOTONIC,
&__ts);
// On self-deadlock, we just fail to acquire the lock. Technically,
diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index e5336b7..1822d42 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -287,7 +287,11 @@ class SharedPointerPrinter(printer_base):
def _get_refcounts(self):
if self._typename == 'std::atomic':
# A tagged pointer is stored as uintptr_t.
- ptr_val = self._val['_M_refcount']['_M_val']['_M_i']
+ val = self._val['_M_refcount']['_M_val']
+ if val.type.is_scalar: # GCC 16 stores uintptr_t
+ ptr_val = val
+ else: # GCC 12-15 stores std::atomic<uintptr_t>
+ ptr_val = val['_M_i']
ptr_val = ptr_val - (ptr_val % 2) # clear lock bit
ptr_type = find_type(self._val['_M_refcount'].type, 'pointer')
return ptr_val.cast(ptr_type)
diff --git a/libstdc++-v3/src/c++11/thread.cc b/libstdc++-v3/src/c++11/thread.cc
index 6c2ec29..5cfe564 100644
--- a/libstdc++-v3/src/c++11/thread.cc
+++ b/libstdc++-v3/src/c++11/thread.cc
@@ -231,10 +231,30 @@ namespace std _GLIBCXX_VISIBILITY(default)
_GLIBCXX_BEGIN_NAMESPACE_VERSION
namespace this_thread
{
+namespace
+{
+ // returns min(s, Dur::max())
+ template<typename Dur>
+ inline chrono::seconds
+ limit(chrono::seconds s)
+ {
+ static_assert(ratio_equal<typename Dur::period, ratio<1>>::value,
+ "period must be seconds to avoid potential overflow");
+
+ if (s > Dur::max()) [[__unlikely__]]
+ s = chrono::duration_cast<chrono::seconds>(Dur::max());
+ return s;
+ }
+}
+
void
__sleep_for(chrono::seconds __s, chrono::nanoseconds __ns)
{
#ifdef _GLIBCXX_USE_NANOSLEEP
+#pragma GCC diagnostic ignored "-Wc++17-extensions"
+ if constexpr (is_integral<time_t>::value) // POSIX.1-2001 allows floating
+ __s = limit<chrono::duration<time_t>>(__s);
+
struct ::timespec __ts =
{
static_cast<std::time_t>(__s.count()),
@@ -246,6 +266,8 @@ namespace this_thread
const auto target = chrono::steady_clock::now() + __s + __ns;
while (true)
{
+ __s = limit<chrono::duration<unsigned>>(__s);
+
unsigned secs = __s.count();
if (__ns.count() > 0)
{
@@ -271,12 +293,28 @@ namespace this_thread
break;
__s = chrono::duration_cast<chrono::seconds>(target - now);
__ns = chrono::duration_cast<chrono::nanoseconds>(target - (now + __s));
- }
+ }
#elif defined(_GLIBCXX_USE_WIN32_SLEEP)
- unsigned long ms = __ns.count() / 1000000;
- if (__ns.count() > 0 && ms == 0)
- ms = 1;
- ::Sleep(chrono::milliseconds(__s).count() + ms);
+
+ // Can't use limit<chrono::milliseconds>(__s) here because it would
+ // multiply __s by 1000 which could overflow.
+ // Limit to milliseconds::max() and truncate to seconds:
+ chrono::milliseconds ms = chrono::milliseconds::max();
+ if (__s < chrono::duration_cast<chrono::seconds>(ms))
+ {
+ ms = __s;
+ ms += chrono::__detail::ceil<chrono::milliseconds>(__ns);
+ }
+
+ // Use Sleep(DWORD millis) where DWORD is uint32_t.
+ constexpr chrono::milliseconds max_sleep(INFINITE - 1u);
+ while (ms > max_sleep)
+ {
+ ::Sleep(max_sleep.count());
+ ms -= max_sleep;
+ }
+
+ ::Sleep(ms.count());
#endif
}
}
diff --git a/libstdc++-v3/src/c++17/fs_path.cc b/libstdc++-v3/src/c++17/fs_path.cc
index 215afa0..03bb5ec 100644
--- a/libstdc++-v3/src/c++17/fs_path.cc
+++ b/libstdc++-v3/src/c++17/fs_path.cc
@@ -34,6 +34,7 @@
#include <filesystem>
#include <algorithm>
#include <array>
+#include <new>
#include <bits/stl_uninitialized.h>
#include <ext/numeric_traits.h> // __gnu_cxx::__int_traits
@@ -207,6 +208,10 @@ struct path::_List::_Impl
_Impl(int cap) : _M_size(0), _M_capacity(cap) { }
+ ~_Impl() { clear(); }
+
+ // Align the first member like the value_type so that we can store one or
+ // more objects of that type immediately after the memory occupied by *this.
alignas(value_type) int _M_size;
int _M_capacity;
@@ -246,29 +251,67 @@ struct path::_List::_Impl
unique_ptr<_Impl, _Impl_deleter> copy() const
{
const auto n = size();
- void* p = ::operator new(sizeof(_Impl) + n * sizeof(value_type));
- unique_ptr<_Impl, _Impl_deleter> newptr(::new (p) _Impl{n});
+ // *this already has n elements so don't need to check if n overflows:
+ auto newptr = create_unchecked(n);
std::uninitialized_copy_n(begin(), n, newptr->begin());
newptr->_M_size = n;
return newptr;
}
+ // We use the two least significant bits to store a _Type value so
+ // require memory aligned to at least 4 bytes:
+ static_assert(__STDCPP_DEFAULT_NEW_ALIGNMENT__ >= 4);
+ // Require memory suitably aligned for an _Impl and its value types:
+ static_assert(__STDCPP_DEFAULT_NEW_ALIGNMENT__ >= alignof(value_type));
+
// Clear the lowest two bits from the pointer (i.e. remove the _Type value)
static _Impl* notype(_Impl* p)
{
constexpr uintptr_t mask = ~(uintptr_t)0x3;
return reinterpret_cast<_Impl*>(reinterpret_cast<uintptr_t>(p) & mask);
}
+
+ // Create a new _Impl with capacity for n components.
+ static unique_ptr<_Impl, _Impl_deleter>
+ create(int n)
+ {
+ using __gnu_cxx::__int_traits;
+ // Nobody should need paths with this many components.
+ if (n >= __int_traits<int>::__max / 4)
+ std::__throw_bad_alloc();
+
+ if constexpr (__int_traits<int>::__max >= __int_traits<size_t>::__max)
+ {
+ // Check that the calculation in create_unchecked(n) won't overflow.
+ size_t bytes;
+ if (__builtin_mul_overflow(n, sizeof(value_type), &bytes)
+ || __builtin_add_overflow(sizeof(_Impl), bytes, &bytes))
+ std::__throw_bad_alloc();
+ }
+ // Otherwise, it can't overflow, even for 20-bit size_t on msp430.
+
+ return create_unchecked(n);
+ }
+
+ // pre: no overflow in Si + n * Sv
+ static unique_ptr<_Impl, _Impl_deleter>
+ create_unchecked(int n)
+ {
+ void* p = ::operator new(sizeof(_Impl) + n * sizeof(value_type));
+ return std::unique_ptr<_Impl, _Impl_deleter>(::new(p) _Impl{n});
+ }
};
-void path::_List::_Impl_deleter::operator()(_Impl* p) const noexcept
+// Destroy and deallocate an _Impl.
+void
+path::_List::_Impl_deleter::operator()(_Impl* p) const noexcept
{
p = _Impl::notype(p);
if (p)
{
- __glibcxx_assert(p->_M_size <= p->_M_capacity);
- p->clear();
- ::operator delete(p, sizeof(*p) + p->_M_capacity * sizeof(value_type));
+ const auto n = p->_M_capacity;
+ p->~_Impl();
+ ::operator delete(p, sizeof(_Impl) + n * sizeof(_Impl::value_type));
}
}
@@ -455,24 +498,7 @@ path::_List::reserve(int newcap, bool exact = false)
newcap = nextcap;
}
- using __gnu_cxx::__int_traits;
- // Nobody should need paths with this many components.
- if (newcap >= __int_traits<int>::__max / 4)
- std::__throw_bad_alloc();
-
- size_t bytes;
- if constexpr (__int_traits<int>::__max >= __int_traits<size_t>::__max)
- {
- size_t components;
- if (__builtin_mul_overflow(newcap, sizeof(value_type), &components)
- || __builtin_add_overflow(sizeof(_Impl), components, &bytes))
- std::__throw_bad_alloc();
- }
- else // This won't overflow, even for 20-bit size_t on msp430.
- bytes = sizeof(_Impl) + newcap * sizeof(value_type);
-
- void* p = ::operator new(bytes);
- std::unique_ptr<_Impl, _Impl_deleter> newptr(::new(p) _Impl{newcap});
+ auto newptr = _Impl::create(newcap);
const int cursize = curptr ? curptr->size() : 0;
if (cursize)
{
diff --git a/libstdc++-v3/src/c++20/atomic.cc b/libstdc++-v3/src/c++20/atomic.cc
index 4120e1a..7978809 100644
--- a/libstdc++-v3/src/c++20/atomic.cc
+++ b/libstdc++-v3/src/c++20/atomic.cc
@@ -350,14 +350,7 @@ __platform_wait_until(const __platform_wait_t* __addr,
__platform_wait_t __old,
const __wait_clock_t::time_point& __atime) noexcept
{
- auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
- auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
-
- struct timespec __rt =
- {
- static_cast<std::time_t>(__s.time_since_epoch().count()),
- static_cast<long>(__ns.count())
- };
+ struct timespec __rt = chrono::__to_timeout_timespec(__atime);
if (syscall (SYS_futex, __addr,
static_cast<int>(__futex_wait_flags::__wait_bitset_private),
@@ -378,14 +371,7 @@ bool
__cond_wait_until(__condvar& __cv, mutex& __mx,
const __wait_clock_t::time_point& __atime)
{
- auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
- auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
-
- __gthread_time_t __ts =
- {
- static_cast<std::time_t>(__s.time_since_epoch().count()),
- static_cast<long>(__ns.count())
- };
+ __gthread_time_t __ts = chrono::__to_timeout_gthread_time_t(__atime);
#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
if constexpr (is_same_v<chrono::steady_clock, __wait_clock_t>)
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/pr118757.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/pr118757.cc
new file mode 100644
index 0000000..d54abd8
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/pr118757.cc
@@ -0,0 +1,29 @@
+// { dg-do run { target c++20 } }
+// { dg-require-gthreads "" }
+// { dg-require-effective-target hosted }
+
+#include <memory>
+#include <chrono>
+#include <thread>
+#include <barrier>
+
+std::shared_ptr<int> q = std::make_shared<int>(42);
+std::atomic<std::shared_ptr<int>> p = q;
+
+std::barrier bar(2);
+
+void signaller()
+{
+ std::this_thread::sleep_for(std::chrono::seconds(1));
+ p.store(std::shared_ptr<int>(q, nullptr));
+ p.notify_one();
+ bar.arrive_and_wait();
+}
+
+int main(int, char**)
+{
+ std::thread thr(signaller);
+ p.wait(q);
+ bar.arrive_and_wait();
+ thr.join();
+}
diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/pr118757.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/pr118757.cc
new file mode 100644
index 0000000..f048f13
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/weak_ptr/pr118757.cc
@@ -0,0 +1,30 @@
+// { dg-do run { target c++20 } }
+// { dg-require-gthreads "" }
+// { dg-require-effective-target hosted }
+
+#include <memory>
+#include <chrono>
+#include <thread>
+#include <barrier>
+
+std::shared_ptr<int> s = std::make_shared<int>(42);
+std::weak_ptr<int> q = s;
+std::atomic<std::weak_ptr<int>> p = q;
+
+std::barrier bar(2);
+
+void signaller()
+{
+ std::this_thread::sleep_for(std::chrono::seconds(1));
+ p.store(std::shared_ptr<int>(s, nullptr));
+ p.notify_one();
+ bar.arrive_and_wait();
+}
+
+int main(int, char**)
+{
+ std::thread thr(signaller);
+ p.wait(q);
+ bar.arrive_and_wait();
+ thr.join();
+}
diff --git a/libstdc++-v3/testsuite/30_threads/condition_variable/members/116586.cc b/libstdc++-v3/testsuite/30_threads/condition_variable/members/116586.cc
new file mode 100644
index 0000000..7114007
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/condition_variable/members/116586.cc
@@ -0,0 +1,60 @@
+// { dg-do run { target c++11 } }
+
+#include <condition_variable>
+#include <chrono>
+#include <mutex>
+#include <initializer_list>
+#include <testsuite_hooks.h>
+
+namespace chrono = std::chrono;
+
+// thread.timedmutex.requirements.general:
+// If abs_time has already passed, the function attempts to obtain
+// ownership without blocking (as if by calling try_lock()).
+
+template <typename Clock>
+void
+test_absolute(chrono::nanoseconds offset)
+{
+ std::mutex mtx;
+ std::condition_variable cv;
+ chrono::time_point<Clock> tp(offset);
+ std::unique_lock<std::mutex> lock(mtx);
+ // Doesn't cope with spurious wakeup
+ VERIFY(cv.wait_until(lock, tp) == std::cv_status::timeout);
+}
+
+// The type of clock used for the actual wait depends on whether
+// _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK is defined. We might as well just test
+// both steady_clock and system_clock.
+template <typename Clock>
+void
+test_relative(chrono::nanoseconds offset)
+{
+ std::mutex mtx;
+ std::condition_variable cv;
+ const auto d = -Clock::now().time_since_epoch() + offset;
+ std::unique_lock<std::mutex> lock(mtx);
+ // Doesn't cope with spurious wakeup
+ VERIFY(cv.wait_for(lock, d) == std::cv_status::timeout);
+}
+
+int main()
+{
+ // It's not really possible to arrange for the relative calls to have
+ // tv_nsec == 0 due to time advancing.
+ for (const chrono::nanoseconds offset : {
+ // tv_sec == 0, tv_nsec == 0
+ chrono::nanoseconds{0},
+ // tv_sec == 0, tv_nsec < 0
+ chrono::duration_cast<chrono::nanoseconds>(chrono::milliseconds{-10}),
+ // tv_sec < 0
+ chrono::duration_cast<chrono::nanoseconds>(chrono::seconds{-10})
+ }) {
+ test_absolute<chrono::system_clock>(offset);
+ test_relative<chrono::system_clock>(offset);
+
+ test_absolute<chrono::steady_clock>(offset);
+ test_relative<chrono::steady_clock>(offset);
+ }
+}
diff --git a/libstdc++-v3/testsuite/30_threads/future/members/116586.cc b/libstdc++-v3/testsuite/30_threads/future/members/116586.cc
new file mode 100644
index 0000000..b7cd12c
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/future/members/116586.cc
@@ -0,0 +1,55 @@
+// { dg-do run { target c++11 } }
+
+#include <future>
+#include <chrono>
+#include <initializer_list>
+#include <testsuite_hooks.h>
+
+namespace chrono = std::chrono;
+
+// thread.timedmutex.requirements.general:
+// If abs_time has already passed, the function attempts to obtain
+// ownership without blocking (as if by calling try_lock()).
+
+template <typename Clock>
+void
+test_absolute(chrono::nanoseconds offset)
+{
+ std::promise<int> p;
+ std::future<int> f = p.get_future();
+ const chrono::time_point<Clock> tp(offset);
+ VERIFY(f.wait_until(tp) == std::future_status::timeout);
+}
+
+// The type of clock used for the actual wait depends on whether
+// _GLIBCXX_HAVE_LINUX_FUTEX is defined. We might as well just test both
+// steady_clock and system_clock.
+template <typename Clock>
+void
+test_relative(chrono::nanoseconds offset)
+{
+ std::promise<int> p;
+ std::future<int> f = p.get_future();
+ const auto d = -Clock::now().time_since_epoch() + offset;
+ VERIFY(f.wait_for(d) == std::future_status::timeout);
+}
+
+int main()
+{
+ // It's not really possible to arrange for the relative calls to have tv_nsec
+ // == 0 due to time advancing.
+ for (const chrono::nanoseconds offset : {
+ // tv_sec == 0, tv_nsec == 0
+ chrono::nanoseconds{0},
+ // tv_sec == 0, tv_nsec < 0
+ chrono::duration_cast<chrono::nanoseconds>(chrono::milliseconds{-10}),
+ // tv_sec < 0
+ chrono::duration_cast<chrono::nanoseconds>(chrono::seconds{-10})
+ }) {
+ test_absolute<chrono::system_clock>(offset);
+ test_relative<chrono::system_clock>(offset);
+
+ test_absolute<chrono::steady_clock>(offset);
+ test_relative<chrono::steady_clock>(offset);
+ }
+}
diff --git a/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/116586.cc b/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/116586.cc
new file mode 100644
index 0000000..941f3af
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/116586.cc
@@ -0,0 +1,72 @@
+// { dg-do run { target c++11 } }
+
+#include <mutex>
+#include <chrono>
+#include <future>
+#include <initializer_list>
+#include <testsuite_hooks.h>
+
+namespace chrono = std::chrono;
+
+// thread.timedmutex.requirements.general:
+// If abs_time has already passed, the function attempts to obtain
+// ownership without blocking (as if by calling try_lock()).
+
+template <typename Clock>
+void
+test_absolute(chrono::nanoseconds offset)
+{
+ std::recursive_timed_mutex mtx;
+ chrono::time_point<Clock> tp(offset);
+ VERIFY(mtx.try_lock_until(tp));
+
+ {
+ // To test failing to lock a recursive mutex we need to try to lock on a
+ // different thread.
+ auto t = std::async(std::launch::async, [&mtx, tp]() {
+ VERIFY(!mtx.try_lock_until(tp));
+ });
+ }
+}
+
+// The type of clock used for the actual wait depends on whether
+// _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK is defined. We might as well just test
+// both steady_clock and system_clock.
+template <typename Clock>
+void
+test_relative(chrono::nanoseconds offset)
+{
+ std::recursive_timed_mutex mtx;
+ const auto d = -Clock::now().time_since_epoch() + offset;
+ VERIFY(mtx.try_lock_for(d));
+
+ {
+ // To test failing to lock a recursive mutex we need to try to lock on a
+ // different thread.
+ auto t = std::async(std::launch::async, [&mtx, d]() {
+ VERIFY(!mtx.try_lock_for(d));
+ });
+ }
+}
+
+int main()
+{
+ // Try once with an offset that ought to result in tv_sec == 0, tv_nsec < 0
+ // and one with an offset that ought to result in tv_sec < 0, tv_nsec == 0
+ // for the absolute calls at least. It's not really possible to arrange for
+ // the relative calls to have tv_nsec == 0 due to time advancing.
+ for (const chrono::nanoseconds offset : {
+ // tv_sec == 0, tv_nsec == 0
+ chrono::nanoseconds{0},
+ // tv_sec == 0, tv_nsec < 0
+ chrono::duration_cast<chrono::nanoseconds>(chrono::milliseconds{-10}),
+ // tv_sec < 0
+ chrono::duration_cast<chrono::nanoseconds>(chrono::seconds{-10})
+ }) {
+ test_absolute<chrono::system_clock>(offset);
+ test_relative<chrono::system_clock>(offset);
+
+ test_absolute<chrono::steady_clock>(offset);
+ test_relative<chrono::steady_clock>(offset);
+ }
+}
diff --git a/libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_for.cc b/libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_for.cc
index 39681c7..94acb25 100644
--- a/libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_for.cc
+++ b/libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_for.cc
@@ -24,6 +24,7 @@
#include <chrono>
#include <thread>
#include <atomic>
+#include <initializer_list>
#include <testsuite_hooks.h>
void test01()
@@ -90,9 +91,30 @@ test03()
s.try_acquire_for(timeout);
}
+// Prove semaphore doesn't suffer from PR116586
+template <typename Clock>
+void
+test_relative(std::chrono::nanoseconds offset)
+{
+ std::binary_semaphore sem(1);
+ VERIFY(sem.try_acquire_for(offset));
+ VERIFY(!sem.try_acquire_for(offset));
+}
+
int main()
{
test01();
test02();
test03();
+ using namespace std::chrono;
+ for (const nanoseconds offset : {
+ nanoseconds{0},
+ nanoseconds{-10ms},
+ nanoseconds{-10s}
+ }) {
+ test_relative<std::chrono::system_clock>(offset);
+ test_relative<std::chrono::system_clock>(offset - std::chrono::system_clock::now().time_since_epoch());
+ test_relative<std::chrono::steady_clock>(offset);
+ test_relative<std::chrono::steady_clock>(offset - std::chrono::steady_clock::now().time_since_epoch());
+ }
}
diff --git a/libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_until.cc b/libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_until.cc
index de0068d..ed6bd11 100644
--- a/libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_until.cc
+++ b/libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_until.cc
@@ -24,6 +24,7 @@
#include <chrono>
#include <thread>
#include <atomic>
+#include <initializer_list>
#include <testsuite_hooks.h>
void test01()
@@ -87,8 +88,31 @@ void test02()
b.wait(1);
}
+// Prove semaphore doesn't suffer from PR116586
+template <typename Clock>
+void
+test_absolute(std::chrono::nanoseconds offset)
+{
+ std::binary_semaphore sem(1);
+ std::chrono::time_point<Clock> tp(offset);
+ VERIFY(sem.try_acquire_until(tp));
+ VERIFY(!sem.try_acquire_until(tp));
+}
+
int main()
{
test01();
test02();
+ using namespace std::chrono;
+ for (const nanoseconds offset : {
+ // tv_sec == 0, tv_nsec == 0
+ nanoseconds{0},
+ // tv_sec == 0, tv_nsec < 0
+ nanoseconds{-10ms},
+ // tv_sec < 0
+ nanoseconds{-10s}
+ }) {
+ test_absolute<std::chrono::system_clock>(offset);
+ test_absolute<std::chrono::steady_clock>(offset);
+ }
}
diff --git a/libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock_until/116586.cc b/libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock_until/116586.cc
new file mode 100644
index 0000000..cebbb3a
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock_until/116586.cc
@@ -0,0 +1,97 @@
+// { dg-do run { target c++14 } }
+
+#include <shared_mutex>
+#include <chrono>
+#include <future>
+#include <initializer_list>
+#include <testsuite_hooks.h>
+
+namespace chrono = std::chrono;
+
+// thread.timedmutex.requirements.general:
+// If abs_time has already passed, the function attempts to obtain
+// ownership without blocking (as if by calling try_lock()).
+
+template <typename Clock>
+void
+test_exclusive_absolute(chrono::nanoseconds offset)
+{
+ std::shared_timed_mutex stm;
+ chrono::time_point<Clock> tp(offset);
+ VERIFY(stm.try_lock_until(tp));
+ VERIFY(!stm.try_lock_until(tp));
+}
+
+template <typename Clock>
+void
+test_shared_absolute(chrono::nanoseconds offset)
+{
+ std::shared_timed_mutex stm;
+ chrono::time_point<Clock> tp(offset);
+ VERIFY(stm.try_lock_shared_until(tp));
+ stm.unlock_shared();
+
+ VERIFY(stm.try_lock_for(chrono::seconds{10}));
+
+ {
+ // NPTL will give us EDEADLK if pthread_rwlock_timedrdlock() is called on
+ // the same thread that already holds the exclusive (write) lock, so let's
+ // arrange for a different thread to try to acquire the shared lock.
+ auto t = std::async(std::launch::async, [&stm, tp]() {
+ VERIFY(!stm.try_lock_shared_until(tp));
+ });
+ }
+}
+
+// The type of clock used for the actual wait depends on whether
+// _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK is defined. We might as well just test
+// both steady_clock and system_clock.
+template <typename Clock>
+void
+test_exclusive_relative(chrono::nanoseconds offset)
+{
+ std::shared_timed_mutex stm;
+ const auto d = -Clock::now().time_since_epoch() + offset;
+ VERIFY(stm.try_lock_for(d));
+ VERIFY(!stm.try_lock_for(d));
+}
+
+template <typename Clock>
+void
+test_shared_relative(chrono::nanoseconds offset)
+{
+ std::shared_timed_mutex stm;
+ const auto d = -Clock::now().time_since_epoch() + offset;
+ VERIFY(stm.try_lock_shared_for(d));
+ stm.unlock_shared();
+ // Should complete immediately
+ VERIFY(stm.try_lock_for(chrono::seconds{10}));
+ VERIFY(!stm.try_lock_shared_for(d));
+}
+
+int main()
+{
+ // Try once with an offset that ought to result in tv_sec == 0, tv_nsec < 0
+ // and one with an offset that ought to result in tv_sec < 0, tv_nsec == 0
+ // for the absolute calls at least. It's not really possible to arrange for
+ // the relative calls to have tv_nsec == 0 due to time advancing.
+ using namespace std::chrono_literals;
+ for (const chrono::nanoseconds offset : {
+ // tv_sec == 0, tv_nsec == 0
+ chrono::nanoseconds{0},
+ // tv_sec == 0, tv_nsec < 0
+ chrono::nanoseconds{-10ms},
+ // tv_sec < 0
+ chrono::nanoseconds{-10s}
+ }) {
+ test_exclusive_absolute<chrono::system_clock>(offset);
+ test_shared_absolute<chrono::system_clock>(offset);
+ test_exclusive_relative<chrono::system_clock>(offset);
+ test_shared_relative<chrono::system_clock>(offset);
+
+ test_exclusive_absolute<chrono::steady_clock>(offset);
+ test_shared_absolute<chrono::steady_clock>(offset);
+ test_exclusive_relative<chrono::steady_clock>(offset);
+ test_shared_relative<chrono::steady_clock>(offset);
+ }
+}
diff --git a/libstdc++-v3/testsuite/30_threads/this_thread/113327.cc b/libstdc++-v3/testsuite/30_threads/this_thread/113327.cc
new file mode 100644
index 0000000..2daa2b0
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/this_thread/113327.cc
@@ -0,0 +1,29 @@
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-pthread" { target pthread } }
+// { dg-require-gthreads "" }
+
+// PR libstdc++/113327
+// std::sleep_for(std::chrono::hours::max()) returns immediately
+
+#include <thread>
+#include <chrono>
+#include <cstdlib>
+#include <csignal>
+
+int main()
+{
+ std::thread sleepy([] {
+ // Rather than overflowing to a negative value, the timeout should be
+ // truncated to seconds::max() and so sleep for 292 billion years.
+ std::this_thread::sleep_for(std::chrono::minutes::max());
+ // This should not happen:
+ throw 1;
+ });
+ // Give the new thread a chance to start sleeping:
+ std::this_thread::yield();
+ std::this_thread::sleep_for(std::chrono::seconds(2));
+ // If we get here without the other thread throwing an exception
+ // then it should be sleeping peacefully, so the test passed.
+ // pthread_kill(sleepy.native_handle(), SIGINT);
+ std::_Exit(0);
+}
diff --git a/libstdc++-v3/testsuite/30_threads/this_thread/sleep_for.cc b/libstdc++-v3/testsuite/30_threads/this_thread/sleep_for.cc
index 3f55ccc..5b0518d 100644
--- a/libstdc++-v3/testsuite/30_threads/this_thread/sleep_for.cc
+++ b/libstdc++-v3/testsuite/30_threads/this_thread/sleep_for.cc
@@ -37,7 +37,20 @@ test01()
VERIFY( (chr::system_clock::now() - begin) >= ms );
}
+void
+test_negative()
+{
+ chr::system_clock::time_point begin = chr::system_clock::now();
+
+ std::this_thread::sleep_for(-chr::hours(8));
+
+ // That should have completed immediately, but be generous because we don't
+ // want spurious failures on busy machines.
+ VERIFY( (chr::system_clock::now() - begin) < chr::seconds(10) );
+}
+
int main()
{
test01();
+ test_negative();
}
diff --git a/libstdc++-v3/testsuite/30_threads/this_thread/sleep_until.cc b/libstdc++-v3/testsuite/30_threads/this_thread/sleep_until.cc
index 1fb82b6..8c70c2e 100644
--- a/libstdc++-v3/testsuite/30_threads/this_thread/sleep_until.cc
+++ b/libstdc++-v3/testsuite/30_threads/this_thread/sleep_until.cc
@@ -26,18 +26,36 @@
namespace chr = std::chrono;
+template <typename Clock>
void
test01()
{
- chr::system_clock::time_point begin = chr::system_clock::now();
+ typename Clock::time_point begin = Clock::now();
chr::microseconds ms(500);
- std::this_thread::sleep_until(chr::system_clock::now() + ms);
+ std::this_thread::sleep_until(Clock::now() + ms);
- VERIFY( (chr::system_clock::now() - begin) >= ms );
+ VERIFY( (Clock::now() - begin) >= ms );
+}
+
+template <typename Clock>
+void
+test_negative()
+{
+ typename Clock::time_point begin = Clock::now();
+
+ typename Clock::time_point tp(-chr::hours(8));
+ std::this_thread::sleep_until(tp);
+
+ // That should have completed immediately, but be generous because we don't
+ // want spurious failures on busy machines.
+ VERIFY( (Clock::now() - begin) < chr::seconds(10) );
}
int main()
{
- test01();
+ test01<chr::steady_clock>();
+ test01<chr::system_clock>();
+ test_negative<chr::steady_clock>();
+ test_negative<chr::system_clock>();
}
diff --git a/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/116586.cc b/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/116586.cc
new file mode 100644
index 0000000..dcba7aa
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/116586.cc
@@ -0,0 +1,57 @@
+// { dg-do run { target c++11 } }
+
+#include <chrono>
+#include <mutex>
+#include <initializer_list>
+#include <testsuite_hooks.h>
+
+namespace chrono = std::chrono;
+
+// thread.timedmutex.requirements.general:
+// If abs_time has already passed, the function attempts to obtain
+// ownership without blocking (as if by calling try_lock()).
+
+template <typename Clock>
+void
+test_absolute(chrono::nanoseconds offset)
+{
+ std::timed_mutex mtx;
+ chrono::time_point<Clock> tp(offset);
+ VERIFY(mtx.try_lock_until(tp));
+ VERIFY(!mtx.try_lock_until(tp));
+}
+
+// The type of clock used for the actual wait depends on whether
+// _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK is defined. We might as well just test
+// both steady_clock and system_clock.
+template <typename Clock>
+void
+test_relative(chrono::nanoseconds offset)
+{
+ std::timed_mutex mtx;
+ const auto d = -Clock::now().time_since_epoch() + offset;
+ VERIFY(mtx.try_lock_for(d));
+ VERIFY(!mtx.try_lock_for(d));
+}
+
+int main()
+{
+ // Try once with an offset that ought to result in tv_sec == 0, tv_nsec < 0
+ // and one with an offset that ought to result in tv_sec < 0, tv_nsec == 0
+ // for the absolute calls at least. It's not really possible to arrange for
+ // the relative calls to have tv_nsec == 0 due to time advancing.
+ for (const chrono::nanoseconds offset : {
+ // tv_sec == 0, tv_nsec == 0
+ chrono::nanoseconds{0},
+ // tv_sec == 0, tv_nsec < 0
+ chrono::duration_cast<chrono::nanoseconds>(chrono::milliseconds{-10}),
+ // tv_sec < 0
+ chrono::duration_cast<chrono::nanoseconds>(chrono::seconds{-10})
+ }) {
+ test_absolute<chrono::system_clock>(offset);
+ test_relative<chrono::system_clock>(offset);
+
+ test_absolute<chrono::steady_clock>(offset);
+ test_relative<chrono::steady_clock>(offset);
+ }
+}
diff --git a/libstdc++-v3/testsuite/std/format/ranges/string.cc b/libstdc++-v3/testsuite/std/format/ranges/string.cc
index 99e5eaf..bef2cc7 100644
--- a/libstdc++-v3/testsuite/std/format/ranges/string.cc
+++ b/libstdc++-v3/testsuite/std/format/ranges/string.cc
@@ -279,6 +279,93 @@ void test_padding()
VERIFY( strip_prefix(resv, 46, '*') );
VERIFY( strip_quotes(resv) );
VERIFY( resv == in );
+
+ // width is 5, size is 15
+ in = "\u2160\u2161\u2162\u2163\u2164";
+ in += in; // width is 10, size is 30
+ in += in; // width is 20, size is 60
+ in += in; // width is 40, size is 120
+ in += in; // width is 80, size is 240
+ in += in; // width is 160, size is 480
+
+ lc.assign_range(in);
+
+ resv = res = std::format("{:s}", lc);
+ VERIFY( resv == in );
+
+ resv = res = std::format("{:*>10s}", lc);
+ VERIFY( resv == in );
+
+ resv = res = std::format("{:*>200s}", lc);
+ VERIFY( strip_prefix(resv, 40, '*') );
+ VERIFY( resv == in );
+
+ resv = res = std::format("{:?s}", lc);
+ VERIFY( strip_quotes(resv) );
+ VERIFY( resv == in );
+
+ resv = res = std::format("{:*>10?s}", lc);
+ VERIFY( strip_quotes(resv) );
+ VERIFY( resv == in );
+
+ resv = res = std::format("{:*>200?s}", lc);
+ VERIFY( strip_prefix(resv, 38, '*') );
+ VERIFY( strip_quotes(resv) );
+ VERIFY( resv == in );
+}
+
+void test_escaping()
+{
+ std::string res;
+ std::string_view resv;
+
+ const std::string_view input =
+ "\t\n\r\\\""
+ "\u008a" // Cc, Control, Line Tabulation Set,
+ "\u00ad" // Cf, Format, Soft Hyphen
+ "\u1d3d" // Lm, Modifier letter, Modifier Letter Capital Ou
+ "\u00a0" // Zs, Space Separator, No-Break Space (NBSP)
+ "\u2029" // Zp, Paragraph Separator, Paragraph Separator
+ "\U0001f984" // So, Other Symbol, Unicorn Face
+ ;
+ const std::string_view output =
+ R"(\t\n\r\\\")"
+ R"(\u{8a})"
+ R"(\u{ad})"
+ "\u1d3d"
+ R"(\u{a0})"
+ R"(\u{2029})"
+ "\U0001f984";
+
+ std::forward_list<char> lc(std::from_range, input);
+ resv = res = std::format("{:s}", lc);
+ VERIFY( resv == input );
+ resv = res = std::format("{:?s}", lc);
+ VERIFY( strip_quotes(resv) );
+ VERIFY( resv == output );
+
+ // width is 5, size is 15
+ std::string in = "\u2160\u2161\u2162\u2163\u2164";
+ in += in; // width is 10, size is 30
+ in += in; // width is 20, size is 60
+ in += in; // width is 40, size is 120
+ in += in; // width is 80, size is 240
+ in += in; // width is 160, size is 480
+ std::string_view inv = in;
+
+ // last charcter is incomplete
+ lc.assign_range(inv.substr(0, 479));
+
+ // non-debug format, chars copied as is
+ resv = res = std::format("{:s}", lc);
+ VERIFY( resv == inv.substr(0, 479) );
+
+ // debug-format, incomplete code-point sequence is esaped
+ resv = res = std::format("{:?s}", lc);
+ VERIFY( strip_quotes(resv) );
+ VERIFY( resv.substr(0, 477) == inv.substr(0, 477) );
+ resv.remove_prefix(477);
+ VERIFY( resv == R"(\x{e2}\x{85})" );
}
int main()
@@ -287,4 +374,6 @@ int main()
test_outputs<char>();
test_outputs<wchar_t>();
test_nested();
+ test_padding();
+ test_escaping();
}
diff --git a/libstdc++-v3/testsuite/std/time/month_day/io.cc b/libstdc++-v3/testsuite/std/time/month_day/io.cc
index 30aa588..c3ae180 100644
--- a/libstdc++-v3/testsuite/std/time/month_day/io.cc
+++ b/libstdc++-v3/testsuite/std/time/month_day/io.cc
@@ -23,6 +23,45 @@ test_ostream()
}
void
+test_format()
+{
+ using namespace std::chrono;
+ std::locale loc_fr(ISO_8859(15,fr_FR));
+
+ auto s = std::format("{:%b%%%B%t%m%n %d%%%e}", month(1)/day(3));
+ VERIFY( s == "Jan%January\t01\n 03% 3" );
+ s = std::format(loc_fr, "{:L%b%%%B%t%m%n %d%%%e}", month(1)/day(3));
+ VERIFY( s == "janv.%janvier\t01\n 03% 3");
+
+ s = std::format("{0:%m/%d} {0}", month(10)/day(13));
+ VERIFY( s == "10/13 Oct/13" );
+ s = std::format("{0:%m/%d} {0}", month(13)/day(34));
+ VERIFY( s == "13/34 13 is not a valid month/34 is not a valid day" );
+
+ std::string_view specs = "aAbBcCdDeFgGhHIjmMpqQrRSTuUVwWxXyYzZ";
+ std::string_view my_specs = "bBdehm";
+ for (char c : specs)
+ {
+ char fmt[] = { '{', ':', '%', c, '}' };
+ try
+ {
+ auto md = month(1)/day(10);
+ (void) std::vformat(std::string_view(fmt, 5), std::make_format_args(md));
+ // The call above should throw for any conversion-spec not in my_specs:
+ VERIFY(my_specs.find(c) != my_specs.npos);
+ }
+ catch (const std::format_error& e)
+ {
+ VERIFY(my_specs.find(c) == my_specs.npos);
+ std::string_view s = e.what();
+ // Libstdc++-specific message:
+ VERIFY(s.find("format argument does not contain the information "
+ "required by the chrono-specs") != s.npos);
+ }
+ }
+}
+
+void
test_parse()
{
using namespace std::chrono;
@@ -102,6 +141,6 @@ test_parse()
int main()
{
test_ostream();
- // TODO: test_format();
+ test_format();
test_parse();
}
diff --git a/libstdc++-v3/testsuite/std/time/month_day_last/io.cc b/libstdc++-v3/testsuite/std/time/month_day_last/io.cc
index d15192c..484a8d8 100644
--- a/libstdc++-v3/testsuite/std/time/month_day_last/io.cc
+++ b/libstdc++-v3/testsuite/std/time/month_day_last/io.cc
@@ -22,8 +22,47 @@ test_ostream()
VERIFY( ss.str() == "juil./last" );
}
+void
+test_format()
+{
+ using namespace std::chrono;
+ std::locale loc_fr(ISO_8859(15,fr_FR));
+
+ auto s = std::format("{:%b%%%B%t%m%n}", month(3)/last);
+ VERIFY( s == "Mar%March\t03\n" );
+ s = std::format(loc_fr, "{:L%b%%%B%t%m%n}", month(3)/last);
+ VERIFY( s == "mars%mars\t03\n");
+
+ s = std::format("{0:%m/last} {0}", month(4)/last);
+ VERIFY( s == "04/last Apr/last" );
+ s = std::format("{0:%m/last} {0}", month(0)/last);
+ VERIFY( s == "00/last 0 is not a valid month/last" );
+
+ std::string_view specs = "aAbBcCdDeFgGhHIjmMpqQrRSTuUVwWxXyYzZ";
+ std::string_view my_specs = "bBhm";
+ for (char c : specs)
+ {
+ char fmt[] = { '{', ':', '%', c, '}' };
+ try
+ {
+ auto mdl = month(1)/last;
+ (void) std::vformat(std::string_view(fmt, 5), std::make_format_args(mdl));
+ // The call above should throw for any conversion-spec not in my_specs:
+ VERIFY(my_specs.find(c) != my_specs.npos);
+ }
+ catch (const std::format_error& e)
+ {
+ VERIFY(my_specs.find(c) == my_specs.npos);
+ std::string_view s = e.what();
+ // Libstdc++-specific message:
+ VERIFY(s.find("format argument does not contain the information "
+ "required by the chrono-specs") != s.npos);
+ }
+ }
+}
+
int main()
{
test_ostream();
- // TODO: test_format();
+ test_format();
}
diff --git a/libstdc++-v3/testsuite/std/time/month_weekday/io.cc b/libstdc++-v3/testsuite/std/time/month_weekday/io.cc
index 1838030..0c2dcaf 100644
--- a/libstdc++-v3/testsuite/std/time/month_weekday/io.cc
+++ b/libstdc++-v3/testsuite/std/time/month_weekday/io.cc
@@ -23,8 +23,47 @@ test_ostream()
VERIFY( ss.str() == "juil./jeu.[4]" );
}
+void
+test_format()
+{
+ using namespace std::chrono;
+ std::locale loc_fr(ISO_8859(15,fr_FR));
+
+ auto s = std::format("{:%b%%%B%t%m%n %a%%%A%t%u%n%w}", month(5)/weekday(1)[2]);
+ VERIFY( s == "May%May\t05\n Mon%Monday\t1\n1" );
+ s = std::format(loc_fr, "{:L%b%%%B%t%m%n %a%%%A%t%u%n%w}", month(5)/weekday(1)[2]);
+ VERIFY( s == "mai%mai\t05\n lun.%lundi\t1\n1");
+
+ s = std::format("{0:%m/%u[]} {0}", month(9)/weekday(0)[2]);
+ VERIFY( s == "09/7[] Sep/Sun[2]" );
+ s = std::format("{0:%m/%u[]} {0}", month(111)/weekday(8)[0]);
+ VERIFY( s == "111/8[] 111 is not a valid month/8 is not a valid weekday[0 is not a valid index]" );
+
+ std::string_view specs = "aAbBcCdDeFgGhHIjmMpqQrRSTuUVwWxXyYzZ";
+ std::string_view my_specs = "aAbBhmuw";
+ for (char c : specs)
+ {
+ char fmt[] = { '{', ':', '%', c, '}' };
+ try
+ {
+ auto mwi = month(1)/weekday(1)[1];
+ (void) std::vformat(std::string_view(fmt, 5), std::make_format_args(mwi));
+ // The call above should throw for any conversion-spec not in my_specs:
+ VERIFY(my_specs.find(c) != my_specs.npos);
+ }
+ catch (const std::format_error& e)
+ {
+ VERIFY(my_specs.find(c) == my_specs.npos);
+ std::string_view s = e.what();
+ // Libstdc++-specific message:
+ VERIFY(s.find("format argument does not contain the information "
+ "required by the chrono-specs") != s.npos);
+ }
+ }
+}
+
int main()
{
test_ostream();
- // TODO: test_format();
+ test_format();
}
diff --git a/libstdc++-v3/testsuite/std/time/month_weekday_last/io.cc b/libstdc++-v3/testsuite/std/time/month_weekday_last/io.cc
index 6ba4d8a..2c29258 100644
--- a/libstdc++-v3/testsuite/std/time/month_weekday_last/io.cc
+++ b/libstdc++-v3/testsuite/std/time/month_weekday_last/io.cc
@@ -23,8 +23,47 @@ test_ostream()
VERIFY( ss.str() == "juil./jeu.[last]" );
}
+void
+test_format()
+{
+ using namespace std::chrono;
+ std::locale loc_fr(ISO_8859(15,fr_FR));
+
+ auto s = std::format("{:%b%%%B%t%m%n %a%%%A%t%u%n%w}", month(6)/weekday(2)[last]);
+ VERIFY( s == "Jun%June\t06\n Tue%Tuesday\t2\n2" );
+ s = std::format(loc_fr, "{:L%b%%%B%t%m%n %a%%%A%t%u%n%w}", month(6)/weekday(2)[last]);
+ VERIFY( s == "juin%juin\t06\n mar.%mardi\t2\n2");
+
+ s = std::format("{0:%m/%w[last]} {0}", month(8)/weekday(7)[last]);
+ VERIFY( s == "08/0[last] Aug/Sun[last]" );
+ s = std::format("{0:%m/%w[last]} {0}", month(70)/weekday(9)[last]);
+ VERIFY( s == "70/9[last] 70 is not a valid month/9 is not a valid weekday[last]" );
+
+ std::string_view specs = "aAbBcCdDeFgGhHIjmMpqQrRSTuUVwWxXyYzZ";
+ std::string_view my_specs = "aAbBhmuw";
+ for (char c : specs)
+ {
+ char fmt[] = { '{', ':', '%', c, '}' };
+ try
+ {
+ auto mwl = month(1)/weekday(1)[last];
+ (void) std::vformat(std::string_view(fmt, 5), std::make_format_args(mwl));
+ // The call above should throw for any conversion-spec not in my_specs:
+ VERIFY(my_specs.find(c) != my_specs.npos);
+ }
+ catch (const std::format_error& e)
+ {
+ VERIFY(my_specs.find(c) == my_specs.npos);
+ std::string_view s = e.what();
+ // Libstdc++-specific message:
+ VERIFY(s.find("format argument does not contain the information "
+ "required by the chrono-specs") != s.npos);
+ }
+ }
+}
+
int main()
{
test_ostream();
- // TODO: test_format();
+ test_format();
}
diff --git a/libstdc++-v3/testsuite/std/time/weekday_indexed/io.cc b/libstdc++-v3/testsuite/std/time/weekday_indexed/io.cc
index ca315de..ae86419 100644
--- a/libstdc++-v3/testsuite/std/time/weekday_indexed/io.cc
+++ b/libstdc++-v3/testsuite/std/time/weekday_indexed/io.cc
@@ -22,8 +22,47 @@ test_ostream()
VERIFY( ss.str() == "sam.[1]" );
}
+void
+test_format()
+{
+ using namespace std::chrono;
+ std::locale loc_fr(ISO_8859(15,fr_FR));
+
+ auto s = std::format("{:%a%%%A%t%u%n%w}", weekday(7)[3]);
+ VERIFY( s == "Sun%Sunday\t7\n0" );
+ s = std::format(loc_fr, "{:L%a%%%A%t%u%n%w}", weekday(7)[3]);
+ VERIFY( s == "dim.%dimanche\t7\n0");
+
+ s = std::format("{0:%w[]} {0}", weekday(4)[4]);
+ VERIFY( s == "4[] Thu[4]" );
+ s = std::format("{0:%w[]} {0}", weekday(10)[7]);
+ VERIFY( s == "10[] 10 is not a valid weekday[7 is not a valid index]" );
+
+ std::string_view specs = "aAbBcCdDeFgGhHIjmMpqQrRSTuUVwWxXyYzZ";
+ std::string_view my_specs = "aAuw";
+ for (char c : specs)
+ {
+ char fmt[] = { '{', ':', '%', c, '}' };
+ try
+ {
+ auto wi = weekday(1)[1];
+ (void) std::vformat(std::string_view(fmt, 5), std::make_format_args(wi));
+ // The call above should throw for any conversion-spec not in my_specs:
+ VERIFY(my_specs.find(c) != my_specs.npos);
+ }
+ catch (const std::format_error& e)
+ {
+ VERIFY(my_specs.find(c) == my_specs.npos);
+ std::string_view s = e.what();
+ // Libstdc++-specific message:
+ VERIFY(s.find("format argument does not contain the information "
+ "required by the chrono-specs") != s.npos);
+ }
+ }
+}
+
int main()
{
test_ostream();
- // TODO: test_format();
+ test_format();
}
diff --git a/libstdc++-v3/testsuite/std/time/weekday_last/io.cc b/libstdc++-v3/testsuite/std/time/weekday_last/io.cc
index 3b64c65..49cf0d5 100644
--- a/libstdc++-v3/testsuite/std/time/weekday_last/io.cc
+++ b/libstdc++-v3/testsuite/std/time/weekday_last/io.cc
@@ -22,8 +22,47 @@ test_ostream()
VERIFY( ss.str() == "sam.[last]" );
}
+void
+test_format()
+{
+ using namespace std::chrono;
+ std::locale loc_fr(ISO_8859(15,fr_FR));
+
+ auto s = std::format("{:%a%%%A%t%u%n%w}", weekday(5)[last]);
+ VERIFY( s == "Fri%Friday\t5\n5" );
+ s = std::format(loc_fr, "{:L%a%%%A%t%u%n%w}", weekday(5)[last]);
+ VERIFY( s == "ven.%vendredi\t5\n5");
+
+ s = std::format("{0:%w[last]} {0}", weekday(6)[last]);
+ VERIFY( s == "6[last] Sat[last]" );
+ s = std::format("{0:%w[last]} {0}", weekday(9)[last]);
+ VERIFY( s == "9[last] 9 is not a valid weekday[last]" );
+
+ std::string_view specs = "aAbBcCdDeFgGhHIjmMpqQrRSTuUVwWxXyYzZ";
+ std::string_view my_specs = "aAuw";
+ for (char c : specs)
+ {
+ char fmt[] = { '{', ':', '%', c, '}' };
+ try
+ {
+ auto wl = weekday(1)[last];
+ (void) std::vformat(std::string_view(fmt, 5), std::make_format_args(wl));
+ // The call above should throw for any conversion-spec not in my_specs:
+ VERIFY(my_specs.find(c) != my_specs.npos);
+ }
+ catch (const std::format_error& e)
+ {
+ VERIFY(my_specs.find(c) == my_specs.npos);
+ std::string_view s = e.what();
+ // Libstdc++-specific message:
+ VERIFY(s.find("format argument does not contain the information "
+ "required by the chrono-specs") != s.npos);
+ }
+ }
+}
+
int main()
{
test_ostream();
- // TODO: test_format();
+ test_format();
}
diff --git a/libstdc++-v3/testsuite/std/time/year_month/io.cc b/libstdc++-v3/testsuite/std/time/year_month/io.cc
index 7bb3442..3392eb3 100644
--- a/libstdc++-v3/testsuite/std/time/year_month/io.cc
+++ b/libstdc++-v3/testsuite/std/time/year_month/io.cc
@@ -23,6 +23,45 @@ test_ostream()
}
void
+test_format()
+{
+ using namespace std::chrono;
+ std::locale loc_fr(ISO_8859(15,fr_FR));
+
+ auto s = std::format("{:%C%%%y\t%Y %b%%%B%t%m%n}", year(2019)/month(4));
+ VERIFY( s == "20%19\t2019 Apr%April\t04\n" );
+ s = std::format(loc_fr, "{:L%C%%%y\t%Y %b%%%B%t%m%n}", year(2019)/month(4));
+ VERIFY( s == "20%19\t2019 avril%avril\t04\n");
+
+ s = std::format("{0:%Y/%m} {0}", year(2018)/month(2));
+ VERIFY( s == "2018/02 2018/Feb" );
+ s = std::format("{0:%Y/%m} {0}", year(-32768)/month(15));
+ VERIFY( s == "-32768/15 -32768 is not a valid year/15 is not a valid month" );
+
+ std::string_view specs = "aAbBcCdDeFgGhHIjmMpqQrRSTuUVwWxXyYzZ";
+ std::string_view my_specs = "CbBhmyY";
+ for (char c : specs)
+ {
+ char fmt[] = { '{', ':', '%', c, '}' };
+ try
+ {
+ auto ym = year(2013)/month(1);
+ (void) std::vformat(std::string_view(fmt, 5), std::make_format_args(ym));
+ // The call above should throw for any conversion-spec not in my_specs:
+ VERIFY(my_specs.find(c) != my_specs.npos);
+ }
+ catch (const std::format_error& e)
+ {
+ VERIFY(my_specs.find(c) == my_specs.npos);
+ std::string_view s = e.what();
+ // Libstdc++-specific message:
+ VERIFY(s.find("format argument does not contain the information "
+ "required by the chrono-specs") != s.npos);
+ }
+ }
+}
+
+void
test_parse()
{
using namespace std::chrono;
@@ -73,6 +112,6 @@ test_parse()
int main()
{
test_ostream();
- // TODO: test_format();
+ test_format();
test_parse();
}