[gcc r15-718] ada: Add new Mingw task priority mapping

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:c32fd1a614bd3bfd219bb6fd72e9b7ebf4a0a9c2

commit r15-718-gc32fd1a614bd3bfd219bb6fd72e9b7ebf4a0a9c2
Author: Justin Squirek 
Date:   Mon Mar 11 15:15:34 2024 +

ada: Add new Mingw task priority mapping

This patch adds a new mapping (Non_FIFO_Underlying_Priorities) for 
dynamically
setting task priorities in Windows when pragma Task_Dispatching_Policy
(FIFO_Within_Priorities) is not present. Additionally, it documents the
requirement to specify the pragma in order to use Set_Priority in the 
general
case.

gcc/ada/

* doc/gnat_ugn/platform_specific_information.rst: Add note about
different priority level granularities under different policies in
Windows and move POSIX related info into new section.
* libgnarl/s-taprop.ads: Add note about Task_Dispatching_Policy.
* libgnarl/s-taprop__mingw.adb:
(Set_Priority): Add use of Non_FIFO_Underlying_Priorities.
* libgnat/system-mingw.ads: Add documentation for modifying
priority mappings and add alternative mapping
Non_FIFO_Underlying_Priorities.
* gnat_ugn.texi: Regenerate.

Diff:
---
 .../doc/gnat_ugn/platform_specific_information.rst | 117 ---
 gcc/ada/gnat_ugn.texi  | 359 +++--
 gcc/ada/libgnarl/s-taprop.ads  |   9 +
 gcc/ada/libgnarl/s-taprop__mingw.adb   |   5 +-
 gcc/ada/libgnat/system-mingw.ads   |  27 +-
 5 files changed, 289 insertions(+), 228 deletions(-)

diff --git a/gcc/ada/doc/gnat_ugn/platform_specific_information.rst 
b/gcc/ada/doc/gnat_ugn/platform_specific_information.rst
index 3744b742f8e..7eeb6c2c396 100644
--- a/gcc/ada/doc/gnat_ugn/platform_specific_information.rst
+++ b/gcc/ada/doc/gnat_ugn/platform_specific_information.rst
@@ -171,57 +171,6 @@ Selecting another run-time library temporarily can be
 achieved by using the :switch:`--RTS` switch, e.g., :switch:`--RTS=sjlj`
 
 
-.. _Choosing_the_Scheduling_Policy:
-
-.. index:: SCHED_FIFO scheduling policy
-.. index:: SCHED_RR scheduling policy
-.. index:: SCHED_OTHER scheduling policy
-
-Choosing the Scheduling Policy
---
-
-When using a POSIX threads implementation, you have a choice of several
-scheduling policies: ``SCHED_FIFO``, ``SCHED_RR`` and ``SCHED_OTHER``.
-
-Typically, the default is ``SCHED_OTHER``, while using ``SCHED_FIFO``
-or ``SCHED_RR`` requires special (e.g., root) privileges.
-
-.. index:: pragma Time_Slice
-.. index:: -T0 option
-.. index:: pragma Task_Dispatching_Policy
-
-
-By default, GNAT uses the ``SCHED_OTHER`` policy. To specify
-``SCHED_FIFO``,
-you can use one of the following:
-
-* ``pragma Time_Slice (0.0)``
-* the corresponding binder option :switch:`-T0`
-* ``pragma Task_Dispatching_Policy (FIFO_Within_Priorities)``
-
-
-To specify ``SCHED_RR``,
-you should use ``pragma Time_Slice`` with a
-value greater than 0.0, or else use the corresponding :switch:`-T`
-binder option.
-
-
-To make sure a program is running as root, you can put something like
-this in a library package body in your application:
-
-  .. code-block:: ada
-
- function geteuid return Integer;
- pragma Import (C, geteuid, "geteuid");
- Ignore : constant Boolean :=
-   (if geteuid = 0 then True else raise Program_Error with "must be root");
-
-It gets the effective user id, and if it's not 0 (i.e. root), it raises
-Program_Error. Note that if you re running the code in a container, this may
-not be sufficient, as you may have sufficient priviledge on the container,
-but not on the host machine running the container, so check that you also
-have sufficient priviledge for running the container image.
-
 .. index:: Linux
 .. index:: GNU/Linux
 
@@ -296,6 +245,55 @@ drop the :samp:`-no-pie` workaround, you'll need to get 
the identified
 dependencies rebuilt with PIE enabled (compiled with :samp:`-fPIE`
 and linked with :samp:`-pie`).
 
+.. _Choosing_the_Scheduling_Policy_With_GNU_Linux:
+
+.. index:: SCHED_FIFO scheduling policy
+.. index:: SCHED_RR scheduling policy
+.. index:: SCHED_OTHER scheduling policy
+
+Choosing the Scheduling Policy with GNU/Linux
+-
+
+When using a POSIX threads implementation, you have a choice of several
+scheduling policies: ``SCHED_FIFO``, ``SCHED_RR`` and ``SCHED_OTHER``.
+
+Typically, the default is ``SCHED_OTHER``, while using ``SCHED_FIFO``
+or ``SCHED_RR`` requires special (e.g., root) privileges.
+
+.. index:: pragma Time_Slice
+.. index:: -T0 option
+.. index:: pragma Task_Dispatching_Policy
+
+
+By default, GNAT uses the ``SCHED_OTHER`` policy. To specify
+``SCHED_FIFO``,
+you can use one of the following:
+
+* ``pragma Time_Slice (0.0)``
+* the corresponding binder option :switch:`-T0`
+* ``pragma Task_Dispatching_Policy (FIFO_Within_Priorities)``
+
+To specify ``SCHED_RR``,
+you should use ``pragma T

[gcc r15-719] ada: Follow-up fix to previous change for Text_Ptr

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:b22c01db9a8cbc4030af4353a7b4d01be2c6123f

commit r15-719-gb22c01db9a8cbc4030af4353a7b4d01be2c6123f
Author: Eric Botcazou 
Date:   Tue Apr 2 10:51:00 2024 +0200

ada: Follow-up fix to previous change for Text_Ptr

The variable would be saved and restored while still uninitialized.

gcc/ada/

* err_vars.ads (Error_Msg_Sloc): Initialize to No_Location.

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

diff --git a/gcc/ada/err_vars.ads b/gcc/ada/err_vars.ads
index 113dd936db6..838217b95f4 100644
--- a/gcc/ada/err_vars.ads
+++ b/gcc/ada/err_vars.ads
@@ -107,7 +107,7 @@ package Err_Vars is
 
--  WARNING: There is a matching C declaration of these variables in fe.h
 
-   Error_Msg_Sloc : Source_Ptr;
+   Error_Msg_Sloc : Source_Ptr := No_Location;
--  Source location for # insertion character in message
 
Error_Msg_Name_1 : Name_Id;


[gcc r15-720] ada: Remove trailing NUL in minimal expansion of Put_Image attribute

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:1bc1fa1160f186b1120bf354f3be3f9b0bf536fb

commit r15-720-g1bc1fa1160f186b1120bf354f3be3f9b0bf536fb
Author: Piotr Trojanek 
Date:   Fri Mar 22 19:02:00 2024 +0100

ada: Remove trailing NUL in minimal expansion of Put_Image attribute

When procedure that implements Put_Image attribute emits the type name,
this name was wrongly followed by a NUL character.

gcc/ada/

* exp_put_image.adb (Build_Record_Put_Image_Procedure): Remove
trailing NUL from the fully qualified type name.

Diff:
---
 gcc/ada/exp_put_image.adb | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/exp_put_image.adb b/gcc/ada/exp_put_image.adb
index c23b4e24354..f5141a56626 100644
--- a/gcc/ada/exp_put_image.adb
+++ b/gcc/ada/exp_put_image.adb
@@ -832,7 +832,9 @@ package body Exp_Put_Image is
 Parameter_Associations => New_List
   (Make_Identifier (Loc, Name_S),
Make_String_Literal (Loc,
- To_String (Fully_Qualified_Name_String (Btyp));
+ To_String
+   (Fully_Qualified_Name_String
+  (Btyp, Append_NUL => False));
  end if;
   elsif Is_Null_Record_Type (Btyp, Ignore_Privacy => True) then


[gcc r15-721] ada: Remove conversion from String_Id to String and back to String_Id

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:5035d5e33bce179c19c32d9f4aa2c47a5a29d8df

commit r15-721-g5035d5e33bce179c19c32d9f4aa2c47a5a29d8df
Author: Piotr Trojanek 
Date:   Fri Mar 22 19:06:48 2024 +0100

ada: Remove conversion from String_Id to String and back to String_Id

Code cleanup; semantics is unaffected.

gcc/ada/

* exp_put_image.adb (Build_Record_Put_Image_Procedure): Remove
useless conversions.

Diff:
---
 gcc/ada/exp_put_image.adb | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/exp_put_image.adb b/gcc/ada/exp_put_image.adb
index f5141a56626..09fbfa75eeb 100644
--- a/gcc/ada/exp_put_image.adb
+++ b/gcc/ada/exp_put_image.adb
@@ -44,7 +44,6 @@ with Sinfo.Nodes;use Sinfo.Nodes;
 with Sinfo.Utils;use Sinfo.Utils;
 with Snames; use Snames;
 with Stand;
-with Stringt;use Stringt;
 with Tbuild; use Tbuild;
 with Ttypes; use Ttypes;
 with Uintp;  use Uintp;
@@ -832,9 +831,8 @@ package body Exp_Put_Image is
 Parameter_Associations => New_List
   (Make_Identifier (Loc, Name_S),
Make_String_Literal (Loc,
- To_String
-   (Fully_Qualified_Name_String
-  (Btyp, Append_NUL => False));
+ Fully_Qualified_Name_String
+   (Btyp, Append_NUL => False);
  end if;
   elsif Is_Null_Record_Type (Btyp, Ignore_Privacy => True) then


[gcc r15-722] ada: Do not leak tagged type names when Discard_Names is enabled

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:a311db8758b573494211735412f0228f4efe120d

commit r15-722-ga311db8758b573494211735412f0228f4efe120d
Author: Piotr Trojanek 
Date:   Fri Mar 22 23:11:10 2024 +0100

ada: Do not leak tagged type names when Discard_Names is enabled

When both pragmas Discard_Names and No_Tagged_Streams apply to a tagged
type, the intended behavior is to prevent type names from leaking into
object code, as documented in GNAT RM.

However, while Discard_Names can be used as a configuration pragma,
No_Tagged_Streams must be applied to each type separately. This patch
enables the use of restriction No_Streams, which can be activated
globally, instead of No_Tagged_Streams on individual types.

When no tagged stream object can be created and allocated, then routines
that make use of the External_Tag won't be used.

gcc/ada/

* doc/gnat_rm/implementation_defined_pragmas.rst
(No_Tagged_Streams): Document how to avoid exposing entity names
for the entire partition.
* exp_disp.adb (Make_DT): Make use of restriction No_Streams.
* exp_put_image.adb (Build_Record_Put_Image_Procedure): Respect
Discard_Names in the generated Put_Image procedure.
* gnat_rm.texi: Regenerate.

Diff:
---
 .../doc/gnat_rm/implementation_defined_pragmas.rst |  6 
 gcc/ada/exp_disp.adb   |  5 ++--
 gcc/ada/exp_put_image.adb  | 34 +-
 gcc/ada/gnat_rm.texi   |  6 
 4 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst 
b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
index 0661670e047..7e4dd935342 100644
--- a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
+++ b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
@@ -4000,6 +4000,12 @@ applied to a tagged type its Expanded_Name and 
External_Tag are initialized
 with empty strings. This is useful to avoid exposing entity names at binary
 level but has a negative impact on the debuggability of tagged types.
 
+Alternatively, when pragmas ``Discard_Names`` and ``Restrictions (No_Streams)``
+simultanously apply to a tagged type, its Expanded_Name and External_Tag are
+also initialized with empty strings. In particular, both these pragmas can be
+applied as configuration pragmas to avoid exposing entity names at binary
+level for the entire parition.
+
 Pragma Normalize_Scalars
 
 
diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb
index 601d463a8b0..66be77c9ffc 100644
--- a/gcc/ada/exp_disp.adb
+++ b/gcc/ada/exp_disp.adb
@@ -4600,8 +4600,9 @@ package body Exp_Disp is
   --streams.
 
   Discard_Names : constant Boolean :=
-Present (No_Tagged_Streams_Pragma (Typ))
-  and then
+(Present (No_Tagged_Streams_Pragma (Typ))
+   or else Restriction_Active (No_Streams))
+  and then
 (Global_Discard_Names or else Einfo.Entities.Discard_Names (Typ));
 
   --  The following name entries are used by Make_DT to generate a number
diff --git a/gcc/ada/exp_put_image.adb b/gcc/ada/exp_put_image.adb
index 09fbfa75eeb..94299e39661 100644
--- a/gcc/ada/exp_put_image.adb
+++ b/gcc/ada/exp_put_image.adb
@@ -44,6 +44,7 @@ with Sinfo.Nodes;use Sinfo.Nodes;
 with Sinfo.Utils;use Sinfo.Utils;
 with Snames; use Snames;
 with Stand;
+with Stringt;use Stringt;
 with Tbuild; use Tbuild;
 with Ttypes; use Ttypes;
 with Uintp;  use Uintp;
@@ -825,14 +826,31 @@ package body Exp_Put_Image is
   Make_Raise_Program_Error (Loc,
   Reason => PE_Explicit_Raise));
  else
-Append_To (Stms,
-  Make_Procedure_Call_Statement (Loc,
-Name => New_Occurrence_Of (RTE (RE_Put_Image_Unknown), Loc),
-Parameter_Associations => New_List
-  (Make_Identifier (Loc, Name_S),
-   Make_String_Literal (Loc,
- Fully_Qualified_Name_String
-   (Btyp, Append_NUL => False);
+declare
+   Type_Name : String_Id;
+begin
+   --  If aspect Discard_Names is enabled the intention is to
+   --  prevent type names from leaking into object file. Instead,
+   --  we emit string that is different from the ones from the
+   --  default implementations of the Put_Image attribute.
+
+   if Global_Discard_Names or else Discard_Names (Typ) then
+  Start_String;
+  Store_String_Chars ("(DISCARDED TYPE NAME)");
+  Type_Name := End_String;
+   else
+  Type_Name :=
+Fully_Qualified_Name_String (Btyp, Append_NUL => False);
+ 

[gcc r15-723] ada: Update documentation of warning messages

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:01cb6e1338be45a8dd08dd8eb260477b7e8120a6

commit r15-723-g01cb6e1338be45a8dd08dd8eb260477b7e8120a6
Author: Viljar Indus 
Date:   Tue Apr 2 13:48:55 2024 +0300

ada: Update documentation of warning messages

Update the documentation of warning messages that only
emit info messages to clearly reflect that they only emit
info messages and not warning messages.

gcc/ada/

* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
Update the documentation of -gnatw.n and -gnatw.l
* gnat_ugn.texi: Regenerate.

Diff:
---
 .../gnat_ugn/building_executable_programs_with_gnat.rst  | 14 +++---
 gcc/ada/gnat_ugn.texi| 16 
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst 
b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
index 21e277d5916..2f63d02daf7 100644
--- a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
+++ b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
@@ -3415,7 +3415,7 @@ of the pragma in the :title:`GNAT_Reference_manual`).
 .. index:: -gnatw.l  (gcc)
 
 :switch:`-gnatw.l`
-  *List inherited aspects.*
+  *List inherited aspects as info messages.*
 
   This switch causes the compiler to list inherited invariants,
   preconditions, and postconditions from Type_Invariant'Class, Invariant'Class,
@@ -3425,7 +3425,7 @@ of the pragma in the :title:`GNAT_Reference_manual`).
 .. index:: -gnatw.L  (gcc)
 
 :switch:`-gnatw.L`
-  *Suppress listing of inherited aspects.*
+  *Suppress listing of inherited aspects as info messages.*
 
   This switch suppresses listing of inherited aspects.
 
@@ -3495,20 +3495,20 @@ of the pragma in the :title:`GNAT_Reference_manual`).
 .. index:: Atomic Synchronization, warnings
 
 :switch:`-gnatw.n`
-  *Activate warnings on atomic synchronization.*
+  *Activate info messages on atomic synchronization.*
 
-  This switch actives warnings when an access to an atomic variable
+  This switch activates info messages when an access to an atomic variable
   requires the generation of atomic synchronization code. These
-  warnings are off by default.
+  info messages are off by default.
 
 .. index:: -gnatw.N  (gcc)
 
 :switch:`-gnatw.N`
-  *Suppress warnings on atomic synchronization.*
+  *Suppress info messages on atomic synchronization.*
 
   .. index:: Atomic Synchronization, warnings
 
-  This switch suppresses warnings when an access to an atomic variable
+  This switch suppresses info messages when an access to an atomic variable
   requires the generation of atomic synchronization code.
 
 
diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi
index 43251ba3f1c..2df2a780ec7 100644
--- a/gcc/ada/gnat_ugn.texi
+++ b/gcc/ada/gnat_ugn.texi
@@ -11646,7 +11646,7 @@ This switch suppresses warnings for possible 
elaboration problems.
 
 @item @code{-gnatw.l}
 
-`List inherited aspects.'
+`List inherited aspects as info messages.'
 
 This switch causes the compiler to list inherited invariants,
 preconditions, and postconditions from Type_Invariant’Class, Invariant’Class,
@@ -11660,7 +11660,7 @@ Pre’Class, and Post’Class aspects. Also list inherited 
subtype predicates.
 
 @item @code{-gnatw.L}
 
-`Suppress listing of inherited aspects.'
+`Suppress listing of inherited aspects as info messages.'
 
 This switch suppresses listing of inherited aspects.
 @end table
@@ -11755,11 +11755,11 @@ use of @code{-gnatg}.
 
 @item @code{-gnatw.n}
 
-`Activate warnings on atomic synchronization.'
+`Activate info messages on atomic synchronization.'
 
-This switch actives warnings when an access to an atomic variable
+This switch activates info messages when an access to an atomic variable
 requires the generation of atomic synchronization code. These
-warnings are off by default.
+info messages are off by default.
 @end table
 
 @geindex -gnatw.N (gcc)
@@ -11769,12 +11769,12 @@ warnings are off by default.
 
 @item @code{-gnatw.N}
 
-`Suppress warnings on atomic synchronization.'
+`Suppress info messages on atomic synchronization.'
 
 @geindex Atomic Synchronization
 @geindex warnings
 
-This switch suppresses warnings when an access to an atomic variable
+This switch suppresses info messages when an access to an atomic variable
 requires the generation of atomic synchronization code.
 @end table
 
@@ -29645,8 +29645,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-724] ada: Fix index entry for an implemented AI feature

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:b0a97d4e223b9ab22f35b7a6008257596f78418b

commit r15-724-gb0a97d4e223b9ab22f35b7a6008257596f78418b
Author: Piotr Trojanek 
Date:   Mon Mar 18 17:29:07 2024 +0100

ada: Fix index entry for an implemented AI feature

Fix inconsistent reference with "05" in the name of AI.

gcc/ada/

* doc/gnat_rm/implementation_of_ada_2012_features.rst
(AI-0216): Fix index reference.
* gnat_rm.texi: Regenerate.

Diff:
---
 gcc/ada/doc/gnat_rm/implementation_of_ada_2012_features.rst | 2 +-
 gcc/ada/gnat_rm.texi| 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/doc/gnat_rm/implementation_of_ada_2012_features.rst 
b/gcc/ada/doc/gnat_rm/implementation_of_ada_2012_features.rst
index 2825362c616..d7f1fea01f3 100644
--- a/gcc/ada/doc/gnat_rm/implementation_of_ada_2012_features.rst
+++ b/gcc/ada/doc/gnat_rm/implementation_of_ada_2012_features.rst
@@ -1243,7 +1243,7 @@ Supported Aspect Source
 
   RM References:  B.01 (17)   B.03 (62)   B.03 (71.1/2)
 
-.. index:: AI05-0216 (Ada 2012 feature)
+.. index:: AI-0216 (Ada 2012 feature)
 
 * *AI-0216 No_Task_Hierarchy forbids local tasks (-00-00)*
 
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index 4ff1de42db2..0d38b1a4bc6 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -28603,7 +28603,7 @@ non-portable.
 RM References:  B.01 (17)   B.03 (62)   B.03 (71.1/2)
 @end itemize
 
-@geindex AI05-0216 (Ada 2012 feature)
+@geindex AI-0216 (Ada 2012 feature)
 
 
 @itemize *


[gcc r15-726] ada: Fix formatting in list of implemented Ada 2012 features

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:238fba24a43280e692fc9c53852657837bbc94bc

commit r15-726-g238fba24a43280e692fc9c53852657837bbc94bc
Author: Piotr Trojanek 
Date:   Mon Mar 18 22:43:54 2024 +0100

ada: Fix formatting in list of implemented Ada 2012 features

Fix formatting; meaning is unaffected.

gcc/ada/

* doc/gnat_rm/implementation_of_ada_2012_features.rst:
Fix formatting.
* gnat_rm.texi: Regenerate.

Diff:
---
 gcc/ada/doc/gnat_rm/implementation_of_ada_2012_features.rst | 6 +++---
 gcc/ada/gnat_rm.texi| 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/doc/gnat_rm/implementation_of_ada_2012_features.rst 
b/gcc/ada/doc/gnat_rm/implementation_of_ada_2012_features.rst
index 706de492301..9708e15de8d 100644
--- a/gcc/ada/doc/gnat_rm/implementation_of_ada_2012_features.rst
+++ b/gcc/ada/doc/gnat_rm/implementation_of_ada_2012_features.rst
@@ -255,7 +255,7 @@ http://www.ada-auth.org/ai05-summary.html.
 
 * *AI-0039 Stream attributes cannot be dynamic (-00-00)*
 
-  The RM permitted the use of dynamic expressions (such as ``ptr.all``)`
+  The RM permitted the use of dynamic expressions (such as ``ptr.all``)
   for stream attributes, but these were never useful and are now illegal. GNAT
   has always regarded such expressions as illegal.
 
@@ -555,7 +555,7 @@ http://www.ada-auth.org/ai05-summary.html.
   This AI clarifies that 'needs finalization' is part of dynamic semantics,
   and therefore depends on the run-time characteristics of an object (i.e. its
   tag) and not on its nominal type. As the AI indicates: "we do not expect
-  this to affect any implementation''.
+  this to affect any implementation".
 
   RM References:  7.06.01 (6)   7.06.01 (7)   7.06.01 (8)   7.06.01 (9/2)
 
@@ -812,7 +812,7 @@ http://www.ada-auth.org/ai05-summary.html.
 
   The new syntax for iterating over arrays and containers is now implemented.
   Iteration over containers is for now limited to read-only iterators. Only
-  default iterators are supported, with the syntax:  ``for Elem of C``.
+  default iterators are supported, with the syntax: ``for Elem of C``.
 
   RM References:  5.05
 
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index df6969f98b7..776dd4a4afc 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -26913,7 +26913,7 @@ RM References:  A.10.05 (37)   A.10.07 (8/1)   A.10.07 
(10)   A.10.07 (12)   A.1
 @item 
 `AI-0039 Stream attributes cannot be dynamic (-00-00)'
 
-The RM permitted the use of dynamic expressions (such as @code{ptr.all})`
+The RM permitted the use of dynamic expressions (such as @code{ptr.all})
 for stream attributes, but these were never useful and are now illegal. GNAT
 has always regarded such expressions as illegal.
 
@@ -27358,7 +27358,7 @@ RM References:  3.10.01 (6)   3.10.01 (9.2/2)
 This AI clarifies that ‘needs finalization’ is part of dynamic semantics,
 and therefore depends on the run-time characteristics of an object (i.e. its
 tag) and not on its nominal type. As the AI indicates: “we do not expect
-this to affect any implementation’’.
+this to affect any implementation”.
 
 RM References:  7.06.01 (6)   7.06.01 (7)   7.06.01 (8)   7.06.01 (9/2)
 @end itemize
@@ -27730,7 +27730,7 @@ RM References:  A.04.11
 
 The new syntax for iterating over arrays and containers is now implemented.
 Iteration over containers is for now limited to read-only iterators. Only
-default iterators are supported, with the syntax:  @code{for Elem of C}.
+default iterators are supported, with the syntax: @code{for Elem of C}.
 
 RM References:  5.05
 @end itemize


[gcc r15-728] ada: Simplify management of scopes while inlining

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:8af95ac6c3b1ca737fdb140e54bfaf5814b0afdb

commit r15-728-g8af95ac6c3b1ca737fdb140e54bfaf5814b0afdb
Author: Piotr Trojanek 
Date:   Wed Apr 3 13:43:07 2024 +0200

ada: Simplify management of scopes while inlining

Code cleanup; semantics is unaffected.

gcc/ada/

* inline.adb (Add_Scope_To_Clean): Use Append_Unique_Elmt.
(Analyze_Inlined_Bodies): Refine type of a local counter;
remove extra whitespace.

Diff:
---
 gcc/ada/inline.adb | 19 ---
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb
index a628a59e145..17b3099e6a6 100644
--- a/gcc/ada/inline.adb
+++ b/gcc/ada/inline.adb
@@ -845,19 +845,8 @@ package body Inline is

 
procedure Add_Scope_To_Clean (Scop : Entity_Id) is
-  Elmt : Elmt_Id;
-
begin
-  Elmt := First_Elmt (To_Clean);
-  while Present (Elmt) loop
- if Node (Elmt) = Scop then
-return;
- end if;
-
- Next_Elmt (Elmt);
-  end loop;
-
-  Append_Elmt (Scop, To_Clean);
+  Append_Unique_Elmt (Scop, To_Clean);
end Add_Scope_To_Clean;
 
--
@@ -915,7 +904,7 @@ package body Inline is
 
procedure Analyze_Inlined_Bodies is
   Comp_Unit : Node_Id;
-  J : Int;
+  J : Nat;
   Pack  : Entity_Id;
   Subp  : Subp_Index;
   S : Succ_Index;
@@ -2569,8 +2558,8 @@ package body Inline is
(Proc_Id   : out Entity_Id;
 Decl_List : out List_Id)
  is
-Formals   : constant List_Id   := New_List;
-Subp_Name : constant Name_Id   := New_Internal_Name ('F');
+Formals   : constant List_Id := New_List;
+Subp_Name : constant Name_Id := New_Internal_Name ('F');
 
 Body_Decls : List_Id := No_List;
 Decl   : Node_Id;


[gcc r15-730] ada: Remove useless trampolines caused by Unchecked_Conversion

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:933d27af7748c38f1213edceaa6a2edf46f82cc2

commit r15-730-g933d27af7748c38f1213edceaa6a2edf46f82cc2
Author: Eric Botcazou 
Date:   Thu Apr 4 18:15:24 2024 +0200

ada: Remove useless trampolines caused by Unchecked_Conversion

The partial solution implemented in Validate_Unchecked_Conversion to support
unchecked conversions between addresses and pointers to subprograms, for the
platforms where pointers to subprograms do not all have the same size, turns
out to be counter-productive for others because it may cause the creation of
useless trampolines, which in turn makes the stack executable.

gcc/ada/

* sem_ch13.adb (Validate_Unchecked_Conversion): Restrict forcing the
Can_Use_Internal_Rep flag to platforms that require unnesting.

Diff:
---
 gcc/ada/sem_ch13.adb | 29 -
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 59c80022c20..4cf6fc9a645 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -18132,20 +18132,23 @@ package body Sem_Ch13 is
  Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
   end if;
 
-  --  If the unchecked conversion is between Address and an access
-  --  subprogram type, show that we shouldn't use an internal
-  --  representation for the access subprogram type.
+  --  For code generators that do not support nested subprograms, if the
+  --  unchecked conversion is between Address and an access subprogram
+  --  type, show that we shouldn't use an internal representation for the
+  --  access subprogram type.
 
-  if Is_Access_Subprogram_Type (Target)
-and then Is_Descendant_Of_Address (Source)
-and then In_Same_Source_Unit (Target, N)
-  then
- Set_Can_Use_Internal_Rep (Base_Type (Target), False);
-  elsif Is_Access_Subprogram_Type (Source)
-and then Is_Descendant_Of_Address (Target)
-and then In_Same_Source_Unit (Source, N)
-  then
- Set_Can_Use_Internal_Rep (Base_Type (Source), False);
+  if Unnest_Subprogram_Mode then
+ if Is_Access_Subprogram_Type (Target)
+   and then Is_Descendant_Of_Address (Source)
+   and then In_Same_Source_Unit (Target, N)
+ then
+Set_Can_Use_Internal_Rep (Base_Type (Target), False);
+ elsif Is_Access_Subprogram_Type (Source)
+   and then Is_Descendant_Of_Address (Target)
+   and then In_Same_Source_Unit (Source, N)
+ then
+Set_Can_Use_Internal_Rep (Base_Type (Source), False);
+ end if;
   end if;
 
   --  Generate N_Validate_Unchecked_Conversion node for back end in case


[gcc r15-731] ada: Remove duplicate statement

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:417b6bd4783665cb3dae1569ece57e4a033cafef

commit r15-731-g417b6bd4783665cb3dae1569ece57e4a033cafef
Author: Ronan Desplanques 
Date:   Tue Apr 2 18:27:39 2024 +0200

ada: Remove duplicate statement

This patch removes a duplicate statement that was useless and could
be misleading to the reader by suggesting that there are multiple
global variables named Style_Check, while there is just one.

gcc/ada/

* frontend.adb (Frontend): Remove duplicate statement.

Diff:
---
 gcc/ada/frontend.adb | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/ada/frontend.adb b/gcc/ada/frontend.adb
index bd0f0c44ff4..ece0e728e4a 100644
--- a/gcc/ada/frontend.adb
+++ b/gcc/ada/frontend.adb
@@ -158,7 +158,6 @@ begin
   --  intended -gnatg or -gnaty compilations. We also disconnect checking
   --  for maximum line length.
 
-  Opt.Style_Check := False;
   Style_Check := False;
 
   --  Capture current suppress options, which may get modified


[gcc r15-727] ada: Remove some explicit yields in tasking run-time

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:0cb4e7f41b6466718715ea71fce6621c9e93ecfd

commit r15-727-g0cb4e7f41b6466718715ea71fce6621c9e93ecfd
Author: Ronan Desplanques 
Date:   Tue Apr 2 09:09:31 2024 +0200

ada: Remove some explicit yields in tasking run-time

This patch removes three occurrences where tasking run-time
subprograms yielded control shortly before conditional calls to Sleep,
in order to avoid these calls more often. It was intended as an
optimization on systems where calls to Sleep are costly and in
particular VMS.

A problem was that two of the yields contained data races that were
reported by thread sanitizing tools on some platforms, and that's the
motivation for removing them.

gcc/ada/

* libgnarl/s-taenca.adb (Wait_For_Completion): Remove call to
Yield.
* libgnarl/s-tasren.adb (Timed_Selective_Wait, Wait_For_Call):
Remove calls to Yield.

Diff:
---
 gcc/ada/libgnarl/s-taenca.adb | 12 
 gcc/ada/libgnarl/s-tasren.adb | 24 
 2 files changed, 36 deletions(-)

diff --git a/gcc/ada/libgnarl/s-taenca.adb b/gcc/ada/libgnarl/s-taenca.adb
index cd9c53b19fe..1dc8ec518bd 100644
--- a/gcc/ada/libgnarl/s-taenca.adb
+++ b/gcc/ada/libgnarl/s-taenca.adb
@@ -410,18 +410,6 @@ package body System.Tasking.Entry_Calls is
 
   Self_Id.Common.State := Entry_Caller_Sleep;
 
-  --  Try to remove calls to Sleep in the loop below by letting the caller
-  --  a chance of getting ready immediately, using Unlock & Yield.
-  --  See similar action in Wait_For_Call & Timed_Selective_Wait.
-
-  STPO.Unlock (Self_Id);
-
-  if Entry_Call.State < Done then
- STPO.Yield;
-  end if;
-
-  STPO.Write_Lock (Self_Id);
-
   loop
  Check_Pending_Actions_For_Entry_Call (Self_Id, Entry_Call);
 
diff --git a/gcc/ada/libgnarl/s-tasren.adb b/gcc/ada/libgnarl/s-tasren.adb
index d65b9f011b0..6face7ef8d4 100644
--- a/gcc/ada/libgnarl/s-tasren.adb
+++ b/gcc/ada/libgnarl/s-tasren.adb
@@ -1317,18 +1317,6 @@ package body System.Tasking.Rendezvous is
 
 Self_Id.Common.State := Acceptor_Delay_Sleep;
 
---  Try to remove calls to Sleep in the loop below by letting the
---  caller a chance of getting ready immediately, using Unlock
---  Yield. See similar action in Wait_For_Completion/Wait_For_Call.
-
-Unlock (Self_Id);
-
-if Self_Id.Open_Accepts /= null then
-   Yield;
-end if;
-
-Write_Lock (Self_Id);
-
 --  Check if this task has been aborted while the lock was released
 
 if Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level then
@@ -1510,18 +1498,6 @@ package body System.Tasking.Rendezvous is
begin
   Self_Id.Common.State := Acceptor_Sleep;
 
-  --  Try to remove calls to Sleep in the loop below by letting the caller
-  --  a chance of getting ready immediately, using Unlock & Yield.
-  --  See similar action in Wait_For_Completion & Timed_Selective_Wait.
-
-  Unlock (Self_Id);
-
-  if Self_Id.Open_Accepts /= null then
- Yield;
-  end if;
-
-  Write_Lock (Self_Id);
-
   --  Check if this task has been aborted while the lock was released
 
   if Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level then


[gcc r15-729] ada: Add elaboration switch tags to info messages

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:21484502b0d773ae485be9c9b814b30f2b52fb2f

commit r15-729-g21484502b0d773ae485be9c9b814b30f2b52fb2f
Author: Viljar Indus 
Date:   Tue Apr 2 14:32:04 2024 +0300

ada: Add elaboration switch tags to info messages

Add the ?$? insertion characters for elaboration
message so they would be marked with the [-gnatel]
tag. Note that these insertion characters were
not added for SPARK elaboration messages:

gcc/ada/

* sem_elab.adb: Add missing elaboration insertion
characters to info messages.

Diff:
---
 gcc/ada/sem_elab.adb | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/sem_elab.adb b/gcc/ada/sem_elab.adb
index 9205f4cef82..4d6e14cc49c 100644
--- a/gcc/ada/sem_elab.adb
+++ b/gcc/ada/sem_elab.adb
@@ -4920,7 +4920,7 @@ package body Sem_Elab is
and then not New_In_State.Suppress_Info_Messages
  then
 Error_Msg_NE
-  ("info: access to & during elaboration", Attr, Subp_Id);
+  ("info: access to & during elaboration?$?", Attr, Subp_Id);
  end if;
 
  --  Warnings are suppressed when a prior scenario is already in that
@@ -5027,7 +5027,7 @@ package body Sem_Elab is
and then not New_In_State.Suppress_Info_Messages
  then
 Error_Msg_NE
-  ("info: activation of & during elaboration", Call, Obj_Id);
+  ("info: activation of & during elaboration?$?", Call, Obj_Id);
  end if;
 
  --  Nothing to do when the call activates a task whose type is defined
@@ -6461,7 +6461,7 @@ package body Sem_Elab is
 if In_SPARK then
return " in SPARK";
 else
-   return "";
+   return "?$?";
 end if;
  end Suffix;
 
@@ -8277,7 +8277,9 @@ package body Sem_Elab is
Error_Msg_Name_1 := Prag_Nam;
Error_Msg_Qual_Level := Nat'Last;
 
-   Error_Msg_NE ("info: missing pragma % for unit &", N, Unit_Id);
+   Error_Msg_NE
+ ("info: missing pragma % for unit &?$?", N,
+  Unit_Id);
Error_Msg_Qual_Level := 0;
 end if;
  end Info_Missing_Pragma;
@@ -8406,7 +8408,8 @@ package body Sem_Elab is
Error_Msg_Qual_Level := Nat'Last;
 
Error_Msg_NE
- ("info: implicit pragma % generated for unit &", N, Unit_Id);
+ ("info: implicit pragma % generated for unit &?$?",
+   N, Unit_Id);
 
Error_Msg_Qual_Level := 0;
Output_Active_Scenarios (N, In_State);


[gcc r15-732] ada: Fix layout in a list of aspects

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:8cadfeb5f6d7d15cb3d008b11105a2e67b46dbe9

commit r15-732-g8cadfeb5f6d7d15cb3d008b11105a2e67b46dbe9
Author: Piotr Trojanek 
Date:   Wed Apr 3 13:36:35 2024 +0200

ada: Fix layout in a list of aspects

Code cleanup; semantics is unaffected.

gcc/ada/

* aspects.ads (Nonoverridable_Aspect_Id): Fix layout.

Diff:
---
 gcc/ada/aspects.ads | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/gcc/ada/aspects.ads b/gcc/ada/aspects.ads
index ce393d4f602..3cc62de3411 100644
--- a/gcc/ada/aspects.ads
+++ b/gcc/ada/aspects.ads
@@ -237,14 +237,17 @@ package Aspects is
--  Aspect_Id's excluding No_Aspect
 
subtype Nonoverridable_Aspect_Id is Aspect_Id with
- Static_Predicate => Nonoverridable_Aspect_Id in
-   Aspect_Default_Iterator | Aspect_Iterator_Element |
-   Aspect_Implicit_Dereference | Aspect_Constant_Indexing |
-   Aspect_Variable_Indexing | Aspect_Aggregate |
-   Aspect_Max_Entry_Queue_Length
-| Aspect_No_Controlled_Parts
-   --  ??? No_Controlled_Parts not yet in Aspect_Id enumeration
-   ;  --  see RM 13.1.1(18.7)
+ Static_Predicate =>
+   Nonoverridable_Aspect_Id in Aspect_Aggregate
+ | Aspect_Constant_Indexing
+ | Aspect_Default_Iterator
+ | Aspect_Implicit_Dereference
+ | Aspect_Iterator_Element
+ | Aspect_Max_Entry_Queue_Length
+ | Aspect_No_Controlled_Parts
+ | Aspect_Variable_Indexing;
+   --  ??? No_Controlled_Parts not yet in Aspect_Id enumeration see RM
+   --  13.1.1(18.7).
 
--  The following array indicates aspects that accept 'Class


[gcc r15-735] ada: Fix small inaccuracy for Size attribute applied to objects

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:dc775b12224ca18088b5f6a8a7759c426a58b116

commit r15-735-gdc775b12224ca18088b5f6a8a7759c426a58b116
Author: Eric Botcazou 
Date:   Thu Dec 14 15:18:28 2023 +0100

ada: Fix small inaccuracy for Size attribute applied to objects

This reverts a change made some time ago in lvalue_required_for_attribute_p
whereby the Size attribute applied to objects would no longer be considered
as requiring an lvalue.

While not wrong in principle, this turns out to be problematic because the
implementation in Attribute_to_gnu needs to look at the translated prefix
to spot particular cases and not only at the actual type of its value.

This of course requires a small adjustment in gnat_to_gnu to compensate.

gcc/ada/

* gcc-interface/trans.cc (access_attribute_p): New predicate.
(lvalue_required_for_attribute_p): Return again 1 for Size and add
the missing terminating call to gcc_unreachable.
(gnat_to_gnu): Return the result unmodified for a reference to an
unconstrained array only if it is the prefix of an access attribute.

Diff:
---
 gcc/ada/gcc-interface/trans.cc | 28 +---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index 8c7ffbf5687..6f761766559 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -745,6 +745,26 @@ build_raise_check (int check, enum exception_info_kind 
kind)
   return result;
 }
 
+/* Return true if GNAT_NODE, which is an N_Attribute_Reference, is one of the
+   access attributes.  */
+
+static bool
+access_attribute_p (Node_Id gnat_node)
+{
+  switch (Get_Attribute_Id (Attribute_Name (gnat_node)))
+{
+case Attr_Access:
+case Attr_Unchecked_Access:
+case Attr_Unrestricted_Access:
+  return true;
+
+default:
+  return false;
+}
+
+  gcc_unreachable ();
+}
+
 /* Return a positive value if an lvalue is required for GNAT_NODE, which is
an N_Attribute_Reference.  */
 
@@ -760,7 +780,6 @@ lvalue_required_for_attribute_p (Node_Id gnat_node)
 case Attr_Range_Length:
 case Attr_Length:
 case Attr_Object_Size:
-case Attr_Size:
 case Attr_Value_Size:
 case Attr_Component_Size:
 case Attr_Descriptor_Size:
@@ -786,11 +805,14 @@ lvalue_required_for_attribute_p (Node_Id gnat_node)
 case Attr_First_Bit:
 case Attr_Last_Bit:
 case Attr_Bit:
+case Attr_Size:
 case Attr_Asm_Input:
 case Attr_Asm_Output:
 default:
   return 1;
 }
+
+  gcc_unreachable ();
 }
 
 /* Return a positive value if an lvalue is required for GNAT_NODE.  GNU_TYPE
@@ -8472,7 +8494,7 @@ gnat_to_gnu (Node_Id gnat_node)
  return slot optimization in this case.
 
5. If this is a reference to an unconstrained array which is used either
- as the prefix of an attribute reference that requires an lvalue or in
+ as the prefix of an attribute reference for an access attribute or in
  a return statement without storage pool, return the result unmodified
  because we want to return the original bounds.
 
@@ -8539,7 +8561,7 @@ gnat_to_gnu (Node_Id gnat_node)
   else if (TREE_CODE (TREE_TYPE (gnu_result)) == UNCONSTRAINED_ARRAY_TYPE
   && Present (Parent (gnat_node))
   && ((Nkind (Parent (gnat_node)) == N_Attribute_Reference
-   && lvalue_required_for_attribute_p (Parent (gnat_node)))
+   && access_attribute_p (Parent (gnat_node)))
   || (Nkind (Parent (gnat_node)) == N_Simple_Return_Statement
   && No (Storage_Pool (Parent (gnat_node))
 ;


[gcc r15-736] ada: Fix crash on aliased constant with packed array type and -g switch

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:0967e06caaa606eec7b2f222bb9926ec6523ea02

commit r15-736-g0967e06caaa606eec7b2f222bb9926ec6523ea02
Author: Eric Botcazou 
Date:   Fri Jan 12 10:50:01 2024 +0100

ada: Fix crash on aliased constant with packed array type and -g switch

The problem is that we build a template whose array field is not an array
in the case of an aliased object with nominal unconstrained array subtype.

gcc/ada/

* gcc-interface/decl.cc (gnat_to_gnu_entity) : For an
array allocated with its bounds, make sure to have an array type
to build the template.

Diff:
---
 gcc/ada/gcc-interface/decl.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index ca174bff009..41d5c29a17c 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -939,6 +939,9 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, 
bool definition)
&& !type_annotate_only)
  {
tree gnu_array = gnat_to_gnu_type (Base_Type (gnat_type));
+   /* Make sure to have an array type for the template.  */
+   if (TYPE_IS_PADDING_P (gnu_type))
+ gnu_type = TREE_TYPE (TYPE_FIELDS (gnu_type));
gnu_type
  = build_unc_object_type_from_ptr (TREE_TYPE (gnu_array),
gnu_type,


[gcc r15-738] ada: Remove unused dependencies from gnatbind object list

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:448157fbf9f2261ad1a2e98139603c002f86c7bf

commit r15-738-g448157fbf9f2261ad1a2e98139603c002f86c7bf
Author: Piotr Trojanek 
Date:   Fri Jan 26 11:08:35 2024 +0100

ada: Remove unused dependencies from gnatbind object list

The gnatbind executable does not depend on aspects, SCIL, style checks,
etc. Also, these dependencies are not needed to actually build the
executable. Cleanup.

gcc/ada/

* gcc-interface/Make-lang.in (GNATBIND_OBJS): Remove unused
dependencies.

Diff:
---
 gcc/ada/gcc-interface/Make-lang.in | 5 -
 1 file changed, 5 deletions(-)

diff --git a/gcc/ada/gcc-interface/Make-lang.in 
b/gcc/ada/gcc-interface/Make-lang.in
index f6404c0b1eb..4f1b310fb84 100644
--- a/gcc/ada/gcc-interface/Make-lang.in
+++ b/gcc/ada/gcc-interface/Make-lang.in
@@ -572,7 +572,6 @@ GNATBIND_OBJS = \
  ada/ali-util.o   \
  ada/ali.o\
  ada/alloc.o  \
- ada/aspects.o\
  ada/atree.o  \
  ada/bcheck.o \
  ada/binde.o  \
@@ -602,12 +601,10 @@ GNATBIND_OBJS = \
  ada/exit.o   \
  ada/final.o  \
  ada/fmap.o   \
- ada/fname-uf.o   \
  ada/fname.o  \
  ada/gnatbind.o   \
  ada/gnatvsn.o\
  ada/hostparm.o   \
- ada/krunch.o \
  ada/lib.o\
  ada/link.o   \
  ada/namet.o  \
@@ -618,7 +615,6 @@ GNATBIND_OBJS = \
  ada/output.o \
  ada/rident.o \
  ada/scans.o  \
- ada/scil_ll.o\
  ada/scng.o   \
  ada/sdefault.o   \
  ada/seinfo.o\
@@ -631,7 +627,6 @@ GNATBIND_OBJS = \
  ada/snames.o \
  ada/stand.o  \
  ada/stringt.o\
- ada/style.o  \
  ada/styleg.o \
  ada/stylesw.o\
  ada/switch-b.o   \


[gcc r15-739] ada: Avoid temporary for conditional expression of discriminated record type

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:e49eac82e805ede5dd9b3c5d4ae9f8d90b0cc034

commit r15-739-ge49eac82e805ede5dd9b3c5d4ae9f8d90b0cc034
Author: Eric Botcazou 
Date:   Tue Feb 6 12:57:38 2024 +0100

ada: Avoid temporary for conditional expression of discriminated record type

This just aligns the definite case (discriminants with default) with the
indefinite case (discriminants without default), the latter case having
been properly handled for long.  In the former case, the maximum size is
used so a temporary can be much larger than the actual data it contains.

gcc/ada/

* gcc-interface/utils2.cc (build_cond_expr): Use the indirect path
for all types containing a placeholder.

Diff:
---
 gcc/ada/gcc-interface/utils2.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/gcc-interface/utils2.cc b/gcc/ada/gcc-interface/utils2.cc
index a953b070ed8..fb0ccf59224 100644
--- a/gcc/ada/gcc-interface/utils2.cc
+++ b/gcc/ada/gcc-interface/utils2.cc
@@ -1715,8 +1715,8 @@ build_cond_expr (tree result_type, tree condition_operand,
  then dereference the result.  Likewise if the result type is passed by
  reference, because creating a temporary of this type is not allowed.  */
   if (TREE_CODE (result_type) == UNCONSTRAINED_ARRAY_TYPE
-  || TYPE_IS_BY_REFERENCE_P (result_type)
-  || CONTAINS_PLACEHOLDER_P (TYPE_SIZE (result_type)))
+  || type_contains_placeholder_p (result_type)
+  || TYPE_IS_BY_REFERENCE_P (result_type))
 {
   result_type = build_pointer_type (result_type);
   true_operand = build_unary_op (ADDR_EXPR, result_type, true_operand);


[gcc r15-733] ada: Missing constraint check for initial value of object with address clause

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:2ccf77d982d41dda5d352e99d67f901d1cfb7668

commit r15-733-g2ccf77d982d41dda5d352e99d67f901d1cfb7668
Author: Steve Baird 
Date:   Fri Apr 5 12:35:08 2024 -0700

ada: Missing constraint check for initial value of object with address 
clause

In some cases where an object is declared with an initial value that is
an aggregate and also with a specified Address (either via an
aspect_specification or via an attribute_definition_clause), the
check that the initial value satisfies the constraints of the object's
subtype was incorrectly omitted.

gcc/ada/

* exp_util.adb (Remove_Side_Effects): Make_Reference assumes that
the referenced object satisfies the constraints of the designated
subtype of the access type. Ensure that this assumption holds by
introducing a qualified expression if needed (and then ensuring
that checking associated with evaluation of the qualified
expression is not suppressed).

Diff:
---
 gcc/ada/exp_util.adb | 29 +
 1 file changed, 29 insertions(+)

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index b71f7739481..654ea7d9124 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -12772,6 +12772,35 @@ package body Exp_Util is
 --  since we know it cannot be null and we don't want a check.
 
 else
+   --  Make_Reference assumes that the referenced
+   --  object satisfies the constraints of the designated
+   --  subtype of the access type. Ensure that this assumption
+   --  holds by introducing a qualified expression if needed.
+
+   if not Analyzed (Exp)
+ and then Nkind (Exp) = N_Aggregate
+ and then (Is_Array_Type (Exp_Type)
+   or else Has_Discriminants (Exp_Type))
+ and then Is_Constrained (Exp_Type)
+   then
+  --  Do not suppress checks associated with the qualified
+  --  expression we are about to introduce (unless those
+  --  checks were already suppressed when Remove_Side_Effects
+  --  was called).
+
+  if Is_Array_Type (Exp_Type) then
+ Scope_Suppress.Suppress (Length_Check)
+   := Svg_Suppress.Suppress (Length_Check);
+  else
+ Scope_Suppress.Suppress (Discriminant_Check)
+   := Svg_Suppress.Suppress (Discriminant_Check);
+  end if;
+
+  E := Make_Qualified_Expression (Loc,
+ Subtype_Mark => New_Occurrence_Of (Exp_Type, Loc),
+ Expression => E);
+   end if;
+
New_Exp := Make_Reference (Loc, E);
Set_Is_Known_Non_Null (Def_Id);
 end if;


[gcc r15-744] ada: Make detection of useless copy for return more robust

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:d851e08ba97f5d0671711763f6a7d4c94afb8457

commit r15-744-gd851e08ba97f5d0671711763f6a7d4c94afb8457
Author: Eric Botcazou 
Date:   Tue Mar 12 17:56:00 2024 +0100

ada: Make detection of useless copy for return more robust

In the return-by-invisible-reference case, the return object of an extended
return statement is allocated directly on the return stack and, therefore,
the copy operation on return is useless.  The code detecting this was not
robust enough and missed some complex cases.

gcc/ada/

* gcc-interface/trans.cc (gnat_to_gnu) :
In the return-by-invisible-reference case, remove conversions before
looking for a dereference in the return values and building the test
protecting against a useless copy operation.

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

diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index a6b86ec8b51..4ae599b8b4c 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -7767,11 +7767,12 @@ gnat_to_gnu (Node_Id gnat_node)
gnu_result = build2 (INIT_EXPR, void_type_node,
 gnu_ret_deref, gnu_ret_val);
/* Avoid a useless copy with __builtin_return_slot.  */
-   if (INDIRECT_REF_P (gnu_ret_val))
+   tree gnu_inner_val = remove_conversions (gnu_ret_val, false);
+   if (INDIRECT_REF_P (gnu_inner_val))
  gnu_result
= build3 (COND_EXPR, void_type_node,
  fold_build2 (NE_EXPR, boolean_type_node,
-  TREE_OPERAND (gnu_ret_val, 0),
+  TREE_OPERAND (gnu_inner_val, 0),
   gnu_ret_obj),
  gnu_result, NULL_TREE);
add_stmt_with_node (gnu_result, gnat_node);


[gcc r15-745] ada: Fix strict aliasing violation in parameter passing (continued)

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:ccdef2aef6463159a596ef1a4afe6ddce9d0f2ea

commit r15-745-gccdef2aef6463159a596ef1a4afe6ddce9d0f2ea
Author: Eric Botcazou 
Date:   Sun Mar 10 13:22:55 2024 +0100

ada: Fix strict aliasing violation in parameter passing (continued)

This fixes another long-standing (implicit) violation of the strict aliasing
rules that occurs when the result of a value conversion is directly passed
as an actual parameter in a call to a subprogram and the passing mechanism
is by reference.  In this case, the reference passed to the subprogram may
be to a type that is too different from the type of the underlying object,
which is the definition of such a violation.

The change reworks and strengthens the previous fix as follows: first, the
detection of these violations is moved into a dedicated predicate; second,
an assertion is added to check that none of them has been missed, which is
triggered by either -fchecking or -fstrict-aliasing, as the closely related
assertion that is present in relate_alias_sets.

The assertion uncovered two internal sources of violations: implementation
types for packed array types with peculiar index types and interface types,
which are fixed by propagating alias sets in the first case and resorting to
universal aliasing in the second case.

Finally, an unconditional warning is implemented to inform the user that the
temporary is created and to suggest a possible solution to prevent that.

gcc/ada/

* gcc-interface/decl.cc (gnat_to_gnu_entity) : For a
packed type implemented specially, temporarily save the XUA type as
equivalent to the entity before processing the implementation type.
For this implementation type, if its component type is the same as
that of the original type, copy the alias set from the latter.
: Resort to universal aliasing for all interface types.
* gcc-interface/trans.cc (Call_to_gnu): Add GNU_ACTUAL_TYPE local
variable and rename existing one to GNU_UNPADDED_ACTUAL_TYPE.
If the formal is passed by reference and the actual is a conversion,
call aliasable_p to detect aliasing violations, issue a warning upon
finding one and create the temporary in the target type.
Add an assertion that no such violation has been missed above.
(addressable_p): Revert latest changes.
(aliasable_p): New predicate.
* gcc-interface/utils2.cc (build_binary_op) : When
creating a new array type on the fly, preserve the alias set of the
operation type.

Diff:
---
 gcc/ada/gcc-interface/decl.cc   |  48 
 gcc/ada/gcc-interface/trans.cc  | 167 +---
 gcc/ada/gcc-interface/utils2.cc |   6 +-
 3 files changed, 159 insertions(+), 62 deletions(-)

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index ab54d2ccf13..6e40a157734 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -2119,6 +2119,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, 
bool definition)
 
 case E_Array_Type:
   {
+   const Entity_Id OAT = Original_Array_Type (gnat_entity);
const Entity_Id PAT = Packed_Array_Impl_Type (gnat_entity);
const bool convention_fortran_p
  = (Convention (gnat_entity) == Convention_Fortran);
@@ -2392,14 +2393,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree 
gnu_expr, bool definition)
  set_typeless_storage_on_aggregate_type (tem);
  }
 
-   /* If this is a packed type implemented specially, then process the
-  implementation type so it is elaborated in the proper scope.  */
-   if (Present (PAT))
- gnat_to_gnu_entity (PAT, NULL_TREE, false);
-
-   /* Otherwise, if an alignment is specified, use it if valid and, if
-  the alignment was requested with an explicit clause, state so.  */
-   else if (Known_Alignment (gnat_entity))
+   /* If an alignment is specified for an array that is not a packed type
+  implemented specially, use the alignment if it is valid and, if it
+  was requested with an explicit clause, preserve the information.  */
+   if (Known_Alignment (gnat_entity) && No (PAT))
  {
SET_TYPE_ALIGN (tem,
validate_alignment (Alignment (gnat_entity),
@@ -2418,7 +2415,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, 
bool definition)
 
TYPE_BIT_PACKED_ARRAY_TYPE_P (tem)
  = (Is_Packed_Array_Impl_Type (gnat_entity)
-? Is_Bit_Packed_Array (Original_Array_Type (gnat_entity))
+? Is_Bit_Packed_Array (OAT)
 : Is_Bit_Packed_Array (gnat_entity));
 
if (Treat_As_Volatile (gnat_entity))
@@ -2447,8 +2444,9 @@ gnat_to_gnu_entity (Entity_Id gna

[gcc r15-746] ada: Fix internal error on discriminated record with Atomic aspect in Ada 2022

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:bf69349b8d974ff2a2518976e69724d21aa1f423

commit r15-746-gbf69349b8d974ff2a2518976e69724d21aa1f423
Author: Eric Botcazou 
Date:   Thu Mar 28 00:02:11 2024 +0100

ada: Fix internal error on discriminated record with Atomic aspect in Ada 
2022

It occurs in build_load_modify_store where the pattern matching logic cannot
find the atomic load that is present in the tree because it has been wrapped
in a SAVE_EXPR by gnat_protect_expr, which is unnecessary.

gcc/ada/

* gcc-interface/utils2.cc (gnat_protect_expr): Deal specifically
with atomic loads. Document the relationship with gnat_save_expr.

Diff:
---
 gcc/ada/gcc-interface/utils2.cc | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/gcc-interface/utils2.cc b/gcc/ada/gcc-interface/utils2.cc
index c1346cfadeb..8fb86ab29e3 100644
--- a/gcc/ada/gcc-interface/utils2.cc
+++ b/gcc/ada/gcc-interface/utils2.cc
@@ -2887,7 +2887,11 @@ gnat_save_expr (tree exp)
 
 /* Protect EXP for immediate reuse.  This is a variant of gnat_save_expr that
is optimized under the assumption that EXP's value doesn't change before
-   its subsequent reuse(s) except through its potential reevaluation.  */
+   its subsequent reuse(s) except potentially through its reevaluation.
+
+   gnat_protect_expr guarantees that multiple evaluations of the expression
+   will not generate multiple side effects, whereas gnat_save_expr further
+   guarantees that all evaluations will yield the same result.  */
 
 tree
 gnat_protect_expr (tree exp)
@@ -2932,6 +2936,13 @@ gnat_protect_expr (tree exp)
 return build3 (code, type, gnat_protect_expr (TREE_OPERAND (exp, 0)),
   TREE_OPERAND (exp, 1), NULL_TREE);
 
+  /* An atomic load is an INDIRECT_REF of its first argument, so apply the
+ same transformation as in the INDIRECT_REF case above.  */
+  if (code == CALL_EXPR && call_is_atomic_load (exp))
+return build_call_expr (TREE_OPERAND (CALL_EXPR_FN (exp), 0), 2,
+   gnat_protect_expr (CALL_EXPR_ARG (exp, 0)),
+   CALL_EXPR_ARG (exp, 1));
+
   /* If this is a COMPONENT_REF of a fat pointer, save the entire fat pointer.
  This may be more efficient, but will also allow us to more easily find
  the match for the PLACEHOLDER_EXPR.  */


[gcc r15-737] ada: Fix assembler error for gigantic library-level object on 64-bit Windows

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:15ac30dbe8e80453b980b6d242f5b1f9a025e2ca

commit r15-737-g15ac30dbe8e80453b980b6d242f5b1f9a025e2ca
Author: Eric Botcazou 
Date:   Mon Jan 22 23:56:37 2024 +0100

ada: Fix assembler error for gigantic library-level object on 64-bit Windows

Most small 64-bit code models have a limit of 2 GB on the span of binaries,
so we also use the limit for the size of the largest statically allocatable
object by the compiler.  If the limit is topped, the compiler switches over
to a dynamic allocation (if not forbidden) after giving a warning.

gcc/ada/

* gcc-interface/decl.cc (gnat_to_gnu_entity) : Give a
warning for a statically allocated object whose size is constant,
valid but too large.
(allocatable_size_p): In the static case, return false for a size
that is constant, valid but too large.

Diff:
---
 gcc/ada/gcc-interface/decl.cc | 27 +--
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index 41d5c29a17c..e16ee6edac5 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -1415,10 +1415,22 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree 
gnu_expr, bool definition)
 false);
  }
 
-   if (TREE_CODE (TYPE_SIZE_UNIT (gnu_alloc_type)) == INTEGER_CST
-   && !valid_constant_size_p (TYPE_SIZE_UNIT (gnu_alloc_type)))
- post_error ("??Storage_Error will be raised at run time!",
- gnat_entity);
+   /* Give a warning if the size is constant but too large.  */
+   if (TREE_CODE (TYPE_SIZE_UNIT (gnu_alloc_type)) == INTEGER_CST)
+ {
+   if (valid_constant_size_p (TYPE_SIZE_UNIT (gnu_alloc_type)))
+ {
+   post_error
+ ("??too large object cannot be allocated statically",
+  gnat_entity);
+   post_error ("\\?dynamic allocation will be used 
instead",
+   gnat_entity);
+ }
+
+   else
+ post_error ("??Storage_Error will be raised at run time!",
+ gnat_entity);
+ }
 
gnu_expr
  = build_allocator (gnu_alloc_type, gnu_expr, gnu_type,
@@ -6822,9 +6834,12 @@ constructor_address_p (tree gnu_expr)
 static bool
 allocatable_size_p (tree gnu_size, bool static_p)
 {
-  /* We can allocate a fixed size if it is a valid for the middle-end.  */
+  /* We can allocate a fixed size if it is a valid for the middle-end but, for
+ a static allocation, we do not allocate more than 2 GB because this would
+ very likely be unintended and problematic for usual code models.  */
   if (TREE_CODE (gnu_size) == INTEGER_CST)
-return valid_constant_size_p (gnu_size);
+return valid_constant_size_p (gnu_size)
+  && (!static_p || tree_to_uhwi (gnu_size) <= INT_MAX);
 
   /* We can allocate a variable size if this isn't a static allocation.  */
   else


[gcc r15-734] ada: Fix oversight in previous change

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:0715ed49b40311e9b2715f63308a970195dd2417

commit r15-734-g0715ed49b40311e9b2715f63308a970195dd2417
Author: Eric Botcazou 
Date:   Thu Dec 14 13:05:52 2023 +0100

ada: Fix oversight in previous change

In rare cases, types using structural equality may reach relate_alias_sets.

gcc/ada/

* gcc-interface/utils.cc (relate_alias_sets): Restore previous code
when the type uses structural equality.

Diff:
---
 gcc/ada/gcc-interface/utils.cc | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc
index b628481335d..ae520542ace 100644
--- a/gcc/ada/gcc-interface/utils.cc
+++ b/gcc/ada/gcc-interface/utils.cc
@@ -1867,8 +1867,11 @@ relate_alias_sets (tree new_type, tree old_type, enum 
alias_set_op op)
  && TYPE_NONALIASED_COMPONENT (new_type)
 != TYPE_NONALIASED_COMPONENT (old_type)));
 
-  /* The alias set always lives on the TYPE_CANONICAL.  */
-  TYPE_ALIAS_SET (TYPE_CANONICAL (new_type)) = get_alias_set (old_type);
+  /* The alias set is a property of the TYPE_CANONICAL if it exists.  */
+  if (TYPE_STRUCTURAL_EQUALITY_P (new_type))
+   TYPE_ALIAS_SET (new_type) = get_alias_set (old_type);
+  else
+   TYPE_ALIAS_SET (TYPE_CANONICAL (new_type)) = get_alias_set (old_type);
   break;
 
 case ALIAS_SET_SUBSET:


[gcc r15-740] ada: Follow-up adjustment to earlier fix in Build_Allocate_Deallocate_Proc

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:bc54f5b8b21114c7f63f4b318f36d63026add3b6

commit r15-740-gbc54f5b8b21114c7f63f4b318f36d63026add3b6
Author: Eric Botcazou 
Date:   Sun Feb 11 19:18:46 2024 +0100

ada: Follow-up adjustment to earlier fix in Build_Allocate_Deallocate_Proc

The deallocation call of the return and secondary stacks no longer matches
the profile built in Exp_Util.Build_Allocate_Deallocate_Proc, so this just
removes the code as unreachable and adds an assertion to that effect.

gcc/ada/

* gcc-interface/utils2.cc (build_call_alloc_dealloc_proc): Add an
assertion that this is not a deallocation of the return or secondary
stack and remove subsequent unreachable code.

Diff:
---
 gcc/ada/gcc-interface/utils2.cc | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/gcc/ada/gcc-interface/utils2.cc b/gcc/ada/gcc-interface/utils2.cc
index fb0ccf59224..64712cb9962 100644
--- a/gcc/ada/gcc-interface/utils2.cc
+++ b/gcc/ada/gcc-interface/utils2.cc
@@ -2187,15 +2187,16 @@ build_call_alloc_dealloc_proc (tree gnu_obj, tree 
gnu_size, tree gnu_type,
= Etype (Next_Formal (First_Formal (gnat_proc)));
   tree gnu_size_type = gnat_to_gnu_type (gnat_size_type);
 
+  /* Deallocation is not supported for return and secondary stacks.  */
+  gcc_assert (!gnu_obj);
+
   gnu_size = convert (gnu_size_type, gnu_size);
   gnu_align = convert (gnu_size_type, gnu_align);
 
   if (DECL_BUILT_IN_CLASS (gnu_proc) == BUILT_IN_FRONTEND
  && DECL_FE_FUNCTION_CODE (gnu_proc) == BUILT_IN_RETURN_SLOT)
{
- /* This must be an allocation of the return stack in a function that
-returns by invisible reference.  */
- gcc_assert (!gnu_obj);
+ /* This must be a function that returns by invisible reference.  */
  gcc_assert (current_function_decl
  && TREE_ADDRESSABLE (TREE_TYPE (current_function_decl)));
  tree gnu_ret_size;
@@ -2221,11 +,6 @@ build_call_alloc_dealloc_proc (tree gnu_obj, tree 
gnu_size, tree gnu_type,
 N_Raise_Program_Error));
}
 
-  /* The first arg is the address of the object, for a deallocator,
-then the size.  */
-  else if (gnu_obj)
-   gnu_call = build_call_n_expr (gnu_proc, 2, gnu_obj, gnu_size);
-
   else
gnu_call = build_call_n_expr (gnu_proc, 2, gnu_size, gnu_align);
 }


[gcc r15-743] ada: Fix strict aliasing violation in parameter passing

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:f20a57edefe0cb185e57f82a15e887887b98d3ab

commit r15-743-gf20a57edefe0cb185e57f82a15e887887b98d3ab
Author: Eric Botcazou 
Date:   Thu Feb 29 09:14:27 2024 +0100

ada: Fix strict aliasing violation in parameter passing

This fixes a long-standing (implicit) violation of the strict aliasing rules
that occurs when the result of a call to an instance of Unchecked_Conversion
is directly passed as an actual parameter in a call to a subprogram and the
passing mechanism is by reference.  In this case, the reference passed to
the subprogram may be to a type that has nothing to do with the type of the
underlying object, which is the definition of such a violation.

This implements the following two-pronged approach: first, the problematic
cases are detected and a reference to a temporary is passed instead of the
direct reference to the underlying object; second, the implementation of
pragma Universal_Aliasing is enhanced so that it is propagated from the
component type of an array type to the array type itself, or else can be
applied to the array type directly, and may therefore be used to prevent
the violation from occurring in the first place, when the array type is
involved in the Unchecked_Conversion.

gcc/ada/

* gcc-interface/decl.cc (gnat_to_gnu_entity) : Set
TYPE_TYPELESS_STORAGE on the array types if Universal_Aliasing is
set on the type or its component type.
: Likewise.
For other aggregate types, set TYPE_TYPELESS_STORAGE in this case.
(set_typeless_storage_on_aggregate_type): New function.
(set_universal_aliasing_on_type): Likewise.
* gcc-interface/trans.cc (Call_to_gnu): Add const to local variable.
Adjust comment.  Pass GNAT_NAME in the call to addressable_p and add
a bypass for atomic types in case it returns false.
(addressable_p): Add GNAT_EXPR third parameter with default value
and add a default value to the existing second parameter.
: Return false if the expression comes from a
function call and if the alias sets of source and target types are
both distinct from zero and each other.

Diff:
---
 gcc/ada/gcc-interface/decl.cc  | 40 +++-
 gcc/ada/gcc-interface/trans.cc | 60 ++
 2 files changed, 82 insertions(+), 18 deletions(-)

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index 0987d534e69..ab54d2ccf13 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -205,6 +205,8 @@ static Entity_Id Gigi_Cloned_Subtype (Entity_Id);
 static tree gnu_ext_name_for_subprog (Entity_Id, tree);
 static void set_nonaliased_component_on_array_type (tree);
 static void set_reverse_storage_order_on_array_type (tree);
+static void set_typeless_storage_on_aggregate_type (tree);
+static void set_universal_aliasing_on_type (tree);
 static bool same_discriminant_p (Entity_Id, Entity_Id);
 static bool array_type_has_nonaliased_component (tree, Entity_Id);
 static bool compile_time_known_address_p (Node_Id);
@@ -2385,6 +2387,9 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, 
bool definition)
  set_reverse_storage_order_on_array_type (tem);
if (array_type_has_nonaliased_component (tem, gnat_entity))
  set_nonaliased_component_on_array_type (tem);
+   if (Universal_Aliasing (gnat_entity)
+   || Universal_Aliasing (Component_Type (gnat_entity)))
+ set_typeless_storage_on_aggregate_type (tem);
  }
 
/* If this is a packed type implemented specially, then process the
@@ -2790,6 +2795,9 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, 
bool definition)
set_reverse_storage_order_on_array_type (gnu_type);
  if (array_type_has_nonaliased_component (gnu_type, gnat_entity))
set_nonaliased_component_on_array_type (gnu_type);
+ if (Universal_Aliasing (gnat_entity)
+ || Universal_Aliasing (Component_Type (gnat_entity)))
+   set_typeless_storage_on_aggregate_type (gnu_type);
 
  /* Clear the TREE_OVERFLOW flag, if any, for null arrays.  */
  if (gnu_null_ranges[index])
@@ -4757,7 +4765,17 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree 
gnu_expr, bool definition)
 
  /* Record whether a pragma Universal_Aliasing was specified.  */
  if (Universal_Aliasing (gnat_entity) && !TYPE_IS_DUMMY_P (gnu_type))
-   TYPE_UNIVERSAL_ALIASING_P (gnu_type) = 1;
+   {
+ /* Set TYPE_TYPELESS_STORAGE if this is an aggregate type and
+TYPE_UNIVERSAL_ALIASING_P otherwise, since the former is not
+available in the latter case  Both will effectively put alias
+s

[gcc r15-741] ada: Minor typo fix in comment

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:3f4485608f1b4e2e0e91d2da8fa0a815110c5f8e

commit r15-741-g3f4485608f1b4e2e0e91d2da8fa0a815110c5f8e
Author: Marc Poulhiès 
Date:   Fri Jan 26 13:58:34 2024 +0100

ada: Minor typo fix in comment

gcc/ada/

* gcc-interface/decl.cc: Fix typo in comment.

Diff:
---
 gcc/ada/gcc-interface/decl.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index e16ee6edac5..0987d534e69 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -5629,7 +5629,7 @@ gnat_to_gnu_param (Entity_Id gnat_param, tree 
gnu_param_type, bool first,
   by_ref = true;
 }
 
-  /* If we were requested or muss pass by reference, do so.
+  /* If we were requested or must pass by reference, do so.
  If we were requested to pass by copy, do so.
  Otherwise, for foreign conventions, pass In Out or Out parameters
  or aggregates by reference.  For COBOL and Fortran, pass all


[gcc r15-742] ada: Fix crash with aliased array and if expression

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:a687d5da7015042fa7ff047430e3c5cb57524a7c

commit r15-742-ga687d5da7015042fa7ff047430e3c5cb57524a7c
Author: Ronan Desplanques 
Date:   Fri Feb 23 09:53:32 2024 +0100

ada: Fix crash with aliased array and if expression

The way if expressions were translated led the gimplifying phase
to attempt to create a temporary of a variable-sized type in some
cases. This patch fixes this by adding an address indirection layer
in those cases.

gcc/ada/

* gcc-interface/utils2.cc (build_cond_expr): Also apply an
indirection when the result type is variable-sized.

Diff:
---
 gcc/ada/gcc-interface/utils2.cc | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/gcc-interface/utils2.cc b/gcc/ada/gcc-interface/utils2.cc
index 64712cb9962..161f0f11e5c 100644
--- a/gcc/ada/gcc-interface/utils2.cc
+++ b/gcc/ada/gcc-interface/utils2.cc
@@ -1711,11 +1711,13 @@ build_cond_expr (tree result_type, tree 
condition_operand,
   true_operand = convert (result_type, true_operand);
   false_operand = convert (result_type, false_operand);
 
-  /* If the result type is unconstrained, take the address of the operands and
- then dereference the result.  Likewise if the result type is passed by
- reference, because creating a temporary of this type is not allowed.  */
+  /* If the result type is unconstrained or variable-sized, take the address
+ of the operands and then dereference the result.  Likewise if the result
+ type is passed by reference, because creating a temporary of this type is
+ not allowed.  */
   if (TREE_CODE (result_type) == UNCONSTRAINED_ARRAY_TYPE
   || type_contains_placeholder_p (result_type)
+  || !TREE_CONSTANT (TYPE_SIZE (result_type))
   || TYPE_IS_BY_REFERENCE_P (result_type))
 {
   result_type = build_pointer_type (result_type);


[gcc r15-748] ada: Streamline implementation of simple nonbinary modular operations

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:ea793db568348d7fb9a6dd08d34d9c40608f6023

commit r15-748-gea793db568348d7fb9a6dd08d34d9c40608f6023
Author: Eric Botcazou 
Date:   Thu Apr 4 16:39:55 2024 +0200

ada: Streamline implementation of simple nonbinary modular operations

They are implemented by the nonbinary_modular_operation routine, which is
complex and, in particular, creates signed types and types with a partial
precision each time a subtraction or a multiplication resp. is generated.
Both are unnecessary and a simple approach even generates better code for
the subtraction on architectures with conditional moves.

gcc/ada/

* gcc-interface/utils2.cc (nonbinary_modular_operation): Rewrite.
Do not create signed types for subtraction, do not create types with
partial precision, call fold_convert instead of convert throughout.

Diff:
---
 gcc/ada/gcc-interface/utils2.cc | 91 +
 1 file changed, 28 insertions(+), 63 deletions(-)

diff --git a/gcc/ada/gcc-interface/utils2.cc b/gcc/ada/gcc-interface/utils2.cc
index 8fb86ab29e3..4b7e2739f6a 100644
--- a/gcc/ada/gcc-interface/utils2.cc
+++ b/gcc/ada/gcc-interface/utils2.cc
@@ -535,85 +535,50 @@ compare_fat_pointers (location_t loc, tree result_type, 
tree p1, tree p2)
 }
 
 /* Compute the result of applying OP_CODE to LHS and RHS, where both are of
-   type TYPE.  We know that TYPE is a modular type with a nonbinary
-   modulus.  */
+   TYPE.  We know that TYPE is a modular type with a nonbinary modulus.  */
 
 static tree
 nonbinary_modular_operation (enum tree_code op_code, tree type, tree lhs,
  tree rhs)
 {
   tree modulus = TYPE_MODULUS (type);
-  unsigned int needed_precision = tree_floor_log2 (modulus) + 1;
-  unsigned int precision;
-  bool unsignedp = true;
-  tree op_type = type;
-  tree result;
+  unsigned precision = tree_floor_log2 (modulus) + 1;
+  tree op_type, result;
 
-  /* If this is an addition of a constant, convert it to a subtraction
- of a constant since we can do that faster.  */
-  if (op_code == PLUS_EXPR && TREE_CODE (rhs) == INTEGER_CST)
-{
-  rhs = fold_build2 (MINUS_EXPR, type, modulus, rhs);
-  op_code = MINUS_EXPR;
-}
-
-  /* For the logical operations, we only need PRECISION bits.  For
- addition and subtraction, we need one more and for multiplication we
- need twice as many.  But we never want to make a size smaller than
- our size. */
+  /* For the logical operations, we only need PRECISION bits.  For addition and
+ subtraction, we need one more, and for multiplication twice as many.  */
   if (op_code == PLUS_EXPR || op_code == MINUS_EXPR)
-needed_precision += 1;
+precision += 1;
   else if (op_code == MULT_EXPR)
-needed_precision *= 2;
-
-  precision = MAX (needed_precision, TYPE_PRECISION (op_type));
+precision *= 2;
 
-  /* Unsigned will do for everything but subtraction.  */
-  if (op_code == MINUS_EXPR)
-unsignedp = false;
-
-  /* If our type is the wrong signedness or isn't wide enough, make a new
- type and convert both our operands to it.  */
-  if (TYPE_PRECISION (op_type) < precision
-  || TYPE_UNSIGNED (op_type) != unsignedp)
+  /* If the type is not wide enough, make a new type of the needed precision
+ and convert modulus and operands to it.  Use a type with full precision
+ for its mode since operations are ultimately performed in the mode.  */
+  if (TYPE_PRECISION (type) < precision)
 {
-  /* Copy the type so we ensure it can be modified to make it modular.  */
-  op_type = copy_type (gnat_type_for_size (precision, unsignedp));
-  modulus = convert (op_type, modulus);
-  SET_TYPE_MODULUS (op_type, modulus);
-  TYPE_MODULAR_P (op_type) = 1;
-  lhs = convert (op_type, lhs);
-  rhs = convert (op_type, rhs);
+  const scalar_int_mode m = smallest_int_mode_for_size (precision);
+  op_type = gnat_type_for_mode (m, 1);
+  modulus = fold_convert (op_type, modulus);
+  lhs = fold_convert (op_type, lhs);
+  rhs = fold_convert (op_type, rhs);
 }
+  else
+op_type = type;
 
   /* Do the operation, then we'll fix it up.  */
   result = fold_build2 (op_code, op_type, lhs, rhs);
 
-  /* For multiplication, we have no choice but to do a full modulus
- operation.  However, we want to do this in the narrowest
- possible size.  */
-  if (op_code == MULT_EXPR)
-{
-  /* Copy the type so we ensure it can be modified to make it modular.  */
-  tree div_type = copy_type (gnat_type_for_size (needed_precision, 1));
-  modulus = convert (div_type, modulus);
-  SET_TYPE_MODULUS (div_type, modulus);
-  TYPE_MODULAR_P (div_type) = 1;
-  result = convert (op_type,
-   fold_build2 (TRUNC_MOD_EXPR, div_type,
-convert (div_type, result), modulus));
-}
+  /* Unconditionally add the modulus to the r

[gcc r15-747] ada: Simplify test for propagation of attributes to subtypes

2024-05-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:9fbf129bade8014d1fd7ab8ecd255df7e12570f0

commit r15-747-g9fbf129bade8014d1fd7ab8ecd255df7e12570f0
Author: Eric Botcazou 
Date:   Fri Mar 29 09:08:08 2024 +0100

ada: Simplify test for propagation of attributes to subtypes

This changes the test to use the Is_Base_Type predicate and also removes the
superfluous call to Base_Type before First_Subtype.  No functional changes.

gcc/ada/

* gcc-interface/decl.cc (gnat_to_gnu_entity): Use the Is_Base_Type
predicate and remove superfluous calls to Base_Type.

Diff:
---
 gcc/ada/gcc-interface/decl.cc | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index 6e40a157734..f6a4c0631b6 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -506,11 +506,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, 
bool definition)
   /* Machine_Attributes on types are expected to be propagated to
 subtypes.  The corresponding Gigi_Rep_Items are only attached
 to the first subtype though, so we handle the propagation here.  */
-  if (Base_Type (gnat_entity) != gnat_entity
+  if (!Is_Base_Type (gnat_entity)
  && !Is_First_Subtype (gnat_entity)
- && Has_Gigi_Rep_Item (First_Subtype (Base_Type (gnat_entity
-   prepend_attributes (&attr_list,
-   First_Subtype (Base_Type (gnat_entity)));
+ && Has_Gigi_Rep_Item (First_Subtype (gnat_entity)))
+   prepend_attributes (&attr_list, First_Subtype (gnat_entity));
 
   /* Compute a default value for the size of an elementary type.  */
   if (Known_Esize (gnat_entity) && Is_Elementary_Type (gnat_entity))


[gcc r15-749] contrib/gcc-changelog/git_update_version.py: Improve diagnostic

2024-05-21 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:9596f6567ce6fdf94227b97ac28d3549f421ef73

commit r15-749-g9596f6567ce6fdf94227b97ac28d3549f421ef73
Author: Tobias Burnus 
Date:   Tue May 21 10:13:13 2024 +0200

contrib/gcc-changelog/git_update_version.py: Improve diagnostic

contrib/ChangeLog:

* gcc-changelog/git_update_version.py: Add '-i'/'--ignore' argument
to add to-be-ignored commits via the command line.
(ignored_commits): Rename from IGNORED_COMMITS and change
type from tuple to set.
(prepend_to_changelog_files): Show git hash if errors occurred.
(update_current_branch): Mark argument as optional by defaulting
to None.

Diff:
---
 contrib/gcc-changelog/git_update_version.py | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/contrib/gcc-changelog/git_update_version.py 
b/contrib/gcc-changelog/git_update_version.py
index 24f6c43d0b2..c69a3a6897a 100755
--- a/contrib/gcc-changelog/git_update_version.py
+++ b/contrib/gcc-changelog/git_update_version.py
@@ -22,6 +22,7 @@ import argparse
 import datetime
 import logging
 import os
+import re
 
 from git import Repo
 
@@ -30,7 +31,7 @@ from git_repository import parse_git_revisions
 current_timestamp = datetime.datetime.now().strftime('%Y%m%d\n')
 
 # Skip the following commits, they cannot be correctly processed
-IGNORED_COMMITS = (
+ignored_commits = {
 'c2be82058fb40f3ae891c68d185ff53e07f14f45',
 '04a040d907a83af54e0a98bdba5bfabc0ef4f700',
 '2e96b5f14e4025691b57d2301d71aa6092ed44bc',
@@ -41,7 +42,7 @@ IGNORED_COMMITS = (
 '040e5b0edbca861196d9e2ea2af5e805769c8d5d',
 '8057f9aa1f7e70490064de796d7a8d42d446caf8',
 '109f1b28fc94c93096506e3df0c25e331cef19d0',
-'39f81924d88e3cc197fc3df74204c9b5e01e12f7')
+'39f81924d88e3cc197fc3df74204c9b5e01e12f7'}
 
 FORMAT = '%(asctime)s:%(levelname)s:%(name)s:%(message)s'
 logging.basicConfig(level=logging.INFO, format=FORMAT,
@@ -58,6 +59,7 @@ def read_timestamp(path):
 
 def prepend_to_changelog_files(repo, folder, git_commit, add_to_git):
 if not git_commit.success:
+logging.info(f"While processing {git_commit.info.hexsha}:")
 for error in git_commit.errors:
 logging.info(error)
 raise AssertionError()
@@ -93,13 +95,15 @@ parser.add_argument('-d', '--dry-mode',
  ' is expected')
 parser.add_argument('-c', '--current', action='store_true',
 help='Modify current branch (--push argument is ignored)')
+parser.add_argument('-i', '--ignore', action='append',
+help='list of commits to ignore')
 args = parser.parse_args()
 
 repo = Repo(args.git_path)
 origin = repo.remotes['origin']
 
 
-def update_current_branch(ref_name):
+def update_current_branch(ref_name=None):
 commit = repo.head.commit
 commit_count = 1
 while commit:
@@ -123,7 +127,7 @@ def update_current_branch(ref_name):
 head = head.parents[1]
 commits = parse_git_revisions(args.git_path, '%s..%s'
   % (commit.hexsha, head.hexsha), ref_name)
-commits = [c for c in commits if c.info.hexsha not in IGNORED_COMMITS]
+commits = [c for c in commits if c.info.hexsha not in ignored_commits]
 for git_commit in reversed(commits):
 prepend_to_changelog_files(repo, args.git_path, git_commit,
not args.dry_mode)
@@ -153,6 +157,9 @@ def update_current_branch(ref_name):
 else:
 logging.info('DATESTAMP unchanged')
 
+if args.ignore is not None:
+for item in args.ignore:
+ignored_commits.update(set(i for i in re.split(r'\s*,\s*|\s+', item)))
 
 if args.current:
 logging.info('=== Working on the current branch ===')


[gcc r15-750] tree-optimization/115149 - VOP live and missing PHIs

2024-05-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:ec9b8bafe20755d13ab9a1b834b5da79ae972c0e

commit r15-750-gec9b8bafe20755d13ab9a1b834b5da79ae972c0e
Author: Richard Biener 
Date:   Tue May 21 09:48:04 2024 +0200

tree-optimization/115149 - VOP live and missing PHIs

The following fixes a bug in vop-live get_live_in which was using
NULL to indicate the first processed edge but at the same time
using it for the case the live-in virtual operand cannot be computed.
The following fixes this, avoiding sinking a load to a place where
we'd have to insert virtual PHIs to make the virtual operand SSA
web OK.

PR tree-optimization/115149
* tree-ssa-live.cc (virtual_operand_live::get_live_in):
Explicitly track the first processed edge.

* gcc.dg/pr115149.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/pr115149.c | 16 
 gcc/tree-ssa-live.cc|  8 ++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr115149.c b/gcc/testsuite/gcc.dg/pr115149.c
new file mode 100644
index 000..9f6bc97dbe6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr115149.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fno-inline -fno-tree-vrp -fno-ipa-sra -fno-tree-dce 
-fno-tree-ch" } */
+
+int a, c, e, f, g, h[1], i;
+static int j(int b) { return 0; }
+static void k(int d) {}
+int main()
+{
+  if (h[0])
+while (1) {
+   k(f && j(i && (h[g] = e)));
+   while (a)
+ c ^= 1;
+}
+  return 0;
+}
diff --git a/gcc/tree-ssa-live.cc b/gcc/tree-ssa-live.cc
index e6ae551a457..60dfc05dcd9 100644
--- a/gcc/tree-ssa-live.cc
+++ b/gcc/tree-ssa-live.cc
@@ -1675,14 +1675,18 @@ virtual_operand_live::get_live_in (basic_block bb)
   edge_iterator ei;
   edge e;
   tree livein = NULL_TREE;
+  bool first = true;
   FOR_EACH_EDGE (e, ei, bb->preds)
 if (e->flags & EDGE_DFS_BACK)
   /* We can ignore backedges since if there's a def there it would
 have forced a PHI in the source because it also acts as use
 downstream.  */
   continue;
-else if (!livein)
-  livein = get_live_out (e->src);
+else if (first)
+  {
+   livein = get_live_out (e->src);
+   first = false;
+  }
 else if (get_live_out (e->src) != livein)
   /* When there's no virtual use downstream this indicates a point
 where we'd insert a PHI merging the different live virtual


[gcc r13-8782] Bump BASE-VER.

2024-05-21 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:bde589428198cd4a24fe6327a73a68c1a46e2a10

commit r13-8782-gbde589428198cd4a24fe6327a73a68c1a46e2a10
Author: Jakub Jelinek 
Date:   Tue May 21 10:56:25 2024 +0200

Bump BASE-VER.

2024-05-21  Jakub Jelinek  

* BASE-VER: Set to 13.3.1.

Diff:
---
 gcc/BASE-VER | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/BASE-VER b/gcc/BASE-VER
index ac565bc1cab..c3d10c59d83 100644
--- a/gcc/BASE-VER
+++ b/gcc/BASE-VER
@@ -1 +1 @@
-13.3.0
+13.3.1


[gcc r15-751] Fix Ada runtime library breakage on Solaris (bis)

2024-05-21 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:7b215c867629e095a4ac403bd026b6eb293962b4

commit r15-751-g7b215c867629e095a4ac403bd026b6eb293962b4
Author: Eric Botcazou 
Date:   Tue May 21 11:11:02 2024 +0200

Fix Ada runtime library breakage on Solaris (bis)

Recent changes made to the runtime library broke again its build on Solaris
because it uses Solaris threads instead of POSIX threads on this platform.

gcc/ada/
PR ada/115168
* libgnarl/s-taprop__solaris.adb (Initialize): Fix pasto.
* libgnat/s-oslock__solaris.ads (Owner_Int): Delete.
(Owner_ID): Change the designated type to Integer.

Diff:
---
 gcc/ada/libgnarl/s-taprop__solaris.adb | 2 +-
 gcc/ada/libgnat/s-oslock__solaris.ads  | 5 +
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/libgnarl/s-taprop__solaris.adb 
b/gcc/ada/libgnarl/s-taprop__solaris.adb
index 09f90e6e204..6d05e8db004 100644
--- a/gcc/ada/libgnarl/s-taprop__solaris.adb
+++ b/gcc/ada/libgnarl/s-taprop__solaris.adb
@@ -424,7 +424,7 @@ package body System.Task_Primitives.Operations is
 
begin
   Environment_Task_Id := Environment_Task;
-  Self_ID.Common.LL.Thread := thr_self;
+  Environment_Task.Common.LL.Thread := thr_self;
 
   Interrupt_Management.Initialize;
 
diff --git a/gcc/ada/libgnat/s-oslock__solaris.ads 
b/gcc/ada/libgnat/s-oslock__solaris.ads
index cc5a83df02e..56a242c8070 100644
--- a/gcc/ada/libgnat/s-oslock__solaris.ads
+++ b/gcc/ada/libgnat/s-oslock__solaris.ads
@@ -42,10 +42,7 @@ package System.OS_Locks is
type Private_Task_Serial_Number is mod 2 ** Long_Long_Integer'Size;
--  Used to give each task a unique serial number
 
-   type Owner_Int is new Integer;
-   for Owner_Int'Alignment use Standard'Maximum_Alignment;
-
-   type Owner_ID is access all Owner_Int;
+   type Owner_ID is access all Integer;
 
function To_Owner_ID is
  new Ada.Unchecked_Conversion (System.Address, Owner_ID);


[gcc r15-752] Cache the set of EH_RETURN_DATA_REGNOs

2024-05-21 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:7f35863ebbf7ba63e2f075edfbec105de272578a

commit r15-752-g7f35863ebbf7ba63e2f075edfbec105de272578a
Author: Richard Sandiford 
Date:   Tue May 21 10:21:16 2024 +0100

Cache the set of EH_RETURN_DATA_REGNOs

While reviewing Andrew's fix for PR114843, it seemed like it would
be convenient to have a HARD_REG_SET of EH_RETURN_DATA_REGNOs.
This patch adds one and uses it to simplify a couple of use sites.

gcc/
* hard-reg-set.h (target_hard_regs::x_eh_return_data_regs): New 
field.
(eh_return_data_regs): New macro.
* reginfo.cc (init_reg_sets_1): Initialize x_eh_return_data_regs.
* df-scan.cc (df_get_exit_block_use_set): Use it.
* ira-lives.cc (process_out_of_region_eh_regs): Likewise.

Diff:
---
 gcc/df-scan.cc |  8 +---
 gcc/hard-reg-set.h |  5 +
 gcc/ira-lives.cc   | 10 ++
 gcc/reginfo.cc | 10 ++
 4 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/gcc/df-scan.cc b/gcc/df-scan.cc
index 1bade2cd71e..c8ab3c09cee 100644
--- a/gcc/df-scan.cc
+++ b/gcc/df-scan.cc
@@ -3702,13 +3702,7 @@ df_get_exit_block_use_set (bitmap exit_block_uses)
 
   /* Mark the registers that will contain data for the handler.  */
   if (reload_completed && crtl->calls_eh_return)
-for (i = 0; ; ++i)
-  {
-   unsigned regno = EH_RETURN_DATA_REGNO (i);
-   if (regno == INVALID_REGNUM)
- break;
-   bitmap_set_bit (exit_block_uses, regno);
-  }
+IOR_REG_SET_HRS (exit_block_uses, eh_return_data_regs);
 
 #ifdef EH_RETURN_STACKADJ_RTX
   if ((!targetm.have_epilogue () || ! epilogue_completed)
diff --git a/gcc/hard-reg-set.h b/gcc/hard-reg-set.h
index 8c1d1512ca2..340eb425c10 100644
--- a/gcc/hard-reg-set.h
+++ b/gcc/hard-reg-set.h
@@ -421,6 +421,9 @@ struct target_hard_regs {
  with the local stack frame are safe, but scant others.  */
   HARD_REG_SET x_regs_invalidated_by_call;
 
+  /* The set of registers that are used by EH_RETURN_DATA_REGNO.  */
+  HARD_REG_SET x_eh_return_data_regs;
+
   /* Table of register numbers in the order in which to try to use them.  */
   int x_reg_alloc_order[FIRST_PSEUDO_REGISTER];
 
@@ -485,6 +488,8 @@ extern struct target_hard_regs *this_target_hard_regs;
 #define call_used_or_fixed_regs \
   (regs_invalidated_by_call | fixed_reg_set)
 #endif
+#define eh_return_data_regs \
+  (this_target_hard_regs->x_eh_return_data_regs)
 #define reg_alloc_order \
   (this_target_hard_regs->x_reg_alloc_order)
 #define inv_reg_alloc_order \
diff --git a/gcc/ira-lives.cc b/gcc/ira-lives.cc
index e07d3dc3e89..958eabb9708 100644
--- a/gcc/ira-lives.cc
+++ b/gcc/ira-lives.cc
@@ -1260,14 +1260,8 @@ process_out_of_region_eh_regs (basic_block bb)
   for (int n = ALLOCNO_NUM_OBJECTS (a) - 1; n >= 0; n--)
{
  ira_object_t obj = ALLOCNO_OBJECT (a, n);
- for (int k = 0; ; k++)
-   {
- unsigned int regno = EH_RETURN_DATA_REGNO (k);
- if (regno == INVALID_REGNUM)
-   break;
- SET_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno);
- SET_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno);
-   }
+ OBJECT_CONFLICT_HARD_REGS (obj) |= eh_return_data_regs;
+ OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) |= eh_return_data_regs;
}
 }
 }
diff --git a/gcc/reginfo.cc b/gcc/reginfo.cc
index a0baeb90e12..73121365c47 100644
--- a/gcc/reginfo.cc
+++ b/gcc/reginfo.cc
@@ -420,6 +420,16 @@ init_reg_sets_1 (void)
}
 }
 
+  /* Recalculate eh_return_data_regs.  */
+  CLEAR_HARD_REG_SET (eh_return_data_regs);
+  for (i = 0; ; ++i)
+{
+  unsigned int regno = EH_RETURN_DATA_REGNO (i);
+  if (regno == INVALID_REGNUM)
+   break;
+  SET_HARD_REG_BIT (eh_return_data_regs, regno);
+}
+
   memset (have_regs_of_mode, 0, sizeof (have_regs_of_mode));
   memset (contains_reg_of_mode, 0, sizeof (contains_reg_of_mode));
   for (m = 0; m < (unsigned int) MAX_MACHINE_MODE; m++)


[gcc r15-753] tree-optimization/115137 - more ptr-vs-ptr compare fixes

2024-05-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:85f7828679edc3ae7488594145756cd53787650e

commit r15-753-g85f7828679edc3ae7488594145756cd53787650e
Author: Richard Biener 
Date:   Tue May 21 10:12:40 2024 +0200

tree-optimization/115137 - more ptr-vs-ptr compare fixes

The following fixes the omission of const-pool included in NONLOCAL.

PR tree-optimization/115137
* tree-ssa-structalias.cc (pt_solution_includes_const_pool): 
NONLOCAL
also includes constant pool entries.

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

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr115137.c | 34 +
 gcc/tree-ssa-structalias.cc |  1 +
 2 files changed, 35 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/torture/pr115137.c 
b/gcc/testsuite/gcc.dg/torture/pr115137.c
new file mode 100644
index 000..9cd8ff93633
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr115137.c
@@ -0,0 +1,34 @@
+/* { dg-do run } */
+
+struct a {
+  int b;
+} c;
+
+int d;
+long e;
+
+static void f(char *g, char *h, struct a *l) {
+  char a[1024];
+  int j = 0;
+
+  if (d)
+h = a;
+
+  for (; g < h; g++)
+if (__builtin_iscntrl(*g))
+  ++j;
+
+  while (l->b < j)
+;
+}
+
+int main() {
+  static const struct {
+char *input;
+  } k[] = {{"somepage.html"}, {""}};
+
+  for (unsigned int i = 0; i < 1; ++i) {
+e = __builtin_strlen(k[i].input);
+f(k[i].input, k[i].input + e, &c);
+  }
+}
diff --git a/gcc/tree-ssa-structalias.cc b/gcc/tree-ssa-structalias.cc
index 61fb3610a17..0e9423a78ec 100644
--- a/gcc/tree-ssa-structalias.cc
+++ b/gcc/tree-ssa-structalias.cc
@@ -7087,6 +7087,7 @@ bool
 pt_solution_includes_const_pool (struct pt_solution *pt)
 {
   return (pt->const_pool
+ || pt->nonlocal
  || (pt->escaped && (!cfun || cfun->gimple_df->escaped.const_pool))
  || (pt->ipa_escaped && ipa_escaped_pt.const_pool));
 }


[gcc r15-754] modula2: Pass --destdir for dir index during install of m2.info.

2024-05-21 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:232a86f9640cde6908d0875b8df52c36030c5b5e

commit r15-754-g232a86f9640cde6908d0875b8df52c36030c5b5e
Author: Sam James 
Date:   Tue May 21 12:31:47 2024 +0100

modula2: Pass --destdir for dir index during install of m2.info.

This patch adds DESTDIR to the infodir when installing m2.info.

gcc/m2/ChangeLog

* Make-lang.in (m2.install-info): Pass --destdir for dir index.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/Make-lang.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index 0abd8ce1455..da4226123df 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -425,7 +425,7 @@ m2.install-info: installdirs
else true; fi
-if [ -f gm2$(exeext) ] && [ -f $(DESTDIR)$(infodir)/m2.info ]; then \
  if $(SHELL) -c 'install-info --version' >/dev/null 2>&1; then \
-   install-info --dir-file=$(infodir)/dir 
$(DESTDIR)$(infodir)/m2.info; \
+   install-info --dir-file=$(DESTDIR)$(infodir)/dir 
$(DESTDIR)$(infodir)/m2.info; \
  else true; fi; \
else true; fi


[gcc r15-755] match: Disable `(type)zero_one_valuep*CST` for 1bit signed types [PR115154]

2024-05-21 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:49c87d22535ac4f8aacf088b3f462861c26cacb4

commit r15-755-g49c87d22535ac4f8aacf088b3f462861c26cacb4
Author: Andrew Pinski 
Date:   Mon May 20 00:16:40 2024 -0700

match: Disable `(type)zero_one_valuep*CST` for 1bit signed types [PR115154]

The problem here is the pattern added in r13-1162-g9991d84d2a8435
assumes that it is well defined to multiply zero_one_valuep by the truncated
converted integer constant. It is well defined for all types except for 
signed 1bit types.
Where `a * -1` is produced which is undefined/
So disable this pattern for 1bit signed types.

Note the pattern added in r14-3432-gddd64a6ec3b38e is able to workaround 
the undefinedness except when
`-fsanitize=undefined` is turned on, this is why I added a testcase for 
that.

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

PR tree-optimization/115154

gcc/ChangeLog:

* match.pd (convert (mult zero_one_valued_p@1 INTEGER_CST@2)): 
Disable
for 1bit signed types.

gcc/testsuite/ChangeLog:

* c-c++-common/ubsan/signed1bitfield-1.c: New test.
* gcc.c-torture/execute/signed1bitfield-1.c: New test.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/match.pd   |  6 --
 .../c-c++-common/ubsan/signed1bitfield-1.c | 25 ++
 .../gcc.c-torture/execute/signed1bitfield-1.c  | 23 
 3 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 0f9c34fa897..35e3d82b131 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2395,12 +2395,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (mult (convert @0) @1)))
 
 /* Narrow integer multiplication by a zero_one_valued_p operand.
-   Multiplication by [0,1] is guaranteed not to overflow.  */
+   Multiplication by [0,1] is guaranteed not to overflow except for
+   1bit signed types.  */
 (simplify
  (convert (mult@0 zero_one_valued_p@1 INTEGER_CST@2))
  (if (INTEGRAL_TYPE_P (type)
   && INTEGRAL_TYPE_P (TREE_TYPE (@0))
-  && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@0)))
+  && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@0))
+  && (TYPE_UNSIGNED (type) || TYPE_PRECISION (type) > 1))
   (mult (convert @1) (convert @2
 
 /* (X << C) != 0 can be simplified to X, when C is zero_one_valued_p.
diff --git a/gcc/testsuite/c-c++-common/ubsan/signed1bitfield-1.c 
b/gcc/testsuite/c-c++-common/ubsan/signed1bitfield-1.c
new file mode 100644
index 000..2ba8cf4dab0
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/signed1bitfield-1.c
@@ -0,0 +1,25 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -fsanitize=undefined" } */
+
+/* PR tree-optimization/115154 */
+/* This was being miscompiled with -fsanitize=undefined due to
+   `(signed:1)(t*5)` being transformed into `-((signed:1)t)` which
+   is undefined. */
+
+struct s {
+  signed b : 1;
+} f;
+int i = 55;
+__attribute__((noinline))
+void check(int a)
+{
+if (!a)
+__builtin_abort();
+}
+int main() {
+int t = i != 5;
+t = t*5;
+f.b = t;
+int tt = f.b;
+check(f.b);
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/signed1bitfield-1.c 
b/gcc/testsuite/gcc.c-torture/execute/signed1bitfield-1.c
new file mode 100644
index 000..ab888ca3a04
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/signed1bitfield-1.c
@@ -0,0 +1,23 @@
+/* PR tree-optimization/115154 */
+/* This was being miscompiled to `(signed:1)(t*5)`
+   being transformed into `-((signed:1)t)` which is undefined.
+   Note there is a pattern which removes the negative in some cases
+   which works around the issue.  */
+
+struct {
+  signed b : 1;
+} f;
+int i = 55;
+__attribute__((noinline))
+void check(int a)
+{
+if (!a)
+__builtin_abort();
+}
+int main() {
+int t = i != 5;
+t = t*5;
+f.b = t;
+int tt = f.b;
+check(f.b);
+}


[gcc r14-10224] match: Disable `(type)zero_one_valuep*CST` for 1bit signed types [PR115154]

2024-05-21 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:b2bb49d6a77e4568c0b91db17b2599f5929fb85b

commit r14-10224-gb2bb49d6a77e4568c0b91db17b2599f5929fb85b
Author: Andrew Pinski 
Date:   Mon May 20 00:16:40 2024 -0700

match: Disable `(type)zero_one_valuep*CST` for 1bit signed types [PR115154]

The problem here is the pattern added in r13-1162-g9991d84d2a8435
assumes that it is well defined to multiply zero_one_valuep by the truncated
converted integer constant. It is well defined for all types except for 
signed 1bit types.
Where `a * -1` is produced which is undefined/
So disable this pattern for 1bit signed types.

Note the pattern added in r14-3432-gddd64a6ec3b38e is able to workaround 
the undefinedness except when
`-fsanitize=undefined` is turned on, this is why I added a testcase for 
that.

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

PR tree-optimization/115154

gcc/ChangeLog:

* match.pd (convert (mult zero_one_valued_p@1 INTEGER_CST@2)): 
Disable
for 1bit signed types.

gcc/testsuite/ChangeLog:

* c-c++-common/ubsan/signed1bitfield-1.c: New test.
* gcc.c-torture/execute/signed1bitfield-1.c: New test.

Signed-off-by: Andrew Pinski 
(cherry picked from commit 49c87d22535ac4f8aacf088b3f462861c26cacb4)

Diff:
---
 gcc/match.pd   |  6 --
 .../c-c++-common/ubsan/signed1bitfield-1.c | 25 ++
 .../gcc.c-torture/execute/signed1bitfield-1.c  | 23 
 3 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index d401e7503e6..4a0aa80cee1 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2395,12 +2395,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (mult (convert @0) @1)))
 
 /* Narrow integer multiplication by a zero_one_valued_p operand.
-   Multiplication by [0,1] is guaranteed not to overflow.  */
+   Multiplication by [0,1] is guaranteed not to overflow except for
+   1bit signed types.  */
 (simplify
  (convert (mult@0 zero_one_valued_p@1 INTEGER_CST@2))
  (if (INTEGRAL_TYPE_P (type)
   && INTEGRAL_TYPE_P (TREE_TYPE (@0))
-  && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@0)))
+  && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@0))
+  && (TYPE_UNSIGNED (type) || TYPE_PRECISION (type) > 1))
   (mult (convert @1) (convert @2
 
 /* (X << C) != 0 can be simplified to X, when C is zero_one_valued_p.
diff --git a/gcc/testsuite/c-c++-common/ubsan/signed1bitfield-1.c 
b/gcc/testsuite/c-c++-common/ubsan/signed1bitfield-1.c
new file mode 100644
index 000..2ba8cf4dab0
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/signed1bitfield-1.c
@@ -0,0 +1,25 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -fsanitize=undefined" } */
+
+/* PR tree-optimization/115154 */
+/* This was being miscompiled with -fsanitize=undefined due to
+   `(signed:1)(t*5)` being transformed into `-((signed:1)t)` which
+   is undefined. */
+
+struct s {
+  signed b : 1;
+} f;
+int i = 55;
+__attribute__((noinline))
+void check(int a)
+{
+if (!a)
+__builtin_abort();
+}
+int main() {
+int t = i != 5;
+t = t*5;
+f.b = t;
+int tt = f.b;
+check(f.b);
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/signed1bitfield-1.c 
b/gcc/testsuite/gcc.c-torture/execute/signed1bitfield-1.c
new file mode 100644
index 000..ab888ca3a04
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/signed1bitfield-1.c
@@ -0,0 +1,23 @@
+/* PR tree-optimization/115154 */
+/* This was being miscompiled to `(signed:1)(t*5)`
+   being transformed into `-((signed:1)t)` which is undefined.
+   Note there is a pattern which removes the negative in some cases
+   which works around the issue.  */
+
+struct {
+  signed b : 1;
+} f;
+int i = 55;
+__attribute__((noinline))
+void check(int a)
+{
+if (!a)
+__builtin_abort();
+}
+int main() {
+int t = i != 5;
+t = t*5;
+f.b = t;
+int tt = f.b;
+check(f.b);
+}


[gcc r13-8783] match: Disable `(type)zero_one_valuep*CST` for 1bit signed types [PR115154]

2024-05-21 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:d6cf49eaf5ac237c57785dce42c89deac911affa

commit r13-8783-gd6cf49eaf5ac237c57785dce42c89deac911affa
Author: Andrew Pinski 
Date:   Mon May 20 00:16:40 2024 -0700

match: Disable `(type)zero_one_valuep*CST` for 1bit signed types [PR115154]

The problem here is the pattern added in r13-1162-g9991d84d2a8435
assumes that it is well defined to multiply zero_one_valuep by the truncated
converted integer constant. It is well defined for all types except for 
signed 1bit types.
Where `a * -1` is produced which is undefined/
So disable this pattern for 1bit signed types.

Note the pattern added in r14-3432-gddd64a6ec3b38e is able to workaround 
the undefinedness except when
`-fsanitize=undefined` is turned on, this is why I added a testcase for 
that.

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

PR tree-optimization/115154

gcc/ChangeLog:

* match.pd (convert (mult zero_one_valued_p@1 INTEGER_CST@2)): 
Disable
for 1bit signed types.

gcc/testsuite/ChangeLog:

* c-c++-common/ubsan/signed1bitfield-1.c: New test.
* gcc.c-torture/execute/signed1bitfield-1.c: New test.

Signed-off-by: Andrew Pinski 
(cherry picked from commit 49c87d22535ac4f8aacf088b3f462861c26cacb4)

Diff:
---
 gcc/match.pd   |  6 --
 .../c-c++-common/ubsan/signed1bitfield-1.c | 25 ++
 .../gcc.c-torture/execute/signed1bitfield-1.c  | 23 
 3 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index dc34e7ead9f..fda4a211efc 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2023,12 +2023,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (mult (convert @0) @1)))
 
 /* Narrow integer multiplication by a zero_one_valued_p operand.
-   Multiplication by [0,1] is guaranteed not to overflow.  */
+   Multiplication by [0,1] is guaranteed not to overflow except for
+   1bit signed types.  */
 (simplify
  (convert (mult@0 zero_one_valued_p@1 INTEGER_CST@2))
  (if (INTEGRAL_TYPE_P (type)
   && INTEGRAL_TYPE_P (TREE_TYPE (@0))
-  && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@0)))
+  && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@0))
+  && (TYPE_UNSIGNED (type) || TYPE_PRECISION (type) > 1))
   (mult (convert @1) (convert @2
 
 /* (X << C) != 0 can be simplified to X, when C is zero_one_valued_p.
diff --git a/gcc/testsuite/c-c++-common/ubsan/signed1bitfield-1.c 
b/gcc/testsuite/c-c++-common/ubsan/signed1bitfield-1.c
new file mode 100644
index 000..2ba8cf4dab0
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/signed1bitfield-1.c
@@ -0,0 +1,25 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -fsanitize=undefined" } */
+
+/* PR tree-optimization/115154 */
+/* This was being miscompiled with -fsanitize=undefined due to
+   `(signed:1)(t*5)` being transformed into `-((signed:1)t)` which
+   is undefined. */
+
+struct s {
+  signed b : 1;
+} f;
+int i = 55;
+__attribute__((noinline))
+void check(int a)
+{
+if (!a)
+__builtin_abort();
+}
+int main() {
+int t = i != 5;
+t = t*5;
+f.b = t;
+int tt = f.b;
+check(f.b);
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/signed1bitfield-1.c 
b/gcc/testsuite/gcc.c-torture/execute/signed1bitfield-1.c
new file mode 100644
index 000..ab888ca3a04
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/signed1bitfield-1.c
@@ -0,0 +1,23 @@
+/* PR tree-optimization/115154 */
+/* This was being miscompiled to `(signed:1)(t*5)`
+   being transformed into `-((signed:1)t)` which is undefined.
+   Note there is a pattern which removes the negative in some cases
+   which works around the issue.  */
+
+struct {
+  signed b : 1;
+} f;
+int i = 55;
+__attribute__((noinline))
+void check(int a)
+{
+if (!a)
+__builtin_abort();
+}
+int main() {
+int t = i != 5;
+t = t*5;
+f.b = t;
+int tt = f.b;
+check(f.b);
+}


[gcc r13-8784] PHIOPT: Don't transform minmax if middle bb contains a phi [PR115143]

2024-05-21 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:3f6a42510a1bd4b004ed70ac44cdad2770b732a8

commit r13-8784-g3f6a42510a1bd4b004ed70ac44cdad2770b732a8
Author: Andrew Pinski 
Date:   Sat May 18 11:55:58 2024 -0700

PHIOPT: Don't transform minmax if middle bb contains a phi [PR115143]

The problem here is even if last_and_only_stmt returns a statement,
the bb might still contain a phi node which defines a ssa name
which is used in that statement so we need to add a check to make sure
that the phi nodes are empty for the middle bbs in both the
`CMP?MINMAX:MINMAX` case and the `CMP?MINMAX:B` cases.

Bootstrapped and tested on x86_64_linux-gnu with no regressions.

PR tree-optimization/115143

gcc/ChangeLog:

* tree-ssa-phiopt.cc (minmax_replacement): Check for empty
phi nodes for middle bbs for the case where middle bb is not empty.

gcc/testsuite/ChangeLog:

* gcc.c-torture/compile/pr115143-1.c: New test.
* gcc.c-torture/compile/pr115143-2.c: New test.
* gcc.c-torture/compile/pr115143-3.c: New test.

Signed-off-by: Andrew Pinski 
(cherry picked from commit 9ff8f041331ef8b56007fb3c4d41d76f9850010d)

Diff:
---
 gcc/testsuite/gcc.c-torture/compile/pr115143-1.c | 21 +
 gcc/testsuite/gcc.c-torture/compile/pr115143-2.c | 30 
 gcc/testsuite/gcc.c-torture/compile/pr115143-3.c | 29 +++
 gcc/tree-ssa-phiopt.cc   | 12 ++
 4 files changed, 92 insertions(+)

diff --git a/gcc/testsuite/gcc.c-torture/compile/pr115143-1.c 
b/gcc/testsuite/gcc.c-torture/compile/pr115143-1.c
new file mode 100644
index 000..5cb119ea432
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr115143-1.c
@@ -0,0 +1,21 @@
+/* PR tree-optimization/115143 */
+/* This used to ICE.
+   minmax part of phiopt would transform,
+   would transform `a!=0?min(a, b) : 0` into `min(a,b)`
+   which was correct except b was defined by a phi in the inner
+   bb which was not handled. */
+short a, d;
+char b;
+long c;
+unsigned long e, f;
+void g(unsigned long h) {
+  if (c ? e : b)
+if (e)
+  if (d) {
+a = f ? ({
+  unsigned long i = d ? f : 0, j = e ? h : 0;
+  i < j ? i : j;
+}) : 0;
+  }
+}
+
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr115143-2.c 
b/gcc/testsuite/gcc.c-torture/compile/pr115143-2.c
new file mode 100644
index 000..05c3bbe9738
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr115143-2.c
@@ -0,0 +1,30 @@
+/* { dg-options "-fgimple" } */
+/* PR tree-optimization/115143 */
+/* This used to ICE.
+   minmax part of phiopt would transform,
+   would transform `a!=0?min(a, b) : 0` into `min(a,b)`
+   which was correct except b was defined by a phi in the inner
+   bb which was not handled. */
+unsigned __GIMPLE (ssa,startwith("phiopt"))
+foo (unsigned a, unsigned b)
+{
+  unsigned j;
+  unsigned _23;
+  unsigned _12;
+
+  __BB(2):
+  if (a_6(D) != 0u)
+goto __BB3;
+  else
+goto __BB4;
+
+  __BB(3):
+  j_10 = __PHI (__BB2: b_11(D));
+  _23 = __MIN (a_6(D), j_10);
+  goto __BB4;
+
+  __BB(4):
+  _12 = __PHI (__BB3: _23, __BB2: 0u);
+  return _12;
+
+}
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr115143-3.c 
b/gcc/testsuite/gcc.c-torture/compile/pr115143-3.c
new file mode 100644
index 000..53c5fb5588e
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr115143-3.c
@@ -0,0 +1,29 @@
+/* { dg-options "-fgimple" } */
+/* PR tree-optimization/115143 */
+/* This used to ICE.
+   minmax part of phiopt would transform,
+   would transform `a!=0?min(a, b) : 0` into `min(a,b)`
+   which was correct except b was defined by a phi in the inner
+   bb which was not handled. */
+unsigned __GIMPLE (ssa,startwith("phiopt"))
+foo (unsigned a, unsigned b)
+{
+  unsigned j;
+  unsigned _23;
+  unsigned _12;
+
+  __BB(2):
+  if (a_6(D) > 0u)
+goto __BB3;
+  else
+goto __BB4;
+
+  __BB(3):
+  j_10 = __PHI (__BB2: b_7(D));
+  _23 = __MIN (a_6(D), j_10);
+  goto __BB4;
+
+  __BB(4):
+  _12 = __PHI (__BB3: _23, __BB2: 0u);
+  return _12;
+}
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index c3d78d1400b..d507530307a 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -2106,6 +2106,10 @@ minmax_replacement (basic_block cond_bb, basic_block 
middle_bb, basic_block alt_
  || gimple_code (assign) != GIMPLE_ASSIGN)
return false;
 
+  /* There cannot be any phi nodes in the middle bb. */
+  if (!gimple_seq_empty_p (phi_nodes (middle_bb)))
+   return false;
+
   lhs = gimple_assign_lhs (assign);
   ass_code = gimple_assign_rhs_code (assign);
   if (ass_code != MAX_EXPR && ass_code != MIN_EXPR)
@@ -2119,6 +2123,10 @@ minmax_replacement (basic_block cond_bb, basic_block 
middle_bb, basic_block alt_
  || gimple_code (assign) != GIMPLE_ASSIGN)
return false;
 
+  /* There cannot be any 

[gcc r15-756] modula2: use groups in the type resolver of the bootstrap tool mc

2024-05-21 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:20e6f36771df7e3a8857628dd367eecfe77ba4fc

commit r15-756-g20e6f36771df7e3a8857628dd367eecfe77ba4fc
Author: Gaius Mulley 
Date:   Tue May 21 15:46:46 2024 +0100

modula2: use groups in the type resolver of the bootstrap tool mc

This patch introduces groups to maintain the lists used when resolving
types in the bootstrap tool mc.  The groups and type resolver are very
similar to that used in cc1gm2.  Specifically the resolver uses the group
to detect any change to any element in any list within a group.  This is
much cleaner and safer than the previous list length comparisons.

gcc/m2/ChangeLog:

* Make-lang.in (MC_EXTENDED_OPAQUE): New definition.
* mc-boot/GDynamicStrings.cc: Rebuild.
* mc-boot/GDynamicStrings.h: Rebuild.
* mc-boot/Galists.cc: Rebuild.
* mc-boot/Galists.h: Rebuild.
* mc-boot/Gdecl.cc: Rebuild.
* mc/alists.def (equalList): New procedure.
* mc/alists.mod (equalList): New procedure implementation.
* mc/decl.mod (group): New type.
(freeGroup): New variable.
(globalGroup): Ditto.
(todoQ): Remove declaration and prefix all occurances with 
globalGroup^.
(partialQ): Ditto.
(doneQ): Ditto.
(newGroup): New procedure.
(initGroup): Ditto.
(killGroup): Ditto.
(dupGroup): Ditto.
(equalGroup): Ditto.
(topologicallyOut): Rewrite.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/Make-lang.in   |   5 +-
 gcc/m2/mc-boot/GDynamicStrings.cc |  74 -
 gcc/m2/mc-boot/GDynamicStrings.h  |  17 +-
 gcc/m2/mc-boot/Galists.cc |  43 +
 gcc/m2/mc-boot/Galists.h  |   6 +
 gcc/m2/mc-boot/Gdecl.cc   | 319 +++---
 gcc/m2/mc/alists.def  |   7 +
 gcc/m2/mc/alists.mod  |  28 
 gcc/m2/mc/decl.mod| 218 ++
 9 files changed, 552 insertions(+), 165 deletions(-)

diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index da4226123df..83d592f35d8 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -505,6 +505,7 @@ MC_ARGS= --olang=c++ \
  $(MC_COPYRIGHT) \
  --gcc-config-system
 
+MC_EXTENDED_OPAQUE=--extended-opaque
 MCDEPS=m2/boot-bin/mc$(exeext)
 
 MC=m2/boot-bin/mc$(exeext) $(MC_ARGS)
@@ -1539,7 +1540,7 @@ m2/gm2-libs-boot/SysStorage.o: 
$(srcdir)/m2/gm2-libs/SysStorage.mod $(MCDEPS) $(
 
 m2/gm2-compiler-boot/M2GCCDeclare.o: 
$(srcdir)/m2/gm2-compiler/M2GCCDeclare.mod $(MCDEPS) $(BUILD-BOOT-H)
-test -d $(@D)/$(DEPDIR) || $(mkinstalldirs) $(@D)/$(DEPDIR)
-   $(MC) --extended-opaque -o=m2/gm2-compiler-boot/M2GCCDeclare.c $<
+   $(MC) $(MC_EXTENDED_OPAQUE) -o=m2/gm2-compiler-boot/M2GCCDeclare.c $<
$(COMPILER) $(CM2DEP) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(GM2GCC) 
\
 -I. -I$(srcdir)/../include -I$(srcdir) \
 -I. -Im2/gm2-libs-boot -Im2/gm2-compiler-boot \
@@ -1548,7 +1549,7 @@ m2/gm2-compiler-boot/M2GCCDeclare.o: 
$(srcdir)/m2/gm2-compiler/M2GCCDeclare.mod
 
 m2/gm2-compiler-boot/M2Error.o: $(srcdir)/m2/gm2-compiler/M2Error.mod 
$(MCDEPS) $(BUILD-BOOT-H)
-test -d $(@D)/$(DEPDIR) || $(mkinstalldirs) $(@D)/$(DEPDIR)
-   $(MC) --extended-opaque -o=m2/gm2-compiler-boot/M2Error.c $<
+   $(MC) $(MC_EXTENDED_OPAQUE) -o=m2/gm2-compiler-boot/M2Error.c $<
$(COMPILER) $(CM2DEP) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(GM2GCC) 
\
 -I. -I$(srcdir)/../include -I$(srcdir) \
 -I. -Im2/gm2-libs-boot -Im2/gm2-compiler-boot \
diff --git a/gcc/m2/mc-boot/GDynamicStrings.cc 
b/gcc/m2/mc-boot/GDynamicStrings.cc
index 7f61778af64..a1cb88c03b7 100644
--- a/gcc/m2/mc-boot/GDynamicStrings.cc
+++ b/gcc/m2/mc-boot/GDynamicStrings.cc
@@ -255,12 +255,25 @@ extern "C" int DynamicStrings_Index 
(DynamicStrings_String s, char ch, unsigned
 
 /*
RIndex - returns the indice of the last occurance of, ch,
-in String, s. The search starts at position, o.
--1 is returned if, ch, is not found.
+in String, s.  The search starts at position, o.
+-1 is returned if, ch, is not found.  The search
+is performed left to right.
 */
 
 extern "C" int DynamicStrings_RIndex (DynamicStrings_String s, char ch, 
unsigned int o);
 
+/*
+   ReverseIndex - returns the indice of the last occurance of ch
+  in String s.  The search starts at position o
+  and searches from right to left.  The start position
+  may be indexed negatively from the right (-1 is the
+  last index).
+  The return value if ch is found will always be positive.
+  -1 is returned if ch is not found.
+*/
+
+extern "C" int DynamicStrings_ReverseIndex (DynamicStrings_String s, char ch, 
int o);
+
 /

[gcc r13-8785] testsuite: Adjust pr113359-2_*.c with unsigned long long [PR114662]

2024-05-21 Thread Martin Jambor via Gcc-cvs
https://gcc.gnu.org/g:c827f46d8652d7a089e614302a4cffb6b192284d

commit r13-8785-gc827f46d8652d7a089e614302a4cffb6b192284d
Author: Kewen Lin 
Date:   Wed Apr 10 02:59:43 2024 -0500

testsuite: Adjust pr113359-2_*.c with unsigned long long [PR114662]

pr113359-2_*.c define a struct having unsigned long type
members ay and az which have 4 bytes size at -m32, while
the related constants CL1 and CL2 used for equality check
are always 8 bytes, it makes compiler consider the below

  69   if (a.ay != CL1)
  70 __builtin_abort ();

always to abort and optimize away the following call to
getb, which leads to the expected wpa dumping on
"Semantic equality" missing.

This patch is to modify the types with unsigned long long
accordingly.

PR testsuite/114662

gcc/testsuite/ChangeLog:

* gcc.dg/lto/pr113359-2_0.c: Use unsigned long long instead of
unsigned long.
* gcc.dg/lto/pr113359-2_1.c: Likewise.

(cherry picked from commit 4923ed49b93352bcf9e43cafac38345e4a54c3f8)

Diff:
---
 gcc/testsuite/gcc.dg/lto/pr113359-2_0.c | 8 
 gcc/testsuite/gcc.dg/lto/pr113359-2_1.c | 8 
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/lto/pr113359-2_0.c 
b/gcc/testsuite/gcc.dg/lto/pr113359-2_0.c
index 8b2d5bdfab2..8495667599d 100644
--- a/gcc/testsuite/gcc.dg/lto/pr113359-2_0.c
+++ b/gcc/testsuite/gcc.dg/lto/pr113359-2_0.c
@@ -8,15 +8,15 @@
 struct SA
 {
   unsigned int ax;
-  unsigned long ay;
-  unsigned long az;
+  unsigned long long ay;
+  unsigned long long az;
 };
 
 struct SB
 {
   unsigned int bx;
-  unsigned long by;
-  unsigned long bz;
+  unsigned long long by;
+  unsigned long long bz;
 };
 
 struct ZA
diff --git a/gcc/testsuite/gcc.dg/lto/pr113359-2_1.c 
b/gcc/testsuite/gcc.dg/lto/pr113359-2_1.c
index 61bc0547981..8320f347efe 100644
--- a/gcc/testsuite/gcc.dg/lto/pr113359-2_1.c
+++ b/gcc/testsuite/gcc.dg/lto/pr113359-2_1.c
@@ -5,15 +5,15 @@
 struct SA
 {
   unsigned int ax;
-  unsigned long ay;
-  unsigned long az;
+  unsigned long long ay;
+  unsigned long long az;
 };
 
 struct SB
 {
   unsigned int bx;
-  unsigned long by;
-  unsigned long bz;
+  unsigned long long by;
+  unsigned long long bz;
 };
 
 struct ZA


[gcc r15-757] RISC-V: avoid LUI based const mat in prologue/epilogue expansion [PR/105733]

2024-05-21 Thread Vineet Gupta via Gcc-cvs
https://gcc.gnu.org/g:f9cfc192ed0127edb7e79818917dd2859fce4d44

commit r15-757-gf9cfc192ed0127edb7e79818917dd2859fce4d44
Author: Vineet Gupta 
Date:   Mon May 13 11:46:03 2024 -0700

RISC-V: avoid LUI based const mat in prologue/epilogue expansion [PR/105733]

If the constant used for stack offset can be expressed as sum of two S12
values, the constant need not be materialized (in a reg) and instead the
two S12 bits can be added to instructions involved with frame pointer.
This avoids burning a register and more importantly can often get down
to be 2 insn vs. 3.

The prev patches to generally avoid LUI based const materialization didn't
fix this PR and need this directed fix in funcion prologue/epilogue
expansion.

This fix doesn't move the neddle for SPEC, at all, but it is still a
win considering gcc generates one insn fewer than llvm for the test ;-)

   gcc-13.1 release   |  gcc 230823 |   |
  |g6619b3d4c15c|   This patch  |  
clang/llvm

-
li  t0,-4096 | lit0,-4096  | addi  sp,sp,-2048 | addi 
sp,sp,-2048
addit0,t0,2016   | addi  t0,t0,2032| add   sp,sp,-16   | addi 
sp,sp,-32
li  a4,4096  | add   sp,sp,t0  | add   a5,sp,a0| add  
a1,sp,16
add sp,sp,t0 | addi  a5,sp,-2032   | sbzero,0(a5)  | add  
a0,a0,a1
li  a5,-4096 | add   a0,a5,a0  | addi  sp,sp,2032  | sb   
zero,0(a0)
addia4,a4,-2032  | lit0, 4096  | addi  sp,sp,32| addi 
sp,sp,2032
add a4,a4,a5 | sbzero,2032(a0) | ret   | addi 
sp,sp,48
addia5,sp,16 | addi  t0,t0,-2032   |   | ret
add a5,a4,a5 | add   sp,sp,t0  |
add a0,a5,a0 | ret |
li  t0,4096  |
sd  a5,8(sp) |
sb  zero,2032(a0)|
addit0,t0,-2016  |
add sp,sp,t0 |
ret  |

gcc/ChangeLog:
PR target/105733
* config/riscv/riscv.h: New macros for with aligned offsets.
* config/riscv/riscv.cc (riscv_split_sum_of_two_s12): New
function to split a sum of two s12 values into constituents.
(riscv_expand_prologue): Handle offset being sum of two S12.
(riscv_expand_epilogue): Ditto.
* config/riscv/riscv-protos.h (riscv_split_sum_of_two_s12): New.

gcc/testsuite/ChangeLog:
* gcc.target/riscv/pr105733.c: New Test.
* gcc.target/riscv/rvv/autovec/vls/spill-1.c: Adjust to not
expect LUI 4096.
* gcc.target/riscv/rvv/autovec/vls/spill-2.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/spill-3.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/spill-4.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/spill-5.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/spill-6.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/spill-7.c: Ditto.

Tested-by: Edwin Lu  # pre-commit-CI #1568
Signed-off-by: Vineet Gupta 

Diff:
---
 gcc/config/riscv/riscv-protos.h|  2 +
 gcc/config/riscv/riscv.cc  | 54 --
 gcc/config/riscv/riscv.h   |  7 +++
 gcc/testsuite/gcc.target/riscv/pr105733.c  | 15 ++
 .../gcc.target/riscv/rvv/autovec/vls/spill-1.c |  4 +-
 .../gcc.target/riscv/rvv/autovec/vls/spill-2.c |  4 +-
 .../gcc.target/riscv/rvv/autovec/vls/spill-3.c |  4 +-
 .../gcc.target/riscv/rvv/autovec/vls/spill-4.c |  4 +-
 .../gcc.target/riscv/rvv/autovec/vls/spill-5.c |  4 +-
 .../gcc.target/riscv/rvv/autovec/vls/spill-6.c |  4 +-
 .../gcc.target/riscv/rvv/autovec/vls/spill-7.c |  4 +-
 11 files changed, 89 insertions(+), 17 deletions(-)

diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index c64aae18deb..0704968561b 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -167,6 +167,8 @@ extern void riscv_subword_address (rtx, rtx *, rtx *, rtx 
*, rtx *);
 extern void riscv_lshift_subword (machine_mode, rtx, rtx, rtx *);
 extern enum memmodel riscv_union_memmodels (enum memmodel, enum memmodel);
 extern bool riscv_reg_frame_related (rtx);
+extern void riscv_split_sum_of_two_s12 (HOST_WIDE_INT, HOST_WIDE_INT *,
+   HOST_WIDE_INT *);
 
 /* Routines implemented in riscv-c.cc.  */
 void riscv_cpu_cpp_builtins (cpp_reader *);
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index d0c22058b8c..2ecbcf1d0af 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -4075,6 +4075,32 @@ riscv_split_doubleword_move (rtx dest, rtx src)
riscv_emit_move (riscv_subword (dest, true), riscv_subword (src, true));
  }
 }
+
+/

[gcc r15-758] RISC-V: avoid LUI based const mat in alloca epilogue expansion

2024-05-21 Thread Vineet Gupta via Gcc-cvs
https://gcc.gnu.org/g:9926c40a902edbc665919d508ef0c36f362f9c41

commit r15-758-g9926c40a902edbc665919d508ef0c36f362f9c41
Author: Vineet Gupta 
Date:   Wed Mar 6 15:44:27 2024 -0800

RISC-V: avoid LUI based const mat in alloca epilogue expansion

This is continuing on the prev patch in function epilogue expansion.
Broken out of easy of review.

gcc/ChangeLog:
* config/riscv/riscv.cc (riscv_expand_epilogue): Handle offset
being sum of two S12.

Tested-by: Patrick O'Neill  # pre-commit-CI #1569
Signed-off-by: Vineet Gupta 

Diff:
---
 gcc/config/riscv/riscv.cc | 33 ++---
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 2ecbcf1d0af..85df5b7ab49 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -8111,7 +8111,10 @@ riscv_expand_epilogue (int style)
   need_barrier_p = false;
 
   poly_int64 adjust_offset = -frame->hard_frame_pointer_offset;
+  rtx dwarf_adj = gen_int_mode (adjust_offset, Pmode);
   rtx adjust = NULL_RTX;
+  bool sum_of_two_s12 = false;
+  HOST_WIDE_INT one, two;
 
   if (!adjust_offset.is_constant ())
{
@@ -8123,14 +8126,23 @@ riscv_expand_epilogue (int style)
}
   else
{
- if (!SMALL_OPERAND (adjust_offset.to_constant ()))
+ HOST_WIDE_INT adj_off_value = adjust_offset.to_constant ();
+ if (SMALL_OPERAND (adj_off_value))
+   {
+ adjust = GEN_INT (adj_off_value);
+   }
+ else if (SUM_OF_TWO_S12_ALGN (adj_off_value))
+   {
+ riscv_split_sum_of_two_s12 (adj_off_value, &one, &two);
+ dwarf_adj = adjust = GEN_INT (one);
+ sum_of_two_s12 = true;
+   }
+ else
{
  riscv_emit_move (RISCV_PROLOGUE_TEMP (Pmode),
-  GEN_INT (adjust_offset.to_constant ()));
+  GEN_INT (adj_off_value));
  adjust = RISCV_PROLOGUE_TEMP (Pmode);
}
- else
-   adjust = GEN_INT (adjust_offset.to_constant ());
}
 
   insn = emit_insn (
@@ -8138,14 +8150,21 @@ riscv_expand_epilogue (int style)
  adjust));
 
   rtx dwarf = NULL_RTX;
-  rtx cfa_adjust_value = gen_rtx_PLUS (
-  Pmode, hard_frame_pointer_rtx,
-  gen_int_mode (-frame->hard_frame_pointer_offset, 
Pmode));
+  rtx cfa_adjust_value = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx,
+  dwarf_adj);
   rtx cfa_adjust_rtx = gen_rtx_SET (stack_pointer_rtx, cfa_adjust_value);
   dwarf = alloc_reg_note (REG_CFA_ADJUST_CFA, cfa_adjust_rtx, dwarf);
+
   RTX_FRAME_RELATED_P (insn) = 1;
 
   REG_NOTES (insn) = dwarf;
+
+  if (sum_of_two_s12)
+   {
+ insn = emit_insn (gen_add3_insn (stack_pointer_rtx, stack_pointer_rtx,
+   GEN_INT (two)));
+ RTX_FRAME_RELATED_P (insn) = 1;
+   }
 }
 
   if (use_restore_libcall || use_multi_pop)


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [to-be-committed, RISC-V] Improve some shift-add sequences

2024-05-21 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:03f61ba899a4e1025284ee0de2390363694190cc

commit 03f61ba899a4e1025284ee0de2390363694190cc
Author: Jeff Law 
Date:   Sat May 18 15:08:07 2024 -0600

[to-be-committed,RISC-V] Improve some shift-add sequences

So this is a minor fix/improvement for shift-add sequences.  This was
supposed to help xz in a minor way IIRC.

Combine may present us with (x + C2') << C1 which was canonicalized from
(x << C1) + C2.

Depending on the precise values of C2 and C2' one form may be better
than the other.  We can (somewhat awkwardly) use riscv_const_insns to
test for which sequence would be preferred.

Tested on Ventana's CI system as well as my own.  Waiting on CI results
from Rivos's tester before moving forward.

Jeff
gcc/
* config/riscv/riscv.md: Add new patterns to allow selection
between (x << C1) + C2 vs (x + C2') << C1 depending on the
cost C2 vs C2'.

gcc/testsuite

* gcc.target/riscv/shift-add-1.c: New test.

(cherry picked from commit 3c9c52a1c0fa7af22f769a2116b28a0b7ea18129)

Diff:
---
 gcc/config/riscv/riscv.md| 56 
 gcc/testsuite/gcc.target/riscv/shift-add-1.c | 21 +++
 2 files changed, 77 insertions(+)

diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index ff4557c1325..78c16adee98 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -4162,6 +4162,62 @@
   }
 )
 
+;; These are forms of (x << C1) + C2, potentially canonicalized from
+;; ((x + C2') << C1.  Depending on the cost to load C2 vs C2' we may
+;; want to go ahead and recognize this form as C2 may be cheaper to
+;; synthesize than C2'.
+;;
+;; It might be better to refactor riscv_const_insns a bit so that we
+;; can have an API that passes integer values around rather than
+;; constructing a lot of garbage RTL.
+;;
+;; The mvconst_internal pattern in effect requires this pattern to
+;; also be a define_insn_and_split due to insn count costing when
+;; splitting in combine.
+(define_insn_and_split ""
+  [(set (match_operand:DI 0 "register_operand" "=r")
+   (plus:DI (ashift:DI (match_operand:DI 1 "register_operand" "r")
+   (match_operand 2 "const_int_operand" "n"))
+(match_operand 3 "const_int_operand" "n")))
+   (clobber (match_scratch:DI 4 "=&r"))]
+  "(TARGET_64BIT
+&& riscv_const_insns (operands[3])
+&& ((riscv_const_insns (operands[3])
+< riscv_const_insns (GEN_INT (INTVAL (operands[3]) >> INTVAL 
(operands[2]
+   || riscv_const_insns (GEN_INT (INTVAL (operands[3]) >> INTVAL 
(operands[2]))) == 0))"
+  "#"
+  "&& reload_completed"
+  [(set (match_dup 0) (ashift:DI (match_dup 1) (match_dup 2)))
+   (set (match_dup 4) (match_dup 3))
+   (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 4)))]
+  ""
+  [(set_attr "type" "arith")])
+
+(define_insn_and_split ""
+  [(set (match_operand:DI 0 "register_operand" "=r")
+   (sign_extend:DI (plus:SI (ashift:SI
+  (match_operand:SI 1 "register_operand" "r")
+  (match_operand 2 "const_int_operand" "n"))
+(match_operand 3 "const_int_operand" "n"
+   (clobber (match_scratch:DI 4 "=&r"))]
+  "(TARGET_64BIT
+&& riscv_const_insns (operands[3])
+&& ((riscv_const_insns (operands[3])
+< riscv_const_insns (GEN_INT (INTVAL (operands[3]) >> INTVAL 
(operands[2]
+   || riscv_const_insns (GEN_INT (INTVAL (operands[3]) >> INTVAL 
(operands[2]))) == 0))"
+  "#"
+  "&& reload_completed"
+  [(set (match_dup 0) (ashift:DI (match_dup 1) (match_dup 2)))
+   (set (match_dup 4) (match_dup 3))
+   (set (match_dup 0) (sign_extend:DI (plus:SI (match_dup 5) (match_dup 6]
+  "{
+ operands[1] = gen_lowpart (DImode, operands[1]);
+ operands[5] = gen_lowpart (SImode, operands[0]);
+ operands[6] = gen_lowpart (SImode, operands[4]);
+   }"
+  [(set_attr "type" "arith")])
+
+
 (include "bitmanip.md")
 (include "crypto.md")
 (include "sync.md")
diff --git a/gcc/testsuite/gcc.target/riscv/shift-add-1.c 
b/gcc/testsuite/gcc.target/riscv/shift-add-1.c
new file mode 100644
index 000..d98875c3271
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/shift-add-1.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zba_zbb_zbs -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
+
+int composeFromSurrogate(const unsigned short high) {
+
+return  ((high - 0xD800) << 10) ;
+}
+
+
+long composeFromSurrogate_2(const unsigned long high) {
+
+return  ((high - 0xD800) << 10) ;
+}
+
+
+/* { dg-final { scan-assembler-times "\tli\t" 2 } } */
+/* { dg-final { scan-assembler-times "\tslli\t" 2 } } */
+/* { dg-final { scan-assembler-times "\taddw\t" 1 } } */
+/* { dg-final { scan-assembler-times "\tadd\t" 1 } } */
+


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] RISC-V: Implement -m{, no}fence-tso

2024-05-21 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:1b074bdb09654ddd7d0d10ed31133f58df0d656e

commit 1b074bdb09654ddd7d0d10ed31133f58df0d656e
Author: Palmer Dabbelt 
Date:   Sat May 18 15:15:09 2024 -0600

RISC-V: Implement -m{,no}fence-tso

Some processors from T-Head don't implement the `fence.tso` instruction
natively and instead trap to firmware.  This breaks some users who
haven't yet updated the firmware and one could imagine it breaking users
who are trying to build firmware if they're using the C memory model.

So just add an option to disable emitting it, in a similar fashion to
how we allow users to forbid other instructions.

Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1070959
---
I've just smoke tested this one, but

void func(void) { __atomic_thread_fence(__ATOMIC_ACQ_REL); }

generates `fence.tso` without the argument and `fence rw,rw` with
`-mno-fence-tso`, so it seems to be at least mostly there.  I figured
I'd just send it up for comments before putting together the DG bits:
it's kind of a pain to carry around these workarounds for unimplemented
instructions, but it's in HW so there's not much we can do about that.

gcc/ChangeLog:

* config/riscv/riscv.opt: Add -mno-fence-tso.
* config/riscv/sync-rvwmo.md (mem_thread_fence_rvwmo): Respect
-mno-fence-tso.
* doc/invoke.texi (RISC-V): Document -mno-fence-tso.

(cherry picked from commit a6114c2a691112f9cf5b072c21685d2e43c76d81)

Diff:
---
 gcc/config/riscv/riscv.opt | 4 
 gcc/config/riscv/sync-rvwmo.md | 2 +-
 gcc/doc/invoke.texi| 8 
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt
index d209ac896fd..87f58332016 100644
--- a/gcc/config/riscv/riscv.opt
+++ b/gcc/config/riscv/riscv.opt
@@ -624,3 +624,7 @@ Enum(tls_type) String(desc) Value(TLS_DESCRIPTORS)
 mtls-dialect=
 Target RejectNegative Joined Enum(tls_type) Var(riscv_tls_dialect) 
Init(TLS_TRADITIONAL) Save
 Specify TLS dialect.
+
+mfence-tso
+Target Var(TARGET_FENCE_TSO) Init(1)
+Specifies whether the fence.tso instruction should be used.
diff --git a/gcc/config/riscv/sync-rvwmo.md b/gcc/config/riscv/sync-rvwmo.md
index d4fd26069f7..e639a1e2392 100644
--- a/gcc/config/riscv/sync-rvwmo.md
+++ b/gcc/config/riscv/sync-rvwmo.md
@@ -33,7 +33,7 @@
 if (model == MEMMODEL_SEQ_CST)
return "fence\trw,rw";
 else if (model == MEMMODEL_ACQ_REL)
-   return "fence.tso";
+   return TARGET_FENCE_TSO ? "fence.tso" : "fence\trw,rw";
 else if (model == MEMMODEL_ACQUIRE)
return "fence\tr,rw";
 else if (model == MEMMODEL_RELEASE)
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index dc4c5a3189d..1d48d57bcc7 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1243,6 +1243,7 @@ See RS/6000 and PowerPC Options.
 -mplt  -mno-plt
 -mabi=@var{ABI-string}
 -mfdiv  -mno-fdiv
+-mfence-tso  -mno-fence-tso
 -mdiv  -mno-div
 -misa-spec=@var{ISA-spec-string}
 -march=@var{ISA-string}
@@ -30378,6 +30379,13 @@ Do or don't use hardware floating-point divide and 
square root instructions.
 This requires the F or D extensions for floating-point registers.  The default
 is to use them if the specified architecture has these instructions.
 
+@opindex mfence-tso
+@item -mfence-tso
+@itemx -mno-fence-tso
+Do or don't use the @samp{fence.tso} instruction, which is unimplemented on
+some processors (including those from T-Head).  If the @samp{fence.tso}
+instruction is not availiable then a stronger fence will be used instead.
+
 @opindex mdiv
 @item -mdiv
 @itemx -mno-div


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [to-be-committed][RISC-V][PR target/115142] Do not create invalidate shift-add insn

2024-05-21 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:08aaf0da2e4cb4e36df0471e532ddf1acc873e79

commit 08aaf0da2e4cb4e36df0471e532ddf1acc873e79
Author: Jeff Law 
Date:   Sun May 19 09:56:16 2024 -0600

[to-be-committed][RISC-V][PR target/115142] Do not create invalidate 
shift-add insn

The circumstances which triggered this weren't something that should appear 
in
the wild (-ftree-ter, without optimization enabled).  So I wasn't planning 
to
backport.  Obviously if it shows up in another context we can revisit that
decision.

I've run this through my rv32gcv and rv64gc tester.  Waiting on the CI 
system before committing.

PR target/115142
gcc/

* config/riscv/riscv.cc (mem_shadd_or_shadd_rtx_p): Make sure
shifted argument is a register.

gcc/testsuite

* gcc.target/riscv/pr115142.c: New test.

(cherry picked from commit e1ce9c37ed68136a99d44c8301990c184ba41849)

Diff:
---
 gcc/config/riscv/riscv.cc |  1 +
 gcc/testsuite/gcc.target/riscv/pr115142.c | 10 ++
 2 files changed, 11 insertions(+)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 7a34b4be873..d0c22058b8c 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -2465,6 +2465,7 @@ mem_shadd_or_shadd_rtx_p (rtx x)
 {
   return ((GET_CODE (x) == ASHIFT
   || GET_CODE (x) == MULT)
+ && register_operand (XEXP (x, 0), GET_MODE (x))
  && CONST_INT_P (XEXP (x, 1))
  && ((GET_CODE (x) == ASHIFT && IN_RANGE (INTVAL (XEXP (x, 1)), 1, 3))
  || (GET_CODE (x) == MULT
diff --git a/gcc/testsuite/gcc.target/riscv/pr115142.c 
b/gcc/testsuite/gcc.target/riscv/pr115142.c
new file mode 100644
index 000..40ba49dfa20
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/pr115142.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O0 -ftree-ter" } */
+
+long a;
+char b;
+void e() {
+  char f[8][1];
+  b = f[a][a];
+}
+


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] DSE: Fix ICE after allow vector type in get_stored_val

2024-05-21 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:5ef90118a30e49ce73f48a6f3c94129374290b5c

commit 5ef90118a30e49ce73f48a6f3c94129374290b5c
Author: Pan Li 
Date:   Tue Apr 30 09:42:39 2024 +0800

DSE: Fix ICE after allow vector type in get_stored_val

We allowed vector type for get_stored_val when read is less than or
equal to store in previous.  Unfortunately,  the valididate_subreg
treats the vector type's size is less than vector register as
invalid.  Then we will have ICE here.

This patch would like to fix it by filter-out the invalid type size,
and make sure the subreg is valid for both the read_mode and store_mode
before perform the real gen_lowpart.

The below test suites are passed for this patch:

* The x86 bootstrap test.
* The x86 regression test.
* The riscv rv64gcv regression test.
* The riscv rv64gc regression test.
* The aarch64 regression test.

gcc/ChangeLog:

* dse.cc (get_stored_val): Make sure read_mode/write_mode
is valid subreg before gen_lowpart.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/bug-6.c: New test.

Signed-off-by: Pan Li 
(cherry picked from commit 88b3f83238087cbe2aa2c51c6054796856f2fb94)

Diff:
---
 gcc/dse.cc  |  4 +++-
 gcc/testsuite/gcc.target/riscv/rvv/base/bug-6.c | 22 ++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/dse.cc b/gcc/dse.cc
index edc7a1dfecf..1596da91da0 100644
--- a/gcc/dse.cc
+++ b/gcc/dse.cc
@@ -1946,7 +1946,9 @@ get_stored_val (store_info *store_info, machine_mode 
read_mode,
 copy_rtx (store_info->const_rhs));
   else if (VECTOR_MODE_P (read_mode) && VECTOR_MODE_P (store_mode)
 && known_le (GET_MODE_BITSIZE (read_mode), GET_MODE_BITSIZE (store_mode))
-&& targetm.modes_tieable_p (read_mode, store_mode))
+&& targetm.modes_tieable_p (read_mode, store_mode)
+&& validate_subreg (read_mode, store_mode, copy_rtx (store_info->rhs),
+   subreg_lowpart_offset (read_mode, store_mode)))
 read_reg = gen_lowpart (read_mode, copy_rtx (store_info->rhs));
   else
 read_reg = extract_low_bits (read_mode, store_mode,
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/bug-6.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/bug-6.c
new file mode 100644
index 000..5bb00b8f587
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/bug-6.c
@@ -0,0 +1,22 @@
+/* Test that we do not have ice when compile */
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O3 -ftree-vectorize" } */
+
+struct A { float x, y; };
+struct B { struct A u; };
+
+extern void bar (struct A *);
+
+float
+f3 (struct B *x, int y)
+{
+  struct A p = {1.0f, 2.0f};
+  struct A *q = &x[y].u;
+
+  __builtin_memcpy (&q->x, &p.x, sizeof (float));
+  __builtin_memcpy (&q->y, &p.y, sizeof (float));
+
+  bar (&p);
+
+  return x[y].u.x + x[y].u.y;
+}


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] Regenerate riscv.opt.urls and i386.opt.urls

2024-05-21 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:97fb62e5969841287c275bc12b80fd950a38061b

commit 97fb62e5969841287c275bc12b80fd950a38061b
Author: Mark Wielaard 
Date:   Mon May 20 13:13:02 2024 +0200

Regenerate riscv.opt.urls and i386.opt.urls

risc-v added an -mfence-tso option. i386 removed Xeon Phi ISA support
options. But the opt.urls files weren't regenerated.

Fixes: a6114c2a6911 ("RISC-V: Implement -m{,no}fence-tso")
Fixes: e1a7e2c54d52 ("i386: Remove Xeon Phi ISA support")

gcc/ChangeLog:

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

(cherry picked from commit 591bc70139d898c06b1d605ff4fed591ffd2e2e7)

Diff:
---
 gcc/config/i386/i386.opt.urls   | 15 ---
 gcc/config/riscv/riscv.opt.urls |  3 +++
 2 files changed, 3 insertions(+), 15 deletions(-)

diff --git a/gcc/config/i386/i386.opt.urls b/gcc/config/i386/i386.opt.urls
index 81c5bb9a927..40e8a844936 100644
--- a/gcc/config/i386/i386.opt.urls
+++ b/gcc/config/i386/i386.opt.urls
@@ -238,12 +238,6 @@ UrlSuffix(gcc/x86-Options.html#index-mavx2)
 mavx512f
 UrlSuffix(gcc/x86-Options.html#index-mavx512f)
 
-mavx512pf
-UrlSuffix(gcc/x86-Options.html#index-mavx512pf)
-
-mavx512er
-UrlSuffix(gcc/x86-Options.html#index-mavx512er)
-
 mavx512cd
 UrlSuffix(gcc/x86-Options.html#index-mavx512cd)
 
@@ -262,12 +256,6 @@ UrlSuffix(gcc/x86-Options.html#index-mavx512ifma)
 mavx512vbmi
 UrlSuffix(gcc/x86-Options.html#index-mavx512vbmi)
 
-mavx5124fmaps
-UrlSuffix(gcc/x86-Options.html#index-mavx5124fmaps)
-
-mavx5124vnniw
-UrlSuffix(gcc/x86-Options.html#index-mavx5124vnniw)
-
 mavx512vpopcntdq
 UrlSuffix(gcc/x86-Options.html#index-mavx512vpopcntdq)
 
@@ -409,9 +397,6 @@ UrlSuffix(gcc/x86-Options.html#index-mrdrnd)
 mf16c
 UrlSuffix(gcc/x86-Options.html#index-mf16c)
 
-mprefetchwt1
-UrlSuffix(gcc/x86-Options.html#index-mprefetchwt1)
-
 mfentry
 UrlSuffix(gcc/x86-Options.html#index-mfentry)
 
diff --git a/gcc/config/riscv/riscv.opt.urls b/gcc/config/riscv/riscv.opt.urls
index 2f01ae5d627..e02ef3ee3dd 100644
--- a/gcc/config/riscv/riscv.opt.urls
+++ b/gcc/config/riscv/riscv.opt.urls
@@ -91,3 +91,6 @@ UrlSuffix(gcc/RISC-V-Options.html#index-minline-strlen)
 
 ; skipping UrlSuffix for 'mtls-dialect=' due to finding no URLs
 
+mfence-tso
+UrlSuffix(gcc/RISC-V-Options.html#index-mfence-tso)
+


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] RISC-V: avoid LUI based const mat in prologue/epilogue expansion [PR/105733]

2024-05-21 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:259f9f2c67458b594fec9eac9df0ddb8a5a27867

commit 259f9f2c67458b594fec9eac9df0ddb8a5a27867
Author: Vineet Gupta 
Date:   Mon May 13 11:46:03 2024 -0700

RISC-V: avoid LUI based const mat in prologue/epilogue expansion [PR/105733]

If the constant used for stack offset can be expressed as sum of two S12
values, the constant need not be materialized (in a reg) and instead the
two S12 bits can be added to instructions involved with frame pointer.
This avoids burning a register and more importantly can often get down
to be 2 insn vs. 3.

The prev patches to generally avoid LUI based const materialization didn't
fix this PR and need this directed fix in funcion prologue/epilogue
expansion.

This fix doesn't move the neddle for SPEC, at all, but it is still a
win considering gcc generates one insn fewer than llvm for the test ;-)

   gcc-13.1 release   |  gcc 230823 |   |
  |g6619b3d4c15c|   This patch  |  
clang/llvm

-
li  t0,-4096 | lit0,-4096  | addi  sp,sp,-2048 | addi 
sp,sp,-2048
addit0,t0,2016   | addi  t0,t0,2032| add   sp,sp,-16   | addi 
sp,sp,-32
li  a4,4096  | add   sp,sp,t0  | add   a5,sp,a0| add  
a1,sp,16
add sp,sp,t0 | addi  a5,sp,-2032   | sbzero,0(a5)  | add  
a0,a0,a1
li  a5,-4096 | add   a0,a5,a0  | addi  sp,sp,2032  | sb   
zero,0(a0)
addia4,a4,-2032  | lit0, 4096  | addi  sp,sp,32| addi 
sp,sp,2032
add a4,a4,a5 | sbzero,2032(a0) | ret   | addi 
sp,sp,48
addia5,sp,16 | addi  t0,t0,-2032   |   | ret
add a5,a4,a5 | add   sp,sp,t0  |
add a0,a5,a0 | ret |
li  t0,4096  |
sd  a5,8(sp) |
sb  zero,2032(a0)|
addit0,t0,-2016  |
add sp,sp,t0 |
ret  |

gcc/ChangeLog:
PR target/105733
* config/riscv/riscv.h: New macros for with aligned offsets.
* config/riscv/riscv.cc (riscv_split_sum_of_two_s12): New
function to split a sum of two s12 values into constituents.
(riscv_expand_prologue): Handle offset being sum of two S12.
(riscv_expand_epilogue): Ditto.
* config/riscv/riscv-protos.h (riscv_split_sum_of_two_s12): New.

gcc/testsuite/ChangeLog:
* gcc.target/riscv/pr105733.c: New Test.
* gcc.target/riscv/rvv/autovec/vls/spill-1.c: Adjust to not
expect LUI 4096.
* gcc.target/riscv/rvv/autovec/vls/spill-2.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/spill-3.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/spill-4.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/spill-5.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/spill-6.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/spill-7.c: Ditto.

Tested-by: Edwin Lu  # pre-commit-CI #1568
Signed-off-by: Vineet Gupta 
(cherry picked from commit f9cfc192ed0127edb7e79818917dd2859fce4d44)

Diff:
---
 gcc/config/riscv/riscv-protos.h|  2 +
 gcc/config/riscv/riscv.cc  | 54 --
 gcc/config/riscv/riscv.h   |  7 +++
 gcc/testsuite/gcc.target/riscv/pr105733.c  | 15 ++
 .../gcc.target/riscv/rvv/autovec/vls/spill-1.c |  4 +-
 .../gcc.target/riscv/rvv/autovec/vls/spill-2.c |  4 +-
 .../gcc.target/riscv/rvv/autovec/vls/spill-3.c |  4 +-
 .../gcc.target/riscv/rvv/autovec/vls/spill-4.c |  4 +-
 .../gcc.target/riscv/rvv/autovec/vls/spill-5.c |  4 +-
 .../gcc.target/riscv/rvv/autovec/vls/spill-6.c |  4 +-
 .../gcc.target/riscv/rvv/autovec/vls/spill-7.c |  4 +-
 11 files changed, 89 insertions(+), 17 deletions(-)

diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index c64aae18deb..0704968561b 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -167,6 +167,8 @@ extern void riscv_subword_address (rtx, rtx *, rtx *, rtx 
*, rtx *);
 extern void riscv_lshift_subword (machine_mode, rtx, rtx, rtx *);
 extern enum memmodel riscv_union_memmodels (enum memmodel, enum memmodel);
 extern bool riscv_reg_frame_related (rtx);
+extern void riscv_split_sum_of_two_s12 (HOST_WIDE_INT, HOST_WIDE_INT *,
+   HOST_WIDE_INT *);
 
 /* Routines implemented in riscv-c.cc.  */
 void riscv_cpu_cpp_builtins (cpp_reader *);
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index d0c22058b8c..2ecbcf1d0af 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -4075,6 +4075,32 @@ riscv_split_doubleword_move (rtx dest, rtx src)
riscv_emit_move (riscv_s

[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] RISC-V: avoid LUI based const mat in alloca epilogue expansion

2024-05-21 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:106d603005c774ad619103bae3b653c94b80bf9c

commit 106d603005c774ad619103bae3b653c94b80bf9c
Author: Vineet Gupta 
Date:   Wed Mar 6 15:44:27 2024 -0800

RISC-V: avoid LUI based const mat in alloca epilogue expansion

This is continuing on the prev patch in function epilogue expansion.
Broken out of easy of review.

gcc/ChangeLog:
* config/riscv/riscv.cc (riscv_expand_epilogue): Handle offset
being sum of two S12.

Tested-by: Patrick O'Neill  # pre-commit-CI #1569
Signed-off-by: Vineet Gupta 
(cherry picked from commit 9926c40a902edbc665919d508ef0c36f362f9c41)

Diff:
---
 gcc/config/riscv/riscv.cc | 33 ++---
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 2ecbcf1d0af..85df5b7ab49 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -8111,7 +8111,10 @@ riscv_expand_epilogue (int style)
   need_barrier_p = false;
 
   poly_int64 adjust_offset = -frame->hard_frame_pointer_offset;
+  rtx dwarf_adj = gen_int_mode (adjust_offset, Pmode);
   rtx adjust = NULL_RTX;
+  bool sum_of_two_s12 = false;
+  HOST_WIDE_INT one, two;
 
   if (!adjust_offset.is_constant ())
{
@@ -8123,14 +8126,23 @@ riscv_expand_epilogue (int style)
}
   else
{
- if (!SMALL_OPERAND (adjust_offset.to_constant ()))
+ HOST_WIDE_INT adj_off_value = adjust_offset.to_constant ();
+ if (SMALL_OPERAND (adj_off_value))
+   {
+ adjust = GEN_INT (adj_off_value);
+   }
+ else if (SUM_OF_TWO_S12_ALGN (adj_off_value))
+   {
+ riscv_split_sum_of_two_s12 (adj_off_value, &one, &two);
+ dwarf_adj = adjust = GEN_INT (one);
+ sum_of_two_s12 = true;
+   }
+ else
{
  riscv_emit_move (RISCV_PROLOGUE_TEMP (Pmode),
-  GEN_INT (adjust_offset.to_constant ()));
+  GEN_INT (adj_off_value));
  adjust = RISCV_PROLOGUE_TEMP (Pmode);
}
- else
-   adjust = GEN_INT (adjust_offset.to_constant ());
}
 
   insn = emit_insn (
@@ -8138,14 +8150,21 @@ riscv_expand_epilogue (int style)
  adjust));
 
   rtx dwarf = NULL_RTX;
-  rtx cfa_adjust_value = gen_rtx_PLUS (
-  Pmode, hard_frame_pointer_rtx,
-  gen_int_mode (-frame->hard_frame_pointer_offset, 
Pmode));
+  rtx cfa_adjust_value = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx,
+  dwarf_adj);
   rtx cfa_adjust_rtx = gen_rtx_SET (stack_pointer_rtx, cfa_adjust_value);
   dwarf = alloc_reg_note (REG_CFA_ADJUST_CFA, cfa_adjust_rtx, dwarf);
+
   RTX_FRAME_RELATED_P (insn) = 1;
 
   REG_NOTES (insn) = dwarf;
+
+  if (sum_of_two_s12)
+   {
+ insn = emit_insn (gen_add3_insn (stack_pointer_rtx, stack_pointer_rtx,
+   GEN_INT (two)));
+ RTX_FRAME_RELATED_P (insn) = 1;
+   }
 }
 
   if (use_restore_libcall || use_multi_pop)


[gcc r14-10225] Fortran: fix dependency checks for inquiry refs [PR115039]

2024-05-21 Thread Harald Anlauf via Gcc-cvs
https://gcc.gnu.org/g:edde60a53c7d4ee5a58c9835c8e1e1758ba636f7

commit r14-10225-gedde60a53c7d4ee5a58c9835c8e1e1758ba636f7
Author: Harald Anlauf 
Date:   Fri May 10 21:18:03 2024 +0200

Fortran: fix dependency checks for inquiry refs [PR115039]

gcc/fortran/ChangeLog:

PR fortran/115039
* expr.cc (gfc_traverse_expr): An inquiry ref does not constitute
a dependency and cannot collide with a symbol.

gcc/testsuite/ChangeLog:

PR fortran/115039
* gfortran.dg/statement_function_5.f90: New test.

(cherry picked from commit d4974fd22730014e337fd7ec2471945ba8afb00e)

Diff:
---
 gcc/fortran/expr.cc|  2 +-
 gcc/testsuite/gfortran.dg/statement_function_5.f90 | 20 
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 09d1ebd95d2..50e32a7a3b7 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -5491,7 +5491,7 @@ gfc_traverse_expr (gfc_expr *expr, gfc_symbol *sym,
  break;
 
case REF_INQUIRY:
- return true;
+ return false;
 
default:
  gcc_unreachable ();
diff --git a/gcc/testsuite/gfortran.dg/statement_function_5.f90 
b/gcc/testsuite/gfortran.dg/statement_function_5.f90
new file mode 100644
index 000..bc5a5dba7a0
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/statement_function_5.f90
@@ -0,0 +1,20 @@
+! { dg-do compile }
+! PR fortran/115039
+!
+! Check that inquiry refs work with statement functions
+!
+! { dg-additional-options "-std=legacy -fdump-tree-optimized" }
+! { dg-prune-output " Obsolescent feature" }
+! { dg-final { scan-tree-dump-not "_gfortran_stop_numeric" "optimized" } }
+
+program testit
+  implicit none
+  complex :: x
+  real:: im
+  integer :: slen
+  character(5) :: s
+  im(x)   = x%im + x%re + x%kind
+  slen(s) = s%len
+  if (im((1.0,3.0) + (2.0,4.0)) /= 14.) stop 1
+  if (slen('abcdef') /= 5)  stop 2
+end program testit


[gcc r13-8786] Fortran: fix dependency checks for inquiry refs [PR115039]

2024-05-21 Thread Harald Anlauf via Gcc-cvs
https://gcc.gnu.org/g:5ed32d00a7b408baa48d85e841740e73c8504d7a

commit r13-8786-g5ed32d00a7b408baa48d85e841740e73c8504d7a
Author: Harald Anlauf 
Date:   Fri May 10 21:18:03 2024 +0200

Fortran: fix dependency checks for inquiry refs [PR115039]

gcc/fortran/ChangeLog:

PR fortran/115039
* expr.cc (gfc_traverse_expr): An inquiry ref does not constitute
a dependency and cannot collide with a symbol.

gcc/testsuite/ChangeLog:

PR fortran/115039
* gfortran.dg/statement_function_5.f90: New test.

(cherry picked from commit d4974fd22730014e337fd7ec2471945ba8afb00e)

Diff:
---
 gcc/fortran/expr.cc|  2 +-
 gcc/testsuite/gfortran.dg/statement_function_5.f90 | 20 
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index a6c4dccb125..4a9b29c7e9d 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -5483,7 +5483,7 @@ gfc_traverse_expr (gfc_expr *expr, gfc_symbol *sym,
  break;
 
case REF_INQUIRY:
- return true;
+ return false;
 
default:
  gcc_unreachable ();
diff --git a/gcc/testsuite/gfortran.dg/statement_function_5.f90 
b/gcc/testsuite/gfortran.dg/statement_function_5.f90
new file mode 100644
index 000..bc5a5dba7a0
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/statement_function_5.f90
@@ -0,0 +1,20 @@
+! { dg-do compile }
+! PR fortran/115039
+!
+! Check that inquiry refs work with statement functions
+!
+! { dg-additional-options "-std=legacy -fdump-tree-optimized" }
+! { dg-prune-output " Obsolescent feature" }
+! { dg-final { scan-tree-dump-not "_gfortran_stop_numeric" "optimized" } }
+
+program testit
+  implicit none
+  complex :: x
+  real:: im
+  integer :: slen
+  character(5) :: s
+  im(x)   = x%im + x%re + x%kind
+  slen(s) = s%len
+  if (im((1.0,3.0) + (2.0,4.0)) /= 14.) stop 1
+  if (slen('abcdef') /= 5)  stop 2
+end program testit


[gcc r15-759] c++: folding non-dep enumerator from current inst [PR115139]

2024-05-21 Thread Patrick Palka via Gcc-cvs
https://gcc.gnu.org/g:f0c0bced62b9c728ed1e672747aa234d918da22c

commit r15-759-gf0c0bced62b9c728ed1e672747aa234d918da22c
Author: Patrick Palka 
Date:   Tue May 21 15:54:10 2024 -0400

c++: folding non-dep enumerator from current inst [PR115139]

After the tsubst_copy removal r14-4796-g3e3d73ed5e85e7 GCC 14 ICEs during
fold_non_dependent_expr for 'e1 | e2' below ultimately because we no
longer exit early when substituting the CONST_DECLs for e1 and e2 with
args=NULL_TREE and instead proceed to substitute the class context A
(also with args=NULL_TREE) which ends up ICEing from tsubst_pack_expansion
(due to processing_template_decl being cleared).

Incidentally, the ICE went away on trunk ever since the tsubst_aggr_type
removal r15-123-gf04dc89a991ddc since it changed the CONST_DECL case of
tsubst_expr to use tsubst to substitute the context, which short circuits
for empty args and so avoids the ICE.

This patch fixes this ICE for GCC 14 by narrowly restoring the early exit
for empty args that would've happened in tsubst_copy when substituting an
enumerator CONST_DECL.  We might as well apply this to trunk too, as a
small optimization.

PR c++/115139

gcc/cp/ChangeLog:

* pt.cc (tsubst_expr) : Exit early if args
is empty.

gcc/testsuite/ChangeLog:

* g++.dg/template/non-dependent33.C: New test.

Reviewed-by: Marek Polacek 
Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/pt.cc|  2 +-
 gcc/testsuite/g++.dg/template/non-dependent33.C | 13 +
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index e77c48e463e..a95ce6eb3da 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -21519,7 +21519,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t 
complain, tree in_decl)
 
if (DECL_TEMPLATE_PARM_P (t))
  RETURN (RECUR (DECL_INITIAL (t)));
-   if (!uses_template_parms (DECL_CONTEXT (t)))
+   if (!args || !uses_template_parms (DECL_CONTEXT (t)))
  RETURN (t);
 
/* Unfortunately, we cannot just call lookup_name here.
diff --git a/gcc/testsuite/g++.dg/template/non-dependent33.C 
b/gcc/testsuite/g++.dg/template/non-dependent33.C
new file mode 100644
index 000..ea5b41fba93
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/non-dependent33.C
@@ -0,0 +1,13 @@
+// PR c++/115139
+// { dg-do compile { target c++11 } }
+
+template
+class A {
+  enum E {
+e1 = 1,
+e2 = 2,
+e3 = e1 | e2,
+  };
+};
+
+template class A;


[gcc r14-10226] c++: folding non-dep enumerator from current inst [PR115139]

2024-05-21 Thread Patrick Palka via Gcc-cvs
https://gcc.gnu.org/g:caf43cc9e5c0b3265b55e5a0dc77fc55e9618c77

commit r14-10226-gcaf43cc9e5c0b3265b55e5a0dc77fc55e9618c77
Author: Patrick Palka 
Date:   Tue May 21 15:54:10 2024 -0400

c++: folding non-dep enumerator from current inst [PR115139]

After the tsubst_copy removal r14-4796-g3e3d73ed5e85e7 GCC 14 ICEs during
fold_non_dependent_expr for 'e1 | e2' below ultimately because we no
longer exit early when substituting the CONST_DECLs for e1 and e2 with
args=NULL_TREE and instead proceed to substitute the class context A
(also with args=NULL_TREE) which ends up ICEing from tsubst_pack_expansion
(due to processing_template_decl being cleared).

Incidentally, the ICE went away on trunk ever since the tsubst_aggr_type
removal r15-123-gf04dc89a991ddc since it changed the CONST_DECL case of
tsubst_expr to use tsubst to substitute the context, which short circuits
for empty args and so avoids the ICE.

This patch fixes this ICE for GCC 14 by narrowly restoring the early exit
for empty args that would've happened in tsubst_copy when substituting an
enumerator CONST_DECL.  We might as well apply this to trunk too, as a
small optimization.

PR c++/115139

gcc/cp/ChangeLog:

* pt.cc (tsubst_expr) : Exit early if args
is empty.

gcc/testsuite/ChangeLog:

* g++.dg/template/non-dependent33.C: New test.

Reviewed-by: Marek Polacek 
Reviewed-by: Jason Merrill 
(cherry picked from commit f0c0bced62b9c728ed1e672747aa234d918da22c)

Diff:
---
 gcc/cp/pt.cc|  2 +-
 gcc/testsuite/g++.dg/template/non-dependent33.C | 13 +
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index e9882f2a3e0..ba47620ec59 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -21524,7 +21524,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t 
complain, tree in_decl)
 
if (DECL_TEMPLATE_PARM_P (t))
  RETURN (RECUR (DECL_INITIAL (t)));
-   if (!uses_template_parms (DECL_CONTEXT (t)))
+   if (!args || !uses_template_parms (DECL_CONTEXT (t)))
  RETURN (t);
 
/* Unfortunately, we cannot just call lookup_name here.
diff --git a/gcc/testsuite/g++.dg/template/non-dependent33.C 
b/gcc/testsuite/g++.dg/template/non-dependent33.C
new file mode 100644
index 000..ea5b41fba93
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/non-dependent33.C
@@ -0,0 +1,13 @@
+// PR c++/115139
+// { dg-do compile { target c++11 } }
+
+template
+class A {
+  enum E {
+e1 = 1,
+e2 = 2,
+e3 = e1 | e2,
+  };
+};
+
+template class A;


[gcc r15-760] c++: Fix std dialect hint for std::to_address [PR107800]

2024-05-21 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:826a7d3d19d3ebf04e21d6f1c89eb341a36fb5d1

commit r15-760-g826a7d3d19d3ebf04e21d6f1c89eb341a36fb5d1
Author: Jonathan Wakely 
Date:   Tue May 21 13:16:33 2024 +0100

c++: Fix std dialect hint for std::to_address [PR107800]

The correct dialect for std::to_address is cxx20 not cxx11.

gcc/cp/ChangeLog:

PR libstdc++/107800
* cxxapi-data.csv : Change dialect to cxx20.
* std-name-hint.gperf: Regenerate.
* std-name-hint.h: Regenerate.

Diff:
---
 gcc/cp/cxxapi-data.csv | 2 +-
 gcc/cp/std-name-hint.gperf | 2 +-
 gcc/cp/std-name-hint.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/cxxapi-data.csv b/gcc/cp/cxxapi-data.csv
index 75ee1b3ac92..1cbf774acd7 100644
--- a/gcc/cp/cxxapi-data.csv
+++ b/gcc/cp/cxxapi-data.csv
@@ -460,7 +460,7 @@
 # unimplemented ,default_accessor,1,no
 # unimplemented ,mdspan,1,cxx23
 ,pointer_traits,1,cxx11
-,to_address,1,cxx11
+,to_address,1,cxx20
 ,align,1,cxx11
 ,assume_aligned,1,cxx20
 ,allocator_arg_t,1,cxx11
diff --git a/gcc/cp/std-name-hint.gperf b/gcc/cp/std-name-hint.gperf
index b26bc6949ba..4fb23da40a6 100644
--- a/gcc/cp/std-name-hint.gperf
+++ b/gcc/cp/std-name-hint.gperf
@@ -220,7 +220,7 @@ pointer_traits, "", cxx11
 reinterpret_pointer_cast, "", cxx17
 shared_ptr, "", cxx11
 static_pointer_cast, "", cxx11
-to_address, "", cxx11
+to_address, "", cxx20
 uninitialized_construct_using_allocator, "", cxx20
 unique_ptr, "", cxx11
 uses_allocator, "", cxx11
diff --git a/gcc/cp/std-name-hint.h b/gcc/cp/std-name-hint.h
index e37d769c1ce..231689355d1 100644
--- a/gcc/cp/std-name-hint.h
+++ b/gcc/cp/std-name-hint.h
@@ -291,7 +291,7 @@ std_name_hint_lookup::find (const char *str, size_t len)
 #line 472 "std-name-hint.gperf"
   {"variant_npos", "", cxx17},
 #line 223 "std-name-hint.gperf"
-  {"to_address", "", cxx11},
+  {"to_address", "", cxx20},
 #line 460 "std-name-hint.gperf"
   {"pair", "", cxx98},
 #line 269 "std-name-hint.gperf"


[gcc r14-10227] c++: Fix std dialect hint for std::to_address [PR107800]

2024-05-21 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:5b96d547ce71b8f03ddbc2318c64618110839e20

commit r14-10227-g5b96d547ce71b8f03ddbc2318c64618110839e20
Author: Jonathan Wakely 
Date:   Tue May 21 13:16:33 2024 +0100

c++: Fix std dialect hint for std::to_address [PR107800]

The correct dialect for std::to_address is cxx20 not cxx11.

gcc/cp/ChangeLog:

PR libstdc++/107800
* cxxapi-data.csv : Change dialect to cxx20.
* std-name-hint.gperf: Regenerate.
* std-name-hint.h: Regenerate.

(cherry picked from commit 826a7d3d19d3ebf04e21d6f1c89eb341a36fb5d1)

Diff:
---
 gcc/cp/cxxapi-data.csv | 2 +-
 gcc/cp/std-name-hint.gperf | 2 +-
 gcc/cp/std-name-hint.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/cxxapi-data.csv b/gcc/cp/cxxapi-data.csv
index 75ee1b3ac92..1cbf774acd7 100644
--- a/gcc/cp/cxxapi-data.csv
+++ b/gcc/cp/cxxapi-data.csv
@@ -460,7 +460,7 @@
 # unimplemented ,default_accessor,1,no
 # unimplemented ,mdspan,1,cxx23
 ,pointer_traits,1,cxx11
-,to_address,1,cxx11
+,to_address,1,cxx20
 ,align,1,cxx11
 ,assume_aligned,1,cxx20
 ,allocator_arg_t,1,cxx11
diff --git a/gcc/cp/std-name-hint.gperf b/gcc/cp/std-name-hint.gperf
index b26bc6949ba..4fb23da40a6 100644
--- a/gcc/cp/std-name-hint.gperf
+++ b/gcc/cp/std-name-hint.gperf
@@ -220,7 +220,7 @@ pointer_traits, "", cxx11
 reinterpret_pointer_cast, "", cxx17
 shared_ptr, "", cxx11
 static_pointer_cast, "", cxx11
-to_address, "", cxx11
+to_address, "", cxx20
 uninitialized_construct_using_allocator, "", cxx20
 unique_ptr, "", cxx11
 uses_allocator, "", cxx11
diff --git a/gcc/cp/std-name-hint.h b/gcc/cp/std-name-hint.h
index e37d769c1ce..231689355d1 100644
--- a/gcc/cp/std-name-hint.h
+++ b/gcc/cp/std-name-hint.h
@@ -291,7 +291,7 @@ std_name_hint_lookup::find (const char *str, size_t len)
 #line 472 "std-name-hint.gperf"
   {"variant_npos", "", cxx17},
 #line 223 "std-name-hint.gperf"
-  {"to_address", "", cxx11},
+  {"to_address", "", cxx20},
 #line 460 "std-name-hint.gperf"
   {"pair", "", cxx98},
 #line 269 "std-name-hint.gperf"


[gcc r13-8787] c++: Fix std dialect hint for std::to_address [PR107800]

2024-05-21 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:0a9df2c711f40e067cd57707d8e623136ae4efbe

commit r13-8787-g0a9df2c711f40e067cd57707d8e623136ae4efbe
Author: Jonathan Wakely 
Date:   Tue May 21 13:16:33 2024 +0100

c++: Fix std dialect hint for std::to_address [PR107800]

The correct dialect for std::to_address is cxx20 not cxx11.

gcc/cp/ChangeLog:

PR libstdc++/107800
* cxxapi-data.csv : Change dialect to cxx20.
* std-name-hint.gperf: Regenerate.
* std-name-hint.h: Regenerate.

(cherry picked from commit 826a7d3d19d3ebf04e21d6f1c89eb341a36fb5d1)

Diff:
---
 gcc/cp/cxxapi-data.csv | 2 +-
 gcc/cp/std-name-hint.gperf | 2 +-
 gcc/cp/std-name-hint.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/cxxapi-data.csv b/gcc/cp/cxxapi-data.csv
index eb6dbcd6057..aecad73a7e8 100644
--- a/gcc/cp/cxxapi-data.csv
+++ b/gcc/cp/cxxapi-data.csv
@@ -460,7 +460,7 @@
 # unimplemented ,default_accessor,1,no
 # unimplemented ,mdspan,1,cxx23
 ,pointer_traits,1,cxx11
-,to_address,1,cxx11
+,to_address,1,cxx20
 ,align,1,cxx11
 ,assume_aligned,1,cxx20
 ,allocator_arg_t,1,cxx11
diff --git a/gcc/cp/std-name-hint.gperf b/gcc/cp/std-name-hint.gperf
index 758e74f77d6..a46c7f3e68f 100644
--- a/gcc/cp/std-name-hint.gperf
+++ b/gcc/cp/std-name-hint.gperf
@@ -220,7 +220,7 @@ pointer_traits, "", cxx11
 reinterpret_pointer_cast, "", cxx17
 shared_ptr, "", cxx11
 static_pointer_cast, "", cxx11
-to_address, "", cxx11
+to_address, "", cxx20
 uninitialized_construct_using_allocator, "", cxx20
 unique_ptr, "", cxx11
 uses_allocator, "", cxx11
diff --git a/gcc/cp/std-name-hint.h b/gcc/cp/std-name-hint.h
index 5848fca6f0e..8503d195145 100644
--- a/gcc/cp/std-name-hint.h
+++ b/gcc/cp/std-name-hint.h
@@ -291,7 +291,7 @@ std_name_hint_lookup::find (const char *str, size_t len)
 #line 472 "std-name-hint.gperf"
   {"variant_npos", "", cxx17},
 #line 223 "std-name-hint.gperf"
-  {"to_address", "", cxx11},
+  {"to_address", "", cxx20},
 #line 460 "std-name-hint.gperf"
   {"pair", "", cxx98},
 #line 269 "std-name-hint.gperf"


[gcc r13-8788] libstdc++: Fix handling of surrogate CP in codecvt [PR108976]

2024-05-21 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:bd5e672303f5f777e8927a746d3ee42db21d871b

commit r13-8788-gbd5e672303f5f777e8927a746d3ee42db21d871b
Author: Dimitrij Mijoski 
Date:   Thu Sep 28 21:38:11 2023 +0200

libstdc++: Fix handling of surrogate CP in codecvt [PR108976]

This patch fixes the handling of surrogate code points in all standard
facets for transcoding Unicode that are based on std::codecvt. Surrogate
code points should always be treated as error. On the other hand
surrogate code units can only appear in UTF-16 and only when they come
in a proper pair.

Additionally, it fixes a bug in std::codecvt_utf16::in() when odd number
of bytes were given in the range [from, from_end), error was returned
always. The last byte in such range does not form a full UTF-16 code
unit and we can not make any decisions for error, instead partial should
be returned.

The testsuite for testing these facets was updated in the following
order:

1. All functions that test codecvts that work with UTF-8 were refactored
   and made more generic so they accept codecvt that works with the char
   type char8_t.
2. The same functions were updated with new test cases for transcoding
   errors and now additionally test for surrogates, overlong UTF-8
   sequences, code points out of the Unicode range, and more tests for
   missing leading and trailing code units.
3. New tests were added to test codecvt_utf16 in both of its variants,
   UTF-16 <-> UTF-32/UCS-4 and UTF-16 <-> UCS-2.

libstdc++-v3/ChangeLog:

PR libstdc++/108976
* src/c++11/codecvt.cc (read_utf8_code_point): Fix handing of
surrogates in UTF-8.
(ucs4_out): Fix handling of surrogates in UCS-4 -> UTF-8.
(ucs4_in): Fix handling of range with odd number of bytes.
(ucs4_out): Fix handling of surrogates in UCS-4 -> UTF-16.
(ucs2_out): Fix handling of surrogates in UCS-2 -> UTF-16.
(ucs2_in): Fix handling of range with odd number of bytes.
(__codecvt_utf16_base::do_in): Likewise.
(__codecvt_utf16_base::do_in): Likewise.
(__codecvt_utf16_base::do_in): Likewise.
* testsuite/22_locale/codecvt/codecvt_unicode.cc: Renames, add
tests for codecvt_utf16 and codecvt_utf16.
* testsuite/22_locale/codecvt/codecvt_unicode.h: Refactor UTF-8
testing functions for char8_t, add more test cases for errors,
add testing functions for codecvt_utf16.
* testsuite/22_locale/codecvt/codecvt_unicode_wchar_t.cc:
Renames, add tests for codecvt_utf16.
* testsuite/22_locale/codecvt/codecvt_utf16/79980.cc (test06):
Fix test.
* testsuite/22_locale/codecvt/codecvt_unicode_char8_t.cc: New
test.

(cherry picked from commit a8b9c32da787ea0bfbfc9118ac816fa7be4b1bc8)

Diff:
---
 libstdc++-v3/src/c++11/codecvt.cc  |   18 +-
 .../testsuite/22_locale/codecvt/codecvt_unicode.cc |   38 +-
 .../testsuite/22_locale/codecvt/codecvt_unicode.h  | 1799 +++-
 .../22_locale/codecvt/codecvt_unicode_char8_t.cc   |   53 +
 .../22_locale/codecvt/codecvt_unicode_wchar_t.cc   |   32 +-
 .../22_locale/codecvt/codecvt_utf16/79980.cc   |2 +-
 6 files changed, 1493 insertions(+), 449 deletions(-)

diff --git a/libstdc++-v3/src/c++11/codecvt.cc 
b/libstdc++-v3/src/c++11/codecvt.cc
index 02f05752de8..2cc812cfc34 100644
--- a/libstdc++-v3/src/c++11/codecvt.cc
+++ b/libstdc++-v3/src/c++11/codecvt.cc
@@ -284,6 +284,8 @@ namespace
return invalid_mb_sequence;
   if (c1 == 0xE0 && c2 < 0xA0) [[unlikely]] // overlong
return invalid_mb_sequence;
+  if (c1 == 0xED && c2 >= 0xA0) [[unlikely]] // surrogate
+   return invalid_mb_sequence;
   if (avail < 3) [[unlikely]]
return incomplete_mb_character;
   char32_t c3 = (unsigned char) from[2];
@@ -484,6 +486,8 @@ namespace
 while (from.size())
   {
const char32_t c = from[0];
+   if (0xD800 <= c && c <= 0xDFFF) [[unlikely]]
+ return codecvt_base::error;
if (c > maxcode) [[unlikely]]
  return codecvt_base::error;
if (!write_utf8_code_point(to, c)) [[unlikely]]
@@ -508,7 +512,7 @@ namespace
  return codecvt_base::error;
to = codepoint;
   }
-return from.size() ? codecvt_base::partial : codecvt_base::ok;
+return from.nbytes() ? codecvt_base::partial : codecvt_base::ok;
   }
 
   // ucs4 -> utf16
@@ -521,6 +525,8 @@ namespace
 while (from.size())
   {
const char32_t c = from[0];
+   if (0xD800 <= c && c <= 0xDFFF) [[unlikely]]
+ return codecvt_base::error;
if (c > maxcode) [[unlikely]]
  return codecvt_base::error;
if (!write_utf16_code_point(to, c, mode)) [[unlikely]]
@@ -653,7 +659,7 @@ namespace
 while (from.size() && to.siz

[gcc r13-8789] libstdc++: testsuite: Enhance codecvt_unicode with tests for length()

2024-05-21 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:9433e308e0ca48822aa5e3a9875aac1f86cbac72

commit r13-8789-g9433e308e0ca48822aa5e3a9875aac1f86cbac72
Author: Dimitrij Mijoski 
Date:   Wed Oct 18 12:52:20 2023 +0200

libstdc++: testsuite: Enhance codecvt_unicode with tests for length()

We can test codecvt::length() with the same data that we test
codecvt::in(). For each call of in() we add another call to length().
Some additional small cosmentic changes are applied.

libstdc++-v3/ChangeLog:

* testsuite/22_locale/codecvt/codecvt_unicode.h: Test length()

(cherry picked from commit 59a7d38997ec4d8a606c97b00e1a8b697edd1316)

Diff:
---
 .../testsuite/22_locale/codecvt/codecvt_unicode.h  | 123 ++---
 1 file changed, 110 insertions(+), 13 deletions(-)

diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.h 
b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.h
index d3ae42fac13..42270c50f14 100644
--- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.h
+++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.h
@@ -17,7 +17,6 @@
 
 #include 
 #include 
-#include 
 #include 
 
 struct test_offsets_ok
@@ -79,6 +78,11 @@ utf8_to_utf32_in_ok (const std::codecvt &cvt)
   VERIFY (char_traits::compare (out, exp, t.out_size) == 0);
   if (t.out_size < array_size (out))
VERIFY (out[t.out_size] == 0);
+
+  state = {};
+  auto len = cvt.length (state, in, in + t.in_size, t.out_size);
+  VERIFY (len >= 0);
+  VERIFY (static_cast (len) == t.in_size);
 }
 
   for (auto t : offsets)
@@ -99,6 +103,11 @@ utf8_to_utf32_in_ok (const std::codecvt &cvt)
   VERIFY (char_traits::compare (out, exp, t.out_size) == 0);
   if (t.out_size < array_size (out))
VERIFY (out[t.out_size] == 0);
+
+  state = {};
+  auto len = cvt.length (state, in, in + t.in_size, array_size (out));
+  VERIFY (len >= 0);
+  VERIFY (static_cast (len) == t.in_size);
 }
 }
 
@@ -163,6 +172,11 @@ utf8_to_utf32_in_partial (const std::codecvt &cvt)
  == 0);
   if (t.expected_out_next < array_size (out))
VERIFY (out[t.expected_out_next] == 0);
+
+  state = {};
+  auto len = cvt.length (state, in, in + t.in_size, t.out_size);
+  VERIFY (len >= 0);
+  VERIFY (static_cast (len) == t.expected_in_next);
 }
 }
 
@@ -303,6 +317,11 @@ utf8_to_utf32_in_error (const std::codecvt &cvt)
   if (t.expected_out_next < array_size (out))
VERIFY (out[t.expected_out_next] == 0);
 
+  state = {};
+  auto len = cvt.length (state, in, in + t.in_size, t.out_size);
+  VERIFY (len >= 0);
+  VERIFY (static_cast (len) == t.expected_in_next);
+
   in[t.replace_pos] = old_char;
 }
 }
@@ -334,7 +353,7 @@ utf32_to_utf8_out_ok (const std::codecvt &cvt)
   VERIFY (char_traits::length (in) == 4);
   VERIFY (char_traits::length (exp) == 10);
 
-  const test_offsets_ok offsets[] = {{0, 0}, {1, 1}, {2, 3}, {3, 6}, {4, 10}};
+  test_offsets_ok offsets[] = {{0, 0}, {1, 1}, {2, 3}, {3, 6}, {4, 10}};
   for (auto t : offsets)
 {
   ExternT out[array_size (exp) - 1] = {};
@@ -374,7 +393,7 @@ utf32_to_utf8_out_partial (const std::codecvt &cvt)
   VERIFY (char_traits::length (in) == 4);
   VERIFY (char_traits::length (exp) == 10);
 
-  const test_offsets_partial offsets[] = {
+  test_offsets_partial offsets[] = {
 {1, 0, 0, 0}, // no space for first CP
 
 {2, 1, 1, 1}, // no space for second CP
@@ -528,6 +547,11 @@ utf8_to_utf16_in_ok (const std::codecvt &cvt)
   VERIFY (char_traits::compare (out, exp, t.out_size) == 0);
   if (t.out_size < array_size (out))
VERIFY (out[t.out_size] == 0);
+
+  state = {};
+  auto len = cvt.length (state, in, in + t.in_size, t.out_size);
+  VERIFY (len >= 0);
+  VERIFY (static_cast (len) == t.in_size);
 }
 
   for (auto t : offsets)
@@ -548,6 +572,11 @@ utf8_to_utf16_in_ok (const std::codecvt &cvt)
   VERIFY (char_traits::compare (out, exp, t.out_size) == 0);
   if (t.out_size < array_size (out))
VERIFY (out[t.out_size] == 0);
+
+  state = {};
+  auto len = cvt.length (state, in, in + t.in_size, array_size (out));
+  VERIFY (len >= 0);
+  VERIFY (static_cast (len) == t.in_size);
 }
 }
 
@@ -617,6 +646,11 @@ utf8_to_utf16_in_partial (const std::codecvt &cvt)
  == 0);
   if (t.expected_out_next < array_size (out))
VERIFY (out[t.expected_out_next] == 0);
+
+  state = {};
+  auto len = cvt.length (state, in, in + t.in_size, t.out_size);
+  VERIFY (len >= 0);
+  VERIFY (static_cast (len) == t.expected_in_next);
 }
 }
 
@@ -757,6 +791,11 @@ utf8_to_utf16_in_error (const std::codecvt &cvt)
   if (t.expected_out_next < array_size (out))
VERIFY (out[t.expected_out_next] == 0);
 
+  state = {};
+  auto len = cvt.length (state, in, in + t.in_size, t.out_size);
+  VERIFY (len >= 0);
+  VERIFY (static_cast (l

[gcc r15-762] c++: Strengthen checks on 'main'

2024-05-21 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:292fc21a8d7aa2f16e61ac941e22ada6ddd85500

commit r15-762-g292fc21a8d7aa2f16e61ac941e22ada6ddd85500
Author: Nathaniel Shead 
Date:   Sat May 11 22:25:44 2024 +1000

c++: Strengthen checks on 'main'

This patch adds some missing requirements for legal main declarations,
as according to [basic.start.main] p2.

gcc/cp/ChangeLog:

* decl.cc (grokfndecl): Check for main functions with language
linkage or module attachment.
(grokvardecl): Check for extern 'C' entities named main.

gcc/testsuite/ChangeLog:

* g++.dg/abi/main.C: Check pedwarn for main with linkage-spec.
* g++.dg/modules/contracts-1_b.C: Don't declare main in named
module.
* g++.dg/modules/contracts-3_b.C: Likewise.
* g++.dg/modules/contracts-4_d.C: Likewise.
* g++.dg/modules/horcrux-1_a.C: Export declarations, so that...
* g++.dg/modules/horcrux-1_b.C: Don't declare main in named
module.
* g++.dg/modules/main-1.C: New test.
* g++.dg/parse/linkage5.C: New test.
* g++.dg/parse/linkage6.C: New test.

Signed-off-by: Nathaniel Shead 

Diff:
---
 gcc/cp/decl.cc   | 19 +++
 gcc/testsuite/g++.dg/abi/main.C  |  3 ++-
 gcc/testsuite/g++.dg/modules/contracts-1_b.C |  4 
 gcc/testsuite/g++.dg/modules/contracts-3_b.C |  4 
 gcc/testsuite/g++.dg/modules/contracts-4_d.C |  2 --
 gcc/testsuite/g++.dg/modules/horcrux-1_a.C   |  3 +++
 gcc/testsuite/g++.dg/modules/horcrux-1_b.C   |  2 +-
 gcc/testsuite/g++.dg/modules/main-1.C|  5 +
 gcc/testsuite/g++.dg/parse/linkage5.C| 14 ++
 gcc/testsuite/g++.dg/parse/linkage6.C| 13 +
 10 files changed, 53 insertions(+), 16 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 6fcab615d55..a992d54dc8f 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -10788,6 +10788,11 @@ grokfndecl (tree ctype,
  "cannot declare %<::main%> to be %qs", "consteval");
   if (!publicp)
error_at (location, "cannot declare %<::main%> to be static");
+  if (current_lang_depth () != 0)
+   pedwarn (location, OPT_Wpedantic, "cannot declare %<::main%> with a"
+" linkage specification");
+  if (module_attach_p ())
+   error_at (location, "cannot attach %<::main%> to a named module");
   inlinep = 0;
   publicp = 1;
 }
@@ -11287,10 +11292,16 @@ grokvardecl (tree type,
 DECL_INTERFACE_KNOWN (decl) = 1;
 
   if (DECL_NAME (decl)
-  && MAIN_NAME_P (DECL_NAME (decl))
-  && scope == global_namespace)
-error_at (DECL_SOURCE_LOCATION (decl),
- "cannot declare %<::main%> to be a global variable");
+  && MAIN_NAME_P (DECL_NAME (decl)))
+{
+  if (scope == global_namespace)
+   error_at (DECL_SOURCE_LOCATION (decl),
+ "cannot declare %<::main%> to be a global variable");
+  else if (DECL_EXTERN_C_P (decl))
+   error_at (DECL_SOURCE_LOCATION (decl),
+ "an entity named % cannot be declared with "
+ "C language linkage");
+}
 
   /* Check that the variable can be safely declared as a concept.
  Note that this also forbids explicit specializations.  */
diff --git a/gcc/testsuite/g++.dg/abi/main.C b/gcc/testsuite/g++.dg/abi/main.C
index 4c5f1ea213c..2797a16df5b 100644
--- a/gcc/testsuite/g++.dg/abi/main.C
+++ b/gcc/testsuite/g++.dg/abi/main.C
@@ -1,10 +1,11 @@
 /* { dg-do compile } */
+/* { dg-additional-options "-Wno-error=pedantic" }
 
 /* Check if entry points get implicit C linkage. If they don't, compiler will
  * error on incompatible declarations */
 
 int main();
-extern "C" int main();
+extern "C" int main();  // { dg-warning "linkage specification" }
 
 #ifdef __MINGW32__
 
diff --git a/gcc/testsuite/g++.dg/modules/contracts-1_b.C 
b/gcc/testsuite/g++.dg/modules/contracts-1_b.C
index 30c15f6928b..aa36c8d6b1b 100644
--- a/gcc/testsuite/g++.dg/modules/contracts-1_b.C
+++ b/gcc/testsuite/g++.dg/modules/contracts-1_b.C
@@ -1,15 +1,11 @@
 // { dg-module-do run }
 // { dg-additional-options "-fmodules-ts -fcontracts 
-fcontract-continuation-mode=on" }
-module;
 #include 
-export module bar;
-// { dg-module-cmi bar }
 import foo;
 
 template
 bool bar_fn_pre(T n) { printf("bar fn pre(%d)\n", n); return true; }
 
-export
 template
 T bar_fn(T n)
   [[ pre: bar_fn_pre(n) && n > 0 ]]
diff --git a/gcc/testsuite/g++.dg/modules/contracts-3_b.C 
b/gcc/testsuite/g++.dg/modules/contracts-3_b.C
index b1d6375391b..1a29e2c3e5d 100644
--- a/gcc/testsuite/g++.dg/modules/contracts-3_b.C
+++ b/gcc/testsuite/g++.dg/modules/contracts-3_b.C
@@ -1,15 +1,11 @@
 // { dg-module-do run }
 // { dg-additional-options "-fmodules-ts -fcontracts 
-fcontract-role=default:ignore,ignore,ignore" }
-module;
 #include 
-export module bar;
-// { dg-module-cmi bar }
 im

[gcc r15-763] RISC-V: Enable vectorization for vect-early-break_124-pr114403.c

2024-05-21 Thread Li Xu via Gcc-cvs
https://gcc.gnu.org/g:ffab721f3c9ecbb9831844d844ad257b69a77993

commit r15-763-gffab721f3c9ecbb9831844d844ad257b69a77993
Author: xuli 
Date:   Mon May 20 01:56:47 2024 +

RISC-V: Enable vectorization for vect-early-break_124-pr114403.c

Because "targetm.slow_unaligned_access" is set to true by default
(aka -mtune=rocket) for RISC-V, it causes the __builtin_memcpy with
8 bytes failed to folded into int64 assignment during ccp1.

So adding "-mtune=generic-ooo" to the RISC-V target can vectorize
vect-early-break_124-pr114403.c.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/vect-early-break_124-pr114403.c: Enable vectrization 
for RISC-V target.

Diff:
---
 gcc/testsuite/gcc.dg/vect/vect-early-break_124-pr114403.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_124-pr114403.c 
b/gcc/testsuite/gcc.dg/vect/vect-early-break_124-pr114403.c
index 101ae1e0eaa..610b951b262 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-early-break_124-pr114403.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_124-pr114403.c
@@ -1,8 +1,9 @@
 /* { dg-add-options vect_early_break } */
 /* { dg-require-effective-target vect_early_break_hw } */
 /* { dg-require-effective-target vect_long_long } */
+/* { dg-additional-options "-mtune=generic-ooo" { target riscv*-*-* } } */
 
-/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" { xfail riscv*-*-* } } 
} */
+/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */
 
 #include "tree-vect.h"
 
@@ -74,4 +75,3 @@ int main ()
 
   return 0;
 }
-


[gcc r15-764] i386: Disable ix86_expand_vecop_qihi2 when !TARGET_AVX512BW

2024-05-21 Thread Haochen Jiang via Gcc-cvs
https://gcc.gnu.org/g:73a167cfa225d5ee7092d41596b9fea1719898ff

commit r15-764-g73a167cfa225d5ee7092d41596b9fea1719898ff
Author: Haochen Jiang 
Date:   Tue May 21 14:10:43 2024 +0800

i386: Disable ix86_expand_vecop_qihi2 when !TARGET_AVX512BW

Since vpermq is really slow, we should avoid using it for permutation
when vpmovwb is not available (needs AVX512BW) for ix86_expand_vecop_qihi2
and fall back to ix86_expand_vecop_qihi.

gcc/ChangeLog:

PR target/115069
* config/i386/i386-expand.cc (ix86_expand_vecop_qihi2):
Do not enable the optimization when AVX512BW is not enabled.

gcc/testsuite/ChangeLog:

PR target/115069
* gcc.target/i386/pr115069.c: New.

Diff:
---
 gcc/config/i386/i386-expand.cc   | 7 +++
 gcc/testsuite/gcc.target/i386/pr115069.c | 9 +
 2 files changed, 16 insertions(+)

diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index 7142c0a9d77..ec402a78a09 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -24188,6 +24188,13 @@ ix86_expand_vecop_qihi2 (enum rtx_code code, rtx dest, 
rtx op1, rtx op2)
   bool op2vec = GET_MODE_CLASS (GET_MODE (op2)) == MODE_VECTOR_INT;
   bool uns_p = code != ASHIFTRT;
 
+  /* Without VPMOVWB (provided by AVX512BW ISA), the expansion uses the
+ generic permutation to merge the data back into the right place.  This
+ permutation results in VPERMQ, which is slow, so better fall back to
+ ix86_expand_vecop_qihi.  */
+  if (!TARGET_AVX512BW)
+return false;
+
   if ((qimode == V16QImode && !TARGET_AVX2)
   || (qimode == V32QImode && (!TARGET_AVX512BW || !TARGET_EVEX512))
   /* There are no V64HImode instructions.  */
diff --git a/gcc/testsuite/gcc.target/i386/pr115069.c 
b/gcc/testsuite/gcc.target/i386/pr115069.c
new file mode 100644
index 000..50a3e033079
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr115069.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx2" } */
+/* { dg-final { scan-assembler-not "vpermq" } } */
+
+typedef char v16qi __attribute__((vector_size(16)));
+
+v16qi foo (v16qi a, v16qi b) {
+return a * b;
+}


[gcc r14-10229] i386: Disable ix86_expand_vecop_qihi2 when !TARGET_AVX512BW

2024-05-21 Thread Haochen Jiang via Gcc-cvs
https://gcc.gnu.org/g:1ad5c9d524d8fa99773045e75da04ae958012085

commit r14-10229-g1ad5c9d524d8fa99773045e75da04ae958012085
Author: Haochen Jiang 
Date:   Tue May 21 14:10:43 2024 +0800

i386: Disable ix86_expand_vecop_qihi2 when !TARGET_AVX512BW

Since vpermq is really slow, we should avoid using it for permutation
when vpmovwb is not available (needs AVX512BW) for ix86_expand_vecop_qihi2
and fall back to ix86_expand_vecop_qihi.

gcc/ChangeLog:

PR target/115069
* config/i386/i386-expand.cc (ix86_expand_vecop_qihi2):
Do not enable the optimization when AVX512BW is not enabled.

gcc/testsuite/ChangeLog:

PR target/115069
* gcc.target/i386/pr115069.c: New.

Diff:
---
 gcc/config/i386/i386-expand.cc   | 7 +++
 gcc/testsuite/gcc.target/i386/pr115069.c | 9 +
 2 files changed, 16 insertions(+)

diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index 8bb8f21e686..51efe6fdd7d 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -23963,6 +23963,13 @@ ix86_expand_vecop_qihi2 (enum rtx_code code, rtx dest, 
rtx op1, rtx op2)
   bool op2vec = GET_MODE_CLASS (GET_MODE (op2)) == MODE_VECTOR_INT;
   bool uns_p = code != ASHIFTRT;
 
+  /* Without VPMOVWB (provided by AVX512BW ISA), the expansion uses the
+ generic permutation to merge the data back into the right place.  This
+ permutation results in VPERMQ, which is slow, so better fall back to
+ ix86_expand_vecop_qihi.  */
+  if (!TARGET_AVX512BW)
+return false;
+
   if ((qimode == V16QImode && !TARGET_AVX2)
   || (qimode == V32QImode && (!TARGET_AVX512BW || !TARGET_EVEX512))
   /* There are no V64HImode instructions.  */
diff --git a/gcc/testsuite/gcc.target/i386/pr115069.c 
b/gcc/testsuite/gcc.target/i386/pr115069.c
new file mode 100644
index 000..50a3e033079
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr115069.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx2" } */
+/* { dg-final { scan-assembler-not "vpermq" } } */
+
+typedef char v16qi __attribute__((vector_size(16)));
+
+v16qi foo (v16qi a, v16qi b) {
+return a * b;
+}