]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
2 years agoDisable avoid_false_dep_for_bmi for atom and icelake(and later) core processors.
liuhongt [Mon, 22 May 2023 02:41:50 +0000 (10:41 +0800)] 
Disable avoid_false_dep_for_bmi for atom and icelake(and later) core processors.

lzcnt/tzcnt has been fixed since skylake, popcnt has been fixed since
icelake. At least for icelake and later intel Core processors, the
errata tune is not needed. And the tune isn't need for ATOM either.

gcc/ChangeLog:

* config/i386/x86-tune.def (X86_TUNE_AVOID_FALSE_DEP_FOR_BMI):
Remove ATOM and ICELAKE(and later) core processors.

2 years agoDaily bump.
GCC Administrator [Sat, 27 May 2023 00:16:49 +0000 (00:16 +0000)] 
Daily bump.

2 years agoc: -Wstringop-overflow for parameters with forward-declared sizes
Martin Uecker [Fri, 26 May 2023 09:19:01 +0000 (11:19 +0200)] 
c: -Wstringop-overflow for parameters with forward-declared sizes

Warnings from -Wstringop-overflow do not appear for parameters declared
as VLAs when the bound refers to a parameter forward declaration. This
is fixed by splitting the loop that passes through parameters into two,
first only recording the positions of all possible size expressions
and then processing the parameters.

PR c/109970

gcc/c-family:

* c-attribs.cc (build_attr_access_from_parms): Split loop to first
record all parameters.

gcc/testsuite:

* gcc.dg/pr109970.c: New test.

2 years agoRISC-V: Implement autovec abs, vneg, vnot.
Robin Dapp [Fri, 12 May 2023 14:26:08 +0000 (16:26 +0200)] 
RISC-V: Implement autovec abs, vneg, vnot.

This patch implements abs<mode>2, vneg<mode>2 and vnot<mode>2
expanders for integer vector registers and adds tests for them.

gcc/ChangeLog:

* config/riscv/autovec.md (<optab><mode>2): Add vneg/vnot.
(abs<mode>2): Add.
* config/riscv/riscv-protos.h (emit_vlmax_masked_mu_insn):
Declare.
* config/riscv/riscv-v.cc (emit_vlmax_masked_mu_insn): New
function.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/rvv.exp: Add unop tests.
* gcc.target/riscv/rvv/autovec/unop/abs-run.c: New test.
* gcc.target/riscv/rvv/autovec/unop/abs-rv32gcv.c: New test.
* gcc.target/riscv/rvv/autovec/unop/abs-rv64gcv.c: New test.
* gcc.target/riscv/rvv/autovec/unop/abs-template.h: New test.
* gcc.target/riscv/rvv/autovec/unop/vneg-run.c: New test.
* gcc.target/riscv/rvv/autovec/unop/vneg-rv32gcv.c: New test.
* gcc.target/riscv/rvv/autovec/unop/vneg-rv64gcv.c: New test.
* gcc.target/riscv/rvv/autovec/unop/vneg-template.h: New test.
* gcc.target/riscv/rvv/autovec/unop/vnot-run.c: New test.
* gcc.target/riscv/rvv/autovec/unop/vnot-rv32gcv.c: New test.
* gcc.target/riscv/rvv/autovec/unop/vnot-rv64gcv.c: New test.
* gcc.target/riscv/rvv/autovec/unop/vnot-template.h: New test.

2 years agoRISC-V: Add autovec sign/zero extension and truncation.
Robin Dapp [Wed, 17 May 2023 12:38:18 +0000 (14:38 +0200)] 
RISC-V: Add autovec sign/zero extension and truncation.

This patch implements the autovec expanders for sign and zero extension
patterns as well as the accompanying truncations.  In order to use them
additional mode_attr iterators as well as vectorizer hooks are required.
Using these hooks we can e.g. vectorize with VNx4QImode as base mode
and extend VNx4SI to VNx4DI.  They are still going to be expanded in the
future.

vf4 and vf8 truncations are emulated by truncating two and three times
respectively.

The patch also adds tests and changes some expectations for already
existing ones.

Combine does not yet handle binary operations of two widened operands
as we are missing the necessary split/rewrite patterns.  These will be
added at a later time.

Co-authored-by: Juzhe Zhong <juzhe.zhong@rivai.ai>
gcc/ChangeLog:

* config/riscv/autovec.md (<optab><v_double_trunc><mode>2): New
expander.
(<optab><v_quad_trunc><mode>2): Dito.
(<optab><v_oct_trunc><mode>2): Dito.
(trunc<mode><v_double_trunc>2): Dito.
(trunc<mode><v_quad_trunc>2): Dito.
(trunc<mode><v_oct_trunc>2): Dito.
* config/riscv/riscv-protos.h (vectorize_related_mode): Define.
(autovectorize_vector_modes): Define.
* config/riscv/riscv-v.cc (vectorize_related_mode): Implement
hook.
(autovectorize_vector_modes): Implement hook.
* config/riscv/riscv.cc (riscv_autovectorize_vector_modes):
Implement target hook.
(riscv_vectorize_related_mode): Implement target hook.
(TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES): Define.
(TARGET_VECTORIZE_RELATED_MODE): Define.
* config/riscv/vector-iterators.md: Add lowercase versions of
mode_attr iterators.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/binop/shift-rv32gcv.c: Adjust
expectation.
* gcc.target/riscv/rvv/autovec/binop/shift-rv64gcv.c: Dito.
* gcc.target/riscv/rvv/autovec/binop/vdiv-run.c: Dito.
* gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv.c: Dito.
* gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv.c: Dito.
* gcc.target/riscv/rvv/autovec/binop/vdiv-template.h: Dito.
* gcc.target/riscv/rvv/autovec/binop/vrem-rv32gcv.c: Dito.
* gcc.target/riscv/rvv/autovec/binop/vrem-rv64gcv.c: Dito.
* gcc.target/riscv/rvv/autovec/zve32f_zvl128b-2.c: Dito.
* gcc.target/riscv/rvv/autovec/zve32x_zvl128b-2.c: Dito.
* gcc.target/riscv/rvv/autovec/zve64d-2.c: Dito.
* gcc.target/riscv/rvv/autovec/zve64f-2.c: Dito.
* gcc.target/riscv/rvv/autovec/zve64x-2.c: Dito.
* gcc.target/riscv/rvv/rvv.exp: Add new conversion tests.
* gcc.target/riscv/rvv/vsetvl/avl_single-38.c: Do not vectorize.
* gcc.target/riscv/rvv/vsetvl/avl_single-47.c: Dito.
* gcc.target/riscv/rvv/vsetvl/avl_single-48.c: Dito.
* gcc.target/riscv/rvv/vsetvl/avl_single-49.c: Dito.
* gcc.target/riscv/rvv/vsetvl/imm_switch-8.c: Dito.
* gcc.target/riscv/rvv/autovec/conversions/vncvt-run.c: New test.
* gcc.target/riscv/rvv/autovec/conversions/vncvt-rv32gcv.c: New test.
* gcc.target/riscv/rvv/autovec/conversions/vncvt-rv64gcv.c: New test.
* gcc.target/riscv/rvv/autovec/conversions/vncvt-template.h: New test.
* gcc.target/riscv/rvv/autovec/conversions/vsext-run.c: New test.
* gcc.target/riscv/rvv/autovec/conversions/vsext-rv32gcv.c: New test.
* gcc.target/riscv/rvv/autovec/conversions/vsext-rv64gcv.c: New test.
* gcc.target/riscv/rvv/autovec/conversions/vsext-template.h: New test.
* gcc.target/riscv/rvv/autovec/conversions/vzext-run.c: New test.
* gcc.target/riscv/rvv/autovec/conversions/vzext-rv32gcv.c: New test.
* gcc.target/riscv/rvv/autovec/conversions/vzext-rv64gcv.c: New test.
* gcc.target/riscv/rvv/autovec/conversions/vzext-template.h: New test.

2 years agoFortran/OpenMP: Add parsing support for allocators/allocate directives
Tobias Burnus [Fri, 26 May 2023 18:39:33 +0000 (20:39 +0200)] 
Fortran/OpenMP: Add parsing support for allocators/allocate directives

gcc/fortran/ChangeLog:

* dump-parse-tree.cc (show_omp_namelist): Update allocator, fix
align dump.
(show_omp_node, show_code_node): Handle EXEC_OMP_ALLOCATE.
* gfortran.h (enum gfc_statement): Add ST_OMP_ALLOCATE and ..._EXEC.
(enum gfc_exec_op): Add EXEC_OMP_ALLOCATE.
(struct gfc_omp_namelist): Add 'allocator' to 'u2' union.
(struct gfc_namespace): Add omp_allocate.
(gfc_resolve_omp_allocate): New.
* match.cc (gfc_free_omp_namelist): Free 'u2.allocator'.
* match.h (gfc_match_omp_allocate, gfc_match_omp_allocators): New.
* openmp.cc (gfc_omp_directives): Uncomment allocate/allocators.
(gfc_match_omp_variable_list): Add bool arg for
rejecting listening common-block vars separately.
(gfc_match_omp_clauses): Update for u2.allocators.
(OMP_ALLOCATORS_CLAUSES, gfc_match_omp_allocate,
gfc_match_omp_allocators, is_predefined_allocator,
gfc_resolve_omp_allocate): New.
(resolve_omp_clauses): Update 'allocate' clause checks.
(omp_code_to_statement, gfc_resolve_omp_directive): Handle
OMP ALLOCATE/ALLOCATORS.
* parse.cc (in_exec_part): New global var.
(check_omp_allocate_stmt, parse_openmp_allocate_block): New.
(decode_omp_directive, case_exec_markers, case_omp_decl,
gfc_ascii_statement, parse_omp_structured_block): Handle
OMP allocate/allocators.
(verify_st_order, parse_executable): Set in_exec_part.
* resolve.cc (gfc_resolve_blocks, resolve_codes): Handle
allocate/allocators.
* st.cc (gfc_free_statement): Likewise.
* trans.cc (trans_code): Likewise.
* trans-openmp.cc (gfc_trans_omp_directive): Likewise.
(gfc_trans_omp_clauses, gfc_split_omp_clauses): Update for
u2.allocator, fix for u.align.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/allocate-4.f90: Update dg-error.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/allocate-2.f90: Update dg-error.
* gfortran.dg/gomp/allocate-4.f90: New test.
* gfortran.dg/gomp/allocate-5.f90: New test.
* gfortran.dg/gomp/allocate-6.f90: New test.
* gfortran.dg/gomp/allocate-7.f90: New test.
* gfortran.dg/gomp/allocators-1.f90: New test.
* gfortran.dg/gomp/allocators-2.f90: New test.

2 years agoRemove accidentally added gfortran.dg/gomp/allocate*-.f90 files
Tobias Burnus [Fri, 26 May 2023 16:13:47 +0000 (18:13 +0200)] 
Remove accidentally added gfortran.dg/gomp/allocate*-.f90 files

I looked at the commit, proof reading the commit, but missed
a <tab> in the changelog, fixing it with 'git ... --amend',
the new files sneaked in - and the auto-accept new files
without ChangeLog entry feature let it pass.

Hence, remove those bogus files again that were added
in r14-1299-g366e3d30b8d5dc2bf226696987dfbd2a7df192f5

gcc/testsuite:
* gfortran.dg/gomp/allocate-4.f90: Remove autoadded file.
* gfortran.dg/gomp/allocate-5.f90: Likewise.
* gfortran.dg/gomp/allocate-6.f90: Likewise.
* gfortran.dg/gomp/allocate-7.f90: Likewise.
* gfortran.dg/gomp/allocators-1.f90: Likewise.
* gfortran.dg/gomp/allocators-2.f90: Likewise.

2 years agoamdgcn: Change -m(no-)xnack to -mxnack=(on,off,any)
Tobias Burnus [Fri, 26 May 2023 16:07:34 +0000 (18:07 +0200)] 
amdgcn: Change -m(no-)xnack to -mxnack=(on,off,any)

Since object code target ID V4, xnack has the values unspecified, '+' and '-',
which with this commit is represented in GCC as 'any', 'on', and 'off',
following the precidence for 'sram(-)ecc' and -msram-ecc=.

The current default was 'no' and is now 'off'; however, once XNACK is
implemented, the default should be probably 'any'.

This commit updates the commandline options to permit the new tristate and
updates the documentation. As the feature itself is currently not really
supported in GCC, the change should not affect real-world users.

The XNACK feature allows memory load instructions to restart safely following
a page-miss interrupt.  This is useful for shared-memory devices, like APUs,
and to implement OpenMP Unified Shared Memory.

2023-05-26  Andrew Stubbs  <ams@codesourcery.com>
    Tobias Burnus  <tobias@codesourcery.com>

* config/gcn/gcn-hsa.h (XNACKOPT): New macro.
(ASM_SPEC): Use XNACKOPT.
* config/gcn/gcn-opts.h (enum sram_ecc_type): Rename to ...
(enum hsaco_attr_type): ... this, and generalize the names.
(TARGET_XNACK): New macro.
* config/gcn/gcn.cc (gcn_option_override): Update to sorry for all
but -mxnack=off.
(output_file_start): Update xnack handling.
(gcn_hsa_declare_function_name): Use TARGET_XNACK.
* config/gcn/gcn.opt (-mxnack): Add the "on/off/any" syntax.
(sram_ecc_type): Rename to ...
(hsaco_attr_type: ... this.)
* config/gcn/mkoffload.cc (SET_XNACK_ANY): New macro.
(TEST_XNACK): Delete.
(TEST_XNACK_ANY): New macro.
(TEST_XNACK_ON): New macro.
(main): Support the new -mxnack=on/off/any syntax.
* doc/invoke.texi (-mxnack): Update for new syntax.

2 years agogenmatch: Emit debug message right before "return x" instead of earlier
Andrew Pinski [Thu, 25 May 2023 22:08:24 +0000 (22:08 +0000)] 
genmatch: Emit debug message right before "return x" instead of earlier

This is based on the review of https://gcc.gnu.org/pipermail/gcc-patches/2023-May/619342.html .
Instead of emitting debug message even if we don't apply a pattern, this fixes the issue
by only emitting it if it the pattern finally succeeded.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

gcc/ChangeLog:

* genmatch.cc (emit_debug_printf): New function.
(dt_simplify::gen_1): Emit printf into the code
before the `return true` or returning the folded result
instead of emitting it always.

2 years agolibstdc++: Resolve -Wsign-compare issue
Matthias Kretz [Thu, 25 May 2023 08:45:21 +0000 (10:45 +0200)] 
libstdc++: Resolve -Wsign-compare issue

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
libstdc++-v3/ChangeLog:

* include/experimental/bits/simd_ppc.h (_S_bit_shift_left):
Negative __y is UB, so prefer signed compare.

2 years agoxtensa: Rework 'setmemsi' insn pattern
Takayuki 'January June' Suwa [Thu, 25 May 2023 15:08:52 +0000 (00:08 +0900)] 
xtensa: Rework 'setmemsi' insn pattern

In order to reject voodoo estimation logic with lots of magic numbers,
this patch revises the code to measure the costs of the three memset
methods based on the actual emission size of the insn sequence
corresponding to each method and choose the smallest one.

gcc/ChangeLog:

* config/xtensa/xtensa-protos.h
(xtensa_expand_block_set_unrolled_loop,
xtensa_expand_block_set_small_loop): Remove.
(xtensa_expand_block_set): New prototype.
* config/xtensa/xtensa.cc
(xtensa_expand_block_set_libcall): New subfunction.
(xtensa_expand_block_set_unrolled_loop,
xtensa_expand_block_set_small_loop): Rewrite as subfunctions.
(xtensa_expand_block_set): New function that calls the above
subfunctions.
* config/xtensa/xtensa.md (memsetsi): Change to invoke only
xtensa_expand_block_set().

2 years agoxtensa: Add 'subtraction from constant' insn pattern
Takayuki 'January June' Suwa [Thu, 25 May 2023 15:07:49 +0000 (00:07 +0900)] 
xtensa: Add 'subtraction from constant' insn pattern

This patch makes try to eliminate using temporary pseudo for
'(minus:SI (const_int) (reg:SI))' if the addition of negative constant
value can be emitted in a single machine instruction.

    /* example */
    int test0(int x) {
      return 1 - x;
    }
    int test1(int x) {
      return 100 - x;
    }
    int test2(int x) {
      return 25600 - x;
    }

    ;; before
    test0:
movi.n a9, 1
sub a2, a9, a2
ret.n
    test1:
movi a9, 0x64
sub a2, a9, a2
ret.n
    test2:
movi.n a9, 0x19
slli a9, a9, 10
sub a2, a9, a2
ret.n

    ;; after
    test0:
addi.n a2, a2, -1
neg a2, a2
ret.n
    test1:
addi a2, a2, -100
neg a2, a2
ret.n
    test2:
addmi a2, a2, -0x6400
neg a2, a2
ret.n

    gcc/ChangeLog:

* config/xtensa/xtensa-protos.h (xtensa_m1_or_1_thru_15):
New prototype.
* config/xtensa/xtensa.cc (xtensa_m1_or_1_thru_15):
New function.
* config/xtensa/constraints.md (O):
Change to use the above function.
* config/xtensa/xtensa.md (*subsi3_from_const):
New insn_and_split pattern.

2 years agoxtensa: tidy extzvsi-1bit patterns
Takayuki 'January June' Suwa [Thu, 25 May 2023 15:11:50 +0000 (00:11 +0900)] 
xtensa: tidy extzvsi-1bit patterns

gcc/ChangeLog:

* config/xtensa/xtensa.md (*extzvsi-1bit_ashlsi3):
Retract excessive line folding, and correct the value of
the "length" insn attribute related to TARGET_DENSITY.
(*extzvsi-1bit_addsubx): Ditto.

2 years agoada: Corrections to premature-references rules
Bob Duff [Wed, 29 Mar 2023 17:57:35 +0000 (13:57 -0400)] 
ada: Corrections to premature-references rules

This patch corrects the implementation of RM-8.3(17),
which says that a record extension is self-hidden until "record".
Previously, such premature references could cause a compiler crash.

gcc/ada/

* sem_ch3.adb
(Build_Derived_Record_Type): Temporarily set the state of the
Derived_Type to "self-hidden" while processing constraints
and discriminants of a record extension.

2 years agoada: Fix typos "statment" and "condtion"
Bob Duff [Wed, 29 Mar 2023 18:11:29 +0000 (14:11 -0400)] 
ada: Fix typos "statment" and "condtion"

...caused by moving code here from Atree.

gcc/ada/

* einfo.ads: Add comma.
* contracts.adb: Fix typos.
* exp_attr.adb: Likewise.
* exp_ch5.adb: Likewise.
* exp_ch6.adb: Likewise.
* lib-xref.adb: Likewise.

2 years agoada: Use truncation for dynamic conversions from floating point to fixed point
Eric Botcazou [Wed, 29 Mar 2023 10:52:57 +0000 (12:52 +0200)] 
ada: Use truncation for dynamic conversions from floating point to fixed point

This changes the implementation of dynamic conversions from floating-point
to ordinary fixed-point types, from rounding (to the nearest number) to
truncation (toward zero), so as to make them consistent with both static
conversions between these types and also the value of the Machine_Rounds
attribute, which is False for all fixed-point types with GNAT.

The rounding is still available under the debug switch -gnatd.N for the
sake of backward compatibility with the previous implementation.

gcc/ada/

* debug.adb (d.N): Document new usage.
* exp_ch4.adb (Expand_N_Type_Conversion): Copy the Float_Truncate
flag when rewriting a floating-point to fixed-point conversion as
a floating-point to integer conversion.
* exp_fixd.adb: Add with and use clauses for Debug.
(Expand_Convert_Fixed_To_Fixed): Generate a truncation in all cases
except if the result is explicitly rounded.
(Expand_Convert_Integer_To_Fixed): Likewise.
(Expand_Convert_Float_To_Fixed): Generate a truncation for all kind
of fixed-point types, except if the result is explicitly rounded, or
-gnatd.N is specified and the type is an ordinary fixed-point type.
* sinfo.ads (Float_Truncate): Document usage for floating-point to
fixed-point conversions.

2 years agoada: Crash on function returning allocated object containing tasks
Javier Miranda [Sun, 26 Mar 2023 11:45:50 +0000 (11:45 +0000)] 
ada: Crash on function returning allocated object containing tasks

The frontend crashes when a function returns an object of a
limited type that may have task components, has discriminants,
and the object is created with an allocator.

gcc/ada/

* exp_ch4.adb
(Expand_N_Allocator): If an allocator with constraints is called
in the return statement of a function returning a general access
type, then propagate to the itype the master of the general
access type (since it is the master associated with the
returned object).

2 years agoada: Default initialize entity to avoid CodePeer message
Yannick Moy [Wed, 29 Mar 2023 13:02:32 +0000 (15:02 +0200)] 
ada: Default initialize entity to avoid CodePeer message

CodePeer issues a false alarm when reading local entity Component later
if not initialized by default. Fix this.

gcc/ada/

* sem_aggr.adb (Resolve_Record_Aggregate): Add dummy initialization and
assertion that clarifies when we reassigned to a useful value.

2 years agoada: Minor doc clarification
Yannick Moy [Wed, 22 Mar 2023 09:17:54 +0000 (10:17 +0100)] 
ada: Minor doc clarification

Pattern Matching extension does not apply yet to case expressions.
This is worth stating clearly, as this is a natural use of pattern
matching to program in more functional style.

gcc/ada/

* doc/gnat_rm/gnat_language_extensions.rst: Be more explicit on
pattern matching limitation.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

2 years agoada: Complete contracts of SPARK units
Yannick Moy [Thu, 23 Mar 2023 14:45:09 +0000 (15:45 +0100)] 
ada: Complete contracts of SPARK units

SPARK units in the standard library (both Ada and GNAT ones) should have
subprograms correctly annotated with contracts, so that a SPARK subprogram
should always return (not fail or raise an exception) under the conditions
expressed in its precondition, unless it is a procedure annotated with
Might_Not_Return.

gcc/ada/

* libgnat/a-calend.ads: Mark with SPARK_Mode=>Off the functions which may
raise Time_Error.
* libgnat/a-ngelfu.ads: Mark with SPARK_Mode=>Off the functions which may
lead to an overflow (which is not the case of Tan with one parameter for
example, or Arctanh or Arcoth, despite their mathematical range covering
the reals).
* libgnat/a-textio.ads: Remove Always_Return annotation from functions, as
this is now compulsory for functions to always return in SPARK.
* libgnat/i-cstrin.ads: Add Might_Not_Return annotation to Update procedure
which may not return.

2 years agoada: Fix crash on 'Img as generic actual function
Bob Duff [Mon, 27 Mar 2023 22:07:17 +0000 (18:07 -0400)] 
ada: Fix crash on 'Img as generic actual function

'Image is allowed as an actual for a generic formal function.
This patch fixes a crash when 'Img is used instead of 'Image
in that context.

Misc cleanups.

gcc/ada/

* exp_put_image.adb (Build_Image_Call): Treat 'Img the same as
'Image.
* exp_imgv.adb (Expand_Image_Attribute): If Discard_Names, expand
to 'Image instead of 'Img.
* snames.ads-tmpl, par-ch4.adb, sem_attr.adb, sem_attr.ads:
Cleanups: Rename Attribute_Class_Array to be Attribute_Set. Remove
unnecessary qualifications. DRY: Don't repeat "True".

2 years agoada: Remove redundant guard against empty lists
Piotr Trojanek [Wed, 29 Mar 2023 07:36:39 +0000 (09:36 +0200)] 
ada: Remove redundant guard against empty lists

There is no need to guard against routine Contains being called on
No_Elist, because it will return False. Code cleanup related to handling
of primitive operations in GNATprove; semantics is unaffected.

gcc/ada/

* sem_prag.adb (Record_Possible_Body_Reference): Remove call to Present.
* sem_util.adb (Find_Untagged_Type_Of): Likewise.

2 years agoada: Fix double free on finalization of Vector in array aggregate
Eric Botcazou [Sun, 26 Mar 2023 22:55:08 +0000 (00:55 +0200)] 
ada: Fix double free on finalization of Vector in array aggregate

The handling of finalization is delicate during the expansion of aggregates
since the generated assignments must not cause the finalization of the RHS.
That's why the No_Ctrl_Actions flag is set on them and the adjustments are
generated manually.

This was not done in the case of an array of array with controlled component
when its subaggregates are not expanded in place but instead are replaced by
temporaries, leading to double free or memory corruption.

gcc/ada/

* exp_aggr.adb (Initialize_Array_Component): Remove obsolete code.
(Expand_Array_Aggregate): In the case where a temporary is created
and the parent is an assignment statement with No_Ctrl_Actions set,
set Is_Ignored_Transient on the temporary.

2 years agoada: Fix internal error on Big_Integer conversion ghost instance
Eric Botcazou [Sat, 25 Mar 2023 20:42:11 +0000 (21:42 +0100)] 
ada: Fix internal error on Big_Integer conversion ghost instance

The problem is that the ghost mode of the instance is used to analyze the
parent of the generic body, whose own ghost mode has nothing to do with it.

gcc/ada/

* sem_ch12.adb (Instantiate_Package_Body): Set the ghost mode to
that of the instance only after loading the generic's parent.
(Instantiate_Subprogram_Body): Likewise.

2 years agoada: Simplify expansion of set membership
Piotr Trojanek [Fri, 24 Mar 2023 17:09:48 +0000 (18:09 +0100)] 
ada: Simplify expansion of set membership

Code cleanup; semantics is unaffected.

gcc/ada/

* exp_ch4.adb (Expand_Set_Membership): Simplify by using Evolve_Or_Else.

2 years agoada: Cleanup expansion of membership operators into attribute Valid
Piotr Trojanek [Thu, 23 Mar 2023 20:00:54 +0000 (21:00 +0100)] 
ada: Cleanup expansion of membership operators into attribute Valid

Code cleanup; semantics is unaffected.

gcc/ada/

* exp_ch4.adb (Is_OK_Object_Reference): Replace loop with a call to
Unqual_Conv; consequently, change object from variable to constant;
replace an IF statement with an AND THEN expression.

2 years agoada: Remove leftover code for counting protected entries
Piotr Trojanek [Thu, 23 Mar 2023 19:15:19 +0000 (20:15 +0100)] 
ada: Remove leftover code for counting protected entries

We used to count protected entries by iterating over component
declarations, but then switched to iterating over entities and
left some code that is no longer needed. Cleanup; semantics is
unaffected (maybe except fixing an assertion failure in developer
builds when there is pragma among entry family declarations).

gcc/ada/

* exp_ch9.adb
(Build_Entry_Count_Expression): Remove loop over component declaration;
consequently remove a parameter that is no longer used; adapt callers.
(Make_Task_Create_Call): Refine type of a local variable.

2 years agoada: Fix detection of non-static expressions in records with pragmas
Piotr Trojanek [Thu, 23 Mar 2023 17:46:08 +0000 (18:46 +0100)] 
ada: Fix detection of non-static expressions in records with pragmas

When iterating over record components we must ignore pragmas.
Minor bug, as pragmas within record components do not appear often.

gcc/ada/

* sem_cat.adb (Check_Non_Static_Default_Expr): Detect components inside
loop, not in the loop condition itself.

2 years agoada: Reorder components in Ada.Containers.Bounded_Doubly_Linked_Lists
Eric Botcazou [Thu, 23 Mar 2023 14:55:15 +0000 (15:55 +0100)] 
ada: Reorder components in Ada.Containers.Bounded_Doubly_Linked_Lists

gcc/ada/

* libgnat/a-cbdlli.ads (List): Move Nodes component to the end.

2 years agoada: Reorder components in Ada.Containers.Restricted_Doubly_Linked_Lists
Eric Botcazou [Thu, 23 Mar 2023 13:35:57 +0000 (14:35 +0100)] 
ada: Reorder components in Ada.Containers.Restricted_Doubly_Linked_Lists

An instantiation of the package compiled with -gnatw.q yields:
  warning: in instantiation at a-crdlli.ads:317 [-gnatw.q]
  warning: record layout may cause performance issues [-gnatw.q]
  warning: in instantiation at a-crdlli.ads:317 [-gnatw.q]
  warning:
       component "Nodes" whose length depends on a discriminant [-gnatw.q]
  warning: in instantiation at a-crdlli.ads:317 [-gnatw.q]
  warning: comes too early and was moved down [-gnatw.q]

gcc/ada/

* libgnat/a-crdlli.ads (List): Move Nodes component to the end.

2 years agoada: Reject thin 'Unrestricted_Access value to aliased constrained array
Eric Botcazou [Sun, 5 Mar 2023 17:30:34 +0000 (18:30 +0100)] 
ada: Reject thin 'Unrestricted_Access value to aliased constrained array

This rejects the Unrestricted_Access attribute applied to an aliased array
with a constrained nominal subtype when its type is resolved to be a thin
pointer.  The reason is that supporting this case would require the aliased
array to contain its bounds, and this is the case only for aliased arrays
whose nominal subtype is unconstrained.

gcc/ada/

* sem_attr.adb (Is_Thin_Pointer_To_Unc_Array): New predicate.
(Resolve_Attribute): Apply the static matching legality rule to an
Unrestricted_Access attribute applied to an aliased prefix if the
type is a thin pointer.  Call Is_Thin_Pointer_To_Unc_Array for the
aliasing legality rule as well.

2 years agoada: Simplify iteration over record component items with possible pragmas
Piotr Trojanek [Mon, 20 Mar 2023 19:30:09 +0000 (20:30 +0100)] 
ada: Simplify iteration over record component items with possible pragmas

Code cleanup; semantics is unaffected.

gcc/ada/

* sem_util.adb (Is_Null_Record_Definition): Use First_Non_Pragma and
Next_Non_Pragma to ignore pragmas within component list.

2 years agoada: Fix handling of Global contracts inside generic subprograms
Piotr Trojanek [Tue, 5 Oct 2021 13:29:44 +0000 (15:29 +0200)] 
ada: Fix handling of Global contracts inside generic subprograms

Routine Get_Argument works differently for generic units (as explained
in its comment), but it failed to reliably detect such units when their
kind is temporarily made non-generic (for resolving recursive calls, as
explained in the comment at the end of Is_Generic_Declaration_Or_Body).

With this patch the frontend will look at the decorated expression of
the Global contract attached to the Global aspect; previously it was
looking at the undecorated expression attached to the corresponding
pragma.

gcc/ada/

* sem_prag.adb (Get_Argument): Improve detection of generic units.

2 years agoada: Tune detection of expression functions within a declare expression
Piotr Trojanek [Wed, 1 Feb 2023 19:41:49 +0000 (20:41 +0100)] 
ada: Tune detection of expression functions within a declare expression

Code cleanup; semantics is unaffected.

gcc/ada/

* sem_ch4.adb (Check_Action_OK): Replace low-level test with a
high-level routine.
* sem_ch13.adb (Is_Predicate_Static): Likewise.

2 years agoada: Crash on loop in dispatching conditional entry call
Javier Miranda [Mon, 20 Mar 2023 19:24:17 +0000 (19:24 +0000)] 
ada: Crash on loop in dispatching conditional entry call

gcc/ada/

* exp_ch9.adb
(Expand_N_Conditional_Entry_Call): Factorize code to avoid
duplicating subtrees; required to avoid problems when the copied
code has implicit labels.
* sem_util.ads (New_Copy_Separate_List): Removed.
(New_Copy_Separate_Tree): Removed.
* sem_util.adb (New_Copy_Separate_List): Removed.
(New_Copy_Separate_Tree): Removed.

2 years agoada: Remove redundant protection against empty lists
Piotr Trojanek [Tue, 21 Mar 2023 09:29:39 +0000 (10:29 +0100)] 
ada: Remove redundant protection against empty lists

Calls to Length on No_List intentionally return 0, so explicit guards
against No_List are unnecessary. Code cleanup; semantics is unaffected.

gcc/ada/

* sem_ch13.adb (Check_Component_List): Local variable Compl is now
a constant; a nested block is no longer needed.

2 years agoada: Cleanups in handling of aggregates
Piotr Trojanek [Fri, 17 Mar 2023 13:10:03 +0000 (14:10 +0100)] 
ada: Cleanups in handling of aggregates

Assorted cleanups related to recent fixes of aggregate handling for
GNATprove; semantics is unaffected.

gcc/ada/

* sem_aggr.adb
(Resolve_Record_Aggregate): Remove useless assignment.
* sem_aux.adb
(Has_Variant_Part): Remove useless guard; this routine is only called
on type entities (and now will crash in other cases).
* sem_ch3.adb
(Create_Constrained_Components): Only assign Assoc_List when necessary;
tune whitespace.
(Is_Variant_Record): Refactor repeated calls to Parent.
* sem_util.adb
(Gather_Components): Assert that discriminant association has just one
choice in component_association; refactor repeated calls to Next.
* sem_util.ads
(Gather_Components): Tune whitespace in comment.

2 years agoada: Fix iteration over component items with pragmas
Piotr Trojanek [Tue, 21 Mar 2023 08:46:57 +0000 (09:46 +0100)] 
ada: Fix iteration over component items with pragmas

Component items in a record declaration might include pragmas, which
must be ignored when detecting components with default expressions.

More a code cleanup than a bugfix, as it only affects artificial corner
cases. Found while fixing missing legality checks for variant component
declarations.

gcc/ada/

* sem_ch3.adb (Check_CPP_Type_Has_No_Defaults): Iterate with
First_Non_Pragma and Next_Non_Pragma.
* exp_dist.adb (Append_Record_Traversal): Likewise.

2 years agoada: Duplicate declaration of _master entity
Javier Miranda [Tue, 14 Mar 2023 20:46:34 +0000 (20:46 +0000)] 
ada: Duplicate declaration of _master entity

gcc/ada/

* exp_ch9.adb (Build_Class_Wide_Master): Remember internal blocks
that have a task master entity declaration.
(Build_Master_Entity): Code cleanup.
* sem_util.ads (Is_Internal_Block): New subprogram.
* sem_util.adb (Is_Internal_Block): New subprogram.

2 years agoada: Remove redundant guards from handling of record components
Piotr Trojanek [Fri, 17 Mar 2023 13:10:32 +0000 (14:10 +0100)] 
ada: Remove redundant guards from handling of record components

Call to First on empty list is intentionally returning Empty.

gcc/ada/

* sem_util.adb (Gather_Components): Remove guard for empty list of
components.

2 years agoada: Remove Is_Descendant_Of_Address flag from Standard_Address
Eric Botcazou [Sat, 18 Mar 2023 23:24:54 +0000 (00:24 +0100)] 
ada: Remove Is_Descendant_Of_Address flag from Standard_Address

It breaks the Allow_Integer_Address special mode.

Add new standard_address parameters to gigi and alphabetize others, this is
necessary when addresses are not treated like integers.

gcc/ada/

* back_end.adb (Call_Back_End): Add gigi_standard_address to the
signature of the gigi procedure and alphabetize other parameters.
Pass Standard_Address as actual parameter for it.
* cstand.adb (Create_Standard): Do not set Is_Descendant_Of_Address
on Standard_Address.
* gcc-interface/gigi.h (gigi): Add a standard_address parameter and
alphabetize others.
* gcc-interface/trans.cc (gigi): Likewise.  Record a builtin address
type and save it as the type for Standard.Address.

2 years agoada: Handle new Controlling_Tag format when converting to SCIL
Ghjuvan Lacambre [Thu, 23 Feb 2023 14:20:54 +0000 (15:20 +0100)] 
ada: Handle new Controlling_Tag format when converting to SCIL

This commit fixes two CodePeer crashes that were introduced when the
format of the controlling tag changed.

gcc/ada/

* exp_disp.adb (Expand_Dispatching_Call): Handle new Controlling_Tag.
* sem_scil.adb (Check_SCIL_Node): Treat N_Object_Renaming_Declaration as
N_Object_Declaration.

2 years agoada: Use context variables in expansion of aggregates
Piotr Trojanek [Thu, 16 Mar 2023 09:39:37 +0000 (10:39 +0100)] 
ada: Use context variables in expansion of aggregates

Code cleanup; semantics is unaffected.

gcc/ada/

* exp_aggr.adb
(Build_Constrained_Type): Remove local constants that were shadowing
equivalent global constants; replace a wrapper that calls
Make_Integer_Literal with a numeric literal; remove explicit
Aliased_Present parameter which is equivalent to the default value.
(Check_Bounds): Remove unused initial value.
(Expand_Array_Aggregate): Use aggregate type from the context.

2 years agoada: Fix missing finalization in library-level instance body
Eric Botcazou [Fri, 3 Mar 2023 19:34:09 +0000 (20:34 +0100)] 
ada: Fix missing finalization in library-level instance body

This extends the delaying mechanism present in the cases where the instance
is not at library level, so as to wait until after the instantiation of the
body is performed, before generating the finalizer of the compilation unit.

gcc/ada/

* einfo.ads (Delay_Cleanups): Document new usage.
* exp_ch7.ads (Build_Finalizer): New declaration.
* exp_ch7.adb (Build_Finalizer.Process_Declarations): Do not treat
library-level package instantiations specially.
(Build_Finalizer): Return early for package bodies and specs that
are not compilation units instead of using a more convoluted test.
(Expand_N_Package_Body): Do not build a finalizer if Delay_Cleanups
is set on the defining entity.
(Expand_N_Package_Declaration): Likewise.
* inline.ads (Pending_Body_Info): Reorder and add Fin_Scop.
(Add_Pending_Instantiation): Add Fin_Scop parameter.
* inline.adb (Add_Pending_Instantiation): Likewise and copy it into
the Pending_Body_Info appended to Pending_Instantiations.
(Add_Scope_To_Clean): Change parameter name to Scop and remove now
irrelevant processing.
(Cleanup_Scopes): Deal with scopes that are package specs or bodies.
(Instantiate_Body): For package instantiations, deal specially with
scopes that are package bodies and with scopes that are dynamic.
Pass the resulting scope to Add_Scope_To_Clean directly.
* sem_ch12.adb (Analyze_Package_Instantiation): In the case where a
body is needed, compute the enclosing finalization scope and pass it
in the call to Add_Pending_Instantiation.
(Inline_Instance_Body): Adjust aggregate passed in the calls to
Instantiate_Package_Body.
(Load_Parent_Of_Generic): Likewise.

2 years agoada: Minor tweak in condition
Eric Botcazou [Thu, 16 Mar 2023 17:38:20 +0000 (18:38 +0100)] 
ada: Minor tweak in condition

gcc/ada/

* sem_util.adb (Compile_Time_Constraint_Error): Test the Ekind.

2 years agoada: Simplify expansion of positional aggregates
Piotr Trojanek [Thu, 16 Mar 2023 09:36:20 +0000 (10:36 +0100)] 
ada: Simplify expansion of positional aggregates

Code cleanup; semantics is unaffected.

gcc/ada/

* exp_aggr.adb (Build_Constrained_Type): Use List_Length to count
expressions in consecutive subaggregates.

2 years agoada: Use computed value from os_constants to define sigset_t
Doug Rupp [Thu, 9 Mar 2023 06:24:18 +0000 (22:24 -0800)] 
ada: Use computed value from os_constants to define sigset_t

Remove hard coded definition and conform to standard usage of using
computed os_constants for opaque type declarations.

gcc/ada/

* libgnarl/s-osinte__qnx.ads (sigset_t): Modify
declaration to use system.os_constants computed
value. Align it.

2 years agoada: Fix another couple of unchecked conversions to Ada.Tags.Tag
Eric Botcazou [Wed, 15 Mar 2023 12:56:33 +0000 (13:56 +0100)] 
ada: Fix another couple of unchecked conversions to Ada.Tags.Tag

They are problematic on platforms where the provenance of pointers must be
tracked throughout their lifetime.

gcc/ada/

* exp_sel.adb: Add clauses for Sem_Util, remove them for Opt, Sinfo
and Sinfo.Nodes.
(Build_K): Always use 'Tag of the object.
(Build_S_Assignment): Likewise.

2 years agoada: Refine types for an accessibility-checking routine
Piotr Trojanek [Wed, 1 Feb 2023 20:47:32 +0000 (21:47 +0100)] 
ada: Refine types for an accessibility-checking routine

Code cleanup related to work on expression functions for GNATprove
(which require accessibility checks even when they are not expanded
and thus have no explicit return statements).

gcc/ada/

* accessibility.adb
(Is_Formal_Of_Current_Function): This routine expects an entity
reference and not the entity itself, so its parameter is a Node_Id
and not an Entity_Id.

2 years agoada: Clean style in expansion of array aggregates
Piotr Trojanek [Mon, 13 Mar 2023 11:26:09 +0000 (12:26 +0100)] 
ada: Clean style in expansion of array aggregates

Code cleanup only; semantics is unaffected.

gcc/ada/

* exp_aggr.adb
(Build_Array_Aggr_Code): Change variable to constant.
(Check_Same_Aggr_Bounds): Fix style; remove unused initial value.

2 years agoada: Fix late extra formals creation
Ronan Desplanques [Tue, 14 Mar 2023 09:01:06 +0000 (10:01 +0100)] 
ada: Fix late extra formals creation

Before this patch, in some situations, a subprogram call could be
expanded before the extra formals for the subprogram were created.

This patch fixes the problem in those situations.

gcc/ada/

* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Create extra formals
in more situations.

2 years agoada: Add missing guards in Selected_Range_Checks
Eric Botcazou [Tue, 14 Mar 2023 11:42:53 +0000 (12:42 +0100)] 
ada: Add missing guards in Selected_Range_Checks

gcc/ada/

* checks.adb (Selected_Range_Checks): Add guards to protect calls
to Expr_Value on bounds.

2 years agoada: Enhance Is_Null_Range and Not_Null_Range predicates
Eric Botcazou [Mon, 13 Mar 2023 11:03:47 +0000 (12:03 +0100)] 
ada: Enhance Is_Null_Range and Not_Null_Range predicates

Both predicates bail out if the bounds of the range are not known at compile
time, whereas Compile_Time_Compare can deal with them in specific cases.

gcc/ada/

* sem_eval.ads (Is_Null_Range): Remove requirements of compile-time
known bounds and add WARNING line.
(Not_Null_Range): Remove requirements of compile-time known bounds.
* sem_eval.adb (Is_Null_Range): Fall back to Compile_Time_Compare.
(Not_Null_Range): Likewise.
* fe.h (Is_Null_Range): New predicate.

2 years agoi386: Do not disable call to ix86_expand_vecop_qihi2
Uros Bizjak [Fri, 26 May 2023 05:30:24 +0000 (07:30 +0200)] 
i386: Do not disable call to ix86_expand_vecop_qihi2

gcc/ChangeLog:

* config/i386/i386-expand.cc (ix86_expand_vecop_qihi):
Do not disable call to ix86_expand_vecop_qihi2.

2 years agoOnly use NO_REGS in cost calculation when !hard_regno_mode_ok for GENERAL_REGS and...
liuhongt [Tue, 16 May 2023 02:36:16 +0000 (10:36 +0800)] 
Only use NO_REGS in cost calculation when !hard_regno_mode_ok for GENERAL_REGS and mode.

r14-172-g0368d169492017 replaces GENERAL_REGS with NO_REGS in cost
calculation when the preferred register class are not known yet.
It regressed powerpc PR109610 and PR109858, it looks too aggressive to use
NO_REGS when mode can be allocated with GENERAL_REGS.
The patch takes a step back, still use GENERAL_REGS when
hard_regno_mode_ok for mode and GENERAL_REGS, otherwise uses NO_REGS.

gcc/ChangeLog:

PR target/109610
PR target/109858
* ira-costs.cc (scan_one_insn): Only use NO_REGS in cost
calculation when !hard_regno_mode_ok for GENERAL_REGS and
mode, otherwise still use GENERAL_REGS.

2 years agoRISC-V: Fix zero-scratch-regs-3.c fail
Juzhe-Zhong [Fri, 26 May 2023 00:59:29 +0000 (08:59 +0800)] 
RISC-V: Fix zero-scratch-regs-3.c fail

gcc/ChangeLog:

* config/riscv/riscv.cc (vector_zero_call_used_regs): Add
explict VL and drop VL in ops.

Signed-off-by: Juzhe-Zhong <juzhe.zhong@rivai.ai>
2 years agoDaily bump.
GCC Administrator [Fri, 26 May 2023 00:17:04 +0000 (00:17 +0000)] 
Daily bump.

2 years agolibstdc++: Add relational operators to __gnu_test::PointerBase
Jonathan Wakely [Thu, 25 May 2023 20:17:19 +0000 (21:17 +0100)] 
libstdc++: Add relational operators to __gnu_test::PointerBase

The Cpp17Allocator requirements say that an allocator's pointer and
const_pointer types must meet the Cpp17RandomAccessIterator
requirements. That means our PointerBase helper for defining fancy
pointer types should support the full set of relational operators.

libstdc++-v3/ChangeLog:

* testsuite/util/testsuite_allocator.h (PointerBase): Add
relational operators.

2 years agotestsuite: Require trampolines for nestev-vla tests
Dimitar Dimitrov [Thu, 25 May 2023 04:57:21 +0000 (07:57 +0300)] 
testsuite: Require trampolines for nestev-vla tests

gcc/testsuite/ChangeLog:

* gcc.dg/nested-vla-1.c: Require effective target trampolines.
* gcc.dg/nested-vla-2.c: Ditto.
* gcc.dg/nested-vla-3.c: Ditto.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2 years agoIn pipeline scheduling, insns should not be fusion in different BB blocks.
Jin Ma [Thu, 25 May 2023 17:55:26 +0000 (11:55 -0600)] 
In pipeline scheduling, insns should not be fusion in different BB blocks.

gcc/ChangeLog:

* sched-deps.cc (sched_macro_fuse_insns): Insns should not be fusion
in different BB blocks.

2 years agoi386: Use 2x-wider modes when emulating QImode vector instructions
Uros Bizjak [Thu, 25 May 2023 17:40:26 +0000 (19:40 +0200)] 
i386: Use 2x-wider modes when emulating QImode vector instructions

Rewrite ix86_expand_vecop_qihi2 to expand fo 2x-wider (e.g. V16QI -> V16HImode)
instructions when available.  Currently, the compiler generates following
assembly for V16QImode multiplication (-mavx2):

vpunpcklbw      %xmm0, %xmm0, %xmm3
vpunpcklbw      %xmm1, %xmm1, %xmm2
vpunpckhbw      %xmm0, %xmm0, %xmm0
movl    $255, %eax
vpunpckhbw      %xmm1, %xmm1, %xmm1
vpmullw %xmm3, %xmm2, %xmm2
vmovd   %eax, %xmm3
vpmullw %xmm0, %xmm1, %xmm1
vpbroadcastw    %xmm3, %xmm3
vpand   %xmm2, %xmm3, %xmm0
vpand   %xmm1, %xmm3, %xmm3
vpackuswb       %xmm3, %xmm0, %xmm0

and only with -mavx512bw -mavx512vl generates:

vpmovzxbw       %xmm1, %ymm1
vpmovzxbw       %xmm0, %ymm0
vpmullw %ymm1, %ymm0, %ymm0
vpmovwb %ymm0, %xmm0

Patched compiler generates more optimized code involving multiplication
in 2x-wider mode in cases where missing truncate instruction has to be
emulated with a permutation (-mavx2):

vpmovzxbw       %xmm0, %ymm0
vpmovzxbw       %xmm1, %ymm1
movl    $255, %eax
vpmullw %ymm1, %ymm0, %ymm1
vmovd   %eax, %xmm0
vpbroadcastw    %xmm0, %ymm0
vpand   %ymm1, %ymm0, %ymm0
vpackuswb       %ymm0, %ymm0, %ymm0
vpermq  $216, %ymm0, %ymm0

The patch also adjusts cost calculation of V*QImode emulations to account
for generation of 2x-wider mode instructions.

gcc/ChangeLog:

* config/i386/i386-expand.cc (ix86_expand_vecop_qihi2):
Rewrite to expand to 2x-wider (e.g. V16QI -> V16HImode)
instructions when available.  Emulate truncation via
ix86_expand_vec_perm_const_1 when native truncate insn
is not available.
(ix86_expand_vecop_qihi_partial) <case MULT>: Use pmovzx
when available.  Trivially rename some variables.
(ix86_expand_vecop_qihi): Unconditionally call ix86_expand_vecop_qihi2.
* config/i386/i386.cc (ix86_multiplication_cost): Rewrite cost
calculation of V*QImode emulations to account for generation of
2x-wider mode instructions.
(ix86_shift_rotate_cost): Update cost calculation of V*QImode
emulations to account for generation of 2x-wider mode instructions.

gcc/testsuite/ChangeLog:

* gcc.target/i386/avx512vl-pr95488-1.c: Revert 2023-05-18 change.

2 years agotarget/104327: Allow more inlining between different optimization levels.
Georg-Johann Lay [Tue, 23 May 2023 12:54:12 +0000 (14:54 +0200)] 
target/104327: Allow more inlining between different optimization levels.

avr-common.cc introduces the following options that are set depending
on optimization level: -mgas-isr-prologues, -mmain-is-OS-task and
-fsplit-wide-types-early.  The inliner thinks that different options
disallow cross-optimization inlining, so provide can_inline_p.

gcc/
PR target/104327
* config/avr/avr.cc (avr_can_inline_p): New static function.
(TARGET_CAN_INLINE_P): Define to that function.

2 years agotarget/82931: Make a pattern more generic to match more bit-transfers.
Georg-Johann Lay [Thu, 25 May 2023 17:02:34 +0000 (19:02 +0200)] 
target/82931: Make a pattern more generic to match more bit-transfers.

There is already a pattern in avr.md that matches single-bit transfers
from one register to another one, but it only handled bit 0 of 8-bit
registers.  This change makes that pattern more generic so it matches
more of similar single-bit transfers.

gcc/
PR target/82931
* config/avr/avr.md (*movbitqi.0): Rename to *movbit<mode>.0-6.
Handle any bit position and use mode QISI.
* config/avr/avr.cc (avr_rtx_costs_1) [IOR]: Return a cost
of 2 insns for bit-transfer of respective style.

gcc/testsuite/
PR target/82931
* gcc.target/avr/pr82931.c: New test.

2 years agoarm: merge MVE_5 and MVE_6 iterators
Christophe Lyon [Thu, 25 May 2023 12:19:52 +0000 (12:19 +0000)] 
arm: merge MVE_5 and MVE_6 iterators

MVE_5 and MVE_6 iterators are the same: this patch replaces MVE_6 with
MVE_5 everywhere in mve.md and removes MVE_6 from iterators.md.

2023-05-25  Christophe Lyon <christophe.lyon@linaro.org>

gcc/
* config/arm/iterators.md (MVE_6): Remove.
* config/arm/mve.md: Replace MVE_6 with MVE_5.

2 years agoVECT: Add decrement IV iteration loop control by variable amount support
Ju-Zhe Zhong [Thu, 25 May 2023 14:42:35 +0000 (22:42 +0800)] 
VECT: Add decrement IV iteration loop control by variable amount support

This patch is supporting decrement IV by following the flow designed by
Richard:

(1) In vect_set_loop_condition_partial_vectors, for the first iteration of:
    call vect_set_loop_controls_directly.

(2) vect_set_loop_controls_directly calculates "step" as in your patch.
If rgc has 1 control, this step is the SSA name created for that
control.  Otherwise the step is a fresh SSA name, as in your patch.

(3) vect_set_loop_controls_directly stores this step somewhere for later
use, probably in LOOP_VINFO.  Let's use "S" to refer to this stored
step.

(4) After the vect_set_loop_controls_directly call above, and outside
the "if" statement that now contains vect_set_loop_controls_directly,
check whether rgc->controls.length () > 1.  If so, use
vect_adjust_loop_lens_control to set the controls based on S.

Then the only caller of vect_adjust_loop_lens_control is
vect_set_loop_condition_partial_vectors.  And the starting
step for vect_adjust_loop_lens_control is always S.

This patch has well tested for single-rgroup and multiple-rgroup (SLP)
and passed all testcase in RISC-V port.

Signed-off-by: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
Co-Authored-By: Richard Sandiford <richard.sandiford@arm.com>
gcc/ChangeLog:

* tree-vect-loop-manip.cc (vect_adjust_loop_lens_control): New
function.
(vect_set_loop_controls_directly): Add decrement IV support.
(vect_set_loop_condition_partial_vectors): Ditto.
* tree-vect-loop.cc (_loop_vec_info::_loop_vec_info): New
variable.
* tree-vectorizer.h (LOOP_VINFO_USING_DECREMENTING_IV_P): New
macro.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/partial/multiple_rgroup-3.c: New test.
* gcc.target/riscv/rvv/autovec/partial/multiple_rgroup-4.c: New test.
* gcc.target/riscv/rvv/autovec/partial/multiple_rgroup_run-3.c: New test.
* gcc.target/riscv/rvv/autovec/partial/multiple_rgroup_run-4.c: New test.

2 years agoaarch64: PR target/99195 Annotate complex FP patterns for vec-concat-zero
Kyrylo Tkachov [Thu, 25 May 2023 14:00:16 +0000 (15:00 +0100)] 
aarch64: PR target/99195 Annotate complex FP patterns for vec-concat-zero

This patch annotates the complex add and mla patterns for vec-concat-zero.
Testing showed an interesting bug in our MD patterns where they were defined to match:
(plus:VHSDF (match_operand:VHSDF 1 "register_operand" "0")
    (unspec:VHSDF [(match_operand:VHSDF 2 "register_operand" "w")
   (match_operand:VHSDF 3 "register_operand" "w")
   (match_operand:SI 4 "const_int_operand" "n")]
   FCMLA))

but the canonicalisation rules for PLUS require the more "complex" operand to be first so
during combine when the new substituted patterns were attempted to be formed combine/recog would
try to match:
(plus:V2SF (unspec:V2SF [
                        (reg:V2SF 100)
                        (reg:V2SF 101)
                        (const_int 0 [0])
                    ] UNSPEC_FCMLA270)
                (reg:V2SF 99))
instead. This patch fixes the operands of the PLUS RTX in these patterns.
Similar patterns for the dot-product instructions already used the right order.

Bootstrapped and tested on aarch64-none-linux-gnu and aarch64_be-none-elf.

gcc/ChangeLog:

PR target/99195
* config/aarch64/aarch64-simd.md (aarch64_fcadd<rot><mode>): Rename to...
(aarch64_fcadd<rot><mode><vczle><vczbe>): ... This.
Fix canonicalization of PLUS operands.
(aarch64_fcmla<rot><mode>): Rename to...
(aarch64_fcmla<rot><mode><vczle><vczbe>): ... This.
Fix canonicalization of PLUS operands.
(aarch64_fcmla_lane<rot><mode>): Rename to...
(aarch64_fcmla_lane<rot><mode><vczle><vczbe>): ... This.
Fix canonicalization of PLUS operands.
(aarch64_fcmla_laneq<rot>v4hf): Rename to...
(aarch64_fcmla_laneq<rot>v4hf<vczle><vczbe>): ... This.
Fix canonicalization of PLUS operands.
(aarch64_fcmlaq_lane<rot><mode>): Fix canonicalization of PLUS operands.

gcc/testsuite/ChangeLog:

PR target/99195
* gcc.target/aarch64/simd/pr99195_9.c: New test.

2 years agoarm: Implement ACLE Data Intrinsics
Chris Sidebottom [Thu, 25 May 2023 13:57:34 +0000 (14:57 +0100)] 
arm: Implement ACLE Data Intrinsics

This patch implements a number of scalar data processing intrinsics from ACLE
that were requested by some users. Some of these have fast single-instruction
sequences for Armv6 and later, but even for earlier versions they can still emit
an inline sequence or a call to libgcc (and ACLE recommends them being unconditionally
available).

Chris Sidebottom wrote most of the patch, I just cleaned it up, wired up some builtins
and adjusted the tests.

Bootstrapped and tested on arm-none-linux-gnueabihf.

Co-authored-by: Chris Sidebottom <chris.sidebottom@arm.com>
gcc/ChangeLog:

* config/arm/arm.md (rbitsi2): Rename to...
(arm_rbit): ... This.
(ctzsi2): Adjust for the above.
(arm_rev16si2): Convert to define_expand.
(arm_rev16si2_alt1): New pattern.
(arm_rev16si2_alt): Rename to...
(*arm_rev16si2_alt2): ... This.
* config/arm/arm_acle.h (__ror, __rorl, __rorll, __clz, __clzl, __clzll,
__cls, __clsl, __clsll, __revsh, __rev, __revl, __revll, __rev16,
__rev16l, __rev16ll, __rbit, __rbitl, __rbitll): Define intrinsics.
* config/arm/arm_acle_builtins.def (rbit, rev16si2): Define builtins.

gcc/testsuite/ChangeLog:

* gcc.target/arm/acle/data-intrinsics-armv6.c: New test.
* gcc.target/arm/acle/data-intrinsics-assembly.c: New test.
* gcc.target/arm/acle/data-intrinsics-rbit.c: New test.
* gcc.target/arm/acle/data-intrinsics.c: New test.

2 years agoarm: Fix ICE due to infinite splitting [PR109800]
Alex Coplan [Thu, 25 May 2023 12:34:46 +0000 (13:34 +0100)] 
arm: Fix ICE due to infinite splitting [PR109800]

In r11-966-g9a182ef9ee011935d827ab5c6c9a7cd8e22257d8 we introduce a
simplification to emit_move_insn that attempts to simplify moves of the form:

(set (subreg:M1 (reg:M2 ...)) (constant C))

where M1 and M2 are of equal mode size. That is problematic for the splitter
vfp.md:no_literal_pool_df_immediate in the arm backend, which tries to pun an
lvalue DFmode pseudo into DImode and assign a constant to it with
emit_move_insn, as the new transformation simply undoes this, and we end up
splitting indefinitely.

This patch changes things around in the arm backend so that we use a
DImode temporary (instead of DFmode) and first load the DImode constant
into the pseudo, and then pun the pseudo into DFmode as an rvalue in a
reg -> reg move. I believe this should be semantically equivalent but
avoids the pathalogical behaviour seen in the PR.

gcc/ChangeLog:

PR target/109800
* config/arm/arm.md (movdf): Generate temporary pseudo in DImode
instead of DFmode.
* config/arm/vfp.md (no_literal_pool_df_immediate): Rather than punning an
lvalue DFmode pseudo into DImode, use a DImode pseudo and pun it into
DFmode as an rvalue.

gcc/testsuite/ChangeLog:

PR target/109800
* gcc.target/arm/pure-code/pr109800.c: New test.

2 years agotarget/109955 - handle pattern generated COND_EXPR without vcond
Richard Biener [Thu, 25 May 2023 10:55:11 +0000 (12:55 +0200)] 
target/109955 - handle pattern generated COND_EXPR without vcond

The following properly handles pattern matching generated COND_EXPRs
which can still have embedded compares in vectorizable_condition
which will always code generate the masked vector variant.  We
were requiring vcond with embedded comparisons instead of also
allowing (as code generated) split compare and VEC_COND_EXPR.

This fixes some of the fallout when removing vcond{,u,eq} expanders
from the x86 backend.

PR target/109955
* tree-vect-stmts.cc (vectorizable_condition): For
embedded comparisons also handle the case when the target
only provides vec_cmp and vcond_mask.

2 years agoarc: Make TLS Local Dynamic work like Global Dynamic model
Claudiu Zissulescu [Thu, 25 May 2023 09:53:14 +0000 (12:53 +0300)] 
arc: Make TLS Local Dynamic work like Global Dynamic model

Current ARC's TLS Local Dynamic model is using two anchors to access
data, namely `.tdata` and `.tbss`. This implementation is unnecessary
complicated. However, the TLS Local Dynamic model has better results
using Global Dynamic model and anchors.

gcc/ChangeLog;

* config/arc/arc.cc (arc_call_tls_get_addr): Simplify access using
TLS Local Dynamic.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2 years ago[aarch64] Ignore cost of scalar moves for seq in vector initialization.
Prathamesh Kulkarni [Thu, 25 May 2023 09:53:57 +0000 (15:23 +0530)] 
[aarch64] Ignore cost of scalar moves for seq in vector initialization.

gcc/ChangeLog:
* config/aarch64/aarch64.cc (scalar_move_insn_p): New function.
(seq_cost_ignoring_scalar_moves): Likewise.
(aarch64_expand_vector_init): Call seq_cost_ignoring_scalar_moves.

2 years agoaarch64: Implement vector FP absolute compare intrinsics with builtins
Kyrylo Tkachov [Thu, 25 May 2023 08:48:33 +0000 (09:48 +0100)] 
aarch64: Implement vector FP absolute compare intrinsics with builtins

While optimising some vector math library code with intrinsics we stumbled upon the issue in the testcase.
The compiler should be generating a FACGT instruction but instead we generate:
foo(__Float32x4_t, __Float32x4_t, __Float32x4_t):
        fabs    v0.4s, v0.4s
        adrp    x0, .LC0
        ldr     q31, [x0, #:lo12:.LC0]
        fcmgt   v0.4s, v0.4s, v31.4s
        ret

This is because the vcagtq_f32 intrinsic is open-coded in arm_neon.h as
return vabsq_f32 (__a) > vabsq_f32 (__b)
thus relying on the optimisers to merge it back together. But since one of the arms of the comparison
is a vector constant the combine pass optimises the abs into it and tries matching:
(set (reg:V4SI 101)
    (neg:V4SI (gt:V4SI (reg:V4SF 100)
            (const_vector:V4SF [
                    (const_double:SF 1.0e+2 [0x0.c8p+7]) repeated x4
                ]))))
and
(set (reg:V4SI 101)
    (neg:V4SI (gt:V4SI (abs:V4SF (reg:V4SF 104))
            (reg:V4SF 103))))

instead of what we want:
(insn 13 9 14 2 (set (reg/i:V4SI 32 v0)
        (neg:V4SI (gt:V4SI (abs:V4SF (reg:V4SF 98))
                (abs:V4SF (reg:V4SF 96)))))

I don't really see a good way around that with our current implementation of these intrinsics.
Therefore this patch reimplements these intrinsics with aarch64 builtins that generate the RTL for these
instructions directly. Apparently we already had them defined in aarch64-simd-builtins.def and have been
using them for the fp16 case already.
I realise that this approach is against the general principle of expressing intrinsics in the higher-level constructs,
so I'm willing to listen to counter-arguments.
That said, the FACGT/FACGE instructions are as fast as the non-ABS comparison instructions on all microarchitectures that I know of
so it should always be a win to have them in the merged form rather than split the fabs step separately or try to hoist it.
And the testcase does come from real library code that we're trying to optimise.
With this patch for the testcase we generate:
foo:
        adrp    x0, .LC0
        ldr     q31, [x0, #:lo12:.LC0]
        facgt   v0.4s, v0.4s, v31.4s
        ret

gcc/ChangeLog:

* config/aarch64/arm_neon.h (vcage_f64): Reimplement with builtins.
(vcage_f32): Likewise.
(vcages_f32): Likewise.
(vcageq_f32): Likewise.
(vcaged_f64): Likewise.
(vcageq_f64): Likewise.
(vcagts_f32): Likewise.
(vcagt_f32): Likewise.
(vcagt_f64): Likewise.
(vcagtq_f32): Likewise.
(vcagtd_f64): Likewise.
(vcagtq_f64): Likewise.
(vcale_f32): Likewise.
(vcale_f64): Likewise.
(vcaled_f64): Likewise.
(vcales_f32): Likewise.
(vcaleq_f32): Likewise.
(vcaleq_f64): Likewise.
(vcalt_f32): Likewise.
(vcalt_f64): Likewise.
(vcaltd_f64): Likewise.
(vcaltq_f32): Likewise.
(vcaltq_f64): Likewise.
(vcalts_f32): Likewise.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/simd/facgt_constpool_1.c: New test.

2 years agoi386: Fix incorrect intrinsic signature for AVX512 s{lli|rai|rli}
Hu, Lin1 [Tue, 23 May 2023 02:08:29 +0000 (10:08 +0800)] 
i386: Fix incorrect intrinsic signature for AVX512 s{lli|rai|rli}

This patch aims to fix incorrect intrinsic signature for
_mm{512|256|}_s{lli|rai|rli}_epi*.

gcc/ChangeLog:

PR target/109173
PR target/109174
* config/i386/avx512bwintrin.h (_mm512_srli_epi16): Change type from
int to const int or const int to const unsigned int.
(_mm512_mask_srli_epi16): Ditto.
(_mm512_slli_epi16): Ditto.
(_mm512_mask_slli_epi16): Ditto.
(_mm512_maskz_slli_epi16): Ditto.
(_mm512_srai_epi16): Ditto.
(_mm512_mask_srai_epi16): Ditto.
(_mm512_maskz_srai_epi16): Ditto.
* config/i386/avx512fintrin.h (_mm512_slli_epi64): Ditto.
(_mm512_mask_slli_epi64): Ditto.
(_mm512_maskz_slli_epi64): Ditto.
(_mm512_srli_epi64): Ditto.
(_mm512_mask_srli_epi64): Ditto.
(_mm512_maskz_srli_epi64): Ditto.
(_mm512_srai_epi64): Ditto.
(_mm512_mask_srai_epi64): Ditto.
(_mm512_maskz_srai_epi64): Ditto.
(_mm512_slli_epi32): Ditto.
(_mm512_mask_slli_epi32): Ditto.
(_mm512_maskz_slli_epi32): Ditto.
(_mm512_srli_epi32): Ditto.
(_mm512_mask_srli_epi32): Ditto.
(_mm512_maskz_srli_epi32): Ditto.
(_mm512_srai_epi32): Ditto.
(_mm512_mask_srai_epi32): Ditto.
(_mm512_maskz_srai_epi32): Ditto.
* config/i386/avx512vlbwintrin.h (_mm256_mask_srai_epi16): Ditto.
(_mm256_maskz_srai_epi16): Ditto.
(_mm_mask_srai_epi16): Ditto.
(_mm_maskz_srai_epi16): Ditto.
(_mm256_mask_slli_epi16): Ditto.
(_mm256_maskz_slli_epi16): Ditto.
(_mm_mask_slli_epi16): Ditto.
(_mm_maskz_slli_epi16): Ditto.
(_mm_maskz_srli_epi16): Ditto.
* config/i386/avx512vlintrin.h (_mm256_mask_srli_epi32): Ditto.
(_mm256_maskz_srli_epi32): Ditto.
(_mm_mask_srli_epi32): Ditto.
(_mm_maskz_srli_epi32): Ditto.
(_mm256_mask_srli_epi64): Ditto.
(_mm256_maskz_srli_epi64): Ditto.
(_mm_mask_srli_epi64): Ditto.
(_mm_maskz_srli_epi64): Ditto.
(_mm256_mask_srai_epi32): Ditto.
(_mm256_maskz_srai_epi32): Ditto.
(_mm_mask_srai_epi32): Ditto.
(_mm_maskz_srai_epi32): Ditto.
(_mm256_srai_epi64): Ditto.
(_mm256_mask_srai_epi64): Ditto.
(_mm256_maskz_srai_epi64): Ditto.
(_mm_srai_epi64): Ditto.
(_mm_mask_srai_epi64): Ditto.
(_mm_maskz_srai_epi64): Ditto.
(_mm_mask_slli_epi32): Ditto.
(_mm_maskz_slli_epi32): Ditto.
(_mm_mask_slli_epi64): Ditto.
(_mm_maskz_slli_epi64): Ditto.
(_mm256_mask_slli_epi32): Ditto.
(_mm256_maskz_slli_epi32): Ditto.
(_mm256_mask_slli_epi64): Ditto.
(_mm256_maskz_slli_epi64): Ditto.

gcc/testsuite/ChangeLog:

PR target/109173
PR target/109174
* gcc.target/i386/pr109173-1.c: New test.
* gcc.target/i386/pr109174-1.c: Ditto.

2 years agoada: Missing warning on null-excluding array aggregate component
Javier Miranda [Tue, 28 Feb 2023 18:20:38 +0000 (18:20 +0000)] 
ada: Missing warning on null-excluding array aggregate component

The compiler does not report warnings on the initialization
of arrays of null-excluding access type components by means
of iterated component association, when the expression
initializing each component is either a conditional
expression or a case expression that may initialize
some component with a null value.

gcc/ada/

* sem_aggr.adb
(Warn_On_Null_Component_Association): New subprogram.
(Empty_Range): Adding missing support for iterated component
association node.
(Resolve_Array_Aggregate): Report warning on iterated component
association that may initialize some component of an array of
null-excluding access type components with a null value.
* exp_ch4.adb
(Expand_N_Expression_With_Actions): Add missing type check since
the subtype of the EWA node and the subtype of the expression
may differ.

2 years agoada: Expect Exceptional_Cases as a context for attribute Old
Piotr Trojanek [Mon, 13 Mar 2023 09:59:47 +0000 (10:59 +0100)] 
ada: Expect Exceptional_Cases as a context for attribute Old

When determining whether attribute Old is evaluated conditionally, we
must also expect it to appear in the recently added contract
Exceptional_Cases.

gcc/ada/

* sem_util.adb (Determining_Expressions): Fix style; fix layout and
ordering of pragma names; expect pragma Exceptional_Cases.

2 years agoada: Use procedural variant of Next_Index where possible
Piotr Trojanek [Thu, 9 Mar 2023 23:14:32 +0000 (00:14 +0100)] 
ada: Use procedural variant of Next_Index where possible

Code cleanup; semantics is unaffected.

gcc/ada/

* einfo-utils.adb (Write_Entity_Info): Use procedural Next_Index.
* sem_aggr.adb (Collect_Aggr_Bounds): Reuse local constant.
(Resolve_Null_Array_Aggregate): Use procedural Next_Index.

2 years agoada: Crash on empty aggregate using the Ada 2022 notation
Javier Miranda [Sun, 12 Mar 2023 12:32:34 +0000 (12:32 +0000)] 
ada: Crash on empty aggregate using the Ada 2022 notation

The compiler crashes processing an empty aggregate initializing
a component of a discriminated record type using the Ada 2022
notation (that is, []).

gcc/ada/

* exp_aggr.adb (Build_Record_Aggr_Code): Protect access to
aggregate components when the aggregate is empty.

2 years agoada: Enable Support_Atomic_Primitives on VxWorks 7 PPC
Johannes Kliemann [Fri, 10 Mar 2023 15:27:32 +0000 (15:27 +0000)] 
ada: Enable Support_Atomic_Primitives on VxWorks 7 PPC

gcc/ada/

* libgnat/system-vxworks7-ppc-kernel.ads: Enable
Support_Atomic_Primitives.
* libgnat/system-vxworks7-ppc-rtp-smp.ads: Likewise.

2 years agoada: Fix internal error on declare-expression in post-condition
Eric Botcazou [Fri, 10 Mar 2023 17:05:13 +0000 (18:05 +0100)] 
ada: Fix internal error on declare-expression in post-condition

It comes from an incorrect node sharing in the expanded tree.

gcc/ada/

* sem_ch3.adb (Find_Type_Of_Object): Copy the object definition when
building the subtype declaration in the case of a spec expression.

2 years agoada: Require successful build of xsnamest
Tom Tromey [Wed, 8 Mar 2023 17:21:59 +0000 (10:21 -0700)] 
ada: Require successful build of xsnamest

While experimenting, I introduced a compilation error into xsnamest.
This took a little while to track down because, while the error was in
the log, the build did not stop.  This patch changes Make-generated.in
to require a successful build of this program.

gcc/ada/

* Make-generated.in (ada/stamp-snames): Check result of
gnatmake.

2 years agoada: Minor adjustments to Standard_Address
Eric Botcazou [Wed, 8 Mar 2023 22:02:34 +0000 (23:02 +0100)] 
ada: Minor adjustments to Standard_Address

Standard_Address is an internal entity that is meant to be a clone of
System.Address built at compilation startup.  It needs to be seen as a
bona-fide address by the code generator.  For the sake of completeness,
it is also given its modulus, although this does not matter in practice.

gcc/ada/

* cstand.adb (Create_Standard): Set the Is_Descendant_Of_Address
flag on Standard_Address.
* freeze.adb (Freeze_Entity): Copy the modulus of System.Address
onto Standard_Address.

2 years agoada: Add size clause to System.Address
Eric Botcazou [Wed, 8 Mar 2023 17:11:31 +0000 (18:11 +0100)] 
ada: Add size clause to System.Address

Standard'Address_Size is the value provided by the code generator for the
size of pointers, and it is set as the default size of every thin pointer
by the front-end.  Now it is documented in the GNAT RM as having the value
of System.Address'Size, which is indeed the case on (correctly configured)
platforms where pointers contain exactly the number of bits that are needed
to address the memory space.

However, on platforms where pointers contain additional bits of metadata,
it has a larger value and the documented relation does not hold, which also
means that unchecked conversions between System.Address and pointers are
seen as potentially problematic.  In order to fix the discrepancy on these
platforms, this change adds the obvious size clause to System.Address, which
is confirming on all the other (correctly configured) platforms.

gcc/ada/

* libgnat/system-aix.ads (Address): Likewise.
* libgnat/system-darwin-arm.ads (Address): Likewise.
* libgnat/system-darwin-ppc.ads (Address): Likewise.
* libgnat/system-darwin-x86.ads (Address): Likewise.
* libgnat/system-djgpp.ads (Address): Likewise.
* libgnat/system-dragonfly-x86_64.ads (Address): Likewise.
* libgnat/system-freebsd.ads (Address): Likewise.
* libgnat/system-hpux-ia64.ads (Address): Likewise.
* libgnat/system-hpux.ads (Address): Likewise.
* libgnat/system-linux-alpha.ads (Address): Likewise.
* libgnat/system-linux-arm.ads (Address): Likewise.
* libgnat/system-linux-hppa.ads (Address): Likewise.
* libgnat/system-linux-ia64.ads (Address): Likewise.
* libgnat/system-linux-m68k.ads (Address): Likewise.
* libgnat/system-linux-mips.ads (Address): Likewise.
* libgnat/system-linux-ppc.ads (Address): Likewise.
* libgnat/system-linux-riscv.ads (Address): Likewise.
* libgnat/system-linux-s390.ads (Address): Likewise.
* libgnat/system-linux-sh4.ads (Address): Likewise.
* libgnat/system-linux-sparc.ads (Address): Likewise.
* libgnat/system-linux-x86.ads (Address): Likewise.
* libgnat/system-lynxos178-ppc.ads (Address): Likewise.
* libgnat/system-lynxos178-x86.ads (Address): Likewise.
* libgnat/system-mingw.ads (Address): Likewise.
* libgnat/system-qnx-arm.ads (Address): Likewise.
* libgnat/system-rtems.ads (Address): Likewise.
* libgnat/system-solaris-sparc.ads (Address): Likewise.
* libgnat/system-solaris-x86.ads (Address): Likewise.
* libgnat/system-vxworks-ppc-kernel.ads (Address): Likewise.
* libgnat/system-vxworks-ppc-rtp-smp.ads (Address): Likewise.
* libgnat/system-vxworks-ppc-rtp.ads (Address): Likewise.
* libgnat/system-vxworks7-aarch64-rtp-smp.ads (Address): Likewise.
* libgnat/system-vxworks7-aarch64.ads (Address): Likewise.
* libgnat/system-vxworks7-arm-rtp-smp.ads (Address): Likewise.
* libgnat/system-vxworks7-arm.ads (Address): Likewise.
* libgnat/system-vxworks7-ppc-kernel.ads (Address): Likewise.
* libgnat/system-vxworks7-ppc-rtp-smp.ads (Address): Likewise.
* libgnat/system-vxworks7-ppc64-kernel.ads (Address): Likewise.
* libgnat/system-vxworks7-ppc64-rtp-smp.ads (Address): Likewise.
* libgnat/system-vxworks7-x86-kernel.ads (Address): Likewise.
* libgnat/system-vxworks7-x86-rtp-smp.ads (Address): Likewise.
* libgnat/system-vxworks7-x86_64-kernel.ads (Address): Likewise.
* libgnat/system-vxworks7-x86_64-rtp-smp.ads (Address): Likewise.

2 years agoada: Fix error message for Aggregate aspect
Marc Poulhiès [Wed, 8 Mar 2023 19:39:45 +0000 (20:39 +0100)] 
ada: Fix error message for Aggregate aspect

The error message was wrongly using % instead of & in the format string,
causing the displayed message to refer to incorrect names in some cases.

gcc/ada/

* sem_ch13.adb (Check_Aspect_At_Freeze_Point): fix format string,
use existing local Ident.

2 years agoada: Switch from E_Void to Is_Not_Self_Hidden
Bob Duff [Wed, 8 Mar 2023 17:15:13 +0000 (12:15 -0500)] 
ada: Switch from E_Void to Is_Not_Self_Hidden

We had previously used Ekind = E_Void to indicate that a declaration is
self-hidden. We now use the Is_Not_Self_Hidden flag instead. This allows
us to avoid many "vanishing fields", which are (possibly-latent) bugs,
and we now enable the assertions in Atree that detect such bugs.

gcc/ada/

* atree.adb (Check_Vanishing_Fields): Fix bug in the "blah type
only" cases. Remove the special cases for E_Void. Misc cleanup.
(Mutate_Nkind): Disallow mutating to the same kind.
(Mutate_Ekind): Disallow mutating to E_Void.
(From E_Void is still OK -- entities start out as E_Void by
default.) Fix bug in statistics gathering -- was setting the wrong
count. Enable Check_Vanishing_Fields for entities.
* sem_ch8.adb (Is_Self_Hidden): New function.
(Find_Direct_Name): Call Is_Self_Hidden to use the new
Is_Not_Self_Hidden flag to determine whether a declaration is
hidden from all visibility by itself. This replaces the old method
of checking E_Void.
(Find_Expanded_Name): Likewise.
(Find_Selected_Component): Likewise.
* sem_util.adb (Enter_Name): Remove setting of Ekind to E_Void.
* sem_ch3.adb: Set the Is_Not_Self_Hidden flag in appropriate
places. Comment fixes.
(Inherit_Component): Remove setting of Ekind to E_Void.
* sem_ch9.adb
(Analyze_Protected_Type_Declaration): Update comment. Skip Itypes,
which should not be turned into components.
* atree.ads (Mutate_Nkind): Document error case.
(Mutate_Ekind): Remove comments apologizing for E_Void mutations.
Document error cases.

2 years agoada: Decouple size of addresses and pointers from size of memory space
Eric Botcazou [Wed, 8 Mar 2023 14:12:27 +0000 (15:12 +0100)] 
ada: Decouple size of addresses and pointers from size of memory space

This decouples the size of the types representing addresses and pointers,
which is Standard'Address_Size, from the size of the memory space, which
is System.Memory_Size (more precisely log2 of it).  They are tied through
the definition of System.Address:

  type Address is mod Memory_Size;

so Standard'Address_Size >= log2 (System.Memory_Size) necessarily, but the
equality does not hold on platforms where addresses and pointers contain
additional bits of metadata.

gcc/ada/

* libgnat/a-ststio.adb (Set_Mode): Test System.Memory_Size.
* libgnat/g-debuti.ads (Address_64): Likewise.
* libgnat/i-c.ads: Add with clause for System.
(ptrdiff_t): Define based on the size of memory space.
(size_t): Likewise.
* libgnat/s-crtl.ads (size_t): Likewise.
(ssize_t): Likewise.
* libgnat/s-memory.ads (size_t): Likewise.
* libgnat/s-parame.ads (Size_Type): Likewise.
* libgnat/s-parame__hpux.ads (Size_Type): Likewise.
* libgnat/s-parame__posix2008.ads (Size_Type): Likewise.
* libgnat/s-parame__vxworks.ads (Size_Type): Likewise.
* libgnat/s-putima.adb (Signed_Address): Likewise.
(Unsigned_Address): Likewise.
* libgnat/s-stoele.ads (Storage_Offset): Likewise.

2 years agoada: Fix copying of quantified expressions
Piotr Trojanek [Wed, 8 Mar 2023 14:30:41 +0000 (15:30 +0100)] 
ada: Fix copying of quantified expressions

While visiting the AST as part of routine New_Copy_Tree we maintain
an EWA_Level variable in a stack-like fashion. This worked fine for
expression with actions nodes but not for quantified expressions.

gcc/ada/

* sem_util.adb (Visit_Node): Decrement EWA_Level with the same condition
as when it was incremented.

2 years agoada: Deconstruct a no longer used parameter of New_Copy_Tree
Piotr Trojanek [Wed, 8 Mar 2023 10:41:42 +0000 (11:41 +0100)] 
ada: Deconstruct a no longer used parameter of New_Copy_Tree

Parameter Scopes_In_EWA_OK of New_Copy_Tree was introduced in 2018 to
deal with expressions-with-actions (EWA) in the build-in-place
machinery. However, after changes made in 2022 it is no longer used by
any caller.

Cleanup related to handling of expression functions in GNATprove;
semantics is unaffected.

gcc/ada/

* sem_util.ads (New_Copy_Tree): Remove Scopes_In_EWA_OK from spec;
adapt comment.
* sem_util.adb (New_Copy_Tree): Remove Scopes_In_EWA_OK from body;
adapt code.

2 years agoada: Clean up copying of node trees
Piotr Trojanek [Tue, 7 Mar 2023 20:00:46 +0000 (21:00 +0100)] 
ada: Clean up copying of node trees

Before calling routine In_Entity_Map we checked if the entity map is
present; inside this routine we checked this again.

Code cleanup; semantics is unaffected.

gcc/ada/

* sem_util.adb (Update_New_Entities): Remove redundant check for entity
map being present.

2 years agoada: Simplify copying of node lists
Piotr Trojanek [Tue, 7 Mar 2023 18:52:40 +0000 (19:52 +0100)] 
ada: Simplify copying of node lists

When creating a copy of a node list we called Copy_Entity for entities
and Copy_Separate_Tree for other nodes. This was unnecessary, because
the Copy_Separate_Tree when called on entities will just do Copy_Entity.

Code cleanup; semantics is unaffected.

gcc/ada/

* atree.adb (Copy_List): Call Copy_Separate_Tree for both entities and
other nodes.

2 years agoada: Avoid duplicated streaming subprograms
Steve Baird [Fri, 3 Mar 2023 00:51:57 +0000 (16:51 -0800)] 
ada: Avoid duplicated streaming subprograms

In some common cases, a reference to Some_Type'Some_Streaming_Attribute
causes the needed subprogram to be generated "on demand". If there are
multiple such references (e.g., two calls to Some_Type'Write) then we
want to avoid generating multiple essentially-identical subprograms.
This change implies that a generated streaming subprogram may now have
multiple call sites, so we can no longer use the source position information
from the (one and only) call site. If an exception is raised during a
streaming operation, this can make a difference in the reported raise location.

gcc/ada/

* exp_attr.adb
(Cached_Streaming_Ops): A new package, providing maps to save
previously-generated Read/Write/Input/Output procedures.
(Expand_N_Attribute_Reference): When a new subprogram is generated
for a Read/Write/Input/Output attribute reference, record that
type/subp pair in the appropriate Cached_Streaming_Ops map.
(Find_Stream_Subprogram): Check the appropriate
Cached_Streaming_Ops map to see if an appropriate subprogram has
already been generated. If so, then return it. The appropriateness
test includes a call to a new nested subprogram,
In_Available_Context.
* exp_strm.ads, exp_strm.adb: Do not pass in a Loc parameter (or a
source-location-bearing Nod parameter) to the 16 procedures
provided for building streaming-related subprograms. Use the
source location of the type instead.
* exp_dist.adb, exp_ch3.adb: Adapt to Exp_Strm spec changes. For
these calls the source location of the type was already being
used.

2 years agoada: Fix crash during function return analysis
Marc Poulhiès [Tue, 7 Mar 2023 15:35:48 +0000 (16:35 +0100)] 
ada: Fix crash during function return analysis

The compiler would crash when checking type relation between the
function's return type and the type of the expression used in the return
statement. It would not work if the function's return type is an access
type and the expression is not.

gcc/ada/

* sem_ch6.adb (Analyze_Function_Return): Add missing
Is_Access_Type check before accessing the Designated_Type field.

2 years agoada: Remove unused initial value of a local variable
Piotr Trojanek [Tue, 7 Mar 2023 08:02:23 +0000 (09:02 +0100)] 
ada: Remove unused initial value of a local variable

Cleanup related to improved handling of expression functions in
GNATprove; semantics is unaffected.

gcc/ada/

* sem_ch6.adb (Analyze_Return_Type): Remove unused initial value.

2 years agoada: Fix (again) incorrect handling of Aggregate aspect
Marc Poulhiès [Mon, 6 Mar 2023 11:15:13 +0000 (12:15 +0100)] 
ada: Fix (again) incorrect handling of Aggregate aspect

Previous fix stopped the processing of the Aggregate aspect early,
skipping the call to Record_Rep_Item, making later call to
Resolve_Container_Aggregate fail.

Also, the previous fix would not handle correctly the case where the
type is private and the check for non-array type can only be done at the
freeze point with the full type.

Adapt the resolving of the aspect when the input is not correct and the
parameters can't be resolved.

gcc/ada/

* sem_ch13.adb (Analyze_One_Aspect): Call Record_Rep_Item.
(Check_Aspect_At_Freeze_Point): Check the aspect is specified on
non-array type only...
(Analyze_One_Aspect): ... instead of doing it too early here.
* sem_aggr.adb (Resolve_Container_Aggregate): Do nothing in case
the parameters failed to resolve.

2 years agoada: Prevent search of calls in preconditions from going too far
Piotr Trojanek [Sat, 4 Mar 2023 17:07:55 +0000 (18:07 +0100)] 
ada: Prevent search of calls in preconditions from going too far

When determining whether a call to protected function appears within
a pragma expression we can safely stop at the subprogram body.

Cleanup related to recently added support for a new SPARK aspects,
whose implementation was based on Contract_Cases.

gcc/ada/

* sem_util.adb (Check_Internal_Protected_Use): Add standard protection
against search going too far.

2 years agoada: Fix comments for recently added SPARK aspects
Piotr Trojanek [Sat, 4 Mar 2023 17:07:33 +0000 (18:07 +0100)] 
ada: Fix comments for recently added SPARK aspects

Implementation of contract Subprogram_Variant and Exceptional_Cases was
based on the existing code for Contract_Cases, i.e. on the existing
occurrences of Aspect_Contract_Cases, Name_Contract_Cases and
Pragma_Contract_Cases. However, occurrences of "Contract_Cases" itself
in the comments were not updated.

gcc/ada/

* contracts.adb
(Add_Pre_Post_Condition): Mention new aspects in the comment.
* contracts.ads
(Add_Contract_Item): Likewise.
(Analyze_Subprogram_Body_Stub_Contract): Likewise.
* sem_prag.adb
(Contract_Freeze_Error): Likewise.
(Ensure_Aggregate_Form): Likewise.
* sem_prag.ads
(Find_Related_Declaration_Or_Body): Likewise.
* sinfo.ads
(Is_Generic_Contract_Pragma): Likewise.

2 years agoada: Add missing supportive code for recently added SPARK aspects
Piotr Trojanek [Fri, 3 Mar 2023 16:45:20 +0000 (17:45 +0100)] 
ada: Add missing supportive code for recently added SPARK aspects

Fix minor inconsistencies with the recently added SPARK aspects
Exceptional_Cases and Subprogram_Variant, whose implementation is based
on Contract_Cases.

gcc/ada/

* aspects.ads
(Implementation_Defined_Aspect): Recently added aspects are
implementation-defined, just like Contract_Cases.
* sem_prag.ads
(Aspect_Specifying_Pragma): Recently added aspects have corresponding
pragmas, just like Contract_Cases.
(Pragma_Significant_To_Subprograms): Recently added aspects are
significant to subprograms, just like Contract_Cases.

2 years agoada: Tune handling of attributes Old in contract Exceptional_Cases
Piotr Trojanek [Mon, 6 Mar 2023 11:50:04 +0000 (12:50 +0100)] 
ada: Tune handling of attributes Old in contract Exceptional_Cases

Contract Exceptional_Cases allows formal parameters to appear *in*
prefixes of attributes Old, but the code only allowed them to appear
*as* prefixes of those attributes.

For example, we now accetp expressions like "X.all'Old" that were
previously rejected.

gcc/ada/

* sem_res.adb (Resolve_Entity_Name): Tune handling of formal parameters
in contract Exceptional_Cases.

2 years agoada: Remove redundant guards from calls to Move_Aspects
Piotr Trojanek [Fri, 3 Mar 2023 16:27:40 +0000 (17:27 +0100)] 
ada: Remove redundant guards from calls to Move_Aspects

Routine Move_Aspects does nothing if its From parameter has no aspects.
There is no need to check this at the call sites.

Code cleanup related to changes in handling of expressions functions in
GNATprove; semantics is unaffected.

gcc/ada/

* par-ch7.adb (P_Package): Remove redundant guard from call to
Move_Aspects.
* par-ch9.adb (P_Task): Likewise.
* sem_ch6.adb (Analyze_Expression_Function, Is_Inline_Pragma): Likewise.

2 years agoada: Small tweak to implementation of by-copy semantics for storage models
Eric Botcazou [Sat, 4 Mar 2023 14:02:32 +0000 (15:02 +0100)] 
ada: Small tweak to implementation of by-copy semantics for storage models

Get_Actual_Subtype can be used to access the Actual_Designated_Subtype of
explicit dereferences with a storage model. As a side effect, this also
handles the case where the prefix of the dereference is a formal parameter.

gcc/ada/

* exp_ch6.adb (Add_Simple_Call_By_Copy_Code): Use Get_Actual_Subtype
to retrieve the actual subtype for all actuals and do it in only one
place for all unconstrained composite formal types.

2 years agoada: Fix copy-paste mistake in analysis of Exceptional_Cases
Piotr Trojanek [Fri, 3 Mar 2023 17:23:58 +0000 (18:23 +0100)] 
ada: Fix copy-paste mistake in analysis of Exceptional_Cases

Trivial mistakes in copied code.

gcc/ada/

* sem_prag.adb (Analyze_Pragma): Fix references to Exceptional_Cases in
code copied from handling of Subprogram_Variant.