]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
2 years agoRISC-V: Use extension instructions instead of bitwise "and"
Jivan Hakobyan [Mon, 29 May 2023 13:55:29 +0000 (07:55 -0600)] 
RISC-V: Use extension instructions instead of bitwise "and"

In the case where the target supports extension instructions,
it is preferable to use that instead of doing the same in other ways.
For the following case

void foo (unsigned long a, unsigned long* ptr) {
    ptr[0] = a & 0xffffffffUL;
    ptr[1] &= 0xffffffffUL;
}

GCC generates
foo:
        li      a5,-1
        srli    a5,a5,32
        and     a0,a0,a5
        sd      a0,0(a1)
        ld      a4,8(a1)
        and     a5,a4,a5
        sd      a5,8(a1)
        ret

but it will be profitable to generate this one

foo:
  zext.w a0,a0
  sd a0,0(a1)
  lwu a5,8(a1)
  sd a5,8(a1)
  ret

This patch fixes mentioned issue.
It supports HI -> DI, HI->SI and SI -> DI extensions.

gcc/ChangeLog:
* config/riscv/riscv.md (and<mode>3): New expander.
(*and<mode>3) New pattern.
* config/riscv/predicates.md (arith_operand_or_mode_mask): New
predicate.

gcc/testsuite/ChangeLog:
* gcc.target/riscv/and-extend-1.c: New test
* gcc.target/riscv/and-extend-2.c: New test

2 years agoRISC-V: Refactor comments and naming of riscv-v.cc.
Pan Li [Fri, 26 May 2023 11:26:24 +0000 (19:26 +0800)] 
RISC-V: Refactor comments and naming of riscv-v.cc.

This patch would like to remove unnecessary comments of some self
explained parameters and try a better name to avoid misleading.

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

* config/riscv/riscv-v.cc (emit_vlmax_insn): Remove unnecessary
comments and rename local variables.
(emit_nonvlmax_insn): Diito.
(emit_vlmax_merge_insn): Ditto.
(emit_vlmax_cmp_insn): Ditto.
(emit_vlmax_cmp_mu_insn): Ditto.
(emit_scalar_move_insn): Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 years agoDaily bump.
GCC Administrator [Mon, 29 May 2023 11:15:05 +0000 (11:15 +0000)] 
Daily bump.

2 years agoRISC-V: Eliminate the magic number in riscv-v.cc
Pan Li [Fri, 26 May 2023 00:40:26 +0000 (08:40 +0800)] 
RISC-V: Eliminate the magic number in riscv-v.cc

This patch would like to remove the magic number in the riscv-v.cc, and
align the same value to one macro.

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

* config/riscv/riscv-v.cc (emit_vlmax_insn): Eliminate the
magic number.
(emit_nonvlmax_insn): Ditto.
(emit_vlmax_merge_insn): Ditto.
(emit_vlmax_cmp_insn): Ditto.
(emit_vlmax_cmp_mu_insn): Ditto.
(expand_vec_series): Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 years agoRISC-V: Using merge approach to optimize repeating sequence in vec_init
Pan Li [Thu, 25 May 2023 02:58:49 +0000 (10:58 +0800)] 
RISC-V: Using merge approach to optimize repeating sequence in vec_init

This patch would like to optimize the VLS vector initialization like
repeating sequence. From the vslide1down to the vmerge with a simple
cost model, aka every instruction only has 1 cost.

Given code with -march=rv64gcv_zvl256b --param riscv-autovec-preference=fixed-vlmax
typedef int64_t vnx32di __attribute__ ((vector_size (256)));

__attribute__ ((noipa)) void
f_vnx32di (int64_t a, int64_t b, int64_t *out)
{
  vnx32di v = {
    a, b, a, b, a, b, a, b,
    a, b, a, b, a, b, a, b,
    a, b, a, b, a, b, a, b,
    a, b, a, b, a, b, a, b,
  };
  *(vnx32di *) out = v;
}

Before this patch:
vslide1down.vx (x31 times)

After this patch:
li a5,-1431654400
addi a5,a5,-1365
li a3,-1431654400
addi a3,a3,-1366
slli a5,a5,32
add a5,a5,a3
vsetvli a4,zero,e64,m8,ta,ma
vmv.v.x v8,a0
vmv.s.x v0,a5
vmerge.vxm v8,v8,a1,v0
vs8r.v v8,0(a2)

Since we dont't have SEW = 128 in vec_duplicate, we can't combine ab into
SEW = 128 element and then broadcast this big element.

Signed-off-by: Pan Li <pan2.li@intel.com>
Co-Authored by: Juzhe-Zhong <juzhe.zhong@rivai.ai>

gcc/ChangeLog:

* config/riscv/riscv-protos.h (enum insn_type): New type.
* config/riscv/riscv-v.cc (RVV_INSN_OPERANDS_MAX): New macro.
(rvv_builder::can_duplicate_repeating_sequence_p): Align the referenced
class member.
(rvv_builder::get_merged_repeating_sequence): Ditto.
(rvv_builder::repeating_sequence_use_merge_profitable_p): New function
to evaluate the optimization cost.
(rvv_builder::get_merge_scalar_mask): New function to get the merge
mask.
(emit_scalar_move_insn): New function to emit vmv.s.x.
(emit_vlmax_integer_move_insn): New function to emit vlmax vmv.v.x.
(emit_nonvlmax_integer_move_insn): New function to emit nonvlmax
vmv.v.x.
(get_repeating_sequence_dup_machine_mode): New function to get the dup
machine mode.
(expand_vector_init_merge_repeating_sequence): New function to perform
the optimization.
(expand_vec_init): Add this vector init optimization.
* config/riscv/riscv.h (BITS_PER_WORD): New macro.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vls-vlmax/init-repeat-sequence-1.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/init-repeat-sequence-2.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/init-repeat-sequence-3.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/init-repeat-sequence-4.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/init-repeat-sequence-5.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/init-repeat-sequence-run-1.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/init-repeat-sequence-run-2.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/init-repeat-sequence-run-3.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 years agoMAINTAINERS file: Replace spaces with tabs
Martin Jambor [Mon, 29 May 2023 09:51:28 +0000 (11:51 +0200)] 
MAINTAINERS file: Replace spaces with tabs

This change, separating Benjamin's name and email address with tabs
rather than spaces, makes contrib/check-MAINTAINERS.py script happy
about our MAINTAINERS file again.

ChangeLog:

2023-05-29  Martin Jambor  <mjambor@suse.cz>

* MAINTAINERS: Replace spaces with tabs.

2 years agoFix incorrect SLOC inherited by induction variable increment
Eric Botcazou [Mon, 29 May 2023 07:48:14 +0000 (09:48 +0200)] 
Fix incorrect SLOC inherited by induction variable increment

This extends the condition to more cases involving debug instructions.

gcc/
* tree-ssa-loop-manip.cc (create_iv): Try harder to find a SLOC to
put onto the increment when it is inserted after the position.

2 years agoFix artificial overflow during GENERIC folding
Eric Botcazou [Mon, 29 May 2023 07:45:57 +0000 (09:45 +0200)] 
Fix artificial overflow during GENERIC folding

The Ada compiler gives a bogus warning:
storage_offset1.ads:16:52: warning: Constraint_Error will be raised at run
time [enabled by default]

Ironically enough, this occurs because of an intermediate conversion to an
unsigned type which is supposed to hide overflows but is counter-productive
for constants because TREE_OVERFLOW is always set for them, so it ends up
setting a bogus TREE_OVERFLOW when converting back to the original type.

The fix simply redirects INTEGER_CSTs to the other, direct path without the
intermediate conversion to the unsigned type.

gcc/
* match.pd ((T)P - (T)(P + A) -> -(T) A): Avoid artificial overflow
on constants.

gcc/testsuite/
* gnat.dg/specs/storage_offset1.ads: New test.

2 years agoada: Define sigset for systems that does not suport sockets
Cedric Landet [Fri, 31 Mar 2023 12:24:46 +0000 (14:24 +0200)] 
ada: Define sigset for systems that does not suport sockets

In s-oscons-tmplt.c, sigset is defined inside the HAVE_SOCKETS bloc.
A platform could require sigset without supporting sockets.

gcc/ada/

* s-oscons-tmplt.c: move the definition of sigset out of the
HAVE_SOCKETS bloc.

2 years agoada: Set g-spogwa as a GNATRTL_SOCKETS_OBJS
Cedric Landet [Fri, 31 Mar 2023 12:05:37 +0000 (14:05 +0200)] 
ada: Set g-spogwa as a GNATRTL_SOCKETS_OBJS

g-spogwa.adb is the body of the procedure GNAT.Sockets.Poll.G_Wait.
This is a socket specific procedure. It should only be built for
systems that support sockets.

gcc/ada/

* Makefile.rtl: Move g-spogwa$(objext) from GNATRTL_NONTASKING_OBJS
to GNATRTL_SOCKETS_OBJS

2 years agoada: Fix spurious error on imported generic function with precondition
Eric Botcazou [Mon, 10 Apr 2023 08:15:59 +0000 (10:15 +0200)] 
ada: Fix spurious error on imported generic function with precondition

It occurs during the instantiation because the compiler forgets the context
of the generic declaration.

gcc/ada/

* freeze.adb (Wrap_Imported_Subprogram): Use Copy_Subprogram_Spec in
both cases to copy the spec of the subprogram.

2 years agoada: Fix memory leak in expression function returning Big_Integer
Eric Botcazou [Sat, 8 Apr 2023 16:29:16 +0000 (18:29 +0200)] 
ada: Fix memory leak in expression function returning Big_Integer

We fail to establish a transient scope around the return statement because
the function returns a controlled type, but this is no longer problematic
because controlled types are no longer returned on the secondary stack.

gcc/ada/

* exp_ch7.adb (Establish_Transient_Scope.Find_Transient_Context):
Bail out for a simple return statement only if the transient scope
and the function both require secondary stack management, or else
if the function is a thunk.
* sem_res.adb (Resolve_Call): Do not create a transient scope when
the call is the expression of a simple return statement.

2 years agoada: Use Code_Address attribute to determine subprogram addresses
Patrick Bernardi [Thu, 6 Apr 2023 20:55:01 +0000 (16:55 -0400)] 
ada: Use Code_Address attribute to determine subprogram addresses

The runtime used label addresses to determine the code address of
subprograms because the subprogram's canonical address on some targets
is a descriptor or a stub. Simplify the code by using the Code_Address
attribute instead, which is designed to return the code address of a
subprogram. This also works around a current GNAT-LLVM limitation where
the address of a label is incorrectly calculated when using -O1. As a
result, we can now build a-except.adb and g-debpoo.adb at -O1 again with
GNAT-LLVM.

gcc/ada/

* libgnat/a-excach.adb (Call_Chain): Replace
Code_Address_For_AAA/ZZZ functions with AAA/ZZZ'Code_Address.
* libgnat/a-except.adb (Code_Address_For_AAA/ZZZ): Delete.
(AAA/ZZZ): New null procedures.
* libgnat/g-debpoo.adb
(Code_Address_For_Allocate_End): Delete.
(Code_Address_For_Deallocate_End): Delete.
(Code_Address_For_Dereference_End): Delete.
(Allocate): Remove label and use Code_Address attribute to
determine subprogram addresses.
(Dellocate): Likewise.
(Dereference): Likewise.
(Allocate_End): Convert to null procedure.
(Dellocate_End): Likewise.
(Dereference_End): Likewise.

2 years agoada: Call idiomatic routine in Expand_Simple_Function_Return
Eric Botcazou [Sat, 8 Apr 2023 10:43:54 +0000 (12:43 +0200)] 
ada: Call idiomatic routine in Expand_Simple_Function_Return

In the primary stack case, Insert_Actions is invoked when the expression is
being rewritten, whereas Insert_List_Before_And_Analyze is invoked in the
secondary stack case.  The former is idiomatic, the latter is not.

gcc/ada/

* exp_ch6.adb (Expand_Simple_Function_Return): Call Insert_Actions
consistently when rewriting the expression.

2 years agoada: Fix wrong finalization for loop on indexed container
Eric Botcazou [Fri, 7 Apr 2023 17:17:20 +0000 (19:17 +0200)] 
ada: Fix wrong finalization for loop on indexed container

The problem is that a transient temporary created for the constant indexing
of the container is finalized almost immediately after its creation.

gcc/ada/

* exp_util.adb (Is_Finalizable_Transient.Is_Indexed_Container):
New predicate to detect a temporary created to hold the result of
a constant indexing on a container.
(Is_Finalizable_Transient.Is_Iterated_Container): Adjust a couple
of obsolete comments.
(Is_Finalizable_Transient): Return False if Is_Indexed_Container
returns True on the object.

2 years agoada: Fix bogus error on conditional expression with only user-defined literals
Eric Botcazou [Fri, 7 Apr 2023 07:16:12 +0000 (09:16 +0200)] 
ada: Fix bogus error on conditional expression with only user-defined literals

This implements the recursive resolution of conditional expressions whose
dependent expressions are (all) user-defined literals the same way it is
implemented for operators.

gcc/ada/

* sem_res.adb (Has_Applicable_User_Defined_Literal): Make it clear
that the predicate also checks the node itself.
(Try_User_Defined_Literal): Move current implementation to...
Deal only with literals, named numbers and conditional expressions
whose dependent expressions are literals or named numbers.
(Try_User_Defined_Literal_For_Operator): ...this.  Remove multiple
return False statements and put a single one at the end.
(Resolve): Call Try_User_Defined_Literal instead of directly
Has_Applicable_User_Defined_Literal for all nodes.  Call
Try_User_Defined_Literal_For_Operator for operator nodes.

2 years agoada: Fix crash on semi-recursive call in access-to-subprogram contract
Piotr Trojanek [Fri, 7 Apr 2023 11:55:09 +0000 (13:55 +0200)] 
ada: Fix crash on semi-recursive call in access-to-subprogram contract

Calls to access-to-subprogram from its own pre/post aspects are rejected
as illegal, e.g.:

   type F is access function (X : Natural) return Boolean with
     Pre => F.all (X);

but they caused an assertion failure in detection of recursive calls.

Now they are properly recognized as recursive, but the error is
suppressed, because it has been already posted at the call node.

gcc/ada/

* sem_res.adb (Invoked_With_Different_Arguments): Use Get_Called_Entity,
which properly deals with calls via an access-to-subprogram; fix
inconsistent use of a Call object declared in enclosing subprogram.

2 years agoada: Attach pre/post on access-to-subprogram to internal subprogram type
Piotr Trojanek [Sun, 2 Apr 2023 12:47:49 +0000 (14:47 +0200)] 
ada: Attach pre/post on access-to-subprogram to internal subprogram type

Aspects Pre/Post that annotate access-to-subprogram type were attached
to the source entity (whose kind is either E_Access_Subprogram_Type or
E_Access_Protected_Subprogram_Type). However, it is more convenient to
attach them to the internal entity (whose kind is E_Subprogram_Type), so
that both Pre/Post aspects and First_Formal/Next_Formal chain are
attached to the same entity, just like for ordinary subprograms.

The drawback of having the Post aspect attached to an internal entity is
that name in prefixes of attribute Result no longer match the name of
entity where this Post aspect is attached. However, currently there is
no code that relies on this matching and, in general, there are fewer
routines that deal with attribute Result so they are easier to adapt
than the code that queries the Pre/Post aspects.

gcc/ada/

* contracts.adb
(Add_Pre_Post_Condition): Attach pre/post aspects to E_Subprogram_Type
entity.
(Analyze_Entry_Or_Subprogram_Contract): Adapt to use full type
declaration for a contract attached to E_Subprogram_Type entity.
* sem_prag.adb
(Analyze_Pre_Post_Condition): Add pre/post aspects to the designed type.

2 years agoada: Remove redundant protection against empty lists
Piotr Trojanek [Mon, 20 Mar 2023 14:47:29 +0000 (15:47 +0100)] 
ada: Remove redundant protection against empty lists

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

gcc/ada/

* sem_util.adb (Check_Function_Writable_Actuals): Remove guard against
a membership test with no alternatives; simplify with a membership test.

2 years agoada: Remove extra whitespace from FOR loops
Piotr Trojanek [Thu, 16 Mar 2023 12:33:29 +0000 (13:33 +0100)] 
ada: Remove extra whitespace from FOR loops

Whitespace cleanup.

gcc/ada/
* doc/gnat_ugn/gnat_and_program_execution.rst
(Some Useful Memory Pools): Remove extra whitespace from examples.
* sem_aggr.adb (Make_String_Into_Aggregate): Remove extra whitespace.
* gnat_ugn.texi: Regenerate.

2 years agoada: Cleanup detection of type support subprogram entities
Piotr Trojanek [Wed, 5 Apr 2023 21:55:30 +0000 (23:55 +0200)] 
ada: Cleanup detection of type support subprogram entities

Avoid repeated calls to Get_TSS_Name. Code cleanup related to handling
of dispatching operations in GNATprove; semantics is unaffected.

gcc/ada/

* exp_aggr.adb (Convert_Aggr_In_Allocator): Replace Get_TSS_Name
with a high-level Is_TSS.
* sem_ch6.adb (Check_Conformance): Replace DECLARE block and
nested IF with a call to Get_TSS_Name and a membership test.
(Has_Reliable_Extra_Formals): Refactor repeated calls to
Get_TSS_Name.
* sem_disp.adb (Check_Dispatching_Operation): Replace repeated
calls to Get_TSS_Name with a membership test.

2 years agoada: Fix wrong finalization for case expression in expression function
Eric Botcazou [Thu, 6 Apr 2023 22:26:19 +0000 (00:26 +0200)] 
ada: Fix wrong finalization for case expression in expression function

This happens when the case expression contains a single alternative.

gcc/ada/

* exp_ch5.adb (Expand_N_Case_Statement): Do not remove the statement
if it is the node to be wrapped by a transient scope.

2 years agoada: Fix internal error with pragma Compile_Time_{Warning,Error}
Eric Botcazou [Tue, 4 Apr 2023 17:25:11 +0000 (19:25 +0200)] 
ada: Fix internal error with pragma Compile_Time_{Warning,Error}

This happens when the pragmas are deferred to the back-end from an external
unit to the main unit that is generic, because the back-end does not compile
a main unit that is generic.

gcc/ada/

* sem_prag.adb (Process_Compile_Time_Warning_Or_Error): Do not defer
anything to the back-end when the main unit is generic.

2 years agoada: Fix small fallout of previous change
Eric Botcazou [Wed, 5 Apr 2023 21:53:18 +0000 (23:53 +0200)] 
ada: Fix small fallout of previous change

It may lead to an infinite recursion if no interpretation exists.

gcc/ada/

* sem_res.adb (Try_User_Defined_Literal): Restrict previous change
to non-leaf nodes.

2 years agoada: Fix remaining failures in Roman Numbers test
Eric Botcazou [Wed, 5 Apr 2023 18:43:54 +0000 (20:43 +0200)] 
ada: Fix remaining failures in Roman Numbers test

The test is inspired from the example of user-defined literals given in the
Ada 2022 RM.  Mixed Arabic numbers/Roman numbers computations are rejected
because the second resolution pass would try to resolve Arabic numbers only
as user-defined literals.

gcc/ada/

* sem_res.adb (Try_User_Defined_Literal): For arithmetic operators,
also accept operands whose type is covered by the resolution type.

2 years agoada: Fix memory leak in multi-dimensional array aggregate of Vector
Eric Botcazou [Tue, 4 Apr 2023 22:03:27 +0000 (00:03 +0200)] 
ada: Fix memory leak in multi-dimensional array aggregate of Vector

It comes from a superfluous adjustment for subarray components.

gcc/ada/

* exp_aggr.adb (Initialize_Array_Component): Fix condition detecting
the nested case that requires an adjustment.

2 years agoada: Fix wrong result for membership test of null in null-excluding access type
Eric Botcazou [Wed, 5 Apr 2023 18:34:43 +0000 (20:34 +0200)] 
ada: Fix wrong result for membership test of null in null-excluding access type

The result must be False as per the RM 4.5.2 (30.2/4) clause.

gcc/ada/

* exp_ch4.adb (Expand_N_In): Deal specifically with a null operand.

2 years agoada: Fix small fallout of previous change
Eric Botcazou [Wed, 5 Apr 2023 11:56:42 +0000 (13:56 +0200)] 
ada: Fix small fallout of previous change

The same guard must be added to Expand_Simple_Function_Return as the one
that was added to Analyze_Function_Return.

gcc/ada/

* exp_ch6.adb (Expand_Simple_Function_Return): Deal with a rewriting
of the simple return during the adjustment of its expression.

2 years agoada: Fix wrong finalization for call to BIP function in conditional expression
Eric Botcazou [Mon, 3 Apr 2023 08:53:30 +0000 (10:53 +0200)] 
ada: Fix wrong finalization for call to BIP function in conditional expression

This happens when the call is a dependent expression of the conditional
expression, and the conditional expression is either the expression of a
simple return statement or the return expression of an expression function.

The reason is that the special processing of "tail calls" for BIP functions,
i.e. calls that are the expression of simple return statements or the return
expression of expression functions, is not applied.

This change makes sure that it is applied by distributing the simple return
statements enclosing conditional expressions into the dependent expressions
of the conditional expressions in almost all cases.  As a side effect, this
elides a temporary in the nonlimited by-reference case, as well as a pair of
calls to Adjust/Finalize in the nonlimited controlled case.

gcc/ada/

* exp_ch4.adb (Expand_N_Case_Expression): Distribute simple return
statements enclosing the conditional expression into the dependent
expressions in almost all cases.
(Expand_N_If_Expression): Likewise.
(Process_Transient_In_Expression): Adjust to the above distribution.
* exp_ch6.adb (Expand_Ctrl_Function_Call): Deal with calls in the
dependent expressions of a conditional expression.
* sem_ch6.adb (Analyze_Function_Return): Deal with the rewriting of
a simple return statement during the resolution of its expression.

2 years agoada: Accept parameters of enclosing subprograms in exceptional cases
Piotr Trojanek [Tue, 4 Apr 2023 11:38:14 +0000 (13:38 +0200)] 
ada: Accept parameters of enclosing subprograms in exceptional cases

Rules about parameters of modes OUT and IN OUT in aspect
Exceptional_Cases only apply to the parameters of the current
subprogram.

gcc/ada/

* sem_res.adb (Resolve_Entity_Name): Refine rules for Exceptional_Cases.

2 years agoada: Fix crash on vector initialization
Marc Poulhiès [Mon, 27 Mar 2023 14:47:04 +0000 (16:47 +0200)] 
ada: Fix crash on vector initialization

Initializing a vector using

 Vec : V.Vector := [Some_Type'(Some_Abstract_Type with F => 0)];

may crash the compiler. The expander marks the N_Extension_Aggregate for
delayed expansion which never happens and incorrectly ends up in gigi.

The delayed expansion is needed for nested aggregates, which the
original code is testing for, but container aggregates are handled
differently.

Such assignments to container aggregates are later transformed into
procedure calls to the procedures named in the Aggregate aspect
definition, for which the delayed expansion is not required/expected.

gcc/ada/

* exp_aggr.adb (Convert_To_Assignments): Do not mark node for
delayed expansion if parent type has the Aggregate aspect.
* sem_util.adb (Is_Container_Aggregate): Move...
* sem_util.ads (Is_Container_Aggregate): ... here and make it
public.

2 years agoada: Allow attributes like First and Last to be read in Exceptional_Cases
Piotr Trojanek [Tue, 4 Apr 2023 07:49:26 +0000 (09:49 +0200)] 
ada: Allow attributes like First and Last to be read in Exceptional_Cases

Attributes that do not read data from the object can be safely used in
consequences of Exceptional_Cases regardless of the parameter passing
mode.

gcc/ada/

* sem_res.adb (Resolve_Entity_Name): Relax rules for Exceptional_Cases.

2 years agoada: Repair support for user-defined literals in arithmetic operators
Eric Botcazou [Mon, 3 Apr 2023 15:11:11 +0000 (17:11 +0200)] 
ada: Repair support for user-defined literals in arithmetic operators

It was partially broken to fix a regression in error reporting, because the
fix was applied to the first pass of resolution instead of the second pass,
as needs to be done for user-defined literals.

gcc/ada/

* sem_ch4.ads (Unresolved_Operator): New procedure.
* sem_ch4.adb (Has_Possible_Literal_Aspects): Rename into...
(Has_Possible_User_Defined_Literal): ...this.  Tidy up.
(Operator_Check): Accept again unresolved operators if they have a
possible user-defined literal as operand.  Factor out the handling
of the general error message into...
(Unresolved_Operator): ...this new procedure.
* sem_res.adb (Resolve): Be prepared for unresolved operators on
entry in Ada 2022 or later.  If they are still unresolved on exit,
call Unresolved_Operator to give the error message.
(Try_User_Defined_Literal): Tidy up.

2 years agoada: Default_Component_Value trumps Initialize/Normalize_Scalars
Steve Baird [Thu, 30 Mar 2023 20:22:01 +0000 (13:22 -0700)] 
ada: Default_Component_Value trumps Initialize/Normalize_Scalars

If the Default_Component_Value aspect is specified for an array type, then
specifying Initialize_Scalars or Normalize_Scalars should have no effect
on the default initialization of an object of the array type.

gcc/ada/

* exp_ch3.adb
(Expand_N_Object_Declaration.Default_Initialize_Object): Add test for
specified Default_Component_Value aspect when deciding whether
either Initialize_Scalars or Normalize_Scalars impacts default
initialization of an array object.

2 years agoada: Crash on aggregate for tagged record with discriminants
Javier Miranda [Mon, 3 Apr 2023 17:15:47 +0000 (17:15 +0000)] 
ada: Crash on aggregate for tagged record with discriminants

The frontend may crash processing an aggregate initializing
a derived tagged record type that has discriminants.

gcc/ada/

* sem_aggr.adb
(Resolve_Record_Aggregate): For aggregates of derived tagged
record types with discriminants, when collecting components
from ancestors, pass to subprogram Gather_Components the
parent type. Required to report errors on wrong aggregate
components.

2 years agoada: Reuse routine for getting from body entity to spec entity
Piotr Trojanek [Wed, 29 Mar 2023 14:41:44 +0000 (16:41 +0200)] 
ada: Reuse routine for getting from body entity to spec entity

Cleanup related to handling of access-to-subprogram types with Pre and
Post aspects. Behavior is unaffected.

gcc/ada/

* sem_util.adb (Check_Result_And_Post_State): Replace low-level
navigation with a high-level Unique_Entity.

2 years agoada: Fix retrieval of spec entity from entry body entity
Piotr Trojanek [Wed, 29 Mar 2023 14:21:01 +0000 (16:21 +0200)] 
ada: Fix retrieval of spec entity from entry body entity

When retrieving entities of subprogram spec we only handled functions
and procedures, but not entries. This had no consequences, because we
then only applied checks to functions, but still is worth a cleanup, so
the code is easier to adapt for access-to-subprogram entities as well.

gcc/ada/

* sem_util.adb (Check_Result_And_Post_State): Properly handle entry
bodies.

2 years agoada: Restore parent link for both lists and nodes in class-wide condition
Piotr Trojanek [Mon, 3 Apr 2023 14:54:39 +0000 (16:54 +0200)] 
ada: Restore parent link for both lists and nodes in class-wide condition

When preanalysing class-wide conditions, we restore "Function (Object)"
to its original "Object.Function" notation. This requires the Parent
links to be fixed. We did it for nodes; now we do it for lists as well.

This patch is enough to fix assertion failure in CCG and to make the
tree well-connected. Perhaps there is a more elegant solution, but that
remains to be investigated.

gcc/ada/

* contracts.adb (Fix_Parent): Fir part both for lists and nodes.

2 years agoada: Refining handling of inlining for CCG
Arnaud Charlet [Tue, 27 Sep 2022 08:57:00 +0000 (08:57 +0000)] 
ada: Refining handling of inlining for CCG

By marking relevant functions inline when -gnatn is used.

gcc/ada/

* sem_ch7.adb: Refine handling of inlining for CCG

2 years agoada: Fix spurious error on nested instantiations with generic renaming
Eric Botcazou [Sat, 1 Apr 2023 19:57:21 +0000 (21:57 +0200)] 
ada: Fix spurious error on nested instantiations with generic renaming

The problem is that the renaming slightly changes the form of a global
reference that was saved during the analysis of a generic package, and
that is sufficient to fool the code adjusting global references during
the instantiation.

gcc/ada/

* sem_ch12.adb (Copy_Generic_Node): Test the original node kind
for the sake of consistency.  For identifiers and other entity
names and operators, accept an expanded name as associated node.
Replace "or" with "or else" in condtion and fix its formatting.

2 years agoada: Tune message for missing 'Result in Contract_Cases
Piotr Trojanek [Fri, 31 Mar 2023 14:43:23 +0000 (16:43 +0200)] 
ada: Tune message for missing 'Result in Contract_Cases

Make the message consistent with the one for postcondition.

gcc/ada/

* sem_util.adb (Check_Result_And_Post_State): Tune message.

2 years agoada: Simplify removal of formals from the scope
Piotr Trojanek [Fri, 31 Mar 2023 12:40:10 +0000 (14:40 +0200)] 
ada: Simplify removal of formals from the scope

Calls to Install_Formals are typically enclosed by Push_Scope/End_Scope.
There were just two such calls that instead used Pop_Scope, but most
likely that was by mistake.

Cleanup related to handling of class-wide contracts. Behavior appears to
be unaffected.

gcc/ada/

* contracts.adb (Remove_Formals): Remove.
(Preanalyze_Condition): Replace Pop_Scope with End_Scope.
* sem_ch13.adb (Build_Discrete_Static_Predicate): Replace
Pop_Scope with End_Scope; enclose Install_Formals within
Push_Scope/End_Scope.

2 years agoada: Tune message for pre/post on access-to-subprogram in old Ada
Piotr Trojanek [Fri, 31 Mar 2023 11:01:06 +0000 (13:01 +0200)] 
ada: Tune message for pre/post on access-to-subprogram in old Ada

Fix grammar in error message; make it consistent with a similar message
for pre/postcondition on formal subprogram.

gcc/ada/

* sem_prag.adb (Analyze_Pre_Post_Condition): Tune error message.

2 years agoada: Spurious error on string interpolation
Javier Miranda [Wed, 29 Mar 2023 18:48:19 +0000 (18:48 +0000)] 
ada: Spurious error on string interpolation

The frontend reports spurious errors on operators found in
interpolated string literals.

gcc/ada/

* scans.ads (Inside_Interpolated_String_Expression): New variable.
* par-ch2.adb (P_Interpolated_String_Literal): Set/clear new
variable when parsing interpolated string expressions.
* scng.adb (Set_String): Skip processing operator symbols when we
arescanning an interpolated string literal.

2 years agoada: Add QNX specific version of System.Parameters
Johannes Kliemann [Wed, 29 Mar 2023 10:42:20 +0000 (10:42 +0000)] 
ada: Add QNX specific version of System.Parameters

The QNX runtimes used the default implementation of
System.Parameters that defines a default stack size
of 2 MB. The QNX specific version uses the QNX default
stack size of 256 KB instead.

gcc/ada/

* Makefile.rtl (QNX): Use s-parame__qnx.adb for s-parame.adb.
* libgnat/s-parame__qnx.adb: Add QNX specific version of
System.Parameters.

2 years agoada: Restore SPARK_Mode On for numerical functions
Yannick Moy [Thu, 30 Mar 2023 13:07:09 +0000 (15:07 +0200)] 
ada: Restore SPARK_Mode On for numerical functions

GNATprove has ad-hoc support for the standard numerical functions, which
consists in emitting an unprovable preconditions on cases which could
lead to an overflow. These functions are thus valid to call from SPARK
code.

gcc/ada/

* libgnat/a-ngelfu.ads: Restore SPARK_Mode from context.

2 years agoada: Fix restoration of parent link
Marc Poulhiès [Wed, 22 Mar 2023 09:43:07 +0000 (10:43 +0100)] 
ada: Fix restoration of parent link

When resetting the parent link after having restored the selected
component node, the assertion used was incorrectly triggered when the
traversal hits the members of the parameters association list, as in:

   This.Some_Func (Param1, Param2).Dispatching_Call

When restoring the selected component for Dispatching_Call, the
assertion was wrongly triggered when passed Param1 and Param2.

gcc/ada/

* contracts.adb (Restore_Original_Selected_Component): Adjust assertion.

2 years agoada: Analyze pre/post on access-to-subprogram without a wrapper
Piotr Trojanek [Wed, 29 Mar 2023 08:03:29 +0000 (10:03 +0200)] 
ada: Analyze pre/post on access-to-subprogram without a wrapper

Aspects Pre/Post attached to an access-to-subprogram type were relocated
to a spec of a wrapper subprogram and analyzed there; the body of the
wrapper was only created with expansion enabled. However, there were
several problems with this approach.

When switch -gnat2022 was missing, we didn't relocate the Pre/Post
aspects to wrapper and complained that their placement is incorrect
(because we wrongly assumed that relocation is unconditional). Now we
gently inform, that these aspects are Ada 2022 features that require
-gnat20222 switch.

When switch -gnata was missing, we entirely bypassed analysis of the
Pre/Post aspects on access-to-subprogram. This was unlike for Pre/Post
aspects on subprograms, which are checked for legality regardless of the
-gnata switch.

Finally, in the GNATprove backend we were picking the Pre/Post contract
on an access-to-subprogram type from the wrapper, which was awkward as
otherwise we had to ignore the wrapper specs and special-case for their
missing bodies. In general, it is cleaner for GNATprove to extract the
aspect expressions from where they originally appear and not from
various expansion artifacts like access-to-subprogram wrappers (but the
same applies to predication functions, type invariant procedures and
default initialization procedures).

Now we analyze the Pre/Post aspects on the types where they are
originally attached, regardless of the -gnata switch. Once we adapt
GNATprove to pick the aspect expression from there, we will stop
creating the wrapper spec when expansion is disabled.

gcc/ada/

* contracts.adb
(Add_Pre_Post_Condition): Adapt to handle pre/post of an
access-to-subprogram type.
(Analyze_Type_Contract): Analyze pre/post of an
access-to-subprogram.
* contracts.ads
(Analyze_Type_Contract): Adapt comment.
* sem_ch3.adb
(Build_Access_Subprogram_Wrapper): Copy pre/post aspects to
wrapper spec and keep it on the type.
* sem_prag.adb
(Analyze_Pre_Post_Condition): Expect pre/post aspects on
access-to-subprogram and complain if they appear without -gnat2022
switch.
(Analyze_Pre_Post_Condition_In_Decl_Part): Adapt to handle
pre/post on an access-to-subprogram type entity.
* sem_attr.adb (Analyze_Attribute_Old_Result): Likewise.
(Result): Likewise.

2 years agoRISC-V: Fix VSETVL PASS ICE on SLP auto-vectorization
Juzhe-Zhong [Mon, 29 May 2023 06:41:00 +0000 (14:41 +0800)] 
RISC-V: Fix VSETVL PASS ICE on SLP auto-vectorization

Fix bug reported here:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109974

        PR target/109974

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

* config/riscv/riscv-vsetvl.cc (source_equal_p): Fix ICE.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/vsetvl/pr109974.c: New test.

2 years agoRISC-V: Remove redundant printf of abs-run.c
Juzhe-Zhong [Mon, 29 May 2023 04:52:36 +0000 (12:52 +0800)] 
RISC-V: Remove redundant printf of abs-run.c

Notice that this testcase cause unexpected fail:
FAIL: gcc.target/riscv/rvv/autovec/unop/abs-run.c (test for excess
errors)
Excess errors:
/work/home/jzzhong/work/rvv-opensource/software/host/toolchain/gcc/riscv-gcc/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/abs-run.c:22:7:
warning: implicit declaration of function 'printf'
[-Wimplicit-function-declaration]
/work/home/jzzhong/work/rvv-opensource/software/host/toolchain/gcc/riscv-gcc/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/abs-run.c:22:7:
warning: incompatible implicit declaration of built-in function 'printf'
[-Wbuiltin-declaration-mismatch]
/work/home/jzzhong/work/rvv-opensource/software/host/toolchain/gcc/riscv-gcc/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/abs-run.c:22:7:
warning: incompatible implicit declaration of built-in function 'printf'
[-Wbuiltin-declaration-mismatch]
/work/home/jzzhong/work/rvv-opensource/software/host/toolchain/gcc/riscv-gcc/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/abs-run.c:22:7:
warning: incompatible implicit declaration of built-in function 'printf'
[-Wbuiltin-declaration-mismatch]
/work/home/jzzhong/work/rvv-opensource/software/host/toolchain/gcc/riscv-gcc/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/abs-run.c:22:7:
warning: incompatible implicit declaration of built-in function 'printf'
[-Wbuiltin-declaration-mismatch]

spawn /work/home/jzzhong/work/rvv-opensource/output/sim/bin/spike
--isa=RV64GCVZfh
/work/home/jzzhong/work/rvv-opensource/output/sim/riscv64-rivai-elf/bin/pk
./abs-run.exe^M
bbl loader^M^M
0 0 -64^M
1 63 -63^M
2 2 -62^M
3 61 -61^M
4 4 -60^M
5 59 -59^M
6 6 -58^M
7 57 -57^M
8 8 -56^M
9 55 -55^M
10 10 -54^M
11 53 -53^M
12 12 -52^M
13 51 -51^M

Remove printf since it's unnecessary.

Signed-off-by: Juzhe-Zhong <juzhe.zhong@rivai.ai>
gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/unop/abs-run.c: Remove redundant printf.

2 years agoRISC-V: Add RVV FMA auto-vectorization support
Juzhe-Zhong [Mon, 29 May 2023 04:48:08 +0000 (12:48 +0800)] 
RISC-V: Add RVV FMA auto-vectorization support

This patch support FMA auto-vectorization pattern. Let's RA decide
vmacc or vmadd.

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

* config/riscv/autovec.md (fma<mode>4): New pattern.
(*fma<mode>): Ditto.
* config/riscv/riscv-protos.h (enum insn_type): New enum.
(emit_vlmax_ternary_insn): New function.
* config/riscv/riscv-v.cc (emit_vlmax_ternary_insn): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/rvv.exp: Add ternary tests
* gcc.target/riscv/rvv/autovec/ternop/ternop-1.c: New test.
* gcc.target/riscv/rvv/autovec/ternop/ternop-2.c: New test.
* gcc.target/riscv/rvv/autovec/ternop/ternop-3.c: New test.
* gcc.target/riscv/rvv/autovec/ternop/ternop_run-1.c: New test.
* gcc.target/riscv/rvv/autovec/ternop/ternop_run-2.c: New test.
* gcc.target/riscv/rvv/autovec/ternop/ternop_run-3.c: New test.

2 years agoRISC-V: Fix ternary instruction attribute bug
Juzhe-Zhong [Mon, 29 May 2023 04:21:48 +0000 (12:21 +0800)] 
RISC-V: Fix ternary instruction attribute bug

Fix bug of vector.md which generate incorrect information to
VSETVL PASS when testing FMA auto vectorization ternop-3.c.

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

* config/riscv/vector.md: Fix vimuladd instruction bug.

2 years agoRISC-V: Fix incorrect VXRM configuration in mode switching for CALL and ASM
Juzhe-Zhong [Mon, 29 May 2023 03:01:32 +0000 (11:01 +0800)] 
RISC-V: Fix incorrect VXRM configuration in mode switching for CALL and ASM

Currently mode switching incorrect codegen for the following case:
void fn (void);

void f (void * in, void *out, int32_t x, int n, int m)
{
  for (int i = 0; i < n; i++) {
    vint32m1_t v = __riscv_vle32_v_i32m1 (in + i, 4);
    vint32m1_t v2 = __riscv_vle32_v_i32m1_tu (v, in + 100 + i, 4);
    vint32m1_t v3 = __riscv_vaadd_vx_i32m1 (v2, 0, VXRM_RDN, 4);
    fn ();
    v3 = __riscv_vaadd_vx_i32m1 (v3, 3, VXRM_RDN, 4);
    __riscv_vse32_v_i32m1 (out + 100 + i, v3, 4);
  }
}

Before this patch:

Preheader:
  ...
  csrwi vxrm,2
Loop Body:
  ... (no cswri vxrm,2)
  vaadd.vx
  ...
  vaadd.vx
  ...

This codegen is incorrect.

After this patch:

Preheader:
  ...
  csrwi vxrm,2
Loop Body:
  ...
  vaadd.vx
  ...
  csrwi vxrm,2
  ...
  vaadd.vx
  ...

cross-compile build PASS and regression PASS.

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

* config/riscv/riscv.cc (global_state_unknown_p): New function.
(riscv_mode_after): Fix incorrect VXM.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/vxrm-11.c: New test.
* gcc.target/riscv/rvv/base/vxrm-12.c: New test.

2 years agoRISC-V: Add ZVFHMIN extension to the -march= option
Pan Li [Thu, 25 May 2023 11:56:40 +0000 (19:56 +0800)] 
RISC-V: Add ZVFHMIN extension to the -march= option

This patch would like to add new sub extension (aka ZVFHMIN) to the
-march= option. To make it simple, only the sub extension itself is
involved in this patch, and the underlying FP16 related RVV intrinsic
API depends on the TARGET_ZVFHMIN.

The Zvfhmin extension depends on the Zve32f extension. You can locate
more information about ZVFHMIN from below spec doc.

https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc#zvfhmin-vector-extension-for-minimal-half-precision-floating-point

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

* common/config/riscv/riscv-common.cc:
(riscv_implied_info): Add zvfhmin item.
(riscv_ext_version_table): Ditto.
(riscv_ext_flag_table): Ditto.
* config/riscv/riscv-opts.h (MASK_ZVFHMIN): New macro.
(TARGET_ZFHMIN): Align indent.
(TARGET_ZFH): Ditto.
(TARGET_ZVFHMIN): New macro.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/arch-20.c: New test.
* gcc.target/riscv/predef-26.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 years agoDaily bump.
GCC Administrator [Sun, 28 May 2023 00:16:46 +0000 (00:16 +0000)] 
Daily bump.

2 years ago[COMMITTED]: New entry to MAINTAINERS.
Benjamin Priour [Sat, 27 May 2023 20:28:45 +0000 (22:28 +0200)] 
[COMMITTED]: New entry to MAINTAINERS.

ChangeLog:

* MAINTAINERS: New entry.

2 years agoSplit notl + pbraodcast + pand to pbroadcast + pandn more modes.
liuhongt [Thu, 25 May 2023 08:14:14 +0000 (16:14 +0800)] 
Split notl + pbraodcast + pand to pbroadcast + pandn more modes.

r12-5595-gc39d77f252e895306ef88c1efb3eff04e4232554 adds 2 splitter to
transform notl + pbroadcast + pand to pbroadcast + pandn for
VI124_AVX2 which leaves out all DI-element-size ones as
well as all 512-bit ones.
This patch extend the splitter to VI_AVX2 which will handle DImode for
AVX2, and V64QImode,V32HImode,V16SImode,V8DImode for AVX512.

gcc/ChangeLog:

PR target/100711
* config/i386/sse.md (*andnot<mode>3): Extend below splitter
to VI_AVX2 to cover more modes.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr100711-2.c: Add v4di/v2di testcases.
* gcc.target/i386/pr100711-3.c: New test.

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.