]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
2 weeks agotestsuite: arm: Simplify fp16-aapcs tests
Torbjörn SVENSSON [Wed, 27 Aug 2025 14:25:14 +0000 (16:25 +0200)] 
testsuite: arm: Simplify fp16-aapcs tests

Reduce fp16-aapcs testcases to return value testing since parameter
passing are already tested in aapcs/vfp*.c

gcc/testsuite/ChangeLog:
* gcc.target/arm/fp16-aapcs.c: New test.
* gcc.target/arm/fp16-aapcs-1.c: Removed.
* gcc.target/arm/fp16-aapcs-2.c: Likewise.
* gcc.target/arm/fp16-aapcs-3.c: Likewise.
* gcc.target/arm/fp16-aapcs-4.c: Likewise.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2 weeks agolibgomp: Init hash table for 'indirect'-clause of 'declare target' on the host [PR114...
Tobias Burnus [Wed, 17 Sep 2025 06:47:36 +0000 (08:47 +0200)] 
libgomp: Init hash table for 'indirect'-clause of 'declare target' on the host [PR114445, PR119857]

Especially with unified-shared memory and especially with C++'s virtual
functions, it is not uncommon to have on the device a function pointer
that points to the host function - but has an associated device.
If the pointed-to function is (explicitly or implicitly) 'declare target'
with the 'indirect' clause, it is added to the lookup table.

Before this commit, the conversion of the lookup table into a lookup
hash table happened every time a device kernel was launched on the first
team - albeit if already converted, the function immediately returned.

Ignoring the overhead, there was also a race: If multiple teams were
launched, it could happen that another team of the same target region
already tried to use the lookup table which it was still being created.
Likewise when lauching a kernel with 'nowait' and directly afterward
another kernel, there could be a race of creating the table.

With this commit, the creating of the kernel has been moved to the
host-plugin's GOMP_OFFLOAD_load_image. The previous code stored a
pointer to the host/device pointer array, which makes it hard when
creating the hash table on the host (data is needed for finding the
slot) - but accessing it on the device (where the lookup has to work
as well). As the hash-table implementation (only) supports integral
value as payload (0 and 1 having special meaning), the solution was
to move to an uint128_t variable to store both the host and device
address.

As the host-side library is typically dynamically linked and the
device-side one statically, there is the problem of backward
compatibility. The current implementation permits both older
binaries and newer libgomp and newer binaries with older libgomp.
I could imagine us breaking the latter eventually, but for now
there is up and downward compatibility. (Obviously, the race is
only fixed if new + new is combined.)

Code wise, on the device exist GOMP_INDIRECT_ADDR_MAP which was
updated to point to the host/device-address array. Now additionally
GOMP_INDIRECT_ADDR_HMAP exists, which contains the hash-table map.

If the latter exists, libgomp only updates it and the former remains
a NULL pointer; it is also untouched if there are no indirect functions.
Being NULL therefore avoids the call to the device-side build_indirect_map.
The code also currently supports to have no hash and a linear walk. I think
that remained from testing; due to the backward-compat feature, it can
actually be turned of on either side.

libgomp/ChangeLog:

PR libgomp/119857
PR libgomp/114445
* config/accel/target-indirect.c: Change to use uint128_t instead
of a struct as data structure and add GOMP_INDIRECT_ADDR_HMAP as
host-accessible variable.
(struct indirect_map_t): Remove.
(USE_HASHTAB_LOOKUP, INDIRECT_DEV_ADDR, INDIRECT_HOST_ADDR,
SET_INDIRECT_HOST_ADDR, SET_INDIRECT_ADDRS): Define.
(htab_free): Use __builtin_unreachable.
(htab_hash, htab_eq, GOMP_target_map_indirect_ptr,
build_indirect_map): Update for new representation and new
pointer-to-hash variable.
* config/gcn/team.c (gomp_gcn_enter_kernel): Only call
build_indirect_map when GOMP_INDIRECT_ADDR_MAP.
* config/nvptx/team.c (gomp_nvptx_main): Likewise.
* libgomp-plugin.h (GOMP_INDIRECT_ADDR_HMAP): Define.
* plugin/plugin-gcn.c: Conditionally include
build-target-indirect-htab.h.
(USE_HASHTAB_LOOKUP_FOR_INDIRECT): Define.
(create_target_indirect_map): New prototype.
(GOMP_OFFLOAD_load_image): Update to create the device's
indirect-function hash table on the host.
* plugin/plugin-nvptx.c: Conditionally include
build-target-indirect-htab.h.
(USE_HASHTAB_LOOKUP_FOR_INDIRECT): Define.
(create_target_indirect_map): New prototype.
(GOMP_OFFLOAD_load_image): Update to create the device's
indirect-function hash table on the host.
* plugin/build-target-indirect-htab.h: New file.

2 weeks agolibgomp: Add Fortran version of acc_copyout_finalize_async and acc_delete_finalize_async
Tobias Burnus [Wed, 17 Sep 2025 06:42:59 +0000 (08:42 +0200)] 
libgomp: Add Fortran version of acc_copyout_finalize_async and acc_delete_finalize_async

OpenACC 2.5 added several functions for C and Fortran; while
acc_{copyout,delete}{,_finalize,_async} exist for both, for some
reasons only the C version of acc_{copyout,delete}_finalize_async
was actually added, even though the documentation (.texi) and
the .map file listed also the auxiliar Fortran functions!

OpenACC 2.5 added the Fortran version with the following odd
interface:  'type, dimension(:[,:]...)'. In OpenACC 2.6, it
was then updated to the Fortran 2018 syntax:
'type(*), dimension(..)', which is also used in openacc.f90
internally.
This commit now also updates the documentation to the newer
syntax - plus fixes a function-name typo: acc_delete_async_finalize
should have the _async at the end not in the middle!

libgomp/ChangeLog:

* libgomp.map (OACC_2.5): Move previously unimplemented
acc_{copyout,delete}_finalize_async_{32,64,array}_h_ to ...
(OACC_2.6.1): ... here.
* libgomp.texi (acc_copyin, acc_present_or_copyin, acc_create,
acc_present_or_create, acc_copyout, acc_update_device,
acc_update_self, acc_is_present): Use 'type(*), dimension(..)'
instead of 'type, dimension(:[,:]...)' for Fortran.
(acc_delete): Likewise; change acc_delete_async_finalize to
acc_delete_finalize_async.
* openacc.f90 (openacc_internal): Add interfaces for
acc_{copyout,delete}_finalize_async_{{32,64,array}_h,_l}.
(openacc): Add generic interfaces for
acc_copyout_finalize_async and acc_delete_finalize_async.
(acc_{copyout,delete}_finalize_async_{32,64,array}_h): New.
* openacc_lib.h: Add generic interfaces for
acc_copyout_finalize_async and acc_delete_finalize_async.
* testsuite/libgomp.oacc-fortran/pr92970-1.f90: New test.

2 weeks agoRISC-V: Add test for vec_duplicate + vwmulu.vv signed combine with GR2VR cost 0,...
Pan Li [Fri, 12 Sep 2025 13:43:52 +0000 (21:43 +0800)] 
RISC-V: Add test for vec_duplicate + vwmulu.vv signed combine with GR2VR cost 0, 1 and 15

Add asm dump check and run test for vec_duplicate + vwmulu.vv
combine to vwmulu.vx, with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c: Add asm check
for vwmulu.vx.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_widen.h: Add test helper
macros.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_widen_data.h: Add test
data for vwmulu.vx run test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vwmulu-run-1-u64.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 weeks agoRISC-V: Add test for vec_duplicate + vwsubu.vv signed combine with GR2VR cost 0,...
Pan Li [Fri, 12 Sep 2025 13:03:32 +0000 (21:03 +0800)] 
RISC-V: Add test for vec_duplicate + vwsubu.vv signed combine with GR2VR cost 0, 1 and 15

Add asm dump check and run test for vec_duplicate + vwsubu.vv
combine to vwsubu.vx, with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c: Add asm check
for vwsubu.vx.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_widen.h: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_widen_data.h: Add test
data for run test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vwsubu-run-1-u64.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 weeks agoRISC-V: Add test for vec_duplicate + vwaddu.vv signed combine with GR2VR cost 0,...
Pan Li [Fri, 12 Sep 2025 11:57:28 +0000 (19:57 +0800)] 
RISC-V: Add test for vec_duplicate + vwaddu.vv signed combine with GR2VR cost 0, 1 and 15

Add asm dump check and run test for vec_duplicate + vwaddu.vv
combine to vwaddu.vx, with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c: Add asm check
for vwaddu.vx.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vwaddu-run-1-u64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_widen.h: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_widen_data.h: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_widen_vx_run.h: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 weeks agoRISC-V: Combine vec_duplicate + vwaddu.vv to vwaddu.vx on GR2VR cost
Pan Li [Fri, 12 Sep 2025 08:43:00 +0000 (16:43 +0800)] 
RISC-V: Combine vec_duplicate + vwaddu.vv to vwaddu.vx on GR2VR cost

This patch would like to combine the vec_duplicate + vwaddu.vv to the
vwaddu.vx.  From example as below code.  The related pattern will depend
on the cost of vec_duplicate from GR2VR.  Then the late-combine will
take action if the cost of GR2VR is zero, and reject the combination
if the GR2VR cost is greater than zero.

Assume we have example code like below, GR2VR cost is 0.

Before this patch:
  11       beq a3,zero,.L8
  12       vsetvli a5,zero,e32,m1,ta,ma
  13       vmv.v.x v2,a2
  ...
  16   .L3:
  17       vsetvli a5,a3,e32,m1,ta,ma
  ...
  22       vwaddu.vv v1,v2,v3
  ...
  25       bne a3,zero,.L3

After this patch:
  11       beq a3,zero,.L8
  ...
  14    .L3:
  15       vsetvli a5,a3,e32,m1,ta,ma
  ...
  20       vwaddu.vx v1,a2,v3
  ...
  23       bne a3,zero,.L3

The pattern of this patch only works on DImode, aka below pattern.
v1:RVVM1DImode = (zero_extend:RVVM1DImode v2:RVVM1SImode)
  + (vec_dup:RVVM1DImode (zero_extend:DImode x2:SImode));

Unfortunately, for uint16_t to uint32_t or uint8_t to uint16_t, we loss
this extend op after expand.

For uint16_t => uint32_t we have:
(set (reg:SI 149) (subreg/s/v:SI (reg/v:DI 146 [ rs1 ]) 0))

For uint32_t => uint64_t we have:
(set (reg:DI 148 [ _6 ])
     (zero_extend:DI (subreg/s/u:SI (reg/v:DI 146 [ rs1 ]) 0)))

We can see there is no zero_extend for uint16_t to uint32_t, and we
cannot hit the pattern above.  So the combine will try below pattern
for uint16_t to uint32_t.

v1:RVVM1SImode = (zero_extend:RVVM1SImode v2:RVVM1HImode)
  + (vec_dup:RVVM1SImode (subreg:SIMode (:DImode x2:SImode)))

But it cannot match the vwaddu sematics, thus we need another handing
for the vwaddu.vv for uint16_t to uint32_t, as well as the uint8_t to
uint16_t.

gcc/ChangeLog:

* config/riscv/autovec-opt.md (*widen_first_<any_extend:su>_vx_<mode>):
Add helper bridge pattern for vwaddu.vx combine.
(*widen_<any_widen_binop:optab>_<any_extend:su>_vx_<mode>): Add
new pattern to match vwaddu.vx combine.
* config/riscv/iterators.md: Add code attr to get extend CODE.
* config/riscv/vector-iterators.md: Add Dmode iterator for
widen.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 weeks agoi386/testsuite: Correct res_ref2 array size for avx512bw-vpmov{,us}wb-2.c
Haochen Jiang [Tue, 16 Sep 2025 06:40:12 +0000 (14:40 +0800)] 
i386/testsuite: Correct res_ref2 array size for avx512bw-vpmov{,us}wb-2.c

Both of the tests under 128 bit are raising:

warning: writing 16 bytes into a region of size 8 [-Wstringop-overflow=]

when compiling, leading to a test fail. The warning is caused by the
incorrect array size for res_ref2. The wrong size caused the overflow.

Correct them in this patch to fix the test fail.

gcc/testsuite/ChangeLog:

* gcc.target/i386/avx512bw-vpmovuswb-2.c: Correct res_ref2
array size.
* gcc.target/i386/avx512bw-vpmovwb-2.c: Ditto.

2 weeks agoi386/testsuite: Fix scan tree dump in vect-epilogue-4.c
Haochen Jiang [Tue, 16 Sep 2025 07:42:11 +0000 (15:42 +0800)] 
i386/testsuite: Fix scan tree dump in vect-epilogue-4.c

vect-epilogue-4.c uses mask 64 byte to vectorize in epilogue part.
Similar as r16-876 fix for vect-epilogue-5.c, we need to adjust the
scan tree dump.

gcc/testsuite/ChangeLog:

* gcc.target/i386/vect-epilogues-4.c: Fix for epilogue
vect tree dump.

2 weeks agolibstdc++: Explicitly pass -Wsystem-headers in tests that need it
Patrick Palka [Wed, 17 Sep 2025 00:59:10 +0000 (20:59 -0400)] 
libstdc++: Explicitly pass -Wsystem-headers in tests that need it

When running libstdc++ tests using an installed gcc (as opposed to an
in-tree gcc), we naturally use system stdlib headers instead of the
in-tree headers.  But warnings from within system headers are suppressed
by default, so tests that check for such warnings spuriously fail in such
a setup.  This patch makes us compile such tests with -Wsystem-headers so
that they consistently pass.

libstdc++-v3/ChangeLog:

* testsuite/20_util/bind/dangling_ref.cc: Compile with
-Wsystem-headers.
* testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Likewise.
* testsuite/20_util/unique_ptr/lwg4148.cc: Likewise.
* testsuite/29_atomics/atomic/operators/pointer_partial_void.cc:
Likewise.
* testsuite/30_threads/packaged_task/cons/dangling_ref.cc:
Likewise.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2 weeks agoDaily bump.
GCC Administrator [Wed, 17 Sep 2025 00:20:31 +0000 (00:20 +0000)] 
Daily bump.

2 weeks agoc: Reject gimple and rtl functions as needed functions [PR121421]
Andrew Pinski [Tue, 16 Sep 2025 05:37:44 +0000 (22:37 -0700)] 
c: Reject gimple and rtl functions as needed functions [PR121421]

These two don't make sense as nested functions as they both don't handle
the unnesting and/or have support for the static chain.

So let's reject them.

Bootstrapped and tested on x86_64-linux-gnu.

PR c/121421

gcc/c/ChangeLog:

* c-parser.cc (c_parser_declaration_or_fndef): Error out for gimple
and rtl functions as nested functions.

gcc/testsuite/ChangeLog:

* gcc.dg/gimplefe-error-16.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2 weeks agodocs: Adjust -Wimplicit-fallthrough= documentation for C23
Jakub Jelinek [Tue, 16 Sep 2025 17:25:58 +0000 (19:25 +0200)] 
docs: Adjust -Wimplicit-fallthrough= documentation for C23

I've noticed in -Wimplicit-fallthrough= documentation we talk about
[[fallthrough]]; for C++17 but don't mention that it is also standard
way to suppress the warning for C23.

2025-09-16  Jakub Jelinek  <jakub@redhat.com>

* doc/invoke.texi (Wimplicit-fallthrough=): Document that also C23
provides a standard way to suppress the warning with [[fallthrough]];.

2 weeks agolibstdc++: Optimize determination of std::tuple_cat return type
Jonathan Wakely [Tue, 16 Sep 2025 11:00:19 +0000 (12:00 +0100)] 
libstdc++: Optimize determination of std::tuple_cat return type

The std::tuple_cat function has to determine a std::tuple return type
from zero or more tuple-like arguments. This uses the __make_tuple class
template to transform a tuple-like type into a std::tuple, and the
__combine_tuples class template to combine zero or more std::tuple types
into a single std::tuple type.

This change optimizes the __make_tuple class template to use an
_Index_tuple and pack expansion instead of recursive instantiation, and
optimizes __combine_tuples to use fewer levels of recursion.

For ranges::adjacent_view's __detail::__repeated_tuple helper we can
just use the __make_tuple class template directly, instead of doing
overload resolution on std::tuple_cat to get its return type.

libstdc++-v3/ChangeLog:

* include/std/ranges (__detail::__repeated_tuple): Use
__make_tuple helper alias directly, instead of doing overload
resolution on std::tuple_cat.
* include/std/tuple (__make_tuple_impl): Remove.
(__do_make_tuple): Replace recursion with _Index_tuple and pack
expansion.
(__make_tuple): Adjust to new __do_make_tuple definition.
(__combine_tuples<tuple<T1s...>, tuple<T2s...>, Rem...>): Replace
with a partial specialization for exactly two tuples and a
partial specialization for three or more tuples.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2 weeks agolibstdc++: ranges::rotate should not use 'auto' with ranges::iter_move [PR121913]
Jonathan Wakely [Thu, 11 Sep 2025 16:39:43 +0000 (17:39 +0100)] 
libstdc++: ranges::rotate should not use 'auto' with ranges::iter_move [PR121913]

The r16-3835-g7801236069a95c change to use ranges::iter_move should also
have used iter_value_t<_Iter> to ensure we get an object of the value
type, not a proxy reference.

libstdc++-v3/ChangeLog:

PR libstdc++/121913
* include/bits/ranges_algo.h (__rotate_fn::operator()): Use
auto_value_t<_Iter> instead of deduced type.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2 weeks agolibstdc++: Fix missing change to views::pairwise from P2165R4 [PR121956]
Jonathan Wakely [Tue, 16 Sep 2025 12:41:20 +0000 (13:41 +0100)] 
libstdc++: Fix missing change to views::pairwise from P2165R4 [PR121956]

ranges::adjacent_view::_Iterator::value_type should have been changed by
r14-8710-g65b4cba9d6a9ff to always produce std::tuple, even for the
N == 2 views::pairwise specialization.

libstdc++-v3/ChangeLog:

PR libstdc++/121956
* include/std/ranges (adjacent_view::_Iterator::value_type):
Always define as std::tuple<T, N>, not std::pair<T, T>.
* testsuite/std/ranges/adaptors/adjacent/1.cc: Check value type
of views::pairwise.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2 weeks agoxtensa: Simplify the definition of REGNO_OK_FOR_BASE_P() and avoid calling it directly
Takayuki 'January June' Suwa [Tue, 16 Sep 2025 00:42:50 +0000 (09:42 +0900)] 
xtensa: Simplify the definition of REGNO_OK_FOR_BASE_P() and avoid calling it directly

In recent gcc versions, REGNO_OK_FOR_BASE_P() is not called directly, but
rather via regno_ok_for_base_p() which is a wrapper in gcc/addresses.h.
The wrapper obtains a hard register number from pseudo via reg_renumber
array, so REGNO_OK_FOR_BASE_P() does not need to take this into
consideration.

On the other hand, since there is only one use of REGNO_OK_FOR_BASE_P()
in the target-specific code, it would make more sense to simplify the
definition of REGNO_OK_FOR_BASE_P() and replace its call with that of
regno_ok_for_base_p().

gcc/ChangeLog:

* config/xtensa/xtensa.cc (#include):
Add "addresses.h".
* config/xtensa/xtensa.h (REGNO_OK_FOR_BASE_P):
Simplify to just a call to GP_REG_P().
(BASE_REG_P): Replace REGNO_OK_FOR_BASE_P() with the equivalent
call to regno_ok_for_base_p().

2 weeks agoAArch64: Add isnan expander [PR 66462]
Wilco Dijkstra [Thu, 4 Sep 2025 14:31:16 +0000 (14:31 +0000)] 
AArch64: Add isnan expander [PR 66462]

Add an expander for isnan using integer arithmetic.  Since isnan is
just a compare, enable it only with -fsignaling-nans to avoid
generating spurious exceptions.  This fixes part of PR66462.

int isnan1 (float x) { return __builtin_isnan (x); }

Before:
fcmp s0, s0
cset w0, vs
ret

After:
fmov w1, s0
mov w0, -16777216
cmp w0, w1, lsl 1
cset w0, cc
ret

gcc:
PR middle-end/66462
* config/aarch64/aarch64.md (isnan<mode>2): Add new expander.

gcc/testsuite:
PR middle-end/66462
* gcc.target/aarch64/pr66462.c: Update test.

2 weeks agoUnify last two vect_transform_slp_perm_load calls
Richard Biener [Mon, 15 Sep 2025 12:03:00 +0000 (14:03 +0200)] 
Unify last two vect_transform_slp_perm_load calls

The following unifies the vect_transform_slp_perm_load call done
in vectorizable_load with that eventually done in get_load_store_type.
On the way it fixes the conditions on which we can allow
VMAT_ELEMENTWISE or VMAT_GATHER_SCATTER when there's a SLP permutation
(and we arrange to not code generate that).  In particular that only
works for single-lane SLP of non-grouped loads or groups of size one.
VMAT_ELEMENTWISE does not (yet?) materialize a permutation upon
vector build but still relies on vect_transform_slp_perm_load.

* tree-vect-stmts.cc (get_load_store_type): Get in a flag
whether a SLP_TREE_LOAD_PERMUTATION on the node can be
code generated and use it.  Fix the condition on using
strided gather/scatter to avoid dropping a meaningful
permutation.
(vectorizable_store): Adjust.
(vectorizable_load): Analyze the permutation early and
pass the result down to get_load_store_type.  Fix the
condition on when we are allowed to elide a load permutation.

2 weeks agolibstdc++: Do not use _GLIBCXX_MAKE_MOVE_ITERATOR for C++17
Jonathan Wakely [Mon, 15 Sep 2025 13:49:13 +0000 (14:49 +0100)] 
libstdc++: Do not use _GLIBCXX_MAKE_MOVE_ITERATOR for C++17

The _GLIBCXX_MAKE_MOVE_ITERATOR macro is needed for code that needs to
compile as C++98, where it just produces the original iterator. In
std::uninitialized_move and std::uninitialized_move_n we can just call
std::make_move_iterator directly.

libstdc++-v3/ChangeLog:

* include/bits/stl_uninitialized.h (uninitialized_move)
(uninitialized_move_n): Replace _GLIBCXX_MAKE_MOVE_ITERATOR with
std::make_move_iterator.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2 weeks agolibstdc++: Fix more missing uses of iter_difference_t [PR119820]
Jonathan Wakely [Mon, 15 Sep 2025 13:18:04 +0000 (14:18 +0100)] 
libstdc++: Fix more missing uses of iter_difference_t [PR119820]

libstdc++-v3/ChangeLog:

PR libstdc++/119820
* include/bits/ranges_algo.h (__shuffle_fn): Use
ranges::distance to get difference type value to add to
iterator.
* include/std/format (__formatter_str::_M_format_range):
Use ranges::next to increment iterator by a size_t value.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2 weeks agoaarch64: Force vector in SVE gimple_folder::fold_active_lanes_to.
Jennifer Schmitz [Thu, 28 Aug 2025 10:10:27 +0000 (03:10 -0700)] 
aarch64: Force vector in SVE gimple_folder::fold_active_lanes_to.

An ICE was reported in the following test case:
svint8_t foo(svbool_t pg, int8_t op2) {
      return svmul_n_s8_z(pg, svdup_s8(1), op2);
}
with a type mismatch in 'vec_cond_expr':
_4 = VEC_COND_EXPR <v16_2(D), v32_3(D), { 0, ... }>;

The reason is that svmul_impl::fold folds calls where one of the operands
is all ones to the other operand using
gimple_folder::fold_active_lanes_to. However, we implicitly assumed
that the argument that is passed to fold_active_lanes_to is a vector
type. In the given test case op2 is a scalar type, resulting in the type
mismatch in the vec_cond_expr.

This patch fixes the ICE by forcing a vector type of the argument
in fold_active_lanes_to before the statement with the vec_cond_expr.

In the initial version of this patch, the force_vector statement was placed in
svmul_impl::fold, but it was moved to fold_active_lanes_to to align it with
fold_const_binary which takes care of the fixup from scalar to vector
type using vector_const_binop.

The patch was bootstrapped and tested on aarch64-linux-gnu, no regression.
OK for trunk?
OK to backport to GCC 15?

Signed-off-by: Jennifer Schmitz <jschmitz@nvidia.com>
gcc/
PR target/121602
* config/aarch64/aarch64-sve-builtins.cc
(gimple_folder::fold_active_lanes_to): Add force_vector
statement.

gcc/testsuite/
PR target/121602
* gcc.target/aarch64/sve/acle/asm/mul_s16.c: New test.
* gcc.target/aarch64/sve/acle/asm/mul_s32.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/mul_s64.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/mul_s8.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/mul_u16.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/mul_u32.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/mul_u64.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/mul_u8.c: Likewise.

2 weeks agoada: Fix error message for Stream_Size
Ronan Desplanques [Wed, 3 Sep 2025 09:02:53 +0000 (11:02 +0200)] 
ada: Fix error message for Stream_Size

Before this patch, confirming Stream_Size aspect specifications on
elementary types were incorrectly rejected when the stream size was 128,
and the error messages emitted for Stream_Size aspect errors gave
incorrect possible values.

This patch fixes this. The most significant part of the fix is a new
subprogram in Exp_Strm, Get_Primitives, that makes it possible to
retrieve a precise list of supported stream sizes, but also to select
the right runtime streaming primitives for a given type. Using the
latter, this patch factorizes code that was present in both
Build_Elementary_Input_Call and Build_Elementary_Write_Call.

gcc/ada/ChangeLog:

* exp_strm.ads (Get_Primitives): New function.
* exp_strm.adb (Get_Primitives): Likewise.
(Build_Elementary_Input_Call, Build_Elementary_Write_Call): use
Get_Primitives.
(Has_Stream_Standard_Rep): Add formal parameter and rename to...
(Is_Stream_Standard_Rep): New function.
* sem_ch13.adb (Analyze_Attribute_Definition_Clause): Fix error
emission.

2 weeks agoada: Revert "Remove dependence on secondary stack for type with controlled component"
Gary Dismukes [Thu, 4 Sep 2025 00:46:00 +0000 (00:46 +0000)] 
ada: Revert "Remove dependence on secondary stack for type with controlled component"

This reverts commit 91b51fc42b167eedaaded6360c490a4306bc5c55.

2 weeks agoAda, libgnarl: Fix Ada bootstrap for Darwin.
Iain Sandoe [Tue, 16 Sep 2025 06:51:28 +0000 (07:51 +0100)] 
Ada, libgnarl: Fix Ada bootstrap for Darwin.

Recent changes to Ada have produced a new diagnostic:
s-osinte.adb:34:18: warning: unit "Interfaces.C.Extensions"...
which causes a bootstrap fail on Darwin when Ada is enabled.

Fixed thus.

PR ada/114065

gcc/ada/ChangeLog:

* libgnarl/s-osinte__darwin.adb: Add and reference clause
for Interfaces.C, remove clause for Interfaces.C.Extensions.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2 weeks agoRISC-V: Allow profiles input in '--with-arch' option.
Jiawei [Tue, 16 Sep 2025 03:56:05 +0000 (21:56 -0600)] 
RISC-V: Allow profiles input in '--with-arch' option.

Allows profiles input in '--with-arch'. Check profiles with
'riscv-profiles.def'.

gcc/ChangeLog:

* config.gcc: Accept RISC-V profiles in `--with-arch`.
* config/riscv/arch-canonicalize: Add profile detection and
skip canonicalization for profiles.

2 weeks agoRISC-V: Configure Profiles definitions in the definition file.
Jiawei [Tue, 16 Sep 2025 03:54:32 +0000 (21:54 -0600)] 
RISC-V: Configure Profiles definitions in the definition file.

Moving RISC-V Profiles definations into 'riscv-profiles.def'. Add comments for
'riscv_profiles'.

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc (struct riscv_profiles): Add comments.
(RISCV_PROFILE): Removed.
* config/riscv/riscv-profiles.def: New file.

2 weeks agoRISC-V: Imply zicsr for sdtrig and ssstrict extensions.
Dongyan Chen [Tue, 16 Sep 2025 03:49:15 +0000 (21:49 -0600)] 
RISC-V: Imply zicsr for sdtrig and ssstrict extensions.

This patch implies zicsr for sdtrig and ssstrict extensions.
According to the riscv-privileged spec, the sdtrig and ssstrict extensions
are privileged extensions, so they should imply zicsr.

gcc/ChangeLog:

* config/riscv/riscv-ext.def: Imply zicsr.

2 weeks agoi386/testsuite: Fix non unique name tests
Haochen Jiang [Mon, 15 Sep 2025 07:17:35 +0000 (15:17 +0800)] 
i386/testsuite: Fix non unique name tests

After r16-3651, compare_tests script will explicitly mention those
tests have the same name. This helps us review all the tests we have.

Among them, most of them are unintentional typos (e.g., keep testing
the same vector size for scan-assembler). Fix them through this commit.

gcc/testsuite/ChangeLog:

* gcc.target/i386/avx512bw-vpackssdw-1.c:
Fix xmm/ymm mask tests.
* gcc.target/i386/avx512bw-vpacksswb-1.c: Ditto.
* gcc.target/i386/avx512bw-vpackusdw-1.c: Ditto.
* gcc.target/i386/avx512bw-vpackuswb-1.c: Ditto.
* gcc.target/i386/avx512bw-vpermw-1.c: Test xmm.
* gcc.target/i386/avx512bw-vpmulhw-1.c:
Fix xmm/ymm mask tests.
* gcc.target/i386/avx512f-vec-init.c: Remove duplicate test.
* gcc.target/i386/avx512fp16-13.c: Fix test for aligned load.
* gcc.target/i386/avx512fp16-conjugation-1.c: Revise the test
to test more precisely on masks.
* gcc.target/i386/avx512fp16vl-conjugation-1.c: Ditto.
* gcc.target/i386/avx512vbmi-vpermb-1.c: Test xmm.
* gcc.target/i386/avx512vl-vcvtpd2ps-1.c: Fix scan asm.
* gcc.target/i386/avx512vl-vinsert-1.c: Fix typo.
* gcc.target/i386/avx512vl-vpmulld-1.c:
Fix xmm/ymm mask tests.
* gcc.target/i386/avx512vl-vptestmd-1.c: Ditto.
* gcc.target/i386/bitwise_mask_op-1.c: Fix typo.
* gcc.target/i386/cond_op_shift_q-1.c: Test both vpsra{,v}
and vpsll{,v}.
* gcc.target/i386/cond_op_shift_ud-1.c: Ditto.
* gcc.target/i386/cond_op_shift_uq-1.c: Ditto.
* gcc.target/i386/memcpy-pr95886.c: Fix the wrong const int.
* gcc.target/i386/part-vect-sqrtph-1.c: Remove duplicate test.
* gcc.target/i386/pr107432-7.c: Test vpmov{s,z}xbw instead of
vpmov{s,z}xbd.
* gcc.target/i386/pr88828-0.c: Fix pblendw scan asm.

2 weeks agoOptimize vpermpd to vbroadcastf128 for specific permutations.
liuhongt [Thu, 11 Sep 2025 06:03:43 +0000 (23:03 -0700)] 
Optimize vpermpd to vbroadcastf128 for specific permutations.

gcc/ChangeLog:

* config/i386/predicates.md (avx_vbroadcast128_operand): New
predicate.
* config/i386/sse.md (*avx_vbroadcastf128_<mode>_perm): New
pre_reload splitter.

gcc/testsuite/ChangeLog:

* gcc.target/i386/avx_vbroadcastf128.c: New test.

2 weeks agoDaily bump.
GCC Administrator [Tue, 16 Sep 2025 00:20:53 +0000 (00:20 +0000)] 
Daily bump.

2 weeks ago[analyzer] another function name that returns a pointer to errno
Alexandre Oliva [Mon, 15 Sep 2025 23:14:45 +0000 (20:14 -0300)] 
[analyzer] another function name that returns a pointer to errno

Add __get_errno_ptr() as yet another synonym for __errno_location.

for  gcc/analyzer/ChangeLog

* kf.cc (register_known_functions): Add __get_errno_ptr.

2 weeks agoaarch64: move pr113356.C under g++.target
Clément Chigot [Mon, 15 Sep 2025 23:14:40 +0000 (20:14 -0300)] 
aarch64: move pr113356.C under g++.target

This test requires a C++ compiler.

for gcc/testsuite/ChangeLog

* gcc.target/aarch64/pr113356.C: Move to ...
* g++.target/aarch64/pr113356.C: ... here.

2 weeks ago[ppc] [vxworks] allow code model selection
Alexandre Oliva [Mon, 15 Sep 2025 23:14:35 +0000 (20:14 -0300)] 
[ppc] [vxworks] allow code model selection

Bring code model selection logic to vxworks.h as well.

for  gcc/ChangeLog

* config/rs6000/vxworks.h (TARGET_CMODEL, SET_CMODEL): Define.

2 weeks ago[ppc] adjust configure test for large TOC support
Alexandre Oliva [Mon, 15 Sep 2025 23:14:32 +0000 (20:14 -0300)] 
[ppc] adjust configure test for large TOC support

The use of the TLS register in a TOC/GOT address computation was
probably a cut&pasto or a thinko.  It causes a linker warning and,
because the TLS access in the test is incomplete, may cause
significant confusion.  Adjust to use the TOC/GOT register as base.

for  gcc/ChangeLog

* configure.ac: Adjust base register in linker test for large
TOC support.
* configure: Rebuild.

2 weeks agoMatch: Adjust the unsigned SAT_MUL pattern
Pan Li [Mon, 8 Sep 2025 14:32:12 +0000 (22:32 +0800)] 
Match: Adjust the unsigned SAT_MUL pattern

The widen-mul removed the unnecessary cast, thus adjust the
SAT_MUL of wide-mul to a simpler form.

gcc/ChangeLog:

* match.pd: Remove unnecessary cast of unsigned
SAT_MUL for widen-mul.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 weeks agoWidening-Mul: Refine build_and_insert_cast when rhs is cast
Pan Li [Mon, 8 Sep 2025 14:25:03 +0000 (22:25 +0800)] 
Widening-Mul: Refine build_and_insert_cast when rhs is cast

The widening-mul will insert a cast for the widen-mul, the
function build_and_insert_cast is design to take care of it.

In some case the optimized gimple has some unnecessary cast,
for example as below code.

  #define SAT_U_MUL_FMT_5(NT, WT)                 \
  NT __attribute__((noinline))                    \
  sat_u_mul_##NT##_from_##WT##_fmt_5 (NT a, NT b) \
  {                                               \
    WT x = (WT)a * (WT)b;                         \
    NT hi = x >> (sizeof(NT) * 8);                \
    NT lo = (NT)x;                                \
    return lo | -!!hi;                            \
  }

  SAT_U_MUL_FMT_5(uint64_t, uint128_t)

There will be a additional cast to uint128_t after optimized,
this patch would like to refine this by checking the def of
the rhs cast, if it comes from a cast with less or equal
precision, the rhs of the def will be leveraged.

Before this patch:
  29   │   _1 = (__int128 unsigned) a_8(D);
  30   │   _2 = (__int128 unsigned) b_9(D);
  31   │   _35 = (unsigned long) _1;
  32   │   _34 = (unsigned long) _2;
  33   │   x_10 = _35 w* _34;

After this patch:
  27   │   _35 = (unsigned long) a_8(D);
  28   │   _34 = (unsigned long) b_9(D);
  29   │   x_10 = _35 w* _34;

gcc/ChangeLog:

* tree-ssa-math-opts.cc (build_and_insert_cast): Refine
the cast insert by check the rhs of val.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat/widen-mul-0.c: New test.
* gcc.target/riscv/sat/widen-mul-1.c: New test.
* gcc.target/riscv/sat/widen-mul-2.c: New test.
* gcc.target/riscv/sat/widen-mul-3.c: New test.
* gcc.target/riscv/sat/widen-mul.h: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 weeks agoctf: Fix struct size truncation in 32-bit hosts [PR121903,PR121411]
David Faust [Mon, 15 Sep 2025 22:03:31 +0000 (15:03 -0700)] 
ctf: Fix struct size truncation in 32-bit hosts [PR121903,PR121411]

The 'size' argument of ctf_add_sou was size_t.  After the prior fixes
for PR121411, this could cause the struct size to be truncated when
encoding extremely large structs on a host where size_t is smaller than
unsigned HOST_WIDE_INT, manifesting for example as the test failure
reported in PR121903.  Change the argument to uHWI to resolve the issue.

PR debug/121411
PR debug/121903

gcc/

* ctfc.h (ctf_add_sou): Change size arg from size_t to uHWI.
* ctfc.cc (ctf_add_sou): Likewise.

2 weeks agoAda: Fix GNAT build failure for x32 multilib
Eric Botcazou [Mon, 15 Sep 2025 21:02:52 +0000 (23:02 +0200)] 
Ada: Fix GNAT build failure for x32 multilib

gcc/ada
PR ada/114065
PR ada/121953
* Makefile.rtl (LIBGNAT_TARGET_PAIRS) [x32-linux]: Replace
libgnarl/s-osinte__x32.adb with libgnarl/s-osinte__posix.adb.
* libgnarl/s-osinte__x32.adb: Delete.

2 weeks agoforwprop: Handle memcpy for copy prop [PR121418, PR121417]
Andrew Pinski [Sun, 7 Sep 2025 04:49:18 +0000 (21:49 -0700)] 
forwprop: Handle memcpy for copy prop [PR121418, PR121417]

It turns out easy to add support for memcpy copy prop when the memcpy
has changed into `MEM<char[N]>` copy.
Instead of rejecting right out we need to figure out that
`a` and `MEM<char[N]>[&a]` are equivalent in terms of address and size.
And then create a VIEW_CONVER_EXPR from the original src to the new type.

Note this also allows for `a.b` and `a` being considered equivalent if b is the
only field (PR 121751).

Changes since v1:
* v2: Move check for IMAG/REAL and BFR earlier.
      Add a wrapping function around get_inner_reference and use that instead
     of get_addr_base_and_unit_offset.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/121751
PR tree-optimization/121418
PR tree-optimization/121417
gcc/ChangeLog:

* tree-ssa-forwprop.cc (split_core_and_offset_size): New function.
(optimize_agr_copyprop_1): Allow for the same
address but different type accesses via a VCE.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/copy-prop-aggregate-1.c: New test.
* gcc.dg/tree-ssa/copy-prop-aggregate-memcpy-1.c: New test.
* gcc.dg/tree-ssa/copy-prop-aggregate-memcpy-2.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2 weeks agoada: Fix internal error on aspect in complex object declaration
Eric Botcazou [Fri, 22 Aug 2025 12:51:58 +0000 (14:51 +0200)] 
ada: Fix internal error on aspect in complex object declaration

The sufficient conditions are that the aspect be deferred and the object be
rewritten as a renaming because of the complex initialization expression.

gcc/ada/ChangeLog:

* gcc-interface/trans.cc (gnat_to_gnu)
<N_Object_Renaming_Declaration>: Deal with objects whose elaboration
is deferred.
(process_freeze_entity): Deal with renamed objects whose elaboration
is deferred.

2 weeks agoada: Remove dependence on secondary stack for type with controlled component
Gary Dismukes [Mon, 25 Aug 2025 23:44:41 +0000 (23:44 +0000)] 
ada: Remove dependence on secondary stack for type with controlled component

There are cases where GNAT introduces a dependence on the secondary stack
in a build-in-place function with a result subtype that is definite, when
this dependence could be avoided.  In particular this is done for record
types that requires finalization due to having a controlled component.

At one time such functions required the secondary stack in order to
properly handle cases where the function might raise an exception
(to avoid improper finalization in the caller), but that is no longer
necessary.  We remove the dependence of these functions on the SS,
along with the BIPalloc formal and the generation of the big if_statement
that uses that formal.

An additional small change is to revise the condition for determining when
to generate SS mark/release within functions.

gcc/ada/ChangeLog:

* exp_ch6.ads (Make_Build_In_Place_Call_In_Allocator): Simplify comment.
* exp_ch6.adb (Make_Build_In_Place_Call_In_Allocator): Remove obsolete
comment about not being able to allocate fixed-size controlled results
on the caller side, and replace another obsolete comment with a simpler
comment. Call Build_Allocate_Deallocate_Proc when the function doesn't
need a BIPalloc formal to ensure that function results with controlled
parts allocated on the caller side will be chained for finalization.
(Make_Build_In_Place_Call_In_Object_Declaration): Call Needs_BIP_Collection
on the function's Entity_Id rather than the function call.
(Needs_BIP_Collection): If a BIP function doesn't need a BIPalloc formal
then it doesn't need a BIP collection either; return False in that case.
(Needs_BIP_Alloc_Form): Remove test of Needs_BIP_Collection.
* exp_ch7.adb (Expand_Cleanup_Actions): Move test of Uses_Sec_Stack
to be the first conjunct in setting of Needs_Sec_Stack_Mark, and put
the other tests in a disjunction subsidiary to that. Improve preceding
comment.

2 weeks agoada: Fix wrong finalization of aliased array of bounded vector
Eric Botcazou [Wed, 3 Sep 2025 07:17:39 +0000 (09:17 +0200)] 
ada: Fix wrong finalization of aliased array of bounded vector

The problem is that Apply_Discriminant_Check introduces an unnecessary
temporary for an assignment where both sides have the same constrained
subtype but the left-hand side is an aliased component.

This comes from an approximation in the implementation introduced long
time ago to deal with aliased unconstrained objects in Ada 95, more
specifically to still generate a check when both sides have the same
unconstrained subtype in this case; it is replaced by an explicit test
that the common subtype is constrained.

gcc/ada/ChangeLog:

* checks.adb (Apply_Discriminant_Check): Remove undocumented test
on Is_Aliased_View applied to the left-hand side to skip the check
in the case where the subtypes are the same, and replace it with a
test that the subtypes are constrained.

2 weeks agoada: Document hardening features not supported by LLVM
Jose Ruiz [Wed, 3 Sep 2025 10:06:33 +0000 (12:06 +0200)] 
ada: Document hardening features not supported by LLVM

gcc/ada/ChangeLog:

* doc/gnat_rm/security_hardening_features.rst:
clarify that hardening options are not supported by the
LLVM back end.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

2 weeks agoada: Avoid ghost context errors when preanalyzing Loop_Invariant
Viljar Indus [Tue, 2 Sep 2025 12:20:54 +0000 (15:20 +0300)] 
ada: Avoid ghost context errors when preanalyzing Loop_Invariant

gcc/ada/ChangeLog:

* sem_prag.adb (Analyze_Pragma): Disable context checks for
the preanalysis of the expression for Loop_Invariant pragmas
as the ghost region for the pragma has not been set up yet.

2 weeks agoada: Match assertion levels by name
Viljar Indus [Tue, 2 Sep 2025 14:11:14 +0000 (17:11 +0300)] 
ada: Match assertion levels by name

Since Assertion_Levels cannot be named after valid assertion names
we no longer need the policies to be matched by entity.

gcc/ada/ChangeLog:

* sem_prag.adb (Get_Applicable_Policy): Match assertion levels
by name.

2 weeks agoada: C_Pass_By_Copy convention incorrectly ignored
Steve Baird [Fri, 29 Aug 2025 22:40:46 +0000 (15:40 -0700)] 
ada: C_Pass_By_Copy convention incorrectly ignored

In some cases involving a convention-C anonymous access-to-subprogram type
with a parameter whose type has a convention of C_Pass_By_Copy, that
C_Pass_By_Copy convention is incorrectly ignored.

gcc/ada/ChangeLog:

* freeze.adb (Freeze_Entity): In the case of an anonymous
access-to-subprogram type where Do_Freeze_Profile is True, freeze
the designated subprogram type.
(Should_Freeze_Type): Do not call Unit_Declaration_Node with
a parentless argument.
* sem_ch3.adb (Analyze_Object_Declaration): When calling
Freeze_Before, override the default value for Do_Freeze_Profile.
This is needed in some cases to prevent premature freezing in the
case of an object of an anonymous access-to-subprogram type.

2 weeks agoada: Add Assertion_Policy checks for assertion levels
Viljar Indus [Tue, 2 Sep 2025 10:11:30 +0000 (13:11 +0300)] 
ada: Add Assertion_Policy checks for assertion levels

Implement SPARK RM 6.9(19) check:

An Assertion_Policy pragma specifying an Assertion_Level policy shall not occur
within a ghost subprogram or package associated to an assertion level which depends
on this level.

gcc/ada/ChangeLog:

* sem_prag.adb (Analyze_Pragma): Add ghost level check to
Assertion_Policy.

2 weeks agoada: Fix ghost condition for level dependencies for assignments
Viljar Indus [Tue, 2 Sep 2025 09:25:07 +0000 (12:25 +0300)] 
ada: Fix ghost condition for level dependencies for assignments

gcc/ada/ChangeLog:

* ghost.adb (Check_Assignment_Policies): The level of the assignee
should depend on the level of the region.

2 weeks agoada: Remove checks for the old rule 20
Viljar Indus [Tue, 2 Sep 2025 07:30:53 +0000 (10:30 +0300)] 
ada: Remove checks for the old rule 20

This rule was removed. This can scenario can be detected by Rule 18.

gcc/ada/ChangeLog:

* ghost.adb (Is_Ok_Pragma): Remove calls to Check_Policies.

2 weeks agoada: Update ghost code SPARK RM rules
Viljar Indus [Tue, 2 Sep 2025 07:16:37 +0000 (10:16 +0300)] 
ada: Update ghost code SPARK RM rules

gcc/ada/ChangeLog:

* contracts.adb: Update SPARK RM reference numbers.
* freeze.adb: Likewise.
* ghost.adb: Likewise.
* ghost.ads: Likewise.
* sem_ch12.adb: Likewise.
* sem_ch3.adb: Likewise.
* sem_ch6.adb: Likewise.
* sem_prag.adb: Likwise.
* sem_res.adb: Likewise.

2 weeks agoada: Refactor ghost argument consistency checks
Viljar Indus [Fri, 29 Aug 2025 12:09:24 +0000 (15:09 +0300)] 
ada: Refactor ghost argument consistency checks

Create a new method for checking and emitting errors on pragmas
Unused, Unrefefrenced, Unreferenced_Objects, Inline and No_Return
that support specifying multiple entities as arguments.

Emit an error when one argument is ghost and the other is not and
when one argument has a ghost policy check and the other has ghost
policy ignore.

Update the Suppressed_Ghost_Policy_Check_Pragma list pragma Inline
that should be there to avoid an incorrect invalid pragma context
error.

gcc/ada/ChangeLog:

* sem_prag.adb (Check_Inconsistent_Argument_Ghostliness):
new method for handling the ghost constency errors between
different arguments. Use this method in the processing for
pragmas Unused, Unrefefrenced, Unreferenced_Objects, Inline and
No_Return.
* sem_prag.ads (Suppressed_Ghost_Policy_Check_Pragma): add
missing entry for pragma Inline.

2 weeks agoada: Fix the condition of ghost level dependencies inside assignments
Viljar Indus [Mon, 1 Sep 2025 08:00:38 +0000 (11:00 +0300)] 
ada: Fix the condition of ghost level dependencies inside assignments

The assignee should depend on the level of all of the ghost entiies
with the assignment.

gcc/ada/ChangeLog:

* ghost.adb (Check_Assignee_Levels): Fix the condition and improve
error message handling.

2 weeks agoada: Add System.C_Time and GNAT.C_Time units to libgnat
Nicolas Boulenguez [Sat, 19 Jul 2025 18:14:02 +0000 (20:14 +0200)] 
ada: Add System.C_Time and GNAT.C_Time units to libgnat

The first unit provides the time_t, timeval and timespec types corresponding
to the C types defined by the OS, as well as various conversion functions.

The second unit is a mere renaming of the first under the GNAT hierarchy.

This removes C time types and conversions under System, and from bodies and
private parts under GNAT, while keeping visible types and conversions under
GNAT as Obsolescent.

gcc/ada/ChangeLog:

PR ada/114065
* Makefile.rtl (GNATRTL_NONTASKING_OBJS): Add g-c_time$(objext) and
s-c_time$(objext).
(Aarch64/Android): Do not use s-osinte__android.adb.
(SPARC/Solaris): Do not use s-osprim__solaris.adb.
(x86/Solaris): Likewise.
(LynxOS178): Do not use s-parame__posix2008.ads.
(RTEMS): Likewise.
(x32/Linux): Likewise, as well as s-linux__x32.ads.  Replace
s-osprim__x32.adb with s-osprim__posix.adb.
(LIBGNAT_OBJS): Remove cal.o.
* cal.c: Delete.
* doc/gnat_rm/the_gnat_library.rst (GNAT.C_Time): New entry.
(GNAT.Calendar): Do not mention the obsolete conversion functions.
* impunit.adb (Non_Imp_File_Names_95): Add g-c_time.
* libgnarl/a-exetim__posix.adb: Add with clause for System.C_Time
(Clock): Use type and functions from System.C_Time.
* libgnarl/s-linux.ads: Remove with clause for System.Parameters.
Remove declarations of C time types.
* libgnarl/s-linux__alpha.ads: Likewise.
* libgnarl/s-linux__android-aarch64.ads: Likewise.
* libgnarl/s-linux__android-arm.ads: Likewise.
* libgnarl/s-linux__hppa.ads: Likewise.
* libgnarl/s-linux__loongarch.ads: Likewise.
* libgnarl/s-linux__mips.ads: Likewise.
* libgnarl/s-linux__riscv.ads: Likewise.
* libgnarl/s-linux__sparc.ads: Likewise.
* libgnarl/s-osinte__aix.ads: Likewise.
* libgnarl/s-osinte__android.ads: Likewise.
* libgnarl/s-osinte__cheribsd.ads: Likewise.
* libgnarl/s-osinte__darwin.ads: Likewise.
* libgnarl/s-osinte__dragonfly.ads: Likewise.
* libgnarl/s-osinte__freebsd.ads: Likewise.
* libgnarl/s-osinte__gnu.ads: Likewise.
* libgnarl/s-osinte__hpux.ads: Likewise.
* libgnarl/s-osinte__kfreebsd-gnu.ads: Likewise.
* libgnarl/s-osinte__linux.ads: Likewise.
* libgnarl/s-osinte__lynxos178e.ads: Likewise.
* libgnarl/s-osinte__qnx.ads: Likewise.
* libgnarl/s-osinte__rtems.ads: Likewise.
* libgnarl/s-osinte__solaris.ads: Likewise.
* libgnarl/s-osinte__vxworks.ads: Likewise.
* libgnarl/s-qnx.ads: Likewise.
* libgnarl/s-linux__x32.ads: Delete.
* libgnarl/s-osinte__darwin.adb (To_Duration): Remove.
(To_Timespec): Likewise.
* libgnarl/s-osinte__aix.adb: Likewise.
* libgnarl/s-osinte__dragonfly.adb: Likewise.
* libgnarl/s-osinte__freebsd.adb: Likewise.
* libgnarl/s-osinte__gnu.adb: Likewise.
* libgnarl/s-osinte__lynxos178.adb: Likewise.
* libgnarl/s-osinte__posix.adb: Likewise.
* libgnarl/s-osinte__qnx.adb: Likewise.
* libgnarl/s-osinte__rtems.adb: Likewise.
* libgnarl/s-osinte__solaris.adb: Likewise.
* libgnarl/s-osinte__vxworks.adb: Likewise.
* libgnarl/s-osinte__x32.adb: Likewise.
* libgnarl/s-taprop__solaris.adb: Add with clause for System.C_Time.
(Monotonic_Clock): Use type and functions from System.C_Time.
(RT_Resolution): Likewise.
(Timed_Sleep): Likewise.
(Timed_Delay): Likewise.
* libgnarl/s-taprop__vxworks.adb: Likewise.
* libgnarl/s-tpopmo.adb: Likewise.
* libgnarl/s-osinte__android.adb: Delete.
* libgnat/g-c_time.ads: New file.
* libgnat/g-calend.adb: Delegate to System.C_Time.
* libgnat/g-calend.ads: Likewise.
* libgnat/g-socket.adb: Likewise.
* libgnat/g-socthi.adb: Likewise.
* libgnat/g-socthi__vxworks.adb: Likewise.
* libgnat/g-sothco.ads: Likewise.
* libgnat/g-spogwa.adb: Likewise.
* libgnat/s-c_time.adb: New file.
* libgnat/s-c_time.ads: Likewise.
* libgnat/s-optide.adb: Import nanosleep here.
* libgnat/s-os_lib.ads (time_t): Remove.
(To_Ada): Adjust.
(To_C): Likewise.
* libgnat/s-os_lib.adb: Likewise.
* libgnat/s-osprim__darwin.adb: Delegate to System.C_Time.
* libgnat/s-osprim__posix.adb: Likewise.
* libgnat/s-osprim__posix2008.adb: Likewise.
* libgnat/s-osprim__rtems.adb: Likewise.
* libgnat/s-osprim__unix.adb: Likewise.
* libgnat/s-osprim__solaris.adb: Delete.
* libgnat/s-osprim__x32.adb: Likewise.
* libgnat/s-parame.ads (time_t_bits): Remove.
* libgnat/s-parame__hpux.ads: Likewise.
* libgnat/s-parame__vxworks.ads: Likewise.
* libgnat/s-parame__posix2008.ads: Delete.
* s-oscons-tmplt.c (SIZEOF_tv_nsec): New constant.
* gnat_rm.texi: Regenerate.

2 weeks agoada: Fix crash on iterator of type with Constant_Indexing aspect
Eric Botcazou [Fri, 29 Aug 2025 07:24:33 +0000 (09:24 +0200)] 
ada: Fix crash on iterator of type with Constant_Indexing aspect

This happens when the type returned by the indexing function is a private
type whose completion is derived from another private type, because the
Finalize_Address routine cannot correctly fetch the actual root type.

gcc/ada/ChangeLog:

* exp_util.adb (Finalize_Address): In an untagged derivation, call
Root_Type on the full view of the base type if the partial view is
itself not a derived type.
(Is_Untagged_Derivation): Minor formatting tweak.

2 weeks agoada: Fix missing finalization for qualified expression in conditional expression
Eric Botcazou [Tue, 26 Aug 2025 22:16:48 +0000 (00:16 +0200)] 
ada: Fix missing finalization for qualified expression in conditional expression

A qualified expression around a function call may cause a temporary to be
created and, therefore, cannot be bypassed in Expand_Ctrl_Function_Call.

gcc/ada/ChangeLog:

* exp_util.ads (Unqualified_Unconditional_Parent): New function.
* exp_util.adb (Unconditional_Parent): Do not look through qualified
expressions.
(Unqualified_Unconditional_Parent): New function identical to the
original Unconditional_Parent.
* exp_aggr.adb (Convert_To_Assignments): Replace Unconditional_Parent
with Unqualified_Unconditional_Parent.
(Expand_Array_Aggregate): Likewse.
* exp_ch4.adb (Expand_N_Case_Expression): Likewise.
(Expand_N_If_Expression): Likewise.
* exp_ch6.adb (Expand_Ctrl_Function_Call): Do not bypass an enclosing
qualified expression in the parent chain.

2 weeks agoada: Fix section of Finalizable extension in GNAT RM
Ronan Desplanques [Fri, 30 May 2025 09:50:09 +0000 (11:50 +0200)] 
ada: Fix section of Finalizable extension in GNAT RM

The generalized finalization extension was awarded the title of curated
extension some time ago, but this wasn't reflected in the GNAT
reference manual before this patch, which moves the documentation for
generalized finalization in the curated extension section.

gcc/ada/ChangeLog:

* doc/gnat_rm/gnat_language_extensions.rst: Fix section of Finalizable.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

2 weeks agoada: Avoid ghost context check in early freeze
Viljar Indus [Thu, 28 Aug 2025 10:18:39 +0000 (13:18 +0300)] 
ada: Avoid ghost context check in early freeze

We freeze the expression for expression functions that complete
before we have set up the ghost region from both the existing spec
and body. Avoid triggering the ghost context checks during the
analysis for this early freeze as the expression will be reanalyzed
when we analyze the new function body created for the expression
function.

gcc/ada/ChangeLog:

* sem_ch6.adb (Analyze_Expression_Function): Disable ghost
checks during the early freeze.

2 weeks agoada: Implement Super aspect and improve implementation of related features.
Steve Baird [Mon, 18 Aug 2025 21:39:48 +0000 (14:39 -0700)] 
ada: Implement Super aspect and improve implementation of related features.

Implement the GNAT-defined Super aspect (which should not be confused with
with the Super attribute). For a two-part constructor procedure declaration,
an Initialize aspect specification is permitted on the subprogram body,
and not on the subprogram specification (this reverses was what was previously
implemented). Improve the implementation of the Make attribute.

gcc/ada/ChangeLog:

* aspects.ads: Define Super aspect; allow Initialize aspect
specification on a subprogram body.
* exp_attr.adb (Expand_N_Attribute_Reference): Rewrite Make
attribute implementation.
* exp_ch3.adb (Initialization_Control): Delete Initialization_Mode
and Make_Mode_Literal (those declarations were moved to the spec).
(Build_Record_Init_Proc): For a constructor type, component
initialization (other than for the tag component, if any) must be
performed by calling the single-argument constructor procedure.
(Requires_Init_Proc): Return True for a constructor type.
* exp_ch3.ads (Make_Mode_Literal, Initialization_Mode): New, moved
from the body of this package.
* exp_ch6.adb (Expand_N_Subprogram_Body): Declare, implement, and
call a new local procedure, Prepend_Constructor_Procedure_Prologue
in order to generate component initialization for a constructor
procedure.
* sem_attr.adb (Analyze_Attribute): Improve the error message
generated for a 'Make attribute reference if GNAT extensions are
not all allowed.
* sem_ch13.adb (Analyze_One_Aspect): Improved implementation of
aspect specifications for Initialize, Constructor, and Super
aspects. For Super, there was no previous implementation.

2 weeks agoada: Improve ghost region creation for pragmas
Viljar Indus [Tue, 12 Aug 2025 06:55:17 +0000 (09:55 +0300)] 
ada: Improve ghost region creation for pragmas

gcc/ada/ChangeLog:

* atree.adb (Mark_New_Ghost_Node): Set Is_Implicit_Ghost for
all newly created nodes.
* gen_il-fields.ads (Is_Implicit_Ghost): New attribute.
* gen_il-gen-gen_entities.adb (Entity_Kind): Add Is_Implicit_Ghost
attribute.
* ghost.adb (Ghost_Policy_In_Effect): Implicit_Ghost_Entities inside
pragmas get the ghost mode from the region isntead of the global
ghost policy.
(Ghost_Assertion_Level_In_Effect): New function that returns the
applicable assertion level for the given entity in a similar manner
as Ghost_Policy_In_Effect.
(Install_Ghost_Region): Set Is_Inside_Statement_Or_Pragma attribute.
(Mark_And_Set_Ghost_Body): Update the logic for deriving the ghost
region.
(Set_Ghost_Mode): Ignored pragmas attached to checked ghost entities
now create an ignored ghost region. Pragmas attached to non-ghost
entities create the ghost region based on the policy applied to the
given pragma.
* opt.ads (Ghost_Config_Type): add new attribute
Is_Inside_Statement_Or_Pragama to track whether we should take the
active ghost mode from the ghost region for implicit ghost entities.
* sem_prag.adb (Analyze_Pragma): Mark entities that have an explicit
ghost pragma as non-implicit ghost.

2 weeks agoada: Remove the note that GNAT LLVM doesn't ship the light runtime
Sebastian Poeplau [Wed, 27 Aug 2025 08:02:21 +0000 (10:02 +0200)] 
ada: Remove the note that GNAT LLVM doesn't ship the light runtime

gcc/ada/ChangeLog:

* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
Remove the note on light runtimes.

2 weeks agoada: Recommend GPR's Toolchain_Name for GNAT LLVM more prominently
Sebastian Poeplau [Wed, 27 Aug 2025 08:00:10 +0000 (10:00 +0200)] 
ada: Recommend GPR's Toolchain_Name for GNAT LLVM more prominently

gcc/ada/ChangeLog:

* doc/gnat_ugn/building_executable_programs_with_gnat.rst: Move
recommendation of Toolchain_Name up.
* gnat_ugn.texi: Regenerate.

2 weeks agoada: Don't generate call of `System.Standard_Library.Adafinal`
Vadim Godunko [Sun, 13 Jul 2025 06:26:19 +0000 (10:26 +0400)] 
ada: Don't generate call of `System.Standard_Library.Adafinal`

`adafinal` is not available on targets without standard library.

gcc/ada/ChangeLog:

* bindgen.adb (Gen_Adafinal): Don't generate call of adafinal
when use of standard library suppressed.

2 weeks agoada: Fix code generation when there is no No_Finalization restiction
Vadim Godunko [Sun, 13 Jul 2025 05:41:22 +0000 (09:41 +0400)] 
ada: Fix code generation when there is no No_Finalization restiction

Check whether library is elaborated is not generated when there is not
standard library available on target.

gcc/ada/ChangeLog:

* bindgen.adb (Gen_Adafinal): Don't generate code when
use of standard library suppressed.

2 weeks agoada: Add `Set_[Wide_]Wide_String` subprograms to auxiliary packages.
Vadim Godunko [Wed, 27 Aug 2025 09:24:57 +0000 (13:24 +0400)] 
ada: Add `Set_[Wide_]Wide_String` subprograms to auxiliary packages.

gcc/ada/ChangeLog:

* libgnat/a-swunau.ads (Set_Wide_String): New subprogram.
* libgnat/a-swunau.adb (Set_Wide_String): Likewise.
* libgnat/a-swunau__shared.adb (Set_Wide_String): Likewise.
* libgnat/a-szunau.ads (Set_Wide_Wide_String): Likewise.
* libgnat/a-szunau.adb (Set_Wide_Wide_String): Likewise.
* libgnat/a-szunau__shared.adb (Set_Wide_Wide_String): Likewise.

2 weeks agoada: Disable ghost context checks before context is set
Viljar Indus [Wed, 27 Aug 2025 07:54:05 +0000 (10:54 +0300)] 
ada: Disable ghost context checks before context is set

There are cases where we need to analyze the argument of the pragma
in order to determine the ghostliness of the pragma. However during
that analysis the ghost region of the pragma is not set yet so we
cannot perform the ghost context checks at that moment.

This patch provides the mechanism for disabling ghost context checks
and disables them for pragma arguments that determine the ghostliness
of the pragma.

gcc/ada/ChangeLog:

* ghost.adb (Check_Ghost_Context): Avoid context checks when they
are globally disabled.
* sem.ads (Ghost_Context_Checks_Disabled): New flag to control
whether ghost context checks are activated or not.
* sem_prag.adb (Analyze_Pragma): Disable ghost context checks for
pragmas that determine their ghostliness based on one of its arguments.

2 weeks agoada: Fix documentation of Is_Ancestor_Package
Ronan Desplanques [Tue, 26 Aug 2025 13:39:03 +0000 (15:39 +0200)] 
ada: Fix documentation of Is_Ancestor_Package

"Is_Ancestor_Package (E, E)" returns True and this patch fixes a comment
that claimed otherwise. This patch also renames an object local to
Is_Ancestor_Package that was misleadingly named "Par", a common
abbreviation of "Parent".

gcc/ada/ChangeLog:

* sem_util.ads (Is_Ancestor_Package): Fix documentation comment.
* sem_util.adb (Is_Ancestor_Package): Rename local object.

2 weeks agomatch.pd: Add missing type check to reduc(ctor) pattern [PR121772]
Alex Coplan [Tue, 9 Sep 2025 11:57:14 +0000 (12:57 +0100)] 
match.pd: Add missing type check to reduc(ctor) pattern [PR121772]

In this PR we have a reduction of a vector constructor, where the
type of the constructor is int16x8_t and the elements are int16x4_t;
i.e. it is representing a concatenation of two vectors.

This triggers a match.pd pattern which looks like it was written to
handle reductions of vector constructors where the elements of the ctor
are scalars, not vectors.  There is no type check to enforce this
property, which leads to the pattern replacing a reduction to scalar
with an int16x4_t vector in this case, which of course is a type error,
leading to an invalid GIMPLE ICE.

This patch adds a type check to the pattern, only going ahead with the
transformation if the element type of the ctor matches that of the
reduction.

gcc/ChangeLog:

PR tree-optimization/121772
* match.pd: Add type check to reduc(ctor) pattern.

gcc/testsuite/ChangeLog:

PR tree-optimization/121772
* gcc.target/aarch64/torture/pr121772.c: New test.

2 weeks agoAVR: Support AVR32EB14/20/28/32.
Georg-Johann Lay [Mon, 15 Sep 2025 12:20:59 +0000 (14:20 +0200)] 
AVR: Support AVR32EB14/20/28/32.

Add support for some recent AVR devices.

gcc/
* config/avr/avr-mcus.def: Add avr32eb14, avr32eb20,
avr32eb28, avr32eb32.
* doc/avr-mmcu.texi: Rebuild.

3 weeks agox86: Don't align destination for a single instruction
H.J. Lu [Sat, 13 Sep 2025 13:38:44 +0000 (06:38 -0700)] 
x86: Don't align destination for a single instruction

If a single instruction can store or move the whole block of memory, use
vector instruction and don't align destination.

gcc/

PR target/121934
* config/i386/i386-expand.cc (ix86_expand_set_or_cpymem): If a
single instruction can store or move the whole block of memory,
use vector instruction and don't align destination.

gcc/testsuite/

PR target/121934
* gcc.target/i386/pr121934-1a.c: New test.
* gcc.target/i386/pr121934-1b.c: Likewise.
* gcc.target/i386/pr121934-2a.c: Likewise.
* gcc.target/i386/pr121934-2b.c: Likewise.
* gcc.target/i386/pr121934-3a.c: Likewise.
* gcc.target/i386/pr121934-3b.c: Likewise.
* gcc.target/i386/pr121934-4a.c: Likewise.
* gcc.target/i386/pr121934-4b.c: Likewise.
* gcc.target/i386/pr121934-5a.c: Likewise.
* gcc.target/i386/pr121934-5b.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
3 weeks agoLoongArch: Fix wrong code from bstrpick split
Xi Ruoyao [Fri, 12 Sep 2025 07:57:08 +0000 (15:57 +0800)] 
LoongArch: Fix wrong code from bstrpick split

After late-combine is added, split1 can see an input like

    (insn 56 55 169 5
      (set (reg/v:DI 87 [ n ])
        (ior:DI (and:DI (reg/v:DI 87 [ n ])
                        (const_int 281474976710655 [0xffffffffffff]))
                (and:DI (reg:DI 131 [ _45 ])
                        (const_int -281474976710656 [0xffff000000000000]))))
      "pr121906.c":22:8 108 {*bstrins_di_for_ior_mask}
      (nil))

And the splitter ends up emitting

    (insn 184 55 185 5
      (set (reg/v:DI 87 [ n ])
           (reg:DI 131 [ _45 ]))
      "pr121906.c":22:8 -1
      (nil))
    (insn 185 184 169 5
      (set (zero_extract:DI (reg/v:DI 87 [ n ])
                            (const_int 48 [0x30])
                            (const_int 0 [0]))
           (reg/v:DI 87 [ n ]))
      "pr121906.c":22:8 -1
      (nil))

which obviously lost everything in r87, instead of retaining its lower
bits as we expect.  It's because the splitter didn't anticipate the
output register may be one of the input registers.

PR target/121906

gcc/

* config/loongarch/loongarch.md (*bstrins_<mode>_for_ior_mask):
Always create a new pseudo for the input register of the bstrins
instruction.

gcc/testsuite/

* gcc.target/loongarch/pr121906.c: New test.

3 weeks agoexpr, tree: Ensure get_range_pos_neg is called only on scalar integral types [PR121904]
Jakub Jelinek [Mon, 15 Sep 2025 08:34:33 +0000 (10:34 +0200)] 
expr, tree: Ensure get_range_pos_neg is called only on scalar integral types [PR121904]

The gcc.c-torture/compile/20111209-1.c testcase which uses
typedef char* char_ptr32 __attribute__ ((mode(SI)));
ICEs on s390x since my change to optimize extensions by cheaper of
signed or unsigned extension if sign bit is known from VRP not to be set.

The problem is that get_range_pos_neg uses ranger into int_range_max
and so ICEs on pointers.  All the other current callers call it from places
where only scalar integral types can appear (scalar division/modulo,
overflow ifns, etc.) I think, this spot was just testing SCALAR_INT_MODE_P.

The following patch adds check for INTEGRAL_TYPE_P, I think ranger will not
do anything useful for pointers here anyway and what is a negative pointer
is also fuzzy.  I've changed both get_range_pos_neg to punt on that and
the caller, either of those changes are sufficient to fix the ICE, but I
think it doesn't hurt to do it in both places.

2025-09-15  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/121904
* tree.cc (get_range_pos_neg): Return 3 if arg doesn't have
scalar integral type.
* expr.cc (expand_expr_real_2) <CASE_CONVERT>: Only choose between
sign and zero extension based on costs for scalar integral inner
types.

3 weeks agoRISC-V: Fix vendor intrinsic tests for disabled multilib configurations
Kito Cheng [Wed, 10 Sep 2025 10:23:12 +0000 (18:23 +0800)] 
RISC-V: Fix vendor intrinsic tests for disabled multilib configurations

Add wrapper headers that prevent vendor vector headers from including
system stdint.h, ensuring tests work correctly when multilib is disabled.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/andes_vector.h: New file.
* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vfncvtbf16s.c
(#include): Use local andes_vector.h instead of system header.
* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vfwcvtsbf16.c
(#include): Likewise.
* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/andes_vector.h: New file.
* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vfncvtbf16s.c
(#include): Use local andes_vector.h instead of system header.
* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vfwcvtsbf16.c
(#include): Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/andes_vector.h: New file.
* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vfncvtbf16s.c
(#include): Use local andes_vector.h instead of system header.
* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vfwcvtsbf16.c
(#include): Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/overloaded/andes_vector.h: New file.
* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vfncvtbf16s.c
(#include): Use local andes_vector.h instead of system header.
* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vfwcvtsbf16.c
(#include): Likewise.
* gcc.target/riscv/rvv/xsfvector/sifive_vector.h: New file.
* gcc.target/riscv/rvv/xtheadvector/riscv_th_vector.h: New file.
* gcc.target/riscv/rvv/xtheadvector/riscv_vector.h: New file.

3 weeks agoBail out early during gimplify_asm_expr [PR121391]
Stefan Schulze Frielinghaus [Mon, 15 Sep 2025 07:10:53 +0000 (09:10 +0200)] 
Bail out early during gimplify_asm_expr [PR121391]

In case an asm operand is an error node, constraints etc. are still
validated.  Furthermore, all other operands are gimplified, although an
error is returned in the end anyway.  For hard register constraints an
operand is required in order to determine the mode from which the number
of registers follows.  Therefore, instead of adding extra guards, bail
out early.

gcc/ChangeLog:

PR middle-end/121391
* gimplify.cc (gimplify_asm_expr): In case an asm operand is an
error node, bail out early.

gcc/testsuite/ChangeLog:

* gcc.dg/pr121391-1.c: New test.
* gcc.dg/pr121391-2.c: New test.

3 weeks agoFix whitespace after r16-3679-g19d1c7c28f4fd0
Matthias Kretz [Tue, 9 Sep 2025 06:16:02 +0000 (08:16 +0200)] 
Fix whitespace after r16-3679-g19d1c7c28f4fd0

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
gcc/cp/ChangeLog:

* mangle.cc (write_real_cst): Replace 8 spaces with Tab.

3 weeks agoFortran: Dependency check in PDT specification assignments [PR83763]
Paul Thomas [Mon, 15 Sep 2025 05:49:54 +0000 (06:49 +0100)] 
Fortran: Dependency check in PDT specification assignments [PR83763]

2025-09-15  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/83763
* trans-decl.cc (gfc_trans_deferred_vars): Ensure that the
parameterized components of PDTs that do not have allocatable
components are deallocated on leaving scope.
* trans-expr.cc (gfc_trans_assignment_1): Do a dependency check
on PDT assignments. If there is a dependency between lhs and
rhs, deallocate the lhs parameterized components after the rhs
has been evaluated.

gcc/testsuite/
PR fortran/83763
* gfortran.dg/pdt_46.f03: New test.

3 weeks agoDaily bump.
GCC Administrator [Mon, 15 Sep 2025 00:17:47 +0000 (00:17 +0000)] 
Daily bump.

3 weeks agolto/121935 - visit all DECL_ARGUMENTS in free-lang-data
Richard Biener [Sun, 14 Sep 2025 09:01:11 +0000 (11:01 +0200)] 
lto/121935 - visit all DECL_ARGUMENTS in free-lang-data

With no longer visiting TREE_CHAIN for decls we have to visit
the DECL_ARGUMENT chain manually.

PR lto/121935
* ipa-free-lang-data.cc (find_decls_types_r): Visit DECL_ARGUMENTS
chain manually.

* g++.dg/lto/pr121935_0.C: New testcase.

3 weeks agofortran: implement conditional expression for fortran 2023
Yuao Ma [Fri, 12 Sep 2025 12:28:19 +0000 (20:28 +0800)] 
fortran: implement conditional expression for fortran 2023

This patch adds support for conditional expressions in Fortran 2023 for a
limited set of types (logical, numerical), and also includes limited support
for conditional arguments without `.nil.` support.

gcc/fortran/ChangeLog:

* dump-parse-tree.cc (show_expr): Add support for EXPR_CONDITIONAL.
* expr.cc (gfc_get_conditional_expr): Add cond-expr constructor.
(gfc_copy_expr, free_expr0, gfc_is_constant_expr,
simplify_conditional, gfc_simplify_expr, gfc_check_init_expr,
check_restricted, gfc_traverse_expr): Add support for EXPR_CONDITIONAL.
* frontend-passes.cc (gfc_expr_walker): Ditto.
* gfortran.h (enum expr_t): Add EXPR_CONDITIONAL.
(gfc_get_operator_expr): Format fix.
(gfc_get_conditional_expr): New decl.
* matchexp.cc
(match_conditional, match_primary): Parsing for EXPR_CONDITIONAL.
* module.cc (mio_expr): Add support for EXPR_CONDITIONAL.
* resolve.cc (resolve_conditional, gfc_resolve_expr): Ditto.
* trans-array.cc (gfc_walk_conditional_expr, gfc_walk_subexpr): Ditto.
* trans-expr.cc
(gfc_conv_conditional_expr): Codegen for EXPR_CONDITIONAL.
(gfc_apply_interface_mapping_to_expr, gfc_conv_expr,
gfc_conv_expr_reference): Add support for EXPR_CONDITIONAL.

gcc/testsuite/ChangeLog:

* gfortran.dg/conditional_1.f90: New test.
* gfortran.dg/conditional_2.f90: New test.
* gfortran.dg/conditional_3.f90: New test.
* gfortran.dg/conditional_4.f90: New test.
* gfortran.dg/conditional_5.f90: New test.
* gfortran.dg/conditional_6.f90: New test.
* gfortran.dg/conditional_7.f90: New test.
* gfortran.dg/conditional_8.f90: New test.
* gfortran.dg/conditional_9.f90: New test.

3 weeks agoIntegrate SLP permute transform into vect_transform_stmt
Richard Biener [Fri, 12 Sep 2025 11:52:51 +0000 (13:52 +0200)] 
Integrate SLP permute transform into vect_transform_stmt

This adds permute_info_type and removes the duplication from
vect_schedule_slp_node.

* tree-vectorizer.h (stmt_vec_info_type::permute_info_type): Add.
(vectorizable_slp_permutation): Declare.
* tree-vect-slp.cc (vectorizable_slp_permutation): Export.
(vect_slp_analyze_node_operations_1): Set permute_info_type
on permute nodes successfully analyzed.
(vect_schedule_slp_node): Dispatch to vect_transform_stmt
for all nodes.
* tree-vect-stmts.cc (vect_transform_stmt): Remove redundant
dump, handle permute_info_type.

* gcc.dg/vect/vect-reduc-chain-2.c: Adjust.
* gcc.dg/vect/vect-reduc-chain-3.c: Likewise.

3 weeks agoAvoid VMAT_ELEMENTWISE for negative stride SLP
Richard Biener [Fri, 12 Sep 2025 12:15:59 +0000 (14:15 +0200)] 
Avoid VMAT_ELEMENTWISE for negative stride SLP

The following makes us always use VMAT_STRIDED_SLP for negative
stride multi-element accesses.  That handles falling back to
single element accesses transparently.

* tree-vect-stmts.cc (get_load_store_type): Use VMAT_STRIDED_SLP
for negative stride accesses when VMAT_CONTIGUOUS_REVERSE
isn't applicable.

3 weeks agoDo less redundant vect_transform_slp_perm_load calls
Richard Biener [Fri, 12 Sep 2025 11:20:46 +0000 (13:20 +0200)] 
Do less redundant vect_transform_slp_perm_load calls

The following tries to do vect_transform_slp_perm_load exactly
once during analysis and once during transform.  There's a 2nd
case left during analysis in get_load_store_type.  Temporarily
this records n_perms in the load-store info and verifies that
against the value computed at transform stage.

* tree-vectorizer.h (vect_load_store_data::n_perms): New.
* tree-vect-stmts.cc (vectorizable_load): Analyze
SLP_TREE_LOAD_PERMUTATION only once and remember n_perms.
Verify the transform-time n_perms against the value stored
during analysis.

3 weeks agoDaily bump.
GCC Administrator [Sun, 14 Sep 2025 00:17:51 +0000 (00:17 +0000)] 
Daily bump.

3 weeks agotarget.def: Properly mark up __cxa_atexit as code
Gerald Pfeifer [Sat, 13 Sep 2025 23:06:51 +0000 (01:06 +0200)] 
target.def: Properly mark up __cxa_atexit as code

gcc:
* target.def (dtors_from_cxa_atexit): Properly mark up
__cxa_atexit as code.
* doc/tm.texi: Regenerate.

3 weeks agolibstdc++: Fix ranges::shuffle for non-sized range [PR121917]
Patrick Palka [Sat, 13 Sep 2025 14:44:12 +0000 (10:44 -0400)] 
libstdc++: Fix ranges::shuffle for non-sized range [PR121917]

ranges::shuffle has a two-at-a-time PRNG optimization (copied from
std::shuffle) that considers the PRNG width vs the size of the range.
But in C++20 a random access sentinel isn't always sized so we can't
unconditionally do __last - __first to obtain the size in constant
time.

We could instead use ranges::distance, but that'd take linear time for a
non-sized sentinel which makes the optimization less clear of a win.  So
this patch instead makes us only consider this optimization for sized
ranges.

PR libstdc++/121917

libstdc++-v3/ChangeLog:

* include/bits/ranges_algo.h (__shuffle_fn::operator()): Only
consider the two-at-a-time PRNG optimization if the range is
sized.
* testsuite/25_algorithms/shuffle/constrained.cc (test03): New
test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
3 weeks agolra: Stop constraint processing on error [PR121205]
Stefan Schulze Frielinghaus [Thu, 24 Jul 2025 10:03:43 +0000 (12:03 +0200)] 
lra: Stop constraint processing on error [PR121205]

It looks like we didn't have a test so far reaching this point which
changed with the new hard register constraint tests.  Bootstrap and
regtest are still running on x86_64.  If they succeed, ok for mainline?

-- >8 --

As noted by Sam in the PR, with checking enabled tests
gcc.target/i386/asm-hard-reg-{1,2}.c fail with an ICE.  If an error is
detected in curr_insn_transform(), lra_asm_insn_error() is called and
deletes the current insn.  However, afterwards processing continues with
the deleted insn and via lra_process_new_insns() we finally call recog()
for NOTE_INSN_DELETED which ICEs in case of a checking build.  Thus, in
case of an error during curr_insn_transform() bail out and stop
processing.

gcc/ChangeLog:

PR rtl-optimization/121205
* lra-constraints.cc (curr_insn_transform): Stop processing on
error.

3 weeks agodoc: Editorial changes around -fprofile-partial-training
Gerald Pfeifer [Sat, 13 Sep 2025 10:40:38 +0000 (12:40 +0200)] 
doc: Editorial changes around -fprofile-partial-training

gcc:
* doc/invoke.texi (Optimize Options): Editorial changes around
-fprofile-partial-training.

3 weeks agotestsuite: Port asm-hard-reg tests for PRU
Dimitar Dimitrov [Sat, 13 Sep 2025 07:56:35 +0000 (10:56 +0300)] 
testsuite: Port asm-hard-reg tests for PRU

Add the necessary register definitions for PRU, so that asm-hard-reg
tests can pass for PRU.

gcc/testsuite/ChangeLog:

* gcc.dg/asm-hard-reg-error-1.c: Enable test for PRU, and define
registers for PRU.
* gcc.dg/asm-hard-reg-error-4.c: Define hard regs for PRU.
* gcc.dg/asm-hard-reg-error-5.c: Ditto.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
3 weeks agoc: Implement C2y N3517 array subscripting without decay
Joseph Myers [Sat, 13 Sep 2025 00:21:58 +0000 (00:21 +0000)] 
c: Implement C2y N3517 array subscripting without decay

N3517 (array subscripting without decay) has been added to C2y (via a
remote vote in May, not at a meeting).  Implement this in GCC.

The conceptual change, that the array subscripting operator [] no
longer involves an array operand decaying to a pointer, is something
GCC has done for a very long time.  The main effect in terms of what
is made possible in the language, subscripting a register array
(undefined behavior in C23 and before), was available as a GNU
extension, but only with constant indices.  There is also a new
constraint that array indices must not be negative when they are
integer constant expressions and the array operand has array type
(negative indices are fine with pointers) - an access out of bounds of
an array (even when contained within a larger object) has undefined
behavior at runtime when not a constraint violation.

Thus, the previous GCC extension is adapted to allow the cases of
register arrays not previously allowed, clearing DECL_REGISTER on them
as needed (similar to what is done with register declarations of
structures with volatile members) and restricting the pedwarn to
pedwarn_c23.  That pedwarn_c23 is also extended to cover the C23 case
of register compound literals (although not strictly needed since it
was undefined behavior rather than a constraint violation in C23).
The new error is added (only for flag_isoc2y) for negative array
indices with an operand of array type.

N3517 has some specific wording about the type of the result of
non-lvalue array element access.  It's unclear what's actually desired
there in the case where the array element is itself of array type; see
C23 issue 1001 regarding types of qualified members of rvalue
structures and unions more generally.  Rather than implementing the
specific wording about this in N3517, that is deferred until there's
an accepted resolution to issue 1001 and can be dealt with as part of
implementing such a resolution.

Nothing specific is done about the obsolescence in that paper of
writing index[array] or index[pointer] as opposed to array[index] or
pointer[index], although that seems like a reasonable enough thing to
warn about.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/c/
* c-typeck.cc (c_mark_addressable): New parameter
override_register.
(build_array_ref): Update calls to c_mark_addressable.  Give error
in C2Y mode for negative array indices when array expression is an
array not a pointer.  Use pedwarn_c23 for subscripting register
array; diagnose that also for register compound literal.
* c-tree.h (c_mark_addressable): Update prototype.

gcc/testsuite/
* gcc.dg/c23-array-negative-1.c, gcc.dg/c23-register-array-1.c,
gcc.dg/c23-register-array-2.c, gcc.dg/c23-register-array-3.c,
gcc.dg/c23-register-array-4.c, gcc.dg/c2y-array-negative-1.c,
gcc.dg/c2y-register-array-2.c, gcc.dg/c2y-register-array-3.c: New
tests.

3 weeks agoDaily bump.
GCC Administrator [Sat, 13 Sep 2025 00:19:19 +0000 (00:19 +0000)] 
Daily bump.

3 weeks agoFix latent LRA bug
Jeff Law [Fri, 12 Sep 2025 22:08:38 +0000 (16:08 -0600)] 
Fix latent LRA bug

Shreya's work to add the addptr pattern on the RISC-V port exposed a latent bug
in LRA.

We lazily allocate/reallocate the ira_reg_equiv structure and when we do
(re)allocation we'll over-allocate and zero-fill so that we don't have to
actually allocate and relocate the data so often.

In the case exposed by Shreya's work we had N requested entries at the last
rellocation step.  We actually allocate N+M entries.  During LRA we allocate
enough new pseudos and thus have N+M+1 pseudos.

In get_equiv we read ira_reg_equiv[regno] without bounds checking so we read
past the allocated part of the array and get back junk which we use and
depending on the precise contents we fault in various fun and interesting ways.

We could either arrange to re-allocate ira_reg_equiv again on some path through
LRA (possibly in get_equiv itself).  We could also just insert the bounds check
in get_equiv like is done elsewhere in LRA.  Vlad indicated no strong
preference in an email last week.

So this just adds the bounds check in a manner similar to what's done elsewhere
in LRA.  Bootstrapped and regression tested on x86_64 as well as RISC-V with
Shreya's work enabled and regtested across the various embedded targets.

gcc/
* lra-constraints.cc (get_equiv): Bounds check before accessing
data in ira_reg_equiv.

3 weeks agolibstdc++: ranges::rotate should use ranges::iter_move [PR121913]
Jonathan Wakely [Thu, 11 Sep 2025 16:39:43 +0000 (17:39 +0100)] 
libstdc++: ranges::rotate should use ranges::iter_move [PR121913]

Using std::move(*it) is incorrect for iterators that use proxy refs, we
should use ranges::iter_move(it) instead.

libstdc++-v3/ChangeLog:

PR libstdc++/121913
* include/bits/ranges_algo.h (__rotate_fn::operator()): Use
ranges::iter_move(it) instead of std::move(*it).
* testsuite/25_algorithms/rotate/121913.cc: New test.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
3 weeks agolibstdc++: Fix algorithms to use iterators' difference_type for arithmetic [PR121890]
Jonathan Wakely [Wed, 10 Sep 2025 11:00:57 +0000 (12:00 +0100)] 
libstdc++: Fix algorithms to use iterators' difference_type for arithmetic [PR121890]

Whenever we use operator+ or similar operators on random access
iterators we need to be careful to use the iterator's difference_type
rather than some other integer type. It's not guaranteed that an
expression with an arbitrary integer type, such as `it + 1u`, has the
same effects as `it + iter_difference_t<It>(1)`.

Some of our algorithms need changes to cast values to the correct type,
or to use std::next or ranges::next instead of `it + n`. Several tests
also need fixes where the arithmetic occurs directly in the test.

The __gnu_test::random_access_iterator_wrapper class template is
adjusted to have deleted operators that make programs ill-formed if the
argument to relevant operators is not the difference_type. This will
make it easier to avoid regressing in future.

libstdc++-v3/ChangeLog:

PR libstdc++/121890
* include/bits/ranges_algo.h (ranges::rotate, ranges::shuffle)
(__insertion_sort, __unguarded_partition_pivot, __introselect):
Use ranges::next to advance iterators. Use local variables in
rotate to avoid duplicate expressions.
(ranges::push_heap, ranges::pop_heap, ranges::partial_sort)
(ranges::partial_sort_copy): Use ranges::prev.
(__final_insertion_sort): Use iter_difference_t<Iter>
for operand of operator+ on iterator.
* include/bits/ranges_base.h (ranges::advance): Use iterator's
difference_type for all iterator arithmetic.
* include/bits/stl_algo.h (__search_n_aux, __rotate)
(__insertion_sort, __unguarded_partition_pivot, __introselect)
(__final_insertion_sort, for_each_n, random_shuffle): Likewise.
Use local variables in __rotate to avoid duplicate expressions.
* include/bits/stl_algobase.h (__fill_n_a, __lc_rai::__newlast1):
Likewise.
* include/bits/stl_heap.h (push_heap): Likewise.
(__is_heap_until): Add static_assert.
(__is_heap): Convert distance to difference_type.
* include/std/functional (boyer_moore_searcher::operator()): Use
iterator's difference_type for iterator arithmetic.
* testsuite/util/testsuite_iterators.h
(random_access_iterator_wrapper): Add deleted overloads of
operators that should be called with difference_type.
* testsuite/24_iterators/range_operations/advance.cc: Use
ranges::next.
* testsuite/25_algorithms/heap/constrained.cc: Use ranges::next
and ranges::prev.
* testsuite/25_algorithms/nth_element/58800.cc: Use std::next.
* testsuite/25_algorithms/nth_element/constrained.cc: Use
ptrdiff_t for loop variable.
* testsuite/25_algorithms/nth_element/random_test.cc: Use
iterator's difference_type instead of int.
* testsuite/25_algorithms/partial_sort/check_compare_by_value.cc:
Use std::next.
* testsuite/25_algorithms/partial_sort/constrained.cc: Use
ptrdiff_t for loop variable.
* testsuite/25_algorithms/partial_sort/random_test.cc: Use
iterator's difference_type instead of int.
* testsuite/25_algorithms/partial_sort_copy/constrained.cc:
Use ptrdiff_t for loop variable.
* testsuite/25_algorithms/partial_sort_copy/random_test.cc:
Use iterator's difference_type instead of int.
* testsuite/std/ranges/adaptors/drop.cc: Use ranges::next.
* testsuite/25_algorithms/fill_n/diff_type.cc: New test.
* testsuite/25_algorithms/lexicographical_compare/diff_type.cc:
New test.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
3 weeks agoTestsuite: Fix more spurious failure of ACATS-4 tests
Eric Botcazou [Fri, 12 Sep 2025 17:15:08 +0000 (19:15 +0200)] 
Testsuite: Fix more spurious failure of ACATS-4 tests

This tentatively applies the same tweak to twin testcases.

gcc/testsuite/
PR ada/121532
* ada/acats-4/tests/cxa/cxai034.a: Use Long_Switch_To_New_Task
constant instead of Switch_To_New_Task in delay statements.
* ada/acats-4/tests/cxa/cxai035.a: Likewise.
* ada/acats-4/tests/cxa/cxai036.a: Likewise.

3 weeks agoc++: pack indexing is a non-deduced context [PR121795]
Patrick Palka [Fri, 12 Sep 2025 18:21:25 +0000 (14:21 -0400)] 
c++: pack indexing is a non-deduced context [PR121795]

We weren't explicitly treating a pack index specifier as a non-deduced
context (as per [temp.deduct.type]/5), leading to an ICE for the first
testcase below.

PR c++/121795

gcc/cp/ChangeLog:

* pt.cc (unify) <case PACK_INDEX_TYPE>: New non-deduced context
case.

gcc/testsuite/ChangeLog:

* g++.dg/cpp26/pack-indexing17.C: New test.
* g++.dg/cpp26/pack-indexing17a.C: New test.

Reviewed-by: Marek Polacek <polacek@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
3 weeks agoRISC-V: Support vnclip idiom testcase [PR120378]
Edwin Lu [Mon, 8 Sep 2025 17:48:45 +0000 (10:48 -0700)] 
RISC-V: Support vnclip idiom testcase [PR120378]

This patch contains testcases for PR120378 after the change made to
support the vnclipu variant of the SAT_TRUNC pattern.

PR target/120378

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/pr120378-1.c: New test.
* gcc.target/riscv/rvv/autovec/pr120378-2.c: New test.
* gcc.target/riscv/rvv/autovec/pr120378-3.c: New test.
* gcc.target/riscv/rvv/autovec/pr120378-4.c: New test.

Signed-off-by: Edwin Lu <ewlu@rivosinc.com>
3 weeks agoMatch: Support SAT_TRUNC variant NARROW_CLIP
Edwin Lu [Tue, 5 Aug 2025 23:24:39 +0000 (16:24 -0700)] 
Match: Support SAT_TRUNC variant NARROW_CLIP

This patch tries to add support for a variant of SAT_TRUNC where
negative numbers are clipped to 0 instead of NARROW_TYPE_MAX_VALUE.
This form is seen in x264, aka

UT clip (T a)
{
  return a & (UT)(-1) ? (-a) >> 31 : a;
}

Where sizeof(UT) < sizeof(T)

I'm unable to get the SAT_TRUNC pattern to appear on x86_64, however it
does appear when building for riscv as seen below:

Before this patch:
  <bb 3> [local count: 764504183]:
  # i_21 = PHI <i_14(8), 0(15)>
  # vectp_x.10_54 = PHI <vectp_x.10_55(8), x_10(D)(15)>
  # vectp_res.20_66 = PHI <vectp_res.20_67(8), res_11(D)(15)>
  # ivtmp_70 = PHI <ivtmp_71(8), _69(15)>
  _72 = .SELECT_VL (ivtmp_70, POLY_INT_CST [4, 4]);
  _1 = (long unsigned int) i_21;
  _2 = _1 * 4;
  _3 = x_10(D) + _2;
  ivtmp_53 = _72 * 4;
  vect__4.12_57 = .MASK_LEN_LOAD (vectp_x.10_54, 32B, { -1, ... }, _56(D), _72, 0);
  vect_x.13_58 = VIEW_CONVERT_EXPR<vector([4,4]) unsigned int>(vect__4.12_57);
  vect__38.15_60 = -vect_x.13_58;
  vect__15.16_61 = VIEW_CONVERT_EXPR<vector([4,4]) int>(vect__38.15_60);
  vect__16.17_62 = vect__15.16_61 >> 31;
  mask__29.14_59 = vect_x.13_58 > { 255, ... };
  vect__17.18_63 = VEC_COND_EXPR <mask__29.14_59, vect__16.17_62, vect__4.12_57>;
  vect__18.19_64 = (vector([4,4]) unsigned char) vect__17.18_63;
  _4 = *_3;
  _5 = res_11(D) + _1;
  x.0_12 = (unsigned int) _4;
  _38 = -x.0_12;
  _15 = (int) _38;
  _16 = _15 >> 31;
  _29 = x.0_12 > 255;
  _17 = _29 ? _16 : _4;
  _18 = (unsigned char) _17;
  .MASK_LEN_STORE (vectp_res.20_66, 8B, { -1, ... }, _72, 0, vect__18.19_64);
  i_14 = i_21 + 1;
  vectp_x.10_55 = vectp_x.10_54 + ivtmp_53;
  vectp_res.20_67 = vectp_res.20_66 + _72;
  ivtmp_71 = ivtmp_70 - _72;
  if (ivtmp_71 != 0)
    goto <bb 8>; [89.00%]
  else
    goto <bb 17>; [11.00%]

After this patch:

 <bb 3> [local count: 764504183]:
  # i_21 = PHI <i_14(8), 0(15)>
  # vectp_x.10_68 = PHI <vectp_x.10_69(8), x_10(D)(15)>
  # vectp_res.15_75 = PHI <vectp_res.15_76(8), res_11(D)(15)>
  # ivtmp_79 = PHI <ivtmp_80(8), _78(15)>
  _81 = .SELECT_VL (ivtmp_79, POLY_INT_CST [4, 4]);
  _1 = (long unsigned int) i_21;
  _2 = _1 * 4;
  _3 = x_10(D) + _2;
  ivtmp_67 = _81 * 4;
  vect__4.12_71 = .MASK_LEN_LOAD (vectp_x.10_68, 32B, { -1, ... }, _70(D), _81, 0);
  vect_patt_37.13_72 = MAX_EXPR <{ 0, ... }, vect__4.12_71>;
  vect_patt_39.14_73 = .SAT_TRUNC (vect_patt_37.13_72);
  _4 = *_3;
  _5 = res_11(D) + _1;
  x.0_12 = (unsigned int) _4;
  _38 = -x.0_12;
  _15 = (int) _38;
  _16 = _15 >> 31;
  _29 = x.0_12 > 255;
  _17 = _29 ? _16 : _4;
  _18 = (unsigned char) _17;
  .MASK_LEN_STORE (vectp_res.15_75, 8B, { -1, ... }, _81, 0, vect_patt_39.14_73);
  i_14 = i_21 + 1;
  vectp_x.10_69 = vectp_x.10_68 + ivtmp_67;
  vectp_res.15_76 = vectp_res.15_75 + _81;
  ivtmp_80 = ivtmp_79 - _81;
  if (ivtmp_80 != 0)
    goto <bb 8>; [89.00%]
  else
    goto <bb 17>; [11.00%]

gcc/ChangeLog:

* match.pd: New NARROW_CLIP variant for SAT_TRUNC.
* tree-vect-patterns.cc (gimple_unsigned_integer_narrow_clip):
Add new decl for NARROW_CLIP.
(vect_recog_sat_trunc_pattern): Add NARROW_CLIP check.

Signed-off-by: Edwin Lu <ewlu@rivosinc.com>
3 weeks agosparc: Compile TLS LD tests with -fPIC
H.J. Lu [Wed, 10 Sep 2025 12:12:31 +0000 (05:12 -0700)] 
sparc: Compile TLS LD tests with -fPIC

After

commit 8cad8f94b450be9b73d07bdeef7fa1778d3f2b96
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Sep 5 15:40:51 2025 -0700

    c: Update TLS model after processing a TLS variable

GCC will upgrade local-dynamic TLS model to local-exec without -fPIC.
Compile TLS LD tests with -fPIC to keep local-dynamic TLS model.

PR testsuite/121888
* gcc.target/sparc/tls-ld-int16.c: Compile with -fPIC.
* gcc.target/sparc/tls-ld-int32.c: Likewise.
* gcc.target/sparc/tls-ld-int64.c: Likewise.
* gcc.target/sparc/tls-ld-int8.c: Likewise.
* gcc.target/sparc/tls-ld-uint16.c: Likewise.
* gcc.target/sparc/tls-ld-uint32.c: Likewise.
* gcc.target/sparc/tls-ld-uint8.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
3 weeks agodiagnostics: handle fatal_error in SARIF output [PR120063]
David Malcolm [Fri, 12 Sep 2025 14:24:36 +0000 (10:24 -0400)] 
diagnostics: handle fatal_error in SARIF output [PR120063]

gcc/ChangeLog:
PR diagnostics/120063
* diagnostics/context.cc (context::execution_failed_p): Also treat
any kind::fatal errors as leading to failed execution.
* diagnostics/sarif-sink.cc (maybe_get_sarif_level): Handle
kind::fatal as SARIF level "error".

gcc/testsuite/ChangeLog:
PR diagnostics/120063
* gcc.dg/fatal-error.c: New test.
* gcc.dg/fatal-error-html.py: New test.
* gcc.dg/fatal-error-sarif.py: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 weeks agodiagnostics: fix crash-handling inside nested diagnostics [PR121876]
David Malcolm [Fri, 12 Sep 2025 14:24:36 +0000 (10:24 -0400)] 
diagnostics: fix crash-handling inside nested diagnostics [PR121876]

PR diagnostics/121876 tracks an issue inside our crash-handling, where
if an ICE happens when we're within a nested diagnostic, an assertion
fails inside diagnostic::context::set_diagnostic_buffer, leading to
a 2nd ICE.  Happily, this does not infinitely recurse, but it obscures
the original ICE and the useful part of the backtrace, and any SARIF or
HTML sinks we were writing to are left as empty files.

This patch tweaks the above so that the assertion doesn't fail, and adds
test coverage (via a plugin) to ensure that such ICEs/crashes are
gracefully handled and e.g. captured in SARIF/HTML output.

gcc/ChangeLog:
PR diagnostics/121876
* diagnostics/buffering.cc (context::set_diagnostic_buffer): Add
early reject of the no-op case.

gcc/testsuite/ChangeLog:
PR diagnostics/121876
* gcc.dg/plugin/crash-test-nested-ice-html.py: New test.
* gcc.dg/plugin/crash-test-nested-ice-sarif.py: New test.
* gcc.dg/plugin/crash-test-nested-ice.c: New test.
* gcc.dg/plugin/crash-test-nested-write-through-null-html.py: New test.
* gcc.dg/plugin/crash-test-nested-write-through-null-sarif.py: New test.
* gcc.dg/plugin/crash-test-nested-write-through-null.c: New test.
* gcc.dg/plugin/crash_test_plugin.cc: Add "nested" argument, and when
set, inject the problem within a nested diagnostic.
* gcc.dg/plugin/plugin.exp: Add crash-test-nested-ice.c and
crash-test-nested-write-through-null.c.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>