[gcc r15-444] ada: Small fix to Default_Initialize_Object

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:324b37fa94b600d7b8d15108e2bdaf9f9ccc

commit r15-444-g324b37fa94b600d7b8d15108e2bdaf9f9ccc
Author: Eric Botcazou 
Date:   Sun Feb 4 11:16:18 2024 +0100

ada: Small fix to Default_Initialize_Object

Unlike what is assumed in other parts of the front-end, some objects created
with No_Initialization set on their declaration may end up being initialized
with a default value.

gcc/ada/

* exp_ch3.adb (Default_Initialize_Object): Return immediately when
either Has_Init_Expression or No_Initialization is set on the node.
Tidy up the rest of the code accordingly.
(Simple_Initialization_OK): Do not test Has_Init_Expression here.

Diff:
---
 gcc/ada/exp_ch3.adb | 26 ++
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 2477a221c96d..8e5c1f08a860 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -6768,6 +6768,9 @@ package body Exp_Ch3 is
   ---
 
   procedure Default_Initialize_Object (After : Node_Id) is
+ Exceptions_OK : constant Boolean :=
+   not Restriction_Active (No_Exception_Propagation);
+
  function New_Object_Reference return Node_Id;
  --  Return a new reference to Def_Id with attributes Assignment_OK and
  --  Must_Not_Freeze already set.
@@ -6806,13 +6809,10 @@ package body Exp_Ch3 is
(Init_Typ : Entity_Id) return Boolean
  is
  begin
---  Do not consider the object declaration if it comes with an
---  initialization expression, or is internal in which case it
---  will be assigned later.
+--  Skip internal entities as specified in Einfo
 
 return
   not Is_Internal (Def_Id)
-and then not Has_Init_Expression (N)
 and then Needs_Simple_Initialization
(Typ => Init_Typ,
 Consider_IS =>
@@ -6822,9 +6822,6 @@ package body Exp_Ch3 is
 
  --  Local variables
 
- Exceptions_OK : constant Boolean :=
-   not Restriction_Active (No_Exception_Propagation);
-
  Aggr_Init  : Node_Id;
  Comp_Init  : List_Id := No_List;
  Fin_Block  : Node_Id;
@@ -6836,6 +6833,12 @@ package body Exp_Ch3 is
   --  Start of processing for Default_Initialize_Object
 
   begin
+ --  Nothing to do if the object has an initialization expression or
+ --  need not be initialized.
+
+ if Has_Init_Expression (N) or else No_Initialization (N) then
+return;
+
  --  Default initialization is suppressed for objects that are already
  --  known to be imported (i.e. whose declaration specifies the Import
  --  aspect). Note that for objects with a pragma Import, we generate
@@ -6843,7 +6846,9 @@ package body Exp_Ch3 is
  --  the pragma. It is also suppressed for variables for which a pragma
  --  Suppress_Initialization has been explicitly given
 
- if Is_Imported (Def_Id) or else Suppress_Initialization (Def_Id) then
+ elsif Is_Imported (Def_Id)
+   or else Suppress_Initialization (Def_Id)
+ then
 return;
 
  --  Nothing to do if the object being initialized is of a task type
@@ -6877,7 +6882,6 @@ package body Exp_Ch3 is
  --  Initialize the components of the object
 
  if Has_Non_Null_Base_Init_Proc (Typ)
-   and then not No_Initialization (N)
and then not Initialization_Suppressed (Typ)
  then
 --  Do not initialize the components if No_Default_Initialization
@@ -6950,7 +6954,6 @@ package body Exp_Ch3 is
 
  and then Simple_Initialization_OK (Component_Type (Typ))
then
-  Set_No_Initialization (N, False);
   Set_Expression (N,
 Get_Simple_Init_Val
   (Typ  => Typ,
@@ -6978,7 +6981,6 @@ package body Exp_Ch3 is
  --  Provide a default value if the object needs simple initialization
 
  elsif Simple_Initialization_OK (Typ) then
-Set_No_Initialization (N, False);
 Set_Expression (N,
   Get_Simple_Init_Val
 (Typ  => Typ,
@@ -6992,7 +6994,7 @@ package body Exp_Ch3 is
  --  Initialize the object, generate:
  --[Deep_]Initialize (Obj);
 
- if Needs_Finalization (Typ) and then not No_Initialization (N) then
+ if Needs_Finalization (Typ) then
 Obj_Init :=
   Make_Init_Call
 (Obj_Ref => New_Object_Reference,


[gcc r15-445] ada: Fix ghost policy in use for generic instantiation

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:20dfaae2d1ba4749db13792105a32c5d8ef422e3

commit r15-445-g20dfaae2d1ba4749db13792105a32c5d8ef422e3
Author: Yannick Moy 
Date:   Thu Feb 8 11:47:20 2024 +0100

ada: Fix ghost policy in use for generic instantiation

The Ghost assertion policy relevant for analyzing a generic instantiation
is the Ghost policy at the point of instantiation, not the one applicable
for the generic itself.

gcc/ada/

* ghost.adb (Mark_And_Set_Ghost_Instantiation): Fix the current
Ghost policy for the instantiation.

Diff:
---
 gcc/ada/ghost.adb | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/ghost.adb b/gcc/ada/ghost.adb
index 14951a031d9e..677089039e8b 100644
--- a/gcc/ada/ghost.adb
+++ b/gcc/ada/ghost.adb
@@ -1734,13 +1734,17 @@ package body Ghost is
   elsif Ghost_Mode = Ignore then
  Policy := Name_Ignore;
 
-  --  Inherit the "ghostness" of the generic unit
+  --  Inherit the "ghostness" of the generic unit, but the current Ghost
+  --  policy is the relevant one for the instantiation.
 
-  elsif Is_Checked_Ghost_Entity (Gen_Id) then
- Policy := Name_Check;
+  elsif Is_Checked_Ghost_Entity (Gen_Id)
+or else Is_Ignored_Ghost_Entity (Gen_Id)
+  then
+ Policy := Policy_In_Effect (Name_Ghost);
 
-  elsif Is_Ignored_Ghost_Entity (Gen_Id) then
- Policy := Name_Ignore;
+ if Policy = No_Name then
+Policy := Name_Ignore;
+ end if;
   end if;
 
   --  Mark the instantiation as Ghost


[gcc r15-446] ada: Update of SPARK RM legality rules on ghost code

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

commit r15-446-gdf48963b9553a51023c0d115bdf6205309e04bfe
Author: Yannick Moy 
Date:   Fri Feb 2 18:20:06 2024 +0100

ada: Update of SPARK RM legality rules on ghost code

Update checking of ghost code after a small change in SPARK RM
rules 6.9(15) and 6.9(20), so that the Ghost assertion policy
that matters when checking the validity of a reference to a ghost entity
in an assertion expression is the Ghost assertion policy at the point
of declaration of the entity.

Also fix references to SPARK RM rules in comments, which were off by two
in many cases after the insertion of rules 13 and 14 regarding generic
instantiations.

gcc/ada/

* contracts.adb: Fix references to SPARK RM rules.
* freeze.adb: Same.
* ghost.adb: Fix references to SPARK RM rules.
(Check_Ghost_Context): Update checking of references to
ghost entities in assertion expressions.
* sem_ch6.adb: Fix references to SPARK RM rules.
* sem_prag.adb: Same.

Diff:
---
 gcc/ada/contracts.adb |  2 +-
 gcc/ada/freeze.adb|  2 +-
 gcc/ada/ghost.adb | 44 
 gcc/ada/sem_ch6.adb   | 14 +++---
 gcc/ada/sem_prag.adb  | 12 ++--
 5 files changed, 39 insertions(+), 35 deletions(-)

diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb
index 810b360fb94e..9fc9e05db687 100644
--- a/gcc/ada/contracts.adb
+++ b/gcc/ada/contracts.adb
@@ -1114,7 +1114,7 @@ package body Contracts is
   if Comes_From_Source (Obj_Id) and then Is_Ghost_Entity (Obj_Id) then
 
  --  A Ghost object cannot be of a type that yields a synchronized
- --  object (SPARK RM 6.9(19)).
+ --  object (SPARK RM 6.9(21)).
 
  if Yields_Synchronized_Object (Obj_Typ) then
 Error_Msg_N ("ghost object & cannot be synchronized", Obj_Id);
diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index dd4eff1ed199..a980c7e5b47a 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -4094,7 +4094,7 @@ package body Freeze is
  <>
 
  --  A Ghost type cannot have a component of protected or task type
- --  (SPARK RM 6.9(19)).
+ --  (SPARK RM 6.9(21)).
 
  if Is_Ghost_Entity (Arr) and then Is_Concurrent_Type (Ctyp) then
 Error_Msg_N
diff --git a/gcc/ada/ghost.adb b/gcc/ada/ghost.adb
index 677089039e8b..d220e0e1ec0d 100644
--- a/gcc/ada/ghost.adb
+++ b/gcc/ada/ghost.adb
@@ -121,7 +121,7 @@ package body Ghost is
  null;
 
   --  The Ghost policy in effect at the point of declaration and at the
-  --  point of completion must match (SPARK RM 6.9(14)).
+  --  point of completion must match (SPARK RM 6.9(16)).
 
   elsif Is_Checked_Ghost_Entity (Prev_Id)
 and then Policy = Name_Ignore
@@ -173,9 +173,9 @@ package body Ghost is
  --
  --* Be subject to pragma Ghost
 
- function Is_OK_Pragma (Prag : Node_Id) return Boolean;
+ function Is_OK_Pragma (Prag : Node_Id; Id : Entity_Id) return Boolean;
  --  Determine whether node Prag is a suitable context for a reference
- --  to a Ghost entity. To qualify as such, Prag must either
+ --  to a Ghost entity Id. To qualify as such, Prag must either
  --
  --* Be an assertion expression pragma
  --
@@ -318,9 +318,11 @@ package body Ghost is
  -- Is_OK_Pragma --
  --
 
- function Is_OK_Pragma (Prag : Node_Id) return Boolean is
+ function Is_OK_Pragma (Prag : Node_Id; Id : Entity_Id) return Boolean
+ is
 procedure Check_Policies (Prag_Nam : Name_Id);
---  Verify that the Ghost policy in effect is the same as the
+--  Verify that the Ghost policy in effect at the point of the
+--  declaration of Ghost entity Id (if present) is the same as the
 --  assertion policy for pragma name Prag_Nam. Emit an error if
 --  this is not the case.
 
@@ -330,14 +332,16 @@ package body Ghost is
 
 procedure Check_Policies (Prag_Nam : Name_Id) is
AP : constant Name_Id := Check_Kind (Prag_Nam);
-   GP : constant Name_Id := Policy_In_Effect (Name_Ghost);
 
 begin
-   --  If the Ghost policy in effect at the point of a Ghost entity
-   --  reference is Ignore, then the assertion policy of the pragma
-   --  must be Ignore (SPARK RM 6.9(18)).
+   --  If the Ghost policy in effect at the point of the
+   --  declaration of Ghost entity Id is Ignore, then the assertion
+   --  policy of the pragma must be Ignore (SPARK RM 6.9(20)).
 
-   if GP = Name_Ignore and then AP /= Name_Ignore then
+   if Present (Id)
+ and then not Is_Checked_G

[gcc r15-448] ada: Fix crash with -gnatyB and -gnatdJ

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:821772478bdc8cb52249aa561975e4ff6aa7792f

commit r15-448-g821772478bdc8cb52249aa561975e4ff6aa7792f
Author: Ronan Desplanques 
Date:   Fri Feb 2 18:08:57 2024 +0100

ada: Fix crash with -gnatyB and -gnatdJ

The crash this patch fixes happened because calling the Errout.Error_Msg
procedures that don't have an N parameter is not allowed when not
parsing and -gnatdJ is on. And -gnatyB style checks are not emitted during
parsing but during semantic analysis.

This commit moves Check_Boolean_Operator from Styleg to Style so it can
call Errout.Error_Msg with a Node_Id parameter. This change of package
makes sense because:

1. The compiler is currently the only user of Check_Boolean_Operator.
2. Other tools don't do semantic analysis, and so cannot possibly
know when to use Check_Boolean_Operator anyway.

gcc/ada/

* styleg.ads (Check_Boolean_Operator): Moved ...
* style.ads (Check_Boolean_Operator): ... here.
* styleg.adb (Check_Boolean_Operator): Moved ...
* style.adb (Check_Boolean_Operator): ... here. Also add node
parameter to call to Errout.Error_Msg.

Diff:
---
 gcc/ada/style.adb  | 81 
 gcc/ada/style.ads  |  3 +-
 gcc/ada/styleg.adb | 83 --
 gcc/ada/styleg.ads |  4 ---
 4 files changed, 82 insertions(+), 89 deletions(-)

diff --git a/gcc/ada/style.adb b/gcc/ada/style.adb
index e73bfddb524c..aaa668aab000 100644
--- a/gcc/ada/style.adb
+++ b/gcc/ada/style.adb
@@ -94,6 +94,87 @@ package body Style is
   end if;
end Check_Array_Attribute_Index;
 
+   
+   -- Check_Boolean_Operator --
+   
+
+   procedure Check_Boolean_Operator (Node : Node_Id) is
+
+  function OK_Boolean_Operand (N : Node_Id) return Boolean;
+  --  Returns True for simple variable, or "not X1" or "X1 and X2" or
+  --  "X1 or X2" where X1, X2 are recursively OK_Boolean_Operand's.
+
+  
+  -- OK_Boolean_Operand --
+  
+
+  function OK_Boolean_Operand (N : Node_Id) return Boolean is
+  begin
+ if Nkind (N) in N_Identifier | N_Expanded_Name then
+return True;
+
+ elsif Nkind (N) = N_Op_Not then
+return OK_Boolean_Operand (Original_Node (Right_Opnd (N)));
+
+ elsif Nkind (N) in N_Op_And | N_Op_Or then
+return OK_Boolean_Operand (Original_Node (Left_Opnd (N)))
+ and then
+   OK_Boolean_Operand (Original_Node (Right_Opnd (N)));
+
+ else
+return False;
+ end if;
+  end OK_Boolean_Operand;
+
+   --  Start of processing for Check_Boolean_Operator
+
+   begin
+  if Style_Check_Boolean_And_Or
+and then Comes_From_Source (Node)
+  then
+ declare
+Orig : constant Node_Id := Original_Node (Node);
+
+ begin
+if Nkind (Orig) in N_Op_And | N_Op_Or then
+   declare
+  L : constant Node_Id := Original_Node (Left_Opnd  (Orig));
+  R : constant Node_Id := Original_Node (Right_Opnd (Orig));
+
+   begin
+  --  First OK case, simple boolean constants/identifiers
+
+  if OK_Boolean_Operand (L)
+   and then
+ OK_Boolean_Operand (R)
+  then
+ return;
+
+  --  Second OK case, modular types
+
+  elsif Is_Modular_Integer_Type (Etype (Node)) then
+ return;
+
+  --  Third OK case, array types
+
+  elsif Is_Array_Type (Etype (Node)) then
+ return;
+
+  --  Otherwise we have an error
+
+  elsif Nkind (Orig) = N_Op_And then
+ Error_Msg -- CODEFIX
+   ("(style) `AND THEN` required?B?", Sloc (Orig), Orig);
+  else
+ Error_Msg -- CODEFIX
+   ("(style) `OR ELSE` required?B?", Sloc (Orig), Orig);
+  end if;
+   end;
+end if;
+ end;
+  end if;
+   end Check_Boolean_Operator;
+
--
-- Check_Identifier --
--
diff --git a/gcc/ada/style.ads b/gcc/ada/style.ads
index dc8b337f2bd4..c0925e9ce345 100644
--- a/gcc/ada/style.ads
+++ b/gcc/ada/style.ads
@@ -90,8 +90,7 @@ package Style is
--  designator is a reserved word (access, digits, delta or range) to allow
--  differing rules for the two cases.
 
-   procedure Check_Boolean_Operator (Node : Node_Id)
- renames Style_Inst.Check_Boolean_Operator;
+   procedure Check_Boolean_Operator (Node : Node_Id);
--  Called after resolving AND or OR node to check short circuit ru

[gcc r15-450] ada: Rtsfind should not trash state used in analyzing instantiations.

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

commit r15-450-gb2453909f68aa3e6810e4995bdcb0a555aab3902
Author: Steve Baird 
Date:   Wed Feb 7 11:47:22 2024 -0800

ada: Rtsfind should not trash state used in analyzing instantiations.

During analysis of an instantiation, Sem_Ch12 manages formal/actual binding
information in package state (see Sem_Ch12.Generic_Renamings_HTable).
A call to rtsfind can cause another unit to be loaded and compiled.
If this occurs during the analysis of an instantiation, and if the loaded
unit contains a second instantiation, then the Sem_Ch12 state needed for
analyzing the first instantiation can be trashed during the analysis of the
second instantiation. Rtsfind calls that can include the analysis of an
instantiation need to save and restore Sem_Ch12's state.

gcc/ada/

* sem_ch12.ads: Declare new Instance_Context package, which
declares a private type Context with operations Save_And_Reset and
Restore.
* sem_ch12.adb: Provide body for new Instance_Context package.
* rtsfind.adb (Load_RTU): Wrap an Instance_Context Save/Restore
call pair around the call to Semantics.
* table.ads: Add initial value for Last_Val (because
Save_And_Reset expects Last_Val to be initialized).

Diff:
---
 gcc/ada/rtsfind.adb  |  9 +++-
 gcc/ada/sem_ch12.adb | 62 
 gcc/ada/sem_ch12.ads | 25 +
 gcc/ada/table.ads|  2 +-
 4 files changed, 96 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/rtsfind.adb b/gcc/ada/rtsfind.adb
index 8933ca6ce168..7c9935e614c2 100644
--- a/gcc/ada/rtsfind.adb
+++ b/gcc/ada/rtsfind.adb
@@ -47,6 +47,7 @@ with Restrict;   use Restrict;
 with Sem;use Sem;
 with Sem_Aux;use Sem_Aux;
 with Sem_Ch7;use Sem_Ch7;
+with Sem_Ch12;use Sem_Ch12;
 with Sem_Dist;   use Sem_Dist;
 with Sem_Util;   use Sem_Util;
 with Sinfo;  use Sinfo;
@@ -1185,7 +1186,13 @@ package body Rtsfind is
 
 else
Save_Private_Visibility;
-   Semantics (Cunit (U.Unum));
+   declare
+  Saved_Instance_Context : constant Instance_Context.Context
+:= Instance_Context.Save_And_Reset;
+   begin
+  Semantics (Cunit (U.Unum));
+  Instance_Context.Restore (Saved_Instance_Context);
+   end;
Restore_Private_Visibility;
 
if Fatal_Error (U.Unum) = Error_Detected then
diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index cb05a71e96f9..4ceddda20526 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -17753,4 +17753,66 @@ package body Sem_Ch12 is
 raise Program_Error;
   end case;
end Validate_Formal_Type_Default;
+
+   package body Instance_Context is
+
+  
+  -- Save_And_Reset --
+  
+
+  function Save_And_Reset return Context is
+  begin
+ return Result : Context (0 .. Integer (Generic_Renamings.Last)) do
+for Index in Result'Range loop
+   declare
+  Indexed_Assoc : Assoc renames Generic_Renamings.Table
+  (Assoc_Ptr (Index));
+  Result_Pair : Binding_Pair renames Result (Index);
+   begin
+  --  If we have called Increment_Last but have not yet
+  --  initialized the new last element of the table, then
+  --  that last element might be invalid. Saving and
+  --  restoring (especially restoring, it turns out) invalid
+  --  values can result in exceptions if predicate checking
+  --  is enabled, so replace invalid values with Empty.
+
+  if Indexed_Assoc.Gen_Id'Valid then
+ Result_Pair.Formal_Id := Indexed_Assoc.Gen_Id;
+  else
+ pragma Assert (Index = Result'Last);
+ Result_Pair.Formal_Id := Empty;
+  end if;
+
+  if Indexed_Assoc.Act_Id'Valid then
+ Result_Pair.Actual_Id := Indexed_Assoc.Act_Id;
+  else
+ pragma Assert (Index = Result'Last);
+ Result_Pair.Actual_Id := Empty;
+  end if;
+   end;
+end loop;
+
+Generic_Renamings.Init;
+Generic_Renamings.Set_Last (0);
+Generic_Renamings_HTable.Reset;
+ end return;
+  end Save_And_Reset;
+
+  -
+  -- Restore --
+  -
+
+  procedure Restore (Saved : Context) is
+  begin
+ Generic_Renamings.Init;
+ Generic_Renamings.Set_Last (0);
+ Generic_Renamin

[gcc r15-447] ada: Small fix to printing of raise statements

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:4dd6f75e35065f2f0732c4cfbaf412b50c51e26e

commit r15-447-g4dd6f75e35065f2f0732c4cfbaf412b50c51e26e
Author: Eric Botcazou 
Date:   Thu Feb 8 15:45:11 2024 +0100

ada: Small fix to printing of raise statements

The Name is optional on these nodes and a superflous space is printed if
it is not present on them.

gcc/ada/

* sprint.adb (Sprint_Node_Actual) : Be prepared
for an empty Name.
: Likewise.

Diff:
---
 gcc/ada/sprint.adb | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/sprint.adb b/gcc/ada/sprint.adb
index 938b378b66b2..3f73006ad6e0 100644
--- a/gcc/ada/sprint.adb
+++ b/gcc/ada/sprint.adb
@@ -3116,8 +3116,12 @@ package body Sprint is
 Write_Condition_And_Reason (Node);
 
  when N_Raise_Statement =>
-Write_Indent_Str_Sloc ("raise ");
-Sprint_Node (Name (Node));
+if Present (Name (Node)) then
+   Write_Indent_Str_Sloc ("raise ");
+   Sprint_Node (Name (Node));
+else
+   Write_Indent_Str_Sloc ("raise");
+end if;
 
 if Present (Expression (Node)) then
Write_Str_With_Col_Check_Sloc (" with ");
@@ -3127,8 +3131,12 @@ package body Sprint is
 Write_Char (';');
 
  when N_Raise_When_Statement =>
-Write_Indent_Str_Sloc ("raise ");
-Sprint_Node (Name (Node));
+if Present (Name (Node)) then
+   Write_Indent_Str_Sloc ("raise ");
+   Sprint_Node (Name (Node));
+else
+   Write_Indent_Str_Sloc ("raise");
+end if;
 Write_Str (" when ");
 Sprint_Node (Condition (Node));


[gcc r15-449] ada: Factor out implementation of default initialization for objects

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

commit r15-449-gcad2744cb385413d4762057a19f972fcb74233d6
Author: Eric Botcazou 
Date:   Tue Feb 6 19:31:09 2024 +0100

ada: Factor out implementation of default initialization for objects

As written down in a comment, "There is a *huge* amount of code duplication"
in the implementation of default initializaion for objects in the front-end,
between the (static) declaration case and the dynamic allocation case.

This change factors out the implementation of the (static) declaration case
and uses it for the dynamic allocation case, with the following benefits:

  1. getting rid of the duplication and reducing total line count,

  2. bringing optimizations implemented for the (static) declaration case
 to the dynamic allocation case,

  3. performing the missing abort deferral prescribed by RM 9.8(9) in the
 dynamic allocation case.

gcc/ada/

* exp_aggr.adb (Build_Record_Aggr_Code): Replace reference to
Build_Task_Allocate_Block_With_Init_Stmts in comment with reference
to Build_Task_Allocate_Block.
(Convert_Aggr_In_Allocator): Likewise for the call in the code.
* exp_ch6.adb (Make_Build_In_Place_Call_In_Allocator): Likewise.
* exp_ch3.ads: Alphabetize clauses.
(Build_Default_Initialization): New function declaration.
(Build_Default_Simple_Initialization): Likewise.
(Build_Initialization_Call): Add Target_Ref parameter with default.
* exp_ch3.adb (Build_Default_Initialization): New function extracted
from...
(Build_Default_Simple_Initialization): Likewise.
(Build_Initialization_Call): Add Target_Ref parameter with default.
(Expand_N_Object_Declaration): ...here.
(Default_Initialize_Object): Call Build_Default_Initialization and
Build_Default_Simple_Initialization.
* exp_ch4.adb (Expand_Allocator_Expression): Minor comment tweaks.
(Expand_N_Allocator): Call Build_Default_Initialization and
Build_Default_Simple_Initialization to implement the default
initialization of the allocated object.
* exp_ch9.ads (Build_Task_Allocate_Block): Delete.
(Build_Task_Allocate_Block_With_Init_Stmts): Rename into...
(Build_Task_Allocate_Block): ...this.
* exp_ch9.adb: Remove clauses for Exp_Tss.
(Build_Task_Allocate_Block): Delete.
(Build_Task_Allocate_Block_With_Init_Stmts): Rename into...
(Build_Task_Allocate_Block): ...this.
* exp_util.adb (Build_Allocate_Deallocate_Proc): Remove unnecessary
initialization expression, adjust commentary and replace early exit
with assertion.
* sem_ch4.adb (Analyze_Allocator): In the null-exclusion case, call
Apply_Compile_Time_Constraint_Error to insert the raise.

Diff:
---
 gcc/ada/exp_aggr.adb |4 +-
 gcc/ada/exp_ch3.adb  | 1015 +++---
 gcc/ada/exp_ch3.ads  |   53 ++-
 gcc/ada/exp_ch4.adb  |  605 +-
 gcc/ada/exp_ch6.adb  |2 +-
 gcc/ada/exp_ch9.adb  |   67 +---
 gcc/ada/exp_ch9.ads  |   19 +-
 gcc/ada/exp_util.adb |   28 +-
 gcc/ada/sem_ch4.adb  |   21 +-
 9 files changed, 795 insertions(+), 1019 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index c82bd07aedc9..86f304e90bba 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -3192,7 +3192,7 @@ package body Exp_Aggr is
 --  Ada 2005 (AI-287): If the component type has tasks then
 --  generate the activation chain and master entities (except
 --  in case of an allocator because in that case these entities
---  are generated by Build_Task_Allocate_Block_With_Init_Stmts).
+--  are generated by Build_Task_Allocate_Block).
 
 declare
Ctype: constant Entity_Id := Etype (Selector);
@@ -3567,7 +3567,7 @@ package body Exp_Aggr is
 Init_Stmts := Late_Expansion (Aggr, Typ, Occ);
 
 if Has_Task (Typ) then
-   Build_Task_Allocate_Block_With_Init_Stmts (L, Aggr, Init_Stmts);
+   Build_Task_Allocate_Block (L, Aggr, Init_Stmts);
Insert_Actions (Alloc, L);
 else
Insert_Actions (Alloc, Init_Stmts);
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 8e5c1f08a860..4bb69b03e3df 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -962,6 +962,524 @@ package body Exp_Ch3 is
   end if;
end Build_Array_Init_Proc;
 
+   --
+   -- Build_Default_Initialization --
+   --
+
+   function Build_Default_Initialization
+ (N  : Node_Id;
+  Typ

[gcc r15-451] ada: Error in determining accumulator subtype for a reduction expression

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

commit r15-451-gd9f3a1d612eacc35027bc5ca42b0ee29b554306a
Author: Steve Baird 
Date:   Wed Feb 7 13:52:58 2024 -0800

ada: Error in determining accumulator subtype for a reduction expression

There was an earlier bug in determining the accumulator subtype for a
reduction expression in the case where the reducer subprogram is overloaded.
The fix for that bug introduced a recently-discovered
regression. Redo accumulator subtype computation in order to address
this regression while preserving the benefits of the earlier fix.

gcc/ada/

* exp_attr.adb: Move computation of Accum_Typ entirely into the
function Build_Stat.

Diff:
---
 gcc/ada/exp_attr.adb | 65 +---
 1 file changed, 26 insertions(+), 39 deletions(-)

diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index 63b311c1b890..809116d89e3f 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -24,7 +24,6 @@
 --
 
 with Accessibility;  use Accessibility;
-with Aspects;use Aspects;
 with Atree;  use Atree;
 with Checks; use Checks;
 with Debug;  use Debug;
@@ -6013,6 +6012,7 @@ package body Exp_Attr is
 
 begin
if Nkind (E1) = N_Attribute_Reference then
+  Accum_Typ := Base_Type (Entity (Prefix (E1)));
   Stat := Make_Assignment_Statement (Loc,
 Name => New_Occurrence_Of (Bnn, Loc),
 Expression => Make_Attribute_Reference (Loc,
@@ -6023,12 +6023,15 @@ package body Exp_Attr is
 Comp)));
 
elsif Ekind (Entity (E1)) = E_Procedure then
+  Accum_Typ := Etype (First_Formal (Entity (E1)));
   Stat := Make_Procedure_Call_Statement (Loc,
 Name => New_Occurrence_Of (Entity (E1), Loc),
Parameter_Associations => New_List (
  New_Occurrence_Of (Bnn, Loc),
  Comp));
+
else
+  Accum_Typ := Etype (Entity (E1));
   Stat := Make_Assignment_Statement (Loc,
 Name => New_Occurrence_Of (Bnn, Loc),
 Expression => Make_Function_Call (Loc,
@@ -6038,6 +6041,28 @@ package body Exp_Attr is
 Comp)));
end if;
 
+   --  Try to cope if E1 is wrong because it is an overloaded
+   --  subprogram that happens to be the first candidate
+   --  on a homonym chain, but that resolution candidate turns
+   --  out to be the wrong one.
+   --  This workaround usually gets the right type, but it can
+   --  yield the wrong subtype of that type.
+
+   if Base_Type (Accum_Typ) /= Base_Type (Etype (N)) then
+  Accum_Typ := Etype (N);
+   end if;
+
+   --  Try to cope with wrong E1 when Etype (N) doesn't help
+   if Is_Universal_Numeric_Type (Accum_Typ) then
+  if Is_Array_Type (Etype (Prefix (N))) then
+ Accum_Typ := Component_Type (Etype (Prefix (N)));
+  else
+ --  Further hackery can be added here when there is a
+ --  demonstrated need.
+ null;
+  end if;
+   end if;
+
return Stat;
 end Build_Stat;
 
@@ -6088,10 +6113,6 @@ package body Exp_Attr is
   End_Label => Empty,
   Statements =>
 New_List (Build_Stat (Relocate_Node (Expr;
-
-  --  Look at the context to find the type.
-
-  Accum_Typ := Etype (N);
end;
 
 else
@@ -6121,40 +6142,6 @@ package body Exp_Attr is
   Statements => New_List (
 Build_Stat (New_Occurrence_Of (Elem, Loc;
 
-  --  Look at the prefix to find the type. This is
-  --  modeled on Analyze_Iterator_Specification in Sem_Ch5.
-
-  declare
- Ptyp : constant Entity_Id :=
-  Base_Type (Etype (Prefix (N)));
-
-  begin
- if Is_Array_Type (Ptyp) then
-Accum_Typ := Component_Type (Ptyp);
-
- elsif Has_Aspect (Ptyp, Aspect_Iterable) then
-declare
-   Element : constant Entity_Id :=
-   Get_Iterable_Type_Primitive
- (Ptyp, Name_Element);
-b

[gcc r15-460] ada: Replace "not Present" tests with "No".

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

commit r15-460-gfb48b0aa2faf88897fb0110026e80dfa1a59056f
Author: Steve Baird 
Date:   Mon Feb 12 13:39:45 2024 -0800

ada: Replace "not Present" tests with "No".

Fix constructs that were flagged by CodePeer.

gcc/ada/

* exp_attr.adb: Replace 6 "not Present" tests with equivalent calls 
to "No".

Diff:
---
 gcc/ada/exp_attr.adb | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index b7277118a9cb..6dba600620ec 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -4334,7 +4334,7 @@ package body Exp_Attr is
 
  Fname := Find_Stream_Subprogram (P_Type, TSS_Stream_Input, N);
 
- if not Present (Fname) then
+ if No (Fname) then
 
 --  If there is a Stream_Convert pragma, use it, we rewrite
 
@@ -5422,7 +5422,7 @@ package body Exp_Attr is
 
  Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Output, N);
 
- if not Present (Pname) then
+ if No (Pname) then
 
 --  If there is a Stream_Convert pragma, use it, we rewrite
 
@@ -5998,7 +5998,7 @@ package body Exp_Attr is
Pname := Cached_Attribute_Ops.Put_Image_Map.Get (U_Type);
Cached_Attribute_Ops.Validate_Cached_Candidate
  (Pname, Attr_Ref => N);
-   if not Present (Pname) then
+   if No (Pname) then
   declare
  procedure Build_And_Insert_Array_Put_Image_Proc is
new Build_And_Insert_Type_Attr_Subp
@@ -6052,7 +6052,7 @@ package body Exp_Attr is
   Pname := Cached_Attribute_Ops.Put_Image_Map.Get (Base_Typ);
   Cached_Attribute_Ops.Validate_Cached_Candidate
 (Pname, Attr_Ref => N);
-  if not Present (Pname) then
+  if No (Pname) then
  declare
 procedure Build_And_Insert_Record_Put_Image_Proc is
   new Build_And_Insert_Type_Attr_Subp
@@ -6352,7 +6352,7 @@ package body Exp_Attr is
 
  Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Read, N);
 
- if not Present (Pname) then
+ if No (Pname) then
 
 --  If there is a Stream_Convert pragma, use it, we rewrite
 
@@ -8067,7 +8067,7 @@ package body Exp_Attr is
 
  Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Write, N);
 
- if not Present (Pname) then
+ if No (Pname) then
 
 --  If there is a Stream_Convert pragma, use it, we rewrite


[gcc r15-463] ada: Restore default size for dynamic allocations of discriminated type

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:062626502fd5d56cd19c5e20c19f2d7cc2c03986

commit r15-463-g062626502fd5d56cd19c5e20c19f2d7cc2c03986
Author: Eric Botcazou 
Date:   Mon Feb 12 15:23:41 2024 +0100

ada: Restore default size for dynamic allocations of discriminated type

The allocation strategy for objects of a discriminated type with defaulted
discriminants is not the same when the allocation is dynamic as when it is
static (i.e a declaration): in the former case, the compiler allocates the
default size whereas, in the latter case, it allocates the maximum size.

This restores the default size, which was dropped during the refactoring.

gcc/ada/

* exp_aggr.adb (Build_Array_Aggr_Code): Pass N in the call to
Build_Initialization_Call.
(Build_Record_Aggr_Code): Likewise.
(Convert_Aggr_In_Object_Decl): Likewise.
(Initialize_Discriminants): Likewise.
* exp_ch3.ads (Build_Initialization_Call): Replace Loc witn N.
* exp_ch3.adb (Build_Array_Init_Proc): Pass N in the call to
Build_Initialization_Call.
(Build_Default_Initialization): Likewise.
(Expand_N_Object_Declaration): Likewise.
(Build_Initialization_Call): Replace Loc witn N parameter and add
Loc local variable.  Build a default subtype for an allocator of
a discriminated type with defaulted discriminants.
(Build_Record_Init_Proc): Pass the declaration of components in the
call to Build_Initialization_Call.
* exp_ch6.adb (Make_CPP_Constructor_Call_In_Allocator): Pass the
allocator in the call to Build_Initialization_Call.

Diff:
---
 gcc/ada/exp_aggr.adb | 18 --
 gcc/ada/exp_ch3.adb  | 37 -
 gcc/ada/exp_ch3.ads  |  4 ++--
 gcc/ada/exp_ch6.adb  |  2 +-
 4 files changed, 39 insertions(+), 22 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 86f304e90bba..a4e4d81f0a8f 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -1493,7 +1493,7 @@ package body Exp_Aggr is
   or else Has_Task (Base_Type (Ctype))
 then
Append_List_To (Stmts,
- Build_Initialization_Call (Loc,
+ Build_Initialization_Call (N,
Id_Ref=> Indexed_Comp,
Typ   => Ctype,
With_Default_Init => True));
@@ -2936,7 +2936,7 @@ package body Exp_Aggr is
 
if not Is_Interface (Init_Typ) then
   Append_List_To (L,
-Build_Initialization_Call (Loc,
+Build_Initialization_Call (N,
   Id_Ref=> Ref,
   Typ   => Init_Typ,
   In_Init_Proc  => Within_Init_Proc,
@@ -2971,7 +2971,7 @@ package body Exp_Aggr is
Set_Assignment_OK (Ref);
 
Append_List_To (L,
- Build_Initialization_Call (Loc,
+ Build_Initialization_Call (N,
Id_Ref=> Ref,
Typ   => Init_Typ,
In_Init_Proc  => Within_Init_Proc,
@@ -3148,7 +3148,7 @@ package body Exp_Aggr is
 
  if Is_CPP_Constructor_Call (Expression (Comp)) then
 Append_List_To (L,
-  Build_Initialization_Call (Loc,
+  Build_Initialization_Call (N,
 Id_Ref=>
   Make_Selected_Component (Loc,
 Prefix=> New_Copy_Tree (Target),
@@ -3217,7 +3217,7 @@ package body Exp_Aggr is
 end;
 
 Append_List_To (L,
-  Build_Initialization_Call (Loc,
+  Build_Initialization_Call (N,
 Id_Ref=> Make_Selected_Component (Loc,
Prefix=> New_Copy_Tree (Target),
Selector_Name =>
@@ -3747,8 +3747,8 @@ package body Exp_Aggr is
   Param := First (Parameter_Associations (Stmt));
   Insert_Actions
 (Stmt,
- Build_Initialization_Call
-   (Sloc (N), New_Copy_Tree (Param), Etype (Param)));
+ Build_Initialization_Call (N,
+   New_Copy_Tree (Param), Etype (Param)));
end if;
 
Next (Stmt);
@@ -9279,13 +9279,11 @@ package body Exp_Aggr is
   Present (Variant_Part (Component_List (Type_Definition (Decl
 and then Nkind (N) /= N_Extension_Aggregate
   then
-
  --   Call init proc to set discriminants.
  --   There should eventually be a special procedure for this ???
 
  Ref := New_Occurrence_Of (Defining_Identifier (N), Loc);
- Insert_Actions_After (N,
-   Bui

[gcc r15-464] ada: Fix crash with -gnatdJ and -gnatw.w

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:34aba1547d277eb8c7fa5db7f58e35b1726693df

commit r15-464-g34aba1547d277eb8c7fa5db7f58e35b1726693df
Author: Ronan Desplanques 
Date:   Tue Feb 13 11:04:00 2024 +0100

ada: Fix crash with -gnatdJ and -gnatw.w

This patch fixes a crash when -gnatdJ is enabled and a warning
must be emitted about an ineffective pragma Warnings clause.

Some modifications are made to the specific warnings machinery so
that warnings carry the ID of the pragma node they're about, so the
-gnatdJ mechanism can find an appropriate enclosing subprogram.

gcc/ada/

* sem_prag.adb (Analyze_Pragma): Adapt call to new signature.
* erroutc.ads (Set_Specific_Warning_Off): change signature
and update documentation.
(Validate_Specific_Warnings): Move ...
* errout.adb: ... here and change signature. Also move body
of Validate_Specific_Warnings from erroutc.adb.
(Finalize): Adapt call.
* errout.ads (Set_Specific_Warning_Off): Adapt signature of
renaming.
* erroutc.adb (Set_Specific_Warning_Off): Adapt signature and
body.
(Validate_Specific_Warnings): Move to the body of Errout.
(Warning_Specifically_Suppressed): Adapt body.

Diff:
---
 gcc/ada/errout.adb   | 50 +++-
 gcc/ada/errout.ads   |  2 +-
 gcc/ada/erroutc.adb  | 58 
 gcc/ada/erroutc.ads  | 25 --
 gcc/ada/sem_prag.adb |  2 +-
 5 files changed, 69 insertions(+), 68 deletions(-)

diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
index c4761bd1bc9e..4622290897b9 100644
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -213,6 +213,10 @@ package body Errout is
--  should have 'Class appended to its name (see Add_Class procedure), and
--  is otherwise unchanged.
 
+   procedure Validate_Specific_Warnings;
+   --  Checks that specific warnings are consistent (for non-configuration
+   --  case, properly closed, and used).
+
function Warn_Insertion return String;
--  This is called for warning messages only (so Warning_Msg_Char is set)
--  and returns a corresponding string to use at the beginning of generated
@@ -1745,7 +1749,7 @@ package body Errout is
   --  do this on the last call, after all possible warnings are posted.
 
   if Last_Call then
- Validate_Specific_Warnings (Error_Msg'Access);
+ Validate_Specific_Warnings;
   end if;
end Finalize;
 
@@ -2001,6 +2005,50 @@ package body Errout is
   --  True if S starts with Size_For
end Is_Size_Too_Small_Message;
 
+   
+   -- Validate_Specific_Warnings --
+   
+
+   procedure Validate_Specific_Warnings is
+   begin
+  if not Warnsw.Warn_On_Warnings_Off then
+ return;
+  end if;
+
+  for J in Specific_Warnings.First .. Specific_Warnings.Last loop
+ declare
+SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
+
+ begin
+if not SWE.Config then
+
+   --  Warn for unmatched Warnings (Off, ...)
+
+   if SWE.Open then
+  Error_Msg_N
+("?.w?pragma Warnings Off with no matching Warnings On",
+ SWE.Start);
+
+   --  Warn for ineffective Warnings (Off, ..)
+
+   elsif not SWE.Used
+
+ --  Do not issue this warning for -Wxxx messages since the
+ --  back-end doesn't report the information. Note that there
+ --  is always an asterisk at the start of every message.
+
+ and then not
+   (SWE.Msg'Length > 3 and then SWE.Msg (2 .. 3) = "-W")
+   then
+  Error_Msg_N
+("?.w?no warning suppressed by this pragma",
+ SWE.Start);
+   end if;
+end if;
+ end;
+  end loop;
+   end Validate_Specific_Warnings;
+
---
-- Last_Node --
---
diff --git a/gcc/ada/errout.ads b/gcc/ada/errout.ads
index 5a7764aa0a36..089da867d454 100644
--- a/gcc/ada/errout.ads
+++ b/gcc/ada/errout.ads
@@ -896,7 +896,7 @@ package Errout is
--  location from which warnings are to be turned back on.
 
procedure Set_Specific_Warning_Off
- (Loc: Source_Ptr;
+ (Node   : Node_Id;
   Msg: String;
   Reason : String_Id;
   Config : Boolean;
diff --git a/gcc/ada/erroutc.adb b/gcc/ada/erroutc.adb
index 125cbf822ffc..96d8d128d843 100644
--- a/gcc/ada/erroutc.adb
+++ b/gcc/ada/erroutc.adb
@@ -38,6 +38,7 @@ with Fname;use Fname;
 with Namet;use Namet;
 with Opt;  use Opt;
 with Output;   use Output;
+with Sinfo.Nodes;
 with Sinput;   use Sinput;
 with Snames;   use Snames;
 with Stringt;  use Stringt;
@@ -1650,15 +165

[gcc r15-467] ada: Fix warning indicators in usage string

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

commit r15-467-gad510c7c8b72cfe43ec0c0c94d650cdff91cc6a6
Author: Ronan Desplanques 
Date:   Wed Feb 14 10:34:32 2024 +0100

ada: Fix warning indicators in usage string

Before this patch, the default status of -gnatw.i and -gnatw.d are
reported incorrectly in the usage string used throughout GNAT tools.
This patch fixes this.

gcc/ada/

* usage.adb (Usage): Fix enabled-by-default indicators.

Diff:
---
 gcc/ada/usage.adb | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/usage.adb b/gcc/ada/usage.adb
index 85b371ac4f1a..59cbd6f4a2f6 100644
--- a/gcc/ada/usage.adb
+++ b/gcc/ada/usage.adb
@@ -498,8 +498,8 @@ begin
  "Compile_Time_Warning");
Write_Line ("dturn on warnings for implicit dereference");
Write_Line ("D*   turn off warnings for implicit dereference");
-   Write_Line (".d   turn on tagging of warnings with -gnatw switch");
-   Write_Line (".D*  turn off tagging of warnings with -gnatw switch");
+   Write_Line (".d*  turn on tagging of warnings with -gnatw switch");
+   Write_Line (".D   turn off tagging of warnings with -gnatw switch");
Write_Line ("etreat all warnings (but not info) as errors");
Write_Line (".e   turn on every optional info/warning " &
   "(no exceptions)");
@@ -517,8 +517,8 @@ begin
Write_Line (".H*  turn off warnings for holes in records");
Write_Line ("i*+  turn on warnings for implementation unit");
Write_Line ("Iturn off warnings for implementation unit");
-   Write_Line (".i*+ turn on warnings for overlapping actuals");
-   Write_Line (".I   turn off warnings for overlapping actuals");
+   Write_Line (".i+  turn on warnings for overlapping actuals");
+   Write_Line (".I*  turn off warnings for overlapping actuals");
Write_Line ("j+   turn on warnings for obsolescent " &
   "(annex J) feature");
Write_Line ("J*   turn off warnings for obsolescent " &


[gcc r15-472] ada: Decouple attachment from dynamic allocation for controlled objects

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:151d1533f2b5d1742ab08f99fcc67affae9587f5

commit r15-472-g151d1533f2b5d1742ab08f99fcc67affae9587f5
Author: Eric Botcazou 
Date:   Thu Feb 15 16:02:51 2024 +0100

ada: Decouple attachment from dynamic allocation for controlled objects

This decouples the attachment to the appropriate finalization collection of
dynamically allocated objects that need finalization from their allocation.

The current implementation immediately attaches them after allocating them,
which means that they will be finalized even if their initialization does
not complete successfully.  The new implementation instead generates the
same sequence as the one generated for (statically) declared objects, that
is to say, allocation, initialization and attachment in this order.

gcc/ada/

* exp_ch3.adb (Build_Default_Initialization): Do not generate the
protection for finalization collections.
(Build_Heap_Or_Pool_Allocator): Set the No_Initialization flag on
the declaration of the temporary.
* exp_ch4.adb (Build_Aggregate_In_Place): Do not build an allocation
procedure here.
(Expand_Allocator_Expression): Build an allocation procedure, if it
is required, only just before rewriting the allocator.
(Expand_N_Allocator): Do not build an allocation procedure if the
No_Initialization flag is set on the allocator, except for those
generated for special return objects.  In other cases, build an
allocation procedure, if it is required, only before rewriting
the allocator.
* exp_ch7.ads (Make_Address_For_Finalize): New function declaration.
* exp_ch7.adb (Finalization Management): Update description for
dynamically allocated objects.
(Make_Address_For_Finalize): Remove declaration.
(Find_Last_Init): Change to function and move to...
(Process_Object_Declaration): Adjust to above change.
* exp_util.ads (Build_Allocate_Deallocate_Proc): Add Mark parameter
with Empty default and document it.
(Find_Last_Init): New function declaration.
* exp_util.adb (Build_Allocate_Deallocate_Proc): Add Mark parameter
with Empty default and pass it in recursive call.  Deal with type
conversions created for interface types.  Adjust call sequence to
Allocate_Any_Controlled by changing Collection to In/Out parameter
and removing Finalize_Address parameter.  For a controlled object,
generate a conditional call to Attach_Object_To_Collection for an
allocation and to Detach_Object_From_Collection for a deallocation.
(Find_Last_Init): ...here.  Compute the initialization type for an
allocator whose designating type is class wide specifically and also
handle concurrent types.
* rtsfind.ads (RE_Id): Add RE_Attach_Object_To_Collection and
RE_Detach_Object_From_Collection.
(RE_Unit_Table): Add entries for RE_Attach_Object_To_Collection and
RE_Detach_Object_From_Collection.
* libgnat/s-finpri.ads (Finalization_Started): Delete.
(Attach_Node_To_Collection): Likewise.
(Detach_Node_From_Collection): Move to...
(Attach_Object_To_Collection): New procedure declaration.
(Detach_Object_From_Collection): Likewise.
(Finalization_Collection): Remove Atomic for Finalization_Started.
Add pragma Inline for Initialize.
* libgnat/s-finpri.adb: Add clause for Ada.Unchecked_Conversion.
(To_Collection_Node_Ptr): New instance of Ada.Unchecked_Conversion.
(Detach_Node_From_Collection): ...here.
(Attach_Object_To_Collection): New procedure.
(Detach_Object_From_Collection): Likewise.
(Finalization_Started): Delete.
(Finalize): Replace allocation with attachment in comments.
* libgnat/s-stposu.ads (Allocate_Any_Controlled): Rename parameter
Context_Subpool into Named_Subpool, parameter Context_Collection
into Collection and change it to In/Out, and remove Fin_Address.
* libgnat/s-stposu.adb: Remove clause for Ada.Unchecked_Conversion
and Finalization_Primitives.
(To_Collection_Node_Ptr): Delete.
(Allocate_Any_Controlled): Rename parameter Context_Subpool into
Named_Subpool, parameter Context_Collection into Collection and
change it to In/Out, and remove Fin_Address.  Do not lock/unlock
and do not attach the object, instead only displace its address.
(Deallocate_Any_Controlled): Do not lock/unlock and do not detach
the object.
(Header_Size_With_Padding): Use qualified name for Header_Size.

D

[gcc r15-474] ada: Fix small inaccuracy in previous change

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

commit r15-474-ga252022d9a1f285e471d8b3b37fe645244919ab5
Author: Eric Botcazou 
Date:   Fri Feb 16 10:30:17 2024 +0100

ada: Fix small inaccuracy in previous change

The call to Build_Allocate_Deallocate_Proc must occur before the special
accessibility check for class-wide allocation is generated, because this
check comes with cleanup code.

gcc/ada/

* exp_ch4.adb (Expand_Allocator_Expression): Move the first call to
Build_Allocate_Deallocate_Proc up to before the accessibility check.

Diff:
---
 gcc/ada/exp_ch4.adb | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index b1f7593de2ac..762e75616a7f 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -960,12 +960,18 @@ package body Exp_Ch4 is
 end if;
  end if;
 
+ --  This needs to done before generating the accessibility check below
+ --  because the check comes with cleanup code that invokes Free on the
+ --  temporary and, therefore, expects the object to be attached to its
+ --  finalization collection if it is controlled.
+
+ Build_Allocate_Deallocate_Proc (Declaration_Node (Temp), Mark => N);
+
  --  Note: the accessibility check must be inserted after the call to
  --  [Deep_]Adjust to ensure proper completion of the assignment.
 
  Apply_Accessibility_Check_For_Allocator (N, Exp, Temp);
 
- Build_Allocate_Deallocate_Proc (Declaration_Node (Temp), Mark => N);
  Rewrite (N, New_Occurrence_Of (Temp, Loc));
  Analyze_And_Resolve (N, PtrT);


[gcc r15-452] ada: Fix double finalization for dependent expression of case expression

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:59c4d2e5a7169d5afa49facd0329bc2f9fe91b1a

commit r15-452-g59c4d2e5a7169d5afa49facd0329bc2f9fe91b1a
Author: Eric Botcazou 
Date:   Sat Feb 10 00:03:42 2024 +0100

ada: Fix double finalization for dependent expression of case expression

The recent fix to Default_Initialize_Object, which has ensured that the
No_Initialization flag set on an object declaration, for example for the
temporary created by Expand_N_Case_Expression, is honored in all cases,
has also uncovered a latent issue in the machinery responsible for the
finalization of transient objects.

More specifically, the answer returned by the Is_Finalizable_Transient
predicate for an object of an access type is different when it is left
uninitialized (true) than when it is initialized to null (false), which
is incorrect; it must return false in both cases, because the only case
where an object can be finalized by the machinery through an access value
is when this value is a reference (N_Reference node) to the object.

This was already more or less the current state of the evolution of the
predicate, but this now explicitly states it in the code.

The change also sets the No_Initialization flag for the temporary created
by Expand_N_If_Expression for the sake of consistency.

gcc/ada/

* exp_ch4.adb (Expand_N_If_Expression): Set No_Initialization on the
declaration of the temporary in the by-reference case.
* exp_util.adb (Initialized_By_Access): Delete.
(Is_Allocated): Likewise.
(Initialized_By_Reference): New predicate.
(Is_Finalizable_Transient): If the transient object is of an access
type, do not return true unless it is initialized by a reference.

Diff:
---
 gcc/ada/exp_ch4.adb  |  1 +
 gcc/ada/exp_util.adb | 66 +---
 2 files changed, 22 insertions(+), 45 deletions(-)

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index fcbc82f56104..d8895d648d4c 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -5549,6 +5549,7 @@ package body Exp_Ch4 is
   Make_Object_Declaration (Loc,
 Defining_Identifier => Cnn,
 Object_Definition   => New_Occurrence_Of (Ptr_Typ, Loc));
+Set_No_Initialization (Decl);
 
 --  Generate:
 --if Cond then
diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index e411f32a5191..103d59e4deba 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -8234,11 +8234,6 @@ package body Exp_Util is
   Obj_Id  : constant Entity_Id := Defining_Identifier (Decl);
   Obj_Typ : constant Entity_Id := Base_Type (Etype (Obj_Id));
 
-  function Initialized_By_Access (Trans_Id : Entity_Id) return Boolean;
-  --  Determine whether transient object Trans_Id is initialized either
-  --  by a function call which returns an access type or simply renames
-  --  another pointer.
-
   function Initialized_By_Aliased_BIP_Func_Call
 (Trans_Id : Entity_Id) return Boolean;
   --  Determine whether transient object Trans_Id is initialized by a
@@ -8247,6 +8242,11 @@ package body Exp_Util is
   --  This case creates an aliasing between the returned value and the
   --  value denoted by BIPaccess.
 
+  function Initialized_By_Reference (Trans_Id : Entity_Id) return Boolean;
+  --  Determine whether transient object Trans_Id is initialized by a
+  --  reference to another object. This is the only case where we can
+  --  possibly finalize a transient object through an access value.
+
   function Is_Aliased
 (Trans_Id   : Entity_Id;
  First_Stmt : Node_Id) return Boolean;
@@ -8254,9 +8254,6 @@ package body Exp_Util is
   --  aliased through 'reference in the statement list starting from
   --  First_Stmt.
 
-  function Is_Allocated (Trans_Id : Entity_Id) return Boolean;
-  --  Determine whether transient object Trans_Id is allocated on the heap
-
   function Is_Indexed_Container
 (Trans_Id   : Entity_Id;
  First_Stmt : Node_Id) return Boolean;
@@ -8275,20 +8272,6 @@ package body Exp_Util is
   --  Return True if N is directly part of a build-in-place return
   --  statement.
 
-  ---
-  -- Initialized_By_Access --
-  ---
-
-  function Initialized_By_Access (Trans_Id : Entity_Id) return Boolean is
- Expr : constant Node_Id := Expression (Parent (Trans_Id));
-
-  begin
- return
-   Present (Expr)
- and then Nkind (Expr) /= N_Reference
- and then Is_Access_Type (Etype (Expr));
-  end Initialized_By_Access;
-
   --
   -- Initialized_By_Aliased_BIP_Func_Call --
   --
@@ -8386,6 +8369

[gcc r15-456] ada: Spurious unreferenced warning on selected component

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:416e572edb0cbc84081de5a1932be7a2138a529a

commit r15-456-g416e572edb0cbc84081de5a1932be7a2138a529a
Author: Justin Squirek 
Date:   Mon Feb 12 15:50:24 2024 +

ada: Spurious unreferenced warning on selected component

This patch fixes an error in the compiler whereby a selected component on 
the
left hand side of an assignment statement may not get marked as referenced -
leading to spurious unreferenced warnings on such objects.

gcc/ada/

* sem_util.adb (Set_Referenced_Modified): Use Original_Node to
avoid recursive calls on expanded / internal objects such that
source nodes get appropriately marked as referenced.

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

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index b5c33638b35f..4e1258e7cecd 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -27625,7 +27625,11 @@ package body Sem_Util is
   --  Deal with indexed or selected component where prefix is modified
 
   if Nkind (N) in N_Indexed_Component | N_Selected_Component then
- Pref := Prefix (N);
+
+ --  Grab the original node to avoid looking at internally generated
+ --  objects.
+
+ Pref := Original_Node (Prefix (N));
 
  --  If prefix is access type, then it is the designated object that is
  --  being modified, which means we have no entity to set the flag on.


[gcc r15-458] ada: Reduce generated code duplication for streaming and Put_Image subprograms

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

commit r15-458-g0b7673ae72286ba1a8939320580f6e9002980e73
Author: Steve Baird 
Date:   Thu Dec 21 13:58:51 2023 -0800

ada: Reduce generated code duplication for streaming and Put_Image 
subprograms

In the case of an untagged composite type, the compiler does not generate
streaming-related subprograms or a Put_Image procedure when the type is
declared. Instead, these subprograms are declared "on demand" when a
corresponding attribute reference is encountered. In this case, hoist the
declaration of the implicitly declared subprogram out as far as possible
in order to maximize the chances that it can be reused (as opposed to
generating an identical second subprogram) in the case where a second
reference to the same attribute is encountered. Also relax some
privacy-related rules to allow these procedures to do what they need to do
even when constructed in a scope where some of those actions would
normally be illegal.

gcc/ada/

* exp_attr.adb: Change name of package Cached_Streaming_Ops to
reflect the fact that it is now also used for Put_Image
procedures. Similarly change other "Streaming_Op" names therein.
Add Validate_Cached_Candidate procedure to detect case where a
subprogram found in the cache cannot be reused. Add new generic
procedure Build_And_Insert_Type_Attr_Subp; the "Build" part is
handled by just calling a formal procedure; the bulk of this
(generic) procedure's code has to with deciding where in the tree
to insert the newly-constructed subprogram. Replace each later
"Build" call (and the following Insert_Action or
Compile_Stream_Body_In_Scope call) with a declare block that
instantiates and then calls this generic procedure. Delete the
now-unused procedure Compile_Stream_Body_In_Scope. A constructed
subprogram is entered in the appropriate cache if the
corresponding type is untagged; this replaces more complex tests.
A new function Interunit_Ref_OK is added to determine whether an
attribute reference occuring in one unit can safely refer to a
cached subprogram declared in another unit.
* exp_ch3.adb (Build_Predefined_Primitive_Bodies): A formal
parameter was deleted, so delete the corresponding actual in a
call.
* exp_put_image.adb (Build_Array_Put_Image_Procedure): Because the
procedure being built may be referenced more than once, the
generated procedure takes its source position info from the type
declaration instead of the (first) attribute reference.
(Build_Record_Put_Image_Procedure): Likewise.
* exp_put_image.ads (Build_Array_Put_Image_Procedure): Eliminate
now-unused Nod parameter.
(Build_Record_Put_Image_Procedure): Eliminate now-unused Loc 
parameter.
* sem_ch3.adb (Constrain_Discriminated_Type): For declaring a
subtype with a discriminant constraint, ignore privacy if
Comes_From_Source is false (as is already done if Is_Instance is
true).
* sem_res.adb (Resolve): When passed two type entities that have
the same underlying base type, Sem_Type.Covers may return False in
some cases because of privacy. [This can happen even if
Is_Private_Type returns False both for Etype (N) and for Typ;
Covers calls Base_Type, which can take a non-private argument and
yield a private result.] If Comes_From_Source (N) is False
(e.g., for a compiler-generated Put_Image or streaming subprogram), 
then
avoid that scenario by not calling Covers. Covers already has tests 
for
doing this sort of thing (see the calls therein to 
Full_View_Covers),
but the Comes_From_Source test is too coarse to apply there. So 
instead
we handle the problem here at the call site.
(Original_Implementation_Base_Type): A new function. Same as
Implementation_Base_Type except if the Original_Node attribute of
a non-derived type declaration indicates that it once was a derived
type declaration. Needed for looking through privacy.
(Valid Conversion): Ignore privacy when converting between 
different views
of the same type if Comes_From_Source is False for the conversion.
(Valid_Tagged_Conversion): An ancestor-to-descendant conversion is 
not an
illegal downward conversion if there is no type extension involved
(because the derivation was from an untagged view of the parent 
type).

Diff:
---
 gcc/ada/exp_attr.adb  | 627 +-
 gcc/ada/exp_ch

[gcc r15-453] ada: Missing support for consistent assertion policy

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

commit r15-453-g3f079f2244f088e5563d77da1430f804c38863b5
Author: Javier Miranda 
Date:   Sun Feb 11 16:22:28 2024 +

ada: Missing support for consistent assertion policy

Add missing support for RM 10.2/5: the region for a pragma
Assertion_Policy given as a configuration pragma is the
declarative region for the entire compilation unit (or units)
to which it applies.

gcc/ada/

* sem_ch10.adb (Install_Inherited_Policy_Pragmas): New subprogram.
(Remove_Inherited_Policy_Pragmas): New subprogram.
(Analyze_Compilation_Unit): Call the new subprograms to
install and remove inherited assertion policy pragmas.

Diff:
---
 gcc/ada/sem_ch10.adb | 212 ++-
 1 file changed, 208 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/sem_ch10.adb b/gcc/ada/sem_ch10.adb
index 7fc623b6278c..73e5388affdc 100644
--- a/gcc/ada/sem_ch10.adb
+++ b/gcc/ada/sem_ch10.adb
@@ -292,6 +292,18 @@ package body Sem_Ch10 is
   --  Spec_Context_Items to that of the spec. Parent packages are not
   --  examined for documentation purposes.
 
+  function Install_Inherited_Policy_Pragmas
+(Comp_Unit : Node_Id) return Node_Id;
+  --  Install assertion_policy pragmas placed at the start of the spec of
+  --  the given compilation unit (and the spec of its parent units). Return
+  --  the last pragma found in the check policy list before installing
+  --  these pragmas; used to remove the installed pragmas.
+
+  procedure Remove_Inherited_Policy_Pragmas (Last_Pragma : Node_Id);
+  --  Remove assertion_policy pragmas installed after the given pragma. If
+  --  Last_Pragma is empty then remove all the pragmas installed in the
+  --  check policy list (if any).
+
   ---
   -- Check_Redundant_Withs --
   ---
@@ -631,6 +643,186 @@ package body Sem_Ch10 is
  end loop;
   end Check_Redundant_Withs;
 
+  --
+  -- Install_Inherited_Policy_Pragmas --
+  --
+
+  --  Opt.Check_Policy_List is handled as a stack; assertion policy
+  --  pragmas defined at inner scopes are placed at the beginning of
+  --  the list. Therefore, policy pragmas defined at the start of
+  --  parent units must be appended to the end of this list.
+
+  --  When the compilation unit is a package body (or a subprogram body
+  --  that does not act as its spec) we recursively traverse to its spec
+  --  (and from there to its ultimate parent); when the compilation unit
+  --  is a child package (or subprogram) spec we recursively climb until
+  --  its ultimate parent. In both cases policy pragmas defined at the
+  --  beginning of all these traversed units are appended to the check
+  --  policy list in the way back to the current compilation unit (and
+  --  they are left installed in reverse order). For example:
+  --
+  -- pragma Assertion_Policy (...) -- [policy-1]
+  -- package Pkg is ...
+  --
+  -- pragma Assertion_Policy (...) -- [policy-2]
+  -- package Pkg.Child is ...
+  --
+  -- pragma Assertion_Policy (...) -- [policy-3]
+  -- package body Pkg.Child is ...
+  --
+  --  When the compilation unit Pkg.Child is analyzed, and its context
+  --  clauses are analyzed, these are the contents of Check_Policy_List:
+  --
+  -- Opt.Check_Policy_List -> [policy-3]
+  --  ^
+  --   last_policy_pragma
+  --
+  --  After climbing to the ultimate parent spec, these are the contents
+  --  of Check_Policy_List:
+  --
+  -- Opt.Check_Policy_List -> [policy-3] -> [policy-2] -> [policy-1]
+  --  ^
+  --   last_policy_pragma
+  --
+  --  The reference to the last policy pragma in the initial contents of
+  --  the list is used later to remove installed inherited pragmas.
+
+  function Install_Inherited_Policy_Pragmas
+(Comp_Unit : Node_Id) return Node_Id
+  is
+ Last_Policy_Pragma : Node_Id;
+
+ procedure Install_Parent_Policy_Pragmas (N : Node_Id);
+ --  Recursively climb to the ultimate parent and install their policy
+ --  pragmas after Last_Policy_Pragma.
+
+ ---
+ -- Install_Parent_Policy_Pragmas --
+ ---
+
+ procedure Install_Parent_Policy_Pragmas (N : Node_Id) is
+Lib_Unit : constant Node_Id := Unit (N);
+Item : Node_Id;
+
+ begin
+if Is_Child_Spec (Lib_Unit) then
+   Install_Parent_Policy_P

[gcc r15-461] ada: Compiler crash or errors on if_expression in container aggregate

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

commit r15-461-ga9714dce8245f87c937a8fdef52db15ca6571525
Author: Gary Dismukes 
Date:   Mon Feb 12 20:18:36 2024 +

ada: Compiler crash or errors on if_expression in container aggregate

The compiler may either crash or incorrectly report errors when
a component association in a container aggregate is an if_expression
with an elsif part whose dependent expression is a call to a function
returning a result that requires finalization. The compiler complains
that a private type is expected, but a package or procedure name was
found. This is due to the compiler improperly associating expanded
calls to Finalize_Object with the aggregate, rather than the enclosing
object declaration being initialized by the aggregate, which can result
in the Finalize_Object procedure call being passed as an actual to
the Add_Unnamed operation of the container type and leading to a type
mismatch and the confusing error message. This is fixed by adjusting
the code that locates the proper context for insertion of Finalize_Object
calls to locate the enclosing declaration or statement rather than
stopping at the aggregate.

gcc/ada/

* exp_util.adb (Find_Hook_Context): Exclude N_*Aggregate Nkinds
of Parent (Par) from the early return in the second loop of the
In_Cond_Expr case, to prevent returning an aggregate from this
function rather than the enclosing declaration or statement.

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

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 4b1c5322f621..d9623e2ea40a 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -6412,7 +6412,9 @@ package body Exp_Util is
   and then Nkind (Parent (Par)) not in N_Function_Call
  | N_Procedure_Call_Statement
  | N_Entry_Call_Statement
-
+ | N_Aggregate
+ | N_Delta_Aggregate
+ | N_Extension_Aggregate
 then
return Par;


[gcc r15-462] ada: Fix typo in diagnostic message

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

commit r15-462-gab4a519a84611acc928ebbec920bd31e24993436
Author: Ronan Desplanques 
Date:   Tue Feb 13 09:50:55 2024 +0100

ada: Fix typo in diagnostic message

A previous change introduced an error in the diagnostic message about
overlapping actuals. This commit fixes this.

gcc/ada/

* sem_warn.adb (Warn_On_Overlapping_Actuals): Fix typo.

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

diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index ccf9067c6720..2de3f8668b05 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -3865,7 +3865,7 @@ package body Sem_Warn is
 --  This is one of the messages
 
 Error_Msg_FE ("<.i

[gcc r15-465] ada: Fix crash with -gnatdJ and JSON output

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:996fd76402004d5f2fedbbf86cd8534e8c0c1f71

commit r15-465-g996fd76402004d5f2fedbbf86cd8534e8c0c1f71
Author: Ronan Desplanques 
Date:   Tue Feb 13 12:46:36 2024 +0100

ada: Fix crash with -gnatdJ and JSON output

This patch tweaks the calls made to Errout subprograms to report
violations of dependence restrictions, in order fix a crash that
occurred with -gnatdJ and -fdiagnostics-format=json.

gcc/ada/

* restrict.adb (Violation_Of_No_Dependence): Tweak error
reporting calls.

Diff:
---
 gcc/ada/restrict.adb | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/restrict.adb b/gcc/ada/restrict.adb
index 1cc75bec3263..bda35d8f441a 100644
--- a/gcc/ada/restrict.adb
+++ b/gcc/ada/restrict.adb
@@ -1704,16 +1704,16 @@ package body Restrict is

 
procedure Violation_Of_No_Dependence (Unit : Int; N : Node_Id) is
+  Unit_Node : constant Node_Id := No_Dependences.Table (Unit).Unit;
begin
-  Error_Msg_Node_1 := No_Dependences.Table (Unit).Unit;
-  Error_Msg_Sloc   := Sloc (Error_Msg_Node_1);
+  Error_Msg_Sloc := Sloc (Unit_Node);
 
   if No_Dependences.Table (Unit).Warn then
- Error_Msg
-   ("?*?violation of restriction `No_Dependence '='> &`#", Sloc (N));
+ Error_Msg_NE ("?*?violation of restriction `No_Dependence '='> &`#",
+   N, Unit_Node);
   else
- Error_Msg
-   ("|violation of restriction `No_Dependence '='> &`#", Sloc (N));
+ Error_Msg_NE ("|violation of restriction `No_Dependence '='> &`#", N,
+   Unit_Node);
   end if;
end Violation_Of_No_Dependence;


[gcc r15-455] ada: Fix overlap warning suppression

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

commit r15-455-gf545412378592e3c4b420b61867bfd3dda2f6480
Author: Ronan Desplanques 
Date:   Mon Feb 12 16:49:38 2024 +0100

ada: Fix overlap warning suppression

Before this patch, some warnings about overlapping actuals were
emitted regardless of the Value of
Warnsw.Warnings_Package.Warn_On_Overlap. This patch fixes this.

gcc/ada/

* sem_warn.adb (Warn_On_Overlapping_Actuals): Stop ignoring
warning suppression settings.

Diff:
---
 gcc/ada/sem_warn.adb | 33 +
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 57bdee653566..ccf9067c6720 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -3831,16 +3831,6 @@ package body Sem_Warn is
   then
  null;
 
-  --  We only report warnings on overlapping arrays and record
-  --  types if switch is set.
-
-  elsif not Warn_On_Overlap
-and then not (Is_Elementary_Type (Etype (Form1))
-and then
-  Is_Elementary_Type (Etype (Form2)))
-  then
- null;
-
   --  Here we may need to issue overlap message
 
   else
@@ -3858,22 +3848,25 @@ package body Sem_Warn is
 
or else not
 (Is_Elementary_Type (Etype (Form1))
- and then Is_Elementary_Type (Etype (Form2)))
+ and then Is_Elementary_Type (Etype (Form2)));
 
-   --  debug flag -gnatd.E changes the error to a warning
-   --  even in Ada 2012 mode.
+ if not Error_Msg_Warn or else Warn_On_Overlap then
+--  debug flag -gnatd.E changes the error to a warning
+--  even in Ada 2012 mode.
 
-   or else Error_To_Warning;
+if Error_To_Warning then
+   Error_Msg_Warn := True;
+end if;
 
- --  For greater clarity, give name of formal
+--  For greater clarity, give name of formal
 
- Error_Msg_Node_2 := Form2;
+Error_Msg_Node_2 := Form2;
 
- --  This is one of the messages
+--  This is one of the messages
 
- Error_Msg_FE
-   ("<.i

[gcc r15-457] ada: Better error message for bad general case statements

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:33541b880694fedb901cf8f38b2be77e4c429068

commit r15-457-g33541b880694fedb901cf8f38b2be77e4c429068
Author: Steve Baird 
Date:   Fri Feb 9 15:08:51 2024 -0800

ada: Better error message for bad general case statements

If -gnatX0 is specified, we allow case statements with a selector
expression of a record or array type, but not of a private type.
If the selector expression is of a private type then we should generate
an appropriate error message instead of a bugbox.

gcc/ada/

* sem_ch5.adb (Analyze_Case_Statement): Emit a message and return
early in the case where general case statements are allowed but
the selector expression is of a private type. This is done to
avoid a bugbox.

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

diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index 2677a2c5a1cc..65370ebfe7ea 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -1497,6 +1497,15 @@ package body Sem_Ch5 is
  Resolve (Exp, Etype (Exp));
  Exp_Type := Etype (Exp);
  Is_General_Case_Statement := True;
+ if not (Is_Record_Type (Exp_Type) or Is_Array_Type (Exp_Type)) then
+Error_Msg_N
+  ("selecting expression of general case statement " &
+   "must be a record or an array",
+   Exp);
+
+--  Avoid cascading errors
+return;
+ end if;
   else
  Analyze_And_Resolve (Exp, Any_Discrete);
  Exp_Type := Etype (Exp);


[gcc r15-471] ada: Follow up fixes for Put_Image/streaming regressions

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:00c7f2296fbad17a54629f571da42104f1054478

commit r15-471-g00c7f2296fbad17a54629f571da42104f1054478
Author: Steve Baird 
Date:   Wed Feb 14 16:27:59 2024 -0800

ada: Follow up fixes for Put_Image/streaming regressions

A recent change to reduce duplication of compiler-generated Put_Image and
streaming subprograms introduced two regressions. One is yet another of the
many cases where generating these routines "on demand" (as opposed at the
point of the associated type declaration) requires loosening the compiler's
enforcement of privacy. The other is a use-before-definition issue that
occurs because the declaration of a Put_Image procedure is not hoisted far
enough.

gcc/ada/

* exp_attr.adb (Build_And_Insert_Type_Attr_Subp): If a subprogram
associated with a (library-level) type declared in another unit is
to be inserted somewhere in a list, then insert it at the head of
the list.
* sem_ch5.adb (Analyze_Assignment): Normally a limited-type
assignment is illegal. Relax this rule if Comes_From_Source is
False and the type is not immutably limited.

Diff:
---
 gcc/ada/exp_attr.adb | 3 ++-
 gcc/ada/sem_ch5.adb  | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index 6dba600620ec..e12e8b4a439a 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -1953,7 +1953,8 @@ package body Exp_Attr is
 
 while Present (Ancestor) loop
if Is_List_Member (Ancestor) then
-  Insertion_Point := Ancestor;
+  Insertion_Point := First (List_Containing (Ancestor));
+  pragma Assert (Present (Insertion_Point));
end if;
Ancestor := Parent (Ancestor);
 end loop;
diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index 65370ebfe7ea..1e09e57919e1 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -597,10 +597,13 @@ package body Sem_Ch5 is
 
   --  Error of assigning to limited type. We do however allow this in
   --  certain cases where the front end generates the assignments.
+  --  Comes_From_Source test is needed to allow compiler-generated
+  --  streaming/put_image subprograms, which may ignore privacy.
 
   elsif Is_Limited_Type (T1)
 and then not Assignment_OK (Lhs)
 and then not Assignment_OK (Original_Node (Lhs))
+and then (Comes_From_Source (N) or Is_Immutably_Limited_Type (T1))
   then
  --  CPP constructors can only be called in declarations


[gcc r15-477] ada: Fix crash with -gnatdJ and -gnatf

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:4a45c99302b688cacf788946b9a88ea8593bb395

commit r15-477-g4a45c99302b688cacf788946b9a88ea8593bb395
Author: Ronan Desplanques 
Date:   Mon Feb 19 17:19:27 2024 +0100

ada: Fix crash with -gnatdJ and -gnatf

This patch fixes a crash when the compiler emits a warning about
an unchecked conversion and -gnatdJ is enabled.

gcc/ada/

* sem_ch13.adb (Validate_Unchecked_Conversions): Add node
parameters to Error_Msg calls.

Diff:
---
 gcc/ada/sem_ch13.adb | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 0470ce10ac7a..1ad5c4c0128f 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -18401,7 +18401,8 @@ package body Sem_Ch13 is
  Error_Msg_Uint_1 := Source_Siz;
  Error_Msg_Name_2 := Chars (Target);
  Error_Msg_Uint_2 := Target_Siz;
- Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
+ Error_Msg
+   ("\size of % is ^, size of % is ^?z?", Eloc, Act_Unit);
 
  Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
 
@@ -18412,17 +18413,17 @@ package body Sem_Ch13 is
 if Source_Siz > Target_Siz then
Error_Msg
  ("\?z?^ high order bits of source will "
-  & "be ignored!", Eloc);
+  & "be ignored!", Eloc, Act_Unit);
 
 elsif Is_Unsigned_Type (Source) then
Error_Msg
  ("\?z?source will be extended with ^ high order "
-  & "zero bits!", Eloc);
+  & "zero bits!", Eloc, Act_Unit);
 
 else
Error_Msg
  ("\?z?source will be extended with ^ high order "
-  & "sign bits!", Eloc);
+  & "sign bits!", Eloc, Act_Unit);
 end if;
 
  elsif Source_Siz < Target_Siz then


[gcc r15-478] ada: Fix classification of SPARK Boolean aspects

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

commit r15-478-g8d15d848b90f502bdc3070f5b4e6213721eb2272
Author: Piotr Trojanek 
Date:   Mon Feb 19 09:46:04 2024 +0100

ada: Fix classification of SPARK Boolean aspects

The implementation of User_Aspect_Definition uses subtype
Boolean_Aspects to decide which existing aspects can be used to define
old aspects. This subtype didn't include many of the SPARK aspects,
notably the Always_Terminates.

gcc/ada/

* aspects.ads (Aspect_Id, Boolean_Aspect): Change categorization
of Boolean-valued SPARK aspects.
* sem_ch13.adb (Analyze_Aspect_Specification): Adapt CASE
statements to new classification of Boolean-valued SPARK
aspects.

Diff:
---
 gcc/ada/aspects.ads  |  39 --
 gcc/ada/sem_ch13.adb | 203 +++
 2 files changed, 41 insertions(+), 201 deletions(-)

diff --git a/gcc/ada/aspects.ads b/gcc/ada/aspects.ads
index a348b322d29a..eb5ab1a85dd4 100644
--- a/gcc/ada/aspects.ads
+++ b/gcc/ada/aspects.ads
@@ -72,14 +72,10 @@ package Aspects is
   Aspect_Address,
   Aspect_Aggregate,
   Aspect_Alignment,
-  Aspect_Always_Terminates, -- GNAT
   Aspect_Annotate,  -- GNAT
-  Aspect_Async_Readers, -- GNAT
-  Aspect_Async_Writers, -- GNAT
   Aspect_Attach_Handler,
   Aspect_Bit_Order,
   Aspect_Component_Size,
-  Aspect_Constant_After_Elaboration,-- GNAT
   Aspect_Constant_Indexing,
   Aspect_Contract_Cases,-- GNAT
   Aspect_Convention,
@@ -95,13 +91,9 @@ package Aspects is
   Aspect_Dimension_System,  -- GNAT
   Aspect_Dispatching_Domain,
   Aspect_Dynamic_Predicate,
-  Aspect_Effective_Reads,   -- GNAT
-  Aspect_Effective_Writes,  -- GNAT
   Aspect_Exceptional_Cases, -- GNAT
-  Aspect_Extensions_Visible,-- GNAT
   Aspect_External_Name,
   Aspect_External_Tag,
-  Aspect_Ghost, -- GNAT
   Aspect_Ghost_Predicate,   -- GNAT
   Aspect_Global,-- GNAT
   Aspect_GNAT_Annotate, -- GNAT
@@ -121,7 +113,6 @@ package Aspects is
   Aspect_Max_Entry_Queue_Depth, -- GNAT
   Aspect_Max_Entry_Queue_Length,
   Aspect_Max_Queue_Length,  -- GNAT
-  Aspect_No_Caching,-- GNAT
   Aspect_No_Controlled_Parts,
   Aspect_No_Task_Parts, -- GNAT
   Aspect_Object_Size,   -- GNAT
@@ -146,7 +137,6 @@ package Aspects is
   Aspect_Relaxed_Initialization,-- GNAT
   Aspect_Scalar_Storage_Order,  -- GNAT
   Aspect_Secondary_Stack_Size,  -- GNAT
-  Aspect_Side_Effects,  -- GNAT
   Aspect_Simple_Storage_Pool,   -- GNAT
   Aspect_Size,
   Aspect_Small,
@@ -168,7 +158,6 @@ package Aspects is
   Aspect_User_Aspect,   -- GNAT
   Aspect_Value_Size,-- GNAT
   Aspect_Variable_Indexing,
-  Aspect_Volatile_Function, -- GNAT
   Aspect_Warnings,  -- GNAT
   Aspect_Write,
 
@@ -190,17 +179,25 @@ package Aspects is
   --  the aspect value is inherited from the parent, in which case, we do
   --  not allow False if we inherit a True value from the parent.
 
+  Aspect_Always_Terminates, -- GNAT
   Aspect_Asynchronous,
+  Aspect_Async_Readers, -- GNAT
+  Aspect_Async_Writers, -- GNAT
   Aspect_Atomic,
   Aspect_Atomic_Components,
+  Aspect_Constant_After_Elaboration,-- GNAT
   Aspect_Disable_Controlled,-- GNAT
   Aspect_Discard_Names,
   Aspect_CUDA_Device,   -- GNAT
   Aspect_CUDA_Global,   -- GNAT
+  Aspect_Effective_Reads,   -- GNAT
+  Aspect_Effective_Writes,  -- GNAT
   Aspect_Exclusive_Functions,
   Aspect_Export,
+  Aspect_Extensions_Visible,-- GNAT
   Aspect_Favor_Top_Level,   -- GNAT
   Aspect_Full_Access_Only,
+  Aspect_Ghost, -- GNAT
   Aspect_Independent,
   Aspect_Independent_Components,
   Aspect_Import,
@@ -208,6 +205,7 @@ package Aspects is
   Aspect_Inline_Always, -- GNAT
   Aspect_Interrupt_Handler,
   Aspect_Lock_Free, -- GNAT
+  Aspect_No_Caching,-- GNAT
   Aspect_No_Inline, -- GNAT
   Aspect_No_Return,
   Aspect_No_Tagged_Streams, -- GNAT
@@ -217,6 +215,7 @@ package Aspects is
   Aspect_Pure_Function, -- GNAT
   Aspect_Remote_Access_Type,-- GNAT
   Asp

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

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:4f3567cf3b71ccf5447659a028d08429c2d30df7

commit r15-454-g4f3567cf3b71ccf5447659a028d08429c2d30df7
Author: Eric Botcazou 
Date:   Sun Feb 11 19:05:08 2024 +0100

ada: Follow-up adjustment to earlier fix in Build_Allocate_Deallocate_Proc

The profile of the procedure built for an allocation on the secondary stack
now includes the alignment parameter, so the parameter can just be forwarded
in the call to Allocate_Any_Controlled.

gcc/ada/

* exp_util.adb (Build_Allocate_Deallocate_Proc): Pass the alignment
parameter in the inner call for a secondary stack allocation too.

Diff:
---
 gcc/ada/exp_util.adb | 43 ++-
 1 file changed, 18 insertions(+), 25 deletions(-)

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 103d59e4deba..4b1c5322f621 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -1081,10 +1081,8 @@ package body Exp_Util is
  --  allocations can be performed without getting the alignment from
  --  the type's Type Specific Record.
 
- if ((Is_Allocate and then No (Alloc_Expr))
-   or else
- not Is_Class_Wide_Type (Desig_Typ))
-   and then not Use_Secondary_Stack_Pool
+ if (Is_Allocate and then No (Alloc_Expr))
+   or else not Is_Class_Wide_Type (Desig_Typ)
  then
 Append_To (Actuals, New_Occurrence_Of (Alig_Id, Loc));
 
@@ -1103,9 +1101,6 @@ package body Exp_Util is
 --  into the code that reads the value of alignment from the TSD
 --  (see Expand_N_Attribute_Reference)
 
---  In the Use_Secondary_Stack_Pool case, Alig_Id is not
---  passed in and therefore must not be referenced.
-
 Append_To (Actuals,
   Unchecked_Convert_To (RTE (RE_Storage_Offset),
 Make_Attribute_Reference (Loc,
@@ -1255,53 +1250,51 @@ package body Exp_Util is
 Proc_To_Call := RTE (RE_Deallocate_Any_Controlled);
  end if;
 
- --  Create a custom Allocate / Deallocate routine which has identical
- --  profile to that of System.Storage_Pools.
+ --  Create a custom Allocate/Deallocate routine which has identical
+ --  profile to that of System.Storage_Pools, except for a secondary
+ --  stack allocation where the profile must be identical to that of
+ --  the System.Secondary_Stack.SS_Allocate procedure (deallocation
+ --  is not supported for the secondary stack).
 
  declare
---  P : Root_Storage_Pool
 function Pool_Param return Node_Id is (
   Make_Parameter_Specification (Loc,
 Defining_Identifier => Make_Temporary (Loc, 'P'),
 Parameter_Type  =>
   New_Occurrence_Of (RTE (RE_Root_Storage_Pool), Loc)));
+--  P : Root_Storage_Pool
 
---  A : [out] Address
 function Address_Param return Node_Id is (
   Make_Parameter_Specification (Loc,
 Defining_Identifier => Addr_Id,
 Out_Present => Is_Allocate,
 Parameter_Type  =>
   New_Occurrence_Of (RTE (RE_Address), Loc)));
+--  A : [out] Address
 
---  S : Storage_Count
 function Size_Param return Node_Id is (
   Make_Parameter_Specification (Loc,
 Defining_Identifier => Size_Id,
 Parameter_Type  =>
   New_Occurrence_Of (RTE (RE_Storage_Count), Loc)));
+--  S : Storage_Count
 
---  L : Storage_Count
 function Alignment_Param return Node_Id is (
   Make_Parameter_Specification (Loc,
 Defining_Identifier => Alig_Id,
 Parameter_Type  =>
   New_Occurrence_Of (RTE (RE_Storage_Count), Loc)));
+--  L : Storage_Count
 
-Formal_Params : List_Id;
+Formal_Params : constant List_Id :=
+  (if Use_Secondary_Stack_Pool
+then New_List (Address_Param, Size_Param, Alignment_Param)
+else
+  New_List
+(Pool_Param, Address_Param, Size_Param, Alignment_Param));
+--  The list of formal parameters of the routine
 
  begin
-if Use_Secondary_Stack_Pool then
-   --  Gigi expects a different profile in the Secondary_Stack_Pool
-   --  case. There must be no uses of the two missing formals
-   --  (i.e., Pool_Param and Alignment_Param) in this case.
-   Formal_Params := New_List
- (Address_Param, Size_Param, Alignment_Param);
-else
-   Formal_Params := New_List (
- Pool_Param, Address_Param, Size_Param, Alignment_Param);
-end if;
-
 Insert_A

[gcc r15-459] ada: Follow-up adjustment after fix to Default_Initialize_Object

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

commit r15-459-gba0b16a527b6d658dddca2e2609ab6b6c1fe32d4
Author: Eric Botcazou 
Date:   Mon Feb 12 19:25:39 2024 +0100

ada: Follow-up adjustment after fix to Default_Initialize_Object

Now that Default_Initialize_Object honors the No_Initialization flag in all
cases, objects of an access type declared without initialization expression
can no longer be considered as being automatically initialized to null.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration): Examine the Expression
field after the call to Default_Initialize_Object in order to set
Is_Known_Null, as well as Is_Known_Non_Null, on an access object.

Diff:
---
 gcc/ada/exp_ch3.adb | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index e34cb8fb58f6..9109d5926905 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -7604,6 +7604,16 @@ package body Exp_Ch3 is
 
  if not Special_Ret_Obj then
 Default_Initialize_Object (Init_After);
+
+--  Check whether an access object has been initialized above
+
+if Is_Access_Type (Typ) and then Present (Expression (N)) then
+   if Known_Non_Null (Expression (N)) then
+  Set_Is_Known_Non_Null (Def_Id);
+   elsif Known_Null (Expression (N)) then
+  Set_Is_Known_Null (Def_Id);
+   end if;
+end if;
  end if;
 
  --  Generate attribute for Persistent_BSS if needed
@@ -7625,12 +7635,6 @@ package body Exp_Ch3 is
 end;
  end if;
 
- --  If access type, then we know it is null if not initialized
-
- if Is_Access_Type (Typ) then
-Set_Is_Known_Null (Def_Id);
- end if;
-
   --  Explicit initialization present
 
   else


[gcc r15-468] ada: Small cleanup about allocators and aggregates

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:08039257610508b153d13b6cab1f252297d143a9

commit r15-468-g08039257610508b153d13b6cab1f252297d143a9
Author: Eric Botcazou 
Date:   Wed Feb 14 01:22:49 2024 +0100

ada: Small cleanup about allocators and aggregates

This eliminates a few oddities present in the expander for allocators and
aggregates present in allocators:

  - Convert_Array_Aggr_In_Allocator takes both a Decl and Alloc parameters,
and inserts new code before Alloc for records and after Decl for arrays
through Convert_Array_Aggr_In_Allocator.  Now, for the 3 (duplicated)
calls to the procedure, that's the same place.  It also creates a new
list that it does not use in most cases.

  - Expand_Allocator_Expression uses the same code sequence in 3 places
when the expression is an aggregate to build in place.

  - Build_Allocate_Deallocate_Proc takes an Is_Allocate parameter that is
entirely determined by the N parameter: if N is an allocator, it must
be true; if N is a free statement, it must be false.  Barring that,
the procedure either raises an assertion or Program_Error.  It also
contains useless pattern matching code in the second part.

No functional changes.

gcc/ada/

* exp_aggr.ads (Convert_Aggr_In_Allocator): Rename Alloc into N,
replace Decl with Temp and adjust description.
(Convert_Aggr_In_Object_Decl): Alphabetize.
(Is_Delayed_Aggregate): Likewise.
* exp_aggr.adb (Convert_Aggr_In_Allocator): Rename Alloc into N
and replace Decl with Temp.  Allocate a list only when neeeded.
(Convert_Array_Aggr_In_Allocator): Replace N with Decl and insert
new code before it.
* exp_ch4.adb (Build_Aggregate_In_Place): New procedure nested in
Expand_Allocator_Expression.
(Expand_Allocator_Expression): Call it to build aggregates in place.
Remove second parameter in calls to Build_Allocate_Deallocate_Proc.
(Expand_N_Allocator): Likewise.
* exp_ch13.adb (Expand_N_Free_Statement): Likewise.
* exp_util.ads (Build_Allocate_Deallocate_Proc): Remove Is_Allocate
parameter.
* exp_util.adb (Build_Allocate_Deallocate_Proc): Remove Is_Allocate
parameter and replace it with local variable of same name.  Delete
useless pattern matching.

Diff:
---
 gcc/ada/exp_aggr.adb |  34 +++---
 gcc/ada/exp_aggr.ads |  33 +++---
 gcc/ada/exp_ch13.adb |   2 +-
 gcc/ada/exp_ch4.adb  | 123 +--
 gcc/ada/exp_util.adb |  48 +++-
 gcc/ada/exp_util.ads |   7 +--
 6 files changed, 102 insertions(+), 145 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index a4e4d81f0a8f..27a7f3d2b495 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -283,7 +283,7 @@ package body Exp_Aggr is
--are writing into.
 
procedure Convert_Array_Aggr_In_Allocator
- (Decl   : Node_Id;
+ (N  : Node_Id;
   Aggr   : Node_Id;
   Target : Node_Id);
--  If the aggregate appears within an allocator and can be expanded in
@@ -3542,13 +3542,12 @@ package body Exp_Aggr is
---
 
procedure Convert_Aggr_In_Allocator
- (Alloc :  Node_Id;
-  Decl  :  Node_Id;
-  Aggr  :  Node_Id)
+ (N: Node_Id;
+  Aggr : Node_Id;
+  Temp : Entity_Id)
is
   Loc  : constant Source_Ptr := Sloc (Aggr);
   Typ  : constant Entity_Id  := Etype (Aggr);
-  Temp : constant Entity_Id  := Defining_Identifier (Decl);
 
   Occ  : constant Node_Id :=
 Unchecked_Convert_To (Typ,
@@ -3556,26 +3555,29 @@ package body Exp_Aggr is
 
begin
   if Is_Array_Type (Typ) then
- Convert_Array_Aggr_In_Allocator (Decl, Aggr, Occ);
+ Convert_Array_Aggr_In_Allocator (N, Aggr, Occ);
 
   elsif Has_Default_Init_Comps (Aggr) then
  declare
-L  : constant List_Id := New_List;
-Init_Stmts : List_Id;
+Init_Stmts : constant List_Id := Late_Expansion (Aggr, Typ, Occ);
 
  begin
-Init_Stmts := Late_Expansion (Aggr, Typ, Occ);
-
 if Has_Task (Typ) then
-   Build_Task_Allocate_Block (L, Aggr, Init_Stmts);
-   Insert_Actions (Alloc, L);
+   declare
+  Actions : constant List_Id := New_List;
+
+   begin
+  Build_Task_Allocate_Block (Actions, Aggr, Init_Stmts);
+  Insert_Actions (N, Actions);
+   end;
+
 else
-   Insert_Actions (Alloc, Init_Stmts);
+   Insert_Actions (N, Init_Stmts);
 end if;
  end;
 
   else
- Insert_Actions (Alloc, Late_Expansion (Aggr, Typ, Occ));
+ Insert_Actions (N

[gcc r15-475] ada: Document more details of the implementation of finalization chains

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:26afb0040cf728de82db2c1417c5a2973d06f0aa

commit r15-475-g26afb0040cf728de82db2c1417c5a2973d06f0aa
Author: Eric Botcazou 
Date:   Fri Feb 16 23:57:23 2024 +0100

ada: Document more details of the implementation of finalization chains

gcc/ada/

* exp_ch7.adb (Finalization Management): Add a short description of
the implementation of finalization chains.

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

diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
index e978a778f1e5..25a7c0b2b46d 100644
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -100,6 +100,35 @@ package body Exp_Ch7 is
--  have to be detached from the finalization chain, in case (2) they must
--  not and in case (1) this is optional as we are exiting the scope anyway.
 
+   --  There are two kinds of finalization chain to which objects are attached,
+   --  depending on the way they are created. For objects (statically) declared
+   --  in a scope, the finalization chain is that of the master of the scope,
+   --  which is embodied in a Finalization_Master object. As per RM 7.6.1(11/3)
+   --  the finalization of the master (on scope exit) performs the finalization
+   --  of objects attached to its chain in the reverse order of their creation.
+
+   --  For dynamically allocated objects, the finalization chain is that of the
+   --  finalization collection of the access type through which the objects are
+   --  allocated, which is embodied in a Finalization_Collection object. As per
+   --  RM 7.6.1(11.1/3), the finalization of the collection performs the
+   --  finalization of objects attached to its chain in an arbitrary order.
+
+   --  A Finalization_Collection object is implemented as a controlled object
+   --  and its finalization is therefore driven by the finalization master of
+   --  the scope where it is declared. As per RM 7.6.1(11.2/3), for a named
+   --  access type, the Finalization_Collection object is declared in the list
+   --  of actions of its freeze node.
+
+   --  ??? For an anonymous access type, the implementation deviates from the
+   --  RM 7.6.1 clause as follows: all the anonymous access types with the same
+   --  designated type that are (implicitly) declared in a library unit share a
+   --  single Finalization_Collection object declared in the outermost scope of
+   --  the library unit, except if the designated type is declared in a dynamic
+   --  scope nested in the unit; in this case no Finalization_Collection object
+   --  is created. As a result, in the first case, objects allocated through
+   --  the anonymous access types are finalized when the library unit goes out
+   --  of scope, while in the second case, they are not finalized at all.
+
--  Here is a simple example of the expansion of a controlled block:
 
--declare


[gcc r15-470] ada: Fix pragma Compile_Time_Error and -gnatdJ crash

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

commit r15-470-gf5798041ac97347e52d985be37f049c6d902d282
Author: Ronan Desplanques 
Date:   Wed Feb 14 16:02:48 2024 +0100

ada: Fix pragma Compile_Time_Error and -gnatdJ crash

This patch makes it so the diagnostics coming from occurrences of
pragma Compile_Time_Error and Compile_Time_Warning are emitted with
a node parameter so they don't cause a crash when -gnatdJ is enabled.

gcc/ada/

* errout.ads (Error_Msg): Add node parameter.
* errout.adb (Error_Msg): Add parameter and pass it to
the underlying call.
* sem_prag.adb (Validate_Compile_Time_Warning_Or_Error): Pass
pragma node when emitting errors.

Diff:
---
 gcc/ada/errout.adb   | 3 ++-
 gcc/ada/errout.ads   | 7 ---
 gcc/ada/sem_prag.adb | 8 
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
index 4622290897b9..f10539d09492 100644
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -325,12 +325,13 @@ package body Errout is
procedure Error_Msg
   (Msg : String;
Flag_Location : Source_Ptr;
+   N : Node_Id;
Is_Compile_Time_Pragma : Boolean)
is
   Save_Is_Compile_Time_Msg : constant Boolean := Is_Compile_Time_Msg;
begin
   Is_Compile_Time_Msg := Is_Compile_Time_Pragma;
-  Error_Msg (Msg, To_Span (Flag_Location), Current_Node);
+  Error_Msg (Msg, To_Span (Flag_Location), N);
   Is_Compile_Time_Msg := Save_Is_Compile_Time_Msg;
end Error_Msg;
 
diff --git a/gcc/ada/errout.ads b/gcc/ada/errout.ads
index 089da867d454..f0e3f5d0b7cb 100644
--- a/gcc/ada/errout.ads
+++ b/gcc/ada/errout.ads
@@ -738,10 +738,11 @@ package Errout is
procedure Error_Msg
  (Msg: String;
   Flag_Location  : Source_Ptr;
+  N  : Node_Id;
   Is_Compile_Time_Pragma : Boolean);
-   --  Same as Error_Msg (String, Source_Ptr) except Is_Compile_Time_Pragma
-   --  lets the caller specify whether this is a Compile_Time_Warning or
-   --  Compile_Time_Error pragma.
+   --  Same as Error_Msg (String, Source_Ptr, Node_Id) except
+   --  Is_Compile_Time_Pragma lets the caller specify whether this is a
+   --  Compile_Time_Warning or Compile_Time_Error pragma.
 
procedure Error_Msg_S (Msg : String);
--  Output a message at current scan pointer location. This routine can be
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index dfc415da3f34..9646e891c460 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -33145,11 +33145,11 @@ package body Sem_Prag is
   if Force then
  if Cont = False then
 Error_Msg
-   ("<<~!!", Eloc, Is_Compile_Time_Pragma => True);
+   ("<<~!!", Eloc, N, Is_Compile_Time_Pragma => True);
 Cont := True;
  else
 Error_Msg
-   ("\<<~!!", Eloc, Is_Compile_Time_Pragma => True);
+   ("\<<~!!", Eloc, N, Is_Compile_Time_Pragma => True);
  end if;
 
   --  Error, rather than warning, or in a body, so we do not
@@ -33161,11 +33161,11 @@ package body Sem_Prag is
   else
  if Cont = False then
 Error_Msg
-   ("<<~", Eloc, Is_Compile_Time_Pragma => True);
+   ("<<~", Eloc, N, Is_Compile_Time_Pragma => True);
 Cont := True;
  else
 Error_Msg
-   ("\<<~", Eloc, Is_Compile_Time_Pragma => True);
+   ("\<<~", Eloc, N, Is_Compile_Time_Pragma => True);
  end if;
   end if;


[gcc r15-466] ada: Correct System.Win32.LocalFileTimeToFileTime wrapper typo

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:42ea46c67ddcde686e3792864d035dfd1645801f

commit r15-466-g42ea46c67ddcde686e3792864d035dfd1645801f
Author: Philippe Gil 
Date:   Wed Feb 7 14:53:54 2024 +0100

ada: Correct System.Win32.LocalFileTimeToFileTime wrapper typo

The parameters should be swapped to fit Fileapi.h documentation.
BOOL LocalFileTimeToFileTime(
[in]  const FILETIME *lpLocalFileTime,
[out] LPFILETIME lpFileTime
);

gcc/ada/
* libgnat/s-win32.ads (LocalFileTimeToFileTime): Swap parameters.

Diff:
---
 gcc/ada/libgnat/s-win32.ads | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/libgnat/s-win32.ads b/gcc/ada/libgnat/s-win32.ads
index 6ea661536392..6e8e246d903a 100644
--- a/gcc/ada/libgnat/s-win32.ads
+++ b/gcc/ada/libgnat/s-win32.ads
@@ -315,8 +315,8 @@ package System.Win32 is
pragma Import (Stdcall, FileTimeToLocalFileTime, "FileTimeToLocalFileTime");
 
function LocalFileTimeToFileTime
- (lpFileTime  : access Long_Long_Integer;
-  lpLocalFileTime : access Long_Long_Integer) return BOOL;
+ (lpLocalFileTime : access Long_Long_Integer;
+  lpFileTime  : access Long_Long_Integer) return BOOL;
pragma Import (Stdcall, LocalFileTimeToFileTime, "LocalFileTimeToFileTime");
 
procedure Sleep (dwMilliseconds : DWORD);


[gcc r15-469] ada: Fix crash with -gnatdJ and -gnatyz

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

commit r15-469-gfaf462cfe686228113fc9d968809dd4f40395dde
Author: Ronan Desplanques 
Date:   Wed Feb 14 15:12:15 2024 +0100

ada: Fix crash with -gnatdJ and -gnatyz

This patch makes it so -gnatyz style checks reports specify a node
ID. That is required since those checks are sometimes made during
semantic analysis of short-circuit operators, where the Current_Node
mechanism that -gnatdJ uses is not operational.

Check_Xtra_Parens_Precedence is moved from Styleg to Style to make
this possible.

gcc/ada/

* styleg.ads (Check_Xtra_Parens_Precedence): Moved ...
* style.ads (Check_Xtra_Parens_Precedence): ... here. Also
replace corresponding renaming.
* styleg.adb (Check_Xtra_Parens_Precedence): Moved ...
* style.adb (Check_Xtra_Parens_Precedence): here. Also use
Errout.Error_Msg and pass it a node parameter.

Diff:
---
 gcc/ada/style.adb  | 22 ++
 gcc/ada/style.ads  |  3 +--
 gcc/ada/styleg.adb | 22 --
 gcc/ada/styleg.ads |  4 
 4 files changed, 23 insertions(+), 28 deletions(-)

diff --git a/gcc/ada/style.adb b/gcc/ada/style.adb
index aaa668aab000..18b110b911d3 100644
--- a/gcc/ada/style.adb
+++ b/gcc/ada/style.adb
@@ -337,6 +337,28 @@ package body Style is
   end if;
end Check_Identifier;
 
+   --
+   -- Check_Xtra_Parens_Precedence --
+   --
+
+   procedure Check_Xtra_Parens_Precedence (N : Node_Id) is
+   begin
+  if Style_Check_Xtra_Parens_Precedence
+and then
+  Paren_Count (N) >
+(if Nkind (N) in N_Case_Expression
+   | N_Expression_With_Actions
+   | N_If_Expression
+   | N_Quantified_Expression
+   | N_Raise_Expression
+ then 1
+ else 0)
+  then
+ Error_Msg -- CODEFIX
+   ("(style) redundant parentheses?z?", First_Sloc (N), N);
+  end if;
+   end Check_Xtra_Parens_Precedence;
+

-- Missing_Overriding --

diff --git a/gcc/ada/style.ads b/gcc/ada/style.ads
index c0925e9ce345..9614242269cd 100644
--- a/gcc/ada/style.ads
+++ b/gcc/ada/style.ads
@@ -196,8 +196,7 @@ package Style is
--  Called after scanning an entire expression (N) that does not require an
--  extra level of parentheses.
 
-   procedure Check_Xtra_Parens_Precedence (N : Node_Id)
- renames Style_Inst.Check_Xtra_Parens_Precedence;
+   procedure Check_Xtra_Parens_Precedence (N : Node_Id);
--  Called after scanning a subexpression (N) that does not require an
--  extra level of parentheses according to operator precedence rules.
 
diff --git a/gcc/ada/styleg.adb b/gcc/ada/styleg.adb
index 287589f92da7..c405dec2b332 100644
--- a/gcc/ada/styleg.adb
+++ b/gcc/ada/styleg.adb
@@ -1054,28 +1054,6 @@ package body Styleg is
   end if;
end Check_Xtra_Parens;
 
-   --
-   -- Check_Xtra_Parens_Precedence --
-   --
-
-   procedure Check_Xtra_Parens_Precedence (N : Node_Id) is
-   begin
-  if Style_Check_Xtra_Parens_Precedence
-and then
-  Paren_Count (N) >
-(if Nkind (N) in N_Case_Expression
-   | N_Expression_With_Actions
-   | N_If_Expression
-   | N_Quantified_Expression
-   | N_Raise_Expression
- then 1
- else 0)
-  then
- Error_Msg -- CODEFIX
-   ("(style) redundant parentheses?z?", Errout.First_Sloc (N));
-  end if;
-   end Check_Xtra_Parens_Precedence;
-

-- Determine_Token_Casing --

diff --git a/gcc/ada/styleg.ads b/gcc/ada/styleg.ads
index 9028e85cc4ea..a16ea5c59610 100644
--- a/gcc/ada/styleg.ads
+++ b/gcc/ada/styleg.ads
@@ -160,10 +160,6 @@ package Styleg is
--  Called after scanning an entire expression (N) that does not require an
--  extra level of parentheses.
 
-   procedure Check_Xtra_Parens_Precedence (N : Node_Id);
-   --  Called after scanning a subexpression (N) that does not require an
-   --  extra level of parentheses according to operator precedence rules.
-
function Mode_In_Check return Boolean;
pragma Inline (Mode_In_Check);
--  Determines whether style checking is active and the Mode_In_Check is


[gcc r15-480] rs6000: Enable overlapped by-pieces operations

2024-05-14 Thread HaoChen Gui via Gcc-cvs
https://gcc.gnu.org/g:fbd115fe83e96e0796cd8e262ed773b0ba07db81

commit r15-480-gfbd115fe83e96e0796cd8e262ed773b0ba07db81
Author: Haochen Gui 
Date:   Tue May 14 16:37:06 2024 +0800

rs6000: Enable overlapped by-pieces operations

This patch enables overlapped by-piece operations by defining
TARGET_OVERLAP_OP_BY_PIECES_P to true.  On rs6000, default move/set/clear
ratio is 2.  So the overlap is only enabled with compare by-pieces.

gcc/
* config/rs6000/rs6000.cc (TARGET_OVERLAP_OP_BY_PIECES_P): Define.

gcc/testsuite/
* gcc.target/powerpc/block-cmp-9.c: New.

Diff:
---
 gcc/config/rs6000/rs6000.cc|  3 +++
 gcc/testsuite/gcc.target/powerpc/block-cmp-9.c | 11 +++
 2 files changed, 14 insertions(+)

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 117999613d83..e713a1e1d570 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -1776,6 +1776,9 @@ static const scoped_attribute_specs *const 
rs6000_attribute_table[] =
 #undef TARGET_CONST_ANCHOR
 #define TARGET_CONST_ANCHOR 0x8000
 
+#undef TARGET_OVERLAP_OP_BY_PIECES_P
+#define TARGET_OVERLAP_OP_BY_PIECES_P hook_bool_void_true
+
 
 
 /* Processor table.  */
diff --git a/gcc/testsuite/gcc.target/powerpc/block-cmp-9.c 
b/gcc/testsuite/gcc.target/powerpc/block-cmp-9.c
new file mode 100644
index ..f16429c2ffb0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/block-cmp-9.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-final { scan-assembler-not {\ml[hb]z\M} } } */
+
+/* Test if by-piece overlap compare is enabled and following case is
+   implemented by two overlap word loads and compares.  */
+
+int foo (const char* s1, const char* s2)
+{
+  return __builtin_memcmp (s1, s2, 7) == 0;
+}


[gcc r15-473] ada: Fix pragma Warnings and -gnatD interaction

2024-05-14 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:13d8374188eea21d56603135b6af254599c9e4b3

commit r15-473-g13d8374188eea21d56603135b6af254599c9e4b3
Author: Ronan Desplanques 
Date:   Thu Feb 15 15:02:10 2024 +0100

ada: Fix pragma Warnings and -gnatD interaction

A recent change broke pragma Warnings when -gnatD is enabled in some
cases. This patch fixes this by caching more slocs at times when it's
known that they haven't been modified by -gnatD.

gcc/ada/

* errout.adb (Validate_Specific_Warnings): Adapt to record
definition change.
* erroutc.adb (Set_Specific_Warning_On, Set_Specific_Warning_Off,
Warning_Specifically_Suppressed): Likewise.
* erroutc.ads: Change record definition.

Diff:
---
 gcc/ada/errout.adb  |  4 ++--
 gcc/ada/erroutc.adb | 11 +--
 gcc/ada/erroutc.ads | 10 +-
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
index f10539d09492..92c4f6a46350 100644
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -2028,7 +2028,7 @@ package body Errout is
if SWE.Open then
   Error_Msg_N
 ("?.w?pragma Warnings Off with no matching Warnings On",
- SWE.Start);
+ SWE.Node);
 
--  Warn for ineffective Warnings (Off, ..)
 
@@ -2043,7 +2043,7 @@ package body Errout is
then
   Error_Msg_N
 ("?.w?no warning suppressed by this pragma",
- SWE.Start);
+ SWE.Node);
end if;
 end if;
  end;
diff --git a/gcc/ada/erroutc.adb b/gcc/ada/erroutc.adb
index 96d8d128d843..be200e0016e3 100644
--- a/gcc/ada/erroutc.adb
+++ b/gcc/ada/erroutc.adb
@@ -1660,9 +1660,10 @@ package body Erroutc is
   Loc : constant Source_Ptr := Sinfo.Nodes.Sloc (Node);
begin
   Specific_Warnings.Append
-((Start  => Node,
+((Start  => Loc,
   Msg=> new String'(Msg),
   Stop   => Source_Last (Get_Source_File_Index (Loc)),
+  Node   => Node,
   Reason => Reason,
   Open   => True,
   Used   => Used,
@@ -1682,13 +1683,12 @@ package body Erroutc is
   for J in 1 .. Specific_Warnings.Last loop
  declare
 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
-Start_Loc : constant Source_Ptr := Sinfo.Nodes.Sloc (SWE.Start);
 
  begin
 if Msg = SWE.Msg.all
-  and then Loc > Start_Loc
+  and then Loc > SWE.Start
   and then SWE.Open
-  and then Get_Source_File_Index (Start_Loc) =
+  and then Get_Source_File_Index (SWE.Start) =
Get_Source_File_Index (Loc)
 then
SWE.Stop := Loc;
@@ -1819,13 +1819,12 @@ package body Erroutc is
   for J in Specific_Warnings.First .. Specific_Warnings.Last loop
  declare
 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
-Start_Loc : constant Source_Ptr := Sinfo.Nodes.Sloc (SWE.Start);
  begin
 --  Pragma applies if it is a configuration pragma, or if the
 --  location is in range of a specific non-configuration pragma.
 
 if SWE.Config
-  or else Sloc_In_Range (Loc, Start_Loc, SWE.Stop)
+  or else Sloc_In_Range (Loc, SWE.Start, SWE.Stop)
 then
if Matches (Msg.all, SWE.Msg.all)
  or else Matches (Tag, SWE.Msg.all)
diff --git a/gcc/ada/erroutc.ads b/gcc/ada/erroutc.ads
index 250461f4b5c5..1c43bce2b21c 100644
--- a/gcc/ada/erroutc.ads
+++ b/gcc/ada/erroutc.ads
@@ -347,11 +347,19 @@ package Erroutc is
--  which is the pattern to match for suppressing a warning.
 
type Specific_Warning_Entry is record
-  Start : Node_Id;
+  Start : Source_Ptr;
   Stop  : Source_Ptr;
   --  Starting and ending source pointers for the range. These are always
   --  from the same source file.
 
+  Node : Node_Id;
+  --  Node for the pragma Warnings occurrence. We store it to compute the
+  --  enclosing subprogram if -gnatdJ is enabled and a message about this
+  --  clause needs to be emitted. Note that we cannot remove the Start
+  --  component above and use Sloc (Node) on message display instead
+  --  because -gnatD output can already have messed with slocs at the point
+  --  when warnings about ineffective clauses are emitted.
+
   Reason : String_Id;
   --  Reason string from pragma Warnings, or null string if none


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

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

commit r15-476-g0ec8c070f3ccebc9a58ecb593c2e5cfdb6bcfd5c
Author: Marc Poulhiès 
Date:   Mon Jan 8 15:50:03 2024 +0100

ada: Minor typo fix in comment

gcc/ada/

* sem_util.adb: Typo fix in comment.
* exp_aggr.adb: Likewise.

Diff:
---
 gcc/ada/exp_aggr.adb | 2 +-
 gcc/ada/sem_util.adb | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 27a7f3d2b495..bdaca4aab58b 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -1988,7 +1988,7 @@ package body Exp_Aggr is
   --  STEP 1: Process component associations
 
   --  For those associations that may generate a loop, initialize
-  --  Loop_Actions to collect inserted actions that may be crated.
+  --  Loop_Actions to collect inserted actions that may be created.
 
   --  Skip this if no component associations
 
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 4e1258e7cecd..1785931530f8 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -7785,7 +7785,7 @@ package body Sem_Util is
 Set_Is_Immediately_Visible (E, False);
 
  --  Case of renaming declaration constructed for package instances.
- --  if there is an explicit declaration with the same identifier,
+ --  If there is an explicit declaration with the same identifier,
  --  the renaming is not immediately visible any longer, but remains
  --  visible through selected component notation.
 
@@ -7794,7 +7794,7 @@ package body Sem_Util is
  then
 Set_Is_Immediately_Visible (E, False);
 
- --  The new entity may be the package renaming, which has the same
+ --  The new entity may be the package renaming, which has the
  --  same name as a generic formal which has been seen already.
 
  elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration


[gcc r15-479] MAINTAINERS: Fix an entry using spaces instead of tabs

2024-05-14 Thread Filip Kastl via Gcc-cvs
https://gcc.gnu.org/g:1a809280929fac9836ff31dcc0980ac8acee7631

commit r15-479-g1a809280929fac9836ff31dcc0980ac8acee7631
Author: Filip Kastl 
Date:   Tue May 14 10:34:12 2024 +0200

MAINTAINERS: Fix an entry using spaces instead of tabs

In the MAINTAINERS file, names and emails are separated by tabs.  One of
the entries recently added used spaces.  This patch corrects this.

The check-MAINTAINERS.py script breaks a bit when this happens.  This
patch also adds warning about this situation into the script.

ChangeLog:

* MAINTAINERS: Use tabs between name and email.

contrib/ChangeLog:

* check-MAINTAINERS.py: Add warning about not using tabs.

Signed-off-by: Filip Kastl 

Diff:
---
 MAINTAINERS  | 2 +-
 contrib/check-MAINTAINERS.py | 8 
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 361059fd55c6..8bb435dd54ea 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -738,7 +738,7 @@ Kwok Cheung Yeung   

 Greta Yorsh
 David Yuste
 Adhemerval Zanella 
-Xiao Zeng   
+Xiao Zeng  
 Dennis Zhang   
 Yufeng Zhang   
 Qing Zhao  
diff --git a/contrib/check-MAINTAINERS.py b/contrib/check-MAINTAINERS.py
index 9f31a10bcffb..2bac67f08214 100755
--- a/contrib/check-MAINTAINERS.py
+++ b/contrib/check-MAINTAINERS.py
@@ -71,6 +71,14 @@ def check_group(name, lines):
 print(f'Line should not start with space: "{line}"')
 exit_code = 2
 
+# Special-case some names
+if line == 'James Norris':
+continue
+
+if '\t' not in line:
+print(f'Name and email should be separated by tabs: "{line}"')
+exit_code = 2
+
 lines = [line + '\n' for line in lines]
 sorted_lines = sorted(lines, key=sort_by_surname)
 if lines != sorted_lines:


[gcc r14-10203] libstdc++: Fix for -std=c++23 -ffreestanding [PR114866]

2024-05-14 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:95055199ee80e526da98c3458308fa345a041d9a

commit r14-10203-g95055199ee80e526da98c3458308fa345a041d9a
Author: Jonathan Wakely 
Date:   Thu May 2 12:14:52 2024 +0100

libstdc++: Fix  for -std=c++23 -ffreestanding [PR114866]

std::shared_ptr isn't declared for freestanding, so guard uses of it
with #if _GLIBCXX_HOSTED in .

libstdc++-v3/ChangeLog:

PR libstdc++/114866
* include/bits/out_ptr.h [!_GLIBCXX_HOSTED]: Don't refer to
shared_ptr, __shared_ptr or __is_shred_ptr.
* testsuite/20_util/headers/memory/114866.cc: New test.

(cherry picked from commit 9927059bb88e966e0a45f09e4fd1193f93df708f)

Diff:
---
 libstdc++-v3/include/bits/out_ptr.h | 10 ++
 libstdc++-v3/testsuite/20_util/headers/memory/114866.cc |  4 
 2 files changed, 14 insertions(+)

diff --git a/libstdc++-v3/include/bits/out_ptr.h 
b/libstdc++-v3/include/bits/out_ptr.h
index aeeb66404418..d74c9f52d3b5 100644
--- a/libstdc++-v3/include/bits/out_ptr.h
+++ b/libstdc++-v3/include/bits/out_ptr.h
@@ -54,9 +54,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 class out_ptr_t
 {
+#if _GLIBCXX_HOSTED
   static_assert(!__is_shared_ptr<_Smart> || sizeof...(_Args) != 0,
"a deleter must be used when adapting std::shared_ptr "
"with std::out_ptr");
+#endif
 
 public:
   explicit
@@ -216,6 +218,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  [[no_unique_address]] _Del2 _M_del;
};
 
+#if _GLIBCXX_HOSTED
   // Partial specialization for std::shared_ptr.
   // This specialization gives direct access to the private member
   // of the shared_ptr, avoiding the overhead of storing a separate
@@ -274,6 +277,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
  using _Impl<_Smart, _Pointer, _Del, allocator>::_Impl;
};
+#endif
 
   using _Impl_t = _Impl<_Smart, _Pointer, _Args...>;
 
@@ -293,8 +297,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 class inout_ptr_t
 {
+#if _GLIBCXX_HOSTED
   static_assert(!__is_shared_ptr<_Smart>,
"std::inout_ptr can not be used to wrap std::shared_ptr");
+#endif
 
 public:
   explicit
@@ -320,11 +326,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 
 private:
+#if _GLIBCXX_HOSTED
   // Avoid an invalid instantiation of out_ptr_t, ...>
   using _Out_ptr_t
= __conditional_t<__is_shared_ptr<_Smart>,
  out_ptr_t,
  out_ptr_t<_Smart, _Pointer, _Args...>>;
+#else
+  using _Out_ptr_t = out_ptr_t<_Smart, _Pointer, _Args...>;
+#endif
   using _Impl_t = typename _Out_ptr_t::_Impl_t;
   _Impl_t _M_impl;
 };
diff --git a/libstdc++-v3/testsuite/20_util/headers/memory/114866.cc 
b/libstdc++-v3/testsuite/20_util/headers/memory/114866.cc
new file mode 100644
index ..7cf6be0539d2
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/headers/memory/114866.cc
@@ -0,0 +1,4 @@
+// { dg-options "-ffreestanding" }
+// { dg-do compile }
+// PR libstdc++/114866  & out_ptr in freestanding
+#include 


[gcc r14-10204] libstdc++: Fix handling of incomplete UTF-8 sequences in _Unicode_view

2024-05-14 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:b0f022f93a710c8143badedf8110a47227e17f62

commit r14-10204-gb0f022f93a710c8143badedf8110a47227e17f62
Author: Jonathan Wakely 
Date:   Wed May 1 17:09:39 2024 +0100

libstdc++: Fix handling of incomplete UTF-8 sequences in _Unicode_view

Eddie Nolan reported to me that _Unicode_view was not correctly
implementing the substitution of ill-formed subsequences with U+FFFD,
due to failing to increment the counter when the iterator reaches the
end of the sequence before a multibyte sequence is complete.  As a
result, the incomplete sequence was not completely consumed, and then
the remaining character was treated as another ill-formed sequence,
giving two U+FFFD characters instead of one.

To avoid similar mistakes in future, this change introduces a lambda
that increments the iterator and the counter together. This ensures the
counter is always incremented when the iterator is incremented, so that
we always know how many characters have been consumed.

libstdc++-v3/ChangeLog:

* include/bits/unicode.h (_Unicode_view::_M_read_utf8): Ensure
count of characters consumed is correct when the end of the
input is reached unexpectedly.
* testsuite/ext/unicode/view.cc: Test incomplete UTF-8
sequences.

(cherry picked from commit 3f04f3939ea0ac8fdd766a60655d29de2ffb44e5)

Diff:
---
 libstdc++-v3/include/bits/unicode.h| 24 +++-
 libstdc++-v3/testsuite/ext/unicode/view.cc |  7 +++
 2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/libstdc++-v3/include/bits/unicode.h 
b/libstdc++-v3/include/bits/unicode.h
index 29813b743dc1..46238143fb61 100644
--- a/libstdc++-v3/include/bits/unicode.h
+++ b/libstdc++-v3/include/bits/unicode.h
@@ -261,9 +261,13 @@ namespace __unicode
   {
_Guard<_Iter> __g{this, _M_curr()};
char32_t __c{};
-   uint8_t __u = *_M_curr()++;
const uint8_t __lo_bound = 0x80, __hi_bound = 0xBF;
+   uint8_t __u = *_M_curr()++;
uint8_t __to_incr = 1;
+   auto __incr = [&, this] {
+ ++__to_incr;
+ return ++_M_curr();
+   };
 
if (__u <= 0x7F) [[likely]]  // 0x00 to 0x7F
  __c = __u;
@@ -281,8 +285,7 @@ namespace __unicode
else
  {
__c = (__c << 6) | (__u & 0x3F);
-   ++_M_curr();
-   ++__to_incr;
+   __incr();
  }
  }
else if (__u <= 0xEF) // 0xE0 to 0xEF
@@ -295,11 +298,10 @@ namespace __unicode
 
if (__u < __lo_bound_2 || __u > __hi_bound_2) [[unlikely]]
  __c = _S_error();
-   else if (++_M_curr() == _M_last) [[unlikely]]
+   else if (__incr() == _M_last) [[unlikely]]
  __c = _S_error();
else
  {
-   ++__to_incr;
__c = (__c << 6) | (__u & 0x3F);
__u = *_M_curr();
 
@@ -308,8 +310,7 @@ namespace __unicode
else
  {
__c = (__c << 6) | (__u & 0x3F);
-   ++_M_curr();
-   ++__to_incr;
+   __incr();
  }
  }
  }
@@ -323,21 +324,19 @@ namespace __unicode
 
if (__u < __lo_bound_2 || __u > __hi_bound_2) [[unlikely]]
  __c = _S_error();
-   else if (++_M_curr() == _M_last) [[unlikely]]
+   else if (__incr() == _M_last) [[unlikely]]
  __c = _S_error();
else
  {
-   ++__to_incr;
__c = (__c << 6) | (__u & 0x3F);
__u = *_M_curr();
 
if (__u < __lo_bound || __u > __hi_bound) [[unlikely]]
  __c = _S_error();
-   else if (++_M_curr() == _M_last) [[unlikely]]
+   else if (__incr() == _M_last) [[unlikely]]
  __c = _S_error();
else
  {
-   ++__to_incr;
__c = (__c << 6) | (__u & 0x3F);
__u = *_M_curr();
 
@@ -346,8 +345,7 @@ namespace __unicode
else
  {
__c = (__c << 6) | (__u & 0x3F);
-   ++_M_curr();
-   ++__to_incr;
+   __incr();
  }
  }
  }
diff --git a/libstdc++-v3/testsuite/ext/unicode/view.cc 
b/libstdc++-v3/testsuite/ext/unicode/view.cc
index ee23b0b1d8a3..6f3c099bd84a 100644
--- a/libstdc++-v3/testsuite/ext/unicode/view.cc
+++ b/libstdc++-v3/testsuite/ext/unicode/view.cc
@@ -55,6 +55,13 @@ test_illformed_utf8()
   VERIFY( std::ranges::equal(v5, 
u8"\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\x41\uFFFD\uFFFD\x42"sv) );
   uc::_Utf8_view v6("\xe1\x80\xe2\xf0\x91\x92\xf1\xbf\x41"sv); // Table 3-11
   VERIFY( std::ranges::equal(v6, u8"\uFFFD\uFFFD\uFFFD\uFFFD\x

[gcc r14-10205] libstdc++: Update ABI test to disallow adding to released symbol versions

2024-05-14 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:788ccd269e0c32c33ce0c1359137fe1b35dc7a2d

commit r14-10205-g788ccd269e0c32c33ce0c1359137fe1b35dc7a2d
Author: Jonathan Wakely 
Date:   Thu Apr 11 15:35:11 2024 +0100

libstdc++: Update ABI test to disallow adding to released symbol versions

If we update the list of "active" symbols versions now, rather than when
adding a new symbol version, we will notice if new symbols get added to
the wrong version (as in PR 114692).

libstdc++-v3/ChangeLog:

* testsuite/util/testsuite_abi.cc: Update latest versions to
new versions that should be used in future.

(cherry picked from commit 6e25ca387fbbb412a2e498e28ea5db28e033a318)

Diff:
---
 libstdc++-v3/testsuite/util/testsuite_abi.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/testsuite/util/testsuite_abi.cc 
b/libstdc++-v3/testsuite/util/testsuite_abi.cc
index e4bf3cdc8e07..ec7c3df9eccb 100644
--- a/libstdc++-v3/testsuite/util/testsuite_abi.cc
+++ b/libstdc++-v3/testsuite/util/testsuite_abi.cc
@@ -254,8 +254,8 @@ check_version(symbol& test, bool added)
test.version_status = symbol::incompatible;
 
   // Check that added symbols are added in the latest pre-release version.
-  bool latestp = (test.version_name == "GLIBCXX_3.4.33"
-|| test.version_name == "CXXABI_1.3.15"
+  bool latestp = (test.version_name == "GLIBCXX_3.4.34"
+|| test.version_name == "CXXABI_1.3.16"
 || test.version_name == "CXXABI_FLOAT128"
 || test.version_name == "CXXABI_TM_1");
   if (added && !latestp)


[gcc r14-10206] libstdc++: Guard uses of is_pointer_interconvertible_v [PR114891]

2024-05-14 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:4d3b358fd757ddd09cbee202f47939043c78676c

commit r14-10206-g4d3b358fd757ddd09cbee202f47939043c78676c
Author: Jonathan Wakely 
Date:   Tue Apr 30 09:48:00 2024 +0100

libstdc++: Guard uses of is_pointer_interconvertible_v [PR114891]

This type trait isn't supported by Clang 18. It's only used in static
assertions, so they can just be omitted if the trait isn't available.

libstdc++-v3/ChangeLog:

PR libstdc++/114891
* include/std/generator: Check feature test macro before using
is_pointer_interconvertible_v.

(cherry picked from commit 1fbe1a50d86df11f434351cf62461a32747f9710)

Diff:
---
 libstdc++-v3/include/std/generator | 8 
 1 file changed, 8 insertions(+)

diff --git a/libstdc++-v3/include/std/generator 
b/libstdc++-v3/include/std/generator
index 789016b5a883..1d5acc914203 100644
--- a/libstdc++-v3/include/std/generator
+++ b/libstdc++-v3/include/std/generator
@@ -322,8 +322,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template
auto await_suspend(std::coroutine_handle<_Promise> __c) noexcept
{
+#ifdef __glibcxx_is_pointer_interconvertible
  static_assert(is_pointer_interconvertible_base_of_v<
_Promise_erased, _Promise>);
+#endif
 
  auto& __n = __c.promise()._M_nest;
  return __n._M_pop();
@@ -344,8 +346,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template
void await_suspend(std::coroutine_handle<_Promise>) noexcept
{
+#ifdef __glibcxx_is_pointer_interconvertible
  static_assert(is_pointer_interconvertible_base_of_v<
_Promise_erased, _Promise>);
+#endif
  _M_bottom_value = ::std::addressof(_M_value);
}
 
@@ -375,8 +379,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::coroutine_handle<>
await_suspend(std::coroutine_handle<_Promise> __p) noexcept
{
+#ifdef __glibcxx_is_pointer_interconvertible
  static_assert(is_pointer_interconvertible_base_of_v<
_Promise_erased, _Promise>);
+#endif
 
  auto __c = _Coro_handle::from_address(__p.address());
  auto __t = _Coro_handle::from_address(this->_M_gen._M_coro.address());
@@ -685,8 +691,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return { coroutine_handle::from_promise(*this) }; }
   };
 
+#ifdef __glibcxx_is_pointer_interconvertible
   static_assert(is_pointer_interconvertible_base_of_v<_Erased_promise,
promise_type>);
+#endif
 
   generator(const generator&) = delete;


[gcc r14-10207] libstdc++: Fix typo in std::stacktrace::max_size [PR115063]

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

commit r14-10207-gc60205cd4aeea586b7b1fe06baa9861b6d279648
Author: Jonathan Wakely 
Date:   Mon May 13 16:25:13 2024 +0100

libstdc++: Fix typo in std::stacktrace::max_size [PR115063]

libstdc++-v3/ChangeLog:

PR libstdc++/115063
* include/std/stacktrace (basic_stacktrace::max_size): Fix typo
in reference to _M_alloc member.
* testsuite/19_diagnostics/stacktrace/stacktrace.cc: Check
max_size() compiles.

(cherry picked from commit dd9677f3343ca2a4b4aab9428b8129774accac29)

Diff:
---
 libstdc++-v3/include/std/stacktrace|  2 +-
 libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc | 10 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/stacktrace 
b/libstdc++-v3/include/std/stacktrace
index 92a69a53d986..d217d63af3bb 100644
--- a/libstdc++-v3/include/std/stacktrace
+++ b/libstdc++-v3/include/std/stacktrace
@@ -430,7 +430,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   [[nodiscard]]
   size_type
   max_size() const noexcept
-  { return _Impl::_S_max_size(_M_impl._M_alloc); }
+  { return _Impl::_S_max_size(_M_alloc); }
 
   [[nodiscard]]
   const_reference
diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc 
b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
index 070c4157471c..a49cddfef268 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
@@ -206,10 +206,20 @@ test_pr105031()
   s = auto(s);
 }
 
+void
+test_pr115063()
+{
+  // PR libstdc++/115063
+  // compilation error: std::basic_stracktrace::max_size()
+  std::stacktrace s;
+  VERIFY( s.max_size() != 0 );
+}
+
 int main()
 {
   test_cons();
   test_assign();
   test_swap();
   test_pr105031();
+  test_pr115063();
 }


[gcc r13-8768] libstdc++: Fix run_doxygen for Doxygen 1.10 man page format

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

commit r13-8768-gbce15a5d7d2c4053b8d5e718f00db8eb20116cb6
Author: Jonathan Wakely 
Date:   Thu Apr 25 13:24:56 2024 +0100

libstdc++: Fix run_doxygen for Doxygen 1.10 man page format

Doxygen switched from \fC to \fR in its man page output:
https://github.com/doxygen/doxygen/pull/10497

This breaks our script that expects \fC so change the regaulr expression
to work with either style.

libstdc++-v3/ChangeLog:

* scripts/run_doxygen: Adjust sed pattern to match '\fR' for
new man output that Doxygen 1.10 generates.

(cherry picked from commit c9cc1c850c6d084752207b6cf247a0a48bae0d52)

Diff:
---
 libstdc++-v3/scripts/run_doxygen | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/scripts/run_doxygen b/libstdc++-v3/scripts/run_doxygen
index 42ed9eb4f5df..9c11a0cfa1fd 100644
--- a/libstdc++-v3/scripts/run_doxygen
+++ b/libstdc++-v3/scripts/run_doxygen
@@ -294,7 +294,11 @@ $gxx $cppflags $cxxflags 
${srcdir}/doc/doxygen/stdheader.cc -o ./stdheader || ex
 problematic=`grep -E -l '#include <.*h>' [a-z]*.3`
 for f in $problematic; do
 # this is also slow, but safe and easy to debug
-oldh=`sed -n '/fC#include .*/\1/p' $f`
+oldh=`sed -n '/f[CR]#include .*/\1/p' $f`
+if [ "$oldh" == "" ]; then
+  echo "ERROR: Doxygen man page formatting changed" 2>&1
+  continue
+fi
 newh=`echo $oldh | sed 's/&\\././g' | ./stdheader`
 sed "s=${oldh/\\/.}=${newh}=" $f > TEMP && mv TEMP $f
 done


[gcc r13-8769] libstdc++: Fix typo in Doxygen comment

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

commit r13-8769-gebc61a9c4c730bf5562db25b1fcc06d615e33e66
Author: Jonathan Wakely 
Date:   Thu Apr 25 13:52:00 2024 +0100

libstdc++: Fix typo in Doxygen comment

libstdc++-v3/ChangeLog:

* include/std/chrono (tzdb_list): Fix typo in Doxygen comment.

(cherry picked from commit 6391cf8bd9c1d71805d9aba00b25fdaa550f39c8)

Diff:
---
 libstdc++-v3/include/std/chrono | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index edb782f6f10e..1f3f897d932a 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -2790,7 +2790,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /** Remove the tzdb object _after_ the one the iterator refers to.
*
-   * Calling this function concurently with any of `front()`, `begin()`,
+   * Calling this function concurrently with any of `front()`, `begin()`,
* or `end()` does not cause a data race, but in general this function
* is not thread-safe. The behaviour may be undefined if erasing an
* element from the list while another thread is calling the same


[gcc r13-8770] libstdc++: Adjust expected locale-dependent date formats in tests

2024-05-14 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:b9e2a3227359f20a6e3501e02ae5f909f7f96b8a

commit r13-8770-gb9e2a3227359f20a6e3501e02ae5f909f7f96b8a
Author: Jonathan Wakely 
Date:   Wed Apr 10 13:24:51 2024 +0100

libstdc++: Adjust expected locale-dependent date formats in tests

The std/time/year_month_day/io.cc test assumes that %x in the fr_FR
locale is %d/%m/%Y but on FreeBSD it is %d.%m.%Y instead. Make the test
PASS for either format.

Similarly, 27_io/manipulators/extended/get_time/char/2.cc expects that
%a in the de_DE locale is "Di" but on FreeBSD it's "Di." with a trailing
period. Adjust the input string to be "1971 Di." instead of "Di 1971"
and that way if %a doesn't expect the trailing '.' it simply won't
extract it from the stream.

This fixes:
FAIL: std/time/year_month_day/io.cc  -std=gnu++20 execution test
FAIL: 27_io/manipulators/extended/get_time/char/2.cc  -std=gnu++17 
execution test

libstdc++-v3/ChangeLog:

* testsuite/27_io/manipulators/extended/get_time/char/2.cc:
Adjust input string so that it matches %a with or without a
trailing period.
* testsuite/std/time/year_month_day/io.cc: Adjust expected
format for %x in the fr_FR locale.

(cherry picked from commit 4decc1062f0f6eb44209d9d5a26a744ffa474648)

Diff:
---
 .../testsuite/27_io/manipulators/extended/get_time/char/2.cc| 6 +++---
 libstdc++-v3/testsuite/std/time/year_month_day/io.cc| 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git 
a/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/2.cc 
b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/2.cc
index b99264012879..1de9eadc9e7e 100644
--- a/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/2.cc
+++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_time/char/2.cc
@@ -35,9 +35,9 @@ void test01()
   VERIFY( loc_de != loc_c );
   istringstream iss;
   iss.imbue(loc_de);
-  iss.str("Di 1971");
-  tm time1;
-  iss >> get_time(&time1, "%a %Y");
+  iss.str("1971 Di."); // %a is "Di" on some targets, "Di." on others.
+  tm time1{};
+  iss >> get_time(&time1, "%Y %a");
   VERIFY(time1.tm_wday == 2);
   VERIFY(time1.tm_year == 71);
 }
diff --git a/libstdc++-v3/testsuite/std/time/year_month_day/io.cc 
b/libstdc++-v3/testsuite/std/time/year_month_day/io.cc
index 04e6e59c8f76..0efa25a61425 100644
--- a/libstdc++-v3/testsuite/std/time/year_month_day/io.cc
+++ b/libstdc++-v3/testsuite/std/time/year_month_day/io.cc
@@ -85,7 +85,7 @@ test_format()
   s = std::format(loc_fr, "{:%x}", 2022y/December/19);
   VERIFY( s == "12/19/22" );
   s = std::format(loc_fr, "{:L%x}", 2022y/December/19);
-  VERIFY( s == "19/12/2022" );
+  VERIFY( s == "19/12/2022" || s == "19.12.2022" ); // depends on locale defs
   s = std::format(loc_fr, "{}", 2022y/December/19);
   VERIFY( s == "2022-12-19" );
   s = std::format(loc_fr, "{:L%F}", 2022y/December/19);


[gcc r13-8771] libstdc++: Fix infinite loop in std::binomial_distribution [PR114359]

2024-05-14 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:71e941b0e329d3a316e465569c92e08788a68614

commit r13-8771-g71e941b0e329d3a316e465569c92e08788a68614
Author: Jonathan Wakely 
Date:   Mon Mar 18 13:22:17 2024 +

libstdc++: Fix infinite loop in std::binomial_distribution [PR114359]

The multiplication (4 * _M_t * __1p) can wraparound to zero if _M_t is
unsigned and 4 * _M_t wraps to zero. The third operand has type double,
so do the second multiplication first, so that we aren't multiplying
integers.

libstdc++-v3/ChangeLog:

PR libstdc++/114359
* include/bits/random.tcc (binomial_distribution::param_type):
Ensure arithmetic is done as type double.
* testsuite/26_numerics/random/binomial_distribution/114359.cc: New 
test.

(cherry picked from commit 07e03761a7fc1626a6a74ed957e117f56981558c)

Diff:
---
 libstdc++-v3/include/bits/random.tcc |  2 +-
 .../26_numerics/random/binomial_distribution/114359.cc   | 12 
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/random.tcc 
b/libstdc++-v3/include/bits/random.tcc
index 6afddbbdd467..9e9c98e6826f 100644
--- a/libstdc++-v3/include/bits/random.tcc
+++ b/libstdc++-v3/include/bits/random.tcc
@@ -1503,7 +1503,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  // sqrt(pi / 2)
  const double __spi_2 = 1.2533141373155002512078826424055226L;
  _M_s1 = std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
- _M_s2 = std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p));
+ _M_s2 = std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * (_M_t * __1p)));
  _M_c = 2 * _M_d1 / __np;
  _M_a1 = std::exp(_M_c) * _M_s1 * __spi_2;
  const double __a12 = _M_a1 + _M_s2 * __spi_2;
diff --git 
a/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/114359.cc 
b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/114359.cc
new file mode 100644
index ..c1e4c380bf91
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/114359.cc
@@ -0,0 +1,12 @@
+// { dg-do run { target c++11 } }
+
+// Bug 114359 - std::binomial_distribution hangs in infinite loop
+
+#include 
+
+int main()
+{
+  std::default_random_engine g{};
+  std::binomial_distribution b(1U << 30);
+  b(g);  // hangs forever
+}


[gcc r13-8772] libstdc++: Fix typo in std::stacktrace::max_size [PR115063]

2024-05-14 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:7dca716decf5a07f903610fda9457ff0422d2758

commit r13-8772-g7dca716decf5a07f903610fda9457ff0422d2758
Author: Jonathan Wakely 
Date:   Mon May 13 16:25:13 2024 +0100

libstdc++: Fix typo in std::stacktrace::max_size [PR115063]

libstdc++-v3/ChangeLog:

PR libstdc++/115063
* include/std/stacktrace (basic_stacktrace::max_size): Fix typo
in reference to _M_alloc member.
* testsuite/19_diagnostics/stacktrace/stacktrace.cc: Check
max_size() compiles.

(cherry picked from commit dd9677f3343ca2a4b4aab9428b8129774accac29)

Diff:
---
 libstdc++-v3/include/std/stacktrace|  2 +-
 libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc | 10 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/stacktrace 
b/libstdc++-v3/include/std/stacktrace
index e4ca2d6bfa99..8f09467d7512 100644
--- a/libstdc++-v3/include/std/stacktrace
+++ b/libstdc++-v3/include/std/stacktrace
@@ -483,7 +483,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   size_type
   max_size() const noexcept
-  { return _Impl::_S_max_size(_M_impl._M_alloc); }
+  { return _Impl::_S_max_size(_M_alloc); }
 
   const_reference
   operator[](size_type __n) const noexcept
diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc 
b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
index 0a358b7b8ff7..1caa0fd35cb5 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
@@ -206,10 +206,20 @@ test_pr105031()
   s = auto(s);
 }
 
+void
+test_pr115063()
+{
+  // PR libstdc++/115063
+  // compilation error: std::basic_stracktrace::max_size()
+  std::stacktrace s;
+  VERIFY( s.max_size() != 0 );
+}
+
 int main()
 {
   test_cons();
   test_assign();
   test_swap();
   test_pr105031();
+  test_pr115063();
 }


[gcc r15-481] libstdc++: Fix typo in std::stacktrace::max_size [PR115063]

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

commit r15-481-gccc26a1af07b34ce2e7d3b2497f27992d1b1bbc2
Author: Jonathan Wakely 
Date:   Mon May 13 16:25:13 2024 +0100

libstdc++: Fix typo in std::stacktrace::max_size [PR115063]

libstdc++-v3/ChangeLog:

PR libstdc++/115063
* include/std/stacktrace (basic_stacktrace::max_size): Fix typo
in reference to _M_alloc member.
* testsuite/19_diagnostics/stacktrace/stacktrace.cc: Check
max_size() compiles.

Diff:
---
 libstdc++-v3/include/std/stacktrace|  2 +-
 libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc | 10 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/stacktrace 
b/libstdc++-v3/include/std/stacktrace
index 92a69a53d986..d217d63af3bb 100644
--- a/libstdc++-v3/include/std/stacktrace
+++ b/libstdc++-v3/include/std/stacktrace
@@ -430,7 +430,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   [[nodiscard]]
   size_type
   max_size() const noexcept
-  { return _Impl::_S_max_size(_M_impl._M_alloc); }
+  { return _Impl::_S_max_size(_M_alloc); }
 
   [[nodiscard]]
   const_reference
diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc 
b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
index 070c4157471c..a49cddfef268 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
@@ -206,10 +206,20 @@ test_pr105031()
   s = auto(s);
 }
 
+void
+test_pr115063()
+{
+  // PR libstdc++/115063
+  // compilation error: std::basic_stracktrace::max_size()
+  std::stacktrace s;
+  VERIFY( s.max_size() != 0 );
+}
+
 int main()
 {
   test_cons();
   test_assign();
   test_swap();
   test_pr105031();
+  test_pr115063();
 }


[gcc r15-482] Reduce recursive inlining of always_inline functions

2024-05-14 Thread Jan Hubicka via Gcc-cvs
https://gcc.gnu.org/g:1ec49897253e093e1ef6261eb104ac0c111bac83

commit r15-482-g1ec49897253e093e1ef6261eb104ac0c111bac83
Author: Jan Hubicka 
Date:   Tue May 14 12:58:56 2024 +0200

Reduce recursive inlining of always_inline functions

this patch tames down inliner on (mutiply) self-recursive always_inline 
functions.
While we already have caps on recursive inlning, the testcase combines 
early inliner
and late inliner to get very wide recursive inlining tree.  The basic idea 
is to
ignore DISREGARD_INLINE_LIMITS when deciding on inlining self recursive 
functions
(so we cut on function being large) and clear the flag once it is detected.

I did not include the testcase since it still produces a lot of code and 
would
slow down testing.  It also outputs many inlining failed messages that is 
not
very nice, but it is hard to detect self recursin cycles in full generality
when indirect calls and other tricks may happen.

gcc/ChangeLog:

PR ipa/113291

* ipa-inline.cc (enum can_inline_edge_by_limits_flags): New enum.
(can_inline_edge_by_limits_p): Take flags instead of multiple 
bools; add flag
for forcing inlinie limits.
(can_early_inline_edge_p): Update.
(want_inline_self_recursive_call_p): Update; use FORCE_LIMITS mode.
(check_callers): Update.
(update_caller_keys): Update.
(update_callee_keys): Update.
(recursive_inlining): Update.
(add_new_edges_to_heap): Update.
(speculation_useful_p): Update.
(inline_small_functions): Clear DECL_DISREGARD_INLINE_LIMITS on 
self recursion.
(flatten_function): Update.
(inline_to_all_callers_1): Update.

Diff:
---
 gcc/ipa-inline.cc | 79 +--
 1 file changed, 53 insertions(+), 26 deletions(-)

diff --git a/gcc/ipa-inline.cc b/gcc/ipa-inline.cc
index e52757510ce9..9fc41b7696d8 100644
--- a/gcc/ipa-inline.cc
+++ b/gcc/ipa-inline.cc
@@ -496,24 +496,33 @@ inline_insns_auto (cgraph_node *n, bool hint, bool hint2)
   return max_inline_insns_auto;
 }
 
+enum can_inline_edge_by_limits_flags
+{
+  /* True if we are early inlining.  */
+  CAN_INLINE_EARLY = 1,
+  /* Ignore size limits.  */
+  CAN_INLINE_DISREGARD_LIMITS = 2,
+  /* Force size limits (ignore always_inline).  This is used for
+ recrusive inlining where always_inline may lead to inline bombs
+ and technically it is non-sential anyway.  */
+  CAN_INLINE_FORCE_LIMITS = 4,
+  /* Report decision to dump file.  */
+  CAN_INLINE_REPORT = 8,
+};
+
 /* Decide if we can inline the edge and possibly update
inline_failed reason.  
We check whether inlining is possible at all and whether
-   caller growth limits allow doing so.  
-
-   if REPORT is true, output reason to the dump file.
-
-   if DISREGARD_LIMITS is true, ignore size limits.  */
+   caller growth limits allow doing so.  */
 
 static bool
-can_inline_edge_by_limits_p (struct cgraph_edge *e, bool report,
-bool disregard_limits = false, bool early = false)
+can_inline_edge_by_limits_p (struct cgraph_edge *e, int flags)
 {
   gcc_checking_assert (e->inline_failed);
 
   if (cgraph_inline_failed_type (e->inline_failed) == CIF_FINAL_ERROR)
 {
-  if (report)
+  if (flags & CAN_INLINE_REPORT)
 report_inline_failed_reason (e);
   return false;
 }
@@ -527,10 +536,11 @@ can_inline_edge_by_limits_p (struct cgraph_edge *e, bool 
report,
   tree callee_tree
 = callee ? DECL_FUNCTION_SPECIFIC_OPTIMIZATION (callee->decl) : NULL;
   /* Check if caller growth allows the inlining.  */
-  if (!DECL_DISREGARD_INLINE_LIMITS (callee->decl)
-  && !disregard_limits
-  && !lookup_attribute ("flatten",
-DECL_ATTRIBUTES (caller->decl))
+  if (!(flags & CAN_INLINE_DISREGARD_LIMITS)
+  && ((flags & CAN_INLINE_FORCE_LIMITS)
+ || (!DECL_DISREGARD_INLINE_LIMITS (callee->decl)
+ && !lookup_attribute ("flatten",
+DECL_ATTRIBUTES (caller->decl
   && !caller_growth_limits (e))
 inlinable = false;
   else if (callee->externally_visible
@@ -558,7 +568,7 @@ can_inline_edge_by_limits_p (struct cgraph_edge *e, bool 
report,
to inline library always_inline functions. See PR65873.
Disable the check for early inlining for now until better solution
is found.  */
- if (always_inline && early)
+ if (always_inline && (flags & CAN_INLINE_EARLY))
;
   /* There are some options that change IL semantics which means
  we cannot inline in these cases for correctness reason.
@@ -594,7 +604,7 @@ can_inline_edge_by_limits_p (struct cgraph_edge *e, bool 
report,
  /* When devirtualization is disabled for callee, it is not safe
 to inline it as we possibly mangled the type info.
 Allo

[gcc r13-8773] ICF&SRA: Make ICF and SRA agree on padding

2024-05-14 Thread Martin Jambor via Gcc-cvs
https://gcc.gnu.org/g:10bf53a80eefa46500bffb442719777e2640e7d7

commit r13-8773-g10bf53a80eefa46500bffb442719777e2640e7d7
Author: Martin Jambor 
Date:   Mon Apr 8 18:53:23 2024 +0200

ICF&SRA: Make ICF and SRA agree on padding

PR 113359 shows that (at least with -fno-strict-aliasing) ICF can
unify two functions which copy an aggregate type of the same size but
then SRA, through its total scalarization, can copy the aggregate by
pieces, skipping paddding, but the padding was not the same in the two
original functions that ICF unified.

This patch enhances SRA with the ability to collect padding
information which then can be compared from within ICF.  Unfortunately
SRA uses OPTION_SET_P when determining its limits, so ICF needs to
switch cfuns at least once to figure it out too.

gcc/ChangeLog:

2024-03-27  Martin Jambor  

PR ipa/113359
* ipa-icf-gimple.h (func_checker): New members
safe_for_total_scalarization_p, m_total_scalarization_limit_known_p
and m_total_scalarization_limit.
(func_checker::func_checker): Initialize new member variables.
* ipa-icf-gimple.cc: Include tree-sra.h.
(func_checker::func_checker): Initialize new member variables.
(func_checker::safe_for_total_scalarization_p): New function.
(func_checker::compare_operand): Use the new function.
* tree-sra.h (sra_get_max_scalarization_size): Declare.
(sra_total_scalarization_would_copy_same_data_p): Likewise.
* tree-sra.cc (prepare_iteration_over_array_elts): New function.
(class sra_padding_collecting): New.
(sra_padding_collecting::record_padding): Likewise.
(scalarizable_type_p): Rename to totally_scalarizable_type_p.  Add
ability to record padding when requested.
(totally_scalarize_subtree): Split out gathering information 
necessary
to iterate over array elements to prepare_iteration_over_array_elts.
Fix errornous early exit.
(analyze_all_variable_accesses): Adjust the call to
totally_scalarizable_type_p.  Move determining of total scalariation
size limit...
(sra_get_max_scalarization_size): ...here.
(check_ts_and_push_padding_to_vec): New function.
(sra_total_scalarization_would_copy_same_data_p): Likewise.

gcc/testsuite/ChangeLog:

2024-03-27  Martin Jambor  

PR ipa/113359
* gcc.dg/lto/pr113359-1_0.c: New.
* gcc.dg/lto/pr113359-1_1.c: Likewise.
* gcc.dg/lto/pr113359-2_0.c: Likewise.
* gcc.dg/lto/pr113359-2_1.c: Likewise.
* gcc.dg/lto/pr113359-3_0.c: Likewise.
* gcc.dg/lto/pr113359-3_1.c: Likewise.
* gcc.dg/lto/pr113359-4_0.c: Likewise.
* gcc.dg/lto/pr113359-4_1.c: Likewise.
* gcc.dg/lto/pr113359-5_0.c: Likewise.
* gcc.dg/lto/pr113359-5_1.c: Likewise.

(cherry picked from commit 1e3312a25a7b34d6e3f549273e1674c7114e4408)

Diff:
---
 gcc/ipa-icf-gimple.cc   |  41 +-
 gcc/ipa-icf-gimple.h|  15 +-
 gcc/testsuite/gcc.dg/lto/pr113359-1_0.c |  86 +++
 gcc/testsuite/gcc.dg/lto/pr113359-1_1.c |  38 +
 gcc/testsuite/gcc.dg/lto/pr113359-2_0.c |  87 +++
 gcc/testsuite/gcc.dg/lto/pr113359-2_1.c |  38 +
 gcc/testsuite/gcc.dg/lto/pr113359-3_0.c | 114 +++
 gcc/testsuite/gcc.dg/lto/pr113359-3_1.c |  49 +++
 gcc/testsuite/gcc.dg/lto/pr113359-4_0.c | 114 +++
 gcc/testsuite/gcc.dg/lto/pr113359-4_1.c |  49 +++
 gcc/testsuite/gcc.dg/lto/pr113359-5_0.c | 118 +++
 gcc/testsuite/gcc.dg/lto/pr113359-5_1.c |  50 +++
 gcc/tree-sra.cc | 252 +---
 gcc/tree-sra.h  |   3 +
 14 files changed, 999 insertions(+), 55 deletions(-)

diff --git a/gcc/ipa-icf-gimple.cc b/gcc/ipa-icf-gimple.cc
index f4180c0fa813..49302ad56c65 100644
--- a/gcc/ipa-icf-gimple.cc
+++ b/gcc/ipa-icf-gimple.cc
@@ -39,6 +39,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "cfgloop.h"
 #include "attribs.h"
 #include "gimple-walk.h"
+#include "tree-sra.h"
 
 #include "tree-ssa-alias-compare.h"
 #include "ipa-icf-gimple.h"
@@ -59,7 +60,8 @@ func_checker::func_checker (tree source_func_decl, tree 
target_func_decl,
   : m_source_func_decl (source_func_decl), m_target_func_decl 
(target_func_decl),
 m_ignored_source_nodes (ignored_source_nodes),
 m_ignored_target_nodes (ignored_target_nodes),
-m_ignore_labels (ignore_labels), m_tbaa (tbaa)
+m_ignore_labels (ignore_labels), m_tbaa (tbaa),
+m_total_scalarization_limit_known_p (false)
 {
   function *source_func = DECL_STRUCT_FUNCTION (source_func_decl);
   function *target_func = DECL_STRUCT_FUNCTION (target_func_de

[gcc r15-483] [debug] Fix dwarf v4 .debug_macro.dwo

2024-05-14 Thread Tom de Vries via Gcc-cvs
https://gcc.gnu.org/g:b7003b4cc5e263343f047fe64ed1ae12f561b2d1

commit r15-483-gb7003b4cc5e263343f047fe64ed1ae12f561b2d1
Author: Tom de Vries 
Date:   Mon May 13 18:10:15 2024 +0200

[debug] Fix dwarf v4 .debug_macro.dwo

Consider a hello world, compiled with -gsplit-dwarf and dwarf version 4, and
-g3:
...
$ gcc -gdwarf-4 -gsplit-dwarf /data/vries/hello.c -g3 -save-temps -dA
...

In section .debug_macro.dwo, we have:
...
.Ldebug_macro0:
.value  0x4 # DWARF macro version number
.byte   0x2 # Flags: 32-bit, lineptr present
.long   .Lskeleton_debug_line0
.byte   0x3 # Start new file
.uleb128 0  # Included from line number 0
.uleb128 0x1# file /data/vries/hello.c
.byte   0x5 # Define macro strp
.uleb128 0  # At line number 0
.uleb128 0x1d0  # The macro: "__STDC__ 1"
...

Given that we use a DW_MACRO_define_strp, we'd expect 0x1d0 to be an
offset into a .debug_str.dwo section.

But in fact, 0x1d0 is an index into the string offset table in
section .debug_str_offsets.dwo:
...
.long   0x34f0  # indexed string 0x1d0: __STDC__ 1
...

Add asserts that catch this inconsistency, and fix this by using
DW_MACRO_define_strx instead.

Tested on x86_64.

gcc/ChangeLog:

2024-05-14  Tom de Vries  

PR debug/115066
* dwarf2out.cc (output_macinfo_op): Fix DW_MACRO_define_strx/strp
choice for v4 .debug_macro.dwo.  Add asserts to check that choice.

gcc/testsuite/ChangeLog:

2024-05-14  Tom de Vries  

PR debug/115066
* gcc.dg/pr115066.c: New test.

Diff:
---
 gcc/dwarf2out.cc| 20 ++--
 gcc/testsuite/gcc.dg/pr115066.c |  8 
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index eedb13bb069f..70b7f5f42cd7 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -29045,7 +29045,7 @@ output_macinfo_op (macinfo_entry *ref)
  && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
  && (debug_str_section->common.flags & SECTION_MERGE) != 0)
{
- if (dwarf_split_debug_info && dwarf_version >= 5)
+ if (dwarf_split_debug_info)
ref->code = ref->code == DW_MACINFO_define
? DW_MACRO_define_strx : DW_MACRO_undef_strx;
  else
@@ -29097,12 +29097,20 @@ output_macinfo_op (macinfo_entry *ref)
   HOST_WIDE_INT_PRINT_UNSIGNED,
   ref->lineno);
   if (node->form == DW_FORM_strp)
-dw2_asm_output_offset (dwarf_offset_size, node->label,
-   debug_str_section, "The macro: \"%s\"",
-   ref->info);
+   {
+ gcc_assert (ref->code == DW_MACRO_define_strp
+ || ref->code == DW_MACRO_undef_strp);
+ dw2_asm_output_offset (dwarf_offset_size, node->label,
+debug_str_section, "The macro: \"%s\"",
+ref->info);
+   }
   else
-dw2_asm_output_data_uleb128 (node->index, "The macro: \"%s\"",
- ref->info);
+   {
+ gcc_assert (ref->code == DW_MACRO_define_strx
+ || ref->code == DW_MACRO_undef_strx);
+ dw2_asm_output_data_uleb128 (node->index, "The macro: \"%s\"",
+  ref->info);
+   }
   break;
 case DW_MACRO_import:
   dw2_asm_output_data (1, ref->code, "Import");
diff --git a/gcc/testsuite/gcc.dg/pr115066.c b/gcc/testsuite/gcc.dg/pr115066.c
new file mode 100644
index ..645757df2092
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr115066.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-skip-if "split DWARF unsupported" { hppa*-*-hpux* powerpc*-ibm-aix* 
*-*-darwin* } } */
+/* { dg-options "-gsplit-dwarf -g3 -dA -gdwarf-4" } */
+/* { dg-final { scan-assembler-times {\.section\t"?\.debug_macro} 1 } } */
+/* { dg-final { scan-assembler-not {\.byte\t0x5\t# Define macro strp} } } */
+/* { dg-final { scan-assembler {\.byte\t0xb\t# Define macro strx} } } */
+
+#define foo 1


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] RISC-V: Fix typos in code or comment [NFC]

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:11c50b62894f2f9487063b1b2906bb0c8981fa5d

commit 11c50b62894f2f9487063b1b2906bb0c8981fa5d
Author: Kito Cheng 
Date:   Tue May 7 10:18:58 2024 +0800

RISC-V: Fix typos in code or comment [NFC]

Just found some typo when fixing bugs and then use aspell to find few
more typos, this patch didn't do anything other than fix typo.

gcc/ChangeLog:

* config/riscv/riscv-vsetvl.cc: Fix typos in comments.
(get_all_predecessors): Ditto.
(pre_vsetvl::m_unknow_info): Rename to...
(pre_vsetvl::m_unknown_info): this.
(pre_vsetvl::compute_vsetvl_def_data): Rename m_unknow_info to
m_unknown_info.
(pre_vsetvl::cleaup): Rename to...
(pre_vsetvl::cleanup): this.
(pre_vsetvl::compute_vsetvl_def_data): Fix typos.
(pass_vsetvl::lazy_vsetvl): Update function name and fix typos.
* config/riscv/riscv.cc: Fix typos in comments.
(struct machine_function): Fix typo in comments.
(riscv_valid_lo_sum_p): Ditto.
(riscv_force_address): Ditto.
(riscv_immediate_operand_p): Ditto.
(riscv_in_small_data_p): Ditto.
(riscv_first_stack_step): Ditto.
(riscv_expand_prologue): Ditto.
(riscv_convert_vector_chunks): Ditto.
(riscv_override_options_internal): Ditto.
(get_common_costs): Ditto.

(cherry picked from commit d83070aebdb810e38f12d008e7a10acf1063f456)

Diff:
---
 gcc/config/riscv/riscv-vsetvl.cc | 64 
 gcc/config/riscv/riscv.cc| 36 +++---
 2 files changed, 50 insertions(+), 50 deletions(-)

diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc
index 48ce757a6ee5..bbea2b5fd4f3 100644
--- a/gcc/config/riscv/riscv-vsetvl.cc
+++ b/gcc/config/riscv/riscv-vsetvl.cc
@@ -95,7 +95,7 @@ using namespace riscv_vector;
It's a bit different from bitmap_union_of_preds in cfganal.cc. This function
takes into account the case where pred is ENTRY basic block. The main reason
for this difference is to make it easier to insert some special value into
-   the ENTRY base block. For example, vsetvl_info with a status of UNKNOW.  */
+   the ENTRY base block. For example, vsetvl_info with a status of UNKNOWN.  */
 static void
 bitmap_union_of_preds_with_entry (sbitmap dst, sbitmap *src, basic_block b)
 {
@@ -126,9 +126,9 @@ bitmap_union_of_preds_with_entry (sbitmap dst, sbitmap 
*src, basic_block b)
   }
 }
 
-/* Compute the reaching defintion in and out based on the gen and KILL
-   informations in each Base Blocks.
-   This function references the compute_avaiable implementation in lcm.cc  */
+/* Compute the reaching definition in and out based on the gen and KILL
+   information's in each Base Blocks.
+   This function references the compute_available implementation in lcm.cc  */
 static void
 compute_reaching_defintion (sbitmap *gen, sbitmap *kill, sbitmap *in,
sbitmap *out)
@@ -719,7 +719,7 @@ get_all_predecessors (basic_block bb)
require SEW and LMUL to be fixed.
Therefore, if the former RVV instruction needs DEMAND_RATIO_P and the latter
instruction needs DEMAND_SEW_LMUL_P and its SEW/LMUL is the same as that of
-   the former instruction, then we can make the minimu demand of the former
+   the former instruction, then we can make the minimum demand of the former
instruction strict to DEMAND_SEW_LMUL_P, and its required SEW and LMUL are
the SEW and LMUL of the latter instruction, and the vsetvl instruction
generated according to the new demand can also be used for the latter
@@ -741,7 +741,7 @@ enum demand_flags : unsigned
 /* We split the demand information into three parts. They are sew and lmul
related (sew_lmul_demand_type), tail and mask policy related
(policy_demand_type) and avl related (avl_demand_type). Then we define three
-   interfaces avaiable_with, compatible_p and merge. avaiable_with is
+   interfaces available_p, compatible_p and merge. available_p is
used to determine whether the two vsetvl infos prev_info and next_info are
available or not. If prev_info is available for next_info, it means that the
RVV insn corresponding to next_info on the path from prev_info to next_info
@@ -1361,17 +1361,17 @@ public:
 
 /* Demand system is the RVV-based VSETVL info analysis tools wrapper.
It defines compatible rules for SEW/LMUL, POLICY and AVL.
-   Also, it provides 3 iterfaces avaiable_p, compatible_p and
+   Also, it provides 3 interfaces available_p, compatible_p and
merge for the VSETVL PASS analysis and optimization.
 
- - avaiable_p: Determine whether the next info can get the
-   avaiable VSETVL status from previous info.
+ - available_p: Determine whether the next info can get the
+   available VSETVL status from previous info.
e.g. bb 

[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [RISC-V] Use shNadd for constant synthesis

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:28db6a196e3251908df676d7c5e9626d29d37e5e

commit 28db6a196e3251908df676d7c5e9626d29d37e5e
Author: Jeff Law 
Date:   Fri May 10 13:49:44 2024 -0600

[RISC-V] Use shNadd for constant synthesis

So here's the next idiom to improve constant synthesis.

The basic idea here is to try and use shNadd to generate the constant when 
profitable.

Let's take 0x30801.  Right now that generates:

li  a0,3145728
addia0,a0,1
sllia0,a0,12
addia0,a0,-2047

But we can do better.  The constant is evenly divisible by 9 resulting in
0x5639 which doesn't look terribly interesting.  But that constant can 
be
generated with two instructions, then we can use a sh3add to multiply it by 
9.
So the updated sequence looks like:

li  a0,1431654400
addia0,a0,1593
sh3add  a0,a0,a0

This doesn't trigger a whole lot, but I haven't really set up a test to 
explore
the most likely space where this might be useful.  The tests were found
exploring a different class of constant synthesis problems.

If you were to dive into the before/after you'd see that the shNadd 
interacts
quite nicely with the recent bseti work.   The joys of recursion.

Probably the most controversial thing in here is using the "FMA" opcode to
stand in for when we want to use shNadd.  Essentially when we synthesize a
constant we generate a series of RTL opcodes and constants for emission by
another routine.   We don't really have a way to say we want a shift-add.  
But
you can think of shift-add as a limited form of multiply-accumulate.  It's a
bit of a stretch, but not crazy bad IMHO.

Other approaches would be to store our own enum rather than an RTL opcode.  
Or
store an actual generator function rather than any kind of opcode.

It wouldn't take much pushback over (ab)using FMA in this manner to get me 
to
use our own enums rather than RTL opcodes for this stuff.

gcc/

* config/riscv/riscv.cc (riscv_build_integer_1): Recognize cases 
where
we can use shNadd to improve constant synthesis.
(riscv_move_integer): Handle code generation for shNadd.

gcc/testsuite
* gcc.target/riscv/synthesis-1.c: Also count shNadd instructions.
* gcc.target/riscv/synthesis-3.c: New test.

(cherry picked from commit dbbd059b49edc936769737204f5c270d8d6ff553)

Diff:
---
 gcc/config/riscv/riscv.cc| 42 +++
 gcc/testsuite/gcc.target/riscv/synthesis-1.c |  2 +-
 gcc/testsuite/gcc.target/riscv/synthesis-3.c | 81 
 3 files changed, 124 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 2860137af718..9c98b1da0357 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -880,6 +880,40 @@ riscv_build_integer_1 (struct riscv_integer_op 
codes[RISCV_MAX_INTEGER_OPS],
}
 }
 
+  if (cost > 2 && TARGET_64BIT && TARGET_ZBA)
+{
+  if ((value % 9) == 0
+ && (alt_cost
+ = riscv_build_integer_1 (alt_codes, value / 9, mode) + 1) < cost)
+   {
+  alt_codes[alt_cost - 1].code = FMA;
+  alt_codes[alt_cost - 1].value = 9;
+  alt_codes[alt_cost - 1].use_uw = false;
+  memcpy (codes, alt_codes, sizeof (alt_codes));
+  cost = alt_cost;
+   }
+  if ((value % 5) == 0
+ && (alt_cost
+ = riscv_build_integer_1 (alt_codes, value / 5, mode) + 1) < cost)
+   {
+  alt_codes[alt_cost - 1].code = FMA;
+  alt_codes[alt_cost - 1].value = 5;
+  alt_codes[alt_cost - 1].use_uw = false;
+  memcpy (codes, alt_codes, sizeof (alt_codes));
+  cost = alt_cost;
+   }
+  if ((value % 3) == 0
+ && (alt_cost
+ = riscv_build_integer_1 (alt_codes, value / 3, mode) + 1) < cost)
+   {
+  alt_codes[alt_cost - 1].code = FMA;
+  alt_codes[alt_cost - 1].value = 3;
+  alt_codes[alt_cost - 1].use_uw = false;
+  memcpy (codes, alt_codes, sizeof (alt_codes));
+  cost = alt_cost;
+   }
+}
+
   /* Final cases, particularly focused on bseti.  */
   if (cost > 2 && TARGET_ZBS)
 {
@@ -2542,6 +2576,14 @@ riscv_move_integer (rtx temp, rtx dest, HOST_WIDE_INT 
value,
  x = gen_rtx_fmt_ee (AND, mode, x, GEN_INT (value));
  x = riscv_emit_set (t, x);
}
+ else if (codes[i].code == FMA)
+   {
+ HOST_WIDE_INT value = exact_log2 (codes[i].value - 1);
+ rtx ashift = gen_rtx_fmt_ee (ASHIFT, mode, x, GEN_INT (value));
+ x = gen_rtx_fmt_ee (PLUS, mode, ashift, x);
+ rtx t = can_create_pseudo_p () ? gen_reg_rtx (mode) : temp;
+ x = riscv_emit_set (t,

[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [to-be-committed, RISC-V] Improve usage of slli.uw in constant synthesis

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:71edaf678fae607d7c8ce28ace9a321af711799b

commit 71edaf678fae607d7c8ce28ace9a321af711799b
Author: Jeff Law 
Date:   Sun May 12 07:12:04 2024 -0600

[to-be-committed,RISC-V] Improve usage of slli.uw in constant synthesis

And an improvement to using slli.uw...

I recently added the ability to use slli.uw in the synthesis path.  That
code was conditional on the right justified constant being a LUI_OPERAND
after sign extending from bit 31 to bit 63.

That code is working fine, but could be improved.  Specifically there's
no reason it shouldn't work for LUI+ADDI under the same circumstances.
So rather than testing the sign extended, right justified constant is a
LUI_OPERAND, we can just test that the right justified constant has
precisely 32 leading zeros.

gcc/
* config/riscv/riscv.cc (riscv_build_integer_1): Use slli.uw more.

gcc/testsuite
* gcc.target/riscv/synthesis-5.c: New test.

(cherry picked from commit 83fb5e6f382ea99ca0e2a0afeb25a9f78909f25f)

Diff:
---
 gcc/config/riscv/riscv.cc|   9 +-
 gcc/testsuite/gcc.target/riscv/synthesis-5.c | 294 +++
 2 files changed, 299 insertions(+), 4 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 049f8f8cb9fc..a1e5a014bedf 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -819,13 +819,14 @@ riscv_build_integer_1 (struct riscv_integer_op 
codes[RISCV_MAX_INTEGER_OPS],
  & ~HOST_WIDE_INT_C (0x8000)
shift -= IMM_BITS, x <<= IMM_BITS;
 
-  /* Adjust X if it isn't a LUI operand in isolation, but we can use
-a subsequent "uw" instruction form to mask off the undesirable
-bits.  */
+  /* If X has bits 32..63 clear and bit 31 set, then go ahead and mark
+it as desiring a "uw" operation for the shift.  That way we can have
+LUI+ADDI to generate the constant, then shift it into position
+clearing out the undesirable bits.  */
   if (!LUI_OPERAND (x)
  && TARGET_64BIT
  && TARGET_ZBA
- && LUI_OPERAND (x & ~HOST_WIDE_INT_C (0x8000UL)))
+ && clz_hwi (x) == 32)
{
  x = sext_hwi (x, 32);
  use_uw = true;
diff --git a/gcc/testsuite/gcc.target/riscv/synthesis-5.c 
b/gcc/testsuite/gcc.target/riscv/synthesis-5.c
new file mode 100644
index ..4d81565b563b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/synthesis-5.c
@@ -0,0 +1,294 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target rv64 } */
+
+/* We aggressively skip as we really just need to test the basic synthesis
+   which shouldn't vary based on the optimization level.  -O1 seems to work
+   and eliminates the usual sources of extraneous dead code that would throw
+   off the counts.  */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-O2" "-O3" "-Os" "-Oz" "-flto" } } 
*/
+/* { dg-options "-march=rv64gc_zba_zbb_zbs" } */
+
+/* Rather than test for a specific synthesis of all these constants or
+   having thousands of tests each testing one variant, we just test the
+   total number of instructions.
+
+   This isn't expected to change much and any change is worthy of a look.  */
+/* { dg-final { scan-assembler-times 
"\\t(add|addi|bseti|li|ret|sh1add|sh2add|sh3add|slli)" 556 } } */
+
+unsigned long foo_0x80180001000(void) { return 0x80180001000UL; }
+
+unsigned long foo_0x80280001000(void) { return 0x80280001000UL; }
+
+unsigned long foo_0x80480001000(void) { return 0x80480001000UL; }
+
+unsigned long foo_0x80880001000(void) { return 0x80880001000UL; }
+
+unsigned long foo_0x81080001000(void) { return 0x81080001000UL; }
+
+unsigned long foo_0x82080001000(void) { return 0x82080001000UL; }
+
+unsigned long foo_0x84080001000(void) { return 0x84080001000UL; }
+
+unsigned long foo_0x88080001000(void) { return 0x88080001000UL; }
+
+unsigned long foo_0x90080001000(void) { return 0x90080001000UL; }
+
+unsigned long foo_0xa0080001000(void) { return 0xa0080001000UL; }
+
+unsigned long foo_0x8031000(void) { return 0x8031000UL; }
+
+unsigned long foo_0x8051000(void) { return 0x8051000UL; }
+
+unsigned long foo_0x8091000(void) { return 0x8091000UL; }
+
+unsigned long foo_0x8111000(void) { return 0x8111000UL; }
+
+unsigned long foo_0x8211000(void) { return 0x8211000UL; }
+
+unsigned long foo_0x8411000(void) { return 0x8411000UL; }
+
+unsigned long foo_0x8811000(void) { return 0x8811000UL; }
+
+unsigned long foo_0x9011000(void) { return 0x9011000UL; }
+
+unsigned long foo_0xa011000(void) { return 0xa011000UL; }
+
+unsigned long foo_0xc011000(void) { return 0xc011000UL; }
+
+unsigned long foo_0x8061000(void) { return 0x8061000UL; }
+
+unsigned long foo_0x80a1000(void) { return 0x80a1000UL; }
+
+unsigned long foo_0x8121000(void) { return 0x812

[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [to-be-committed, RISC-V] Improve single inverted bit extraction - v3

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:8be088a0f395047189e139d4c791cfc2275898b9

commit 8be088a0f395047189e139d4c791cfc2275898b9
Author: Jeff Law 
Date:   Mon May 13 07:14:08 2024 -0600

[to-be-committed,RISC-V] Improve single inverted bit extraction - v3

So this patch fixes a minor code generation inefficiency that (IIRC) the
RAU team discovered a while ago in spec.

If we want the inverted value of a single bit we can use bext to extract
the bit, then seq to invert the value (if viewed as a 0/1 truth value).

The RTL is fairly convoluted, but it's basically a right shift to get
the bit into position, bitwise-not then masking off all but the low bit.
So it's a 3->2 combine, hidden by the fact that and-not is a
define_insn_and_split, so it actually looks like a 2->2 combine.

We've run this through Ventana's internal CI (which includes
zba_zbb_zbs) and I've run it in my own tester (rv64gc, rv32gcv).  I'll
wait for the upstream CI to finish with positive results before pushing.

gcc/
* config/riscv/bitmanip.md (bextseqzdisi): New patterns.

gcc/testsuite/

* gcc.target/riscv/zbs-bext-2.c: New test.
* gcc.target/riscv/zbs-bext.c: Fix one of the possible expectes 
sequences.

(cherry picked from commit 0c585c8d0dd85601a8d116ada99126a48c8ce9fd)

Diff:
---
 gcc/config/riscv/.riscv.cc.swo  | Bin 0 -> 417792 bytes
 gcc/config/riscv/bitmanip.md|  43 
 gcc/config/riscv/j  |   0
 gcc/testsuite/gcc.target/riscv/zbs-bext-2.c |  19 
 gcc/testsuite/gcc.target/riscv/zbs-bext.c   |   2 +-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/.riscv.cc.swo b/gcc/config/riscv/.riscv.cc.swo
new file mode 100644
index ..77ed37353bee
Binary files /dev/null and b/gcc/config/riscv/.riscv.cc.swo differ
diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
index d76a72d30e02..724511b6df3b 100644
--- a/gcc/config/riscv/bitmanip.md
+++ b/gcc/config/riscv/bitmanip.md
@@ -711,6 +711,49 @@
   "bext\t%0,%1,%2"
   [(set_attr "type" "bitmanip")])
 
+;; This is a bext followed by a seqz.  Normally this would be a 3->2 split
+;; But the and-not pattern with a constant operand is a define_insn_and_split,
+;; so this looks like a 2->2 split, which combine rejects.  So implement it
+;; as a define_insn_and_split as well.
+(define_insn_and_split "*bextseqzdisi"
+  [(set (match_operand:DI 0 "register_operand" "=r")
+   (and:DI
+ (not:DI
+   (subreg:DI
+ (lshiftrt:SI
+   (match_operand:SI 1 "register_operand" "r")
+   (match_operand:QI 2 "register_operand" "r")) 0))
+ (const_int 1)))]
+  "TARGET_64BIT && TARGET_ZBS"
+  "#"
+  "&& 1"
+  [(set (match_dup 0)
+   (zero_extract:DI (match_dup 1)
+(const_int 1)
+(zero_extend:DI (match_dup 2
+   (set (match_dup 0) (eq:DI (match_dup 0) (const_int 0)))]
+  "operands[1] = gen_lowpart (word_mode, operands[1]);"
+  [(set_attr "type" "bitmanip")])
+
+(define_insn_and_split "*bextseqzdisi"
+  [(set (match_operand:X 0 "register_operand" "=r")
+   (and:X
+ (not:X
+   (lshiftrt:X
+ (match_operand:X 1 "register_operand" "r")
+ (match_operand:QI 2 "register_operand" "r")))
+ (const_int 1)))]
+  "TARGET_ZBS"
+  "#"
+  "&& 1"
+  [(set (match_dup 0)
+   (zero_extract:X (match_dup 1)
+   (const_int 1)
+   (zero_extend:X (match_dup 2
+   (set (match_dup 0) (eq:X (match_dup 0) (const_int 0)))]
+  "operands[1] = gen_lowpart (word_mode, operands[1]);"
+  [(set_attr "type" "bitmanip")])
+
 ;; When performing `(a & (1UL << bitno)) ? 0 : -1` the combiner
 ;; usually has the `bitno` typed as X-mode (i.e. no further
 ;; zero-extension is performed around the bitno).
diff --git a/gcc/config/riscv/j b/gcc/config/riscv/j
new file mode 100644
index ..e69de29bb2d1
diff --git a/gcc/testsuite/gcc.target/riscv/zbs-bext-2.c 
b/gcc/testsuite/gcc.target/riscv/zbs-bext-2.c
new file mode 100644
index ..79f120b22863
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zbs-bext-2.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zbs -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
+
+
+_Bool match(const int ch, int fMap) {
+return ((fMap & (1<<(ch))) == 0);
+}
+
+_Bool match2(const int ch, int fMap) {
+return ((fMap & (1UL<<(ch))) == 0);
+}
+
+
+/* { dg-final { scan-assembler-times "bext\t" 2 } } */
+/* { dg-final { scan-assembler-times "seqz\t|xori\t" 2 } } */
+/* { dg-final { scan-assembler-not "sraw\t" } } */
+/* { dg-final { scan-assembler-not "not\t" } } */
+/* { dg-final { scan-assembler-not "andi\t" } } */
diff --git a/gcc/testsuite/gcc.target/riscv/zbs-bext.c 
b/gcc/testsuite/gcc.target/ri

[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] RISC-V: Bugfix ICE for RVV intrinisc vfw on _Float16 scalar

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:7d135c53cf480c99b6fa883569e9b8d55ed92ea5

commit 7d135c53cf480c99b6fa883569e9b8d55ed92ea5
Author: Pan Li 
Date:   Sat May 11 15:25:28 2024 +0800

RISC-V: Bugfix ICE for RVV intrinisc vfw on _Float16 scalar

For the vfw vx format RVV intrinsic, the scalar type _Float16 also
requires the zvfh extension.  Unfortunately,  we only check the
vector tree type and miss the scalar _Float16 type checking.  For
example:

vfloat32mf2_t test_vfwsub_wf_f32mf2(vfloat32mf2_t vs2, _Float16 rs1, size_t 
vl)
{
  return __riscv_vfwsub_wf_f32mf2(vs2, rs1, vl);
}

It should report some error message like zvfh extension is required
instead of ICE for unreg insn.

This patch would like to make up such kind of validation for _Float16
in the RVV intrinsic API.  It will report some error like below when
there is no zvfh enabled.

error: built-in function '__riscv_vfwsub_wf_f32mf2(vs2,  rs1,  vl)'
  requires the zvfhmin or zvfh ISA extension

Passed the rv64gcv fully regression tests, included c/c++/fortran.

PR target/114988

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.cc
(validate_instance_type_required_extensions): New func impl to
validate the intrinisc func type ops.
(expand_builtin): Validate instance type before expand.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/pr114988-1.c: New test.
* gcc.target/riscv/rvv/base/pr114988-2.c: New test.

Signed-off-by: Pan Li 
(cherry picked from commit 41b3cf262e61aee9d26380f1c820e0eaae740f50)

Diff:
---
 gcc/config/riscv/riscv-vector-builtins.cc  | 51 ++
 .../gcc.target/riscv/rvv/base/pr114988-1.c |  9 
 .../gcc.target/riscv/rvv/base/pr114988-2.c |  9 
 3 files changed, 69 insertions(+)

diff --git a/gcc/config/riscv/riscv-vector-builtins.cc 
b/gcc/config/riscv/riscv-vector-builtins.cc
index 192a6c230d1c..3fdb4400d70d 100644
--- a/gcc/config/riscv/riscv-vector-builtins.cc
+++ b/gcc/config/riscv/riscv-vector-builtins.cc
@@ -4632,6 +4632,54 @@ gimple_fold_builtin (unsigned int code, 
gimple_stmt_iterator *gsi, gcall *stmt)
   return gimple_folder (rfn.instance, rfn.decl, gsi, stmt).fold ();
 }
 
+static bool
+validate_instance_type_required_extensions (const rvv_type_info type,
+   tree exp)
+{
+  uint64_t exts = type.required_extensions;
+
+  if ((exts & RVV_REQUIRE_ELEN_FP_16) &&
+!TARGET_VECTOR_ELEN_FP_16_P (riscv_vector_elen_flags))
+{
+  error_at (EXPR_LOCATION (exp),
+   "built-in function %qE requires the "
+   "zvfhmin or zvfh ISA extension",
+   exp);
+  return false;
+}
+
+  if ((exts & RVV_REQUIRE_ELEN_FP_32) &&
+!TARGET_VECTOR_ELEN_FP_32_P (riscv_vector_elen_flags))
+{
+  error_at (EXPR_LOCATION (exp),
+   "built-in function %qE requires the "
+   "zve32f, zve64f, zve64d or v ISA extension",
+   exp);
+  return false;
+}
+
+  if ((exts & RVV_REQUIRE_ELEN_FP_64) &&
+!TARGET_VECTOR_ELEN_FP_64_P (riscv_vector_elen_flags))
+{
+  error_at (EXPR_LOCATION (exp),
+   "built-in function %qE requires the zve64d or v ISA extension",
+   exp);
+  return false;
+}
+
+  if ((exts & RVV_REQUIRE_ELEN_64) &&
+!TARGET_VECTOR_ELEN_64_P (riscv_vector_elen_flags))
+{
+  error_at (EXPR_LOCATION (exp),
+   "built-in function %qE requires the "
+   "zve64x, zve64f, zve64d or v ISA extension",
+   exp);
+  return false;
+}
+
+  return true;
+}
+
 /* Expand a call to the RVV function with subcode CODE.  EXP is the call
expression and TARGET is the preferred location for the result.
Return the value of the lhs.  */
@@ -4649,6 +4697,9 @@ expand_builtin (unsigned int code, tree exp, rtx target)
   return target;
 }
 
+  if (!validate_instance_type_required_extensions (rfn.instance.type, exp))
+return target;
+
   return function_expander (rfn.instance, rfn.decl, exp, target).expand ();
 }
 
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr114988-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/pr114988-1.c
new file mode 100644
index ..b8474804c880
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr114988-1.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O3" } */
+
+#include "riscv_vector.h"
+
+vfloat32mf2_t test_vfwsub_wf_f32mf2(vfloat32mf2_t vs2, _Float16 rs1, size_t vl)
+{
+  return __riscv_vfwsub_wf_f32mf2(vs2, rs1, vl); /* { dg-error {built-in 
function '__riscv_vfwsub_wf_f32mf2\(vs2,  rs1,  vl\)' requires the zvfhmin or 
zvfh ISA extension} } */
+}
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr114988-2.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/pr114988-2.

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

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:c6ed1bc38b17d650ae678b7cac28ce8c2692eb09

commit c6ed1bc38b17d650ae678b7cac28ce8c2692eb09
Author: Jeff Law 
Date:   Mon May 13 17:37:46 2024 -0600

[to-be-committed,RISC-V] Improve AND with some constants

If we have an AND with a constant operand and the constant operand
requires synthesis, then we may be able to generate more efficient code
than we do now.

Essentially the need for constant synthesis gives us a budget for
alternative ways to clear bits, which zext.w can do for bits 32..63
trivially.   So if we clear 32..63  via zext.w, the constant for the
remaining bits to clear may be simple enough to use with andi or bseti.
That will save us an instruction.

This has tested in Ventana's CI system as well as my own.  I'll wait for
the upstream CI tester to report success before committing.

Jeff
gcc/
* config/riscv/bitmanip.md: Add new splitter for AND with
a constant that masks off bits 32..63 and needs synthesis.

gcc/testsuite/

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

(cherry picked from commit 158aa1b65ce29d5e58182782de66292c51774d71)

Diff:
---
 gcc/config/riscv/bitmanip.md   | 34 ++
 gcc/testsuite/gcc.target/riscv/zba_zbs_and-1.c | 22 +
 2 files changed, 56 insertions(+)

diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
index 724511b6df3b..8769a6b818b7 100644
--- a/gcc/config/riscv/bitmanip.md
+++ b/gcc/config/riscv/bitmanip.md
@@ -843,6 +843,40 @@
 }
 [(set_attr "type" "bitmanip")])
 
+;; If we have the ZBA extension, then we can clear the upper half of a 64
+;; bit object with a zext.w.  So if we have AND where the constant would
+;; require synthesis of two or more instructions, but 32->64 sign extension
+;; of the constant is a simm12, then we can use zext.w+andi.  If the adjusted
+;; constant is a single bit constant, then we can use zext.w+bclri
+;;
+;; With the mvconst_internal pattern claiming a single insn to synthesize
+;; constants, this must be a define_insn_and_split.
+(define_insn_and_split ""
+  [(set (match_operand:DI 0 "register_operand" "=r")
+   (and:DI (match_operand:DI 1 "register_operand" "r")
+   (match_operand 2 "const_int_operand" "n")))]
+  "TARGET_64BIT
+   && TARGET_ZBA
+   && !paradoxical_subreg_p (operands[1])
+   /* Only profitable if synthesis takes more than one insn.  */
+   && riscv_const_insns (operands[2]) != 1
+   /* We need the upper half to be zero.  */
+   && (INTVAL (operands[2]) & HOST_WIDE_INT_C (0x)) == 0
+   /* And the the adjusted constant must either be something we can
+  implement with andi or bclri.  */
+   && ((SMALL_OPERAND (sext_hwi (INTVAL (operands[2]), 32))
+|| (TARGET_ZBS && popcount_hwi (INTVAL (operands[2])) == 31))
+   && INTVAL (operands[2]) != 0x7fff)"
+  "#"
+  "&& 1"
+  [(set (match_dup 0) (zero_extend:DI (match_dup 3)))
+   (set (match_dup 0) (and:DI (match_dup 0) (match_dup 2)))]
+  "{
+ operands[3] = gen_lowpart (SImode, operands[1]);
+ operands[2] = GEN_INT (sext_hwi (INTVAL (operands[2]), 32));
+   }"
+  [(set_attr "type" "bitmanip")])
+
 ;; IF_THEN_ELSE: test for 2 bits of opposite polarity
 (define_insn_and_split "*branch_mask_twobits_equals_singlebit"
   [(set (pc)
diff --git a/gcc/testsuite/gcc.target/riscv/zba_zbs_and-1.c 
b/gcc/testsuite/gcc.target/riscv/zba_zbs_and-1.c
new file mode 100644
index ..23fd769449ea
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zba_zbs_and-1.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zba_zbb_zbs -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
+
+
+unsigned long long w32mem_1(unsigned long long w32)
+{
+return w32 & ~(1U << 0);
+}
+
+unsigned long long w32mem_2(unsigned long long w32)
+{
+return w32 & ~(1U << 30);
+}
+
+unsigned long long w32mem_3(unsigned long long w32)
+{
+return w32 & ~(1U << 31);
+}
+
+/* If we do synthesis, then we'd see an addi.  */
+/* { dg-final { scan-assembler-not "addi\t" } } */


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] RISC-V: Fix format issue for trailing operator [NFC]

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:0c1a07d6e5b30aad71798aa7c37fc80bd19b7f63

commit 0c1a07d6e5b30aad71798aa7c37fc80bd19b7f63
Author: Pan Li 
Date:   Tue May 14 09:38:55 2024 +0800

RISC-V: Fix format issue for trailing operator [NFC]

This patch would like to fix below format issue of trailing operator.

=== ERROR type #1: trailing operator (4 error(s)) ===
gcc/config/riscv/riscv-vector-builtins.cc:4641:39:  if ((exts &
RVV_REQUIRE_ELEN_FP_16) &&
gcc/config/riscv/riscv-vector-builtins.cc:4651:39:  if ((exts &
RVV_REQUIRE_ELEN_FP_32) &&
gcc/config/riscv/riscv-vector-builtins.cc:4661:39:  if ((exts &
RVV_REQUIRE_ELEN_FP_64) &&
gcc/config/riscv/riscv-vector-builtins.cc:4670:36:  if ((exts &
RVV_REQUIRE_ELEN_64) &&

Passed the ./contrib/check_GNU_style.sh for this patch,  and double
checked there is no other format issue of the original patch.

Committed as format change.

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.cc
(validate_instance_type_required_extensions): Remove the
operator from the trailing and put it to new line.

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

Diff:
---
 gcc/config/riscv/riscv-vector-builtins.cc | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/gcc/config/riscv/riscv-vector-builtins.cc 
b/gcc/config/riscv/riscv-vector-builtins.cc
index 3fdb4400d70d..c08d87a26807 100644
--- a/gcc/config/riscv/riscv-vector-builtins.cc
+++ b/gcc/config/riscv/riscv-vector-builtins.cc
@@ -4638,8 +4638,8 @@ validate_instance_type_required_extensions (const 
rvv_type_info type,
 {
   uint64_t exts = type.required_extensions;
 
-  if ((exts & RVV_REQUIRE_ELEN_FP_16) &&
-!TARGET_VECTOR_ELEN_FP_16_P (riscv_vector_elen_flags))
+  if ((exts & RVV_REQUIRE_ELEN_FP_16)
+&& !TARGET_VECTOR_ELEN_FP_16_P (riscv_vector_elen_flags))
 {
   error_at (EXPR_LOCATION (exp),
"built-in function %qE requires the "
@@ -4648,8 +4648,8 @@ validate_instance_type_required_extensions (const 
rvv_type_info type,
   return false;
 }
 
-  if ((exts & RVV_REQUIRE_ELEN_FP_32) &&
-!TARGET_VECTOR_ELEN_FP_32_P (riscv_vector_elen_flags))
+  if ((exts & RVV_REQUIRE_ELEN_FP_32)
+&& !TARGET_VECTOR_ELEN_FP_32_P (riscv_vector_elen_flags))
 {
   error_at (EXPR_LOCATION (exp),
"built-in function %qE requires the "
@@ -4658,8 +4658,8 @@ validate_instance_type_required_extensions (const 
rvv_type_info type,
   return false;
 }
 
-  if ((exts & RVV_REQUIRE_ELEN_FP_64) &&
-!TARGET_VECTOR_ELEN_FP_64_P (riscv_vector_elen_flags))
+  if ((exts & RVV_REQUIRE_ELEN_FP_64)
+&& !TARGET_VECTOR_ELEN_FP_64_P (riscv_vector_elen_flags))
 {
   error_at (EXPR_LOCATION (exp),
"built-in function %qE requires the zve64d or v ISA extension",
@@ -4667,8 +4667,8 @@ validate_instance_type_required_extensions (const 
rvv_type_info type,
   return false;
 }
 
-  if ((exts & RVV_REQUIRE_ELEN_64) &&
-!TARGET_VECTOR_ELEN_64_P (riscv_vector_elen_flags))
+  if ((exts & RVV_REQUIRE_ELEN_64)
+&& !TARGET_VECTOR_ELEN_64_P (riscv_vector_elen_flags))
 {
   error_at (EXPR_LOCATION (exp),
"built-in function %qE requires the "


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [to-be-committed] RISC-V Fix minor regression in synthesis WRT bseti usage

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:a39fd3b589c57f3d2860f73d255902bbdef1a51c

commit a39fd3b589c57f3d2860f73d255902bbdef1a51c
Author: Jeff Law 
Date:   Sun May 12 07:05:43 2024 -0600

[to-be-committed] RISC-V Fix minor regression in synthesis WRT bseti usage

Overnight testing showed a small number of cases where constant synthesis 
was
doing something dumb.  Specifically generating more instructions than the
number of bits set in the constant.

It was a minor goof in the recent bseti code.  In the code to first figure 
out
what bits LUI could set, I included one bit outside the space LUI operates.
For some dumb reason I kept thinking in terms of 11 low bits belonging to 
addi,
but it's actually 12 bits.  The net is what we thought should be a single 
LUI
for costing turned into LUI+ADDI.

I didn't let the test run to completion, but over the course of 12 hours it
found 9 cases.  Given we know that the triggers all have 0x800 set, I bet we
could likely find more, but I doubt it's that critical to cover every 
possible
constant that regressed.

gcc/
* config/riscv/riscv.cc (riscv_build_integer_1): Fix thinko in 
testing
when lui can be used to set several bits in bseti path.

gcc/testsuite

* gcc.target/riscv/synthesis-4.c: New test

(cherry picked from commit 77a28ed91b2a527b9006ee1a220b468756b43eca)

Diff:
---
 gcc/config/riscv/riscv.cc|  6 ++---
 gcc/testsuite/gcc.target/riscv/synthesis-4.c | 34 
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 9c98b1da0357..049f8f8cb9fc 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -921,12 +921,12 @@ riscv_build_integer_1 (struct riscv_integer_op 
codes[RISCV_MAX_INTEGER_OPS],
 
   /* First handle any bits set by LUI.  Be careful of the
 SImode sign bit!.  */
-  if (value & 0x7800)
+  if (value & 0x7000)
{
  alt_codes[i].code = (i == 0 ? UNKNOWN : IOR);
- alt_codes[i].value = value & 0x7800;
+ alt_codes[i].value = value & 0x7000;
  alt_codes[i].use_uw = false;
- value &= ~0x7800;
+ value &= ~0x7000;
   i++;
}
 
diff --git a/gcc/testsuite/gcc.target/riscv/synthesis-4.c 
b/gcc/testsuite/gcc.target/riscv/synthesis-4.c
new file mode 100644
index ..328a55b9e6e5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/synthesis-4.c
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target rv64 } */
+/* We aggressively skip as we really just need to test the basic synthesis
+   which shouldn't vary based on the optimization level.  -O1 seems to work
+   and eliminates the usual sources of extraneous dead code that would throw
+   off the counts.  */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-O2" "-O3" "-Os" "-Oz" "-flto" } } 
*/
+/* { dg-options "-march=rv64gc_zba_zbb_zbs" } */
+
+/* Rather than test for a specific synthesis of all these constants or
+   having thousands of tests each testing one variant, we just test the
+   total number of instructions. 
+
+   This isn't expected to change much and any change is worthy of a look.  */
+/* { dg-final { scan-assembler-times 
"\\t(add|addi|bseti|li|ret|sh1add|sh2add|sh3add|slli)" 45 } } */
+
+
+unsigned long foo_0x640800(void) { return 0x640800UL; }
+
+unsigned long foo_0xc40800(void) { return 0xc40800UL; }
+
+unsigned long foo_0x1840800(void) { return 0x1840800UL; }
+
+unsigned long foo_0x3040800(void) { return 0x3040800UL; }
+
+unsigned long foo_0x6040800(void) { return 0x6040800UL; }
+
+unsigned long foo_0xc040800(void) { return 0xc040800UL; }
+
+unsigned long foo_0x18040800(void) { return 0x18040800UL; }
+
+unsigned long foo_0x30040800(void) { return 0x30040800UL; }
+
+unsigned long foo_0x60040800(void) { return 0x60040800UL; }


[gcc r15-484] libstdc++: Document when std::string::shrink_to_fit was added

2024-05-14 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:0a99ad5c52caa06c113b1889bbe6634812b89be5

commit r15-484-g0a99ad5c52caa06c113b1889bbe6634812b89be5
Author: Jonathan Wakely 
Date:   Tue May 14 14:28:21 2024 +0100

libstdc++: Document when std::string::shrink_to_fit was added

This section can be misread to say that shrink_to_fit is available from
GCC 3.4, but it was added later.

libstdc++-v3/ChangeLog:

* doc/xml/manual/strings.xml: Clarify that GCC 4.5 added
std::string::shrink_to_fit.
* doc/html/manual/strings.html: Regenerate.

Diff:
---
 libstdc++-v3/doc/html/manual/strings.html | 4 ++--
 libstdc++-v3/doc/xml/manual/strings.xml   | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/strings.html 
b/libstdc++-v3/doc/html/manual/strings.html
index ceb09f97eac4..34a34dfa980c 100644
--- a/libstdc++-v3/doc/html/manual/strings.html
+++ b/libstdc++-v3/doc/html/manual/strings.html
@@ -269,8 +269,8 @@ stringtok(Container &container, string const &in,
   (see this FAQ
   entry) but the regular copy constructor cannot be used
   because libstdc++'s string is Copy-On-Write in 
GCC 3.
-   In C++11 mode you can call
-  s.shrink_to_fit() to achieve the same effect as
+   From GCC 4.5 in C++11 mode you
+  can call s.shrink_to_fit() to achieve the same 
effect as
   s.reserve(s.size()).
CString 
(MFC)
 A common lament seen in various newsgroups deals with the Standard
diff --git a/libstdc++-v3/doc/xml/manual/strings.xml 
b/libstdc++-v3/doc/xml/manual/strings.xml
index b0dab645a2d9..4a63dd964771 100644
--- a/libstdc++-v3/doc/xml/manual/strings.xml
+++ b/libstdc++-v3/doc/xml/manual/strings.xml
@@ -356,8 +356,8 @@ stringtok(Container &container, string const &in,
   entry) but the regular copy constructor cannot be used
   because libstdc++'s string is Copy-On-Write in GCC 3.

-   In C++11 mode you can call
-  s.shrink_to_fit() to achieve the same effect as
+   From GCC 4.5 in C++11 mode you
+  can call s.shrink_to_fit() to achieve the same effect as
   s.reserve(s.size()).



[gcc r15-485] libstdc++: Guard dynamic_cast use in src/c++23/print.cc [PR115015]

2024-05-14 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:6cc8698244b522ad079675022c9de9e40de85878

commit r15-485-g6cc8698244b522ad079675022c9de9e40de85878
Author: Jonathan Wakely 
Date:   Tue May 14 14:32:23 2024 +0100

libstdc++: Guard dynamic_cast use in src/c++23/print.cc [PR115015]

Do not use dynamic_cast unconditionally, in case libstdc++ is built with
-fno-rtti.

libstdc++-v3/ChangeLog:

PR libstdc++/115015
* src/c++23/print.cc (__open_terminal(streambuf*)) [!__cpp_rtti]:
Do not use dynamic_cast.

Diff:
---
 libstdc++-v3/src/c++23/print.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/src/c++23/print.cc b/libstdc++-v3/src/c++23/print.cc
index aceca6f9139b..99a19cd45002 100644
--- a/libstdc++-v3/src/c++23/print.cc
+++ b/libstdc++-v3/src/c++23/print.cc
@@ -87,7 +87,7 @@ namespace
   void*
   __open_terminal(std::streambuf* sb)
   {
-#ifndef _GLIBCXX_USE_STDIO_PURE
+#if ! defined _GLIBCXX_USE_STDIO_PURE && defined __cpp_rtti
 using namespace __gnu_cxx;
 
 if (auto fb = dynamic_cast*>(sb))


[gcc r14-10208] libstdc++: Guard dynamic_cast use in src/c++23/print.cc [PR115015]

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

commit r14-10208-geefa4c06483f95f5076687ed6aae5c6001731164
Author: Jonathan Wakely 
Date:   Tue May 14 14:32:23 2024 +0100

libstdc++: Guard dynamic_cast use in src/c++23/print.cc [PR115015]

Do not use dynamic_cast unconditionally, in case libstdc++ is built with
-fno-rtti.

libstdc++-v3/ChangeLog:

PR libstdc++/115015
* src/c++23/print.cc (__open_terminal(streambuf*)) [!__cpp_rtti]:
Do not use dynamic_cast.

Diff:
---
 libstdc++-v3/src/c++23/print.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/src/c++23/print.cc b/libstdc++-v3/src/c++23/print.cc
index aceca6f9139b..99a19cd45002 100644
--- a/libstdc++-v3/src/c++23/print.cc
+++ b/libstdc++-v3/src/c++23/print.cc
@@ -87,7 +87,7 @@ namespace
   void*
   __open_terminal(std::streambuf* sb)
   {
-#ifndef _GLIBCXX_USE_STDIO_PURE
+#if ! defined _GLIBCXX_USE_STDIO_PURE && defined __cpp_rtti
 using namespace __gnu_cxx;
 
 if (auto fb = dynamic_cast*>(sb))


[gcc r15-486] testsuite: analyzer: Fix fd-glibc-byte-stream-connection-server.c on Solaris [PR107750]

2024-05-14 Thread Rainer Orth via Gcc-cvs
https://gcc.gnu.org/g:f97d86f897bcf0ffda4d8d2e5b78a160e9ece140

commit r15-486-gf97d86f897bcf0ffda4d8d2e5b78a160e9ece140
Author: Rainer Orth 
Date:   Tue May 14 16:23:14 2024 +0200

testsuite: analyzer: Fix fd-glibc-byte-stream-connection-server.c on 
Solaris [PR107750]

gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c currently FAILs
on Solaris:

FAIL: gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c (test for
excess errors)

Excess errors:

/vol/gcc/src/hg/master/local/gcc/testsuite/gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c:91:3:
error: implicit declaration of function 'memset'
[-Wimplicit-function-declaration]

Solaris  has

but no declaration of memset.  While one can argue that this should be
fixed, it's easy enough to just include  instead, which is
what this patch does.

Tested on i386-pc-solaris2.11 and i686-pc-linux-gnu.

2024-05-14  Rainer Orth  

gcc/testsuite:
PR analyzer/107750
* gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c:
Include .

Diff:
---
 gcc/testsuite/gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/gcc/testsuite/gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c 
b/gcc/testsuite/gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c
index f922a52238f9..71dbef6d6e77 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #if __has_include()


[gcc r15-487] [testsuite] Fix gcc.dg/pr115066.c fail on aarch64

2024-05-14 Thread Tom de Vries via Gcc-cvs
https://gcc.gnu.org/g:c1356e8cc9a8c869ab936c927b1812b4691265b6

commit r15-487-gc1356e8cc9a8c869ab936c927b1812b4691265b6
Author: Tom de Vries 
Date:   Tue May 14 15:26:39 2024 +0200

[testsuite] Fix gcc.dg/pr115066.c fail on aarch64

On aarch64, I get this failure:
...
FAIL: gcc.dg/pr115066.c scan-assembler \\.byte\\t0xb\\t# Define macro strx
...

This happens because we expect to match:
...
.byte   0xb # Define macro strx
...
but instead we get:
...
.byte   0xb // Define macro strx
...

Fix this by not explicitly matching the comment marker.

Tested on aarch64 and x86_64.

gcc/testsuite/ChangeLog:

2024-05-14  Tom de Vries  

* gcc.dg/pr115066.c: Don't match comment marker.

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

diff --git a/gcc/testsuite/gcc.dg/pr115066.c b/gcc/testsuite/gcc.dg/pr115066.c
index 645757df2092..780767ac2952 100644
--- a/gcc/testsuite/gcc.dg/pr115066.c
+++ b/gcc/testsuite/gcc.dg/pr115066.c
@@ -2,7 +2,7 @@
 /* { dg-skip-if "split DWARF unsupported" { hppa*-*-hpux* powerpc*-ibm-aix* 
*-*-darwin* } } */
 /* { dg-options "-gsplit-dwarf -g3 -dA -gdwarf-4" } */
 /* { dg-final { scan-assembler-times {\.section\t"?\.debug_macro} 1 } } */
-/* { dg-final { scan-assembler-not {\.byte\t0x5\t# Define macro strp} } } */
-/* { dg-final { scan-assembler {\.byte\t0xb\t# Define macro strx} } } */
+/* { dg-final { scan-assembler-not {\.byte\t0x5\t[^\n\r]* Define macro strp} } 
} */
+/* { dg-final { scan-assembler {\.byte\t0xb\t[^\n\r]* Define macro strx} } } */
 
 #define foo 1


[gcc r13-8774] ipa: Compare jump functions in ICF (PR 113907)

2024-05-14 Thread Martin Jambor via Gcc-cvs
https://gcc.gnu.org/g:1db45e83021a8a87f41e22053910fcce6e8e2c2c

commit r13-8774-g1db45e83021a8a87f41e22053910fcce6e8e2c2c
Author: Martin Jambor 
Date:   Tue May 14 17:01:21 2024 +0200

ipa: Compare jump functions in ICF (PR 113907)

This is a manual backport of r14-9840-g1162861439fd3c from master.
Manual because the bits and value range representation in jump
functions have changes during the gcc 14 development cycle.

In PR 113907 comment #58, Honza found a case where ICF thinks bodies
of functions are equivalent but becaise of difference in aliases in a
memory access, different aggregate jump functions are associated with
supposedly equivalent call statements.  This patch adds a way to
compare jump functions and plugs it into ICF to avoid the issue.

gcc/ChangeLog:

2024-05-14  Martin Jambor  

PR ipa/113907
* ipa-prop.h (ipa_jump_functions_equivalent_p): Declare.
(values_equal_for_ipcp_p): Likewise.
* ipa-prop.cc (ipa_agg_pass_through_jf_equivalent_p): New function.
(ipa_agg_jump_functions_equivalent_p): Likewise.
(ipa_jump_functions_equivalent_p): Likewise.
* ipa-cp.cc (values_equal_for_ipcp_p): Make function public.
* ipa-icf-gimple.cc: Include alloc-pool.h, symbol-summary.h, 
sreal.h,
ipa-cp.h and ipa-prop.h.
(func_checker::compare_gimple_call): Comapre jump functions.

gcc/testsuite/ChangeLog:

2024-05-10  Martin Jambor  

PR ipa/113907
* gcc.dg/lto/pr113907_0.c: New.
* gcc.dg/lto/pr113907_1.c: Likewise.
* gcc.dg/lto/pr113907_2.c: Likewise.

Diff:
---
 gcc/ipa-cp.cc |   2 +-
 gcc/ipa-icf-gimple.cc |  29 +++
 gcc/ipa-prop.cc   | 157 ++
 gcc/ipa-prop.h|   3 +
 gcc/testsuite/gcc.dg/lto/pr113907_0.c |  18 
 gcc/testsuite/gcc.dg/lto/pr113907_1.c |  35 
 gcc/testsuite/gcc.dg/lto/pr113907_2.c |  11 +++
 7 files changed, 254 insertions(+), 1 deletion(-)

diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
index b3e0f62e4003..8f36608cf33b 100644
--- a/gcc/ipa-cp.cc
+++ b/gcc/ipa-cp.cc
@@ -458,7 +458,7 @@ ipcp_lattice::is_single_const ()
 
 /* Return true iff X and Y should be considered equal values by IPA-CP.  */
 
-static bool
+bool
 values_equal_for_ipcp_p (tree x, tree y)
 {
   gcc_checking_assert (x != NULL_TREE && y != NULL_TREE);
diff --git a/gcc/ipa-icf-gimple.cc b/gcc/ipa-icf-gimple.cc
index 49302ad56c65..054a557bd588 100644
--- a/gcc/ipa-icf-gimple.cc
+++ b/gcc/ipa-icf-gimple.cc
@@ -42,7 +42,11 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-sra.h"
 
 #include "tree-ssa-alias-compare.h"
+#include "alloc-pool.h"
+#include "symbol-summary.h"
 #include "ipa-icf-gimple.h"
+#include "sreal.h"
+#include "ipa-prop.h"
 
 namespace ipa_icf_gimple {
 
@@ -751,6 +755,31 @@ func_checker::compare_gimple_call (gcall *s1, gcall *s2)
   && !compatible_types_p (TREE_TYPE (t1), TREE_TYPE (t2)))
 return return_false_with_msg ("GIMPLE internal call LHS type mismatch");
 
+  if (!gimple_call_internal_p (s1))
+{
+  cgraph_edge *e1 = cgraph_node::get (m_source_func_decl)->get_edge (s1);
+  cgraph_edge *e2 = cgraph_node::get (m_target_func_decl)->get_edge (s2);
+  class ipa_edge_args *args1 = ipa_edge_args_sum->get (e1);
+  class ipa_edge_args *args2 = ipa_edge_args_sum->get (e2);
+  if ((args1 != nullptr) != (args2 != nullptr))
+   return return_false_with_msg ("ipa_edge_args mismatch");
+  if (args1)
+   {
+ int n1 = ipa_get_cs_argument_count (args1);
+ int n2 = ipa_get_cs_argument_count (args2);
+ if (n1 != n2)
+   return return_false_with_msg ("ipa_edge_args nargs mismatch");
+ for (int i = 0; i < n1; i++)
+   {
+ struct ipa_jump_func *jf1 = ipa_get_ith_jump_func (args1, i);
+ struct ipa_jump_func *jf2 = ipa_get_ith_jump_func (args2, i);
+ if (((jf1 != nullptr) != (jf2 != nullptr))
+ || (jf1 && !ipa_jump_functions_equivalent_p (jf1, jf2)))
+   return return_false_with_msg ("jump function mismatch");
+   }
+   }
+}
+
   return compare_operand (t1, t2, get_operand_access_type (&map, t1));
 }
 
diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 0d8167495341..11ba2521b2c9 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -6022,5 +6022,162 @@ ipcp_transform_function (struct cgraph_node *node)
   return modified_mem_access ? TODO_update_ssa_only_virtuals : 0;
 }
 
+/* Return true if the two pass_through components of two jump functions are
+   known to be equivalent.  AGG_JF denotes whether they are part of aggregate
+   functions or not.  The function can be used before the IPA phase of IPA-CP
+   or inlining because it cannot cope with refdesc changes these

[gcc r15-488] [1/3] expr: Export clear_by_pieces()

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:e6e41b68fd805ab126895a20bb9670442b198f62

commit r15-488-ge6e41b68fd805ab126895a20bb9670442b198f62
Author: Christoph Müllner 
Date:   Tue May 14 09:19:13 2024 -0600

[1/3] expr: Export clear_by_pieces()

Make clear_by_pieces() available to other parts of the compiler,
similar to store_by_pieces().

gcc/ChangeLog:

* expr.cc (clear_by_pieces): Remove static from clear_by_pieces.
* expr.h (clear_by_pieces): Add prototype for clear_by_pieces.

Diff:
---
 gcc/expr.cc | 6 +-
 gcc/expr.h  | 5 +
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/gcc/expr.cc b/gcc/expr.cc
index 9f66d4794459..1baa39b98eba 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -85,7 +85,6 @@ static void emit_block_move_via_sized_loop (rtx, rtx, rtx, 
unsigned, unsigned);
 static void emit_block_move_via_oriented_loop (rtx, rtx, rtx, unsigned, 
unsigned);
 static rtx emit_block_cmp_via_loop (rtx, rtx, rtx, tree, rtx, bool,
unsigned, unsigned);
-static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
 static rtx_insn *compress_float_constant (rtx, rtx);
 static rtx get_subtarget (rtx);
 static rtx store_field (rtx, poly_int64, poly_int64, poly_uint64, poly_uint64,
@@ -1840,10 +1839,7 @@ store_by_pieces (rtx to, unsigned HOST_WIDE_INT len,
 return to;
 }
 
-/* Generate several move instructions to clear LEN bytes of block TO.  (A MEM
-   rtx with BLKmode).  ALIGN is maximum alignment we can assume.  */
-
-static void
+void
 clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
 {
   if (len == 0)
diff --git a/gcc/expr.h b/gcc/expr.h
index 64956f630297..751815841083 100644
--- a/gcc/expr.h
+++ b/gcc/expr.h
@@ -245,6 +245,11 @@ extern bool can_store_by_pieces (unsigned HOST_WIDE_INT,
 extern rtx store_by_pieces (rtx, unsigned HOST_WIDE_INT, by_pieces_constfn,
void *, unsigned int, bool, memop_ret);
 
+/* Generate several move instructions to clear LEN bytes of block TO.  (A MEM
+   rtx with BLKmode).  ALIGN is maximum alignment we can assume.  */
+
+extern void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
+
 /* If can_store_by_pieces passes for worst-case values near MAX_LEN, call
store_by_pieces within conditionals so as to handle variable LEN 
efficiently,
storing VAL, if non-NULL_RTX, or valc instead.  */


[gcc r15-490] [PATCH 3/3] RISC-V: Add memset-zero expansion to cbo.zero

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:54ba8d44bbd703bca6984700b4d6f978890097e2

commit r15-490-g54ba8d44bbd703bca6984700b4d6f978890097e2
Author: Christoph Müllner 
Date:   Tue May 14 09:21:17 2024 -0600

[PATCH 3/3] RISC-V: Add memset-zero expansion to cbo.zero

The Zicboz extension offers the cbo.zero instruction, which can be used
to clean a memory region corresponding to a cache block.
The Zic64b extension defines the cache block size to 64 byte.
If both extensions are available, it is possible to use cbo.zero
to clear memory, if the alignment and size constraints are met.
This patch implements this.

gcc/ChangeLog:

* config/riscv/riscv-protos.h (riscv_expand_block_clear): New 
prototype.
* config/riscv/riscv-string.cc 
(riscv_expand_block_clear_zicboz_zic64b):
New function to expand a block-clear with cbo.zero.
(riscv_expand_block_clear): New RISC-V block-clear expansion 
function.
* config/riscv/riscv.md (setmem): New setmem expansion.

Diff:
---
 gcc/config/riscv/riscv-protos.h|  1 +
 gcc/config/riscv/riscv-string.cc   | 59 ++
 gcc/config/riscv/riscv.md  | 24 +
 .../gcc.target/riscv/cmo-zicboz-zic64-1.c  | 43 
 4 files changed, 127 insertions(+)

diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index e5aebf3fc3d5..255fd6a0de97 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -189,6 +189,7 @@ rtl_opt_pass * make_pass_vsetvl (gcc::context *ctxt);
 
 /* Routines implemented in riscv-string.c.  */
 extern bool riscv_expand_block_move (rtx, rtx, rtx);
+extern bool riscv_expand_block_clear (rtx, rtx);
 
 /* Information about one CPU we know about.  */
 struct riscv_cpu_info {
diff --git a/gcc/config/riscv/riscv-string.cc b/gcc/config/riscv/riscv-string.cc
index 41cb061c746d..87f5fdee3c14 100644
--- a/gcc/config/riscv/riscv-string.cc
+++ b/gcc/config/riscv/riscv-string.cc
@@ -794,6 +794,65 @@ riscv_expand_block_move (rtx dest, rtx src, rtx length)
   return false;
 }
 
+/* Expand a block-clear instruction via cbo.zero instructions.  */
+
+static bool
+riscv_expand_block_clear_zicboz_zic64b (rtx dest, rtx length)
+{
+  unsigned HOST_WIDE_INT hwi_length;
+  unsigned HOST_WIDE_INT align;
+  const unsigned HOST_WIDE_INT cbo_bytes = 64;
+
+  gcc_assert (TARGET_ZICBOZ && TARGET_ZIC64B);
+
+  if (!CONST_INT_P (length))
+return false;
+
+  hwi_length = UINTVAL (length);
+  if (hwi_length < cbo_bytes)
+return false;
+
+  align = MEM_ALIGN (dest) / BITS_PER_UNIT;
+  if (align < cbo_bytes)
+return false;
+
+  /* We don't emit loops.  Instead apply move-bytes limitation.  */
+  unsigned HOST_WIDE_INT max_bytes = RISCV_MAX_MOVE_BYTES_STRAIGHT /
+ UNITS_PER_WORD * cbo_bytes;
+  if (hwi_length > max_bytes)
+return false;
+
+  unsigned HOST_WIDE_INT offset = 0;
+  while (offset + cbo_bytes <= hwi_length)
+{
+  rtx mem = adjust_address (dest, BLKmode, offset);
+  rtx addr = force_reg (Pmode, XEXP (mem, 0));
+  emit_insn (gen_riscv_zero_di (addr));
+  offset += cbo_bytes;
+}
+
+  if (offset < hwi_length)
+{
+  rtx mem = adjust_address (dest, BLKmode, offset);
+  clear_by_pieces (mem, hwi_length - offset, align);
+}
+
+  return true;
+}
+
+bool
+riscv_expand_block_clear (rtx dest, rtx length)
+{
+  /* Only use setmem-zero expansion for Zicboz + Zic64b.  */
+  if (!TARGET_ZICBOZ || !TARGET_ZIC64B)
+return false;
+
+  if (optimize_function_for_size_p (cfun))
+return false;
+
+  return riscv_expand_block_clear_zicboz_zic64b (dest, length);
+}
+
 /* --- Vector expanders --- */
 
 namespace riscv_vector {
diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index 4d6de9925572..c45b1129b0a0 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -2608,6 +2608,30 @@
 FAIL;
 })
 
+;; Fill memory with constant byte.
+;; Argument 0 is the destination
+;; Argument 1 is the constant byte
+;; Argument 2 is the length
+;; Argument 3 is the alignment
+
+(define_expand "setmem"
+  [(parallel [(set (match_operand:BLK 0 "memory_operand")
+  (match_operand:QI 2 "const_int_operand"))
+ (use (match_operand:P 1 ""))
+ (use (match_operand:SI 3 "const_int_operand"))])]
+ ""
+ {
+  /* If value to set is not zero, use the library routine.  */
+  if (operands[2] != const0_rtx)
+FAIL;
+
+  if (riscv_expand_block_clear (operands[0], operands[1]))
+DONE;
+  else
+FAIL;
+})
+
+
 ;; Expand in-line code to clear the instruction cache between operand[0] and
 ;; operand[1].
 (define_expand "clear_cache"
diff --git a/gcc/testsuite/gcc.target/riscv/cmo-zicboz-zic64-1.c 
b/gcc/testsuite/gcc.target/riscv/cmo-zicboz-zic64-1.c
new file mode 100644
index ..c2d79eb7ae68
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/cmo-zicboz-zic64

[gcc r15-489] [PATCH 2/3] RISC-V: testsuite: Make cmo tests LTO safe

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:21855f960141c1811d6a5f6ad3b2065f20d4b353

commit r15-489-g21855f960141c1811d6a5f6ad3b2065f20d4b353
Author: Christoph Müllner 
Date:   Tue May 14 09:20:18 2024 -0600

[PATCH 2/3] RISC-V: testsuite: Make cmo tests LTO safe

Let's add '\t' to the instruction match pattern to avoid false positive
matches when compiling with -flto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/cmo-zicbom-1.c: Add \t to test pattern.
* gcc.target/riscv/cmo-zicbom-2.c: Likewise.
* gcc.target/riscv/cmo-zicbop-1.c: Likewise.
* gcc.target/riscv/cmo-zicbop-2.c: Likewise.
* gcc.target/riscv/cmo-zicboz-1.c: Likewise.
* gcc.target/riscv/cmo-zicboz-2.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.target/riscv/cmo-zicbom-1.c | 6 +++---
 gcc/testsuite/gcc.target/riscv/cmo-zicbom-2.c | 6 +++---
 gcc/testsuite/gcc.target/riscv/cmo-zicbop-1.c | 6 +++---
 gcc/testsuite/gcc.target/riscv/cmo-zicbop-2.c | 6 +++---
 gcc/testsuite/gcc.target/riscv/cmo-zicboz-1.c | 2 +-
 gcc/testsuite/gcc.target/riscv/cmo-zicboz-2.c | 2 +-
 6 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/gcc/testsuite/gcc.target/riscv/cmo-zicbom-1.c 
b/gcc/testsuite/gcc.target/riscv/cmo-zicbom-1.c
index 6341f7874d3e..02c38e201fae 100644
--- a/gcc/testsuite/gcc.target/riscv/cmo-zicbom-1.c
+++ b/gcc/testsuite/gcc.target/riscv/cmo-zicbom-1.c
@@ -24,6 +24,6 @@ void foo3()
 __builtin_riscv_zicbom_cbo_inval((void*)0x111);
 }
 
-/* { dg-final { scan-assembler-times "cbo.clean" 3 } } */
-/* { dg-final { scan-assembler-times "cbo.flush" 3 } } */
-/* { dg-final { scan-assembler-times "cbo.inval" 3 } } */
+/* { dg-final { scan-assembler-times "cbo.clean\t" 3 } } */
+/* { dg-final { scan-assembler-times "cbo.flush\t" 3 } } */
+/* { dg-final { scan-assembler-times "cbo.inval\t" 3 } } */
diff --git a/gcc/testsuite/gcc.target/riscv/cmo-zicbom-2.c 
b/gcc/testsuite/gcc.target/riscv/cmo-zicbom-2.c
index a04f106c8b0e..040b96952bc3 100644
--- a/gcc/testsuite/gcc.target/riscv/cmo-zicbom-2.c
+++ b/gcc/testsuite/gcc.target/riscv/cmo-zicbom-2.c
@@ -24,6 +24,6 @@ void foo3()
 __builtin_riscv_zicbom_cbo_inval((void*)0x111);
 }
 
-/* { dg-final { scan-assembler-times "cbo.clean" 3 } } */
-/* { dg-final { scan-assembler-times "cbo.flush" 3 } } */
-/* { dg-final { scan-assembler-times "cbo.inval" 3 } } */
+/* { dg-final { scan-assembler-times "cbo.clean\t" 3 } } */
+/* { dg-final { scan-assembler-times "cbo.flush\t" 3 } } */
+/* { dg-final { scan-assembler-times "cbo.inval\t" 3 } } */
diff --git a/gcc/testsuite/gcc.target/riscv/cmo-zicbop-1.c 
b/gcc/testsuite/gcc.target/riscv/cmo-zicbop-1.c
index c5d78c1763d3..97181154d85b 100644
--- a/gcc/testsuite/gcc.target/riscv/cmo-zicbop-1.c
+++ b/gcc/testsuite/gcc.target/riscv/cmo-zicbop-1.c
@@ -18,6 +18,6 @@ int foo1()
   return __builtin_riscv_zicbop_cbo_prefetchi(1);
 }
 
-/* { dg-final { scan-assembler-times "prefetch.i" 1 } } */
-/* { dg-final { scan-assembler-times "prefetch.r" 4 } } */
-/* { dg-final { scan-assembler-times "prefetch.w" 4 } } */
+/* { dg-final { scan-assembler-times "prefetch.i\t" 1 } } */
+/* { dg-final { scan-assembler-times "prefetch.r\t" 4 } } */
+/* { dg-final { scan-assembler-times "prefetch.w\t" 4 } } */
diff --git a/gcc/testsuite/gcc.target/riscv/cmo-zicbop-2.c 
b/gcc/testsuite/gcc.target/riscv/cmo-zicbop-2.c
index 6576365b39ca..4871a97b21aa 100644
--- a/gcc/testsuite/gcc.target/riscv/cmo-zicbop-2.c
+++ b/gcc/testsuite/gcc.target/riscv/cmo-zicbop-2.c
@@ -18,6 +18,6 @@ int foo1()
   return __builtin_riscv_zicbop_cbo_prefetchi(1);
 }
 
-/* { dg-final { scan-assembler-times "prefetch.i" 1 } } */
-/* { dg-final { scan-assembler-times "prefetch.r" 4 } } */
-/* { dg-final { scan-assembler-times "prefetch.w" 4 } } */ 
+/* { dg-final { scan-assembler-times "prefetch.i\t" 1 } } */
+/* { dg-final { scan-assembler-times "prefetch.r\t" 4 } } */
+/* { dg-final { scan-assembler-times "prefetch.w\t" 4 } } */ 
diff --git a/gcc/testsuite/gcc.target/riscv/cmo-zicboz-1.c 
b/gcc/testsuite/gcc.target/riscv/cmo-zicboz-1.c
index 5eb78ab94b5a..63b8782bf89e 100644
--- a/gcc/testsuite/gcc.target/riscv/cmo-zicboz-1.c
+++ b/gcc/testsuite/gcc.target/riscv/cmo-zicboz-1.c
@@ -10,4 +10,4 @@ void foo1()
 __builtin_riscv_zicboz_cbo_zero((void*)0x121);
 }
 
-/* { dg-final { scan-assembler-times "cbo.zero" 3 } } */ 
+/* { dg-final { scan-assembler-times "cbo.zero\t" 3 } } */ 
diff --git a/gcc/testsuite/gcc.target/riscv/cmo-zicboz-2.c 
b/gcc/testsuite/gcc.target/riscv/cmo-zicboz-2.c
index fdc9c719669c..cc3bd505ec09 100644
--- a/gcc/testsuite/gcc.target/riscv/cmo-zicboz-2.c
+++ b/gcc/testsuite/gcc.target/riscv/cmo-zicboz-2.c
@@ -10,4 +10,4 @@ void foo1()
 __builtin_riscv_zicboz_cbo_zero((void*)0x121);
 }
 
-/* { dg-final { scan-assembler-times "cbo.zero" 3 } } */ 
+/* { dg-final { scan-assembler-times "cbo.zero\t" 3 } } */


[gcc r15-491] tree-optimization/99954 - redo loop distribution memcpy recognition fix

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

commit r15-491-gc290e6a0b7a9de5692963affc6627a4af7dc2411
Author: Richard Biener 
Date:   Tue May 14 11:13:51 2024 +0200

tree-optimization/99954 - redo loop distribution memcpy recognition fix

The following revisits the fix for PR99954 which was observed as
causing missed memcpy recognition and instead using memmove for
non-aliasing copies.  While the original fix mitigated bogus
recognition of memcpy the root cause was not properly identified.
The root cause is dr_analyze_indices "failing" to handle union
references and leaving the DRs indices in a state that's not correctly
handled by dr_may_alias.  The following mitigates this there
appropriately, restoring memcpy recognition for non-aliasing copies.

This makes us run into a latent issue in ptr_deref_may_alias_decl_p
when the pointer is something like &MEM[0].a in which case we fail
to handle non-SSA name pointers.  Add code similar to what we have
in ptr_derefs_may_alias_p.

PR tree-optimization/99954
* tree-data-ref.cc (dr_may_alias_p): For bases that are
not completely analyzed fall back to TBAA and points-to.
* tree-loop-distribution.cc
(loop_distribution::classify_builtin_ldst): When there
is no dependence again classify as memcpy.
* tree-ssa-alias.cc (ptr_deref_may_alias_decl_p): Verify
the pointer is an SSA name.

* gcc.dg/tree-ssa/ldist-40.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/tree-ssa/ldist-40.c | 10 ++
 gcc/tree-data-ref.cc | 22 ++
 gcc/tree-loop-distribution.cc|  4 ++--
 gcc/tree-ssa-alias.cc|  5 +
 4 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ldist-40.c 
b/gcc/testsuite/gcc.dg/tree-ssa/ldist-40.c
new file mode 100644
index ..238a0098352a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ldist-40.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ldist-details" } */
+
+void copy_a_to_b (char * __restrict b, char * a, int n)
+{
+  for (int i = 0; i < n; ++i)
+b[i] = a[i];
+}
+
+/* { dg-final { scan-tree-dump "generated memcpy" "ldist" } } */
diff --git a/gcc/tree-data-ref.cc b/gcc/tree-data-ref.cc
index f37734b53409..db15ddb43ded 100644
--- a/gcc/tree-data-ref.cc
+++ b/gcc/tree-data-ref.cc
@@ -3066,6 +3066,28 @@ dr_may_alias_p (const struct data_reference *a, const 
struct data_reference *b,
return ptr_derefs_may_alias_p (build_fold_addr_expr (addr_a),
   TREE_OPERAND (addr_b, 0));
 }
+  /* If dr_analyze_innermost failed to handle a component we are
+ possibly left with a non-base in which case we didn't analyze
+ a possible evolution of the base when analyzing a loop.  */
+  else if (loop_nest
+  && (handled_component_p (addr_a) || handled_component_p (addr_b)))
+{
+  /* For true dependences we can apply TBAA.  */
+  if (flag_strict_aliasing
+ && DR_IS_WRITE (a) && DR_IS_READ (b)
+ && !alias_sets_conflict_p (get_alias_set (DR_REF (a)),
+get_alias_set (DR_REF (b
+   return false;
+  if (TREE_CODE (addr_a) == MEM_REF)
+   return ptr_derefs_may_alias_p (TREE_OPERAND (addr_a, 0),
+  build_fold_addr_expr (addr_b));
+  else if (TREE_CODE (addr_b) == MEM_REF)
+   return ptr_derefs_may_alias_p (build_fold_addr_expr (addr_a),
+  TREE_OPERAND (addr_b, 0));
+  else
+   return ptr_derefs_may_alias_p (build_fold_addr_expr (addr_a),
+  build_fold_addr_expr (addr_b));
+}
 
   /* Otherwise DR_BASE_OBJECT is an access that covers the whole object
  that is being subsetted in the loop nest.  */
diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc
index 45932bae5e7f..668dc4204490 100644
--- a/gcc/tree-loop-distribution.cc
+++ b/gcc/tree-loop-distribution.cc
@@ -1840,11 +1840,11 @@ loop_distribution::classify_builtin_ldst (loop_p loop, 
struct graph *rdg,
   /* Now check that if there is a dependence.  */
   ddr_p ddr = get_data_dependence (rdg, src_dr, dst_dr);
 
-  /* Classify as memmove if no dependence between load and store.  */
+  /* Classify as memcpy if no dependence between load and store.  */
   if (DDR_ARE_DEPENDENT (ddr) == chrec_known)
 {
   partition->builtin = alloc_builtin (dst_dr, src_dr, base, src_base, 
size);
-  partition->kind = PKIND_MEMMOVE;
+  partition->kind = PKIND_MEMCPY;
   return;
 }
 
diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
index e7c1c1aa6243..374ba04e6fd0 100644
--- a/gcc/tree-ssa-alias.cc
+++ b/gcc/tree-ssa-alias.cc
@@ -294,6 +294,11 @@ ptr_deref_may_alias_decl_p (tree ptr, 

[gcc(refs/users/meissner/heads/work165-tar)] Add -mintspr. Default -mtar for power10, not power9.

2024-05-14 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:84becba734412efd2da9a75c859d2d776ab25666

commit 84becba734412efd2da9a75c859d2d776ab25666
Author: Michael Meissner 
Date:   Tue May 14 13:44:45 2024 -0400

Add -mintspr.  Default -mtar for power10, not power9.

2024-05-14  Michael Meissner  

* config/rs6000/rs6000-cpus.def (ISA_2_7_MASKS_SERVER): Don't set 
TAR
options here.
(OTHER_POWER10_MASKS): Set TAR options here.  Add -mintspr.
(POWERPC_MASKS): Add -mintspr.
* config/rs6000/rs6000.cc (rs6000_hard_regno_mode_ok_uncached): Add
support for -mintspr.
(rs6000_option_override_internal): Require -mcpu=power9 or 
-mcpu=power10
to use -mtar.
(rs6000_opt_masks): Add -mmfspr and -mintspr.
* config/rs6000/rs6000.opt (-mintspr): New option.

Diff:
---
 gcc/config/rs6000/rs6000-cpus.def | 15 ++-
 gcc/config/rs6000/rs6000.cc   | 19 ---
 gcc/config/rs6000/rs6000.opt  |  4 
 3 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-cpus.def 
b/gcc/config/rs6000/rs6000-cpus.def
index f53bd3e7dcba..46e26b0df5ec 100644
--- a/gcc/config/rs6000/rs6000-cpus.def
+++ b/gcc/config/rs6000/rs6000-cpus.def
@@ -51,19 +51,20 @@
 | OPTION_MASK_P8_VECTOR\
 | OPTION_MASK_CRYPTO   \
 | OPTION_MASK_EFFICIENT_UNALIGNED_VSX  \
-| OPTION_MASK_MFSPR\
 | OPTION_MASK_QUAD_MEMORY  \
-| OPTION_MASK_QUAD_MEMORY_ATOMIC   \
-| OPTION_MASK_TAR)
+| OPTION_MASK_QUAD_MEMORY_ATOMIC)
 
 /* ISA masks setting fusion options.  */
 #define OTHER_FUSION_MASKS (OPTION_MASK_P8_FUSION  \
 | OPTION_MASK_P8_FUSION_SIGN)
 
 /* Add ISEL back into ISA 3.0, since it is supposed to be a win.  Do not add
-   FLOAT128_HW here until we are ready to make -mfloat128 on by default.  */
+   FLOAT128_HW here until we are ready to make -mfloat128 on by default.  While
+   ISA 2.07 (power9) supports the TAR register, don't enable it here, because
+   it doesn't seem to help.  */
 #define ISA_3_0_MASKS_SERVER   ((ISA_2_7_MASKS_SERVER  \
  | OPTION_MASK_ISEL\
+ | OPTION_MASK_MFSPR   \
  | OPTION_MASK_MODULO  \
  | OPTION_MASK_P9_MINMAX   \
  | OPTION_MASK_P9_MISC \
@@ -80,9 +81,12 @@
 /* We comment out PCREL_OPT here to disable it by default because SPEC2017
performance was degraded by it.  */
 #define OTHER_POWER10_MASKS(OPTION_MASK_MMA\
+| OPTION_MASK_INTSPR   \
+| OPTION_MASK_MFSPR\
 | OPTION_MASK_PCREL\
 /* | OPTION_MASK_PCREL_OPT */  \
-| OPTION_MASK_PREFIXED)
+| OPTION_MASK_PREFIXED \
+| OPTION_MASK_TAR)
 
 #define ISA_3_1_MASKS_SERVER   (ISA_3_0_MASKS_SERVER   \
 | OPTION_MASK_POWER10  \
@@ -135,6 +139,7 @@
 | OPTION_MASK_POWER11  \
 | OPTION_MASK_P10_FUSION   \
 | OPTION_MASK_HTM  \
+| OPTION_MASK_INTSPR   \
 | OPTION_MASK_ISEL \
 | OPTION_MASK_MFCRF\
 | OPTION_MASK_MFSPR\
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 6bfcfdfb22c5..7f4ee65c42c4 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -1930,8 +1930,8 @@ rs6000_hard_regno_mode_ok_uncached (int regno, 
machine_mode mode)
   if (CR_REGNO_P (regno))
 return GET_MODE_CLASS (mode) == MODE_CC;
 
-  /* Limit SPR registers to integer modes that can fit in a single register.
- Do not allow complex modes or modes that need sign/zero extension.  */
+  /* If desired, limit SPR registers to integer modes that can fit in a single
+ register.  Do not allow complex modes.  */
   switch (regno)
 {
 case LR_REGNO:
@@ -1940,7 +1940,9 @@ rs6000_hard_regno_mode_ok_uncached (int regno, 
machine_mode mode)
 case VRSAVE_REGNO:

[gcc(refs/users/meissner/heads/work165-tar)] Update ChangeLog.*

2024-05-14 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:414c4437358308f8dcc349b6be15977bdb7af487

commit 414c4437358308f8dcc349b6be15977bdb7af487
Author: Michael Meissner 
Date:   Tue May 14 13:46:50 2024 -0400

Update ChangeLog.*

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

diff --git a/gcc/ChangeLog.tar b/gcc/ChangeLog.tar
index 3e4684c22019..ad0c80ed7acc 100644
--- a/gcc/ChangeLog.tar
+++ b/gcc/ChangeLog.tar
@@ -1,3 +1,20 @@
+ Branch work165-tar, patch #204 
+
+Add -mintspr.  Default -mtar for power10, not power9.
+
+2024-05-14  Michael Meissner  
+
+   * config/rs6000/rs6000-cpus.def (ISA_2_7_MASKS_SERVER): Don't set TAR
+   options here.
+   (OTHER_POWER10_MASKS): Set TAR options here.  Add -mintspr.
+   (POWERPC_MASKS): Add -mintspr.
+   * config/rs6000/rs6000.cc (rs6000_hard_regno_mode_ok_uncached): Add
+   support for -mintspr.
+   (rs6000_option_override_internal): Require -mcpu=power9 or -mcpu=power10
+   to use -mtar.
+   (rs6000_opt_masks): Add -mmfspr and -mintspr.
+   * config/rs6000/rs6000.opt (-mintspr): New option.
+
  Branch work165-tar, patch #203 
 
 Limit SPR registers to hold only DImode/SImode.


[gcc r15-492] RISC-V: avoid LUI based const materialization ... [part of PR/106265]

2024-05-14 Thread Vineet Gupta via Gcc-cvs
https://gcc.gnu.org/g:4bfc4585c9935fbde75ccf04e44a15d24f42cde9

commit r15-492-g4bfc4585c9935fbde75ccf04e44a15d24f42cde9
Author: Vineet Gupta 
Date:   Mon May 13 11:45:55 2024 -0700

RISC-V: avoid LUI based const materialization ... [part of PR/106265]

... if the constant can be represented as sum of two S12 values.
The two S12 values could instead be fused with subsequent ADD insn.
The helps
 - avoid an additional LUI insn
 - side benefits of not clobbering a reg

e.g.
w/o patch w/ patch
long  | |
plus(unsigned long i) | li  a5,4096 |
{ | addia5,a5,-2032 | addi a0, a0, 2047
   return i + 2064;   | add a0,a0,a5| addi a0, a0, 17
} | ret | ret

NOTE: In theory not having const in a standalone reg might seem less
  CSE friendly, but for workloads in consideration these mat are
  from very late LRA reloads and follow on GCSE is not doing much
  currently.

The real benefit however is seen in base+offset computation for array
accesses and especially for stack accesses which are finalized late in
optim pipeline, during LRA register allocation. Often the finalized
offsets trigger LRA reloads resulting in mind boggling repetition of
exact same insn sequence including LUI based constant materialization.

This shaves off 290 billion dynamic instrustions (QEMU icounts) in
SPEC 2017 Cactu benchmark which is over 10% of workload. In the rest of
suite, there additional 10 billion shaved, with both gains and losses
in indiv workloads as is usual with compiler changes.

 500.perlbench_r-0 |  1,214,534,029,025 | 1,212,887,959,387 |
 500.perlbench_r-1 |740,383,419,739 |   739,280,308,163 |
 500.perlbench_r-2 |692,074,638,817 |   691,118,734,547 |
 502.gcc_r-0   |190,820,141,435 |   190,857,065,988 |
 502.gcc_r-1   |225,747,660,839 |   225,809,444,357 | <- -0.02%
 502.gcc_r-2   |220,370,089,641 |   220,406,367,876 | <- -0.03%
 502.gcc_r-3   |179,111,460,458 |   179,135,609,723 | <- -0.02%
 502.gcc_r-4   |219,301,546,340 |   219,320,416,956 | <- -0.01%
 503.bwaves_r-0|278,733,324,691 |   278,733,323,575 | <- -0.01%
 503.bwaves_r-1|442,397,521,282 |   442,397,519,616 |
 503.bwaves_r-2|344,112,218,206 |   344,112,216,760 |
 503.bwaves_r-3|417,561,469,153 |   417,561,467,597 |
 505.mcf_r |669,319,257,525 |   669,318,763,084 |
 507.cactuBSSN_r   |  2,852,767,394,456 | 2,564,736,063,742 | <+ 10.10%
 508.namd_r|  1,855,884,342,110 | 1,855,881,110,934 |
 510.parest_r  |  1,654,525,521,053 | 1,654,402,859,174 |
 511.povray_r  |  2,990,146,655,619 | 2,990,060,324,589 |
 519.lbm_r |  1,158,337,294,525 | 1,158,337,294,529 |
 520.omnetpp_r |  1,021,765,791,283 | 1,026,165,661,394 |
 521.wrf_r |  1,715,955,652,503 | 1,714,352,737,385 |
 523.xalancbmk_r   |849,846,008,075 |   849,836,851,752 |
 525.x264_r-0  |277,801,762,763 |   277,488,776,427 |
 525.x264_r-1  |927,281,789,540 |   926,751,516,742 |
 525.x264_r-2  |915,352,631,375 |   914,667,785,953 |
 526.blender_r |  1,652,839,180,887 | 1,653,260,825,512 |
 527.cam4_r|  1,487,053,494,925 | 1,484,526,670,770 |
 531.deepsjeng_r   |  1,641,969,526,837 | 1,642,126,598,866 |
 538.imagick_r |  2,098,016,546,691 | 2,097,997,929,125 |
 541.leela_r   |  1,983,557,323,877 | 1,983,531,314,526 |
 544.nab_r |  1,516,061,611,233 | 1,516,061,407,715 |
 548.exchange2_r   |  2,072,594,330,215 | 2,072,591,648,318 |
 549.fotonik3d_r   |  1,001,499,307,366 | 1,001,478,944,189 |
 554.roms_r|  1,028,799,739,111 | 1,028,780,904,061 |
 557.xz_r-0|363,827,039,684 |   363,057,014,260 |
 557.xz_r-1|906,649,112,601 |   905,928,888,732 |
 557.xz_r-2|509,023,898,187 |   508,140,356,932 |
 997.specrand_fr   |402,535,577 |   403,052,561 |
 999.specrand_ir   |402,535,577 |   403,052,561 |

This should still be considered damage control as the real/deeper fix
would be to reduce number of LRA reloads or CSE/anchor those during
LRA constraint sub-pass (re)runs (thats a different PR/114729.

Implementation Details (for posterity)
--
 - basic idea is to have a splitter selected via a new predicate for 
constant
   being possible sum of two S12 and provide the transform.
   This is however a 2 -> 2 transform which combine can't handle.
   So we specify it using a define_insn_and_split.

 - the initial loose "i" constraint caused LRA to accept invalid insn

[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [1/3] expr: Export clear_by_pieces()

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

commit 5b00e29d1833dee69e1146f13a8d8a37dadfa31a
Author: Christoph Müllner 
Date:   Tue May 14 09:19:13 2024 -0600

[1/3] expr: Export clear_by_pieces()

Make clear_by_pieces() available to other parts of the compiler,
similar to store_by_pieces().

gcc/ChangeLog:

* expr.cc (clear_by_pieces): Remove static from clear_by_pieces.
* expr.h (clear_by_pieces): Add prototype for clear_by_pieces.

(cherry picked from commit e6e41b68fd805ab126895a20bb9670442b198f62)

Diff:
---
 gcc/expr.cc | 6 +-
 gcc/expr.h  | 5 +
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/gcc/expr.cc b/gcc/expr.cc
index d4414e242cb9..eaf86d3d8429 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -85,7 +85,6 @@ static void emit_block_move_via_sized_loop (rtx, rtx, rtx, 
unsigned, unsigned);
 static void emit_block_move_via_oriented_loop (rtx, rtx, rtx, unsigned, 
unsigned);
 static rtx emit_block_cmp_via_loop (rtx, rtx, rtx, tree, rtx, bool,
unsigned, unsigned);
-static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
 static rtx_insn *compress_float_constant (rtx, rtx);
 static rtx get_subtarget (rtx);
 static rtx store_field (rtx, poly_int64, poly_int64, poly_uint64, poly_uint64,
@@ -1832,10 +1831,7 @@ store_by_pieces (rtx to, unsigned HOST_WIDE_INT len,
 return to;
 }
 
-/* Generate several move instructions to clear LEN bytes of block TO.  (A MEM
-   rtx with BLKmode).  ALIGN is maximum alignment we can assume.  */
-
-static void
+void
 clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
 {
   if (len == 0)
diff --git a/gcc/expr.h b/gcc/expr.h
index 64956f630297..751815841083 100644
--- a/gcc/expr.h
+++ b/gcc/expr.h
@@ -245,6 +245,11 @@ extern bool can_store_by_pieces (unsigned HOST_WIDE_INT,
 extern rtx store_by_pieces (rtx, unsigned HOST_WIDE_INT, by_pieces_constfn,
void *, unsigned int, bool, memop_ret);
 
+/* Generate several move instructions to clear LEN bytes of block TO.  (A MEM
+   rtx with BLKmode).  ALIGN is maximum alignment we can assume.  */
+
+extern void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
+
 /* If can_store_by_pieces passes for worst-case values near MAX_LEN, call
store_by_pieces within conditionals so as to handle variable LEN 
efficiently,
storing VAL, if non-NULL_RTX, or valc instead.  */


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [PATCH 2/3] RISC-V: testsuite: Make cmo tests LTO safe

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:0db572dff53572f4c471ec588c7328a33f2cb6ab

commit 0db572dff53572f4c471ec588c7328a33f2cb6ab
Author: Christoph Müllner 
Date:   Tue May 14 09:20:18 2024 -0600

[PATCH 2/3] RISC-V: testsuite: Make cmo tests LTO safe

Let's add '\t' to the instruction match pattern to avoid false positive
matches when compiling with -flto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/cmo-zicbom-1.c: Add \t to test pattern.
* gcc.target/riscv/cmo-zicbom-2.c: Likewise.
* gcc.target/riscv/cmo-zicbop-1.c: Likewise.
* gcc.target/riscv/cmo-zicbop-2.c: Likewise.
* gcc.target/riscv/cmo-zicboz-1.c: Likewise.
* gcc.target/riscv/cmo-zicboz-2.c: Likewise.

(cherry picked from commit 21855f960141c1811d6a5f6ad3b2065f20d4b353)

Diff:
---
 gcc/testsuite/gcc.target/riscv/cmo-zicbom-1.c | 6 +++---
 gcc/testsuite/gcc.target/riscv/cmo-zicbom-2.c | 6 +++---
 gcc/testsuite/gcc.target/riscv/cmo-zicbop-1.c | 6 +++---
 gcc/testsuite/gcc.target/riscv/cmo-zicbop-2.c | 6 +++---
 gcc/testsuite/gcc.target/riscv/cmo-zicboz-1.c | 2 +-
 gcc/testsuite/gcc.target/riscv/cmo-zicboz-2.c | 2 +-
 6 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/gcc/testsuite/gcc.target/riscv/cmo-zicbom-1.c 
b/gcc/testsuite/gcc.target/riscv/cmo-zicbom-1.c
index 6341f7874d3e..02c38e201fae 100644
--- a/gcc/testsuite/gcc.target/riscv/cmo-zicbom-1.c
+++ b/gcc/testsuite/gcc.target/riscv/cmo-zicbom-1.c
@@ -24,6 +24,6 @@ void foo3()
 __builtin_riscv_zicbom_cbo_inval((void*)0x111);
 }
 
-/* { dg-final { scan-assembler-times "cbo.clean" 3 } } */
-/* { dg-final { scan-assembler-times "cbo.flush" 3 } } */
-/* { dg-final { scan-assembler-times "cbo.inval" 3 } } */
+/* { dg-final { scan-assembler-times "cbo.clean\t" 3 } } */
+/* { dg-final { scan-assembler-times "cbo.flush\t" 3 } } */
+/* { dg-final { scan-assembler-times "cbo.inval\t" 3 } } */
diff --git a/gcc/testsuite/gcc.target/riscv/cmo-zicbom-2.c 
b/gcc/testsuite/gcc.target/riscv/cmo-zicbom-2.c
index a04f106c8b0e..040b96952bc3 100644
--- a/gcc/testsuite/gcc.target/riscv/cmo-zicbom-2.c
+++ b/gcc/testsuite/gcc.target/riscv/cmo-zicbom-2.c
@@ -24,6 +24,6 @@ void foo3()
 __builtin_riscv_zicbom_cbo_inval((void*)0x111);
 }
 
-/* { dg-final { scan-assembler-times "cbo.clean" 3 } } */
-/* { dg-final { scan-assembler-times "cbo.flush" 3 } } */
-/* { dg-final { scan-assembler-times "cbo.inval" 3 } } */
+/* { dg-final { scan-assembler-times "cbo.clean\t" 3 } } */
+/* { dg-final { scan-assembler-times "cbo.flush\t" 3 } } */
+/* { dg-final { scan-assembler-times "cbo.inval\t" 3 } } */
diff --git a/gcc/testsuite/gcc.target/riscv/cmo-zicbop-1.c 
b/gcc/testsuite/gcc.target/riscv/cmo-zicbop-1.c
index c5d78c1763d3..97181154d85b 100644
--- a/gcc/testsuite/gcc.target/riscv/cmo-zicbop-1.c
+++ b/gcc/testsuite/gcc.target/riscv/cmo-zicbop-1.c
@@ -18,6 +18,6 @@ int foo1()
   return __builtin_riscv_zicbop_cbo_prefetchi(1);
 }
 
-/* { dg-final { scan-assembler-times "prefetch.i" 1 } } */
-/* { dg-final { scan-assembler-times "prefetch.r" 4 } } */
-/* { dg-final { scan-assembler-times "prefetch.w" 4 } } */
+/* { dg-final { scan-assembler-times "prefetch.i\t" 1 } } */
+/* { dg-final { scan-assembler-times "prefetch.r\t" 4 } } */
+/* { dg-final { scan-assembler-times "prefetch.w\t" 4 } } */
diff --git a/gcc/testsuite/gcc.target/riscv/cmo-zicbop-2.c 
b/gcc/testsuite/gcc.target/riscv/cmo-zicbop-2.c
index 6576365b39ca..4871a97b21aa 100644
--- a/gcc/testsuite/gcc.target/riscv/cmo-zicbop-2.c
+++ b/gcc/testsuite/gcc.target/riscv/cmo-zicbop-2.c
@@ -18,6 +18,6 @@ int foo1()
   return __builtin_riscv_zicbop_cbo_prefetchi(1);
 }
 
-/* { dg-final { scan-assembler-times "prefetch.i" 1 } } */
-/* { dg-final { scan-assembler-times "prefetch.r" 4 } } */
-/* { dg-final { scan-assembler-times "prefetch.w" 4 } } */ 
+/* { dg-final { scan-assembler-times "prefetch.i\t" 1 } } */
+/* { dg-final { scan-assembler-times "prefetch.r\t" 4 } } */
+/* { dg-final { scan-assembler-times "prefetch.w\t" 4 } } */ 
diff --git a/gcc/testsuite/gcc.target/riscv/cmo-zicboz-1.c 
b/gcc/testsuite/gcc.target/riscv/cmo-zicboz-1.c
index 5eb78ab94b5a..63b8782bf89e 100644
--- a/gcc/testsuite/gcc.target/riscv/cmo-zicboz-1.c
+++ b/gcc/testsuite/gcc.target/riscv/cmo-zicboz-1.c
@@ -10,4 +10,4 @@ void foo1()
 __builtin_riscv_zicboz_cbo_zero((void*)0x121);
 }
 
-/* { dg-final { scan-assembler-times "cbo.zero" 3 } } */ 
+/* { dg-final { scan-assembler-times "cbo.zero\t" 3 } } */ 
diff --git a/gcc/testsuite/gcc.target/riscv/cmo-zicboz-2.c 
b/gcc/testsuite/gcc.target/riscv/cmo-zicboz-2.c
index fdc9c719669c..cc3bd505ec09 100644
--- a/gcc/testsuite/gcc.target/riscv/cmo-zicboz-2.c
+++ b/gcc/testsuite/gcc.target/riscv/cmo-zicboz-2.c
@@ -10,4 +10,4 @@ void foo1()
 __builtin_riscv_zicboz_cbo_zero((void*)0x121);
 }
 
-/* { dg-final { scan-assembler-times "cbo.zero" 3 } } */ 
+/* { dg-final { scan-assembler-times "cbo.zero\t" 3 } } */


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [PATCH 3/3] RISC-V: Add memset-zero expansion to cbo.zero

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:f9a0426cdbd0d1e796cd0a9bcd39d31e3d2df018

commit f9a0426cdbd0d1e796cd0a9bcd39d31e3d2df018
Author: Christoph Müllner 
Date:   Tue May 14 09:21:17 2024 -0600

[PATCH 3/3] RISC-V: Add memset-zero expansion to cbo.zero

The Zicboz extension offers the cbo.zero instruction, which can be used
to clean a memory region corresponding to a cache block.
The Zic64b extension defines the cache block size to 64 byte.
If both extensions are available, it is possible to use cbo.zero
to clear memory, if the alignment and size constraints are met.
This patch implements this.

gcc/ChangeLog:

* config/riscv/riscv-protos.h (riscv_expand_block_clear): New 
prototype.
* config/riscv/riscv-string.cc 
(riscv_expand_block_clear_zicboz_zic64b):
New function to expand a block-clear with cbo.zero.
(riscv_expand_block_clear): New RISC-V block-clear expansion 
function.
* config/riscv/riscv.md (setmem): New setmem expansion.

(cherry picked from commit 54ba8d44bbd703bca6984700b4d6f978890097e2)

Diff:
---
 gcc/config/riscv/riscv-protos.h|  1 +
 gcc/config/riscv/riscv-string.cc   | 59 ++
 gcc/config/riscv/riscv.md  | 24 +
 .../gcc.target/riscv/cmo-zicboz-zic64-1.c  | 43 
 4 files changed, 127 insertions(+)

diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index e5aebf3fc3d5..255fd6a0de97 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -189,6 +189,7 @@ rtl_opt_pass * make_pass_vsetvl (gcc::context *ctxt);
 
 /* Routines implemented in riscv-string.c.  */
 extern bool riscv_expand_block_move (rtx, rtx, rtx);
+extern bool riscv_expand_block_clear (rtx, rtx);
 
 /* Information about one CPU we know about.  */
 struct riscv_cpu_info {
diff --git a/gcc/config/riscv/riscv-string.cc b/gcc/config/riscv/riscv-string.cc
index 41cb061c746d..87f5fdee3c14 100644
--- a/gcc/config/riscv/riscv-string.cc
+++ b/gcc/config/riscv/riscv-string.cc
@@ -794,6 +794,65 @@ riscv_expand_block_move (rtx dest, rtx src, rtx length)
   return false;
 }
 
+/* Expand a block-clear instruction via cbo.zero instructions.  */
+
+static bool
+riscv_expand_block_clear_zicboz_zic64b (rtx dest, rtx length)
+{
+  unsigned HOST_WIDE_INT hwi_length;
+  unsigned HOST_WIDE_INT align;
+  const unsigned HOST_WIDE_INT cbo_bytes = 64;
+
+  gcc_assert (TARGET_ZICBOZ && TARGET_ZIC64B);
+
+  if (!CONST_INT_P (length))
+return false;
+
+  hwi_length = UINTVAL (length);
+  if (hwi_length < cbo_bytes)
+return false;
+
+  align = MEM_ALIGN (dest) / BITS_PER_UNIT;
+  if (align < cbo_bytes)
+return false;
+
+  /* We don't emit loops.  Instead apply move-bytes limitation.  */
+  unsigned HOST_WIDE_INT max_bytes = RISCV_MAX_MOVE_BYTES_STRAIGHT /
+ UNITS_PER_WORD * cbo_bytes;
+  if (hwi_length > max_bytes)
+return false;
+
+  unsigned HOST_WIDE_INT offset = 0;
+  while (offset + cbo_bytes <= hwi_length)
+{
+  rtx mem = adjust_address (dest, BLKmode, offset);
+  rtx addr = force_reg (Pmode, XEXP (mem, 0));
+  emit_insn (gen_riscv_zero_di (addr));
+  offset += cbo_bytes;
+}
+
+  if (offset < hwi_length)
+{
+  rtx mem = adjust_address (dest, BLKmode, offset);
+  clear_by_pieces (mem, hwi_length - offset, align);
+}
+
+  return true;
+}
+
+bool
+riscv_expand_block_clear (rtx dest, rtx length)
+{
+  /* Only use setmem-zero expansion for Zicboz + Zic64b.  */
+  if (!TARGET_ZICBOZ || !TARGET_ZIC64B)
+return false;
+
+  if (optimize_function_for_size_p (cfun))
+return false;
+
+  return riscv_expand_block_clear_zicboz_zic64b (dest, length);
+}
+
 /* --- Vector expanders --- */
 
 namespace riscv_vector {
diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index 4d6de9925572..c45b1129b0a0 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -2608,6 +2608,30 @@
 FAIL;
 })
 
+;; Fill memory with constant byte.
+;; Argument 0 is the destination
+;; Argument 1 is the constant byte
+;; Argument 2 is the length
+;; Argument 3 is the alignment
+
+(define_expand "setmem"
+  [(parallel [(set (match_operand:BLK 0 "memory_operand")
+  (match_operand:QI 2 "const_int_operand"))
+ (use (match_operand:P 1 ""))
+ (use (match_operand:SI 3 "const_int_operand"))])]
+ ""
+ {
+  /* If value to set is not zero, use the library routine.  */
+  if (operands[2] != const0_rtx)
+FAIL;
+
+  if (riscv_expand_block_clear (operands[0], operands[1]))
+DONE;
+  else
+FAIL;
+})
+
+
 ;; Expand in-line code to clear the instruction cache between operand[0] and
 ;; operand[1].
 (define_expand "clear_cache"
diff --git a/gcc/testsuite/gcc.target/riscv/cmo-zicboz-zic64-1.c 
b/gcc/testsuite/gcc.target/riscv/cmo-zicboz-zic64-1.c
new file mode 100644
index ..c2d79eb7ae6

[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] RISC-V: avoid LUI based const materialization ... [part of PR/106265]

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:de257cc78146b0e518b272de5afc3faa9bbf3669

commit de257cc78146b0e518b272de5afc3faa9bbf3669
Author: Vineet Gupta 
Date:   Mon May 13 11:45:55 2024 -0700

RISC-V: avoid LUI based const materialization ... [part of PR/106265]

... if the constant can be represented as sum of two S12 values.
The two S12 values could instead be fused with subsequent ADD insn.
The helps
 - avoid an additional LUI insn
 - side benefits of not clobbering a reg

e.g.
w/o patch w/ patch
long  | |
plus(unsigned long i) | li  a5,4096 |
{ | addia5,a5,-2032 | addi a0, a0, 2047
   return i + 2064;   | add a0,a0,a5| addi a0, a0, 17
} | ret | ret

NOTE: In theory not having const in a standalone reg might seem less
  CSE friendly, but for workloads in consideration these mat are
  from very late LRA reloads and follow on GCSE is not doing much
  currently.

The real benefit however is seen in base+offset computation for array
accesses and especially for stack accesses which are finalized late in
optim pipeline, during LRA register allocation. Often the finalized
offsets trigger LRA reloads resulting in mind boggling repetition of
exact same insn sequence including LUI based constant materialization.

This shaves off 290 billion dynamic instrustions (QEMU icounts) in
SPEC 2017 Cactu benchmark which is over 10% of workload. In the rest of
suite, there additional 10 billion shaved, with both gains and losses
in indiv workloads as is usual with compiler changes.

 500.perlbench_r-0 |  1,214,534,029,025 | 1,212,887,959,387 |
 500.perlbench_r-1 |740,383,419,739 |   739,280,308,163 |
 500.perlbench_r-2 |692,074,638,817 |   691,118,734,547 |
 502.gcc_r-0   |190,820,141,435 |   190,857,065,988 |
 502.gcc_r-1   |225,747,660,839 |   225,809,444,357 | <- -0.02%
 502.gcc_r-2   |220,370,089,641 |   220,406,367,876 | <- -0.03%
 502.gcc_r-3   |179,111,460,458 |   179,135,609,723 | <- -0.02%
 502.gcc_r-4   |219,301,546,340 |   219,320,416,956 | <- -0.01%
 503.bwaves_r-0|278,733,324,691 |   278,733,323,575 | <- -0.01%
 503.bwaves_r-1|442,397,521,282 |   442,397,519,616 |
 503.bwaves_r-2|344,112,218,206 |   344,112,216,760 |
 503.bwaves_r-3|417,561,469,153 |   417,561,467,597 |
 505.mcf_r |669,319,257,525 |   669,318,763,084 |
 507.cactuBSSN_r   |  2,852,767,394,456 | 2,564,736,063,742 | <+ 10.10%
 508.namd_r|  1,855,884,342,110 | 1,855,881,110,934 |
 510.parest_r  |  1,654,525,521,053 | 1,654,402,859,174 |
 511.povray_r  |  2,990,146,655,619 | 2,990,060,324,589 |
 519.lbm_r |  1,158,337,294,525 | 1,158,337,294,529 |
 520.omnetpp_r |  1,021,765,791,283 | 1,026,165,661,394 |
 521.wrf_r |  1,715,955,652,503 | 1,714,352,737,385 |
 523.xalancbmk_r   |849,846,008,075 |   849,836,851,752 |
 525.x264_r-0  |277,801,762,763 |   277,488,776,427 |
 525.x264_r-1  |927,281,789,540 |   926,751,516,742 |
 525.x264_r-2  |915,352,631,375 |   914,667,785,953 |
 526.blender_r |  1,652,839,180,887 | 1,653,260,825,512 |
 527.cam4_r|  1,487,053,494,925 | 1,484,526,670,770 |
 531.deepsjeng_r   |  1,641,969,526,837 | 1,642,126,598,866 |
 538.imagick_r |  2,098,016,546,691 | 2,097,997,929,125 |
 541.leela_r   |  1,983,557,323,877 | 1,983,531,314,526 |
 544.nab_r |  1,516,061,611,233 | 1,516,061,407,715 |
 548.exchange2_r   |  2,072,594,330,215 | 2,072,591,648,318 |
 549.fotonik3d_r   |  1,001,499,307,366 | 1,001,478,944,189 |
 554.roms_r|  1,028,799,739,111 | 1,028,780,904,061 |
 557.xz_r-0|363,827,039,684 |   363,057,014,260 |
 557.xz_r-1|906,649,112,601 |   905,928,888,732 |
 557.xz_r-2|509,023,898,187 |   508,140,356,932 |
 997.specrand_fr   |402,535,577 |   403,052,561 |
 999.specrand_ir   |402,535,577 |   403,052,561 |

This should still be considered damage control as the real/deeper fix
would be to reduce number of LRA reloads or CSE/anchor those during
LRA constraint sub-pass (re)runs (thats a different PR/114729.

Implementation Details (for posterity)
--
 - basic idea is to have a splitter selected via a new predicate for 
constant
   being possible sum of two S12 and provide the transform.
   This is however a 2 -> 2 transform which combine can't handle.
   So we specify it using a define_insn_and_split.

 - the initial loose "i" constraint caused LRA to accept invalid insns thus
  

[gcc r15-493] pru: Implement TARGET_CLASS_LIKELY_SPILLED_P to fix PR115013

2024-05-14 Thread Dimitar Dimitrov via Gcc-cvs
https://gcc.gnu.org/g:fc559584fa5b1e101a4520e88a936246458d5a5d

commit r15-493-gfc559584fa5b1e101a4520e88a936246458d5a5d
Author: Dimitar Dimitrov 
Date:   Mon May 13 19:24:14 2024 +0300

pru: Implement TARGET_CLASS_LIKELY_SPILLED_P to fix PR115013

Commit r15-436-g44e7855e did not fix PR115013 for PRU because
SMALL_REGISTER_CLASS_P is not returning an accurate value for the PRU
backend.

Word mode for PRU backend is defined as 8-bit, yet all ALU operations
are preferred in 32-bit mode.  Thus checking whether a register class
contains a single word_mode register would not classify the actually
single SImode register classes as small.  This affected the
multiplication source and destination register classes.

Fix by implementing TARGET_CLASS_LIKELY_SPILLED_P to treat all register
classes with SImode or smaller size as likely spilled.  This in turn
corrects the behaviour of SMALL_REGISTER_CLASS_P for PRU.

PR rtl-optimization/115013

gcc/ChangeLog:

* config/pru/pru.cc (pru_class_likely_spilled_p): Implement
to mark classes containing one SImode register as likely
spilled.
(TARGET_CLASS_LIKELY_SPILLED_P): Define.

Signed-off-by: Dimitar Dimitrov 

Diff:
---
 gcc/config/pru/pru.cc | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/gcc/config/pru/pru.cc b/gcc/config/pru/pru.cc
index 41d7195d2b55..491f66432b37 100644
--- a/gcc/config/pru/pru.cc
+++ b/gcc/config/pru/pru.cc
@@ -517,6 +517,17 @@ pru_can_use_return_insn (void)
   return cfun->machine->total_size == 0;
 }
 
+/* Implement `TARGET_CLASS_LIKELY_SPILLED_P'.  The original intention
+   of the default implementation is kept, but is adjusted for PRU.
+   Return TRUE if the given class C contains a single SImode
+   (as opposed to word_mode!) register.  */
+
+static bool
+pru_class_likely_spilled_p (reg_class_t c)
+{
+  return (reg_class_size[(int) c] <= GET_MODE_SIZE (SImode));
+}
+
 /* Implement TARGET_HARD_REGNO_MODE_OK.  */
 
 static bool
@@ -3181,6 +3192,9 @@ pru_unwind_word_mode (void)
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE pru_can_eliminate
 
+#undef TARGET_CLASS_LIKELY_SPILLED_P
+#define TARGET_CLASS_LIKELY_SPILLED_P pru_class_likely_spilled_p
+
 #undef TARGET_HARD_REGNO_MODE_OK
 #define TARGET_HARD_REGNO_MODE_OK pru_hard_regno_mode_ok


[gcc r15-494] c++ comment adjustments for 114935

2024-05-14 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:1288283051435c6b23473448aa21fa9ca53fabac

commit r15-494-g1288283051435c6b23473448aa21fa9ca53fabac
Author: Jason Merrill 
Date:   Tue May 14 17:37:08 2024 -0400

c++ comment adjustments for 114935

gcc/cp/ChangeLog:

* decl.cc (wrap_cleanups_r): Clarify comment.
* init.cc (build_vec_init): Update comment.

Diff:
---
 gcc/cp/decl.cc | 10 +-
 gcc/cp/init.cc | 10 --
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 3fc8835154d9..a139b293e00c 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -8028,11 +8028,11 @@ wrap_cleanups_r (tree *stmt_p, int *walk_subtrees, void 
*data)
Unfortunately, there's no way to express this properly in terms of
nesting, as the regions for the temporaries overlap the region for the
variable itself; if there are two temporaries, the variable needs to be
-   the first thing destroyed if either of them throws.  However, we only
-   want to run the variable's cleanup if it actually got constructed.  So
-   we need to guard the temporary cleanups with the variable's cleanup if
-   they are run on the normal path, but not if they are run on the
-   exceptional path.  We implement this by telling
+   the first thing destroyed if either of the temporary destructors throws.
+   However, we only want to run the variable's cleanup if it actually got
+   constructed.  So we need to guard the temporary cleanups with the
+   variable's cleanup if they are run on the normal path, but not if they
+   are run on the exceptional path.  We implement this by telling
honor_protect_cleanup_actions to strip the variable cleanup from the
exceptional path.
 
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index 7bb98f445c37..906e401974cb 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -4685,8 +4685,14 @@ build_vec_init (tree base, tree maxindex, tree init,
 for any temporaries in the initialization are naturally within our
 cleanup region, so we don't want wrap_temporary_cleanups to do
 anything for arrays.  But if the array is a subobject, we need to
-tell split_nonconstant_init how to turn off this cleanup in favor of
-the cleanup for the complete object.  */
+tell split_nonconstant_init or cp_genericize_target_expr how to turn
+off this cleanup in favor of the cleanup for the complete object.
+
+??? For an array temporary such as an initializer_list backing array,
+it would avoid redundancy to leave this cleanup active, clear
+CLEANUP_EH_ONLY, and not build another cleanup for the temporary
+itself.  But that breaks when gimplify_target_expr adds a clobber
+cleanup that runs before the build_vec_init cleanup.  */
   if (cleanup_flags)
vec_safe_push (*cleanup_flags, build_tree_list (iterator, maxindex));
 }


[gcc r15-495] c++: ICE in build_deduction_guide for invalid template [PR105760]

2024-05-14 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:0003e469d4664397b65080a66ad7d6557bd7ffce

commit r15-495-g0003e469d4664397b65080a66ad7d6557bd7ffce
Author: Simon Martin 
Date:   Mon May 6 15:20:10 2024 +0200

c++: ICE in build_deduction_guide for invalid template [PR105760]

We currently ICE upon the following invalid snippet because we fail to
properly handle tsubst_arg_types returning error_mark_node in
build_deduction_guide.

== cut ==
template
struct A { A(Ts...); };
A a;
== cut ==

This patch fixes this, and has been successfully tested on 
x86_64-pc-linux-gnu.

PR c++/105760

gcc/cp/ChangeLog:

* pt.cc (build_deduction_guide): Check for error_mark_node
result from tsubst_arg_types.

gcc/testsuite/ChangeLog:

* g++.dg/parse/error66.C: New test.

Diff:
---
 gcc/cp/pt.cc | 2 ++
 gcc/testsuite/g++.dg/parse/error66.C | 6 ++
 2 files changed, 8 insertions(+)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 4b71e199d27f..32640f8e946d 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -30031,6 +30031,8 @@ build_deduction_guide (tree type, tree ctor, tree 
outer_args, tsubst_flags_t com
 references to members of an unknown specialization.  */
  cp_evaluated ev;
  fparms = tsubst_arg_types (fparms, targs, NULL_TREE, complain, ctor);
+if (fparms == error_mark_node)
+  ok = false;
  fargs = tsubst (fargs, targs, complain, ctor);
  if (ci)
{
diff --git a/gcc/testsuite/g++.dg/parse/error66.C 
b/gcc/testsuite/g++.dg/parse/error66.C
new file mode 100644
index ..82f4b8b8a530
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/error66.C
@@ -0,0 +1,6 @@
+// PR c++/105760
+// { dg-do compile { target c++17 } }
+
+template // { dg-error "must be at the end of the template 
parameter list" }
+struct A { A(Ts...); };
+A a;


[gcc r15-497] [to-be-committed, RISC-V] Remove redundant AND in shift-add sequence

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:32ff344d57d56fddb66c4976b5651345d40b7157

commit r15-497-g32ff344d57d56fddb66c4976b5651345d40b7157
Author: Jeff Law 
Date:   Tue May 14 18:17:59 2024 -0600

[to-be-committed,RISC-V] Remove redundant AND in shift-add sequence

So this patch allows us to eliminate an redundant AND in some shift-add
style sequences.   I think the testcase was reduced from xz by the RAU
team, but I'm not highly confident of that.

Specifically the AND is masking off the upper 32 bits of the un-shifted
value and there's an outer SIGN_EXTEND from SI to DI.  However in the
RTL it's working on the post-shifted value, so the constant is left
shifted, so we have to account for that in the pattern's condition.

We can just drop the AND in this case.  So instead we do a 64bit shift,
then a sign extending ADD utilizing the low part of that 64bit shift result.

This has run through Ventana's CI as well as my own.  I'll wait for it
to run through the larger CI system before pushing.

Jeff

gcc/
* config/riscv/riscv.md: Add pattern for sign extended shift-add
sequence with a masked input.

gcc/testsuite

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

Diff:
---
 gcc/config/riscv/riscv.md| 25 +
 gcc/testsuite/gcc.target/riscv/shift-add-2.c | 16 
 2 files changed, 41 insertions(+)

diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index 893040f28541..ee15c63db107 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -4120,6 +4120,31 @@
   [(set_attr "type" "load")
(set (attr "length") (const_int 8))])
 
+;; The AND is redunant here.  It always turns off the high 32 bits  and the
+;; low number of bits equal to the shift count.  Those upper 32 bits will be
+;; reset by the SIGN_EXTEND at the end.
+;;
+;; One could argue combine should have realized this and simplified what it
+;; presented to the backend.  But we can obviously cope with what it gave us.
+(define_insn_and_split ""
+  [(set (match_operand:DI 0 "register_operand" "=r")
+   (sign_extend:DI
+ (plus:SI (subreg:SI
+(and:DI
+  (ashift:DI (match_operand:DI 1 "register_operand" "r")
+ (match_operand 2 "const_int_operand" "n"))
+  (match_operand 3 "const_int_operand" "n")) 0)
+  (match_operand:SI 4 "register_operand" "r"
+   (clobber (match_scratch:DI 5 "=&r"))]
+  "TARGET_64BIT
+   && (INTVAL (operands[3]) | ((1 << INTVAL (operands[2])) - 1)) == 0x"
+  "#"
+  "&& reload_completed"
+  [(set (match_dup 5) (ashift:DI (match_dup 1) (match_dup 2)))
+   (set (match_dup 0) (sign_extend:DI (plus:SI (match_dup 6) (match_dup 4]
+  "{ operands[6] = gen_lowpart (SImode, operands[5]); }"
+  [(set_attr "type" "arith")])
+
 (include "bitmanip.md")
 (include "crypto.md")
 (include "sync.md")
diff --git a/gcc/testsuite/gcc.target/riscv/shift-add-2.c 
b/gcc/testsuite/gcc.target/riscv/shift-add-2.c
new file mode 100644
index ..87439858e59e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/shift-add-2.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zba_zbb_zbs -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
+
+int sub2(int a, long long b) {
+  b = (b << 32) >> 31;
+  unsigned int x = a + b;
+  return x;
+}
+
+
+/* { dg-final { scan-assembler-times "\tslli\t" 1 } } */
+/* { dg-final { scan-assembler-times "\taddw\t" 1 } } */
+/* { dg-final { scan-assembler-not "\tsrai\t" } } */
+/* { dg-final { scan-assembler-not "\tsh.add\t" } } */
+


[gcc(refs/users/meissner/heads/work165-test)] Update to tar branch.

2024-05-14 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:9cefcbbe66343a37b89353aa9c23cd289bf01777

commit 9cefcbbe66343a37b89353aa9c23cd289bf01777
Author: Michael Meissner 
Date:   Tue May 14 21:19:38 2024 -0400

Update to tar branch.

2024-05-14  Michael Meissner  

* config/rs6000/rs6000-cpus.def (ISA_2_7_MASKS_SERVER): Remove -mtar
support from -mcpu=power8.
(OTHER_POWER10_MASKS): Add -mtar, -mmfspr, and -mintspr.
(POWERPC_MASKS): Add -mintspr.
* config/rs6000/rs6000.cc (rs6000_hard_regno_mode_ok_uncached): Add
support for -mintspr.
(rs6000_option_override_internal): Do not allow -mtar unless power9 
or
power10.
(rs6000_opt_masks): Add -mmfspr and -minttar.
* config/rs6000/rs6000.opt (-mintspr): New switch.

Diff:
---
 gcc/config/rs6000/rs6000-cpus.def | 14 +-
 gcc/config/rs6000/rs6000.cc   | 26 +-
 gcc/config/rs6000/rs6000.opt  |  4 
 3 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-cpus.def 
b/gcc/config/rs6000/rs6000-cpus.def
index f53bd3e7dcba..a526918927ff 100644
--- a/gcc/config/rs6000/rs6000-cpus.def
+++ b/gcc/config/rs6000/rs6000-cpus.def
@@ -51,17 +51,17 @@
 | OPTION_MASK_P8_VECTOR\
 | OPTION_MASK_CRYPTO   \
 | OPTION_MASK_EFFICIENT_UNALIGNED_VSX  \
-| OPTION_MASK_MFSPR\
 | OPTION_MASK_QUAD_MEMORY  \
-| OPTION_MASK_QUAD_MEMORY_ATOMIC   \
-| OPTION_MASK_TAR)
+| OPTION_MASK_QUAD_MEMORY_ATOMIC)
 
 /* ISA masks setting fusion options.  */
 #define OTHER_FUSION_MASKS (OPTION_MASK_P8_FUSION  \
 | OPTION_MASK_P8_FUSION_SIGN)
 
 /* Add ISEL back into ISA 3.0, since it is supposed to be a win.  Do not add
-   FLOAT128_HW here until we are ready to make -mfloat128 on by default.  */
+   FLOAT128_HW here until we are ready to make -mfloat128 on by default.  While
+   ISA 2.07 (power9) supports the TAR register, don't enable it here, because
+   it doesn't seem to help.  */
 #define ISA_3_0_MASKS_SERVER   ((ISA_2_7_MASKS_SERVER  \
  | OPTION_MASK_ISEL\
  | OPTION_MASK_MODULO  \
@@ -80,9 +80,12 @@
 /* We comment out PCREL_OPT here to disable it by default because SPEC2017
performance was degraded by it.  */
 #define OTHER_POWER10_MASKS(OPTION_MASK_MMA\
+| OPTION_MASK_INTSPR   \
+| OPTION_MASK_MFSPR\
 | OPTION_MASK_PCREL\
 /* | OPTION_MASK_PCREL_OPT */  \
-| OPTION_MASK_PREFIXED)
+| OPTION_MASK_PREFIXED \
+| OPTION_MASK_TAR)
 
 #define ISA_3_1_MASKS_SERVER   (ISA_3_0_MASKS_SERVER   \
 | OPTION_MASK_POWER10  \
@@ -135,6 +138,7 @@
 | OPTION_MASK_POWER11  \
 | OPTION_MASK_P10_FUSION   \
 | OPTION_MASK_HTM  \
+| OPTION_MASK_INTSPR   \
 | OPTION_MASK_ISEL \
 | OPTION_MASK_MFCRF\
 | OPTION_MASK_MFSPR\
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 9f9f942a7860..7f4ee65c42c4 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -1930,11 +1930,8 @@ rs6000_hard_regno_mode_ok_uncached (int regno, 
machine_mode mode)
   if (CR_REGNO_P (regno))
 return GET_MODE_CLASS (mode) == MODE_CC;
 
-  if (CA_REGNO_P (regno))
-return mode == Pmode || mode == SImode;
-
-  /* Limit SPR registers to integer modes that can fit in a single register.
- Do not allow complex modes.  */
+  /* If desired, limit SPR registers to integer modes that can fit in a single
+ register.  Do not allow complex modes.  */
   switch (regno)
 {
 case LR_REGNO:
@@ -1942,10 +1939,10 @@ rs6000_hard_regno_mode_ok_uncached (int regno, 
machine_mode mode)
 case TAR_REGNO:
 case VRSAVE_REGNO:
 case VSCR_REGNO:
-  return (orig_mode == Pmode
- || orig_mode == SImode
- || orig_mode == HImode
- || orig_mode == QImode);
+case CA_REGN

[gcc(refs/users/meissner/heads/work165-test)] Update ChangeLog.*

2024-05-14 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:a61440a86c5c5322b40247f2b776e7d4dace79af

commit a61440a86c5c5322b40247f2b776e7d4dace79af
Author: Michael Meissner 
Date:   Tue May 14 21:21:04 2024 -0400

Update ChangeLog.*

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

diff --git a/gcc/ChangeLog.test b/gcc/ChangeLog.test
index fdf5f736b47d..01c13bbd7887 100644
--- a/gcc/ChangeLog.test
+++ b/gcc/ChangeLog.test
@@ -1,3 +1,20 @@
+ Branch work165-test, patch #401 
+
+Update to tar branch.
+
+2024-05-14  Michael Meissner  
+
+   * config/rs6000/rs6000-cpus.def (ISA_2_7_MASKS_SERVER): Remove -mtar
+   support from -mcpu=power8.
+   (OTHER_POWER10_MASKS): Add -mtar, -mmfspr, and -mintspr.
+   (POWERPC_MASKS): Add -mintspr.
+   * config/rs6000/rs6000.cc (rs6000_hard_regno_mode_ok_uncached): Add
+   support for -mintspr.
+   (rs6000_option_override_internal): Do not allow -mtar unless power9 or
+   power10.
+   (rs6000_opt_masks): Add -mmfspr and -minttar.
+   * config/rs6000/rs6000.opt (-mintspr): New switch.
+
  Branch work165-test, patch #400 
 
 Limit SPR registers to hold only small integer modes.


[gcc(refs/users/meissner/heads/work165-tar)] Revert previous changes

2024-05-14 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:be9d1542324190545ef14f01c68cceabb085bdc0

commit be9d1542324190545ef14f01c68cceabb085bdc0
Author: Michael Meissner 
Date:   Tue May 14 21:25:16 2024 -0400

Revert previous changes

Diff:
---
 gcc/ChangeLog.tar  | 101 +
 gcc/config/rs6000/constraints.md   |   5 +-
 gcc/config/rs6000/rs6000-cpus.def  |  13 +--
 gcc/config/rs6000/rs6000.cc|  84 ++---
 gcc/config/rs6000/rs6000.h |  31 +++
 gcc/config/rs6000/rs6000.md|  23 +++--
 gcc/config/rs6000/rs6000.opt   |  12 ---
 gcc/doc/invoke.texi|  12 +--
 gcc/lra-constraints.cc |   9 +-
 gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c|   4 +-
 gcc/testsuite/gcc.target/powerpc/pr51513.c |   4 +-
 .../gcc.target/powerpc/safe-indirect-jump-3.c  |   2 +-
 12 files changed, 49 insertions(+), 251 deletions(-)

diff --git a/gcc/ChangeLog.tar b/gcc/ChangeLog.tar
index ad0c80ed7acc..5e1035a5f9f6 100644
--- a/gcc/ChangeLog.tar
+++ b/gcc/ChangeLog.tar
@@ -1,99 +1,8 @@
- Branch work165-tar, patch #204 
-
-Add -mintspr.  Default -mtar for power10, not power9.
-
-2024-05-14  Michael Meissner  
-
-   * config/rs6000/rs6000-cpus.def (ISA_2_7_MASKS_SERVER): Don't set TAR
-   options here.
-   (OTHER_POWER10_MASKS): Set TAR options here.  Add -mintspr.
-   (POWERPC_MASKS): Add -mintspr.
-   * config/rs6000/rs6000.cc (rs6000_hard_regno_mode_ok_uncached): Add
-   support for -mintspr.
-   (rs6000_option_override_internal): Require -mcpu=power9 or -mcpu=power10
-   to use -mtar.
-   (rs6000_opt_masks): Add -mmfspr and -mintspr.
-   * config/rs6000/rs6000.opt (-mintspr): New option.
-
- Branch work165-tar, patch #203 
-
-Limit SPR registers to hold only DImode/SImode.
-
-2024-05-08  Michael Meissner  
-
-   * config/rs6000/rs6000.cc (rs6000_hard_regno_mode_ok_uncached): Limit
-   SPR registers to only hold SImode/DImode.
-
- Branch work165-tar, patch #202 
-
-Add -mfspr option.
-
-2024-05-08  Michael Meissner  
-
-   * config/rs6000/rs6000-cpus.def (ISA_2_7_MASKS_SERVER): Add -mfspr
-   support.
-   (POWERPC_MASKS): Likewise.
-   * config/rs6000/rs6000.cc (rs6000_register_move_cost): Likewise.
-   * config/rs6000/rs6000.opt (-mfspr): Likewise.
-
- Branch work165-tar, patch #201 
-
-Fix tests if -mtar is used.
-
-2024-05-06  Michael Meissner  
-
-gcc/testsuite/
-
-   * gcc.target/powerpc/ppc-switch-1.c: Add support for using the TAR
-   register.
-   * gcc.target/powerpc/pr51513.c: Likewise.
-   * gcc.target/powerpc/safe-indirect-jump-3.c: Likewise.
-
- Branch work165-tar, patch #200 
-
-Add support for -mtar
-
-2024-05-03  Michael Meissner  
-
-gcc/
-
-   * config/rs6000/constraints.md (h constraint): Add tar register to
-   documentation.
-   (wt constraint): New constraint.
-   * config/rs6000/rs6000-cpus.def (ISA_2_7_MASKS_SERVER): Add -mtar.
-   (POWERPC_MASKS): Likewise.
-   * config/rs6000/rs6000.cc (rs6000_reg_names): Add new tar register.
-   (alt_reg_names): Likewise.
-   (rs6000_debug_reg_global): Likewise.
-   (rs6000_init_hard_regno_mode_ok): Likewise.
-   (rs6000_option_override_internal): Likewise.
-   (rs6000_conditional_register_usage): Likewise.
-   (print_operand): Likewise.
-   (rs6000_debugger_regno): Likewise.
-   (rs6000_opt_masks): Likewise.
-   * config/rs6000/rs6000.h (FIRST_PSEUDO_REGISTER): Likewise.
-   (FiXED_REGISTERS): Likewise.
-   (CALL_REALLY_USED_REGISTERS): Likewise.
-   (REG_ALLOC_ORDER): Likewise.
-   (reg_class): Add new TAR_REGS register class.
-   (REG_CLASS_NAMES): Likewise.
-   (REG_CLASS_CONTENTS): Likewise.
-   (r6000_reg_class_enum): Add RS6000_CONSTRAINT_wt.
-   (REG_NAMES): Add tar register.
-   * config/rs6000/rs6000.md (TAR_REGNO): New constant.
-   (mov_internal): Add support for tar register.
-   (movcc_): Likewise.
-   (movsf_hardfloat): Likewise.
-   (movsd_hardfloat): Likewise.
-   (mov_softfloat): Likewise.
-   (mov_hardfloat64): Likewise.
-   (mov_softfloat64): Likewise.
-   (@tablejump_insn_normal); Likewise.
-   (@tablejump_insn_nospec); Likewise.
-   * config/rs6000/rs6000.opt (-mtar): New option.
-   * doc/invoke.texi (RS/6000 options): Document -mtar.
-   * lra-constraints.md (lra_constraints): Print out insn that we can't
-   generate reloads for.
+ Branch work165-tar, patch #204 was reverted 

+ Branch work165-tar, patch #203 was reverted 
==

[gcc(refs/users/meissner/heads/work165-tar)] Add -mtar, -mintspr, and -mmfspr, but don't enable them.

2024-05-14 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:56fb71d854c67b711565f520a8c55dcb2e647f1c

commit 56fb71d854c67b711565f520a8c55dcb2e647f1c
Author: Michael Meissner 
Date:   Tue May 14 22:08:31 2024 -0400

Add -mtar, -mintspr, and -mmfspr, but don't enable them.

gcc/

2024-05-14  Michael Meissner  

* config/rs6000/constraints.md (h constraint): Add documentation 
for TAR
register.
(wt constraint): New constraint.
* config/rs6000/rs6000-cpus.def (POWERPC_MASKS): Add -mtar, 
-mintspr,
and -mmfspr.
* config/rs6000/rs6000.cc (rs6000_reg_names): Add TAR register.
(alt_reg_names): Likewise.
(rs6000_hard_regno_mode_ok_uncached): Add support for -mintspr.
(rs6000_debug_reg_global): Print information about the TAR register 
and
the wt constraint.
(rs6000_init_hard_regno_mode_ok): Setup the TAR register.  Set up 
the wt
constraint if -mtar.
(rs6000_option_override_internal): If -mtar, make sure we are 
running on
at least a power9.
(rs6000_conditional_register_usage): Enable TAR register if -mtar.
(print_operand): Handle the TAR register.
(rs6000_debugger_regno): Likewise.
(rs6000_opt_masks): Add -mtar, -mintspr, and -mmfspr.
* config/rs6000/rs6000.h (FIRST_PSEUDO_REGISTER): Add TAR register.
(FIXED_REGISTERS): Likewise.
(CALL_REALLY_USED_REGISTERS): Likewise.
(REG_ALLOC_ORDER): Likewise.
(enum reg_class): Add TAR_REGS register class.
(REG_CLASS_NAMES): Likewise.
(REG_CLASS_CONTENTS): Likewise.
(enum r6000_reg_class_enum): Add wt constraint.
(rs6000_reg_names): Add TAR register.
* config/rs6000/rs6000.md (TAR_REGNO): New constant.
(mov_internal): Add support for the TAR register.
(movcc_): Likewise.
(movsf_hardfloat): Likewise.
(movsf_hardfloat): Likewise.
(movsd_hardfloat): Likewise.
(mov_hardfloat64): Likewise.
(mov_softfloat64): Likewise.
(@tablejump_insn_normal): Likewise.
(@tablejump_insn_nospec): Likewise.
* config/rs6000/rs6000.opt (-mtar): New option.
(-mmfspr): Likewise.
(-mintspr): Likewise.

gcc/testsuite/

2024-05-14  Michael Meissner  

* gcc.target/powerpc/ppc-switch-1.c: Update test for the TAR 
register.
* gcc.target/powerpc/pr51513.c: Likewise.
* gcc.target/powerpc/safe-indirect-jump-3.c: Likewise.

Diff:
---
 gcc/config/rs6000/constraints.md   |  5 +-
 gcc/config/rs6000/rs6000-cpus.def  |  3 +
 gcc/config/rs6000/rs6000.cc| 78 +++---
 gcc/config/rs6000/rs6000.h | 31 +
 gcc/config/rs6000/rs6000.md| 23 ---
 gcc/config/rs6000/rs6000.opt   | 12 
 gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c|  4 +-
 gcc/testsuite/gcc.target/powerpc/pr51513.c |  4 +-
 .../gcc.target/powerpc/safe-indirect-jump-3.c  |  2 +-
 9 files changed, 125 insertions(+), 37 deletions(-)

diff --git a/gcc/config/rs6000/constraints.md b/gcc/config/rs6000/constraints.md
index 369a7b75042d..14f0465d7ae5 100644
--- a/gcc/config/rs6000/constraints.md
+++ b/gcc/config/rs6000/constraints.md
@@ -57,7 +57,7 @@
   "@internal A compatibility alias for @code{wa}.")
 
 (define_register_constraint "h" "SPECIAL_REGS"
-  "@internal A special register (@code{vrsave}, @code{ctr}, or @code{lr}).")
+  "@internal A special register (@code{vrsave}, @code{ctr}, @code{lr} or 
@code{tar}).")
 
 (define_register_constraint "c" "CTR_REGS"
   "The count register, @code{ctr}.")
@@ -91,6 +91,9 @@
   "@internal Like @code{r}, if @option{-mpowerpc64} is used; otherwise,
@code{NO_REGS}.")
 
+(define_register_constraint "wt" "rs6000_constraints[RS6000_CONSTRAINT_wt]"
+  "The tar register, @code{tar}.")
+
 (define_register_constraint "wx" "rs6000_constraints[RS6000_CONSTRAINT_wx]"
   "@internal Like @code{d}, if @option{-mpowerpc-gfxopt} is used; otherwise,
@code{NO_REGS}.")
diff --git a/gcc/config/rs6000/rs6000-cpus.def 
b/gcc/config/rs6000/rs6000-cpus.def
index d625dbeb91fd..0907930b2d8b 100644
--- a/gcc/config/rs6000/rs6000-cpus.def
+++ b/gcc/config/rs6000/rs6000-cpus.def
@@ -133,8 +133,10 @@
 | OPTION_MASK_POWER11  \
 | OPTION_MASK_P10_FUSION   \
 | OPTION_MASK_HTM  \
+| OPTION_MASK_INTSPR   \
 | OPTION_MASK_ISEL \
 | OPTION_MASK_MFCRF\
+| O

[gcc(refs/users/meissner/heads/work165-tar)] Update ChangeLog.*

2024-05-14 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:1fbe8c58bd936a87c828b93b64f2d17c01f6bb74

commit 1fbe8c58bd936a87c828b93b64f2d17c01f6bb74
Author: Michael Meissner 
Date:   Tue May 14 22:09:50 2024 -0400

Update ChangeLog.*

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

diff --git a/gcc/ChangeLog.tar b/gcc/ChangeLog.tar
index 5e1035a5f9f6..9296af6ab567 100644
--- a/gcc/ChangeLog.tar
+++ b/gcc/ChangeLog.tar
@@ -1,3 +1,60 @@
+ Branch work165-tar, patch #210 
+
+Add -mtar, -mintspr, and -mmfspr, but don't enable them.
+
+gcc/
+
+2024-05-14  Michael Meissner  
+
+   * config/rs6000/constraints.md (h constraint): Add documentation for TAR
+   register.
+   (wt constraint): New constraint.
+   * config/rs6000/rs6000-cpus.def (POWERPC_MASKS): Add -mtar, -mintspr,
+   and -mmfspr.
+   * config/rs6000/rs6000.cc (rs6000_reg_names): Add TAR register.
+   (alt_reg_names): Likewise.
+   (rs6000_hard_regno_mode_ok_uncached): Add support for -mintspr.
+   (rs6000_debug_reg_global): Print information about the TAR register and
+   the wt constraint.
+   (rs6000_init_hard_regno_mode_ok): Setup the TAR register.  Set up the wt
+   constraint if -mtar.
+   (rs6000_option_override_internal): If -mtar, make sure we are running on
+   at least a power9.
+   (rs6000_conditional_register_usage): Enable TAR register if -mtar.
+   (print_operand): Handle the TAR register.
+   (rs6000_debugger_regno): Likewise.
+   (rs6000_opt_masks): Add -mtar, -mintspr, and -mmfspr.
+   * config/rs6000/rs6000.h (FIRST_PSEUDO_REGISTER): Add TAR register.
+   (FIXED_REGISTERS): Likewise.
+   (CALL_REALLY_USED_REGISTERS): Likewise.
+   (REG_ALLOC_ORDER): Likewise.
+   (enum reg_class): Add TAR_REGS register class.
+   (REG_CLASS_NAMES): Likewise.
+   (REG_CLASS_CONTENTS): Likewise.
+   (enum r6000_reg_class_enum): Add wt constraint.
+   (rs6000_reg_names): Add TAR register.
+   * config/rs6000/rs6000.md (TAR_REGNO): New constant.
+   (mov_internal): Add support for the TAR register.
+   (movcc_): Likewise.
+   (movsf_hardfloat): Likewise.
+   (movsf_hardfloat): Likewise.
+   (movsd_hardfloat): Likewise.
+   (mov_hardfloat64): Likewise.
+   (mov_softfloat64): Likewise.
+   (@tablejump_insn_normal): Likewise.
+   (@tablejump_insn_nospec): Likewise.
+   * config/rs6000/rs6000.opt (-mtar): New option.
+   (-mmfspr): Likewise.
+   (-mintspr): Likewise.
+
+gcc/testsuite/
+
+2024-05-14  Michael Meissner  
+
+   * gcc.target/powerpc/ppc-switch-1.c: Update test for the TAR register.
+   * gcc.target/powerpc/pr51513.c: Likewise.
+   * gcc.target/powerpc/safe-indirect-jump-3.c: Likewise.
+
  Branch work165-tar, patch #204 was reverted 

  Branch work165-tar, patch #203 was reverted 

  Branch work165-tar, patch #202 was reverted 



[gcc r15-498] c++: lvalueness of non-dependent assignment expr [PR114994]

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

commit r15-498-gc6cc6d4741a880109c4e0e64d5a189687fb526f6
Author: Patrick Palka 
Date:   Tue May 14 22:55:16 2024 -0400

c++: lvalueness of non-dependent assignment expr [PR114994]

r14-4111-g6e92a6a2a72d3b made us check non-dependent simple assignment
expressions ahead of time and give them a type, as was already done for
compound assignments.  Unlike for compound assignments however, if a
simple assignment resolves to an operator overload we represent it as a
(typed) MODOP_EXPR instead of a CALL_EXPR to the selected overload.
(I reckoned this was at worst a pessimization -- we'll just have to repeat
overload resolution at instantiatiation time.)

But this turns out to break the below testcase ultimately because
MODOP_EXPR (of non-reference type) is always treated as an lvalue
according to lvalue_kind, which is incorrect for the MODOP_EXPR
representing x=42.

We can fix this by representing such class assignment expressions as
CALL_EXPRs as well, but this turns out to require some tweaking of our
-Wparentheses warning logic and may introduce other fallout making it
unsuitable for backporting.

So this patch instead fixes lvalue_kind to consider the type of a
MODOP_EXPR representing a class assignment.

PR c++/114994

gcc/cp/ChangeLog:

* tree.cc (lvalue_kind) : For a class
assignment, consider the result type.

gcc/testsuite/ChangeLog:

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

Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/tree.cc  |  5 -
 gcc/testsuite/g++.dg/template/non-dependent32.C | 18 ++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index f1a23ffe8179..9d37d255d8d5 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -275,7 +275,10 @@ lvalue_kind (const_tree ref)
   /* We expect to see unlowered MODOP_EXPRs only during
 template processing.  */
   gcc_assert (processing_template_decl);
-  return clk_ordinary;
+  if (CLASS_TYPE_P (TREE_TYPE (TREE_OPERAND (ref, 0
+   goto default_;
+  else
+   return clk_ordinary;
 
 case MODIFY_EXPR:
 case TYPEID_EXPR:
diff --git a/gcc/testsuite/g++.dg/template/non-dependent32.C 
b/gcc/testsuite/g++.dg/template/non-dependent32.C
new file mode 100644
index ..54252c7dfaf9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/non-dependent32.C
@@ -0,0 +1,18 @@
+// PR c++/114994
+// { dg-do compile { target c++11 } }
+
+struct udl_arg {
+  udl_arg operator=(int);
+};
+
+void f(udl_arg&&);
+
+template
+void g() {
+  udl_arg x;
+  f(x=42); // { dg-bogus "cannot bind" }
+}
+
+int main() {
+  g();
+}


[gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [to-be-committed, RISC-V] Remove redundant AND in shift-add sequence

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:9de32107d731fbbf15096d065bf706bb9aff94f6

commit 9de32107d731fbbf15096d065bf706bb9aff94f6
Author: Jeff Law 
Date:   Tue May 14 18:17:59 2024 -0600

[to-be-committed,RISC-V] Remove redundant AND in shift-add sequence

So this patch allows us to eliminate an redundant AND in some shift-add
style sequences.   I think the testcase was reduced from xz by the RAU
team, but I'm not highly confident of that.

Specifically the AND is masking off the upper 32 bits of the un-shifted
value and there's an outer SIGN_EXTEND from SI to DI.  However in the
RTL it's working on the post-shifted value, so the constant is left
shifted, so we have to account for that in the pattern's condition.

We can just drop the AND in this case.  So instead we do a 64bit shift,
then a sign extending ADD utilizing the low part of that 64bit shift result.

This has run through Ventana's CI as well as my own.  I'll wait for it
to run through the larger CI system before pushing.

Jeff

gcc/
* config/riscv/riscv.md: Add pattern for sign extended shift-add
sequence with a masked input.

gcc/testsuite

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

(cherry picked from commit 32ff344d57d56fddb66c4976b5651345d40b7157)

Diff:
---
 gcc/config/riscv/riscv.md| 25 +
 gcc/testsuite/gcc.target/riscv/shift-add-2.c | 16 
 2 files changed, 41 insertions(+)

diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index 893040f28541..ee15c63db107 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -4120,6 +4120,31 @@
   [(set_attr "type" "load")
(set (attr "length") (const_int 8))])
 
+;; The AND is redunant here.  It always turns off the high 32 bits  and the
+;; low number of bits equal to the shift count.  Those upper 32 bits will be
+;; reset by the SIGN_EXTEND at the end.
+;;
+;; One could argue combine should have realized this and simplified what it
+;; presented to the backend.  But we can obviously cope with what it gave us.
+(define_insn_and_split ""
+  [(set (match_operand:DI 0 "register_operand" "=r")
+   (sign_extend:DI
+ (plus:SI (subreg:SI
+(and:DI
+  (ashift:DI (match_operand:DI 1 "register_operand" "r")
+ (match_operand 2 "const_int_operand" "n"))
+  (match_operand 3 "const_int_operand" "n")) 0)
+  (match_operand:SI 4 "register_operand" "r"
+   (clobber (match_scratch:DI 5 "=&r"))]
+  "TARGET_64BIT
+   && (INTVAL (operands[3]) | ((1 << INTVAL (operands[2])) - 1)) == 0x"
+  "#"
+  "&& reload_completed"
+  [(set (match_dup 5) (ashift:DI (match_dup 1) (match_dup 2)))
+   (set (match_dup 0) (sign_extend:DI (plus:SI (match_dup 6) (match_dup 4]
+  "{ operands[6] = gen_lowpart (SImode, operands[5]); }"
+  [(set_attr "type" "arith")])
+
 (include "bitmanip.md")
 (include "crypto.md")
 (include "sync.md")
diff --git a/gcc/testsuite/gcc.target/riscv/shift-add-2.c 
b/gcc/testsuite/gcc.target/riscv/shift-add-2.c
new file mode 100644
index ..87439858e59e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/shift-add-2.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zba_zbb_zbs -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
+
+int sub2(int a, long long b) {
+  b = (b << 32) >> 31;
+  unsigned int x = a + b;
+  return x;
+}
+
+
+/* { dg-final { scan-assembler-times "\tslli\t" 1 } } */
+/* { dg-final { scan-assembler-times "\taddw\t" 1 } } */
+/* { dg-final { scan-assembler-not "\tsrai\t" } } */
+/* { dg-final { scan-assembler-not "\tsh.add\t" } } */
+


[gcc r15-499] x86: Add 3-instruction subroutine vector shift for V16QI in ix86_expand_vec_perm_const_1 [PR107563]

2024-05-14 Thread hongtao Liu via Gcc-cvs
https://gcc.gnu.org/g:a71f90c5a7ae2942083921033cb23dcd63e70525

commit r15-499-ga71f90c5a7ae2942083921033cb23dcd63e70525
Author: Levy Hsu 
Date:   Thu May 9 16:50:56 2024 +0800

x86: Add 3-instruction subroutine vector shift for V16QI in 
ix86_expand_vec_perm_const_1 [PR107563]

Hi All

We've introduced a new subroutine in ix86_expand_vec_perm_const_1
to optimize vector shifting for the V16QI type on x86.
This patch uses a three-instruction sequence psrlw, psllw, and por
to handle specific vector shuffle operations more efficiently.
The change aims to improve assembly code generation for configurations
supporting SSE2.

Bootstrapped and tested on x86_64-linux-gnu, OK for trunk?

Best
Levy

gcc/ChangeLog:

PR target/107563
* config/i386/i386-expand.cc (expand_vec_perm_psrlw_psllw_por): New
subroutine.
(ix86_expand_vec_perm_const_1): Call 
expand_vec_perm_psrlw_psllw_por.

gcc/testsuite/ChangeLog:

PR target/107563
* g++.target/i386/pr107563-a.C: New test.
* g++.target/i386/pr107563-b.C: New test.

Diff:
---
 gcc/config/i386/i386-expand.cc | 64 ++
 gcc/testsuite/g++.target/i386/pr107563-a.C | 13 ++
 gcc/testsuite/g++.target/i386/pr107563-b.C | 12 ++
 3 files changed, 89 insertions(+)

diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index 1ab22fe79736..e846a946de07 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -22362,6 +22362,67 @@ expand_vec_perm_2perm_pblendv (struct 
expand_vec_perm_d *d, bool two_insn)
   return true;
 }
 
+/* A subroutine of ix86_expand_vec_perm_const_1.
+   Implement a permutation with psrlw, psllw and por.
+   It handles case:
+   __builtin_shufflevector (v,v,1,0,3,2,5,4,7,6,9,8,11,10,13,12,15,14);
+   __builtin_shufflevector (v,v,1,0,3,2,5,4,7,6); */
+
+static bool
+expand_vec_perm_psrlw_psllw_por (struct expand_vec_perm_d *d)
+{
+  unsigned i;
+  rtx (*gen_shr) (rtx, rtx, rtx);
+  rtx (*gen_shl) (rtx, rtx, rtx);
+  rtx (*gen_or) (rtx, rtx, rtx);
+  machine_mode mode = VOIDmode;
+
+  if (!TARGET_SSE2 || !d->one_operand_p)
+return false;
+
+  switch (d->vmode)
+{
+case E_V8QImode:
+  if (!TARGET_MMX_WITH_SSE)
+   return false;
+  mode = V4HImode;
+  gen_shr = gen_ashrv4hi3;
+  gen_shl = gen_ashlv4hi3;
+  gen_or = gen_iorv4hi3;
+  break;
+case E_V16QImode:
+  mode = V8HImode;
+  gen_shr = gen_vlshrv8hi3;
+  gen_shl = gen_vashlv8hi3;
+  gen_or = gen_iorv8hi3;
+  break;
+default: return false;
+}
+
+  if (!rtx_equal_p (d->op0, d->op1))
+return false;
+
+  for (i = 0; i < d->nelt; i += 2)
+if (d->perm[i] != i + 1 || d->perm[i + 1] != i)
+  return false;
+
+  if (d->testing_p)
+return true;
+
+  rtx tmp1 = gen_reg_rtx (mode);
+  rtx tmp2 = gen_reg_rtx (mode);
+  rtx op0 = force_reg (d->vmode, d->op0);
+
+  emit_move_insn (tmp1, lowpart_subreg (mode, op0, d->vmode));
+  emit_move_insn (tmp2, lowpart_subreg (mode, op0, d->vmode));
+  emit_insn (gen_shr (tmp1, tmp1, GEN_INT (8)));
+  emit_insn (gen_shl (tmp2, tmp2, GEN_INT (8)));
+  emit_insn (gen_or (tmp1, tmp1, tmp2));
+  emit_move_insn (d->target, lowpart_subreg (d->vmode, tmp1, mode));
+
+  return true;
+}
+
 /* A subroutine of ix86_expand_vec_perm_const_1.  Implement a V4DF
permutation using two vperm2f128, followed by a vshufpd insn blending
the two vectors together.  */
@@ -23782,6 +23843,9 @@ ix86_expand_vec_perm_const_1 (struct expand_vec_perm_d 
*d)
   if (expand_vec_perm_2perm_pblendv (d, false))
 return true;
 
+  if (expand_vec_perm_psrlw_psllw_por (d))
+return true;
+
   /* Try sequences of four instructions.  */
 
   if (expand_vec_perm_even_odd_trunc (d))
diff --git a/gcc/testsuite/g++.target/i386/pr107563-a.C 
b/gcc/testsuite/g++.target/i386/pr107563-a.C
new file mode 100755
index ..605c1bdf814b
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/pr107563-a.C
@@ -0,0 +1,13 @@
+/* PR target/107563.C */
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-std=c++2b -O3 -msse2" } */
+/* { dg-final { scan-assembler-times "psllw" 1 } } */
+/* { dg-final { scan-assembler-times "psraw" 1 } } */
+/* { dg-final { scan-assembler-times "por" 1 } } */
+
+using temp_vec_type2 [[__gnu__::__vector_size__(8)]] = char;
+
+void foo2(temp_vec_type2& v) noexcept
+{
+  v = __builtin_shufflevector(v, v, 1, 0, 3, 2, 5, 4, 7, 6);
+}
diff --git a/gcc/testsuite/g++.target/i386/pr107563-b.C 
b/gcc/testsuite/g++.target/i386/pr107563-b.C
new file mode 100755
index ..0ce3e8263bb5
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/pr107563-b.C
@@ -0,0 +1,12 @@
+/* PR target/107563.C */
+/* { dg-options "-std=c++2b -O3 -msse2" } */
+/* { dg-final { scan-assembler-times "psllw" 1 } } */
+/* { dg-final { scan-assembler-times "psrlw" 1 } } */
+/* {

[gcc r15-500] [committed] Fix rv32 issues with recent zicboz work

2024-05-14 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:e410ad74e5e4589aeb666aa298b2f933e7b5d9e7

commit r15-500-ge410ad74e5e4589aeb666aa298b2f933e7b5d9e7
Author: Jeff Law 
Date:   Tue May 14 22:50:15 2024 -0600

[committed] Fix rv32 issues with recent zicboz work

I should have double-checked the CI system before pushing Christoph's 
patches
for memset-zero.  While I thought I'd checked CI state, I must have been
looking at the wrong patch from Christoph.

Anyway, this fixes the rv32 ICEs and disables one of the tests for rv32.

The test would need a revamp for rv32 as the expected output is all rv64 
code
using "sd" instructions.  I'm just not vested deeply enough into rv32 to 
adjust
the test to work in that environment though it should be fairly trivial to 
copy
the test and provide new expected output if someone cares enough.

Verified this fixes the rv32 failures in my tester:
> New tests that FAIL (6 tests):
>
> unix/-march=rv32gcv: gcc: gcc.target/riscv/cmo-zicboz-zic64-1.c   -O1  
(internal compiler error: in extract_insn, at recog.cc:2812)
> unix/-march=rv32gcv: gcc: gcc.target/riscv/cmo-zicboz-zic64-1.c   -O1  
(test for excess errors)
> unix/-march=rv32gcv: gcc: gcc.target/riscv/cmo-zicboz-zic64-1.c   -O2  
(internal compiler error: in extract_insn, at recog.cc:2812)
> unix/-march=rv32gcv: gcc: gcc.target/riscv/cmo-zicboz-zic64-1.c   -O2  
(test for excess errors)
> unix/-march=rv32gcv: gcc: gcc.target/riscv/cmo-zicboz-zic64-1.c   -O3 -g  
(internal compiler error: in extract_insn, at recog.cc:2812)
> unix/-march=rv32gcv: gcc: gcc.target/riscv/cmo-zicboz-zic64-1.c   -O3 -g  
(test for excess errors)

And after the ICE is fixed, these are eliminated by only running the test 
for
rv64:

> New tests that FAIL (3 tests):
>
> unix/-march=rv32gcv: gcc: gcc.target/riscv/cmo-zicboz-zic64-1.c   -O1   
check-function-bodies clear_buf_123
> unix/-march=rv32gcv: gcc: gcc.target/riscv/cmo-zicboz-zic64-1.c   -O2   
check-function-bodies clear_buf_123
> unix/-march=rv32gcv: gcc: gcc.target/riscv/cmo-zicboz-zic64-1.c   -O3 -g  
 check-function-bodies clear_buf_123

gcc/
* config/riscv/riscv-string.cc
(riscv_expand_block_clear_zicboz_zic64b): Handle rv32 correctly.

gcc/testsuite

* gcc.target/riscv/cmo-zicboz-zic64-1.c: Don't run on rv32.

Diff:
---
 gcc/config/riscv/riscv-string.cc| 5 -
 gcc/testsuite/gcc.target/riscv/cmo-zicboz-zic64-1.c | 3 +--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/gcc/config/riscv/riscv-string.cc b/gcc/config/riscv/riscv-string.cc
index 87f5fdee3c14..b515f44d17ae 100644
--- a/gcc/config/riscv/riscv-string.cc
+++ b/gcc/config/riscv/riscv-string.cc
@@ -827,7 +827,10 @@ riscv_expand_block_clear_zicboz_zic64b (rtx dest, rtx 
length)
 {
   rtx mem = adjust_address (dest, BLKmode, offset);
   rtx addr = force_reg (Pmode, XEXP (mem, 0));
-  emit_insn (gen_riscv_zero_di (addr));
+  if (TARGET_64BIT)
+   emit_insn (gen_riscv_zero_di (addr));
+  else
+   emit_insn (gen_riscv_zero_si (addr));
   offset += cbo_bytes;
 }
 
diff --git a/gcc/testsuite/gcc.target/riscv/cmo-zicboz-zic64-1.c 
b/gcc/testsuite/gcc.target/riscv/cmo-zicboz-zic64-1.c
index c2d79eb7ae68..6d4535287d08 100644
--- a/gcc/testsuite/gcc.target/riscv/cmo-zicboz-zic64-1.c
+++ b/gcc/testsuite/gcc.target/riscv/cmo-zicboz-zic64-1.c
@@ -1,6 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-march=rv64gc_zic64b_zicboz" { target { rv64 } } } */
-/* { dg-options "-march=rv32gc_zic64b_zicboz" { target { rv32 } } } */
+/* { dg-options "-march=rv64gc_zic64b_zicboz -mabi=lp64d" } */
 /* { dg-skip-if "" { *-*-* } {"-O0" "-Os" "-Og" "-Oz" "-flto" } } */
 /* { dg-final { check-function-bodies "**" "" } } */
 /* { dg-allow-blank-lines-in-output 1 } */