[gcc r15-2662] ada: Fix detection of suspicious loop patterns

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:99337cb2385c38182e48a491442da449c028f51c

commit r15-2662-g99337cb2385c38182e48a491442da449c028f51c
Author: Ronan Desplanques 
Date:   Thu Jul 4 15:43:04 2024 +0200

ada: Fix detection of suspicious loop patterns

This patch fixes an assertion failure in some cases in the code to
warn about possible misuse of range attributes in loop. The root of
the problem is that this code failed to consider the case where the
outer loop is a while loop.

Also fix a typo in a nearby comment.

gcc/ada/

* sem_ch5.adb (Analyze_Loop_Statement): Fix loop pattern detection
code. Fix typo.

Diff:
---
 gcc/ada/sem_ch5.adb | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index e4506036cc2b..4db3a1a26ee3 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -3967,7 +3967,7 @@ package body Sem_Ch5 is
   Push_Scope (Ent);
   Analyze_Iteration_Scheme (Iter);
 
-  --  Check for following case which merits a warning if the type E of is
+  --  Check for following case which merits a warning if the type of E is
   --  a multi-dimensional array (and no explicit subscript ranges present).
 
   --  for J in E'Range
@@ -3992,6 +3992,10 @@ package body Sem_Ch5 is
 and then Number_Dimensions (Typ) > 1
 and then Nkind (Parent (N)) = N_Loop_Statement
 and then Present (Iteration_Scheme (Parent (N)))
+  --  The next conjunct tests that the enclosing loop is
+  --  a for loop and not a while loop.
+and then Present (Loop_Parameter_Specification
+  (Iteration_Scheme (Parent (N
   then
  declare
 OIter : constant Node_Id :=


[gcc r15-2663] ada: Fix crash on expression function returning tagged type in nested package

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:058e5fd2bd1f18e2c1b6bd1fc02e77560d99f8e8

commit r15-2663-g058e5fd2bd1f18e2c1b6bd1fc02e77560d99f8e8
Author: Eric Botcazou 
Date:   Thu Jul 4 23:35:01 2024 +0200

ada: Fix crash on expression function returning tagged type in nested 
package

This happens when the expression is a reference to a formal parameter of
the function, or a conditional expression with such a reference as one of
its dependent expressions, because the RM 6.5(8/5) subclause prescribes a
tag reassignment in this case, which requires freezing the tagged type in
the GNAT freezing model, although the language says there is no freezing.

In other words, it's another occurrence of the discrepancy between this
model tailored to Ada 95 and the freezing rules introduced in Ada 2012,
that is papered over by Should_Freeze_Type and the associated processing.

gcc/ada/

* exp_util.ads (Is_Conversion_Or_Reference_To_Formal): New
function declaration.
* exp_util.adb (Is_Conversion_Or_Reference_To_Formal): New
function body.
* exp_ch6.adb (Expand_Simple_Function_Return): Call the predicate
Is_Conversion_Or_Reference_To_Formal in order to decide whether a
tag check or reassignment is needed.
* freeze.adb (Should_Freeze_Type): Move declaration and body to
the appropriate places. Also return True for tagged results
subject to the expansion done in Expand_Simple_Function_Return
that is guarded by the predicate
Is_Conversion_Or_Reference_To_Formal.

Diff:
---
 gcc/ada/exp_ch6.adb  |   9 +--
 gcc/ada/exp_util.adb |  16 +
 gcc/ada/exp_util.ads |   4 ++
 gcc/ada/freeze.adb   | 180 +++
 4 files changed, 130 insertions(+), 79 deletions(-)

diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index 548589284e24..9c182b2c6b47 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -6989,14 +6989,7 @@ package body Exp_Ch6 is
   if Present (Utyp)
 and then Is_Tagged_Type (Utyp)
 and then not Is_Class_Wide_Type (Utyp)
-and then (Nkind (Exp) in
-  N_Type_Conversion | N_Unchecked_Type_Conversion
-or else (Nkind (Exp) = N_Explicit_Dereference
-   and then Nkind (Prefix (Exp)) in
-  N_Type_Conversion |
-  N_Unchecked_Type_Conversion)
-or else (Is_Entity_Name (Exp)
-   and then Is_Formal (Entity (Exp
+and then Is_Conversion_Or_Reference_To_Formal (Exp)
   then
  --  When the return type is limited, perform a check that the tag of
  --  the result is the same as the tag of the return type.
diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index de096ea752a5..c5d3af7545e3 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -8560,6 +8560,22 @@ package body Exp_Util is
   end if;
end Is_Captured_Function_Call;
 
+   --
+   -- Is_Conversion_Or_Reference_To_Formal --
+   --
+
+   function Is_Conversion_Or_Reference_To_Formal (N : Node_Id) return Boolean
+   is
+   begin
+  return Nkind (N) in N_Type_Conversion | N_Unchecked_Type_Conversion
+or else (Nkind (N) = N_Explicit_Dereference
+  and then Nkind (Prefix (N)) in N_Type_Conversion
+  |  N_Unchecked_Type_Conversion)
+or else (Is_Entity_Name (N)
+  and then Present (Entity (N))
+  and then Is_Formal (Entity (N)));
+   end Is_Conversion_Or_Reference_To_Formal;
+
--
-- Is_Finalizable_Transient --
--
diff --git a/gcc/ada/exp_util.ads b/gcc/ada/exp_util.ads
index c772d411bcfd..7fbbe5fc9fd2 100644
--- a/gcc/ada/exp_util.ads
+++ b/gcc/ada/exp_util.ads
@@ -769,6 +769,10 @@ package Exp_Util is
--Rnn : constant Ann := Func (...)'reference;
--Rnn.all
 
+   function Is_Conversion_Or_Reference_To_Formal (N : Node_Id) return Boolean;
+   --  Return True if N is a type conversion, or a dereference thereof, or a
+   --  reference to a formal parameter.
+
function Is_Finalizable_Transient
  (Decl : Node_Id;
   N: Node_Id) return Boolean;
diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index cf7a22efcae1..c8d20d020c70 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -185,77 +185,6 @@ package body Freeze is
--  the designated type. Otherwise freezing the access type does not freeze
--  the designated type.
 
-   function Should_Freeze_Type
- (Typ : Entity_Id; E : Entity_Id; N : Node_Id) return Boolean;
-   --  If Typ is in the current scope, then return True.
-   --  N is a

[gcc r15-2664] ada: Fix layout of GNAT reference manual section

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:b1dc668b71bf64046b65b508f43157fcaa095ea9

commit r15-2664-gb1dc668b71bf64046b65b508f43157fcaa095ea9
Author: Ronan Desplanques 
Date:   Fri Jul 5 10:52:58 2024 +0200

ada: Fix layout of GNAT reference manual section

gcc/ada/

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

Diff:
---
 gcc/ada/doc/gnat_rm/gnat_language_extensions.rst | 5 +++--
 gcc/ada/gnat_rm.texi | 5 +++--
 gcc/ada/gnat_ugn.texi| 2 +-
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst 
b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
index 0f001c4aca91..efda4afb7427 100644
--- a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
+++ b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
@@ -53,8 +53,6 @@ A basic_declarative_item may appear at the place of any 
statement.
 This avoids the heavy syntax of block_statements just to declare
 something locally.
 
-Link to the original RFC:
-https://github.com/AdaCore/ada-spark-rfcs/blob/master/prototyped/rfc-local-vars-without-block.md
 For example:
 
 .. code-block:: ada
@@ -67,6 +65,9 @@ For example:
   X := X + Squared;
end if;
 
+Link to the original RFC:
+https://github.com/AdaCore/ada-spark-rfcs/blob/master/prototyped/rfc-local-vars-without-block.md
+
 Conditional when constructs
 ---
 
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index b27bd627c17f..d15d6204cd8f 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -28850,8 +28850,6 @@ A basic_declarative_item may appear at the place of any 
statement.
 This avoids the heavy syntax of block_statements just to declare
 something locally.
 
-Link to the original RFC:
-@indicateurl{https://github.com/AdaCore/ada-spark-rfcs/blob/master/prototyped/rfc-local-vars-without-block.md}
 For example:
 
 @example
@@ -28864,6 +28862,9 @@ if X > 5 then
 end if;
 @end example
 
+Link to the original RFC:
+@indicateurl{https://github.com/AdaCore/ada-spark-rfcs/blob/master/prototyped/rfc-local-vars-without-block.md}
+
 @node Conditional when constructs,Fixed lower bounds for array types and 
subtypes,Local Declarations Without Block,Curated Extensions
 @anchor{gnat_rm/gnat_language_extensions 
conditional-when-constructs}@anchor{443}
 @subsection Conditional when constructs
diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi
index ea1d2f9d71a8..0e3ee935552d 100644
--- a/gcc/ada/gnat_ugn.texi
+++ b/gcc/ada/gnat_ugn.texi
@@ -29670,8 +29670,8 @@ to permit their use in free software.
 
 @printindex ge
 
-@anchor{gnat_ugn/gnat_utility_programs switches-related-to-project-files}@w{   
   }
 @anchor{d1}@w{  }
+@anchor{gnat_ugn/gnat_utility_programs switches-related-to-project-files}@w{   
   }
 
 @c %**end of body
 @bye


[gcc r15-2665] ada: Improve documenation about security of PRGNs

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:dc72d4dca9e6ee5af2ea2af0353a994a7a109db3

commit r15-2665-gdc72d4dca9e6ee5af2ea2af0353a994a7a109db3
Author: Johannes Kliemann 
Date:   Fri Jul 5 11:27:44 2024 +

ada: Improve documenation about security of PRGNs

The pseudo random number generators used in GNAT are not
suitable for applications that require cryptographic
security. While this was mentioned in some places others
did not have a corresponding note, leading to these
generators being used in a non-suitable context.

gcc/ada/

* doc/gnat_rm/standard_library_routines.rst: Add note to section
of Ada.Numerics.Discrete_Random and Ada.Numerics.Float_Random.
* doc/gnat_rm/the_gnat_library.rst: Add note to section about
GNAT.Random_Numbers.
* libgnat/a-nudira.ads: Add note about cryptographic properties.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

Diff:
---
 gcc/ada/doc/gnat_rm/standard_library_routines.rst |  6 --
 gcc/ada/doc/gnat_rm/the_gnat_library.rst  |  4 +++-
 gcc/ada/gnat_rm.texi  | 10 +++---
 gcc/ada/gnat_ugn.texi |  2 +-
 gcc/ada/libgnat/a-nudira.ads  |  2 ++
 5 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/doc/gnat_rm/standard_library_routines.rst 
b/gcc/ada/doc/gnat_rm/standard_library_routines.rst
index 27659a404630..2e7642652b2c 100644
--- a/gcc/ada/doc/gnat_rm/standard_library_routines.rst
+++ b/gcc/ada/doc/gnat_rm/standard_library_routines.rst
@@ -302,12 +302,14 @@ the unit is not implemented.
 
 ``Ada.Numerics.Discrete_Random``
   This generic package provides a random number generator suitable for 
generating
-  uniformly distributed values of a specified discrete subtype.
+  uniformly distributed values of a specified discrete subtype. It should not 
be
+  used as a cryptographic pseudo-random source.
 
 
 ``Ada.Numerics.Float_Random``
   This package provides a random number generator suitable for generating
-  uniformly distributed floating point values in the unit interval.
+  uniformly distributed floating point values in the unit interval. It should 
not
+  be used as a cryptographic pseudo-random source.
 
 
 ``Ada.Numerics.Generic_Complex_Elementary_Functions``
diff --git a/gcc/ada/doc/gnat_rm/the_gnat_library.rst 
b/gcc/ada/doc/gnat_rm/the_gnat_library.rst
index 88204d4cfe72..ac45b5eb7af8 100644
--- a/gcc/ada/doc/gnat_rm/the_gnat_library.rst
+++ b/gcc/ada/doc/gnat_rm/the_gnat_library.rst
@@ -1329,7 +1329,9 @@ convenient for use with realtime applications.
 .. index:: Random number generation
 
 Provides random number capabilities which extend those available in the
-standard Ada library and are more convenient to use.
+standard Ada library and are more convenient to use. This package is
+however NOT suitable for situations requiring cryptographically secure
+randomness.
 
 .. _`GNAT.Regexp_(g-regexp.ads)`:
 
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index d15d6204cd8f..d6e2f265ab9c 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -21142,12 +21142,14 @@ build the type @code{Complex} and @code{Imaginary}.
 @item @code{Ada.Numerics.Discrete_Random}
 
 This generic package provides a random number generator suitable for generating
-uniformly distributed values of a specified discrete subtype.
+uniformly distributed values of a specified discrete subtype. It should not be
+used as a cryptographic pseudo-random source.
 
 @item @code{Ada.Numerics.Float_Random}
 
 This package provides a random number generator suitable for generating
-uniformly distributed floating point values in the unit interval.
+uniformly distributed floating point values in the unit interval. It should not
+be used as a cryptographic pseudo-random source.
 
 @item @code{Ada.Numerics.Generic_Complex_Elementary_Functions}
 
@@ -24688,7 +24690,9 @@ convenient for use with realtime applications.
 @geindex Random number generation
 
 Provides random number capabilities which extend those available in the
-standard Ada library and are more convenient to use.
+standard Ada library and are more convenient to use. This package is
+however NOT suitable for situations requiring cryptographically secure
+randomness.
 
 @node GNAT Regexp g-regexp ads,GNAT Registry g-regist ads,GNAT Random_Numbers 
g-rannum ads,The GNAT Library
 @anchor{gnat_rm/the_gnat_library 
gnat-regexp-g-regexp-ads}@anchor{270}@anchor{gnat_rm/the_gnat_library 
id90}@anchor{39b}
diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi
index 0e3ee935552d..ea1d2f9d71a8 100644
--- a/gcc/ada/gnat_ugn.texi
+++ b/gcc/ada/gnat_ugn.texi
@@ -29670,8 +29670,8 @@ to permit their use in free software.
 
 @printindex ge
 
-@anchor{d1}@w{  }
 @anchor{gnat_ugn/gnat_utility_programs switches-related-to-project-files}@w{   
   }
+@anchor{d1}@w{  

[gcc r15-2667] ada: Type conversion in instance incorrectly rejected.

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:a846b4cfc7383e7a2550993cbf669b94db838069

commit r15-2667-ga846b4cfc7383e7a2550993cbf669b94db838069
Author: Steve Baird 
Date:   Mon Jul 8 14:45:55 2024 -0700

ada: Type conversion in instance incorrectly rejected.

In some cases, a legal type conversion in a generic package is correctly
accepted but the corresponding type conversion in an instance of the generic
is incorrectly rejected.

gcc/ada/

* sem_res.adb (Valid_Conversion): Test In_Instance instead of
In_Instance_Body.

Diff:
---
 gcc/ada/sem_res.adb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index 8a18430ff585..9a3b6ddbb534 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -14697,7 +14697,7 @@ package body Sem_Res is
 
   --  If it was legal in the generic, it's legal in the instance
 
-  elsif In_Instance_Body then
+  elsif In_Instance then
  return True;
 
   --  Ignore privacy for streaming or Put_Image routines


[gcc r15-2669] ada: Fix handling reference warnings with slices

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:d32a5294de92637680accd17d68421f485eaba32

commit r15-2669-gd32a5294de92637680accd17d68421f485eaba32
Author: Viljar Indus 
Date:   Tue Jul 9 10:34:37 2024 +0300

ada: Fix handling reference warnings with slices

gcc/ada/

* sem_util.adb (Set_Referenced_Modified): Set referenced as LHS
for the prefixes of array slices.

Diff:
---
 gcc/ada/sem_util.adb | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 7901eb8ee387..7b575c09c302 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -27787,9 +27787,10 @@ package body Sem_Util is
   Pref : Node_Id;
 
begin
-  --  Deal with indexed or selected component where prefix is modified
+  --  Deal with indexed components, selected components, or slices where
+  --  the prefix is modified.
 
-  if Nkind (N) in N_Indexed_Component | N_Selected_Component then
+  if Nkind (N) in N_Indexed_Component | N_Selected_Component | N_Slice then
 
  --  Grab the original node to avoid looking at internally generated
  --  objects.


[gcc r15-2670] ada: Finish up support for relaxed finalization

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:04fd9ee038684469d5ae1be6dda3c3ebbd87e8b1

commit r15-2670-g04fd9ee038684469d5ae1be6dda3c3ebbd87e8b1
Author: Eric Botcazou 
Date:   Tue Jul 9 22:44:40 2024 +0200

ada: Finish up support for relaxed finalization

This adds a variant of the System.Finalization_Primitives unit that supports
only controlled types with relaxed finalization, and adds the description of
its implementation to Exp_Ch7.

gcc/ada/

* exp_ch7.adb (Relaxed Finalization): New paragraph in head
comment.
* sem_ch13.adb (Validate_Finalizable_Aspect): Give an error
message if strict finalization is required but not supported by
the runtime.

Diff:
---
 gcc/ada/exp_ch7.adb  | 58 
 gcc/ada/sem_ch13.adb | 18 
 2 files changed, 72 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
index 044b14ad3055..b545a58448d8 100644
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -337,6 +337,64 @@ package body Exp_Ch7 is
--  directly by the compiler during the expansion of allocators and calls to
--  instances of the Unchecked_Deallocation procedure.
 
+   --
+   -- Relaxed Finalization --
+   --
+
+   --  This paragraph describes the differences between the implementation of
+   --  finalization as specified by the Ada RM (called "strict" and documented
+   --  in the previous paragraph) and that of finalization as specified by the
+   --  GNAT RM (called "relaxed") for a second category of controlled objects.
+
+   --  For objects (statically) declared in a scope, the default implementation
+   --  documented in the previous paragraph is used for the scope as a whole as
+   --  soon as one controlled object with strict finalization is present in it,
+   --  including one transient controlled object. Otherwise, that is to say, if
+   --  all the controlled objects in the scope have relaxed finalization, then
+   --  no Finalization_Master is built for this scope, and all the objects are
+   --  finalized explicitly in the reverse order of their creation:
+
+   --declare
+   --   X : Ctrl := Init;
+   --   Y : Ctrl := Init;
+
+   --begin
+   --   null;
+   --end;
+
+   --  is expanded into:
+
+   --declare
+   --   XMN : aliased System.Finalization_Primitives.Master_Node;
+   --   X : Ctrl := Init;
+   --   System.Finalization_Primitives.Attach_To_Node
+   -- (X'address,
+   --  CtrlFD'unrestricted_access,
+   --  XMN'unrestricted_access);
+   --   YMN : aliased System.Finalization_Primitives.Master_Node;
+   --   Y : Ctrl := Init;
+   --   System.Finalization_Primitives.Attach_To_Node
+   -- (Y'address,
+   --  CtrlFD'unrestricted_access,
+   --  YMN'unrestricted_access);
+
+   --   procedure _Finalizer is
+   --   begin
+   --  Abort_Defer;
+   --  System.Finalization_Primitives.Finalize_Object (YMN);
+   --  System.Finalization_Primitives.Finalize_Object (XMN);
+   --  Abort_Undefer;
+   --   end _Finalizer;
+
+   --begin
+   --   null;
+   --end;
+   --at end
+   --   _Finalizer;
+
+   --  Dynamically allocated objects with relaxed finalization need not be
+   --  finalized and, therefore, are not attached to any finalization chain.
+
type Final_Primitives is
  (Initialize_Case, Adjust_Case, Finalize_Case, Address_Case);
--  This enumeration type is defined in order to ease sharing code for
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 55b0a7a5ccf3..3fb0209f612e 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -17907,9 +17907,10 @@ package body Sem_Ch13 is
   --  If Relaxed_Finalization is set, the Finalize and Adjust procedures
   --  are considered as having the No_Raise aspect specified.
 
-  if Has_Relaxed_Finalization (Typ)
-and then Serious_Errors_Detected = 0
-  then
+  if Serious_Errors_Detected > 0 then
+ null;
+
+  elsif Has_Relaxed_Finalization (Typ) then
  Assoc := First (Component_Associations (Aggr));
  while Present (Assoc) loop
 Nam := First (Choices (Assoc));
@@ -17922,8 +17923,17 @@ package body Sem_Ch13 is
 
 Next (Assoc);
  end loop;
-  end if;
 
+  --  If Relaxed_Finalization is not set, then check that the support for
+  --  strict finalization is available in the runtime library.
+
+  elsif not In_Predefined_Unit (Cunit (Get_Source_Unit (Typ)))
+and then not RTE_Available (RE_Finalization_Master)
+  then
+ Error_Msg_N
+   ("only Relaxed Finalization is supported in this configuration",
+ASN);
+  end if;
end Validate_Finalizable_Aspect;
 
--


[gcc r15-2668] ada: Reject illegal uses of type/subtype current instance

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:e2fe0b18a66aafdd489ba9dbf148794906732f64

commit r15-2668-ge2fe0b18a66aafdd489ba9dbf148794906732f64
Author: Steve Baird 
Date:   Mon Jul 8 14:02:15 2024 -0700

ada: Reject illegal uses of type/subtype current instance

The current instance of a type or subtype (see RM 8.6) is an object or
value, not a type or subtype. So a name denoting such a current instance is
illegal in any context that requires a name denoting a type or subtype.
In some cases this error was not detected.

gcc/ada/

* sem_ch8.adb (Find_Type): If Is_Current_Instance returns True for
N (and Comes_From_Source (N) is also True) then flag an error.
Call Is_Current_Instance (twice) instead of duplicating (twice)
N_Access_Definition-related code in Is_Current_Instance.
* sem_util.adb (Is_Current_Instance): Implement
access-type-related clauses of the RM 8.6 current instance rule.
For pragmas Predicate and Predicate_Failure, distinguish between
the first and subsequent pragma arguments.

Diff:
---
 gcc/ada/sem_ch8.adb  | 24 ++--
 gcc/ada/sem_util.adb | 31 ++-
 2 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
index d2752af320ea..c77a69e51181 100644
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -8801,6 +8801,16 @@ package body Sem_Ch8 is
 Error_Msg_NE ("\\found & declared#", N, T_Name);
 Set_Entity (N, Any_Type);
 
+ elsif Is_Current_Instance (N) and then Comes_From_Source (N) then
+if Nkind (Parent (T_Name)) = N_Subtype_Declaration then
+   Error_Msg_N ("reference to current instance of subtype" &
+" does not denote a subtype (RM 8.6)", N);
+else
+   Error_Msg_N ("reference to current instance of type" &
+" does not denote a type (RM 8.6)", N);
+end if;
+Set_Entity (N, Any_Type);
+
  else
 --  If the type is an incomplete type created to handle
 --  anonymous access components of a record type, then the
@@ -8831,12 +8841,9 @@ package body Sem_Ch8 is
 if In_Open_Scopes (T_Name) then
if Ekind (Base_Type (T_Name)) = E_Task_Type then
 
-  --  In Ada 2005, a task name can be used in an access
-  --  definition within its own body.
+  --  OK if the "current instance" rule does not apply.
 
-  if Ada_Version >= Ada_2005
-and then Nkind (Parent (N)) = N_Access_Definition
-  then
+  if not Is_Current_Instance (N) then
  Set_Entity (N, T_Name);
  Set_Etype  (N, T_Name);
  return;
@@ -8849,12 +8856,9 @@ package body Sem_Ch8 is
 
elsif Ekind (Base_Type (T_Name)) = E_Protected_Type then
 
-  --  In Ada 2005, a protected name can be used in an access
-  --  definition within its own body.
+  --  OK if the "current instance" rule does not apply.
 
-  if Ada_Version >= Ada_2005
-and then Nkind (Parent (N)) = N_Access_Definition
-  then
+  if not Is_Current_Instance (N) then
  Set_Entity (N, T_Name);
  Set_Etype  (N, T_Name);
  return;
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 032684f3ddba..7901eb8ee387 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -16080,6 +16080,29 @@ package body Sem_Util is
   P   : Node_Id;
 
begin
+  --  Since Ada 2005, the "current instance" rule does not apply
+  --  to a type_mark in an access_definition (RM 8.6),
+  --  although it does apply in an access_to_object definition.
+  --  So the rule does not apply in the definition of an anonymous
+  --  access type, but it does apply in the definition of a named
+  --  access-to-object type.
+  --  The rule also does not apply in a designated subprogram profile.
+
+  if Ada_Version >= Ada_2005 then
+ case Nkind (Parent (N)) is
+when N_Access_Definition | N_Access_Function_Definition =>
+   return False;
+when N_Parameter_Specification =>
+   if Nkind (Parent (Parent (N))) in
+ N_Access_To_Subprogram_Definition
+   then
+  return False;
+   end if;
+when others =>
+   null;
+ end case;
+  end if;
+
   --  Simplest case: entity is a concurrent type and we are currently
   --  inside the body. This will eventually be expanded into a call to
   --  Self (for tasks) or _object (for protected objects).
@@ -16129,6 +161

[gcc r15-2671] ada: Compiler accepts illegal assignment to reference type target.

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:30ba62d91ff96b0f86cc1a8544dd1ed30196ca40

commit r15-2671-g30ba62d91ff96b0f86cc1a8544dd1ed30196ca40
Author: Steve Baird 
Date:   Tue Jul 9 16:54:59 2024 -0700

ada: Compiler accepts illegal assignment to reference type target.

An assignment statement whose LHS is of a reference type is never legal. If
no other legality rule is violated, then it is ambiguous. In some cases this
ambiguity was not correctly detected.

gcc/ada/

* sem_ch5.adb (Analyze_Assignment): Delete code that was
incorrectly implementing a preference rule.

Diff:
---
 gcc/ada/sem_ch5.adb | 8 
 1 file changed, 8 deletions(-)

diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index 4db3a1a26ee3..d44a12d1dd14 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -437,14 +437,6 @@ package body Sem_Ch5 is
then
   null;
 
-   --  This may be a call to a parameterless function through an
-   --  implicit dereference, so discard interpretation as well.
-
-   elsif Is_Entity_Name (Lhs)
- and then Has_Implicit_Dereference (It.Typ)
-   then
-  null;
-
elsif Has_Compatible_Type (Rhs, It.Typ) then
   if T1 = Any_Type then
  T1 := It.Typ;


[gcc r15-2672] ada: Reject ambiguous function calls in interpolated string expressions

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:ee7945e367c2e9a1127aac0c11c078638601258d

commit r15-2672-gee7945e367c2e9a1127aac0c11c078638601258d
Author: Javier Miranda 
Date:   Sat Jul 6 19:07:16 2024 +

ada: Reject ambiguous function calls in interpolated string expressions

This patch enhances support for this language feature by rejecting
more ambiguous function calls. In terms of name resolution, the
analysis of interpolated expressions is now treated as an expression
of any type, as required by the documentation. Additionally, support
for nested interpolated strings has been removed.

gcc/ada/

* gen_il-fields.ads (Is_Interpolated_String_Literal): New field.
* gen_il-gen-gen_nodes.adb (Is_Interpolated_String_Literal): The
new field is a flag handled by the parser (syntax flag).
* par-ch2.adb (P_Interpolated_String_Literal): Decorate the new
flag.
* sem_ch2.adb (Analyze_Interpolated_String_Literal): Improve code
detecting and reporting ambiguous function calls.
* sem_res.adb (Resolve_Interpolated_String_Literal): Restrict
resolution imposed by the context type to string literals that
have the new flag.
* sinfo.ads (Is_Interpolated_String_Literal): New field defined in
string literals. Fix documentation of the syntax rule of
interpolated string literal.

Diff:
---
 gcc/ada/gen_il-fields.ads|   1 +
 gcc/ada/gen_il-gen-gen_nodes.adb |   1 +
 gcc/ada/par-ch2.adb  |   2 +
 gcc/ada/sem_ch2.adb  | 242 ++-
 gcc/ada/sem_res.adb  |  13 ++-
 gcc/ada/sinfo.ads|   9 +-
 6 files changed, 213 insertions(+), 55 deletions(-)

diff --git a/gcc/ada/gen_il-fields.ads b/gcc/ada/gen_il-fields.ads
index 520ea554e114..9b85401eadc8 100644
--- a/gcc/ada/gen_il-fields.ads
+++ b/gcc/ada/gen_il-fields.ads
@@ -263,6 +263,7 @@ package Gen_IL.Fields is
   Is_In_Discriminant_Check,
   Is_Inherited_Pragma,
   Is_Initialization_Block,
+  Is_Interpolated_String_Literal,
   Is_Known_Guaranteed_ABE,
   Is_Machine_Number,
   Is_Null_Loop,
diff --git a/gcc/ada/gen_il-gen-gen_nodes.adb b/gcc/ada/gen_il-gen-gen_nodes.adb
index b1ca6cf6c865..7224556accd7 100644
--- a/gcc/ada/gen_il-gen-gen_nodes.adb
+++ b/gcc/ada/gen_il-gen-gen_nodes.adb
@@ -444,6 +444,7 @@ begin -- Gen_IL.Gen.Gen_Nodes
Cc (N_String_Literal, N_Numeric_Or_String_Literal,
(Sy (Strval, String_Id),
 Sy (Is_Folded_In_Parser, Flag),
+Sy (Is_Interpolated_String_Literal, Flag),
 Sm (Has_Wide_Character, Flag),
 Sm (Has_Wide_Wide_Character, Flag)));
 
diff --git a/gcc/ada/par-ch2.adb b/gcc/ada/par-ch2.adb
index f249ae760236..98232344dce1 100644
--- a/gcc/ada/par-ch2.adb
+++ b/gcc/ada/par-ch2.adb
@@ -237,6 +237,7 @@ package body Ch2 is
  Error_Msg_SC ("string literal expected");
 
   else
+ Set_Is_Interpolated_String_Literal (Token_Node);
  Append_To (Elements_List, Token_Node);
  Scan;  --  past string_literal
 
@@ -261,6 +262,7 @@ package body Ch2 is
   Error_Msg_SC ("unexpected string literal");
end if;
 
+   Set_Is_Interpolated_String_Literal (Token_Node);
Append_To (Elements_List, Token_Node);
Scan; --  past string_literal
 end if;
diff --git a/gcc/ada/sem_ch2.adb b/gcc/ada/sem_ch2.adb
index ddbb329d1f84..6d11b71b95fe 100644
--- a/gcc/ada/sem_ch2.adb
+++ b/gcc/ada/sem_ch2.adb
@@ -138,67 +138,113 @@ package body Sem_Ch2 is
 
procedure Analyze_Interpolated_String_Literal (N : Node_Id) is
 
-  procedure Check_Ambiguous_Parameterless_Call (Func_Call : Node_Id);
-  --  Examine the interpretations of the call to the given parameterless
-  --  function call and report the location of each interpretation.
+  procedure Check_Ambiguous_Call (Func_Call : Node_Id);
+  --  Examine the interpretations of the call to the given function call
+  --  and report the location of each interpretation.
 
-  
-  -- Check_Ambiguous_Parameterless_Call --
-  
+  --
+  -- Check_Ambiguous_Call --
+  --
 
-  procedure Check_Ambiguous_Parameterless_Call (Func_Call : Node_Id) is
+  procedure Check_Ambiguous_Call (Func_Call : Node_Id) is
 
- procedure Report_Interpretation (E : Entity_Id);
- --  Report an interpretation of the function call
+ procedure Report_Interpretation (Nam : Entity_Id; Typ : Entity_Id);
+ --  Report an interpretation of the function call. When calling a
+ --  standard operator, use the location of the type, which may be
+ --  user-defined.
 
  ---
  -- Report_Int

[gcc r15-2673] ada: Update doc of Style_Checks pragma

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:8239a5f75dffe5e3a95b3400da9a12c11fd0d100

commit r15-2673-g8239a5f75dffe5e3a95b3400da9a12c11fd0d100
Author: Tonu Naks 
Date:   Tue Jul 9 12:02:57 2024 +

ada: Update doc of Style_Checks pragma

gcc/ada/

* doc/gnat_rm/implementation_defined_pragmas.rst: Add examples.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

Diff:
---
 .../doc/gnat_rm/implementation_defined_pragmas.rst | 79 --
 gcc/ada/gnat_rm.texi   | 77 -
 gcc/ada/gnat_ugn.texi  |  2 +-
 3 files changed, 150 insertions(+), 8 deletions(-)

diff --git a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst 
b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
index 926c5f4e37b7..7ff94c4c2b90 100644
--- a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
+++ b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
@@ -6328,21 +6328,91 @@ activated.  These are additive, so they apply in 
addition to any previously
 set style check options.  The codes for the options are the same as those
 used in the *-gnaty* switch to *gcc* or *gnatmake*.
 For example the following two methods can be used to enable
-layout checking:
+layout checking and to change the maximum nesting level value:
 
 *
 
-  ::
+  .. code-block:: ada
 
+--  switch on layout checks
 pragma Style_Checks ("l");
-
+--  set the number of maximum allowed nesting levels to 15
+pragma Style_Checks ("L15");
 
 *
 
   ::
 
-gcc -c -gnatyl ...
+gcc -c -gnatyl -gnatyL15 ...
+
+
+The string literal values can be cumulatively switched on and off by prefixing
+the value with ``+`` or ``-``, where:
+
+* ``+`` is equivalent to no prefix. It applies the check referenced by the
+  literal value;
+* ``-`` switches the referenced check off.
+
+
+.. code-block:: ada
+  :linenos:
+  :emphasize-lines: 15
+
+  --  allow misaligned block by disabling layout check
+  pragma Style_Checks ("-l");
+  declare
+  msg : constant String := "Hello";
+  begin
+  Put_Line (msg);
+  end;
+
+  --  enable the layout check again
+  pragma Style_Checks ("l");
+  declare
+  msg : constant String := "Hello";
+  begin
+  Put_Line (msg);
+  end;
+
+The code above contains two layout errors, however, only
+the last line is picked up by the compiler.
+
+Similarly, the switches containing a numeric value can be applied in sequence.
+In the example below, the permitted nesting level is reduced in in the middle
+block and the compiler raises a warning on the highlighted line.
 
+.. code-block:: ada
+  :linenos:
+  :emphasize-lines: 15
+
+  -- Permit 3 levels of nesting
+  pragma Style_Checks ("L3");
+
+  procedure Main is
+  begin
+  if True then
+if True then
+null;
+end if;
+  end if;
+  --  Reduce permitted nesting levels to 2.
+  --  Note that "+L2" and "L2" are equivalent.
+  pragma Style_Checks ("+L2");
+  if True then
+if True then
+null;
+end if;
+  end if;
+  --  Disable checking permitted nesting levels.
+  --  Note that the number after "-L" is insignificant,
+  --  "-L", "-L3" and "-Lx" are all equivalent.
+  pragma Style_Checks ("-L3");
+  if True then
+if True then
+null;
+end if;
+  end if;
+  end Main;
 
 The form ``ALL_CHECKS`` activates all standard checks (its use is equivalent
 to the use of the :switch:`gnaty` switch with no options.
@@ -6356,7 +6426,6 @@ The forms with ``Off`` and ``On``
 can be used to temporarily disable style checks
 as shown in the following example:
 
-
 .. code-block:: ada
 
   pragma Style_Checks ("k"); -- requires keywords in lower case
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index d5e8931e088e..3a766ccc38db 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -7901,22 +7901,95 @@ activated.  These are additive, so they apply in 
addition to any previously
 set style check options.  The codes for the options are the same as those
 used in the `-gnaty' switch to `gcc' or `gnatmake'.
 For example the following two methods can be used to enable
-layout checking:
+layout checking and to change the maximum nesting level value:
 
 
 @itemize *
 
 @item 
 @example
+--  switch on layout checks
 pragma Style_Checks ("l");
+--  set the number of maximum allowed nesting levels to 15
+pragma Style_Checks ("L15");
 @end example
 
 @item 
 @example
-gcc -c -gnatyl ...
+gcc -c -gnatyl -gnatyL15 ...
 @end example
 @end itemize
 
+The string literal values can be cumulatively switched on and off by prefixing
+the value with @code{+} or @code{-}, where:
+
+
+@itemize *
+
+@item 
+@code{+} is equivalent to no prefix. It applies the check referenced by the
+literal value;
+
+@item 
+@code{-} switches the referenced check off.
+@end itemize
+
+@example
+--  allow misaligned block by disabling layout check
+pragma 

[gcc r15-2678] ada: Add contracts to Ada.Strings.Unbounded and adapt implementation

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:425eceb75d09f3fa228c3e26c5136ce0d688fbcf

commit r15-2678-g425eceb75d09f3fa228c3e26c5136ce0d688fbcf
Author: Yannick Moy 
Date:   Tue Jul 2 16:07:05 2024 +0200

ada: Add contracts to Ada.Strings.Unbounded and adapt implementation

Add complete functional contracts to all subprograms in
Ada.Strings.Unbounded, except Count, following the specification from
Ada RM A.4.5. These contracts are similar to the contracts found in
Ada.Strings.Fixed and Ada.Strings.Bounded.

A difference is that type Unbounded_String is controlled, thus we avoid
performing copies of a parameter Source with Source'Old, and instead
apply 'Old attribute on the enclosing call, such as Length(Source)'Old.

As Unbounded_String is controlled, the implementation is not in SPARK.
Instead, we have separately proved a slightly different implementation
for which Unbounded_String is not controlled, against the same
specification. This ensures that the specification is consistent.

To minimize differences between this test from the SPARK testsuite and
the actual implementation (the one in a-strunb.adb), and to avoid
overflows in the actual implementation, some code is slightly rewritten.
Delete and Insert are modified to return the correct result in all
cases allowed by the standard.

The same contracts are added to the version in a-strunb__shared.ads and
similar implementation patches are applied to the body
a-strunb__shared.adb. In particular, tests are added to avoid overflows
on strings for which the last index is Natural'Last, and the computations
that involve Sum to guarantee that an exception is raised in case of
overflow are rewritten to guarantee correct detection and no intermediate
overflows (and such tests are applied consistently between the procedure
and the function when both exist).

gcc/ada/

* libgnat/a-strunb.adb (Sum, Saturated_Sum, Saturated_Mul): Adapt
function signatures to more precise types that allow proof.
(function "&"): Conditionally assign a slice to avoid possible
overflow which only occurs when the assignment is a noop (because
the slice is empty in that case).
(Append): Same.
(function "*"): Retype K to avoid a possible overflow. Add early
return on null length for proof.
(Delete): Fix implementation to return the correct result in all
cases allowed by the Ada standard.
(Insert): Same. Also avoid possible overflows.
(Length): Rewrite as expression function for proof.
(Overwrite): Avoid possible overflows.
(Slice): Same.
(To_String): Rewrite as expression function for proof.
* libgnat/a-strunb.ads: Extend Assertion_Policy to new contracts
used. Add complete functional contracts to all subprograms of the
public API except Count.
* libgnat/a-strunb__shared.adb (Sum): Adapt function signature to
more precise types that allow proof.
(function "&"): Conditionally assign a slice to avoid possible
overflow.
(function "*"): Retype K to avoid a possible overflow.
(Delete): Fix implementation to return the correct result in all
cases allowed by the Ada standard.
(Insert): Avoid possible overflows.
(Overwrite): Avoid possible overflows.
(Replace_Slice): Same.
(Slice): Same.
(To_String): Rewrite as expression function for proof.
* libgnat/a-strunb__shared.ads: Extend Assertion_Policy to new
contracts used. Add complete functional contracts to all
subprograms of the public API except Count. Mark public part of
spec as in SPARK.

Diff:
---
 gcc/ada/libgnat/a-strunb.adb |  110 ++--
 gcc/ada/libgnat/a-strunb.ads | 1039 +++---
 gcc/ada/libgnat/a-strunb__shared.adb |  150 +++--
 gcc/ada/libgnat/a-strunb__shared.ads | 1029 ++---
 4 files changed, 2068 insertions(+), 260 deletions(-)

diff --git a/gcc/ada/libgnat/a-strunb.adb b/gcc/ada/libgnat/a-strunb.adb
index c3d4c71271b2..163906ed5cdd 100644
--- a/gcc/ada/libgnat/a-strunb.adb
+++ b/gcc/ada/libgnat/a-strunb.adb
@@ -30,22 +30,21 @@
 --
 
 with Ada.Strings.Fixed;
-with Ada.Strings.Search;
 with Ada.Unchecked_Deallocation;
 
 package body Ada.Strings.Unbounded is
 
-   function Sum (Left : Natural; Right : Integer) return Natural with Inline;
+   function Sum (Left, Right : Natural) return Natural with Inline;
--  Returns summary of Left and Right, raise Constraint_Error on overflow
 
function Mul (Left, Right : Natural) return Natural with Inline;
--  Returns multiplication of 

[gcc r15-2676] ada: Remove unreferenced procedure

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:342e3cdc8b29e5dcfb68159ce9f72b744519b3db

commit r15-2676-g342e3cdc8b29e5dcfb68159ce9f72b744519b3db
Author: Richard Kenner 
Date:   Fri Jul 12 09:38:21 2024 -0400

ada: Remove unreferenced procedure

gcc/ada/

* exp_ch4.adb (Generate_Temporary): Remove unused procedure.

Diff:
---
 gcc/ada/exp_ch4.adb | 43 ---
 1 file changed, 43 deletions(-)

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 371cb1182431..18ec7125cc1e 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -10816,49 +10816,6 @@ package body Exp_Ch4 is
  Expr : Node_Id;
  Ityp : Entity_Id;
 
- procedure Generate_Temporary;
- --  Generate a temporary to facilitate in the C backend the code
- --  generation of the unchecked conversion since the size of the
- --  source type may differ from the size of the target type.
-
- 
- -- Generate_Temporary --
- 
-
- procedure Generate_Temporary is
- begin
-if Esize (Etype (Expr)) < Esize (Etype (Ityp)) then
-   declare
-  Exp_Type : constant Entity_Id := Ityp;
-  Def_Id   : constant Entity_Id :=
-   Make_Temporary (Loc, 'R', Expr);
-  E: Node_Id;
-  Res  : Node_Id;
-
-   begin
-  Set_Is_Internal (Def_Id);
-  Set_Etype (Def_Id, Exp_Type);
-  Res := New_Occurrence_Of (Def_Id, Loc);
-
-  E :=
-Make_Object_Declaration (Loc,
-  Defining_Identifier => Def_Id,
-  Object_Definition   => New_Occurrence_Of
-   (Exp_Type, Loc),
-  Constant_Present=> True,
-  Expression  => Relocate_Node (Expr));
-
-  Set_Assignment_OK (E);
-  Insert_Action (Expr, E);
-
-  Set_Assignment_OK (Res, Assignment_OK (Expr));
-
-  Rewrite (Expr, Res);
-  Analyze_And_Resolve (Expr, Exp_Type);
-   end;
-end if;
- end Generate_Temporary;
-
   --  Start of processing for Discrete_Range_Check
 
   begin


[gcc r15-2674] ada: Add leap second support to conversion of Unix_Time

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:384283f91d218b7dbd0d665996512634383389ce

commit r15-2674-g384283f91d218b7dbd0d665996512634383389ce
Author: Tonu Naks 
Date:   Mon Jul 8 08:50:00 2024 +

ada: Add leap second support to conversion of Unix_Time

Unix timestamp jumps one second back when a leap second
is applied and doesn't count cumulative leap seconds.
This was not taken into account in conversions between
Unix time and Ada time. Now fixed.

gcc/ada/

* libgnat/a-calend.adb: Modify unix time handling.

Diff:
---
 gcc/ada/libgnat/a-calend.adb | 135 ++-
 1 file changed, 70 insertions(+), 65 deletions(-)

diff --git a/gcc/ada/libgnat/a-calend.adb b/gcc/ada/libgnat/a-calend.adb
index 1083ece44d29..c28042d13c46 100644
--- a/gcc/ada/libgnat/a-calend.adb
+++ b/gcc/ada/libgnat/a-calend.adb
@@ -110,6 +110,17 @@ is
  new Ada.Unchecked_Conversion (Duration, Time_Rep);
--  Convert a duration value into a time representation value
 
+   function Elapsed_Leaps (Start_Time, End_Time : Time_Rep) return Natural
+  with Pre => (End_Time >= Start_Time);
+   --  If the target supports leap seconds, determine the number of leap
+   --  seconds elapsed between start_time and end_time.
+   --
+   --  NB! This function assumes that End_Time is not smaller than
+   --  Start_Time. There are usages of the function that correct the time
+   --  by passed leap seconds and use the results for another seach.
+   --  If negative leap seconds are introduced eventually, then such
+   --  calls should be revised as the correction can go to either direction.
+
function Time_Rep_To_Duration is
  new Ada.Unchecked_Conversion (Time_Rep, Duration);
--  Convert a time representation value into a duration value
@@ -355,13 +366,34 @@ is
   end if;
end Check_Within_Time_Bounds;
 
+   ---
+   -- Elapsed_Leaps --
+   ---
+
+   function Elapsed_Leaps (Start_Time, End_Time : Time_Rep) return Natural
+   is
+  Elapsed   : Natural := 0;
+  Next_Leap_N   : Time_Rep;
+   begin
+  if Leap_Support then
+ Cumulative_Leap_Seconds
+   (Start_Time, End_Time, Elapsed, Next_Leap_N);
+
+ --  The system clock may fall exactly on a leap second
+
+ if End_Time >= Next_Leap_N then
+Elapsed := Elapsed + 1;
+ end if;
+  end if;
+
+  return Elapsed;
+   end Elapsed_Leaps;
+
---
-- Clock --
---
 
function Clock return Time is
-  Elapsed_Leaps : Natural;
-  Next_Leap_N   : Time_Rep;
 
   --  The system clock returns the time in UTC since the Unix Epoch of
   --  1970-01-01 00:00:00.0. We perform an origin shift to the Ada Epoch
@@ -371,26 +403,7 @@ is
 Duration_To_Time_Rep (System.OS_Primitives.Clock) + Unix_Min;
 
begin
-  --  If the target supports leap seconds, determine the number of leap
-  --  seconds elapsed until this moment.
-
-  if Leap_Support then
- Cumulative_Leap_Seconds
-   (Start_Of_Time, Res_N, Elapsed_Leaps, Next_Leap_N);
-
- --  The system clock may fall exactly on a leap second
-
- if Res_N >= Next_Leap_N then
-Elapsed_Leaps := Elapsed_Leaps + 1;
- end if;
-
-  --  The target does not support leap seconds
-
-  else
- Elapsed_Leaps := 0;
-  end if;
-
-  Res_N := Res_N + Time_Rep (Elapsed_Leaps) * Nano;
+  Res_N := Res_N + Time_Rep (Elapsed_Leaps (Start_Of_Time, Res_N)) * Nano;
 
   return Time (Res_N);
end Clock;
@@ -806,10 +819,8 @@ is
   is
  Res_Dur   : Time_Dur;
  Earlier   : Time_Rep;
- Elapsed_Leaps : Natural;
  Later : Time_Rep;
  Negate: Boolean := False;
- Next_Leap_N   : Time_Rep;
  Sub_Secs  : Duration;
  Sub_Secs_Diff : Time_Rep;
 
@@ -825,22 +836,6 @@ is
 Negate  := True;
  end if;
 
- --  If the target supports leap seconds, process them
-
- if Leap_Support then
-Cumulative_Leap_Seconds
-  (Earlier, Later, Elapsed_Leaps, Next_Leap_N);
-
-if Later >= Next_Leap_N then
-   Elapsed_Leaps := Elapsed_Leaps + 1;
-end if;
-
- --  The target does not support leap seconds
-
- else
-Elapsed_Leaps := 0;
- end if;
-
  --  Sub seconds processing. We add the resulting difference to one
  --  of the input dates in order to account for any potential rounding
  --  of the difference in the next step.
@@ -856,12 +851,14 @@ is
  --  either add or drop a second. We compensate for this issue in the
  --  previous step.
 
+ Leap_Seconds := Elapsed_Leaps (Earlier, Later);
+
  Res_Dur :=
-   Time_Dur (Later / Nano - Earlier / Nano) - Time_Dur (Elapsed_Leaps);
+   Time_Dur (Later / Nano - Earlier / N

[gcc r15-2677] ada: Ensure variable is initialized before use

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:eb43eb5c1a9b691b77782938f41de33506694a54

commit r15-2677-geb43eb5c1a9b691b77782938f41de33506694a54
Author: Ronan Desplanques 
Date:   Fri Jul 12 10:56:58 2024 +0200

ada: Ensure variable is initialized before use

This patch is motivated by a GNAT SAS report.

gcc/ada/

* scng.adb (Slit): Initialize object in uncommon path.

Diff:
---
 gcc/ada/scng.adb | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/ada/scng.adb b/gcc/ada/scng.adb
index c9ccc4d9b52f..08ce2ab5ad1c 100644
--- a/gcc/ada/scng.adb
+++ b/gcc/ada/scng.adb
@@ -1166,6 +1166,7 @@ package body Scng is
  when '\' | '"' | '{' | '}'
   => Code := Get_Char_Code (C);
  when others =>
+Code := Get_Char_Code ('?');
 Error_Msg_S ("illegal escaped character");
   end case;


[gcc r15-2686] ada: Fix handling of iterated component associations with sub-aggregates

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:d8a27bb9a7d932b3a3f8b1ffc9e156f698d08aee

commit r15-2686-gd8a27bb9a7d932b3a3f8b1ffc9e156f698d08aee
Author: Piotr Trojanek 
Date:   Tue Jul 16 16:07:59 2024 +0200

ada: Fix handling of iterated component associations with sub-aggregates

Fix a number of problems in handling of actions generated for a
2-dimensional array aggregate where the outer aggregate has iterated
component association and the inner aggregate involves run-time checks.

gcc/ada/

* exp_aggr.adb (Add_Loop_Actions): Actions are now attached to
iterated component association just like they are attached to
ordinary component association.
(Build_Array_Aggr_Code): If resolution of the array aggregate
generated some actions, e.g. for run-time checks, then we must
keep them; same for the Other_Clause.
* sem_aggr.adb (Resolve_Iterated_Component_Association): Unset
references to iterator variable in loop actions (which might come
from run-time check), just these references are unset in the
expression itself.

Diff:
---
 gcc/ada/exp_aggr.adb | 14 +++---
 gcc/ada/sem_aggr.adb |  9 +
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 8496fcd9b002..aa6079d82b58 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -1259,7 +1259,8 @@ package body Exp_Aggr is
 if No (Expr) then
return Lis;
 
-elsif Nkind (Parent (Expr)) = N_Component_Association
+elsif Nkind (Parent (Expr)) in N_Component_Association
+ | N_Iterated_Component_Association
   and then Present (Loop_Actions (Parent (Expr)))
 then
Res := Loop_Actions (Parent (Expr));
@@ -1962,7 +1963,9 @@ package body Exp_Aggr is
 
Bounds := Get_Index_Bounds (Choice);
 
-   if Low /= High then
+   if Low /= High
+ and then No (Loop_Actions (Assoc))
+   then
   Set_Loop_Actions (Assoc, New_List);
end if;
 
@@ -2038,7 +2041,12 @@ package body Exp_Aggr is
 
   if First or else not Empty_Range (Low, High) then
  First := False;
- Set_Loop_Actions (Others_Assoc, New_List);
+ if Present (Loop_Actions (Others_Assoc)) then
+pragma Assert
+  (Is_Empty_List (Loop_Actions (Others_Assoc)));
+ else
+Set_Loop_Actions (Others_Assoc, New_List);
+ end if;
  Expr := Get_Assoc_Expr (Others_Assoc);
  Append_List (Gen_Loop (Low, High, Expr), To => New_Code);
   end if;
diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index 656d789de735..087e324b5c15 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -2212,6 +2212,15 @@ package body Sem_Aggr is
 
  if Operating_Mode /= Check_Semantics then
 Remove_References (Expr);
+declare
+   Loop_Action : Node_Id;
+begin
+   Loop_Action := First (Loop_Actions (N));
+   while Present (Loop_Action) loop
+  Remove_References (Loop_Action);
+  Next (Loop_Action);
+   end loop;
+end;
  end if;
 
  --  An iterated_component_association may appear in a nested


[gcc r15-2675] ada: Clean up handling of inlining of finalizer procedures

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:3e64ad035302af0cd8e329bb508aa9ef1eb27597

commit r15-2675-g3e64ad035302af0cd8e329bb508aa9ef1eb27597
Author: Richard Kenner 
Date:   Fri Jul 12 09:45:26 2024 -0400

ada: Clean up handling of inlining of finalizer procedures

Change Is_Finalizer from synthesized attribute into flag. Remove duplicate
Is_Finalizer_Proc. Add new Try_Inline_Always for backend usage.

gcc/ada/

* einfo-utils.ads (Is_Finalizer): Delete.
* einfo-utils.adb (Is_Finalizer): Delete.
* einfo.ads: Adjust comment.
* gen_il-fields.ads, gen_il-gen-gen_entities.adb: Add Is_Finalizer
flag.
* exp_ch3.adb (Build_Init_Procedure): Set it.
* exp_ch7.adb (Create_Finalizer): Likewise.
* exp_util.adb (Try_Inline_Always): New function.
* exp_util.ads (Try_Inline_Always): New function.
* sem_elab.adb (Is_Finalizer_Proc): Replace with Is_Finalizer.

Diff:
---
 gcc/ada/einfo-utils.adb |  9 -
 gcc/ada/einfo-utils.ads |  1 -
 gcc/ada/einfo.ads   |  2 +-
 gcc/ada/exp_ch3.adb |  1 +
 gcc/ada/exp_ch7.adb |  1 +
 gcc/ada/exp_util.adb| 10 ++
 gcc/ada/exp_util.ads|  5 +
 gcc/ada/gen_il-fields.ads   |  1 +
 gcc/ada/gen_il-gen-gen_entities.adb |  1 +
 gcc/ada/sem_elab.adb| 26 +-
 10 files changed, 25 insertions(+), 32 deletions(-)

diff --git a/gcc/ada/einfo-utils.adb b/gcc/ada/einfo-utils.adb
index c0c79f92e136..3dc25b36ad41 100644
--- a/gcc/ada/einfo-utils.adb
+++ b/gcc/ada/einfo-utils.adb
@@ -1567,15 +1567,6 @@ package body Einfo.Utils is
 Has_Option (Id, Name_Synchronous));
end Is_External_State;
 
-   --
-   -- Is_Finalizer --
-   --
-
-   function Is_Finalizer (Id : E) return B is
-   begin
-  return Ekind (Id) = E_Procedure and then Chars (Id) = Name_uFinalizer;
-   end Is_Finalizer;
-
--
-- Is_Full_Access --
--
diff --git a/gcc/ada/einfo-utils.ads b/gcc/ada/einfo-utils.ads
index 8207576fb89f..c0480c71cb86 100644
--- a/gcc/ada/einfo-utils.ads
+++ b/gcc/ada/einfo-utils.ads
@@ -190,7 +190,6 @@ package Einfo.Utils is
function Is_Dynamic_Scope (Id : E) return B;
function Is_Elaboration_Target (Id : E) return B;
function Is_External_State (Id : E) return B;
-   function Is_Finalizer (Id : E) return B with Inline;
function Is_Full_Access (Id : E) return B with Inline;
function Is_Null_State (Id : E) return B;
function Is_Package_Or_Generic_Package (Id : E) return B with Inline;
diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index 9d0f2ee3c028..4486ab3636fd 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -2647,7 +2647,7 @@ package Einfo is
 --   the transient finalization mechanisms. The flag prevents the double
 --   finalization of the object.
 
---Is_Finalizer (synthesized)
+--Is_Finalizer
 --   Applies to all entities, true for procedures containing finalization
 --   code to process local or library level objects.
 
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 6fee2b41bac6..bf04ea9d70a5 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -3532,6 +3532,7 @@ package body Exp_Ch3 is
DF_Id :=
  Make_Defining_Identifier (Loc,
Chars => New_External_Name (Name_uFinalizer));
+   Set_Is_Finalizer (DF_Id);
 
Append_To (Decls, Make_Local_Deep_Finalize (Rec_Type, DF_Id));
 
diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
index b545a58448d8..72f0b539c2eb 100644
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -1979,6 +1979,7 @@ package body Exp_Ch7 is
 Fin_Id :=
   Make_Defining_Identifier (Loc,
 Chars => New_External_Name (Name_uFinalizer));
+Set_Is_Finalizer (Fin_Id);
 
 --  The visibility semantics of At_End handlers force a strange
 --  separation of spec and body for stack-related finalizers:
diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index c5d3af7545e3..bd8bbb39d9c8 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -14525,6 +14525,16 @@ package body Exp_Util is
   return Target;
end Thunk_Target;
 
+   ---
+   -- Try_Inline_Always --
+   ---
+
+   function Try_Inline_Always (Subp : Entity_Id) return Boolean is
+ ((Is_Expression_Function (Subp) or else Is_Finalizer (Subp))
+   and then not Debug_Flag_Dot_8);
+   --  We want to inline expression functions and finalizers as much as
+   --  practical unless -gnatd.8.
+
---
-- Type_Map_Hash --
---
diff --git a/gcc/ada/exp_util.ads b/gcc/ada/exp_util.ads
index 7fbbe5fc9fd2..14d9e345b537 100644
--- a

[gcc r15-2682] ada: Simplify code by reusing Choice_List

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:4d9dfa0082ee46ce969283fafe67b2008ab661fc

commit r15-2682-g4d9dfa0082ee46ce969283fafe67b2008ab661fc
Author: Piotr Trojanek 
Date:   Fri Jul 5 13:01:08 2024 +0200

ada: Simplify code by reusing Choice_List

Code cleanup; semantics is unaffected.

gcc/ada/

* exp_aggr.adb (Gen_Assign): Fix layout.
* sem_aggr.adb (Empty_Range): Reuse Choice_List.

Diff:
---
 gcc/ada/exp_aggr.adb | 8 
 gcc/ada/sem_aggr.adb | 8 +---
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 25af78a4da7b..7a2d0570dbd4 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -1010,8 +1010,8 @@ package body Exp_Aggr is
   --  Returns a new reference to the index type name
 
   function Gen_Assign
-(Ind : Node_Id;
- Expr: Node_Id) return List_Id;
+(Ind  : Node_Id;
+ Expr : Node_Id) return List_Id;
   --  Ind must be a side-effect-free expression. If the input aggregate N
   --  to Build_Loop contains no subaggregates, then this function returns
   --  the assignment statement:
@@ -1237,8 +1237,8 @@ package body Exp_Aggr is
   
 
   function Gen_Assign
-(Ind : Node_Id;
- Expr: Node_Id) return List_Id
+(Ind  : Node_Id;
+ Expr : Node_Id) return List_Id
is
  function Add_Loop_Actions (Lis : List_Id) return List_Id;
  --  Collect insert_actions generated in the construction of a loop,
diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index 565f2cb8a794..656d789de735 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -2735,15 +2735,9 @@ package body Sem_Aggr is
 -
 
 function Empty_Range (A : Node_Id) return Boolean is
-   R : Node_Id;
+   R : constant Node_Id := First (Choice_List (A));
 
 begin
-   if Nkind (A) = N_Iterated_Component_Association then
-  R := First (Discrete_Choices (A));
-   else
-  R := First (Choices (A));
-   end if;
-
return No (Next (R))
  and then Nkind (R) = N_Range
  and then Compile_Time_Compare


[gcc r15-2683] ada: Refactor negated conjuncts

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:72ae355328fe30d61227501be4314689295a03f1

commit r15-2683-g72ae355328fe30d61227501be4314689295a03f1
Author: Piotr Trojanek 
Date:   Fri Jul 5 17:15:49 2024 +0200

ada: Refactor negated conjuncts

Code cleanup; semantics is unaffected.

gcc/ada/

* exp_util.adb (Insert_Actions): Move negation in front of
complex conjunctions.

Diff:
---
 gcc/ada/exp_util.adb | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index bd8bbb39d9c8..bde50687597d 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -8146,12 +8146,13 @@ package body Exp_Util is
  --  not already set can lead to gigi assertion failures that
  --  are presumably due to malformed trees, so don't do that.
 
- and then (Nkind (P) /= N_Iterated_Component_Association
-or else not Is_List_Member (N)
-or else
-  List_Containing (N) /= Discrete_Choices (P))
- and then (Nkind (P) /= N_Component_Association
-or else Present (Loop_Actions (P)))
+ and then
+   not (Nkind (P) = N_Iterated_Component_Association
+  and then Is_List_Member (N)
+  and then List_Containing (N) = Discrete_Choices (P))
+ and then
+   not (Nkind (P) = N_Component_Association
+  and then No (Loop_Actions (P)))
then
   if Is_Empty_List (Loop_Actions (P)) then
  Set_Loop_Actions (P, Ins_Actions);


[gcc r15-2679] ada: Tweak container aggregate expansion code

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:54acd24d5f82766e7ad43a41519b00369ae46863

commit r15-2679-g54acd24d5f82766e7ad43a41519b00369ae46863
Author: Ronan Desplanques 
Date:   Mon Jul 15 10:22:29 2024 +0200

ada: Tweak container aggregate expansion code

This patch makes a minor modification to Expand_Container_Aggregate
in order to silence a GNAT SAS false positive.

gcc/ada/

* exp_aggr.adb (Expand_Container_Aggregate): Remove variables.
(To_Int): New function.
(Add_Range_Size): Use newly introduced function.

Diff:
---
 gcc/ada/exp_aggr.adb | 40 ++--
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 59ed75e8d695..ed0dad1444b3 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -6642,8 +6642,6 @@ package body Exp_Aggr is
 
   Choice_Lo : Node_Id := Empty;
   Choice_Hi : Node_Id := Empty;
-  Int_Choice_Lo : Int;
-  Int_Choice_Hi : Int;
 
   Is_Indexed_Aggregate : Boolean := False;
 
@@ -6696,32 +6694,38 @@ package body Exp_Aggr is
  
 
  procedure Add_Range_Size is
-Range_Int_Lo : Int;
-Range_Int_Hi : Int;
+function To_Int (Expr : N_Subexpr_Id) return Int;
+--  Return the Int value corresponding to the bound Expr
 
- begin
---  The bounds of the discrete range are integers or enumeration
---  literals
+
+-- To_Int --
+
 
-if Nkind (Lo) = N_Integer_Literal then
-   Range_Int_Lo := UI_To_Int (Intval (Lo));
-   Range_Int_Hi := UI_To_Int (Intval (Hi));
+function To_Int (Expr : N_Subexpr_Id) return Int is
+begin
+   --  The bounds of the discrete range are integers or enumeration
+   --  literals
+   return UI_To_Int
+ ((if Nkind (Expr) = N_Integer_Literal then
+ Intval (Expr)
+   else
+ Enumeration_Pos (Expr)));
+end To_Int;
 
-else
-   Range_Int_Lo := UI_To_Int (Enumeration_Pos (Lo));
-   Range_Int_Hi := UI_To_Int (Enumeration_Pos (Hi));
-end if;
+--  Local variables
+
+Range_Int_Lo : constant Int := To_Int (Lo);
+Range_Int_Hi : constant Int := To_Int (Hi);
 
+ begin
 Siz := Siz + Range_Int_Hi - Range_Int_Lo + 1;
 
-if No (Choice_Lo) or else Range_Int_Lo < Int_Choice_Lo then
+if No (Choice_Lo) or else Range_Int_Lo < To_Int (Choice_Lo) then
Choice_Lo   := Lo;
-   Int_Choice_Lo := Range_Int_Lo;
 end if;
 
-if No (Choice_Hi) or else Range_Int_Hi > Int_Choice_Hi then
+if No (Choice_Hi) or else Range_Int_Hi > To_Int (Choice_Hi) then
Choice_Hi   := Hi;
-   Int_Choice_Hi := Range_Int_Hi;
 end if;
  end Add_Range_Size;


[gcc r15-2680] ada: Plug loophole in handling of No_Raise pragma

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:5f3902ed1d9c7686fa7bad1e24f0c2b40fd35efe

commit r15-2680-g5f3902ed1d9c7686fa7bad1e24f0c2b40fd35efe
Author: Eric Botcazou 
Date:   Mon Jul 15 22:29:06 2024 +0200

ada: Plug loophole in handling of No_Raise pragma

Unlike the aspect, the pragma needs to be propagated explicitly from a
generic subprogram to its instances.

gcc/ada/

* sem_ch12.adb (Analyze_Subprogram_Instantiation): Propagate the
No_Raise flag like the No_Return flag.

Diff:
---
 gcc/ada/sem_ch12.adb | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index 6b98343aeebe..25821cb76954 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -6069,9 +6069,16 @@ package body Sem_Ch12 is
  Set_Has_Pragma_No_Inline
(Anon_Id, Has_Pragma_No_Inline (Gen_Unit));
 
- --  Propagate No_Return if pragma applied to generic unit. This must
- --  be done explicitly because pragma does not appear in generic
- --  declaration (unlike the aspect case).
+ --  Propagate No_Raise if pragma applied to generic unit. This must
+ --  be done explicitly because the pragma does not appear in generic
+ --  declarations (unlike the aspect).
+
+ if No_Raise (Gen_Unit) then
+Set_No_Raise (Act_Decl_Id);
+Set_No_Raise (Anon_Id);
+ end if;
+
+ --  Likewise for No_Return
 
  if No_Return (Gen_Unit) then
 Set_No_Return (Act_Decl_Id);


[gcc r15-2684] ada: Simplify manipulation of the list with loop actions

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:913fa16483256daacd576476312dfcc2d2421517

commit r15-2684-g913fa16483256daacd576476312dfcc2d2421517
Author: Piotr Trojanek 
Date:   Fri Jul 5 17:16:36 2024 +0200

ada: Simplify manipulation of the list with loop actions

Code cleanup; behavior is unaffected.

gcc/ada/

* exp_aggr.adb (Add_Loop_Actions): Change manipulation of list
to avoid unnecessary calls to Parent and Loop_Actions.

Diff:
---
 gcc/ada/exp_aggr.adb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 7a2d0570dbd4..8496fcd9b002 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -1262,9 +1262,9 @@ package body Exp_Aggr is
 elsif Nkind (Parent (Expr)) = N_Component_Association
   and then Present (Loop_Actions (Parent (Expr)))
 then
-   Append_List (Lis, Loop_Actions (Parent (Expr)));
Res := Loop_Actions (Parent (Expr));
Set_Loop_Actions (Parent (Expr), No_List);
+   Append_List (Lis, To => Res);
return Res;
 
 else


[gcc r15-2685] ada: Remove unused null branch

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:637b27b98076d8857aa62655bbb815a39f8f68bc

commit r15-2685-g637b27b98076d8857aa62655bbb815a39f8f68bc
Author: Piotr Trojanek 
Date:   Fri Jul 5 17:42:00 2024 +0200

ada: Remove unused null branch

Code cleanup; semantics is unaffected.

gcc/ada/

* exp_util.adb (Insert_Actions): Remove null ELSE branch.

Diff:
---
 gcc/ada/exp_util.adb | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index bde50687597d..ef8c91dfe949 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -8186,9 +8186,6 @@ package body Exp_Util is
   end if;
 
   return;
-
-   else
-  null;
end if;
 
 --  Special case: an attribute denoting a procedure call


[gcc r15-2687] ada: Fix handling of SPARK_Mode on standalone child subprogram

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:ce7f7b92505e59ae517b05493694be2102cadf5a

commit r15-2687-gce7f7b92505e59ae517b05493694be2102cadf5a
Author: Yannick Moy 
Date:   Wed Jul 17 10:43:06 2024 +0200

ada: Fix handling of SPARK_Mode on standalone child subprogram

SPARK_Mode aspect was not properly propagated to the body of
a standalone child subprogram from the generated spec for that subprogram,
leading GNATprove to not analyze this body. Now fixed.

gcc/ada/

* aspects.adb (Find_Aspect): Take into account the case of a node
of kind N_Defining_Program_Unit_Name.
* sem_ch10.adb (Analyze_Compilation_Unit): Copy the SPARK aspect
from the spec to the body. Delay semantic analysis after that
point to ensure that SPARK_Mode is properly analyzed.

Diff:
---
 gcc/ada/aspects.adb  |  8 +++-
 gcc/ada/sem_ch10.adb | 12 +++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/aspects.adb b/gcc/ada/aspects.adb
index b7262c56f3f1..4c8ab7b4a332 100644
--- a/gcc/ada/aspects.adb
+++ b/gcc/ada/aspects.adb
@@ -190,13 +190,19 @@ package body Aspects is
   --  Note that not all aspects are added to the chain of representation
   --  items. In such cases, search the list of aspect specifications. First
   --  find the declaration node where the aspects reside. This is usually
-  --  the parent or the parent of the parent.
+  --  the parent or the parent of the parent, after getting through the
+  --  additional indirection of the N_Defining_Program_Unit_Name if needed.
 
   if No (Parent (Owner)) then
  return Empty;
   end if;
 
   Decl := Parent (Owner);
+
+  if Nkind (Decl) = N_Defining_Program_Unit_Name then
+ Decl := Parent (Decl);
+  end if;
+
   if not Permits_Aspect_Specifications (Decl) then
  Decl := Parent (Decl);
 
diff --git a/gcc/ada/sem_ch10.adb b/gcc/ada/sem_ch10.adb
index 73e5388affdc..e56fe30adaea 100644
--- a/gcc/ada/sem_ch10.adb
+++ b/gcc/ada/sem_ch10.adb
@@ -1046,17 +1046,27 @@ package body Sem_Ch10 is
  Set_Library_Unit (N, Lib_Unit);
  Set_Parent_Spec (Unit (Lib_Unit), Cunit (Unum));
  Make_Child_Decl_Unit (N);
- Semantics (Lib_Unit);
 
  --  Now that a separate declaration exists, the body
  --  of the child unit does not act as spec any longer.
 
  Set_Acts_As_Spec (N, False);
  Move_Aspects (From => Unit_Node, To => Unit (Lib_Unit));
+
+ --  Ensure that the generated corresponding spec and
+ --  original body share the same SPARK_Mode pragma or
+ --  aspect. As a result, both have the same SPARK_Mode
+ --  attributes, and the global SPARK_Mode value is
+ --  correctly set for local subprograms.
+
+ Copy_SPARK_Mode_Aspect (Unit (Lib_Unit), To => Unit_Node);
+
  Set_Is_Child_Unit (Defining_Entity (Unit_Node));
  Set_Debug_Info_Needed (Defining_Entity (Unit (Lib_Unit)));
  Set_Comes_From_Source_Default (SCS);
 
+ Semantics (Lib_Unit);
+
  --  Restore Context_Items to the body
 
  Set_Context_Items (N, Context_Items (Lib_Unit));


[gcc r15-2681] ada: Errors on legal container aggregates with iterated_element_associations

2024-08-02 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:32c4a7278fd182af126c4f37228e467a3e4db568

commit r15-2681-g32c4a7278fd182af126c4f37228e467a3e4db568
Author: Gary Dismukes 
Date:   Mon Jul 15 23:57:43 2024 +

ada: Errors on legal container aggregates with iterated_element_associations

The compiler rejects various cases of container aggregates with
iterated_element_associations that include a 
loop_parameter_subtype_indication
or that include the "reverse" keyword. The fixes are in the parser, for
naccepting the syntax for these cases, as well as for properly accounting
for reverse iterators in the analyzer and expander.

gcc/ada/

* exp_aggr.adb
(Expand_Container_Aggregate.Expand_Iterated_Component): Set the
Reverse_Present flag when creating the loop's iteration_scheme.
* gen_il-gen-gen_nodes.adb: Add flag Reverse_Present to
N_Iterated_Component_Association nodes.
* par-ch3.adb (P_Constraint_Op): Remove testing for and ignoring
of Tok_In following a constraint. It's allowed for "in" to follow
a constraint of loop_parameter_subtype_indication of an
iterator_specification, so it shouldn't be ignored.
* par-ch4.adb (P_Iterated_Component_Association): Account for
"reverse" following the "in" in an iterated_component_association,
and set the Reverse_Present flag on the
N_Iterated_Component_Association node. Add handling for a ":"
following the identifier in an iterator_specification of an
iterated_element_association, sharing the code with the "of" case
(which backs up to the identifier at the beginning of the
iterator_specification). Fix incorrect trailing comment following
the call to Scan.
(Build_Iterated_Element_Association): Set the Reverse_Present flag
on an N_Loop_Parameter_Specification node of an
N_Iterated_Element_Association.
* par-ch5.adb (P_Iterator_Specification): Remove error-recovery
and error code that reports "subtype indication is only legal on
an element iterator", as that error can no longer be emitted (and
was formerly only reported on one fixedbugs test).
* sem_aggr.adb
(Resolve_Container_Aggregate.Resolve_Iterated_Association): When
creating an N_Iterator_Specification for an
N_Iterated_Component_Association, set the Reverse_Present flag of
the N_Iterated_Specification from the flag on the latter.
* sinfo.ads: Add comments for the Reverse_Present flag, which is
now allowed on nodes of kind N_Iterated_Component_Association.

Diff:
---
 gcc/ada/exp_aggr.adb |  1 +
 gcc/ada/gen_il-gen-gen_nodes.adb |  1 +
 gcc/ada/par-ch3.adb  |  4 
 gcc/ada/par-ch4.adb  | 12 +++-
 gcc/ada/par-ch5.adb  | 12 
 gcc/ada/sem_aggr.adb |  2 +-
 gcc/ada/sinfo.ads|  6 ++
 7 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index ed0dad1444b3..25af78a4da7b 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -7019,6 +7019,7 @@ package body Exp_Aggr is
Loop_Parameter_Specification =>
  Make_Loop_Parameter_Specification (Loc,
Defining_Identifier => Loop_Id,
+   Reverse_Present => Reverse_Present (Comp),
Discrete_Subtype_Definition => L_Range));
 end if;
  end if;
diff --git a/gcc/ada/gen_il-gen-gen_nodes.adb b/gcc/ada/gen_il-gen-gen_nodes.adb
index 7224556accd7..327ff376d12a 100644
--- a/gcc/ada/gen_il-gen-gen_nodes.adb
+++ b/gcc/ada/gen_il-gen-gen_nodes.adb
@@ -1489,6 +1489,7 @@ begin -- Gen_IL.Gen.Gen_Nodes
 Sy (Iterator_Specification, Node_Id, Default_Empty),
 Sy (Expression, Node_Id, Default_Empty),
 Sy (Discrete_Choices, List_Id),
+Sy (Reverse_Present, Flag),
 Sy (Box_Present, Flag),
 Sm (Loop_Actions, List_Id)));
 
diff --git a/gcc/ada/par-ch3.adb b/gcc/ada/par-ch3.adb
index 01dd45c4f235..a5f4319debf6 100644
--- a/gcc/ada/par-ch3.adb
+++ b/gcc/ada/par-ch3.adb
@@ -1196,10 +1196,6 @@ package body Ch3 is
   elsif Token = Tok_Left_Paren then
  return P_Index_Or_Discriminant_Constraint;
 
-  elsif Token = Tok_In then
- Ignore (Tok_In);
- return P_Constraint_Opt;
-
   --  One more possibility is e.g. 1 .. 10 (i.e. missing RANGE keyword)
 
   elsif Token = Tok_Identifier  or else
diff --git a/gcc/ada/par-ch4.adb b/gcc/ada/par-ch4.adb
index 9c9b0d70207c..8b491c2cfd79 100644
--- a/gcc/ada/par-ch4.adb
+++ b/gcc/ada/par-ch4.adb
@@ -3584,6 +3584,7 @@ package body Ch4 is
   Iter_Spec  : Node_Id;
   Loop_Spec  : Node_Id;
   State  

[gcc r15-2688] libstdc++: Add missing to test

2024-08-02 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:06201faa6376cade5a286850370dd070c1573531

commit r15-2688-g06201faa6376cade5a286850370dd070c1573531
Author: Jonathan Wakely 
Date:   Fri Aug 2 08:27:09 2024 +0100

libstdc++: Add missing  to test

libstdc++-v3/ChangeLog:

* testsuite/libstdc++-prettyprinters/shared_ptr.cc: Include
.

Diff:
---
 libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc 
b/libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc
index a9910e6a56d6..5ff206a145b0 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc
@@ -20,6 +20,7 @@
 
 #include 
 #include 
+#include 
 
 template
 void


[gcc r14-10551] Refine constraint "Bk" to define_special_memory_constraint.

2024-08-02 Thread hongtao Liu via Gcc-cvs
https://gcc.gnu.org/g:a295076bee293aa3112c615f9af7a27231816a36

commit r14-10551-ga295076bee293aa3112c615f9af7a27231816a36
Author: liuhongt 
Date:   Wed Jul 24 11:29:23 2024 +0800

Refine constraint "Bk" to define_special_memory_constraint.

For below pattern, RA may still allocate r162 as v/k register, try to
reload for address with leaq __libc_tsd_CTYPE_B@gottpoff(%rip), %rsi
which result a linker error.

(set (reg:DI 162)
 (mem/u/c:DI
   (const:DI (unspec:DI
 [(symbol_ref:DI ("a") [flags 0x60]  )]
 UNSPEC_GOTNTPOFF))

Quote from H.J for why linker issue an error.
>What do these do:
>
>leaq__libc_tsd_CTYPE_B@gottpoff(%rip), %rax
>vmovq   (%rax), %xmm0
>
>From x86-64 TLS psABI:
>
>The assembler generates for the x@gottpoff(%rip) expressions a R X86
>64 GOTTPOFF relocation for the symbol x which requests the linker to
>generate a GOT entry with a R X86 64 TPOFF64 relocation. The offset of
>the GOT entry relative to the end of the instruction is then used in
>the instruction. The R X86 64 TPOFF64 relocation is pro- cessed at
>program startup time by the dynamic linker by looking up the symbol x
>in the modules loaded at that point. The offset is written in the GOT
>entry and later loaded by the addq instruction.
>
>The above code sequence looks wrong to me.

gcc/ChangeLog:

PR target/116043
* config/i386/constraints.md (Bk): Refine to
define_special_memory_constraint.

gcc/testsuite/ChangeLog:

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

(cherry picked from commit bc1fda00d5f20e2f3e77a50b2822562b6e0040b2)

Diff:
---
 gcc/config/i386/constraints.md   |  2 +-
 gcc/testsuite/gcc.target/i386/pr116043.c | 33 
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/gcc/config/i386/constraints.md b/gcc/config/i386/constraints.md
index 7508d7a58bd7..b760e7c221a1 100644
--- a/gcc/config/i386/constraints.md
+++ b/gcc/config/i386/constraints.md
@@ -187,7 +187,7 @@
   "@internal Vector memory operand."
   (match_operand 0 "vector_memory_operand"))
 
-(define_memory_constraint "Bk"
+(define_special_memory_constraint "Bk"
   "@internal TLS address that allows insn using non-integer registers."
   (and (match_operand 0 "memory_operand")
(not (match_test "ix86_gpr_tls_address_pattern_p (op)"
diff --git a/gcc/testsuite/gcc.target/i386/pr116043.c 
b/gcc/testsuite/gcc.target/i386/pr116043.c
new file mode 100644
index ..76553496c109
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr116043.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-mavx512bf16 -O3" } */
+/* { dg-final { scan-assembler-not {(?n)lea.*@gottpoff} } } */
+
+extern __thread int a, c, i, j, k, l;
+int *b;
+struct d {
+  int e;
+} f, g;
+char *h;
+
+void m(struct d *n) {
+  b = &k;
+  for (; n->e; b++, n--) {
+i = b && a;
+if (i)
+  j = c;
+  }
+}
+
+char *o(struct d *n) {
+  for (; n->e;)
+return h;
+}
+
+int q() {
+  if (l)
+return 1;
+  int p = *o(&g);
+  m(&f);
+  m(&g);
+  l = p;
+}


[gcc r15-2689] i386: Fix comment/naming for APX NDD constraints

2024-08-02 Thread Kong Lingling via Gcc-cvs
https://gcc.gnu.org/g:1fbce3252bc00b1678cdf62b8798a94962e99f76

commit r15-2689-g1fbce3252bc00b1678cdf62b8798a94962e99f76
Author: Lingling Kong 
Date:   Fri Aug 2 16:52:33 2024 +0800

i386: Fix comment/naming for APX NDD constraints

gcc/ChangeLog:

* config/i386/constraints.md: Fixed the comment/naming for je/jM/jO.
* config/i386/predicates.md (apx_ndd_memory_operand): Renamed and
fixed the comment.
(apx_evex_memory_operand): New name.
(apx_ndd_add_memory_operand): Ditto.
(apx_evex_add_memory_operand): Ditto.

Diff:
---
 gcc/config/i386/constraints.md | 13 +++--
 gcc/config/i386/predicates.md  | 22 --
 2 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/gcc/config/i386/constraints.md b/gcc/config/i386/constraints.md
index 18389c478002..91a63089a967 100644
--- a/gcc/config/i386/constraints.md
+++ b/gcc/config/i386/constraints.md
@@ -463,14 +463,15 @@
  "TARGET_APX_EGPR && !TARGET_AVX ? GENERAL_GPR16 : GENERAL_REGS")
 
 (define_memory_constraint "je"
-  "@internal Memory operand for APX NDD ADD."
-  (match_operand 0 "apx_ndd_add_memory_operand"))
+  "@internal Memory operand for APX EVEX-encoded ADD (i.e. APX NDD/NF)."
+  (match_operand 0 "apx_evex_add_memory_operand"))
 
 (define_memory_constraint "jM"
-  "@internal Memory operand, with APX NDD check."
-  (match_operand 0 "apx_ndd_memory_operand"))
+  "@internal Memory operand, with APX EVEX-encoded (i.e. APX NDD/NF) check."
+  (match_operand 0 "apx_evex_memory_operand"))
 
 (define_memory_constraint "jO"
-  "@internal Offsettable memory operand, with APX NDD check."
-  (and (match_operand 0 "apx_ndd_memory_operand")
+  "@internal Offsettable memory operand, with APX EVEX-encoded
+   (i.e. APX NDD/NF) check."
+  (and (match_operand 0 "apx_evex_memory_operand")
   (match_test "offsettable_nonstrict_memref_p (op)")))
diff --git a/gcc/config/i386/predicates.md b/gcc/config/i386/predicates.md
index 680594871de0..ab6a2e14d355 100644
--- a/gcc/config/i386/predicates.md
+++ b/gcc/config/i386/predicates.md
@@ -2265,10 +2265,10 @@
 })
 
 ;; Return true if OP is a memory operand that can be also used in APX
-;; NDD patterns with immediate operand.  With non-default address space,
-;; segment register or address size prefix, APX NDD instruction length
-;; can exceed the 15 byte size limit.
-(define_predicate "apx_ndd_memory_operand"
+;; EVEX-encoded patterns (i.e. APX NDD/NF) with immediate operand.  With
+;; non-default address space, segment register or address size prefix,
+;; APX EVEX-encoded instruction length can exceed the 15 byte size limit.
+(define_predicate "apx_evex_memory_operand"
   (match_operand 0 "memory_operand")
 {
   /* OK if immediate operand size < 4 bytes.  */
@@ -2312,19 +2312,21 @@
   return true;
 })
 
-;; Return true if OP is a memory operand which can be used in APX NDD
-;; ADD with register source operand.  UNSPEC_GOTNTPOFF memory operand
-;; is allowed with APX NDD ADD only if R_X86_64_CODE_6_GOTTPOFF works.
-(define_predicate "apx_ndd_add_memory_operand"
+;; Return true if OP is a memory operand which can be used in APX EVEX-encoded
+;; ADD patterns (i.e. APX NDD/NF) for with register source operand.
+;; UNSPEC_GOTNTPOFF memory operand is allowed with APX EVEX-encoded ADD only if
+;; R_X86_64_CODE_6_GOTTPOFF works.
+(define_predicate "apx_evex_add_memory_operand"
   (match_operand 0 "memory_operand")
 {
-  /* OK if "add %reg1, name@gottpoff(%rip), %reg2" is supported.  */
+  /* OK if "add %reg1, name@gottpoff(%rip), %reg2" or
+   "{nf} add name@gottpoff(%rip), %reg1" are supported.  */
   if (HAVE_AS_R_X86_64_CODE_6_GOTTPOFF)
 return true;
 
   op = XEXP (op, 0);
 
-  /* Disallow APX NDD ADD with UNSPEC_GOTNTPOFF.  */
+  /* Disallow APX EVEX-encoded ADD with UNSPEC_GOTNTPOFF.  */
   if (GET_CODE (op) == CONST
   && GET_CODE (XEXP (op, 0)) == UNSPEC
   && XINT (XEXP (op, 0), 1) == UNSPEC_GOTNTPOFF)


[gcc r15-2690] c: Add support for byte arrays in C2Y

2024-08-02 Thread Martin Uecker via Gcc-cvs
https://gcc.gnu.org/g:4b9ba9cee9511930411b7b53e1333e1b6b93078d

commit r15-2690-g4b9ba9cee9511930411b7b53e1333e1b6b93078d
Author: Martin Uecker 
Date:   Sun Jun 23 23:14:33 2024 +0200

c: Add support for byte arrays in C2Y

To get correct aliasing behavior requires that structures and unions
that contain a byte array, i.e. an array of non-atomic character
type (N3254), are marked with TYPE_TYPELESS_STORAGE.  This change
affects also earlier language modes.

gcc/c/
* c-decl.cc (grokdeclarator, finish_struct): Set and
propagate TYPE_TYPELESS_STORAGE.

gcc/testsuite/
* gcc.dg/c2y-byte-alias-1.c: New test.
* gcc.dg/c2y-byte-alias-2.c: New test.
* gcc.dg/c2y-byte-alias-3.c: New test.

Diff:
---
 gcc/c/c-decl.cc | 15 +--
 gcc/testsuite/gcc.dg/c2y-byte-alias-1.c | 46 
 gcc/testsuite/gcc.dg/c2y-byte-alias-2.c | 43 ++
 gcc/testsuite/gcc.dg/c2y-byte-alias-3.c | 47 +
 4 files changed, 149 insertions(+), 2 deletions(-)

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 97f1d346835e..8cef8f2c2895 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -7502,12 +7502,18 @@ grokdeclarator (const struct c_declarator *declarator,
   modify the shared type, so we gcc_assert (itype)
   below.  */
  {
+   /* Identify typeless storage as introduced in C2Y
+  and supported also in earlier language modes.  */
+   bool typeless = (char_type_p (type)
+&& !(type_quals & TYPE_QUAL_ATOMIC))
+   || (AGGREGATE_TYPE_P (type)
+   && TYPE_TYPELESS_STORAGE (type));
+
addr_space_t as = DECODE_QUAL_ADDR_SPACE (type_quals);
if (!ADDR_SPACE_GENERIC_P (as) && as != TYPE_ADDR_SPACE (type))
  type = build_qualified_type (type,
   ENCODE_QUAL_ADDR_SPACE (as));
-
-   type = build_array_type (type, itype);
+   type = build_array_type (type, itype, typeless);
  }
 
if (type != error_mark_node)
@@ -9659,6 +9665,10 @@ finish_struct (location_t loc, tree t, tree fieldlist, 
tree attributes,
   if (DECL_NAME (x)
  || RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
saw_named_field = true;
+
+  if (AGGREGATE_TYPE_P (TREE_TYPE (x))
+ && TYPE_TYPELESS_STORAGE (TREE_TYPE (x)))
+   TYPE_TYPELESS_STORAGE (t) = true;
 }
 
   detect_field_duplicates (fieldlist);
@@ -9859,6 +9869,7 @@ finish_struct (location_t loc, tree t, tree fieldlist, 
tree attributes,
   TYPE_FIELDS (x) = TYPE_FIELDS (t);
   TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
   TYPE_TRANSPARENT_AGGR (x) = TYPE_TRANSPARENT_AGGR (t);
+  TYPE_TYPELESS_STORAGE (x) = TYPE_TYPELESS_STORAGE (t);
   C_TYPE_FIELDS_READONLY (x) = C_TYPE_FIELDS_READONLY (t);
   C_TYPE_FIELDS_VOLATILE (x) = C_TYPE_FIELDS_VOLATILE (t);
   C_TYPE_FIELDS_NON_CONSTEXPR (x) = C_TYPE_FIELDS_NON_CONSTEXPR (t);
diff --git a/gcc/testsuite/gcc.dg/c2y-byte-alias-1.c 
b/gcc/testsuite/gcc.dg/c2y-byte-alias-1.c
new file mode 100644
index ..30bc2c09c2f8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2y-byte-alias-1.c
@@ -0,0 +1,46 @@
+/* { dg-do run } */
+/* { dg-options "-std=c2y -O2" } */
+
+struct f { _Alignas(int) char buf[sizeof(int)]; };
+struct f2 { struct f x; };
+union g { _Alignas(int) char buf[sizeof(int)]; };
+
+[[gnu::noinline]]
+int foo(struct f *p, int *q)
+{
+   *q = 1;
+   *p = (struct f){ };
+   return *q;
+}
+
+[[gnu::noinline]]
+int foo2(struct f2 *p, int *q)
+{
+   *q = 1;
+   *p = (struct f2){ };
+   return *q;
+}
+
+[[gnu::noinline]]
+int bar(union g *p, int *q)
+{
+   *q = 1;
+   *p = (union g){ };
+   return *q;
+}
+
+
+int main()
+{
+   struct f p;
+   if (0 != foo(&p, (void*)&p.buf))
+   __builtin_abort();
+
+   struct f2 p2;
+   if (0 != foo2(&p2, (void*)&p2.x.buf))
+   __builtin_abort();
+
+   union g q;
+   if (0 != bar(&q, (void*)&q.buf))
+   __builtin_abort();
+}
diff --git a/gcc/testsuite/gcc.dg/c2y-byte-alias-2.c 
b/gcc/testsuite/gcc.dg/c2y-byte-alias-2.c
new file mode 100644
index ..9bd2d18b3864
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2y-byte-alias-2.c
@@ -0,0 +1,43 @@
+/* { dg-do run } */
+/* { dg-options "-std=c2y -O2" } */
+
+struct f2 {
+   struct f {
+   _Alignas(int) char buf[sizeof(int)];
+   } x[2];
+   int i;
+};
+
+[[gnu::noinline]]
+int foo2(struct f2 *p, int *q)
+{
+   *q = 1;
+   *p = (struct f2){ };
+   return *q;
+}
+
+struct g2 {
+   union g {
+   _Alignas(int) char buf[sizeof(int)];
+   } x[2];
+   int i;
+};
+
+[[gnu::noinline]]
+

[gcc] Deleted branch 'mikael/heads/backport_103789' in namespace 'refs/users'

2024-08-02 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/backport_103789' in namespace 'refs/users' was deleted.
It previously pointed to:

 1791f19b8c5f... Fortran: Fix KIND argument index for LEN_TRIM.

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  1791f19... Fortran: Fix KIND argument index for LEN_TRIM.
  6b52847... Fortran: Ignore KIND argument of a few more intrinsics. [PR


[gcc r15-2691] forwprop: Don't add uses to dce list if debug statement [PR116156]

2024-08-02 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:33baa20c5cdcf5ff8164606115f00aa30f559312

commit r15-2691-g33baa20c5cdcf5ff8164606115f00aa30f559312
Author: Andrew Pinski 
Date:   Thu Aug 1 10:33:34 2024 -0700

forwprop: Don't add uses to dce list if debug statement [PR116156]

The problem here is that when forwprop does a copy prop, into a statement,
we mark the uses of that statement as possibly need to be removed. But it 
just
happened that statement was a debug statement, there will be a difference 
when
compiling with debuging info turned on vs off; this is not expected.
So the fix is not to add the old use to dce list to process if it was a 
debug
statement.

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

PR tree-optimization/116156

gcc/ChangeLog:

* tree-ssa-forwprop.cc (pass_forwprop::execute): Don't add
uses if the statement was a debug statement.

gcc/testsuite/ChangeLog:

* c-c++-common/torture/pr116156-1.c: New test.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/testsuite/c-c++-common/torture/pr116156-1.c | 30 +
 gcc/tree-ssa-forwprop.cc| 16 +++--
 2 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/torture/pr116156-1.c 
b/gcc/testsuite/c-c++-common/torture/pr116156-1.c
new file mode 100644
index ..10f938ef4e5a
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/pr116156-1.c
@@ -0,0 +1,30 @@
+/* { dg-additional-options "-fcompare-debug" } */
+/* PR tree-optimization/116156 */
+
+/* Forwprop used to delete an unused statement
+   but only with debug statements around. */
+
+struct jpeg_compress_struct {
+  int X_density;
+};
+void gg();
+int h(const char*,const char*) __attribute((pure));
+int h1(const char*) __attribute((pure));
+int f1() __attribute__((returns_twice));
+void real_save_jpeg(char **keys, char *values) {
+  struct jpeg_compress_struct cinfo;
+  int x_density = 0;
+  while (*keys)
+  {
+if (h1(*keys) == 0)
+  gg();
+if (h1(*keys) == 0)  {
+  if (!*values)
+x_density = -1;
+  if (x_density <= 0)
+gg();
+}
+  }
+  if (f1())
+cinfo.X_density = x_density;
+}
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 44a6b5d39aa7..2e37642359c9 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -3923,7 +3923,8 @@ pass_forwprop::execute (function *fun)
  tree val = fwprop_ssa_val (use);
  if (val && val != use)
{
- bitmap_set_bit (simple_dce_worklist, SSA_NAME_VERSION (use));
+ if (!is_gimple_debug (stmt))
+   bitmap_set_bit (simple_dce_worklist, SSA_NAME_VERSION 
(use));
  if (may_propagate_copy (use, val))
{
  propagate_value (usep, val);
@@ -3963,12 +3964,13 @@ pass_forwprop::execute (function *fun)
if (gimple_cond_true_p (cond)
|| gimple_cond_false_p (cond))
  cfg_changed = true;
- /* Queue old uses for simple DCE.  */
- for (tree use : uses)
-   if (TREE_CODE (use) == SSA_NAME
-   && !SSA_NAME_IS_DEFAULT_DEF (use))
- bitmap_set_bit (simple_dce_worklist,
- SSA_NAME_VERSION (use));
+ /* Queue old uses for simple DCE if not debug statement.  */
+ if (!is_gimple_debug (stmt))
+   for (tree use : uses)
+ if (TREE_CODE (use) == SSA_NAME
+ && !SSA_NAME_IS_DEFAULT_DEF (use))
+   bitmap_set_bit (simple_dce_worklist,
+   SSA_NAME_VERSION (use));
}
 
  if (changed || substituted_p)


[gcc r15-2692] c++, coroutines: Fix a typo in checking for void expression types.

2024-08-02 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:370a0dee5556941c215c2b3fc61a8bcc40ae4942

commit r15-2692-g370a0dee5556941c215c2b3fc61a8bcc40ae4942
Author: Iain Sandoe 
Date:   Wed Jul 24 20:59:10 2024 +0100

c++, coroutines: Fix a typo in checking for void expression types.

The current code fails to check for void expression types because it does
not looup the type.  Fixed thus.

gcc/cp/ChangeLog:

* coroutines.cc (replace_continue): Look up expression type.

Signed-off-by: Iain Sandoe 

Diff:
---
 gcc/cp/coroutines.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index 91bbe6b0a0eb..9c1e5f0c5d78 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -3433,7 +3433,7 @@ replace_continue (tree *stmt, int *do_subtree, void *d)
   tree expr = *stmt;
   if (TREE_CODE (expr) == CLEANUP_POINT_EXPR)
 expr = TREE_OPERAND (expr, 0);
-  if (CONVERT_EXPR_P (expr) && VOID_TYPE_P (expr))
+  if (CONVERT_EXPR_P (expr) && VOID_TYPE_P (TREE_TYPE (expr)))
 expr = TREE_OPERAND (expr, 0);
   STRIP_NOPS (expr);
   if (!STATEMENT_CLASS_P (expr))


[gcc r15-2693] c++, coroutines: Remove unused suspend point state [NFC].

2024-08-02 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:ffd521d8dcddcd4cfe1f0f10890a2cb8b6e6493f

commit r15-2693-gffd521d8dcddcd4cfe1f0f10890a2cb8b6e6493f
Author: Iain Sandoe 
Date:   Tue Jul 30 08:58:42 2024 +0100

c++, coroutines: Remove unused suspend point state [NFC].

We maintain state on the progress of await analysis in an object that
is passed to the various tree walks used.  Some of the state had become
stale (i.e. unused members).  Remove those and provide a CTOR so that
updates are localised.

Remove the file scope hash_map used to collect the final state for the
actor function and make that part of the suspend point state.

gcc/cp/ChangeLog:

* coroutines.cc (struct susp_frame_data): Remove unused members,
provide a CTOR.
(morph_fn_to_coro): Use susp_frame_data CTOR, and make the suspend
state hash map local to the morph function.

Signed-off-by: Iain Sandoe 

Diff:
---
 gcc/cp/coroutines.cc | 56 +---
 1 file changed, 27 insertions(+), 29 deletions(-)

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index 9c1e5f0c5d78..78a72047846f 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -1988,12 +1988,11 @@ struct suspend_point_info
   tree await_field_id;
 };
 
-static hash_map *suspend_points;
-
 struct await_xform_data
 {
   tree actor_fn;   /* Decl for context.  */
   tree actor_frame;
+  hash_map *suspend_points;
 };
 
 /* When we built the await expressions, we didn't know the coro frame
@@ -2003,7 +2002,7 @@ struct await_xform_data
 static tree
 transform_await_expr (tree await_expr, await_xform_data *xform)
 {
-  suspend_point_info *si = suspend_points->get (await_expr);
+  suspend_point_info *si = xform->suspend_points->get (await_expr);
   location_t loc = EXPR_LOCATION (await_expr);
   if (!si)
 {
@@ -2227,6 +2226,7 @@ coro_get_frame_dtor (tree coro_fp, tree orig, tree 
frame_size,
 static void
 build_actor_fn (location_t loc, tree coro_frame_type, tree actor, tree fnbody,
tree orig, hash_map *local_var_uses,
+   hash_map *suspend_points,
vec *param_dtor_list,
tree resume_idx_var, unsigned body_count, tree frame_size)
 {
@@ -2407,7 +2407,7 @@ build_actor_fn (location_t loc, tree coro_frame_type, 
tree actor, tree fnbody,
   /* Now we know the real promise, and enough about the frame layout to
  decide where to put things.  */
 
-  await_xform_data xform = {actor, actor_frame};
+  await_xform_data xform = {actor, actor_frame, suspend_points};
 
   /* Transform the await expressions in the function body.  Only do each
  await tree once!  */
@@ -2642,7 +2642,8 @@ build_init_or_final_await (location_t loc, bool is_final)
function.  */
 
 static bool
-register_await_info (tree await_expr, tree aw_type, tree aw_nam)
+register_await_info (tree await_expr, tree aw_type, tree aw_nam,
+hash_map *suspend_points)
 {
   bool seen;
   suspend_point_info &s
@@ -2663,21 +2664,26 @@ register_await_info (tree await_expr, tree aw_type, 
tree aw_nam)
 struct susp_frame_data
 {
   /* Function-wide.  */
-  tree *field_list; /* The current coroutine frame field list.  */
-  tree handle_type; /* The self-handle type for this coroutine.  */
-  tree fs_label;/* The destination for co_returns.  */
+  tree fs_label;   /* The destination for co_returns.  */
+  hash_map *suspend_points; /* Not owned.  */
   vec *block_stack; /* Track block scopes.  */
   vec *bind_stack;  /* Track current bind expr.  */
-  unsigned await_number;/* Which await in the function.  */
-  unsigned cond_number; /* Which replaced condition in the fn. 
 */
+  unsigned await_number = 0;/* Which await in the function.  */
+  unsigned cond_number = 0; /* Which replaced condition in the fn. 
 */
+
   /* Temporary values for one statement or expression being analyzed.  */
-  hash_set captured_temps; /* The suspend captured these temps.  */
-  vec *to_replace;  /* The VAR decls to replace.  */
-  hash_set *truth_aoif_to_expand; /* The set of TRUTH exprs to expand.  
*/
-  unsigned saw_awaits;  /* Count of awaits in this statement  */
-  bool captures_temporary;  /* This expr captures temps by ref.  */
-  bool needs_truth_if_exp;  /* We must expand a truth_if expression.  */
-  bool has_awaiter_init;/* We must handle initializing an awaiter.  */
+  hash_set *truth_aoif_to_expand = nullptr; /* The set of TRUTH exprs to 
expand.  */
+  unsigned saw_awaits = 0;  /* Count of awaits in this statement  
*/
+  bool captures_temporary = false;  /* This expr captures temps by ref.  */
+  bool needs_truth_if_exp = false;  /* We must expand a truth_if 
expression.  */
+  bool has_awaiter_init = false;/* We must handle initializing an 
awaiter.  */
+
+  susp_frame_data (tree _final_susp, hash_map *_spt)
+: fs_label (_f

[gcc r15-2694] c++, coroutines: Provide a CTOR for a callback object [NFC].

2024-08-02 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:00019b88e714c29c387a3f492155366c921474a0

commit r15-2694-g00019b88e714c29c387a3f492155366c921474a0
Author: Iain Sandoe 
Date:   Wed Jul 31 14:51:31 2024 +0100

c++, coroutines: Provide a CTOR for a callback object [NFC].

This provides and uses a CTOR to initialize the object used in
tree walks to track local variable uses.  This makes the idiom
used consistent.

gcc/cp/ChangeLog:

* coroutines.cc (struct local_vars_frame_data): Add a
CTOR.
(morph_fn_to_coro): Use CTOR for local_vars_frame_data
instead of brace init.

Signed-off-by: Iain Sandoe 

Diff:
---
 gcc/cp/coroutines.cc | 23 ++-
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index 78a72047846f..af03f5e0f744 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -3989,10 +3989,14 @@ struct local_vars_frame_data
 {
   tree *field_list;
   hash_map *local_var_uses;
-  unsigned int nest_depth, bind_indx;
-  location_t loc;
-  bool saw_capture;
-  bool local_var_seen;
+  unsigned int nest_depth = 0;
+  unsigned int bind_indx = 0;
+  location_t loc = UNKNOWN_LOCATION;
+  bool saw_capture = false;
+  bool local_var_seen = false;
+
+  local_vars_frame_data (tree *_fl, hash_map *_lvu)
+: field_list (_fl), local_var_uses (_lvu) {}
 };
 
 /* A tree-walk callback that processes one bind expression noting local
@@ -4577,8 +4581,6 @@ morph_fn_to_coro (tree orig, tree *resumer, tree 
*destroyer)
   /* Build our dummy coro frame layout.  */
   coro_frame_type = begin_class_definition (coro_frame_type);
 
-  /* The fields for the coro frame.  */
-  tree field_list = NULL_TREE;
 
   /* We need to know, and inspect, each suspend point in the function
  in several places.  It's convenient to place this map out of line
@@ -4592,10 +4594,13 @@ morph_fn_to_coro (tree orig, tree *resumer, tree 
*destroyer)
   cp_walk_tree (&fnbody, await_statement_walker, &body_aw_points, NULL);
 
   /* 4. Now make space for local vars, this is conservative again, and we
- would expect to delete unused entries later.  */
+ would expect to delete unused entries later.  Compose the frame entries
+ list.  */
+
+  /* The fields for the coro frame.  */
+  tree field_list = NULL_TREE;
   hash_map local_var_uses;
-  local_vars_frame_data local_vars_data
-= {&field_list, &local_var_uses, 0, 0, fn_start, false, false};
+  local_vars_frame_data local_vars_data (&field_list, &local_var_uses);
   cp_walk_tree (&fnbody, register_local_var_uses, &local_vars_data, NULL);
 
   /* Tie off the struct for now, so that we can build offsets to the


[gcc] Deleted branch 'mikael/heads/fortran-dev' in namespace 'refs/users'

2024-08-02 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/fortran-dev' in namespace 'refs/users' was deleted.
It previously pointed to:

 d089c4a37a7f... Merge from trunk (r239915 to r240230)


[gcc] Created branch 'mikael/heads/dummy_back_minmaxloc_final' in namespace 'refs/users'

2024-08-02 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/dummy_back_minmaxloc_final' was created in namespace 
'refs/users' pointing to:

 999b16301553... fortran: Support optional dummy as BACK argument of MINLOC/


[gcc(refs/users/mikael/heads/dummy_back_minmaxloc_final)] fortran: Support optional dummy as BACK argument of MINLOC/MAXLOC.

2024-08-02 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:999b16301553cce5778173fca530722ba5a8bf73

commit 999b16301553cce5778173fca530722ba5a8bf73
Author: Mikael Morin 
Date:   Fri Aug 2 14:24:34 2024 +0200

fortran: Support optional dummy as BACK argument of MINLOC/MAXLOC.

Protect the evaluation of BACK with a check that the reference is non-null
in case the expression is an optional dummy, in the inline code generated
for MINLOC and MAXLOC.

This change contains a revert of the non-testsuite part of commit
r15-1994-ga55d24b3cf7f4d07492bb8e6fcee557175b47ea3, which factored the
evaluation of BACK out of the loop using the scalarizer.  It was a bad idea,
because delegating the argument evaluation to the scalarizer makes it
cumbersome to add a null pointer check next to the evaluation.

Instead, evaluate BACK at the beginning, before scalarization, add a check
that the argument is present if necessary, and evaluate the resulting
expression to a variable, before using the variable in the inline code.

gcc/fortran/ChangeLog:

* trans-intrinsic.cc (maybe_absent_optional_variable): New function.
(gfc_conv_intrinsic_minmaxloc): Remove BACK from scalarization and
evaluate it before.  Add a check that BACK is not null if the
expression is an optional dummy.  Save the resulting expression to a
variable.  Use the variable in the generated inline code.

gcc/testsuite/ChangeLog:

* gfortran.dg/maxloc_6.f90: New test.
* gfortran.dg/minloc_7.f90: New test.

Diff:
---
 gcc/fortran/trans-intrinsic.cc |  83 ++--
 gcc/testsuite/gfortran.dg/maxloc_6.f90 | 366 +
 gcc/testsuite/gfortran.dg/minloc_7.f90 | 366 +
 3 files changed, 801 insertions(+), 14 deletions(-)

diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 180d0d7a88c6..11d4503d401c 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -5209,6 +5209,50 @@ gfc_conv_intrinsic_dot_product (gfc_se * se, gfc_expr * 
expr)
 }
 
 
+/* Tells whether the expression E is a reference to an optional variable whose
+   presence is not known at compile time.  Those are variable references 
without
+   subreference; if there is a subreference, we can assume the variable is
+   present.  We have to special case full arrays, which we represent with a 
fake
+   "full" reference, and class descriptors for which a reference to data is not
+   really a subreference.  */
+
+bool
+maybe_absent_optional_variable (gfc_expr *e)
+{
+  if (!(e && e->expr_type == EXPR_VARIABLE))
+return false;
+
+  gfc_symbol *sym = e->symtree->n.sym;
+  if (!sym->attr.optional)
+return false;
+
+  gfc_ref *ref = e->ref;
+  if (ref == nullptr)
+return true;
+
+  if (ref->type == REF_ARRAY
+  && ref->u.ar.type == AR_FULL
+  && ref->next == nullptr)
+return true;
+
+  if (!(sym->ts.type == BT_CLASS
+   && ref->type == REF_COMPONENT
+   && ref->u.c.component == CLASS_DATA (sym)))
+return false;
+
+  gfc_ref *next_ref = ref->next;
+  if (next_ref == nullptr)
+return true;
+
+  if (next_ref->type == REF_ARRAY
+  && next_ref->u.ar.type == AR_FULL
+  && next_ref->next == nullptr)
+return true;
+
+  return false;
+}
+
+
 /* Remove unneeded kind= argument from actual argument list when the
result conversion is dealt with in a different place.  */
 
@@ -5321,11 +5365,11 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * 
expr, enum tree_code op)
   tree nonempty;
   tree lab1, lab2;
   tree b_if, b_else;
+  tree back;
   gfc_loopinfo loop;
   gfc_actual_arglist *actual;
   gfc_ss *arrayss;
   gfc_ss *maskss;
-  gfc_ss *backss;
   gfc_se arrayse;
   gfc_se maskse;
   gfc_expr *arrayexpr;
@@ -5391,10 +5435,29 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * 
expr, enum tree_code op)
 && maskexpr->symtree->n.sym->attr.dummy
 && maskexpr->symtree->n.sym->attr.optional;
   backexpr = actual->next->next->expr;
-  if (backexpr)
-backss = gfc_get_scalar_ss (gfc_ss_terminator, backexpr);
+
+  gfc_init_se (&backse, NULL);
+  if (backexpr == nullptr)
+back = logical_false_node;
+  else if (maybe_absent_optional_variable (backexpr))
+{
+  /* This should have been checked already by
+ maybe_absent_optional_variable.  */
+  gcc_checking_assert (backexpr->expr_type == EXPR_VARIABLE);
+
+  gfc_conv_expr (&backse, backexpr);
+  tree present = gfc_conv_expr_present (backexpr->symtree->n.sym, false);
+  back = fold_build2_loc (input_location, TRUTH_ANDIF_EXPR,
+ logical_type_node, present, backse.expr);
+}
   else
-backss = nullptr;
+{
+  gfc_conv_expr (&backse, backexpr);
+  back = backse.expr;
+}
+  gfc_add_block_to_block (&se->pre, &backse.pre);
+  back = gfc_evaluate_now_loc (input_location, back, &se->pre)

[gcc] Created branch 'mikael/heads/dummy_back_minmaxloc_final02' in namespace 'refs/users'

2024-08-02 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/dummy_back_minmaxloc_final02' was created in namespace 
'refs/users' pointing to:

 40122a405386... fortran: Support optional dummy as BACK argument of MINLOC/


[gcc(refs/users/mikael/heads/dummy_back_minmaxloc_final02)] fortran: Support optional dummy as BACK argument of MINLOC/MAXLOC.

2024-08-02 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:40122a405386a8b67c11bbaad523ffce5c1c7855

commit 40122a405386a8b67c11bbaad523ffce5c1c7855
Author: Mikael Morin 
Date:   Fri Aug 2 14:24:34 2024 +0200

fortran: Support optional dummy as BACK argument of MINLOC/MAXLOC.

Protect the evaluation of BACK with a check that the reference is non-null
in case the expression is an optional dummy, in the inline code generated
for MINLOC and MAXLOC.

This change contains a revert of the non-testsuite part of commit
r15-1994-ga55d24b3cf7f4d07492bb8e6fcee557175b47ea3, which factored the
evaluation of BACK out of the loop using the scalarizer.  It was a bad idea,
because delegating the argument evaluation to the scalarizer makes it
cumbersome to add a null pointer check next to the evaluation.

Instead, evaluate BACK at the beginning, before scalarization, add a check
that the argument is present if necessary, and evaluate the resulting
expression to a variable, before using the variable in the inline code.

gcc/fortran/ChangeLog:

* trans-intrinsic.cc (maybe_absent_optional_variable): New function.
(gfc_conv_intrinsic_minmaxloc): Remove BACK from scalarization and
evaluate it before.  Add a check that BACK is not null if the
expression is an optional dummy.  Save the resulting expression to a
variable.  Use the variable in the generated inline code.

gcc/testsuite/ChangeLog:

* gfortran.dg/maxloc_6.f90: New test.
* gfortran.dg/minloc_7.f90: New test.

Diff:
---
 gcc/fortran/trans-intrinsic.cc |  83 ++--
 gcc/testsuite/gfortran.dg/maxloc_6.f90 | 366 +
 gcc/testsuite/gfortran.dg/minloc_7.f90 | 366 +
 3 files changed, 801 insertions(+), 14 deletions(-)

diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 180d0d7a88c6..150cb9ff963b 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -5209,6 +5209,50 @@ gfc_conv_intrinsic_dot_product (gfc_se * se, gfc_expr * 
expr)
 }
 
 
+/* Tells whether the expression E is a reference to an optional variable whose
+   presence is not known at compile time.  Those are variable references 
without
+   subreference; if there is a subreference, we can assume the variable is
+   present.  We have to special case full arrays, which we represent with a 
fake
+   "full" reference, and class descriptors for which a reference to data is not
+   really a subreference.  */
+
+bool
+maybe_absent_optional_variable (gfc_expr *e)
+{
+  if (!(e && e->expr_type == EXPR_VARIABLE))
+return false;
+
+  gfc_symbol *sym = e->symtree->n.sym;
+  if (!sym->attr.optional)
+return false;
+
+  gfc_ref *ref = e->ref;
+  if (ref == nullptr)
+return true;
+
+  if (ref->type == REF_ARRAY
+  && ref->u.ar.type == AR_FULL
+  && ref->next == nullptr)
+return true;
+
+  if (!(sym->ts.type == BT_CLASS
+   && ref->type == REF_COMPONENT
+   && ref->u.c.component == CLASS_DATA (sym)))
+return false;
+
+  gfc_ref *next_ref = ref->next;
+  if (next_ref == nullptr)
+return true;
+
+  if (next_ref->type == REF_ARRAY
+  && next_ref->u.ar.type == AR_FULL
+  && next_ref->next == nullptr)
+return true;
+
+  return false;
+}
+
+
 /* Remove unneeded kind= argument from actual argument list when the
result conversion is dealt with in a different place.  */
 
@@ -5321,11 +5365,11 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * 
expr, enum tree_code op)
   tree nonempty;
   tree lab1, lab2;
   tree b_if, b_else;
+  tree back;
   gfc_loopinfo loop;
   gfc_actual_arglist *actual;
   gfc_ss *arrayss;
   gfc_ss *maskss;
-  gfc_ss *backss;
   gfc_se arrayse;
   gfc_se maskse;
   gfc_expr *arrayexpr;
@@ -5391,10 +5435,29 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * 
expr, enum tree_code op)
 && maskexpr->symtree->n.sym->attr.dummy
 && maskexpr->symtree->n.sym->attr.optional;
   backexpr = actual->next->next->expr;
-  if (backexpr)
-backss = gfc_get_scalar_ss (gfc_ss_terminator, backexpr);
+
+  gfc_init_se (&backse, NULL);
+  if (backexpr == nullptr)
+back = logical_false_node;
+  else if (maybe_absent_optional_variable (backexpr))
+{
+  /* This should have been checked already by
+maybe_absent_optional_variable.  */
+  gcc_checking_assert (backexpr->expr_type == EXPR_VARIABLE);
+
+  gfc_conv_expr (&backse, backexpr);
+  tree present = gfc_conv_expr_present (backexpr->symtree->n.sym, false);
+  back = fold_build2_loc (input_location, TRUTH_ANDIF_EXPR,
+ logical_type_node, present, backse.expr);
+}
   else
-backss = nullptr;
+{
+  gfc_conv_expr (&backse, backexpr);
+  back = backse.expr;
+}
+  gfc_add_block_to_block (&se->pre, &backse.pre);
+  back = gfc_evaluate_now_loc (input_location, back, &se->pre);

[gcc r15-2695] c++: DR882, main cannot be deleted [PR116169]

2024-08-02 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:a790828ccb3b06a7771f871651e7b54d13c3a168

commit r15-2695-ga790828ccb3b06a7771f871651e7b54d13c3a168
Author: Marek Polacek 
Date:   Thu Aug 1 11:32:26 2024 -0400

c++: DR882, main cannot be deleted [PR116169]

This DR clarifies that "int main() = delete;" is ill-formed.

PR c++/116169

gcc/cp/ChangeLog:

* decl.cc (cp_finish_decl): Disallow deleting ::main.

gcc/testsuite/ChangeLog:

* g++.dg/DRs/dr882.C: New test.

Diff:
---
 gcc/cp/decl.cc   | 26 ++
 gcc/testsuite/g++.dg/DRs/dr882.C |  5 +
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 279af21eed03..687ae6937f53 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -8649,15 +8649,25 @@ cp_finish_decl (tree decl, tree init, bool 
init_const_expr_p,
  && TREE_TYPE (init) == ridpointers[(int)RID_DELETE]))
{
  /* FIXME check this is 1st decl.  */
- DECL_DELETED_FN (decl) = 1;
- DECL_DECLARED_INLINE_P (decl) = 1;
- DECL_INITIAL (decl)
-   = TREE_CODE (init) == STRING_CST ? init : error_mark_node;
- FOR_EACH_CLONE (clone, decl)
+ if (UNLIKELY (DECL_MAIN_P (decl)))
{
- DECL_DELETED_FN (clone) = 1;
- DECL_DECLARED_INLINE_P (clone) = 1;
- DECL_INITIAL (clone) = DECL_INITIAL (decl);
+ /* [basic.start.main]/3: A program that defines main as deleted
+is ill-formed.  */
+ error ("%<::main%> cannot be deleted");
+ DECL_INITIAL (decl) = NULL_TREE;
+   }
+ else
+   {
+ DECL_DELETED_FN (decl) = 1;
+ DECL_DECLARED_INLINE_P (decl) = 1;
+ DECL_INITIAL (decl)
+   = TREE_CODE (init) == STRING_CST ? init : error_mark_node;
+ FOR_EACH_CLONE (clone, decl)
+   {
+ DECL_DELETED_FN (clone) = 1;
+ DECL_DECLARED_INLINE_P (clone) = 1;
+ DECL_INITIAL (clone) = DECL_INITIAL (decl);
+   }
}
  init = NULL_TREE;
}
diff --git a/gcc/testsuite/g++.dg/DRs/dr882.C b/gcc/testsuite/g++.dg/DRs/dr882.C
new file mode 100644
index ..c41cf7416a29
--- /dev/null
+++ b/gcc/testsuite/g++.dg/DRs/dr882.C
@@ -0,0 +1,5 @@
+// DR882 - Defining main as deleted
+// PR c++/116169
+// { dg-do compile { target c++11 } }
+
+int main() = delete; // { dg-error "cannot be deleted" }


[gcc r15-2696] Make may_trap_p_1 return false for constant pool references [PR116145]

2024-08-02 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:ba730fd10934e4ca004251aa3748bf9da4d35e62

commit r15-2696-gba730fd10934e4ca004251aa3748bf9da4d35e62
Author: Richard Sandiford 
Date:   Fri Aug 2 15:58:31 2024 +0100

Make may_trap_p_1 return false for constant pool references [PR116145]

The testcase contains the constant:

  arr2 = svreinterpret_u8(svdup_u32(0x0a0d5c3f));

which was initially hoisted by hand, but which gimple optimisers later
propagated to each use (as expected).  The constant was then expanded
as a load-and-duplicate from the constant pool.  Normally that load
should then be hoisted back out of the loop, but may_trap_or_fault_p
stopped that from happening in this case.

The code responsible was:

  if (/* MEM_NOTRAP_P only relates to the actual position of the memory
 reference; moving it out of context such as when moving code
 when optimizing, might cause its address to become invalid.  */
  code_changed
  || !MEM_NOTRAP_P (x))
{
  poly_int64 size = MEM_SIZE_KNOWN_P (x) ? MEM_SIZE (x) : -1;
  return rtx_addr_can_trap_p_1 (XEXP (x, 0), 0, size,
GET_MODE (x), code_changed);
}

where code_changed is true.  (Arguably it doesn't need to be true in
this case, if we inserted invariants on the preheader edge, but it
would still need to be true for conditionally executed loads.)

Normally this wouldn't be a problem, since rtx_addr_can_trap_p_1
would recognise that the address refers to the constant pool.
However, the SVE load-and-replicate instructions have a limited
offset range, so it isn't possible for them to have a LO_SUM address.
All we have is a plain pseudo base register.

MEM_READONLY_P is defined as:

  /* 1 if RTX is a mem that is statically allocated in read-only memory.  */
  #define MEM_READONLY_P(RTX) \
(RTL_FLAG_CHECK1 ("MEM_READONLY_P", (RTX), MEM)->unchanging)

and so I think it should be safe to move memory references if both
MEM_READONLY_P and MEM_NOTRAP_P are true.

The testcase isn't a minimal reproducer, but I think it's good
to have a realistic full routine in the testsuite.

gcc/
PR rtl-optimization/116145
* rtlanal.cc (may_trap_p_1): Trust MEM_NOTRAP_P even for code
movement if MEM_READONLY_P is also true.

gcc/testsuite/
PR rtl-optimization/116145
* gcc.target/aarch64/sve/acle/general/pr116145.c: New test.

Diff:
---
 gcc/rtlanal.cc | 14 +--
 .../gcc.target/aarch64/sve/acle/general/pr116145.c | 46 ++
 2 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc
index 4158a531bdd7..893a6afbbc53 100644
--- a/gcc/rtlanal.cc
+++ b/gcc/rtlanal.cc
@@ -3152,10 +3152,16 @@ may_trap_p_1 (const_rtx x, unsigned flags)
  && MEM_VOLATILE_P (x)
  && XEXP (x, 0) == stack_pointer_rtx)
return true;
-  if (/* MEM_NOTRAP_P only relates to the actual position of the memory
-reference; moving it out of context such as when moving code
-when optimizing, might cause its address to become invalid.  */
- code_changed
+  if (/* MEM_READONLY_P means that the memory is both statically
+allocated and readonly, so MEM_NOTRAP_P should remain true
+even if the memory reference is moved.  This is certainly
+true for the important case of force_const_mem.
+
+Otherwise, MEM_NOTRAP_P only relates to the actual position
+of the memory reference; moving it out of context such as
+when moving code when optimizing, might cause its address
+to become invalid.  */
+ (code_changed && !MEM_READONLY_P (x))
  || !MEM_NOTRAP_P (x))
{
  poly_int64 size = MEM_SIZE_KNOWN_P (x) ? MEM_SIZE (x) : -1;
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr116145.c 
b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr116145.c
new file mode 100644
index ..a3d93d3e1c84
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr116145.c
@@ -0,0 +1,46 @@
+// { dg-options "-O2" }
+
+#include 
+#include 
+
+#pragma GCC target "+sve2"
+
+typedef unsigned char uchar;
+
+const uchar *
+search_line_fast (const uchar *s, const uchar *end)
+{
+  size_t VL = svcntb();
+  svuint8_t arr1, arr2;
+  svbool_t pc, pg = svptrue_b8();
+
+  // This should not be loaded inside the loop every time.
+  arr2 = svreinterpret_u8(svdup_u32(0x0a0d5c3f));
+
+  for (; s+VL <= end; s += VL) {
+arr1 = svld1_u8(pg, s);
+pc = svmatch_u8(pg, arr1, arr2);
+
+if (svptest_any(pg, pc)) {
+  pc = svbrkb_z(pg, pc);
+  return s+svcntp_b8(pg, pc);
+}
+  }
+
+  // Handle remainder.
+  if (s < 

[gcc r15-2697] AArch64: Fuse CMP+CSEL and CMP+CSET for -mcpu=neoverse-v2

2024-08-02 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:884846351c74dc79ab143a06c25f00fc7c9e3cfb

commit r15-2697-g884846351c74dc79ab143a06c25f00fc7c9e3cfb
Author: Jennifer Schmitz 
Date:   Fri Aug 2 15:58:32 2024 +0100

AArch64: Fuse CMP+CSEL and CMP+CSET for -mcpu=neoverse-v2

According to the Neoverse V2 Software Optimization Guide (section 4.14), the
instruction pairs CMP+CSEL and CMP+CSET can be fused, which had not been
implemented so far. This patch implements and tests the two fusion pairs.

The patch was bootstrapped and regtested on aarch64-linux-gnu, no 
regression.
There was also no non-noise impact on SPEC CPU2017 benchmark.
OK for mainline?

Signed-off-by: Jennifer Schmitz 

gcc/

* config/aarch64/aarch64.cc (aarch_macro_fusion_pair_p): Implement
fusion logic.
* config/aarch64/aarch64-fusion-pairs.def (cmp+csel): New entry.
(cmp+cset): Likewise.
* config/aarch64/tuning_models/neoversev2.h: Enable logic in
field fusible_ops.

gcc/testsuite/

* gcc.target/aarch64/fuse_cmp_csel.c: New test.
* gcc.target/aarch64/fuse_cmp_cset.c: Likewise.

Diff:
---
 gcc/config/aarch64/aarch64-fusion-pairs.def  |  2 ++
 gcc/config/aarch64/aarch64.cc| 20 ++
 gcc/config/aarch64/tuning_models/neoversev2.h|  5 +++-
 gcc/testsuite/gcc.target/aarch64/fuse_cmp_csel.c | 33 
 gcc/testsuite/gcc.target/aarch64/fuse_cmp_cset.c | 31 ++
 5 files changed, 90 insertions(+), 1 deletion(-)

diff --git a/gcc/config/aarch64/aarch64-fusion-pairs.def 
b/gcc/config/aarch64/aarch64-fusion-pairs.def
index 9a43b0c80657..bf5e85ba8fe1 100644
--- a/gcc/config/aarch64/aarch64-fusion-pairs.def
+++ b/gcc/config/aarch64/aarch64-fusion-pairs.def
@@ -37,5 +37,7 @@ AARCH64_FUSION_PAIR ("aes+aesmc", AES_AESMC)
 AARCH64_FUSION_PAIR ("alu+branch", ALU_BRANCH)
 AARCH64_FUSION_PAIR ("alu+cbz", ALU_CBZ)
 AARCH64_FUSION_PAIR ("addsub_2reg_const1", ADDSUB_2REG_CONST1)
+AARCH64_FUSION_PAIR ("cmp+csel", CMP_CSEL)
+AARCH64_FUSION_PAIR ("cmp+cset", CMP_CSET)
 
 #undef AARCH64_FUSION_PAIR
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 113ebb45cfda..9e12bd9711cd 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -27357,6 +27357,26 @@ aarch_macro_fusion_pair_p (rtx_insn *prev, rtx_insn 
*curr)
   && reg_referenced_p (SET_DEST (prev_set), PATTERN (curr)))
 return true;
 
+  /* Fuse CMP and CSEL/CSET.  */
+  if (prev_set && curr_set
+  && GET_CODE (SET_SRC (prev_set)) == COMPARE
+  && SCALAR_INT_MODE_P (GET_MODE (XEXP (SET_SRC (prev_set), 0)))
+  && reg_referenced_p (SET_DEST (prev_set), PATTERN (curr)))
+{
+  enum attr_type prev_type = get_attr_type (prev);
+  if ((prev_type == TYPE_ALUS_SREG || prev_type == TYPE_ALUS_IMM)
+ && ((aarch64_fusion_enabled_p (AARCH64_FUSE_CMP_CSEL)
+  && GET_CODE (SET_SRC (curr_set)) == IF_THEN_ELSE
+  && aarch64_reg_or_zero (XEXP (SET_SRC (curr_set), 1), VOIDmode)
+  && aarch64_reg_or_zero (XEXP (SET_SRC (curr_set), 2), VOIDmode)
+  && SCALAR_INT_MODE_P (GET_MODE (XEXP (SET_SRC (curr_set), 1
+ || (aarch64_fusion_enabled_p (AARCH64_FUSE_CMP_CSET)
+ && GET_RTX_CLASS (GET_CODE (SET_SRC (curr_set)))
+== RTX_COMPARE
+ && REG_P (SET_DEST (curr_set)
+   return true;
+}
+
   /* Fuse flag-setting ALU instructions and conditional branch.  */
   if (aarch64_fusion_enabled_p (AARCH64_FUSE_ALU_BRANCH)
   && any_condjump_p (curr))
diff --git a/gcc/config/aarch64/tuning_models/neoversev2.h 
b/gcc/config/aarch64/tuning_models/neoversev2.h
index c9c3019dd01a..bd259a37e9c9 100644
--- a/gcc/config/aarch64/tuning_models/neoversev2.h
+++ b/gcc/config/aarch64/tuning_models/neoversev2.h
@@ -221,7 +221,10 @@ static const struct tune_params neoversev2_tunings =
 2 /* store_pred.  */
   }, /* memmov_cost.  */
   5, /* issue_rate  */
-  (AARCH64_FUSE_AES_AESMC | AARCH64_FUSE_CMP_BRANCH), /* fusible_ops  */
+  (AARCH64_FUSE_AES_AESMC
+   | AARCH64_FUSE_CMP_BRANCH
+   | AARCH64_FUSE_CMP_CSEL
+   | AARCH64_FUSE_CMP_CSET), /* fusible_ops  */
   "32:16", /* function_align.  */
   "4", /* jump_align.  */
   "32:16", /* loop_align.  */
diff --git a/gcc/testsuite/gcc.target/aarch64/fuse_cmp_csel.c 
b/gcc/testsuite/gcc.target/aarch64/fuse_cmp_csel.c
new file mode 100644
index ..85f302bab983
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/fuse_cmp_csel.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mcpu=neoverse-v2" } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+/*
+** f1:
+** ...
+** cmp w[0-9]+, w[0-9]+
+** cselw[0-9]+, w[0-9]+, w[0-9]+, le
+** ret
+*/
+int f1 (int a, int b, int c)
+{
+  int cmp = a > b;
+  int add1 = c + 3;
+  int

[gcc r15-2698] arm: Fix testism with mve/ivopts-3.c testcase

2024-08-02 Thread Andre Simoes Dias Vieira via Gcc-cvs
https://gcc.gnu.org/g:995ac87a053c22364bcdc0bc041fd6e5b3087bc5

commit r15-2698-g995ac87a053c22364bcdc0bc041fd6e5b3087bc5
Author: Andre Vieira 
Date:   Fri Aug 2 16:39:34 2024 +0100

arm: Fix testism with mve/ivopts-3.c testcase

This patch ensures this testcase is ran for armv8.1-m.main+mve as this is
testing that doloops with function calls that aren't intrinsics get rejected
as potential doloop targets during ivopts.  For other targets this loop gets
rejected for different reasons.

gcc/testsuite/ChangeLog:

* gcc.target/arm/mve/ivopts-3.c: Add require target and options.

Diff:
---
 gcc/testsuite/gcc.target/arm/mve/ivopts-3.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/testsuite/gcc.target/arm/mve/ivopts-3.c 
b/gcc/testsuite/gcc.target/arm/mve/ivopts-3.c
index 19b2442ef12c..08879424501f 100644
--- a/gcc/testsuite/gcc.target/arm/mve/ivopts-3.c
+++ b/gcc/testsuite/gcc.target/arm/mve/ivopts-3.c
@@ -1,5 +1,7 @@
 /* { dg-do compile } */
+/* { dg-require-effective-target arm_v8_1m_mve_ok } */
 /* { dg-options "-O2 -fdump-tree-ivopts-details" } */
+/* { dg-add-options arm_v8_1m_mve } */
 
 void f2 (void);


[gcc r15-2699] RISC-V: Improve length attributes for atomic insn sequences

2024-08-02 Thread Patrick O'Neill via Gcc-cvs
https://gcc.gnu.org/g:7ecd6610528a301e349df273b624513ef3827321

commit r15-2699-g7ecd6610528a301e349df273b624513ef3827321
Author: Patrick O'Neill 
Date:   Thu Aug 1 20:27:52 2024 -0700

RISC-V: Improve length attributes for atomic insn sequences

gcc/ChangeLog:

* config/riscv/sync-rvwmo.md: Add conditional length attributes.
* config/riscv/sync-ztso.md: Ditto.
* config/riscv/sync.md: Fix incorrect insn length attributes and
reformat existing conditional checks.

Signed-off-by: Patrick O'Neill 

Diff:
---
 gcc/config/riscv/sync-rvwmo.md | 10 --
 gcc/config/riscv/sync-ztso.md  |  9 +++--
 gcc/config/riscv/sync.md   | 10 ++
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/gcc/config/riscv/sync-rvwmo.md b/gcc/config/riscv/sync-rvwmo.md
index 5db94c8c27fa..e26f53ccd3e9 100644
--- a/gcc/config/riscv/sync-rvwmo.md
+++ b/gcc/config/riscv/sync-rvwmo.md
@@ -68,7 +68,10 @@
   return "\t%0,%1";
   }
   [(set_attr "type" "multi")
-   (set (attr "length") (const_int 12))])
+   (set (attr "length")
+   (symbol_ref "(is_mm_seq_cst (memmodel_from_int (INTVAL (operands[2]))) 
? 12
+ : is_mm_acquire (memmodel_from_int (INTVAL 
(operands[2]))) ? 8
+ : 4)"))])
 
 ;; Implement atomic stores with conservative fences.
 ;; This allows us to be compatible with the ISA manual Table A.6 and Table A.7.
@@ -94,4 +97,7 @@
   return "\t%z1,%0";
   }
   [(set_attr "type" "multi")
-   (set (attr "length") (const_int 12))])
+   (set (attr "length")
+   (symbol_ref "(is_mm_seq_cst (memmodel_from_int (INTVAL (operands[2]))) 
? 12
+ : is_mm_release (memmodel_from_int (INTVAL 
(operands[2]))) ? 8
+ : 4)"))])
diff --git a/gcc/config/riscv/sync-ztso.md b/gcc/config/riscv/sync-ztso.md
index f99a21b45ca4..7121b97083f3 100644
--- a/gcc/config/riscv/sync-ztso.md
+++ b/gcc/config/riscv/sync-ztso.md
@@ -58,7 +58,10 @@
   return "\t%0,%1";
   }
   [(set_attr "type" "multi")
-   (set (attr "length") (const_int 12))])
+   (set (attr "length")
+   (symbol_ref "(is_mm_seq_cst (memmodel_from_int (INTVAL (operands[2]))) 
? 8
+ : 4)"))])
+
 
 (define_insn "atomic_store_ztso"
   [(set (match_operand:ANYI 0 "memory_operand" "=A")
@@ -78,4 +81,6 @@
   return "\t%z1,%0";
   }
   [(set_attr "type" "multi")
-   (set (attr "length") (const_int 8))])
+   (set (attr "length")
+   (symbol_ref "(is_mm_seq_cst (memmodel_from_int (INTVAL (operands[2]))) 
? 8
+ : 4)"))])
diff --git a/gcc/config/riscv/sync.md b/gcc/config/riscv/sync.md
index 0c493fea828f..aa0c20446f42 100644
--- a/gcc/config/riscv/sync.md
+++ b/gcc/config/riscv/sync.md
@@ -199,7 +199,7 @@
   "bnez\t%4, 1b";
   }
   [(set_attr "type" "atomic")
-   (set (attr "length") (const_int 20))])
+   (set (attr "length") (const_int 16))])
 
 (define_insn "subword_atomic_fetch_strong_"
   [(set (match_operand:SI 0 "register_operand" "=&r") ;; old value 
at mem
@@ -416,7 +416,7 @@
   "mv\t%0, %4";
   }
   [(set_attr "type" "atomic")
-   (set (attr "length") (const_int 20))])
+   (set (attr "length") (const_int 16))])
 
 (define_expand "atomic_exchange"
   [(match_operand:SHORT 0 "register_operand") ;; old value at mem
@@ -560,7 +560,8 @@
   }
   [(set_attr "type" "atomic")
(set (attr "length")
-(symbol_ref "is_mm_seq_cst(memmodel_from_int(INTVAL (operands[5]))) ? 
8 : 4"))])
+   (symbol_ref "(is_mm_seq_cst (memmodel_from_int (INTVAL (operands[5]))) 
? 8
+ : 4)"))])
 
 (define_expand "atomic_compare_and_swap"
   [(match_operand:SI 0 "register_operand" "")   ;; bool output
@@ -646,7 +647,8 @@
   }
   [(set_attr "type" "atomic")
(set (attr "length")
-(symbol_ref "is_mm_seq_cst(memmodel_from_int(INTVAL (operands[5]))) ? 
8 : 4"))])
+   (symbol_ref "(is_mm_seq_cst (memmodel_from_int (INTVAL (operands[5]))) 
? 8
+ : 4)"))])
 
 (define_expand "atomic_compare_and_swap"
   [(match_operand:SI 0 "register_operand");; bool output


[gcc/devel/fortran_unsigned] Add decimal formatted I/O for unsigneds.

2024-08-02 Thread Thomas Kテカnig via Gcc-cvs
https://gcc.gnu.org/g:4ee8acd349ebc55526421b7fa73b0b7a30ee4ebe

commit 4ee8acd349ebc55526421b7fa73b0b7a30ee4ebe
Author: Thomas Koenig 
Date:   Fri Aug 2 18:33:40 2024 +0200

Add decimal formatted I/O for unsigneds.

Diff:
---
 gcc/testsuite/gfortran.dg/unsigned_4.f90 |  15 
 libgfortran/io/io.h  |   7 ++
 libgfortran/io/read.c| 135 ++-
 libgfortran/io/transfer.c|  42 +-
 libgfortran/io/write.c   |   5 ++
 5 files changed, 178 insertions(+), 26 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/unsigned_4.f90 
b/gcc/testsuite/gfortran.dg/unsigned_4.f90
new file mode 100644
index ..495523d919d3
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/unsigned_4.f90
@@ -0,0 +1,15 @@
+! { dg-do run }
+! { dg-options "-funsigned" }
+! Test some basic formatted I/O.
+
+program main
+  unsigned :: u
+  open (10,status="scratch")
+  write (10,'(I4)') 1u
+  write (10,'(I4)') -1
+  rewind 10
+  read (10,'(I4)') u
+  if (u /= 1u) stop 1
+  read (10,'(I4)') u
+  if (u /= 4294967295u) stop 2
+end program main
diff --git a/libgfortran/io/io.h b/libgfortran/io/io.h
index 32e2b825ed5b..2677551b277d 100644
--- a/libgfortran/io/io.h
+++ b/libgfortran/io/io.h
@@ -897,6 +897,10 @@ internal_proto(read_radix);
 extern void read_decimal (st_parameter_dt *, const fnode *, char *, int);
 internal_proto(read_decimal);
 
+extern void read_decimal_unsigned (st_parameter_dt *, const fnode *, char *,
+  int);
+internal_proto(read_decimal_unsigned);
+
 extern void read_user_defined (st_parameter_dt *, void *);
 internal_proto(read_user_defined);
 
@@ -947,6 +951,9 @@ internal_proto(write_f);
 extern void write_i (st_parameter_dt *, const fnode *, const char *, int);
 internal_proto(write_i);
 
+extern void write_iu (st_parameter_dt *, const fnode *, const char *, int);
+internal_proto(write_iu);
+
 extern void write_l (st_parameter_dt *, const fnode *, char *, int);
 internal_proto(write_l);
 
diff --git a/libgfortran/io/read.c b/libgfortran/io/read.c
index 2fb39392fc99..60b497a810d9 100644
--- a/libgfortran/io/read.c
+++ b/libgfortran/io/read.c
@@ -470,7 +470,7 @@ read_utf8 (st_parameter_dt *dtp, size_t *nbytes)
 if ((c & ~masks[nb-1]) == patns[nb-1])
   goto found;
   goto invalid;
-   
+
  found:
   c = (c & masks[nb-1]);
   nread = nb - 1;
@@ -501,7 +501,7 @@ read_utf8 (st_parameter_dt *dtp, size_t *nbytes)
 goto invalid;
 
   return c;
-  
+
  invalid:
   generate_error (&dtp->common, LIBERROR_READ_VALUE, "Invalid UTF-8 encoding");
   return (gfc_char4_t) '?';
@@ -544,7 +544,7 @@ read_default_char1 (st_parameter_dt *dtp, char *p, size_t 
len, size_t width)
   size_t m;
 
   s = read_block_form (dtp, &width);
-  
+
   if (s == NULL)
 return;
   if (width > len)
@@ -688,7 +688,7 @@ read_a_char4 (st_parameter_dt *dtp, const fnode *f, char 
*p, size_t length)
 read_utf8_char4 (dtp, p, length, w);
   else
 read_default_char4 (dtp, p, length, w);
-  
+
   dtp->u.p.sf_read_comma =
 dtp->u.p.current_unit->decimal_status == DECIMAL_COMMA ? 0 : 1;
 }
@@ -729,7 +729,7 @@ next_char (st_parameter_dt *dtp, char **p, size_t *w)
   if (c != ' ')
 return c;
   if (dtp->u.p.blank_status != BLANK_UNSPECIFIED)
-return ' ';  /* return a blank to signal a null */ 
+return ' ';  /* return a blank to signal a null */
 
   /* At this point, the rest of the field has to be trailing blanks */
 
@@ -808,19 +808,19 @@ read_decimal (st_parameter_dt *dtp, const fnode *f, char 
*dest, int length)
   c = next_char (dtp, &p, &w);
   if (c == '\0')
break;
-   
+
   if (c == ' ')
 {
  if (dtp->u.p.blank_status == BLANK_NULL)
{
  /* Skip spaces.  */
  for ( ; w > 0; p++, w--)
-   if (*p != ' ') break; 
+   if (*p != ' ') break;
  continue;
}
  if (dtp->u.p.blank_status == BLANK_ZERO) c = '0';
 }
-
+
   if (c < '0' || c > '9')
goto bad;
 
@@ -856,6 +856,98 @@ read_decimal (st_parameter_dt *dtp, const fnode *f, char 
*dest, int length)
 
 }
 
+/* read_decimal_unsigned () - almost the same as above, but we do not check for
+   overflow, but just calculate everything mod 2^n. */
+
+void
+read_decimal_unsigned (st_parameter_dt *dtp, const fnode *f, char *dest,
+  int length)
+{
+  GFC_UINTEGER_LARGEST value, v;
+  size_t w;
+  int negative;
+  char c, *p;
+
+  w = f->u.w;
+
+  /* This is a legacy extension, and the frontend will only allow such cases
+   * through when -fdec-format-defaults is passed.
+   */
+  if (w == (size_t) DEFAULT_WIDTH)
+w = default_width_for_integer (length);
+
+  p = read_block_form (dtp, &w);
+
+  if (p == NULL)
+return;
+
+  p = eat_leading_spaces (&w, p);
+  if (w == 0)
+{
+  set_unsigned (dest, (GFC_UINTEGER_LARGEST) 0, length);
+  return;
+}
+
+  

[gcc r14-10552] forwprop: Don't add uses to dce list if debug statement [PR116156]

2024-08-02 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:14fa2b2ae7f49dee5e7e7469243e281e48d925b9

commit r14-10552-g14fa2b2ae7f49dee5e7e7469243e281e48d925b9
Author: Andrew Pinski 
Date:   Thu Aug 1 10:33:34 2024 -0700

forwprop: Don't add uses to dce list if debug statement [PR116156]

The problem here is that when forwprop does a copy prop, into a statement,
we mark the uses of that statement as possibly need to be removed. But it 
just
happened that statement was a debug statement, there will be a difference 
when
compiling with debuging info turned on vs off; this is not expected.
So the fix is not to add the old use to dce list to process if it was a 
debug
statement.

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

PR tree-optimization/116156

gcc/ChangeLog:

* tree-ssa-forwprop.cc (pass_forwprop::execute): Don't add
uses if the statement was a debug statement.

gcc/testsuite/ChangeLog:

* c-c++-common/torture/pr116156-1.c: New test.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/testsuite/c-c++-common/torture/pr116156-1.c | 30 +
 gcc/tree-ssa-forwprop.cc| 16 +++--
 2 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/torture/pr116156-1.c 
b/gcc/testsuite/c-c++-common/torture/pr116156-1.c
new file mode 100644
index ..10f938ef4e5a
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/pr116156-1.c
@@ -0,0 +1,30 @@
+/* { dg-additional-options "-fcompare-debug" } */
+/* PR tree-optimization/116156 */
+
+/* Forwprop used to delete an unused statement
+   but only with debug statements around. */
+
+struct jpeg_compress_struct {
+  int X_density;
+};
+void gg();
+int h(const char*,const char*) __attribute((pure));
+int h1(const char*) __attribute((pure));
+int f1() __attribute__((returns_twice));
+void real_save_jpeg(char **keys, char *values) {
+  struct jpeg_compress_struct cinfo;
+  int x_density = 0;
+  while (*keys)
+  {
+if (h1(*keys) == 0)
+  gg();
+if (h1(*keys) == 0)  {
+  if (!*values)
+x_density = -1;
+  if (x_density <= 0)
+gg();
+}
+  }
+  if (f1())
+cinfo.X_density = x_density;
+}
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index abf71f0d3a03..692e96604b84 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -3919,7 +3919,8 @@ pass_forwprop::execute (function *fun)
  tree val = fwprop_ssa_val (use);
  if (val && val != use)
{
- bitmap_set_bit (simple_dce_worklist, SSA_NAME_VERSION (use));
+ if (!is_gimple_debug (stmt))
+   bitmap_set_bit (simple_dce_worklist, SSA_NAME_VERSION 
(use));
  if (may_propagate_copy (use, val))
{
  propagate_value (usep, val);
@@ -3959,12 +3960,13 @@ pass_forwprop::execute (function *fun)
if (gimple_cond_true_p (cond)
|| gimple_cond_false_p (cond))
  cfg_changed = true;
- /* Queue old uses for simple DCE.  */
- for (tree use : uses)
-   if (TREE_CODE (use) == SSA_NAME
-   && !SSA_NAME_IS_DEFAULT_DEF (use))
- bitmap_set_bit (simple_dce_worklist,
- SSA_NAME_VERSION (use));
+ /* Queue old uses for simple DCE if not debug statement.  */
+ if (!is_gimple_debug (stmt))
+   for (tree use : uses)
+ if (TREE_CODE (use) == SSA_NAME
+ && !SSA_NAME_IS_DEFAULT_DEF (use))
+   bitmap_set_bit (simple_dce_worklist,
+   SSA_NAME_VERSION (use));
}
 
  if (changed || substituted_p)


[gcc r15-2700] genemit: Fix handling of explicit parallels for clobbers [PR116058]

2024-08-02 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:da33ad53bcb57943fa671c745938a53f4de89a1b

commit r15-2700-gda33ad53bcb57943fa671c745938a53f4de89a1b
Author: Andrew Pinski 
Date:   Thu Aug 1 14:22:36 2024 -0700

genemit: Fix handling of explicit parallels for clobbers [PR116058]

In a define_insn, you could use either an explicit parallel for
the insns or genrecog/genemit will add one for you.
The problem when genemit is processing the pattern for clobbers
(to create the function add_clobbers), genemit hadn't add the implicit
parallel yet but at the same time forgot to ignore that there
could be an explicit parallel there.
This means in some cases (like in the sh backend), add_clobbers
and recog had a different idea if there was clobbers on the insn.
This fixes the problem by looking through the explicit parallel
for the instruction in genemit.

Bootstrapped and tested on x86_64-linux-gnu.

PR middle-end/116058

gcc/ChangeLog:

* genemit.cc (struct clobber_pat): Change pattern to be rtvec.
Add code field.
(gen_insn): Look through an explicit parallel if there was one.
Update store to new clobber_pat.
(output_add_clobbers): Update call to gen_exp for the changed
clobber_pat.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/genemit.cc | 38 +++---
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/gcc/genemit.cc b/gcc/genemit.cc
index 98d0477424b0..5d3d10f5061a 100644
--- a/gcc/genemit.cc
+++ b/gcc/genemit.cc
@@ -35,10 +35,11 @@ along with GCC; see the file COPYING3.  If not see
 struct clobber_pat
 {
   struct clobber_ent *insns;
-  rtx pattern;
+  rtvec pattern;
   int first_clobber;
   struct clobber_pat *next;
   int has_hard_reg;
+  rtx_code code;
 } *clobber_list;
 
 /* Records one insn that uses the clobber list.  */
@@ -337,19 +338,25 @@ gen_insn (md_rtx_info *info, FILE *file)
   if (XVEC (insn, 1))
 {
   int has_hard_reg = 0;
+  rtvec pattern = XVEC (insn, 1);
 
-  for (i = XVECLEN (insn, 1) - 1; i > 0; i--)
+  /* Look though an explicit parallel. */
+  if (GET_NUM_ELEM (pattern) == 1
+ && GET_CODE (RTVEC_ELT (pattern, 0)) == PARALLEL)
+   pattern = XVEC (RTVEC_ELT (pattern, 0), 0);
+
+  for (i = GET_NUM_ELEM (pattern) - 1; i > 0; i--)
{
- if (GET_CODE (XVECEXP (insn, 1, i)) != CLOBBER)
+ if (GET_CODE (RTVEC_ELT (pattern, i)) != CLOBBER)
break;
 
- if (REG_P (XEXP (XVECEXP (insn, 1, i), 0)))
+ if (REG_P (XEXP (RTVEC_ELT (pattern, i), 0)))
has_hard_reg = 1;
- else if (GET_CODE (XEXP (XVECEXP (insn, 1, i), 0)) != MATCH_SCRATCH)
+ else if (GET_CODE (XEXP (RTVEC_ELT (pattern, i), 0)) != MATCH_SCRATCH)
break;
}
 
-  if (i != XVECLEN (insn, 1) - 1)
+  if (i != GET_NUM_ELEM (pattern) - 1)
{
  struct clobber_pat *p;
  struct clobber_ent *link = XNEW (struct clobber_ent);
@@ -363,13 +370,13 @@ gen_insn (md_rtx_info *info, FILE *file)
  for (p = clobber_list; p; p = p->next)
{
  if (p->first_clobber != i + 1
- || XVECLEN (p->pattern, 1) != XVECLEN (insn, 1))
+ || GET_NUM_ELEM (p->pattern) != GET_NUM_ELEM (pattern))
continue;
 
- for (j = i + 1; j < XVECLEN (insn, 1); j++)
+ for (j = i + 1; j < GET_NUM_ELEM (pattern); j++)
{
- rtx old_rtx = XEXP (XVECEXP (p->pattern, 1, j), 0);
- rtx new_rtx = XEXP (XVECEXP (insn, 1, j), 0);
+ rtx old_rtx = XEXP (RTVEC_ELT (p->pattern, j), 0);
+ rtx new_rtx = XEXP (RTVEC_ELT (pattern, j), 0);
 
  /* OLD and NEW_INSN are the same if both are to be a SCRATCH
 of the same mode,
@@ -383,7 +390,7 @@ gen_insn (md_rtx_info *info, FILE *file)
break;
}
 
- if (j == XVECLEN (insn, 1))
+ if (j == GET_NUM_ELEM (pattern))
break;
}
 
@@ -392,10 +399,11 @@ gen_insn (md_rtx_info *info, FILE *file)
  p = XNEW (struct clobber_pat);
 
  p->insns = 0;
- p->pattern = insn;
+ p->pattern = pattern;
  p->first_clobber = i + 1;
  p->next = clobber_list;
  p->has_hard_reg = has_hard_reg;
+ p->code = GET_CODE (insn);
  clobber_list = p;
}
 
@@ -662,11 +670,11 @@ output_add_clobbers (md_rtx_info *info, FILE *file)
   for (ent = clobber->insns; ent; ent = ent->next)
fprintf (file, "case %d:\n", ent->code_number);
 
-  for (i = clobber->first_clobber; i < XVECLEN (clobber->pattern, 1); i++)
+  for (i = clobber->first_clobber; i < GET_NUM_ELEM (clobber->pattern); 
i++)
{
  fprintf (file, "  XVECEXP 

[gcc r15-2701] fortran: Support optional dummy as BACK argument of MINLOC/MAXLOC.

2024-08-02 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:a10436a8404ad2f0cc5aa4d6a0cc850abe5ef49e

commit r15-2701-ga10436a8404ad2f0cc5aa4d6a0cc850abe5ef49e
Author: Mikael Morin 
Date:   Fri Aug 2 14:24:34 2024 +0200

fortran: Support optional dummy as BACK argument of MINLOC/MAXLOC.

Protect the evaluation of BACK with a check that the reference is non-null
in case the expression is an optional dummy, in the inline code generated
for MINLOC and MAXLOC.

This change contains a revert of the non-testsuite part of commit
r15-1994-ga55d24b3cf7f4d07492bb8e6fcee557175b47ea3, which factored the
evaluation of BACK out of the loop using the scalarizer.  It was a bad idea,
because delegating the argument evaluation to the scalarizer makes it
cumbersome to add a null pointer check next to the evaluation.

Instead, evaluate BACK at the beginning, before scalarization, add a check
that the argument is present if necessary, and evaluate the resulting
expression to a variable, before using the variable in the inline code.

gcc/fortran/ChangeLog:

* trans-intrinsic.cc (maybe_absent_optional_variable): New function.
(gfc_conv_intrinsic_minmaxloc): Remove BACK from scalarization and
evaluate it before.  Add a check that BACK is not null if the
expression is an optional dummy.  Save the resulting expression to a
variable.  Use the variable in the generated inline code.

gcc/testsuite/ChangeLog:

* gfortran.dg/maxloc_6.f90: New test.
* gfortran.dg/minloc_7.f90: New test.

Diff:
---
 gcc/fortran/trans-intrinsic.cc |  83 ++--
 gcc/testsuite/gfortran.dg/maxloc_6.f90 | 366 +
 gcc/testsuite/gfortran.dg/minloc_7.f90 | 366 +
 3 files changed, 801 insertions(+), 14 deletions(-)

diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 180d0d7a88c6..150cb9ff963b 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -5209,6 +5209,50 @@ gfc_conv_intrinsic_dot_product (gfc_se * se, gfc_expr * 
expr)
 }
 
 
+/* Tells whether the expression E is a reference to an optional variable whose
+   presence is not known at compile time.  Those are variable references 
without
+   subreference; if there is a subreference, we can assume the variable is
+   present.  We have to special case full arrays, which we represent with a 
fake
+   "full" reference, and class descriptors for which a reference to data is not
+   really a subreference.  */
+
+bool
+maybe_absent_optional_variable (gfc_expr *e)
+{
+  if (!(e && e->expr_type == EXPR_VARIABLE))
+return false;
+
+  gfc_symbol *sym = e->symtree->n.sym;
+  if (!sym->attr.optional)
+return false;
+
+  gfc_ref *ref = e->ref;
+  if (ref == nullptr)
+return true;
+
+  if (ref->type == REF_ARRAY
+  && ref->u.ar.type == AR_FULL
+  && ref->next == nullptr)
+return true;
+
+  if (!(sym->ts.type == BT_CLASS
+   && ref->type == REF_COMPONENT
+   && ref->u.c.component == CLASS_DATA (sym)))
+return false;
+
+  gfc_ref *next_ref = ref->next;
+  if (next_ref == nullptr)
+return true;
+
+  if (next_ref->type == REF_ARRAY
+  && next_ref->u.ar.type == AR_FULL
+  && next_ref->next == nullptr)
+return true;
+
+  return false;
+}
+
+
 /* Remove unneeded kind= argument from actual argument list when the
result conversion is dealt with in a different place.  */
 
@@ -5321,11 +5365,11 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * 
expr, enum tree_code op)
   tree nonempty;
   tree lab1, lab2;
   tree b_if, b_else;
+  tree back;
   gfc_loopinfo loop;
   gfc_actual_arglist *actual;
   gfc_ss *arrayss;
   gfc_ss *maskss;
-  gfc_ss *backss;
   gfc_se arrayse;
   gfc_se maskse;
   gfc_expr *arrayexpr;
@@ -5391,10 +5435,29 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * 
expr, enum tree_code op)
 && maskexpr->symtree->n.sym->attr.dummy
 && maskexpr->symtree->n.sym->attr.optional;
   backexpr = actual->next->next->expr;
-  if (backexpr)
-backss = gfc_get_scalar_ss (gfc_ss_terminator, backexpr);
+
+  gfc_init_se (&backse, NULL);
+  if (backexpr == nullptr)
+back = logical_false_node;
+  else if (maybe_absent_optional_variable (backexpr))
+{
+  /* This should have been checked already by
+maybe_absent_optional_variable.  */
+  gcc_checking_assert (backexpr->expr_type == EXPR_VARIABLE);
+
+  gfc_conv_expr (&backse, backexpr);
+  tree present = gfc_conv_expr_present (backexpr->symtree->n.sym, false);
+  back = fold_build2_loc (input_location, TRUTH_ANDIF_EXPR,
+ logical_type_node, present, backse.expr);
+}
   else
-backss = nullptr;
+{
+  gfc_conv_expr (&backse, backexpr);
+  back = backse.expr;
+}
+  gfc_add_block_to_block (&se->pre, &backse.pre);
+  back = gfc_evaluate_now_loc (input_location, back, 

[gcc] Deleted branch 'mikael/heads/dummy_back_minmaxloc_final' in namespace 'refs/users'

2024-08-02 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/dummy_back_minmaxloc_final' in namespace 'refs/users' 
was deleted.
It previously pointed to:

 999b16301553... fortran: Support optional dummy as BACK argument of MINLOC/

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  999b163... fortran: Support optional dummy as BACK argument of MINLOC/


[gcc] Deleted branch 'mikael/heads/dummy_back_minmaxloc_v01' in namespace 'refs/users'

2024-08-02 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/dummy_back_minmaxloc_v01' in namespace 'refs/users' 
was deleted.
It previously pointed to:

 baba12c6c972... fortran: Support optional dummy as BACK argument of MINLOC/

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  baba12c... fortran: Support optional dummy as BACK argument of MINLOC/


[gcc] Deleted branch 'mikael/heads/dummy_back_minmaxloc_final02' in namespace 'refs/users'

2024-08-02 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/dummy_back_minmaxloc_final02' in namespace 
'refs/users' was deleted.
It previously pointed to:

 40122a405386... fortran: Support optional dummy as BACK argument of MINLOC/

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  40122a4... fortran: Support optional dummy as BACK argument of MINLOC/


[gcc] Deleted branch 'mikael/heads/pr99798_v66' in namespace 'refs/users'

2024-08-02 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/pr99798_v66' in namespace 'refs/users' was deleted.
It previously pointed to:

 4b2e3dff5615... fortran: Fix leaked symbol

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  4b2e3df... fortran: Fix leaked symbol
  934742d... fortran: Assume there is no cyclic reference with submodule


[gcc r15-2702] c++/coroutines: check for members we use in handle_types [PR105475]

2024-08-02 Thread Arsen Arsenovic via Gcc-cvs
https://gcc.gnu.org/g:5b4476a165565cb20729c0a97a3f43b060595209

commit r15-2702-g5b4476a165565cb20729c0a97a3f43b060595209
Author: Arsen Arsenović 
Date:   Thu Jul 25 22:41:34 2024 +0200

c++/coroutines: check for members we use in handle_types [PR105475]

Currently, it is possible to ICE GCC by giving it sufficiently broken
code, where sufficiently broken means a std::coroutine_handle missing a
default on the promise_type template argument, and missing members.
As the code generator relies on lookups in the coroutine_handle never
failing (and has no way to signal that error), lets do it ahead of time,
save the result, and use that.  This saves us some lookups and allows us
to propagate an error.

PR c++/105475 - coroutines: ICE in coerce_template_parms, at cp/pt.cc:9183

gcc/cp/ChangeLog:

PR c++/105475
* coroutines.cc (struct coroutine_info): Add from_address.
Carries the from_address member we looked up earlier.
(coro_resume_identifier): Remove.  Unused.
(coro_init_identifiers): Do not initialize the above.
(void_coro_handle_address): New variable.  Contains the baselink
for the std::coroutine_handle::address() instance method.
(get_handle_type_address): New function.  Looks up and validates
handle_type::address in a given handle_type.
(get_handle_type_from_address): New function.  Looks up and
validates handle_type::from_address in a given handle_type.
(coro_promise_type_found_p): Remove reliance on
coroutine_handle<> defaulting the promise type to void.  Store
get_handle_type_* results where appropriate.
(get_coroutine_from_address): New helper.  Gets the
handle_type::from_address BASELINK from a coroutine_info.
(build_actor_fn): Use the get_coroutine_from_address helper and
void_coro_handle_address.

gcc/testsuite/ChangeLog:

PR c++/105475
* g++.dg/coroutines/pr103868.C: Add std::coroutine_handle
members we check for now.
* g++.dg/coroutines/pr105287.C: Ditto.
* g++.dg/coroutines/pr105301.C: Ditto.
* g++.dg/coroutines/pr94528.C: Ditto.
* g++.dg/coroutines/pr94879-folly-1.C: Ditto.
* g++.dg/coroutines/pr94883-folly-2.C: Ditto.
* g++.dg/coroutines/pr98118.C: Ditto.
* g++.dg/coroutines/pr105475.C: New test.
* g++.dg/coroutines/pr105475-1.C: New test.
* g++.dg/coroutines/pr105475-2.C: New test.
* g++.dg/coroutines/pr105475-3.C: New test.
* g++.dg/coroutines/pr105475-4.C: New test.
* g++.dg/coroutines/pr105475-5.C: New test.
* g++.dg/coroutines/pr105475-6.C: New test.
* g++.dg/coroutines/pr105475-broken-spec.C: New test.
* g++.dg/coroutines/pr105475-broken-spec-2.C: New test.

Diff:
---
 gcc/cp/coroutines.cc   | 138 ++---
 gcc/testsuite/g++.dg/coroutines/pr103868.C |   2 +
 gcc/testsuite/g++.dg/coroutines/pr105287.C |   2 +
 gcc/testsuite/g++.dg/coroutines/pr105301.C |   5 +-
 gcc/testsuite/g++.dg/coroutines/pr105475-1.C   |  27 
 gcc/testsuite/g++.dg/coroutines/pr105475-2.C   |  29 +
 gcc/testsuite/g++.dg/coroutines/pr105475-3.C   |  29 +
 gcc/testsuite/g++.dg/coroutines/pr105475-4.C   |  41 ++
 gcc/testsuite/g++.dg/coroutines/pr105475-5.C   |  29 +
 gcc/testsuite/g++.dg/coroutines/pr105475-6.C   |  29 +
 .../g++.dg/coroutines/pr105475-broken-spec-2.C |  33 +
 .../g++.dg/coroutines/pr105475-broken-spec.C   |  29 +
 gcc/testsuite/g++.dg/coroutines/pr105475.C |  28 +
 gcc/testsuite/g++.dg/coroutines/pr94528.C  |  11 +-
 gcc/testsuite/g++.dg/coroutines/pr94879-folly-1.C  |  10 +-
 gcc/testsuite/g++.dg/coroutines/pr94883-folly-2.C  |  10 +-
 gcc/testsuite/g++.dg/coroutines/pr98118.C  |  10 +-
 17 files changed, 439 insertions(+), 23 deletions(-)

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index af03f5e0f744..742f0e505976 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -91,6 +91,7 @@ struct GTY((for_user)) coroutine_info
 one that will eventually be allocated in the coroutine
 frame.  */
   tree promise_proxy; /* Likewise, a proxy promise instance.  */
+  tree from_address;  /* handle_type from_address function.  */
   tree return_void;   /* The expression for p.return_void() if it exists.  */
   location_t first_coro_keyword; /* The location of the keyword that made this
function into a coroutine.  */
@@ -203,7 +204,6 @@ static GTY(()) tree coro_final_suspend_identifier;
 static GTY(()) tree coro_return_void_identifier;
 static GTY(()) tree coro_retu

[gcc r15-2703] c++: Move -Wdangling-reference to -Wextra

2024-08-02 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:5ebfaf2d4994c124ce81aa0abd7eaa1529644749

commit r15-2703-g5ebfaf2d4994c124ce81aa0abd7eaa1529644749
Author: Marek Polacek 
Date:   Thu Aug 1 10:35:38 2024 -0400

c++: Move -Wdangling-reference to -Wextra

Despite a number of mitigations (don't warn for std::span-like classes,
lambdas, adding [[gnu::no_dangling]], etc.), the warning still seems to
cause some grief.  Let's move the warning to -Wextra, then.

gcc/c-family/ChangeLog:

* c.opt (Wdangling-reference): Move from -Wall to -Wextra.

gcc/ChangeLog:

* doc/invoke.texi: Document that -Wdangling-reference is
enabled by -Wextra.

Diff:
---
 gcc/c-family/c.opt  | 2 +-
 gcc/doc/invoke.texi | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index a52682d835ce..979f17a7e323 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -604,7 +604,7 @@ C ObjC C++ ObjC++ Joined RejectNegative UInteger 
Var(warn_dangling_pointer) Warn
 Warn for uses of pointers to auto variables whose lifetime has ended.
 
 Wdangling-reference
-C++ ObjC++ Var(warn_dangling_reference) Warning LangEnabledBy(C++ ObjC++, Wall)
+C++ ObjC++ Var(warn_dangling_reference) Warning LangEnabledBy(C++ ObjC++, 
Wextra)
 Warn when a reference is bound to a temporary whose lifetime has ended.
 
 Wdate-time
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 54ecd9a00eb4..0fe99ca8ef6e 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -3962,7 +3962,7 @@ that has a pointer data member and a trivial destructor.
 The warning can be disabled by using the @code{gnu::no_dangling} attribute
 (@pxref{C++ Attributes}).
 
-This warning is enabled by @option{-Wall}.
+This warning is enabled by @option{-Wextra}.
 
 @opindex Wdelete-non-virtual-dtor
 @opindex Wno-delete-non-virtual-dtor
@@ -6481,6 +6481,7 @@ name is still supported, but the newer name is more 
descriptive.)
 -Wcalloc-transposed-args
 -Wcast-function-type
 -Wclobbered
+-Wdangling-reference @r{(C++ only)}
 -Wdeprecated-copy @r{(C++ and Objective-C++ only)}
 -Wempty-body
 -Wenum-conversion @r{(only for C/ObjC)}


[gcc(refs/users/meissner/heads/work175)] Add support for -mcpu=future

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:a489eddc49baf526a4ddbef6f40cd8f31af0529a

commit a489eddc49baf526a4ddbef6f40cd8f31af0529a
Author: Michael Meissner 
Date:   Fri Aug 2 18:16:22 2024 -0400

Add support for -mcpu=future

This patch adds the support that can be used in developing GCC support for
future PowerPC processors.

2024-08-02  Michael Meissner  

* config/rs6000/rs6000-arch.def: Add future processor.
* config/rs6000/rs6000-c.cc (rs6000_target_modify_macros): Define
_ARCH_FUTURE if -mcpu=future.
* config/rs6000/rs6000-cpus.def (FUTURE_MASKS_SERVER): New macro.
(future cpu): Add support for -mcpu=future.
* config/rs6000/rs6000-opts.h (enum processor_type): Likewise.
* config/rs6000/rs6000-tables.opt: Regenerate.
* config/rs6000/rs6000.cc (get_arch_flags): Likewise.
(rs6000_option_override_internal): Likewise.
(rs6000_machine_from_flags): Likewise.
(rs6000_reassociation_width): Likewise.
(rs6000_adjust_cost): Likewise.
(rs6000_issue_rate): Likewise.
(rs6000_sched_reorder): Likewise.
(rs6000_issue_rate): Likewise.
(rs6000_register_move_cost): Likewise.
* config/rs6000/rs6000.h (TARGET_FUTURE): New macro.
* config/rs6000/rs6000.md (cpu attribute): Add future processor.

Diff:
---
 gcc/config/rs6000/rs6000-arch.def   |  1 +
 gcc/config/rs6000/rs6000-c.cc   |  2 ++
 gcc/config/rs6000/rs6000-cpus.def   |  3 +++
 gcc/config/rs6000/rs6000-opts.h |  1 +
 gcc/config/rs6000/rs6000-tables.opt | 11 +++
 gcc/config/rs6000/rs6000.cc | 34 ++
 gcc/config/rs6000/rs6000.h  |  1 +
 gcc/config/rs6000/rs6000.md |  2 +-
 8 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-arch.def 
b/gcc/config/rs6000/rs6000-arch.def
index e5b6e9581331..d103c57867a1 100644
--- a/gcc/config/rs6000/rs6000-arch.def
+++ b/gcc/config/rs6000/rs6000-arch.def
@@ -46,3 +46,4 @@ ARCH_EXPAND(POWER8,  "power8")
 ARCH_EXPAND(POWER9,  "power9")
 ARCH_EXPAND(POWER10, "power10")
 ARCH_EXPAND(POWER11, "power11")
+ARCH_EXPAND(FUTURE,  "future")
diff --git a/gcc/config/rs6000/rs6000-c.cc b/gcc/config/rs6000/rs6000-c.cc
index c8f33289fa38..82826f96a8e7 100644
--- a/gcc/config/rs6000/rs6000-c.cc
+++ b/gcc/config/rs6000/rs6000-c.cc
@@ -440,6 +440,8 @@ rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT 
flags,
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR10");
   if ((arch_flags & ARCH_MASK_POWER11) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR11");
+  if ((arch_flags & ARCH_MASK_FUTURE) != 0)
+rs6000_define_or_undefine_macro (define_p, "_ARCH_FUTURE");
   if ((flags & OPTION_MASK_SOFT_FLOAT) != 0)
 rs6000_define_or_undefine_macro (define_p, "_SOFT_FLOAT");
   if ((flags & OPTION_MASK_RECIP_PRECISION) != 0)
diff --git a/gcc/config/rs6000/rs6000-cpus.def 
b/gcc/config/rs6000/rs6000-cpus.def
index a3568898b0b6..e73d9ef51f8d 100644
--- a/gcc/config/rs6000/rs6000-cpus.def
+++ b/gcc/config/rs6000/rs6000-cpus.def
@@ -86,6 +86,8 @@
 
 #define POWER11_MASKS_SERVER   ISA_3_1_MASKS_SERVER
 
+#define FUTURE_MASKS_SERVERPOWER11_MASKS_SERVER
+
 /* Flags that need to be turned off if -mno-vsx.  */
 #define OTHER_VSX_VECTOR_MASKS (OPTION_MASK_EFFICIENT_UNALIGNED_VSX\
 | OPTION_MASK_FLOAT128_KEYWORD \
@@ -249,6 +251,7 @@ RS6000_CPU ("power9", PROCESSOR_POWER9, MASK_POWERPC64 | 
ISA_3_0_MASKS_SERVER
| OPTION_MASK_HTM)
 RS6000_CPU ("power10", PROCESSOR_POWER10, MASK_POWERPC64 | 
ISA_3_1_MASKS_SERVER)
 RS6000_CPU ("power11", PROCESSOR_POWER11, MASK_POWERPC64 | 
POWER11_MASKS_SERVER)
+RS6000_CPU ("future", PROCESSOR_FUTURE, MASK_POWERPC64 | FUTURE_MASKS_SERVER)
 RS6000_CPU ("powerpc", PROCESSOR_POWERPC, 0)
 RS6000_CPU ("powerpc64", PROCESSOR_POWERPC64, OPTION_MASK_PPC_GFXOPT
| MASK_POWERPC64)
diff --git a/gcc/config/rs6000/rs6000-opts.h b/gcc/config/rs6000/rs6000-opts.h
index 88e357835a5c..c25ddf92858c 100644
--- a/gcc/config/rs6000/rs6000-opts.h
+++ b/gcc/config/rs6000/rs6000-opts.h
@@ -63,6 +63,7 @@ enum processor_type
PROCESSOR_POWER9,
PROCESSOR_POWER10,
PROCESSOR_POWER11,
+   PROCESSOR_FUTURE,
 
PROCESSOR_RS64A,
PROCESSOR_MPCCORE,
diff --git a/gcc/config/rs6000/rs6000-tables.opt 
b/gcc/config/rs6000/rs6000-tables.opt
index a5649fef1ece..fc187c641f8d 100644
--- a/gcc/config/rs6000/rs6000-tables.opt
+++ b/gcc/config/rs6000/rs6000-tables.opt
@@ -189,14 +189,17 @@ EnumValue
 Enum(rs6000_cpu_opt_value) String(power11) Value(53)
 
 EnumValue
-Enum(rs6000_cpu_opt_value) String(powerpc) Value(54)
+Enum(rs6000_cpu_opt_value) String(future) Value(54)
 
 EnumValue
-Enum(rs6000_cpu_opt_value) String(powerpc64) Value(55)
+Enum(rs6000_cpu_opt_value) String(powerpc) Value(55)
 
 EnumValue
-Enum(rs6000_cpu_opt_value) String(

[gcc(refs/users/meissner/heads/work175)] Add -mcpu=future tuning support.

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:a22ff2fb0646120c26d3f8baf4abb92e6c01043e

commit a22ff2fb0646120c26d3f8baf4abb92e6c01043e
Author: Michael Meissner 
Date:   Fri Aug 2 18:20:33 2024 -0400

Add -mcpu=future tuning support.

This patch makes -mtune=future use the same tuning decision as 
-mtune=power11.

2024-08-02  Michael Meissner  

gcc/

* config/rs6000/power10.md (all reservations): Add future as an
alterntive to power10 and power11.

Diff:
---
 gcc/config/rs6000/power10.md | 144 +--
 1 file changed, 72 insertions(+), 72 deletions(-)

diff --git a/gcc/config/rs6000/power10.md b/gcc/config/rs6000/power10.md
index 2310c4603457..e42b057dc45b 100644
--- a/gcc/config/rs6000/power10.md
+++ b/gcc/config/rs6000/power10.md
@@ -1,4 +1,4 @@
-;; Scheduling description for the IBM Power10 and Power11 processors.
+;; Scheduling description for the IBM Power10, Power11, and Future processors.
 ;; Copyright (C) 2020-2024 Free Software Foundation, Inc.
 ;;
 ;; Contributed by Pat Haugen (pthau...@us.ibm.com).
@@ -97,12 +97,12 @@
(eq_attr "update" "no")
(eq_attr "size" "!128")
(eq_attr "prefixed" "no")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_any_power10,LU_power10")
 
 (define_insn_reservation "power10-fused-load" 4
   (and (eq_attr "type" "fused_load_cmpi,fused_addis_load,fused_load_load")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,LU_power10")
 
 (define_insn_reservation "power10-prefixed-load" 4
@@ -110,13 +110,13 @@
(eq_attr "update" "no")
(eq_attr "size" "!128")
(eq_attr "prefixed" "yes")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,LU_power10")
 
 (define_insn_reservation "power10-load-update" 4
   (and (eq_attr "type" "load")
(eq_attr "update" "yes")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,LU_power10+SXU_power10")
 
 (define_insn_reservation "power10-fpload-double" 4
@@ -124,7 +124,7 @@
(eq_attr "update" "no")
(eq_attr "size" "64")
(eq_attr "prefixed" "no")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_any_power10,LU_power10")
 
 (define_insn_reservation "power10-prefixed-fpload-double" 4
@@ -132,14 +132,14 @@
(eq_attr "update" "no")
(eq_attr "size" "64")
(eq_attr "prefixed" "yes")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,LU_power10")
 
 (define_insn_reservation "power10-fpload-update-double" 4
   (and (eq_attr "type" "fpload")
(eq_attr "update" "yes")
(eq_attr "size" "64")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,LU_power10+SXU_power10")
 
 ; SFmode loads are cracked and have additional 3 cycles over DFmode
@@ -148,27 +148,27 @@
   (and (eq_attr "type" "fpload")
(eq_attr "update" "no")
(eq_attr "size" "32")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,LU_power10")
 
 (define_insn_reservation "power10-fpload-update-single" 7
   (and (eq_attr "type" "fpload")
(eq_attr "update" "yes")
(eq_attr "size" "32")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,LU_power10+SXU_power10")
 
 (define_insn_reservation "power10-vecload" 4
   (and (eq_attr "type" "vecload")
(eq_attr "size" "!256")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_any_power10,LU_power10")
 
 ; lxvp
 (define_insn_reservation "power10-vecload-pair" 4
   (and (eq_attr "type" "vecload")
(eq_attr "size" "256")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,LU_power10+SXU_power10")
 
 ; Store Unit
@@ -178,12 +178,12 @@
(eq_attr "prefixed" "no")
(eq_attr "size" "!128")
(eq_attr "size" "!256")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_any_power10,STU_power10")
 
 (define_insn_reservation "power10-fused-store" 0
   (and (eq_attr "type" "fused_store_store")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,STU_power10")
 
 (define_insn_reservation "power10-prefixed-store" 0
@@ -191,52 +191,52 @@
(eq_attr "prefixed" "yes")
(eq_attr "size" "!128")
(eq_attr "size" "!256")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,STU_power10")
 
 ; Update forms have 2 cycle latency for update

[gcc(refs/users/meissner/heads/work175)] Update ChangeLog.*

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:a833e57943a3f3275b28f7e5aa1b8ef4b8fecf6b

commit a833e57943a3f3275b28f7e5aa1b8ef4b8fecf6b
Author: Michael Meissner 
Date:   Fri Aug 2 18:22:48 2024 -0400

Update ChangeLog.*

Diff:
---
 gcc/ChangeLog.meissner | 64 ++
 1 file changed, 64 insertions(+)

diff --git a/gcc/ChangeLog.meissner b/gcc/ChangeLog.meissner
index ed41155fa674..ea351008f85c 100644
--- a/gcc/ChangeLog.meissner
+++ b/gcc/ChangeLog.meissner
@@ -1,3 +1,67 @@
+ Branch work175, patch #11 
+
+Add -mcpu=future tuning support.
+
+This patch makes -mtune=future use the same tuning decision as -mtune=power11.
+
+2024-07-03  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/power10.md (all reservations): Add future as an
+   alterntive to power10 and power11.
+
+ Branch work175, patch #10 
+
+Add -mcpu=future support.
+
+This patch adds the future option to the -mcpu= and -mtune= switches.
+
+This patch treats the future like a power11 in terms of costs and reassociation
+width.
+
+This patch issues a ".machine future" to the assembly file if you use
+-mcpu=power11.
+
+This patch defines _ARCH_PWR_FUTURE if the user uses -mcpu=future.
+
+This patch allows GCC to be configured with the --with-cpu=future and
+--with-tune=future options.
+
+This patch passes -mfuture to the assembler if the user uses -mcpu=future.
+
+2024-07-03  Michael Meissner  
+
+gcc/
+
+   * config.gcc (rs6000*-*-*, powerpc*-*-*): Add support for power11.
+   * config/rs6000/aix71.h (ASM_CPU_SPEC): Add support for -mcpu=power11.
+   * config/rs6000/aix72.h (ASM_CPU_SPEC): Likewise.
+   * config/rs6000/aix73.h (ASM_CPU_SPEC): Likewise.
+   * config/rs6000/driver-rs6000.cc (asm_names): Likewise.
+   * config/rs6000/rs6000-c.cc (rs6000_target_modify_macros): Define
+   _ARCH_PWR_FUTURE if -mcpu=future.
+   * config/rs6000/rs6000-cpus.def (ISA_FUTURE_MASKS_SERVER): New define.
+   (POWERPC_MASKS): Add future isa bit.
+   (power11 cpu): Add future definition.
+   * config/rs6000/rs6000-opts.h (PROCESSOR_FUTURE): Add future processor.
+   * config/rs6000/rs6000-string.cc (expand_compare_loop): Likewise.
+   * config/rs6000/rs6000-tables.opt: Regenerate.
+   * config/rs6000/rs6000.cc (rs6000_option_override_internal): Add future
+   support.
+   (rs6000_machine_from_flags): Likewise.
+   (rs6000_reassociation_width): Likewise.
+   (rs6000_adjust_cost): Likewise.
+   (rs6000_issue_rate): Likewise.
+   (rs6000_sched_reorder): Likewise.
+   (rs6000_sched_reorder2): Likewise.
+   (rs6000_register_move_cost): Likewise.
+   (rs6000_opt_masks): Likewise.
+   * config/rs6000/rs6000.h (ASM_CPU_SPEC): Likewise.
+   * config/rs6000/rs6000.md (cpu attribute): Add future.
+   * config/rs6000/rs6000.opt (-mpower11): Add internal future ISA flag.
+   * doc/invoke.texi (RS/6000 and PowerPC Options): Document -mcpu=future.
+
  Branch work175, patch #9 
 
 Update tests to work with architecture flags changes.


[gcc/meissner/heads/work175-bugs] (5 commits) Merge commit 'refs/users/meissner/heads/work175-bugs' of gi

2024-08-02 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work175-bugs' was updated to point to:

 63e8b76ddfe7... Merge commit 'refs/users/meissner/heads/work175-bugs' of gi

It previously pointed to:

 6569017aeadd... Merge commit 'refs/users/meissner/heads/work175-bugs' of gi

Diff:

Summary of changes (added commits):
---

  63e8b76... Merge commit 'refs/users/meissner/heads/work175-bugs' of gi
  7cfd0a7... Add ChangeLog.bugs and update REVISION.
  a833e57... Update ChangeLog.* (*)
  a22ff2f... Add -mcpu=future tuning support. (*)
  a489edd... Add support for -mcpu=future (*)

(*) This commit already exists in another branch.
Because the reference `refs/users/meissner/heads/work175-bugs' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc(refs/users/meissner/heads/work175-bugs)] Add ChangeLog.bugs and update REVISION.

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:7cfd0a7d44698a32c85eeec84793d75a2b3c087d

commit 7cfd0a7d44698a32c85eeec84793d75a2b3c087d
Author: Michael Meissner 
Date:   Thu Aug 1 15:51:21 2024 -0400

Add ChangeLog.bugs and update REVISION.

2024-08-01  Michael Meissner  

gcc/

* ChangeLog.bugs: New file for branch.
* REVISION: Update.

Diff:
---
 gcc/ChangeLog.bugs | 6 ++
 gcc/REVISION   | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.bugs b/gcc/ChangeLog.bugs
new file mode 100644
index ..94889013fa70
--- /dev/null
+++ b/gcc/ChangeLog.bugs
@@ -0,0 +1,6 @@
+ Branch work175-bugs, baseline 
+
+2024-08-01   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/REVISION b/gcc/REVISION
index 1573af834b31..90da570993ff 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work175 branch
+work175-bugs branch


[gcc(refs/users/meissner/heads/work175-bugs)] Merge commit 'refs/users/meissner/heads/work175-bugs' of git+ssh://gcc.gnu.org/git/gcc into me/work1

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:63e8b76ddfe7df6c2731b5a826f1d90c5cb609e7

commit 63e8b76ddfe7df6c2731b5a826f1d90c5cb609e7
Merge: 7cfd0a7d4469 6569017aeadd
Author: Michael Meissner 
Date:   Fri Aug 2 18:24:10 2024 -0400

Merge commit 'refs/users/meissner/heads/work175-bugs' of 
git+ssh://gcc.gnu.org/git/gcc into me/work175-bugs

Diff:


[gcc/meissner/heads/work175-dmf] (5 commits) Merge commit 'refs/users/meissner/heads/work175-dmf' of git

2024-08-02 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work175-dmf' was updated to point to:

 1fc1d66280c2... Merge commit 'refs/users/meissner/heads/work175-dmf' of git

It previously pointed to:

 7533a789cc60... Merge commit 'refs/users/meissner/heads/work175-dmf' of git

Diff:

Summary of changes (added commits):
---

  1fc1d66... Merge commit 'refs/users/meissner/heads/work175-dmf' of git
  6d3cf2d... Add ChangeLog.dmf and update REVISION.
  a833e57... Update ChangeLog.* (*)
  a22ff2f... Add -mcpu=future tuning support. (*)
  a489edd... Add support for -mcpu=future (*)

(*) This commit already exists in another branch.
Because the reference `refs/users/meissner/heads/work175-dmf' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc(refs/users/meissner/heads/work175-dmf)] Add ChangeLog.dmf and update REVISION.

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:6d3cf2d1ca44dfb19fb224298c8472bbd4c9628a

commit 6d3cf2d1ca44dfb19fb224298c8472bbd4c9628a
Author: Michael Meissner 
Date:   Thu Aug 1 15:48:37 2024 -0400

Add ChangeLog.dmf and update REVISION.

2024-08-01  Michael Meissner  

gcc/

* ChangeLog.dmf: New file for branch.
* REVISION: Update.

Diff:
---
 gcc/ChangeLog.dmf | 6 ++
 gcc/REVISION  | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.dmf b/gcc/ChangeLog.dmf
new file mode 100644
index ..d3f1cc6620a5
--- /dev/null
+++ b/gcc/ChangeLog.dmf
@@ -0,0 +1,6 @@
+ Branch work175-dmf, baseline 
+
+2024-08-01   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/REVISION b/gcc/REVISION
index 1573af834b31..c8ba460272a5 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work175 branch
+work175-dmf branch


[gcc(refs/users/meissner/heads/work175-dmf)] Merge commit 'refs/users/meissner/heads/work175-dmf' of git+ssh://gcc.gnu.org/git/gcc into me/work17

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:1fc1d66280c2cad9b66ada94e4c382480300749d

commit 1fc1d66280c2cad9b66ada94e4c382480300749d
Merge: 6d3cf2d1ca44 7533a789cc60
Author: Michael Meissner 
Date:   Fri Aug 2 18:26:45 2024 -0400

Merge commit 'refs/users/meissner/heads/work175-dmf' of 
git+ssh://gcc.gnu.org/git/gcc into me/work175-dmf

Diff:


[gcc/meissner/heads/work175-tar] (5 commits) Merge commit 'refs/users/meissner/heads/work175-tar' of git

2024-08-02 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work175-tar' was updated to point to:

 a154e40b3459... Merge commit 'refs/users/meissner/heads/work175-tar' of git

It previously pointed to:

 0597aad3398b... Merge commit 'refs/users/meissner/heads/work175-tar' of git

Diff:

Summary of changes (added commits):
---

  a154e40... Merge commit 'refs/users/meissner/heads/work175-tar' of git
  a074a0a... Add ChangeLog.tar and update REVISION.
  a833e57... Update ChangeLog.* (*)
  a22ff2f... Add -mcpu=future tuning support. (*)
  a489edd... Add support for -mcpu=future (*)

(*) This commit already exists in another branch.
Because the reference `refs/users/meissner/heads/work175-tar' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc(refs/users/meissner/heads/work175-tar)] Add ChangeLog.tar and update REVISION.

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:a074a0a985f46d49df0ae046d05ad92c2aa2f8a8

commit a074a0a985f46d49df0ae046d05ad92c2aa2f8a8
Author: Michael Meissner 
Date:   Thu Aug 1 15:50:27 2024 -0400

Add ChangeLog.tar and update REVISION.

2024-08-01  Michael Meissner  

gcc/

* ChangeLog.tar: New file for branch.
* REVISION: Update.

Diff:
---
 gcc/ChangeLog.tar | 6 ++
 gcc/REVISION  | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.tar b/gcc/ChangeLog.tar
new file mode 100644
index ..3a9f2525f736
--- /dev/null
+++ b/gcc/ChangeLog.tar
@@ -0,0 +1,6 @@
+ Branch work175-tar, baseline 
+
+2024-08-01   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/REVISION b/gcc/REVISION
index 1573af834b31..abb1260b1697 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work175 branch
+work175-tar branch


[gcc(refs/users/meissner/heads/work175-tar)] Merge commit 'refs/users/meissner/heads/work175-tar' of git+ssh://gcc.gnu.org/git/gcc into me/work17

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:a154e40b345906c26372827cd76bbac15f8a7146

commit a154e40b345906c26372827cd76bbac15f8a7146
Merge: a074a0a985f4 0597aad3398b
Author: Michael Meissner 
Date:   Fri Aug 2 18:28:06 2024 -0400

Merge commit 'refs/users/meissner/heads/work175-tar' of 
git+ssh://gcc.gnu.org/git/gcc into me/work175-tar

Diff:


[gcc/meissner/heads/work175-test] (5 commits) Merge commit 'refs/users/meissner/heads/work175-test' of gi

2024-08-02 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work175-test' was updated to point to:

 7338f4b69698... Merge commit 'refs/users/meissner/heads/work175-test' of gi

It previously pointed to:

 8ae428118cb5... Merge commit 'refs/users/meissner/heads/work175-test' of gi

Diff:

Summary of changes (added commits):
---

  7338f4b... Merge commit 'refs/users/meissner/heads/work175-test' of gi
  fdc608d... Add ChangeLog.test and update REVISION.
  a833e57... Update ChangeLog.* (*)
  a22ff2f... Add -mcpu=future tuning support. (*)
  a489edd... Add support for -mcpu=future (*)

(*) This commit already exists in another branch.
Because the reference `refs/users/meissner/heads/work175-test' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc(refs/users/meissner/heads/work175-test)] Add ChangeLog.test and update REVISION.

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:fdc608dff440fef0d04e60fe854ba007b0ca385f

commit fdc608dff440fef0d04e60fe854ba007b0ca385f
Author: Michael Meissner 
Date:   Thu Aug 1 15:52:09 2024 -0400

Add ChangeLog.test and update REVISION.

2024-08-01  Michael Meissner  

gcc/

* ChangeLog.test: New file for branch.
* REVISION: Update.

Diff:
---
 gcc/ChangeLog.test | 6 ++
 gcc/REVISION   | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.test b/gcc/ChangeLog.test
new file mode 100644
index ..a94f433cda2b
--- /dev/null
+++ b/gcc/ChangeLog.test
@@ -0,0 +1,6 @@
+ Branch work175-test, baseline 
+
+2024-08-01   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/REVISION b/gcc/REVISION
index 1573af834b31..ad7bacba19e3 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work175 branch
+work175-test branch


[gcc(refs/users/meissner/heads/work175-test)] Merge commit 'refs/users/meissner/heads/work175-test' of git+ssh://gcc.gnu.org/git/gcc into me/work1

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:7338f4b696982af9e9ed887788d401e8332425e2

commit 7338f4b696982af9e9ed887788d401e8332425e2
Merge: fdc608dff440 8ae428118cb5
Author: Michael Meissner 
Date:   Fri Aug 2 18:29:26 2024 -0400

Merge commit 'refs/users/meissner/heads/work175-test' of 
git+ssh://gcc.gnu.org/git/gcc into me/work175-test

Diff:


[gcc/meissner/heads/work175-vpair] (5 commits) Merge commit 'refs/users/meissner/heads/work175-vpair' of g

2024-08-02 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work175-vpair' was updated to point to:

 b8e6d6a6961d... Merge commit 'refs/users/meissner/heads/work175-vpair' of g

It previously pointed to:

 326ac993f2b3... Merge commit 'refs/users/meissner/heads/work175-vpair' of g

Diff:

Summary of changes (added commits):
---

  b8e6d6a... Merge commit 'refs/users/meissner/heads/work175-vpair' of g
  ebe9842... Add ChangeLog.vpair and update REVISION.
  a833e57... Update ChangeLog.* (*)
  a22ff2f... Add -mcpu=future tuning support. (*)
  a489edd... Add support for -mcpu=future (*)

(*) This commit already exists in another branch.
Because the reference `refs/users/meissner/heads/work175-vpair' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc(refs/users/meissner/heads/work175-vpair)] Add ChangeLog.vpair and update REVISION.

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:ebe9842dc533011f023ff44dbdcb695e036cbfe5

commit ebe9842dc533011f023ff44dbdcb695e036cbfe5
Author: Michael Meissner 
Date:   Thu Aug 1 15:49:33 2024 -0400

Add ChangeLog.vpair and update REVISION.

2024-08-01  Michael Meissner  

gcc/

* ChangeLog.vpair: New file for branch.
* REVISION: Update.

Diff:
---
 gcc/ChangeLog.vpair | 6 ++
 gcc/REVISION| 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.vpair b/gcc/ChangeLog.vpair
new file mode 100644
index ..8355bde3ebaa
--- /dev/null
+++ b/gcc/ChangeLog.vpair
@@ -0,0 +1,6 @@
+ Branch work175-vpair, baseline 
+
+2024-08-01   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/REVISION b/gcc/REVISION
index 1573af834b31..55efdc156d49 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work175 branch
+work175-vpair branch


[gcc(refs/users/meissner/heads/work175-vpair)] Merge commit 'refs/users/meissner/heads/work175-vpair' of git+ssh://gcc.gnu.org/git/gcc into me/work

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:b8e6d6a6961d5d195aaf270be64bf834f52cf02c

commit b8e6d6a6961d5d195aaf270be64bf834f52cf02c
Merge: ebe9842dc533 326ac993f2b3
Author: Michael Meissner 
Date:   Fri Aug 2 18:30:37 2024 -0400

Merge commit 'refs/users/meissner/heads/work175-vpair' of 
git+ssh://gcc.gnu.org/git/gcc into me/work175-vpair

Diff:


[gcc r15-2705] Fortran: Fix ICE on invalid in gfc_format_decoder.

2024-08-02 Thread Jerry DeLisle via Gcc-cvs
https://gcc.gnu.org/g:a53c029bf855fd4250076a07d0d8150b9c39bc91

commit r15-2705-ga53c029bf855fd4250076a07d0d8150b9c39bc91
Author: Steve Kargl 
Date:   Thu Aug 1 21:50:49 2024 -0700

Fortran: Fix ICE on invalid in gfc_format_decoder.

PR fortran/104626

gcc/fortran/ChangeLog:

* symbol.cc (gfc_add_save): Add checks for SAVE attribute
conflicts and duplicate SAVE attribute.

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/fortran/symbol.cc  | 16 ++--
 gcc/testsuite/gfortran.dg/pr104626.f90 |  8 
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc
index a8479b862e39..b5143d9f7907 100644
--- a/gcc/fortran/symbol.cc
+++ b/gcc/fortran/symbol.cc
@@ -1307,9 +1307,8 @@ gfc_add_save (symbol_attribute *attr, save_state s, const 
char *name,
 
   if (s == SAVE_EXPLICIT && gfc_pure (NULL))
 {
-  gfc_error
-   ("SAVE attribute at %L cannot be specified in a PURE procedure",
-where);
+  gfc_error ("SAVE attribute at %L cannot be specified in a PURE "
+"procedure", where);
   return false;
 }
 
@@ -1319,10 +1318,15 @@ gfc_add_save (symbol_attribute *attr, save_state s, 
const char *name,
   if (s == SAVE_EXPLICIT && attr->save == SAVE_EXPLICIT
   && (flag_automatic || pedantic))
 {
-   if (!gfc_notify_std (GFC_STD_LEGACY,
-"Duplicate SAVE attribute specified at %L",
-where))
+  if (!where)
+   {
+ gfc_error ("Duplicate SAVE attribute specified near %C");
  return false;
+   }
+
+  if (!gfc_notify_std (GFC_STD_LEGACY, "Duplicate SAVE attribute "
+  "specified at %L", where))
+   return false;
 }
 
   attr->save = s;
diff --git a/gcc/testsuite/gfortran.dg/pr104626.f90 
b/gcc/testsuite/gfortran.dg/pr104626.f90
new file mode 100644
index ..faff65a8c924
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr104626.f90
@@ -0,0 +1,8 @@
+! { dg-do compile }
+program p
+   procedure(g), save :: f ! { dg-error "PROCEDURE attribute conflicts" }
+   procedure(g), save :: f ! { dg-error "Duplicate SAVE attribute" }
+contains
+   subroutine g
+   end
+end


[gcc(refs/users/meissner/heads/work175)] Revert changes

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:71db6b9e2fdff223f757c52a602e833a652244e0

commit 71db6b9e2fdff223f757c52a602e833a652244e0
Author: Michael Meissner 
Date:   Fri Aug 2 20:47:42 2024 -0400

Revert changes

Diff:
---
 gcc/config/rs6000/power10.md| 144 ++--
 gcc/config/rs6000/rs6000-arch.def   |   1 -
 gcc/config/rs6000/rs6000-c.cc   |   2 -
 gcc/config/rs6000/rs6000-cpus.def   |   3 -
 gcc/config/rs6000/rs6000-opts.h |   1 -
 gcc/config/rs6000/rs6000-tables.opt |  11 +--
 gcc/config/rs6000/rs6000.cc |  34 ++---
 gcc/config/rs6000/rs6000.h  |   1 -
 gcc/config/rs6000/rs6000.md |   2 +-
 9 files changed, 85 insertions(+), 114 deletions(-)

diff --git a/gcc/config/rs6000/power10.md b/gcc/config/rs6000/power10.md
index e42b057dc45b..2310c4603457 100644
--- a/gcc/config/rs6000/power10.md
+++ b/gcc/config/rs6000/power10.md
@@ -1,4 +1,4 @@
-;; Scheduling description for the IBM Power10, Power11, and Future processors.
+;; Scheduling description for the IBM Power10 and Power11 processors.
 ;; Copyright (C) 2020-2024 Free Software Foundation, Inc.
 ;;
 ;; Contributed by Pat Haugen (pthau...@us.ibm.com).
@@ -97,12 +97,12 @@
(eq_attr "update" "no")
(eq_attr "size" "!128")
(eq_attr "prefixed" "no")
-   (eq_attr "cpu" "power10,power11,future"))
+   (eq_attr "cpu" "power10,power11"))
   "DU_any_power10,LU_power10")
 
 (define_insn_reservation "power10-fused-load" 4
   (and (eq_attr "type" "fused_load_cmpi,fused_addis_load,fused_load_load")
-   (eq_attr "cpu" "power10,power11,future"))
+   (eq_attr "cpu" "power10,power11"))
   "DU_even_power10,LU_power10")
 
 (define_insn_reservation "power10-prefixed-load" 4
@@ -110,13 +110,13 @@
(eq_attr "update" "no")
(eq_attr "size" "!128")
(eq_attr "prefixed" "yes")
-   (eq_attr "cpu" "power10,power11,future"))
+   (eq_attr "cpu" "power10,power11"))
   "DU_even_power10,LU_power10")
 
 (define_insn_reservation "power10-load-update" 4
   (and (eq_attr "type" "load")
(eq_attr "update" "yes")
-   (eq_attr "cpu" "power10,power11,future"))
+   (eq_attr "cpu" "power10,power11"))
   "DU_even_power10,LU_power10+SXU_power10")
 
 (define_insn_reservation "power10-fpload-double" 4
@@ -124,7 +124,7 @@
(eq_attr "update" "no")
(eq_attr "size" "64")
(eq_attr "prefixed" "no")
-   (eq_attr "cpu" "power10,power11,future"))
+   (eq_attr "cpu" "power10,power11"))
   "DU_any_power10,LU_power10")
 
 (define_insn_reservation "power10-prefixed-fpload-double" 4
@@ -132,14 +132,14 @@
(eq_attr "update" "no")
(eq_attr "size" "64")
(eq_attr "prefixed" "yes")
-   (eq_attr "cpu" "power10,power11,future"))
+   (eq_attr "cpu" "power10,power11"))
   "DU_even_power10,LU_power10")
 
 (define_insn_reservation "power10-fpload-update-double" 4
   (and (eq_attr "type" "fpload")
(eq_attr "update" "yes")
(eq_attr "size" "64")
-   (eq_attr "cpu" "power10,power11,future"))
+   (eq_attr "cpu" "power10,power11"))
   "DU_even_power10,LU_power10+SXU_power10")
 
 ; SFmode loads are cracked and have additional 3 cycles over DFmode
@@ -148,27 +148,27 @@
   (and (eq_attr "type" "fpload")
(eq_attr "update" "no")
(eq_attr "size" "32")
-   (eq_attr "cpu" "power10,power11,future"))
+   (eq_attr "cpu" "power10,power11"))
   "DU_even_power10,LU_power10")
 
 (define_insn_reservation "power10-fpload-update-single" 7
   (and (eq_attr "type" "fpload")
(eq_attr "update" "yes")
(eq_attr "size" "32")
-   (eq_attr "cpu" "power10,power11,future"))
+   (eq_attr "cpu" "power10,power11"))
   "DU_even_power10,LU_power10+SXU_power10")
 
 (define_insn_reservation "power10-vecload" 4
   (and (eq_attr "type" "vecload")
(eq_attr "size" "!256")
-   (eq_attr "cpu" "power10,power11,future"))
+   (eq_attr "cpu" "power10,power11"))
   "DU_any_power10,LU_power10")
 
 ; lxvp
 (define_insn_reservation "power10-vecload-pair" 4
   (and (eq_attr "type" "vecload")
(eq_attr "size" "256")
-   (eq_attr "cpu" "power10,power11,future"))
+   (eq_attr "cpu" "power10,power11"))
   "DU_even_power10,LU_power10+SXU_power10")
 
 ; Store Unit
@@ -178,12 +178,12 @@
(eq_attr "prefixed" "no")
(eq_attr "size" "!128")
(eq_attr "size" "!256")
-   (eq_attr "cpu" "power10,power11,future"))
+   (eq_attr "cpu" "power10,power11"))
   "DU_any_power10,STU_power10")
 
 (define_insn_reservation "power10-fused-store" 0
   (and (eq_attr "type" "fused_store_store")
-   (eq_attr "cpu" "power10,power11,future"))
+   (eq_attr "cpu" "power10,power11"))
   "DU_even_power10,STU_power10")
 
 (define_insn_reservation "power10-prefixed-store" 0
@@ -191,52 +191,52 @@
(eq_attr "prefixed" "yes")
(eq_attr "size" "!128")
(eq_attr "size" "!256")
-   (eq_attr "cpu" "power10,power11,future"))
+   (eq_attr "cpu" "power10,power11"))

[gcc(refs/users/meissner/heads/work175)] Add support for -mcpu=future

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:8553a0ef10272912c66e35df3fa3d95ebfd9d875

commit 8553a0ef10272912c66e35df3fa3d95ebfd9d875
Author: Michael Meissner 
Date:   Fri Aug 2 21:22:13 2024 -0400

Add support for -mcpu=future

This patch adds the support that can be used in developing GCC support for
future PowerPC processors.

2024-08-02  Michael Meissner  

* config.gcc (powerpc*-*-*): Add support for --with-cpu=future.
* config/rs6000/aix71.h (ASM_CPU_SPEC): Add support for 
-mcpu=future.
* config/rs6000/aix72.h (ASM_CPU_SPEC): Likewise.
* config/rs6000/aix73.h (ASM_CPU_SPEC): Likewise.
* config/rs6000/driver-rs6000.cc (asm_names): Likewise.
* config/rs6000/rs6000-arch.def: Add future cpu.
* config/rs6000/rs6000-c.cc (rs6000_target_modify_macros): If
-mcpu=future, define _ARCH_FUTURE.
* config/rs6000/rs6000-cpus.def (FUTURE_MASKS_SERVER): New macro.
(future cpu): Define.
* config/rs6000/rs6000-opts.h (enum processor_type): Add
PROCESSOR_FUTURE.
* config/rs6000/rs6000-tables.opt: Regenerate.
* config/rs6000/rs6000.cc (power10_cost): Update comment.
(get_arch_flags): Add support for future processor.
(rs6000_option_override_internal): Likewise.
(rs6000_machine_from_flags): Likewise.
(rs6000_reassociation_width): Likewise.
(rs6000_adjust_cost): Likewise.
(rs6000_issue_rate): Likewise.
(rs6000_sched_reorder): Likewise.
(rs6000_sched_reorder2): Likewise.
(rs6000_register_move_cost): Likewise.
* config/rs6000/rs6000.h (ASM_CPU_SPEC): Likewise.
(TARGET_POWER11): New macro.
* config/rs6000/rs6000.md (cpu attribute): Likewise.

Diff:
---
 gcc/config.gcc  |  4 ++--
 gcc/config/rs6000/aix71.h   |  1 +
 gcc/config/rs6000/aix72.h   |  1 +
 gcc/config/rs6000/aix73.h   |  1 +
 gcc/config/rs6000/driver-rs6000.cc  |  2 ++
 gcc/config/rs6000/rs6000-arch.def   |  1 +
 gcc/config/rs6000/rs6000-c.cc   |  2 ++
 gcc/config/rs6000/rs6000-cpus.def   |  3 +++
 gcc/config/rs6000/rs6000-opts.h |  1 +
 gcc/config/rs6000/rs6000-tables.opt | 11 +++
 gcc/config/rs6000/rs6000.cc | 34 ++
 gcc/config/rs6000/rs6000.h  |  2 ++
 gcc/config/rs6000/rs6000.md |  2 +-
 13 files changed, 50 insertions(+), 15 deletions(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index a36dd1bcbc66..412ff100d546 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -533,7 +533,7 @@ powerpc*-*-*)
extra_headers="${extra_headers} ppu_intrinsics.h spu2vmx.h vec_types.h 
si2vmx.h"
extra_headers="${extra_headers} amo.h"
case x$with_cpu in
-   
xpowerpc64|xdefault64|x6[23]0|x970|xG5|xpower[3456789]|xpower1[01]|xpower6x|xrs64a|xcell|xa2|xe500mc64|xe5500|xe6500)
+   
xpowerpc64|xdefault64|x6[23]0|x970|xG5|xpower[3456789]|xpower1[01]|xpower6x|xrs64a|xcell|xa2|xe500mc64|xe5500|xe6500|xfuture)
cpu_is_64bit=yes
;;
esac
@@ -5640,7 +5640,7 @@ case "${target}" in
tm_defines="${tm_defines} CONFIG_PPC405CR"
eval "with_$which=405"
;;
-   "" | common | native \
+   "" | common | native | future \
| power[3456789] | power1[01] | power5+ | power6x \
| powerpc | powerpc64 | powerpc64le \
| rs64 \
diff --git a/gcc/config/rs6000/aix71.h b/gcc/config/rs6000/aix71.h
index 41037b3852d7..570ddcc451db 100644
--- a/gcc/config/rs6000/aix71.h
+++ b/gcc/config/rs6000/aix71.h
@@ -79,6 +79,7 @@ do {  
\
 #undef ASM_CPU_SPEC
 #define ASM_CPU_SPEC \
 "%{mcpu=native: %(asm_cpu_native); \
+  mcpu=future: -mfuture; \
   mcpu=power11: -mpwr11; \
   mcpu=power10: -mpwr10; \
   mcpu=power9: -mpwr9; \
diff --git a/gcc/config/rs6000/aix72.h b/gcc/config/rs6000/aix72.h
index fe59f8319b48..242ca94bd065 100644
--- a/gcc/config/rs6000/aix72.h
+++ b/gcc/config/rs6000/aix72.h
@@ -79,6 +79,7 @@ do {  
\
 #undef ASM_CPU_SPEC
 #define ASM_CPU_SPEC \
 "%{mcpu=native: %(asm_cpu_native); \
+  mcpu=future: -mfuture; \
   mcpu=power11: -mpwr11; \
   mcpu=power10: -mpwr10; \
   mcpu=power9: -mpwr9; \
diff --git a/gcc/config/rs6000/aix73.h b/gcc/config/rs6000/aix73.h
index 1318b0b3662d..2bd6b4bb3c4f 100644
--- a/gcc/config/rs6000/aix73.h
+++ b/gcc/config/rs6000/aix73.h
@@ -79,6 +79,7 @@ do {  
\
 #undef ASM_CPU_SPEC
 #define ASM_CPU_SPEC \
 "%{mcpu=native: %(asm_cpu_native); \
+  mcpu=future: -mfuture; \
   mcpu=power11: -m

[gcc(refs/users/meissner/heads/work175)] Add -mcpu=future tuning support.

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:e198be0393e913bbca7123da02c013359d1fec9d

commit e198be0393e913bbca7123da02c013359d1fec9d
Author: Michael Meissner 
Date:   Fri Aug 2 21:23:42 2024 -0400

Add -mcpu=future tuning support.

This patch makes -mtune=future use the same tuning decision as 
-mtune=power11.

2024-08-02  Michael Meissner  

gcc/

* config/rs6000/power10.md (all reservations): Add future as an
alterntive to power10 and power11.

Diff:
---
 gcc/config/rs6000/power10.md | 144 +--
 1 file changed, 72 insertions(+), 72 deletions(-)

diff --git a/gcc/config/rs6000/power10.md b/gcc/config/rs6000/power10.md
index 2310c4603457..e42b057dc45b 100644
--- a/gcc/config/rs6000/power10.md
+++ b/gcc/config/rs6000/power10.md
@@ -1,4 +1,4 @@
-;; Scheduling description for the IBM Power10 and Power11 processors.
+;; Scheduling description for the IBM Power10, Power11, and Future processors.
 ;; Copyright (C) 2020-2024 Free Software Foundation, Inc.
 ;;
 ;; Contributed by Pat Haugen (pthau...@us.ibm.com).
@@ -97,12 +97,12 @@
(eq_attr "update" "no")
(eq_attr "size" "!128")
(eq_attr "prefixed" "no")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_any_power10,LU_power10")
 
 (define_insn_reservation "power10-fused-load" 4
   (and (eq_attr "type" "fused_load_cmpi,fused_addis_load,fused_load_load")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,LU_power10")
 
 (define_insn_reservation "power10-prefixed-load" 4
@@ -110,13 +110,13 @@
(eq_attr "update" "no")
(eq_attr "size" "!128")
(eq_attr "prefixed" "yes")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,LU_power10")
 
 (define_insn_reservation "power10-load-update" 4
   (and (eq_attr "type" "load")
(eq_attr "update" "yes")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,LU_power10+SXU_power10")
 
 (define_insn_reservation "power10-fpload-double" 4
@@ -124,7 +124,7 @@
(eq_attr "update" "no")
(eq_attr "size" "64")
(eq_attr "prefixed" "no")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_any_power10,LU_power10")
 
 (define_insn_reservation "power10-prefixed-fpload-double" 4
@@ -132,14 +132,14 @@
(eq_attr "update" "no")
(eq_attr "size" "64")
(eq_attr "prefixed" "yes")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,LU_power10")
 
 (define_insn_reservation "power10-fpload-update-double" 4
   (and (eq_attr "type" "fpload")
(eq_attr "update" "yes")
(eq_attr "size" "64")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,LU_power10+SXU_power10")
 
 ; SFmode loads are cracked and have additional 3 cycles over DFmode
@@ -148,27 +148,27 @@
   (and (eq_attr "type" "fpload")
(eq_attr "update" "no")
(eq_attr "size" "32")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,LU_power10")
 
 (define_insn_reservation "power10-fpload-update-single" 7
   (and (eq_attr "type" "fpload")
(eq_attr "update" "yes")
(eq_attr "size" "32")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,LU_power10+SXU_power10")
 
 (define_insn_reservation "power10-vecload" 4
   (and (eq_attr "type" "vecload")
(eq_attr "size" "!256")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_any_power10,LU_power10")
 
 ; lxvp
 (define_insn_reservation "power10-vecload-pair" 4
   (and (eq_attr "type" "vecload")
(eq_attr "size" "256")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,LU_power10+SXU_power10")
 
 ; Store Unit
@@ -178,12 +178,12 @@
(eq_attr "prefixed" "no")
(eq_attr "size" "!128")
(eq_attr "size" "!256")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_any_power10,STU_power10")
 
 (define_insn_reservation "power10-fused-store" 0
   (and (eq_attr "type" "fused_store_store")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,STU_power10")
 
 (define_insn_reservation "power10-prefixed-store" 0
@@ -191,52 +191,52 @@
(eq_attr "prefixed" "yes")
(eq_attr "size" "!128")
(eq_attr "size" "!256")
-   (eq_attr "cpu" "power10,power11"))
+   (eq_attr "cpu" "power10,power11,future"))
   "DU_even_power10,STU_power10")
 
 ; Update forms have 2 cycle latency for update

[gcc(refs/users/meissner/heads/work175)] Update ChangeLog.*

2024-08-02 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:6ef0fb14e8ff666dd25b44d0dc51618150264c98

commit 6ef0fb14e8ff666dd25b44d0dc51618150264c98
Author: Michael Meissner 
Date:   Fri Aug 2 21:25:12 2024 -0400

Update ChangeLog.*

Diff:
---
 gcc/ChangeLog.meissner | 59 --
 1 file changed, 23 insertions(+), 36 deletions(-)

diff --git a/gcc/ChangeLog.meissner b/gcc/ChangeLog.meissner
index ea351008f85c..6420fcaff5f7 100644
--- a/gcc/ChangeLog.meissner
+++ b/gcc/ChangeLog.meissner
@@ -1,54 +1,41 @@
- Branch work175, patch #11 
+ Branch work175, patch #21 
 
 Add -mcpu=future tuning support.
 
 This patch makes -mtune=future use the same tuning decision as -mtune=power11.
 
-2024-07-03  Michael Meissner  
+2024-08-02  Michael Meissner  
 
 gcc/
 
* config/rs6000/power10.md (all reservations): Add future as an
alterntive to power10 and power11.
 
- Branch work175, patch #10 
+ Branch work175, patch #20 
 
-Add -mcpu=future support.
+Add support for -mcpu=future
 
-This patch adds the future option to the -mcpu= and -mtune= switches.
+This patch adds the support that can be used in developing GCC support for
+future PowerPC processors.
 
-This patch treats the future like a power11 in terms of costs and reassociation
-width.
+2024-08-02  Michael Meissner  
 
-This patch issues a ".machine future" to the assembly file if you use
--mcpu=power11.
-
-This patch defines _ARCH_PWR_FUTURE if the user uses -mcpu=future.
-
-This patch allows GCC to be configured with the --with-cpu=future and
---with-tune=future options.
-
-This patch passes -mfuture to the assembler if the user uses -mcpu=future.
-
-2024-07-03  Michael Meissner  
-
-gcc/
-
-   * config.gcc (rs6000*-*-*, powerpc*-*-*): Add support for power11.
-   * config/rs6000/aix71.h (ASM_CPU_SPEC): Add support for -mcpu=power11.
+   * config.gcc (powerpc*-*-*): Add support for --with-cpu=future.
+   * config/rs6000/aix71.h (ASM_CPU_SPEC): Add support for -mcpu=future.
* config/rs6000/aix72.h (ASM_CPU_SPEC): Likewise.
* config/rs6000/aix73.h (ASM_CPU_SPEC): Likewise.
* config/rs6000/driver-rs6000.cc (asm_names): Likewise.
-   * config/rs6000/rs6000-c.cc (rs6000_target_modify_macros): Define
-   _ARCH_PWR_FUTURE if -mcpu=future.
-   * config/rs6000/rs6000-cpus.def (ISA_FUTURE_MASKS_SERVER): New define.
-   (POWERPC_MASKS): Add future isa bit.
-   (power11 cpu): Add future definition.
-   * config/rs6000/rs6000-opts.h (PROCESSOR_FUTURE): Add future processor.
-   * config/rs6000/rs6000-string.cc (expand_compare_loop): Likewise.
+   * config/rs6000/rs6000-arch.def: Add future cpu.
+   * config/rs6000/rs6000-c.cc (rs6000_target_modify_macros): If
+   -mcpu=future, define _ARCH_FUTURE.
+   * config/rs6000/rs6000-cpus.def (FUTURE_MASKS_SERVER): New macro.
+   (future cpu): Define.
+   * config/rs6000/rs6000-opts.h (enum processor_type): Add
+   PROCESSOR_FUTURE.
* config/rs6000/rs6000-tables.opt: Regenerate.
-   * config/rs6000/rs6000.cc (rs6000_option_override_internal): Add future
-   support.
+   * config/rs6000/rs6000.cc (power10_cost): Update comment.
+   (get_arch_flags): Add support for future processor.
+   (rs6000_option_override_internal): Likewise.
(rs6000_machine_from_flags): Likewise.
(rs6000_reassociation_width): Likewise.
(rs6000_adjust_cost): Likewise.
@@ -56,11 +43,11 @@ gcc/
(rs6000_sched_reorder): Likewise.
(rs6000_sched_reorder2): Likewise.
(rs6000_register_move_cost): Likewise.
-   (rs6000_opt_masks): Likewise.
* config/rs6000/rs6000.h (ASM_CPU_SPEC): Likewise.
-   * config/rs6000/rs6000.md (cpu attribute): Add future.
-   * config/rs6000/rs6000.opt (-mpower11): Add internal future ISA flag.
-   * doc/invoke.texi (RS/6000 and PowerPC Options): Document -mcpu=future.
+   (TARGET_POWER11): New macro.
+   * config/rs6000/rs6000.md (cpu attribute): Likewise.
+
+ Branch work175, patches #10-11 were revoked 

 
  Branch work175, patch #9