]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
3 weeks agoada: Fix section of Finalizable extension in GNAT RM
Ronan Desplanques [Fri, 30 May 2025 09:50:09 +0000 (11:50 +0200)] 
ada: Fix section of Finalizable extension in GNAT RM

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

gcc/ada/ChangeLog:

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

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

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

gcc/ada/ChangeLog:

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

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

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

gcc/ada/ChangeLog:

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

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

gcc/ada/ChangeLog:

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

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

gcc/ada/ChangeLog:

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

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

gcc/ada/ChangeLog:

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

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

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

gcc/ada/ChangeLog:

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

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

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

gcc/ada/ChangeLog:

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

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

gcc/ada/ChangeLog:

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

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

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

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

gcc/ada/ChangeLog:

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

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

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

gcc/ada/ChangeLog:

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

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

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

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

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

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

Add support for some recent AVR devices.

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

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

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

gcc/

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

gcc/testsuite/

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

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

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

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

And the splitter ends up emitting

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

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

PR target/121906

gcc/

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

gcc/testsuite/

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

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

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

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

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

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

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

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

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

gcc/testsuite/ChangeLog:

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

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

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

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

gcc/fortran/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

This adds permute_info_type and removes the duplication from
vect_schedule_slp_node.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

PR libstdc++/121917

libstdc++-v3/ChangeLog:

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

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

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

-- >8 --

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

gcc/ChangeLog:

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

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

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

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

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

gcc/testsuite/ChangeLog:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

libstdc++-v3/ChangeLog:

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

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

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

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

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

libstdc++-v3/ChangeLog:

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

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

This tentatively applies the same tweak to twin testcases.

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

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

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

PR c++/121795

gcc/cp/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

PR target/120378

gcc/testsuite/ChangeLog:

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

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

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

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

Where sizeof(UT) < sizeof(T)

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

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

After this patch:

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

gcc/ChangeLog:

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

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

After

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

    c: Update TLS model after processing a TLS variable

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

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

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

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

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

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

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

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

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

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

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 weeks agotestsuite: fix typo in name of plugin test file
David Malcolm [Fri, 12 Sep 2025 14:24:35 +0000 (10:24 -0400)] 
testsuite: fix typo in name of plugin test file

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/crash-test-write-though-null-sarif.c: Rename to...
* gcc.dg/plugin/crash-test-write-through-null-sarif.c: ...this.
* gcc.dg/plugin/crash-test-write-though-null-stderr.c: Rename to...
* gcc.dg/plugin/crash-test-write-through-null-stderr.c: ...this.
* gcc.dg/plugin/plugin.exp: Update for above renamings.  Sort the
test files for crash_test_plugin.cc alphabetically.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 weeks ago[RISC-V] Adjust ABI specification in recently added Andes tests
Jeff Law [Fri, 12 Sep 2025 13:17:56 +0000 (07:17 -0600)] 
[RISC-V] Adjust ABI specification in recently added Andes tests

Another lp64 vs lp64d issue.  This time adjusting a #include in the test isn't
sufficient.  So instead this sets the ABI to lp64d instead of lp64.  I don't
think that'll impact the test materially.

Tested on the BPI and Pioneer systems where it fixes the failures with the
Andes tests.  Pushing to the trunk.

gcc/testsuite
* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vd4dots.c:
Adjust ABI specification.
* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vd4dotsu.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vd4dotu.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vfncvtbf16s.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vfpmadb.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vfpmadt.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vfwcvtsbf16.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vln8.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vd4dots.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vd4dotsu.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vd4dotu.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vfncvtbf16s.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vfpmadb.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vfpmadt.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vfwcvtsbf16.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vln8.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vd4dots.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vd4dotsu.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vd4dotu.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vfncvtbf16s.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vfpmadb.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vfpmadt.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vfwcvtsbf16.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vln8.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vd4dots.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vd4dotsu.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vd4dotu.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vfncvtbf16s.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vfpmadb.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vfpmadt.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vfwcvtsbf16.c:
Likewise.
* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vln8.c:
Likewise.

3 weeks agolibstdc++: Fix memory leak in PSTL TBB backend [PR117276]
Jonathan Wakely [Fri, 12 Sep 2025 11:49:39 +0000 (12:49 +0100)] 
libstdc++: Fix memory leak in PSTL TBB backend [PR117276]

Backport of upstream patch:
https://github.com/uxlfoundation/oneDPL/pull/1589

libstdc++-v3/ChangeLog:

PR libstdc++/117276
* include/pstl/parallel_backend_tbb.h (__func_task::finalize):
Make deallocation unconditional.

3 weeks agolibstdc++: Constrain __gnu_debug::bitset(const CharT*) constructor [PR121046]
Jonathan Wakely [Sat, 12 Jul 2025 12:09:03 +0000 (13:09 +0100)] 
libstdc++: Constrain __gnu_debug::bitset(const CharT*) constructor [PR121046]

The r16-3435-gbbc0e70b610f19 change (for LWG 4294) needs to be applied
to the debug mode __gnu_debug::bitset as well as the normal one.

libstdc++-v3/ChangeLog:

PR libstdc++/121046
* include/debug/bitset (bitset(const CharT*, ...)): Add
constraints on CharT type.

3 weeks agoc++/modules: Fix missed unwrapping of STAT_HACK in ADL [PR121893]
Nathaniel Shead [Fri, 12 Sep 2025 12:50:39 +0000 (22:50 +1000)] 
c++/modules: Fix missed unwrapping of STAT_HACK in ADL [PR121893]

My r16-3559-gc2e567a6edb563 reworked ADL for modules, including a change
to allow seeing module-linkage declarations if they only exist on the
instantiation path.  This caused a crash however as I neglected to
unwrap the stat hack wrapper when we were happy to see all declarations,
allowing search_adl to add non-functions to the overload set.

PR c++/121893

gcc/cp/ChangeLog:

* name-lookup.cc (name_lookup::adl_namespace_fns): Unwrap the
STAT_HACK also when on_inst_path.

gcc/testsuite/ChangeLog:

* g++.dg/modules/adl-10_a.C: New test.
* g++.dg/modules/adl-10_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
3 weeks agoipa-free-lang-data: Don't walk into DECL_CHAIN when finding decls/types [PR121865]
Nathaniel Shead [Wed, 10 Sep 2025 04:25:22 +0000 (14:25 +1000)] 
ipa-free-lang-data: Don't walk into DECL_CHAIN when finding decls/types [PR121865]

On a DECL, TREE_CHAIN will find any other declarations in the same
binding level.  This caused an ICE in PR121865 because the next entity
in the binding level was the uninstantiated unique friend 'foo', for
which after being found the compiler tries to generate a mangled name
for it and crashes.

This didn't happen in non-modules testcases only because normally the
unique friend function would have been chained after its template_decl,
and find_decl_types_r bails on lang-specific nodes so it never saw the
uninstantiated decl.  With modules however the order of chaining
changed, causing the error.

I don't think it's ever necessary to walk into the DECL_CHAIN, from what
I can see; other cases where it might be useful (block vars or type
fields) are already handled explicitly elsewhere, and only one test
fails because of the change, due to accidentally relying on this "walk
into the next in-scope declaration" behaviour.

PR c++/121865

gcc/ChangeLog:

* ipa-free-lang-data.cc (find_decls_types_r): Don't walk into
DECL_CHAIN for any DECL.

gcc/testsuite/ChangeLog:

* g++.dg/lto/pr101396_0.C: Ensure A will be walked into (and
isn't constant-folded out of the GIMPLE for the function).
* g++.dg/lto/pr101396_1.C: Add message.
* g++.dg/modules/lto-4_a.C: New test.
* g++.dg/modules/lto-4_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Richard Biener <rguenther@suse.de>
3 weeks agolibstdc++: Fix bootstrap failure in atomicity.cc
Jonathan Wakely [Fri, 12 Sep 2025 10:33:20 +0000 (11:33 +0100)] 
libstdc++: Fix bootstrap failure in atomicity.cc

My r16-3810-g6456da6bab8a2c changes broke bootstrap for targets that use
the mutex-based atomic helpers. This fixes it by casting away the
unnecessary volatile-qualification on the _Atomic_word* before passing
it to __exchange_and_add_single.

libstdc++-v3/ChangeLog:

* config/cpu/generic/atomicity_mutex/atomicity.h
(__exchange_and_add): Use const_cast to remove volatile.

3 weeks agoMinor tweaks to ipa-pure-const.cc
Eric Botcazou [Fri, 12 Sep 2025 09:30:22 +0000 (11:30 +0200)] 
Minor tweaks to ipa-pure-const.cc

gcc/
* ipa-pure-const.cc (check_stmt): Minor formatting tweaks.
(pass_data_nothrow): Fix pasto in description.

3 weeks agomiddle-end: Use addhn for compression instead of inclusive OR when reducing compariso...
Tamar Christina [Fri, 12 Sep 2025 07:30:55 +0000 (08:30 +0100)] 
middle-end: Use addhn for compression instead of inclusive OR when reducing comparison values

Given a sequence such as

int foo ()
{
#pragma GCC unroll 4
  for (int i = 0; i < N; i++)
    if (a[i] == 124)
      return 1;

  return 0;
}

where a[i] is long long, we will unroll the loop and use an OR reduction for
early break on Adv. SIMD.  Afterwards the sequence is followed by a compression
sequence to compress the 128-bit vectors into 64-bits for use by the branch.

However if we have support for add halving and narrowing then we can instead of
using an OR, use an ADDHN which will do the combining and narrowing.

Note that for now I only do the last OR, however if we have more than one level
of unrolling we could technically chain them.  I will revisit this in another
up coming early break series, however an unroll of 2 is fairly common.

gcc/ChangeLog:

* internal-fn.def (VEC_TRUNC_ADD_HIGH): New.
* doc/generic.texi: Document it.
* optabs.def (vec_trunc_add_high): New.
* doc/md.texi: Document it.
* tree-vect-stmts.cc (vectorizable_early_exit): Use addhn if supported.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/vect-early-break-addhn_1.c: New test.
* gcc.target/aarch64/vect-early-break-addhn_2.c: New test.
* gcc.target/aarch64/vect-early-break-addhn_3.c: New test.
* gcc.target/aarch64/vect-early-break-addhn_4.c: New test.

3 weeks agoAarch64: Add support for addhn vectorizer optabs for Adv.SIMD
Tamar Christina [Fri, 12 Sep 2025 07:29:46 +0000 (08:29 +0100)] 
Aarch64: Add support for addhn vectorizer optabs for Adv.SIMD

This implements the new vector optabs vec_<su>addh_narrow<mode>
adding support for in-vectorizer use for early break.

gcc/ChangeLog:

* config/aarch64/aarch64-simd.md (vec_addh_narrow<mode>): New.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/vect-addhn_1.c: New test.

3 weeks agomiddle-end: clear the user unroll flag if the cost model has overriden it
Tamar Christina [Fri, 12 Sep 2025 07:28:44 +0000 (08:28 +0100)] 
middle-end: clear the user unroll flag if the cost model has overriden it

If the user has requested loop unrolling through pragma GCC unroll then at the
moment we only set LOOP_VINFO_USER_UNROLL if the vectorizer has not overrode the
unroll factor (through backend costing) or if the VF made the requested unroll
factor be 1.

When we have a loop of say int and a pragma unroll 4

If the vectorizer picks V4SI as the mode, the requested unroll ended up exactly
matching the VF. As such the requested unroll is 1 and we don't clear the pragma.

So it did honor the requested unroll factor. However since we didn't set the
unroll amount back and left it at 4 the rtl unroller won't use the rtl cost
model at all and just unroll the vector loop 4 times.

But of these events are costing related, and so it stands to reason that we
should set LOOP_VINFO_USER_UNROLL to we return the RTL unroller to use the
backend costing for any further unrolling.

gcc/ChangeLog:

* tree-vect-loop.cc (vect_analyze_loop_1): If the unroll pragma was set
mark it as handled.
* doc/extend.texi (pragma GCC unroll): Update documentation.

3 weeks agoDaily bump.
GCC Administrator [Fri, 12 Sep 2025 00:20:54 +0000 (00:20 +0000)] 
Daily bump.

3 weeks agodoc: Correct the return type of float comparison
Trevor Gross [Thu, 11 Sep 2025 20:50:04 +0000 (20:50 +0000)] 
doc: Correct the return type of float comparison

Documentation for `__cmpsf2` and similar functions currently indicate a
return type of `int`. This is not correct however; the `libgcc`
functions return `CMPtype`, the size of which is determined by the
`libgcc_cmp_return` mode.

Update documentation to use `CMPtype` and indicate that this is
target-dependent, also mentioning the usual modes.

Reported-by: beetrees <b@beetr.ee>
Fixes: https://github.com/rust-lang/compiler-builtins/issues/919#issuecomment-2905347318
Signed-off-by: Trevor Gross <tmgross@umich.edu>
* doc/libgcc.texi (Comparison functions): Document functions as
returning CMPtype.

3 weeks agoFortran: fix assignment to allocatable scalar polymorphic component [PR121616]
Harald Anlauf [Thu, 11 Sep 2025 18:17:31 +0000 (20:17 +0200)] 
Fortran: fix assignment to allocatable scalar polymorphic component [PR121616]

PR fortran/121616

gcc/fortran/ChangeLog:

* primary.cc (gfc_variable_attr): Properly set dimension attribute
from a component ref.

gcc/testsuite/ChangeLog:

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

3 weeks agolibstdc++: Trap on std::shared_ptr reference count overflow [PR71945]
Jonathan Wakely [Wed, 16 Jul 2025 23:21:54 +0000 (00:21 +0100)] 
libstdc++: Trap on std::shared_ptr reference count overflow [PR71945]

This adds checks when incrementing the shared count and weak count and
will trap if they would be be incremented past its maximum. The maximum
value is the value at which incrementing it produces an invalid
use_count(). So that is either the maximum positive value of
_Atomic_word, or for targets where we now allow the counters to wrap
around to negative values, the "maximum" value is -1, because that is
the value at which one more increment overflows the usable range and
resets the counter to zero.

For the weak count the maximum is always -1 as we always allow that
count to use nagative values, so we only tap if it wraps all the way
back to zero.

libstdc++-v3/ChangeLog:

PR libstdc++/71945
* include/bits/shared_ptr_base.h (_Sp_counted_base::_S_chk):
Trap if a reference count cannot be incremented any higher.
(_Sp_counted_base::_M_add_ref_copy): Use _S_chk.
(_Sp_counted_base::_M_add_weak_ref): Likewise.
(_Sp_counted_base<_S_mutex>::_M_add_ref_lock_nothrow): Likewise.
(_Sp_counted_base<_S_atomic>::_M_add_ref_lock_nothrow): Likewise.
(_Sp_counted_base<_S_single>::_M_add_ref_copy): Use _S_chk.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
3 weeks agolibstdc++: Allow std::shared_ptr reference counts to be negative [PR71945]
Jonathan Wakely [Wed, 16 Jul 2025 23:21:54 +0000 (00:21 +0100)] 
libstdc++: Allow std::shared_ptr reference counts to be negative [PR71945]

This change doubles the effective range of the std::shared_ptr and
std::weak_ptr reference counts for most 64-bit targets.

The counter type, _Atomic_word, is usually a signed 32-bit int (except
on Solaris v9 where it is a signed 64-bit long). The return type of
std::shared_ptr::use_count() is long. For targets where long is wider
than _Atomic_word (most 64-bit targets) we can treat the _Atomic_word
reference counts as unsigned and allow them to wrap around from their
most positive value to their most negative value without any problems.
The logic that operates on the counts only cares if they are zero or
non-zero, and never performs relational comparisons. The atomic
fetch_add operations on integers are required by the standard to behave
like unsigned types, so that overflow is well-defined:

  "the result is as if the object value and parameters were converted to
  their corresponding unsigned types, the computation performed on those
  types, and the result converted back to the signed type."

So if we allow the counts to wrap around to negative values, all we need
to do is cast the value to make_unsigned_t<_Atomic_word> before
returning it as long from the use_count() function.

In practice even exceeding INT_MAX is extremely unlikely, as it would
require billions of shared_ptr or weak_ptr objects to have been
constructed and never destroyed. However, if that happens we now have
double the range before the count returns to zero and causes problems.

Some of the member functions for the _Sp_counted_base<_S_single>
specialization are adusted to use the __atomic_add_single and
__exchange_and_add_single helpers instead of plain ++ and -- operations.
This is done because those helpers use unsigned arithmetic, where the
plain increments and decrements would have undefined behaviour on
overflow.

libstdc++-v3/ChangeLog:

PR libstdc++/71945
* include/bits/shared_ptr_base.h
(_Sp_counted_base::_M_get_use_count): Cast _M_use_count to
unsigned before returning as long.
(_Sp_counted_base<_S_single>::_M_add_ref_copy): Use atomic
helper function to adjust ref count using unsigned arithmetic.
(_Sp_counted_base<_S_single>::_M_weak_release): Likewise.
(_Sp_counted_base<_S_single>::_M_get_use_count): Cast
_M_use_count to unsigned before returning as long.
(_Sp_counted_base<_S_single>::_M_add_ref_lock_nothrow): Use
_M_add_ref_copy to do increment using unsigned arithmetic.
(_Sp_counted_base<_S_single>::_M_release): Use atomic helper and
_M_weak_release to do decrements using unsigned arithmetic.
(_Sp_counted_base<_S_mutex>::_M_release): Add comment.
(_Sp_counted_base<_S_single>::_M_weak_add_ref): Remove
specialization.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
3 weeks agolibstdc++: Make atomicity helpers use unsigned arithmetic [PR121148]
Jonathan Wakely [Thu, 17 Jul 2025 21:02:45 +0000 (22:02 +0100)] 
libstdc++: Make atomicity helpers use unsigned arithmetic [PR121148]

The standard requires that std::atomic<integral-type>::fetch_add does
not have undefined behaviour for signed overflow, instead it wraps like
unsigned integers. The compiler ensures this is true for the atomic
built-ins that std::atomic uses, but it's not currently true for the
__gnu_cxx::__exchange_and_add and __gnu_cxx::__atomic_add functions
defined in libstdc++, which operate on type _Atomic_word.

For the inline __exchange_and_add_single function (used when there's
only one thread in the process), we can copy the value to an unsigned
long and do the addition on that, then assign it back to the
_Atomic_word variable.

The __exchange_and_add in config/cpu/generic/atomicity_mutex/atomicity.h
locks a mutex and then performs exactly the same steps as
__exchange_and_add_single.  Calling __exchange_and_add_single instead of
duplicating the code benefits from the fix just made to
__exchange_and_add_single.

For the remaining config/cpu/$arch/atomicity.h implementations, they
either use inline assembly which uses wrapping instructions (so no
changes needed), or we can fix them by compiling with -fwrapv.

After ths change, UBsan no longer gives an error for:

  _Atomic_word i = INT_MAX;
  __gnu_cxx::__exchange_and_add_dispatch(&i, 1);

/usr/include/c++/14/ext/atomicity.h:85:12: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'

libstdc++-v3/ChangeLog:

PR libstdc++/121148
* config/cpu/generic/atomicity_mutex/atomicity.h
(__exchange_and_add): Call __exchange_and_add_single.
* include/ext/atomicity.h (__exchange_and_add_single): Use an
unsigned type for the addition.
* libsupc++/Makefile.am (atomicity.o): Compile with -fwrapv.
* libsupc++/Makefile.in: Regenerate.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
3 weeks agopr107421.f90: Require PIE and pass -fPIE for non-x86 targets
H.J. Lu [Mon, 8 Sep 2025 14:47:35 +0000 (07:47 -0700)] 
pr107421.f90: Require PIE and pass -fPIE for non-x86 targets

-mno-direct-extern-access is used to disable direct access to external
symbol from executable with and without PIE for x86.  Require PIE and
pass -fPIE to disable direct access to external symbol for other targets.

PR fortran/107421
PR testsuite/121848
* gfortran.dg/gomp/pr107421.f90: Require PIE and pass -fPIE for
non-x86 targets.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
3 weeks agolibstdc++: Use consteval for _S_noexcept() helper functions
Jonathan Wakely [Thu, 11 Sep 2025 08:55:12 +0000 (09:55 +0100)] 
libstdc++: Use consteval for _S_noexcept() helper functions

These _S_noexcept() functions are only used in noexcept-specifiers and
never need to be called at runtime. They can be immediate functions,
i.e. consteval.

libstdc++-v3/ChangeLog:

* include/bits/iterator_concepts.h (_IterMove::_S_noexcept)
(_IterSwap::_S_noexcept): Change constexpr to consteval.
* include/bits/ranges_base.h (_Begin::_S_noexcept)
(_End::_S_noexcept, _RBegin::_S_noexcept, _REnd::_S_noexcept)
(_Size::_S_noexcept, _Empty::_S_noexcept, _Data::_S_noexcept):
Likewise.
* include/std/concepts (_Swap::_S_noexcept): Likewise.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
3 weeks agolibstdc++: Add always_inline to ranges iterator ops and access functions
Jonathan Wakely [Thu, 11 Sep 2025 08:34:02 +0000 (09:34 +0100)] 
libstdc++: Add always_inline to ranges iterator ops and access functions

Most of the basis operations for ranges such as ranges::begin and
ranges::next are trivial one-line function bodies, so can be made
always_inline to reduce the abstraction penalty for -O0 code.

Now that we no longer need to support the -fconcepts-ts grammar, we can
also move some [[nodiscard]] attributes to the more natural position
before the function declaration, instead of between the declarator-id
and the function parameters, e.g. we can use:

  template<typename T> requires C<T> [[nodiscard]] auto operator()(T&&)

instead of:

  template<typename T> requires C<T> auto operator() [[nodiscard]] (T&&)

The latter form was necessary because -fconcepts-ts used a different
grammar for the requires-clause, parsing 'C<T>[[x]]' as a subscripting
operator with an ill-formed argument '[x]'. In the C++20 grammar you
would need to use parentheses to use a subscript in a constraint, so
without parentheses it's parsed as an attribute.

libstdc++-v3/ChangeLog:

* include/bits/ranges_base.h (__detail::__to_unsigned_like)
(__access::__possible_const_range, __access::__as_const)
(__distance_fn::operator(), __next_fn::operator())
(__prev_fn::operator()): Add always_inline attribute.
(_Begin::operator(), _End::operator(), _RBegin::operator())
(_REnd::operator(), _Size::operator(), _SSize::operator())
(_Empty::operator(), _Data::operator(), _SSize::operator()):
Likewise. Move nodiscard attribute to start of declaration.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
3 weeks agotestsuite: Add tests for PR c/107419 and PR c++/107393
H.J. Lu [Mon, 8 Sep 2025 22:10:02 +0000 (15:10 -0700)] 
testsuite: Add tests for PR c/107419 and PR c++/107393

Both C and C++ frontends should set a tentative TLS model in grokvardecl
and update TLS mode with the default TLS access model after a TLS variable
has been fully processed if the default TLS access model is stronger.

PR c/107419
PR c++/107393
* c-c++-common/tls-attr-common.c: New test.
* c-c++-common/tls-attr-le-pic.c: Likewise.
* c-c++-common/tls-attr-le-pie.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
3 weeks agolibstdc++: optimize weak_ptr converting constructor/assignment
Giuseppe D'Angelo [Wed, 2 Oct 2024 16:14:34 +0000 (18:14 +0200)] 
libstdc++: optimize weak_ptr converting constructor/assignment

Converting a weak_ptr<Derived> to a weak_ptr<Base> requires calling
lock() on the source object in the general case.

Although the source weak_ptr<Derived> does contain a raw pointer to
Derived, we can't just get it and (up)cast it to Base, as that will
dereference the pointer in case Base is a virtual base class of Derived.

We don't know if the managed object is still alive, and therefore if
this operation is safe to do; we therefore temporarily lock() the source
weak_ptr, do the cast using the resulting shared_ptr, and then discard
this shared_ptr. Simply checking the strong counter isn't sufficient,
because if multiple threads are involved then we'd have a race / TOCTOU
problem; the object may get destroyed after we check the strong counter
and before we cast the pointer.

However lock() is not necessary if we know that Base is *not* a virtual
base class of Derived; in this case we can avoid the relatively
expensive call to lock() and just cast the pointer. This commit uses
the newly added builtin to detect this case and optimize std::weak_ptr's
converting constructors and assignment operations.

Apart from non-virtual bases, there's also another couple of interesting
cases where we can also avoid locking. Specifically:

1) converting a weak_ptr<T[N]> to a weak_ptr<T cv[]>;
2) converting a weak_ptr<T*> to a weak_ptr<T const * const> or similar.

Since this logic is going to be used by multiple places, I've
centralized it in a new static helper.

libstdc++-v3/ChangeLog:

* include/bits/shared_ptr_base.h (__weak_ptr): Avoid calling
lock() when converting or assigning a weak_ptr<Derived> to
a weak_ptr<Base> in case Base is not a virtual base of Derived.
This logic is centralized in _S_safe_upcast, called by the
various converting constructors/assignment operators.
(_S_safe_upcast): New helper function.
* testsuite/20_util/weak_ptr/cons/virtual_bases.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
3 weeks agoc++: Don't upgrade TLS model if TLS model isn't set.
H.J. Lu [Wed, 10 Sep 2025 19:47:47 +0000 (12:47 -0700)] 
c++: Don't upgrade TLS model if TLS model isn't set.

Don't upgrade TLS model when cplus_decl_attributes is called on a thread
local variable whose TLS model isn't set yet.

gcc/cp/

PR c++/121889
* decl2.cc (cplus_decl_attributes): Don't upgrade TLS model if
TLS model isn't set yet.

gcc/testsuite/

PR c++/121889
* g++.dg/tls/pr121889.C: New test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
3 weeks agoAArch64: Add isfinite expander [PR 66462]
Wilco Dijkstra [Wed, 27 Aug 2025 17:20:21 +0000 (17:20 +0000)] 
AArch64: Add isfinite expander [PR 66462]

Add an expander for isfinite using integer arithmetic.  This is
typically faster and avoids generating spurious exceptions on
signaling NaNs.  This fixes part of PR66462.

int isfinite1 (float x) { return __builtin_isfinite (x); }

Before:
fabs    s0, s0
mov     w0, 2139095039
fmov    s31, w0
fcmp    s0, s31
cset    w0, hi
eor     w0, w0, 1
ret

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

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

gcc/testsuite:
PR middle-end/66462
* gcc.target/aarch64/pr66462.c: Add tests for isfinite.

3 weeks agotree-optimization/121595 - new fabs(a+0.0) -> fabs(a) pattern
Matteo Nicoli [Fri, 22 Aug 2025 18:42:12 +0000 (20:42 +0200)] 
tree-optimization/121595 - new fabs(a+0.0) -> fabs(a) pattern

With -fno-trapping-math it is safe to optimize fabs(a + 0.0) as
fabs (a).

PR tree-optimization/121595
* match.pd (fabs(a + 0.0) -> fabs (a)): Optimization pattern limited to
the -fno-trapping-math case.

* gcc.dg/fabs-plus-zero-1.c: New testcase.
* gcc.dg/fabs-plus-zero-2.c: Likewise.

Signed-off-by: Matteo Nicoli <matteo.nicoli001@gmail.com>
Reviewed-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
3 weeks agotestsuite: LoongArch: Enable 16B atomic tests if the test machine supports LSX and SCQ
Xi Ruoyao [Tue, 19 Aug 2025 03:01:56 +0000 (11:01 +0800)] 
testsuite: LoongArch: Enable 16B atomic tests if the test machine supports LSX and SCQ

Enable those tests so we won't make too stupid mistakes in 16B atomic
implementation anymore.

All these test passed on a Loongson 3C6000/S except
atomic-other-int128.c.  With GDB patched to support sc.q
(https://sourceware.org/pipermail/gdb-patches/2025-August/220034.html)
this test also XPASS.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp
(check_effective_target_loongarch_scq_hw): New.
(check_effective_target_sync_int_128_runtime): Return 1 on
loongarch64-*-* if hardware supports both LSX and SCQ.
* gcc.dg/atomic-compare-exchange-5.c: Pass -mlsx -mscq for
loongarch64-*-*.
* gcc.dg/atomic-exchange-5.c: Likewise.
* gcc.dg/atomic-load-5.c: Likewise.
* gcc.dg/atomic-op-5.c: Likewise.
* gcc.dg/atomic-store-5.c: Likewise.
* gcc.dg/atomic-store-6.c: Likewise.
* gcc.dg/simulate-thread/atomic-load-int128.c: Likewise.
* gcc.dg/simulate-thread/atomic-other-int128.c: Likewise.
(dg-final): xfail on loongarch64-*-* because  gdb does not
handle sc.q properly yet.

3 weeks agoLoongArch: Fix the semantic of 16B CAS
Xi Ruoyao [Mon, 18 Aug 2025 09:18:32 +0000 (17:18 +0800)] 
LoongArch: Fix the semantic of 16B CAS

In a CAS operation, even if expected != *memory we still need to do an
atomic load of *memory into output.  But I made a mistake in the initial
implementation, causing the output to contain junk in this situation.

Like a normal atomic load, the atomic load embedded in the CAS semantic
is required to work on read-only page.  Thus we cannot rely on sc.q to
ensure the atomicity of the load.  Use LSX to perform the load instead,
and also use LSX to compare the 16B values to keep the ll-sc loop body
short.

gcc/ChangeLog:

* config/loongarch/sync.md (atomic_compare_and_swapti_scq):
Require LSX.  Change the operands for the output, the memory,
and the expected value to LSX vector modes.  Add a FCCmode
output to indicate if CAS has written the desired value into
memory.  Use LSX to atomically load both words of the 16B value
in memory.
(atomic_compare_and_swapti): Pun the modes to satisify
the new atomic_compare_and_swapti_scq implementation.  Read the
bool return value from the FCC instead of performing a
comparision.

3 weeks agoLoongArch: Fix the "%t" modifier handling for (const_int 0)
Xi Ruoyao [Tue, 19 Aug 2025 03:14:42 +0000 (11:14 +0800)] 
LoongArch: Fix the "%t" modifier handling for (const_int 0)

This modifier is intended to output $r0 for (const_int 0), but the
logic:

GET_MODE (op) != TImode || (op != CONST0_RTX (TImode) && code != REG)

will reject (const_int 0) because (const_int 0) actually does not have
a mode and GET_MODE will return VOIDmode for it.

Use reg_or_0_operand instead to fix the issue.

gcc/ChangeLog:

* config/loongarch/loongarch.cc (loongarch_print_operand): Call
reg_or_0_operand for checking the sanity of %t.

3 weeks agolibstdc++: Remove trailing whitespace in <syncstream>
Jonathan Wakely [Thu, 11 Sep 2025 09:36:22 +0000 (10:36 +0100)] 
libstdc++: Remove trailing whitespace in <syncstream>

libstdc++-v3/ChangeLog:

* include/std/syncstream: Remove trailing whitespace.

3 weeks agotree-optimization/121703 - UBSAN error with moving from uninit data
Richard Biener [Fri, 5 Sep 2025 12:47:33 +0000 (14:47 +0200)] 
tree-optimization/121703 - UBSAN error with moving from uninit data

The PR reports

vectorizer.h:276:3: runtime error: load of value 32695, which is not a valid value for type 'internal_fn'

which I believe is from

      slp_node->data = new vect_load_store_data (std::move (ls));

where 'ls' can be partly uninitialized (and that data will be not
used, but of course the move CTOR doesn't know this).  The following
tries to fix that by using value-initialization of 'ls'.

PR tree-optimization/121703
* tree-vect-stmts.cc (vectorizable_store): Value-initialize ls.
(vectorizable_load): Likewise.

3 weeks agoRISC-V: Suppress cross CC sibcall optimization from vector
Tsukasa OI [Tue, 9 Sep 2025 01:51:18 +0000 (01:51 +0000)] 
RISC-V: Suppress cross CC sibcall optimization from vector

In general, tail call optimization requires that the callee's saved
registers are a superset of the caller's.

The Standard Vector Calling Convention Variant (assembler: .variant_cc)
requires that a function with this calling convention preserves vector
registers v1-v7 and v24-v31 across calls (i.e. callee-saved).  However,
the same set of registers are (function-local) temporary registers
(i.e. caller-saved) on the normal (non-vector) calling convention.

Even if a function with this calling convention variant calls another
function with a non-vector calling convention, those vector registers
are correctly clobbered -- except when the sibling (tail) call
optimization occurs as it violates the general rule mentioned above.

If this happens, following function body:

1.  Save v1-v7 and v24-v31 for clobbering
2.  Call another function with a non-vector calling convention
    (which may destroy v1-v7 and/or v24-v31)
3.  Restore v1-v7 and v24-v31
4.  Return.

may be incorrectly optimized into the following sequence:

1.  Save v1-v7 and v24-v31 for clobbering
2.  Restore v1-v7 and v24-v31 (?!)
3.  Jump to another function with a non-vector calling convention
    (which may destroy v1-v7 and/or v24-v31).

This commit suppresses cross CC sibling call optimization from
the vector calling convention variant.

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_function_ok_for_sibcall):
Suppress cross calling convention sibcall optimization from
the vector calling convention variant.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/abi-call-variant_cc-sibcall.c: New test.
* gcc.target/riscv/rvv/base/abi-call-variant_cc-sibcall-indirect-1.c: Ditto.
* gcc.target/riscv/rvv/base/abi-call-variant_cc-sibcall-indirect-2.c: Ditto.

3 weeks agotree-optimization/121829 - bogus CFG with asm goto
Richard Biener [Mon, 8 Sep 2025 10:40:30 +0000 (12:40 +0200)] 
tree-optimization/121829 - bogus CFG with asm goto

When the vectorizer removes a forwarder created earlier by split_edge
it uses redirect_edge_pred for convenience and efficiency.  That breaks
down when the edge split is originating from an asm goto as that is
a jump that needs adjustments from redirect_edge_and_branch.  The
following factores a simple vect_remove_forwarder handling this
situation appropriately.

PR tree-optimization/121829
* cfgloopmanip.cc (create_preheader): Ensure we can insert
at the end of a preheader.

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

3 weeks agoDeal with prior EH/abormal cleanup when fixing up noreturn calls
Richard Biener [Wed, 10 Sep 2025 15:14:07 +0000 (17:14 +0200)] 
Deal with prior EH/abormal cleanup when fixing up noreturn calls

When a dead EH or abnormal edge makes a call queued for noreturn fixup
unreachable, just skip processing it.

PR tree-optimization/121870
* tree-ssa-propagate.cc
(substitute_and_fold_engine::substitute_and_fold): Skip
removed stmts from noreturn fixup.

* g++.dg/torture/pr121870.C: New testcase.

3 weeks agoada: add BACKLOG_MAX OS constant
Marc Poulhiès [Mon, 8 Sep 2025 14:42:48 +0000 (16:42 +0200)] 
ada: add BACKLOG_MAX OS constant

BACKLOG_MAX represents the number of outstanding connections in the
socket's listen queue.

gcc/ada/ChangeLog:

* libgnat/g-socket.adb (Listen_Socket): Change default value.
* libgnat/g-socket.ads (Listen_Socket): Likewise.
* s-oscons-tmplt.c (BACKLOG_MAX): New.

3 weeks agoada: Minor comment tweaks
Marc Poulhiès [Mon, 8 Sep 2025 14:21:37 +0000 (16:21 +0200)] 
ada: Minor comment tweaks

gcc/ada/ChangeLog:

* env.c (__gnat_clearenv): Adjust comment.
* libgnarl/a-intnam__bsd.ads: Fix copyright date.

3 weeks agoada: Give a warning for huge imported objects
Eric Botcazou [Thu, 21 Aug 2025 08:21:59 +0000 (10:21 +0200)] 
ada: Give a warning for huge imported objects

This is a follow-up to a recent change, where a warning was implemented
for huge library-level objects.  However it is not given if the objects
are imported, although an indirection is also added for them under the
hood to match the export side.

gcc/ada/ChangeLog:

* gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Variable>: Give a
warning for huge imported objects as well.

3 weeks agoada: Get rid of TYPE_ALIGN_OK flag in gcc-interface
Eric Botcazou [Tue, 5 Aug 2025 07:14:44 +0000 (09:14 +0200)] 
ada: Get rid of TYPE_ALIGN_OK flag in gcc-interface

The TYPE_ALIGN_OK flag had originally been a GCC flag tested in the RTL
expander and was at some point kicked out of the middle-end to become a
pure Gigi flag.  But it's only set for tagged types and CW-equivalent
types and can be replaced by a explicit predicate without too much work.

gcc/ada/ChangeLog:

* gcc-interface/ada-tree.h (TYPE_ALIGN_OK): Delete.
* gcc-interface/decl.cc (gnat_to_gnu_entity): Do not set it.
* gcc-interface/gigi.h (standard_datatypes): Add ADT_tag_name_id.
(tag_name_id): New macro.
(type_is_tagged_or_cw_equivalent): New inline predicate.
* gcc-interface/trans.cc (gigi): Initialize tag_name_id.
(gnat_to_gnu) <N_Unchecked_Type_Conversion>: Replace tests on
TYPE_ALIGN_OK with calls to type_is_tagged_or_cw_equivalent.
(addressable_p): Likewise.
* gcc-interface/utils.cc (convert): Likewise.
* gcc-interface/utils2.cc (build_binary_op): Likewise.

3 weeks agoada: Fix crash on reference to aliased object of packed array type with -g
Eric Botcazou [Mon, 28 Jul 2025 20:16:08 +0000 (22:16 +0200)] 
ada: Fix crash on reference to aliased object of packed array type with -g

This happens when the object is declared in another compilation unit.

gcc/ada/ChangeLog:

* gcc-interface/misc.cc (gnat_get_array_descr_info): In the record
type case, bail out if the original array type cannot be retrieved.

3 weeks agoada: Implement overflow checking for unsigned types
Eric Botcazou [Tue, 22 Jul 2025 22:19:10 +0000 (00:19 +0200)] 
ada: Implement overflow checking for unsigned types

The implementation is essentially mirrored from the one for signed types.

gcc/ada/ChangeLog:

* gcc-interface/gigi.h (standard_datatypes): Add ADT_uns_mulv64_decl
and ADT_uns_mulv128_decl.
(uns_mulv64_decl): New macro.
(uns_mulv128_decl): Likewise.
* gcc-interface/trans.cc (gigi): Create the uns_mulv64_decl and
uns_mulv128_decl declarations.
(gnat_to_gnu) <N_Op_Add>: Perform an overflow check for unsigned
integer addition, subtraction and multiplication if required.
<N_Op_Minus>: Perform an overflow check for unsigned integer
negation if required.
(build_unary_op_trapv): Add support for unsigned types.
(build_binary_op_trapv): Likewise.
<MINUS_EXPR>: Perform the check if the LHS is zero in the signed
case as well.

3 weeks agoada: Perform predicate check before, not after, parameter copy back.
Steve Baird [Thu, 21 Aug 2025 21:20:51 +0000 (14:20 -0700)] 
ada: Perform predicate check before, not after, parameter copy back.

In the case of a call to a subprogram that has an out (or in-out) parameter
that is passed by copy, the caller performs copy-back after the call returns.
If the actual parameter is a view conversion to a subtype that has an enabled
predicate, then the predicate check performed at that point should be
performed before, not after, the operand of the view conversion is updated.

gcc/ada/ChangeLog:

* exp_ch6.adb (Expand_Actuals): After building the tree for a
predicate check, call Prepend_To instead of Append_To so that the
check is performed before, instead of after, the corresponding
parameter copy-back.

3 weeks agoada: Create a ghost region for pragma annotate
Viljar Indus [Fri, 22 Aug 2025 08:31:56 +0000 (11:31 +0300)] 
ada: Create a ghost region for pragma annotate

Create a ghost region for pragma annotate so that we are able to analyze
the entity references correctly inside the pragma.

gcc/ada/ChangeLog:

* sem_prag.adb: Create a ghost region for pragma annotate before
analyzing its arguments.

3 weeks agoada: Check instantces of ghost iterator functions
Viljar Indus [Thu, 21 Aug 2025 09:14:08 +0000 (12:14 +0300)] 
ada: Check instantces of ghost iterator functions

Since we do not analyze the policy errors for expanded code we need to
check the functions specified in the Iterable aspect whenever we are
analyzing an iterator spcification with that aspect.

gcc/ada/ChangeLog:

* sem_ch5.adb (Analyze_Iterator_Specification): Check ghost context
of Iterable functions when handling iterator specifications with an
Iterable aspect.

3 weeks agoada: Update coding style
Viljar Indus [Mon, 25 Aug 2025 08:55:29 +0000 (11:55 +0300)] 
ada: Update coding style

gcc/ada/ChangeLog:

* ghost.adb (Check_Ghost_Policy): Update coding style.

3 weeks agoada: Ignore ghost policy errors inside aspect Iterable
Viljar Indus [Mon, 25 Aug 2025 08:52:06 +0000 (11:52 +0300)] 
ada: Ignore ghost policy errors inside aspect Iterable

It is OK to define a checked ghost type with an iterable aspect
that has ignored Iterable functions.

gcc/ada/ChangeLog:

* ghost.adb (Check_Ghost_Policy): Avoid triggering a ghost
policy error if the policy is referenced within the Iterable
aspect.

3 weeks agoada: Check ghost level dependencies inside assignments
Viljar Indus [Mon, 25 Aug 2025 07:13:02 +0000 (10:13 +0300)] 
ada: Check ghost level dependencies inside assignments

Check that entities on the RHS are ghost level dependent on the
entities on the LHS of the assignemnt.

gcc/ada/ChangeLog:

* ghost.adb (Is_OK_Statement): Check the levels of the
assignee with the levels of the entity are ghost level dependent.
(Check_Assignement_Levels): New function for checking the level
dependencies.

3 weeks agoada: Tune description of Ghost_Assertion_Level
Piotr Trojanek [Fri, 22 Aug 2025 13:08:33 +0000 (15:08 +0200)] 
ada: Tune description of Ghost_Assertion_Level

Fix grammar in comment.

gcc/ada/ChangeLog:

* einfo.ads (Ghost_Assertion_Level): Fix comment.

3 weeks agoada: Apply ghost regions for assigmnents correctly
Viljar Indus [Thu, 21 Aug 2025 11:24:04 +0000 (14:24 +0300)] 
ada: Apply ghost regions for assigmnents correctly

When frontend is operating in GNATprove mode (where expander is disabled), it
should check ghost policy for assignment statements just like it does for other
statements. This is because we want ghost policy errors to be reported not just
by GNAT, but also by GNATprove.

Additionally we need to perform the checks for valid location of ghost assigments
based on the region around the assigment before we create the region for
the assignment itself.

gcc/ada/ChangeLog:

* ghost.adb (Mark_And_Set_Ghost_Assignment): Create a ghost region
for an assigment irregardless of whether the expander is active.
Relocate the Assignment validity checks from Is_OK_Statement to
this subprogram.

3 weeks agoada: Compiler crash on container aggregate association with nonstatic key choice
Gary Dismukes [Thu, 21 Aug 2025 18:48:12 +0000 (18:48 +0000)] 
ada: Compiler crash on container aggregate association with nonstatic key choice

The compiler blows up on a container aggregate with a container element
association that has a key_choice given by a nonstatic key expression.
This happens in the size computation for the aggregate due to calling
Update_Choices with the nonstatic expression.  The fix is simply to
condition the call to Update_Choices on whether the choice expression
is static.

gcc/ada/ChangeLog:

* exp_aggr.adb (Build_Container_Aggr_Code.Build_Size_Expr): In the case
of an association with a single choice, only call Update_Choices when
the choice expression is nonstatic.

3 weeks agoada: Fix visibility bug related to target name
Bob Duff [Wed, 20 Aug 2025 18:07:14 +0000 (14:07 -0400)] 
ada: Fix visibility bug related to target name

This patch fixes the following bug:
If the right-hand side of an expression contains a target name
(i.e. "@"), and also contains a reference to a user-defined operator
that is directly visible because of a "use type" clause on a renaming of
the package where the operator is declared, the compiler gives an
incorrect error saying that the renamed package is not visible.

It turns out that setting Entity of resolved nodes is unnecessary
and wrong; the fix is to simply remove that code.

gcc/ada/ChangeLog:

* exp_ch5.adb
(Expand_Assign_With_Target_Names.Replace_Target):
Remove code setting Entity to Empty.
* sinfo.ads (Has_Target_Names):
Improve comment: add "@" to clarify what "target name"
means, and remove the content-free phrase "and must
be expanded accordingly."

3 weeks agoada: Fix regression in Root_Type -- adjustment
Bob Duff [Tue, 19 Aug 2025 16:22:38 +0000 (12:22 -0400)] 
ada: Fix regression in Root_Type -- adjustment

Recent changes "Fix regression in Root_Type" and
"Crash on b3a1004 with assertions enabled" are partially
redundant; they are addressing the same bug.
This patch adjusts the former in the case of Root_Type.
But we leave Root_Type_If_Set alone; debugging printouts
should survive bugs when possible.

gcc/ada/ChangeLog:

* einfo-utils.adb (Root_Type): Do not deal with missing Etype.

3 weeks agoada: Fix regression in Root_Type
Bob Duff [Mon, 18 Aug 2025 18:35:35 +0000 (14:35 -0400)] 
ada: Fix regression in Root_Type

Previous change, "Make pp and friends more robust (base type only)"
introduced a bug in Root_Type. Etype (T) can, in fact, be Empty
(but only in case of errors.) This patch fixes it.

gcc/ada/ChangeLog:

* einfo-utils.adb (Root_Type): Deal with missing Etype.
(Root_Type_If_Set): Likewise.

3 weeks agoada: Crash on b3a1004 with assertions enabled
Javier Miranda [Sun, 17 Aug 2025 09:45:31 +0000 (09:45 +0000)] 
ada: Crash on b3a1004 with assertions enabled

The compilation of files b3a10041.ads and b3a10042.adb crash when
the compiler is built with assertions enabled.

gcc/ada/ChangeLog:

* freeze.adb (Freeze_Entity): Protect call to Associated_Storage_Pool
since it cannot be used when the Etype is not set.
* sem_ch3.adb (Access_Type_Declaration): Ditto.
* sem_aux.adb (Is_Derived_Type): Protect call to Root_Type since it
cannot be used when the Etype is not set.

3 weeks agoada: Fix argument type of read() and write() on windows
Tonu Naks [Fri, 15 Aug 2025 10:04:27 +0000 (10:04 +0000)] 
ada: Fix argument type of read() and write() on windows

gcc/ada/ChangeLog:

* libgnat/s-crtl.ads: define unsigned
* libgnat/s-crtl__mingw.adb (read, write): change arg type

3 weeks agoada: Allow implicit packing of arrays when larger than needed
Bob Duff [Sun, 17 Aug 2025 15:23:23 +0000 (11:23 -0400)] 
ada: Allow implicit packing of arrays when larger than needed

For Implicit_Packing, do not require the Size clause to exactly match
the packed size.

For example, an array of 7 Booleans will fit in
7 bits if packed, or 7*8=56 bits if not packed.
This patch allows "for T'Size use 8;" to force packing
in Implicit_Packing mode; previously, the compiler
ignored Implicit_Packing unless it was exactly "use 7".

Apparently, customers have that sort of code, and the
whole point of Implicit_Packing is to allow such legacy
code to work.

We already do the right thing for records, at least in
cases tested.

We deliberately avoid changing the error messages given here.
They could possibly use some work, but there are subtle interactions
with the messages given in Sem_Ch13 for the same thing.

gcc/ada/ChangeLog:

* freeze.adb (Freeze_Entity): Change "=" to ">=" in
size comparison for Implicit_Packing mode.
Keep it as "=" for giving error messages.
* opt.ads (Implicit_Packing): Minor: correct obsolete
comment.

3 weeks agoada: Crash on null aggregate of multidimensional type
Javier Miranda [Fri, 15 Aug 2025 10:33:46 +0000 (10:33 +0000)] 
ada: Crash on null aggregate of multidimensional type

A compiler built with assertions enabled crashes processing
a null aggregate of multidimensional type.

gcc/ada/ChangeLog:

* sem_aggr.adb (Report_Null_Array_Constraint_Error): Adjust code
for reporting the error on enumeration types.
(Resolve_Null_Array_Aggregate): On multidimiensional arrays, avoid
reporting the same error several times. Flag the node as raising
constraint error when the bounds are known and some of them is
known to raise constraint error.

3 weeks agoada: Make pp and friends more robust (base type only)
Bob Duff [Fri, 15 Aug 2025 15:15:23 +0000 (11:15 -0400)] 
ada: Make pp and friends more robust (base type only)

Prior to this fix, if pp(N) tried to print a "base type only" field, and
Base_Type(N) was not yet set, it would raise an exception, which was
confusing. This patch makes it simply ignore such fields. Similarly
for Impl_Base_Type_Only and Root_Type_Only fields.

We do this by having alternative versions of Base_Type,
Implementation_Base_Type, and Root_Type that return Empty
in error cases, and call these alteratives from Treepr.
We don't want to Base_Type and friends to return Empty;
we want them to blow up when called from anywhere but
Treepr.

gcc/ada/ChangeLog:

* atree.ads (Node_To_Fetch_From_If_Set): Alternative to
Node_To_Fetch_From that returns Empty in error cases.
For use only in Treepr.
* treepr.adb (Print_Entity_Field): Avoid printing field
if Node_To_Fetch_From_If_Set returns Empty.
* einfo-utils.ads (Base_Type_If_Set): Alternative to
Base_Type that returns Empty in error cases.
(Implementation_Base_Type_If_Set): Likewise.
(Root_Type_If_Set): Likewise.
(Underlying_Type): Use more accurate result subtype.
* einfo-utils.adb (Base_Type): Add Asserts.
(Implementation_Base_Type): Add Assert; minor cleanup.
(Root_Type): Add Assert; minor cleanup. Remove Assert that
is redundant with predicate.
(Base_Type_If_Set): Body of new function.
(Implementation_Base_Type_If_Set): Body of new function.
(Root_Type_If_Set): Body of new function.