]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
3 weeks agogcc/system.h: Allow for '#define INCLUDE_ITERATOR' to '#include <iterator>'
Thomas Schwinge [Wed, 8 Jul 2026 21:13:17 +0000 (23:13 +0200)] 
gcc/system.h: Allow for '#define INCLUDE_ITERATOR' to '#include <iterator>'

This avoids:

    In file included from /gnu/store/jdibb0iw7n0y56pq3rvz9fmzb4j60acr-gcc-5.5.0/include/c++/bits/basic_ios.h:37:0,
                     from /gnu/store/jdibb0iw7n0y56pq3rvz9fmzb4j60acr-gcc-5.5.0/include/c++/ios:44,
                     from /gnu/store/jdibb0iw7n0y56pq3rvz9fmzb4j60acr-gcc-5.5.0/include/c++/ostream:38,
                     from /gnu/store/jdibb0iw7n0y56pq3rvz9fmzb4j60acr-gcc-5.5.0/include/c++/iterator:64,
                     from ../../source-gcc/gcc/[...]
    /gnu/store/jdibb0iw7n0y56pq3rvz9fmzb4j60acr-gcc-5.5.0/include/c++/bits/locale_facets.h:247:53: error: macro "toupper" passed 2 arguments, but takes just 1
           toupper(char_type *__lo, const char_type* __hi) const
                                                         ^
    [...]

gcc/
* system.h [INCLUDE_ITERATOR]: '#include <iterator>'.

3 weeks agogcc/cp-tree: require that temp_override deduces on first constructor arg
Arsen Arsenović [Fri, 19 Jun 2026 18:21:14 +0000 (18:21 +0000)] 
gcc/cp-tree: require that temp_override deduces on first constructor arg

This helps force a conversion from the second argument into whatever
type the variable truly is.

This change ended up being unnecessary, but it is probably useful for
others anyway.

gcc/cp/ChangeLog:

* cp-tree.h (temp_override): In provided-value constructor,
don't deduce based on provided value.

3 weeks agoRegenerate i386.opt.urls
Mark Wielaard [Fri, 10 Jul 2026 09:25:59 +0000 (11:25 +0200)] 
Regenerate i386.opt.urls

riscv also got an -munroll-only-small-loops option. This means that
the doc urls for the existing -munroll-only-small-loops for i386 got
renamed (so they have distinct names). riscv.opt.urls already got
regenerated. Now also regenerate i386.opt.urls

Fixes: d15703b27aa4 RISC-V: Add small loop unrolling support via -munroll-only-small-loops
gcc/ChangeLog:

* config/i386/i386.opt.urls: Regenerate.

3 weeks agofold-mem-offsets: Convert from DF to RTL-SSA
Konstantinos Eleftheriou [Sat, 14 Jun 2025 15:39:54 +0000 (17:39 +0200)] 
fold-mem-offsets: Convert from DF to RTL-SSA

This patch converts the fold-mem-offsets pass from DF to RTL-SSA.
Along with this conversion, the way the pass collects information was
completely reworked.  Instead of visiting each instruction multiple
times, this is now done only once.

Most significant changes are:
* The pass operates mainly on insn_info objects from RTL-SSA.
* Single iteration over all nondebug INSNs for identification
  of fold-mem-roots.  Then walk of the fold-mem-roots' DEF-chain
  to collect foldable constants.
* The class fold_mem_info holds vectors for the DEF-chain of
  the to-be-folded INSNs (fold_agnostic_insns, which don't need
  to be adjusted, and fold_insns, which need their constant to
  be set to zero).
* Introduction of a single-USE mode, which only collects DEFs,
  that have a single USE and therefore are safe to transform
  (the fold-mem-root will be the final USE).  This mode is fast
  and will always run (unless disabled via -fno-fold-mem-offsets).
* Introduction of a multi-USE mode, which allows DEFs to have
  multiple USEs, but all USEs must be part of any fold-mem-root's
  DEF-chain.  The analysis of all USEs is expensive and therefore,
  this mode is disabled for highly connected CFGs, unless
  -fexpensive-optimizations (enabled by default at -O2) forces it on.
  Note that multi-USE mode will miss some opportunities that the
  single-USE mode finds (e.g. multi-USE mode fails for
  fold-mem-offsets-3.c).

The following testing was done:
* Bootstrapped and regtested on aarch64-linux, x86-64-linux and
  arm-linux.
* SPEC CPU tested on aarch64.

A compile time analysis with
  `/bin/time -v ./install/usr/local/bin/gcc -O2 all.i`
(all.i from PR117922) shows:
 * -fno-fold-mem-offsets:    1681 s (user time)
                             23626232 kBytes (max resident set size)
 * -ffold-mem-offsets:       1849 s (user time)
                             23625708 kBytes (max resident set size)

Multi-USE mode (on by default at -O2 via -fexpensive-optimizations) does
not have an impact on the duration or the memory footprint.

gcc/ChangeLog:

PR rtl-optimization/117922
* fold-mem-offsets.cc (INCLUDE_ALGORITHM):  Added definition.
(INCLUDE_FUNCTIONAL): Likewise.
(class pass_fold_mem_offsets): Moved to bottom of file.
(class change_info): New.
(def_shadowed_by_cond_exec_p): New.
(get_single_def_in_bb): Converted to RTL-SSA.
(get_fold_mem_offset_root): Converted to RTL-SSA.
(get_uses): Removed.
(fold_offsets): Converted to RTL-SSA.
(fold_offsets_value): New.
(fold_offsets_1): Converted to RTL-SSA.
(has_foldable_uses_p): Converted to RTL-SSA.
(get_fold_mem_root): Removed.
(insn_uses_not_in_bitmap): New.
(drop_unsafe_candidates): New.
(do_commit_offset): Converted to RTL-SSA.
(do_analysis): Removed.
(do_commit_insn): Converted to RTL-SSA.
(do_fold_info_calculation): Removed.
(sort_changes): New.
(struct regno_changes): New.
(sort_pairs): New.
(do_check_validity): Removed.
(get_last_def): New.
(move_uses_to_prev_def): New.
(compute_validity_closure): Removed.
(change_in_vec_p): New.
(cancel_changes_for_group): New.
(find_keys_to_remove): New.
(free_changes_info): New.
(update_insns): New.
(fold_mem_offsets_1): New.
(pass_fold_mem_offsets::execute): Moved to bottom of file.
(fold_mem_offsets): New.

gcc/testsuite/ChangeLog:

* g++.target/aarch64/fold-mem-offsets.C: New test.
* gcc.target/aarch64/fold-mem-offsets.c: New test.

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
3 weeks agoc++: Don't advertise __has_cpp_attribute (gnu::trivial_abi)
Jakub Jelinek [Fri, 10 Jul 2026 07:13:37 +0000 (09:13 +0200)] 
c++: Don't advertise __has_cpp_attribute (gnu::trivial_abi)

I've noticed we advertise __has_cpp_attribute (gnu::trivial_abi)
and __has_attribute (gnu::trivial_abi).  It is true we have
gnu::trivial_abi in the tables, but solely to give errors on those
when using the gnu:: scope and to suggest [[clang::trivial_abi]]
or __attribute__((trivial_abi)).

2026-07-10  Jakub Jelinek  <jakub@redhat.com>

PR c++/107187
* c-lex.cc (c_common_has_attribute): Don't advertise
__has_cpp_attribute (gnu::trivial_abi) in C++.

* g++.dg/cpp0x/attr-trivial_abi8.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
3 weeks agonvptx: Resolve 'flexible_array_member_type_p' conflict
Thomas Schwinge [Thu, 9 Jul 2026 22:52:46 +0000 (00:52 +0200)] 
nvptx: Resolve 'flexible_array_member_type_p' conflict

    [...]/source-gcc/gcc/config/nvptx/nvptx.cc:2485:1: error: ‘bool flexible_array_member_type_p(const_tree)’ was declared ‘extern’ and later ‘static’ [-fpermissive]
     2485 | flexible_array_member_type_p (const_tree type)
          | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from [...]/source-gcc/gcc/config/nvptx/nvptx.cc:30:
    [...]/source-gcc/gcc/tree.h:7022:13: note: previous declaration of ‘bool flexible_array_member_type_p(const_tree)’
     7022 | extern bool flexible_array_member_type_p (const_tree);
          |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

That's due to recent commit ed1d15e94f5ce28a9fdba6e3b255efef420c93f0
"c: harmonize checking for flex array member type".

gcc/
* config/nvptx/nvptx.cc (flexible_array_member_type_p): Rename to
'nvptx_flexible_array_member_type_p'.

3 weeks agoAda: Suppress access checks during analysis of expanded dispatching calls
Eric Botcazou [Fri, 10 Jul 2026 06:37:12 +0000 (08:37 +0200)] 
Ada: Suppress access checks during analysis of expanded dispatching calls

Expanded dispatching calls had been historically analyzed with all checks
disabled, but this was recently changed, thus causing the generation of a
lot of additional and useless access checks.

gcc/ada/
* exp_disp.adb (Expand_Dispatching_Call): Reenable the suppression
of access checks during analysis of expanded dispatching calls.

3 weeks agoFix m68k bootstrap due to diagnostic
Jeff Law [Fri, 10 Jul 2026 02:48:00 +0000 (20:48 -0600)] 
Fix m68k bootstrap due to diagnostic

Andreas S. noted I put the !! in the wrong place and should have kept
the macro parameter in its own parens.  Fix with the attached patch.

gcc
* config/m68k/m68k.h (ASM_PREFERRED_EH_DATA_FORMAT): Adjust parens
so they wrap the macro parameter.

3 weeks agoRISC-V: Adjust test case due to vf[sz]ext.vf4 overlap
Pan Li [Wed, 8 Jul 2026 13:55:33 +0000 (21:55 +0800)] 
RISC-V: Adjust test case due to vf[sz]ext.vf4 overlap

Remove the xfail due to vf4 changes.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/pr112431-16.c: Remove xfail.
* gcc.target/riscv/rvv/base/pr112431-17.c: Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
3 weeks agoRISC-V: Adjust the scan asm for v[sz]ext.vf2 for v1 and v12
Pan Li [Wed, 8 Jul 2026 05:57:43 +0000 (13:57 +0800)] 
RISC-V: Adjust the scan asm for v[sz]ext.vf2 for v1 and v12

The previous match v1 may match the v12 as well, therefore
add the non-num boundary.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf2-i16-m1.c:
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf2-i16-m2.c:
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf2-i16-m4.c:
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf2-i16-mf2.c:
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf2-i16-mf4.c:
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf2-i32-m1.c:
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf2-i32-m2.c:
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf2-i32-mf2.c:
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf2-i8-m1.c:
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf2-i8-m2.c:
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf2-i8-mf2.c:
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf2-i8-mf4.c:
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf2-i8-mf8.c:

Signed-off-by: Pan Li <pan2.li@intel.com>
3 weeks agoRISC-V: Add test cases for vzext.vf4 reg overlap
Pan Li [Wed, 8 Jul 2026 05:57:04 +0000 (13:57 +0800)] 
RISC-V: Add test cases for vzext.vf4 reg overlap

Add test cases for vzext.vf4 register group overlap, please
note it is not overlap as much as possible.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf4-u16-m1.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf4-u16-m2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf4-u16-mf2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf4-u16-mf4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf4-u8-m1.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf4-u8-m2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf4-u8-mf2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf4-u8-mf4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf4-u8-mf8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
3 weeks agoRISC-V: Add test cases for vsext.vf4 reg overlap
Pan Li [Wed, 8 Jul 2026 05:56:19 +0000 (13:56 +0800)] 
RISC-V: Add test cases for vsext.vf4 reg overlap

Add test cases for vsext.vf4 register group overlap, please
note it is not overlap as much as possible.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf4-i16-m1.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf4-i16-m2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf4-i16-mf2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf4-i16-mf4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf4-i8-m1.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf4-i8-m2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf4-i8-mf2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf4-i8-mf4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vsext_vf4-i8-mf8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
3 weeks agoRISC-V: Allow RVV register overlap for v[sz]ext.vf4
Pan Li [Wed, 8 Jul 2026 12:04:35 +0000 (20:04 +0800)] 
RISC-V: Allow RVV register overlap for v[sz]ext.vf4

Like v[sz]ext.vf2, allow the rvv register overlap
for v[sz]ext.vf4.

gcc/ChangeLog:

* config/riscv/riscv-protos.h (is_frac_vlmul_p): Add new func
decl to predicate frac vlmul for a mode.
* config/riscv/riscv-v.cc (is_frac_vlmul_p): Add new func impl
for above.
(riscv_v_widen_constraint_ok): Add Source and Dest lmul less
and equal 1 handling.
* config/riscv/vector.md: Leverage widen constraint Wvr.

Signed-off-by: Pan Li <pan2.li@intel.com>
3 weeks agomatch: Fix up `((a ^ b) & c) cmp d || a != b` pattern and add support for && case...
Andrew Pinski [Sat, 4 Jul 2026 07:32:03 +0000 (00:32 -0700)] 
match: Fix up `((a ^ b) & c) cmp d || a != b` pattern and add support for && case [PR116860]

Turns out it was easy to fix these patterns for
`--param=logical-op-non-short-circuit=0` case after all.
Just add support for `((a ^ b) & c) cmp d && a == b`
which is the same as `!(((a ^ b) & c) cmp d || a != b)`.
So this adds the bit_and case to support exactly that.
Also fixes up some of the `:c` on the operands.
`:c` needs to be on the outer bitop and does not need to be
on the inner one for bit_xor as it will be the same order as ne/eq.

PR tree-optimization/116860
PR tree-optimization/114326
gcc/ChangeLog:

* match.pd (`((a ^ b) & c) cmp d || a != b`): Expand
to support bit_and and fix up the :c.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/fold-xor-and-or-1.c: New test.
* gcc.dg/tree-ssa/fold-xor-or-1.c: New test.
* gcc.dg/tree-ssa/pr102793-1.c: Update for the optimization
happening in pre.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
3 weeks agoDaily bump.
GCC Administrator [Fri, 10 Jul 2026 00:16:35 +0000 (00:16 +0000)] 
Daily bump.

3 weeks agoopenmp: Pass iteration count to static worksharing builtins for OMPT
Paul-Antoine Arras [Wed, 1 Jul 2026 16:51:07 +0000 (18:51 +0200)] 
openmp: Pass iteration count to static worksharing builtins for OMPT

Add parameter to GOMP_{loop,distribute}_static_worksharing{,_start} carrying the
total number of loop iterations. niter is unused for now, pending OMPT
implementation.

The call in omp-expand.cc is moved after the iteration count computation
so that the iteration count is available to pass as the argument.

gcc/ChangeLog:

* builtin-types.def (BT_FN_COMPLEX_INT): Remove.
(BT_FN_COMPLEX_INT_ULONGLONG): New.
* omp-builtins.def (BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING): Use
BT_FN_COMPLEX_INT_ULONGLONG.
(BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_START): Likewise.
(BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING): Likewise.
(BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_START): Likewise.
* omp-expand.cc (expand_omp_for_static_nochunk): Move worksharing
builtin call after iteration count computation; pass n as niter.
(expand_omp_for_static_chunk): Likewise.

gcc/fortran/ChangeLog:

* types.def (BT_FN_COMPLEX_INT): Remove.
(BT_FN_COMPLEX_INT_ULONGLONG): New.

libgomp/ChangeLog:

* config/gcn/teams.c (GOMP_distribute_static_worksharing): Add
long niter parameter (unused).
(GOMP_distribute_static_worksharing_start): Likewise.
* config/nvptx/teams.c (GOMP_distribute_static_worksharing):
Likewise.
(GOMP_distribute_static_worksharing_start): Likewise.
* libgomp.texi: Update function signatures; fix real/imaginary
description; document niter parameter.
* libgomp_g.h (GOMP_loop_static_worksharing): Update prototype.
(GOMP_distribute_static_worksharing): Likewise.
* loop.c (GOMP_loop_static_worksharing): Add long niter parameter
(unused).
(GOMP_loop_static_worksharing_start): Likewise.
* teams.c (GOMP_distribute_static_worksharing): Likewise.
(GOMP_distribute_static_worksharing_start): Likewise.
* testsuite/libgomp.c-c++-common/for-static-1.c: Update scan
pattern to match niter argument.
* testsuite/libgomp.c-c++-common/for-static-2.c: Likewise.
* testsuite/libgomp.c-c++-common/for-static-3.c: Likewise.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/for-static-1.c: Update scan pattern to match
niter argument.
* c-c++-common/gomp/for-static-2.c: Likewise.
* c-c++-common/gomp/for-static-3.c: Likewise.

Co-authored-by: Thomas Schwinge <tschwinge@baylibre.com>
3 weeks agoopenmp: Add OMPT entry points for worksharing-loop, single, and masked constructs
Paul-Antoine Arras [Tue, 30 Jun 2026 09:06:44 +0000 (11:06 +0200)] 
openmp: Add OMPT entry points for worksharing-loop, single, and masked constructs

Add two new compiler flags, -fopenmp-ompt and -fopenmp-ompt-detailed, that
cause the compiler to emit OMPT-aware runtime entry points around OpenMP
worksharing constructs.  With -fopenmp-ompt, the _start and _end variants
are called instead of the plain worksharing functions; with
-fopenmp-ompt-detailed, a _dispatch stub is additionally called after the
chunk bounds are computed.  New stubs are added to libgomp as placeholders
for future OMPT callback invocations.

gcc/ChangeLog:

* common.opt (fopenmp-ompt): New option.
(fopenmp-ompt-detailed): New option.
* common.opt.urls: Regenerate.
* doc/invoke.texi (Option Summary): Add -fopenmp-ompt and
-fopenmp-ompt-detailed.
(OpenMP and OpenACC Options): Document -fopenmp-ompt and
-fopenmp-ompt-detailed.
* omp-builtins.def (BUILT_IN_GOMP_SINGLE_START_WITH_END): New builtin.
(BUILT_IN_GOMP_SINGLE_END): New builtin.
(BUILT_IN_GOMP_MASKED_END): New builtin.
(BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_START): New builtin.
(BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_END): New builtin.
(BUILT_IN_GOMP_LOOP_STATIC_WORKSHARING_DISPATCH): New builtin.
(BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_START): New builtin.
(BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_END): New builtin.
(BUILT_IN_GOMP_DISTRIBUTE_STATIC_WORKSHARING_DISPATCH): New builtin.
* omp-expand.cc (expand_omp_for_static_nochunk): With -fopenmp-ompt,
emit _start and _end variants instead of the plain worksharing call;
with -fopenmp-ompt-detailed, also emit _dispatch.
(expand_omp_for_static_chunk): Likewise.
* omp-low.cc (lower_omp_single_simple): With -fopenmp-ompt, use
GOMP_single_start_with_end instead of GOMP_single_start.
(lower_omp_single): With -fopenmp-ompt, emit GOMP_single_end.
(lower_omp_master): With -fopenmp-ompt, emit GOMP_masked_end.
* opts.cc (finish_options): Diagnose -fopenmp-ompt and
-fopenmp-ompt-detailed used without -fopenmp.

libgomp/ChangeLog:

* config/gcn/teams.c (GOMP_distribute_static_worksharing_start,
GOMP_distribute_static_worksharing_dispatch,
GOMP_distribute_static_worksharing_end): New functions.
* config/nvptx/teams.c (GOMP_distribute_static_worksharing_start,
GOMP_distribute_static_worksharing_dispatch,
GOMP_distribute_static_worksharing_end): Likewise.
* libgomp.map (GOMP_6.0.2): Export new entry points.
* libgomp_g.h: Add prototypes for GOMP_loop_static_worksharing,
GOMP_loop_static_worksharing_start, GOMP_loop_static_worksharing_dispatch,
GOMP_loop_static_worksharing_end, GOMP_has_masked_thread_num,
GOMP_masked_end, GOMP_single_start_with_end, GOMP_single_end,
GOMP_distribute_static_worksharing_start,
GOMP_distribute_static_worksharing_dispatch, and
GOMP_distribute_static_worksharing_end.
* loop.c (GOMP_loop_static_worksharing): Move here from parallel.c.
(GOMP_loop_static_worksharing_start): New function.
(GOMP_loop_static_worksharing_dispatch): New stub.
(GOMP_loop_static_worksharing_end): New stub.
(GOMP_has_masked_thread_num): Move here from parallel.c.
(GOMP_masked_end): New stub.
* parallel.c (GOMP_loop_static_worksharing): Move to loop.c.
(GOMP_has_masked_thread_num): Move to loop.c.
* single.c (GOMP_single_start_with_end): New function.
(GOMP_single_end): New stub.
(GOMP_single_copy_start): Fix trailing whitespace.
* teams.c (GOMP_distribute_static_worksharing_start): New function.
(GOMP_distribute_static_worksharing_dispatch): New stub.
(GOMP_distribute_static_worksharing_end): New stub.
* testsuite/libgomp.c-c++-common/for-static-1.c: New test.
* testsuite/libgomp.c-c++-common/for-static-2.c: New test.
* testsuite/libgomp.c-c++-common/for-static-3.c: New test.
* testsuite/libgomp.c-c++-common/for-static.h: New test.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/masked-1.c: Add scan-tree-dump-not check that
GOMP_masked_end is not emitted without -fopenmp-ompt.
* c-c++-common/gomp/for-8.c: Remove; superseded by for-static-*.c.
* c-c++-common/gomp/for-static-1.c: New test; checks that the plain
worksharing builtins are emitted without -fopenmp-ompt.
* c-c++-common/gomp/for-static-2.c: New test; checks that _start and
_end variants are emitted with -fopenmp-ompt.
* c-c++-common/gomp/for-static-3.c: New test; checks that _dispatch is
also emitted with -fopenmp-ompt-detailed.
* c-c++-common/gomp/for-static.h: New shared test header.
* c-c++-common/gomp/masked-3.c: New test for GOMP_masked_end emission
with -fopenmp-ompt.
* c-c++-common/gomp/openmp-ompt-1.c: New test; checks that
-fopenmp-ompt without -fopenmp is diagnosed.
* c-c++-common/gomp/openmp-ompt-2.c: New test; checks that
-fopenmp-ompt-detailed without -fopenmp is diagnosed.
* c-c++-common/gomp/single2.c: New test for GOMP_single_start_with_end
and GOMP_single_end emission with -fopenmp-ompt.

3 weeks agocselib: Restore 32-bit hash [PR126169]
Richard Sandiford [Thu, 9 Jul 2026 21:44:54 +0000 (22:44 +0100)] 
cselib: Restore 32-bit hash [PR126169]

r17-629-g582adc3c97b1e0 shrank cselib_val::hash to 30 bits in order
to free up two bits for new flags.  However, I hadn't realised that
cselib_hash_rtx uses zero as an error return and so requires the hash
to be nonzero.  In the PR, trimming the hash to 30 bits had the effect
of dropping the only nonzero bits, leading cselib_lookup_1 to fail even
when the "create" parameter was true.

Rather than fight against the system, it seemed better to restore the
hash to 32 bits and get the space another way: by moving the uid field
from cselib_val to the u2 field of the VALUE rtx.  This slightly
complicates some uses and slightly simplifies others.

There is currently a 1:1 mapping between VALUEs and cselib_vals.
The only time val_rtx is set is in new_cselib_val:

  e->val_rtx = (rtx_def*) value_pool.allocate ();

and the only times CSELIB_VAL_PTR is set are in new_cselib_val:

  CSELIB_VAL_PTR (e->val_rtx) = e;

and discard_useless_values:

      CSELIB_VAL_PTR (v->val_rtx) = NULL;

If in future we allowed multiple VALUEs to point to the same cselib_val
(e.g. for canonical_cselib_val), we would need to copy CSELIB_VAL_UID at
the same time as copying CSELIB_VAL_PTR.

gcc/
PR debug/126169
* rtl.h (rtx_def::u2): Add value_uid to the union.
(CSELIB_VAL_UID): New macro.
* cselib.h (cselib_val::HASH_MASK): Delete.
(cselib_val::hash): Restore to a full int.
(cselib_val::uid): Delete.
(canonical_cselib_val): Use CSELIB_VAL_UID instead of cselib_val::uid.
* alias.cc (refs_newer_value_p): Likewise.
* dse.cc (canon_address): Likewise.
* print-rtl.cc (rtx_writer::print_rtx_operand_code_0): Likewise.
* var-tracking.cc (dv_uid, canon_value_cmp): Likewise.
(variable_post_merge_new_vals): Likewise.
* cselib.cc (new_elt_loc_list, new_cselib_val): Likewise.
(cselib_lookup): Likewise.
(cselib_find_slot): Remove use of cselib_val::HASH_MASK.

3 weeks agom68k: Properly model bset/bclr on memory
Andreas Schwab [Thu, 9 Jul 2026 18:24:35 +0000 (20:24 +0200)] 
m68k: Properly model bset/bclr on memory

When operating on memory the bset and bclr insns use only the low 3 bits
of the bit number.

PR target/126121
gcc/
* config/m68k/m68k.md (bsetmemqi, *bsetmemqi_ext, bclrmemqi)
(*bclrmemqi_ext): Add AND with 7 around bit number.
gcc/testsuite/
* gcc.dg/torture/pr126121.c: New test.

3 weeks agoRemove uses of `CONSTEXPR` macro
Karl Meakin [Thu, 9 Jul 2026 14:04:49 +0000 (14:04 +0000)] 
Remove uses of `CONSTEXPR` macro

The `CONSTEXPR` macro was used to support building GCC with compiler
that don't support `constexpr`, but we have required GCC to be built
with in C++14 mode for a few years now, so any compiler will have to
support `constexpr` anyway.

gcc/ChangeLog:

* bitmap.h: Replace uses of `CONSTEXPR` with `constexpr`.
* config/aarch64/aarch64-acle-builtins.cc: Likewise.
* config/aarch64/aarch64-builtins.cc: Likewise.
* config/aarch64/aarch64-protos.h: Likewise.
* config/aarch64/aarch64-sve-builtins-base.cc: Likewise.
* config/aarch64/aarch64-sve-builtins-functions.h: Likewise.
* config/aarch64/aarch64-sve-builtins-shapes.cc: Likewise.
* config/aarch64/aarch64-sve-builtins-sme.cc: Likewise.
* config/aarch64/aarch64-sve-builtins-sve2.cc: Likewise.
* config/aarch64/aarch64.cc: Likewise.
* config/aarch64/driver-aarch64.cc: Likewise.
* config/arm/arm-mve-builtins-base.cc: Likewise.
* config/arm/arm-mve-builtins-functions.h: Likewise.
* config/arm/arm-mve-builtins-shapes.cc: Likewise.
* config/arm/arm-mve-builtins.cc: Likewise.
* config/riscv/andes-vector-builtins-bases.cc: Likewise.
* config/riscv/riscv-protos.h: Likewise.
* config/riscv/riscv-vector-builtins-bases.cc: Likewise.
* config/riscv/riscv-vector-builtins-shapes.cc: Likewise.
* config/riscv/riscv-vector-builtins.cc: Likewise.
* config/riscv/riscv-vector-builtins.h: Likewise.
* config/riscv/sifive-vector-builtins-bases.cc: Likewise.
* machmode.h: Likewise.

3 weeks agoaarch64: Ignore vcopy_lane_indices.c on 32-bit targets
Karl Meakin [Tue, 7 Jul 2026 16:53:26 +0000 (16:53 +0000)] 
aarch64: Ignore vcopy_lane_indices.c on 32-bit targets

The `vcopy_lane` family of intrinsics are only available on AArch64
targets (ie not on 32-bit targets), so the test should be ignored on
those targets.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/advsimd-intrinsics/vcopy_lane_indices.c:
Don't test this file on 32-bit targets.

3 weeks agoamdgcn: Testsuite cond_fmaxnm fixups
Andrew Stubbs [Thu, 9 Jul 2026 16:27:54 +0000 (16:27 +0000)] 
amdgcn: Testsuite cond_fmaxnm fixups

These testcases had a typo that means they scan for SFmode twice, and DFmode
never.  They were also incompatible with the pattern names in my address vector
patches (not yet committed).

This patch fixes both issues.

gcc/testsuite/ChangeLog:

* gcc.target/gcn/cond_fmaxnm_3.c: Fix assembler scan patterns.
* gcc.target/gcn/cond_fmaxnm_4.c: Fix assembler scan patterns.
* gcc.target/gcn/cond_fminnm_3.c: Fix assembler scan patterns.
* gcc.target/gcn/cond_fminnm_4.c: Fix assembler scan patterns.

3 weeks agotree-ssa-math-opts: separate FMA-deferring trigger from reassoc reorder
Philipp Tomsich [Thu, 9 Jul 2026 16:08:08 +0000 (18:08 +0200)] 
tree-ssa-math-opts: separate FMA-deferring trigger from reassoc reorder

param_avoid_fma_max_bits gates two independent transforms: the
widening_mul FMA-deferring in tree-ssa-math-opts.cc, which leaves a
loop-carried multiply-add as fmul + fadd, and the reassoc
loop-carried-FMA reorder added in r14-5779-g746344dd538
(PR tree-optimization/110279), which parallelises 3+ operand chains.
Both fire when TYPE_SIZE (elt) <= avoid-fma-max-bits, so for a given
type they switch on at the same threshold and a target cannot keep one
while dropping the other.

This hurts the AArch64 AVOID_CROSS_LOOP_FMA cores (the Ampere-1
family): a 2-operand reduction such as an sgemm inner K-loop is left as
fmul + fadd, slower than fmadd on their dispatch-bound pipeline, yet
setting avoid-fma-max-bits to 0 to avoid it also disables the reorder.

Add a new --param=widening-mul-defer-fma (default 1) that gates only the
widening_mul deferring; avoid-fma-max-bits keeps gating the reorder
alone.  The AVOID_CROSS_LOOP_FMA callback sets the param to 0.  No other
target and no default behaviour changes.

gcc/ChangeLog:

* doc/params.texi (widening-mul-defer-fma): Document.
* params.opt (-param=widening-mul-defer-fma=): New param.
* tree-ssa-math-opts.cc (math_opts_dom_walker::after_dom_children):
Gate fma_deferring_state's enable predicate on
param_widening_mul_defer_fma on top of param_avoid_fma_max_bits.
* config/aarch64/aarch64-tuning-flags.def (AVOID_CROSS_LOOP_FMA):
Update the comment for the widening-mul-defer-fma effect.
* config/aarch64/aarch64.cc (aarch64_override_options_internal):
Inside the AARCH64_EXTRA_TUNE_AVOID_CROSS_LOOP_FMA block, set
param_widening_mul_defer_fma to 0.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/widening-mul-defer-fma-1.c: New test.
* gcc.target/aarch64/widening-mul-defer-fma-2.c: New test.
* gcc.target/aarch64/widening-mul-defer-fma-3.c: New test.

3 weeks agoAllow tm files to add generator programs
Nathan Sidwell [Mon, 22 Jun 2026 18:26:07 +0000 (14:26 -0400)] 
Allow tm files to add generator programs

gcc/
* Makefile.in (genprogrtl, genprogmd, genprogerr, genprog): Append,
rather than set.
* config/riscv/t-riscv: Delete genrvv-type-indexer workaround rule,
it is no longer needed.

3 weeks agoipa-cp: Only create all-context nodes for local cgraph nodes (PR125207)
Martin Jambor [Thu, 9 Jul 2026 15:17:50 +0000 (17:17 +0200)] 
ipa-cp: Only create all-context nodes for local cgraph nodes (PR125207)

IPA-CP contains special logic to create specially marked clones with
constants that come from all callees (that are constant in all
contexts).  In the past that was the only case in which the heuristics
tried to assess the effect of multiple constants at once (that is no
longer true since GCC 16) and they are also useful when we realize we
can refine them still further in the case of recursive calls (such as
in testsuite/gcc.dg/ipa/pr93707.c) turn to carry more constants after
the initial "all-context" clone is created.

Unfortunately, the code creating the clones simply redirects all
incoming call graph edges which may include those which were indirect
in the phase of the algorithm which gathered IPA-CP lattices and the
arguments in these calls might contain different values than all
initially known ones, leading to miscompilations like the one in
PR125207.

Since GCC 16 already feeds the heuristics with all known constants
that are passed along with the constant the evaluation was initiated
for, the all-context nodes are really only necessary for the recursive
refinement cases described above.  It seems appropriate to only create
them when they are what they are called, when there can be no indirect
or unknown calls to them, i.e. when they are local.  This has the nice
effect of simplifying decide_whether_version_node somewhat.

There is some testsuite fallout.  First, IPA-CP will now no longer
clone a non-static function to only remove a (non-constant) parameter.
This likely only makes sense with tiny values of param
ipa-cp-eval-threshold or very small functions which are likely going
to be inlined anyway.  But gcc.dg/vla-1.c expected that to happen so I
made the function to be cloned static.

The testcase libgomp.c/ipcp-cb-spec1.c stopped working for the same
reason (the outlined task body has its address taken) but looking into
the dumps the test does not seem to test what it is supposed to, the
test function was completely eliminated before IPA.  I have therefore
changed it to really propagate constants.

gcc/ChangeLog:

2026-06-02  Martin Jambor  <mjambor@suse.cz>

PR ipa/125207
* ipa-cp.cc (decide_about_value): Add detailed dumping about skipping
a value when there are no edges for it.  Make dumping about skipping
because of growth limit violation consistent with other cases.
(decide_whether_version_node): Only create all-context nodes for local
nodes, remove the logic doing it in other cases, allow cloning for
single constant lattices for non-local nodes.  Adjust dumping.

gcc/testsuite/ChangeLog:

2026-06-02  Martin Jambor  <mjambor@suse.cz>

PR ipa/125207
* gcc.dg/ipa/pr125207.c: New test.
* gcc.dg/vla-1.c (f1): Make function f1 static.

libgomp/ChangeLog:

2026-06-03  Martin Jambor  <mjambor@suse.cz>

PR ipa/125207
* testsuite/libgomp.c/ipcp-cb-spec1.c (test): Rework.

3 weeks agocobol: prevent invalid TYPE reference, and define YYLOCATION_PRINT
James K. Lowden [Thu, 9 Jul 2026 14:42:42 +0000 (10:42 -0400)] 
cobol: prevent invalid TYPE reference, and define YYLOCATION_PRINT

gcc/cobol/ChangeLog:

PR cobol/126105
* parse.y: Remove unnecessary test and improve diagnostic message.
* parse_ante.h (yylocation_print): New function.
(YYLOCATION_PRINT): Define, because user-defined cbl_loc_t location.
* symbols.cc (symbol_typedef): Exclude current field from type search.
* symbols.h (symbol_typedef): Delete unused overload.

3 weeks ago[PATCH] RISC-V: Fix memcpy size threshold gating in vector block move
Jim Lin [Thu, 9 Jul 2026 15:02:51 +0000 (09:02 -0600)] 
[PATCH] RISC-V: Fix memcpy size threshold gating in vector block move

In riscv_vector_expand_block_move, the memcpy path (!movmem_p) compared
the length against riscv_memcpy_size_threshold but gated the check on
riscv_memmove_size_threshold >= 0.  Both params default to -1, so the
memcpy threshold was honored only when the unrelated memmove param was
set, and when memmove was set but memcpy left at -1 the "length > -1"
test rejected every constant-length copy.

Gate the memcpy path on riscv_memcpy_size_threshold, matching the
memmove branch above.

gcc/ChangeLog:

* config/riscv/riscv-string.cc (riscv_vector_expand_block_move):
Gate the memcpy path on riscv_memcpy_size_threshold instead of
riscv_memmove_size_threshold.

3 weeks agoivopts: Set register pressure cost to zero if there are enough registers.
Jovan Dmitrovic [Thu, 9 Jul 2026 13:31:17 +0000 (07:31 -0600)] 
ivopts: Set register pressure cost to zero if there are enough registers.

In function ivopts_estimate_reg_pressure, return zero if there are
enough registers available so that spilling is not necessary.

gcc/ChangeLog:

* tree-ssa-loop-ivopts.cc (ivopts_estimate_reg_pressure):
Return zero if there are enough registers to store new
invariants and induction variables.

Suggested-by: Richard Biener <richard.guenther@gmail.com>
Signed-off-by: Jovan Dmitrović <jovan.dmitrovic@htecgroup.com>
Signed-off-by: Djordje Todorović <djordje.todorovic@htecgroup.com>
Signed-off-by: Chao-Ying Fu <chao-ying.fu@globalfoundries.com>
Signed-off-by: Radosav Krunić <radosav.krunic@htecgroup.com>
3 weeks ago[PATCH v3 1/2] MATCH: Simplify `(trunc)copysign ((extend)x, CST)` to `copysign (x...
Eikansh Gupta [Thu, 9 Jul 2026 13:24:31 +0000 (07:24 -0600)] 
[PATCH v3 1/2] MATCH: Simplify `(trunc)copysign ((extend)x, CST)` to `copysign (x, -1.0/1.0)` [PR112472]

Add a pattern for `(trunc)copysign ((extend)x, CST)`.  Only the sign of
CST matters, not its value, so it can be simplified to
`copysign (x, -1.0/1.0)` depending on the sign of CST.

PR tree-optimization/112472

gcc/ChangeLog:

* match.pd ((trunc)copysign ((extend)x, CST) --> copysign (x, -1.0/1.0)):
New pattern.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr112472.c: New test.

3 weeks agocobol: add diagnostic for SORT without defined key
James K. Lowden [Wed, 8 Jul 2026 22:16:27 +0000 (18:16 -0400)] 
cobol: add diagnostic for SORT without defined key

gcc/cobol/ChangeLog:

PR cobol/126106
* parse.y: Report error instead of crashing.

3 weeks agotree-optimization: Recognize widened unsigned multiply overflow checks
Zhou Xuhang [Thu, 4 Jun 2026 03:31:14 +0000 (11:31 +0800)] 
tree-optimization: Recognize widened unsigned multiply overflow checks

For unsigned operands, a widened multiplication compared against the maximum
value of the narrow type is an overflow check when the widened type is at
least twice as precise as the operand type.

Canonicalize the shifted high-half form to the widened comparison form, then
fold the comparison form to IFN_MUL_OVERFLOW when the target has direct
unsigned multiply-overflow support.

gcc/
* match.pd: Canonicalize shifted high-half unsigned multiply
overflow checks to widened comparisons.  Simplify widened unsigned
multiply comparison against the narrow type maximum to IFN_MUL_OVERFLOW.

gcc/testsuite/
* g++.target/i386/mul-overflow-widen-1.C: New test.
* g++.target/i386/mul-overflow-widen-2.C: New test.

Signed-off-by: Zhou Xuhang <zhouxh2002@gmail.com>
3 weeks agors6000: Corrections for the AES builtins for powerpc
Avinash Jayakar [Thu, 9 Jul 2026 08:15:30 +0000 (13:45 +0530)] 
rs6000: Corrections for the AES builtins for powerpc

This patch fixes few implementations issues for the AES builtins in
powerpc in documentation, testcases and builtin definition.

2026-07-09  Avinash Jayakar  <avinashd@linux.ibm.com>

gcc/ChangeLog:
* config/rs6000/rs6000-builtins.def: Move AES builtins to future-vsx
stanza.
* doc/extend.texi: Add subheading for AES builtins.

gcc/testsuite/ChangeLog:
* gcc.target/powerpc/aes-builtin-1.c: Add future_compile_ok and lp64
testsuite directive.
* gcc.target/powerpc/aes-builtin-2.c: Add future_compile_ok and lp64
testsuite directive.
* gcc.target/powerpc/aes-builtin-3.c: Add future_compile_ok and lp64
testsuite directive.

3 weeks agos390: Remove -m31 support
Stefan Schulze Frielinghaus [Thu, 9 Jul 2026 07:28:12 +0000 (09:28 +0200)] 
s390: Remove -m31 support

This patch removes -m31 support and as a consequence -mesa support.
Using the respective command line options result in errors whereas -m64
and -mzarch are still accepted for the sake of backwards compatibility
but do not have any additional effect anymore since those are the
defaults and only options, now.

Since a 64-bit GAS defaults to -m64, do not explicitly specify -m64
-mzarch anymore.

ChangeLog:

* configure: Regenerate.
* configure.ac: Remove deprecation warning for -m31.

contrib/ChangeLog:

* compare-all-tests: Remove opts -m31 and so on.
* config-list.mk: Remove s390-linux-gnu.

gcc/ChangeLog:

* config.gcc: Remove target s390-*. Don't accept
--with-mode=esa anymore.
* config.host: Remove target s390-*.
* config/host-linux.cc (TRY_EMPTY_VM_SPACE): Remove definition
for s390.
* config/s390/2827.md: Remove scheduling information for
mnemonics which are only used by -m31 but not by -m64.
* config/s390/2964.md: Ditto.
* config/s390/3906.md: Ditto.
* config/s390/3931.md: Ditto.
* config/s390/8561.md: Ditto.
* config/s390/9175.md: Ditto.
* config/s390/constraints.md (ZL): Remove TARGET_64BIT test.
* config/s390/driver-native.cc (s390_host_detect_local_cpu):
Remove handling for -mesa/-mzarch.
* config/s390/htmxlintrin.h (__TM_failure_address): Remove
-m31 part.
* config/s390/linux.h: Remove -m31 parts.
* config/s390/predicates.md: Ditto.
* config/s390/s390-builtins.def: Rename RTL expander name for
s390_vsce[fg].
* config/s390/s390-c.cc (s390_cpu_cpp_builtins): Remove
TARGET_{64BIT,ZARCH} tests.
* config/s390/s390-d.cc (s390_d_target_versions): Remove
TARGET_64BIT test.
* config/s390/s390.cc: Remove -m31 parts.  In particular, there
is no need to distinguish between 64-bit registers in ABI
contexts anymore which is why UNITS_PER_WORD and UNITS_PER_LONG
always equal, now.  Hence, replace UNITS_PER_LONG by
UNITS_PER_WORD.
* config/s390/s390.h: Ditto.
* config/s390/s390.md: Ditto. Mode iterator GPR is replaced by
DSI. Likewise, DGPR by new mode iterator TDSI.  Remove mode
iterators P, DW, W because they are singletons, now.
* config/s390/s390.opt: Keep -m64 and -mzarch for backwards
compatibility.  Mark -m31 and -mesa as undocumented.
* config/s390/s390.opt.urls: Regenerate.
* config/s390/t-linux64: Remove -m31 parts.
* config/s390/tpf.h (POINTERS_EXTEND_UNSIGNED): This is only
required for TPF which is why it is moved from s390.h here.
(TARGET_DEFAULT): Remove MASK_64BIT and MASK_ZARCH.
* config/s390/vector.md: Remove -m31 parts.
* config/s390/vx-builtins.md
(vec_scatter_element<V_HW_2:mode>_SI): There is no need for
multiplexing different address sizes for vec_scatter_element
anymore.
(vec_scatter_element<V_HW_32_64:mode>): Ditto.
* configure: Regenerate.
* configure.ac: Remove target s390-*.
* doc/install.texi: Remove mentions of s390 without also
referring to s390x.
* doc/invoke.texi: Remove options -m31 and -mesa.  Document that
-m64 and -mzarch are the defaults, now, and that they don't have
any additional effect when explicitly specified.
* config/s390/s390x.h: Removed.

libgcc/ChangeLog:

* config.host: Remove target s390-*.  Remove -m31 part.
* config/s390/libgcc-glibc.ver: Remove -m31 part.
* config/s390/morestack.S: Ditto.
* config/s390/sfp-machine.h: Ditto.
* configure: Regenerate.
* configure.ac: Remove target s390-*.
* generic-morestack.c: Remove -m31 part.
* config/s390/32/_fixdfdi.c: Removed.
* config/s390/32/_fixsfdi.c: Removed.
* config/s390/32/_fixtfdi.c: Removed.
* config/s390/32/_fixunsdfdi.c: Removed.
* config/s390/32/_fixunssfdi.c: Removed.
* config/s390/32/_fixunstfdi.c: Removed.
* config/s390/32/t-floattodi: Removed.

libgm2/ChangeLog:

* configure.host: Remove s390 host part; keep s390x.

libitm/ChangeLog:

* config/s390/sjlj.S: Remove -m31 part.

libstdc++-v3/ChangeLog:

* configure.host: Remove s390 host part; keep s390x.

gcc/testsuite/ChangeLog:

* gcc.dg/asm-hard-reg-error-3.c: Remove target s390-*.
* gcc.dg/builtin-bswap-8.c: Remove target s390-*.
* gcc.dg/ifcvt-4.c: Remove -m31 part.
* gcc.dg/optimize-bswaphi-1.c: Ditto.
* gcc.dg/optimize-bswapsi-3.c: Ditto.
* gcc.dg/optimize-bswapsi-4.c: Ditto.
* gcc.dg/optimize-bswapsi-5.c: Ditto.
* gcc.dg/optimize-bswapsi-6.c: Ditto.
* gcc.dg/optimize-bswapsi-7.c: Ditto.
* gcc.dg/pr120525.c: Ditto.
* gcc.dg/tree-ssa/loop-1.c: Ditto.
* gcc.misc-tests/linkage.exp: Ditto.
* gcc.target/s390/addsub-signed-overflow-1.c: Ditto.
* gcc.target/s390/addsub-signed-overflow-2.c: Ditto.
* gcc.target/s390/asm-constant-1.c: Ditto.
* gcc.target/s390/call-z10-pic-nodatarel.c: Ditto.
* gcc.target/s390/call-z10-pic.c: Ditto.
* gcc.target/s390/call-z10.c: Ditto.
* gcc.target/s390/call-z9-pic-nodatarel.c: Ditto.
* gcc.target/s390/call-z9-pic.c: Ditto.
* gcc.target/s390/call-z9.c: Ditto.
* gcc.target/s390/fcall-saved.c: Ditto.
* gcc.target/s390/global-array-element-pic2.c: Ditto.
* gcc.target/s390/insv-1.c: Ditto.
* gcc.target/s390/isfinite-isinf-isnormal-signbit-2.c: Ditto.
* gcc.target/s390/isfinite-isinf-isnormal-signbit-3.c: Ditto.
* gcc.target/s390/larl-1.c: Ditto.
* gcc.target/s390/leaf-profile.c: Ditto.
* gcc.target/s390/load-relative-check.c: Ditto.
* gcc.target/s390/load-thread-pointer-once-2.c: Ditto.
* gcc.target/s390/load-thread-pointer-once.c: Ditto.
* gcc.target/s390/loc-1.c: Ditto.
* gcc.target/s390/md/andc-splitter-2.c: Ditto.
* gcc.target/s390/mrecord-mcount.c: Ditto.
* gcc.target/s390/mul-signed-overflow-1.c: Ditto.
* gcc.target/s390/mul-signed-overflow-2.c: Ditto.
* gcc.target/s390/not.c: Ditto.
* gcc.target/s390/pr42224.c: Guard as a TPF test.
* gcc.target/s390/preserve-args-1.c: Remove -m31 part.
* gcc.target/s390/preserve-args-3.c: Ditto.
* gcc.target/s390/risbg-ll-1.c: Ditto.
* gcc.target/s390/risbg-ll-2.c: Ditto.
* gcc.target/s390/risbg-ll-3.c: Ditto.
* gcc.target/s390/stack-protector-guard-tls-1.c: Ditto.
* gcc.target/s390/target-attribute/tattr-12.c: Ditto.
* gcc.target/s390/target-attribute/tattr-15.c: Ditto.
* gcc.target/s390/tls.c: Ditto.
* gcc.target/s390/uaddc-1.c: Ditto.
* gcc.target/s390/uaddc-2.c: Ditto.
* gcc.target/s390/uaddc-3.c: Ditto.
* gcc.target/s390/usubc-1.c: Ditto.
* gcc.target/s390/usubc-2.c: Ditto.
* gcc.target/s390/usubc-3.c: Ditto.
* gcc.target/s390/vector/pattern-avg-1.c: Ditto.
* gcc.target/s390/vector/vec-abi-1.c: Ditto.
* gcc.target/s390/vector/vec-abi-3.c: Ditto.
* gcc.target/s390/vector/vec-abi-4.c: Ditto.
* gcc.target/s390/vector/vec-abi-vararg-1.c: Ditto.
* gcc.target/s390/vector/vec-scalar-cmp-1.c: Ditto.
* gcc.target/s390/zero-scratch-regs-1.c: Ditto.
* gcc.target/s390/zvector/vec-cmp-1.c: Ditto.
* gcc.target/s390/20020926-1.c: Removed.
* gcc.target/s390/20140327-1.c: Removed.
* gcc.target/s390/dwarfregtable-1.c: Removed.
* gcc.target/s390/dwarfregtable-2.c: Removed.
* gcc.target/s390/fp2int1.c: Removed.
* gcc.target/s390/mnop-mcount-m31-mzarch.c: Removed.
* gcc.target/s390/pr102222.c: Removed.
* gcc.target/s390/pr106355-2.c: Removed.
* gcc.target/s390/pr106355-3.c: Removed.
* gcc.target/s390/pr119873-5.c: Removed.
* gcc.target/s390/pr61078.c: Removed.
* gcc.target/s390/stack-clash-4.c: Removed.
* gcc.target/s390/stack-clash-5.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-1.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-10.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-11.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-12.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-13.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-14.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-15.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-16.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-17.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-18.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-19.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-2.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-20.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-21.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-22.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-23.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-24.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-25.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-26.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-27.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-28.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-29.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-3.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-30.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-31.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-32.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-4.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-5.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-6.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-7.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-8.c: Removed.
* gcc.target/s390/target-attribute/tattr-m31-9.c: Removed.

4 weeks agoDaily bump.
GCC Administrator [Thu, 9 Jul 2026 00:16:52 +0000 (00:16 +0000)] 
Daily bump.

4 weeks ago[PATCH] RISC-V: Enable TARGET_SFB_ALU for andes-45-series
Jim Lin [Wed, 8 Jul 2026 23:56:19 +0000 (17:56 -0600)] 
[PATCH] RISC-V: Enable TARGET_SFB_ALU for andes-45-series

Enable short forward branch (SFB) ALU support for the andes-45-series
tune, matching the existing sfb_alu scheduling reservation already
present in andes-45-series.md.

gcc/ChangeLog:

* config/riscv/riscv.h (TARGET_SFB_ALU): Add andes_45_series.

4 weeks agofortran: Fix derived type rank not set for allocate mold
Jerry DeLisle [Wed, 8 Jul 2026 15:52:25 +0000 (08:52 -0700)] 
fortran: Fix derived type rank not set for allocate mold

When mold was being used in the allocate of an array within
a derived type, the rank was not getting set.

gcc/fortran/ChangeLog:

* trans-array.cc (gfc_array_init_size): Set the rank for the
dtype.

gcc/testsuite/ChangeLog:

* gfortran.dg/allocate_with_mold_6.f90: New test.
* gfortran.dg/allocate_with_mold_7.f90: New test.

4 weeks agofortran: [PR126116] Internal file I/O corrupts NEWUNIT state
Jerry DeLisle [Wed, 8 Jul 2026 17:22:04 +0000 (10:22 -0700)] 
fortran: [PR126116] Internal file I/O corrupts NEWUNIT state

Before this fix, Performing an internal file I/O
(such as WRITE to a character variable) incorrectly corrupts
the internal unit management table in libgfortran.

This patch adds a bool to the gfc_unit structure to allow
tracking whether a gfc_unit was created for purposes of
internal I/O to avoid the breakage.

PR libfortran/126116

libgfortran/ChangeLog:

* io/io.h (struct gfc_unit): Add bool for tracking.
Fix some white space problems.
* io/unit.c (close_unit_1): Add a declaration for this
function so it can be called before it has been defined.
Use the new bool.
(is_internal_reserved): New helper function. Returns true
only if the unit is not null and the internal unit kind is zero
meaning its not a character string.
(find_unit): Use the new helper function
(find_or_create_unit): Use the new helper.
(get_unit): Set the new bool.
(close_unit): Update the close_unit_1 argument list.
(close_units): Likewise.

gcc/testsuite/ChangeLog:

* gfortran.dg/pr126116.f90: New test.

4 weeks agolibstdc++: make trees hetero equal_range O(lg n) [PR118851]
Nathan Myers [Fri, 5 Jun 2026 03:42:11 +0000 (23:42 -0400)] 
libstdc++: make trees hetero equal_range O(lg n) [PR118851]

As shipped, the heterogeneous-key members equal_range of rbtree
containers map, multimap, set, and multiset walk the entire range
calling the predicate, in violation of the requirement for
logarithmic complexity. This patch revises them to match the
behavior of the non-heterogeneous multimap and multiset members,
and provides tests to verify it.

libstdc++-v3/Changelog:
PR libstdc++/118851
* include/bits/stl_tree.h (_M_equal_range_tr): Rewrite to match
non-heterogeneous equal_range implementation.
* testsuite/23_containers/map/operations/hetero/equal_range.cc:
New test.
* testsuite/23_containers/multimap/operations/hetero/equal_range.cc:
Same.
* testsuite/23_containers/multiset/operations/hetero/equal_range.cc:
Same.
* testsuite/23_containers/set/operations/hetero/equal_range.cc: Same.

4 weeks agocobol: Support non-unique section names.
James K. Lowden [Wed, 8 Jul 2026 19:41:04 +0000 (15:41 -0400)] 
cobol: Support non-unique section names.

Correct section->paragraph map in the symbol table.  Allow section
names to be repeated and for paragraphs in them to be PERFORMed if the
name-pair is unique. Verify all referenced procedures are defined.

gcc/cobol/ChangeLog:

* genapi.cc (parser_call_targets_dump): Remove function.
* genapi.h (parser_call_targets_dump): Same.
* parse.y: Instantiate forward labels consistently.
(label_add) Capture forward references for efficiency.
(paragraph_reference) Use forward reference.
(label_add_once): New function.
* parse_ante.h (label_add_once): Declare function.
(label_instantiate): New function.
(ast_enter_exit_section): Improve debug message.
* symbols.cc (label_cmp): Allow forward reference to have a parent.
(cbl_label_ref_t): Remove class.
(symbol_label): Whitespace.
(symbols_dump): Add information to output.
(symbol_add): Remove program label symbol-assignment to symbol_label_add.
(cbl_label_t::str): Add information to output.
(symbol_label_add): Assign id to program label.
* symbols.h (class cbl_label_ref_t): Remove.
(struct symbol_elem_t): Remove struct keyword.
(struct cbl_label_t): Same.
(struct cbl_special_name_t): Same.
(struct cbl_field_t): Same.
(symbol_typedef): Same.
(symbol_field): Same.
(symbol_label): Same.
(symbol_function): Same.
(symbol_function_any): Same.
(symbol_program): Same.
(symbol_literalA): Same.
(symbol_special): Same.
(symbol_locale): Same.
(symbol_alphabet): Same.
(symbol_file): Same.
(symbol_file_record): Same.
(struct cbl_section_t): Same.
(symbol_section): Same.
(parent_of): Same.
* util.cc: (match_proc::find) Use only section and paragraph names.

4 weeks agocobol: Do not crash on bad refmod literal. Fix PR 126104.
James K. Lowden [Mon, 6 Jul 2026 16:09:24 +0000 (12:09 -0400)] 
cobol: Do not crash on bad refmod literal.  Fix PR 126104.

gcc/cobol/ChangeLog:

* parse.y (literal_refmod_valid): Do not deference NULL pointer.

4 weeks agoFortran: fix resolution of user-defined operators in named BLOCK [PR126127]
Harald Anlauf [Tue, 7 Jul 2026 18:06:35 +0000 (20:06 +0200)] 
Fortran: fix resolution of user-defined operators in named BLOCK [PR126127]

PR fortran/126127

gcc/fortran/ChangeLog:

* interface.cc (find_symtree0): Check for NULL pointer.
(gfc_find_sym_in_symtree): Also search user-defined operator list
when the symbol refers to a function.

gcc/testsuite/ChangeLog:

* gfortran.dg/block_18.f90: New test.

4 weeks agoi386: Fix ccmp support checks for floating-point modes [PR126148]
Uros Bizjak [Wed, 8 Jul 2026 14:50:15 +0000 (16:50 +0200)] 
i386: Fix ccmp support checks for floating-point modes [PR126148]

The ccmp expansion code allowed DFmode, SFmode and HFmode comparisons
without verifying that the corresponding floating-point instruction
set was available. This could result in attempts to generate ccmp
sequences for comparisons that cannot be emitted as a single instruction
under the selected target options.

Restrict XFmode support to x87 targets, DFmode/SFmode support to
targets with either x87 or SSE with SSE math enabled, and HFmode
support to targets with AVX512FP16 enabled.

PR target/126148

gcc/ChangeLog:

* config/i386/i386-expand.cc (ix86_gen_ccmp_first): Restrict
floating-point modes accepted for ccmp according to the
available floating-point instruction set.

gcc/testsuite/ChangeLog:

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

4 weeks agoAVR: Add R18:SI = neg R18:SI to libgcc.
Georg-Johann Lay [Wed, 8 Jul 2026 17:40:26 +0000 (19:40 +0200)] 
AVR: Add R18:SI = neg R18:SI to libgcc.

This patch factors out negating R18:SI which is used in several
places.  It also adds

   .macro  .call_if_neg  reg, labl

for convenience.  It calls <labl> iff <reg> < 0.

libgcc/
* config/avr/t-avr (LIB1ASMFUNCS): Add _negsi2_r18.
* config/avr/asm-defs.h (.call_if_neg): New .macro.
* config/avr/lib1funcs.S (__divmodsi4): Use .call_if_neg.
(__negsi2_r18): New function.
* config/avr/lib1funcs-fixed.S (__divsa3): Use .call_if_neg.

4 weeks ago[PR rtl-optimization/126136] Fix dest = cond ? x : -1 when STORE_FLAG_VALUE is -1
Jeff Law [Wed, 8 Jul 2026 18:30:56 +0000 (12:30 -0600)] 
[PR rtl-optimization/126136] Fix dest = cond ? x : -1 when STORE_FLAG_VALUE is -1

So a while back I added support for selecting x/-1 into the ifcvt.cc by using
scc and a couple ALU operations.  That code explicitly rejects STORE_FLAG_VALUE
if it is not 1 or -1.

The "1" case has been working well.  But -1 has been buggy since inception --
the affected platforms are m68k and gcn, so not getting a ton of testing.

In the "1" case we have to subtract one from the output of the SCC insn to give
us a 0/-1 value for T/F.  In the -1 case the SCC naturally gives us the -1
value, so we don't need that subtract one step.  But the tense is inverted, ie
-1/0 for T/F and I failed to account for the inverted tense.

This patch obviously fixes the code to handle that inverted tense.
Bootstrapped and regression tested on x86, riscv and m68k.   Pushing to the
trunk.

PR rtl-optimization/126136
gcc/
* ifcvt.cc (noce_try_store_flag_logical): Fix for STORE_FLAG_VALUE
of -1.

gcc/testsuite
* gcc.dg/torture/pr126136.c: New test.

4 weeks agogccrs: Fix typechecking of block expression and labels
Philip Herron [Mon, 29 Jun 2026 18:22:53 +0000 (19:22 +0100)] 
gccrs: Fix typechecking of block expression and labels

Tail expressions were always ignoring the context here and returning
unit-type. This patch respects the label context here properly.

Fixes Rust-GCC#4538

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): respect context for labels

gcc/testsuite/ChangeLog:

* rust/compile/issue-4538.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 weeks agogccrs: add missing_abi lint
Lucas Ly Ba [Sun, 28 Jun 2026 16:04:29 +0000 (18:04 +0200)] 
gccrs: add missing_abi lint

Warn on an `extern` block written without an explicit ABI string, such as
a bare `extern { ... }`, which silently defaults to the C ABI. Rust
deprecates this in favour of spelling the ABI out, e.g. `extern "C"`.

The HIR `ExternBlock` only stored the resolved ABI enum, which always
collapses a missing ABI to the C default, so it could not tell a bare
`extern` from `extern "C"`. Carry the AST's `has_abi` flag through
lowering so the lint can distinguish the two.

gcc/rust/ChangeLog:

* hir/tree/rust-hir-item.h (ExternBlock): Track whether the ABI
was explicit and expose it through has_abi.
* hir/tree/rust-hir-item.cc (ExternBlock::ExternBlock): Likewise.
(ExternBlock::operator=): Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_extern_block):
Forward the AST has_abi flag to the HIR node.
* checks/lints/unused/rust-unused-checker.cc (UnusedChecker::visit):
New.
* checks/lints/unused/rust-unused-checker.h (UnusedChecker::visit):
New.

gcc/testsuite/ChangeLog:

* rust/compile/missing-abi_0.rs: New test.

Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
4 weeks agogccrs: backend: Fix incorrect impl block selection
Enes Cevik [Mon, 29 Jun 2026 07:34:58 +0000 (10:34 +0300)] 
gccrs: backend: Fix incorrect impl block selection

During vtable generation in `compute_address_for_trait_item`, the
compiler was picking the first `impl` block that satisfied the trait
predicate, without verifying if the `impl` block actually belonged to
the target receiver type. This caused dynamic dispatch to call the
wrong methods when multiple types implemented the same trait in the
same scope.

This patch adds a comparison between the impl block's resolved type and
the `receiver` type to ensure we compute the address of the correct
associated function.

gcc/rust/ChangeLog:

* backend/rust-compile.cc
(HIRCompileBase::compute_address_for_trait_item): Ensure the
impl block type matches the receiver type.

gcc/testsuite/ChangeLog:

* rust/execute/trait-multi-impl.rs: New test.
* rust/execute/trait-multi-impl-generic.rs: New test.
* rust/execute/trait-multi-impl-generic2.rs: New test.

Signed-off-by: Enes Cevik <enes@nsvke.com>
4 weeks agogccrs: turn on can_alias_all on build_pointer_type
Philip Herron [Mon, 29 Jun 2026 18:59:25 +0000 (19:59 +0100)] 
gccrs: turn on can_alias_all on build_pointer_type

Rust semantics are that all raw pointers can alias but then we get stronger
garentees on reference types.

Fixes Rust-GCC#4536

gcc/rust/ChangeLog:

* rust-gcc.cc (pointer_type): turn on can alias

gcc/testsuite/ChangeLog:

* rust/execute/raw-pointer-aliasing.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 weeks agogccrs: intrinsic: Add min_align_of_val
Enes Cevik [Tue, 30 Jun 2026 07:14:36 +0000 (10:14 +0300)] 
gccrs: intrinsic: Add min_align_of_val

This patch adds the min_align_of_val intrinsic to the compiler. This
intrinsic evaluates the align of a value at runtime, including
Dynamically Sized Types (DSTs).

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (generic_intrinsics): Add
min_align_of_val_handler to the map.
* backend/rust-intrinsic-handlers.cc (min_align_of_val_handler):
New function.
* backend/rust-intrinsic-handlers.h (min_align_of_val_handler):
New declaration.
* typecheck/rust-hir-type-check-intrinsic.cc
(IntrinsicChecker::intrinsic_rules): Add min_align_of_val
signature rule to the map.
* util/rust-intrinsic-values.h (class Intrinsics): Add
MIN_ALIGN_OF_VAL constexpr.

gcc/testsuite/ChangeLog:

* rust/execute/min-align-of-val.rs: New test.

Signed-off-by: Enes Cevik <enes@nsvke.com>
4 weeks agogccrs: intrinsic: Add size_of_val
Enes Cevik [Mon, 29 Jun 2026 13:03:44 +0000 (16:03 +0300)] 
gccrs: intrinsic: Add size_of_val

This patch adds the size_of_val intrinsic to the compiler. This
intrinsic evaluates the size of a value at runtime, including
Dynamically Sized Types (DSTs).

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (generic_intrinsics): Add
size_of_val_handler to the map.
* backend/rust-intrinsic-handlers.cc (size_of_val_handler): New
function.
* backend/rust-intrinsic-handlers.h (size_of_val_handler): New
declaration.
* typecheck/rust-hir-type-check-intrinsic.cc
(IntrinsicChecker::intrinsic_rules): Add size_of_val signature
rule to the map.
* util/rust-intrinsic-values.h (class Intrinsics): Add
SIZE_OF_VAL constexpr.

gcc/testsuite/ChangeLog:

* rust/execute/size-of-val.rs: New test.

Signed-off-by: Enes Cevik <enes@nsvke.com>
4 weeks agogccrs: Fix unify code on ADT's to check defid
Philip Herron [Mon, 29 Jun 2026 17:06:14 +0000 (18:06 +0100)] 
gccrs: Fix unify code on ADT's to check defid

There is a simple upfront check on ADT's we can check that def-id's match
before continuing to unify them.

gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::expect_adt): check defid

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 weeks agogccrs: Fix crash when resolving invalid enum item
Philip Herron [Mon, 29 Jun 2026 11:01:59 +0000 (12:01 +0100)] 
gccrs: Fix crash when resolving invalid enum item

Fixes Rust-GCC#1617

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): check valid

gcc/testsuite/ChangeLog:

* rust/compile/issue-4617.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 weeks agogccrs: rust: Fix ICE with infer type used in struct attribute
João Novo [Tue, 31 Mar 2026 15:05:03 +0000 (16:05 +0100)] 
gccrs: rust: Fix ICE with infer type used in struct attribute

When visiting a struct declaration, add check for when a struct's
attribute is declared as an infer type, emitting an error if true.

Fixes Rust-GCC#3583

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit):
Add check for infer type on struct's attribute or its subtypes.
* typecheck/rust-tyty.cc (BaseType::contains_infer):
Add check for an array type's capacity being an infer type.

gcc/testsuite/ChangeLog:

* rust/compile/infer-type-issue-3583.rs: New test.

Signed-off-by: João Novo <joao.c.novo@tecnico.ulisboa.pt>
4 weeks agogccrs: lang: Add lang owned_box and box expression
Enes Cevik [Wed, 3 Jun 2026 07:18:14 +0000 (10:18 +0300)] 
gccrs: lang: Add lang owned_box and box expression

This patch implement the lang item `owned_box` and add support box
expression.

gcc/rust/ChangeLog:

* ast/rust-expr.h (BoxExpr): Add comment description to class.
* backend/rust-compile-block.h (visit): Add stub for BoxExpr.
* backend/rust-compile-expr.cc (compile_box_struct): New
function.
(compile_box): New function.
(build_box_inner_ptr): New function.
(CompileExpr::visit): Implement BoxExpr lowering using
exchange_malloc and constructor expressions. Handle owned_box
in FieldAccessExpr and DereferenceExpr.
(HIRCompileBase::resolve_deref_adjustment): Support owned_box
in deref adjustments.
* backend/rust-compile-expr.h (visit): Declare BoxExpr visitor.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::visit): Evaluate inner expression and push
tmp assignment for BoxExpr.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h (visit):
Declare BoxExpr visitor.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h
(visit): Mark BoxExpr as unreachable.
* checks/errors/borrowck/rust-bir-builder-struct.h (visit):
Likewise.
* checks/errors/borrowck/rust-function-collector.h (visit):
Add visit stub for BoxExpr.
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::visit): Delegate privacy reporting to inner
expression of BoxExpr.
* checks/errors/privacy/rust-privacy-reporter.h (visit):
Declare BoxExpr visitor.
* checks/errors/rust-const-checker.cc (ConstChecker::visit):
Delegate const checking to inner expression.
* checks/errors/rust-const-checker.h (visit): Declare BoxExpr
visitor.
* checks/errors/rust-hir-pattern-analysis.cc
(PatternChecker::visit): Delegate pattern analysis to inner
expression.
* checks/errors/rust-hir-pattern-analysis.h (visit): Declare
BoxExpr visitor.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit):
Delegate unsafe checking to inner expression.
* checks/errors/rust-unsafe-checker.h (visit): Declare BoxExpr
visitor.
* checks/lints/rust-lint-marklive.cc (MarkLive::visit): Resolve
inner ADT type for owned_box when marking live fields.
* checks/lints/rust-lint-marklive.h (visit): Declare BoxExpr
visitor.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Translate
AST BoxExpr to HIR BoxExpr.
* hir/rust-hir-dump.cc (Dump::visit): Dump HIR BoxExpr.
* hir/rust-hir-dump.h (visit): Declare BoxExpr visitor.
* hir/tree/rust-hir-expr-abstract.h (ExprType): Add Box to enum.
* hir/tree/rust-hir-expr.cc (BoxExpr::BoxExpr): Implement
constructors for BoxExpr. (BoxExpr::operator=): Implement
assignment operator.
* hir/tree/rust-hir-expr.h (class BoxExpr): Define HIR BoxExpr
node.
* hir/tree/rust-hir-full-decls.h (class BoxExpr): Forward
declaration.
* hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Walk
inner expression of BoxExpr.
* hir/tree/rust-hir-visitor.h (visit): Add routing for BoxExpr.
* hir/tree/rust-hir.cc (BoxExpr::to_string): Implement
to_string.
(BoxExpr::accept_vis): Implement visitor acceptance.
* typecheck/rust-autoderef.cc (AutoderefCycle::cycle): Attempt
autoderef using the owned_box lang item.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Implement type checking, validation, and generic substitution
for BoxExpr. Support owned_box autoderef in field access and
dereferencing operations.
* typecheck/rust-tyty.cc (try_get_box_inner_type): New function.
* typecheck/rust-tyty.h (try_get_box_inner_type): New
declaration.
* typecheck/rust-hir-type-check-expr.h (visit): Declare BoxExpr
visitor.
* util/rust-lang-item.cc (Rust::LangItem::lang_items): Register
owned_box to BiMap.
* util/rust-lang-item.h (LangItem::Kind): Add OWNED_BOX.

gcc/testsuite/ChangeLog:

* rust/compile/box-expr.rs: New test.
* rust/compile/lang-owned-box-error1.rs: New test.
* rust/compile/lang-owned-box-error2.rs: New test.

Signed-off-by: Enes Cevik <enes@nsvke.com>
4 weeks agogccrs: Add tests for local binding LIFO and nested block scopes
Lishin [Fri, 26 Jun 2026 17:54:46 +0000 (17:54 +0000)] 
gccrs: Add tests for local binding LIFO and nested block scopes

The new tests verify that multiple local bindings in the
same scope are dropped in LIFO order, and nested block scopes
drop inner bindings before outer bindings.

gcc/testsuite/ChangeLog:

* rust/execute/drop-local-binding-lifo.rs: New test.
* rust/execute/drop-nested-block-scope.rs: New test.

Signed-off-by: Lishin <lishin1008@gmail.com>
4 weeks agogccrs: Refactor CompileDrop and add DropBuilder
Lishin [Tue, 16 Jun 2026 15:44:11 +0000 (15:44 +0000)] 
gccrs: Refactor CompileDrop and add DropBuilder

Refactor CompileDrop to keep Context as a member
instead of passing it to each method.

Move the drop candidate note/peek operations from
Context to DropBuilder. This keeps the drop-specific
API off the compile Context.

gcc/rust/ChangeLog:

* Make-lang.in: Add rust-compile-drop-builder.o.
* backend/rust-compile-base.cc
(HIRCompileBase::compile_function_body):
Update CompileDrop calls.
* backend/rust-compile-block.cc (CompileBlock::visit):
Update CompileDrop calls.
* backend/rust-compile-context.h (Context): Allow
DropBuilder to access drop candidate storage and move
drop candidate APIs to DropBuilder.
* backend/rust-compile-drop.cc (CompileDrop::CompileDrop):
Add constructor.
(CompileDrop::type_has_drop_impl): Use stored Context member.
(CompileDrop::compile_drop_call): Likewise.
(CompileDrop::emit_current_scope_drop_calls): Use stored
Context member and get drop candidates from DropBuilder.
* backend/rust-compile-drop.h: Store Context as a member.
* backend/rust-compile-pattern.cc (CompilePatternLet::visit):
Use DropBuilder and update CompileDrop calls.
* backend/rust-compile-drop-builder.cc: New file.
* backend/rust-compile-drop-builder.h: New file.

Signed-off-by: Lishin <lishin1008@gmail.com>
4 weeks agogccrs: backend: Refactor dynamic object fat pointers and vtable generation
Enes Cevik [Tue, 23 Jun 2026 15:42:17 +0000 (18:42 +0300)] 
gccrs: backend: Refactor dynamic object fat pointers and vtable generation

Previously, the compiler incorrectly embedded the vtable as an array
directly inside the fat pointer. Furthermore, it lacked essential trait
object metadata such as 'size', 'align' and 'drop_in_place'.

Now, the fat pointer is strictly fixed to 2 words. The vtable is
generated as a separate global static struct and it's structure
correctly includes 'drop_in_place', 'size' and 'align' fields, followed
by trait methods. Also implemented a caching mechanism in the
compilation context to prevent duplicate vtable generation and linker
conflicts for the same Type-Trait combinations.

gcc/rust/ChangeLog:

* backend/rust-compile-context.h (class Context): Add
insert_vtable and lookup_vtable methods.
* backend/rust-compile-expr.cc
(CompileExpr::get_fn_addr_from_dyn): Change access method
array access to struct field access.
* backend/rust-compile-type.cc
(TyTyResolveCompile::create_dyn_obj_record): Create vtable type
as a record instead of an array.
* backend/rust-compile.cc
(HIRCompileBase::coerce_to_dyn_object): Change vtable structure.

gcc/testsuite/ChangeLog:

* rust/execute/torture/dyn_object.rs: New test.

Signed-off-by: Enes Cevik <enes@nsvke.com>
4 weeks agogccrs: intrinsic: Add arith_offset
Enes Cevik [Fri, 26 Jun 2026 13:40:51 +0000 (16:40 +0300)] 
gccrs: intrinsic: Add arith_offset

This patch implements the 'arith_offset' compiler intrinsic. It moves a
pointer forward or backward by a given number of elements. It does not
cause Undefined Behavior if the pointer goes out of bounds.

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (generic_intrinsics): Add
arith_offset handler to map.
* backend/rust-intrinsic-handlers.cc (arith_offset_handler): New
function.
* backend/rust-intrinsic-handlers.h (arith_offset_handler): New
declaration.
* typecheck/rust-hir-type-check-intrinsic.cc
(IntrinsicChecker::intrinsic_rules): Add arith_offset rule.
* util/rust-intrinsic-values.h (class Intrinsics): Add
ARITH_OFFSET constexpr.

gcc/testsuite/ChangeLog:

* rust/execute/arith-offset.rs: New test.

Signed-off-by: Enes Cevik <enes@nsvke.com>
4 weeks agogccrs: intrinsic: Add write_bytes
Enes Cevik [Fri, 26 Jun 2026 12:53:46 +0000 (15:53 +0300)] 
gccrs: intrinsic: Add write_bytes

This patch implements the 'write_bytes' compiler intrinsic. It performs
a write operation to memory using '__builtin_memset'.

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (generic_intrinsics): Add
write_bytes handler to map.
* backend/rust-intrinsic-handlers.cc (write_bytes_handler): New
function.
* backend/rust-intrinsic-handlers.h (write_bytes_handler): New
declaration.
* typecheck/rust-hir-type-check-intrinsic.cc
(IntrinsicChecker::intrinsic_rules): Add write_bytes rule.
* util/rust-intrinsic-values.h (class Intrinsics): Add
WRITE_BYTES constexpr.

gcc/testsuite/ChangeLog:

* rust/execute/write-bytes.rs: New test.

Signed-off-by: Enes Cevik <enes@nsvke.com>
4 weeks agogccrs: fix ICE on break with a label and a value
Lucas Ly Ba [Sat, 27 Jun 2026 19:15:51 +0000 (21:15 +0200)] 
gccrs: fix ICE on break with a label and a value

A `break 'label value` expression looks up a temporary variable
associated with the labeled loop to hold the value, but labeled loops
never registered that temporary, leading to an ICE in the code
generator. Register the loop result temporary against the label.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Associate the loop
result temporary with the loop label.

gcc/testsuite/ChangeLog:

* rust/compile/break-label-loop.rs: New test.

Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
4 weeks agogccrs: fix ICE on generic type aliases
Lucas Ly Ba [Sat, 27 Jun 2026 19:15:27 +0000 (21:15 +0200)] 
gccrs: fix ICE on generic type aliases

A type alias with generic parameters never resolved those parameters
into the type context, so the reachability pass asserted when looking
up their types. Resolve the generic parameters, as the other items do.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Resolve
the generic parameters of a type alias.

gcc/testsuite/ChangeLog:

* rust/compile/type-alias-generic-params.rs: New test.

Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
4 weeks agogccrs: add non_contiguous_range_endpoints lint
Lucas Ly Ba [Sun, 28 Jun 2026 18:30:27 +0000 (20:30 +0200)] 
gccrs: add non_contiguous_range_endpoints lint

Warn when an exclusive range pattern and the next arm are one value
apart, such as `20..30` followed by `31..=40`, which silently skips 30.

gcc/rust/ChangeLog:

* checks/lints/unused/rust-unused-checker.cc (UnusedChecker::visit):
New.
* checks/lints/unused/rust-unused-checker.h (UnusedChecker::visit):
New.

gcc/testsuite/ChangeLog:

* rust/compile/non-contiguous-range-endpoints_0.rs: New test.

Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
4 weeks agogccrs: Detect errors in macro eager expansion
Owen Avery [Sun, 28 Jun 2026 04:37:27 +0000 (00:37 -0400)] 
gccrs: Detect errors in macro eager expansion

gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc
(MacroExpander::expand_eager_invocations): Handle errors during
eager expansion.
(MacroExpander::expand_invoc): Avoid expanding macros which have
pending eager invocations and return error fragments in more
cases.

gcc/testsuite/ChangeLog:

* rust/compile/macros/builtin/eager4.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 weeks agogccrs: Fix field access on DST fat pointers
Yap Zhi Heng [Thu, 18 Jun 2026 15:02:19 +0000 (23:02 +0800)] 
gccrs: Fix field access on DST fat pointers

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit (FieldAccessExpr)):
Handle DST fat pointers by reinterpreting the fat pointer as its field type.

Signed-Off-By: Yap Zhi Heng <yapzhhg@gmail.com>
4 weeks agogccrs: Introduce CStr language item
Yap Zhi Heng [Sun, 7 Jun 2026 14:42:53 +0000 (22:42 +0800)] 
gccrs: Introduce CStr language item

gcc/rust/ChangeLog:
* util/rust-lang-item.h (LangItem::Kind): New CSTR kind.
* util/rust-lang-item.cc (LangItem::lang_items): Ditto.
* backend/rust-compile-type.cc (visit(TyTy::ReferenceType)): Add specific record
type for CStr.
* typecheck/rust-tyty.h (ReferenceType): Add function definition for is_dyn_cstr_type.
* typecheck/rust-tyty.cc (ReferenceType::is_dyn_object): Update to include
is_dyn_cstr_type.
(ReferenceType::is_dyn_cstr_type): Add implementation to check whether the
ReferenceType is of type CStr.
* typecheck/rust-hir-type-check-base.cc(resolve_literal): Update C_STRING case to
resolve to the CStr language item instead.

gcc/testsuite/ChangeLog:
* rust/execute/torture/c_string.rs: Add CStr language item definition.
* rust/compile/c_string_null_byte_check.rs: Ditto.
* rust/execute/torture/c_string_ensure_null_term.rs: New test.

Signed-Off-By: Yap Zhi Heng <yapzhhg@gmail.com>
4 weeks agogccrs: Add new compiler flag for parsing & compiling C-style string literals
Yap Zhi Heng [Tue, 2 Jun 2026 03:07:27 +0000 (11:07 +0800)] 
gccrs: Add new compiler flag for parsing & compiling C-style string literals

gcc/rust/ChangeLog:
* lang.opt: Add new -frust-c-style-string-literals option.
* parse/rust-parse.h: Import options.h for reading flag_c_style_string_literals.
* parse/rust-parse-impl-expr.hxx (Parser<ManagedTokenSource>::parse_literal_expr):
Abort parsing C-style string literals if flag_c_style_string_literals is not set.
(Parser<ManagedTokenSource>::null_denotation_not_path): Ditto.

gcc/testsuite/ChangeLog:
* rust/execute/torture/c_string.rs: Set -frust-c-style-string-literals.
* rust/compile/c_string_null_byte_check.rs: Set -frust-c-style-string-literals.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
4 weeks agogccrs: Implement C-style string literals
Yap Zhi Heng [Sun, 31 May 2026 14:18:57 +0000 (22:18 +0800)] 
gccrs: Implement C-style string literals

Current behaviour is similar to normal string literals, except they are type-checked
as slice types instead of array, and the compiled fat pointer has +1 to size to
include the null terminator.

gcc/rust/ChangeLog:
* lex/rust-token.h (RS_TOKEN_LIST): Add C_STRING_LITERAL and RAW_C_STRING_LITERAL
(unused for now).
* lex/rust-lex.h (Lexer): Define new parse_c_string function.
* lex/rust-lex.cc (Lexer::build_token): Implement lexing for C-style string
literals.
(Lexer::parse_c_string): Add implementation.
* hir/tree/rust-hir-literal.h (HIR::Literal): Define new C_STRING LitType.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_literal): Add new case for
C_STRING.
* parse/rust-parse-impl-attribute.hxx (Parser<ManagedTokenSource>::parse_attr_input):
Add new case for C_STRING.
* parse/rust-parse-impl-expr.hxx (Parser<ManagedTokenSource>::parse_literal_expr):
Add new case for parsing C_STRING.
(Parser<ManagedTokenSource>::null_denotation_not_path): Add new case for C_STRING.
* ast/rust-ast.h (Token::is_string_lit): Add new case for C_STRING_LITERAL.
* ast/rust-ast.cc (AttributeParser::parse_meta_item_inner): Add new case for
C_STRING_LITERAL.
* ast/rust-ast-collector.cc (TokenCollector::visit): Add new case for
C_STRING_LITERAL.
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal):
Implement type checking for the new C_STRING type.
* backend/rust-compile-expr.h (CompileExpr): Define new function
compile_c_string_literal.
* backend/rust-compile-expr.cc (CompileExpr::visit(LiteralExpr)): Add new case
for C_STRING.
(CompileExpr::compile_c_string_literal): Implement compilation of C-style string
literals.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
4 weeks agogccrs: rust: avoid ICE on attributed struct base parsing
hriztam [Fri, 3 Apr 2026 20:10:59 +0000 (01:40 +0530)] 
gccrs: rust: avoid ICE on attributed struct base parsing

gcc/rust/ChangeLog:

* parse/rust-parse-error.h (StructExprField): Add
STRUCT_BASE_ATTRIBUTES.
* parse/rust-parse-impl-expr.hxx
(Parser<ManagedTokenSource>::parse_struct_expr_field):
Reject attributes before struct-base `..`.
(Parser<ManagedTokenSource>::parse_struct_expr_struct_partial):
Handle struct-base parse results without dereferencing an errored
expected.

gcc/testsuite/ChangeLog:

* rust/compile/issue-4476.rs: New test.

Signed-off-by: Hritam Shrivastava <hritamstark05@gmail.com>
4 weeks agogccrs: add non shorthand field patterns lint
Lucas Ly Ba [Fri, 26 Jun 2026 22:39:10 +0000 (00:39 +0200)] 
gccrs: add non shorthand field patterns lint

gcc/rust/ChangeLog:

* checks/lints/unused/rust-unused-checker.cc (UnusedChecker::visit):
New.
* checks/lints/unused/rust-unused-checker.h (UnusedChecker::visit):
New.

gcc/testsuite/ChangeLog:

* rust/compile/non-shorthand-field-patterns_0.rs: New test.

Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
4 weeks agogccrs: add unused visibilities lint
Lucas Ly Ba [Sat, 27 Jun 2026 21:45:56 +0000 (23:45 +0200)] 
gccrs: add unused visibilities lint

Warn on a visibility qualifier applied to a `const _` item, as it has no
effect.

gcc/rust/ChangeLog:

* checks/lints/unused/rust-unused-checker.cc (UnusedChecker::visit):
Warn on a visibility qualifier on a `const _` item.

gcc/testsuite/ChangeLog:

* rust/compile/unused-visibilities_0.rs: New test.

Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
4 weeks agogccrs: Handle assert with custom message
Owen Avery [Sun, 7 Jun 2026 23:23:37 +0000 (19:23 -0400)] 
gccrs: Handle assert with custom message

The built-in macro "assert" has a second form, with a custom message
used on assertion failure. This patch allows the second form to be
compiled.

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-log-debug.cc
(MacroBuiltin::assert_handler): Forward any custom message on to
the built-in panic macro.

gcc/testsuite/ChangeLog:

* rust/compile/assert_missing_panic.rs: Add usage of the second
form of assert.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 weeks agogccrs: Fix ICE when trying to resolve const expr
Philip Herron [Wed, 24 Jun 2026 15:28:11 +0000 (16:28 +0100)] 
gccrs: Fix ICE when trying to resolve const expr

We cannot resolve N + 1 a this stage since N has no default and is const
generic, rustc makes a more precise error diag here but our one is
completely fine for now.

Fixes Rust-GCC#4302

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc: use error_mark_node

gcc/testsuite/ChangeLog:

* rust/compile/issue-4302.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 weeks agogccrs: remove useless diagnostic
Philip Herron [Wed, 24 Jun 2026 15:24:20 +0000 (16:24 +0100)] 
gccrs: remove useless diagnostic

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): remove error_at

gcc/testsuite/ChangeLog:

* rust/compile/issue-2479.rs: update test

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 weeks agogccrs: Add testcases to show gat issue is fixed
Philip Herron [Wed, 24 Jun 2026 14:37:42 +0000 (15:37 +0100)] 
gccrs: Add testcases to show gat issue is fixed

Fixes Rust-GCC#4471

gcc/testsuite/ChangeLog:

* rust/compile/issue-4471-1.rs: New test.
* rust/compile/issue-4471-2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 weeks agogccrs: Add test case to show bug is fixed
Philip Herron [Wed, 24 Jun 2026 14:32:23 +0000 (15:32 +0100)] 
gccrs: Add test case to show bug is fixed

Fixes Rust-GCC#4481

gcc/testsuite/ChangeLog:

* rust/compile/issue-4481.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 weeks agogccrs: Fix ICE when handling offset on types with unknown size
Philip Herron [Wed, 24 Jun 2026 14:02:45 +0000 (15:02 +0100)] 
gccrs: Fix ICE when handling offset on types with unknown size

This patch also threads through the expr locus for where intrinsics are
called from so we can improve the diagnostics.

Fixes Rust-GCC#4592

gcc/rust/ChangeLog:

* backend/rust-compile-extern.h: add expr locus
* backend/rust-compile-intrinsic.cc (Intrinsics::compile): likewise
* backend/rust-compile-intrinsic.h: likewise
* backend/rust-compile-resolve-path.cc: likewise
* backend/rust-intrinsic-handlers.cc (op_with_overflow): likewise
(rotate_left): likewise
(rotate_right): likewise
(wrapping_op): likewise
(atomic_store): likewise
(atomic_load): likewise
(unchecked_op): likewise
(copy): likewise
(expect): likewise
(try_handler): likewise
(sorry): likewise
(assume): likewise
(discriminant_value): likewise
(variant_count): likewise
(move_val_init): likewise
(uninit): likewise
(prefetch_read_data): likewise
(prefetch_write_data): likewise
(transmute): likewise
(sizeof_handler): likewise
(min_align_of_handler): likewise
(offset): likewise
(bswap_handler): likewise
(ctlz_handler): likewise
(ctlz_nonzero_handler): likewise
(cttz_handler): likewise
(cttz_nonzero_handler): likewise
* backend/rust-intrinsic-handlers.h (std::function<tree): likewise
(rotate_left): likewise
(rotate_right): likewise
(offset): likewise
(sizeof_handler): likewise
(min_align_of_handler): likewise
(transmute): likewise
(uninit): likewise
(move_val_init): likewise
(assume): likewise
(discriminant_value): likewise
(variant_count): likewise
(bswap_handler): likewise
(ctlz_handler): likewise
(ctlz_nonzero_handler): likewise
(cttz_handler): likewise
(cttz_nonzero_handler): likewise
(wrapping_op): likewise
(prefetch_read_data): likewise
(prefetch_write_data): likewise
(sorry): likewise
* backend/rust-tree.cc (pointer_offset_expression): check for size

gcc/testsuite/ChangeLog:

* rust/compile/issue-4592.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 weeks agogccrs: Fix ICE when handling invalid results during monomprhization
Philip Herron [Wed, 24 Jun 2026 14:25:58 +0000 (15:25 +0100)] 
gccrs: Fix ICE when handling invalid results during monomprhization

Fixes Rust-GCC#4486

gcc/rust/ChangeLog:

* backend/rust-compile-item.cc (CompileItem::visit): check instead of assert

gcc/testsuite/ChangeLog:

* rust/compile/issue-4486-1.rs: New test.
* rust/compile/issue-4486-2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 weeks agogccrs: Implment proper generic associated types
Philip Herron [Mon, 22 Jun 2026 20:27:53 +0000 (21:27 +0100)] 
gccrs: Implment proper generic associated types

This patch adds in GATs using proper projection types instead of mutating
associated type placeholders during resolution which rapidly becomes very
messy.

The simple case is trait impl handling, entering a trait impl block we first
walk the associated type items and build an ImplTraitFrame for that impl.
This frame records the trait, the impl self type and the mapping from trait
associated items to the impl associated type values. While typechecking
items in that impl we can then look through the active impl trait context
to resolve projections such as `<Self as Trait>::Item`.

The more complex cases need lazy evaluation. A projection can appear
outside the impl body, inside a where-clause binding, behind another
projection, or after substitution has rebound Self and the trait arguments.
For those cases we keep associated types as ProjectionType values carrying
the trait ref, associated item, Self type and substitutions, then normalize
them when the type is actually used. This avoids global associated type
mutation and lets generic associated type arguments compose through
substitution, unification and backend lowering.

Fixes Rust-GCC#4293

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::generate_closure_fntype):
Stop eagerly setting FnOnce::Output
* backend/rust-compile-item.cc (CompileItem::visit): Push impl-trait
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Normalize
projection types
* backend/rust-intrinsic-handlers.cc (discriminant_value): Handle
projection
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::check_base_type_privacy): Skip unresolved
* typecheck/rust-hir-type-check-intrinsic.cc (IntrinsicChecker::check_type): make permissive
* typecheck/rust-autoderef.cc: remove old
* typecheck/rust-hir-impl-trait-context.h: New file.
* typecheck/rust-hir-trait-reference.cc (TraitReference::on_resolved):
Pass the trait reference into item resolution.
(TraitReference::clear_associated_types): Remove.
(TraitReference::clear_associated_type_projections): Remove.
(AssociatedImplTrait::AssociatedImplTrait): Store an impl trait frame
(AssociatedImplTrait::get_frame): New function.
* typecheck/rust-hir-trait-reference.h: Add impl trait context
* typecheck/rust-hir-trait-resolve.cc (TraitItemReference::on_resolved):
Pass trait reference
(TraitItemReference::resolve_item): Represent associated types as
projection types
(TraitItemReference::associated_type_set): Remove.
(TraitItemReference::associated_type_reset): Remove.
(AssociatedImplTrait::setup_raw_associated_types): Remove.
(AssociatedImplTrait::bind_impl_for_projection): New function.
(AssociatedImplTrait::bind_impl_for_bound): New function.
(AssociatedImplTrait::reset_associated_types): Remove.
* typecheck/rust-hir-type-check-base.cc
(TypeCheckBase::ResolvePredicateFromBound): New function.
* typecheck/rust-hir-type-check-base.h
(TypeCheckBase::ResolvePredicateFromBound): Declare.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Handle projection
(TypeCheckExpr::resolve_fn_trait_call): monomorphized
* typecheck/rust-hir-type-check-implitem.cc
(TypeCheckImplItemWithTrait::visit): Store impl associated types as
projections
* typecheck/rust-hir-type-check-item.cc
(TypeCheckItem::ResolveImplBlockSubstitutions): New function.
(TypeCheckItem::ResolveImplTraitAssociatedTypes): New function.
(TypeCheckItem::validate_trait_impl_block): cleanup
(TypeCheckItem::visit): Split inherent and trait impl handling.
(TypeCheckItem::resolve_impl_block): New function.
(TypeCheckItem::resolve_trait_impl_block): New function.
(TypeCheckItem::resolve_impl_block_substitutions): cleanup
* typecheck/rust-hir-type-check-item.h: helpers
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit):
cleanup
(TypeCheckExpr::resolve_segments): Use lazy projection normalization
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit):
Normalize type path projections and build qualified associated types
* typecheck/rust-hir-type-check.h (class ScopedPush): New class.
(class ImplTraitFrameGuard): New class.
* typecheck/rust-type-util.cc (query_type): Push impl trait frames
while resolving impl items.
(rebind_projection_self_from_fn): New function.
(normalize_projection): New function.
* typecheck/rust-type-util.h (normalize_projection): Declare.
(rebind_projection_self_from_fn): Declare.
* typecheck/rust-typecheck-context.cc
(TypeCheckContext::find_matching_impl_trait_frame): New function.
(TypeCheckContext::have_impl_trait_context): New function.
(TypeCheckContext::push_impl_trait_context): New function.
(TypeCheckContext::pop_impl_trait_context): New function.
(TypeCheckContext::peek_impl_trait_context): New function.
* typecheck/rust-tyty-bounds.cc
(TypeBoundPredicate::apply_argument_mappings): Stop mutating
associated type items for binding arguments.
(TypeBoundPredicateItem::get_tyty_for_receiver): Rebase projections
using trait substitution coordinates.
(TypeBoundPredicate::handle_substitions): Stop mutating associated
type items for binding arguments.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Rebind
projection self types after function monomorphization.
* typecheck/rust-tyty-subst.cc
(SubstitutionParamMapping::fill_param_ty): Guard recursive
(SubstitutionRef::get_mappings_from_generic_args): Account for outer
GAT parameters.
(SubstitutionRef::prepare_higher_ranked_bounds): Remove.
(SubstitutionRef::monomorphize): Bind matching impls
* typecheck/rust-tyty-subst.h
(SubstitutionRef::get_outer_param_count): New function.
(SubstitutionRef::prepare_higher_ranked_bounds): Remove.
* typecheck/rust-tyty.cc (BaseType::satisfies_bound): Check
associated type bindings through projection types.
(BaseType::destructure): Stop destructuring through projections.
(BaseType::monomorphized_clone): Normalize projection clones.
(BaseType::is_concrete): Handle projections
(ClosureType::setup_fn_once_output): Remove.
(destructure_through_projections): New function.
(ReferenceType::is_dyn_slice_type): Normalize projections
(ReferenceType::is_dyn_str_type): Likewise.
(ReferenceType::is_dyn_obj_type): Likewise.
(PointerType::is_dyn_slice_type): Likewise.
(PointerType::is_dyn_str_type): Likewise.
(PointerType::is_dyn_obj_type): Likewise.
(ParamType::get_name): Guard recursive
(PlaceholderType::set_associated_type): Remove
(PlaceholderType::clear_associated_type): Remove
(ProjectionType::ProjectionType): Track projection self type and
inherited trait substitutions.
(ProjectionType::is_trait_position): New function
(ProjectionType::get): Handle non-trait-position projections
(ProjectionType::get_self): New function.
(ProjectionType::get_trait_ref): New function.
(ProjectionType::get_item_defid): New function.
(ProjectionType::as_string): Include projection self and trait
(ProjectionType::clone): Clone projection self and preserve bounds
(ProjectionType::handle_substitions): Substitute projection self
* typecheck/rust-tyty.h: Update projection
* typecheck/rust-unify.cc (UnifyRules::go): Normalize projections
(UnifyRules::expect_projection): Support projection-to-projection

gcc/testsuite/ChangeLog:

* rust/compile/gat1.rs: Add lang item setup.
* rust/compile/gat2.rs: Use no_core setup.
* rust/compile/issue-2036.rs: Remove obsolete type inference error.
* rust/compile/issue-2905-2.rs: Enable iterator impl coverage.
* rust/compile/torture/traits18.rs: Move to...
* rust/compile/torture/traits18.rs.disabled: ...here.
* rust/compile/gat3.rs: New test.
* rust/compile/gat4.rs: New test.
* rust/compile/gat5.rs: New test.
* rust/compile/gat6.rs: New test.
* rust/compile/gat7.rs: New test.
* rust/compile/gat8.rs: New test.
* rust/compile/issue-4293.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 weeks agogccrs: allow bidirection inference on call expressions
Philip Herron [Mon, 22 Jun 2026 19:57:27 +0000 (20:57 +0100)] 
gccrs: allow bidirection inference on call expressions

This handles the awkward case of the try from stuff where everything needs
to constrain based on the return type of the block its part of.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): push expected type
* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): apply expected ty on tail
* typecheck/rust-hir-type-check.h: helpers
* typecheck/rust-typecheck-context.cc (TypeCheckContext::push_expected_type): likewise
(TypeCheckContext::pop_expected_type): likewise
(TypeCheckContext::peek_expected_type): likewise
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): check expected

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 weeks agogccrs: Fix ICE when ident is a lang item
Philip Herron [Sat, 18 Apr 2026 21:23:41 +0000 (22:23 +0100)] 
gccrs: Fix ICE when ident is a lang item

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): check for lang item

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 weeks agogccrs: Fix missing copy constructor arguments
Philip Herron [Sat, 18 Apr 2026 20:49:40 +0000 (21:49 +0100)] 
gccrs: Fix missing copy constructor arguments

gcc/rust/ChangeLog:

* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::TypeBoundPredicate): missing argument
(TypeBoundPredicate::operator=): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 weeks agogccrs: Optionally pull in the inherited arguments when required
Philip Herron [Sat, 17 Jan 2026 20:47:29 +0000 (20:47 +0000)] 
gccrs: Optionally pull in the inherited arguments when required

gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc: we can optionally apply inherited arguments

gcc/testsuite/ChangeLog:

* rust/compile/gat2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 weeks ago[PATCH] RISC-V: Fix dead cpop reservation for spacemit-x60
Jim Lin [Wed, 8 Jul 2026 13:59:30 +0000 (07:59 -0600)] 
[PATCH] RISC-V: Fix dead cpop reservation for spacemit-x60

The type "cpop" was listed in both spacemit_x60_alu (latency 1) and the
dedicated spacemit_x60_alu2c reservation (latency 2).  Since
spacemit_x60_alu appears first, it always matched cpop and left
spacemit_x60_alu2c dead, so cpop was scheduled with the wrong latency.

Remove cpop from spacemit_x60_alu so the dedicated 2-cycle reservation
takes effect.

gcc/ChangeLog:

* config/riscv/spacemit-x60.md (spacemit_x60_alu): Remove cpop
from the type list.

4 weeks agoRemove group_size argument from vect_built_slp_tree* APIs
Richard Biener [Wed, 8 Jul 2026 12:25:08 +0000 (14:25 +0200)] 
Remove group_size argument from vect_built_slp_tree* APIs

The group_size argument is redundant with the stmt vector length.

* tree-vect-slp.cc (vect_build_slp_tree_1): Remove group_size
argument and adjust.
(vect_build_slp_tree_2): Likewise.
(vect_build_slp_tree): Likewise.
(optimize_load_redistribution_1): Likewise.
(vect_build_slp_instance): Likewise.
(vect_analyze_slp_reduc_chain): Likewise.
(vect_analyze_slp_reduction): Likewise.
(vect_analyze_slp_reduction_group): Likewise.
(vect_analyze_slp_instance): Likewise.
(vect_lower_load_permutations): Likewise.

4 weeks agotree-optimization/126150 - ICE with replace_uses_by
Richard Biener [Wed, 8 Jul 2026 11:57:17 +0000 (13:57 +0200)] 
tree-optimization/126150 - ICE with replace_uses_by

replace_uses_by triggers eventual BB removal from inside a
FOR_EACH_IMM_USE_STMT iteration.  That's a no-go since we might
eliminate uses in the list we are currently processing.  The
fix is to defer EH edge purging.

PR tree-optimization/126150
* tree-cfg.cc (replace_uses_by): Delay purging of EH edges
until after FOR_EACH_IMM_USE_STMT finished.

* g++.dg/pr126150.C: New testcase.

4 weeks agoc: harmonize handling of arrays of zero size
Martin Uecker [Sun, 28 Jun 2026 17:29:48 +0000 (19:29 +0200)] 
c: harmonize handling of arrays of zero size

Use common functions for creating and detecting arrays of zero size.
The function to detect arrays of zero size is changed to also accept
C++ style representation that are somtimes created (at least in
complete_array_type).  A future change may switch to only use this
representation.  Other code is refactored to use the new helper functions
and to use flexible_array_member_type_p to properly distinguish between
the two cases (instead of checking for TYPE_MAX_VALUE being NULL_TREE).
As part of this, the explict check for complete types is removed from
composite_type_internal, which may be helpful when potentially allowing
arrays with incomplete element type (which alsoC occur already for
built-in va_arg types).

gcc/c/ChangeLog:
* c-tree.h (zero_length_array_type_p,
c_build_array_type_zero_size) Add prototypes.
* c-decl.cc (zero_length_array_type_p): External linkage.
(c_build_array_type_zero_size): New.
(grokdeclarator): Use new function.
* c-typeck.cc (c_verify_type): New consistency checks.
(c_build_array_type_zero_size): New function
(composite_type_internal): Refactor.
(comptypes_internal): Refactor.

4 weeks agoc: harmonize checking for flex array member type
Martin Uecker [Sun, 28 Jun 2026 18:04:14 +0000 (20:04 +0200)] 
c: harmonize checking for flex array member type

We already have a helper function to detect the type of a flexible
array member.  Rename it for consistency and move it to tree.cc.
Also use the function for some additional cases instead of using a
direct test.  In digest_init the change removes the warning for
zero-sized arrays, but it is misleading and redundant as we already
warn for excess initializers (and with -Wpedantic also for the use
of zero-sized arrays).

gcc/c-family/ChangeLog:
* c-attribs.cc (handle_counted_by_attribute): Adapt.
* c-common.h (c_flexible_array_member_type_p): Remove.
* c-common.cc (c_flexible_array_member_type_p): Remove.

gcc/c/ChangeLog:
* c-decl.cc (grokdeclarator): Add assertion.
(add_flexible_array_elts_to_size): Adapt.
(is_flexible_array_member_p): Adapt.
(verify_counted_by_attribute): Adapt.
(finish_struct): Adapt.
* c-typeck.cc (check_counted_by_attribute): Adapt.
(build_counted_by_ref): Adapt.
(build_access_with_size_for_counted_by): Adapt.
(handle_counted_by_for_component_ref): Adapt.
(c_incomplete_type_error): Use new helper function.
(digest_init): Use new helper function.
(pop_init_level): Use new helper function.

gcc/ChangeLog:
* tree.h (flexible_array_member_type_p): New helper function.
* tree.cc (flexible_array_member_type_p): New helper function.
(flexible_array_type_p): Use new helper function.

4 weeks agotree-optimization/126159 - handle unions in data dependence analysis
Richard Biener [Wed, 8 Jul 2026 08:06:40 +0000 (10:06 +0200)] 
tree-optimization/126159 - handle unions in data dependence analysis

The following implements minimal handling of union accesses in
data reference analysis, namely accesses to non-aggregate fields,
in particular those we are not adding additional subsetting on.

PR tree-optimization/126159
* tree-data-ref.cc (dr_analyze_indices): Handle non-aggregate
union field accesses.
(access_fn_component_p): Adjust.

* gcc.dg/vect/vect-pr126159-1.c: New testcase.
* gcc.dg/vect/vect-pr126159-2.c: Likewise.

4 weeks agofortran: Create a dedicated type for ranks and array dimensions
Mikael Morin [Mon, 22 Jun 2026 14:53:30 +0000 (16:53 +0200)] 
fortran: Create a dedicated type for ranks and array dimensions

This patch adds a type to represent ranks and array dimension, using the
same base type as originally used for the rank in array descriptors
(signed char), but with the stricter bounds (0 to GFC_MAX_DIMENSIONS)
brought to the knowledge of the middle-end.  The new type is used for
the rank in array descriptors, and in various places in the compiler as
well, such as loops on array dimensions.  Conversions to signed char
are added in places where negative intermediary results were possible,
and loops on array dimensions where the new type is used have been
double-checked to not step backwards (in which case the iteration index
would reach -1 after the last iteration).

gcc/fortran/ChangeLog:

* trans-types.h (gfc_array_dim_rank_type): New type node
declaration.
* trans-types.cc (gfc_array_dim_rank_type): Likewise.
(gfc_init_types) : Initialize the new type node.
(get_dtype_type_node): Use the new type for the rank field.
* trans-descriptor.cc (gfc_conv_descriptor_rank): Likewise.
* trans-const.h (gfc_index_zero_node, gfc_index_one_node): Make
each macro a separate node declaration.
* trans-const.cc (gfc_index_zero_node, gfc_index_one_node):
Declare new nodes.
(gfc_init_constants): Initialize them.  Use the new type for the
constants of the gfc_rank_cst array.
* trans-array.cc (gfc_tree_array_size): Use the new type for the
RANK, IDX and DIM variables.  Avoid negative intermediary value
in comparison using the new type.
(gfc_conv_array_parameter): Use the new type when assigning a
value to the descriptor's rank.  Use the new type for the IDX
variable.
* trans-decl.cc (gfc_conv_cfi_to_gfc): Use the new type for the
rank, and the dimension index variable (including loop initial
value and step).
* trans-expr.cc (gfc_conv_gfc_desc_to_cfi_desc): Likewise.
(gfc_conv_variable): Use the new type for the rank variable.
(gfc_trans_structure_assign): Use the new type when assigning a
value to the descriptor's rank.
* trans-openmp.cc (gfc_omp_get_array_size): Use the new type
for the dimension index variable and the loop initialization,
bound and step.
* trans-intrinsic.cc (gfc_conv_intrinsic_bound): Use the new
type for the DIM argument and the rank.
(conv_intrinsic_cobound): Likewise.
(trans_this_image): Likewise.  Use the new type for the loop
variable, initialization, bound and step.
(gfc_conv_intrinsic_sizeof): Likewise.
* trans-stmt.cc (gfc_trans_select_rank_cases): Use signed char
as type for the select value.

4 weeks agomatch.pd: Fold SAD_EXPR with identical inputs
Pengfei Li [Mon, 6 Jul 2026 13:11:32 +0000 (13:11 +0000)] 
match.pd: Fold SAD_EXPR with identical inputs

Normally, SAD_EXPRs with identical first and second operands are not
constructed, since the absolute difference value is zero. However, this
can still appear when vectorizing small iteration-count reduction loops
with an absolute difference operation.

This patch adds a match.pd rule to fold the redundant SAD_EXPR to its
accumulator operand.

Bootstrapped and tested on aarch64-linux-gnu and x86_64-linux-gnu.

gcc/ChangeLog:

* match.pd: Simplify SAD(x, x, acc) into acc.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/sve/sad_2.c: New test.

4 weeks agoRename SEH functions for reuse in AArch64
Evgeny Karpov [Fri, 15 Nov 2024 12:36:41 +0000 (13:36 +0100)] 
Rename SEH functions for reuse in AArch64

This patch renames functions related to SEH functionality. These
functions will be reused in the aarch64-w64-mingw32 target.

Signed-off-by: Evgeny Karpov <evgeny@kmaps.co>
gcc/ChangeLog:

* config/i386/cygming.h (TARGET_ASM_FUNCTION_END_PROLOGUE):
Rename.
(TARGET_ASM_EMIT_EXCEPT_PERSONALITY): Likewise.
(TARGET_ASM_INIT_SECTIONS): Likewise.
(SUBTARGET_ASM_UNWIND_INIT): Likewise.
(ASM_DECLARE_FUNCTION_SIZE): Likewise.
(ASM_DECLARE_COLD_FUNCTION_SIZE): Likewise.
* config/i386/i386-protos.h (i386_pe_end_function):
Remove declarations.
(i386_pe_end_cold_function): Likewise.
(i386_pe_seh_init): Likewise.
(i386_pe_seh_end_prologue): Likewise.
(i386_pe_seh_cold_init): Likewise.
(i386_pe_seh_emit_except_personality): Likewise.
(i386_pe_seh_init_sections): Likewise.
* config/mingw/winnt.cc (defined): Update.
(struct seh_frame_state): Move to mingw/winnt.h.
(i386_pe_seh_init): Rename into ...
(mingw_pe_seh_init): ... this.
(i386_pe_seh_end_prologue): Rename into ...
(mingw_pe_seh_end_prologue): ... this.
(i386_pe_seh_cold_init): Rename into ...
(mingw_pe_seh_cold_init): ... this.
(i386_pe_seh_fini): Rename into ...
(mingw_pe_seh_fini): ... this.
(seh_emit_stackalloc): Rename into ...
(mingw_pe_seh_emit_stackalloc): ... this.
(seh_cfa_adjust_cfa): Update.
(seh_frame_related_expr): Update.
(i386_pe_seh_emit_except_personality): Rename into ...
(mingw_pe_seh_emit_except_personality): ... this.
(i386_pe_seh_init_sections): Rename into ...
(mingw_pe_seh_init_sections): ... this.
(i386_pe_end_function): Rename into ...
(mingw_pe_end_function): ... this.
(i386_pe_end_cold_function): Rename into ...
(mingw_pe_end_cold_function): ... this.
* config/mingw/winnt.h (struct seh_frame_state):
Move from mingw/winnt.cc.
(mingw_pe_end_cold_function): Add declarations.
(mingw_pe_end_function): Likewise.
(mingw_pe_seh_init): Likewise.
(mingw_pe_seh_init_sections): Likewise.
(mingw_pe_seh_cold_init): Likewise.
(mingw_pe_seh_emit_except_personality): Likewise.
(mingw_pe_seh_end_prologue): Likewise.

4 weeks agovect: unshare header computation for more CSE
Tamar Christina [Wed, 8 Jul 2026 07:35:45 +0000 (08:35 +0100)] 
vect: unshare header computation for more CSE

The example loop

#define N 512
#define START 1
#define END 505

int x[N] __attribute__((aligned(32)));

int __attribute__((noipa))
foo (void)
{
  for (int *p = x + START; p < x + END; ++p)
    if (*p == 0)
      return START;

  return -1;
}

shows that when we vectorize we generate the following pre-header when doing
peeling for alignment:

  _22 = (unsigned long) &MEM <int[512]> [(void *)&x + 4B];
  _23 = _22 & POLY_INT_CST [15, 16];
  _24 = _23 >> 2;
  _26 = 1 - _24;
  _27 = _26 * 4;
  vectp_x.6_25 = &x + _27;
  _36 = 504 + _24;
  max_mask_37 = .WHILE_ULT (0, _36, { 0, ... });
  _38 = .WHILE_ULT (0, _24, { 0, ... });
  _39 = ~_38;
  _40 = max_mask_37 & _39;

notice how _22 and and the actual vector pointer vectp_x.6_25 start at the
same offset but have a different base.  This happens because in
vect_create_addr_base_for_vector_ref we fold the offset into the base very
early and so we can't form or share the address computation anymore with the
scalar address which needs to be there for the alignment checks.

The patch delays this and forms an explicit base + offset and keeping base as
a separate value.  This allows VN at the end of vect to share the computations
and we get

  _22 = (unsigned long) &MEM <int[512]> [(void *)&x + 4B];
  _23 = _22 & POLY_INT_CST [15, 16];
  _24 = _23 >> 2;
  _27 = _24 * 4;
  _28 = -_27;
  vectp_x.6_26 = &MEM <int[512]> [(void *)&x + 4B] + _28;
  _37 = 504 + _24;
  max_mask_38 = .WHILE_ULT (0, _37, { 0, ... });
  _39 = .WHILE_ULT (0, _24, { 0, ... });
  _40 = ~_39;
  _41 = max_mask_38 & _40;

Notice how they now share the same base address.  This drops two instructions
off the loop pre-header:

from

foo:
        cntb    x0
        sub     x3, x0, #1
        cmp     x0, 4096
        and     x0, x0, x3
        ccmp    x0, 0, 0, ls
        bne     .L7
        adrp    x4, .LANCHOR0
        add     x4, x4, :lo12:.LANCHOR0
        add     x1, x4, 4
        mov     w2, 1
        and     x1, x1, x3
        mov     w0, 0
        cntw    x3
        lsr     x1, x1, 2
        whilelo p15.s, xzr, x1
        sub     x2, x2, x1
        add     x1, x1, 504
        whilelo p7.s, xzr, x1
        not     p7.b, p7/z, p15.b
        add     x2, x4, x2, lsl 2
        b       .L4

to

foo:
        cntb    x0
        sub     x1, x0, #1
        cmp     x0, 4096
        and     x0, x0, x1
        adrp    x2, .LANCHOR0
        ccmp    x0, 0, 0, ls
        add     x2, x2, :lo12:.LANCHOR0
        bne     .L7
        add     x2, x2, 4
        mov     w0, 0
        and     x1, x2, x1
        cntw    x3
        sub     x2, x2, x1
        lsr     x1, x1, 2
        whilelo p15.s, xzr, x1
        add     x1, x1, 504
        whilelo p7.s, xzr, x1
        not     p7.b, p7/z, p15.b
        b       .L4

gcc/ChangeLog:

* tree-vect-data-refs.cc (vect_create_addr_base_for_vector_ref):
Restructure computations to force separate base.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/sve/vect-early-break-cbranch_18.c: New test.

4 weeks agovect: replace iterations bounded to length to for_each
Tamar Christina [Wed, 8 Jul 2026 07:34:33 +0000 (08:34 +0100)] 
vect: replace iterations bounded to length to for_each

Replace uses of iterators over length of SLP_TREE_SCALAR_STMTS and
SLP_TREE_SCALAR_OPS with for-each loops when the .length () was just being used
as an index.

This is because we are trying to get rid of the notion of the number of scalar
statement or ops determining the number of lanes in the SLP tree and such
iterators are confusing.

i.e. it was a numbered for each.

gcc/ChangeLog:

* tree-vect-data-refs.cc (vect_slp_analyze_store_dependences,
vect_slp_analyze_load_dependences,
vect_slp_analyze_instance_dependence): Use for-each over for with len.
* tree-vect-slp.cc (vect_mark_slp_stmts_relevant,
,vect_find_last_scalar_stmt_in_slp, vect_find_first_scalar_stmt_in_slp,
vect_build_slp_store_interleaving, vect_analyze_slp,
vect_slp_prune_covered_roots, vect_bb_partition_graph_r,
vect_remove_slp_scalar_calls): Likewise.

4 weeks agoImprove variadic function call handling in PTA
Richard Biener [Tue, 7 Jul 2026 06:54:45 +0000 (08:54 +0200)] 
Improve variadic function call handling in PTA

The following fixes handling of __builtin_va_start handling and
implements .VA_ARG handling in PTA constraint generation to
improve precision around variadic calls.  I've added a testcase
for IPA PTA involving an indirect variadic call verifying precision.

The pr99679-1.C no longer emits an expected error that was triggered
by PTA calling aggregate_value_p on the .VA_ARG call which we no
longer do.

* gimple-ssa-pta-constraints.cc (find_func_aliases_for_builtin_call):
Correctly use SCALAR rhs from the variadic argument part of
the function info or from NONLOCAL in case of intra-PTA.
(find_func_aliases_for_call): Handle .VA_ARG.

* gcc.dg/ipa/ipa-pta-20.c: New testcase.
* g++.target/i386/pr99679-1.C: Remove expected error.
* g++.target/i386/pr99679-2.C: Likewise.

4 weeks agoaarch64: populate issue_info for the ampere1 family
Philipp Tomsich [Wed, 8 Jul 2026 06:46:25 +0000 (08:46 +0200)] 
aarch64: populate issue_info for the ampere1 family

The ampere1, ampere1a and ampere1b tunes leave the vector issue_info
in cpu_vector_cost as NULL, so determine_suggested_unroll_factor bails
out early and reduction loops are never multi-accumulator-unrolled on
these cores.  Fill it in from the ampere1 optimization guide (L1D two
128-bit loads plus one store per cycle, four general ops per cycle).

gcc/ChangeLog:

* config/aarch64/tuning_models/ampere1.h (ampere1_scalar_issue_info)
(ampere1_advsimd_issue_info, ampere1_vec_issue_info): New.
(ampere1_vector_cost): Use ampere1_vec_issue_info for issue_info.
* config/aarch64/tuning_models/ampere1b.h (ampere1b_scalar_issue_info)
(ampere1b_advsimd_issue_info, ampere1b_vec_issue_info): New.
(ampere1b_vector_cost): Use ampere1b_vec_issue_info for issue_info.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/ampere1-reduction-unroll-1.c: New test.

4 weeks agox86: Implement TARGET_FNTYPE_ABI
H.J. Lu [Tue, 14 Apr 2026 10:37:20 +0000 (18:37 +0800)] 
x86: Implement TARGET_FNTYPE_ABI

Implement TARGET_FNTYPE_ABI to avoid spills of callee-saved registers
when calling functions with no_caller_saved_registers attribute.

After

commit 754c6600fe058f1026098fde57860bbc38cc28fe
Author: Richard Sandiford <rdsandiford@googlemail.com>
Date:   Wed Jun 3 13:11:17 2026 +0100

    Add CALL_INSN_ABI_ID

there is no need for ix86_expand_call to add clobbers for when one ABI
calls another ABI.

ABI_ALTERNATE is the alternate function ABI from the system ABI.  If
ix86_abi is SYSV_ABI, ABI_ALTERNATE is the function ABI for MS_ABI.
Otherwise, ABI_ALTERNATE is the function ABI for SYSV_ABI.

This target hook also properly marks the implicit __tls_get_addr call:

(call_insn/u 9 8 10 (parallel [
            (set (reg:DI 0 ax)
                (call:DI (mem:QI (symbol_ref:DI ("__tls_get_addr")) [0  S1 A8])
                    (const_int 0 [0])))
            (unspec:DI [
                    (reg/f:DI 7 sp)
                ] UNSPEC_TLS_LD_BASE)
            (clobber (reg:DI 5 di))
        ]) "x.c":7:16 -1
     (expr_list:REG_EH_REGION (const_int -2147483648 [0xffffffff80000000])
        (nil))
    (nil) 0)

with ABI_DEFAULT function ABI.

Tested on Linux/x86-64 and with CPython 3.14.4.

gcc/

PR target/124798
PR target/125436
* config/i386/i386-expand.cc: Include "function-abi.h".
(x86_64_ms_sysv_extra_clobbered_registers): Removed.
(ix86_expand_call): Don't add explicit call and ABI-switch
clobbers.
* config/i386/i386-features.cc (ix86_emit_tls_call): Call
ix86_tls_get_addr_abi to get GNU TLS ABI and use it, instead of
default_function_abi, for registers clobbered by GNU TLS call.
(ix86_place_single_tls_call): Set CALL_INSN_ABI_ID on TLS calls.
* config/i386/i386-options.cc (ix86_set_current_function): Don't
call reinit_regs.
* config/i386/i386-protos.h
(ix86_type_no_callee_saved_registers_p): Removed.
(ix86_tls_get_addr_abi): New.
* config/i386/i386.cc (ix86_alternate_abi): New prototype.
(ix86_conditional_register_usage): Changed to describe the
system ABI.
(ix86_type_no_callee_saved_registers_p): Make it static.
(ix86_function_value_regno_p): Replace ix86_cfun_abi () with
ix86_abi.
(ix86_save_reg): Only check TYPE_NO_CALLEE_SAVED_REGISTERS as
a special case.
(ix86_tls_get_addr_abi): New.
(legitimize_tls_address): Set CALL_INSN_ABI_ID on TLS calls.
Call ix86_alternate_abi to initialize the alternate function ABI.
(ix86_initialize_abi): New function.
(ix86_no_callee_saved_abi): Likewise.
(ix86_no_caller_saved_abi): Likewise.
(ix86_standard_abi): Likewise.
(ix86_alternate_abi): Likewise.
(ix86_function_abi_id): Likewise.
(ix86_fntype_abi): Likewise.
(ix86_hard_regno_call_part_clobbered): Handle newly added ABIs.
(TARGET_FNTYPE_ABI): New.
* config/i386/i386.md: Add ABI_ALTERNATE, ABI_NO_CALLEE_SAVED,
ABI_NO_CALLER_SAVED_RETURN_VOID, ABI_NO_CALLER_SAVED_RETURN_AX,
ABI_NO_CALLER_SAVED_RETURN_AX_DX,
ABI_NO_CALLER_SAVED_RETURN_AX_XMM0,
ABI_NO_CALLER_SAVED_RETURN_XMM0 and
ABI_NO_CALLER_SAVED_RETURN_XMM0_XMM1.

gcc/testsuite/

PR target/124798
PR target/125436
* gcc.target/i386/abi-mix-1.c: New test.
* gcc.target/i386/abi-mix-2.c: Likewise.
* gcc.target/i386/no-callee-saved-20.c: Likewise.
* gcc.target/i386/no-caller-saved-1-ms.c: Likewise.
* gcc.target/i386/no-caller-saved-1-sysv.c: Likewise.
* gcc.target/i386/no-caller-saved-1.c: Likewise.
* gcc.target/i386/no-caller-saved-2.c: Likewise.
* gcc.target/i386/no-caller-saved-3.c: Likewise.
* gcc.target/i386/no-caller-saved-4.c: Likewise.
* gcc.target/i386/no-caller-saved-5.c: Likewise.
* gcc.target/i386/no-caller-saved-6.c: Likewise.
* gcc.target/i386/no-caller-saved-7.c: Likewise.
* gcc.target/i386/no-caller-saved-8.c: Likewise.
* gcc.target/i386/no-caller-saved-9.c: Likewise.
* gcc.target/i386/no-caller-saved-10.c: Likewise.
* gcc.target/i386/no-caller-saved-11.c: Likewise.
* gcc.target/i386/pr125436-1a.c: Likewise.
* gcc.target/i386/pr125436-1b.c: Likewise.
* gcc.target/i386/pr125436-2a.c: Likewise.
* gcc.target/i386/pr125436-2b.c: Likewise.
* gcc.target/i386/pr125436-3.c: Likewise.
* gcc.target/i386/pr125436-4.c: Likewise.
* gcc.target/i386/pr119784b.c: Adjusted for unused RBP.
* gcc.target/i386/no-callee-saved-18.c: Don't check frame
register.
* gcc.target/i386/no-callee-saved-19b.c: Update the expected
instruction order.
* gcc.target/i386/no-callee-saved-19d.c: Likewise.
* gcc.target/i386/no-callee-saved-19e.c: Likewise.
* gcc.target/i386/no-callee-saved-2.c: Check frame register isn't
saved nor restored in 64-bit mode.
* gcc.target/i386/no-callee-saved-8.c: Expect no saving nor
restoring caller-saved registers.
* gcc.target/i386/no-callee-saved-9.c: Likewise.
* gcc.target/i386/preserve-none-14.c: Don't check frame register.
* gcc.target/i386/preserve-none-23.c: Likewise.
* gcc.target/i386/preserve-none-7.c: Check frame register isn't
saved nor restored in 64-bit mode.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Co-Authored-by: Richard Sandiford <rdsandiford@googlemail.com>
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
4 weeks agoi386: Avoid always-true condition
Richard Sandiford [Thu, 14 May 2026 22:06:39 +0000 (23:06 +0100)] 
i386: Avoid always-true condition

ix86_function_arg is always passed a cumulative argument structure,
so the ?: test in the patch was redundant.

gcc/
* config/i386/i386.cc (ix86_function_arg): Remove always-true
condition.

4 weeks agoi386: Avoid reading call_used_regs
Richard Sandiford [Thu, 14 May 2026 21:43:40 +0000 (22:43 +0100)] 
i386: Avoid reading call_used_regs

call_used_regs is a legacy interface that targets use to tell
init_reg_sets_1 about the default (system) ABI.  In x86 terms,
that means the ABI associated with ix86_abi.

Targets can continue to read call_used_regs directly if they
don't have multiple ABIs.  But now that x86 does, it's better
to be explicit about which ABI is being queried.  This is
currently a nop but becomes important with the upcoming
function_abi patch.

As the comment in ix86_emit_tls_call says:

      /* TLS_GD and TLS_LD_BASE instructions are normal functions which
 clobber caller-saved registers. [...]

So that function really is querying the system ABI.

Similarly, x86_order_regs_for_local_alloc is called when initialising
a target, rather than once per function, so it too should query the
system ABI.

ix86_save_reg and x86_64_select_profile_regnum ask about the
current function's ABI, which is crtl->abi.

gcc/
* config/i386/i386-features.cc: Include function-abi.h.
(ix86_emit_tls_call): Use default_function_abi instead of
call_used_regs.
* config/i386/i386.cc (x86_order_regs_for_local_alloc): Likewise.
(ix86_save_reg, x86_64_select_profile_regnum): Use crtl->abi
instead of call_used_regs.

4 weeks agoi386: Split out call_saved_registers_type detection
Richard Sandiford [Thu, 14 May 2026 21:51:49 +0000 (22:51 +0100)] 
i386: Split out call_saved_registers_type detection

There are currently two places that want to query a function's
call_saved_registers_type: ix86_set_func_type (when setting up
cfun->machine) and ix86_type_no_callee_saved_registers_p
(a derived query).  The upcoming function_abi patch will add
another one, so this patch splits the code out into a subroutine.

ix86_set_func_type did some of the detection first, into
no_callee_saved_registers, but then ignored the result if
cfun->machine->func_type had already been set.  The patch therefore
moves all of the detection after the cfun->machine->func_type test,
rather than moving all of it before.

gcc/
* config/i386/i386-protos.h (ix86_fntype_call_saved_registers):
Declare.
* config/i386/i386-options.cc (ix86_fntype_call_saved_registers): New
function, split out from...
(ix86_set_func_type): ...here.  Avoid calling it if the result
would be ignored.
* config/i386/i386.cc (ix86_type_no_callee_saved_registers_p): Use
ix86_fntype_call_saved_registers instead of querying attributes
directly.

4 weeks agoRISC-V: Add test cases for vzext.vf2 reg overlap
Pan Li [Wed, 1 Jul 2026 05:48:17 +0000 (13:48 +0800)] 
RISC-V: Add test cases for vzext.vf2 reg overlap

Add test cases for vzext.vf2 register group overlap, please
note it is not overlap as much as possible.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf2-u16-m1.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf2-u16-m2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf2-u16-m4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf2-u16-mf2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf2-u16-mf4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf2-u32-m1.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf2-u32-m2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf2-u32-m4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf2-u32-mf2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf2-u8-m1.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf2-u8-m2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf2-u8-m4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf2-u8-mf2.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf2-u8-mf4.c: New test.
* gcc.target/riscv/rvv/autovec/group_overlap/vzext_vf2-u8-mf8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>