]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
7 months agoarm: [MVE intrinsics] add store_scatter_offset shape
Christophe Lyon [Thu, 10 Oct 2024 10:48:42 +0000 (10:48 +0000)] 
arm: [MVE intrinsics] add store_scatter_offset shape

This patch adds the store_scatter_offset shape and uses a new helper
class (store_scatter), which will also be used by later patches.

gcc/ChangeLog:

* config/arm/arm-mve-builtins-shapes.cc (struct store_scatter): New.
(struct store_scatter_offset_def): New.
* config/arm/arm-mve-builtins-shapes.h (store_scatter_offset): New.

7 months agoarm: [MVE intrinsics] add mode_after_pred helper in function_shape
Christophe Lyon [Thu, 10 Oct 2024 16:35:23 +0000 (16:35 +0000)] 
arm: [MVE intrinsics] add mode_after_pred helper in function_shape

This new helper returns true if the mode suffix goes after the
predicate suffix.  This is true in most cases, so the base
implementations in nonoverloaded_base and overloaded_base return true.
For instance: vaddq_m_n_s32.

This will be useful in later patches to implement
vstr?q_scatter_offset_p (_p appears after _offset).

gcc/ChangeLog:

* config/arm/arm-mve-builtins-shapes.cc (struct
nonoverloaded_base): Implement mode_after_pred.
(struct overloaded_base): Likewise.
* config/arm/arm-mve-builtins.cc (function_builder::get_name):
Call mode_after_pred as needed.
* config/arm/arm-mve-builtins.h (function_shape): Add
mode_after_pred.

7 months agoC++: reject OpenMP directives in constexpr functions
Tobias Burnus [Fri, 13 Dec 2024 13:27:08 +0000 (14:27 +0100)] 
C++: reject OpenMP directives in constexpr functions

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_construct, cp_parser_pragma): Reject
OpenMP expressions in constexpr functions.

gcc/testsuite/ChangeLog:

* g++.dg/gomp/pr108607.C: Update dg-error.
* g++.dg/gomp/pr79664.C: Update dg-error.
* g++.dg/gomp/omp-constexpr.C: New test.

7 months agogenrecog: Split into separate partitions [PR111600].
Robin Dapp [Tue, 26 Nov 2024 13:44:17 +0000 (14:44 +0100)] 
genrecog: Split into separate partitions [PR111600].

Hi,

this patch makes genrecog split its output into separate files (10 by
default) in the same vein genemit does.  The changes are mostly
mechanical again, changing printfs and puts to fprintf.
As insn-recog.cc relies on being able to call other recog functions a
header insn-recog.h is introduced that pre declares all of those.

For simplicity the number of files is determined by (re-using)
--with-insnemit-partitions.  Naming suggestions welcome :)

Bootstrapped and regtested on x86 and power10, regtested on riscv.
aarch64 bootstrap is currently blocked because of the
"maybe uninitialized" issue discussed on IRC.

Regards
 Robin

PR target/111600

gcc/ChangeLog:

* Makefile.in:  Add insn-recog split.
* configure: Regenerate.
* configure.ac: Document that the number of insnemit partitions is
used for insn-recog as well.
* genconditions.cc (write_one_condition): Use fprintf.
* genpreds.cc (write_predicate_expr): Ditto.
(write_init_reg_class_start_regs): Ditto.
* genrecog.cc (write_header): Add header file to includes.
(printf_indent): Use fprintf.
(change_state): Ditto.
(print_code): Ditto.
(print_host_wide_int): Ditto.
(print_parameter_value): Ditto.
(print_test_rtx): Ditto.
(print_nonbool_test): Ditto.
(print_label_value): Ditto.
(print_test): Ditto.
(print_decision): Ditto.
(print_state): Ditto.
(print_subroutine_call): Ditto.
(print_acceptance): Ditto.
(print_subroutine_start): Ditto.
(print_pattern): Ditto.
(print_subroutine): Ditto.
(print_subroutine_group): Ditto.
(handle_arg): Add -O and -H for output and header file handling.
(main): Use callback.
* gentarget-def.cc (def_target_insn): Use fprintf.
* read-md.cc (md_reader::print_c_condition): Ditto.
* read-md.h (class md_reader): Ditto.

7 months agolibstdc++: Fix uninitialized data in std::basic_spanbuf::seekoff
Jonathan Wakely [Fri, 13 Dec 2024 10:54:29 +0000 (10:54 +0000)] 
libstdc++: Fix uninitialized data in std::basic_spanbuf::seekoff

I noticed a -Wmaybe-uninitialized warning for this function, which turns
out to be correct. If the caller passes a valid std::ios_base::seekdir
value then there's no problem, but if they pass std::seekdir(999) then
we don't initialize the __base variable before adding it to __off.

Rather than initialize it to an arbitrary value, we should return an
error.

Also add [[unlikely]] attributes to the paths that return an error.

libstdc++-v3/ChangeLog:

* include/std/spanstream (basic_spanbuf::seekoff): Return an
error for invalid seekdir values.

7 months agolibstdc++: Swap expressions in noexcept-specifier of ranges::not_equal_to
Jonathan Wakely [Thu, 12 Dec 2024 23:24:39 +0000 (23:24 +0000)] 
libstdc++: Swap expressions in noexcept-specifier of ranges::not_equal_to

Although this should never make a difference for sensible code, we
should really make the expression in the noexcept-specifier match the
expression in the function body.

libstdc++-v3/ChangeLog:

* include/bits/ranges_cmp.h (not_equal_to): Make order of
expressions in noexcept-specifier match the body.
* testsuite/20_util/function_objects/range.cmp/not_equal_to.cc:
Check noexcept.

7 months agolibstdc++: Fix -Wsign-compare warning in <regex>
Jonathan Wakely [Fri, 13 Dec 2024 11:59:08 +0000 (11:59 +0000)] 
libstdc++: Fix -Wsign-compare warning in <regex>

libstdc++-v3/ChangeLog:

* include/bits/regex.tcc: Fix -Wsign-compare warning.

7 months agolibstdc++: Fix -Wreorder warning in <pstl/parallel_backend_tbb.h>
Jonathan Wakely [Fri, 13 Dec 2024 11:00:19 +0000 (11:00 +0000)] 
libstdc++: Fix -Wreorder warning in <pstl/parallel_backend_tbb.h>

libstdc++-v3/ChangeLog:

* include/pstl/parallel_backend_tbb.h (__merge_func): Fix order
of mem-initializers.

7 months agolibstdc++: Fix -Wmisleading-indentation warning in testcase
Jonathan Wakely [Thu, 12 Dec 2024 23:50:13 +0000 (23:50 +0000)] 
libstdc++: Fix -Wmisleading-indentation warning in testcase

libstdc++-v3/ChangeLog:

* testsuite/26_numerics/random/random_device/entropy.cc: Fix
indentation to avoid -Wmisleading-indentation warning.

7 months agoAArch64: Set L1 data cache size according to size on CPUs
Tamar Christina [Fri, 13 Dec 2024 11:20:18 +0000 (11:20 +0000)] 
AArch64: Set L1 data cache size according to size on CPUs

This sets the L1 data cache size for some cores based on their size in their
Technical Reference Manuals.

Today the port minimum is 256 bytes as explained in commit
g:9a99559a478111f7fbeec29bd78344df7651c707, however like Neoverse V2 most cores
actually define the L1 cache size as 64-bytes.  The generic Armv9-A model was
already changed in g:f000cb8cbc58b23a91c84d47d69481904981a1d9 and this
change follows suite for a few other cores based on their TRMs.

This results in less memory pressure when running on large core count machines.

gcc/ChangeLog:

* config/aarch64/tuning_models/cortexx925.h: Set L1 cache size to 64b.
* config/aarch64/tuning_models/neoverse512tvb.h: Likewise.
* config/aarch64/tuning_models/neoversen1.h: Likewise.
* config/aarch64/tuning_models/neoversen2.h: Likewise.
* config/aarch64/tuning_models/neoversen3.h: Likewise.
* config/aarch64/tuning_models/neoversev1.h: Likewise.
* config/aarch64/tuning_models/neoversev2.h: Likewise.
(neoversev2_prefetch_tune): Removed.
* config/aarch64/tuning_models/neoversev3.h: Likewise.
* config/aarch64/tuning_models/neoversev3ae.h: Likewise.

7 months agoAArch64: Add CMP+CSEL and CMP+CSET for cores that support it
Tamar Christina [Fri, 13 Dec 2024 11:17:55 +0000 (11:17 +0000)] 
AArch64: Add CMP+CSEL and CMP+CSET for cores that support it

GCC 15 added two new fusions CMP+CSEL and CMP+CSET.

This patch enables them for cores that support based on their Software
Optimization Guides and generically on Armv9-A.   Even if a core does not
support it there's no negative performance impact.

gcc/ChangeLog:

* config/aarch64/aarch64-fusion-pairs.def (AARCH64_FUSE_NEOVERSE_BASE):
New.
* config/aarch64/tuning_models/neoverse512tvb.h: Use it.
* config/aarch64/tuning_models/neoversen2.h: Use it.
* config/aarch64/tuning_models/neoversen3.h: Use it.
* config/aarch64/tuning_models/neoversev1.h: Use it.
* config/aarch64/tuning_models/neoversev2.h: Use it.
* config/aarch64/tuning_models/neoversev3.h: Use it.
* config/aarch64/tuning_models/neoversev3ae.h: Use it.
* config/aarch64/tuning_models/cortexx925.h: Add fusions.
* config/aarch64/tuning_models/generic_armv9_a.h: Add fusions.

7 months agoi386: Add vec_fm{addsub,subadd}v2sf4 patterns [PR116979]
Jakub Jelinek [Fri, 13 Dec 2024 09:31:04 +0000 (10:31 +0100)] 
i386: Add vec_fm{addsub,subadd}v2sf4 patterns [PR116979]

As mentioned in the PR, the addition of vec_addsubv2sf3 expander caused
the testcase to be vectorized and no longer to use fma.
The following patch adds new expanders so that it can be vectorized
again with the alternating add/sub fma instructions.

There is some bug on the slp cost computation side which causes it
not to count some scalar multiplication costs, but I think the patch
is desirable anyway before that is fixed and the testcase for now just
uses -fvect-cost-model=unlimited.

2024-12-13  Jakub Jelinek  <jakub@redhat.com>

PR target/116979
* config/i386/mmx.md (vec_fmaddsubv2sf4, vec_fmsubaddv2sf4): New
define_expand patterns.

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

7 months agoRISC-V: Improve slide1up pattern.
Robin Dapp [Sat, 16 Nov 2024 14:13:09 +0000 (15:13 +0100)] 
RISC-V: Improve slide1up pattern.

This patch adds a second variant to implement the extract/slide1up
pattern.  In order to do a permutation like
<3, 4, 5, 6> from vectors <0, 1, 2, 3> and <4, 5, 6, 7>
we currently extract <3> from the first vector and re-insert it into the
second vector.  Unless register-file crossing latency is essentially
zero it should be preferable to first slide the second vector up by
one, then slide down the first vector by (nunits - 1).

gcc/ChangeLog:

* config/riscv/riscv-protos.h (riscv_register_move_cost):
Export.
* config/riscv/riscv-v.cc (shuffle_extract_and_slide1up_patterns):
Rename...
(shuffle_off_by_one_patterns): ... to this and add slideup/slidedown
variant.
(expand_vec_perm_const_1): Call renamed function.
* config/riscv/riscv.cc (riscv_secondary_memory_needed): Remove
static.
(riscv_register_move_cost): Add VR<->GR/FR handling.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/pr112599-2.c: Adjust test
expectation.

7 months agoRISC-V: Add even/odd vec_perm_const pattern.
Robin Dapp [Thu, 17 Oct 2024 09:33:19 +0000 (11:33 +0200)] 
RISC-V: Add even/odd vec_perm_const pattern.

This adds handling for even/odd patterns.

gcc/ChangeLog:

* config/riscv/riscv-v.cc (shuffle_even_odd_patterns): New
function.
(expand_vec_perm_const_1): Use new function.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-evenodd-run.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-evenodd.c: New test.

7 months agoRISC-V: Add interleave pattern.
Robin Dapp [Wed, 16 Oct 2024 20:39:08 +0000 (22:39 +0200)] 
RISC-V: Add interleave pattern.

This patch adds efficient handling of interleaving patterns like
[0 4 1 5] to vec_perm_const.  It is implemented by a slideup and a
gather.

gcc/ChangeLog:

* config/riscv/riscv-v.cc (shuffle_interleave_patterns): New
function.
(expand_vec_perm_const_1): Use new function.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-interleave-run.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-interleave.c: New test.

7 months agoRISC-V: Add slide to perm_const strategies.
Robin Dapp [Mon, 16 Sep 2024 20:22:14 +0000 (22:22 +0200)] 
RISC-V: Add slide to perm_const strategies.

This patch adds a shuffle_slide_patterns to expand_vec_perm_const.
It recognizes permutations like

  {0, 1, 4, 5}
or
  {2, 3, 6, 7}

which can be constructed by a slideup or slidedown of one of the vectors
into the other one.

gcc/ChangeLog:

* config/riscv/riscv-v.cc (shuffle_slide_patterns): New.
(expand_vec_perm_const_1): Call new function.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-slide-run.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-slide.c: New test.

7 months agoRISC-V: Emit vector shift pattern for const_vector [PR117353].
Robin Dapp [Thu, 12 Dec 2024 09:33:28 +0000 (10:33 +0100)] 
RISC-V: Emit vector shift pattern for const_vector [PR117353].

In PR117353 and PR117878 we expand a const vector during reload.  For
this we use an unpredicated left shift.  Normally an insn like this is
split but as we introduce it late and cannot create pseudos anymore
it remains unpredicated and is not recognized by the vsetvl pass (where
we expect all insns to be in predicated RVV format).

This patch directly emits a predicated shift instead.  We could
distinguish between !lra_in_progress and lra_in_progress and emit
an unpredicated shift in the former case but we're not very likely
to optimize it anyway so it doesn't seem worth it.

PR target/117353
PR target/117878

gcc/ChangeLog:

* config/riscv/riscv-v.cc (expand_const_vector): Use predicated
instead of simple shift.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/pr117353.c: New test.

7 months agotestsuite: Fix typo in directive names
Jakub Jelinek [Fri, 13 Dec 2024 08:40:50 +0000 (09:40 +0100)] 
testsuite: Fix typo in directive names

Some directives in the test were #errror rather than #error.

2024-12-13  Jakub Jelinek  <jakub@redhat.com>

* c-c++-common/cpp/embed-1.c: Use #error rather than #errror.

7 months agoRISC-V: Make vector strided load alias all other memories
Pan Li [Fri, 13 Dec 2024 02:45:38 +0000 (10:45 +0800)] 
RISC-V: Make vector strided load alias all other memories

The vector strided load doesn't include the (mem:BLK (scratch)) to
alias all other memories.  It will make the alias analysis only
consider the base address of strided load and promopt the store
before the strided load.  For example as below

  #define STEP 10

  char d[225];
  int e[STEP];

  int main() {
    // store 0, 10, 20, 30, 40, 50, 60, 70, 80, 90
    for (long h = 0; h < STEP; ++h)
      d[h * STEP] = 9;

    // load 30, 40, 50, 60, 70, 80, 90
    // store 3,  4,  5,  6,  7,  8,  9
    for (int h = 3; h < STEP; h += 1)
      e[h] = d[h * STEP];

    if (e[5] != 9) {
      __builtin_abort ();
    }

    return 0;
  }

The asm dump will be:
main:
        lui     a5,%hi(.LANCHOR0)
        addi    a5,a5,%lo(.LANCHOR0)
        li      a4,9
        sb      a4,30(a5)
        addi    a3,a5,30
        vsetivli        zero,7,e32,m1,ta,ma
        li      a2,10
        vlse8.v v2,0(a3),a2 // depends on 30(a5), 40(a5), ... 90(a5) but
                            // only 30(a5) has been promoted before vlse.
                            // It is store after load mistake.
        addi    a3,a5,252
        sb      a4,0(a5)
        sb      a4,10(a5)
        sb      a4,20(a5)
        sb      a4,40(a5)
        vzext.vf4       v1,v2
        sb      a4,50(a5)
        sb      a4,60(a5)
        vse32.v v1,0(a3)
        li      a0,0
        sb      a4,70(a5)
        sb      a4,80(a5)
        sb      a4,90(a5)
        lw      a5,260(a5)
        beq     a5,a4,.L4
        li      a0,123

After this patch:
main:
        vsetivli        zero,4,e32,m1,ta,ma
        vmv.v.i v1,9
        lui     a5,%hi(.LANCHOR0)
        addi    a5,a5,%lo(.LANCHOR0)
        addi    a4,a5,244
        vse32.v v1,0(a4)
        li      a4,9
        sb      a4,0(a5)
        sb      a4,10(a5)
        sb      a4,20(a5)
        sb      a4,30(a5)
        sb      a4,40(a5)
        sb      a4,50(a5)
        sb      a4,60(a5)
        sb      a4,70(a5)
        sb      a4,80(a5)
        sb      a4,90(a5)
        vsetivli        zero,3,e32,m1,ta,ma
        addi    a4,a5,70
        li      a3,10
        vlse8.v v2,0(a4),a3
        addi    a5,a5,260
        li      a0,0
        vzext.vf4       v1,v2
        vse32.v v1,0(a5)
        ret

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

PR target/117990

gcc/ChangeLog:

* config/riscv/vector.md: Add the (mem:BLK (scratch)) to the
vector strided load.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/pr117990-run-1.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
7 months agoada: Fix internal error on packed record with 0-size component
Eric Botcazou [Tue, 19 Nov 2024 18:14:53 +0000 (19:14 +0100)] 
ada: Fix internal error on packed record with 0-size component

The problem is that the order of components listed in a constant CONSTRUCTOR
does not match that of the associated record type.

gcc/ada/ChangeLog:

* gcc-interface/utils2.cc (compare_elmt_bitpos): Deal specially with
0-sized components when the bit position is the same.

7 months agoada: Pass artificial_p to create_type_decl
Tom Tromey [Fri, 15 Nov 2024 17:12:28 +0000 (10:12 -0700)] 
ada: Pass artificial_p to create_type_decl

The recent "nameless types" change to gcc-interface caused the gdb
pretty-printer for VSS to fail.  This happens because one call to
create_type_decl unconditionally passes "true" as the "artificial_p"
parameter.  This patch changes this call to instead pass the entity's
local artificial_p value instead.  This makes sense, I think, because
the type decl being created for debug purposes (as the comment says)
is there to represent the relevant entity from the source.

gcc/ada/ChangeLog:

* gcc-interface/decl.cc (gnat_to_gnu_entity): Pass artificial_p to
create_type_decl.

7 months agoada: Cleanup preanalysis of static expressions
Javier Miranda [Sun, 1 Dec 2024 19:02:52 +0000 (19:02 +0000)] 
ada: Cleanup preanalysis of static expressions

During preanalysis, the frontend does not generate freeze nodes.
The exception to this rule occurs during the preanalysis of default
and per-object expressions, where static expressions are frozen.

A patch merged six years ago to address an issue in this area introduced
additional complexity and confusion regarding the frontend's behavior in
such cases. The purpose of this patch is to revert that change, simplifying
the support for the preanalysis of static expressions to make it cleaner
and easier to understand.

gcc/ada/ChangeLog:

* sem.ads (Inside_Preanalysis_Without_Freezing): Removed.
* sem.adb (Semantics): Remove Inside_Preanalysis_Without_Freezing.
* sem_ch6.adb (Preanalyze_Formal_Expression): Removed.
* sem_ch3.ads (Preanalyze_Assert_Expression): Add documentation.
(Preanalyze_Spec_Expression): Add documentation.
* sem_ch3.adb (Preanalyze_Assert_Expression) Code cleanup.
(Preanalyze_Default_Expression): Code cleanup.
* sem_res.ads (Preanalyze_With_Freezing_And_Resolve): Removed.
* sem_res.adb (Preanalyze_With_Freezing_And_Resolve): Removed.
(Preanalyze_And_Resolve): Code cleanup.
* freeze.adb (Freeze_Entity): No freeze under strict preanalysis.
(Freeze_Expression): Code cleanup.
(Freeze_Expr_Types): Replace call to Preanalyze_Spec_Expression by
strict preanalysis during preanalysis of a duplicate of the
expression performed to have available the minimum decoration
to locate referenced unfrozen types.
* sem_aggr.adb (Resolve_Array_Aggregate): Minor code cleanup.
* sem_attr.adb (Resolve_Attribute): Add documentation.
* sem_ch13.adb (Resolve_Aspect_Expressions[Aspect_Default_Value]):
Replace call to Preanalyze_Spec_Expression by Preanalyze_And_Resolve.
(Resolve_Aspect_Expressions[Aspect_Default_Component_Value]): Ditto.
* sem_ch8.adb (Set_Entity_Or_Discriminal): Code cleaup.
* sem_prag.adb (Analyze_Initial_Condition_In_Decl_Part): Replace
call to Preanalyze_Assert_Expression by call to Preanalyze_And_Resolve.
(Analyze_Pre_Post_Condition): Replace call to Preanayze_Spec_Expression
by call to Preanalyze_Assert_Expression.
* sem_util.ads (In_Pragma_Expression): Adding a formal to extend the
functionality of this subprogram.
(Within_Static_Expression): New subprogram.
* sem_util.adb (In_Pragma_Expression): Ditto.
(Within_Static_Expression): Ditto.
* checks.adb (Install_Null_Excluding_Check): No check during preanalysis.
(Install_Primitive_Elaboration_Check): Ditto.

7 months agoada: Improve expansion of nested conditional expressions in return statements
Eric Botcazou [Sun, 1 Dec 2024 22:42:36 +0000 (23:42 +0100)] 
ada: Improve expansion of nested conditional expressions in return statements

This arranges for nested conditional expressions in simple return statements
to have their expansion delayed until the returns are distributed into their
dependent expressions.  This comprises the case of the elsif part of an if
expression present in the source code.

This also distributes qualified expressions into the dependent expressions
of conditional expressions, although this seems to occur rarely in practice.

gcc/ada/ChangeLog:

* exp_aggr.ads (Is_Delayed_Conditional_Expression): Move to...
* exp_aggr.adb (Is_Delayed_Conditional_Expression): Move to...
(Convert_To_Assignments): Use Delay_Conditional_Expressions_Between.
* exp_ch3.adb (Expand_N_Object_Declaration): Reset the Analyzed flag
by means of Unanalyze_Delayed_Conditional_Expression.
* exp_ch4.adb (Expand_N_Case_Expression): Likewise.  Delay expanding
the expression if it is in the context of a simple return statement.
(Expand_N_If_Expression): Likewise.
(Expand_N_Qualified_Expression): Fold identical operand.  Distribute
the expression into an operand that is a conditional expression with
expansion delayed.
(Process_Transient_In_Expression): Also test the parent node for the
presence of a simple return statement.
* exp_ch6.adb (Expand_Ctrl_Function_Call): Test the unconditional
parent node for the presence of a simple return statement.
* exp_util.ads (Delayed Expansion): New description.
(Delay_Conditional_Expressions_Between): New procedure.
(Is_Delayed_Conditional_Expression): ...here.
(Unanalyze_Delayed_Conditional_Expression): New procedure.
(Unconditional_Parent): New function.
* exp_util.adb (Find_Hook_Context): Take into account conditional
statements coming from conditional expressions.
(Within_Conditional_Expression): Likewise.
(Delay_Conditional_Expressions_Between): New procedure.
(Is_Delayed_Conditional_Expression): ...here.
(Unanalyze_Delayed_Conditional_Expression): New procedure.
(Unconditional_Parent): New function.
* sinfo.ads (Expansion_Delayed): Adjust description.

7 months agoada: Fix indentation in record component declarations
Piotr Trojanek [Mon, 2 Dec 2024 15:37:38 +0000 (16:37 +0100)] 
ada: Fix indentation in record component declarations

Code cleanup.

gcc/ada/ChangeLog:

* exp_aggr.adb (Case_Bounds): Fix indentation.
* sem_case.adb (Choice_Bounds): Likewise.
* libgnat/s-dourea.ads (Duuble_T): Likewise.
* libgnat/s-excmac__arm.ads (Cleanup_Cache_Type): Likewise.

7 months agoada: Fix code indentation
Piotr Trojanek [Fri, 29 Nov 2024 22:30:07 +0000 (23:30 +0100)] 
ada: Fix code indentation

Fix uncontroversial coding style violations detected by an experiment with
a tree-sitter indentation support in Emacs.

gcc/ada/ChangeLog:

* atree.adb, diagnostics-pretty_emitter.adb,
diagnostics-utils.adb, einfo-utils.adb, errout.adb, exp_aggr.adb,
exp_ch3.adb, exp_ch5.adb, exp_ch6.adb, exp_ch7.adb, exp_imgv.adb,
exp_pakd.adb, exp_prag.adb, exp_unst.adb, exp_util.adb, gnatchop.adb,
gnatlink.adb, inline.adb, itypes.adb, osint.adb, rtsfind.adb,
sem_aggr.adb, sem_ch10.adb, sem_ch12.adb, sem_ch13.adb, sem_ch3.adb,
sem_ch4.adb, sem_dim.adb, sem_elab.adb, sem_prag.adb, sem_util.adb,
sprint.adb, switch-m.adb, table.adb: Fix code indentation.

7 months agoada: Fix fixed point text-io when subtype has dynamic range
Marc Poulhiès [Fri, 29 Nov 2024 08:15:42 +0000 (09:15 +0100)] 
ada: Fix fixed point text-io when subtype has dynamic range

When the fixed point subtype has dynamic range, for example in the
context of a generic procedure Test where Fixed_Type is a type formal:

  procedure Test (Low, High : Fixed_Type) is
    type New_Subtype is new Fixed_Type range Low .. High;
    package New_Io is new Text_IO.Fixed_IO (New_Subtype);

the compiler would complain with:
 non-static universal integer value out of range

Have the check use the Base type for checking what integer type can be
used. If a given integer type can be used for a base type, it can
also be used for any of its subtypes.

gcc/ada/ChangeLog:

* libgnat/a-tifiio.adb (OK_Get_32): Use 'Base.
(OK_Put_32, OK_Get_64, OK_Put_64): Likewise.
* libgnat/a-tifiio__128.adb (OK_Get_32, OK_Put_32, OK_Get_64)
(OK_Put_64, OK_Get_128, OK_Put_128): Likewise.
* libgnat/a-wtfiio.adb (OK_Get_32): Likewise.
(OK_Put_32, OK_Get_64, OK_Put_64): Likewise.
* libgnat/a-wtfiio__128.adb (OK_Get_32, OK_Put_32, OK_Get_64)
(OK_Put_64, OK_Get_128, OK_Put_128): Likewise.
* libgnat/a-ztfiio.adb (OK_Get_32): Likewise.
(OK_Put_32, OK_Get_64, OK_Put_64): Likewise.
* libgnat/a-ztfiio__128.adb (OK_Get_32, OK_Put_32, OK_Get_64)
(OK_Put_64, OK_Get_128, OK_Put_128): Likewise.

7 months agoada: Refactor code of Check_Ambiguous_Call and Valid_Conversion
Javier Miranda [Fri, 29 Nov 2024 11:05:31 +0000 (11:05 +0000)] 
ada: Refactor code of Check_Ambiguous_Call and Valid_Conversion

gcc/ada/ChangeLog:

* sem_res.adb (Report_Ambiguous_Argument): Code cleanup.
(Resolve): Code cleanup.

7 months agoada: Implement new rules about effectively volatile types in SPARK
Piotr Trojanek [Fri, 22 Nov 2024 13:31:52 +0000 (14:31 +0100)] 
ada: Implement new rules about effectively volatile types in SPARK

New rules make record types effectively volatile based on the effective
volatility of their components; same for effectively volatile for
reading. Now volatility composition for records works like volatility
composition for arrays.

gcc/ada/ChangeLog:

* sem_util.adb (Is_Effectively_Volatile,
Is_Effectively_Volatile_For_Reading): Implement new rule for
record types.
* sem_util.ads (Is_Effectively_Volatile,
Is_Effectively_Volatile_For_Reading): Adjust comments.

7 months agoada: Remove unused parameter from volatile type queries
Piotr Trojanek [Fri, 22 Nov 2024 10:31:38 +0000 (11:31 +0100)] 
ada: Remove unused parameter from volatile type queries

Routines Is_Effectively_Volatile and Is_Effectively_Volatile_For_Reading
were always called with Ignore_Protected parameter set to True (or has
been passed unmodified on recursive calls), so this parameter wasn't
actually needed.

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* sem_util.adb (Is_Effectively_Volatile,
Is_Effectively_Volatile_For_Reading): Remove Ignore_Protected
parameter.
(Is_Effectively_Volatile_Object,
Is_Effectively_Volatile_Object_For_Reading): Remove
single-parameter wrappers that are needed to instantiate
generic subprogram.
* sem_util.ads (Is_Effectively_Volatile,
Is_Effectively_Volatile_For_Reading): Remove parameter; adjust
comment.

7 months agoada: Elide copy for calls in allocators for nonlimited by-reference types
Eric Botcazou [Fri, 29 Nov 2024 08:21:09 +0000 (09:21 +0100)] 
ada: Elide copy for calls in allocators for nonlimited by-reference types

This prevents a temporary from being created on the primary stack to hold
the result of the function calls before it is copied to the newly allocated
memory in the nonlimited by-reference case.

That's already not done in the nonlimited non-by-reference case and there is
no reason to do it in the former case either.  The main issue is the call to
Remove_Side_Effects in Expand_Allocator_Expression, but its only purpose is
to cover the problematic processing done in Build_Allocate_Deallocate_Proc
on (part of) the expression; once this is fixed, the call is unnecessary.

The change also contains another small fix to deal with the corner case of
allocators for access-to-access types.

gcc/ada/ChangeLog:

* exp_ch4.adb (Expand_Allocator_Expression): Do not preventively
call Remove_Side_Effects on the expression in the nonlimited
by-reference case.  Always call Build_Allocate_Deallocate_Proc
in the default case.
* exp_ch6.adb (Expand_Ctrl_Function_Call): Bail out if the call
is the qualified expression of an allocator.
* exp_util.adb (Build_Allocate_Deallocate_Proc): Replace all the
calls to Relocate_Node by calls to Duplicate_Subexpr_No_Checks.

7 months agoada: Remove last call to Preanalyze_And_Resolve from Exp_Aggr
Eric Botcazou [Fri, 29 Nov 2024 08:04:09 +0000 (09:04 +0100)] 
ada: Remove last call to Preanalyze_And_Resolve from Exp_Aggr

All the expressions are now at least preanalyzed in a non-iterated context,
so we do not need to redo it in Aggr_Assignment_OK_For_Backend, given that
Is_OK_Aggregate explicitly rejects iterated component associations.

gcc/ada/ChangeLog:

* exp_aggr.adb (Aggr_Assignment_OK_For_Backend): Do not call again
Preanalyze_And_Resolve on the expression.

7 months agoada: Fix breakage of GNATprove introduced by latest change
Eric Botcazou [Thu, 28 Nov 2024 22:05:52 +0000 (23:05 +0100)] 
ada: Fix breakage of GNATprove introduced by latest change

gcc/ada/ChangeLog:

* sem_aggr.adb (Resolve_Aggr_Expr): Always perform a full analysis
of the expression in SPARK mode.

7 months agoada: Fix typo in reference manual
Ronan Desplanques [Thu, 28 Nov 2024 13:25:55 +0000 (14:25 +0100)] 
ada: Fix typo in reference manual

gcc/ada/ChangeLog:

* doc/gnat_rm/gnat_language_extensions.rst: Fix typo.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

7 months agoada: Fix dangling reference with user-defined indexing of function call
Eric Botcazou [Wed, 27 Nov 2024 12:03:08 +0000 (13:03 +0100)] 
ada: Fix dangling reference with user-defined indexing of function call

This happens with a noncontrolled type because the user-defined indexing is
expanded into a function call that binds the lifetime of the original call
to its return value.  The temporary must be created explicitly in this case,
so that the front-end can control its lifetime.

gcc/ada/ChangeLog:

* exp_ch6.adb (Expand_Call_Helper): Also create a temporary in the
case of a noncontrolled user-defined indexing.

7 months agoada: Fix documentation of Ada.Real_Time.Timing_Events
Ronan Desplanques [Mon, 25 Nov 2024 16:39:04 +0000 (17:39 +0100)] 
ada: Fix documentation of Ada.Real_Time.Timing_Events

The GNAT reference manual stated that GNAT did not implement this
language-defined package, but GNAT in fact does offer an implementation
of it.

gcc/ada/ChangeLog:

* doc/gnat_rm/standard_library_routines.rst: Fix documentation.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

7 months agoada: Exclude library units from gnatcov instrumentation
Ronan Desplanques [Tue, 26 Nov 2024 12:45:32 +0000 (13:45 +0100)] 
ada: Exclude library units from gnatcov instrumentation

Before this patch, we instrumented code that's only used during the
build process to generate more code. This patch marks the
code-generating code so it's not instrumented for coverage.

gcc/ada/ChangeLog:

* gnat2.gpr: Add library units to coverage exclusion list.

7 months agoada: Further work in semantic analysis of iterated component associations
Eric Botcazou [Thu, 24 Oct 2024 15:09:39 +0000 (17:09 +0200)] 
ada: Further work in semantic analysis of iterated component associations

This finishes up the transition to preanalysis of a copy of the expression
for iterated component associations in all contexts, thus voiding the need
to clean things up afterward.

However, this requires a larger cleanup in semantics analysis of aggregates,
in particular for others choices, which are currently skipped in Sem_Aggr,
with Exp_Aggr trying to patch things up afterward but leaving some legality
loopholes in the end.  That's why this makes sure that all the expressions
appearing in aggregates are either analyzed or preanalyzed by Sem_Aggr, as
documented in the spec of Sem, modulo the copy in an iteration context.

gcc/ada/ChangeLog:

* exp_aggr.adb (Build_Array_Aggr_Code): Remove obsolete comment.
(Convert_To_Positional): Remove Ctyp local variable.
(Is_Static_Element): Remove Dims parameter and do not preanalyze the
expression there.
(Expand_Array_Aggregate): Make Ctyp a constant.
(Compute_Others_Present): Do not preanalyze the expression there.
* sem_aggr.adb (Resolve_Array_Aggregate): New Ctyp constant.  Use it
throughout the procedure to denote the component type.
(Resolve_Aggr_Expr): Always preanalyze a copy of the expression in
an iteration context.  Preanalyze it directly when the expander is
active and the choice may cover multiple components.  Otherwise,
fully analyze it.
Do not reanalyze an iterated component association with an others
choice either when there are positional components.
(Resolve_Iterated_Component_Association): Do not remove references
from the expression after invoking Resolve_Aggr_Expr on it.

7 months agoada: Remove implicit assumption in the double case
Eric Botcazou [Tue, 26 Nov 2024 20:20:08 +0000 (21:20 +0100)] 
ada: Remove implicit assumption in the double case

The assumption is fulfilled in all the instantiations of the package, but
it should not be made in the generic code.

gcc/ada/ChangeLog:

* libgnat/s-imager.adb (Set_Image_Real): In the case where a double
integer is needed, do not implicit assume that it can contain up to
'Digits of the floating-point type.

7 months agoada: Adjust cut-off for scaling of floating-point numbers
Eric Botcazou [Tue, 26 Nov 2024 10:25:54 +0000 (11:25 +0100)] 
ada: Adjust cut-off for scaling of floating-point numbers

The value needs to take into account denormals and encompass Maxdigs.

gcc/ada/ChangeLog:

* libgnat/s-imager.adb (Maxscaling): Change to Natural constant and
add Maxdigs to value.

7 months agoFix -fstrict-flex-arrays documentation, again [PR111659]
Sandra Loosemore [Fri, 13 Dec 2024 00:26:29 +0000 (00:26 +0000)] 
Fix -fstrict-flex-arrays documentation, again [PR111659]

My previous attempt to fix this issue ended up garbling the text
instead.  Trying again to make the descriptions of the attribute and
command-line option consistent.

gcc/ChangeLog
PR middle-end/111659
* doc/extend.texi (Common Variable Attributes): Copy-edit description
of the strict_flex_array attribute levels.
* doc/invoke.texi (C Dialect Options): Swap documented behavior for
levels 0 and 3.  Copy the description for the other levels from the
attribute instead of indirecting to it.

7 months agoDaily bump.
GCC Administrator [Fri, 13 Dec 2024 00:19:02 +0000 (00:19 +0000)] 
Daily bump.

7 months agolibstdc++: Fix some -Wsign-compare warnings in the testsuite
Jonathan Wakely [Thu, 12 Dec 2024 23:17:28 +0000 (23:17 +0000)] 
libstdc++: Fix some -Wsign-compare warnings in the testsuite

libstdc++-v3/ChangeLog:

* testsuite/23_containers/unordered_map/modifiers/reserve.cc:
Cast to size_t to fix -Wsign-compare warning.
* testsuite/23_containers/unordered_set/hash_policy/71181.cc:
Likewise.
* testsuite/23_containers/unordered_set/insert/move_range.cc:
Likewise.

7 months agolibstdc++: Fix -Wsign-compare warnings in bits/hashtable_policy.h
Jonathan Wakely [Thu, 12 Dec 2024 21:07:08 +0000 (21:07 +0000)] 
libstdc++: Fix -Wsign-compare warnings in bits/hashtable_policy.h

libstdc++-v3/ChangeLog:

* include/bits/hashtable_policy.h (_Local_iterator_base): Fix
-Wsign-compare warnings.

7 months agolibstdc++: Fix typo in comment in src/c++17/fs_dir.cc
Jonathan Wakely [Thu, 12 Dec 2024 20:38:54 +0000 (20:38 +0000)] 
libstdc++: Fix typo in comment in src/c++17/fs_dir.cc

libstdc++-v3/ChangeLog:

* src/c++17/fs_dir.cc: Fix typo in comment.

7 months agohppa: Remove extra clobber from divsi3, udivsi3, modsi3 and umodsi3 patterns
John David Anglin [Thu, 12 Dec 2024 20:22:22 +0000 (15:22 -0500)] 
hppa: Remove extra clobber from divsi3, udivsi3, modsi3 and umodsi3 patterns

The $$divI, $$divU, $$remI and $$remU millicode calls clobber r1,
r26, r25 and the return link register (r31 or r2).  We don't need
to clobber any other registers.

2024-12-12  John David Anglin  <danglin@gcc.gnu.org>

gcc/ChangeLog:

* config/pa/pa.cc (pa_emit_hpdiv_const): Clobber r1, r25,
r25 and return register.
* config/pa/pa.md (divsi3): Revise clobbers and operands.
Remove second clobber from div:SI insns.
(udivsi3, modsi3, umodsi3): Likewise.

7 months agoRegenerate attr-urls.def.
Sandra Loosemore [Thu, 12 Dec 2024 20:12:42 +0000 (20:12 +0000)] 
Regenerate attr-urls.def.

I noticed there is this new generated file that needs to be updated by
"make regenerate-attr-urls" similarly to "make regenerate-opt-urls", but
nobody had done that recently as the buildbot does not nag about it yet.

gcc/ChangeLog

* attr-urls.def: Regenerate.

7 months agoClean up documentation of -Wsuggest-attribute= [PR115532]
Sandra Loosemore [Thu, 12 Dec 2024 19:56:04 +0000 (19:56 +0000)] 
Clean up documentation of -Wsuggest-attribute= [PR115532]

The list of -Wsuggest-attribute= variants was out of date in the option
summary (and getting too long to fit on one line), and an index entry was
missing for -Wsuggest-attribute=returns_nonnull.

gcc/c-family/ChangeLog
PR c/115532
* c.opt.urls: Regenerated.

gcc/ChangeLog
PR c/115532
* common.opt.urls: Regenerated.
* doc/invoke.texi (Option Summary): Don't try to list all the
-Wsuggest-attribute= variants inline here.
(Warning Options): Likewise.  Add @opindex for
Wsuggest-attribute=returns_nonnull and its no- form.  Remove
@itemx for no- form.

Co-Authored-By: Peter Eisentraut <peter@eisentraut.org>
7 months agomatch.pd: Defer some CTZ/CLZ foldings until after ubsan pass for -fsanitize=builtin...
Jakub Jelinek [Thu, 12 Dec 2024 18:47:46 +0000 (19:47 +0100)] 
match.pd: Defer some CTZ/CLZ foldings until after ubsan pass for -fsanitize=builtin [PR115127]

As the following testcase shows, -fsanitize=builtin instruments the
builtins in the ubsan pass which is done shortly after going into
SSA, but if optimizations optimize the builtins away before that,
nothing is instrumented.  Now, I think it is just fine if the
result of the builtins isn't used in any way and we just DCE them,
but in the following optimizations the result is used.
So, the following patch for -fsanitize=builtin only defers the
optimizations that might turn single argument CLZ/CTZ (aka undefined
at zero) until the ubsan pass is done.
Now, we don't have PROP_ubsan and am not sure it is worth adding it,
there is PROP_ssa set by the ssa pass which is 3 passes before
ubsan, but there are only 2 warning passes in between, so PROP_ssa
looked good enough to me.

2024-12-12  Jakub Jelinek  <jakub@redhat.com>

PR sanitizer/115127
* match.pd (clz (X) == C, ctz (X) == C, ctz (X) >= C): Don't
optimize if -fsanitize=builtin and not yet in SSA form.

* c-c++-common/ubsan/builtin-2.c: New test.

7 months agoOpenMP: Enable has_device_addr clause for 'dispatch' in C/C++
Tobias Burnus [Thu, 12 Dec 2024 17:58:59 +0000 (18:58 +0100)] 
OpenMP: Enable has_device_addr clause for 'dispatch' in C/C++

The 'has_device_addr' of 'dispatch' has to be seen in conjunction with the
'need_device_addr' modifier to the 'adjust_args' clause of 'declare variant'.
As the latter has not yet been implemented, 'has_device_addr' has no real
effect. However, to prepare for 'need_device_addr' and as service to the user:

For C, where 'need_device_addr' is not permitted (contrary to C++ and Fortran),
a note is output when then the user tries to use it (alongside the existing
error that either 'nothing' or 'need_device_ptr' was expected).

And, on the ME side, is is lightly handled by diagnosing when - for the
same argument - there is a mismatch between the variant's adjust_args
'need_device_ptr' modifier and dispatch having an 'has_device_addr' clause
(or likewise for need_device_addr with is_device_ptr) as, according to the
spec, those are completely separate.
Thus, 'dispatch' will still do the host to device pointer conversion for
a 'need_device_ptr' argument, even if it appeared in a 'has_device_addr'
clause.

gcc/c/ChangeLog:

* c-parser.cc (OMP_DISPATCH_CLAUSE_MASK): Add has_device_addr clause.
(c_finish_omp_declare_variant): Add an 'inform' telling the user that
'need_device_addr' is invalid for C.

gcc/cp/ChangeLog:

* parser.cc (OMP_DISPATCH_CLAUSE_MASK): Add has_device_addr clause.

gcc/ChangeLog:

* gimplify.cc (gimplify_call_expr): When handling OpenMP's dispatch,
add diagnostic when there is a ptr vs. addr mismatch between
need_device_{addr,ptr} and {is,has}_device_{ptr,addr}, respectively.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/adjust-args-3.c: New test.
* gcc.dg/gomp/adjust-args-2.c: New test.

7 months agoFortran: Fix testsuite regressions after r15-5083 [PR117797]
Paul Thomas [Thu, 12 Dec 2024 17:50:56 +0000 (17:50 +0000)] 
Fortran: Fix testsuite regressions after r15-5083 [PR117797]

2024-12-12  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/117797
* trans-array.cc (class_array_element_size): New function.
(gfc_get_array_span): Refactor, using class_array_element_size
to return the span for descriptors that are the _data component
of a class expression and then class dummy references. Revert
the conditions to those before r15-5083 tidying up using 'sym'.

gcc/testsuite/
PR fortran/117797
* gfortran.dg/pr117797.f90: New test.

7 months agoFix precondition failure with Ada.Numerics.Generic_Real_Arrays.Eigenvalues
Eric Botcazou [Thu, 12 Dec 2024 15:25:09 +0000 (16:25 +0100)] 
Fix precondition failure with Ada.Numerics.Generic_Real_Arrays.Eigenvalues

This fixes a precondition failure triggered when the Eigenvalues routine
of Ada.Numerics.Generic_Real_Arrays is instantiated with -gnata, beause
it calls Sort_Eigensystem on an empty vector.

gcc/ada
PR ada/117996
* libgnat/a-ngrear.adb (Jacobi): Remove default value for
Compute_Vectors formal parameter.
(Sort_Eigensystem): Add Compute_Vectors formal parameter.  Do not
modify the Vectors if Compute_Vectors is False.
(Eigensystem): Pass True as Compute_Vectors to Sort_Eigensystem.
(Eigenvalues): Pass False as Compute_Vectors to Sort_Eigensystem.

gcc/testsuite
* gnat.dg/matrix1.adb: New test.

7 months agoAVR: target/118000 - Fix copymem from address-spaces.
Georg-Johann Lay [Thu, 12 Dec 2024 15:13:39 +0000 (16:13 +0100)] 
AVR: target/118000 - Fix copymem from address-spaces.

* rampz_rtx et al. were missing MEM_VOLATILE_P.  This is needed because
  avr_emit_cpymemhi is setting RAMPZ explicitly with an own insn.

* avr_out_cpymem was missing a final RAMPZ = 0 on EBI devices.

This only affects the __flash1 ... __flash5 spaces since the other ASes
use different routines,

gcc/
PR target/118000
* config/avr/avr.cc (avr_init_expanders) <sreg_rtx>
<rampd_rtx, rampx_rtx, rampy_rtx, rampz_rtx>: Set MEM_VOLATILE_P.
(avr_out_cpymem) [ELPM && EBI]: Restore RAMPZ to 0 after.

7 months agoifcombine field-merge: set upper bound for get_best_mode
Alexandre Oliva [Thu, 12 Dec 2024 14:43:09 +0000 (11:43 -0300)] 
ifcombine field-merge: set upper bound for get_best_mode

A bootstrap on aarch64-linux-gnu revealed that sometimes (for example,
when building shorten_branches in final.cc) we will find such things
as MEM <unsigned int>, where unsigned int happens to be a variant of
the original unsigned int type, but with 64-bit alignment.  This
unusual alignment circumstance caused (i) get_inner_reference to not
look inside the MEM, (ii) get_best_mode to choose DImode instead of
SImode to access the object, so we built a BIT_FIELD_REF that
attempted to select all 64 bits of a 32-bit object, and that failed
gimple verification ("position plus size exceeds size of referenced
object") because there aren't that many bits in the unsigned int
object.

This patch avoids this failure mode by limiting the bitfield range
with the size of the inner object, if it is a known constant.

This enables us to avoid creating a BIT_FIELD_REF and reusing the load
expr, but we still introduced a separate load, that would presumably
get optimized out, but that is easy enough to avoid in the first place
by reusing the SSA_NAME it was originally loaded into, so I
implemented that in make_bit_field_load.

for  gcc/ChangeLog

* gimple-fold.cc (fold_truth_andor_for_ifcombine): Limit the
size of the bitregion in get_best_mode calls by the inner
object's type size, if known.
(make_bit_field_load): Reuse SSA_NAME if we're attempting to
issue an identical load.

7 months agofold fold_truth_andor field merging into ifcombine
Alexandre Oliva [Thu, 12 Dec 2024 14:43:03 +0000 (11:43 -0300)] 
fold fold_truth_andor field merging into ifcombine

This patch introduces various improvements to the logic that merges
field compares, while moving it into ifcombine.

Before the patch, we could merge:

  (a.x1 EQNE b.x1)  ANDOR  (a.y1 EQNE b.y1)

into something like:

  (((type *)&a)[Na] & MASK) EQNE (((type *)&b)[Nb] & MASK)

if both of A's fields live within the same alignment boundaries, and
so do B's, at the same relative positions.  Constants may be used
instead of the object B.

The initial goal of this patch was to enable such combinations when a
field crossed alignment boundaries, e.g. for packed types.  We can't
generally access such fields with a single memory access, so when we
come across such a compare, we will attempt to combine each access
separately.

Some merging opportunities were missed because of right-shifts,
compares expressed as e.g. ((a.x1 ^ b.x1) & MASK) EQNE 0, and
narrowing conversions, especially after earlier merges.  This patch
introduces handlers for several cases involving these.

The merging of multiple field accesses into wider bitfield-like
accesses is undesirable to do too early in compilation, so we move it
from folding to ifcombine, and guard its warnings with
-Wtautological-compare, turned into a common flag.

When the second of a noncontiguous pair of compares is the first that
accesses a word, we may merge the first compare with part of the
second compare that refers to the same word, keeping the compare of
the remaining bits at the spot where the second compare used to be.

Handling compares with non-constant fields was somewhat generalized
from what fold used to do, now handling non-adjacent fields, even if a
field of one object crosses an alignment boundary but the other
doesn't.

for  gcc/ChangeLog

* fold-const.cc (make_bit_field): Export.
(unextend, all_ones_mask_p): Drop.
(decode_field_reference, fold_truth_andor_1): Move
field compare merging logic...
* gimple-fold.cc: (fold_truth_andor_for_ifcombine) ... here,
with -Wtautological-compare warning guards, and...
(decode_field_reference): ... here.  Rework for gimple.
(gimple_convert_def_p, gimple_binop_def_p): New.
(compute_split_boundary_from_align): New.
(make_bit_field_load, build_split_load): New.
(reuse_split_load): New.
* fold-const.h: (make_bit_field_ref): Declare
(fold_truth_andor_for_ifcombine): Declare.
* tree-ssa-ifcombine.cc (ifcombine_ifandif): Try
fold_truth_andor_for_ifcombine.
* common.opt (Wtautological-compare): Move here.

for  gcc/c-family/ChangeLog

* c.opt (Wtautological-compare): Move to ../common.opt.

for  gcc/testsuite/ChangeLog

* gcc.dg/field-merge-1.c: New.
* gcc.dg/field-merge-2.c: New.
* gcc.dg/field-merge-3.c: New.
* gcc.dg/field-merge-4.c: New.
* gcc.dg/field-merge-5.c: New.
* gcc.dg/field-merge-6.c: New.
* gcc.dg/field-merge-7.c: New.
* gcc.dg/field-merge-8.c: New.
* gcc.dg/field-merge-9.c: New.
* gcc.dg/field-merge-10.c: New.
* gcc.dg/field-merge-11.c: New.
* gcc.dg/field-merge-12.c: New.
* gcc.target/aarch64/long_branch_1.c: Disable ifcombine.

7 months agoAVR: Assert minimal required bit width of section_common::flags.
Georg-Johann Lay [Sat, 7 Dec 2024 13:40:28 +0000 (14:40 +0100)] 
AVR: Assert minimal required bit width of section_common::flags.

gcc/
* config/avr/avr.cc (avr_ctz): New constexpr function.
(section_common::flags): Assert minimal bit width.

7 months agoAVR: target/118001 - Add __flashx as 24-bit named address space.
Georg-Johann Lay [Wed, 11 Dec 2024 12:28:47 +0000 (13:28 +0100)] 
AVR: target/118001 - Add __flashx as 24-bit named address space.

This patch adds __flashx as a new named address space that allocates
objects in .progmemx.data.  The handling is mostly the same or similar
to that of 24-bit space __memx, except that the asm routines are
simpler and more efficient.  Loads are emit inline when ELPMX or
LPMX is available.  The address space uses a 24-bit addresses even
on devices with a program memory size of 64 KiB or less.

PR target/118001
gcc/
* doc/extend.texi (AVR Named Address Spaces): Document __flashx.
* config/avr/avr.h (ADDR_SPACE_FLASHX): New enum value.
* config/avr/avr-protos.h (avr_out_fload, avr_mem_flashx_p)
(avr_fload_libgcc_p, avr_load_libgcc_mem_p)
(avr_load_libgcc_insn_p): New.
* config/avr/avr.cc (avr_addrspace): Add ADDR_SPACE_FLASHX.
(avr_decl_flashx_p, avr_mem_flashx_p, avr_fload_libgcc_p)
(avr_load_libgcc_mem_p, avr_load_libgcc_insn_p, avr_out_fload):
New functions.
(avr_adjust_insn_length) [ADJUST_LEN_FLOAD]: Handle case.
(avr_progmem_p) [avr_decl_flashx_p]: return 2.
(avr_addr_space_legitimate_address_p) [ADDR_SPACE_FLASHX]:
Has same behavior like ADDR_SPACE_MEMX.
(avr_addr_space_convert): Use pointer sizes rather then ASes.
(avr_addr_space_contains): New function.
(avr_convert_to_type): Use it.
(avr_emit_cpymemhi): Handle ADDR_SPACE_FLASHX.
* config/avr/avr.md (adjust_len) <fload>: New attr value.
(gen_load<mode>_libgcc): Renamed from load<mode>_libgcc.
(xload8<mode>_A): Iterate over MOVMODE rather than over ALL1.
(fxmov<mode>_A): New from xloadv<mode>_A.
(xmov<mode>_8): New from xload<mode>_A.
(fmov<mode>): New insns.
(fxload<mode>_A): New from xload<mode>_A.
(fxload_<mode>_libgcc): New from xload_<mode>_libgcc.
(*fxload_<mode>_libgcc): New from *xload_<mode>_libgcc.
(mov<mode>) [avr_mem_flashx_p]: Hande ADDR_SPACE_FLASHX.
(cpymemx_<mode>): Make sure the address space is not lost
when splitting.
(*cpymemx_<mode>) [ADDR_SPACE_FLASHX]: Use __movmemf_<mode> for asm.
(*ashlqi.1.zextpsi_split): New combine pattern.
* config/avr/predicates.md (nox_general_operand): Don't match
when avr_mem_flashx_p is true.
* config/avr/avr-passes.cc (AVR_LdSt_Props):
ADDR_SPACE_FLASHX has no post_inc.

gcc/testsuite/
* gcc.target/avr/torture/addr-space-1.h [AVR_HAVE_ELPM]:
Use a function to bump .progmemx.data to a high address.
* gcc.target/avr/torture/addr-space-2.h: Same.
* gcc.target/avr/torture/addr-space-1-fx.c: New test.
* gcc.target/avr/torture/addr-space-2-fx.c: New test.

libgcc/
* config/avr/t-avr (LIB1ASMFUNCS): Add _fload_1, _fload_2,
_fload_3, _fload_4, _movmemf.
* config/avr/lib1funcs.S (.branch_plus): New .macro.
(__xload_1, __xload_2, __xload_3, __xload_4): When the address is
located in flash, then forward to...
(__fload_1, __fload_2, __fload_3, __fload_4): ...these new
functions, respectively.
(__movmemx_hi): When the address is located in flash, forward to...
(__movmemf_hi): ...this new function.

7 months agoFix type compatibility for types with flexible array member 2/2 [PR113688,PR114713...
Martin Uecker [Sat, 23 Nov 2024 07:04:05 +0000 (08:04 +0100)] 
Fix type compatibility for types with flexible array member 2/2 [PR113688,PR114713,PR117724]

For checking or computing TYPE_CANONICAL, ignore the array size when it is
the last element of a structure or union.  To not get errors because of
an inconsistent number of members, zero-sized arrays which are the last
element are not ignored anymore when checking the fields of a struct.

PR c/113688
PR c/114014
PR c/114713
PR c/117724

gcc/ChangeLog:
* tree.cc (gimple_canonical_types_compatible_p): Add exception.

gcc/lto/ChangeLog:
* lto-common.cc (hash_canonical_type): Add exception.

gcc/testsuite/ChangeLog:
* gcc.dg/pr113688.c: New test.
* gcc.dg/pr114014.c: New test.
* gcc.dg/pr114713.c: New test.
* gcc.dg/pr117724.c: New test.

7 months agoFix type compatibility for types with flexible array member 1/2 [PR113688,PR114713...
Martin Uecker [Mon, 9 Dec 2024 11:07:57 +0000 (12:07 +0100)] 
Fix type compatibility for types with flexible array member 1/2 [PR113688,PR114713,PR117724]

Allow the TYPE_MODE of a type with an array as last member to differ from
another compatible type.

gcc/ChangeLog:
* tree.cc (gimple_canonical_types_compatible_p): Add exception.
(verify_type): Add exception.

gcc/lto/ChangeLog:
* lto-common.cc (hash_canonical_type): Add exception.

7 months agotestsuite: arm: Use -mtune=cortex-m4 for thumb-ifcvt.c test
Torbjörn SVENSSON [Thu, 21 Nov 2024 18:56:19 +0000 (19:56 +0100)] 
testsuite: arm: Use -mtune=cortex-m4 for thumb-ifcvt.c test

On Cortex-M4, the code generated is:
     cmp     r0, r1
     itte    ne
     lslne   r0, r0, r1
     asrne   r0, r0, #1
     moveq   r0, r1
     add     r0, r0, r1
     bx      lr

On Cortex-M7, the code generated is:
     cmp     r0, r1
     beq     .L3
     lsls    r0, r0, r1
     asrs    r0, r0, #1
     add     r0, r0, r1
     bx      lr
.L3:
     mov     r0, r1
     add     r0, r0, r1
     bx      lr

As Cortex-M7 only allow maximum one conditional instruction, force
Cortex-M4 to have a stable test case.

gcc/testsuite/ChangeLog:

* gcc.target/arm/thumb-ifcvt.c: Use -mtune=cortex-m4.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
7 months agotestsuite: arm: Fix build error for thumb2-slow-flash-data-3.c test
Torbjörn SVENSSON [Thu, 21 Nov 2024 15:08:30 +0000 (16:08 +0100)] 
testsuite: arm: Fix build error for thumb2-slow-flash-data-3.c test

gcc/testsuite/ChangeLog:

* gcc.target/arm/thumb2-slow-flash-data-3.c: Added argument to
fn1 to avoid compile error.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
7 months agotestsuite: arm: Check that a far jump is used in thumb1-far-jump-2.c
Torbjörn SVENSSON [Fri, 8 Nov 2024 17:52:53 +0000 (18:52 +0100)] 
testsuite: arm: Check that a far jump is used in thumb1-far-jump-2.c

With the changes in r15-1579-g792f97b44ff, the code used as "padding" in
the test case is optimized way. Prevent this optimization by forcing a
read of the volatile memory.
Also, validate that there is a far jump in the generated assembler.

Without this patch, the generated assembler is reduced to:
f3:
        cmp     r0, #0
        beq     .L1
        ldr     r4, .L6
.L1:
        bx      lr
.L7:
        .align  2
.L6:
        .word   g_0_1

With the patch, the generated assembler is:
f3:
        movs    r2, #1
        ldr     r3, .L6
        push    {lr}
        str     r2, [r3]
        cmp     r0, #0
        bne     .LCB10
        bl      .L1     @far jump
.LCB10:
        b       .L7
.L8:
        .align  2
.L6:
        .word   .LANCHOR0
.L7:
        str     r2, [r3]
        ...
        str     r2, [r3]
.L1:
        pop     {pc}

gcc/testsuite/ChangeLog:

* gcc.target/arm/thumb1-far-jump-2.c: Write to volatile memmory
in macro to avoid optimization.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
7 months agotestsuite: arm: Use effective-target for pr96939 test
Torbjörn SVENSSON [Sun, 10 Nov 2024 17:02:15 +0000 (18:02 +0100)] 
testsuite: arm: Use effective-target for pr96939 test

Update test case to use -mcpu=unset/-march=unset feature introduced in
r15-3606-g7d6c6a0d15c.

gcc/testsuite/ChangeLog:

* gcc.target/arm/lto/pr96939_0.c: Use effective-target
arm_arch_v8a.
* gcc.target/arm/lto/pr96939_1.c: Remove dg-options.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
7 months agotestsuite: arm: Use effective-target for its.c test [PR94531]
Torbjörn SVENSSON [Sun, 10 Nov 2024 11:30:02 +0000 (12:30 +0100)] 
testsuite: arm: Use effective-target for its.c test [PR94531]

The test case gcc.target/arm/its.c was created together with restriction
of IT blocks for Cortex-M7. As the test case fails on all tunes that
does not match Cortex-M7, explicitly test it for Cortex-M7. To have some
additional faith that GCC does the correct thing, I also added another
variant of the test for Cortex-M3 that should allow longer IT blocks.

gcc/testsuite/ChangeLog:

PR testsuite/94531
* gcc.target/arm/its.c: Removed.
* gcc.target/arm/its-1.c: Copy of gcc.target/arm/its.c. Use
effective-target arm_cpu_cortex_m7.
* gcc.target/arm/its-2.c: Copy of gcc.target/arm/its.c. Use
effective-target arm_cpu_cortex_m3.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
7 months agotestsuite: arm: Use -mcpu=unset when overriding -march
Torbjörn SVENSSON [Sun, 13 Oct 2024 11:28:52 +0000 (13:28 +0200)] 
testsuite: arm: Use -mcpu=unset when overriding -march

Update test cases to use -mcpu=unset/-march=unset feature introduced in
r15-3606-g7d6c6a0d15c.

gcc/testsuite/ChangeLog:
* gcc.dg/pr41574.c: Added option "-mcpu=unset".
* gcc.dg/pr59418.c: Likewise.
* lib/target-supports.exp (add_options_for_vect_early_break):
Likewise.
(add_options_for_arm_v8_neon): Likewise.
(check_effective_target_arm_neon_ok_nocache): Likewise.
(check_effective_target_arm_simd32_ok_nocache): Likewise.
(check_effective_target_arm_sat_ok_nocache): Likewise.
(check_effective_target_arm_dsp_ok_nocache): Likewise.
(check_effective_target_arm_crc_ok_nocache): Likewise.
(check_effective_target_arm_v8_neon_ok_nocache): Likewise.
(check_effective_target_arm_v8_1m_mve_fp_ok_nocache): Likewise.
(check_effective_target_arm_v8_1a_neon_ok_nocache): Likewise.
(check_effective_target_arm_v8_2a_fp16_scalar_ok_nocache):
Likewise.
(check_effective_target_arm_v8_2a_fp16_neon_ok_nocache):
Likewise.
(check_effective_target_arm_v8_2a_dotprod_neon_ok_nocache):
Likewise.
(check_effective_target_arm_v8_1m_mve_ok_nocache): Likewise.
(check_effective_target_arm_v8_2a_i8mm_ok_nocache): Likewise.
(check_effective_target_arm_fp16fml_neon_ok_nocache): Likewise.
(check_effective_target_arm_v8_2a_bf16_neon_ok_nocache):
Likewise.
(check_effective_target_arm_v8m_main_cde_ok_nocache): Likewise.
(check_effective_target_arm_v8m_main_cde_fp_ok_nocache):
Likewise.
(check_effective_target_arm_v8_1m_main_cde_mve_ok_nocache):
Likewise.
(check_effective_target_arm_v8_1m_main_cde_mve_fp_ok_nocache):
Likewise.
(check_effective_target_arm_v8_3a_complex_neon_ok_nocache):
Likewise.
(check_effective_target_arm_v8_3a_fp16_complex_neon_ok_nocache):
Likewise.
(check_effective_target_arm_v8_1_lob_ok): Likewise.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
7 months agotestsuite: arm: Use -march=unset for bfloat16_scalar* tests
Torbjörn SVENSSON [Fri, 18 Oct 2024 18:08:45 +0000 (20:08 +0200)] 
testsuite: arm: Use -march=unset for bfloat16_scalar* tests

Update test cases to use -mcpu=unset/-march=unset feature introduced in
r15-3606-g7d6c6a0d15c.

gcc/testsuite/ChangeLog:

* gcc.target/arm/bfloat16_scalar_1_1.c: Use effective-target
arm_arch_v8_2a_bf16_hard.
* gcc.target/arm/bfloat16_scalar_2_1.c: Likewise.
* gcc.target/arm/bfloat16_scalar_3_1.c: Likewise.
* gcc.target/arm/bfloat16_scalar_1_2.c: Use effective-target
arm_arch_v8_2a_bf16.
* gcc.target/arm/bfloat16_scalar_2_2.c: Likewise.
* gcc.target/arm/bfloat16_scalar_3_2.c: Likewise.
* lib/target-supports.exp: Define effective-target
v8_2a_bf16 and v8_2a_bf16_hard.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
7 months agotestsuite: arm: Use effective-target for pr56184.C and pr59985.C
Torbjörn SVENSSON [Sun, 10 Nov 2024 19:46:47 +0000 (20:46 +0100)] 
testsuite: arm: Use effective-target for pr56184.C and pr59985.C

Update test cases to use -mcpu=unset/-march=unset feature introduced in
r15-3606-g7d6c6a0d15c.

gcc/testsuite/ChangeLog:

* g++.dg/other/pr56184.C: Use effective-target
arm_arch_v7a_neon_thumb.
* g++.dg/other/pr59985.C: Use effective-target
arm_arch_v7a_fp_hard.
* lib/target-supports.exp: Define effective-target
arm_arch_v7a_fp_hard, arm_arch_v7a_neon_thumb

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
7 months agoi386: regenerate i386.opt.urls
Sam James [Thu, 12 Dec 2024 10:52:00 +0000 (10:52 +0000)] 
i386: regenerate i386.opt.urls

r15-6128-gfa878dc8c45fa3 missed the regeneration of the URL doc map, so
regenerate it here to make the buildbots happy.

gcc/ChangeLog:

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

7 months agocrc: Comment spelling fix
Jakub Jelinek [Thu, 12 Dec 2024 10:26:14 +0000 (11:26 +0100)] 
crc: Comment spelling fix

"replacement is succeeded" doesn't look correct, this patch drops the
is.

2024-12-12  Jakub Jelinek  <jakub@redhat.com>

* gimple-crc-optimization.cc (crc_optimization::optimize_crc_loop):
Comment spelling fix, is succeeded -> succeeded.

7 months agoada: Fix reference to Ada 2020 in comment
Piotr Trojanek [Mon, 4 Nov 2024 12:37:50 +0000 (13:37 +0100)] 
ada: Fix reference to Ada 2020 in comment

Code cleanup.

gcc/ada/ChangeLog:

* par-ch5.adb (Test_Statement_Required): Fix comment.

7 months agoada: Elide the copy for bit-packed aggregates in object declarations
Eric Botcazou [Thu, 21 Nov 2024 14:28:43 +0000 (15:28 +0100)] 
ada: Elide the copy for bit-packed aggregates in object declarations

The in-place expansion has been historically disabled for them, but there
does not seem to be any good reason left for this.  However, this requires
a small trick in order for the expanded code not to be flagged as using the
object uninitialized by the code generator.

gcc/ada/ChangeLog:

* exp_aggr.adb (Convert_Aggr_In_Object_Decl): Clear the component
referenced on the right-hand side of the first assignment generated
for a bit-packed array, if any.
(Expand_Array_Aggregate): Do not exclude aggregates of bit-packed
array types in object declarations from in-place expansion.
* sem_eval.adb (Eval_Indexed_Component): Do not attempt a constant
evaluation for a bit-packed array type.

7 months agoada: Defend against risk of infinite loop
Ronan Desplanques [Thu, 21 Nov 2024 14:32:47 +0000 (15:32 +0100)] 
ada: Defend against risk of infinite loop

A recently fixed bug caused an infinite loop when assertions were not
checked. With assertions checked, the symptom was just an internal
error caused by an assertion failure. This patch makes it so that if
another bug ever causes the same condition to fail, there will never be
an infinite loop with any assertion policy.

gcc/ada/ChangeLog:

* sem_ch3.adb (Access_Subprogram_Declaration): Replace assertion with
more defensive code.

7 months agoada: Avoid going through symlinks in the json report
Viljar Indus [Thu, 21 Nov 2024 10:22:00 +0000 (12:22 +0200)] 
ada: Avoid going through symlinks in the json report

gcc/ada/ChangeLog:

* errout.adb (Write_JSON_Location): Avoid going through
symbolic links when printing the full name.

7 months agoada: Fix minor display issue on invalid floats
Ronan Desplanques [Thu, 21 Nov 2024 13:26:32 +0000 (14:26 +0100)] 
ada: Fix minor display issue on invalid floats

GNAT implements a format with trailing '*' signs for the Image attribute
of NaN, +inf and -inf. It was probably always intended to be the same
length as the image of 1.0, but one '*' was actually missing. This patch
fixes this.

gcc/ada/ChangeLog:

* libgnat/s-imager.adb (Image_Floating_Point): Tweak display of
invalid floating point values.

7 months agoada: Improve task entry context detection
Ronan Desplanques [Thu, 21 Nov 2024 09:01:47 +0000 (10:01 +0100)] 
ada: Improve task entry context detection

Access parameters are not allowed in specifications of task entries.
Before this patch, the compiler failed to detect that case in accept
statements that were not directly in their task body's scopes. This
patch fixes this issue.

gcc/ada/ChangeLog:

* sem_ch3.adb (Access_Definition): Remove test for task entry context.
* sem_ch6.adb (Process_Formals): Add improved test for task entry
context.

7 months agoada: Refactor warning about null loops
Piotr Trojanek [Wed, 20 Nov 2024 15:32:38 +0000 (16:32 +0100)] 
ada: Refactor warning about null loops

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* sem_ch5.adb (Analyze_Loop_Parameter_Specification): Move call
to Comes_From_Source to the outer if-statement.

7 months agoada: Fix internal error on loop parameter specifications
Piotr Trojanek [Wed, 20 Nov 2024 15:22:05 +0000 (16:22 +0100)] 
ada: Fix internal error on loop parameter specifications

Originally loop parameter specification only occurred in loops, but now
it also occurs in quantified expressions. This patch guards against
flagging non-loop nodes as null loop statements. This was causing
internal compiler errors that were only visible with switch -gnatdk,
which happens to be default in GNATprove testsuite.

gcc/ada/ChangeLog:

* sem_ch5.adb (Analyze_Loop_Parameter_Specification): Only set
flag Is_Null_Loop when loop parameter specification comes from
a loop and not from a quantified expression.

7 months agoada: Elide the copy for bit-packed aggregates in allocators
Eric Botcazou [Wed, 20 Nov 2024 15:37:30 +0000 (16:37 +0100)] 
ada: Elide the copy for bit-packed aggregates in allocators

The in-place expansion has been historically disabled for them, but there
does not seem to be any good reason left for this.

gcc/ada/ChangeLog:

* exp_aggr.adb (Expand_Array_Aggregate): Do not exclude aggregates
of bit-packed array types in allocators from in-place expansion.

7 months agoada: Fix the level of the LLVM chapter in the User's Guide
Sebastian Poeplau [Wed, 20 Nov 2024 11:28:25 +0000 (12:28 +0100)] 
ada: Fix the level of the LLVM chapter in the User's Guide

gcc/ada/ChangeLog:

* doc/gnat_ugn/building_executable_programs_with_gnat.rst: Move
the LLVM chapter one level up.
* gnat_ugn.texi: Regenerate.

7 months agoada: Accept static strings with External_Initialization
Ronan Desplanques [Tue, 19 Nov 2024 09:10:31 +0000 (10:10 +0100)] 
ada: Accept static strings with External_Initialization

Before this patch, the argument to the External_Initialization aspect
had to be a string literal. This patch extends the possibilities so that
any static string is accepted.

A new helper function, Is_OK_Static_Expression_Of_Type, is introduced,
and in addition to the main change of this patch a couple of calls to
that helper function are added in other places to replace equivalent
inline code.

gcc/ada/ChangeLog:

* sem_eval.ads (Is_OK_Static_Expression_Of_Type): New function.
* sem_eval.adb (Is_OK_Static_Expression_Of_Type): Likewise.
* sem_ch13.adb (Check_Expr_Is_OK_Static_Expression): Use new function.
* sem_prag.adb (Check_Expr_Is_OK_Static_Expression): Likewise.
* sem_ch3.adb (Apply_External_Initialization): Accept static strings
for the parameter.

7 months agoada: Fix reference manual clauses
Ronan Desplanques [Tue, 19 Nov 2024 15:51:44 +0000 (16:51 +0100)] 
ada: Fix reference manual clauses

The clauses in section 3.5 of the reference manual were moved around
along the different Ada versions, which caused some comments in our
source code to go out of date. This patch updates the references in
those comments.

gcc/ada/ChangeLog:

* libgnat/a-tifiio.adb: Fix comment.
* libgnat/a-tifiio__128.adb: Likewise.
* libgnat/s-imaged.ads (Image_Decimal): Likewise.
* libgnat/s-imagef.ads (Image_Fixed): Likewise.
* libgnat/s-imager.ads (Image_Fixed_Point): Likewise.
* libgnat/s-imde32.ads (Image_Decimal32): Likewise.
* libgnat/s-imfi64.ads (Image_Fixed64): Likewise.
* libgnat/s-imgcha.adb (Image_Character): Likewise.
* libgnat/s-valuer.adb (Scan_Raw_Real): Likewise.
* sem_attr.adb (Eval_Attribute): Likewise.

7 months agoada: Fix pragma Compile_Time_Error for sizes of nonstatic array types
Eric Botcazou [Tue, 19 Nov 2024 12:04:08 +0000 (13:04 +0100)] 
ada: Fix pragma Compile_Time_Error for sizes of nonstatic array types

The pragma is consistenly rejected for the sizes of nonstatic array types
because Eval_Attribute does not evaluate it even if it is known.

gcc/ada/ChangeLog:

* sem_attr.adb (Eval_Attribute): Treat the various size attributes
like Component_Size for nonstatic array types.

7 months agoada: Refactor code of Check_Ambiguous_Call and Valid_Conversion
Javier Miranda [Tue, 19 Nov 2024 11:07:42 +0000 (11:07 +0000)] 
ada: Refactor code of Check_Ambiguous_Call and Valid_Conversion

gcc/ada/ChangeLog:

* sem_res.adb (Is_Ambiguous_Operand): Add missing decoration of
the operand when it is labeled overloaded but has just one
interpretation.

7 months agoada: Minor refactoring in expansion of array aggregates
Eric Botcazou [Tue, 19 Nov 2024 08:19:22 +0000 (09:19 +0100)] 
ada: Minor refactoring in expansion of array aggregates

This just moves a couple of checks done in conjunction with the predicate
Aggr_Assignment_OK_For_Backend into its body and adds a couple of comments.

No functional changes.

gcc/ada/ChangeLog:

* exp_aggr.adb (Aggr_Assignment_OK_For_Backend): Add Target formal
parameter and check that it is not a bit-aligned component or slice.
Return False in CodePeer mode as well.
(Build_Array_Aggr_Code): Remove redundant tests done in conjunction
with a call to Aggr_Assignment_OK_For_Backend.
(Expand_Array_Aggregate): Likewise.  Add a couple of comments and
improve formatting.

7 months agoada: Fix validity check for private types
Ronan Desplanques [Tue, 19 Nov 2024 09:43:44 +0000 (10:43 +0100)] 
ada: Fix validity check for private types

Before this patch, the machinery to generate validity checks got
confused in some situations involving private views of types, and ended
up generating incorrect conversions from floating point types to integer
types. This patch fixes this.

gcc/ada/ChangeLog:

* exp_attr.adb (Expand_N_Attribute_Reference): Fix computation of type
category.

7 months agoada: Add minimal support for other delayed aspects on controlled objects
Eric Botcazou [Sun, 17 Nov 2024 19:00:42 +0000 (20:00 +0100)] 
ada: Add minimal support for other delayed aspects on controlled objects

This extends the processing done for the Address aspect to other delayed
aspects.  The External_Name aspect is also reclassified as a representation
aspect and the three representation aspects External_Name, Link_Name and
Linker_Section are moved from the Always_Delay to the Rep_Aspect category,
which makes it possible not to delay them in most cases with a small tweak.

gcc/ada/ChangeLog:

* aspects.ads (Is_Representation_Aspect): True for External_Name.
(Aspect_Delay): Use Rep_Aspect for External_Name, Link_Name and
Linker_Section.
* einfo.ads (Initialization_Statements): Document extended usage.
* exp_util.adb (Needs_Initialization_Statements): Return True for
all delayed aspects.
* freeze.adb (Check_Address_Clause): Do not move the initialization
expression here...
(Freeze_Object_Declaration): ...but here instead, as well as for all
delayed aspects.  Remove test for pragma Linker_Section.
* sem_ch13.adb (Analyze_One_Aspect): Do not delay in the Rep_Aspect
case if the expression is a string literal.

7 months agoada: Fix documentation comment for Scan_Sign
Ronan Desplanques [Mon, 18 Nov 2024 13:44:39 +0000 (14:44 +0100)] 
ada: Fix documentation comment for Scan_Sign

This patches fixes a couple of details that were wrong in the
documentation comment for System.Val_Util.Scan_Sign.

gcc/ada/ChangeLog:

* libgnat/s-valuti.ads (Scan_Sign): Fix documentation comment.

7 months agoada: Crash on assignment of task allocator with expanded name
Bob Duff [Fri, 15 Nov 2024 20:18:46 +0000 (15:18 -0500)] 
ada: Crash on assignment of task allocator with expanded name

The compiler crashes on an assignment statement of the form
"X.Y := new T;", where X.Y is an expanded name (i.e. not a record
component or similar) and T is a type containing tasks.

gcc/ada/ChangeLog:

* exp_util.adb (Build_Task_Image_Decls):
Deal properly with the case of an expanded name.
Minor cleanup: use a case statement instead of if/elsif chain.

7 months agoada: Lift technical limitation in expansion of record aggregates
Eric Botcazou [Sun, 17 Nov 2024 19:26:53 +0000 (20:26 +0100)] 
ada: Lift technical limitation in expansion of record aggregates

The mechanim deferring the expansion of record aggregates nested in other
aggregates with intermediate conditional expressions is disabled in the
case where they contain self-references, because of a technical limitation
in the replacements done by Build_Record_Aggr_Code.  This change lifts it.

gcc/ada/ChangeLog:

* exp_aggr.adb (Traverse_Proc_For_Aggregate): New generic procedure.
(Replace_Discriminants): Instantiate it instead of Traverse_Proc.
(Replace_Self_Reference): Likewise.
(Convert_To_Assignments): Remove limitation for nested aggregates
that contain self-references.

7 months agoada: Small improvements to expansion of conditional expressions
Eric Botcazou [Fri, 15 Nov 2024 20:29:18 +0000 (21:29 +0100)] 
ada: Small improvements to expansion of conditional expressions

They comprise using a nonnull accesss type for the indirect expansion to
avoid useless checks, smplifying the expansion of if expressions whose
condition is known at compile time to avoid an N_Expression_With_Actions,
using the indirect expansion for them in the indefinite case too, which
makes the special case for an unconstrained array type obsolete.

No functional changes.

gcc/ada/ChangeLog:

* exp_ch4.adb (Expand_N_Case_Expression): Remove obsolete comment
about C code generation.  Do not create a useless target type if
the parent statement is rewritten instead of the expression.  Use
a nonnull accesss type for the expansion done for composite types.
(Expand_N_If_Expression): Simplify the expansion when the condition
is known at compile time.  Apply the expansion done for by-reference
types to indefinite types and remove the obsolete special case for
unconstrained array types  Use a nonnull access type in this case.
Rename New_If local variable to If_Stmt for the sake of consistency.

7 months agoada: Fix wrong finalization with private unconstrained array type
Eric Botcazou [Fri, 15 Nov 2024 17:40:02 +0000 (18:40 +0100)] 
ada: Fix wrong finalization with private unconstrained array type

The address passed to the routine attaching a controlled object to the
finalization master must be that of its dope vector for an object whose
nominal subtype is an unconstrained array type, but this is not the case
when this subtype has a private declaration.

gcc/ada/ChangeLog:

* exp_ch7.adb (Make_Address_For_Finalize): Look at the underlying
subtype to detect the unconstrained array type case.
* sprint.adb (Write_Itype) <E_Private_Subtype>: New case.

7 months agoada: Update documentation for External_Initialization
Ronan Desplanques [Fri, 15 Nov 2024 10:30:11 +0000 (11:30 +0100)] 
ada: Update documentation for External_Initialization

This fixes an omission in the recent change that was made to file lookup
for External_Initialization.

gcc/ada/ChangeLog:

* doc/gnat_rm/gnat_language_extensions.rst: Update
External_Initialization section.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

7 months agoada: Tweak Is_Predefined_File_Name
Ronan Desplanques [Thu, 14 Nov 2024 16:11:03 +0000 (17:11 +0100)] 
ada: Tweak Is_Predefined_File_Name

This patch slightly widens the set of filenames that the compiler
considers predefined. That makes it possible to build the GNAT runtime
using only the file mapping facilities of the compiler, without having
to rename files.

gcc/ada/ChangeLog:

* fname.adb (Is_Predefined_File_Name): Tweak test.

7 months agoada: Restrict External_Initialization file lookup
Ronan Desplanques [Thu, 14 Nov 2024 15:52:55 +0000 (16:52 +0100)] 
ada: Restrict External_Initialization file lookup

Before this patch, External_Initialization looked for files in all
directories of the source search path, which led to inconsistencies in
some cases. This patch restricts the file lookup so the argument is
interpreted as relative to the current source file's directory only.

gcc/ada/ChangeLog:

* sem_ch3.adb (Apply_External_Initialization): Restrict File lookup.

7 months agoada: Clean up and restrict usage of Initialization_Statements
Eric Botcazou [Thu, 14 Nov 2024 19:33:34 +0000 (20:33 +0100)] 
ada: Clean up and restrict usage of Initialization_Statements

This mechanism is the only producer of N_Compound_Statement in the expanded
code and parks the statements generated for the in-place initialization of
objects by an aggregate, so that they can be moved to the freeze point if
there is an address aspect/clause, or even cancelled if the aggregate has
been generated for Initialize_Scalars/Normalize_Scalars before a subsequent
pragma Import for the object is encountered.

The main condition for its triggering is that the object be not yet frozen,
but that's always the case when its declaration is being processed, so the
mechanism is triggered unnecessarily and the change restricts this but, on
the other hand, it also extends its usage to the in-place initialization by
a function call, which was implemented by means of a custom deferral.

There should be no functional changes.

gcc/ada/ChangeLog:

* einfo.ads (Initialization_Statements): Document usage precisely.
* exp_aggr.adb (Convert_Aggr_In_Object_Decl): Do not create a
compound statement in most cases, do it only if necessary.
* exp_ch3.adb (Expand_N_Object_Declaration): Remove a couple of
useless statements.
* exp_ch6.adb (Make_Build_In_Place_Call_In_Object_Declaration):
Use the Initialization_Statements mechanism if necessary.
* exp_ch7.adb: Remove clauses for Aspects package.
(Insert_Actions_In_Scope_Around): Use the support code of Exp_Util
for the Initialization_Statements mechanism.
* exp_prag.adb (Undo_Initialization): Remove obsolete code.
* exp_util.ads (Move_To_Initialization_Statements): New procedure.
(Needs_Initialization_Statements): New function.
* exp_util.adb (Move_To_Initialization_Statements): New procedure.
(Needs_Initialization_Statements): New predicate.

7 months agoada: Avoid expanding LHS assignments for controlled types
Viljar Indus [Thu, 14 Nov 2024 13:22:44 +0000 (15:22 +0200)] 
ada: Avoid expanding LHS assignments for controlled types

Expanding a function call that returns a controlled type
on the left-hand side of an assignment should be avoided.
Otherwise we will miss the diagnostic for
trying to assign something to a non-variable element.

gcc/ada/ChangeLog:

* exp_ch6.adb (Expand_Ctrl_Function_Call): Avoid expansion
of controlled types when the LHS is a function call.

7 months agoada: Add SIGPROT handler for CheriBSD
Daniel King [Fri, 1 Nov 2024 21:29:59 +0000 (21:29 +0000)] 
ada: Add SIGPROT handler for CheriBSD

gcc/ada/ChangeLog:

* init.c (__gnat_error_handler): Handle SIGPROT
(__gnat_install_handler): Install SIGPROT handler

7 months agoada: Export CHERI exception IDs
Daniel King [Fri, 1 Nov 2024 21:27:00 +0000 (21:27 +0000)] 
ada: Export CHERI exception IDs

This allows CHERI exceptions to be raised from C code in the runtime.

gcc/ada/ChangeLog:

* libgnat/i-cheri-exceptions.ads: Export CHERI exception IDs.

7 months agoada: Ensure minimum stack size for preallocated task stacks
Johannes Kliemann [Tue, 12 Nov 2024 16:53:34 +0000 (17:53 +0100)] 
ada: Ensure minimum stack size for preallocated task stacks

On targets with preallocated task stacks the minimum stack size is
defined as a constant in System.Parameters. When adding preallocated
tasks to the expanded code the compiler does not have direct access to
that value. Instead generate the expression
Max (Task_Size, Minimum_Task_Size) in the expanded tree and let it be
resolved later in the compilation process.

gcc/ada/ChangeLog:

* exp_ch9.adb (Expand_N_Task_Type_Declaration): Take
Minimum_Stack_Size into account when preallocating task stacks.
* rtsfind.ads (RE_Id, RE_Unit_Table): Add RE_Minimum_Stack_Size.

7 months agoFix misplaced x86 -mstack-protector-guard-symbol documentation [PR117150]
Sandra Loosemore [Thu, 12 Dec 2024 04:20:37 +0000 (04:20 +0000)] 
Fix misplaced x86 -mstack-protector-guard-symbol documentation [PR117150]

Commit e1769bdd4cef522ada32aec863feba41116b183a accidentally inserted
the documentation for the x86 -mstack-protector-guard-symbol option in the
wrong place.  Fixed thusly.

gcc/ChangeLog
PR target/117150
* doc/invoke.texi (RS/6000 and PowerPC Options): Move description
of -mstack-protector-guard-symbol from here...
(x86 Options): ...to here.

7 months agoDaily bump.
GCC Administrator [Thu, 12 Dec 2024 00:19:00 +0000 (00:19 +0000)] 
Daily bump.