Lewis Hyatt [Sat, 11 Jul 2026 18:21:12 +0000 (14:21 -0400)]
libcpp: Preparation for LTO linemap changes
The expected way to create a new map in a line_map object is to call
linemap_add() and/or linemap_line_start(), which contain the necessary logic
to decide if a location can be encoded in the currently active map or if a
new map is required, and, in the latter case, what properties the new map
requires. This interface works well for the typical use case where a line
map is built up incrementally as source lines are processed, but it does not
provide the user with precise control over the exact properties of the newly
added map (or even whether a map is added at all).
That level of control will be needed for an upcoming change to the approach
to streaming location data for the LTO front end. Enable it by adding a new
function linemap_add_raw_map(), which simply allows the user (i.e., the LTO
front end) to add maps with the desired properties. The user is then
responsible for making sure the resulting state makes sense.
This patch adds self-tests for the new function, but does not otherwise make
any observable changes yet.
gcc/ChangeLog:
* input.cc (test_accessing_ordinary_linemaps): Test new
line_map_add_raw_map() functionality.
libcpp/ChangeLog:
* include/line-map.h (linemap_next_start_location): New function.
(linemap_add_raw_map): Declare new function.
* line-map.cc (linemap_add): Minor refactor to make use of
linemap_next_start_location().
(linemap_add_raw_map): New function.
(linemap_lookup): Update the comment for clarity.
match: Simplify sign tests for MIN and BIT_IOR [PR126087]
When `b` is known to be non-negative, the sign of both `MIN (a, b)`
and `a | b` depends only on the sign of `a`. Add patterns to match.pd
to optimize `MIN (a, b) cmp 0` and `(a | b) cmp 0` into `a cmp 0`,
where `cmp` is `<` or `>=`. Currently, `(a | b) cmp 0` is optimized
at the RTL level for some targets, but simplifying earlier is
preferable.
PR tree-optimization/126087
gcc/ChangeLog:
* match.pd: Simplify MIN and BIT_IOR compared to 0 when
one operand is non-negative.
i386: Add ROLW %r,8 alternative to bswaphi2 patterns [PR126283]
The HImode bswap can be implemented in two ways: using XCHGB %rH,%rL or
ROLW %r,8 where the former does not clobber flags. Unfortunately, clobber-less
XCHGB form limits available register set to only %ax, %bx, %cx and %dx, where
ROLW can use all registers (but clobbers flags reg).
It is better to use the form that clobbers flags reg and leave insn selection
to the compiler via preferred_for_* machinery. This choice also makes
"improve register allocation" peephole2 obsolete.
Also, always convert HImode rotate by 8 to bswap pattern, which can also
emit MOVBE instruction when available.
The testcase from PR tree-optimization/81549 is already optimized on
current trunk by the existing loop-PHI final-value replacement code.
Add the testcase to preserve coverage for the delayed loop-carried value
and verify that the final stores and return value are folded to constants.
gcc/testsuite/ChangeLog:
PR tree-optimization/81549
* gcc.dg/tree-ssa/pr81549.c: New test.
* gcc.dg/tree-ssa/pr81549-2.c: New test.
Jakub Jelinek [Fri, 17 Jul 2026 07:58:00 +0000 (09:58 +0200)]
c++: Implement C++29 P3424R2 - Deallocation Functions with Throwing Exception Specification Are Ill-formed [PR125833]
The following patch attempts to implement the C++29 P3424R2
Deallocation Functions with Throwing Exception Specification Are Ill-formed
paper by diagnosing those cases in grokfndecl, maybe_instantiate_noexcept and
cp_parser_class_specifier.
2026-07-17 Jakub Jelinek <jakub@redhat.com>
PR c++/125833
* cp-tree.h: Implement C++29 P3424R2 - Deallocation Functions with
Throwing Exception Specification Are Ill-formed.
(maybe_diagnose_deallocation_noexcept_false): Declare.
* decl.cc (maybe_diagnose_deallocation_noexcept_false): New function.
(grokfndecl): Call it.
* pt.cc (maybe_instantiate_noexcept): Likewise.
* parser.cc (cp_parser_class_specifier): Likewise.
* g++.dg/cpp0x/dealloc2.C: Expect extra diagnostics in C++29.
* g++.dg/cpp29/dealloc1.C: New test.
build: testsuite: Generate effective targets from auto-host.h
Several of the testsuite's effective targets are supposed to match the
result of configure tests. However, they often try to redo the tests,
which leads to code duplication and inconsistencies.
Instead, this patch provides a framework to automatically generate
check_effective_target_<effective-target> procs that match an
auto-host.h macro and loads the result into targets-support.exp.
The effective target definitions are read from et-static.def, similar to
the existing *.opt files, with a two-step process: preprocessing
et-static.def by stripping comments and empty lines, emitting the result
in a simple record format. That is used to scan auto-host.h to provide
the actual effective-target definitions.
Both the resulting et-static.def and the auto-host.h file are installed
so they can seamlessly be used for installed testing.
contrib/test_installed has been modified to allow for three scenarios:
* By default, the testsuite will load the installed et-static.exp file
directly.
* To use a modified or fallback et-static.exp, it can be specified with
--with-et-static.
* With --with-auto-host-h, an et-static.exp file matching the source
tree to be tested can be generated from a corresponding auto-host.h
file. This allows for testing an older installed compiler with a
newer source tree.
To avoid interfering with the target-supports.exp code to locate
et-static.exp, test_installed only emits the *_UNDER_TEST variables to
site.exp if a particular front end is actually tested.
To demonstrate the facility, this patch uses the recently added
HAVE_LD_AT_FILE check as a trivial example. Just as HAVE_LD_AT_FILE was
used to replace the current HAVE_GNU_LD, this patch creates a new
ld_at_file effective target, replacing one use of the gld effective
target.
Bootstrapped without regressions on i386-pc-solaris2.11 (as/ld and
gas/gld) and x86_64-pc-linux-gnu. Also tested with test_installed on
i386-pc-solaris2.11.
gcc:
* et-gather.awk, gen-et-static.awk: New scripts.
* Makefile.in (testsuitedir): New.
(native): Depend on testsuite/et-static.exp.
(clean): Remove etlist.
(distclean): Remove et-static.exp.
(install-testsuite): New target.
(install): Depend on it.
(site.exp): Depend on testsuite/et-static.exp.
(testsuite/et-static.exp): New target.
gcc/testsuite:
* lib/et-static.def: New file.
* lib/target-supports.exp: Load et-static.exp.
* gcc.misc-tests/outputs.exp: Use ld_at_file effective target
instead of gld.
Update comment.
contrib:
* test_installed (--with-auto-host-h): New option.
(--with-et-static): Likewise.
(--with-objc): Likewise.
Generate et-static.def if --with-auto-host-h is specified.
(GCC_UNDER_TEST): Only emit to site.def if enabled.
(GXX_UNDER_TEST): Likewise.
(GFORTRAN_UNDER_TEST): Likewise.
(OBJC_UNDER_TEST): Likewise.
(et_static): Emit to site.exp if specified.
determine_block_size: Set len_rtx to min size if min size == max size
ix86_expand_set_or_cpymem may use vector loop on a block of memory whose
size < epilogue size. Don't use misaligned prologue if count <= epilogue
size.
gcc/
PR target/126275
* config/i386/i386-expand.cc (ix86_expand_set_or_cpymem): Don't
use misaligned prologue if count <= epilogue size.
Eric Botcazou [Fri, 17 Jul 2026 07:14:46 +0000 (09:14 +0200)]
Ada: Fix bogus type mismatch for reduction expression with non-integer index
This is a regression recently introduced by the rewrite of the resolution of
reduction expressions. The resolution of the prefix to an array type built
on the fly when it is an aggregate does not work properly, so this removes
it to get back to the previous working state. This requires performing the
full resolution of the reducer even if it is not overloaded to avoid losing
errors in some illegal cases.
gcc/ada/
* sem_attr.adb (Resolve_Attribute) <Attribute_Reduce>: Perform the
full resolution of the reducer even if it is not overloaded, but do
not resolve the prefix if it is an aggregate
Richard Biener [Wed, 15 Jul 2026 09:33:50 +0000 (11:33 +0200)]
Improve BB vectorization of reductions
When there's not a uniform chain of operations gathered from the
reduction operation chain we currently simply fail and to make
success more likely we strip off the last operation to make the
number of lanes at least even. This isn't ideal and somewhat
random as can be seen in PR126028 which is the motivating case
and has a three lane reduction. So the following removes the
early stripping down to an even number of lanes and uses SLP
discovery of the whole group to direct re-analysis of the
larger of the matching or non-matching part.
For gcc.dg/vect/pr106081.c we now BB vectorize parts which
just confuses the loop vectorization dump scanning, so disable it.
PR tree-optimization/126028
* tree-vect-slp.cc (vect_slp_check_for_roots): Do not
force the BB reduction root to have an even number of lanes.
(vect_build_slp_instance): For failed discovery of a BB
reduction attempt to re-try discovery on the matching or
non-matching part.
openmp: Pass loop parameters to static worksharing dispatch builtins for OMPT
The GOMP_*_static_worksharing_dispatch builtins took no arguments and the
OMPT dispatch callback was missing information about the loop. Pass the loop's
iteration count, start, step, chunk size, and the thread's starting
iteration instead.
gcc/ChangeLog:
* builtin-types.def (BT_FN_VOID_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG): New.
* omp-builtins.def (BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_DISPATCH): Use
BT_FN_VOID_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG_ULONGLONG.
(BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_DISPATCH): Likewise.
* omp-expand.cc (expand_omp_for_static_nochunk): Pass niter, start,
incr, chunk size, and istart to the dispatch call.
(expand_omp_for_static_chunk): Likewise.
Andrew MacLeod [Wed, 15 Jul 2026 19:43:14 +0000 (15:43 -0400)]
Path ranger should check root ranger equivalencies as well.
Path ranger currently checks the root ranger for realtions between
only local equivalencies. If that fails, it should also check the
root ranger for any equivalencies and relations between the two names
which occur earlier in the IL.
PR tree-optimization/125986
* value-relation.cc (path_oracle::query): Query root oracle for
relations.
Jin Ma [Thu, 16 Jul 2026 07:56:08 +0000 (15:56 +0800)]
RISC-V: Use a pseudo for sibcall addresses
SIBCALL_REGS excludes t1, so the "j" constraint makes LRA reload a
sibcall address materialized in t1. Sibcalls are therefore correct
without this change.
Use a pseudo for sibcall address materialization so allocation can
select SIBCALL_REGS directly and avoid the reload. Keep t1 for normal
calls. This is an optimization, not a bug fix.
gcc/ChangeLog:
* config/riscv/riscv-protos.h
(riscv_legitimize_call_address): Add a sibcall parameter.
* config/riscv/riscv.cc
(riscv_legitimize_call_address): Use a pseudo for sibcalls.
* config/riscv/riscv.md (sibcall): Pass true for sibcalls.
(sibcall_value): Likewise.
(call): Pass false for ordinary calls.
(call_value): Likewise.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/sibcall-materialize-pseudo.c: New test.
Jin Ma [Sat, 11 Jul 2026 14:45:54 +0000 (22:45 +0800)]
RISC-V: Exclude t1 from SIBCALL_REGS
RISCV_CALL_ADDRESS_TEMP and RISCV_PROLOGUE_TEMP2 both use t1. An
indirect sibcall target in t1 can therefore be overwritten by an RVV
scalable-frame epilogue before the final jump.
Exclude t1 from SIBCALL_REGS and map it to JALR_REGS.
gcc/ChangeLog:
* config/riscv/riscv.cc (riscv_regno_to_class): Map t1 to
JALR_REGS.
* config/riscv/riscv.h (RISCV_PROLOGUE_TEMP_REGNUM): Document
the SIBCALL_REGS restriction.
(REG_CLASS_CONTENTS): Remove t1 from SIBCALL_REGS.
gcc/testsuite/ChangeLog:
* g++.target/riscv/pr97682.C: Accept registers in SIBCALL_REGS.
* gcc.target/riscv/rvv/base/sibcall-scalable-frame-indirect.c:
New test.
* gcc.target/riscv/rvv/base/sibcall-scalable-frame-weak.c: New test.
Tomasz Kamiński [Tue, 14 Jul 2026 14:06:36 +0000 (16:06 +0200)]
libstdc++: Resolve named-rule UNTIL save adjustment [PR116110]
The previous patches for PR 116110 left one case unresolved: a Zone
line with a wall-time UNTIL whose RULES field is a named rule set.
The save value used to convert the wall UNTIL to UTC depends on which
rule of the set was active at the UNTIL instant, but at parse time
the rule records have not all been loaded, so the active-rule lookup
can't yet be performed.
The remaining FIXME in operator>>(istream&, ZoneInfo&) caused zones
like Africa/Algiers (around 1977-10-21) to place their zone-line
boundary one save-period off from the canonical zic interpretation,
producing brief incorrect sys_info windows during DST transitions.
This commit defers the save adjustment to _M_get_sys_info call,
and applies it only for the ZoneInfo surrounding the specified
time. This assumes that applying the save does not change relative
order of ZoneInfo (i.e. the until members are spaced more than save).
The m_expanded member is replaced with four state _M_state setting:
Expanded, and three separte state used for rule based zones:
* SaveKnown - m_save contains save value at time m_until
* SavePending - m_save is defualted to zero, m_until is correct
* UntilPending - as above, but also m_until time need to adjusted
The parser set the UntilPending state when it sees a wall-time
UNTIL on a named-rule line, and SaveKnown if not UNTIL date is
specified.
The fixup in _M_get_sys_info, is performed by calc_save function
on previous/current zone. If necessary (depending on m_state) this
function updates m_save and m_until members, and returns true
if the m_until was shifted in the process. In such case, we redo
the comparision of until() against tp, and move iterator to active
zone info if necessary. The save at boundary for previous/current
ZoneInfo is required to implement proper zone merging, so it is
always computed.
The active-rule lookup either reuses the existing find_active_rule
overload accepting sys_seconds (if UNTIL is not affected by save),
or newly introduced overload accepting local_seconds (local time).
The local_seconds versions, follows the same logic for finding
rule transitions (extracted to find_surrounding_transitions)
surrounding the sys_time. The final active rule, is then determined
after converting the transition times to local time, including the
running save.
The test_apia case in 116110.cc had a hardcoded `+11h` workaround
for the unfixed bug; with this fix in place the workaround is removed
and the value becomes the canonical `+10h`.
libstdc++-v3/ChangeLog:
PR libstdc++/116110
* src/c++20/tzdb.cc (ZoneInfo::calc_save, ZoneInfo::State): Define.
(ZoneInfo::m_expanded): Replaced with m_state.
(ZoneInfo::m_pos): Reduce the bit with to 14.
(ZoneInfo::m_state): Expands m_expanded with four state enum.
(ZoneInfo::ZoneInfo, ZoneInfo::expanded, ZoneInfo::set_abbrev):
Replace m_expanded usage with m_state and State::Expanded.
(Transitions, find_surrounding_transitions): Extracted from
find_active_rule.
(find_active_rule): Define overload for local_seconds. Implement
both in terms of find_surrounding_transitions.
(time_zone::_M_get_sys_info): Use ZoneInfo::calc_save to adjust
until() on surrounding zones, and shift the current zone iterator
(i) accordingly.
(operator>>(istream&, ZoneInfo&)): Set m_state for UntilPending
for UNTIL time using wall time, and SaveKnown for lines without
end date. For clarity, set m_save to 0 if daylight is not used.
* testsuite/std/time/time_zone/116110.cc (test_apia): Use correct
value of the the total offset.
testsuite/std/time/time_zone/pr116110_named.cc: New test.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Co-authored-by: Álvaro Begué <alvaro.begue@gmail.com> Signed-off-by: Álvaro Begué <alvaro.begue@gmail.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
Sebastian Huber [Thu, 16 Jul 2026 04:34:50 +0000 (12:34 +0800)]
gcov: Build edge updates in a local sequence
Instead of inserting each generated statement onto an edge individually, which
happens repeatedly for the same edge while flushing the condition coverage
accumulators, build up a local gimple_seq for the edge and insert it once with
a single gsi_insert_seq_on_edge() call. emit_assign() and emit_bitwise_op()
are changed to append to a caller-supplied gimple_seq instead of inserting
directly on an edge.
Tested on x86_64-pc-linux-gnu (gcov.exp, gcc.dg gcov*.c, tree-prof.exp) with no
regressions.
gcc/ChangeLog:
* tree-profile.cc (emit_assign): Append to a gimple_seq instead
of inserting on an edge. Make the functions static.
(emit_bitwise_op): Likewise.
(instrument_decisions): Build up a local gimple_seq per edge and
insert it once instead of inserting each statement individually.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
Sebastian Huber [Thu, 16 Jul 2026 03:53:41 +0000 (11:53 +0800)]
gcov: Optimize condition coverage code generation
Change the code to avoid emitting bitwise-or operations with a zero constant
operand since they are effectively no-operations. The omitted bitwise-or
operations are potentially relaxed atomic operations which cannot be optimized
away once emitted, so the omission has to happen while generating the profiling
code in instrument_decisions(), not as a later gimple optimization.
For example, consider this test case:
int a(int);
int b(int);
int g(int i)
{
if (i) {
return a(i);
} else {
return b(i);
}
}
On 64-bit RISC-V this change results in the following code changes for
options -fprofile-update=atomic -fcondition-coverage -O2:
Tested on x86_64-pc-linux-gnu (gcov.exp, gcc.dg gcov*.c, tree-prof.exp)
with no regressions, and manually cross-checked on 64-bit RISC-V for the
asm diff shown above.
gcc/ChangeLog:
* tree-profile.cc (emit_bitwise_op): Build/fold the operation with
gimple_build() instead of gimple_build_assign(), and return the
folded result as-is instead of always materializing a new SSA
name.
(instrument_decisions): Do not emit bitwise-or operations with a
zero constant operand.
gcc/testsuite/ChangeLog:
* gcc.dg/gcov-atomic-or-zero.c: New test.
* gcc.misc-tests/gcov-35.c: Likewise.
* gcc.misc-tests/gcov-36.c: Likewise.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
Tomasz Kamiński [Thu, 16 Jul 2026 13:36:08 +0000 (15:36 +0200)]
libstdc++: Disable serialization test for piecewise_linear_distribution<double> on i686
The r17-2455-gf8c277ed801ba6 enabled test_custom unconditionally for both
double and float, however all-combination test shows that double remains
unstable.
libstdc++-v3/ChangeLog:
* testsuite/26_numerics/random/piecewise_linear_distribution/operators/serialize2.cc:
Enable test_customd<double> for __x86_64__.
Tomasz Kamiński [Thu, 16 Jul 2026 10:50:32 +0000 (12:50 +0200)]
libstdc++: Apply rule triggering at Zone line transition [PR124853]
When seeding zone information from the application of the rules
prior the transition, we should consider the rule triggering exactly
at boundary, not only prior, i.e. call find_active_rule with info.begin.
Due the rule_start - t < days(1) check (that is not removed yet), such
transitions were effectively ignored.
This addresses regressions introduced by r17-2060-gf7cde200320e08,
where new differences between outputs of libstdc++ and date library were
introduced for some zones (e.g. Europe/Lisbon in 1976). With this fixup,
the patch is now pure improvement in consistency.
libstdc++-v3/ChangeLog:
PR libstdc++/124853
* src/c++20/tzdb.cc (time_zone::_M_get_sys_info): Find
rules firing exactly at transition time.
* testsuite/std/time/time_zone/wall_cascade.cc: Add test
for Europe/Lisbon, and corrected test_negative.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
Pan Li [Wed, 15 Jul 2026 01:21:06 +0000 (09:21 +0800)]
RISC-V: Add test cases for vwcvtu.x.x.v reg overlap
Add test cases for vwcvtu.x.x.v register group overlap, please
note it is not overlap as much as possible.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvtu-i16-m1.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvtu-i16-m2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvtu-i16-m4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvtu-i16-mf2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvtu-i16-mf4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvtu-i32-m1.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvtu-i32-m2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvtu-i32-m4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvtu-i32-mf2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvtu-i8-m1.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvtu-i8-m2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvtu-i8-m4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvtu-i8-mf2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvtu-i8-mf4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvtu-i8-mf8.c: New test.
Pan Li [Wed, 15 Jul 2026 01:20:10 +0000 (09:20 +0800)]
RISC-V: Add test cases for vwcvt.x.x.v reg overlap
Add test cases for vwcvt.x.x.v register group overlap, please
note it is not overlap as much as possible.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvt-i16-m1.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvt-i16-m2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvt-i16-m4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvt-i16-mf2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvt-i16-mf4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvt-i32-m1.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvt-i32-m2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvt-i32-m4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvt-i32-mf2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvt-i8-m1.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvt-i8-m2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvt-i8-m4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvt-i8-mf2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvt-i8-mf4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vwcvt-i8-mf8.c: New test.
Jonathan Wakely [Wed, 24 Jun 2026 20:50:24 +0000 (21:50 +0100)]
contrib: Fix exit status of relpath.sh for invalid args [PR125956]
The relpath.sh script always writes its usage message to stdout and
exits with zero status, even for invalid arguments. This caused a
problem for libstdc++-v3/src/c++23/Makefile which assumed that
relpath.sh won't exit successfully on error, via:
relpath=$(relpath.sh ...) && sed 's,@MODPATH@,$$relpath,' ...
Because relpath.sh exits successfully for invalid args, the sed command
still ran even when relpath.sh was invoked incorrectly.
The libstdc++ Makefile has been changed to work around this, but
relpath.sh should still have an idiomatic exit status.
contrib/ChangeLog:
PR libstdc++/125956
* relpath.sh: For invalid arguments write to stderr and exit
with non-zero status.
Jeff Law [Thu, 16 Jul 2026 12:37:53 +0000 (06:37 -0600)]
[RISC-V] Improve costing for if-converted sequences
So I'm not happy with this entire routine, but after trying to fix things
right, I'm back to adjusting the cost routine instead.
The fundamental problem as I see it is the cstore patterns on RISC-V are
suboptimal.
Those patterns always have an SI destination. One expander is used for integer
inputs, the other for FP inputs.
In both the integer and FP case we use an iterator to allow different input
modes. But the destination stays fixed in SI.
But it'd be really advantageous to support an output iterator. With the forced
SI output we typically end up with subreg copies, zero extensions and moves in
sequences involving SCC insns. That is usually cleaned up by combine, but
those extra insns participate in if-conversion costing and sometimes cause us
to miss opportunities or force us into a slower/bigger sequence using
generalized conditional moves.
Of course the cstore only has one mode, which if I read the docs correctly
*should* be the output mode. RISC-V is using it for the input modes. So we're
doing something a bit dumb there. To achieve that we'd need to combine the two
expanders since they both have integer output modes and we can't have two
expanders with the same name. To combine the expanders the inputs have to
accept both integer and FP modes. That's likely possible but it's going to get
ugly (for example, use modeless operands and check modes and FAIL in the
expansion code).
So rather than fight that battle, this patch just ignores the trivial copies
that can be generated during expansion. The code was already ignoring certain
extensions and promoted subreg copies. With some in flight if-conversion work
we're able to take this testcase (adjusted from a loongarch test):
extern long lm, ln, lr;
void
test_ne ()
{
if (lm != ln)
lr += (1 << 2);
lr += lm;
}
Which previously generated this code for the conditional add
beq a5,a2,.L2
addi a4,a4,4
.L2:
add a5,a5,a4
With the in flight if-converter work alone we'd generate:
sub t2,t0,t1
li a1,4
czero.eqz a0,a1,t2
add a6,a3,a0
add a7,t0,a6
It's straightline code and probably better due to that alone if the branch has
meaningful unpredictability for the hardware. Add in this patch to send us
through a different if-conversion path and we get:
sub t2,t0,t1
snez a0,t2
sh2add a1,a0,a2
add a6,t0,a1
For shift counts 1..3 we'll get that shNadd form. For shift counts 4..11 we'll
get sll+add. For shift counts > 11 the middle block in the if-conversion path
has two insns because the constant can't encode into an addi instruction and we
can't use the specialized ifcvt paths.
Tested on riscv32-elf and riscv64-elf. Bootstrap & regression test on k3 is in
flight. Bootstrap and regression test and k1 and c920 will fire up later
today. Obviously I'll wait for pre-commit CI to render its verdict, I expect
I'll have k3 data by then as well.
Tomasz Kamiński [Thu, 9 Jul 2026 09:17:58 +0000 (11:17 +0200)]
libstdc++: Generate result_type bits of precision in piecewise distributions.
The piecewise distributions previously always generated a double value
out of provided generator, regardless of the result_type (template
parameter). This patch address above, by generating value of _RealType
by default.
Furthermore, this patch addresses LWG4052, "Bogus requirements for
piecewise_linear_distribution" issue, by converting the inputs
(from iterators, or provided weights functor) to RealType, instead
of double. See input_type test included in this patch.
For consistency the internal computations are now performed in RealType,
instead of double. This reduces the precision if float it used, however
due the ABI compatibility, double is still used for storage, unless
_GLIBCXX_USE_RESULT_TYPE_FOR_PIECEWISE_DENSITIES is defined (see
test_precision_depended in accessors.cc) test.
The above change leads to user-observable changes in the behaviour or
distributions, both in produced outputs and number of calls to provided
generator performed per each element (see test_engine_calls in accessors.cc).
The pre-GCC17 behavior of distributions can be restored by defining
_GLIBCXX_USE_OLD_PIECEWISE_DISTRIBUTIONS (this also reverts r17-2391-geae19
and r17-2392-g86a93). This is achieved by converting the values to _CalcType
that is either defined as double or _RealType. This change is not applied
to interval delta (_M_int[__k + 1] - _M_int[__k]) that used _RealType
already, to preserve the result of computations involving it.
To reduce the code duplication the __generate_one functions are introduced
for both distributions. They are used both by the operator() and
__generate_impl. The linear __generate_impl is now consistent with constant
version, and simply assigns the result of generator invocation for default
configuration.
Finally, this made result of stream operator for float/double param_type
of piecewise_linear_distribution consistent for 32bits/64bits. The
float specialization for constant distribution still produces different
result, however the calculated values are consistent when printed as
hexfloat.
libstdc++-v3/ChangeLog:
* doc/html/manual/using_macros.html: Regenrate.
* doc/xml/manual/using.xml
(_GLIBCXX_USE_OLD_PIECEWISE_DISTRIBUTIONS): Mention LWG4052.
* include/bits/random.h
(piecewise_constant_distribution::_CalcType)
(piecewise_linear_distribution::_CalcType): Define.
(piecewise_constant_distribution::__generate_one)
(piecewise_linear_distribution::__generate_one): Declare.
(piecewise_constant_distribution::_M_initialize2)
(piecewise_linear_distribution::__M_initialize2): Adjust
densities parameter to _CalcType.
* include/bits/random.tcc (std::__normalize): Perform
computation in the type of factor parameter.
(piecewise_constant_distribution::_M_configure)
(piecewise_linear_distribution::_M_configure): Use _CalcType.
(piecewise_constant_distribution::param_type::param_type)
(piecewise_constant_distribution::param_type::param_type):
Cast the inputs to the _CalcType. Use _RealType as input
weight functor.
(piecewise_constant_distribution::__generate_one)
(piecewise_linear_distribution::__generate_one): Extract
from operator() and use _CalcType.
(piecewise_constant_distribution::operator())
(piecewise_constant_distribution::__generate_impl).
(piecewise_linear_distribution::operator()): Use __generate_one.
(piecewise_linear_distribution::__generate_impl): Optimize
_M_cp.empty() case and user __generate_one otherwise.
* testsuite/26_numerics/random/piecewise_constant_distribution/operators/accessors.cc:
(test_precision_depended): Expand test to cover all constructors,
and inputs different from distribution result type.
(test_engine_calls): New tests.
* testsuite/26_numerics/random/piecewise_linear_distribution/operators/accessors.cc:
Likewise.
* testsuite/26_numerics/random/piecewise_constant_distribution/operators/serialize2.cc:
Update values to accommodate the change in precision for float.
Remove trailing whitespaces.
* testsuite/26_numerics/random/piecewise_linear_distribution/operators/serialize2.cc:
Likewise, and enable float/double test for i686.
* testsuite/26_numerics/random/piecewise_constant_distribution/cons/input_type.cc:
New test.
* testsuite/26_numerics/random/piecewise_constant_distribution/cons/input_type_fallback_neg.cc:
New test.
* testsuite/26_numerics/random/piecewise_linear_distribution/cons/input_type.cc:
New test.
* testsuite/26_numerics/random/piecewise_linear_distribution/cons/input_type_fallback_neg.cc:
New test.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
testsuite, aarch64: Drop duplication of big endian AArch64 neon tests.
The aarch64-neon driver script includes a section that allows for a
target to perform the tests as big-endian. Since the majority of LE
targets will not be able to perform these tests this produces a lot
of UNRESOLVED cases there. For big-endian targets the effect is to
do the work twice.
So removing that section.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/neon/aarch64-neon.exp: Remove section
re-runing the tests as big-endian.
Jakub Jelinek [Thu, 16 Jul 2026 11:58:52 +0000 (13:58 +0200)]
libstdc++: Mark std::indirect and std::polymorphic with _GLIBCXX_NO_SPECIALIZATIONS [PR120635]
The following marks these two templates with [[_Clang::no_specializations]]
because the P3019R14 paper which introduced them already added the
restrictions that they shouldn't be specialized by users.
I think I'll defer the rest to others (i.e. P2652R2 - std::allocator_traits,
P0912R5 - std::coroutine_handle and LWG4535 - <simd>).
2026-07-16 Jakub Jelinek <jakub@redhat.com>
PR c++/120635
* include/bits/indirect.h (std::indirect, std::polymorphic): Add
_GLIBCXX_NO_SPECIALIZATIONS.
* testsuite/std/memory/indirect/specialization.cc: New test.
* testsuite/std/memory/polymorphic/specialization.cc: New test.
This fixes a bug I introduced in commit r17-2404-g2468c79741f97c,
OpenMP: Handle 'device_type(host)' on 'target'
For code inside a target region with either 'device(ancestor:1)' or
with 'device_type(host)' no device code should be generated. That's
handled by both omp_discover_declare_target_tgt_fn_r and by
omp_discover_declare_target_fn_r.
While for the latter, walk_tree_without_duplicates is called when
the condition is true, the former sets '*walk_subtrees = 0'.
Looking too similar, r17-2404 ended up using the same condition for
both. - The solution is to inverse the current condition for
omp_discover_declare_target_tgt_fn_r.
Testcase: The already existing and since r17-2404 failing
test libgomp.fortran/reverse-offload-6.f90.
gcc/ChangeLog:
* omp-offload.cc (omp_discover_declare_target_tgt_fn_r): Fix
the condition for anchestor + nohost handling.
Arsen Arsenović [Sat, 20 Jun 2026 17:05:58 +0000 (19:05 +0200)]
libstdc++: Fix LD_LIBRARY_PATH when testing an installed compiler
Previously, none would be set, so an installed compiler that does not
emit an RPATH to its libraries would not be able to execute programs
that require libstdc++.so symbols.
libstdc++-v3/ChangeLog:
* testsuite/lib/libstdc++.exp (libstdc++_init): Use
gcc-set-multilib-library-path to calculate LD_LIBRARY_PATH for
installed G++ compilers.
The memspace modifier to uses_allocators was converted in Fortran not to an
integer number but to an external variable - which failed then at link time.
Additionally, it turned out that - at least with host fallback - multiple
uses_allocator clauses aren't supported as newer ones overrode previous ones;
shifting it by gomp_omp_allocator_data_size data helped.
OpenMP requires 'a constant array, have constant values' for C/C++ and for
Fortran a 'named constant of rank one'; it turned out that the FEs already
generate, e.g.
static struct omp_alloctrait_t traits[1] = {{.key=2, .value=1024}};
which can be directly passed to the runtime library - no need to expand the
initializer values into a new variable and then take the address of that one.
For C/C++, this might be new since commit r17-2414-g9e9e22587f7954
that set calls 'mark_exp_read' to avoid an 'unused but set' warning for the
traits variable [not checked] - but in any case it is now consistent.
PR fortran/126279
gcc/fortran/ChangeLog:
* trans-openmp.cc (gfc_trans_omp_clauses): Convert memspace constant
to an integer not to an external variable.
gcc/ChangeLog:
* omp-low.cc (lower_omp_target): Avoid creating a second static const
variable for the trait array used by uses_allocators.
libgomp/ChangeLog:
* target.c (copy_firstprivate_data): After storing users_allocators'
allocator, shift the offset by its storage size to avoid overriding.
* testsuite/libgomp.fortran/uses_allocators-1.f90: Use kind c_size_t
instead of kind 8 for 32bit compatibility.
* testsuite/libgomp.fortran/uses_allocators-4.f90: Update expected
tree dump.
* testsuite/libgomp.fortran/uses_allocators-7.f90: Extend testcase now
that user-defined allocators are supported by uses_allocators.
(Also, effective-target 'offload_device' tests "if [an] offload device is
available", which wasn't the right conditional here: should rather have used
'offload_target_any': "if compiling for any offload target". But that still
wouldn't have achieved what this intended to test.)
libgomp/
* testsuite/libgomp.c/target-device-type-3.c: Repair offload tree
dump scanning.
In C (per my understanding), this is "valid" (syntax): 'lineptr' appears as
part of the block it's declared in. However, it only gets initialized (to
'NULL') only *after* the first 'goto fail;', therefore that 'goto fail;',
'free (lineptr);' code path invokes undefined behavior, crashes for random junk
in 'lineptr'.
| -- Function: ssize_t getline (char **LINEPTR, size_t *N, FILE *STREAM)
| [...]
| If you set ‘*LINEPTR’ to a null pointer, and ‘*N’ to zero, before
| the call, then ‘getline’ allocates the initial buffer [...]
Confusingly, that's slightly different from the 'getline' definition in
<https://pubs.opengroup.org/onlinepubs/9799919799/functions/getline.html> as
well as common implementation (including glibc's...), which don't require
zero-initialiation of 'nline' given NULL for 'lineptr'. We shall err on the
side of caution, and do similar to other libgomp 'getline' code, that is,
initialize 'nline' to zero in this case here.
PASS: libgomp.c/target-device-type-1.c (test for excess errors)
FAIL: libgomp.c/target-device-type-1.c execution test
PASS: libgomp.c/target-device-type-1.c scan-tree-dump gimple "= __builtin_omp_is_initial_device \\(\\);"
PASS: libgomp.c/target-device-type-1.c scan-tree-dump gimple "__builtin_GOMP_error \\("Executing device-type ..nohost.. target region on the host","
... for (non-USM) AMD GPU offloading:
Memory access fault by GPU node-2 (Agent handle: 0xff37f00) on address 0x7ffd8a413000. Reason: Page not present or supervisor privilege.
..., and correspondingly for (non-USM) NVIDIA GPU offloading:
libgomp: cuCtxSynchronize error: an illegal memory access was encountered
Fix this by 'map'ping 'x' for the OpenMP 'target' construct. Not technically
necessary for 'libgomp.c/target-device-type-2.c' (as that one's exercising the
'host' error case), but still apply the same change also to that one.
FAIL: gcc.dg/vect/tsvc/vect-tsvc-s000.c (test for excess errors)
UNRESOLVED: gcc.dg/vect/tsvc/vect-tsvc-s000.c compilation failed to produce executable
UNRESOLVED: gcc.dg/vect/tsvc/vect-tsvc-s000.c scan-tree-dump-times vect "vectorized 1 loops" 1
Excess errors:
gcc.dg/vect/tsvc/tsvc.h:199:20: error: implicit declaration of function 'memalign' [-Wimplicit-function-declaration]
gcc.dg/vect/tsvc/tsvc.h:199:10: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
gcc.dg/vect/tsvc/tsvc.h:200:11: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
While NetBSD lacks memalign, it has posix_memalign instead.
Tested on amd64-pc-netbsd10.1 and i386-pc-solaris2.11.
testsuite: Require bitint in gcc.dg/torture/bitint-101.c
The new gcc.dg/torture/bitint-101.c test FAILs on Solaris/SPARC:
FAIL: gcc.dg/torture/bitint-101.c -O0 (test for excess errors)
UNRESOLVED: gcc.dg/torture/bitint-101.c -O0 compilation failed to produce executable
Excess errors:
gcc.dg/torture/bitint-101.c:4:1: sorry, unimplemented: '_BitInt(2)' is not supported on this target
gcc.dg/torture/bitint-101.c:11:3: sorry, unimplemented: '_BitInt(2)' is not supported on this target
Fixed by requiring bitint support.
Tested on sparc-sun-solaris2.11 and i386-pc-solaris2.11.
Jakub Jelinek [Thu, 16 Jul 2026 07:55:37 +0000 (09:55 +0200)]
bitintlower: Avoid coalescing lhs with operands for .MUL_OVERFLOW [PR126262]
We need to avoid overlap between the lhs and input operands of __mulbitint3
and __divmodbitint4. This is done in build_bitint_stmt_ssa_conflicts, when
muldiv_p is set, we call use on all the SSA use operands (including operands
of stmts on worklist) first and def on the lhs at the end, while for
!muldiv_p, at least for stmts with a single lhs we call def first and then
all the use calls. For MULT_EXPR etc. we already handle it:
case MULT_EXPR:
case TRUNC_DIV_EXPR:
case EXACT_DIV_EXPR:
case TRUNC_MOD_EXPR:
muldiv_p = true;
Now, for the IFN_*_OVERFLOW, we handle it for bitint_big_endian only
currently, on big endian there is a problem that if the sizes don't match
exactly, even in order updates of the limbs can clobber stuff.
But, for IFN_MUL_OVERFLOW and IFN_UBSAN_CHECK_MUL, we actually use
__mulbitint3 libgcc call and that function really can't be called with
overlapping destination and inputs, because it traverses the inputs multiple
times while writing destination one by one (and it intentionally doesn't
allocate memory for temporaries).
So, the following patch fixes it by making IFN_MUL_OVERFLOW and
IFN_UBSAN_CHECK_MUL calls be always handled as muldiv_p.
2026-07-16 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/126262
* gimple-lower-bitint.cc (build_bitint_stmt_ssa_conflicts): Treat
IFN_MUL_OVERFLOW and IFN_UBSAN_CHECK_MUL like IFN_BSWAP, regardless
of bitint_big_endian.
Jakub Jelinek [Thu, 16 Jul 2026 07:51:48 +0000 (09:51 +0200)]
libstdc++: Use _Clang::__no_specializations__ attribute in a few spots [PR120635]
The following patch adds _Clang::__no_specializations__ attribute
to a couple of templates:
1) LWG3975 - basic_format_{,parse_}context
2) LWG3990 - variant, tuple
3) LWG4305 - type_order
4) LWG2129 - std::initializer_list
This assumes all those issues were handled as defect reports.
What I haven't touched, but has similar wording:
5) P2652R2 - std::allocator_traits
6) P3019R14 - std::indirect
7) P0912R5 - std::coroutine_handle
8) LWG4535 - <simd>
Anything else I'm missing?
Note, seems libcxx adds the attribute to significantly more places, but not
sure if that is desirable. [namespace.std] has some restrictions, but those
generally say that it is UB in that case, which I'm not sure is the right
case for unconditional error. Compared to that, the above mentioned
library issues talk about ill-formed (and not IFNDR, so we really should
be diagnosing that).
2026-07-16 Jakub Jelinek <jakub@redhat.com>
PR c++/119561
PR c++/120635
* include/bits/c++config (_GLIBCXX_NO_SPECIALIZATIONS): Define.
* include/std/variant (std::variant): Use it to resolve LWG3990.
* include/std/format (std::basic_format_parse_context,
std::basic_format_context): Use it to resolve LWG3975.
* libsupc++/compare (std::type_order): Use it to resolve LWG4305.
* libsupc++/initializer_list (std::initializer_list): Use it to
resolve LWG2129.
* include/std/tuple (std::tuple): Use it to resolve LWG3990.
Temporarily ignore -Winvalid-specialization around specializations
of tuple.
* testsuite/18_support/comparisons/type_order/lwg4305.cc: New test.
* testsuite/18_support/initializer_list/lwg2129.cc: New test.
* testsuite/std/format/lwg3975.cc: New test.
* testsuite/20_util/tuple/lwg3990.cc: New test.
* testsuite/20_util/variant/lwg3990.cc: New test.
Add the initial infrastructure required to support Dense Math Facility
(DMF) builtins.
Extend the builtin generator with a new "dm" stanza, ENB_DM enable flag,
DMR base type, and DM-specific builtin attributes used for Dense Math
builtins. Also add TARGET_DMF builtin enablement checks.
These changes provide the foundation for subsequent Dense Math builtin
support. The infrastructure is enabled only when TARGET_DMF is active
(for example, via -mdense-math) and targets a future Power ISA that may
or may not be be implemented in future Power processors and the builtin
interfaces may change accordingly.
2026-07-15 Peter Bergner <bergner@linux.ibm.com>
Kishan Parmar <kishan@linux.ibm.com>
gcc/ChangeLog
* config/rs6000/rs6000-builtin.cc (rs6000_invalid_builtin): Add
ENB_DM diagnostic.
(rs6000_builtin_is_supported): Handle ENB_DM.
* config/rs6000/rs6000-gen-builtins.cc: Update comments for new
Dense Math builtin attributes.
(bif_stanza): Add BSTZ_DM.
(stanza_map): Add "dm" stanza.
(enable_string): Add ENB_DM.
(basetype): Add BT_DMR.
(attrinfo): Add isdm, isdmint and isdmr fields.
(type_map): Add dmr1024 and ptr_dmr1024 type mappings.
(match_type): Recognize dmr1024 type.
(parse_bif_attrs): Parse dm, dmint and dmr attributes.
(complete_vector_type): Handle BT_DMR.
(write_decls): Emit ENB_DM and Dense Math builtin attribute bits
and predicates.
(write_bif_static_init): Initialize Dense Math builtin attributes
and associate dmint builtins with their internal variants.
libgfortran: Define macro to handle z length modifier in format strings
hppa64-hp-hpux* lacks the z length modifier. It specifies the following
integer conversion corresponds to a size_t or a ssize_t argument. The
size_t type is unsigned long on HP-UX, so we can replace the z length
modifier with l on HP-UX.
2026-06-10 John David Anglin <danglin@gcc.gnu.org>
On HP-UX, shm_open parses the name argument directly through file
system checks. As a result, we need a name that specifies a directory
with read, write and execute permisions. This differs from linux
where the name specifies the shared memory object to be created or
opened, and the shared object is identified by a name of the form
/somename.
We also limit the size of the shared objects to 1 GB on HP-UX.
The maximum JFS file size is 2 GB - 1 with the default nolargefiles
option in HP-UX 11.
Finally, we need to compile and link tests with the -pthread option
to ensure they are linked against libpthread.
2026-06-13 John David Anglin <danglin@gcc.gnu.org>
libgfortran/ChangeLog:
* caf/shmem/shared_memory.c (SHM_NAME_FMTD, SHM_NAME_FMTS): Define.
(shared_memory_init) Use SHM_NAME_FMTD format to generate
shm_name.
(shared_memory_cleanup): Use SHM_NAME_FMTS to generate shm_name.
* caf/shmem/supervisor.c (get_memory_size_from_envvar): Use
1 GB on 64-bit Windows and HP-UX.
gcc/testsuite/ChangeLog:
* gfortran.dg/coarray/caf.exp: Run test with -pthread option.
[PATCH v1] RISC-V: Share bases for scaled indexed addresses
riscv_legitimize_address handled scaled indexed addresses only when
the constant offset fit an I-type immediate. Large offsets fell back to
generic legalization and could materialize the same base at each
reference.
Use riscv_add_offset for all offsets before adding the scaled index.
This preserves small-offset code generation and exposes large bases to
CSE.
gcc/ChangeLog:
* config/riscv/riscv.cc (riscv_legitimize_address): Use
riscv_add_offset for scaled indexed addresses.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/large-frame-indexed-base.c: New test.
* gcc.target/riscv/small-frame-indexed-base.c: New test.
Andrew MacLeod [Tue, 14 Jul 2026 18:55:44 +0000 (14:55 -0400)]
Update ranger timestamps for inferred ranges.
If an inferred range is added for a name, mark the name as an updated
range to allow the dependency processing to pick up the change.
PR tree-optimization/126110
gcc/
* gimple-range-cache.cc (ranger_cache::mark_stale): Default defs
get a new timestamp to make them stale.
* gimple-range-infer.cc (infer_range_manager::add_range): When
an inferred range is added, mark the name as updated.
parse_arch tested "if (*m_loc)", dereferencing the location_t pointer,
while every other diagnostic site guards with "if (m_loc)". Since
m_loc can be NULL, test the pointer instead of dereferencing it.
gcc/ChangeLog:
* config/riscv/riscv-target-attr.cc
(riscv_target_attr_parser::parse_arch): Check m_loc instead of *m_loc
before emitting the diagnostic.
Jim Lin [Wed, 15 Jul 2026 19:55:57 +0000 (13:55 -0600)]
[PATCH] RISC-V: Fix GE/GEU zicond splitter emitting the wrong comparison
The splitter matching (x >= 1 ? 2^n : 0) lowered it to
tmp = (x > 1); result = tmp << n, emitting any_gt instead of any_ge.
At x == 1 the original yields 2^n but the split yields 0, a
miscompile. Emit any_ge to reproduce the matched comparison, as the
sibling GE/GEU splitters already do.
gcc/ChangeLog:
* config/riscv/zicond.md: Emit any_ge instead of any_gt in the
GE/GEU if-then-else splitter.
Thomas Koenig [Tue, 14 Jul 2026 16:58:36 +0000 (18:58 +0200)]
Fix some more issues with -Wunused-but-set and -Wundefined-vars.
The root cause for PR 126058 that was that sym->extra_loc was not
being set for possible allocations via allocatablearguments. Looking
at the code, a few more problems became clear: Not only INTENT(OUT)
arguments could allocate allocatables, all other INTENTS could do so
as well, but only if the formal arguments are allocatable as well.
Also, curent intrinsics do not have allocatable components.
During testing, there were also a few cases where, if one warning with
-Wall and one with -Wextra applied, the one with -Wextra was issued peferably.
This is slightly confusing, and also fixed with this patch.
gcc/fortran/ChangeLog:
PR fortran/126058
* gfortran.h (enum var_allocated): New enum.
(symbol_attribute): Change member allocated to new enum.
(gfc_used_in_allocate_expr): Add argument how.
* interface.cc (gfc_compare_actual_formal): Mark variables
as allocated only when the formal arg is allocatable.
* intrinsic.cc (mark_args_as_used): Intrinsics do not allocate
their arguments.
* resolve.cc (find_unused_vs_set): Move warnings enabled with
-Wextra behind those enabled with -Wall. If a variable is
maybe allocated as an argument, mark it as such.
* symbol.cc (mark_vars_as_used): Always set location.
(gfc_used_in_allocate_expr): Add argument how. Use it.
(gfc_lvalue_allocated_at): Set sym->attr.allocated to ALLOCATED_ASSIGNMENT.
gcc/testsuite/ChangeLog:
PR fortran/126058
* gfortran.dg/warn_undefined_vars_7.f90: New test.
* gfortran.dg/warn_unused_but_set_variable_4.f90: New test.
OpenMP: 'allocate' on 'target' with uses_allocators' def'ed allocator
This implements the tweaks required for
omp target uses_allocators(traits(...): my_alloc) allocate(my_alloc:...)
i.e. using an allocator variable in 'allocate' on target, which is
initialized via the 'uses_allocators' directive.
('allocate' on target may either use such an allocator or a predefined
allocator. Using a random allocator handle is rejected at compile time.)
gcc/ChangeLog:
* omp-low.cc (lower_private_allocate): When called on 'target'
and the allocator is a variable, obtain the device variable.
(lower_omp_target): Move processing of OMP_CLAUSE_USES_ALLOCATORS
on the device/receiver side in before the loop over clauses to
ensure the VALUE_EXPR points to uses_allocators's inited var.
libgomp/ChangeLog:
* testsuite/libgomp.c-c++-common/uses_allocators-10.c: New test.
gcc/testsuite/ChangeLog:
* c-c++-common/gomp/uses_allocators-3.c: New test.
Michal Jires [Mon, 11 May 2026 19:11:10 +0000 (21:11 +0200)]
lto: Fix cache partitioning to handle min_partition_size=0
Cache partitioning asserts that {min,max}_partition_size parameter
cannot be 0 to prevent later divisions by zero. This is needlessly
strict, we can clamp the value to 1 to get reasonable/expected behavior.
PR lto/125257
gcc/lto/ChangeLog:
* lto-partition.cc: Handle min/max_partition_size = 0 for
cache partitioning.
James K. Lowden [Wed, 15 Jul 2026 15:11:55 +0000 (11:11 -0400)]
cobol: Correct tests against uninitialized access and other incorrect behavior.
Some tests wrote to an input parameter to NUL-terminate a
filename. Some did not set RETURN-CODE to zero before
returning. MF-specific tests are now also tested with the gcobc script
to ensure compatibility.
gcc/cobol/ChangeLog:
* parse.y: Add debug messages during parameter validation.
* symbols.h: (cbl_ffi_arg_t::capacity_ok): New function.
libgcobol/ChangeLog:
* compat/gnu/lib/CBL_CREATE_FILE.cbl: Do not write to input parameter.
* compat/gnu/lib/CBL_OPEN_FILE.cbl: Same.
* C only: Fix an ICE on invalid for the allocator clause (undeclared
identifier); this is PR122748.
* C/C++: Mark trait variables read to avoid bogus 'unused but set'
warning with uses_allocators.
* libgomp.texi:
- Update implementation status for uses_allocators,
claim that C23 is supported (minus bugs), and remove comment
regarding a not-printed deprecation warning given that there
is now one.
- Memory Management Routines: Move 'omp_free' after the allocation
routines for internal consistency and in line with the spec.
Add '@c * omp_get_dyn_gprivate_...:: <fixme>/TR15' items to
'@menu' for the new TR15 routines (actually TR14 but renamed).
Hence, "grep '@c \*'" should yield all unimplemented or
undocumented 'omp_' functions as of TR15.
- nvptx: Fix an URL that was broken by Nvidia but the new one of
commit r17-1942-g0e2c5d4b2c16c4 wasn't helpful.
PR c/122748
gcc/c/ChangeLog:
* c-parser.cc (c_parser_omp_clause_allocate): Avoid ICE
when allocator is an error_mark_node.
(c_parser_omp_clause_uses_allocators): Mark trait var
as read to avoid 'unused but set' warning.
gcc/cp/ChangeLog:
* parser.cc (cp_parser_omp_clause_uses_allocators): Mark
trait var as read to avoid 'unused but set' warning.
libgomp/ChangeLog:
* libgomp.texi (Implementation status): Mark two
uses_allocators items and C23 support as 'Y';
remove outdated remark regarding a deprecation warning.
(Memory Management Routines): Move omp_free after
omp_realloc; add commented @menu entries for new
TR15 routines.
(nvptx): Update @uref to point to a better webpage.
gcc/testsuite/ChangeLog:
* c-c++-common/gomp/uses_allocators-1.c: New test.
* c-c++-common/gomp/uses_allocators-2.c: New test.
This patch addresses a code quality regression on x86_64 related to
PR 123236. That original PR (and the related PR 101266) concern tree
level optimizations, where this problem should also be fixed, but it
also reveals a regression in the RTL optimizers.
A motivating test case (on x86_64) is:
int bar(int a) {
long long t = a;
return t >> 4;
}
Currently -O2 generates a 64-bit shift:
bar: movslq %edi, %rax
sarq $4, %rax
ret
with this patch we now generate a 32-bit shift:
bar: movl %edi, %eax
sarl $4, %eax
ret
The underlying cause of the RTL-level regression is that some
RTL expressions that were previously expressed as {ZERO,SIGN}_EXTEND
are now sometimes represented as the equivalent {ZERO,SIGN}_EXTRACT,
and that not all simplifications of TRUNCATE({ZERO,SIGN}_EXTEND) are
implemented for TRUNCATE({ZERO,SIGN}_EXTRACT).
Thanks to Segher, simplify_rtx does handle some truncations of extracts,
see https://gcc.gnu.org/pipermail/gcc-patches/2016-November/463629.html
but unfortunately this code (and subsequent tweaks) doesn't quite match
the cases that appear here.
2026-07-15 Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
PR rtl-optimization/123236
* simplify-rtx.cc (simplify_context::simplify_truncation): Handle
cases where a ZERO_EXTRACT or SIGN_EXTRACT has a different mode
to (but at least as wide as) its first operand.
gcc/testsuite/ChangeLog
PR rtl-optimization/123236
* gcc.target/i386/pr123236-1.c: New test case.
Richard Biener [Wed, 15 Jul 2026 08:04:18 +0000 (10:04 +0200)]
tree-optimization/126171 - SCEV and minus of INT_MIN
The following fixes the existing mitigation against UB for handling
of subtraction of the most negative value in a type. We've only
guarded the negation itself which is effective for avoiding UB in
that but it does not help in fixing a wrong scev_direction that
results from flipping the operation from minus to plus. So the
patch, instead of only promoting the negation to unsigned, promotes
the whole operation.
PR tree-optimization/126171
* tree-scalar-evolution.cc (scev_dfs::add_to_evolution):
Remove code argument. Remove MINUS_EXPR handling here.
(scev_dfs::follow_ssa_edge_binary): Likewise.
(scev_dfs::follow_ssa_edge_expr): Handle MINUS_EXPR
separately here, promoting the whole operation to unsigned
instead of just the addend.
* gcc.dg/pr126171-1.c: New testcase.
* gcc.dg/torture/pr126171-2.c: Likewise.
Andrew Stubbs [Wed, 1 Jul 2026 14:36:55 +0000 (14:36 +0000)]
regrename: Handle MEM segments
This patch fixes the register rename pass to allow for MEM that have "segment"
elements in the address.
rtl.h and rtanal.h allow MEM addresses to have the format "segment + base +
offset", where "segment" is an arbitrary UNSPEC. Without the patch, regrename
misidentifies the base and can break 64-bit addresses, on targets with 32-bit
registers, by placing the high-part in a non-contiguous register.
gcc/ChangeLog:
* regrename.cc (scan_rtx_address): Recurse for segment UNSPECs.
Kito Cheng [Thu, 9 Jul 2026 14:16:55 +0000 (22:16 +0800)]
libstdc++: fix UB when ellint phi argument is infinity
When phi is +/-infinity, the periodicity-reduction step computes
std::floor(infinity) which returns infinity, then casts it to int.
That cast is undefined behavior per [conv.fpint] because infinity is
outside the range of int. A conforming compiler is free to exploit
this UB; in practice, Clang eliminates the loop-exit check and
produces an infinite loop. GCC currently does not exploit this
particular UB, but the cast is still undefined and should be fixed.
Fix by rejecting non-finite phi before the floor+cast and throwing
std::domain_error. NaN phi is already handled by the __isnan check
above, so the new guard only needs __builtin_isinf(phi); std::isfinite
is unavailable in the C++98 build of this header. Boost guards against
this by an overflow check (phi >= max_value<T>()), where -infinity is
first negated to +infinity by the sign-handling block[1].
* include/tr1/ell_integral.tcc (__ellint_1): Throw domain_error
when phi is not finite.
(__ellint_2): Likewise.
(__ellint_3): Likewise.
* testsuite/special_functions/11_ellint_1/check_inf.cc: New test.
* testsuite/special_functions/12_ellint_2/check_inf.cc: New test.
* testsuite/special_functions/13_ellint_3/check_inf.cc: New test.
Jonathan Wakely [Mon, 13 Jul 2026 16:57:50 +0000 (17:57 +0100)]
libstdc++: Fix std module to work with --disable-wchar_t [PR126111]
We should not try to export names which are not declared if GCC is
configured with --disable-wchar_t.
We should also not define the wide stream aliases in <syncstream> and
<spanstream>.
libstdc++-v3/ChangeLog:
PR libstdc++/126111
* include/std/format (__format::__write_escape_seq): Remove
unnecessary alias declaration.
* include/std/spanstream (wspanbuf, wispanstream, wospanstream)
(wspanstream): Only declare for _GLIBCXX_USE_WCHAR_T.
* include/std/syncstream (wsyncbuf wosyncstream): Likewise.
* src/c++23/std.cc.in: Add preprocessor checks for
_GLIBCXX_USE_WCHAR_T to names which depend on it.
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Luke Zhuang [Thu, 25 Jun 2026 05:45:16 +0000 (13:45 +0800)]
RISC-V: Declare TLSDESC clobbers for vector registers and CSRs per psABI
Per the RISC-V psABI, the TLSDESC resolver clobbers a0 and t0 in the
base case. With the new psABI update
(https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/496),
when the V extension is enabled, it additionally clobbers all vector
registers and vector CSRs.
This patch updates the clobbering of tlsdesc define_insn: clobbering
not only a0 and t0, but also all V-regs (using 4 x LMUL8 reg
groups covering all 32 physical V-regs), and 4 vector CSRs
(vl/vtype/vxrm/vxstat).
Three new tests are added covering GPR, vector register, and vector
CSR clobber behavior.
gcc/ChangeLog:
* config/riscv/riscv.md (VXSAT_REGNUM): New constant.
(@tlsdesc<mode>): update clobbering.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/tlsdesc_clobber.c: New test.
* gcc.target/riscv/tlsdesc_clobber_v.c: New test.
* gcc.target/riscv/tlsdesc_clobber_v_csr.c: New test.
H.J. Lu [Mon, 13 Jul 2026 01:12:13 +0000 (09:12 +0800)]
x86-64: Add missing SSE and AVX zero-extend patterns
1. Add round_zext and round_saeonly_zext to subst.md.
2. Use them to add missing SSE and AVX zero-extend patterns.
3. Add tests to check for newly added SSE and AVX zero-extend patterns.
The x+x -> x*2 simplication obviously requires that 2 is representable
in type, so that rules out unsigned _BitInt(1) and signed _BitInt(2)
(and 1 too in C2Y, ditto unsigned:1 and signed:2 and :1), otherwise
we don't multiply by 2 but by 0 or -2.
While perhaps we could transform in those cases x+x to x<<1, I'm not
convinced it is worth it.
2026-07-15 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/126257
* match.pd (x+x -> x*2): Only optimize if 2 is representable in the
type.
Jakub Jelinek [Wed, 15 Jul 2026 07:21:41 +0000 (09:21 +0200)]
c++: In attributes expect _Clang namespace rather than __clang__ [PR120635]
Apparently in clang __clang__ is a predefined macro (predefined to 1).
Because of that, clang doesn't have alternate spelling of its scoped
attributes as
[[__clang__::__something__]]
but
[[_Clang::__something__]]
The former isn't accepted even with -U__clang__.
For GNU attributes they do handle
[[__gnu__::__something__]]
like GCC does (if they support a particular attribute).
So, I'm afraid if we want to stay compatible with this mess, we need
to do the same thing.
The following patch does that.
It emits a warning when one attempts to use the __clang__ attribute
namespace suggesting to use _Clang instead (clang++ does that too),
but in __has_cpp_attribute/__has_attribute doesn't do that, just ensures
that 0 is returned in that case (i.e. it is not canonicalized in that
case), just canonicalizes _Clang to clang.
2026-07-15 Jakub Jelinek <jakub@redhat.com>
PR c++/120635
gcc/
* doc/extend.texi: Document variant spelling of
standard attributes and that alternate namespace
spelling for clang namespace is _Clang rather
than __clang__. For no_specializations use
_Clang:: rather than __clang__::.
gcc/c-family/
* c-lex.cc (c_common_has_attribute): For __clang__
namespace don't call canonicalize_attr_name and for
_Clang use clang instead.
gcc/cp/
* parser.cc (cp_parser_std_attribute): Add
canonicalize_attr_ns_name lambda and use it instead of
canonicalize_attr_name for namespaces. Emit a warning
on __clang__::.
(cp_parser_std_attribute_spec): Emit a warning on
using __clang__:.
gcc/testsuite/
* g++.dg/cpp0x/attr-trivial_abi8.C: Add further tests.
* g++.dg/cpp0x/attr-trivial_abi11.C: New test.
* g++.dg/ext/attr-no_specializations1.C: Use _Clang:: instead of
__clang__.
* g++.dg/ext/attr-no_specializations2.C: Likewise.
* g++.dg/ext/attr-no_specializations6.C: Likewise.
* g++.dg/ext/attr-no_specializations7.C: Likewise.
* g++.dg/ext/attr-no_specializations8.C: Likewise.
* g++.dg/ext/attr-no_specializations10.C: Add further tests.
* g++.dg/ext/attr-no_specializations12.C: New test.
When 'device_type(host)' is specified on a target region, no offload code
is generated for the outlined region. Additionally, it is honored for
implicit 'declare target'.
The code is executed as if 'device(omp_initial_device)' were present
(i.e. also no issus with OMP_TARGET_OFFLOAD=mandatory).
gcc/ChangeLog:
* omp-expand.cc (expand_omp_target): For 'device_type(host)',
invoke with device(omp_initial_device)'.
* omp-low.cc (create_omp_child_function): Take host_only
argument to prevent generating offload code.
(scan_omp_parallel, scan_omp_task, scan_omp_target, scan_omp_teams,
lower_omp_target): Update call.
* omp-offload.cc (omp_discover_declare_target_tgt_fn_r,
omp_discover_declare_target_fn_r): Do not add implicit 'declare
target' to target regions with 'device_type(host)'.
libgomp/ChangeLog:
* libgomp.texi (Implementations status): Mark 'device_type'
clause on target as implemented.
* testsuite/libgomp.c/target-device-type-3.c: New test.
middle-end: use tree mode for masked cbranch operand [PR126221]
emit_cmp_and_jump_insns used GET_MODE (expand_normal (masked_op)) to select the
mask mode. For vector boolean constants that expand to CONST_INT, this produces
VOIDmode and triggers the assert mode != VOID_mode in maybe_legitimize_operand.
Use TYPE_MODE (TREE_TYPE (masked_op)), so the constant can be materialized in
the right mask mode.
gcc/ChangeLog:
PR middle-end/126203
PR middle-end/126221
PR middle-end/126232
* optabs.cc (emit_cmp_and_jump_insns): Take the masked_op mode
from TREE_TYPE (masked_op).
The parsing support was already there, this just adds code to handle
'nohost' in the middle end.
That's handled by adding if-else code to the target's structure block
using the omp_is_initial_device builtin in the condition that is
replaced by a constant (late) during compilation. Thus, with optimization
turned on, only the error message or the target body remains for the host
and the nonhost region, respectively.
Note that 'device_type(host)' is not yet implemented.
Note also there is no change to implicit handling, i.e. functions called
in the region will implicitly 'declare target' with 'device_type(any)',
i.e. there is no attempt made to add those with 'nohost', which is also
the most sensible.
gcc/ChangeLog:
* gimplify.cc (gimplify_omp_workshare): Handle 'device_type(nohost)'
on 'target'.
* omp-low.cc (lower_omp_target): Remove sorry for this case.
libgomp/ChangeLog:
* error.c (GOMP_error): When passing msglen == (size_t) -2,
do not show 'error directive encountered:' in the message.
* libgomp.texi (Implementation Status): Mark target + device_type
as partially implemented.
* testsuite/libgomp.c/target-device-type-1.c: New test.
* testsuite/libgomp.c/target-device-type-2.c: New test.
gcc/testsuite/ChangeLog:
* c-c++-common/gomp/target-device-type-1.c: Update dg-sorry
as now only device_type(host) remains unimplemented.
* gfortran.dg/gomp/target-device-type-1.f90: Likewise.
In some of the older testcases, the main function is declared like
main (int, void **). It is frequently useful (especially with the
Darwin port) to compare the output of clang with that of GCC (since
clang is the de-facto standard for Objective-C). Clang complains
about the void** so let's set that to be char ** as usual.
Karl Meakin [Wed, 1 Jul 2026 12:16:40 +0000 (12:16 +0000)]
aarch64: Relax type-checking assert [PR126064]
Comparing `arg_type` and `TREE_TYPE (b)` by pointer address causes an
assertion failure when one type is a `typedef` for the other (eg
`uint32x2_t` and `__Uint32x2_t`. Fix by using a more relaxed comparison.
gcc/ChangeLog:
PR target/126064
* config/aarch64/aarch64-neon-builtins-base.cc: Compare
`arg_type` and `TREE_TYPE (b)` using `types_compatible_p` rather
than comparing their pointer addresses.
gcc/testsuite/ChangeLog:
PR target/126064
* gcc.target/aarch64/pr126064.c: New test.
Add arm_v8_1m_mve_link to check that the options selected by
arm_v8_1m_mve_ok can link successfully.
Without a link test, the board specific ldflags might contain flags that
are incompatible with the linkage of the test case, for example the
built testglue.c from dejagnu is known to cause issues.
Cem Akgok [Mon, 13 Jul 2026 14:21:46 +0000 (17:21 +0300)]
vect: Fix wrong code with SLP IV reuse [PR126225]
vectorizable_induction reduces the number of generated SLP induction
IVs when group_size is evenly divisible by const_nunits. Existing
code did this without checking that the vector chunks being folded have
the same scalar initial values and steps with their counterparts.
If either differed, reusing an earlier IV produced wrong code.
Compute the unreduced IV count first and use the reduced count only when
each folded chunk has initial values and steps equal to its corresponding
earlier chunk.
Added tests for mismatched initial values, mismatched steps, and a valid
multi-IV reuse pattern.
gcc/ChangeLog:
PR tree-optimization/126225
* tree-vect-loop.cc (vect_slp_induction_reuse_p): New function.
(vectorizable_induction): Validate SLP induction IV reuse. Reuse
generated IVs cyclically when filling the SLP group.
gcc/testsuite/ChangeLog:
PR tree-optimization/126225
* gcc.dg/vect/vect-iv-12.c: New test.
* gcc.dg/vect/vect-iv-13.c: New test.
* gcc.dg/vect/vect-iv-14.c: New test.
Compute kth weight using __fw(_M_int[k]) as required by standard,
instead of __fw(_M_int[k] + __delta), i.e. __fw(_M_int[k + 1]).
For __nw == 1, this was already corrected by r17-509-g7bed7d9276c11b.
In both cases, previous behavior can be restored by defining
_GLIBCXX_USE_OLD_PIECEWISE_DISTRIBUTIONS.
Tomasz Kamiński [Tue, 26 May 2026 13:43:00 +0000 (15:43 +0200)]
libstdc++: Change piecewise distribution densities to return vector<result_type> [PR82749]
This implements the interface changes from
LWG1439, "Return from densities() functions?".
Due the ABI concerns, we cannot change the the element_type of member
(_M_den, _M_cp, and _M_m) vectors, and we convert the _M_den values
to result_type when function is invoked. However, as the usage of
distributions with types other than float, double, and long double
is either undefined (pre C++26) or implementaiton-defined (post C++26),
this limitation de-fact applies to float, and long double (if it's
different size than double).
To handle above we introduce the __piecewise_distributions_storage<_Tp>
struct, whose type nested typedef points to double in above two cases,
and _Tp otherwise. The _StorageType is defined in terms of
__piecewise_distributions_storage_t alias to above, and is then used
in defintion of _M_den, _M_cp, and _M_m members. In consequence for
extended floating point types (__float128, std::float16, ...) for which
ABI can be changed, we store densitiees (and other values) as result_type.
To avoid symbol conflicts, the param_type::densities member functions
are marked with "__rt" ABI tag. The corresponding members of the
distributions are modified to invoke param_type method, and marked
as always_inline. For consistency intervals methods are adjusted same
way.
To preserve current behavior, the operators>> load densities
as values of _StorageType.
Finally, we introduce _GLIBCXX_USE_OLD_PICEWISE_DISTRIBUTIONS, that
revers above changes, restoring old behavior for all floating point
types. Additionally for the users accept above ABI change,
we introduce a macro _GLIBCXX_USE_RESULT_TYPE_FOR_PIECEWISE_DENSITIES,
that result in __piecewise_distributions_storage_t being unconditionally
defined as _Tp, and thus adjust internal storage also for float and long
double.
PR libstdc++/82749
libstdc++-v3/ChangeLog:
* doc/xml/manual/using.xml
(_GLIBCXX_USE_OLD_PICEWISE_DISTRIBUTIONS): Add entry.
(_GLIBCXX_USE_RESULT_TYPE_FOR_PIECEWISE_DENSITIES): Add entry.
* doc/html/manual/using_macros.html: Regenerate.
* include/bits/random.h
(__detail::__piecewise_distributions_storage)
(__detail::__piecewise_distributions_storage_t)
(piecewise_constant_distribution::_StorageType)
(piecewise_linear_distribution::_StorageType): Define.
(piecewise_constant_distribution::param_type::_M_den)
(piecewise_constant_distribution::param_type::_M_cp)
(piecewise_linear_distribution::param_type::_M_den)
(piecewise_linear_distribution::param_type::_M_cp)
(piecewise_linear_distribution::param_type::_M_m): Use _StorageType
as element type.
(piecewise_constant_distribution::param_type::densities)
(piecewise_linear_distribution::param_type::densities)
[!_GLIBCXX_USE_OLD_PICEWISE_DISTRIBUTIONS]: Change return type
to vector<result_type>, mark with "__rt" ABI tag, and adjust
implementation.
(piecewise_constant_distribution::param_type::intervals)
(piecewise_linear_distribution::param_type::intervals): Use
result_type alias in return type.
(piecewise_constant_distribution::densities)
(piecewise_linear_distribution::densities): Delegate to param_type
method, additional change return type and mark as always_inline
if _GLIBCXX_USE_OLD_PICEWISE_DISTRIBUTIONS is not defined.
(piecewise_constant_distribution::intervals)
(piecewise_linear_distribution::intervals): Delegate to param_type
method and use result_type alias in return type.
* include/bits/random.tcc
(operator<<(basic_ostream&, const piecewise_constant_distribution&))
(operator<<(basic_ostream&, const piecewise_linear_distribution&)):
Parse vector of _StorageType for densities, to preserve behavior.
* testsuite/26_numerics/random/piecewise_constant_distribution/operators/accessors.cc:
New test.
* testsuite/26_numerics/random/piecewise_linear_distribution/operators/accessors.cc:
New test.
* testsuite/26_numerics/random/piecewise_constant_distribution/operators/accessors_exact.cc:
Run accessors.cc with _GLIBCXX_USE_RESULT_TYPE_FOR_PIECEWISE_DENSITIES.
* testsuite/26_numerics/random/piecewise_linear_distribution/operators/accessors_exact.cc:
Likewise.
* testsuite/26_numerics/random/piecewise_constant_distribution/operators/accessors_fallback.cc:
Run accessors.cc with _GLIBCXX_USE_OLD_PICEWISE_DISTRIBUTIONS.
* testsuite/26_numerics/random/piecewise_linear_distribution/operators/accessors_fallback.cc:
Likewise.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
Jakub Jelinek [Tue, 14 Jul 2026 08:41:08 +0000 (10:41 +0200)]
c-family: Use CAS loop instead of RMW atomics on small _BitInt with padding on targets which need to extend [PR124948]
Some atomic/sync builtins don't sign or zero extend _BitInt values
with padding in it.
IMNSHO this is solely about some of the type-generic atomic/sync builtins
(those documented to take TYPE * arguments) and needs to be handled in the
FE, likely in gcc/c-family/c-common.cc (resolve_overloaded_builtin).
There already is code to transform various type-generic builtins into a CAS
loop for say unsigned _BitInt(253), so I think it should be used also for
the case where the type is BITINT_TYPE with any padding bits in the
extend other than bitint_ext_undef mode.
2026-07-14 Jakub Jelinek <jakub@redhat.com>
PR target/124948
* c-common.cc (sync_resolve_size): Return -1 for fetch ops
on _BitInt types with padding bits where the target requires
extension into the padding bits.
(atomic_bitint_fetch_using_cas_loop): Handle also __sync_*
fetch builtins.
tree-optimization: Fold length-one memset through arbitrary pointers [PR102202]
gimple_fold_builtin_memset currently folds constant-length memset calls
into scalar stores only when the destination is an ADDR_EXPR. Calls
through an arbitrary pointer, such as a function parameter are left as
library calls and non-constant fill values are rejected even for the
length-one case where byte replication is unnecessary.
Add a dedicated folding path for length-one memset calls through
arbitrary pointer destinations. Since the access is exactly one byte,
use unsigned_char_type_node for the store. This supports both constant
and non-constant fill values: constant fills are converted with
fold_convert while non-constant fills use gimple_convert. Volatile
qualification is preserved from the pointed-to type and the store is
emitted as a MEM_REF at offset zero using the usual ref-all character
pointer type.
Defer this new arbitrary-pointer fold until after object-size analysis
has run so that the original memset remains available to object-size
based diagnostics. The existing ADDR_EXPR-based folding path for other
constant lengths is unchanged.
gcc/ChangeLog:
PR tree-optimization/102202
* gimple-fold.cc (gimple_fold_builtin_memset): Hoist
tree_to_uhwi (len) before the INTEGER_CST guard. Fold
length-one memset calls through arbitrary pointer destinations.
Build a ref-all MEM_REF at offset zero and preserve the call
result when it is used.
gcc/testsuite/ChangeLog:
PR tree-optimization/102202
* gcc.dg/pr102202-fold.c: New test.