[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Silence uninitialized warning.

2024-12-07 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:7c71659125082c548e0f53bad7ee21de0844ad17

commit 7c71659125082c548e0f53bad7ee21de0844ad17
Author: Mikael Morin 
Date:   Fri Dec 6 22:27:47 2024 +0100

Silence uninitialized warning.

Diff:
---
 gcc/fortran/trans-intrinsic.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 1b36ac6e5ac1..890e847c0770 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -11771,7 +11771,7 @@ static gfc_ss *
 nest_loop_dimension (gfc_ss *ss, int dim)
 {
   int ss_dim, i;
-  gfc_ss *new_ss, *prev_ss = gfc_ss_terminator;
+  gfc_ss *new_ss = nullptr, *prev_ss = gfc_ss_terminator;
   gfc_loopinfo *new_loop;
 
   gcc_assert (ss != gfc_ss_terminator);


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Utilisation méthode initialisation descripteur gfc_trans_deferred_array

2024-12-07 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:465827c5081a4abe42820829fcd3ad840ef6898c

commit 465827c5081a4abe42820829fcd3ad840ef6898c
Author: Mikael Morin 
Date:   Fri Dec 6 22:05:58 2024 +0100

Utilisation méthode initialisation descripteur gfc_trans_deferred_array

Diff:
---
 gcc/fortran/gfortran.h |   1 +
 gcc/fortran/primary.cc |  87 +++
 gcc/fortran/trans-array.cc | 169 -
 3 files changed, 179 insertions(+), 78 deletions(-)

diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index d08439019a38..79d768a8d285 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -4023,6 +4023,7 @@ const char *gfc_dt_lower_string (const char *);
 const char *gfc_dt_upper_string (const char *);
 
 /* primary.cc */
+symbol_attribute gfc_symbol_attr (gfc_symbol *);
 symbol_attribute gfc_variable_attr (gfc_expr *, gfc_typespec *);
 symbol_attribute gfc_expr_attr (gfc_expr *);
 symbol_attribute gfc_caf_attr (gfc_expr *, bool i = false, bool *r = NULL);
diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index 1db27929eebd..cbc1eafdf768 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -2866,42 +2866,14 @@ check_substring:
 }
 
 
-/* Given an expression that is a variable, figure out what the
-   ultimate variable's type and attribute is, traversing the reference
-   structures if necessary.
-
-   This subroutine is trickier than it looks.  We start at the base
-   symbol and store the attribute.  Component references load a
-   completely new attribute.
-
-   A couple of rules come into play.  Subobjects of targets are always
-   targets themselves.  If we see a component that goes through a
-   pointer, then the expression must also be a target, since the
-   pointer is associated with something (if it isn't core will soon be
-   dumped).  If we see a full part or section of an array, the
-   expression is also an array.
-
-   We can have at most one full array reference.  */
-
 symbol_attribute
-gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts)
+gfc_symbol_attr (gfc_symbol *sym)
 {
-  int dimension, codimension, pointer, allocatable, target, optional;
+  int dimension, codimension, pointer, allocatable, target;
   symbol_attribute attr;
-  gfc_ref *ref;
-  gfc_symbol *sym;
-  gfc_component *comp;
-  bool has_inquiry_part;
-
-  if (expr->expr_type != EXPR_VARIABLE
-  && expr->expr_type != EXPR_FUNCTION
-  && !(expr->expr_type == EXPR_NULL && expr->ts.type != BT_UNKNOWN))
-gfc_internal_error ("gfc_variable_attr(): Expression isn't a variable");
 
-  sym = expr->symtree->n.sym;
   attr = sym->attr;
 
-  optional = attr.optional;
   if (sym->ts.type == BT_CLASS && sym->attr.class_ok && sym->ts.u.derived)
 {
   dimension = CLASS_DATA (sym)->attr.dimension;
@@ -2937,6 +2909,61 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts)
target = 0;
 }
 
+  attr.dimension = dimension;
+  attr.codimension = codimension;
+  attr.pointer = pointer;
+  attr.allocatable = allocatable;
+  attr.target = target;
+  attr.save = sym->attr.save;
+
+  return attr;
+}
+
+
+/* Given an expression that is a variable, figure out what the
+   ultimate variable's type and attribute is, traversing the reference
+   structures if necessary.
+
+   This subroutine is trickier than it looks.  We start at the base
+   symbol and store the attribute.  Component references load a
+   completely new attribute.
+
+   A couple of rules come into play.  Subobjects of targets are always
+   targets themselves.  If we see a component that goes through a
+   pointer, then the expression must also be a target, since the
+   pointer is associated with something (if it isn't core will soon be
+   dumped).  If we see a full part or section of an array, the
+   expression is also an array.
+
+   We can have at most one full array reference.  */
+
+symbol_attribute
+gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts)
+{
+  int dimension, codimension, pointer, allocatable, target, optional;
+  symbol_attribute attr;
+  gfc_ref *ref;
+  gfc_symbol *sym;
+  gfc_component *comp;
+  bool has_inquiry_part;
+
+  if (expr->expr_type != EXPR_VARIABLE
+  && expr->expr_type != EXPR_FUNCTION
+  && !(expr->expr_type == EXPR_NULL && expr->ts.type != BT_UNKNOWN))
+gfc_internal_error ("gfc_variable_attr(): Expression isn't a variable");
+
+  sym = expr->symtree->n.sym;
+  attr = gfc_symbol_attr (sym);
+
+  attr = sym->attr;
+
+  optional = attr.optional;
+  dimension = attr.dimension;
+  codimension = attr.codimension;
+  pointer = attr.pointer;
+  allocatable = attr.allocatable;
+  target = attr.target;
+
   if (ts != NULL && expr->ts.type == BT_UNKNOWN)
 *ts = sym->ts;
 
diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 60c922bb871d..67da66268816 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -614,52 +614,122 @@ get_size_info (gfc_typespec &ts)
 
 
 static tree
-build_dtype (gfc_t

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Creation méthode initialisation descripteur

2024-12-07 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:6ee66376a1b8c97bd0be0eb0a51b90dabbaee58b

commit 6ee66376a1b8c97bd0be0eb0a51b90dabbaee58b
Author: Mikael Morin 
Date:   Thu Dec 5 20:30:08 2024 +0100

Creation méthode initialisation descripteur

Diff:
---
 gcc/fortran/expr.cc|  25 ++---
 gcc/fortran/trans-array.cc | 136 +
 2 files changed, 154 insertions(+), 7 deletions(-)

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index a997bdae726a..da63c3970938 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -5386,27 +5386,38 @@ gfc_get_full_arrayspec_from_expr (gfc_expr *expr)
   gfc_ref *ref;
 
   if (expr->rank == 0)
-return NULL;
+return nullptr;
 
   /* Follow any component references.  */
   if (expr->expr_type == EXPR_VARIABLE
   || expr->expr_type == EXPR_CONSTANT)
 {
-  if (expr->symtree)
-   as = expr->symtree->n.sym->as;
+  gfc_symbol *sym = expr->symtree ? expr->symtree->n.sym : nullptr;
+  if (sym
+ && sym->ts.type == BT_CLASS)
+   as = CLASS_DATA (sym)->as;
+  else if (sym)
+   as = sym->as;
   else
-   as = NULL;
+   as = nullptr;
 
   for (ref = expr->ref; ref; ref = ref->next)
{
  switch (ref->type)
{
case REF_COMPONENT:
- as = ref->u.c.component->as;
+ {
+   gfc_component *comp = ref->u.c.component;
+   if (comp->ts.type == BT_CLASS)
+ as = CLASS_DATA (comp)->as;
+   else
+ as = comp->as;
+ }
  continue;
 
case REF_SUBSTRING:
case REF_INQUIRY:
+ as = nullptr;
  continue;
 
case REF_ARRAY:
@@ -5416,7 +5427,7 @@ gfc_get_full_arrayspec_from_expr (gfc_expr *expr)
  case AR_ELEMENT:
  case AR_SECTION:
  case AR_UNKNOWN:
-   as = NULL;
+   as = nullptr;
continue;
 
  case AR_FULL:
@@ -5428,7 +5439,7 @@ gfc_get_full_arrayspec_from_expr (gfc_expr *expr)
}
 }
   else
-as = NULL;
+as = nullptr;
 
   return as;
 }
diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index a458af322ce8..60c922bb871d 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -543,6 +543,142 @@ gfc_conv_descriptor_ubound_set (stmtblock_t *block, tree 
desc,
   gfc_add_modify (block, t, fold_convert (TREE_TYPE (t), value));
 }
 
+
+static int
+get_type_info (const gfc_typespec &ts)
+{
+  switch (ts.type)
+{
+case BT_INTEGER:
+case BT_LOGICAL:
+case BT_REAL:
+case BT_COMPLEX:
+case BT_DERIVED:
+case BT_CHARACTER:
+case BT_CLASS:
+case BT_VOID:
+case BT_UNSIGNED:
+  return ts.type;
+
+case BT_PROCEDURE:
+case BT_ASSUMED:
+  return BT_VOID;
+
+default:
+  gcc_unreachable ();
+  break;
+}
+
+  return BT_UNKNOWN;
+}
+
+
+static tree
+get_size_info (gfc_typespec &ts)
+{
+  switch (ts.type)
+{
+case BT_INTEGER:
+case BT_LOGICAL:
+case BT_REAL:
+case BT_COMPLEX:
+case BT_DERIVED:
+case BT_UNSIGNED:
+  return size_in_bytes (TREE_TYPE (gfc_typenode_for_spec (&ts)));
+
+case BT_CHARACTER:
+  {
+   tree type = gfc_typenode_for_spec (&ts);
+   if (POINTER_TYPE_P (type))
+ type = TREE_TYPE (type);
+   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
+   tree elt_type = TREE_TYPE (type);
+   tree len = ts.u.cl->backend_decl;
+   return fold_build2_loc (input_location, MULT_EXPR, size_type_node,
+   size_in_bytes (elt_type),
+   len);
+  }
+
+case BT_CLASS:
+  return get_size_info (ts.u.derived->components->ts);
+
+case BT_PROCEDURE:
+case BT_VOID:
+case BT_ASSUMED:
+default:
+  gcc_unreachable ();
+}
+
+  return NULL_TREE;
+}
+
+
+static tree
+build_dtype (gfc_typespec &ts, int rank, const symbol_attribute &)
+{
+  tree type = get_dtype_type_node ();
+
+  tree fields = TYPE_FIELDS (type);
+
+  tree elem_len_field = gfc_advance_chain (fields, GFC_DTYPE_ELEM_LEN);
+  tree elem_len_val = get_size_info (ts);
+
+  tree version_field = gfc_advance_chain (fields, GFC_DTYPE_VERSION);
+  tree version_val = build_int_cst (TREE_TYPE (version_field), 0);
+
+  tree rank_field = gfc_advance_chain (fields, GFC_DTYPE_RANK);
+  tree rank_val = build_int_cst (TREE_TYPE (rank_field), rank);
+
+  tree type_info_field = gfc_advance_chain (fields, GFC_DTYPE_TYPE);
+  tree type_info_val = build_int_cst (TREE_TYPE (type_info_field),
+ get_type_info (ts));
+
+  return build_constructor_va (type, 4,
+  elem_len_field, elem_len_val,
+  version_field, version_val,
+  rank_field, rank_val,
+  type_info

[gcc r15-6012] AVR: Better location for late (during final) diagnostic.

2024-12-07 Thread Georg-Johann Lay via Gcc-cvs
https://gcc.gnu.org/g:68e64c45380e42657ece999c9fe5b68044847e49

commit r15-6012-g68e64c45380e42657ece999c9fe5b68044847e49
Author: Georg-Johann Lay 
Date:   Sat Dec 7 19:54:02 2024 +0100

AVR: Better location for late (during final) diagnostic.

gcc/
* config/avr/avr.cc (avr_print_operand_address): Use
avr_insn_location as location for late (during final) diagnostic.

Diff:
---
 gcc/config/avr/avr.cc | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index 3544571d3dfa..7c7736781c8a 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -2538,11 +2538,17 @@ avr_print_operand_address (FILE *file, machine_mode 
/*mode*/, rtx addr)
  fprintf (file, "+" HOST_WIDE_INT_PRINT_DEC ")",
   2 * INTVAL (XEXP (x, 1)));
  if (AVR_3_BYTE_PC)
-   if (warning (0, "pointer offset from symbol maybe incorrect"))
- {
-   output_addr_const (stderr, addr);
-   fprintf (stderr, "\n");
- }
+   {
+ location_t loc = avr_insn_location != UNKNOWN_LOCATION
+   ? avr_insn_location
+   : input_location;
+ if (warning_at (loc, 0, "pointer offset from symbol may be"
+ " incorrect"))
+   {
+ output_addr_const (stderr, addr);
+ fprintf (stderr, "\n");
+   }
+   }
}
  else
{


[gcc r15-6011] PR modula2/117948: Forward procedure declaration should only be available in ISO

2024-12-07 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:41800372146f5ad15a8796b37f54965f78cc14fb

commit r15-6011-g41800372146f5ad15a8796b37f54965f78cc14fb
Author: Gaius Mulley 
Date:   Sat Dec 7 14:04:44 2024 +

PR modula2/117948: Forward procedure declaration should only be available 
in ISO

This patch restricts the forward procedure declaration to the ISO dialect.

gcc/m2/ChangeLog:

PR modula2/117948
* gm2-compiler/P1Build.bnf (ForwardDeclaration): Pass token
position of the FORWARD keyword to EndBuildForward.
* gm2-compiler/P1SymBuild.def (EndBuildForward): New parameter
forwardPos.
* gm2-compiler/P1SymBuild.mod (EndBuildForward): Issue an error at
forwardPos if the Iso boolean is false.

gcc/testsuite/ChangeLog:

PR modula2/117948
* gm2/pim/fail/forward.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/P1Build.bnf|  2 +-
 gcc/m2/gm2-compiler/P1SymBuild.def |  2 +-
 gcc/m2/gm2-compiler/P1SymBuild.mod | 12 ++--
 gcc/testsuite/gm2/pim/fail/forward.mod | 14 ++
 4 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/gcc/m2/gm2-compiler/P1Build.bnf b/gcc/m2/gm2-compiler/P1Build.bnf
index 42d034dffe7e..22476cae69d0 100644
--- a/gcc/m2/gm2-compiler/P1Build.bnf
+++ b/gcc/m2/gm2-compiler/P1Build.bnf
@@ -878,7 +878,7 @@ ProcedureDeclaration := 
   % VAR
 
 PostProcedureHeading := ProperProcedure | ForwardDeclaration =:
 
-ForwardDeclaration := "FORWARD"% 
EndBuildForward %
+ForwardDeclaration := "FORWARD"% 
EndBuildForward (GetTokenNo ()-1) %
 =:
 
 ProperProcedure := ProcedureBlock  % 
PushAutoOn %
diff --git a/gcc/m2/gm2-compiler/P1SymBuild.def 
b/gcc/m2/gm2-compiler/P1SymBuild.def
index 89ed3ad480bd..478660516fc7 100644
--- a/gcc/m2/gm2-compiler/P1SymBuild.def
+++ b/gcc/m2/gm2-compiler/P1SymBuild.def
@@ -489,7 +489,7 @@ PROCEDURE BuildProcedureHeading ;
Empty
 *)
 
-PROCEDURE EndBuildForward ;
+PROCEDURE EndBuildForward (forwardPos: CARDINAL) ;
 
 
 (*
diff --git a/gcc/m2/gm2-compiler/P1SymBuild.mod 
b/gcc/m2/gm2-compiler/P1SymBuild.mod
index 8a2ed87b3567..cd42417a3948 100644
--- a/gcc/m2/gm2-compiler/P1SymBuild.mod
+++ b/gcc/m2/gm2-compiler/P1SymBuild.mod
@@ -26,7 +26,10 @@ FROM ASCII IMPORT nul ;
 FROM NameKey IMPORT Name, WriteKey, MakeKey, KeyToCharStar, NulName ;
 FROM M2Debug IMPORT Assert, WriteDebug ;
 FROM M2LexBuf IMPORT GetFileName, GetTokenNo, UnknownTokenNo ;
-FROM M2MetaError IMPORT MetaErrorString2, MetaError0, MetaError1, MetaError2, 
MetaErrorT1, MetaErrorT2 ;
+
+FROM M2MetaError IMPORT MetaErrorString2, MetaError0, MetaError1,
+MetaError2, MetaErrorT0, MetaErrorT1, MetaErrorT2 ;
+
 FROM DynamicStrings IMPORT String, Slice, InitString, KillString, 
EqualCharStar, RIndex, Mark, ConCat ;
 FROM M2Printf IMPORT printf0, printf1, printf2 ;
 FROM M2Options IMPORT Iso ;
@@ -1064,13 +1067,18 @@ END EndBuildProcedure ;
Empty
 *)
 
-PROCEDURE EndBuildForward ;
+PROCEDURE EndBuildForward (forwardPos: CARDINAL) ;
 VAR
ProcSym: CARDINAL ;
tok: CARDINAL ;
 BEGIN
ProcSym := OperandT (1) ;
tok := OperandTok (1) ;
+   IF NOT Iso
+   THEN
+  MetaErrorT0 (forwardPos,
+   'forward declaration is only allowed in the ISO dialect of 
Modula-2')
+   END ;
IF GetProcedureDefined (ProcSym, ForwardProcedure)
THEN
   MetaErrorT1 (GetProcedureDeclaredTok (ProcSym, ForwardProcedure),
diff --git a/gcc/testsuite/gm2/pim/fail/forward.mod 
b/gcc/testsuite/gm2/pim/fail/forward.mod
new file mode 100644
index ..123e006dd434
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/fail/forward.mod
@@ -0,0 +1,14 @@
+MODULE forward ;
+
+
+PROCEDURE foo (a: CARDINAL) ; FORWARD ;
+
+PROCEDURE foo (a: CARDINAL) ;
+BEGIN
+
+END foo ;
+
+
+BEGIN
+   foo (1)
+END forward.


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

2024-12-07 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/refactor_descriptor_v01' was created in namespace 
'refs/users' pointing to:

 7c7165912508... Silence uninitialized warning.


[gcc r14-11071] [PATCH] PR modula2/117948: Forward procedure declaration should only be available in ISO

2024-12-07 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:6385000d36a8b0b9dce0b8dc92e101dfcc584ec5

commit r14-11071-g6385000d36a8b0b9dce0b8dc92e101dfcc584ec5
Author: Gaius Mulley 
Date:   Sat Dec 7 15:56:21 2024 +

[PATCH] PR modula2/117948: Forward procedure declaration should only be 
available in ISO

This patch restricts the forward procedure declaration to the ISO dialect.

gcc/m2/ChangeLog:

PR modula2/117948
* gm2-compiler/P1Build.bnf (ForwardDeclaration): Pass token
position of the FORWARD keyword to EndBuildForward.
* gm2-compiler/P1SymBuild.def (EndBuildForward): New parameter
forwardPos.
* gm2-compiler/P1SymBuild.mod (EndBuildForward): Issue an error at
forwardPos if the Iso boolean is false.

gcc/testsuite/ChangeLog:

PR modula2/117948
* gm2/pim/fail/forward.mod: New test.

(cherry picked from commit 41800372146f5ad15a8796b37f54965f78cc14fb)

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/P1Build.bnf|  2 +-
 gcc/m2/gm2-compiler/P1SymBuild.def |  2 +-
 gcc/m2/gm2-compiler/P1SymBuild.mod | 12 ++--
 gcc/testsuite/gm2/pim/fail/forward.mod | 14 ++
 4 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/gcc/m2/gm2-compiler/P1Build.bnf b/gcc/m2/gm2-compiler/P1Build.bnf
index ac96ddb383f1..f41e7780422b 100644
--- a/gcc/m2/gm2-compiler/P1Build.bnf
+++ b/gcc/m2/gm2-compiler/P1Build.bnf
@@ -878,7 +878,7 @@ ProcedureDeclaration := 
   % VAR
 
 PostProcedureHeading := ProperProcedure | ForwardDeclaration =:
 
-ForwardDeclaration := "FORWARD"% 
EndBuildForward %
+ForwardDeclaration := "FORWARD"% 
EndBuildForward (GetTokenNo ()-1) %
 =:
 
 ProperProcedure := ProcedureBlock  % 
PushAutoOn %
diff --git a/gcc/m2/gm2-compiler/P1SymBuild.def 
b/gcc/m2/gm2-compiler/P1SymBuild.def
index 89ed3ad480bd..478660516fc7 100644
--- a/gcc/m2/gm2-compiler/P1SymBuild.def
+++ b/gcc/m2/gm2-compiler/P1SymBuild.def
@@ -489,7 +489,7 @@ PROCEDURE BuildProcedureHeading ;
Empty
 *)
 
-PROCEDURE EndBuildForward ;
+PROCEDURE EndBuildForward (forwardPos: CARDINAL) ;
 
 
 (*
diff --git a/gcc/m2/gm2-compiler/P1SymBuild.mod 
b/gcc/m2/gm2-compiler/P1SymBuild.mod
index 8a2ed87b3567..cd42417a3948 100644
--- a/gcc/m2/gm2-compiler/P1SymBuild.mod
+++ b/gcc/m2/gm2-compiler/P1SymBuild.mod
@@ -26,7 +26,10 @@ FROM ASCII IMPORT nul ;
 FROM NameKey IMPORT Name, WriteKey, MakeKey, KeyToCharStar, NulName ;
 FROM M2Debug IMPORT Assert, WriteDebug ;
 FROM M2LexBuf IMPORT GetFileName, GetTokenNo, UnknownTokenNo ;
-FROM M2MetaError IMPORT MetaErrorString2, MetaError0, MetaError1, MetaError2, 
MetaErrorT1, MetaErrorT2 ;
+
+FROM M2MetaError IMPORT MetaErrorString2, MetaError0, MetaError1,
+MetaError2, MetaErrorT0, MetaErrorT1, MetaErrorT2 ;
+
 FROM DynamicStrings IMPORT String, Slice, InitString, KillString, 
EqualCharStar, RIndex, Mark, ConCat ;
 FROM M2Printf IMPORT printf0, printf1, printf2 ;
 FROM M2Options IMPORT Iso ;
@@ -1064,13 +1067,18 @@ END EndBuildProcedure ;
Empty
 *)
 
-PROCEDURE EndBuildForward ;
+PROCEDURE EndBuildForward (forwardPos: CARDINAL) ;
 VAR
ProcSym: CARDINAL ;
tok: CARDINAL ;
 BEGIN
ProcSym := OperandT (1) ;
tok := OperandTok (1) ;
+   IF NOT Iso
+   THEN
+  MetaErrorT0 (forwardPos,
+   'forward declaration is only allowed in the ISO dialect of 
Modula-2')
+   END ;
IF GetProcedureDefined (ProcSym, ForwardProcedure)
THEN
   MetaErrorT1 (GetProcedureDeclaredTok (ProcSym, ForwardProcedure),
diff --git a/gcc/testsuite/gm2/pim/fail/forward.mod 
b/gcc/testsuite/gm2/pim/fail/forward.mod
new file mode 100644
index ..123e006dd434
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/fail/forward.mod
@@ -0,0 +1,14 @@
+MODULE forward ;
+
+
+PROCEDURE foo (a: CARDINAL) ; FORWARD ;
+
+PROCEDURE foo (a: CARDINAL) ;
+BEGIN
+
+END foo ;
+
+
+BEGIN
+   foo (1)
+END forward.


[gcc r15-6013] SPARC: Add functional comments for VIS4B instructions

2024-12-07 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:1477bbe4b5002b4a00057e6dd25fcbc01fae1406

commit r15-6013-g1477bbe4b5002b4a00057e6dd25fcbc01fae1406
Author: Eric Botcazou 
Date:   Sat Dec 7 19:53:53 2024 +0100

SPARC: Add functional comments for VIS4B instructions

gcc/
* config/sparc/sparc.md (VIS4B instructions): Add comments.

Diff:
---
 gcc/config/sparc/sparc.md | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/gcc/config/sparc/sparc.md b/gcc/config/sparc/sparc.md
index 5fd18b3ca27c..159518d4b8fd 100644
--- a/gcc/config/sparc/sparc.md
+++ b/gcc/config/sparc/sparc.md
@@ -9466,10 +9466,14 @@
   [(set_attr "type" "fp")
(set_attr "fptype" "double")])
 
-;; VIS4B instructions.
+;; VIS4B instructions (specified in the unpublished OSA 2017)
 
 (define_mode_iterator DUMODE [V8QI V4HI V2SI])
 
+;; Unpack a DUMODE right-justified value from {8,4,2} consecutive bitfields of 
(opnd 1):
+;; for  0 <= (opnd 2) <= 7 : V8QI value from 8 consecutive bitfields of (opnd 
2) + 1 bits
+;; for  8 <= (opnd 2) <= 15: V4HI value from 4 consecutive bitfields of (opnd 
2) + 1 bits
+;; for 16 <= (opnd 2) <= 31: V2SI value from 2 consecutive bitfields of (opnd 
2) + 1 bits
 (define_insn "dictunpack"
   [(set (match_operand:DUMODE 0 "register_operand" "=e")
 (unspec:DUMODE [(match_operand:DF 1 "register_operand" "e")
@@ -9480,6 +9484,7 @@
   [(set_attr "type" "fga")
(set_attr "subtype" "other")])
 
+;; Same as fpcmp but the {8,4,2}-bit result is shifted left by (opnd 3) * 
{8,4,2}
 (define_insn "fpcmpshl"
   [(set (match_operand:P 0 "register_operand" "=r")
 (unspec:P [(fpcmpcond:FPCMP (match_operand:FPCMP 1 "register_operand" 
"e")
@@ -9490,6 +9495,7 @@
"fpcmpshl\t%1, %2, %3, %0"
[(set_attr "type" "viscmp")])
 
+;; Same as fpcmpu but the {8,4,2}-bit result is shifted left by (opnd 3) * 
{8,4,2}
 (define_insn "fpcmpushl"
   [(set (match_operand:P 0 "register_operand" "=r")
 (unspec:P [(fpcmpucond:FPCMP (match_operand:FPCMP 1 "register_operand" 
"e")
@@ -9500,6 +9506,9 @@
"fpcmpushl\t%1, %2, %3, %0"
[(set_attr "type" "viscmp")])
 
+;; Dual Equal comparison: the unshifted result is the OR of two EQ comparisons
+;; of (opnd 1) with 1) the 32-bit highpart of (opnd 2) concatenated with itself
+;; and 2) the 32-bit lowpart of (opnd 2) concatenated with itself.
 (define_insn "fpcmpdeshl"
   [(set (match_operand:P 0 "register_operand" "=r")
 (unspec:P [(match_operand:FPCMP 1 "register_operand" "e")
@@ -9510,6 +9519,10 @@
"fpcmpdeshl\t%1, %2, %3, %0"
[(set_attr "type" "viscmp")])
 
+;; Unsigned Range comparison: the unshifted result is True if (opnd 1) lies in
+;; partitioned unsigned range (LB,HB) with LB) the 32-bit highpart of (opnd 2)
+;; concatenated with itself and HB) the 32-bit lowpart of (opnd 2) concatenated
+;; with itself.
 (define_insn "fpcmpurshl"
   [(set (match_operand:P 0 "register_operand" "=r")
 (unspec:P [(match_operand:FPCMP 1 "register_operand" "e")


[gcc r15-6008] The fix for PR116778:

2024-12-07 Thread Denis Chertykov via Gcc-cvs
https://gcc.gnu.org/g:279b3c71702de150eade19635bdbd26ba440b8eb

commit r15-6008-g279b3c71702de150eade19635bdbd26ba440b8eb
Author: Denis Chertykov 
Date:   Sat Dec 7 13:47:04 2024 +0400

The fix for PR116778:

Brief:
The bug appears in LRA after rematerialization pass while creating live 
ranges.
File lra.cc:
*
  /* Now we know what pseudos should be spilled.  Try to
 rematerialize them first.  */
  if (lra_remat ())
{
  /* We need full live info -- see the comment above.  */
  lra_create_live_ranges (lra_reg_spill_p, true);
*
Wrong call `lra_create_live_ranges (lra_reg_spill_p, true)'
It have to be `lra_create_live_ranges (true, true)'.

The explanation:
**
int main (void)
{
  if (a.u33 * a.u33 != 0)
--^
goto abrt;
  if (a.u33 * a.u40 * a.u33 != 0)
**
The bug appears here.

Part of the expression `a.u33 * a.u33'
Before LRA:
*
(insn 13 11 15 2 (set (reg:QI 184 [ _1+3 ])
(mem/c:QI (const:HI (plus:HI (symbol_ref:HI ("a") [flags 0x2]  
)
(const_int 3 [0x3]))) [1 a+3 S1 A8])) "bf.c":11:8 86 
{movqi_insn_split}
 (nil))
(insn 15 13 16 2 (set (reg:QI 64 [ a+4 ])
(mem/c:QI (const:HI (plus:HI (symbol_ref:HI ("a") [flags 0x2]  
)
(const_int 4 [0x4]))) [1 a+4 S1 A8])) "bf.c":11:8 86 
{movqi_insn_split}
 (nil))
(insn 16 15 20 2 (set (reg:QI 185 [ _1+4 ])
(zero_extract:QI (reg:QI 64 [ a+4 ])
(const_int 1 [0x1])
(const_int 0 [0]))) "bf.c":11:8 985 {*extzvqi_split}
 (nil))
*

After LRA:
*
(insn 587 11 13 2 (set (reg:QI 24 r24 [368])
(mem/c:QI (const:HI (plus:HI (symbol_ref:HI ("a") [flags 0x2]  
)
(const_int 3 [0x3]))) [1 a+3 S1 A8])) "bf.c":11:8 86 
{movqi_insn_split}
 (nil))
(insn 13 587 15 2 (set (mem/c:QI (plus:HI (reg/f:HI 28 r28)
(const_int 1 [0x1])) [4 %sfp+1 S1 A8])
(reg:QI 24 r24 [368])) "bf.c":11:8 86 {movqi_insn_split}
 (nil))
(insn 15 13 16 2 (set (reg:QI 6 r6 [orig:64 a+4 ] [64])
(mem/c:QI (const:HI (plus:HI (symbol_ref:HI ("a") [flags 0x2]  
)
(const_int 4 [0x4]))) [1 a+4 S1 A8])) "bf.c":11:8 86 
{movqi_insn_split}
 (nil))
(insn 16 15 572 2 (set (reg:QI 24 r24 [orig:185 _1+4 ] [185])
(zero_extract:QI (reg:QI 6 r6 [orig:64 a+4 ] [64])
(const_int 1 [0x1])
(const_int 0 [0]))) "bf.c":11:8 985 {*extzvqi_split}
 (nil))
(insn 572 16 20 2 (set (mem/c:QI (plus:HI (reg/f:HI 28 r28)
(const_int 1 [0x1])) [4 %sfp+1 S1 A8])
(reg:QI 24 r24 [orig:185 _1+4 ] [185])) "bf.c":11:8 86 
{movqi_insn_split}
 (nil))
*
Insn 13 and insn 572 use sfp+1 as a spill slot, but in IRA pass it was a two
different pseudos r184 and r185.
Insns 13 use sfp+1 as a spill slot for r184
Insns 572 use the same slot for r185. It's wrong.

Here we have a rematerialization.

Fragment from bf.c.317r.reload:

**
 Rematerialization #1: 

df_worklist_dataflow_doublequeue: n_basic_blocks 14 n_edges 18 count 14 (   
 1)
df_worklist_dataflow_doublequeue: n_basic_blocks 14 n_edges 18 count 14 (   
 1)

Cands:
0 (nop=0, remat_regno=185, reload_regno=359):
(insn 16 15 572 2 (set (reg:QI 359 [orig:185 _1+4 ] [185])
(zero_extract:QI (reg:QI 64 [ a+4 ])
(const_int 1 [0x1])
(const_int 0 [0]))) "bf.c":11:8 985 {*extzvqi_split}
 (nil))


**
[...]

**
Ranges after the compression:
 r185: [0..1]
   Frame pointer can not be eliminated anymore
   Spilling non-eliminable hard regs: 28 29
 Spilling r113(28)
 Spilling r184(29)
 Spilling r208(29)
 Spilling r209(28)
  Slot 0 regnos (width = 0): 185 209 208 184 113

**

The bug is here: `r185: 

[gcc r13-9236] libstdc++: Do not define _Insert_base::try_emplace before C++17

2024-12-07 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:01476b39bd0caa9d4a227a2158d724a97658e7ed

commit r13-9236-g01476b39bd0caa9d4a227a2158d724a97658e7ed
Author: Jonathan Wakely 
Date:   Fri Nov 8 13:58:23 2024 +

libstdc++: Do not define _Insert_base::try_emplace before C++17

This is not a reserved name in C++11 and C++14, so must not be defined.

Also use the appropriate feature test macros for the try_emplace members
of the Debug Mode maps.

libstdc++-v3/ChangeLog:

* include/bits/hashtable_policy.h (_Insert_base::try_emplace):
Do not define for C++11 and C++14.
* include/debug/map.h (try_emplace): Use feature test macro.
* include/debug/unordered_map (try_emplace): Likewise.
* testsuite/17_intro/names.cc: Define try_emplace before C++17.

(cherry picked from commit b66a57c0ad300b293ebd366bc29f44f2ddb65c69)

Diff:
---
 libstdc++-v3/include/bits/hashtable_policy.h | 2 ++
 libstdc++-v3/include/debug/map.h | 2 +-
 libstdc++-v3/include/debug/unordered_map | 2 +-
 libstdc++-v3/testsuite/17_intro/names.cc | 2 ++
 4 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/hashtable_policy.h 
b/libstdc++-v3/include/bits/hashtable_policy.h
index 2528dbe21091..f40fa9ed0424 100644
--- a/libstdc++-v3/include/bits/hashtable_policy.h
+++ b/libstdc++-v3/include/bits/hashtable_policy.h
@@ -941,6 +941,7 @@ namespace __detail
return __h._M_insert(__hint, __v, __node_gen, __unique_keys{});
   }
 
+#if __cplusplus >= 201703L && _GLIBCXX_HOSTED
   template
std::pair
try_emplace(const_iterator, _KType&& __k, _Args&&... __args)
@@ -962,6 +963,7 @@ namespace __detail
  __node._M_node = nullptr;
  return { __it, true };
}
+#endif
 
   void
   insert(initializer_list __l)
diff --git a/libstdc++-v3/include/debug/map.h b/libstdc++-v3/include/debug/map.h
index 17c300eca2f3..9ac0ae44854a 100644
--- a/libstdc++-v3/include/debug/map.h
+++ b/libstdc++-v3/include/debug/map.h
@@ -344,7 +344,7 @@ namespace __debug
}
 
 
-#if __cplusplus > 201402L
+#if __cplusplus >= 201703L && _GLIBCXX_HOSTED
   template 
 pair
 try_emplace(const key_type& __k, _Args&&... __args)
diff --git a/libstdc++-v3/include/debug/unordered_map 
b/libstdc++-v3/include/debug/unordered_map
index 4c6f26b6bfa3..e9013ee75bb9 100644
--- a/libstdc++-v3/include/debug/unordered_map
+++ b/libstdc++-v3/include/debug/unordered_map
@@ -440,7 +440,7 @@ namespace __debug
  _M_check_rehashed(__bucket_count);
}
 
-#if __cplusplus > 201402L
+#if __cplusplus >= 201703L && _GLIBCXX_HOSTED
   template 
pair
try_emplace(const key_type& __k, _Args&&... __args)
diff --git a/libstdc++-v3/testsuite/17_intro/names.cc 
b/libstdc++-v3/testsuite/17_intro/names.cc
index 864bc20f146d..1a02525e0bdc 100644
--- a/libstdc++-v3/testsuite/17_intro/names.cc
+++ b/libstdc++-v3/testsuite/17_intro/names.cc
@@ -136,6 +136,8 @@
 //  defines to_chars_result::ptr and to_chars_result::ec
 #define ec (
 #define ptr (
+//  and  define try_emplace
+#define try_emplace (
 #endif
 
 // These clash with newlib so don't use them.


[gcc r13-9235] libstdc++: Add missing parts of LWG 3480 for directory iterators [PR117560]

2024-12-07 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:59ce01a4d20c5dbf5b6ebde88c9d6dcd4588b114

commit r13-9235-g59ce01a4d20c5dbf5b6ebde88c9d6dcd4588b114
Author: Jonathan Wakely 
Date:   Thu Nov 14 01:14:44 2024 +

libstdc++: Add missing parts of LWG 3480 for directory iterators [PR117560]

It looks like I only read half the resolution of LWG 3480 and decided we
already supported it. As well as making the non-member overloads of end
take their parameters by value, we need some specializations of the
enable_borrowed_range and enable_view variable templates.

libstdc++-v3/ChangeLog:

PR libstdc++/117560
* include/bits/fs_dir.h (enable_borrowed_range, enable_view):
Define specializations for directory iterators, as per LWG 3480.
* testsuite/27_io/filesystem/iterators/lwg3480.cc: New test.

(cherry picked from commit eec6e8923586b9a54e37f32cef112d26d86e8f01)

Diff:
---
 libstdc++-v3/include/bits/fs_dir.h | 22 ++
 .../27_io/filesystem/iterators/lwg3480.cc  | 16 
 2 files changed, 38 insertions(+)

diff --git a/libstdc++-v3/include/bits/fs_dir.h 
b/libstdc++-v3/include/bits/fs_dir.h
index 3b0a493dc3fd..e1da502704e1 100644
--- a/libstdc++-v3/include/bits/fs_dir.h
+++ b/libstdc++-v3/include/bits/fs_dir.h
@@ -39,6 +39,7 @@
 #if __cplusplus >= 202002L
 # include // std::strong_ordering
 # include// std::default_sentinel_t
+# include  // enable_view, enable_borrowed_range
 #endif
 
 namespace std _GLIBCXX_VISIBILITY(default)
@@ -626,6 +627,27 @@ _GLIBCXX_END_NAMESPACE_CXX11
   extern template class
 __shared_ptr;
 
+#ifdef __cpp_lib_concepts // >= C++20
+// _GLIBCXX_RESOLVE_LIB_DEFECTS
+// 3480. directory_iterator and recursive_directory_iterator are not ranges
+namespace ranges
+{
+  template<>
+inline constexpr bool
+enable_borrowed_range = true;
+  template<>
+inline constexpr bool
+enable_borrowed_range = true;
+
+  template<>
+inline constexpr bool
+enable_view = true;
+  template<>
+inline constexpr bool
+enable_view = true;
+} // namespace ranges
+#endif // concepts
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/iterators/lwg3480.cc 
b/libstdc++-v3/testsuite/27_io/filesystem/iterators/lwg3480.cc
new file mode 100644
index ..15e0286fff6f
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/filesystem/iterators/lwg3480.cc
@@ -0,0 +1,16 @@
+// { dg-do compile { target c++20 } }
+// { dg-require-filesystem-ts "" }
+
+// LWG 3480
+// directory_iterator and recursive_directory_iterator are not C++20 ranges
+
+#include 
+
+namespace fs = std::filesystem;
+namespace rg = std::ranges;
+
+static_assert( rg::borrowed_range );
+static_assert( rg::borrowed_range );
+
+static_assert( rg::view );
+static_assert( rg::view );


[gcc r13-9234] libstdc++: Replace std::result_of with __invoke_result_t [PR114394]

2024-12-07 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:359917755997a96f00c5bafa3a678f5545f1d03d

commit r13-9234-g359917755997a96f00c5bafa3a678f5545f1d03d
Author: Jonathan Wakely 
Date:   Tue Mar 19 14:02:06 2024 +

libstdc++: Replace std::result_of with __invoke_result_t [PR114394]

Replace std::result_of with std::invoke_result, as specified in the
standard since C++17, to avoid deprecated warnings for std::result_of.

We don't have __invoke_result_t in C++11 mode, so add it as an alias
template for __invoke_result<>::type (which is what std::result_of uses
as its base class, so there's no change in functionality).

This fixes warnings given by Clang 18.

libstdc++-v3/ChangeLog:

PR libstdc++/114394
* include/std/functional (bind): Use __invoke_result_t instead
of result_of::type.
* include/std/type_traits (__invoke_result_t): New alias
template.
* testsuite/20_util/bind/ref_neg.cc: Adjust prune pattern.

(cherry picked from commit 31ef58b18da930b09ea0dfc1d6533c5ef97d8446)

Diff:
---
 libstdc++-v3/include/std/functional| 2 +-
 libstdc++-v3/include/std/type_traits   | 4 
 libstdc++-v3/testsuite/20_util/bind/ref_neg.cc | 2 +-
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/functional 
b/libstdc++-v3/include/std/functional
index c7c6a5a79247..c3cd6ecc2e7d 100644
--- a/libstdc++-v3/include/std/functional
+++ b/libstdc++-v3/include/std/functional
@@ -550,7 +550,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template
using _Res_type_impl
- = typename result_of< _Fn&(_Mu_type<_BArgs, _CallArgs>&&...) >::type;
+ = __invoke_result_t<_Fn&, _Mu_type<_BArgs, _CallArgs>&&...>;
 
   template
using _Res_type = _Res_type_impl<_Functor, _CallArgs, _Bound_args...>;
diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index 2b05e3719539..cea93ad6c615 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -2582,6 +2582,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Functor, _ArgTypes...
   >::type
 { };
+
+  // __invoke_result_t (std::invoke_result_t for C++11)
+  template
+using __invoke_result_t = typename __invoke_result<_Fn, _Args...>::type;
   /// @endcond
 
   template
diff --git a/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc 
b/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc
index 133423ea5422..aab63d551acc 100644
--- a/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc
@@ -50,7 +50,7 @@ void test02()
 
 // Ignore the reasons for deduction/substitution failure in the headers.
 // Arrange for the match to work on installed trees as well as build trees.
-// { dg-prune-output "no type named 'type' in 'struct std::result_of" }
+// { dg-prune-output "no type named 'type' in 'struct std::__invoke_result" }
 
 int main()
 {


[gcc r13-9239] libstdc++: Fix std::vector::emplace to forward parameter

2024-12-07 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:6cd48a88e31943b51440b4371b8cf337195ed743

commit r13-9239-g6cd48a88e31943b51440b4371b8cf337195ed743
Author: Jonathan Wakely 
Date:   Sat Oct 26 21:24:58 2024 +0100

libstdc++: Fix std::vector::emplace to forward parameter

If the parameter is not lvalue-convertible to bool then the current code
will fail to compile. The parameter should be forwarded to restore the
original value category.

libstdc++-v3/ChangeLog:

* include/bits/stl_bvector.h (emplace_back, emplace): Forward
parameter pack to preserve value category.
* testsuite/23_containers/vector/bool/emplace_rvalue.cc: New
test.

(cherry picked from commit f1c844be5202f4be446f165d9a7625eb7ec4c5b4)

Diff:
---
 libstdc++-v3/include/bits/stl_bvector.h|  4 ++--
 .../23_containers/vector/bool/emplace_rvalue.cc| 24 ++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_bvector.h 
b/libstdc++-v3/include/bits/stl_bvector.h
index a8fdc7bc4255..ed70e04dc647 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -1319,7 +1319,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 #endif
emplace_back(_Args&&... __args)
{
- push_back(bool(__args...));
+ push_back(bool(std::forward<_Args>(__args)...));
 #if __cplusplus > 201402L
  return back();
 #endif
@@ -1329,7 +1329,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_GLIBCXX20_CONSTEXPR
iterator
emplace(const_iterator __pos, _Args&&... __args)
-   { return insert(__pos, bool(__args...)); }
+   { return insert(__pos, bool(std::forward<_Args>(__args)...)); }
 #endif
 
 protected:
diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/emplace_rvalue.cc 
b/libstdc++-v3/testsuite/23_containers/vector/bool/emplace_rvalue.cc
new file mode 100644
index ..5dea2426d602
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/bool/emplace_rvalue.cc
@@ -0,0 +1,24 @@
+// { dg-do compile { target c++11 } }
+
+#include 
+
+struct S
+{
+  explicit operator bool() &&;
+};
+
+void
+test_emplace_back()
+{
+  S s;
+  std::vector v;
+  v.emplace_back(std::move(s));
+}
+
+void
+test_emplace()
+{
+  S s;
+  std::vector v;
+  v.emplace(v.begin(), std::move(s));
+}


[gcc r13-9240] libstdc++: Fix allocator-extended move ctor for std::basic_stacktrace [PR117822]

2024-12-07 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:b83a69906cafbe6b2164cc274f390afdd0f600f4

commit r13-9240-gb83a69906cafbe6b2164cc274f390afdd0f600f4
Author: Jonathan Wakely 
Date:   Thu Nov 28 10:24:00 2024 +

libstdc++: Fix allocator-extended move ctor for std::basic_stacktrace 
[PR117822]

libstdc++-v3/ChangeLog:

PR libstdc++/117822
* include/std/stacktrace (stacktrace(stacktrace&&, const A&)):
Fix typo in qualified-id for is_always_equal trait.
* testsuite/19_diagnostics/stacktrace/stacktrace.cc: Test
allocator-extended constructors and allocator propagation.

(cherry picked from commit fe04901737112abb6b1a71fe645f727384dc986a)

Diff:
---
 libstdc++-v3/include/std/stacktrace|   2 +-
 .../19_diagnostics/stacktrace/stacktrace.cc| 207 -
 2 files changed, 204 insertions(+), 5 deletions(-)

diff --git a/libstdc++-v3/include/std/stacktrace 
b/libstdc++-v3/include/std/stacktrace
index 3d8a085a6a92..79bd092c479c 100644
--- a/libstdc++-v3/include/std/stacktrace
+++ b/libstdc++-v3/include/std/stacktrace
@@ -354,7 +354,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   const allocator_type& __alloc) noexcept
   : _M_alloc(__alloc)
   {
-   if constexpr (_Allocator::is_always_equal::value)
+   if constexpr (_AllocTraits::is_always_equal::value)
  _M_impl = std::__exchange(__other._M_impl, {});
else if (_M_alloc == __other._M_alloc)
  _M_impl = std::__exchange(__other._M_impl, {});
diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc 
b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
index 1caa0fd35cb5..8d9d1065a7cc 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
@@ -106,12 +106,164 @@ test_cons()
 VERIFY( s5 != s0 );
 VERIFY( s3 == s0 );
 
-// TODO test allocator-extended copy/move
+Stacktrace s6(s5, Alloc{6});
+VERIFY( ! s6.empty() );
+VERIFY( s6.size() != 0 );
+VERIFY( s6.begin() != s6.end() );
+VERIFY( s6 == s5 );
+VERIFY( s5 != s0 );
+VERIFY( s6.get_allocator().get_personality() == 6 );
 
-// TODO test allocator propagation
+Stacktrace s7(std::move(s6), Alloc{7});
+VERIFY( ! s7.empty() );
+VERIFY( s7.size() != 0 );
+VERIFY( s7.begin() != s7.end() );
+VERIFY( s7 == s5 );
+VERIFY( s5 != s0 );
+VERIFY( s7.get_allocator().get_personality() == 7 );
   }
-}
 
+  {
+using Alloc = __gnu_test::SimpleAllocator;
+using Stacktrace = std::basic_stacktrace;
+
+Stacktrace s0;
+VERIFY( s0.empty() );
+VERIFY( s0.size() == 0 );
+VERIFY( s0.begin() == s0.end() );
+
+Stacktrace s1(Alloc{});
+VERIFY( s1.empty() );
+VERIFY( s1.size() == 0 );
+VERIFY( s1.begin() == s1.end() );
+
+VERIFY( s0 == s1 );
+
+Stacktrace s2(s0);
+VERIFY( s2 == s0 );
+
+const Stacktrace curr = Stacktrace::current();
+
+Stacktrace s3(curr);
+VERIFY( ! s3.empty() );
+VERIFY( s3.size() != 0 );
+VERIFY( s3.begin() != s3.end() );
+VERIFY( s3 != s0 );
+
+Stacktrace s4(s3);
+VERIFY( ! s4.empty() );
+VERIFY( s4.size() != 0 );
+VERIFY( s4.begin() != s4.end() );
+VERIFY( s4 == s3 );
+VERIFY( s4 != s0 );
+
+Stacktrace s5(std::move(s3));
+VERIFY( ! s5.empty() );
+VERIFY( s5.size() != 0 );
+VERIFY( s5.begin() != s5.end() );
+VERIFY( s5 == s4 );
+VERIFY( s5 != s0 );
+VERIFY( s3 == s0 );
+
+Stacktrace s6(s5, Alloc{});
+VERIFY( ! s6.empty() );
+VERIFY( s6.size() != 0 );
+VERIFY( s6.begin() != s6.end() );
+VERIFY( s6 == s5 );
+VERIFY( s5 != s0 );
+
+Stacktrace s7(std::move(s6), Alloc{});
+VERIFY( ! s7.empty() );
+VERIFY( s7.size() != 0 );
+VERIFY( s7.begin() != s7.end() );
+VERIFY( s7 == s5 );
+VERIFY( s5 != s0 );
+  }
+
+{
+using Stacktrace = std::pmr::stacktrace;
+using Alloc = Stacktrace::allocator_type;
+
+Stacktrace s0;
+VERIFY( s0.empty() );
+VERIFY( s0.size() == 0 );
+VERIFY( s0.begin() == s0.end() );
+
+Stacktrace s1(Alloc{});
+VERIFY( s1.empty() );
+VERIFY( s1.size() == 0 );
+VERIFY( s1.begin() == s1.end() );
+
+VERIFY( s0 == s1 );
+
+Stacktrace s2(s0);
+VERIFY( s2 == s0 );
+
+const Stacktrace curr = Stacktrace::current();
+
+Stacktrace s3(curr);
+VERIFY( ! s3.empty() );
+VERIFY( s3.size() != 0 );
+VERIFY( s3.begin() != s3.end() );
+VERIFY( s3 != s0 );
+
+Stacktrace s4(s3);
+VERIFY( ! s4.empty() );
+VERIFY( s4.size() != 0 );
+VERIFY( s4.begin() != s4.end() );
+VERIFY( s4 == s3 );
+VERIFY( s4 != s0 );
+
+Stacktrace s5(std::move(s3));
+VERIFY( ! s5.empty() );
+VERIFY( s5.size() != 0 );
+VERIFY( s5.begin() != s5.end() );
+VERIFY( s5 == s4 );
+VERIFY( s5 != s0 );
+VERIFY( s3 == s0 );
+
+__gnu_test::memory_resourc

[gcc r13-9241] libstdc++: Add missing constraint to operator+ for std::move_iterator

2024-12-07 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:aa66f142d4e8ffd6dfeccde0378439d1bce4eccc

commit r13-9241-gaa66f142d4e8ffd6dfeccde0378439d1bce4eccc
Author: Jonathan Wakely 
Date:   Fri Dec 6 21:32:29 2024 +

libstdc++: Add missing constraint to operator+ for std::move_iterator

This constraint was added by the One Ranges proposal (P0896R4) and
then fixed by LWG 3293, but it was missing from libstdc++.

libstdc++-v3/ChangeLog:

* include/bits/stl_iterator.h (operator+): Add constraint to
move_iterator operator.
* testsuite/24_iterators/move_iterator/rel_ops_c++20.cc: Check
it's constrained.

(cherry picked from commit f91e34644e66b2eb7f4930f17a30da9f49e7d4d2)

Diff:
---
 libstdc++-v3/include/bits/stl_iterator.h |  4 
 .../testsuite/24_iterators/move_iterator/rel_ops_c++20.cc| 12 
 2 files changed, 16 insertions(+)

diff --git a/libstdc++-v3/include/bits/stl_iterator.h 
b/libstdc++-v3/include/bits/stl_iterator.h
index 203ccc7bf6b4..68bb1023081a 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -1747,6 +1747,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 inline _GLIBCXX17_CONSTEXPR bool
 operator==(const move_iterator<_Iterator>& __x,
   const move_iterator<_Iterator>& __y)
+// N.B. No contraints, x.base() == y.base() is always well-formed.
 { return __x.base() == __y.base(); }
 
 #if __cpp_lib_three_way_comparison
@@ -1807,6 +1808,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator>
 operator+(typename move_iterator<_Iterator>::difference_type __n,
  const move_iterator<_Iterator>& __x)
+#ifdef __cpp_lib_concepts
+requires requires { { __x.base() + __n } -> same_as<_Iterator>; }
+#endif
 { return __x + __n; }
 
   template
diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/rel_ops_c++20.cc 
b/libstdc++-v3/testsuite/24_iterators/move_iterator/rel_ops_c++20.cc
index 9f437acb50a6..49e1032a3d18 100644
--- a/libstdc++-v3/testsuite/24_iterators/move_iterator/rel_ops_c++20.cc
+++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/rel_ops_c++20.cc
@@ -19,6 +19,7 @@
 // { dg-do compile { target c++2a } }
 
 #include 
+#include 
 
 template
 struct Iter
@@ -142,3 +143,14 @@ static_assert( cend > beg );
 static_assert( beg <= cend );
 static_assert( cend >= beg );
 static_assert( std::is_lt(beg <=> cend) );
+
+template
+  concept has_plus = requires(std::iter_difference_t n, I i) {
+   { n + i } -> std::same_as;
+  };
+
+using namespace __gnu_test;
+using MBI = std::move_iterator>;
+static_assert( ! has_plus );
+using MRI = std::move_iterator>;
+static_assert( has_plus );


[gcc r13-9243] libstdc++: Disable std::formatter specialization

2024-12-07 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:f7630052b55e21d03760b6f94b07ad5fc7d68f1a

commit r13-9243-gf7630052b55e21d03760b6f94b07ad5fc7d68f1a
Author: Jonathan Wakely 
Date:   Fri Sep 20 17:26:35 2024 +0100

libstdc++: Disable std::formatter specialization

I noticed that char8_t was missing from the list of types that were
prevented from using the std::formatter partial specialization for
integer types. That partial specialization was also matching
cv-qualified integer types, because std::integral is true.

This change simplifies the constraints by introducing a new variable
template which is only true for cv-unqualified integer types, with
explicit specializations to exclude the character types. This should be
slightly more efficient than the previous constraints that checked
std::integral and (!__is_one_of). It also
avoids the need for a separate std::formatter specialization for 128-bit
integers, as they can be handled by the new variable template too.

libstdc++-v3/ChangeLog:

* include/std/format (__format::__is_formattable_integer): New
variable template and specializations.
(template struct formatter): Replace
constraints on first arg with __is_formattable_integer.
* testsuite/std/format/formatter/requirements.cc: Check that
std::formatter specializations for char8_t and const int are
disabled.

(cherry picked from commit 0f52a92ab249bde64b7570d4cf549437a3283520)

Diff:
---
 libstdc++-v3/include/std/format| 53 --
 .../testsuite/std/format/formatter/requirements.cc | 17 +++
 2 files changed, 45 insertions(+), 25 deletions(-)

diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index ed5bcf01504f..3c9b5a088a3f 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -1315,8 +1315,9 @@ namespace __format
 
   // We can format a floating-point type iff it is usable with to_chars.
   template
-concept __formattable_float = requires (_Tp __t, char* __p)
-{ __format::to_chars(__p, __p, __t, chars_format::scientific, 6); };
+concept __formattable_float
+  = is_same_v, _Tp> && requires (_Tp __t, char* __p)
+  { __format::to_chars(__p, __p, __t, chars_format::scientific, 6); };
 
   template<__char _CharT>
 struct __formatter_fp
@@ -2029,32 +2030,33 @@ namespace __format
 };
   /// @}
 
-  /// Format an integer.
-  template
-requires (!__is_one_of<_Tp, char, wchar_t, char16_t, char32_t>::value)
-struct formatter<_Tp, _CharT>
-{
-  formatter() = default;
-
-  [[__gnu__::__always_inline__]]
-  constexpr typename basic_format_parse_context<_CharT>::iterator
-  parse(basic_format_parse_context<_CharT>& __pc)
-  {
-   return _M_f.template _M_parse<_Tp>(__pc);
-  }
+/// @cond undocumented
+namespace __format
+{
+  // each cv-unqualified arithmetic type ArithmeticT other than
+  // char, wchar_t, char8_t, char16_t, or char32_t
+  template
+constexpr bool __is_formattable_integer = __is_integer<_Tp>::__value;
 
-  template
-   typename basic_format_context<_Out, _CharT>::iterator
-   format(_Tp __u, basic_format_context<_Out, _CharT>& __fc) const
-   { return _M_f.format(__u, __fc); }
+#if defined __SIZEOF_INT128__
+  template<> inline constexpr bool __is_formattable_integer<__int128>  = true;
+  template<> inline constexpr bool __is_formattable_integer
+  = true;
+#endif
 
-private:
-  __format::__formatter_int<_CharT> _M_f;
-};
+  template<> inline constexpr bool __is_formattable_integer = false;
+  template<> inline constexpr bool __is_formattable_integer = false;
+#ifdef _GLIBCXX_USE_CHAR8_T
+  template<> inline constexpr bool __is_formattable_integer = false;
+#endif
+  template<> inline constexpr bool __is_formattable_integer = false;
+  template<> inline constexpr bool __is_formattable_integer = false;
+}
+/// @endcond
 
-#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__
+  /// Format an integer.
   template
-requires (__is_one_of<_Tp, __int128, unsigned __int128>::value)
+requires __format::__is_formattable_integer<_Tp>
 struct formatter<_Tp, _CharT>
 {
   formatter() = default;
@@ -2074,7 +2076,6 @@ namespace __format
 private:
   __format::__formatter_int<_CharT> _M_f;
 };
-#endif
 
   /// Format a floating-point value.
   template<__format::__formattable_float _Tp, __format::__char _CharT>
@@ -2309,6 +2310,8 @@ namespace __format
 } // namespace __format
 /// @endcond
 
+// Concept std::formattable was introduced by P2286R8 "Formatting Ranges",
+// but we can't guard it with __cpp_lib_format_ranges until we define that!
 #if __cplusplus > 202002L
   // [format.formattable], concept formattable
   template
diff --git a/libstdc++-v3/testsuite/std/format/formatter/requirements.cc 
b/libstdc++-v3/testsuite/std/format/formatter/require

[gcc r13-9237] libstdc++: Fix calculation of system time in performance tests

2024-12-07 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:d0d1830cc4b51c2890df7aa583375e3b398c4e06

commit r13-9237-gd0d1830cc4b51c2890df7aa583375e3b398c4e06
Author: Jonathan Wakely 
Date:   Wed Nov 13 16:47:04 2024 +

libstdc++: Fix calculation of system time in performance tests

The system_time() function used the wrong element of the splits array.

Also add a comment about the units for time measurements.

libstdc++-v3/ChangeLog:

* testsuite/util/testsuite_performance.h (time_counter): Add
comment about times.
(time_counter::system_time): Use correct split value.

(cherry picked from commit 19d0720f68c2617f1b9b686d3884333b60ca75da)

Diff:
---
 libstdc++-v3/testsuite/util/testsuite_performance.h | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/util/testsuite_performance.h 
b/libstdc++-v3/testsuite/util/testsuite_performance.h
index 9ed9d7ce2899..4674d3f891ad 100644
--- a/libstdc++-v3/testsuite/util/testsuite_performance.h
+++ b/libstdc++-v3/testsuite/util/testsuite_performance.h
@@ -72,6 +72,9 @@ namespace __gnu_test
   class time_counter
   {
   private:
+// All times are measured in clock ticks.
+// There are CLOCKS_PER_SEC ticks per second.
+// POSIX requires CLOCKS_PER_SEC == 100 so ticks == microseconds.
 clock_telapsed_begin;
 clock_telapsed_end;
 tmstms_begin;
@@ -135,7 +138,7 @@ namespace __gnu_test
 
 std::size_t
 system_time() const
-{ return (tms_end.tms_stime - tms_begin.tms_stime) + splits[1]; }
+{ return (tms_end.tms_stime - tms_begin.tms_stime) + splits[2]; }
   };
 
   class resource_counter


[gcc r13-9242] libstdc++: Fix get<0> constraint for lvalue ranges::subrange (LWG 3589)

2024-12-07 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:8fda1b0f513129861729eed25067438031fb6ec5

commit r13-9242-g8fda1b0f513129861729eed25067438031fb6ec5
Author: Jonathan Wakely 
Date:   Thu Nov 14 17:31:43 2024 +

libstdc++: Fix get<0> constraint for lvalue ranges::subrange (LWG 3589)

Approved at October 2021 plenary.

libstdc++-v3/ChangeLog:

* include/bits/ranges_util.h (subrange::begin): Fix constraint,
as per LWG 3589.
* testsuite/std/ranges/subrange/lwg3589.cc: New test.

(cherry picked from commit 4a3a0be34f723df192361e43bb48b9292dfe3a54)

Diff:
---
 libstdc++-v3/include/bits/ranges_util.h|  5 +++-
 .../testsuite/std/ranges/subrange/lwg3589.cc   | 30 ++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/ranges_util.h 
b/libstdc++-v3/include/bits/ranges_util.h
index 5f6a1d360ed0..ddb0260c3772 100644
--- a/libstdc++-v3/include/bits/ranges_util.h
+++ b/libstdc++-v3/include/bits/ranges_util.h
@@ -432,8 +432,11 @@ namespace ranges
 __detail::__make_unsigned_like_t>)
   -> subrange, sentinel_t<_Rng>, subrange_kind::sized>;
 
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 3589. The const lvalue reference overload of get for subrange does not
+  // constrain I to be copyable when N == 0
   template
-requires (_Num < 2)
+requires ((_Num == 0 && copyable<_It>) || _Num == 1)
 constexpr auto
 get(const subrange<_It, _Sent, _Kind>& __r)
 {
diff --git a/libstdc++-v3/testsuite/std/ranges/subrange/lwg3589.cc 
b/libstdc++-v3/testsuite/std/ranges/subrange/lwg3589.cc
new file mode 100644
index ..1ccc52d81f8a
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/ranges/subrange/lwg3589.cc
@@ -0,0 +1,30 @@
+// { dg-do compile { target c++20 } }
+
+// LWG 3589. The const lvalue reference overload of get for subrange does not
+// constrain I to be copyable when N == 0
+
+#include 
+#include 
+
+void
+test_lwg3589()
+{
+  int a[2]{};
+  __gnu_test::test_range r(a);
+
+  // Use a generic lambda so we have a dependent context.
+  auto test = [](auto& x)
+{
+  // This was wrong before the LWG 3589 change:
+  if constexpr (requires { std::ranges::get<0>(x); })
+   (void) std::ranges::get<0>(x);
+
+  // These always worked unconditionally:
+  (void) std::ranges::get<1>(x);
+  (void) std::ranges::get<0>(std::move(x));
+  (void) std::ranges::get<1>(std::move(x));
+};
+
+  std::ranges::subrange sr(r.begin(), r.end());
+  test(sr);
+}


[gcc r13-9238] libstdc++: Use __is_single_threaded() in performance tests

2024-12-07 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:6b31e42fa76b517a617d39d7fa8808afe770dd67

commit r13-9238-g6b31e42fa76b517a617d39d7fa8808afe770dd67
Author: Jonathan Wakely 
Date:   Wed Nov 13 16:37:24 2024 +

libstdc++: Use __is_single_threaded() in performance tests

With recent glibc releases the __gthread_active_p() function is always
true, so we always append "-thread" onto performance benchmark names.

Use the __gnu_cxx::__is_single_threaded() function instead.

libstdc++-v3/ChangeLog:

* testsuite/util/testsuite_performance.h: Use
__gnu_cxx::__is_single_threaded instead of __gthread_active_p().

(cherry picked from commit 2b92007016ce8de3fc0a8c4508a789b822ea8e6b)

Diff:
---
 libstdc++-v3/testsuite/util/testsuite_performance.h | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/testsuite/util/testsuite_performance.h 
b/libstdc++-v3/testsuite/util/testsuite_performance.h
index 4674d3f891ad..e561fa4f07ed 100644
--- a/libstdc++-v3/testsuite/util/testsuite_performance.h
+++ b/libstdc++-v3/testsuite/util/testsuite_performance.h
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #if defined (__linux__) || defined (__GLIBC__)
@@ -226,10 +227,8 @@ namespace __gnu_test
 
 std::ofstream out(name, std::ios_base::app);
 
-#ifdef __GTHREADS
-if (__gthread_active_p())
+if (!__gnu_cxx::__is_single_threaded())
   testname.append("-thread");
-#endif
 
 out.setf(std::ios_base::left);
 out << std::setw(25) << testname << tab;
@@ -256,10 +255,8 @@ namespace __gnu_test
 
 std::ofstream out(name, std::ios_base::app);
 
-#ifdef __GTHREADS
-if (__gthread_active_p ())
+if (!__gnu_cxx::__is_single_threaded ())
   testname.append("-thread");
-#endif
 
 out.setf(std::ios_base::left);
 out << std::setw(25) << testname << tab;


[gcc r15-6009] libstdc++: Fix typo in Doxygen comment in

2024-12-07 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:b7dd0d976022c5ba20d9d676e2f684614231eb72

commit r15-6009-gb7dd0d976022c5ba20d9d676e2f684614231eb72
Author: Jonathan Wakely 
Date:   Sat Dec 7 01:34:33 2024 +

libstdc++: Fix typo in Doxygen comment in 

libstdc++-v3/ChangeLog:

* include/std/format: Fix typo in Doxygen comment.

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

diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 6313d084f45e..e7e0d2d142bb 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -2208,7 +2208,7 @@ namespace __format
   template<> inline constexpr bool __is_formattable_integer = false;
   template<> inline constexpr bool __is_formattable_integer = false;
 }
-/// ~endcond
+/// @endcond
 
   /// Format an integer.
   template


[gcc r15-6010] i386: x r<< (c - y) to x r>> y etc. optimization [PR117930]

2024-12-07 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:4abcf4ad38a4081f02ed09aed7892a3a6af61cbb

commit r15-6010-g4abcf4ad38a4081f02ed09aed7892a3a6af61cbb
Author: Jakub Jelinek 
Date:   Sat Dec 7 11:40:12 2024 +0100

i386: x r<< (c - y) to x r>> y etc. optimization [PR117930]

The following patch optimizes x r<< (c - y) to x r>> y,
x r>> (c - y) to x r<< y, x r<< (c + y) to x r<< y and
x r>> (c + y) to x r>> y if c is a multiple of x's bitsize.

2024-12-07  Jakub Jelinek  

PR target/117930
* config/i386/i386.md (crotate): New define_code_attr.
(*3_add, *3_add_1,
*3_sub, *3_sub_1): New define_insn_and_split
patterns plus following define_split for constant first input
operand.

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

Diff:
---
 gcc/config/i386/i386.md  | 141 +++
 gcc/testsuite/gcc.target/i386/pr117930.c | 118 ++
 2 files changed, 259 insertions(+)

diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index ec816be61821..6edcb6dc657c 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -1079,6 +1079,9 @@
 ;; Base name for insn mnemonic.
 (define_code_attr rotate [(rotate "rol") (rotatert "ror")])
 
+;; Counter rotate.
+(define_code_attr crotate [(rotate "rotatert") (rotatert "rotate")])
+
 ;; Mapping of abs neg operators
 (define_code_iterator absneg [abs neg])
 
@@ -18216,6 +18219,144 @@
(any_rotate:SWI (match_dup 4) (match_dup 2)))]
  "operands[4] = gen_reg_rtx (mode);")
 
+(define_insn_and_split "*3_add"
+  [(set (match_operand:SWI 0 "nonimmediate_operand")
+   (any_rotate:SWI
+ (match_operand:SWI 1 "nonimmediate_operand")
+ (subreg:QI
+   (plus
+ (match_operand 2 "int_nonimmediate_operand")
+ (match_operand 3 "const_int_operand")) 0)))
+   (clobber (reg:CC FLAGS_REG))]
+  "ix86_binary_operator_ok (, mode, operands)
+   && (INTVAL (operands[3]) & ( * BITS_PER_UNIT - 1)) == 0
+   && ix86_pre_reload_split ()"
+  "#"
+  "&& 1"
+  [(parallel
+ [(set (match_dup 0)
+  (any_rotate:SWI (match_dup 1) (match_dup 2)))
+  (clobber (reg:CC FLAGS_REG))])]
+{
+  operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
+  operands[2] = gen_lowpart (QImode, operands[2]);
+})
+
+(define_split
+  [(set (match_operand:SWI 0 "register_operand")
+   (any_rotate:SWI
+ (match_operand:SWI 1 "const_int_operand")
+ (subreg:QI
+   (plus
+ (match_operand 2 "int248_register_operand")
+ (match_operand 3 "const_int_operand")) 0)))]
+ "(INTVAL (operands[3]) & ( * BITS_PER_UNIT - 1)) == 0"
+ [(set (match_dup 4) (match_dup 1))
+  (set (match_dup 0)
+   (any_rotate:SWI (match_dup 4) (subreg:QI (match_dup 2) 0)))]
+ "operands[4] = gen_reg_rtx (mode);")
+
+(define_insn_and_split "*3_add_1"
+  [(set (match_operand:SWI 0 "nonimmediate_operand")
+   (any_rotate:SWI
+ (match_operand:SWI 1 "nonimmediate_operand")
+ (plus:QI
+   (match_operand:QI 2 "nonimmediate_operand")
+   (match_operand:QI 3 "const_int_operand"
+   (clobber (reg:CC FLAGS_REG))]
+  "ix86_binary_operator_ok (, mode, operands)
+   && (INTVAL (operands[3]) & ( * BITS_PER_UNIT - 1)) == 0
+   && ix86_pre_reload_split ()"
+  "#"
+  "&& 1"
+  [(parallel
+ [(set (match_dup 0)
+  (any_rotate:SWI (match_dup 1) (match_dup 2)))
+  (clobber (reg:CC FLAGS_REG))])]
+ "operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);")
+
+(define_split
+  [(set (match_operand:SWI 0 "register_operand")
+   (any_rotate:SWI
+ (match_operand:SWI 1 "const_int_operand")
+ (plus:QI
+   (match_operand:QI 2 "register_operand")
+   (match_operand:QI 3 "const_int_operand"]
+ "(INTVAL (operands[3]) & ( * BITS_PER_UNIT - 1)) == 0"
+ [(set (match_dup 4) (match_dup 1))
+  (set (match_dup 0)
+   (any_rotate:SWI (match_dup 4) (match_dup 2)))]
+ "operands[4] = gen_reg_rtx (mode);")
+
+(define_insn_and_split "*3_sub"
+  [(set (match_operand:SWI 0 "nonimmediate_operand")
+   (any_rotate:SWI
+ (match_operand:SWI 1 "nonimmediate_operand")
+ (subreg:QI
+   (minus
+ (match_operand 3 "const_int_operand")
+ (match_operand 2 "int_nonimmediate_operand")) 0)))
+   (clobber (reg:CC FLAGS_REG))]
+  "ix86_binary_operator_ok (, mode, operands)
+   && (INTVAL (operands[3]) & ( * BITS_PER_UNIT - 1)) == 0
+   && ix86_pre_reload_split ()"
+  "#"
+  "&& 1"
+  [(parallel
+ [(set (match_dup 0)
+  (:SWI (match_dup 1) (match_dup 2)))
+  (clobber (reg:CC FLAGS_REG))])]
+{
+  operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
+  operands[2] = gen_lowpart (QImode, operands[2]);
+})
+
+(define_split
+  [(set (match_operand:SWI 0 "register_operand")
+   (any_rotate:SWI
+ (match_operand:SWI 1 "const_int_operand")
+ (subreg:QI
+ 

[gcc r15-6007] libstdc++: editorconfig: Adjust wildcard patterns

2024-12-07 Thread Matthew Malcomson via Libstdc++-cvs
https://gcc.gnu.org/g:2c605367b4953ff308e0134fdabbd6ddbecbbfc8

commit r15-6007-g2c605367b4953ff308e0134fdabbd6ddbecbbfc8
Author: Matthew Malcomson 
Date:   Fri Dec 6 17:16:42 2024 +

libstdc++: editorconfig: Adjust wildcard patterns

According to the editorconfig file format description, a match against
one of multiple different strings is described with those different
strings separated by commas and within curly braces.  E.g.
[{x,y}.txt]

https://editorconfig.org/, under "Wildcard Patterns".

The current libstdc++-v3/.editorconfig file has a few places where we
match against similar globs by using strings separated by commas but
without the curly braces.  E.g.
[*.h,*.cc]

This doesn't take affect in neovim nor emacs (as far as I can tell), I
haven't looked into other editors.
I would expect that following the standard syntax described in the
documentation would satisfy more editors.  Hence this patch suggests
following that standard by using something like:
[*.{h,cc}]

libstdc++-v3/ChangeLog:

* .editorconfig: Adjust globbing style to standard syntax.

Signed-off-by: Matthew Malcomson 

Diff:
---
 libstdc++-v3/.editorconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/.editorconfig b/libstdc++-v3/.editorconfig
index 88107cedda21..c95e4e26f7a2 100644
--- a/libstdc++-v3/.editorconfig
+++ b/libstdc++-v3/.editorconfig
@@ -5,14 +5,14 @@ root = true
 end_of_line = lf
 insert_final_newline = true
 
-[*.h,*.cc]
+[*.{h,cc}]
 charset = utf-8
 indent_style = tab
 indent_size = 2
 tab_width = 8
 trim_trailing_whitespace = true
 
-[Makefile*,ChangeLog*]
+[{Makefile,ChangeLog}*]
 indent_style = tab
 indent_size = 8
 trim_trailing_whitespace = true