[gcc r15-7690] c++: Fix range for with PMFs [PR118923]

2025-02-25 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:a41b3f54c13890b1327bb3d4fbae8f7feb37d00b

commit r15-7690-ga41b3f54c13890b1327bb3d4fbae8f7feb37d00b
Author: Jakub Jelinek 
Date:   Tue Feb 25 09:26:46 2025 +0100

c++: Fix range for with PMFs [PR118923]

The following testcases segfault because the new range for 
-frange-for-ext-temps
temporary extension extends even the internal TARGET_EXPRs created by
get_member_function_from_ptrfunc.

The following patch fixes that by using get_internal_target_expr for those
instead of force_target_expr (similarly in cp_finish_decl and
build_comparison_op) and using force_target_expr inside of
get_internal_target_expr.

2025-02-25  Jakub Jelinek  

PR c++/118923
* tree.cc (get_internal_target_expr): Use force_target_expr
instead of build_target_expr_with_type.
* typeck.cc (get_member_function_from_ptrfunc): Use
get_internal_target_expr instead of force_target_expr.
* decl.cc (cp_finish_decl): Likewise.
* method.cc (build_comparison_op): Likewise.

* g++.dg/cpp0x/pr118923.C: New test.
* g++.dg/cpp1y/pr118923.C: New test.

Diff:
---
 gcc/cp/decl.cc|  6 ++--
 gcc/cp/method.cc  |  2 +-
 gcc/cp/tree.cc|  3 +-
 gcc/cp/typeck.cc  |  6 ++--
 gcc/testsuite/g++.dg/cpp0x/pr118923.C | 66 +++
 gcc/testsuite/g++.dg/cpp1y/pr118923.C | 38 
 6 files changed, 110 insertions(+), 11 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 05ad9bb24d59..936e48e907e2 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -9377,8 +9377,7 @@ cp_finish_decl (tree decl, tree init, bool 
init_const_expr_p,
  tree guard = NULL_TREE;
  if (cleanups || cleanup)
{
- guard = force_target_expr (boolean_type_node,
-boolean_false_node, tf_none);
+ guard = get_internal_target_expr (boolean_false_node);
  add_stmt (guard);
  guard = TARGET_EXPR_SLOT (guard);
}
@@ -9407,8 +9406,7 @@ cp_finish_decl (tree decl, tree init, bool 
init_const_expr_p,
 popped that all, so push those extra cleanups around
 the whole sequence with a guard variable.  */
  gcc_assert (TREE_CODE (sl) == STATEMENT_LIST);
- guard = force_target_expr (integer_type_node,
-integer_zero_node, tf_none);
+ guard = get_internal_target_expr (integer_zero_node);
  add_stmt (guard);
  guard = TARGET_EXPR_SLOT (guard);
  for (unsigned i = 0; i < n_extra_cleanups; ++i)
diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
index 3914bbb1ef23..05c19cf0661e 100644
--- a/gcc/cp/method.cc
+++ b/gcc/cp/method.cc
@@ -1597,7 +1597,7 @@ build_comparison_op (tree fndecl, bool defining, 
tsubst_flags_t complain)
  /* Some other array, will need runtime loop.  */
  else
{
- idx = force_target_expr (sizetype, maxval, complain);
+ idx = get_internal_target_expr (maxval);
  loop_indexes = tree_cons (idx, NULL_TREE, loop_indexes);
}
  expr_type = TREE_TYPE (expr_type);
diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index 5628a576f01b..5863b6878f02 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -982,8 +982,7 @@ tree
 get_internal_target_expr (tree init)
 {
   init = convert_bitfield_to_declared_type (init);
-  tree t = build_target_expr_with_type (init, TREE_TYPE (init),
-   tf_warning_or_error);
+  tree t = force_target_expr (TREE_TYPE (init), init, tf_warning_or_error);
   TARGET_EXPR_INTERNAL_P (t) = true;
   return t;
 }
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index a9c32ff930d5..bbaca960bd7c 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -4219,16 +4219,14 @@ get_member_function_from_ptrfunc (tree 
*instance_ptrptr, tree function,
  && !DECL_P (instance_ptr)
  && !TREE_CONSTANT (instance_ptr)))
instance_ptr = instance_save_expr
- = force_target_expr (TREE_TYPE (instance_ptr), instance_ptr,
-  complain);
+ = get_internal_target_expr (instance_ptr);
 
   /* See above comment.  */
   if (TREE_SIDE_EFFECTS (function)
  || (!nonvirtual
  && !DECL_P (function)
  && !TREE_CONSTANT (function)))
-   function
- = force_target_expr (TREE_TYPE (function), function, complain);
+   function = get_internal_target_expr (function);
 
   /* Start by extracting all the information from the PMF itself.  */
   e3 = pfn_from_ptrmemfunc (function);
diff --git a/gcc/tests

[gcc r15-7691] openmp: Fix handling of declare target statics with array type which need destruction [PR118876]

2025-02-25 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:86a4af2793393e47af6b78cb7094c97914890091

commit r15-7691-g86a4af2793393e47af6b78cb7094c97914890091
Author: Jakub Jelinek 
Date:   Tue Feb 25 09:29:39 2025 +0100

openmp: Fix handling of declare target statics with array type which need 
destruction [PR118876]

The following testcase ICEs because it attempts to emit the __tcfa function 
twice,
once when handling the host destruction and once when handling nohost 
destruction.

This patch fixes it by using __omp_tcfa function for the nohost case and 
marks it
with the needed "omp declare target" and "omp declare target nohost" 
attributes.

2025-02-25  Jakub Jelinek  

PR c++/118876
* cp-tree.h (register_dtor_fn): Add a bool argument defaulted to 
false.
* decl.cc (start_cleanup_fn): Add OMP_TARGET argument, use
"__omp_tcf" prefix rather than "__tcf" in that case.  Add
"omp declare target" and "omp declare target nohost" attributes
to the fndecl.
(register_dtor_fn): Add OMP_TARGET argument, pass it down to
start_cleanup_fn.
* decl2.cc (one_static_initialization_or_destruction): Add 
OMP_TARGET
argument, pass it down to register_dtor_fn.
(emit_partial_init_fini_fn): Pass omp_target to
one_static_initialization_or_destruction.
(handle_tls_init): Pass false to
one_static_initialization_or_destruction.

* g++.dg/gomp/pr118876.C: New test.

Diff:
---
 gcc/cp/cp-tree.h |  2 +-
 gcc/cp/decl.cc   | 19 ++-
 gcc/cp/decl2.cc  | 12 +++-
 gcc/testsuite/g++.dg/gomp/pr118876.C |  6 ++
 4 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 8866d5e2c2b9..c76a92dd39be 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -7201,7 +7201,7 @@ extern int wrapup_namespace_globals   ();
 extern tree create_implicit_typedef(tree, tree);
 extern int local_variable_p(const_tree);
 extern tree get_cxa_atexit_fn_ptr_type ();
-extern tree register_dtor_fn   (tree);
+extern tree register_dtor_fn   (tree, bool = false);
 extern tmpl_spec_kind current_tmpl_spec_kind   (int);
 extern tree cxx_builtin_function   (tree decl);
 extern tree cxx_builtin_function_ext_scope (tree decl);
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 936e48e907e2..9ca8c6c44816 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -96,7 +96,7 @@ static void record_key_method_defined (tree);
 static tree create_array_type_for_decl (tree, tree, tree, location_t);
 static tree get_atexit_node (void);
 static tree get_dso_handle_node (void);
-static tree start_cleanup_fn (tree, bool);
+static tree start_cleanup_fn (tree, bool, bool);
 static void end_cleanup_fn (void);
 static tree cp_make_fname_decl (location_t, tree, int);
 static void initialize_predefined_identifiers (void);
@@ -10371,7 +10371,7 @@ get_dso_handle_node (void)
is passed to the cleanup function, otherwise no argument is passed.  */
 
 static tree
-start_cleanup_fn (tree decl, bool ob_parm)
+start_cleanup_fn (tree decl, bool ob_parm, bool omp_target)
 {
   push_to_top_level ();
 
@@ -10382,7 +10382,7 @@ start_cleanup_fn (tree decl, bool ob_parm)
   gcc_checking_assert (HAS_DECL_ASSEMBLER_NAME_P (decl));
   const char *dname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
   dname = targetm.strip_name_encoding (dname);
-  char *name = ACONCAT (("__tcf", dname, NULL));
+  char *name = ACONCAT ((omp_target ? "__omp_tcf" : "__tcf", dname, NULL));
 
   tree fntype = TREE_TYPE (ob_parm ? get_cxa_atexit_fn_ptr_type ()
   : get_atexit_fn_ptr_type ());
@@ -10409,6 +10409,15 @@ start_cleanup_fn (tree decl, bool ob_parm)
 }
 
   fndecl = pushdecl (fndecl, /*hidden=*/true);
+  if (omp_target)
+{
+  DECL_ATTRIBUTES (fndecl)
+   = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
+DECL_ATTRIBUTES (fndecl));
+  DECL_ATTRIBUTES (fndecl)
+   = tree_cons (get_identifier ("omp declare target nohost"), NULL_TREE,
+DECL_ATTRIBUTES (fndecl));
+}
   start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
 
   pop_lang_context ();
@@ -10430,7 +10439,7 @@ end_cleanup_fn (void)
static storage duration.  */
 
 tree
-register_dtor_fn (tree decl)
+register_dtor_fn (tree decl, bool omp_target)
 {
   tree cleanup;
   tree addr;
@@ -10476,7 +10485,7 @@ register_dtor_fn (tree decl)
   build_cleanup (decl);
 
   /* Now start the function.  */
-  cleanup = start_cleanup_fn (decl, ob_parm);
+  cleanup = start_cleanup_fn (decl, ob_parm, omp_target);
 
   /* Now, recompute the cleanup.  It may contain SAVE_EXPRs that refer
 to the original function, rather 

[gcc r15-7692] openmp: Mark OpenMP atomic write expression as read [PR119000]

2025-02-25 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:cdffc76393488a73671b70481cf8a4b7c289029d

commit r15-7692-gcdffc76393488a73671b70481cf8a4b7c289029d
Author: Jakub Jelinek 
Date:   Tue Feb 25 09:33:21 2025 +0100

openmp: Mark OpenMP atomic write expression as read [PR119000]

The following testcase was emitting false positive warning that
the rhs of #pragma omp atomic write was stored but not read,
when the atomic actually does read it.  The following patch
fixes that by calling default_function_array_read_conversion
on it, so that it is marked as read as well as converted from
lvalue to rvalue.
Furthermore, the code had
if (code == NOP_EXPR) ... else ... if (code == NOP_EXPR) ...
with none of ... parts changing code, so I've merged the two ifs.

2025-02-25  Jakub Jelinek  

PR c/119000
* c-parser.cc (c_parser_omp_atomic): For omp write call
default_function_array_read_conversion on the rhs expression.
Merge the two adjacent if (code == NOP_EXPR) blocks.

* c-c++-common/gomp/pr119000.c: New test.

Diff:
---
 gcc/c/c-parser.cc  | 22 ++
 gcc/testsuite/c-c++-common/gomp/pr119000.c | 16 
 2 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 62c6bc031d69..7672e06fdd0d 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -22884,9 +22884,16 @@ c_parser_omp_atomic (location_t loc, c_parser *parser, 
bool openacc)
goto saw_error;
   if (code == NOP_EXPR)
{
- lhs = c_parser_expression (parser).value;
- lhs = c_fully_fold (lhs, false, NULL);
- if (lhs == error_mark_node)
+ eloc = c_parser_peek_token (parser)->location;
+ expr = c_parser_expression (parser);
+ expr = default_function_array_read_conversion (eloc, expr);
+ /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
+opcode.  */
+ code = OMP_ATOMIC;
+ lhs = v;
+ v = NULL_TREE;
+ rhs = c_fully_fold (expr.value, false, NULL);
+ if (rhs == error_mark_node)
goto saw_error;
}
   else
@@ -22899,15 +22906,6 @@ c_parser_omp_atomic (location_t loc, c_parser *parser, 
bool openacc)
  if (non_lvalue_p)
lhs = non_lvalue (lhs);
}
-  if (code == NOP_EXPR)
-   {
- /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
-opcode.  */
- code = OMP_ATOMIC;
- rhs = lhs;
- lhs = v;
- v = NULL_TREE;
-   }
   goto done;
 case OMP_ATOMIC_CAPTURE_NEW:
   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
diff --git a/gcc/testsuite/c-c++-common/gomp/pr119000.c 
b/gcc/testsuite/c-c++-common/gomp/pr119000.c
new file mode 100644
index ..e5b7ab0c2b8c
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/pr119000.c
@@ -0,0 +1,16 @@
+/* PR c/119000 */
+/* { dg-do compile } */
+/* { dg-options "-fopenmp -Wunused-but-set-variable" } */
+
+int
+foo (void)
+{
+  int a = 1, b, c = 1, v;  /* { dg-warning "variable 'b' set but not used" 
} */
+  #pragma omp atomic write
+  v = a;
+  #pragma omp atomic read
+  b = v;
+  #pragma omp atomic update
+  v += c;
+  return v;
+}


[gcc r13-9392] tree-optimization/114921 - _Float16 -> __bf16 isn't noop fixup

2025-02-25 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:9abe274a320c61e0e2cf653f3fb64ea2ae8e146c

commit r13-9392-g9abe274a320c61e0e2cf653f3fb64ea2ae8e146c
Author: Richard Biener 
Date:   Mon May 6 12:03:09 2024 +0200

tree-optimization/114921 - _Float16 -> __bf16 isn't noop fixup

The following further strengthens the check which convert expressions
we allow to vectorize as simple copy by resorting to
tree_nop_conversion_p on the vector components.

PR tree-optimization/114921
* tree-vect-stmts.cc (vectorizable_assignment): Use
tree_nop_conversion_p to identify converts we can vectorize
with a simple assignment.

(cherry picked from commit d0d6dcc019cd32eebf85d625f56e0f7573938319)

Diff:
---
 gcc/tree-vect-stmts.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index cf021ec77169..98cf3f2bfc07 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -5587,15 +5587,15 @@ vectorizable_assignment (vec_info *vinfo,
 
   /* We can handle VIEW_CONVERT conversions that do not change the number
  of elements or the vector size or other conversions when the component
- mode keeps the same.  */
+ types are nop-convertible.  */
   if (!vectype_in
   || maybe_ne (TYPE_VECTOR_SUBPARTS (vectype_in), nunits)
   || (code == VIEW_CONVERT_EXPR
  && maybe_ne (GET_MODE_SIZE (TYPE_MODE (vectype)),
   GET_MODE_SIZE (TYPE_MODE (vectype_in
   || (CONVERT_EXPR_CODE_P (code)
- && (TYPE_MODE (TREE_TYPE (vectype))
- != TYPE_MODE (TREE_TYPE (vectype_in)
+ && !tree_nop_conversion_p (TREE_TYPE (vectype),
+TREE_TYPE (vectype_in
 return false;
 
   if (VECTOR_BOOLEAN_TYPE_P (vectype) != VECTOR_BOOLEAN_TYPE_P (vectype_in))


[gcc r13-9393] tree-optimization/117119 - ICE with int128 IV in dataref analysis

2025-02-25 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:55c8de5d87509234cfb9fed025a4d4d7c0277a92

commit r13-9393-g55c8de5d87509234cfb9fed025a4d4d7c0277a92
Author: Richard Biener 
Date:   Mon Jan 13 09:12:23 2025 +0100

tree-optimization/117119 - ICE with int128 IV in dataref analysis

Here's another fix for a missing check that an IV value fits in a
HIW.  It's originally from Stefan.

PR tree-optimization/117119
* tree-data-ref.cc (initialize_matrix_A): Check whether
an INTEGER_CST fits in HWI, otherwise return chrec_dont_know.

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

Co-Authored-By: Stefan Schulze Frielinghaus 
(cherry picked from commit d3904a3ad9d7b4c8e5e536e5166b89548510fd48)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr117119.c | 10 ++
 gcc/tree-data-ref.cc|  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr117119.c 
b/gcc/testsuite/gcc.dg/torture/pr117119.c
new file mode 100644
index ..0ec4ac1b1802
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr117119.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target int128 } */
+
+unsigned __int128 g_728;
+int func_1_l_5011[8];
+void func_1() {
+  for (;; g_728 += 1)
+func_1_l_5011[g_728] ^= func_1_l_5011[g_728 + 5];
+}
+void main() {}
diff --git a/gcc/tree-data-ref.cc b/gcc/tree-data-ref.cc
index a8f07030512e..1a8edf8f9ab2 100644
--- a/gcc/tree-data-ref.cc
+++ b/gcc/tree-data-ref.cc
@@ -4055,7 +4055,7 @@ initialize_matrix_A (lambda_matrix A, tree chrec, 
unsigned index, int mult)
   }
 
 case INTEGER_CST:
-  return chrec;
+  return cst_and_fits_in_hwi (chrec) ? chrec : chrec_dont_know;
 
 default:
   gcc_unreachable ();


[gcc r13-9391] tree-optimization/114921 - _Float16 -> __bf16 isn't noop

2025-02-25 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:98fe2ae8afa5dea19034d48876011a636dc23043

commit r13-9391-g98fe2ae8afa5dea19034d48876011a636dc23043
Author: Richard Biener 
Date:   Thu May 2 13:55:15 2024 +0200

tree-optimization/114921 - _Float16 -> __bf16 isn't noop

The vectorizer handles a _Float16 to __bf16 conversion through
vectorizable_assignment, thinking it's a noop.  The following
fixes this by requiring the same vector component mode when
checking for CONVERT_EXPR_CODE_P, being stricter than for
VIEW_CONVERT_EXPR.

PR tree-optimization/114921
* tree-vect-stmts.cc (vectorizable_assignment): Require
same vector component modes for input and output for
CONVERT_EXPR_CODE_P.

(cherry picked from commit 87e35da16df74cd1c4729a55d94e7bc592487f48)

Diff:
---
 gcc/tree-vect-stmts.cc | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index e3dea33e04a7..cf021ec77169 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -5585,14 +5585,17 @@ vectorizable_assignment (vec_info *vinfo,
   if (!vectype_in)
 vectype_in = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op), slp_node);
 
-  /* We can handle NOP_EXPR conversions that do not change the number
- of elements or the vector size.  */
-  if ((CONVERT_EXPR_CODE_P (code)
-   || code == VIEW_CONVERT_EXPR)
-  && (!vectype_in
- || maybe_ne (TYPE_VECTOR_SUBPARTS (vectype_in), nunits)
- || maybe_ne (GET_MODE_SIZE (TYPE_MODE (vectype)),
-  GET_MODE_SIZE (TYPE_MODE (vectype_in)
+  /* We can handle VIEW_CONVERT conversions that do not change the number
+ of elements or the vector size or other conversions when the component
+ mode keeps the same.  */
+  if (!vectype_in
+  || maybe_ne (TYPE_VECTOR_SUBPARTS (vectype_in), nunits)
+  || (code == VIEW_CONVERT_EXPR
+ && maybe_ne (GET_MODE_SIZE (TYPE_MODE (vectype)),
+  GET_MODE_SIZE (TYPE_MODE (vectype_in
+  || (CONVERT_EXPR_CODE_P (code)
+ && (TYPE_MODE (TREE_TYPE (vectype))
+ != TYPE_MODE (TREE_TYPE (vectype_in)
 return false;
 
   if (VECTOR_BOOLEAN_TYPE_P (vectype) != VECTOR_BOOLEAN_TYPE_P (vectype_in))


[gcc r13-9397] tree-optimization/117912 - bogus address equivalences for __builtin_object_size

2025-02-25 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:56f5e71a5b3de4a07a6f93bac670df5cd4a61734

commit r13-9397-g56f5e71a5b3de4a07a6f93bac670df5cd4a61734
Author: Richard Biener 
Date:   Thu Dec 5 10:47:13 2024 +0100

tree-optimization/117912 - bogus address equivalences for 
__builtin_object_size

VN again is the culprit for exploiting address equivalences before
__builtin_object_size got the chance to do its job.  This time
it isn't about union members but adjacent structure fields where
an address to one after the last element of an array field can
spill over to the next field.

The following protects all out-of-bound accesses on the upper bound
side (singling out TYPE_MAX_VALUE + 1 is more expensive).  It
ignores other out-of-bound addresses that would invoke UB.

Zero-sized arrays are a bit awkward because the C++ represents them
with a -1U upper bound.

There's a similar issue for zero-sized components whose address can
be the same as the adjacent field in C.

PR tree-optimization/117912
* tree-ssa-sccvn.cc (copy_reference_ops_from_ref): For addresses
of zero-sized components do not set ->off if the object size pass
didn't run.
For OOB ARRAY_REF accesses in address expressions avoid setting
->off if the object size pass didn't run.
(valueize_refs_1): Likewise.

* c-c++-common/torture/pr117912-1.c: New testcase.
* c-c++-common/torture/pr117912-2.c: Likewise.
* c-c++-common/torture/pr117912-3.c: Likewise.

(cherry picked from commit 233972ab3b5338d7a5d1d7af9108c1f366170e44)

Diff:
---
 gcc/testsuite/c-c++-common/torture/pr117912-1.c | 28 
 gcc/testsuite/c-c++-common/torture/pr117912-2.c | 28 
 gcc/testsuite/c-c++-common/torture/pr117912-3.c | 61 +
 gcc/tree-ssa-sccvn.cc   | 51 +++--
 4 files changed, 164 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/torture/pr117912-1.c 
b/gcc/testsuite/c-c++-common/torture/pr117912-1.c
new file mode 100644
index ..2750585c7f77
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/pr117912-1.c
@@ -0,0 +1,28 @@
+/* { dg-do run } */
+
+struct S { int a; int b[24]; int c[24]; int d; };
+volatile int *p;
+
+void __attribute__((noipa))
+bar (int *q)
+{
+ p = q;
+}
+
+__SIZE_TYPE__ __attribute__((noipa))
+foo (struct S *p)
+{
+  bar (&p->b[24]);
+  bar (&p->c[0]);
+  return __builtin_object_size (&p->c[0], 1);
+}
+
+int
+main()
+{
+  struct S s;
+  __SIZE_TYPE__ x = foo (&s);
+  if (x < sizeof (int) * 24)
+__builtin_abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/c-c++-common/torture/pr117912-2.c 
b/gcc/testsuite/c-c++-common/torture/pr117912-2.c
new file mode 100644
index ..a3a621575635
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/pr117912-2.c
@@ -0,0 +1,28 @@
+/* { dg-do run } */
+
+struct S { int a; int b[0]; int c[24]; int d; };
+volatile int *p;
+
+void __attribute__((noipa))
+bar (int *q)
+{
+ p = q;
+}
+
+__SIZE_TYPE__ __attribute__((noipa))
+foo (struct S *p)
+{
+  bar (&p->b[0]);
+  bar (&p->c[0]);
+  return __builtin_object_size (&p->c[0], 1);
+}
+
+int
+main()
+{
+  struct S s;
+  __SIZE_TYPE__ x = foo (&s);
+  if (x < sizeof (int) * 24)
+__builtin_abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/c-c++-common/torture/pr117912-3.c 
b/gcc/testsuite/c-c++-common/torture/pr117912-3.c
new file mode 100644
index ..64e981d2a5e7
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/pr117912-3.c
@@ -0,0 +1,61 @@
+/* { dg-do run } */
+/* { dg-additional-options "-std=gnu++20" { target c++ } } */
+
+struct B {};
+struct A { int a;
+#ifdef __cplusplus
+  [[no_unique_address]]
+#endif
+  struct B b;
+  char c[]; };
+volatile void *p;
+
+void __attribute__((noipa))
+bar (void *q)
+{
+  p = q;
+}
+
+__SIZE_TYPE__ __attribute__((noipa))
+foo (struct A *p)
+{
+  bar (&p->b);
+  bar (&p->c);
+  return __builtin_object_size (&p->c, 1);
+}
+
+__SIZE_TYPE__ __attribute__((noipa))
+baz (void)
+{
+  struct A *p = (struct A *) __builtin_malloc (__builtin_offsetof (struct A, 
c) + 64);
+  bar (&p->b);
+  bar (&p->c);
+  return __builtin_object_size (&p->c, 1);
+}
+
+__SIZE_TYPE__ __attribute__((noipa))
+qux (struct A *p)
+{
+  bar (&p->b);
+  bar (&p->c);
+  return __builtin_object_size (&p->c, 3);
+}
+
+__SIZE_TYPE__ __attribute__((noipa))
+boo (void)
+{
+  struct A *p = (struct A *) __builtin_malloc (__builtin_offsetof (struct A, 
c) + 64);
+  bar (&p->b);
+  bar (&p->c);
+  return __builtin_object_size (&p->c, 3);
+}
+
+int
+main ()
+{
+  static struct A a = { .a = 1, .b = {}, .c = { 1, 2, 3, 4, 0 } };
+  if (foo (&a) < 5)
+__builtin_abort ();
+  if (baz () < 64)
+__builtin_abort ();
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 55ae05dc4cd2..3c9db41a8b2f 100644
--- a/gcc/tree-ssa-sccvn.cc

[gcc r13-9396] tree-optimization/116850 - corrupt post-dom info

2025-02-25 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:160e6aeb5c6bf17325c6b7b5dccf32d6eeaf9c32

commit r13-9396-g160e6aeb5c6bf17325c6b7b5dccf32d6eeaf9c32
Author: Richard Biener 
Date:   Thu Sep 26 15:41:59 2024 +0200

tree-optimization/116850 - corrupt post-dom info

Path isolation computes post-dominators on demand but can end up
splitting blocks after that, wrecking it.  We can delay splitting
of blocks until we no longer need the post-dom info which is what
the following patch does to solve the issue.

PR tree-optimization/116850
* gimple-ssa-isolate-paths.cc (bb_split_points): New global.
(insert_trap): Delay BB splitting if post-doms are computed.
(find_explicit_erroneous_behavior): Process delayed BB
splitting after releasing post dominators.
(gimple_ssa_isolate_erroneous_paths): Do not free post-dom
info here.

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

(cherry picked from commit 64163657ba7e70347087a63bb2b32d83b52ea7d9)

Diff:
---
 gcc/gimple-ssa-isolate-paths.cc | 23 ---
 gcc/testsuite/gcc.dg/pr116850.c | 12 
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/gcc/gimple-ssa-isolate-paths.cc b/gcc/gimple-ssa-isolate-paths.cc
index 175598a189c5..7135435f0918 100644
--- a/gcc/gimple-ssa-isolate-paths.cc
+++ b/gcc/gimple-ssa-isolate-paths.cc
@@ -62,6 +62,8 @@ check_loadstore (gimple *stmt, tree op, tree, void *data)
   return false;
 }
 
+static vec *bb_split_points;
+
 /* Insert a trap after SI and split the block after the trap.  */
 
 static void
@@ -104,14 +106,20 @@ insert_trap (gimple_stmt_iterator *si_p, tree op)
   gsi_insert_after (si_p, seq, GSI_NEW_STMT);
   if (stmt_ends_bb_p (stmt))
{
- split_block (gimple_bb (stmt), stmt);
+ if (dom_info_available_p (CDI_POST_DOMINATORS))
+   bb_split_points->safe_push (stmt);
+ else
+   split_block (gimple_bb (stmt), stmt);
  return;
}
 }
   else
 gsi_insert_before (si_p, seq, GSI_NEW_STMT);
 
-  split_block (gimple_bb (new_stmt), new_stmt);
+  if (dom_info_available_p (CDI_POST_DOMINATORS))
+bb_split_points->safe_push (new_stmt);
+  else
+split_block (gimple_bb (new_stmt), new_stmt);
   *si_p = gsi_for_stmt (stmt);
 }
 
@@ -842,6 +850,8 @@ static void
 find_explicit_erroneous_behavior (void)
 {
   basic_block bb;
+  auto_vec local_bb_split_points;
+  bb_split_points = &local_bb_split_points;
 
   FOR_EACH_BB_FN (bb, cfun)
 {
@@ -883,6 +893,14 @@ find_explicit_erroneous_behavior (void)
warn_return_addr_local (bb, return_stmt);
}
 }
+
+  free_dominance_info (CDI_POST_DOMINATORS);
+
+  /* Perform delayed splitting of blocks.  */
+  for (gimple *stmt : local_bb_split_points)
+split_block (gimple_bb (stmt), stmt);
+
+  bb_split_points = NULL;
 }
 
 /* Search the function for statements which, if executed, would cause
@@ -939,7 +957,6 @@ gimple_ssa_isolate_erroneous_paths (void)
   /* We scramble the CFG and loop structures a bit, clean up
  appropriately.  We really should incrementally update the
  loop structures, in theory it shouldn't be that hard.  */
-  free_dominance_info (CDI_POST_DOMINATORS);
   if (cfg_altered)
 {
   free_dominance_info (CDI_DOMINATORS);
diff --git a/gcc/testsuite/gcc.dg/pr116850.c b/gcc/testsuite/gcc.dg/pr116850.c
new file mode 100644
index ..7ab5da1848bd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116850.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-Os -w" } */
+
+int a, b;
+int *c()
+{
+  int d, *e = 0, *f = &d, *g = &a;
+  if (b)
+g = 0;
+  *e = *g;
+  return f;
+}


[gcc r13-9394] tree-optimization/118717 - store commoning vs. abnormals

2025-02-25 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:08852469a263da1a05f020041c647e42c5cff09a

commit r13-9394-g08852469a263da1a05f020041c647e42c5cff09a
Author: Richard Biener 
Date:   Mon Feb 3 09:55:50 2025 +0100

tree-optimization/118717 - store commoning vs. abnormals

When we sink common stores in cselim or the sink pass we have to
make sure to not introduce overlapping lifetimes for abnormals
used in the ref.  The easiest is to avoid sinking stmts which
reference abnormals at all which is what the following does.

PR tree-optimization/118717
* tree-ssa-phiopt.cc (cond_if_else_store_replacement_1):
Do not common stores referencing abnormal SSA names.
* tree-ssa-sink.cc (sink_common_stores_to_bb): Likewise.

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

(cherry picked from commit fbcbbfe2bf83eb8b1347144eeca37b06be5a8bb5)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr118717.c | 41 +
 gcc/tree-ssa-phiopt.cc  |  4 +++-
 gcc/tree-ssa-sink.cc|  4 +++-
 3 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr118717.c 
b/gcc/testsuite/gcc.dg/torture/pr118717.c
new file mode 100644
index ..42dc5ec84f28
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr118717.c
@@ -0,0 +1,41 @@
+/* { dg-do compile } */
+
+void jj(void);
+int ff1(void) __attribute__((__returns_twice__));
+struct s2 {
+  int prev;
+};
+typedef struct s1 {
+  unsigned interrupt_flag;
+  unsigned interrupt_mask;
+  int tag;
+  int state;
+}s1;
+int ff(void);
+static inline
+int mm(s1 *ec) {
+  if (ff())
+if (ec->interrupt_flag & ~(ec)->interrupt_mask)
+  return 0;
+}
+void ll(s1 *ec) {
+  int t = 1;
+  int state;
+  if (t)
+  {
+{
+  s1 *const _ec = ec;
+  struct s2 _tag = {0};
+  if (ff1())
+   state = ec->state;
+  else
+   state = 0;
+  if (!state)
+   mm (ec);
+  _ec->tag = _tag.prev;
+}
+if (state)
+  __builtin_exit(0);
+  }
+  jj();
+}
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index d507530307a5..06b099d517f9 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -3553,7 +3553,9 @@ cond_if_else_store_replacement_1 (basic_block then_bb, 
basic_block else_bb,
   || else_assign == NULL
   || !gimple_assign_single_p (else_assign)
   || gimple_clobber_p (else_assign)
-  || gimple_has_volatile_ops (else_assign))
+  || gimple_has_volatile_ops (else_assign)
+  || stmt_references_abnormal_ssa_name (then_assign)
+  || stmt_references_abnormal_ssa_name (else_assign))
 return false;
 
   lhs = gimple_assign_lhs (then_assign);
diff --git a/gcc/tree-ssa-sink.cc b/gcc/tree-ssa-sink.cc
index 87b1d40c174f..e886aa86b052 100644
--- a/gcc/tree-ssa-sink.cc
+++ b/gcc/tree-ssa-sink.cc
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-cfg.h"
 #include "cfgloop.h"
 #include "tree-eh.h"
+#include "tree-dfa.h"
 
 /* TODO:
1. Sinking store only using scalar promotion (IE without moving the RHS):
@@ -529,7 +530,8 @@ sink_common_stores_to_bb (basic_block bb)
  gimple *def = SSA_NAME_DEF_STMT (arg);
  if (! is_gimple_assign (def)
  || stmt_can_throw_internal (cfun, def)
- || (gimple_phi_arg_edge (phi, i)->flags & EDGE_ABNORMAL))
+ || (gimple_phi_arg_edge (phi, i)->flags & EDGE_ABNORMAL)
+ || stmt_references_abnormal_ssa_name (def))
{
  /* ???  We could handle some cascading with the def being
 another PHI.  We'd have to insert multiple PHIs for


[gcc r13-9395] middle-end/115641 - invalid address construction

2025-02-25 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:ac2bfec1d87d53df6bf7eec9f999781e7fa718b0

commit r13-9395-gac2bfec1d87d53df6bf7eec9f999781e7fa718b0
Author: Richard Biener 
Date:   Thu Jul 18 13:35:33 2024 +0200

middle-end/115641 - invalid address construction

fold_truth_andor_1 via make_bit_field_ref builds an address of
a CALL_EXPR which isn't valid GENERIC and later causes an ICE.
The following simply avoids the folding for f ().a != 1 || f ().b != 2
as it is a premature optimization anyway.  The alternative would
have been to build a TARGET_EXPR around the call.  To get this far
f () has to be const as otherwise the two calls are not semantically
equivalent for the optimization.

PR middle-end/115641
* fold-const.cc (decode_field_reference): If the inner
reference isn't something we can take the address of, fail.

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

(cherry picked from commit 3670c70c561656a19f6bff36dd229f18120af127)

Diff:
---
 gcc/fold-const.cc   |  3 +++
 gcc/testsuite/gcc.dg/torture/pr115641.c | 29 +
 2 files changed, 32 insertions(+)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 4b6552333e6b..8215cbef991f 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -4803,6 +4803,9 @@ decode_field_reference (location_t loc, tree *exp_, 
HOST_WIDE_INT *pbitsize,
   || *pbitsize < 0
   || offset != 0
   || TREE_CODE (inner) == PLACEHOLDER_EXPR
+  /* We eventually want to build a larger reference and need to take
+the address of this.  */
+  || (!REFERENCE_CLASS_P (inner) && !DECL_P (inner))
   /* Reject out-of-bound accesses (PR79731).  */
   || (! AGGREGATE_TYPE_P (TREE_TYPE (inner))
  && compare_tree_int (TYPE_SIZE (TREE_TYPE (inner)),
diff --git a/gcc/testsuite/gcc.dg/torture/pr115641.c 
b/gcc/testsuite/gcc.dg/torture/pr115641.c
new file mode 100644
index ..65fb09ca64fc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr115641.c
@@ -0,0 +1,29 @@
+/* { dg-do run } */
+
+typedef struct {
+  char hours, day, month;
+  short year;
+} T;
+
+T g (void)
+{
+  T now;
+  now.hours = 1;
+  now.day = 2;
+  now.month = 3;
+  now.year = 4;
+  return now;
+}
+
+__attribute__((const)) T f (void)
+{
+  T virk = g ();
+  return virk;
+}
+
+int main ()
+{
+  if (f ().hours != 1 || f ().day != 2 || f ().month != 3 || f ().year != 4)
+__builtin_abort ();
+  return 0;
+}


[gcc r15-7693] Fortran: Use correct size when transferring between images [PR107635]

2025-02-25 Thread Andre Vehreschild via Gcc-cvs
https://gcc.gnu.org/g:cc81363c33a3b5768daf2d8a62ae1a80db12ef96

commit r15-7693-gcc81363c33a3b5768daf2d8a62ae1a80db12ef96
Author: Andre Vehreschild 
Date:   Wed Feb 19 09:04:47 2025 +0100

Fortran: Use correct size when transferring between images [PR107635]

gcc/fortran/ChangeLog:

PR fortran/107635

* trans-intrinsic.cc (conv_caf_sendget): Use the size of data
transferred between the two images and not the descritor's size.

Diff:
---
 gcc/fortran/trans-intrinsic.cc | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 2c4c47816c82..80e98dc3c202 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -1658,20 +1658,23 @@ conv_caf_sendget (gfc_code *code)
   gfc_init_se (&rhs_se, NULL);
   if (rhs_expr->rank == 0)
 {
-  gfc_conv_expr (&rhs_se, rhs_expr);
-  gfc_add_block_to_block (&block, &rhs_se.pre);
   opt_rhs_desc = null_pointer_node;
   if (rhs_expr->ts.type == BT_CHARACTER)
{
+ gfc_conv_expr (&rhs_se, rhs_expr);
+ gfc_add_block_to_block (&block, &rhs_se.pre);
  opt_rhs_charlen = gfc_build_addr_expr (
NULL_TREE, gfc_trans_force_lval (&block, rhs_se.string_length));
  rhs_size = build_int_cstu (size_type_node, rhs_expr->ts.kind);
}
   else
{
+ gfc_typespec *ts
+   = &sender_fn_expr->symtree->n.sym->formal->next->next->sym->ts;
+
  opt_rhs_charlen
= build_zero_cst (build_pointer_type (size_type_node));
- rhs_size = TREE_TYPE (rhs_se.expr)->type_common.size_unit;
+ rhs_size = gfc_typenode_for_spec (ts)->type_common.size_unit;
}
 }
   else if (!TYPE_LANG_SPECIFIC (TREE_TYPE (rhs_caf_decl))->rank


[gcc r15-7694] Fortran: Fix detection of descriptor arrays in coarray [PR107635]

2025-02-25 Thread Andre Vehreschild via Gcc-cvs
https://gcc.gnu.org/g:af73228fdb2e61c6354f972987ba2a746c3519f7

commit r15-7694-gaf73228fdb2e61c6354f972987ba2a746c3519f7
Author: Andre Vehreschild 
Date:   Fri Feb 21 14:06:28 2025 +0100

Fortran: Fix detection of descriptor arrays in coarray [PR107635]

Look at the formal arguments generated type in the function declaration
to figure if an argument is a descriptor arrays.  Fix handling of class
types while splitting coarray expressions.

PR fortran/107635

gcc/fortran/ChangeLog:

* coarray.cc (fixup_comp_refs): For class types set correct
component (class) type.
(split_expr_at_caf_ref): Provide location.
* trans-intrinsic.cc (conv_caf_send_to_remote): Look at
generated formal argument and not declared one to detect
descriptor arrays.
(conv_caf_sendget): Same.

Diff:
---
 gcc/fortran/coarray.cc | 15 ++-
 gcc/fortran/trans-intrinsic.cc | 30 --
 2 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/gcc/fortran/coarray.cc b/gcc/fortran/coarray.cc
index e5648e0d0279..f53de0b20e32 100644
--- a/gcc/fortran/coarray.cc
+++ b/gcc/fortran/coarray.cc
@@ -295,11 +295,12 @@ move_coarray_ref (gfc_ref **from, gfc_expr *expr)
 static void
 fixup_comp_refs (gfc_expr *expr)
 {
-  gfc_symbol *type = expr->symtree->n.sym->ts.type == BT_DERIVED
-  ? expr->symtree->n.sym->ts.u.derived
-  : (expr->symtree->n.sym->ts.type == BT_CLASS
-   ? CLASS_DATA (expr->symtree->n.sym)->ts.u.derived
-   : nullptr);
+  bool class_ref = expr->symtree->n.sym->ts.type == BT_CLASS;
+  gfc_symbol *type
+= expr->symtree->n.sym->ts.type == BT_DERIVED
+   ? expr->symtree->n.sym->ts.u.derived
+   : (class_ref ? CLASS_DATA (expr->symtree->n.sym)->ts.u.derived
+: nullptr);
   if (!type)
 return;
   gfc_ref **pref = &(expr->ref);
@@ -317,6 +318,9 @@ fixup_comp_refs (gfc_expr *expr)
  ref = nullptr;
  break;
}
+ if (class_ref)
+   /* Link to the class type to allow for derived type resolution.  */
+   (*pref)->u.c.sym = ref->u.c.sym;
  (*pref)->next = ref->next;
  ref->next = NULL;
  gfc_free_ref_list (ref);
@@ -372,6 +376,7 @@ split_expr_at_caf_ref (gfc_expr *expr, gfc_namespace *ns,
   st->n.sym->attr.dummy = 1;
   st->n.sym->attr.intent = INTENT_IN;
   st->n.sym->ts = *caf_ts;
+  st->n.sym->declared_at = expr->where;
 
   *post_caf_ref_expr = gfc_get_variable_expr (st);
   (*post_caf_ref_expr)->where = expr->where;
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 80e98dc3c202..c97829fd8a82 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -1445,8 +1445,14 @@ conv_caf_send_to_remote (gfc_code *code)
  NULL_TREE, gfc_trans_force_lval (&block, lhs_se.string_length));
   else
opt_lhs_charlen = build_zero_cst (build_pointer_type (size_type_node));
-  if (!TYPE_LANG_SPECIFIC (TREE_TYPE (caf_decl))->rank
- || GFC_ARRAY_TYPE_P (TREE_TYPE (caf_decl)))
+  /* Get the third formal argument of the receiver function.  (This is the
+location where to put the data on the remote image.)  Need to look at
+the argument in the function decl, because in the gfc_symbol's formal
+argument an array may have no descriptor while in the generated
+function decl it has.  */
+  tmp = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TYPE_ARG_TYPES (
+   TREE_TYPE (receiver_fn_expr->symtree->n.sym->backend_decl);
+  if (!GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp)))
opt_lhs_desc = null_pointer_node;
   else
opt_lhs_desc
@@ -1635,8 +1641,14 @@ conv_caf_sendget (gfc_code *code)
  NULL_TREE, gfc_trans_force_lval (&block, lhs_se.string_length));
   else
opt_lhs_charlen = build_zero_cst (build_pointer_type (size_type_node));
-  if (!TYPE_LANG_SPECIFIC (TREE_TYPE (lhs_caf_decl))->rank
- || GFC_ARRAY_TYPE_P (TREE_TYPE (lhs_caf_decl)))
+  /* Get the third formal argument of the receiver function.  (This is the
+location where to put the data on the remote image.)  Need to look at
+the argument in the function decl, because in the gfc_symbol's formal
+argument an array may have no descriptor while in the generated
+function decl it has.  */
+  tmp = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TYPE_ARG_TYPES (
+   TREE_TYPE (receiver_fn_expr->symtree->n.sym->backend_decl);
+  if (!GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp)))
opt_lhs_desc = null_pointer_node;
   else
opt_lhs_desc
@@ -1677,8 +1689,14 @@ conv_caf_sendget (gfc_code *code)
  rhs_size = gfc_typenode_for_spec (ts)->type_common.size_unit;
}
 }
-  else if (!TYPE_LANG_SPECIFIC (TREE_

[gcc r14-11342] s390: Fix s390_valid_shift_count() for TI mode [PR118835]

2025-02-25 Thread Stefan Schulze Frielinghaus via Gcc-cvs
https://gcc.gnu.org/g:ce4cb48c3396837cf1562882b3f23f768558945b

commit r14-11342-gce4cb48c3396837cf1562882b3f23f768558945b
Author: Stefan Schulze Frielinghaus 
Date:   Thu Feb 13 09:13:06 2025 +0100

s390: Fix s390_valid_shift_count() for TI mode [PR118835]

During combine we may end up with

(set (reg:DI 66 [ _6 ])
 (ashift:DI (reg:DI 72 [ x ])
(subreg:QI (and:TI (reg:TI 67 [ _1 ])
   (const_wide_int 0x0aabf))
   15)))

where the shift count operand does not trivially fit the scheme of
address operands.  Reject those operands, especially since
strip_address_mutations() expects expressions of the form
(and ... (const_int ...)) and fails for (and ... (const_wide_int ...)).

Thus, be more strict here and accept only CONST_INT operands.  Done by
replacing immediate_operand() with const_int_operand() which is enough
since the former only additionally checks for LEGITIMATE_PIC_OPERAND_P
and targetm.legitimate_constant_p which are always true for CONST_INT
operands.

While on it, fix indentation of the if block.

gcc/ChangeLog:

PR target/118835
* config/s390/s390.cc (s390_valid_shift_count): Reject shift
count operands which do not trivially fit the scheme of
address operands.

gcc/testsuite/ChangeLog:

* gcc.target/s390/pr118835.c: New test.

(cherry picked from commit ac9806dae30d07ab082ac341fe5646987753adcb)

Diff:
---
 gcc/config/s390/s390.cc  | 35 ++--
 gcc/testsuite/gcc.target/s390/pr118835.c | 21 +++
 2 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index f2e4f5e101cb..8b383034e036 100644
--- a/gcc/config/s390/s390.cc
+++ b/gcc/config/s390/s390.cc
@@ -3363,26 +3363,31 @@ s390_valid_shift_count (rtx op, HOST_WIDE_INT 
implicit_mask)
 
   /* Check for an and with proper constant.  */
   if (GET_CODE (op) == AND)
-  {
-rtx op1 = XEXP (op, 0);
-rtx imm = XEXP (op, 1);
+{
+  rtx op1 = XEXP (op, 0);
+  rtx imm = XEXP (op, 1);
 
-if (GET_CODE (op1) == SUBREG && subreg_lowpart_p (op1))
-  op1 = XEXP (op1, 0);
+  if (GET_CODE (op1) == SUBREG && subreg_lowpart_p (op1))
+   op1 = XEXP (op1, 0);
 
-if (!(register_operand (op1, GET_MODE (op1)) || GET_CODE (op1) == PLUS))
-  return false;
+  if (!(register_operand (op1, GET_MODE (op1)) || GET_CODE (op1) == PLUS))
+   return false;
 
-if (!immediate_operand (imm, GET_MODE (imm)))
-  return false;
+  /* Accept only CONST_INT as immediates, i.e., reject shift count operands
+which do not trivially fit the scheme of address operands.  Especially
+since strip_address_mutations() expects expressions of the form
+(and ... (const_int ...)) and fails for
+(and ... (const_wide_int ...)).  */
+  if (!const_int_operand (imm, GET_MODE (imm)))
+   return false;
 
-HOST_WIDE_INT val = INTVAL (imm);
-if (implicit_mask > 0
-   && (val & implicit_mask) != implicit_mask)
-  return false;
+  HOST_WIDE_INT val = INTVAL (imm);
+  if (implicit_mask > 0
+ && (val & implicit_mask) != implicit_mask)
+   return false;
 
-op = op1;
-  }
+  op = op1;
+}
 
   /* Check the rest.  */
   return s390_decompose_addrstyle_without_index (op, NULL, NULL);
diff --git a/gcc/testsuite/gcc.target/s390/pr118835.c 
b/gcc/testsuite/gcc.target/s390/pr118835.c
new file mode 100644
index ..1ca6cd95543b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/pr118835.c
@@ -0,0 +1,21 @@
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-O2" } */
+
+/* During combine we may end up with patterns of the form
+
+   (set (reg:DI 66 [ _6 ])
+(ashift:DI (reg:DI 72 [ x ])
+   (subreg:QI (and:TI (reg:TI 67 [ _1 ])
+  (const_wide_int 0x0aabf))
+  15)))
+
+   which should be rejected since the shift count does not trivially fit the
+   scheme of address operands.  */
+
+long
+test (long x, int y)
+{
+  __int128 z = 0xAABF;
+  z &= y;
+  return x << z;
+}


[gcc r15-7704] libphobos: Add script for extracting unittests from phobos

2025-02-25 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:df4565eaa9b02906a8fa6bb37845c0b4fdedaa20

commit r15-7704-gdf4565eaa9b02906a8fa6bb37845c0b4fdedaa20
Author: Iain Buclaw 
Date:   Tue Feb 25 19:47:06 2025 +0100

libphobos: Add script for extracting unittests from phobos

This script parses all unittests annotated with three slashes (`///')
and extracts them into a standalone test case.  The intended use is for
generating inexpensive tests to be ran for the phobos testsuite.

libphobos/ChangeLog:

* scripts/.gitignore: Add tests_extractor.
* scripts/README: Document tests_extractor.d.
* scripts/tests_extractor.d: New file.

Diff:
---
 libphobos/scripts/.gitignore|   1 +
 libphobos/scripts/README|  11 ++
 libphobos/scripts/tests_extractor.d | 224 
 3 files changed, 236 insertions(+)

diff --git a/libphobos/scripts/.gitignore b/libphobos/scripts/.gitignore
index a5d300b6f604..ddbaf4164b69 100644
--- a/libphobos/scripts/.gitignore
+++ b/libphobos/scripts/.gitignore
@@ -1,3 +1,4 @@
 # Dub leaves built programs in this directory.
 gen_druntime_sources
 gen_phobos_sources
+tests_extractor
diff --git a/libphobos/scripts/README b/libphobos/scripts/README
index 248324dddac3..5444b71ccba5 100644
--- a/libphobos/scripts/README
+++ b/libphobos/scripts/README
@@ -26,3 +26,14 @@ gen_phobos_sources.d
 Example:
 
cd src && ../scripts/gen_phobos_sources >> Makefile.am
+
+tests_extractor.d
+
+Searches the given input directory recursively for public unittest blocks
+(annotated with three slashes). The tests will be extracted as one file for
+each source file to the output directory.  Used to regenerate all tests
+cases in testsuite/libphobos.phobos.
+
+Example:
+
+   ./tests_extractor -i ../libphobos/src -o ../testsuite/libphobos.phobos
diff --git a/libphobos/scripts/tests_extractor.d 
b/libphobos/scripts/tests_extractor.d
new file mode 100644
index ..bc861f50ff42
--- /dev/null
+++ b/libphobos/scripts/tests_extractor.d
@@ -0,0 +1,224 @@
+#!/usr/bin/env dub
+/++dub.sdl:
+name "tests_extractor"
+dependency "libdparse" version="~>0.24.0"
+dflags "-fall-instantiations" platform="gdc"
++/
+// Written in the D programming language.
+
+import dparse.ast;
+import std.algorithm;
+import std.conv;
+import std.exception;
+import std.experimental.logger;
+import std.file;
+import std.path;
+import std.range;
+import std.stdio;
+
+class TestVisitor : ASTVisitor
+{
+File outFile;
+ubyte[] sourceCode;
+string moduleName;
+
+this(File outFile, ubyte[] sourceCode)
+{
+this.outFile = outFile;
+this.sourceCode = sourceCode;
+}
+
+alias visit = ASTVisitor.visit;
+
+override void visit(const Module m)
+{
+if (m.moduleDeclaration !is null)
+{
+moduleName = m.moduleDeclaration.moduleName.identifiers.map!(i => 
i.text).join(".");
+}
+else
+{
+// Fallback: convert the file path to its module path, e.g. 
std/uni.d -> std.uni
+moduleName = outFile.name.replace(".d", "").replace(dirSeparator, 
".").replace(".package", "");
+}
+m.accept(this);
+}
+
+override void visit(const Declaration decl)
+{
+if (decl.unittest_ !is null && decl.unittest_.comment !is null)
+print(decl.unittest_, decl.attributes);
+
+decl.accept(this);
+}
+
+override void visit(const ConditionalDeclaration decl)
+{
+bool skipTrue;
+
+// Check if it's a version that should be skipped
+if (auto vcd = decl.compileCondition.versionCondition)
+{
+if (vcd.token.text == "StdDdoc")
+skipTrue = true;
+}
+
+// Search if/version block
+if (!skipTrue)
+{
+foreach (d; decl.trueDeclarations)
+visit(d);
+}
+
+// Search else block
+foreach (d; decl.falseDeclarations)
+visit(d);
+}
+
+private:
+
+void print(const Unittest u, const Attribute[] attributes)
+{
+static immutable predefinedAttributes = ["nogc", "system", "nothrow", 
"safe", "trusted", "pure"];
+
+// Write system attributes
+foreach (attr; attributes)
+{
+// pure and nothrow
+if (attr.attribute.type != 0)
+{
+import dparse.lexer : str;
+const attrText = attr.attribute.type.str;
+outFile.write(text(attrText, " "));
+}
+
+const atAttribute = attr.atAttribute;
+if (atAttribute is null)
+continue;
+
+const atText = atAttribute.identifier.text;
+
+// Ignore custom attributes (@myArg)
+if (!predefinedAttributes.canFind(atText))
+continue;
+
+outFile.write(text("@", atText, " "));
+}
+
+// Write the unittes

[gcc r15-7705] i386: Fix pr101950-2.c [PR115028]

2025-02-25 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:892ee5ffba0760794a932e36771863a86ef2b271

commit r15-7705-g892ee5ffba0760794a932e36771863a86ef2b271
Author: Andrew Pinski 
Date:   Thu Feb 20 13:03:51 2025 -0800

i386: Fix pr101950-2.c [PR115028]

So what is happening here is that after r15-268-g9dbff9c05520a7,
a move instruction still exists after combine and the register
allocator choses different register allocation order for the xor
and because the input operand of lzcntq is not the same as output
operand, there is an extra xor that happens (due to an errata).

This fixes the testcase by using loading from a pointer instead
of a function argument directly. The register allocator has more
freedom since the load has no hard register associated with it (rdi)
so it can be in eax register right away.

Tested for both -m32 and -m64 on x86_64-linux-gnu.

gcc/testsuite/ChangeLog:

PR testsuite/115028
* gcc.target/i386/pr101950-2.c: Use a pointer argument instead
of the argument directly.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/testsuite/gcc.target/i386/pr101950-2.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.target/i386/pr101950-2.c 
b/gcc/testsuite/gcc.target/i386/pr101950-2.c
index 896f1b464146..ccc361e3a46a 100644
--- a/gcc/testsuite/gcc.target/i386/pr101950-2.c
+++ b/gcc/testsuite/gcc.target/i386/pr101950-2.c
@@ -6,14 +6,19 @@
 /* { dg-final { scan-assembler-times "\txor\[ql]\t" 2 } } */
 /* { dg-final { scan-assembler-times "\tsar\[ql]\t|\tcltd" 2 } } */
 
+/* Use pointers to avoid register allocation difference due to argument
+   and return register being different and the difference in selecting eax
+   for one the result of the xor vs selecting rdi due to the order of the
+   shift vs the not shift. */
+
 int
-foo (long x)
+foo (long *x)
 {
-  return __builtin_clrsbl (x);
+  return __builtin_clrsbl (*x);
 }
 
 int
-bar (int x)
+bar (int *x)
 {
-  return __builtin_clrsb (x);
+  return __builtin_clrsb (*x);
 }


[gcc r15-7706] libstdc++: Fix typo in std::fill SFINAE constraint [PR93059]

2025-02-25 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:2256e30874af2ef804bb19d2eba40f9c92953beb

commit r15-7706-g2256e30874af2ef804bb19d2eba40f9c92953beb
Author: Jonathan Wakely 
Date:   Tue Feb 25 18:06:46 2025 +

libstdc++: Fix typo in std::fill SFINAE constraint [PR93059]

The r15-4321-gd8ef4471cb9c9f change incorrectly used __value as the
member of the __memcpyable_integer trait, but it should have been
__width. That meant this overload was not being used for _Tp != _Up.

Also return after doing the loop for the consteval case. The missing
return wasn't causing incorrect behaviour because the consteval loop
increments the iterator until it equals the end of the range, so the
memset isn't done.  But it's still better to return and not even try
to do the memset.

libstdc++-v3/ChangeLog:

PR libstdc++/93059
* include/bits/stl_algobase.h (__fill_a1): Fix typo in SFINAE
constraint.

Diff:
---
 libstdc++-v3/include/bits/stl_algobase.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/stl_algobase.h 
b/libstdc++-v3/include/bits/stl_algobase.h
index be311b91f53a..fc7cc89736a8 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -943,7 +943,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
 inline typename
 __gnu_cxx::__enable_if<__is_byte<_Up>::__value
 && (__are_same<_Up, _Tp>::__value // for std::byte
-  || __memcpyable_integer<_Tp>::__value),
+  || __memcpyable_integer<_Tp>::__width),
   void>::__type
 __fill_a1(_Up* __first, _Up* __last, const _Tp& __x)
 {
@@ -955,6 +955,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
{
  for (; __first != __last; ++__first)
*__first = __val;
+ return;
}
 #endif
   if (const size_t __len = __last - __first)


[gcc r15-7711] testsuite: Add pragma novector to more tests [PR118464]

2025-02-25 Thread Tamar Christina via Gcc-cvs
https://gcc.gnu.org/g:ebe7cd9f2833a79877fbc56829c4f37a518a9b1d

commit r15-7711-gebe7cd9f2833a79877fbc56829c4f37a518a9b1d
Author: Tamar Christina 
Date:   Wed Feb 26 07:31:28 2025 +

testsuite: Add pragma novector to more tests [PR118464]

These loops will now vectorize the entry finding
loops.  As such we get more failures because they
were not expecting to be vectorized.

Fixed by adding #pragma GCC novector.

gcc/testsuite/ChangeLog:

PR tree-optimization/118464
PR tree-optimization/116855
* g++.dg/ext/pragma-unroll-lambda-lto.C: Add pragma novector.
* gcc.dg/tree-ssa/gen-vect-2.c: Likewise.
* gcc.dg/tree-ssa/gen-vect-25.c: Likewise.
* gcc.dg/tree-ssa/gen-vect-32.c: Likewise.
* gcc.dg/tree-ssa/ivopt_mult_2g.c: Likewise.
* gcc.dg/tree-ssa/ivopts-5.c: Likewise.
* gcc.dg/tree-ssa/ivopts-6.c: Likewise.
* gcc.dg/tree-ssa/ivopts-7.c: Likewise.
* gcc.dg/tree-ssa/ivopts-8.c: Likewise.
* gcc.dg/tree-ssa/ivopts-9.c: Likewise.
* gcc.dg/tree-ssa/predcom-dse-1.c: Likewise.
* gcc.dg/tree-ssa/predcom-dse-10.c: Likewise.
* gcc.dg/tree-ssa/predcom-dse-11.c: Likewise.
* gcc.dg/tree-ssa/predcom-dse-12.c: Likewise.
* gcc.dg/tree-ssa/predcom-dse-2.c: Likewise.
* gcc.dg/tree-ssa/predcom-dse-3.c: Likewise.
* gcc.dg/tree-ssa/predcom-dse-4.c: Likewise.
* gcc.dg/tree-ssa/predcom-dse-5.c: Likewise.
* gcc.dg/tree-ssa/predcom-dse-6.c: Likewise.
* gcc.dg/tree-ssa/predcom-dse-7.c: Likewise.
* gcc.dg/tree-ssa/predcom-dse-8.c: Likewise.
* gcc.dg/tree-ssa/predcom-dse-9.c: Likewise.
* gcc.target/i386/pr90178.c: Likewise.

Diff:
---
 gcc/testsuite/g++.dg/ext/pragma-unroll-lambda-lto.C | 1 +
 gcc/testsuite/gcc.dg/tree-ssa/gen-vect-2.c  | 1 +
 gcc/testsuite/gcc.dg/tree-ssa/gen-vect-25.c | 2 ++
 gcc/testsuite/gcc.dg/tree-ssa/gen-vect-32.c | 1 +
 gcc/testsuite/gcc.dg/tree-ssa/ivopt_mult_2g.c   | 2 +-
 gcc/testsuite/gcc.dg/tree-ssa/ivopts-5.c| 1 +
 gcc/testsuite/gcc.dg/tree-ssa/ivopts-6.c| 1 +
 gcc/testsuite/gcc.dg/tree-ssa/ivopts-7.c| 1 +
 gcc/testsuite/gcc.dg/tree-ssa/ivopts-8.c| 1 +
 gcc/testsuite/gcc.dg/tree-ssa/ivopts-9.c| 1 +
 gcc/testsuite/gcc.dg/tree-ssa/predcom-dse-1.c   | 1 +
 gcc/testsuite/gcc.dg/tree-ssa/predcom-dse-10.c  | 1 +
 gcc/testsuite/gcc.dg/tree-ssa/predcom-dse-11.c  | 1 +
 gcc/testsuite/gcc.dg/tree-ssa/predcom-dse-12.c  | 1 +
 gcc/testsuite/gcc.dg/tree-ssa/predcom-dse-2.c   | 1 +
 gcc/testsuite/gcc.dg/tree-ssa/predcom-dse-3.c   | 1 +
 gcc/testsuite/gcc.dg/tree-ssa/predcom-dse-4.c   | 1 +
 gcc/testsuite/gcc.dg/tree-ssa/predcom-dse-5.c   | 1 +
 gcc/testsuite/gcc.dg/tree-ssa/predcom-dse-6.c   | 1 +
 gcc/testsuite/gcc.dg/tree-ssa/predcom-dse-7.c   | 1 +
 gcc/testsuite/gcc.dg/tree-ssa/predcom-dse-8.c   | 1 +
 gcc/testsuite/gcc.dg/tree-ssa/predcom-dse-9.c   | 1 +
 gcc/testsuite/gcc.target/i386/pr90178.c | 1 +
 23 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/ext/pragma-unroll-lambda-lto.C 
b/gcc/testsuite/g++.dg/ext/pragma-unroll-lambda-lto.C
index 0db57c8d3a01..5980bf316899 100644
--- a/gcc/testsuite/g++.dg/ext/pragma-unroll-lambda-lto.C
+++ b/gcc/testsuite/g++.dg/ext/pragma-unroll-lambda-lto.C
@@ -10,6 +10,7 @@ inline Iter
 my_find(Iter first, Iter last, Pred pred)
 {
 #pragma GCC unroll 4
+#pragma GCC novector
 while (first != last && !pred(*first))
 ++first;
 return first;
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-2.c 
b/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-2.c
index a35999a172ac..00fc8f01991c 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-2.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-2.c
@@ -29,6 +29,7 @@ int main ()
 }
 
   /* check results:  */
+#pragma GCC novector
   for (i = 0; i < N; i++)
 {
   if (ca[i] != cb[i])
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-25.c 
b/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-25.c
index 9f14a54c4137..99d5e6231ff0 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-25.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-25.c
@@ -27,6 +27,7 @@ int main_1 (int n, int *p)
 }
 
   /* check results:  */
+#pragma GCC novector
   for (i = 0; i < N; i++)
 {
   if (ia[i] != n)
@@ -40,6 +41,7 @@ int main_1 (int n, int *p)
 }
 
   /* check results:  */
+#pragma GCC novector
   for (i = 0; i < N; i++)
 {
   if (ib[i] != k)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-32.c 
b/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-32.c
index 62d2b5049fd9..1202ec326c7e 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-32.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-32.c
@@ -23,6 +23,7 @@ int main ()
 }
 
   /* check

[gcc r13-9399] s390: Fix s390_valid_shift_count() for TI mode [PR118835]

2025-02-25 Thread Stefan Schulze Frielinghaus via Gcc-cvs
https://gcc.gnu.org/g:b7466cff8cd4984cea6a2a134c54ca18e20f3fb3

commit r13-9399-gb7466cff8cd4984cea6a2a134c54ca18e20f3fb3
Author: Stefan Schulze Frielinghaus 
Date:   Thu Feb 13 09:13:06 2025 +0100

s390: Fix s390_valid_shift_count() for TI mode [PR118835]

During combine we may end up with

(set (reg:DI 66 [ _6 ])
 (ashift:DI (reg:DI 72 [ x ])
(subreg:QI (and:TI (reg:TI 67 [ _1 ])
   (const_wide_int 0x0aabf))
   15)))

where the shift count operand does not trivially fit the scheme of
address operands.  Reject those operands, especially since
strip_address_mutations() expects expressions of the form
(and ... (const_int ...)) and fails for (and ... (const_wide_int ...)).

Thus, be more strict here and accept only CONST_INT operands.  Done by
replacing immediate_operand() with const_int_operand() which is enough
since the former only additionally checks for LEGITIMATE_PIC_OPERAND_P
and targetm.legitimate_constant_p which are always true for CONST_INT
operands.

While on it, fix indentation of the if block.

gcc/ChangeLog:

PR target/118835
* config/s390/s390.cc (s390_valid_shift_count): Reject shift
count operands which do not trivially fit the scheme of
address operands.

gcc/testsuite/ChangeLog:

* gcc.target/s390/pr118835.c: New test.

(cherry picked from commit ac9806dae30d07ab082ac341fe5646987753adcb)

Diff:
---
 gcc/config/s390/s390.cc  | 35 ++--
 gcc/testsuite/gcc.target/s390/pr118835.c | 21 +++
 2 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index a0089e4c0f21..8593a636d122 100644
--- a/gcc/config/s390/s390.cc
+++ b/gcc/config/s390/s390.cc
@@ -3264,26 +3264,31 @@ s390_valid_shift_count (rtx op, HOST_WIDE_INT 
implicit_mask)
 
   /* Check for an and with proper constant.  */
   if (GET_CODE (op) == AND)
-  {
-rtx op1 = XEXP (op, 0);
-rtx imm = XEXP (op, 1);
+{
+  rtx op1 = XEXP (op, 0);
+  rtx imm = XEXP (op, 1);
 
-if (GET_CODE (op1) == SUBREG && subreg_lowpart_p (op1))
-  op1 = XEXP (op1, 0);
+  if (GET_CODE (op1) == SUBREG && subreg_lowpart_p (op1))
+   op1 = XEXP (op1, 0);
 
-if (!(register_operand (op1, GET_MODE (op1)) || GET_CODE (op1) == PLUS))
-  return false;
+  if (!(register_operand (op1, GET_MODE (op1)) || GET_CODE (op1) == PLUS))
+   return false;
 
-if (!immediate_operand (imm, GET_MODE (imm)))
-  return false;
+  /* Accept only CONST_INT as immediates, i.e., reject shift count operands
+which do not trivially fit the scheme of address operands.  Especially
+since strip_address_mutations() expects expressions of the form
+(and ... (const_int ...)) and fails for
+(and ... (const_wide_int ...)).  */
+  if (!const_int_operand (imm, GET_MODE (imm)))
+   return false;
 
-HOST_WIDE_INT val = INTVAL (imm);
-if (implicit_mask > 0
-   && (val & implicit_mask) != implicit_mask)
-  return false;
+  HOST_WIDE_INT val = INTVAL (imm);
+  if (implicit_mask > 0
+ && (val & implicit_mask) != implicit_mask)
+   return false;
 
-op = op1;
-  }
+  op = op1;
+}
 
   /* Check the rest.  */
   return s390_decompose_addrstyle_without_index (op, NULL, NULL);
diff --git a/gcc/testsuite/gcc.target/s390/pr118835.c 
b/gcc/testsuite/gcc.target/s390/pr118835.c
new file mode 100644
index ..1ca6cd95543b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/pr118835.c
@@ -0,0 +1,21 @@
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-O2" } */
+
+/* During combine we may end up with patterns of the form
+
+   (set (reg:DI 66 [ _6 ])
+(ashift:DI (reg:DI 72 [ x ])
+   (subreg:QI (and:TI (reg:TI 67 [ _1 ])
+  (const_wide_int 0x0aabf))
+  15)))
+
+   which should be rejected since the shift count does not trivially fit the
+   scheme of address operands.  */
+
+long
+test (long x, int y)
+{
+  __int128 z = 0xAABF;
+  z &= y;
+  return x << z;
+}


[gcc r15-7703] libphobos: Organize druntime and phobos tests under common directory

2025-02-25 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:a407eada0173455d267ba403e9e0fe54f0f5dd51

commit r15-7703-ga407eada0173455d267ba403e9e0fe54f0f5dd51
Author: Iain Buclaw 
Date:   Tue Feb 25 20:08:14 2025 +0100

libphobos: Organize druntime and phobos tests under common directory

The druntime and druntime_shared tests are identical, save for one
compiled with `-static-libphobos' and the other `-shared-libphobos'.
Move them to libphobos.druntime/static and libphobos.druntime/shared
respectively.  This has also been done for libphobos.phobos.

libphobos/ChangeLog:

* testsuite/libphobos.druntime_shared/druntime_shared.exp: Move 
to...
* testsuite/libphobos.druntime/shared/druntime-shared.exp: ...here.
* testsuite/libphobos.druntime/druntime.exp: Move to...
* testsuite/libphobos.druntime/static/druntime-static.exp: ...here.
* testsuite/libphobos.phobos_shared/phobos_shared.exp: Move to...
* testsuite/libphobos.phobos/shared/phobos-shared.exp: ...here.
* testsuite/libphobos.phobos/phobos.exp: Move to...
* testsuite/libphobos.phobos/static/phobos-static.exp: ...here.

Diff:
---
 .../shared/druntime-shared.exp} | 0
 .../libphobos.druntime/{druntime.exp => static/druntime-static.exp} | 0
 .../phobos_shared.exp => libphobos.phobos/shared/phobos-shared.exp} | 6 +++---
 .../libphobos.phobos/{phobos.exp => static/phobos-static.exp}   | 6 +++---
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libphobos/testsuite/libphobos.druntime_shared/druntime_shared.exp 
b/libphobos/testsuite/libphobos.druntime/shared/druntime-shared.exp
similarity index 100%
rename from libphobos/testsuite/libphobos.druntime_shared/druntime_shared.exp
rename to libphobos/testsuite/libphobos.druntime/shared/druntime-shared.exp
diff --git a/libphobos/testsuite/libphobos.druntime/druntime.exp 
b/libphobos/testsuite/libphobos.druntime/static/druntime-static.exp
similarity index 100%
rename from libphobos/testsuite/libphobos.druntime/druntime.exp
rename to libphobos/testsuite/libphobos.druntime/static/druntime-static.exp
diff --git a/libphobos/testsuite/libphobos.phobos_shared/phobos_shared.exp 
b/libphobos/testsuite/libphobos.phobos/shared/phobos-shared.exp
similarity index 89%
rename from libphobos/testsuite/libphobos.phobos_shared/phobos_shared.exp
rename to libphobos/testsuite/libphobos.phobos/shared/phobos-shared.exp
index 54acea78a686..31cc13dd9ae2 100644
--- a/libphobos/testsuite/libphobos.phobos_shared/phobos_shared.exp
+++ b/libphobos/testsuite/libphobos.phobos/shared/phobos-shared.exp
@@ -35,10 +35,10 @@ if { [is-effective-target linux_pre_2639] } {
 
 set libphobos_skip_tests {
 # Skip curl tests if library is not available
-{ libphobos.phobos_shared/etc/c/curl.d { ! libcurl_available } }
-{ libphobos.phobos_shared/std/net/curl.d { ! libcurl_available } }
+{ libphobos.phobos/shared/etc/c/curl.d { ! libcurl_available } }
+{ libphobos.phobos/shared/std/net/curl.d { ! libcurl_available } }
 # Skip concurrency.d test: SEGVs or hangs on macOS 13+ (PR d/111628).
-{ libphobos.phobos_shared/std/concurrency.d { x86_64-apple-darwin2[2-9]* } 
}
+{ libphobos.phobos/shared/std/concurrency.d { x86_64-apple-darwin2[2-9]* } 
}
 }
 
 # Initialize dg.
diff --git a/libphobos/testsuite/libphobos.phobos/phobos.exp 
b/libphobos/testsuite/libphobos.phobos/static/phobos-static.exp
similarity index 88%
rename from libphobos/testsuite/libphobos.phobos/phobos.exp
rename to libphobos/testsuite/libphobos.phobos/static/phobos-static.exp
index 3e74078f1366..642019c7f6d7 100644
--- a/libphobos/testsuite/libphobos.phobos/phobos.exp
+++ b/libphobos/testsuite/libphobos.phobos/static/phobos-static.exp
@@ -35,10 +35,10 @@ if { [is-effective-target linux_pre_2639] } {
 
 set libphobos_skip_tests {
 # Skip curl tests if library is not available
-{ libphobos.phobos/etc/c/curl.d { ! libcurl_available } }
-{ libphobos.phobos/std/net/curl.d { ! libcurl_available } }
+{ libphobos.phobos/static/etc/c/curl.d { ! libcurl_available } }
+{ libphobos.phobos/static/std/net/curl.d { ! libcurl_available } }
 # Skip concurrency.d test: SEGVs or hangs on macOS 13+ (PR d/111628).
-{ libphobos.phobos/std/concurrency.d { x86_64-apple-darwin2[2-9]* } }
+{ libphobos.phobos/static/std/concurrency.d { x86_64-apple-darwin2[2-9]* } 
}
 }
 
 # Initialize dg.


[gcc r15-7707] libstdc++: add a constexpr macro for C++26

2025-02-25 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:6a30ffd759ba004c77c7e37520659e9ab0eb80cc

commit r15-7707-g6a30ffd759ba004c77c7e37520659e9ab0eb80cc
Author: Giuseppe D'Angelo 
Date:   Tue Feb 25 18:07:46 2025 +

libstdc++: add a constexpr macro for C++26

Following the precedent of _GLIBCXX20_CONSTEXPR.

It will be used to decorate some functions which have been made
constexpr in C++26 (for instance P2562R1, and maybe P3508R0, P3369R0,
...).

libstdc++-v3/ChangeLog:

* include/bits/c++config (_GLIBCXX26_CONSTEXPR): New macro.

Signed-off-by: Giuseppe D'Angelo 

Diff:
---
 libstdc++-v3/include/bits/c++config | 8 
 1 file changed, 8 insertions(+)

diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index 07f75ea66595..6a73507d0748 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -222,6 +222,14 @@
 # endif
 #endif
 
+#ifndef _GLIBCXX26_CONSTEXPR
+# if __cplusplus >= 202400L
+#  define _GLIBCXX26_CONSTEXPR constexpr
+# else
+#  define _GLIBCXX26_CONSTEXPR
+# endif
+#endif
+
 #ifndef _GLIBCXX17_INLINE
 # if __cplusplus >= 201703L
 #  define _GLIBCXX17_INLINE inline


[gcc r15-7708] libstdc++: add support for constexpr stable_sort (P2562R1)

2025-02-25 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:ff43f9853d3b10e0d2694cd607da1056cb80f38a

commit r15-7708-gff43f9853d3b10e0d2694cd607da1056cb80f38a
Author: Giuseppe D'Angelo 
Date:   Tue Feb 25 18:23:55 2025 +

libstdc++: add support for constexpr stable_sort (P2562R1)

stable_sort has been made constexpr in C++26. Apart from plastering a
few functions with constexpr, there's an implementation challenge, that
is: stable_sort takes different codepaths in case extra memory can be
allocated. Rather than doing some major refactorings, simply use the
non-allocating path during constant evaluation. That's the same codepath
used when extra memory could not be allocated, as well as by
freestanding.

libstdc++-v3/ChangeLog:

* include/bits/algorithmfwd.h (stable_sort): Add constexpr.
* include/bits/ranges_algo.h (__stable_sort_fn): Add constexpr
to the function call operators.
* include/bits/stl_algo.h (__stable_sort): Add constexpr.
During constant evaluation, always use the non-allocating path.
(stable_sort): Add constexpr.
(__inplace_stable_sort): Likewise.
(__merge_without_buffer): Likewise.
* include/bits/version.def (constexpr_algorithms): Bump value
for C++26.
* include/bits/version.h: Regnerate.
* testsuite/25_algorithms/cpp_lib_constexpr.cc: Test the bumped
feature-testing macro.
* testsuite/25_algorithms/headers/algorithm/synopsis.cc: Adapt
the test to constexpr stable_sort.
* testsuite/25_algorithms/stable_sort/constexpr.cc: New test.

Signed-off-by: Giuseppe D'Angelo 

Diff:
---
 libstdc++-v3/include/bits/algorithmfwd.h   |  2 +
 libstdc++-v3/include/bits/ranges_algo.h|  2 +
 libstdc++-v3/include/bits/stl_algo.h   | 11 
 libstdc++-v3/include/bits/version.def  |  4 ++
 libstdc++-v3/include/bits/version.h|  7 ++-
 .../testsuite/25_algorithms/cpp_lib_constexpr.cc   |  4 ++
 .../25_algorithms/headers/algorithm/synopsis.cc|  2 +
 .../25_algorithms/stable_sort/constexpr.cc | 62 ++
 8 files changed, 93 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/algorithmfwd.h 
b/libstdc++-v3/include/bits/algorithmfwd.h
index 0b72895796a2..3e81bca0348a 100644
--- a/libstdc++-v3/include/bits/algorithmfwd.h
+++ b/libstdc++-v3/include/bits/algorithmfwd.h
@@ -945,10 +945,12 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
 sort(_RAIter, _RAIter, _Compare);
 
   template
+_GLIBCXX26_CONSTEXPR
 void
 stable_sort(_RAIter, _RAIter);
 
   template
+_GLIBCXX26_CONSTEXPR
 void
 stable_sort(_RAIter, _RAIter, _Compare);
 
diff --git a/libstdc++-v3/include/bits/ranges_algo.h 
b/libstdc++-v3/include/bits/ranges_algo.h
index a72eab582be0..d3644a83f802 100644
--- a/libstdc++-v3/include/bits/ranges_algo.h
+++ b/libstdc++-v3/include/bits/ranges_algo.h
@@ -1842,6 +1842,7 @@ namespace ranges
 template _Sent,
 typename _Comp = ranges::less, typename _Proj = identity>
   requires sortable<_Iter, _Comp, _Proj>
+  _GLIBCXX26_CONSTEXPR
   _Iter
   operator()(_Iter __first, _Sent __last,
 _Comp __comp = {}, _Proj __proj = {}) const
@@ -1855,6 +1856,7 @@ namespace ranges
 template
   requires sortable, _Comp, _Proj>
+  _GLIBCXX26_CONSTEXPR
   borrowed_iterator_t<_Range>
   operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const
   {
diff --git a/libstdc++-v3/include/bits/stl_algo.h 
b/libstdc++-v3/include/bits/stl_algo.h
index 39795e946c91..41b4d0853b71 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -2415,6 +2415,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
   /// This is a helper function for the merge routines.
   template
+_GLIBCXX26_CONSTEXPR
 void
 __merge_without_buffer(_BidirectionalIterator __first,
   _BidirectionalIterator __middle,
@@ -2723,6 +2724,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
 
   /// This is a helper function for the stable sorting routines.
   template
+_GLIBCXX26_CONSTEXPR
 void
 __inplace_stable_sort(_RandomAccessIterator __first,
  _RandomAccessIterator __last, _Compare __comp)
@@ -4971,6 +4973,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
 }
 
   template
+_GLIBCXX26_CONSTEXPR
 inline void
 __stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
  _Compare __comp)
@@ -4984,6 +4987,12 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
return;
 
 #if _GLIBCXX_HOSTED
+  if (__is_constant_evaluated())
+   {
+ std::__inplace_stable_sort(__first, __last, __comp);
+ return;
+   }
+
   typedef _Temporary_buffer<_RandomAccessIterator, _ValueType> _TmpBuf;
   // __stable_sort_adaptive sorts the range in two halves

[gcc r15-7698] libstdc++: Implement LWG 4027 change to possibly-const-range [PR118083]

2025-02-25 Thread Patrick Palka via Libstdc++-cvs
https://gcc.gnu.org/g:1b9e4fe2ff5f4711406cdcf0e6e183b247d9f42b

commit r15-7698-g1b9e4fe2ff5f4711406cdcf0e6e183b247d9f42b
Author: Patrick Palka 
Date:   Tue Feb 25 13:35:04 2025 -0500

libstdc++: Implement LWG 4027 change to possibly-const-range [PR118083]

LWG 4027 effectively makes the const range access CPOs ranges::cfoo behave
more consistently across C++23 and C++20 (pre-P2278R4) and also more
consistently with the std::cfoo range accessors, as the below testcase
adjustments demonstrate (which mostly consist of reverting workarounds
added by r14-3771-gf12e26f3496275 and r13-7186-g0d94c6df183375).

In passing fix PR118083 which reports that the input_range constraint on
possibly-const-range is missing in our implementation.  A consequence of
this is that the const range access CPOs now consistently reject a non-range
argument, and so in some our of tests we need to introduce otherwise
unused begin/end members.

PR libstdc++/118083

libstdc++-v3/ChangeLog:

* include/bits/ranges_base.h
(ranges::__access::__possibly_const_range): Adjust logic as per
LWG 4027.  Add missing input_range constraint.
* testsuite/std/ranges/access/cbegin.cc (test05): Verify LWG
4027 testcases.
* testsuite/std/ranges/access/cdata.cc: Adjust, simplify and
consolidate some tests after the above.
* testsuite/std/ranges/access/cend.cc: Likewise.
* testsuite/std/ranges/access/crbegin.cc: Likewise.
* testsuite/std/ranges/access/crend.cc: Likewise.
* testsuite/std/ranges/adaptors/join.cc: Likewise.
* testsuite/std/ranges/adaptors/take_while.cc: Likewise.
* testsuite/std/ranges/adaptors/transform.cc: Likewise.

Reviewed-by: Jonathan Wakely 

Diff:
---
 libstdc++-v3/include/bits/ranges_base.h|  4 +-
 libstdc++-v3/testsuite/std/ranges/access/cbegin.cc | 17 +
 libstdc++-v3/testsuite/std/ranges/access/cdata.cc  | 21 ++-
 libstdc++-v3/testsuite/std/ranges/access/cend.cc   | 30 ++-
 .../testsuite/std/ranges/access/crbegin.cc | 43 +-
 libstdc++-v3/testsuite/std/ranges/access/crend.cc  | 20 ++
 libstdc++-v3/testsuite/std/ranges/adaptors/join.cc |  8 ++--
 .../testsuite/std/ranges/adaptors/take_while.cc|  2 -
 .../testsuite/std/ranges/adaptors/transform.cc |  4 --
 9 files changed, 59 insertions(+), 90 deletions(-)

diff --git a/libstdc++-v3/include/bits/ranges_base.h 
b/libstdc++-v3/include/bits/ranges_base.h
index 4dcfbf66d51f..28fe64a9e9da 100644
--- a/libstdc++-v3/include/bits/ranges_base.h
+++ b/libstdc++-v3/include/bits/ranges_base.h
@@ -642,11 +642,11 @@ namespace ranges
   namespace __access
   {
 #if __glibcxx_ranges_as_const // >= C++23
-template
+template
   constexpr auto&
   __possibly_const_range(_Range& __r) noexcept
   {
-   if constexpr (constant_range && !constant_range<_Range>)
+   if constexpr (input_range)
  return const_cast(__r);
else
  return __r;
diff --git a/libstdc++-v3/testsuite/std/ranges/access/cbegin.cc 
b/libstdc++-v3/testsuite/std/ranges/access/cbegin.cc
index 5423e7824282..c85303d3e357 100644
--- a/libstdc++-v3/testsuite/std/ranges/access/cbegin.cc
+++ b/libstdc++-v3/testsuite/std/ranges/access/cbegin.cc
@@ -116,10 +116,27 @@ test04()
   VERIFY(std::ranges::cbegin(std::move(c)) == std::ranges::begin(c));
 }
 
+void
+test05()
+{
+  // LWG 4027 - possibly-const-range should prefer returning const R&
+  auto r = std::views::single(0)
+| std::views::transform([](int) { return 0; });
+  using C1 = decltype(std::ranges::cbegin(r));
+  using C1 = decltype(std::cbegin(r));
+
+  [] (auto x) {
+auto r = std::views::single(x) | std::views::lazy_split(0);
+static_assert(!requires { (*std::ranges::cbegin(r)).front() = 42; });
+static_assert(!requires { (*std::cbegin(r)).front() = 42; });
+  }(0);
+}
+
 int
 main()
 {
   test01();
   test03();
   test04();
+  test05();
 }
diff --git a/libstdc++-v3/testsuite/std/ranges/access/cdata.cc 
b/libstdc++-v3/testsuite/std/ranges/access/cdata.cc
index 62c347be43d6..f474ab7ec99c 100644
--- a/libstdc++-v3/testsuite/std/ranges/access/cdata.cc
+++ b/libstdc++-v3/testsuite/std/ranges/access/cdata.cc
@@ -34,20 +34,21 @@ test01()
   {
 int i = 0;
 int j = 0;
+
+#if __cpp_lib_ranges_as_const
+// These overloads mean that range and range are satisfied.
+const int* begin() const { throw; }
+const int* end() const { throw; }
+#endif
+
 int* data() { return &j; }
 const R* data() const noexcept { return nullptr; }
   };
   static_assert( has_cdata );
   static_assert( has_cdata );
   R r;
-#if ! __cpp_lib_ranges_as_const
   VERIFY( std::ranges::cdata(r) == (R*)nullptr );
   static_assert( noexcept(std::ranges::cdata(r)) );
-#else
-  // constant_range is not satisfied, so cdata(r) 

[gcc r15-7697] libphobos: Add scripts to update Makefile.am after an upstream merge

2025-02-25 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:fffe14f045df597bf5ab50730eebe0977eea7090

commit r15-7697-gfffe14f045df597bf5ab50730eebe0977eea7090
Author: Iain Buclaw 
Date:   Tue Feb 25 18:58:27 2025 +0100

libphobos: Add scripts to update Makefile.am after an upstream merge

These two scripts have been used for updating Makefile.am whenever
there's been a file added/removed from either Druntime or Phobos since
the start, but never included in the source tree.

libphobos/ChangeLog:

* libdruntime/Makefile.am: Update comment.
* libdruntime/Makefile.in: Regenerate.
* src/Makefile.am: Update comment.
* src/Makefile.in: Regenerate.
* scripts/.gitignore: New file.
* scripts/README: New file.
* scripts/gen_druntime_sources.d: New file.
* scripts/gen_phobos_sources.d: New file.

Diff:
---
 libphobos/libdruntime/Makefile.am|   2 +-
 libphobos/libdruntime/Makefile.in|   2 +-
 libphobos/scripts/.gitignore |   3 +
 libphobos/scripts/README |  28 
 libphobos/scripts/gen_druntime_sources.d |  92 
 libphobos/scripts/gen_phobos_sources.d   | 116 +++
 libphobos/src/Makefile.am|   2 +-
 libphobos/src/Makefile.in|   2 +-
 8 files changed, 243 insertions(+), 4 deletions(-)

diff --git a/libphobos/libdruntime/Makefile.am 
b/libphobos/libdruntime/Makefile.am
index 8df0e1c43b91..efdae4c57861 100644
--- a/libphobos/libdruntime/Makefile.am
+++ b/libphobos/libdruntime/Makefile.am
@@ -167,7 +167,7 @@ install-data-local:
done
 
 # Source file definitions. Boring stuff, auto-generated with
-# https://gist.github.com/jpf91/8ad1dbc9902d6ad876313f134c6527d1
+# libphobos/scripts/gen_druntime_sources.d
 # Can't use wildcards here:
 # https://www.gnu.org/software/automake/manual/html_node/Wildcards.html
 
diff --git a/libphobos/libdruntime/Makefile.in 
b/libphobos/libdruntime/Makefile.in
index 999064e5221c..1227c59b4854 100644
--- a/libphobos/libdruntime/Makefile.in
+++ b/libphobos/libdruntime/Makefile.in
@@ -850,7 +850,7 @@ libgdruntime_convenience_la_DEPENDENCIES = 
$(libgdruntime_la_DEPENDENCIES)
 libgdruntime_convenience_la_LINK = $(libgdruntime_la_LINK)
 
 # Source file definitions. Boring stuff, auto-generated with
-# https://gist.github.com/jpf91/8ad1dbc9902d6ad876313f134c6527d1
+# libphobos/scripts/gen_druntime_sources.d
 # Can't use wildcards here:
 # https://www.gnu.org/software/automake/manual/html_node/Wildcards.html
 DRUNTIME_CSOURCES = core/stdc/errno_.c etc/valgrind/valgrind_.c
diff --git a/libphobos/scripts/.gitignore b/libphobos/scripts/.gitignore
new file mode 100644
index ..a5d300b6f604
--- /dev/null
+++ b/libphobos/scripts/.gitignore
@@ -0,0 +1,3 @@
+# Dub leaves built programs in this directory.
+gen_druntime_sources
+gen_phobos_sources
diff --git a/libphobos/scripts/README b/libphobos/scripts/README
new file mode 100644
index ..248324dddac3
--- /dev/null
+++ b/libphobos/scripts/README
@@ -0,0 +1,28 @@
+The D language scripts in this directory are used during the syncing of
+libphobos with upstream.  They can be built with the command:
+
+dub build --single name-of-script.d
+
+Or when dub isn't available:
+
+gdc -o name-of-script name-of-script.d [any other dependencies].d
+
+Scripts:
+
+gen_druntime_sources.d
+
+Generates source file definitions for libphobos/libdruntime/Makefile.am.
+Ran from the libdruntime directory and append output to Makefile.am.
+
+Example:
+
+   cd libdruntime && ../scripts/gen_druntime_sources >> Makefile.am
+
+gen_phobos_sources.d
+
+Generates source file definitions for libphobos/src/Makefile.am.  Ran from
+the libphobos/src directory and append output to Makefile.am.
+
+Example:
+
+   cd src && ../scripts/gen_phobos_sources >> Makefile.am
diff --git a/libphobos/scripts/gen_druntime_sources.d 
b/libphobos/scripts/gen_druntime_sources.d
new file mode 100644
index ..ee01477a493f
--- /dev/null
+++ b/libphobos/scripts/gen_druntime_sources.d
@@ -0,0 +1,92 @@
+#!/usr/bin/env dub
+/++dub.sdl:
+name "gen_druntime_sources"
++/
+// Written in the D programming language.
+import std.stdio;
+import std.file;
+import std.path;
+import std.range;
+import std.string;
+import std.algorithm;
+
+string[] filterList = [
+"./Makefile.in", "./Makefile.am",
+"./gcc/config.d.in", "./gcc/libbacktrace.d.in", "./gcc/drtstuff.c",
+"./LICENSE.txt", "./MERGE",
+"./rt/dylib_fixes.c"
+];
+
+struct Files
+{
+string[] baseList, cppList;
+string[][string] sysList;
+}
+
+void main(string[] args)
+{
+Files[string] fileMap;
+
+foreach(entry; ".".dirEntries(SpanMode.depth).filter!(a => 
!filterList.canFind(a)))
+{
+if (entry.name.startsWith("./config/"))
+continue;
+
+if(entry.isFile)
+{
+auto ext = entry.extension.empty ? "" :

[gcc r15-7701] doc: update C++98 bootstrap note

2025-02-25 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:dc9db8007519a3240ebf66262be8baba87a98e20

commit r15-7701-gdc9db8007519a3240ebf66262be8baba87a98e20
Author: Jason Merrill 
Date:   Tue Feb 25 15:13:34 2025 -0500

doc: update C++98 bootstrap note

r10-11132 uses C++11 default member initializers, which breaks bootstrapping
with a C++98 compiler.

gcc/ChangeLog:

* doc/install.texi: 10.5 won't bootstrap with C++98.

Diff:
---
 gcc/doc/install.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 29de3200ae88..bc5263e53487 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -227,7 +227,7 @@ Necessary to bootstrap GCC.  GCC 5.4 or newer has 
sufficient support
 for used C++14 features.
 
 Versions of GCC prior to 15 allow bootstrapping with an ISO C++11
-compiler, versions prior to 11 allow bootstrapping with an ISO C++98
+compiler, versions prior to 10.5 allow bootstrapping with an ISO C++98
 compiler, and versions prior to 4.8 allow bootstrapping with an ISO
 C89 compiler.


[gcc r15-7696] d/i386: Add CET TargetInfo key and predefined version [PR118654]

2025-02-25 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:c17044e509824e5ed3de94c85a7a0dd71cfd9cc1

commit r15-7696-gc17044e509824e5ed3de94c85a7a0dd71cfd9cc1
Author: Iain Buclaw 
Date:   Tue Feb 25 18:01:09 2025 +0100

d/i386: Add CET TargetInfo key and predefined version [PR118654]

Adds a new i386 d_target_info_spec entry to handle requests for
`__traits(getTargetInfo, "CET")', and add predefined target version
`GNU_CET' when the option `-fcf-protecton' is used.

Both TargetInfo key and predefined version have been added to the D
front-end documentation.

In the library, `GNU_CET' replaces the existing use of the user-defined
version flag `CET' when building libphobos.

PR d/118654

gcc/ChangeLog:

* config/i386/i386-d.cc (ix86_d_target_versions): Predefine GNU_CET.
(ix86_d_handle_target_cf_protection): New.
(ix86_d_register_target_info): Add 'CET' TargetInfo key.

gcc/d/ChangeLog:

* implement-d.texi: Document CET version and traits key.

libphobos/ChangeLog:

* Makefile.in: Regenerate.
* configure: Regenerate.
* configure.ac: Remove CET_DFLAGS.
* libdruntime/Makefile.am: Replace CET_DFLAGS with CET_FLAGS.
* libdruntime/Makefile.in: Regenerate.
* libdruntime/core/thread/fiber/package.d: Replace CET with GNU_CET.
* src/Makefile.am: Replace CET_DFLAGS with CET_FLAGS.
* src/Makefile.in: Regenerate.
* testsuite/Makefile.in: Regenerate.
* testsuite/testsuite_flags.in: Replace CET_DFLAGS with CET_FLAGS.

gcc/testsuite/ChangeLog:

* gdc.dg/target/i386/i386.exp: New test.
* gdc.dg/target/i386/targetinfo_CET.d: New test.

Diff:
---
 gcc/config/i386/i386-d.cc | 12 ++
 gcc/d/implement-d.texi|  8 
 gcc/testsuite/gdc.dg/target/i386/i386.exp | 48 +++
 gcc/testsuite/gdc.dg/target/i386/targetinfo_CET.d |  3 ++
 libphobos/Makefile.in |  1 -
 libphobos/configure   |  8 +---
 libphobos/configure.ac|  3 --
 libphobos/libdruntime/Makefile.am |  2 +-
 libphobos/libdruntime/Makefile.in |  3 +-
 libphobos/libdruntime/core/thread/fiber/package.d |  4 +-
 libphobos/src/Makefile.am |  2 +-
 libphobos/src/Makefile.in |  3 +-
 libphobos/testsuite/Makefile.in   |  1 -
 libphobos/testsuite/testsuite_flags.in|  2 +-
 14 files changed, 80 insertions(+), 20 deletions(-)

diff --git a/gcc/config/i386/i386-d.cc b/gcc/config/i386/i386-d.cc
index fbe26e012744..f61b5a50b698 100644
--- a/gcc/config/i386/i386-d.cc
+++ b/gcc/config/i386/i386-d.cc
@@ -44,6 +44,9 @@ ix86_d_target_versions (void)
 d_add_builtin_version ("D_HardFloat");
   else
 d_add_builtin_version ("D_SoftFloat");
+
+  if (flag_cf_protection != CF_NONE)
+d_add_builtin_version ("GNU_CET");
 }
 
 /* Handle a call to `__traits(getTargetInfo, "floatAbi")'.  */
@@ -79,6 +82,14 @@ ix86_d_handle_target_object_format (void)
   return build_string_literal (strlen (objfmt) + 1, objfmt);
 }
 
+/* Handle a call to `__traits(getTargetInfo, "CET")'.  */
+
+static tree
+ix86_d_handle_target_cf_protection (void)
+{
+  return build_int_cst_type (uint32_type_node, flag_cf_protection & ~CF_SET);
+}
+
 /* Implement TARGET_D_REGISTER_CPU_TARGET_INFO.  */
 
 void
@@ -87,6 +98,7 @@ ix86_d_register_target_info (void)
   const struct d_target_info_spec handlers[] = {
 { "floatAbi", ix86_d_handle_target_float_abi },
 { "objectFormat", ix86_d_handle_target_object_format },
+{ "CET", ix86_d_handle_target_cf_protection },
 { NULL, NULL },
   };
 
diff --git a/gcc/d/implement-d.texi b/gcc/d/implement-d.texi
index a5534792e66f..a39fd5834763 100644
--- a/gcc/d/implement-d.texi
+++ b/gcc/d/implement-d.texi
@@ -1892,6 +1892,10 @@ This version is defined by the GNU D compiler.  If all 
you need to know is
 whether or not your D program is being compiled by GDC, or a non-GDC compiler,
 you can simply test @code{version(GNU)}.
 
+@item GNU_CET
+This version is defined when @option{-fcf-protection} is used.  The protection
+level is also set in @code{__traits(getTargetInfo, "CET")} (@pxref{Traits}).
+
 @item GNU_DWARF2_Exceptions
 @itemx GNU_SEH_Exceptions
 @itemx GNU_SjLj_Exceptions
@@ -2121,6 +2125,10 @@ recognize.  These are documented by the D language 
specification hosted at
 The following keys are recognized by GNU D.
 
 @table @code
+@item CET
+When @option{-fcf-protection} is used, the first bit is set to 1 for the value
+@code{branch} and the second bit is set to 1 for the value @code{return}.
+
 @item cppRuntimeLibrary
 The C++ runtime library affinity for this toolchain.
 
diff --git a/gcc/testsuite/gdc.dg/target/i386/i386.exp 
b/gcc/testsuite

[gcc r15-7699] pru: Fix pru_pragma_ctable_entry diagnostics [PR118991]

2025-02-25 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:0bb431d0a77cf8dc790b9c61539b3eb6ab1710f0

commit r15-7699-g0bb431d0a77cf8dc790b9c61539b3eb6ab1710f0
Author: Jakub Jelinek 
Date:   Tue Feb 25 20:03:38 2025 +0100

pru: Fix pru_pragma_ctable_entry diagnostics [PR118991]

HOST_WIDE_INT_PRINT* macros aren't supposed to be used in
gcc-internal-format format strings, we have the w modifier for HOST_WIDE_INT
in that case, the HOST_WIDE_INT_PRINT* macros might not work properly on
some hosts (e.g. mingw32 has HOST_LONG_LONG_FORMAT "I64" and that is
something pretty-print doesn't handle, while it handles "ll" for long long)
and also the use of macros in the middle of format strings breaks
translations (both that exgettext can't retrieve the string from there
and we get
 #: config/pru/pru-pragma.cc:61
 msgid "% index %"
 msgstr ""

 #: config/pru/pru-pragma.cc:64
 msgid "redefinition of % index %lld is not 
valid"
it could be translated on some hosts but not e.g. mingw32).

So, the following patch just uses %wd instead.

Tested it before/after the
patch on
 #pragma ctable_entry 12 0x4804
 #pragma ctable_entry 1024 0x4804
 #pragma ctable_entry 12 0x48040001
and the result is the same.

2025-02-25  Jakub Jelinek  

PR translation/118991
* config/pru/pru-pragma.cc (pru_pragma_ctable_entry): Use %wd
instead of %" HOST_WIDE_INT_PRINT "d to print a hwi in error.

Diff:
---
 gcc/config/pru/pru-pragma.cc | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/gcc/config/pru/pru-pragma.cc b/gcc/config/pru/pru-pragma.cc
index 9c182d788141..c3f3d33d5470 100644
--- a/gcc/config/pru/pru-pragma.cc
+++ b/gcc/config/pru/pru-pragma.cc
@@ -58,11 +58,9 @@ pru_pragma_ctable_entry (cpp_reader *)
  if (type != CPP_EOF)
error ("junk at end of %<#pragma CTABLE_ENTRY%>");
  else if (i >= ARRAY_SIZE (pru_ctable))
-   error ("% index %" HOST_WIDE_INT_PRINT "d"
-  " is not valid", i);
+   error ("% index %wd is not valid", i);
  else if (pru_ctable[i].valid && pru_ctable[i].base != base)
-   error ("redefinition of %", i);
+   error ("redefinition of %", i);
  else
{
  if (base & 0xff)


[gcc r15-7700] [PR115458][LRA]: Run split sub-pass more times

2025-02-25 Thread Vladimir Makarov via Gcc-cvs
https://gcc.gnu.org/g:2341f675edadd6370147d2bc55ca7761a7ecfaa1

commit r15-7700-g2341f675edadd6370147d2bc55ca7761a7ecfaa1
Author: Vladimir N. Makarov 
Date:   Tue Feb 25 15:01:15 2025 -0500

[PR115458][LRA]: Run split sub-pass more times

  In this PR case LRA needs to provide too many hard regs for insn
reloads, where some reload pseudos require 8 aligned regs for
themselves.  As the last attempt, LRA tries to split live ranges of
hard regs for insn reload pseudos.  It is a very rare case.  An
inheritance pseudo involving a reload pseudo of the insn can be
spilled in the assignment sub-pass run right after splitting and we need
to run split sub-pass for the inheritance pseudo now.

gcc/ChangeLog:

PR target/115458
* lra-int.h (LRA_MAX_FAILED_SPLITS): Define and check its value.
(lra_split_hard_reg_for): Change prototype.
* lra.cc (lra): Try to split hard reg range several times after a
failure.
* lra-assigns.cc (lra_split_hard_reg_for): Add an arg, a flag of
giving up.  Report asm error and nullify the asm insn depending on
the arg value.

gcc/testsuite/ChangeLog:

PR target/115458
* g++.target/riscv/pr115458.C: New.

Diff:
---
 gcc/lra-assigns.cc|  50 +++--
 gcc/lra-int.h |  14 +-
 gcc/lra.cc|  14 +-
 gcc/testsuite/g++.target/riscv/pr115458.C | 357 ++
 4 files changed, 410 insertions(+), 25 deletions(-)

diff --git a/gcc/lra-assigns.cc b/gcc/lra-assigns.cc
index f9e3dfc3d5af..480925ad8943 100644
--- a/gcc/lra-assigns.cc
+++ b/gcc/lra-assigns.cc
@@ -1763,12 +1763,13 @@ find_reload_regno_insns (int regno, rtx_insn * &start, 
rtx_insn * &finish)
   return true;
 }
 
-/* Process reload pseudos which did not get a hard reg, split a hard
-   reg live range in live range of a reload pseudo, and then return
-   TRUE.  If we did not split a hard reg live range, report an error,
-   and return FALSE.  */
+/* Process reload pseudos which did not get a hard reg, split a hard reg live
+   range in live range of a reload pseudo, and then return TRUE.  Otherwise,
+   return FALSE.  When FAIL_P is TRUE and if we did not split a hard reg live
+   range for failed reload pseudos, report an error and modify related asm
+   insns.  */
 bool
-lra_split_hard_reg_for (void)
+lra_split_hard_reg_for (bool fail_p)
 {
   int i, regno;
   rtx_insn *insn, *first, *last;
@@ -1843,23 +1844,30 @@ lra_split_hard_reg_for (void)
   regno = u;
   bitmap_ior_into (&failed_reload_insns,
   &lra_reg_info[regno].insn_bitmap);
-  lra_setup_reg_renumber
-   (regno, ira_class_hard_regs[lra_get_allocno_class (regno)][0], false);
-}
-  EXECUTE_IF_SET_IN_BITMAP (&failed_reload_insns, 0, u, bi)
-{
-  insn = lra_insn_recog_data[u]->insn;
-  if (asm_noperands (PATTERN (insn)) >= 0)
-   {
- asm_p = true;
- lra_asm_insn_error (insn);
-   }
-  else if (!asm_p)
-   {
- error ("unable to find a register to spill");
- fatal_insn ("this is the insn:", insn);
-   }
+  if (fail_p)
+   lra_setup_reg_renumber
+ (regno, ira_class_hard_regs[lra_get_allocno_class (regno)][0], false);
 }
+  if (fail_p)
+EXECUTE_IF_SET_IN_BITMAP (&failed_reload_insns, 0, u, bi)
+  {
+   insn = lra_insn_recog_data[u]->insn;
+   if (asm_noperands (PATTERN (insn)) >= 0)
+ {
+   asm_p = true;
+   lra_asm_insn_error (insn);
+   if (JUMP_P (insn))
+ ira_nullify_asm_goto (insn);
+   else
+ PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
+   lra_invalidate_insn_data (insn);
+ }
+   else if (!asm_p)
+ {
+   error ("unable to find a register to spill");
+   fatal_insn ("this is the insn:", insn);
+ }
+  }
   bitmap_clear (&failed_reload_pseudos);
   bitmap_clear (&failed_reload_insns);
   return false;
diff --git a/gcc/lra-int.h b/gcc/lra-int.h
index 1f89e069c4f9..ad42f48cc822 100644
--- a/gcc/lra-int.h
+++ b/gcc/lra-int.h
@@ -252,6 +252,18 @@ typedef class lra_insn_recog_data *lra_insn_recog_data_t;
for preventing LRA cycling in a bug case.  */
 #define LRA_MAX_ASSIGNMENT_ITERATION_NUMBER 30
 
+/* Maximum allowed number of tries to split hard reg live ranges after failure
+   in assignment of reload pseudos.  Theoretical bound for the value is the
+   number of the insn reload pseudos plus the number of inheritance pseudos
+   generated from the reload pseudos.  This bound can be achieved when all the
+   reload pseudos and the inheritance pseudos require hard reg splitting for
+   their assignment.  This is extremely unlikely event.  */
+#define LRA_MAX_FAILED_SPLITS 10
+
+#if LRA_MAX_FAILED_SPLITS >= LRA_MAX_ASSIGNMENT_ITERATION_NUMBER
+#err

[gcc r15-7695] d: Increase max parallelism of the D testsuite

2025-02-25 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:2d812eecc36e69b5c39ad49b80ab9965c63fdd09

commit r15-7695-g2d812eecc36e69b5c39ad49b80ab9965c63fdd09
Author: Iain Buclaw 
Date:   Mon Feb 24 19:57:15 2025 +0100

d: Increase max parallelism of the D testsuite

It was noticed that when running the testsuite for gdc and libphobos in
parallel, this was capped at 10 simultaneous jobs each.  Increase this
limit to 128, which enables running for example `make check-d -j48` to
complete in half the time.

gcc/d/ChangeLog:

* Make-lang.in (check_gdc_parallelize): Increase to 128.

libphobos/ChangeLog:

* testsuite/Makefile.am (check_p_subno): Remove variable.
(check_p_subdirs): Increase default parallel slots to 128.
* testsuite/Makefile.in: Regenerate.

Diff:
---
 gcc/d/Make-lang.in  | 2 +-
 libphobos/testsuite/Makefile.am | 3 +--
 libphobos/testsuite/Makefile.in | 3 +--
 3 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/gcc/d/Make-lang.in b/gcc/d/Make-lang.in
index a29531c8b7f6..2d444c999530 100644
--- a/gcc/d/Make-lang.in
+++ b/gcc/d/Make-lang.in
@@ -308,7 +308,7 @@ d.srcman: doc/gdc.1
 check-d: check-gdc
 lang_checks += check-gdc
 lang_checks_parallelized += check-gdc
-check_gdc_parallelize = 10
+check_gdc_parallelize = 128
 
 # No D-specific selftests.
 selftest-d:
diff --git a/libphobos/testsuite/Makefile.am b/libphobos/testsuite/Makefile.am
index 54dc7ba540f7..ecddb80db5df 100644
--- a/libphobos/testsuite/Makefile.am
+++ b/libphobos/testsuite/Makefile.am
@@ -29,7 +29,6 @@ RUNTESTDEFAULTFLAGS = --tool $$tool --srcdir $$srcdir
 
 PWD_COMMAND = $${PWDCMD-pwd}
 
-check_p_subno=$(word 2,$(subst _, ,$*))
 check_p_numbers0:=1 2 3 4 5 6 7 8 9
 check_p_numbers1:=0 $(check_p_numbers0)
 check_p_numbers2:=$(foreach i,$(check_p_numbers0),$(addprefix 
$(i),$(check_p_numbers1)))
@@ -38,7 +37,7 @@ check_p_numbers4:=$(foreach i,$(check_p_numbers0),$(addprefix 
$(i),$(check_p_num
 check_p_numbers5:=$(addprefix 0,$(check_p_numbers3)) $(check_p_numbers4)
 check_p_numbers6:=$(foreach i,$(check_p_numbers0),$(addprefix 
$(i),$(check_p_numbers5)))
 check_p_numbers:=$(check_p_numbers0) $(check_p_numbers2) $(check_p_numbers4) 
$(check_p_numbers6)
-check_p_subdirs=$(wordlist 1,$(if 
$(GCC_TEST_PARALLEL_SLOTS),$(GCC_TEST_PARALLEL_SLOTS),10),$(check_p_numbers))
+check_p_subdirs=$(wordlist 1,$(if 
$(GCC_TEST_PARALLEL_SLOTS),$(GCC_TEST_PARALLEL_SLOTS),128),$(check_p_numbers))
 check_DEJAGNU_libphobos_targets = $(addprefix 
check-DEJAGNUlibphobos,$(check_p_subdirs))
 $(check_DEJAGNU_libphobos_targets): check-DEJAGNUlibphobos%: 
libphobos%/site.exp
 
diff --git a/libphobos/testsuite/Makefile.in b/libphobos/testsuite/Makefile.in
index 885548018bae..3d3a798f35c1 100644
--- a/libphobos/testsuite/Makefile.in
+++ b/libphobos/testsuite/Makefile.in
@@ -301,7 +301,6 @@ _RUNTEST = $(shell if test -f 
$(top_srcdir)/../dejagnu/runtest; then \
 
 RUNTESTDEFAULTFLAGS = --tool $$tool --srcdir $$srcdir
 PWD_COMMAND = $${PWDCMD-pwd}
-check_p_subno = $(word 2,$(subst _, ,$*))
 check_p_numbers0 := 1 2 3 4 5 6 7 8 9
 check_p_numbers1 := 0 $(check_p_numbers0)
 check_p_numbers2 := $(foreach i,$(check_p_numbers0),$(addprefix 
$(i),$(check_p_numbers1)))
@@ -310,7 +309,7 @@ check_p_numbers4 := $(foreach 
i,$(check_p_numbers0),$(addprefix $(i),$(check_p_n
 check_p_numbers5 := $(addprefix 0,$(check_p_numbers3)) $(check_p_numbers4)
 check_p_numbers6 := $(foreach i,$(check_p_numbers0),$(addprefix 
$(i),$(check_p_numbers5)))
 check_p_numbers := $(check_p_numbers0) $(check_p_numbers2) $(check_p_numbers4) 
$(check_p_numbers6)
-check_p_subdirs = $(wordlist 1,$(if 
$(GCC_TEST_PARALLEL_SLOTS),$(GCC_TEST_PARALLEL_SLOTS),10),$(check_p_numbers))
+check_p_subdirs = $(wordlist 1,$(if 
$(GCC_TEST_PARALLEL_SLOTS),$(GCC_TEST_PARALLEL_SLOTS),128),$(check_p_numbers))
 check_DEJAGNU_libphobos_targets = $(addprefix 
check-DEJAGNUlibphobos,$(check_p_subdirs))
 AM_MAKEFLAGS = "EXEEXT=$(EXEEXT)"
 CLEANFILES = *.exe *.log *.o *.sum site.exp


[gcc r15-7702] libstdc++: [_Hashtable] Fix hash code cache usage when stateful hash functor

2025-02-25 Thread Francois Dumont via Gcc-cvs
https://gcc.gnu.org/g:bcc8dea6a45b46febfa76df6f5e3e5b13f3b4a58

commit r15-7702-gbcc8dea6a45b46febfa76df6f5e3e5b13f3b4a58
Author: François Dumont 
Date:   Sun Feb 16 19:27:49 2025 +0100

libstdc++: [_Hashtable] Fix hash code cache usage when stateful hash functor

It is wrong to reuse a cached hash code from another container when this 
code depends
on the state of the container's Hash functor.

Add checks that Hash functor is stateless before reusing the cached hash 
code.

libstdc++-v3/ChangeLog:

* include/bits/hashtable_policy.h
(_Hash_code_base::_M_copy_code, _Hash_code_base::_M_store_code): 
Remove.
* include/bits/hashtable.h (_M_hash_code_ext): New.
(_M_merge_multi(_Hashtable&)): Use latter.
(_M_copy_code): New.
(_M_assign): Use latter.
(_M_bucket_index_ex): New.
(_M_equals): Use latter.
(_M_store_code): New.
(_M_src_hash_code): Remove key_type parameter.
* testsuite/23_containers/unordered_map/modifiers/merge.cc 
(test10): New
test case.

Diff:
---
 libstdc++-v3/include/bits/hashtable.h  | 71 --
 libstdc++-v3/include/bits/hashtable_policy.h   | 18 --
 .../23_containers/unordered_map/modifiers/merge.cc | 46 ++
 3 files changed, 98 insertions(+), 37 deletions(-)

diff --git a/libstdc++-v3/include/bits/hashtable.h 
b/libstdc++-v3/include/bits/hashtable.h
index d6d76a743bbe..246e62afc6af 100644
--- a/libstdc++-v3/include/bits/hashtable.h
+++ b/libstdc++-v3/include/bits/hashtable.h
@@ -808,6 +808,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   _M_bucket_index(__hash_code __c) const
   { return __hash_code_base::_M_bucket_index(__c, _M_bucket_count); }
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wc++17-extensions" // if constexpr
+  // Get hash code for a node that comes from another _Hashtable.
+  // Reuse a cached hash code if the hash function is stateless,
+  // otherwise recalculate it using our own hash function.
+  __hash_code
+  _M_hash_code_ext(const __node_value_type& __from) const
+  {
+   if constexpr (__and_<__hash_cached, is_empty<_Hash>>::value)
+ return __from._M_hash_code;
+   else
+ return this->_M_hash_code(_ExtractKey{}(__from._M_v()));
+  }
+
+  // Like _M_bucket_index but when the node is coming from another
+  // container instance.
+  size_type
+  _M_bucket_index_ext(const __node_value_type& __from) const
+  { return _RangeHash{}(_M_hash_code_ext(__from), _M_bucket_count); }
+
+  void
+  _M_copy_code(__node_value_type& __to,
+  const __node_value_type& __from) const
+  {
+   if constexpr (__hash_cached::value)
+ __to._M_hash_code = _M_hash_code_ext(__from);
+  }
+
+  void
+  _M_store_code(__node_value_type& __to, __hash_code __code) const
+  {
+   if constexpr (__hash_cached::value)
+ __to._M_hash_code = __code;
+  }
+#pragma GCC diagnostic pop
+
   // Find and insert helper functions and types
 
   // Find the node before the one matching the criteria.
@@ -1210,15 +1246,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // with a hash function that might not match this->hash_function().
   template
__hash_code
-   _M_src_hash_code(const _H2&, const key_type& __k,
-const __node_value_type& __src_n) const
+   _M_src_hash_code(const _H2&, const __node_value_type& __src_n) const
{
- if constexpr (std::is_same_v<_H2, _Hash>)
-   if constexpr (std::is_empty_v<_Hash>)
- // If the node has a cached hash code, it's OK to use it.
- return this->_M_hash_code(__src_n);
-
- return this->_M_hash_code(__k);
+ if constexpr (__and_<__hash_cached,
+   is_same<_H2, _Hash>, is_empty<_Hash>>::value)
+   // If the node has a cached hash code, it's OK to use it.
+   return __src_n._M_hash_code;
+ else
+   return this->_M_hash_code(_ExtractKey{}(__src_n._M_v()));
}
 
 public:
@@ -1327,9 +1362,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
do
  {
const auto& __node = static_cast<__node_type&>(*__prev->_M_nxt);
-   const key_type& __k = _ExtractKey{}(__node._M_v());
-   // Hash code from this->hash_function():
-   auto __code = _M_src_hash_code(__src.hash_function(), __k, __node);
+   // Hash code from this:
+   auto __code = _M_hash_code_ext(__node);
// Bucket index in __src, using code from __src.hash_function():
size_type __src_bkt = __src._M_bucket_index(__node);
auto __nh = __src._M_extract_node(__src_bkt, __prev);
@@ -1355,9 +1389,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  for (auto __i = __src.cbegin(), __end = __src.cend(); __i != __end

[gcc/redhat/heads/gcc-15-branch] (336 commits) Merge commit 'r15-7694-gaf73228fdb2e61c6354f972987ba2a746c3

2025-02-25 Thread Jakub Jelinek via Gcc-cvs
The branch 'redhat/heads/gcc-15-branch' was updated to point to:

 c22206a9eb81... Merge commit 'r15-7694-gaf73228fdb2e61c6354f972987ba2a746c3

It previously pointed to:

 785011ff892f... Merge commit 'r15-7359-g64c66f5bce60fcc4a943bcac1865db2a72a

Diff:

Summary of changes (added commits):
---

  c22206a... Merge commit 'r15-7694-gaf73228fdb2e61c6354f972987ba2a746c3
  af73228... Fortran: Fix detection of descriptor arrays in coarray [PR1 (*)
  cc81363... Fortran: Use correct size when transferring between images  (*)
  cdffc76... openmp: Mark OpenMP atomic write expression as read [PR1190 (*)
  86a4af2... openmp: Fix handling of declare target statics with array t (*)
  a41b3f5... c++: Fix range for with PMFs [PR118923] (*)
  90b735b... Daily bump. (*)
  6be1b9e... RISC-V: Include pattern stmts for dynamic LMUL computation  (*)
  f3d4208... vect: Use original LHS type for gather pattern [PR118950]. (*)
  5806279... reassoc: Fix up optimize_range_tests_to_bit_test [PR118915] (*)
  9e4c57f... tree-optimization/118973 - stray abnormal edge after DCE (*)
  27ebd2a... openmp: Fix diagnostics typo [PR118993] (*)
  0d590d2... Use nonnull_if_nonzero attribute rather than nonnull on var (*)
  206cb6c... analyzer: Handle nonnull_if_nonzero attribute [PR117023] (*)
  4dcd3c7... RISC-V: Fix .cfi_offset directive when push/pop in zcmp (*)
  7cfb2c8... Daily bump. (*)
  bf0aa9d... x86: Add tests for PR tree-optimization/82142 (*)
  4cc54ed... Daily bump. (*)
  d4a777d... libstdc++: Fix bootstrap failure with --enable-vtable-verif (*)
  0128fa8... Turn test cases into UNSUPPORTED if running into 'sorry, un (*)
  e8e228a... Gracefully handle the case that 'gcc/testsuite/lib/gcc-dg.e (*)
  f553b1a... Refactor duplicated code into 'gcc/testsuite/lib/gcc-dg.exp (*)
  2abc942... BPF, nvptx: Standardize on 'sorry, unimplemented: dynamic s (*)
  e759ff0... libgomp: Add '__attribute__((unused))' to variables used on (*)
  4470229... libstdc++: Remove misleading comment in __atomic_base (*)
  a742b27... libstdc++: Remove redundant cast in floating_from_chars.cc (*)
  c978965... OpenMP: Silence uninitialized variable warning in C++ front (*)
  a2f60c1... PR modula2/118978 ICE when attempting to pass an incompatib (*)
  4de2d2f... Daily bump. (*)
  700f049... Append a newline in debug_edge (*)
  ee30e25... tree-optimization/118954 - avoid UB on ref created by predc (*)
  d272005... Improve g++.dg/torture/pr118521.C (*)
  7d383a7... Fortran: initialize non-saved pointers with -fcheck=pointer (*)
  08bdc2a... Fortran: Fix build on solaris [PR107635] (*)
  8293b9e... Fortran: Improve gfc_array_kind for assumed rank; gfc_tree_ (*)
  fe4811f... Daily bump. (*)
  4e9ee99... diagnostics: add comments about global_dc (*)
  c5f541e... sarif-replay: add testcase for empty input file (*)
  5a30a3a... sarif-replay: improve error for unescaped braces in message (*)
  25fa8d6... doc: Drop note for Binutils pre 2.24 (*)
  d7ff314... aarch64: Remove old aarch64_expand_sve_vec_cmp_float code (*)
  2f03b10... testsuite: Fix sve/pcs/args_1.c failures [PR116604] (*)
  9e0b94d... testsuite: Fix sve/var_stride_*.c failures (*)
  a275533... tree-optimization/118521 - bogus diagnostic from unreachabl (*)
  a42374b... invoke.texi: Fix typo in the file-cache-lines param (*)
  c0e865f... libstdc++: Workaround Clang bug with __array_rank built-in  (*)
  57f65c5... libstdc++: Add parentheses around _GLIBCXX_HAS_BUILTIN defi (*)
  e8ad697... libstdc++: Use new type-generic built-ins in  [PR11885 (*)
  32457bc... libstdc++: Fix invalid signed arguments to  functions (*)
  29eb6f8... libstdc++: Remove workaround for reserved init_priority war (*)
  99f5744... libstdc++: Use init_priority attribute for tzdb globals [PR (*)
  d324467... Fortran: Remove deprecated coarray routines [PR107635] (*)
  8bf0ee8... Fortran: Add transfer_between_remotes [PR107635] (*)
  69eb026... Fortran: Add send_to_remote [PR107635] (*)
  1584725... Fortran: Add caf_is_present_on_remote. [PR107635] (*)
  abbfeb2... Fortran: Allow to use non-pure/non-elemental functions in c (*)
  b114312... Fortran: Prepare for more caf-rework. [PR107635] (*)
  90ba829... Fortran: Move caf_get-rewrite to coarray.cc [PR107635] (*)
  94d01a8... tree-optimization/86270 - improve SSA coalescing for loop e (*)
  83bc61c... x86: Add a test for PR target/118936 (*)
  6921c93... Revert "x86: Properly find the maximum stack slot alignment (*)
  0312d11... Revert "i386: Simplify PARALLEL RTX scan in ix86_find_all_r (*)
  49bc1cf... libstdc++: Rename concat_view::iterator to ::_Iterator (*)
  8543dc5... libstdc++: Sync concat_view with final P2542 revision [PR11 (*)
  6d8e9cd... Daily bump. (*)
  ab35fc0... GCN, nvptx: Support '--enable-languages=all' (*)
  30c8204... AVR: Add new ISR test gcc.target/avr/torture/isr-04-regs.c. (*)
  c3fecec... aarch64: Fix testcase pr112105.c (*)
  ee6619b... input: give file_cache_slot its own copy of the file path [ (*)
  58b9013... analyzer: hand

[gcc(refs/vendors/redhat/heads/gcc-15-branch)] Merge commit 'r15-7694-gaf73228fdb2e61c6354f972987ba2a746c3519f7' into redhat/gcc-15-branch

2025-02-25 Thread Jakub Jelinek via Libstdc++-cvs
https://gcc.gnu.org/g:c22206a9eb8110a2e8890b2851c5c170e1323889

commit c22206a9eb8110a2e8890b2851c5c170e1323889
Merge: 785011ff892f af73228fdb2e
Author: Jakub Jelinek 
Date:   Tue Feb 25 16:34:15 2025 +0100

Merge commit 'r15-7694-gaf73228fdb2e61c6354f972987ba2a746c3519f7' into 
redhat/gcc-15-branch

Diff:

 ChangeLog  |11 +
 MAINTAINERS| 1 +
 configure  |39 +-
 configure.ac   |39 +-
 gcc/ChangeLog  |  1558 +
 gcc/DATESTAMP  | 2 +-
 gcc/Makefile.in| 2 +-
 gcc/ada/ChangeLog  | 5 +
 gcc/analyzer/ChangeLog |28 +
 gcc/analyzer/diagnostic-manager.cc |26 +-
 gcc/analyzer/kf.cc |22 +-
 gcc/analyzer/region-model.cc   |13 +
 gcc/analyzer/sm-malloc.cc  |99 +-
 gcc/builtin-attrs.def  |29 +
 gcc/builtins.cc| 3 +
 gcc/builtins.def   |46 +-
 gcc/c-family/ChangeLog |44 +
 gcc/c-family/c-common.def  |11 +-
 gcc/c-family/c-common.h| 9 +-
 gcc/c-family/c-gimplify.cc |84 +-
 gcc/c-family/c-opts.cc |17 +-
 gcc/c-family/c-pretty-print.cc |29 +-
 gcc/c-family/c-pretty-print.h  | 6 +-
 gcc/c/ChangeLog|21 +
 gcc/c/c-parser.cc  |33 +-
 gcc/common/config/gcn/gcn-common.cc| 2 +-
 gcc/common/config/i386/i386-common.cc  |35 +-
 gcc/common/config/i386/i386-isas.h | 5 +-
 gcc/common/config/nvptx/nvptx-common.cc| 2 +-
 gcc/config.gcc | 2 +-
 gcc/config.in  | 6 -
 gcc/config/aarch64/aarch64-builtins.cc |29 +
 gcc/config/aarch64/aarch64-option-extensions.def   |10 +-
 gcc/config/aarch64/aarch64-protos.h| 2 +-
 gcc/config/aarch64/aarch64-sve.md  | 2 +-
 gcc/config/aarch64/aarch64.cc  |58 +-
 gcc/config/aarch64/aarch64.md  |50 +-
 gcc/config/aarch64/iterators.md| 4 +
 gcc/config/aarch64/tuning_models/generic_armv8_a.h | 2 +-
 gcc/config/arm/arm-builtins.cc |55 +
 gcc/config/arm/arm-builtins.h  | 1 +
 gcc/config/arm/arm.cc  |   397 +-
 gcc/config/arm/arm.md  | 8 +-
 gcc/config/arm/t-rtems | 5 +-
 gcc/config/avr/avr-arch.h  |22 +-
 gcc/config/avr/avr-c.cc|47 +-
 gcc/config/avr/avr-mcus.def|   212 +-
 gcc/config/avr/avr-protos.h| 1 -
 gcc/config/avr/avr.cc  |   162 +-
 gcc/config/avr/avr.opt | 8 +
 gcc/config/avr/avr.opt.urls| 6 +
 gcc/config/avr/gen-avr-mmcu-specs.cc   |17 +-
 gcc/config/avr/genmultilib.awk |37 +-
 gcc/config/bfin/bfin.md|15 +-
 gcc/config/bpf/bpf.md  | 5 +-
 gcc/config/gcn/gcn-devices.def |   204 +-
 gcc/config/gcn/gcn-tables.opt  |45 +
 gcc/config/gcn/gcn.cc  |42 +-
 gcc/config/gcn/gcn.md  | 7 +
 gcc/config/gcn/gen-gcn-device-macros.awk   | 4 +-
 gcc/config/gcn/mkoffload.cc|   101 +-
 gcc/config/i386/avx512bwintrin.h   | 2 +-
 gcc/config/i386/driver-i386.cc | 5 +-
 gcc/config/i386/i386-options.cc| 8 +-
 gcc/config/i386/i386.cc|11 +
 gcc/config/i386/i386.h | 2 +-
 gcc/config/i386/i386.md|66 +-
 gcc/config/i386/i386.opt   |15 +-
 gcc/config/i386/i386.opt.urls  | 9 +-
 gcc/config/i386/sse.md |18 +-
 gcc/config/loongarch/constraints.md| 2 +-
 gcc/config/loongarch/genopts/loongarch.opt.in  | 4 +
 gcc/config/loongarch/lasx.md   |  1092 +-
 gcc/config/loongarch/loongarch-builtins.cc |67 +-
 gcc/config/loongarch/loongarch-c.cc