]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
4 hours agoUse can_open_code_p in gimple-ssa-store-merging master trunk
Richard Sandiford [Sat, 6 Jun 2026 08:16:13 +0000 (09:16 +0100)] 
Use can_open_code_p in gimple-ssa-store-merging

...and extend can_open_code_p to handle bswap.

I'm not sure that the removed builtin_decl_explicit_p (BUILT_IN_BSWAP32)
calls are necessary, since the code would go on to use a BSWAP64
rather than a BSWAP32.

This fixes gcc.dg/optimize-bswapsi-6.c on RISC-V.

gcc/
* optabs-query.cc (can_open_code_p): Handle more bswap cases,
incorporating logic from...
* gimple-ssa-store-merging.cc (maybe_optimize_vector_constructor)
(pass_optimize_bswap::execute)
(imm_store_chain_info::try_coalesce_bswap): ...here.  Use
can_open_code_p instead of direct optab_handler checks.

4 hours agoi386: Fix up predicates on <ssse3_avx2>_pmulhrsw<mode>3, smulhrs<mode>3 expanders...
Jakub Jelinek [Sat, 6 Jun 2026 07:50:35 +0000 (09:50 +0200)] 
i386: Fix up predicates on <ssse3_avx2>_pmulhrsw<mode>3, smulhrs<mode>3 expanders [PR125611]

The following testcase ICEs since r6-6060-gacf93f1edc9 aka PR68991 fix.
THe problem is that the commit has changed the predicates on
*<ssse3_avx2>_pmulhrsw<mode>3<mask_name> pattern from nonimmediate_operand
to vector_operand but kept the old predicates on the corresponding
expanders.  With TARGET_AVX that makes no difference (so I've left
the <ssse3_avx2>_pmulhrsw<mode>3_mask expander as is, that is only
TARGET_AVX512BW && TARGET_AVX512VL), but without it if there is unaligned
memory the expander can just expand it as memory without forcing into REG
while the pattern will not match.

2026-06-06  Jakub Jelinek  <jakub@redhat.com>

PR target/125611
* config/i386/sse.md (<ssse3_avx2>_pmulhrsw<mode>3, smulhrs<mode>3):
Use vector_operand instead of nonimmediate_operand.

* gcc.target/i386/ssse3-pr125611.c: New test.

Reviewed-by: Uros Bizjak <ubizjak@gmail.com>
7 hours ago[PATCH] csky: define DWARF_ALT_FRAME_RETURN_COLUMN`
Ramin Moussavi [Sat, 6 Jun 2026 05:13:12 +0000 (23:13 -0600)] 
[PATCH] csky: define DWARF_ALT_FRAME_RETURN_COLUMN`

Tested with a csky-linux-uclibc gcc 15.2.0 cross compiler against uClibc-ng,
running its NPTL test suite on qemu-system-cskyv2: without the fix eight
cancellation tests abort (tst-cancel1/10/11/13/15/16/18, tst-cleanup4); with
it all pass and the rest of the suite is unchanged.

gcc/ChangeLog:

* config/csky/csky.h (DWARF_ALT_FRAME_RETURN_COLUMN): Define.

Signed-off-by: Ramin Moussavi <ramin.moussavi@yacoub.de>
14 hours agoopenmp: Remove warning about unused iterator variable in map clauses
Sandra Loosemore [Wed, 4 Mar 2026 18:44:55 +0000 (18:44 +0000)] 
openmp: Remove warning about unused iterator variable in map clauses

The gimplifier currently issues a warning about unused iterator
variables in map clauses, implemented by doing a code walk to search
for uses.  Unfortunately this is too late; the front ends can optimize
away explicit references to variables, for example by using fold_build*
expression constructors.  This leads to false positives.

Additionally the Fortran front end constructs implicit map clauses for
array descriptors that may be associated with iterators but don't reference
the iterator variable.  Warning about these is just confusing.

Probably, if we are going to warn about this, it should happen in the
front ends.  But it's probably not important enough to justify the amount
of work required, so for now, let's just remove it from the gimplifier.

gcc/ChangeLog
* gimplify.cc (remove_unused_omp_iterator_vars): Don't warn about
possibly-unused iterator variables.  Simplify control flow of
remaining code.

gcc/testsuite/ChangeLog
* c-c++-common/gomp/target-map-iterators-2.c: Don't expect warnings
about unused iterator variables.
* c-c++-common/gomp/target-update-iterators-2.c: Likewise.

14 hours agoC++, OpenMP: Handle ARRAY_TYPE array sections, not just pointers
Sandra Loosemore [Thu, 28 May 2026 15:37:11 +0000 (15:37 +0000)] 
C++, OpenMP: Handle ARRAY_TYPE array sections, not just pointers

This patch is a bug fix for commit gcc-17-202-g3f8c7483112, 'OpenMP:
Expand "declare mapper" mappers for target {enter,exit,} data
directives'.  The ChangeLog for that patch indicated that
cxx_omp_map_array_section was supposed to accept both arrays and
pointers as the base expression, but the code actually only allowed
pointers.  OTOH, both the error-checking in handle_omp_array_sections_1
and the code generation in build_array_ref allow ARRAY_TYPE, and code with
such expressions is actually coming in to the function.

There is no test case included with this patch, but I ran across this
in the two new test cases included with the OpenMP iterators patch
https://gcc.gnu.org/pipermail/gcc-patches/2025-July/689071.html which
I am preparing to resubmit.

gcc/cp/ChangeLog
* semantics.cc (cxx_omp_map_array_section): Allow ARRAY_TYPE
expressions, not just pointers.

15 hours agoc++/modules: disable dependent ADL inside header unit [PR125334]
Patrick Palka [Fri, 5 Jun 2026 21:05:33 +0000 (17:05 -0400)] 
c++/modules: disable dependent ADL inside header unit [PR125334]

This PR reports that building <bits/stdc++.h> as a header unit later
slows down initial std module stream-in by around 2x compared to if
the std module is built without the header unit, i.e.

  g++ -fmodules -fsearch-include-path bits/std.cc
  g++ -fmodules testcase.C # 15% slower vs before r16-6311

vs

  g++ -fmodules -fsearch-include-path bits/stdc++.h bits/std.cc
  g++ -fmodules testcase.C # 100% slower vs before r16-6311

This happens after the dependent ADL patch r16-6311.  My initial theory
for the slowdown was that the ADL step adds in many more dependency edges
between entities and results in larger SCC clusters, making lazy loading
less lazy, but the number of overall clusters doesn't seem to significantly
before/after the patch.  So I have no idea why there's such a big slowdown
and why header units are affected more.

But my basic understanding of the dependent ADL part of reachability
analysis is that it's not really needed when building a header unit
because header units don't discard or hide any entities.

So this patch disables it for header units which restores std module
stream-in back to pre r16-6311 levels when <bits/stdc++.h> is built as a
header unit.  When built without the header unit then std module stream-in
is still about 15% slower.  Maybe there's ways to safely speed up that
case too (e.g. only add dependency edges to GMF entities?) but I'll
leave that as future work.

PR c++/125334

gcc/cp/ChangeLog:

* module.cc (depset::hash::add_dependent_adl_entities):
Disable when inside a header unit.

Reviewed-by: Jason Merrill <jason@redhat.com>
15 hours agoc++/modules: some dependent ADL fixes
Patrick Palka [Fri, 5 Jun 2026 21:05:26 +0000 (17:05 -0400)] 
c++/modules: some dependent ADL fixes

When looking at the stream-in performance regression PR c++/125334
(caused by the dependent ADL patch r16-6311) I spotted some issues with
add_dependent_adl_entities:

  1. Fix memory leak in add_dependent_adl_entities when it exits early.
  2. Only consider type-dependent calls/operator expressions.
  3. Fix early exit test for when all args are type-dependent.
  4. Add assert verifying recursive name lookup does not happen with
     tentative/dependent ADL since it avoids type completion.

Plugging the memory leak reduces max memory usage by 3% when building
the std module, besides that no significant effect towards the
regression.

gcc/cp/ChangeLog:

* module.cc (dep_adl_info::args): Initializer to nullptr
instead of immediately allocating.
(depset::hash::add_dependent_adl_entities): Exit early
for non-type-dependent calls and operator expressions.
Only allocate dep_adl_info::args if we're not exiting early.
Correct all-type-dependent args test.
* name-lookup.cc (name_lookup::preserve_state): Replace
propagation of tentative flag with assert that it's not
set.

Reviewed-by: Jason Merrill <jason@redhat.com>
16 hours agocontrib: Use 'command -v' in download_prerequisites
Jonathan Wakely [Fri, 5 Jun 2026 14:54:44 +0000 (15:54 +0100)] 
contrib: Use 'command -v' in download_prerequisites

If wget is not installed, this script prints a message to standard error
which makes it looks like something is wrong:

./contrib/download_prerequisites: line 53: type: wget: not found

But if curl is installed then the script works fine. The command should
also redirect stderr with 2>&1 but it seems preferable to just replace
the use of 'type' with 'command -v' which is silent when the command is
not found.

Also add an explicit check for curl and print a more helpful error if
not found.

contrib/ChangeLog:

* download_prerequisites: use 'command -v' to check for wget and
curl.

17 hours agocobol: Update tests for IBM COMP-1/2 formatting.
Robert Dubner [Fri, 5 Jun 2026 19:16:06 +0000 (15:16 -0400)] 
cobol: Update tests for IBM COMP-1/2 formatting.

gcc/testsuite/ChangeLog:

* cobol.dg/group2/DISPLAY_IBM-formatted_COMP-1_and_COMP-2.cob:
Tests for "DISPLAY 1.23" as ".123 01".
* cobol.dg/group2/DISPLAY_IBM-formatted_COMP-1_and_COMP-2.out:
Likewise.

17 hours agoDOM should not process unreachable if there is an SSA relation.
Andrew MacLeod [Wed, 3 Jun 2026 21:46:03 +0000 (17:46 -0400)] 
DOM should not process unreachable if there is an SSA relation.

DOM should follow VRP's lead and not attempt o assign global values to
SSA names when the branch leading to a __builtin_unreachable () has
2 ssa-names.  Relations elsewhere may lead to this being invalid.

PR tree-optimization/125501
gcc/
* tree-ssa-dom.cc (set_global_ranges_from_unreachable_edges): Abort
if there are 2 SSA_NAMES on the branch condition.
gcc/testsuite/
* gcc.dg/pr125501.c: New.

17 hours agocobol: Properly DISPLAY COMP-1/-2 variables when "-dialect ibm" is in effect. [PR125616]
Robert Dubner [Fri, 5 Jun 2026 18:57:27 +0000 (14:57 -0400)] 
cobol: Properly DISPLAY COMP-1/-2 variables when "-dialect ibm" is in effect. [PR125616]

Second try at DISPLAY COMP-1.  The generated output now matches the
example giving in the PR.

This also addresses a lang.opt.urls problem.

PR cobol/125616

gcc/cobol/ChangeLog:

* lang.opt.urls: Regenerated.

libgcobol/ChangeLog:

* libgcobol.cc (format_for_display_internal): Format matches the
description in the PR.

18 hours agoc++: add missing auto_diagnostic_group
Marek Polacek [Fri, 5 Jun 2026 17:43:29 +0000 (13:43 -0400)] 
c++: add missing auto_diagnostic_group

Forgot this in r17-1355-gf213d6591640f7.

gcc/cp/ChangeLog:

* pt.cc (check_explicit_inst_of_var_template): Add
auto_diagnostic_group.

19 hours agoforge: Add a prototype CODEOWNERS file
Richard Earnshaw [Fri, 5 Jun 2026 15:24:04 +0000 (16:24 +0100)] 
forge: Add a prototype CODEOWNERS file

Many forge instances support a CODEOWNERS file as a way of automatically
requesting reviewers.  Forgejo is no different, though the syntax is not
the same as some other forge instances; so put this in the .forgejo
directory.

This version is for experimenting with the format.  I expect to want this
file to be autogenerated from other data at a later stage.

ChangeLog:

* .forgejo/CODEOWNERS: New file.

20 hours agofortran: Refactor the commit for 60576
Jerry DeLisle [Fri, 5 Jun 2026 16:22:55 +0000 (09:22 -0700)] 
fortran: Refactor the commit for 60576

PR fortran/60576

gcc/fortran/ChangeLog:

* trans-array.cc (gfc_resize_assumed_rank_dim_field): New
function extracted from gfc_conv_array_parameter.
(gfc_conv_array_parameter): Use the new function.

20 hours agocobol: Properly DISPLAY COMP-1/-2 variables when "-dialect ibm" is in effect. [PR125616]
Robert Dubner [Fri, 5 Jun 2026 15:43:59 +0000 (11:43 -0400)] 
cobol: Properly DISPLAY COMP-1/-2 variables when "-dialect ibm" is in effect. [PR125616]

Instead of GCOBOL's idiosyncratic display of COMP-1 and COMP-2 floating-point
variables, these changes result in IBM's specified format when "-dialect ibm"
is in effect.

The specification says

• Internal floating-point numbers are converted to external floating-point
numbers for display such that:

– A COMP-1 item will display as if it had an external floating-point
PICTURE clause of -.9(8)E-99.
– A COMP-2 item will display as if it had an external floating-point
PICTURE clause of -.9(17)E-99.

That's what these changes implement.

PR cobol/125616

gcc/cobol/ChangeLog:

* genapi.cc (parser_enter_file): New __gg__dialects variable.
(parser_division): Likewise.
* genutil.cc: Likewise.
* genutil.h: Likewise.
* lang.opt.urls: Updated.
* symbols.h (enum cbl_dialect_t): Move this enum to common-defs.h.

libgcobol/ChangeLog:

* common-defs.h (enum cbl_dialect_t): Move cbl_dialect_t here.
* intrinsic.cc (__gg__trim_1): Make a formal parameter const.
* libgcobol.cc (format_for_display_internal): Change the formatting
of COMP-1/COMP2 when "-dialect ibm" is in force.
(default_exception_handler): Whitespace formatting.
(ec_type_disposition): Likewise.
(ec_is_fatal): Likewise.

gcc/testsuite/ChangeLog:

* cobol.dg/group2/DISPLAY_IBM-formatted_COMP-1_and_COMP-2.cob: New test.
* cobol.dg/group2/DISPLAY_IBM-formatted_COMP-1_and_COMP-2.out: New test.

21 hours agoavoid-store-forwarding: Re-apply extension after bit insert sequence [PR124713]
Konstantinos Eleftheriou [Tue, 31 Mar 2026 12:12:33 +0000 (05:12 -0700)] 
avoid-store-forwarding: Re-apply extension after bit insert sequence [PR124713]

The avoid-store-forwarding pass loses SIGN_EXTEND/ZERO_EXTEND
semantics when the forwarding target is an extending load that is
not fully eliminated.  The bit-field insert operates on the
full-width destination register, but does not re-apply the
extension, leaving stale upper bits from the original load.

Fix by emitting the corresponding extension after the bit insert
sequence for non-eliminated extending loads, mirroring what the
load-elimination path already does.

PR rtl-optimization/124713

gcc/ChangeLog:

* avoid-store-forwarding.cc (process_store_forwarding): Re-apply
SIGN_EXTEND/ZERO_EXTEND after bit insert sequence when the load is
not eliminated.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/pr124713.c: New test.

21 hours agostore-merging, riscv: Consider widen_bswap_or_bitreverse in store-merging decisions...
Jakub Jelinek [Fri, 5 Jun 2026 15:16:59 +0000 (17:16 +0200)] 
store-merging, riscv: Consider widen_bswap_or_bitreverse in store-merging decisions and fix up riscv build

On Fri, Jun 05, 2026 at 02:22:25PM +0200, Andreas Schwab wrote:
> This breaks riscv:
>
> ../../gcc/config/riscv/riscv.md:5297:14: error: bswapsi2 cannot FAIL
> ../../gcc/config/riscv/bitmanip.md:543:5: note: in expansion of macro 'FAIL'
>   543 |     FAIL;
>       |     ^~~~

wtw mentioned that on IRC.
In the way IFN_BSWAP/IFN_BITREVERSE are used currently (i.e. only used
for large/huge _BitInt or in the C++ FE, but not making it to expansion)
there is no reason why FAIL wouldn't be allowed (like before my changes),
though I find the riscv hack really ugly.
Instead of adding a workaround, this patch removes the riscv hack and
instead adjusts store-merging pass to take into account
widen_bswap_or_bitreverse; currently it already takes into account
expand_doubleword_bswap_or_bitreverse (on 32-bit word targets which have
bswapsi2 expanders expects __builtin_bswap64 to be cheap).  With this
patch, it expects __builtin_bswap32 to be cheap if bswapdi2 expander
is present, because widen_bswap_or_bitreverse will handle it as
(subreg:SI (lshiftrt:DI (bswap:DI (subreg:DI (arg:SI) 0)) (const_int 32)) low)

2026-06-05  Jakub Jelinek  <jakub@redhat.com>

* gimple-ssa-store-merging.cc (maybe_optimize_vector_constructor):
Also support bswap32 if bswapdi2 expander is present.  Add comment
about bswap64 support on 32-bit targets with bswapsi2 expander.
(pass_optimize_bswap::execute): Likewise.
* config/riscv/bitmanip.md (bswapsi2): Change condition to disable
the expander on TARGET_64BIT without TARGET_XTHEADBB, never FAIL.

Reviewed-by: Richard Sandiford <rdsandiford@googlemail.com>
Reviewed-by: Richard Biener <rguenth@suse.de>
22 hours agoPR target/56102: Improve rtx_costs from -mthumb on ARM.
Roger Sayle [Fri, 5 Jun 2026 13:53:27 +0000 (14:53 +0100)] 
PR target/56102: Improve rtx_costs from -mthumb on ARM.

This patch provides improved (more accurate) RTX costs for -mthumb on ARM.
My recent patch for double word multiplication, PR 122871, revealed that
the current costs for THUMB code on ARM are... let's say a little dubious.

To demonstrate the code generation improvements provided by better
thumb1_rtx_costs consider the function below (from PR middle-end/122871).

long long foo (long long a)
{
  long long c = a << 33;
  c += a;
  return c;
}

With the ARM backend's current costs, this produces 11 instructions with
-O2 -mthumb.

Before: movs    r3, r0
        movs    r2, #0
        adds    r2, r2, r0
        adcs    r3, r3, r1
        adds    r2, r2, r2
        adcs    r3, r3, r3
        subs    r2, r2, r0
        sbcs    r3, r3, r1
        movs    r0, r2
        movs    r1, r3
        bx      lr

With sane RTX costs, GCC now generate the much more reasonable 5 insns:

After:  movs    r2, #0
        lsls    r3, r0, #1
        adds    r0, r0, r2
        adcs    r1, r1, r3
        bx      lr

2026-06-05  Roger Sayle  <roger@nextmovesoftware.com>
    Richard Earnshaw  <richard.earnshaw@arm.com>

gcc/ChangeLog
PR target/56102
PR middle-end/122871
* config/arm/arm.cc (thumb1_rtx_costs): Provide reasonable costs
for PLUS, MINUS, COMPARE, AND, XOR, IOR, NEG, NOT, ASHIFT,
ASHIFTRT and ROTATERT for SImode, DImode, HImode and QImode.
(thumb1_size_rtx_costs): Likewise.

(comp_not_to_clear_mask_str_un): Silence host compiler warning.

23 hours agoaarch64: define duplication into sub-64-bit AdvSIMD vectors [PR125538]
Artemiy Volkov [Thu, 4 Jun 2026 14:47:17 +0000 (14:47 +0000)] 
aarch64: define duplication into sub-64-bit AdvSIMD vectors [PR125538]

This is a second attempt to deal with the ICE reported in PR125538,
triggering when we generate a (vec_duplicate:V4QI (reg:QI)) expression
for which we currently lack RTL support.  More specifically, this occurs
when doing a splat of the most common element in
aarch64_expand_vector_init_fallback () at aarch64.cc:25876.

This is the alternative approach mentioned in the original commit message
at [0], whereby we simply define vec_duplicate patterns for 16-bit and 32-bit
destinations.

Same tests are added as in [0] (a full test reduced in the comments to the
PR, as well as some new vector constructor element combinations in
vec_init_5.c and vec-init-23.c).

Regtested and bootstrapped on aarch64-linux-gnu.

[0] https://gcc.gnu.org/pipermail/gcc-patches/2026-June/719181.html

PR target/125538

gcc/ChangeLog:

* config/aarch64/aarch64-simd.md
(*aarch64_simd_dup_subvector<vcons><mode>): New insn pattern.
(*aarch64_simd_dup_subvectorv2qiqi): Likewise.
* config/aarch64/iterators.md (VSDUP): New mode iterator.
(VCONS): New mode attribute.
(vcons): Likewise.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/sve/vec_init_5.c: Add new 8/16-bit testcases.
* gcc.target/aarch64/vec-init-23.c: Likewise.
* gcc.target/aarch64/pr125538.c: New test.

24 hours agolibstdc++: avoid ill-formed nested generator
Yuao Ma [Fri, 5 Jun 2026 11:50:54 +0000 (19:50 +0800)] 
libstdc++: avoid ill-formed nested generator

This was approved as LWG 4119.

libstdc++-v3/ChangeLog:

* include/std/generator (generator::yield_value): Change the
second template parameter from range_value_t<R> to void.
* testsuite/24_iterators/range_generators/lwg4119.cc: New test.

27 hours agotestsuite: Improve enum argument testing of __builtin_{clz,ctz,clrsb,ffs,parity,popco...
Jakub Jelinek [Fri, 5 Jun 2026 09:01:13 +0000 (11:01 +0200)] 
testsuite: Improve enum argument testing of __builtin_{clz,ctz,clrsb,ffs,parity,popcount,bswap,bitreverse}g

On Wed, Jun 03, 2026 at 06:14:53PM +0000, Joseph Myers wrote:
> The enumerated type error seems to be tested only for C++ (likewise for
> __builtin_bitreverseg).  Presumably it could be tested for C with a cast
> to or variable of enumerated type, or by using an enumeration with fixed
> underlying type.

I've followed what was tested for the other builtins
(clt/ctz/clrsb/ffs/parity/popcount).

So, here is an incremental patch to extend the testing of enumeral
arguments for all those builtins, including enums with fixed underlying
type.

2026-06-05  Jakub Jelinek  <jakub@redhat.com>

* c-c++-common/builtin-bswapg-2.c: Add further enum related tests.
* c-c++-common/builtin-bitreverseg-2.c: Likewise.
* c-c++-common/pr111309-2.c: Likewise.
* c-c++-common/pr111309-3.c: New test.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
27 hours agotree-optimization/125602 - avoid negating the most negative signed value
Richard Biener [Fri, 5 Jun 2026 07:56:09 +0000 (09:56 +0200)] 
tree-optimization/125602 - avoid negating the most negative signed value

The following rewrites another case in niter analysis where we might
end up using fold to negate the most negative signed value and expect
that to be an INTEGER_CST.  Like elsewhere we should swap negation
and conversion to niter_type with the speciality that the affected
path creates an assumption check in the original type.  But for
its construction we can avoid the negation.

PR tree-optimization/125602
* tree-ssa-loop-niter.cc (number_of_iterations_until_wrap):
Avoid double negation for assumption condition.  Compute
negated step in niter_type.

* gcc.dg/torture/pr125602.c: New testcase.

27 hours agobitintlower: Improve __builtin_{clz,ctz,clrsb,ffs,parity,popcount,bswap,bitreverse...
Jakub Jelinek [Fri, 5 Jun 2026 08:42:51 +0000 (10:42 +0200)] 
bitintlower: Improve __builtin_{clz,ctz,clrsb,ffs,parity,popcount,bswap,bitreverse}g lowering

I've noticed that we emit terrible code for the following testcase (all
functions).  We copy the _BitInt values from memory to a temporary and
perform the bit query or bswap/bitreverse operations on the temporary when
it could be done on the value in memory directly, and for bswap/bitreverse
we can also merge it with a following store to (non-bitfield) memory.
The only exception is that we need some temporary for the
x = __builtin_{bswap,bitreverse}g (x);
cases, when they load from the same memory as they store to.  Because the
implementation loops over all the limbs and swaps them, we need one
temporary in that case.  This is similar to e.g. multiplication/division.
The bit-query ifns return a small integer scalar, so they don't need any
merging with a store.

The following patch implements this.

2026-06-05  Jakub Jelinek  <jakub@redhat.com>

* gimple-lower-bitint.cc (bitint_large_huge::lower_bswap_bitreverse):
Add OBJ argument, use it instead of m_vars[part] if non-NULL.  Don't
gsi_remove stmt.
(bitint_large_huge::lower_call): Adjust caller.
(bitint_large_huge::lower_stmt): Handle store of
IFN_BSWAP/IFN_BITREVERSE result.
(stmt_needs_operand_addr): Return true also for
IFN_BSWAP/IFN_BITREVERSE.
(build_bitint_stmt_ssa_conflicts): Formatting fix.
(gimple_lower_bitint): Allow merging IFN_BSWAP/IFN_BITREVERSE with
subsequent non-bitfield store.  Allow merging load of
IFN_{CLZ,CTZ,CLRSB,FFS,PARITY,POPCOUNT,BSWAP,BITREVERSE} argument
with the call.

* gcc.dg/bitint-137.c: New test.

Reviewed-by: Richard Biener <rguenth@suse.de>
27 hours agoc, c++, bitintlower: Add __builtin_{bswap,bitreverse}g type-generic builtins [PR122731]
Jakub Jelinek [Fri, 5 Jun 2026 08:39:55 +0000 (10:39 +0200)] 
c, c++, bitintlower: Add __builtin_{bswap,bitreverse}g type-generic builtins [PR122731]

Clang has added recently type-generic versions of __builtin_bswap{16,32,64}
and __builtin_bitreverse{8,16,32,64} builtins.

The following patch adds them to GCC as well.
Unlike the other __builtin_*g type-generic builtins, these are different in
that the return type is not fixed (usually int or unsigned int), but is the
same as the argument type, so these can't be handled as normal builtins
and are handled in the C and C++ parsers instead.

For consistency with the other __builtin_*g builtins, these only accept
unsigned INTEGER_TYPE (or for C BITINT_TYPE) - users can use various ways
to request unsigned variant of arbitrary types.  For __builtin_bswapg
additionally this requires the type to have precision which is a multiple of
8 (unlike clang, which for some strange reason requires multiple of 16).

2026-06-05  Jakub Jelinek  <jakub@redhat.com>

PR c/122731
gcc/
* doc/extend.texi (__builtin_bswapg, __builtin_bitreverseg): Document.
* internal-fn.def (DEF_INTERNAL_INTSZ_FN): Define.
(DEF_INTERNAL_INTSZ_EXT_FN): Define.
(BSWAP): New internal fn.
(BITREVERSE): Likewise.
* internal-fn.h (expand_BSWAP, expand_BITREVERSE): Declare.
* internal-fn.cc (DEF_INTERNAL_INTSZ_EXT_FN): Define.
(expand_BSWAP, expand_BITREVERSE): New functions.
* builtins.h (fold_build_builtin_bswapg_bitreverseg): Declare.
* builtins.cc (fold_build_builtin_bswapg_bitreverseg): New function.
* wide-int.h (wi::bswap): Fix up docs that only multiple of 8 bits
is required.
* gimple-match-exports.cc (build_call_internal): Handle IFN_BSWAP
and IFN_BITREVERSE.
* gencfn-macros.cc (internal_fn_intsz_names): New variable.
(intsz_suffixes): Likewise.
(suffix_lists): Add intsz_suffixes.
(main): Handle internal_fn_intsz_names.
* match.pd (BSWAP, BITREVERSE): Remove.
(popcount(bswap(x)) is popcount(x)): Use BSWAP BITREVERSE
op lists.
* tree-ssa-phiopt.cc (empty_bb_or_one_feeding_into_p): Use
CASE_CFN_BSWAP and CASE_CFN_BITREVERSE.
(cond_removal_in_builtin_zero_pattern): Likewise.
* fold-const-call.cc (fold_const_call_ss): Likewise.
* fold-const.cc (tree_call_nonnegative_p): Likewise.
* gimple-lower-bitint.cc (struct bitint_large_huge): Declare
lower_bswap_bitreverse method.
(bitint_large_huge::lower_bswap_bitreverse): New method.
(bitint_large_huge::lower_call): Call it.
(build_bitint_stmt_ssa_conflicts): Set muldiv_p for IFN_BSWAP
and IFN_BITREVERSE.
gcc/c-family/
* c-common.h (enum rid): Add RID_BUILTIN_BSWAPG and
RID_BUILTIN_BITREVERSEG.
* c-common.cc (c_common_reswords): Add __builtin_bswapg
and __builtin_bitreverseg.
gcc/c/
* c-parser.cc (c_parser_postfix_expression): Parse
__builtin_bswapg and __builtin_bitreverseg.
gcc/cp/
* parser.cc (cp_parser_postfix_expression): Parse
__builtin_bswapg and __builtin_bitreverseg.
* typeck.cc (build_x_bswapg_bitreverseg): New function.
* cp-tree.h (build_x_bswapg_bitreverseg): Declare.
* pt.cc (tsubst_expr): Handle IFN_BSWAP and IFN_BITREVERSE.
* constexpr.cc (cxx_eval_internal_function): Likewise.
(potential_constant_expression_1): Likewise.
* cp-gimplify.cc (cp_gimplify_expr): Likewise.
gcc/testsuite/
* c-c++-common/builtin-bswapg-1.c: New test.
* c-c++-common/builtin-bswapg-2.c: New test.
* c-c++-common/builtin-bswapg-3.c: New test.
* c-c++-common/builtin-bitreverseg-1.c: New test.
* c-c++-common/builtin-bitreverseg-2.c: New test.

Reviewed-by: Richard Biener <rguenth@suse.de>
Reviewed-by: Joseph Myers <josmyers@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
28 hours agobackprop: Calculate transitive closures of replacements [PR125599]
Richard Sandiford [Fri, 5 Jun 2026 08:18:34 +0000 (09:18 +0100)] 
backprop: Calculate transitive closures of replacements [PR125599]

This PR had the equivalent of:

L1:
  x = PHI(1, z)
  y = -x
  ...
L2:
  z = PHI(x, y)

where z could be simplified to:

  z = PHI(x, x)

i.e. to x.  Changing z triggered a need to replace x with a new SSA name,
but z was left being replaced with x, rather than x's replacement.

Since the replacement values are (of course) restricted to using
dominating definitions, a single RPO pass is enough to calculate the
transitive closure of replacement values.

gcc/
PR tree-optimization/125599
* gimple-ssa-backprop.cc (backprop::execute): Calculate the
transitive closure of replacement values.

gcc/testsuite/
PR tree-optimization/125599
* g++.dg/torture/pr125599.C: New test.

28 hours agoFix EXECUTE_IF_SET_IN_HARD_REG_SET usage in rtl-ssa/insns.cc [PR122992]
Andrew Pinski [Fri, 5 Jun 2026 07:43:28 +0000 (00:43 -0700)] 
Fix EXECUTE_IF_SET_IN_HARD_REG_SET usage in rtl-ssa/insns.cc [PR122992]

r17-1279-gf6103f3a1e42fe had a mistake when converting over to use
EXECUTE_IF_SET_IN_HARD_REG_SET. EXECUTE_IF_SET_IN_HARD_REG_SET does not work
with a temporary as that temporary lifetime will end after the initialization
part of the for loop ends. So the variable becomes garbage or in some cases
GCC will delete the needed stores.
The fix is to create a variable to extend the liftime of that temporary and
pass that to EXECUTE_IF_SET_IN_HARD_REG_SET.

Pushed as obvious after a bootstrap on aarch64-linux-gnu which was failing before.

PR rtl-optimization/125609
PR middle-end/122992
gcc/ChangeLog:

* rtl-ssa/insns.cc (function_info::record_call_clobbers): Use a
variable to store out the result of abi.full_reg_clobbers().

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
29 hours agoada: Robustify error recovery of structural instantiation in generic formal part
Eric Botcazou [Wed, 27 May 2026 11:03:51 +0000 (13:03 +0200)] 
ada: Robustify error recovery of structural instantiation in generic formal part

The previous attempt didn't address the root cause of the cascading errors,
so this rewinds it and starts from scratch.

gcc/ada/ChangeLog:

* sem_ch3.adb (Analyze_Private_Extension_Declaration): Revert latest
change.
(Find_Type_Of_Subtype_Indic): Return Any_Type if Find_Type fails to
resolve the type.
* sem_ch12.adb (Analyze_Formal_Derived_Type): Restore more specific
error recovery path.

29 hours agoada: Fix extra formal mismatch
Ronan Desplanques [Wed, 27 May 2026 05:04:03 +0000 (07:04 +0200)] 
ada: Fix extra formal mismatch

This fixes the criterion that determines whether to add finalization
collection extra formals to BIP functions.

gcc/ada/ChangeLog:

* exp_ch6.adb (Needs_BIP_Collection): Fix condition.

29 hours agoada: Change Constraint_Error into Data_Error in Text_IO to respect ARM
Mathias Aparicio [Mon, 18 May 2026 12:48:48 +0000 (14:48 +0200)] 
ada: Change Constraint_Error into Data_Error in Text_IO to respect ARM

Before the patch, Get_Upper_Half_Char_Immed and Get_Upper_Half_Char would
both raise a Constraint_Error when the input exceeded a bound. However,
ARM A.13 (13) states that the procedure Get should propagate the
Data_Error exception if the input value does not belong to the range of
the required subtype.

Now propagate Data_Error.

gcc/ada/ChangeLog:

* libgnat/a-textio.adb
(Get_Upper_Half_Char, Get_Upper_Half_Char_Immed): Replace
Constraint_Error with Data_Error

29 hours agoada: Avoid suspicious index warnings in expanded code
Viljar Indus [Mon, 25 May 2026 11:29:56 +0000 (14:29 +0300)] 
ada: Avoid suspicious index warnings in expanded code

Some expansions and optimizations wrap the existing code in
functions that loose the range constraints of the original
variable. We should avoid triggering bogus errors in such scenarios.

gcc/ada/ChangeLog:

* sem_warn.adb (Warn_On_Suspicious_Index): Only check elements
that are coming from source.

29 hours agoada: Reject structural instantiation in generic formal part
Eric Botcazou [Mon, 25 May 2026 20:40:20 +0000 (22:40 +0200)] 
ada: Reject structural instantiation in generic formal part

The structural instance would amount to a formal package in this context,
and that's totally unsupported by the current implementation.

gcc/ada/ChangeLog:

* sem_ch3.adb (Analyze_Private_Extension_Declaration): Be prepared
for Find_Type_Of_Subtype_Indic returning no type.
* sem_ch4.adb (Process_Generic_Instantiation): Give an error if the
generic instantation is referenced in a generic formal part.
* sem_ch12.adb (Analyze_Formal_Derived_Type): Return early in every
case of serious errors.

29 hours agoRISC-V: Specify cmodel in OPTION_DEFAULT_SPECS
Kito Cheng [Thu, 4 Jun 2026 14:49:37 +0000 (22:49 +0800)] 
RISC-V: Specify cmodel in OPTION_DEFAULT_SPECS

We have supported --with-cmodel for a while and set the default via
TARGET_DEFAULT_CMODEL.  That works well in general, but not for
multilib, because GCC cannot detect the cmodel for the current multilib
correctly that way.  So we still need to specify the default cmodel in
OPTION_DEFAULT_SPECS.

gcc/ChangeLog:

* config/riscv/riscv.h (OPTION_DEFAULT_SPECS): Specify default
cmodel.

37 hours agofortran: ICE in DO CONCURRENT with DEFAULT(NONE) inside ASSOCIATE
Jerry DeLisle [Thu, 28 May 2026 04:00:19 +0000 (21:00 -0700)] 
fortran: ICE in DO CONCURRENT with DEFAULT(NONE) inside ASSOCIATE

Two bugs in check_default_none_expr caused a segfault when a DO CONCURRENT
with inline type-spec iterators (e.g. "integer :: i = 1:10") contained an
ASSOCIATE construct.

Bug 1: sym->ns->code was used to locate the ext.concur.forall_iterator
list.  When a symbol's namespace is an ASSOCIATE body, sym->ns->code is an
EXEC_BLOCK node, not the DO CONCURRENT node; reading ext.concur from it
interprets the wrong union member and yields a garbage pointer.  Fix: use
d->code instead, the DO CONCURRENT gfc_code node passed through the walker's
data parameter, which is always the correct node.

Bug 2: inline type-spec iterators are shadow iterators, stored internally
with a leading underscore prepended to the name.  The comparison of the
iterator's symtree name against the user-visible sym->name must skip that
underscore by advancing iter_name one character when iter->shadow is set.

PR fortran/125529

Assisted by: Claude Sonnet 4.6

gcc/fortran/ChangeLog:

PR fortran/125529
* resolve.cc (check_default_none_expr): Use d->code instead of
sym->ns->code to locate the DO CONCURRENT forall_iterator list,
avoiding a wrong-union-member read when the symbol's namespace is
an ASSOCIATE body.  Skip leading underscore when comparing iterator
names for shadow iterators.

gcc/testsuite/ChangeLog:

PR fortran/125529
* gfortran.dg/do_concurrent_assoc_default_none.f90: New test.

(cherry picked from commit afe36f5576f07a5650ed8e2d9ade58d2e7e27021)

37 hours agofortran: ICE or wrong-code for ASSOCIATE selector that is a type-bound user-defined...
Jerry DeLisle [Wed, 27 May 2026 22:10:07 +0000 (15:10 -0700)] 
fortran: ICE or wrong-code for ASSOCIATE selector that is a type-bound user-defined operator

Three related bugs prevented ASSOCIATE selectors that are type-bound
user-defined operator expressions from compiling correctly.

Bug 1 (class.cc): find_typebound_proc_uop returned NULL immediately when
the derived type has no f2k_derived namespace, bypassing the parent-type
inheritance walk.  This caused inherited UDOs to be silently not found.
Fix: set root = NULL and let the loop reach the parent type instead.

Bug 2 (resolve.cc): resolve_typebound_procedures called resolve_symbol on
the parent type only after an early return that fires when the derived type
has no direct type-bound bindings.  This left parent-type bindings
unresolved when searched via gfc_find_typebound_user_op.
Fix: move resolve_symbol(super_type) before the early return.

Bug 3 (match.cc): match_association_list did not handle ASSOCIATE selectors
of the form .uop. expr or the nested case .uop2. (.uop1. expr).  When the
selector's type was BT_UNKNOWN at parse time the name of the associate
variable was left untyped, producing a "Syntax error in expression" ICE in
the body of the ASSOCIATE construct.
Fix: add three helpers before match_association_list:
  - resolve_assoc_operand: attempts gfc_resolve_expr on EXPR_FUNCTION
    operands and falls back to gfc_find_dt_in_generic for constructor calls
    whose argument types are not yet known.
  - infer_typebound_uop_type: reads the return type of a type-bound UDO
    directly from specific_st->n.tb->u.specific->n.sym without calling
    gfc_resolve_symbol, avoiding a resolve_symbol_called race condition.
  - extend_assoc_op: walks the expression tree bottom-up, propagating
    types through INTRINSIC_PARENTHESES wrappers before calling the two
    helpers above on each INTRINSIC_USER node.
When the selector is an INTRINSIC_USER EXPR_OP with BT_UNKNOWN type,
call extend_assoc_op on the operands, then gfc_extend_expr (errors
suppressed).  Accept the result when gfc_extend_expr returns MATCH_YES or
when it returns MATCH_ERROR but has already converted the node to
EXPR_COMPCALL with a known type (the full resolution pass finishes it).

Assisted by: Claude Sonnet 4.6

PR fortran/125528

gcc/fortran/ChangeLog:

PR fortran/125528
* class.cc (find_typebound_proc_uop): Set root = NULL instead of
returning NULL when derived type lacks f2k_derived, so parent-type
type-bound procedures and operators are still found via inheritance.
* match.cc (resolve_assoc_operand): New helper.
(infer_typebound_uop_type): New helper.
(extend_assoc_op): New helper.
(match_association_list): Handle ASSOCIATE selectors that are
type-bound user-defined operator expressions, including nested cases.
* resolve.cc (resolve_typebound_procedures): Move resolve_symbol
call for the parent type before the early return so inherited
type-bound bindings are resolved even when the child type has none
of its own.

gcc/testsuite/ChangeLog:

PR fortran/125528
* gfortran.dg/associate_80.f90: New test.

37 hours agocobol: Regenerate gcc/cobol/lang.opt.urls
Xavier Del Campo Romero [Thu, 4 Jun 2026 20:08:23 +0000 (22:08 +0200)] 
cobol: Regenerate gcc/cobol/lang.opt.urls

This had been missed by the following commit:

commit d70dbee952cd6aa956190e2993e14dd3b712efd3
Author: Xavier Del Campo Romero <xdelcampo@symas.com>
Date:   Thu Jun 4 16:05:42 2026 +0200

    cobol: Move copybook path searches to cobol1

gcc/cobol/ChangeLog:

* lang.opt.urls: Regenerate

38 hours agoc++: CWG 1704, type checking in explicit inst of var tmpl [PR125575]
Marek Polacek [Wed, 3 Jun 2026 19:01:33 +0000 (15:01 -0400)] 
c++: CWG 1704, type checking in explicit inst of var tmpl [PR125575]

While working on something else I noticed that we compile

  template<typename T>
  constexpr int vt = 42;
  template float vt<int>;

but we shouldn't due to the float/int mismatch.  Andrew found
98524 which is the same problem.  This turned out to be CWG 1704.

For explicit specialization of functions, determine_specialization
already performs the checking; see the various same_type_p, compparms,
comp_template_parms etc. checks.  Except I do believe it doesn't check
exception specification as it should:

  template<typename T> void (fn)(T) {}
  template void (fn<int>)(int) noexcept; // ill-formed, we accept

The fix should be rather easy.

PR c++/125575
PR c++/98524

gcc/cp/ChangeLog:

* pt.cc (check_explicit_inst_of_var_template): New.
(check_explicit_specialization): Use it.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/var-templ90.C: New test.
* g++.dg/cpp1y/var-templ91.C: New test.
* g++.dg/cpp1y/var-templ92.C: New test.
* g++.dg/cpp1y/var-templ93.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
39 hours agoc: wrong code generated with counted_by on pointer + ubsan [PR125072]
Martin Uecker [Thu, 4 Jun 2026 17:19:33 +0000 (19:19 +0200)] 
c: wrong code generated with counted_by on pointer + ubsan [PR125072]

When a pointer is accessed with a constant offset, this has to be split into
the size of the element type and the index to be able to instrument the
index.   The code failed to re-apply the element size after this.

PR c/125072

gcc/c-family/ChangeLog:
* c-ubsan.cc (get_index_from_offset,get_index_from_pointer_addr_expr,
is_instrumentable_pointer_array_address): Return factor.
(ubsan_maybe_instrument_array_ref): Apply factor.

gcc/testsuite/ChangeLog:
* gcc.dg/pr125072.c: New test.
* gcc.dg/ubsan/pointer-counted-by-bounds-124230-union.c: Avoid heap
corruption.
* gcc.dg/ubsan/pointer-counted-by-bounds-124230.c: Likewise.

39 hours agoc: harmonize handling of arrays
Martin Uecker [Wed, 3 Jun 2026 15:57:30 +0000 (17:57 +0200)] 
c: harmonize handling of arrays

This code harmonizes the handling of arrays in C by consistently
using build_index_type instead of build_range_type when creating
arrays and using top_array_vla_p to detect top-level VLAs.

gcc/c-family/ChangeLog:
* c-common.cc (complete_array_type): Use build_index_type.
* c-ubsan.cc (ubsan_instrument_bounds_pointer_address): Likewise.

gcc/c/ChangeLog:
* c-decl.cc (grokdeclarator): Likewise.
* c-typeck.cc (c_verify_type,c_build_array_type,
c_expr_countof_expr,comptypes_internal): Use top_array_vla_p.
(top_array_vla_p): Rename to use _p convention and simplify.

41 hours agoFortran: fix stack-buffer-overflow passing type to assumed-rank class [PR60576]
Jerry DeLisle [Thu, 4 Jun 2026 19:11:37 +0000 (12:11 -0700)] 
Fortran: fix stack-buffer-overflow passing type to assumed-rank class [PR60576]

Two code paths copied a full GFC_MAX_DIMENSIONS dim[] array from a
descriptor that physically holds only dtype.rank dimensions, triggering
a stack-buffer-overflow detected by AddressSanitizer.

Case 1 - assumed-rank type(T) dummy passed to class(T) assumed-rank:
The caller only allocates storage for dtype.rank dimensions.  The code
generated a static GFC_MAX_DIMENSIONS struct copy of the dim[] array,
reading past the physical end of the descriptor.  Fix by checking
expr->rank == -1 and replacing the static copy with a runtime-sized
__builtin_memcpy of dtype.rank * sizeof(descriptor_dimension) bytes.

Case 2 - fixed-rank type(T) actual passed directly to class(T) assumed-rank:
gfortran uses a rank-specific descriptor type for fixed-rank type arrays
(dim[rank] rather than dim[GFC_MAX_DIMENSIONS]).  The class assumed-rank
formal's descriptor has dim_t[GFC_MAX_DIMENSIONS].  The call to
gfc_class_array_data_assign with lhs_type=true keyed the ARRAY_RANGE_REF
off TREE_TYPE(lhs_dim) = dim_t[GFC_MAX_DIMENSIONS], reading 15*24 = 360
bytes from a descriptor that physically has only rank*24 bytes for the
dim[] array.  Fix by checking CLASS_DATA(fsym)->as->rank == -1 and
passing lhs_type=false so the ARRAY_RANGE_REF is sized by
TREE_TYPE(rhs_dim) = dim_t[rank], copying only the physically present
entries.  Fixed-rank class formals retain lhs_type=true.

Assisted by: Claude Sonnet 4.6

PR fortran/60576

gcc/fortran/ChangeLog:

PR fortran/60576
* trans-array.cc (gfc_conv_array_parameter): For an assumed-rank
actual argument passed to a CLASS assumed-rank formal, use a
runtime-sized memcpy for the dim[] entries instead of a full
GFC_MAX_DIMENSIONS static copy.  For a fixed-rank actual to a
CLASS assumed-rank formal, pass lhs_type=false to
gfc_class_array_data_assign so the dim[] copy is sized by the
RHS descriptor type (dim_t[rank]).  Fixed-rank class formals
retain lhs_type=true.
* trans-expr.cc (gfc_conv_derived_to_class): For an assumed-rank
actual, use a runtime-sized memcpy for the derived_array descriptor
dim[] copy instead of a full GFC_MAX_DIMENSIONS static copy.

gcc/testsuite/ChangeLog:

PR fortran/60576
* gfortran.dg/asan/assumed_rank_26.f90: New test covering both
assumed-rank and fixed-rank type actuals passed to a CLASS
assumed-rank dummy.

41 hours agocobol: Bring TRIM into accordance with the COBOL specification.
Robert Dubner [Thu, 4 Jun 2026 17:53:14 +0000 (13:53 -0400)] 
cobol: Bring TRIM into accordance with the COBOL specification.

The COBOL TRIM function can take optional additional characters to be
trimmed off the ends of a string, rather than just the default, which
trims away spaces.  These changes implement that functionality.

gcc/cobol/ChangeLog:

* genapi.cc (handle_gg_trim): Provide an array of characters to the
library function.
(parser_trim): New function that handles the optional trim chars.
(parser_intrinsic_call_2): Remove __gg__handling from this routine.
* genapi.h (parser_trim): New declaration.
* parse.y: Calls parser_trim() with the list of trim chars.

libgcobol/ChangeLog:

* intrinsic.cc (__gg__formatted_date): Formatting change.
(change_case): Likewise.
(__gg__trim): Rename as __gg__trim_1.
(__gg__trim_1): Reworked to handle an array of single-byte chars.
(__gg__trim_a): Reworked to handle an array of multi-byte chars.
(iscasematch): Formatting change.

gcc/testsuite/ChangeLog:

* cobol.dg/group2/FUNCTION_TRIM_with_extra_characters.cob: New test.
* cobol.dg/group2/FUNCTION_TRIM_with_extra_characters.out: New test.

44 hours agobitmap: Speed up bitmap_list_view
Richard Sandiford [Thu, 4 Jun 2026 15:40:45 +0000 (16:40 +0100)] 
bitmap: Speed up bitmap_list_view

For tree views, bitmap_clear essentially does:

- a conversion to a list view
- a list clear operation
- a (trivial) conversion back to a tree view

We can do that directly without the need for splay operations.

Doing that removes the only case where bitmap_elt_clear_from is called
for a tree view.  The function can therefore assert for a list view.

That in turn means that bitmap_list_view can inline
bitmap_tree_listify_from without having to handle a partial conversion.

The main optimisation here comes from avoiding the sorted_elements
array by building the list as we go.

We can also avoid the stack array by using the prev fields as a list
link.  Avoiding the stack array might not always be a win, since the
bitmap elements are less compact and because cache locality for the
stack should be good while it remains locally allocated.  My reasoning
was:

(1) The cache lines containing the stack prev fields are going to be
    written to when adding the elements to the list.

(2) If the tree is balanced, it's relatively unlikely that those cache
    lines would be evicted between the two updates.

(3) If the tree isn't well balanced and has a long left spine, we'd
    end up allocating heap memory for the vector, which would add
    a new set of overheads.

I'd be happy to switch back to a vector stack if that turns out
to be better after all.

It's possible to write this version of the algorithm in loop form,
but I thought the structure in the patch was easier to follow.

This gives a reproducible 20% improvement in an artificial test that
converts a tree containing 2,000,000 pseudo-random elements (keeping
the same sequence for all tests).  This testing also ensured that
the resulting list view was correct.

gcc/
* bitmap.cc (bitmap_elt_clear_from): Make static.  Require a
list view.
(bitmap_tree_listify_from): Delete.
(bitmap_list_view): Rewrite to avoid separate vectors.
(bitmap_clear): Switch to a list view before calling
bitmap_elt_clear_from and restore the original view afterwards.

44 hours agobitmap: Tweak bitmap_tree_unlink_element
Richard Sandiford [Thu, 4 Jun 2026 15:40:45 +0000 (16:40 +0100)] 
bitmap: Tweak bitmap_tree_unlink_element

bitmap_tree_unlink_element can avoid a splay operation if the maximal
node is at the root.

gcc/
* bitmap.cc (bitmap_tree_unlink_element): Optimize the handling
of the maximal node.

44 hours agobitmap: Avoid amortised O(E) behaviour for tree first/last bit
Richard Sandiford [Thu, 4 Jun 2026 15:40:44 +0000 (16:40 +0100)] 
bitmap: Avoid amortised O(E) behaviour for tree first/last bit

The comments in bitmap.h say that bitmap_first_set_bit and
bitmap_last_set_bit are amortised O(logE) and worst-case O(E).
But the implementation just does a simple pointer chase,
without any splaying.  This can be amortised O(E) if, for example,
code sets bits in ascending order and then repeatedly tests for
the first bit.  Nothing would then move the root away from the
last element or begin to balance the tree.

gcc/
* bitmap.cc: Include pretty-print.h and splay-tree-utils.h.
(bitmap_splay_tree_accessors): New class.
(bitmap_splay_tree): New type.
(bitmap_first_set_bit_worker): Use bitmap_splay_tree::min_node
for tree views.
(bitmap_last_set_bit_worker): Use bitmap_splay_tree::max_node
for tree views.

44 hours agobitmap: Speed up bitmap_tree_link_element
Richard Sandiford [Thu, 4 Jun 2026 15:40:44 +0000 (16:40 +0100)] 
bitmap: Speed up bitmap_tree_link_element

bitmap_tree_link_element first splays the tree to ensure that the
root is a neighbour of the element that we want to insert.  But the
callers have already done the same kind of splay operation in order
to prove that no existing element has the required index.

Repeating the operation isn't free.  For example, if the first splay
operation leaves the left neighbour N in the root, the second splay
operation would need to search N->right->left (N->next->prev),
and similarly in reverse for a right neighbour.

This gives a reproducible 20% improvement in an artificial test that
inserted 2,000,000 pseudo-random elements (keeping the same sequence
for all tests).

gcc/
* bitmap.cc (bitmap_tree_link_element): Require callers to have
done a splay operation.  Avoid doing another one here.

45 hours agocobol: Move copybook path searches to cobol1
Xavier Del Campo Romero [Thu, 4 Jun 2026 14:05:42 +0000 (16:05 +0200)] 
cobol: Move copybook path searches to cobol1

Previously, this task was performed by the gcobol driver. However, prior
art from the Modula-2 front-end showed this was performed by the
compiler instead.

Now, and similarly to Modula-2, cobol1 will honor -B, as well as
-idirafter. While the %I spec is also honored, it will not be as useful
because -B options would only be expanded to -isystem by %I if the
"include/" and "include-fixed/" directories exist wherever -B points at.
However, system copybooks are currently installed on:

- $(libsubdir)/compat/gnu/cpy
- $(libsubdir)/posix/cpy

Thus following again Modula-2's example.

TODO: Some of the -i* options, such as -imultilib, are not supported
yet. Reportedly, only -I, -isystem and -idirafter are supported.

gcc/cobol/ChangeLog:

* Make-lang.in: Make $(libsubdir) available to cobol1.o.
* cobol1.cc (struct GTY): Add dir_separator.
(libcompat_copybook): New function.
(libposix_copybook): New function.
(append_copybook_prefix): New function.
(cobol_langhook_handle_option): New function.
(cobol_langhook_post_options): New function.
(LANG_HOOKS_POST_OPTIONS): New function.
* gcobolspec.cc (lang_specific_driver): Remove path searches.
* lang-specs.h: Honor %{B*} and %I.
* lang.opt: Support -B and -idirafter.

libgcobol/ChangeLog:

* Makefile.am: Install posix copybooks to build tree.
* Makefile.in: Likewise.

gcc/testsuite/ChangeLog:

* cobol.dg/group2/cbltypes.cpy: Removed.

45 hours agoRISC-V: Support multilib with extra options
Kito Cheng [Wed, 3 Jun 2026 08:14:18 +0000 (16:14 +0800)] 
RISC-V: Support multilib with extra options

The syntax of multilib-generator was defined as below:

```
<primary arch>-<abi>-<additional arches>-<extensions>
```

And now extend with one more optional argument:

```
<primary arch>-<abi>-<additional arches>-<extensions>[-<extra-options>]
```

Detail syntax of `<extra-option>`:
```
<extra-options> := <extra-option> ',' <extra-options>
                 | <extra-option>

<extra-option> := <option> '/' <multi-lib-folder>
```

NOTE: Dash ('-') in the option name must replace with underline ('_'),
      and leading dash should skip, e.g. `-fcf-protection=full` become
      `fcf_protection=full`.

e.g.

rv64imafdc_zicfiss_zicfilp-lp64d---fcf_protection=full/cfi

It will build a multilib with
`-march=rv64imafdc_zicfiss_zicfilp -mabi=lp64d -fcf-protection=full`

And will use `rv64imafdc_zicfiss_zicfilp/lp64d/cfi` as multilib folder.

gcc/ChangeLog:

* config/riscv/multilib-generator: Support extra options in the
multilib config string.
* doc/install.texi (--with-multilib-generator): Document the extra
options syntax.

45 hours agoRISC-V: Sync extension of canonical order with spec
Kito Cheng [Wed, 3 Jun 2026 07:01:19 +0000 (15:01 +0800)] 
RISC-V: Sync extension of canonical order with spec

The canonical order has been adjusted a little bit [1-2].  Fortunately, the
affected extensions haven't been ratified yet, so there's no real impact.
Although P doesn't have an upstream yet, to avoid forgetting to update the
canonical order in the future, I've decided to update it now while I still
remember it.

[1] https://github.com/riscv/riscv-isa-manual/pull/2903
[2] https://github.com/riscv/riscv-isa-manual/pull/2910

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc (riscv_supported_std_ext):
Move 'v' before 'p' and drop 'n' to match the spec.
* config/riscv/arch-canonicalize (CANONICAL_ORDER): Ditto.

46 hours agoFortran: fix always_explicit not copied by gfc_copy_attr [PR121204]
Paul Thomas [Thu, 4 Jun 2026 10:55:50 +0000 (11:55 +0100)] 
Fortran: fix always_explicit not copied by gfc_copy_attr [PR121204]

gfc_copy_attr omitted the always_explicit attribute, so when
gfc_copy_dummy_sym created a fresh copy of a dummy procedure symbol in
a submodule module procedure (gfc_match_submod_proc), the flag was
silently lost.  At translation time nodesc_arg was set true for calls
through that dummy procedure, causing array constructors to be passed
as raw data pointers instead of array descriptors.  Callers with
assumed-shape dummy arguments then read garbage bounds.

2026-06-04  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/121204
* symbol.cc (gfc_copy_attr): Copy the always_explicit attribute.

gcc/testsuite
PR fortran/121204
* gfortran.dg/submodule_38.f90: New test.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
46 hours agoFortran: ICE with pointer result from submodule function [PR93424]
Paul Thomas [Thu, 4 Jun 2026 12:24:05 +0000 (13:24 +0100)] 
Fortran: ICE with pointer result from submodule function [PR93424]

The declaration at line 41 of the testcase produced:
   42 |     class(c), pointer :: bp
      |     1
Error: Unclassifiable statement at (1)
Followed by either an ICE (gcc-13 and gcc-17) or
"(null):0: confused by earlier errors, bailing out"
for the other active branches.

It is the error that is key, the aftermath is a distraction especially
in examining the entrails for clues.

The fix recognises 'bp', in the offending line, to be the implicit
result of the module procedure, redeclared in the submodule contained
function. MATCH_YES is emitted and the potential new symbol is not
commited by jumping straight to cleanup.

2026-06-04  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/93424
* decl.cc (variable_decl): Do not commit the symbol if it is
the implicit result of a module procedure being declared in a
function, used in a submodule.

gcc/testsuite/
PR fortran/93424
* gfortran.dg/submodule_37.f90: New test.

47 hours ago[V2][PR target/125387][RISC-V] Properly cost mulh for RISC-V
Raphael Zinsly [Thu, 4 Jun 2026 13:08:08 +0000 (07:08 -0600)] 
[V2][PR target/125387][RISC-V] Properly cost mulh for RISC-V

Bah.  Sent the wrong version.  The integer multiply cost in the tuning
structure already has COSTS_N_INSNS applied, so no need to apply it again
(which causes the costs to skyrocket and the code generation we want to see not
happen).

--

This is a patch Raphael wrote a few years back, but which never got upstreamed.
I can vaguely recall evaluating the patch and concluding to drop it both
internally and from the queue of things to upstream.  But the details of how I
reached that conclusion are lost.

The core problem is we didn't recognize the fairly complex widening multiply
RTL, so it got costed by recursion which is painful on its own.  To add insult
to injury the input operands are TI mode which, IIRC, also increased the cost
of the mulh insn.

The net was a totally bogus cost, it was totally off the charts which in turn
discouraged using multiplies for division-by-constant operations as can be seen
in the BZ.

This patch from Raphael fixes recognition of the mulh RTL and uses the integer
multiply cost out of the costing structure.  This results in sensible costs for
the multiply and using a multiply-by-reciprocal instead of division in more
cases.

It's been tested on riscv32-elf and riscv64-elf without regressions.  I haven't
bootstrapped it as I had my system disabled yesterday for "reasons".  I'll
obviously wait for the pre-commit verdict.

PR target/125387
gcc/
* config/riscv/riscv.cc (riscv_rtx_costs): Recognize and properly cost
mulh instructions.

gcc/testsuite
* gcc.target/riscv/pr125387.c: New test.

Co-authored-by: Jeff Law <jeffrey.law@oss.qualcomm.com>
47 hours agolibstdc++: Remove trailing whitespace in debug/safe_iterator.h
Jonathan Wakely [Thu, 4 Jun 2026 12:54:02 +0000 (13:54 +0100)] 
libstdc++: Remove trailing whitespace in debug/safe_iterator.h

libstdc++-v3/ChangeLog:

* include/debug/safe_iterator.h: Remove trailing whitespace.

2 days agotestsuite: Add PowerPC future hardware compiler support checks
Jeevitha [Thu, 4 Jun 2026 10:11:35 +0000 (05:11 -0500)] 
testsuite: Add PowerPC future hardware compiler support checks

Add new effective-target procs to help write tests for future powerpc.
"check_effective_target_powerpc_future_compile_ok" checks whether the
compiler recognizes -mcpu=future (i.e., defines _ARCH_FUTURE).
"check_effective_target_powerpc_future_assemble_ok" checks whether the
assembler supports "powerpc future" instructions under -mcpu=future.
"check_powerpc_future_hw_available" checks at runtime whether the
hardware supports executing "powerpc future" instructions.

2026-06-04  Jeevitha Palanisamy  <jeevitha@linux.ibm.com>

gcc/testsuite/
* lib/target-supports.exp
(check_effective_target_powerpc_future_compile_ok): New target support
procedure.
(check_effective_target_powerpc_future_assemble_ok): Likewise.
(check_powerpc_future_hw_available): Likewise.
(is-effective-target): Register powerpc_future_hw.
(is-effective-target-keyword): Likewise.

2 days agoi386: Enable fusion and SSE reduction tunings for znver6
vekumar [Tue, 2 Jun 2026 11:04:10 +0000 (16:34 +0530)] 
i386: Enable fusion and SSE reduction tunings for znver6

gcc/ChangeLog:

* config/i386/x86-tune.def (X86_TUNE_FUSE_ALU_AND_BRANCH_MEM): Enable
for m_ZNVER6.
(X86_TUNE_FUSE_ALU_AND_BRANCH_MEM_IMM): Likewise.
(X86_TUNE_SSE_REDUCTION_PREFER_PSHUF): Likewise.

2 days agoada: Remove conversion to an if-statement
Viljar Indus [Wed, 6 May 2026 10:05:22 +0000 (13:05 +0300)] 
ada: Remove conversion to an if-statement

There is no need to convert the ignored pragmas into if-statements
with a statically false condition and a null body since the
ignored ghost node removal should take care of this removal
from now on.

This simplifies the detection of those ignored pragmas and
makes the code more easily identifiable and common with ignored
ghost code that should behave similarly to ignored asseritons.

gcc/ada/ChangeLog:

* expander.adb: Handle pragma statements in the expander.
* sem_ch6.adb (Check_Statement_Sequence): Handle cases where
an ignored assertion pragma is at the end of a function body
that is known to trigger an assertion.
* sem_prag.adb (Analyze_Pragma): Remove the if-statement
creation for ignored pragmas. Relocate checks for assertion
pragma conditions that were performed on these transformed
if-statements here.
* sem_res.adb (Resolve_Short_Circuit): Remove the code for
ignored assertion pragmas.
* sem_util.adb (Original_Aspect_Pragma_Name): use the identifier
name for pragma Check only when it did not come from source.
* tbuild.adb (Make_Implicit_Loop_Statement): Adjust the code
for ignored Check pragmas.

2 days agoada: Remove unnecessary workaround
Viljar Indus [Thu, 16 Apr 2026 11:02:30 +0000 (14:02 +0300)] 
ada: Remove unnecessary workaround

Technically this is no longer necessary as everything will be
removed along with the ignored ghost code removal.

gcc/ada/ChangeLog:

* sem_prag.adb (Analyze_Pragma): Remove overflow supression
workaround.

2 days agoada: Apply ignored ghost regions for ignored pragmas
Viljar Indus [Wed, 15 Apr 2026 12:55:33 +0000 (15:55 +0300)] 
ada: Apply ignored ghost regions for ignored pragmas

gcc/ada/ChangeLog:

* ghost.adb (Set_Ghost_Mode): Create ignored ghost regions
for ignored pragamas.
* sem_prag.adb (Analyze_Pragma): Mark ignored pragmas checks as
ignored ghost pragmas.

2 days agoada: Fix finalize address for arrays of protected types
Artur Pietrek [Thu, 21 May 2026 13:29:10 +0000 (15:29 +0200)] 
ada: Fix finalize address for arrays of protected types

Make_Address_For_Finalize emits a -Descriptor_Size shift whenever
the array's first subtype is unconstrained, but does not check whether
the object has a controlled component. For arrays of protected types
Has_Controlled_Component is False so no dope vector is allocated, but
at scope exit the incorrect finalize address is dereferenced, which
may lead to EXCEPTION_ACCESS_VIOLATION, or silent error.

gcc/ada/ChangeLog:

* exp_ch7.adb (Make_Address_For_Finalize): check
Has_Controlled_Component predicate before emitting the shift to be
consistant with what Is_Constr_Array_Subt_With_Bounds says.

2 days agoada: Fix again internal error on abstract primitive with access result
Eric Botcazou [Wed, 20 May 2026 17:19:42 +0000 (19:19 +0200)] 
ada: Fix again internal error on abstract primitive with access result

The previous fix was papering over the root cause, which is that the itype
built for the anonymous access result type of a derived subprogram is given
the subprogram itself as Scope, instead of the scope of the subprogram. The
incorrect code also temporarily sets the Scope of the subprogram to itself!

gcc/ada/ChangeLog:

* accessibility.adb (Type_Access_Level): Revert ealier change.
* sem_ch3.adb (Derive_Subprogram.Replace_Type): Set the Scope of
the new anonymous access type to the scope of the derived type.
Do not (temporarily) sets the Scope of the subprogram to itself.

2 days agoada: Reuse Is_Rewrite_Substitution where possible
Piotr Trojanek [Mon, 18 May 2026 18:19:07 +0000 (20:19 +0200)] 
ada: Reuse Is_Rewrite_Substitution where possible

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* errout.adb, exp_util.adb, sem_case.adb, sem_ch4.adb, sem_res.adb:
Replace low-lever inequality with a high-level routine.

2 days agoada: Check intrinsic subprograms specified by an aspect
Piotr Trojanek [Wed, 20 May 2026 14:53:34 +0000 (16:53 +0200)] 
ada: Check intrinsic subprograms specified by an aspect

We only checked intrinsic subprograms specified by pragmas that come from
source, but this missed subprograms specified by an aspect (because its
internally generated corresponding pragma doesn't come from source).

gcc/ada/ChangeLog:

* sem_intr.adb (Check_Intrinsic_Subprogram): Recognize pragmas that
do not come from source because they come from aspect specification.

2 days agoada: Remove unused global variable
Ronan Desplanques [Tue, 19 May 2026 15:21:41 +0000 (17:21 +0200)] 
ada: Remove unused global variable

This variable was used for the "Community" variant of GNAT Pro. That's
gone now, so remove the variable.

gcc/ada/ChangeLog:

* opt.ads (Latest_Ada_Only): Remove.
* par-prag.adb (Prag): Adapt to removal.
* sem_prag.adb (Analyze_Pragma): Likewise.
* switch-c.adb (Scan_Front_End_Switches): Likewise.
* usage.adb (Usage): Likewise.

2 days agoada: Rename Apply_Accessibility_Check_For_Parameter
Eric Botcazou [Mon, 18 May 2026 23:16:03 +0000 (01:16 +0200)] 
ada: Rename Apply_Accessibility_Check_For_Parameter

The routine is also used for Ada 2012's stand-alone objects of an anonymous
access type, that is to say not only for access parameters. It is invoked on
an explicit or implicit conversion of the object to another access type.

gcc/ada/ChangeLog:

* accessibility.ads (Apply_Accessibility_Check_For_Parameter):
Rename to...
(Apply_Accessibility_Check_For_Conversion): ...this.
* accessibility.adb (Apply_Accessibility_Check_For_Parameter):
Rename to...
(Apply_Accessibility_Check_For_Conversion): ...this.
* exp_attr.adb (Expand_N_Attribute_Reference) <Attribute_Access>:
Adjust to above renaming.
* exp_ch4.adb (Expand_N_Type_Conversion): Likewise.
* exp_ch6.adb (Expand_Actuals): Likewise.

2 days agoada: Set Is_Local_Anonymous_Access on the anonymous access type of return objects
Eric Botcazou [Mon, 18 May 2026 22:54:00 +0000 (00:54 +0200)] 
ada: Set Is_Local_Anonymous_Access on the anonymous access type of return objects

It is already set on the anonymous access type of function results and will
prevent return objects from being treated as Ada 2012's stand-alone objects,
thus make it easier to enforce the RM 3.10.2(13.2) rule.

gcc/ada/ChangeLog:

* einfo.ads (Is_Local_Anonymous_Access): Mention return objects.
* accessibility.adb (Type_Access_Level): Call Enclosing_Subprogram.
* sem_ch3.adb (Find_Type_Of_Object): Set Is_Local_Anonymous_Access
on the anonymous access type of return objects.

2 days agoada: Null pointer dereference in Adjust for bounded indefinite holders.
Steve Baird [Mon, 18 May 2026 21:55:38 +0000 (14:55 -0700)] 
ada: Null pointer dereference in Adjust for bounded indefinite holders.

In the Adjust procedure for Ada.Containers.Bounded_Indefinite_Holders.Holder,
check to see whether the holder is empty before trying to copy its
(possibly nonexistent) element value.

gcc/ada/ChangeLog:

* libgnat/a-cbinho.adb (Adjust): Avoid null pointer dereference.

2 days agoada: Fix missing error for too deep accessibility level in aggregate return
Eric Botcazou [Wed, 13 May 2026 07:46:31 +0000 (09:46 +0200)] 
ada: Fix missing error for too deep accessibility level in aggregate return

The issue occurs when an access discriminant in an aggregate return is set
to a value obtained by means of a function call written in prefixed form.

The change also adjusts the implementation of the RM 6.5(5.9) rule, which
was hijacking the machinery of dynamic accessibility checks for a static
accessibility check, thus incorrectly flagging stand-alone objects of an
anonymous access type in Ada 2012 and later, per the RM 3.10.2(19.2) rule.

It also merges the implementations of the RM 3.10.2(28) rule for named and
anonymous access types in a single block of code.

gcc/ada/ChangeLog:

* einfo.ads (Is_Local_Anonymous_Access): Mention access results.
* accessibility.adb (Accessibility_Level): Add missing guard on
the entity for error cases.  In the component cases, retrieve the
function call if the prefix is a captured function call.  Remove
the bypass returning the library level in a return context if the
prefix is a function call.  Call Function_Call_Or_Allocator_Level
in this case when the level of the prefix is tied to that of the
result of the enclosing function.
(Check_Return_Construct_Accessibility): Change the implementation
to do a bona-fide static accessibility check.
* sem_attr.adb (Resolve_Attribute) <Attribute_Access>: Merge the
implementations of the RM 3.10.2(28) rule for named and anonymous
access types.
* sem_ch6.adb (Analyze_Expression_Function): Set the Ekind of the
entity created for the body very early.
* sem_util.adb (In_Return_Value): Fix typo in comment.

2 days agoada: Fix ICE on static predicate when all case alternatives are False
Mathias Aparicio [Mon, 4 May 2026 08:45:50 +0000 (10:45 +0200)] 
ada: Fix ICE on static predicate when all case alternatives are False

Before this patch, creating a pragma predicate with the static keyword
whose body included a case-expression where every alternative was
statically evaluated to false leads to an ICE.

When the case expression had all alternatives resolved to False,
Build_Discrete_Static_Predicate.Get_Rlist returned an Empty list and
later in the code Next was called on the Empty List.

Now return false_range in this case.

gcc/ada/ChangeLog:

* sem_ch13.adb (Build_Discrete_Static_Predicate.Get_RList): If
case expression alternatives are False return False_Range.

2 days agoada: Get rid of Effective_Extra_Accessibility function
Eric Botcazou [Sat, 16 May 2026 16:58:41 +0000 (18:58 +0200)] 
ada: Get rid of Effective_Extra_Accessibility function

The computation of accessibility levels does not consistently look through
object renamings when extra accessibility objects are used.  This attempts
to address the issue by making Extra_Accessibility do it automatically.

gcc/ada/ChangeLog:

* einfo.ads (Extra_Accessibility): Rename to...
(Extra_Accessibility_Of_Object): ...this and adjust description.
* gen_il-fields.ads (Opt_Field_Enum): Replace Extra_Accessibility
with Extra_Accessibility_Of_Object.
* gen_il-gen-gen_entities.adb (Constant_Or_Variable_Kind): Ditto.
(Formal_Kind): Ditto.
* accessibility.ads (Effective_Extra_Accessibility): Rename to...
(Extra_Accessibility): ...this.
* accessibility.adb (Apply_Accessibility_Check_For_Parameter): Do
not manually look through renamings and adjust.
(Effective_Extra_Accessibility): Rename to...
(Extra_Accessibility): ...this and add guard.
* exp_ch3.adb (Expand_N_Object_Declaration): Adjust.
* exp_ch4.adb (Expand_N_Type_Conversion): Likewise.
* exp_ch5.adb (Expand_N_Assignment_Statement): Likewise.
* exp_ch6.adb (Expand_Actuals): Likewise.
* sem_ch3.adb (Derive_Subprogram): Likewise.
* sem_ch6.adb (Create_Extra_Formals): Likewise.

2 days agoada: Disable a couple of static accessibility checks in dynamic cases
Eric Botcazou [Sat, 16 May 2026 12:09:54 +0000 (14:09 +0200)] 
ada: Disable a couple of static accessibility checks in dynamic cases

In accordance with the RM 3.10.2(19,19.1,19.2) rules.

gcc/ada/ChangeLog:

* exp_ch4.adb (Expand_Allocator_Expression): In the case of access
discriminants, pass Zero_On_Dynamic_Level to compute the static
accessibility level of the expression.
* sem_res.adb (Check_Aliased_Parameter): Pass Zero_On_Dynamic_Level
to compute the static accessibility level of actual parameters.

2 days agoada: Fix small inaccuracy in Function_Call_Or_Allocator_Level
Eric Botcazou [Sat, 16 May 2026 11:35:22 +0000 (13:35 +0200)] 
ada: Fix small inaccuracy in Function_Call_Or_Allocator_Level

In the case of an object declaration, the function returns the depth of the
enclosing static scope, instead of that of the enclosing dynamic scope like
its parent function Accessibility_Level.

The change contains a couple of cleanups in the expander, which resort to
calling Accessibility_Level in more cases instead of doing manual work.

gcc/ada/ChangeLog:

* accessibility.ads (Accessibility_Level_Kind): Tweak description.
* accessibility.adb (Function_Call_Or_Allocator_Level): Recurse on
the defining identifier for an N_Object_Declaration node.
(Accessibility_Level): Minor tweaks.
* exp_ch3.adb (Expand_N_Object_Declaration): Do not special case
function calls in the computation of accessibility levels.
* exp_ch5.adb (Expand_N_Assignment_Statement): Do not manually
compute the accessibility level of the LHS.

2 days agoada: Inline for proof without creating extra objects
Piotr Trojanek [Wed, 13 May 2026 14:56:03 +0000 (16:56 +0200)] 
ada: Inline for proof without creating extra objects

When inlining subprogram calls in GNATprove mode, we were creating object
declarations only to force checks that would be otherwise missed with object
renamings. Now ghat GNATprove emits those checks for object renamings anyway
(as required by Ada 2022), we no longer need those extra objects.

gcc/ada/ChangeLog:

* inline.adb (Establish_Actual_Mapping_For_Inlined_Call): Do not create
object declarations when actual is captured in an object renaming.

2 days agoada: Simplify code with membership test
Piotr Trojanek [Sun, 17 May 2026 18:54:01 +0000 (20:54 +0200)] 
ada: Simplify code with membership test

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* sem_aux.adb (Is_Definite_Subtype): Only call Ekind if necessary.

2 days agoada: Simplify code with membership test
Piotr Trojanek [Mon, 24 Jun 2024 09:34:15 +0000 (11:34 +0200)] 
ada: Simplify code with membership test

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* sem_ch13.adb (Rep_Item_Too_Late): Simplify with membership test.

2 days agoada: Tune layout in membership test
Piotr Trojanek [Fri, 21 Jun 2024 15:22:28 +0000 (17:22 +0200)] 
ada: Tune layout in membership test

Whitespace cleanup.

gcc/ada/ChangeLog:

* freeze.adb, sem_ch13.adb: Tune whitespace.

2 days agoada: Reuse Boolean_Literals in rewriting of accessibility checks
Piotr Trojanek [Tue, 25 Mar 2025 12:34:11 +0000 (13:34 +0100)] 
ada: Reuse Boolean_Literals in rewriting of accessibility checks

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_ch4.adb (Expand_N_In): Rewrite with True/False entity array.

2 days agoada: Remove redundant guard against empty list of declarations
Piotr Trojanek [Thu, 20 Mar 2025 18:35:55 +0000 (19:35 +0100)] 
ada: Remove redundant guard against empty list of declarations

Code cleanup; when First is called on No_List, it intentionally returns Empty.

gcc/ada/ChangeLog:

* exp_ch9.adb (Scan_Declarations): Remove redundant guard.

2 days agoada: Enforce comment with assertions
Piotr Trojanek [Sun, 17 May 2026 11:42:14 +0000 (13:42 +0200)] 
ada: Enforce comment with assertions

Code cleanup.

gcc/ada/ChangeLog:

* exp_util.adb (Full_Qualified_Name_String): Add assertions; fix style.

2 days agoada: Simplify construction of internal string from characters
Piotr Trojanek [Sun, 17 May 2026 11:39:12 +0000 (13:39 +0200)] 
ada: Simplify construction of internal string from characters

Reuse a variant of Store_String_Char routine that accepts a Character parameter
and internally calls Get_Char_Code. Code cleanup.

gcc/ada/ChangeLog:

* exp_attr.adb (Expand_N_Attribute_Reference): Store chars without
converting the actual parameters.
* exp_ch11.adb (Null_String): Likewise.
* exp_disp.adb (Make_DT): Likewise.
* exp_util.adb (Fully_Qualified_Name_String): Likewise.
* sem_attr.adb (Analyze_Attribute): Likewise.
* sem_dist.adb (Full_Qualified_Name): Likewise.
* sem_prag.adb (Process_Interface_Name, Set_Encoded_Interface_Name):
Likewise.
* stringt.adb (Store_String_Chars): Likewise.

2 days agoada: Fix unbalanced parens in comment
Piotr Trojanek [Thu, 26 Dec 2024 12:41:26 +0000 (13:41 +0100)] 
ada: Fix unbalanced parens in comment

Code cleanup.

gcc/ada/ChangeLog:

* sem_ch9.adb (Analyze_Requeue): Fix unbalanced parens.

2 days agoada: Use collective entity kinds for access-to-subprogram types
Piotr Trojanek [Fri, 25 Apr 2025 14:28:33 +0000 (16:28 +0200)] 
ada: Use collective entity kinds for access-to-subprogram types

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_ch4.adb, sem_attr.adb, sem_ch3.adb: Use Access_Protected_Kind
and Access_Subprogram_Kind where possible.

2 days agoada: Move gnatmake-specific logic from libgnat to gnatmake
Piotr Trojanek [Tue, 14 Apr 2026 10:18:09 +0000 (12:18 +0200)] 
ada: Move gnatmake-specific logic from libgnat to gnatmake

We had a complicated, ancient workaround for gnatmake that simply hardcoded
library names to "libXXX.a".

Note: if we ever wanted to make this platform-specific, it should probably use
__gnat_object_library_extension, which is currently used by gnatlink, but is
equal to "libXXX.a" on every platform except for VMS, which is unsupported.

gcc/ada/ChangeLog:

* adaint.c (__gnat_library_template): Move logic to gnatmake.
* make.adb (Get_Library_File): Use simple single template.

2 days agoada: Guard agains empty switches in GNAT.Command_Line.Getopt
Viljar Indus [Thu, 14 May 2026 12:05:21 +0000 (15:05 +0300)] 
ada: Guard agains empty switches in GNAT.Command_Line.Getopt

Checks for the first character in Switches being an '*'
did not include guards against an empty string in all locations.

gcc/ada/ChangeLog:

* libgnat/g-comlin.adb (Getopt): Check if Switches
are empty before looking at the first element.

2 days agoada: Fix missing error for too deep access result in generic function
Eric Botcazou [Thu, 14 May 2026 09:43:21 +0000 (11:43 +0200)] 
ada: Fix missing error for too deep access result in generic function

The problem is that, unlike in the nongeneric case, the analysis of the
access result definition in the generic function specification does not
cause Is_Local_Anonymous_Access to be set on the anonymous access type
created for the result.

The fix exposes a loophole in the calculation of the accessibility level
for formal objects of generic subprograms, as well as two illegal cases
in the GNAT.CPP_Exceptions unit of the run-time library.

gcc/ada/ChangeLog:

* accessibility.ads: Alphabetize declarations.
(Subprogram_Access_Level): Beef up description.
* accessibility.adb (Accessibility_Level): Deal with formal objects
of generic subprograms.
* sem_ch12.adb (Analyze_Generic_Subprogram_Declaration): Set the
Is_Local_Anonymous_Access flag on the access result type, if any.
* libgnat/g-cppexc.ads (Get_Access_To_Tagged_Object): Do not declare
the formal type parameter as abstract.
* libgnat/g-cppexc.adb (Get_Access_To_Object): Fix illegal code.
(Get_Access_To_Tagged_Object): Likewise.

2 days agoada: Attribute reference in subunit causes compiler Assertion_Error
Steve Baird [Wed, 13 May 2026 22:56:17 +0000 (15:56 -0700)] 
ada: Attribute reference in subunit causes compiler Assertion_Error

In the case of a separate subunit subprogram body, do not take a path that
is intended for the case where there is no enclosing declaration list.
The subunit's stub has an enclosing declaration list.

gcc/ada/ChangeLog:

* exp_attr.adb (Build_And_Insert_Type_Attr_Subp): Test for subunit case before
concluding that a subprogram body has no enclosing declaration list.

2 days agoada: GNATprove inlining/unrolling messages now controlled by two Booleans
Johannes Kanig [Wed, 29 Apr 2026 08:33:13 +0000 (08:33 +0000)] 
ada: GNATprove inlining/unrolling messages now controlled by two Booleans

The GNATprove-related messages for inlining and unrolling are now
controlled by two package-level Booleans instead of a Debug flag.

gcc/ada/ChangeLog:

* inline.ads: Introduce two new Boolean flags
* inline.adb (Cannot_Inline): Modify the negative message into
a warning, and use new flag
* sem_res.adb (Resolve_Call): Use new flag to guard issue of msg
* debug.adb: Debug flag now unused for GNATprove

2 days agoada: Fix file access time information in __gnat_copy_attribs
Tonu Naks [Fri, 8 May 2026 08:08:31 +0000 (08:08 +0000)] 
ada: Fix file access time information in __gnat_copy_attribs

gcc/ada/ChangeLog:

* adaint.c (__gnat_copy_attribs): Fix call to SetFileTime

2 days agoada: Remove forced inlining of generics for configurable run times
Viljar Indus [Mon, 11 May 2026 08:44:11 +0000 (11:44 +0300)] 
ada: Remove forced inlining of generics for configurable run times

This section of code date backs to the time when the frontend
was handling pragma Inline_Always. Technically this is no longer needed.

gcc/ada/ChangeLog:

* sem_ch12.adb (Analyze_Package_Instantiation): Remove
forced inlining in configurable run times.

2 days agoada: Minor cosmetic refactoring
Marc Poulhiès [Thu, 23 Apr 2026 09:27:58 +0000 (11:27 +0200)] 
ada: Minor cosmetic refactoring

Rewrite the sequence of:
 if V = Enum_1
   or else V = Enum_2
   or else V in Enum_R
   ...

with a membership test.

gcc/ada/ChangeLog:

* sem_util.adb (Enclosing_Declaration): Refactor membership test.

2 days agoada: Lift restriction on Valid_Scalars attribute for private tagged types
Eric Botcazou [Sat, 9 May 2026 13:50:14 +0000 (15:50 +0200)] 
ada: Lift restriction on Valid_Scalars attribute for private tagged types

This just generalizes a trick already used for discriminant checks.

gcc/ada/ChangeLog:

* doc/gnat_rm/implementation_defined_attributes.rst (Valid_Scalars):
Remove reference to private tagged types.
* exp_attr.adb  (Expand_N_Attribute_Reference) <Valid_Scalars>: Do
not bail out for private tagged types.
* sem_attr.adb (Analyze_Attribute) <Valid_Scalars>: Do not warn for
for private tagged types.
* sem_ch3.adb (Is_Visible_Component): Accept any component reference
whose prefix is a type conversion that does not come from source.
* gnat_rm.texi: Regenerate.

2 days agoada: Fix ICE on Case_Expression a Pragma_Predicate
Mathias Aparicio [Mon, 27 Apr 2026 08:53:07 +0000 (10:53 +0200)] 
ada: Fix ICE on Case_Expression a Pragma_Predicate

Before this patch, Case_Expression inside a Pragma_Predicate with a
non-static alternative (like a function call) led the Case_Expression
Node to survive unexpanded and caused gnat_to_gnu to abort
(gcc_unreachable for N_Case_Expression).

The guard in Expand_N_Case_Expression checking for non-static
Predicate_Aspect used Has_Dynamic_Predicate_Aspect, which was false
even with a function call in a Case_Expression alternative.

Now add Is_Predicate_Static to the check, which fixes the bug.
This function was private to the sem_ch13 package, so it was made public.

gcc/ada/ChangeLog:

* sem_ch13.ads (Is_Predicate_Static): Public declaration,
from the private function in the package body
* sem_ch13.adb (Is_Predicate_Static): Remove the now-redundant
local declaration
* exp_ch4.adb (Expand_N_Case_Expression): Add Is_Predicate_Static
to the static guard

2 days agoada: Fix directories being identified as executables on Windows
Mathias Aparicio [Thu, 9 Apr 2026 09:55:37 +0000 (11:55 +0200)] 
ada: Fix directories being identified as executables on Windows

On Windows the `__gnat_is_executable_file_attr` checks if a file
is executable but does not check if it is a regular file or a directory.

This may lead to the execution of a directory which will make the program
crash. This patch fixes the issue by checking if the file is regular
before checking if it is executable.

gcc/ada/ChangeLog:

* adaint.c (__gnat_is_executable_file_attr): Initialize
attr->regular using __gnat_is_regular_file_attr. Directly return
0 before checking if executable if the attr->regular is 0.
Remove the now unnecessary check for invalid_file_attributes.

2 days agoada: Update the documentation of Iterable in the GNAT RM
Claire Dross [Tue, 5 May 2026 13:11:35 +0000 (15:11 +0200)] 
ada: Update the documentation of Iterable in the GNAT RM

It now takes into account the possibility to add a Constant_Reference function
instead of an Element function.

gcc/ada/ChangeLog:

* doc/gnat_rm/implementation_defined_aspects.rst (Aspect Iterable):
A Constant_Reference function can be supplied instead of an Element
function.
* gnat_rm.texi: Regenerate.

2 days agoada: Small preliminary cleanup in Sem_Ch3.Is_Visible_Component
Eric Botcazou [Sat, 9 May 2026 09:06:52 +0000 (11:06 +0200)] 
ada: Small preliminary cleanup in Sem_Ch3.Is_Visible_Component

There should be no functional changes.

gcc/ada/ChangeLog:

* sem_ch3.adb (Is_Visible_Component): Fold Is_Local_Type predicate,
reason only on type entities, and tidy up specific processing added
for ACATS B730006 test.

2 days agoada: Improve layout of TSD (Type Specific Data) record for tagged types
Eric Botcazou [Thu, 7 May 2026 11:40:11 +0000 (13:40 +0200)] 
ada: Improve layout of TSD (Type Specific Data) record for tagged types

Compiling Ada.Tags with -gnatRh shows unused bits in the Type_Specific_Data
record type for 64-bit targets.  This saves one 64-bit word in it for them.

gcc/ada/ChangeLog:

* libgnat/a-tags.ads (Type_Specific_Data): Move Boolean components
to right after Natural components and put Is_Abstract last.
* exp_disp.adb (Make_DT): Adjust to above reordering.

2 days agoada: Fix checking context of Initialized attribute
Viljar Indus [Thu, 7 May 2026 11:40:50 +0000 (14:40 +0300)] 
ada: Fix checking context of Initialized attribute

The initialized attribute is a special attribute that can only
be used in places where ghost code can be used.

However in those cases we have no ghost entity to check. Add
guards for this situation inside Check_Ghost_Context.Is_OK_Statement.

gcc/ada/ChangeLog:

* ghost.adb (Is_OK_Statement): Avoid checking for policies and
levels when checking the context of the Initialized attribute.

2 days agoada: Basic support for a new SPARK attribute At
Piotr Trojanek [Thu, 7 May 2026 14:37:01 +0000 (16:37 +0200)] 
ada: Basic support for a new SPARK attribute At

For now, only basic legality checks are present. Expansion is not ready yet.
This should be enough to start implementing the backend support in GNATprove.

gcc/ada/ChangeLog:

* exp_attr.adb (Expand_N_Attribute_Reference): Do not expand new
attribute.
* par-ch4.adb (Scan_Apostrophe): Parse 'At as an attribute reference;
otherwise, it would be parsed as a keyword.
* sem_attr.adb (Analyze_Attribute): Basic checks for new attribute.
(Eval_Attribute): New attribute will never be evaluated.
* snames.ads-tmpl: (Preset Names): "at" is now also an attribute, not
just a keyword.
(Attribute_Id): New attribute identifier.

2 days agoada: Fix bogus validity check failure for FP component of array with reverse SSO
Eric Botcazou [Wed, 6 May 2026 08:44:28 +0000 (10:44 +0200)] 
ada: Fix bogus validity check failure for FP component of array with reverse SSO

It comes from a thinko in Sem_Util.In_Reverse_Storage_Order_Object: only the
innermost enclosing composite type needs to be considered by the predicate.

gcc/ada/ChangeLog:

* sem_util.ads (In_Reverse_Storage_Order_Object): Adjust.
* sem_util.adb (In_Reverse_Storage_Order_Object): Rewrite.

2 days agoada: Complete removal of obsolete project manager sources
Piotr Trojanek [Tue, 14 Apr 2026 10:49:49 +0000 (12:49 +0200)] 
ada: Complete removal of obsolete project manager sources

Remove a leftover from a no-longer-existing project manager.

gcc/ada/ChangeLog:

* adaint.c (__gnat_prj_add_obj_files): Remove; files that referenced
this variable were removed years ago.

2 days agoada: Improve error message for premature record freezing
Mathias Aparicio [Wed, 1 Apr 2026 13:25:14 +0000 (15:25 +0200)] 
ada: Improve error message for premature record freezing

When a record is frozen it must be completely defined. This requires that
all of its components' types must also be completely defined
ARM 3.11.1 (8).

Before this patch, if a record was frozen while one of its components
was of a private type, the compiler complained that the record had a
private component, although privacy was not the root issue.

Now, the compiler states the actual problem directly: the type is not
completely defined.

gcc/ada/ChangeLog:

* freeze.adb (Check_And_Freeze_Type): Emit a more precise error
message when a component's frozen record is incompletely defined
instead of printing private component error.
* sem_util.ads (Incompletely_Defined): New function that
traverses recursively a type and returns the first incompletely
defined component or itself if it is incompletely defined.
* sem_util.adb (Incompletely_Defined): Likewise.
(Is_Incompletely_Defined): Refactor to a test of the new
Incompletely_Defined function for equality with Empty.

2 days agoada: Fix fallout of latest change to Valid_Scalars attribute
Eric Botcazou [Wed, 6 May 2026 16:52:59 +0000 (18:52 +0200)] 
ada: Fix fallout of latest change to Valid_Scalars attribute

The attribute does not work for all private tagged types, but this was not
detected in the case where the full view alone is tagged.

gcc/ada/ChangeLog:

PR ada/124923
* exp_attr.adb  (Expand_N_Attribute_Reference) <Valid_Scalars>: Also
bail out for a private type whose full view alone is tagged.
* sem_attr.adb (Analyze_Attribute) <Valid_Scalars>: Also warn for a
private type whose only full view alone is tagged.

2 days agoada: Avoid use-before-definition within library unit subprograms.
Steve Baird [Fri, 1 May 2026 20:06:52 +0000 (13:06 -0700)] 
ada: Avoid use-before-definition within library unit subprograms.

When the compiler builds a subprogram for an attribute (either Put_Image
or one of the streaming attributes), it needs to be inserted at a place
in the tree where all callers can refer to it.
In some cases involving library unit subprograms, that insertion point was
chosen incorrectly. Gigi would then fail an assertion while processing
a call to a procedure that had not yet been declared.

gcc/ada/ChangeLog:

* exp_attr.adb
(Expand_N_Attribute_Reference.Build_And_Insert_Type_Attr_Subp):
handle the case of a library unit subprogram body; do not assume
that every subprogram body has an enclosing declaration list.