[gcc r15-7661] Fortran: Improve gfc_array_kind for assumed rank; gfc_tree_array_size on 'tree'

2025-02-20 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:8293b9e40f12e94a0fdae61b6ec7f2c25ac5b699

commit r15-7661-g8293b9e40f12e94a0fdae61b6ec7f2c25ac5b699
Author: Tobias Burnus 
Date:   Fri Feb 21 08:54:12 2025 +0100

Fortran: Improve gfc_array_kind for assumed rank; gfc_tree_array_size on 
'tree'

Improve the internal and debug representation of assumed-rank arrays by
honoring the pointer and allocatable property.

Permit obtaining the array size from only a tree (via the array descriptor)
besides obtaining it from the gfc_expr's array spec. This will be used
by a follow up OpenMP patch for mapping derived types with allocatable
components.

gcc/fortran/ChangeLog:

* trans-array.cc (gfc_full_array_size): Obtain the rank from
the array descriptor for assumed rank.
(gfc_tree_array_size): Likewise; permit expr = NULL to operate
only the tree.
(gfc_conv_descriptor_stride_get): Update for added assumed-rank
array types.
* trans-openmp.cc (gfc_omp_finish_clause): Likewise.
* trans-types.cc (gfc_build_array_type, gfc_get_derived_type,
gfc_get_array_descr_info): Likewise.
* trans.h (enum gfc_array_kind): Add
GFC_ARRAY_ASSUMED_RANK_{ALLOCATABLE,POINTER{,_CONT}}.

Diff:
---
 gcc/fortran/trans-array.cc  | 41 
 gcc/fortran/trans-openmp.cc | 33 ++
 gcc/fortran/trans-types.cc  | 57 ++---
 gcc/fortran/trans.h |  3 +++
 4 files changed, 90 insertions(+), 44 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index ec627dddffd4..92e933add8a8 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -483,9 +483,11 @@ gfc_conv_descriptor_stride_get (tree desc, tree dim)
   gcc_assert (GFC_DESCRIPTOR_TYPE_P (type));
   if (integer_zerop (dim)
   && (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE
- ||GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ASSUMED_SHAPE_CONT
- ||GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ASSUMED_RANK_CONT
- ||GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER_CONT))
+ || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ASSUMED_SHAPE_CONT
+ || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ASSUMED_RANK_CONT
+ || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ASSUMED_RANK_ALLOCATABLE
+ || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ASSUMED_RANK_POINTER_CONT
+ || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER_CONT))
 return gfc_index_one_node;
 
   return gfc_conv_descriptor_stride (desc, dim);
@@ -8746,7 +8748,8 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
 
 
 /* Calculate the array size (number of elements); if dim != NULL_TREE,
-   return size for that dim (dim=0..rank-1; only for GFC_DESCRIPTOR_TYPE_P).  
*/
+   return size for that dim (dim=0..rank-1; only for GFC_DESCRIPTOR_TYPE_P).
+   If !expr && descriptor array, the rank is taken from the descriptor.  */
 tree
 gfc_tree_array_size (stmtblock_t *block, tree desc, gfc_expr *expr, tree dim)
 {
@@ -8756,20 +8759,15 @@ gfc_tree_array_size (stmtblock_t *block, tree desc, 
gfc_expr *expr, tree dim)
   return GFC_TYPE_ARRAY_SIZE (TREE_TYPE (desc));
 }
   tree size, tmp, rank = NULL_TREE, cond = NULL_TREE;
-  symbol_attribute attr = gfc_expr_attr (expr);
-  gfc_array_spec *as = gfc_get_full_arrayspec_from_expr (expr);
   gcc_assert (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (desc)));
-  if ((!attr.pointer && !attr.allocatable && as && as->type == AS_ASSUMED_RANK)
-   || !dim)
-{
-  if (expr->rank < 0)
-   rank = fold_convert (signed_char_type_node,
-gfc_conv_descriptor_rank (desc));
-  else
-   rank = build_int_cst (signed_char_type_node, expr->rank);
-}
+  enum gfc_array_kind akind = GFC_TYPE_ARRAY_AKIND (TREE_TYPE (desc));
+  if (expr == NULL || expr->rank < 0)
+rank = fold_convert (signed_char_type_node,
+gfc_conv_descriptor_rank (desc));
+  else
+rank = build_int_cst (signed_char_type_node, expr->rank);
 
-  if (dim || expr->rank == 1)
+  if (dim || (expr && expr->rank == 1))
 {
   if (!dim)
dim = gfc_index_zero_node;
@@ -8786,8 +8784,8 @@ gfc_tree_array_size (stmtblock_t *block, tree desc, 
gfc_expr *expr, tree dim)
   size = max (0, size);  */
   size = fold_build2_loc (input_location, MAX_EXPR, gfc_array_index_type,
  size, gfc_index_zero_node);
-  if (!attr.pointer && !attr.allocatable
- && as && as->type == AS_ASSUMED_RANK)
+  if (akind == GFC_ARRAY_ASSUMED_RANK_CONT
+ || akind == GFC_ARRAY_ASSUMED_RANK)
{
  tmp = fold_build2_loc (input_location, MINUS_EXPR, 
signed_char_type_node,
 rank, build_int_cst (signed_char_type_node, 
1));
@@ -8828,7 +8826,7 @@ gfc_tree_array_size (stmtblo

[gcc r15-7647] libstdc++: Fix invalid signed arguments to functions

2025-02-20 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:32457bc25fea80b7bfb2f572e3e163b1dc359969

commit r15-7647-g32457bc25fea80b7bfb2f572e3e163b1dc359969
Author: Jonathan Wakely 
Date:   Thu Feb 13 09:40:44 2025 +

libstdc++: Fix invalid signed arguments to  functions

These should have been unsigned, but the static assertions are only in
the public std::bit_ceil and std::bit_width functions, not the internal
__bit_ceil and __bit_width ones.

libstdc++-v3/ChangeLog:

* include/experimental/bits/simd.h (__find_next_valid_abi): Cast
__bit_ceil argument to unsigned.
* src/c++17/floating_from_chars.cc (__floating_from_chars_hex):
Cast __bit_ceil argument to unsigned.
* src/c++17/memory_resource.cc (big_block): Cast __bit_width
argument to unsigned.

Diff:
---
 libstdc++-v3/include/experimental/bits/simd.h | 2 +-
 libstdc++-v3/src/c++17/floating_from_chars.cc | 5 +++--
 libstdc++-v3/src/c++17/memory_resource.cc | 3 ++-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/include/experimental/bits/simd.h 
b/libstdc++-v3/include/experimental/bits/simd.h
index 500c1781ae54..f0cb101aaa82 100644
--- a/libstdc++-v3/include/experimental/bits/simd.h
+++ b/libstdc++-v3/include/experimental/bits/simd.h
@@ -4634,7 +4634,7 @@ template  class _Abi, int _Bytes, typename 
_Tp>
 static constexpr auto
 _S_choose()
 {
-  constexpr int _NextBytes = std::__bit_ceil(_Bytes) / 2;
+  constexpr int _NextBytes = std::__bit_ceil((unsigned)_Bytes) / 2;
   using _NextAbi = _Abi<_NextBytes>;
   if constexpr (_NextBytes < sizeof(_Tp) * 2) // break recursion
return _Abi<_Bytes>();
diff --git a/libstdc++-v3/src/c++17/floating_from_chars.cc 
b/libstdc++-v3/src/c++17/floating_from_chars.cc
index f8b1e23937d2..d48f1c0d4545 100644
--- a/libstdc++-v3/src/c++17/floating_from_chars.cc
+++ b/libstdc++-v3/src/c++17/floating_from_chars.cc
@@ -1102,8 +1102,9 @@ namespace
   {
// If the leading hexit is not '1', shift MANTISSA to make it so.
// This normalizes input like "4.08p0" into "1.02p2".
-   const int leading_hexit = mantissa >> mantissa_bits;
-   const int leading_hexit_width = __bit_width(leading_hexit); // FIXME: 
optimize?
+   const unsigned leading_hexit = mantissa >> mantissa_bits;
+   const int leading_hexit_width
+ = __bit_width((unsigned)leading_hexit); // FIXME: optimize?
__glibcxx_assert(leading_hexit_width >= 1 && leading_hexit_width <= 4);
shift_mantissa(leading_hexit_width - 1);
// After this adjustment, we can assume the leading hexit is '1'.
diff --git a/libstdc++-v3/src/c++17/memory_resource.cc 
b/libstdc++-v3/src/c++17/memory_resource.cc
index 0e984f27b827..fac4c782c5f7 100644
--- a/libstdc++-v3/src/c++17/memory_resource.cc
+++ b/libstdc++-v3/src/c++17/memory_resource.cc
@@ -591,7 +591,8 @@ namespace pmr
 // The minimum size of a big block.
 // All big_block allocations will be a multiple of this value.
 // Use bit_ceil to get a power of two even for e.g. 20-bit size_t.
-static constexpr size_t min = __bit_ceil(numeric_limits::digits);
+static constexpr size_t min
+  = __bit_ceil((unsigned)numeric_limits::digits);
 
 constexpr
 big_block(size_t bytes, size_t alignment)


[gcc r15-7650] libstdc++: Workaround Clang bug with __array_rank built-in [PR118559]

2025-02-20 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:c0e865f73ddee2e7247a23a7d57ad80261861d35

commit r15-7650-gc0e865f73ddee2e7247a23a7d57ad80261861d35
Author: Jonathan Wakely 
Date:   Wed Feb 19 14:46:32 2025 +

libstdc++: Workaround Clang bug with __array_rank built-in [PR118559]

We started using the __array_rank built-in with r15-1252-g6f0dfa6f1acdf7
but that built-in is buggy in versions of Clang up to and including 19.

libstdc++-v3/ChangeLog:

PR libstdc++/118559
* include/std/type_traits (rank, rank_v): Do not use
__array_rank for Clang 19 and older.

Diff:
---
 libstdc++-v3/include/std/type_traits | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index 338928182576..676cdf2d7e66 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -1484,7 +1484,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 };
 
   /// rank
-#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank)
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank) \
+  && (!defined(__clang__) || __clang_major__ >= 20) // PR118559
   template
 struct rank
 : public integral_constant { };
@@ -3656,7 +3657,8 @@ template 
 template 
   inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
 
-#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank)
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank) \
+  && (!defined(__clang__) || __clang_major__ >= 20) // PR118559
 template 
   inline constexpr size_t rank_v = __array_rank(_Tp);
 #else


[gcc r15-7648] libstdc++: Use new type-generic built-ins in [PR118855]

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

commit r15-7648-ge8ad697a75b0870a833366daf687668a57cabb6e
Author: Jonathan Wakely 
Date:   Wed Feb 19 14:48:04 2025 +

libstdc++: Use new type-generic built-ins in  [PR118855]

This makes several functions in  faster to compile, with fewer
expressions to parse and fewer instantiations of __numeric_traits
required.

libstdc++-v3/ChangeLog:

PR libstdc++/118855
* include/std/bit (__count_lzero, __count_rzero, __popcount):
Use type-generic built-ins when available.

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

diff --git a/libstdc++-v3/include/std/bit b/libstdc++-v3/include/std/bit
index 483801ee85bf..a4817818d194 100644
--- a/libstdc++-v3/include/std/bit
+++ b/libstdc++-v3/include/std/bit
@@ -205,6 +205,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   using __gnu_cxx::__int_traits;
   constexpr auto _Nd = __int_traits<_Tp>::__digits;
 
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_clzg)
+  return __builtin_clzg(__x, _Nd);
+#else
   if (__x == 0)
 return _Nd;
 
@@ -242,6 +245,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  unsigned long long __low = __x & __max_ull;
  return (_Nd - _Nd_ull) + __builtin_clzll(__low);
}
+#endif
 }
 
   template
@@ -258,6 +262,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   using __gnu_cxx::__int_traits;
   constexpr auto _Nd = __int_traits<_Tp>::__digits;
 
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_ctzg)
+  return __builtin_ctzg(__x, _Nd);
+#else
   if (__x == 0)
 return _Nd;
 
@@ -283,6 +290,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  unsigned long long __high = __x >> _Nd_ull;
  return __builtin_ctzll(__high) + _Nd_ull;
}
+#endif
 }
 
   template
@@ -296,6 +304,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 constexpr int
 __popcount(_Tp __x) noexcept
 {
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_popcountg)
+  return __builtin_popcountg(__x);
+#else
   using __gnu_cxx::__int_traits;
   constexpr auto _Nd = __int_traits<_Tp>::__digits;
 
@@ -319,6 +330,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  unsigned long long __high = __x >> _Nd_ull;
  return __builtin_popcountll(__low) + __builtin_popcountll(__high);
}
+#endif
 }
 
   template


[gcc r15-7649] libstdc++: Add parentheses around _GLIBCXX_HAS_BUILTIN definition

2025-02-20 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:57f65c5c027c7c075c2773a857304f341b9dea1a

commit r15-7649-g57f65c5c027c7c075c2773a857304f341b9dea1a
Author: Jonathan Wakely 
Date:   Wed Feb 19 14:45:16 2025 +

libstdc++: Add parentheses around _GLIBCXX_HAS_BUILTIN definition

This allows _GLIBCXX_HAS_BUILTIN (or _GLIBCXX_USE_BUILTIN_TRAIT) to be
used as part of a larger logical expression.

libstdc++-v3/ChangeLog:

* include/bits/c++config (_GLIBCXX_HAS_BUILTIN): Add parentheses.

Diff:
---
 libstdc++-v3/include/bits/c++config | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index b0ca6579cfb8..07f75ea66595 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -885,7 +885,7 @@ namespace __gnu_cxx
 #ifdef __has_builtin
 # ifdef __is_identifier
 // Intel and older Clang require !__is_identifier for some built-ins:
-#  define _GLIBCXX_HAS_BUILTIN(B) __has_builtin(B) || ! __is_identifier(B)
+#  define _GLIBCXX_HAS_BUILTIN(B) (__has_builtin(B) || ! __is_identifier(B))
 # else
 #  define _GLIBCXX_HAS_BUILTIN(B) __has_builtin(B)
 # endif


[gcc r15-7641] Fortran: Add caf_is_present_on_remote. [PR107635]

2025-02-20 Thread Andre Vehreschild via Gcc-cvs
https://gcc.gnu.org/g:15847252648ede9d2ad9eea398b7b870f62a2b30

commit r15-7641-g15847252648ede9d2ad9eea398b7b870f62a2b30
Author: Andre Vehreschild 
Date:   Wed Jan 22 15:12:29 2025 +0100

Fortran: Add caf_is_present_on_remote. [PR107635]

Replace caf_is_present by caf_is_present_on_remote which is using a
dedicated callback for each object to test on the remote image.

gcc/fortran/ChangeLog:

PR fortran/107635

* coarray.cc (create_allocated_callback): Add creating remote
side procedure for checking allocation status of coarray.
(rewrite_caf_allocated): Rewrite ALLOCATED on coarray to use caf
routine.
(coindexed_expr_callback): Exempt caf_is_present_on_remote from
being rewritten again.
* gfortran.h (enum gfc_isym_id): Add caf_is_present_on_remote
id.
* gfortran.texi: Add documentation for caf_is_present_on_remote.
* intrinsic.cc (add_functions): Add caf_is_present_on_remote
symbol.
* trans-decl.cc (gfc_build_builtin_function_decls): Define
interface of caf_is_present_on_remote.
* trans-intrinsic.cc (gfc_conv_intrinsic_caf_is_present_remote):
Translate caf_is_present_on_remote.
(trans_caf_is_present): Remove.
(caf_this_image_ref): Remove.
(gfc_conv_allocated): Take out coarray treatment, because that
is rewritten to caf_is_present_on_remote now.
(gfc_conv_intrinsic_function): Handle caf_is_present_on_remote
calls.
* trans.h: Add symbol for caf_is_present_on_remote and remove
old one.

libgfortran/ChangeLog:

* caf/libcaf.h (_gfortran_caf_is_present_on_remote): Add new
function.
(_gfortran_caf_is_present): Remove deprecated one.
* caf/single.c (struct accessor_hash_t): Add function ptr access
for remote side call.
(_gfortran_caf_is_present_on_remote): Added.
(_gfortran_caf_is_present): Removed.

gcc/testsuite/ChangeLog:

* gfortran.dg/coarray/coarray_allocated.f90: Adapt to new method
of checking on remote image.
* gfortran.dg/coarray_lib_alloc_4.f90: Same.

Diff:
---
 gcc/fortran/coarray.cc | 157 +
 gcc/fortran/gfortran.h |   1 +
 gcc/fortran/gfortran.texi  |  34 +
 gcc/fortran/intrinsic.cc   |   7 +
 gcc/fortran/trans-decl.cc  |  11 +-
 gcc/fortran/trans-intrinsic.cc | 136 --
 gcc/fortran/trans.h|   2 +-
 .../gfortran.dg/coarray/coarray_allocated.f90  |  16 +--
 gcc/testsuite/gfortran.dg/coarray_lib_alloc_4.f90  |   2 +-
 libgfortran/caf/libcaf.h   |   5 +-
 libgfortran/caf/single.c   | 126 -
 11 files changed, 297 insertions(+), 200 deletions(-)

diff --git a/gcc/fortran/coarray.cc b/gcc/fortran/coarray.cc
index fb211715581b..c4e637e0f519 100644
--- a/gcc/fortran/coarray.cc
+++ b/gcc/fortran/coarray.cc
@@ -942,6 +942,154 @@ add_caf_get_from_remote (gfc_expr *e)
   free (wrapper);
 }
 
+static gfc_expr *
+create_allocated_callback (gfc_expr *expr)
+{
+  gfc_namespace *ns;
+  gfc_symbol *extproc, *proc, *result, *base, *add_data, *caller_image;
+  char tname[GFC_MAX_SYMBOL_LEN + 1];
+  char *name;
+  const char *mname;
+  gfc_expr *cb, *post_caf_ref_expr;
+  gfc_code *code;
+  gfc_code *backup_caf_accessor_prepend = caf_accessor_prepend;
+  caf_accessor_prepend = nullptr;
+  gfc_expr swp;
+
+  /* Find the top-level namespace.  */
+  for (ns = gfc_current_ns; ns->parent; ns = ns->parent)
+;
+
+  if (expr->value.function.actual->expr->expr_type == EXPR_VARIABLE)
+strcpy (tname, expr->value.function.actual->expr->symtree->name);
+  else
+strcpy (tname, "dummy");
+  if (expr->value.function.actual->expr->symtree->n.sym->module)
+mname = expr->value.function.actual->expr->symtree->n.sym->module;
+  else
+mname = "main";
+  name = xasprintf ("_caf_present_%s_%s_%d", mname, tname, ++caf_sym_cnt);
+  gfc_get_symbol (name, ns, &extproc);
+  extproc->declared_at = expr->where;
+  gfc_set_sym_referenced (extproc);
+  ++extproc->refs;
+  gfc_commit_symbol (extproc);
+
+  /* Set up namespace.  */
+  gfc_namespace *sub_ns = gfc_get_namespace (ns, 0);
+  sub_ns->sibling = ns->contained;
+  ns->contained = sub_ns;
+  sub_ns->resolved = 1;
+  /* Set up procedure symbol.  */
+  gfc_find_symbol (name, sub_ns, 1, &proc);
+  sub_ns->proc_name = proc;
+  proc->attr.if_source = IFSRC_DECL;
+  proc->attr.access = ACCESS_PUBLIC;
+  gfc_add_subroutine (&proc->attr, name, NULL);
+  proc->attr.host_assoc = 1;
+  proc->attr.always_explicit = 1;
+  proc->declared_at = expr->whe

[gcc r15-7642] Fortran: Add send_to_remote [PR107635]

2025-02-20 Thread Andre Vehreschild via Gcc-cvs
https://gcc.gnu.org/g:69eb02682b80b84dd0f562f19821c8c8c37ad243

commit r15-7642-g69eb02682b80b84dd0f562f19821c8c8c37ad243
Author: Andre Vehreschild 
Date:   Wed Jan 29 12:42:18 2025 +0100

Fortran: Add send_to_remote [PR107635]

Refactor to use send_to_remote instead of the slow send_by_ref.

gcc/fortran/ChangeLog:

PR fortran/107635

* coarray.cc (move_coarray_ref): Move the coarray reference out
of the given one.  Especially when there is a regular array ref.
(fixup_comp_refs): Move components refs to a derived type where
the codim has been removed, aka a new type.
(split_expr_at_caf_ref): Correctly split the reference chain.
(remove_caf_ref): Simplify.
(create_get_callback): Fix some deficiencies.
(create_allocated_callback): Adapt to new signature of split.
(create_send_callback): New function.
(rewrite_caf_send): Rewrite a call to caf_send to
caf_send_to_remote.
(coindexed_code_callback): Treat caf_send and caf_sendget
correctly.
* gfortran.h (enum gfc_isym_id): Add SENDGET-isym.
* gfortran.texi: Add documentation for send_to_remote.
* resolve.cc (gfc_resolve_code): No longer generate send_by_ref
when allocatable coarray (component) is on the lhs.
* trans-decl.cc (gfc_build_builtin_function_decls): Add
caf_send_to_remote decl.
* trans-intrinsic.cc (conv_caf_func_index): Ensure the static
variables created are not in a block-scope.
(conv_caf_send_to_remote): Translate caf_send_to_remote calls.
(conv_caf_send): Renamed to conv_caf_sendget.
(conv_caf_sendget): Renamed from conv_caf_send.
(gfc_conv_intrinsic_subroutine): Branch correctly for
conv_caf_send and sendget.
* trans.h: Correct decl.

libgfortran/ChangeLog:

* caf/libcaf.h: Add/Correct prototypes for caf_get_from_remote,
caf_send_to_remote.
* caf/single.c (struct accessor_hash_t): Rename accessor_t to
getter_t.
(_gfortran_caf_register_accessor): Use new name of getter_t.
(_gfortran_caf_send_to_remote): New function for sending data to
coarray on a remote image.

gcc/testsuite/ChangeLog:

* gfortran.dg/coarray/send_char_array_1.f90: Extend test to
catch more cases.
* gfortran.dg/coarray_42.f90: Invert tests use, because no
longer a send is needed when local memory in a coarray is
allocated.

Diff:
---
 gcc/fortran/coarray.cc | 402 ++---
 gcc/fortran/gfortran.h |   1 +
 gcc/fortran/gfortran.texi  |  69 
 gcc/fortran/resolve.cc |   3 +-
 gcc/fortran/trans-decl.cc  |  10 +
 gcc/fortran/trans-intrinsic.cc | 209 ++-
 gcc/fortran/trans.h|   9 +-
 .../gfortran.dg/coarray/send_char_array_1.f90  |  13 +-
 gcc/testsuite/gfortran.dg/coarray_42.f90   |   4 +-
 libgfortran/caf/libcaf.h   |  12 +-
 libgfortran/caf/single.c   |  57 ++-
 11 files changed, 706 insertions(+), 83 deletions(-)

diff --git a/gcc/fortran/coarray.cc b/gcc/fortran/coarray.cc
index c4e637e0f519..50029102eb9a 100644
--- a/gcc/fortran/coarray.cc
+++ b/gcc/fortran/coarray.cc
@@ -242,25 +242,125 @@ convert_coarray_class_to_derived_type (gfc_symbol *base, 
gfc_namespace *ns)
   base->attr.pointer = 0; // Ensure, that it is no pointer.
 }
 
+static void
+move_coarray_ref (gfc_ref **from, gfc_expr *expr)
+{
+  int i;
+  gfc_ref *to = expr->ref;
+  for (; to && to->next; to = to->next)
+;
+
+  if (!to)
+{
+  expr->ref = gfc_get_ref ();
+  to = expr->ref;
+  to->type = REF_ARRAY;
+}
+  gcc_assert (to->type == REF_ARRAY);
+  to->u.ar.as = gfc_copy_array_spec ((*from)->u.ar.as);
+  to->u.ar.codimen = (*from)->u.ar.codimen;
+  to->u.ar.dimen = (*from)->u.ar.dimen;
+  to->u.ar.type = AR_FULL;
+  to->u.ar.stat = (*from)->u.ar.stat;
+  (*from)->u.ar.stat = nullptr;
+  to->u.ar.team = (*from)->u.ar.team;
+  (*from)->u.ar.team = nullptr;
+  for (i = 0; i < to->u.ar.dimen; ++i)
+{
+  to->u.ar.start[i] = nullptr;
+  to->u.ar.end[i] = nullptr;
+  to->u.ar.stride[i] = nullptr;
+}
+  for (i = (*from)->u.ar.dimen; i < (*from)->u.ar.dimen + 
(*from)->u.ar.codimen;
+   ++i)
+{
+  to->u.ar.dimen_type[i] = (*from)->u.ar.dimen_type[i];
+  to->u.ar.start[i] = (*from)->u.ar.start[i];
+  (*from)->u.ar.start[i] = nullptr;
+  to->u.ar.end[i] = (*from)->u.ar.end[i];
+  (*from)->u.ar.end[i] = nullptr;
+  to->u.ar.stride[i] = (*from)->u.ar.stride[i];
+  (*f

[gcc r15-7638] Fortran: Move caf_get-rewrite to coarray.cc [PR107635]

2025-02-20 Thread Andre Vehreschild via Gcc-cvs
https://gcc.gnu.org/g:90ba8291c31f2cfb6a8c7bf0c0d6a9d93bbbacc9

commit r15-7638-g90ba8291c31f2cfb6a8c7bf0c0d6a9d93bbbacc9
Author: Andre Vehreschild 
Date:   Wed Jan 8 12:33:27 2025 +0100

Fortran: Move caf_get-rewrite to coarray.cc [PR107635]

Add a rewriter to keep all expression tree that is not optimization
together.  At the moment this is just a move from resolve.cc, but will
be extended to handle more cases where rewriting the expression tree may
be easier.  The first use case is to extract accessors for coarray
remote image data access.

gcc/fortran/ChangeLog:

PR fortran/107635
* Make-lang.in: Add coarray.cc.
* coarray.cc: New file.
* gfortran.h (gfc_coarray_rewrite): New procedure.
* parse.cc (rewrite_expr_tree): Add entrypoint for rewriting
expression trees.
* resolve.cc (gfc_resolve_ref): Remove caf_lhs handling.
(get_arrayspec_from_expr): Moved to rewrite.cc.
(remove_coarray_from_derived_type): Same.
(convert_coarray_class_to_derived_type): Same.
(split_expr_at_caf_ref): Same.
(check_add_new_component): Same.
(create_get_parameter_type): Same.
(create_get_callback): Same.
(add_caf_get_intrinsic): Same.
(resolve_variable): Remove caf_lhs handling.

libgfortran/ChangeLog:

* caf/single.c (_gfortran_caf_finalize): Free memory preventing
leaks.
(_gfortran_caf_get_by_ct): Fix constness.
* caf/libcaf.h (_gfortran_caf_register_accessor): Fix constness.

Diff:
---
 gcc/fortran/Make-lang.in |  14 +-
 gcc/fortran/coarray.cc   | 761 +++
 gcc/fortran/gfortran.h   |   2 +
 gcc/fortran/parse.cc |  13 +
 gcc/fortran/resolve.cc   | 693 +-
 libgfortran/caf/libcaf.h |   8 +-
 libgfortran/caf/single.c |   9 +-
 7 files changed, 793 insertions(+), 707 deletions(-)

diff --git a/gcc/fortran/Make-lang.in b/gcc/fortran/Make-lang.in
index e3219c1f01ed..5b2f921bf2ef 100644
--- a/gcc/fortran/Make-lang.in
+++ b/gcc/fortran/Make-lang.in
@@ -52,13 +52,13 @@ fortran-warn = $(STRICT_WARN)
 # from the parse tree to GENERIC
 
 F95_PARSER_OBJS = fortran/arith.o fortran/array.o fortran/bbt.o \
-fortran/check.o fortran/class.o fortran/constructor.o fortran/cpp.o \
-fortran/data.o fortran/decl.o fortran/dump-parse-tree.o fortran/error.o \
-fortran/expr.o fortran/interface.o fortran/intrinsic.o fortran/io.o \
-fortran/iresolve.o fortran/match.o fortran/matchexp.o fortran/misc.o \
-fortran/module.o fortran/openmp.o fortran/options.o fortran/parse.o \
-fortran/primary.o fortran/resolve.o fortran/scanner.o fortran/simplify.o \
-fortran/st.o fortran/symbol.o fortran/target-memory.o
+fortran/check.o fortran/class.o fortran/coarray.o fortran/constructor.o \
+fortran/cpp.o fortran/data.o fortran/decl.o fortran/dump-parse-tree.o \
+fortran/error.o fortran/expr.o fortran/interface.o fortran/intrinsic.o \
+fortran/io.o fortran/iresolve.o fortran/match.o fortran/matchexp.o \
+fortran/misc.o fortran/module.o fortran/openmp.o fortran/options.o \
+fortran/parse.o fortran/primary.o fortran/resolve.o fortran/scanner.o \
+fortran/simplify.o fortran/st.o fortran/symbol.o fortran/target-memory.o
 
 F95_OBJS = $(F95_PARSER_OBJS) $(FORTRAN_TARGET_OBJS) \
 fortran/convert.o fortran/dependency.o fortran/f95-lang.o \
diff --git a/gcc/fortran/coarray.cc b/gcc/fortran/coarray.cc
new file mode 100644
index ..1094a3aec2a0
--- /dev/null
+++ b/gcc/fortran/coarray.cc
@@ -0,0 +1,761 @@
+/* Rewrite the expression tree for coarrays.
+   Copyright (C) 2010-2025 Free Software Foundation, Inc.
+   Contributed by Andre Vehreschild.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+/* Rewrite the expression for coarrays where needed:
+   - coarray indexing operations need the indexing expression put into a
+ routine callable on the remote image
+
+   This rewriter is meant to used for non-optimisational expression tree
+   rewrites.  When implementing early optimisation it is recommended to
+   do this in frontend-passes.cc.
+*/
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "options.h"
+#include "bitmap.h"
+#in

[gcc r15-7639] Fortran: Prepare for more caf-rework. [PR107635]

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

commit r15-7639-gb114312bbaae51567bc0436d07990c4fbaa3c81d
Author: Andre Vehreschild 
Date:   Wed Jan 8 12:33:36 2025 +0100

Fortran: Prepare for more caf-rework. [PR107635]

Factor out generation of code to get remote function index and to
create the additional data structure.  Rename caf_get_by_ct to
caf_get_from_remote.

gcc/fortran/ChangeLog:

PR fortran/107635

* gfortran.texi: Rename caf_get_by_ct to caf_get_from_remote.
* trans-decl.cc (gfc_build_builtin_function_decls): Rename
intrinsic.
* trans-intrinsic.cc (conv_caf_func_index): Factor out
functionality to be reused by other caf-functions.
(conv_caf_add_call_data): Same.
(gfc_conv_intrinsic_caf_get): Use functions factored out.
* trans.h: Rename intrinsic symbol.

libgfortran/ChangeLog:

* caf/libcaf.h (_gfortran_caf_get_by_ref): Remove from ABI.
This function is replaced by caf_get_from_remote ().
(_gfortran_caf_get_remote_function_index): Use better name.
* caf/single.c (_gfortran_caf_finalize): Free internal data.
(_gfortran_caf_get_by_ref): Remove from public interface, but
keep it, because it is still used by sendget ().

gcc/testsuite/ChangeLog:

* gfortran.dg/coarray_lib_comm_1.f90: Adapt to renamed ABI
function.
* gfortran.dg/coarray_stat_function.f90: Same.
* gfortran.dg/coindexed_1.f90: Same.

Diff:
---
 gcc/fortran/gfortran.texi  |  14 +-
 gcc/fortran/trans-decl.cc  |  25 +--
 gcc/fortran/trans-intrinsic.cc | 236 -
 gcc/fortran/trans.h|   3 +-
 gcc/testsuite/gfortran.dg/coarray_lib_comm_1.f90   |   2 +-
 .../gfortran.dg/coarray_stat_function.f90  |   6 +-
 gcc/testsuite/gfortran.dg/coindexed_1.f90  |   4 +-
 libgfortran/caf/libcaf.h   |  18 +-
 libgfortran/caf/single.c   |  11 +-
 9 files changed, 168 insertions(+), 151 deletions(-)

diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index fa7f563ba2ae..3337a79319a8 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -4211,7 +4211,7 @@ future implementation of teams.  It is about to change 
without further notice.
 * _gfortran_caf_sendget:: Sending data between remote images
 * _gfortran_caf_send_by_ref:: Sending data from a local image to a remote 
image using enhanced references
 * _gfortran_caf_get_by_ref:: Getting data from a remote image using enhanced 
references
-* _gfortran_caf_get_by_ct:: Getting data from a remote image using a remote 
side accessor
+* _gfortran_caf_get_from_remote:: Getting data from a remote image using a 
remote side accessor
 * _gfortran_caf_sendget_by_ref:: Sending data between remote images using 
enhanced references
 * _gfortran_caf_lock:: Locking a lock variable
 * _gfortran_caf_unlock:: Unlocking a lock variable
@@ -4617,8 +4617,8 @@ Return the index of the accessor in the lookup table 
build by
 fast, because it may be called often.  A log(N) lookup time for a given hash is
 preferred.  The reference implementation uses @code{bsearch ()}, for example.
 The index returned shall be an array index to be used by
-@ref{_gfortran_caf_get_by_ct}, i.e. a constant time operation is mandatory for
-quick access.
+@ref{_gfortran_caf_get_from_remote}, i.e. a constant time operation is 
mandatory
+for quick access.
 
 The GFortran compiler ensures that
 @code{_gfortran_caf_get_remote_function_index} is called once only for each
@@ -4975,9 +4975,9 @@ error message why the operation is not permitted.
 @end table
 
 
-@node _gfortran_caf_get_by_ct
-@subsection @code{_gfortran_caf_get_by_ct} --- Getting data from a remote 
image using a remote side accessor
-@cindex Coarray, _gfortran_caf_get_by_ct
+@node _gfortran_caf_get_from_remote
+@subsection @code{_gfortran_caf_get_from_remote} --- Getting data from a 
remote image using a remote side accessor
+@cindex Coarray, _gfortran_caf_get_from_remote
 
 @table @asis
 @item @emph{Description}:
@@ -4985,7 +4985,7 @@ Called to get a scalar, an array section or a whole array 
from a remote image
 identified by the @var{image_index}.
 
 @item @emph{Syntax}:
-@code{void _gfortran_caf_get_by_ct (caf_token_t token,
+@code{void _gfortran_caf_get_from_remote (caf_token_t token,
 const gfc_descriptor_t *opt_src_desc, const size_t *opt_src_charlen,
 const int image_index, const size_t dst_size, void **dst_data,
 size_t *opt_dst_charlen, gfc_descriptor_t *opt_dst_desc,
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index ebb63a47531c..0a6b7477c879 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -140,7 +140,6 @@ tree gfor_fndec

[gcc r15-7643] Fortran: Add transfer_between_remotes [PR107635]

2025-02-20 Thread Andre Vehreschild via Gcc-cvs
https://gcc.gnu.org/g:8bf0ee8d62b8a08e808344d31354ab713157e15d

commit r15-7643-g8bf0ee8d62b8a08e808344d31354ab713157e15d
Author: Andre Vehreschild 
Date:   Fri Feb 7 11:25:31 2025 +0100

Fortran: Add transfer_between_remotes [PR107635]

Add the last missing coarray data manipulation routine using remote
accessors.

gcc/fortran/ChangeLog:

PR fortran/107635

* coarray.cc (rewrite_caf_send): Rewrite to
transfer_between_remotes when both sides of the assignment have
a coarray.
(coindexed_code_callback): Prevent duplicate rewrite.
* gfortran.texi: Add documentation for transfer_between_remotes.
* intrinsic.cc (add_subroutines): Add intrinsic symbol for
caf_sendget to allow easy rewrite to transfer_between_remotes.
* trans-decl.cc (gfc_build_builtin_function_decls): Add
prototype for transfer_between_remotes.
* trans-intrinsic.cc (conv_caf_vector_subscript_elem): Mark as
deprecated.
(conv_caf_vector_subscript): Same.
(compute_component_offset): Same.
(conv_expr_ref_to_caf_ref): Same.
(conv_stat_and_team): Extract stat and team from expr.
(gfc_conv_intrinsic_caf_get): Use conv_stat_and_team.
(conv_caf_send_to_remote): Same.
(has_ref_after_cafref): Mark as deprecated.
(conv_caf_sendget): Translate to transfer_between_remotes.
* trans.h: Add prototype for transfer_between_remotes.

libgfortran/ChangeLog:

* caf/libcaf.h: Add prototype for transfer_between_remotes.
* caf/single.c: Implement transfer_between_remotes.

gcc/testsuite/ChangeLog:

* gfortran.dg/coarray_lib_comm_1.f90: Fix up scan_trees.

Diff:
---
 gcc/fortran/coarray.cc   |   32 +-
 gcc/fortran/gfortran.texi|  106 +
 gcc/fortran/intrinsic.cc |4 +
 gcc/fortran/trans-decl.cc|   15 +-
 gcc/fortran/trans-intrinsic.cc   | 2346 --
 gcc/fortran/trans.h  |1 +
 gcc/testsuite/gfortran.dg/coarray_lib_comm_1.f90 |4 +-
 libgfortran/caf/libcaf.h |   12 +
 libgfortran/caf/single.c |   69 +
 9 files changed, 1517 insertions(+), 1072 deletions(-)

diff --git a/gcc/fortran/coarray.cc b/gcc/fortran/coarray.cc
index 50029102eb9a..e5648e0d0279 100644
--- a/gcc/fortran/coarray.cc
+++ b/gcc/fortran/coarray.cc
@@ -1351,12 +1351,6 @@ rewrite_caf_send (gfc_code *c)
   && arg->next->next && arg->next->next->expr->expr_type == EXPR_VARIABLE)
 return;
 
-  if (gfc_is_coindexed (rhs))
-{
-  c->resolved_isym->id = GFC_ISYM_CAF_SENDGET;
-  return;
-}
-
   send_to_remote_expr = create_send_callback (lhs, rhs);
   send_to_remote_hash_expr = gfc_get_expr ();
   send_to_remote_hash_expr->expr_type = EXPR_CONSTANT;
@@ -1372,6 +1366,28 @@ rewrite_caf_send (gfc_code *c)
   arg = arg->next;
   arg->expr = send_to_remote_expr;
   gfc_add_caf_accessor (send_to_remote_hash_expr, send_to_remote_expr);
+
+  if (gfc_is_coindexed (rhs))
+{
+  gfc_expr *get_from_remote_expr, *get_from_remote_hash_expr;
+
+  c->resolved_isym = gfc_intrinsic_subroutine_by_id (GFC_ISYM_CAF_SENDGET);
+  get_from_remote_expr = create_get_callback (rhs);
+  get_from_remote_hash_expr = gfc_get_expr ();
+  get_from_remote_hash_expr->expr_type = EXPR_CONSTANT;
+  get_from_remote_hash_expr->ts.type = BT_INTEGER;
+  get_from_remote_hash_expr->ts.kind = gfc_default_integer_kind;
+  get_from_remote_hash_expr->where = rhs->where;
+  mpz_init_set_ui (get_from_remote_hash_expr->value.integer,
+  gfc_hash_value (get_from_remote_expr->symtree->n.sym));
+  arg->next = gfc_get_actual_arglist ();
+  arg = arg->next;
+  arg->expr = get_from_remote_hash_expr;
+  arg->next = gfc_get_actual_arglist ();
+  arg = arg->next;
+  arg->expr = get_from_remote_expr;
+  gfc_add_caf_accessor (get_from_remote_hash_expr, get_from_remote_expr);
+}
 }
 
 static int
@@ -1451,7 +1467,9 @@ coindexed_code_callback (gfc_code **c, int *walk_subtrees,
*walk_subtrees = 0;
break;
  case GFC_ISYM_CAF_SENDGET:
-   // rewrite_caf_sendget (*c);
+   /* Seldomly this routine is called again with the symbol already
+  changed to CAF_SENDGET.  Do not process the subtree again.  The
+  rewrite has already been done by rewrite_caf_send ().  */
*walk_subtrees = 0;
break;
  case GFC_ISYM_ATOMIC_ADD:
diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index 059022ea5439..36c203b27b3a 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -4214,6 +4214,7 @@ future implement

[gcc r15-7640] Fortran: Allow to use non-pure/non-elemental functions in coarray indexes [PR107635]

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

commit r15-7640-gabbfeb2ecbb5e90aa5d68e489ac283348ee6b8d5
Author: Andre Vehreschild 
Date:   Wed Jan 22 13:36:21 2025 +0100

Fortran: Allow to use non-pure/non-elemental functions in coarray indexes 
[PR107635]

Extract calls to non-pure or non-elemental functions from index
expressions on a coarray.

gcc/fortran/ChangeLog:

PR fortran/107635

* coarray.cc (get_arrayspec_from_expr): Treat array result of
function calls correctly.
(remove_coarray_from_derived_type): Prevent memory loss.
(add_caf_get_from_remote): Correct locus.
(find_comp): New function to find or create a new component in a
derived type.
(check_add_new_comp_handle_array): Handle allocatable arrays or
non-pure/non-elemental functions in indexes of coarrays.
(check_add_new_component): Use above function.
(create_get_parameter_type): Rename to
create_caf_add_data_parameter_type.
(create_caf_add_data_parameter_type): Renaming of variable and
make the additional data a coarray.
(remove_caf_ref): Factor out to reuse in other caf-functions.
(create_get_callback): Use function factored out, set locus
correctly and ensure a kind is set for parameters.
(add_caf_get_intrinsic): Rename to add_caf_get_from_remote and
rename some variables.
(coindexed_expr_callback): Skip over function created by the
rewriter.
(coindexed_code_callback): Filter some intrinsics not to
process.
(gfc_coarray_rewrite): Rewrite also contained functions.
* trans-intrinsic.cc (gfc_conv_intrinsic_caf_get): Reflect
changed order on caf_get_from_remote ().

libgfortran/ChangeLog:

* caf/libcaf.h (_gfortran_caf_register_accessor): Reflect
changed parameter order.
* caf/single.c (struct accessor_hash_t): Same.
(_gfortran_caf_register_accessor): Call accessor using a token
for accessing arrays with a descriptor on the source side.

gcc/testsuite/ChangeLog:

* gfortran.dg/coarray_lib_comm_1.f90: Adapt scan expression.
* gfortran.dg/coarray/get_with_fn_parameter.f90: New test.
* gfortran.dg/coarray/get_with_scalar_fn.f90: New test.

Diff:
---
 gcc/fortran/coarray.cc | 557 -
 gcc/fortran/trans-intrinsic.cc |   3 +-
 .../gfortran.dg/coarray/get_with_fn_parameter.f90  |  29 ++
 .../gfortran.dg/coarray/get_with_scalar_fn.f90 |  30 ++
 gcc/testsuite/gfortran.dg/coarray_lib_comm_1.f90   |   2 +-
 libgfortran/caf/libcaf.h   |   5 +-
 libgfortran/caf/single.c   |  23 +-
 7 files changed, 499 insertions(+), 150 deletions(-)

diff --git a/gcc/fortran/coarray.cc b/gcc/fortran/coarray.cc
index 1094a3aec2a0..fb211715581b 100644
--- a/gcc/fortran/coarray.cc
+++ b/gcc/fortran/coarray.cc
@@ -34,10 +34,16 @@ along with GCC; see the file COPYING3.  If not see
 #include "bitmap.h"
 #include "gfortran.h"
 
+/* The code tree element that is currently processed.  */
 static gfc_code **current_code;
 
+/* Code that is inserted into the current caf_accessor at the beginning.  */
+static gfc_code *caf_accessor_prepend = nullptr;
+
 static bool caf_on_lhs = false;
 
+static int caf_sym_cnt = 0;
+
 static gfc_array_spec *
 get_arrayspec_from_expr (gfc_expr *expr)
 {
@@ -49,6 +55,9 @@ get_arrayspec_from_expr (gfc_expr *expr)
   if (expr->rank == 0)
 return NULL;
 
+  if (expr->expr_type == EXPR_FUNCTION)
+return gfc_copy_array_spec (expr->symtree->n.sym->as);
+
   /* Follow any component references.  */
   if (expr->expr_type == EXPR_VARIABLE || expr->expr_type == EXPR_CONSTANT)
 {
@@ -158,6 +167,9 @@ get_arrayspec_from_expr (gfc_expr *expr)
break;
 
  case AR_FULL:
+   if (dst_as)
+ /* Prevent memory loss.  */
+ gfc_free_array_spec (dst_as);
dst_as = gfc_copy_array_spec (src_as);
break;
  }
@@ -206,6 +218,7 @@ remove_coarray_from_derived_type (gfc_symbol *base, 
gfc_namespace *ns,
 
   p = n;
 }
+  derived->declared_at = base->declared_at;
   gfc_set_sym_referenced (derived);
   gfc_commit_symbol (derived);
   base->ts.u.derived = derived;
@@ -236,6 +249,7 @@ split_expr_at_caf_ref (gfc_expr *expr, gfc_namespace *ns,
   gfc_ref *caf_ref = NULL;
   gfc_symtree *st;
   gfc_symbol *base;
+  bool created;
 
   gcc_assert (expr->expr_type == EXPR_VARIABLE);
   if (!expr->symtree->n.sym->attr.codimension)
@@ -251,8 +265,9 @@ split_expr_at_caf_ref (gfc_expr *expr, gfc_namespace *ns,
}
 }
 
-  gcc_assert (!gf

[gcc r15-7651] invoke.texi: Fix typo in the file-cache-lines param

2025-02-20 Thread Filip Kastl via Gcc-cvs
https://gcc.gnu.org/g:a42374b60884d9ac4ff47e7787b32142526ac666

commit r15-7651-ga42374b60884d9ac4ff47e7787b32142526ac666
Author: Filip Kastl 
Date:   Thu Feb 20 13:20:34 2025 +0100

invoke.texi: Fix typo in the file-cache-lines param

file-cache-lines param was documented as file-cache-files.  This fixes
the typo.

gcc/ChangeLog:

* doc/invoke.texi: Fix typo file-cache-files ->
file-cache-lines.

Signed-off-by: Filip Kastl 

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

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 0c7adc039b5d..bad49a017cc1 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -15787,7 +15787,7 @@ Max number of files in the file cache.
 The file cache is used to print source lines in diagnostics and do some
 source checks like @option{-Wmisleading-indentation}.
 
-@item file-cache-files
+@item file-cache-lines
 Max number of lines to index into file cache. When 0 this is automatically 
sized.
 The file cache is used to print source lines in diagnostics and do some
 source checks like @option{-Wmisleading-indentation}.


[gcc r14-11321] LoongArch: Fix the issue of function jump out of range caused by crtbeginS.o [PR118844].

2025-02-20 Thread LuluCheng via Gcc-cvs
https://gcc.gnu.org/g:9ffecde121af883b60bbe60d00425036bc873048

commit r14-11321-g9ffecde121af883b60bbe60d00425036bc873048
Author: Lulu Cheng 
Date:   Wed Feb 12 14:29:58 2025 +0800

LoongArch: Fix the issue of function jump out of range caused by 
crtbeginS.o [PR118844].

Due to the presence of R_LARCH_B26 in
/usr/lib/gcc/loongarch64-linux-gnu/14/crtbeginS.o, its addressing
range is [PC-128MiB, PC+128MiB-4]. This means that when the code
segment size exceeds 128MB, linking with lld will definitely fail
(ld will not fail because the order of the two is different).

The linking order:
  lld: crtbeginS.o + .text + .plt
  ld : .plt + crtbeginS.o + .text

To solve this issue, add '-mcmodel=extreme' when compiling crtbeginS.o.

PR target/118844

libgcc/ChangeLog:

* config/loongarch/t-crtstuff: Add '-mcmodel=extreme'
to CRTSTUFF_T_CFLAGS_S.

(cherry picked from commit ae14d7d04da8c6cb542269722638071f999f94d8)

Diff:
---
 libgcc/config/loongarch/t-crtstuff | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libgcc/config/loongarch/t-crtstuff 
b/libgcc/config/loongarch/t-crtstuff
index b8c36eb66b78..2a2489b7ef4e 100644
--- a/libgcc/config/loongarch/t-crtstuff
+++ b/libgcc/config/loongarch/t-crtstuff
@@ -3,3 +3,9 @@
 # to .eh_frame data from crtbeginT.o instead of the user-defined object
 # during static linking.
 CRTSTUFF_T_CFLAGS += -fno-omit-frame-pointer -fno-asynchronous-unwind-tables
+
+# As shown in the test case PR118844, when using lld for linking,
+# it fails due to B26 in crtbeginS.o causing the link to exceed the range.
+# Therefore, the issue was resolved by adding the compilation option
+# "-mcmodel=extreme" when compiling crtbeginS.o.
+CRTSTUFF_T_CFLAGS_S += -mcmodel=extreme


[gcc r15-7652] tree-optimization/118521 - bogus diagnostic from unreachable code

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

commit r15-7652-ga2755339c6c9832467c573d956e91565943ecdc1
Author: Richard Biener 
Date:   Thu Feb 20 13:37:05 2025 +0100

tree-optimization/118521 - bogus diagnostic from unreachable code

When SCCP does final value replacement we end up with unfolded IL like

__result_274 = _150 + 1;
...
__new_finish_106 = __result_274 + 3;  <-- from SCCP
_115 = _150 + 4;
if (__new_finish_106 != _115)

this does only get rectified by the next full folding which happens
in forwprop4 which is after the strlen pass emitting the unwanted
diagnostic.  The following mitigates this case in a similar way as
r15-7472 did for PR118817 - by ensuring we have the IL folded.
This is done by simply folding all immediate uses of the former
PHI def that SCCP replaces.  All other more general approaches have
too much fallout at this point.

PR tree-optimization/118521
* tree-scalar-evolution.cc (final_value_replacement_loop):
Fold uses of the replaced PHI def.

* g++.dg/torture/pr118521.C: New testcase.

Diff:
---
 gcc/testsuite/g++.dg/torture/pr118521.C | 14 ++
 gcc/tree-scalar-evolution.cc| 18 ++
 2 files changed, 32 insertions(+)

diff --git a/gcc/testsuite/g++.dg/torture/pr118521.C 
b/gcc/testsuite/g++.dg/torture/pr118521.C
new file mode 100644
index ..1a66aca0e8d2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr118521.C
@@ -0,0 +1,14 @@
+// { dg-do compile }
+// { dg-additional-options "-Wall" }
+
+#include  // dg-bogus new_allocator.h:191 warning: writing 1 byte into 
a region of size 0
+
+void bar(std::vector);
+
+void foo()
+{
+  std::vector v{1, 2};
+  v.insert(v.end(), 2, 0);
+  v.push_back(1);
+  bar(v);
+}
diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc
index 0ba85917d410..4ca08751a0d3 100644
--- a/gcc/tree-scalar-evolution.cc
+++ b/gcc/tree-scalar-evolution.cc
@@ -284,6 +284,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-into-ssa.h"
 #include "builtins.h"
 #include "case-cfn-macros.h"
+#include "tree-eh.h"
 
 static tree analyze_scalar_evolution_1 (class loop *, tree);
 static tree analyze_scalar_evolution_for_address_of (class loop *loop,
@@ -3947,6 +3948,23 @@ final_value_replacement_loop (class loop *loop)
  print_gimple_stmt (dump_file, SSA_NAME_DEF_STMT (rslt), 0);
  fprintf (dump_file, "\n");
}
+
+  /* Re-fold immediate uses of the replaced def, but avoid
+CFG manipulations from this function.  For now only do
+a single-level re-folding, not re-folding uses of
+folded uses.  */
+  if (! SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rslt))
+   {
+ gimple *use_stmt;
+ imm_use_iterator imm_iter;
+ FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, rslt)
+   {
+ gimple_stmt_iterator gsi = gsi_for_stmt (use_stmt);
+ if (!stmt_can_throw_internal (cfun, use_stmt)
+ && fold_stmt (&gsi, follow_all_ssa_edges))
+   update_stmt (gsi_stmt (gsi));
+   }
+   }
 }
 
   return any;


[gcc r12-10960] libgcc: On FreeBSD use GCC's crt objects for static linking

2025-02-20 Thread Gerald Pfeifer via Gcc-cvs
https://gcc.gnu.org/g:23541b23deb5504c6d3c0a3e96a0858e10c3c627

commit r12-10960-g23541b23deb5504c6d3c0a3e96a0858e10c3c627
Author: Dimitry Andric 
Date:   Tue Jan 28 18:36:16 2025 +0100

libgcc: On FreeBSD use GCC's crt objects for static linking

Add crtbeginT.o to extra_parts on FreeBSD. This ensures we use GCC's
crt objects for static linking. Otherwise it could mix crtbeginT.o
from the base system with libgcc's crtend.o, possibly leading to
segfaults.

libgcc:
PR target/118685
* config.host (*-*-freebsd*): Add crtbeginT.o to extra_parts.

Signed-off-by: Dimitry Andric 

Diff:
---
 libgcc/config.host | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libgcc/config.host b/libgcc/config.host
index 89e3dbc7c8a7..8aa22123addb 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -271,7 +271,7 @@ case ${host} in
   # machine-specific sections may refine and add to this
   # configuration.
   tmake_file="$tmake_file t-freebsd t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip 
t-slibgcc t-slibgcc-gld t-slibgcc-elf-ver"
-  extra_parts="crtbegin.o crtend.o crtbeginS.o crtendS.o"
+  extra_parts="crtbegin.o crtend.o crtbeginS.o crtbeginT.o crtendS.o"
   case ${target_thread_file} in
 posix)
   tmake_file="${tmake_file} t-freebsd-thread"


[gcc r15-7654] testsuite: Fix sve/pcs/args_1.c failures [PR116604]

2025-02-20 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:2f03b10da878fe8365975f54b72ff5e717a295a9

commit r15-7654-g2f03b10da878fe8365975f54b72ff5e717a295a9
Author: Richard Sandiford 
Date:   Thu Feb 20 17:10:14 2025 +

testsuite: Fix sve/pcs/args_1.c failures [PR116604]

This test has been failing since r15-1619-g3b9b8d6cfdf593, which made
IRA prefer a call-clobbered register over a call-preserved register
for mem1 (the second load).  In this particular case, that just
forces the variable p3 to be allocated to a call-preserved register
instead, leading to an extra predicate move from p3 to that register.

However, it was really pot luck that this worked before.  Each argument
is used exactly once, so there isn't an obvious colouring order.
And mem0 and mem1 are passed by indirect reference, so they are not
REG_EQUIV to a stack slot in the way that some memory arguments are.

IIRC, the test was the result of some experimentation, and so I think
the best fix is to rework it to try to make it less sensitive to RA
decisions.  This patch does that by enabling scheduling for the
function and using both memory arguments in the same instruction.
This gets rid of the distracting prologue and epilogue code and
restricts the test to the PCS parts.

gcc/testsuite/
PR testsuite/116604
* gcc.target/aarch64/sve/pcs/args_1.c (callee_pred): Enable 
scheduling
and use both memory arguments in the same instruction.  Expect no
prologue and epilogue code.

Diff:
---
 gcc/testsuite/gcc.target/aarch64/sve/pcs/args_1.c | 31 ---
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pcs/args_1.c 
b/gcc/testsuite/gcc.target/aarch64/sve/pcs/args_1.c
index 6deca3295996..b020a0435239 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/pcs/args_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/pcs/args_1.c
@@ -1,31 +1,32 @@
 /* { dg-do compile } */
-/* { dg-options "-O -g" } */
+/* { dg-options "-O -mtune=generic -g" } */
 /* { dg-final { check-function-bodies "**" "" "" { target lp64 } } } */
 
 #include 
 
 /*
 ** callee_pred:
-** addvl   sp, sp, #-1
-** str p[0-9]+, \[sp\]
-** str p[0-9]+, \[sp, #1, mul vl\]
-** ldr (p[0-9]+), \[x0\]
-** ldr (p[0-9]+), \[x1\]
-** brkpa   (p[0-7])\.b, p0/z, p1\.b, p2\.b
-** brkpb   (p[0-7])\.b, \3/z, p3\.b, \1\.b
-** brkap0\.b, \4/z, \2\.b
-** ldr p[0-9]+, \[sp\]
-** ldr p[0-9]+, \[sp, #1, mul vl\]
-** addvl   sp, sp, #1
+** brkpa   (p[0-3])\.b, p0/z, p1\.b, p2\.b
+** (
+** ldr (p[0-3]), \[x0\]
+** ldr (p[0-3]), \[x1\]
+** brkpb   (p[0-3])\.b, \1/z, \2\.b, \3\.b
+** brkap0\.b, \4/z, p3\.b
+** |
+** ldr (p[0-3]), \[x1\]
+** ldr (p[0-3]), \[x0\]
+** brkpb   (p[0-3])\.b, \1/z, \6\.b, \5\.b
+** brkap0\.b, \7/z, p3\.b
+** )
 ** ret
 */
-__SVBool_t __attribute__((noipa))
+__SVBool_t __attribute__((noipa, optimize("schedule-insns")))
 callee_pred (__SVBool_t p0, __SVBool_t p1, __SVBool_t p2, __SVBool_t p3,
 __SVBool_t mem0, __SVBool_t mem1)
 {
   p0 = svbrkpa_z (p0, p1, p2);
-  p0 = svbrkpb_z (p0, p3, mem0);
-  return svbrka_z (p0, mem1);
+  p0 = svbrkpb_z (p0, mem0, mem1);
+  return svbrka_z (p0, p3);
 }
 
 /*


[gcc r15-7655] aarch64: Remove old aarch64_expand_sve_vec_cmp_float code

2025-02-20 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:d7ff3142821bd114ba925cb5a3778d973fe5335e

commit r15-7655-gd7ff3142821bd114ba925cb5a3778d973fe5335e
Author: Richard Sandiford 
Date:   Thu Feb 20 17:10:14 2025 +

aarch64: Remove old aarch64_expand_sve_vec_cmp_float code

While looking at PR118956, I noticed that we had some dead code
left over after the removal of the vcond patterns.  The can_invert_p
path is no longer used.

gcc/
* config/aarch64/aarch64-protos.h 
(aarch64_expand_sve_vec_cmp_float):
Remove can_invert_p argument and change return type to void.
* config/aarch64/aarch64.cc (aarch64_expand_sve_vec_cmp_float):
Likewise.
* config/aarch64/aarch64-sve.md (vec_cmp): Update call
accordingly.

Diff:
---
 gcc/config/aarch64/aarch64-protos.h |  2 +-
 gcc/config/aarch64/aarch64-sve.md   |  2 +-
 gcc/config/aarch64/aarch64.cc   | 36 +---
 3 files changed, 11 insertions(+), 29 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-protos.h 
b/gcc/config/aarch64/aarch64-protos.h
index 4235f4a0ca51..0291a8aa7611 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -1098,7 +1098,7 @@ void aarch64_finish_ldpstp_peephole (rtx *, bool,
 enum rtx_code = (enum rtx_code)0);
 
 void aarch64_expand_sve_vec_cmp_int (rtx, rtx_code, rtx, rtx);
-bool aarch64_expand_sve_vec_cmp_float (rtx, rtx_code, rtx, rtx, bool);
+void aarch64_expand_sve_vec_cmp_float (rtx, rtx_code, rtx, rtx);
 
 bool aarch64_prepare_sve_int_fma (rtx *, rtx_code);
 bool aarch64_prepare_sve_cond_int_fma (rtx *, rtx_code);
diff --git a/gcc/config/aarch64/aarch64-sve.md 
b/gcc/config/aarch64/aarch64-sve.md
index e975286a0190..a93bc463a909 100644
--- a/gcc/config/aarch64/aarch64-sve.md
+++ b/gcc/config/aarch64/aarch64-sve.md
@@ -8495,7 +8495,7 @@
   "TARGET_SVE"
   {
 aarch64_expand_sve_vec_cmp_float (operands[0], GET_CODE (operands[1]),
- operands[2], operands[3], false);
+ operands[2], operands[3]);
 DONE;
   }
 )
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index f5f23f6ff4b9..fe76730b0a7c 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -26877,14 +26877,10 @@ aarch64_emit_sve_invert_fp_cond (rtx target, rtx_code 
code, rtx pred,
 
 /* Expand an SVE floating-point comparison using the SVE equivalent of:
 
- (set TARGET (CODE OP0 OP1))
-
-   If CAN_INVERT_P is true, the caller can also handle inverted results;
-   return true if the result is in fact inverted.  */
+ (set TARGET (CODE OP0 OP1)).  */
 
-bool
-aarch64_expand_sve_vec_cmp_float (rtx target, rtx_code code,
- rtx op0, rtx op1, bool can_invert_p)
+void
+aarch64_expand_sve_vec_cmp_float (rtx target, rtx_code code, rtx op0, rtx op1)
 {
   machine_mode pred_mode = GET_MODE (target);
   machine_mode data_mode = GET_MODE (op0);
@@ -26902,16 +26898,14 @@ aarch64_expand_sve_vec_cmp_float (rtx target, 
rtx_code code,
 case GE:
 case EQ:
 case NE:
-  {
-   /* There is native support for the comparison.  */
-   aarch64_emit_sve_fp_cond (target, code, ptrue, true, op0, op1);
-   return false;
-  }
+  /* There is native support for the comparison.  */
+  aarch64_emit_sve_fp_cond (target, code, ptrue, true, op0, op1);
+  return;
 
 case LTGT:
   /* This is a trapping operation (LT or GT).  */
   aarch64_emit_sve_or_fp_conds (target, LT, GT, ptrue, true, op0, op1);
-  return false;
+  return;
 
 case UNEQ:
   if (!flag_trapping_math)
@@ -26920,7 +26914,7 @@ aarch64_expand_sve_vec_cmp_float (rtx target, rtx_code 
code,
  op1 = force_reg (data_mode, op1);
  aarch64_emit_sve_or_fp_conds (target, UNORDERED, EQ,
ptrue, true, op0, op1);
- return false;
+ return;
}
   /* fall through */
 case UNLT:
@@ -26941,15 +26935,9 @@ aarch64_expand_sve_vec_cmp_float (rtx target, rtx_code 
code,
code = NE;
  else
code = reverse_condition_maybe_unordered (code);
- if (can_invert_p)
-   {
- aarch64_emit_sve_fp_cond (target, code,
-   ordered, false, op0, op1);
- return true;
-   }
  aarch64_emit_sve_invert_fp_cond (target, code,
   ordered, false, op0, op1);
- return false;
+ return;
}
   break;
 
@@ -26964,13 +26952,7 @@ aarch64_expand_sve_vec_cmp_float (rtx target, rtx_code 
code,
 
   /* There is native support for the inverse comparison.  */
   code = reverse_condition_maybe_unordered (code);
-  if (can_invert_p)
-{
-  aarch64_emit_sve_fp_cond (target, code, ptrue, true, op0, op1);
-  return true;
-   

[gcc r15-7656] doc: Drop note for Binutils pre 2.24

2025-02-20 Thread Gerald Pfeifer via Gcc-cvs
https://gcc.gnu.org/g:25fa8d6dc30ace6493fd9e861c13ee3282aa02c0

commit r15-7656-g25fa8d6dc30ace6493fd9e861c13ee3282aa02c0
Author: Gerald Pfeifer 
Date:   Thu Feb 20 18:53:47 2025 +0100

doc: Drop note for Binutils pre 2.24

Binutils 2.24 was released in 2013, so this is more than 11 years old.

gcc:
PR target/69374
* doc/install.texi (Specific, aarch64*-*-*): Drop note for
Binutils pre 2.24.

Diff:
---
 gcc/doc/install.texi | 4 
 1 file changed, 4 deletions(-)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 08892c676e31..29de3200ae88 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -3942,10 +3942,6 @@ information have to.
 @end html
 @anchor{aarch64-x-x}
 @heading aarch64*-*-*
-Binutils pre 2.24 does not have support for selecting @option{-mabi} and
-does not support ILP32.  If it is used to build GCC 4.9 or later, GCC will
-not support option @option{-mabi=ilp32}.
-
 To enable a workaround for the Cortex-A53 erratum number 835769 by default
 (for all CPUs regardless of -mcpu option given) at configure time use the
 @option{--enable-fix-cortex-a53-835769} option.  This will enable the fix by


[gcc r15-7653] testsuite: Fix sve/var_stride_*.c failures

2025-02-20 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:9e0b94dba0759d9fb992674e3a57f7672864fc86

commit r15-7653-g9e0b94dba0759d9fb992674e3a57f7672864fc86
Author: Richard Sandiford 
Date:   Thu Feb 20 17:10:13 2025 +

testsuite: Fix sve/var_stride_*.c failures

gcc.target/aarch64/sve/var_stride_2.c started failing after
r15-268-g9dbff9c05520, but the change was an improvement:

@@ -36,13 +36,11 @@
b.any   .L9
ret
 .L17:
-   ubfiz   x5, x3, 10, 16
-   ubfiz   x4, x2, 10, 16
-   add x5, x1, x5
-   add x4, x0, x4
-   cmp x0, x5
-   ccmpx1, x4, 2, ls
uxtwx4, w2
+   add x6, x1, x3, lsl 10
+   cmp x0, x6
+   add x5, x0, x4, lsl 10
+   ccmpx1, x5, 2, ls
ccmpw2, 0, 4, hi
beq .L3
cntbx7

This patch therefore changes the test to expect the new output
for var_stride_2.c.

The changes for var_stride_4.c were a wash, with both versions
having 18(!) arithmetic instructions before the alias check branch.
Both versions sign-extend the n and m arguments as part of this
sequence; the question is whether they do it first or later.

This patch therefore changes the test to accept either the old
or the new code for var_stride_4.c.

gcc/testsuite/
* gcc.target/aarch64/sve/var_stride_2.c: Expect ADD+LSL.
* gcc.target/aarch64/sve/var_stride_4.c: Accept LSL or SBFIZ.

Diff:
---
 gcc/testsuite/gcc.target/aarch64/sve/var_stride_2.c | 3 +--
 gcc/testsuite/gcc.target/aarch64/sve/var_stride_4.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.target/aarch64/sve/var_stride_2.c 
b/gcc/testsuite/gcc.target/aarch64/sve/var_stride_2.c
index b8afea70207f..33b9f0f197e4 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/var_stride_2.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/var_stride_2.c
@@ -16,8 +16,7 @@ f (TYPE *x, TYPE *y, unsigned short n, unsigned short m)
 /* { dg-final { scan-assembler {\tldr\tw[0-9]+} } } */
 /* { dg-final { scan-assembler {\tstr\tw[0-9]+} } } */
 /* Should multiply by (257-1)*4 rather than (VF-1)*4 or (VF-2)*4.  */
-/* { dg-final { scan-assembler-times {\tubfiz\tx[0-9]+, x2, 10, 16\n} 1 } } */
-/* { dg-final { scan-assembler-times {\tubfiz\tx[0-9]+, x3, 10, 16\n} 1 } } */
+/* { dg-final { scan-assembler-times {\tadd\tx[0-9]+, x[0-9]+, x[0-9]+, lsl 
10\n} 2 } } */
 /* { dg-final { scan-assembler-not {\tcmp\tx[0-9]+, 0} } } */
 /* { dg-final { scan-assembler-not {\tcmp\tw[0-9]+, 0} } } */
 /* { dg-final { scan-assembler-not {\tcsel\tx[0-9]+} } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/var_stride_4.c 
b/gcc/testsuite/gcc.target/aarch64/sve/var_stride_4.c
index d2e74f9d4175..71b826a4c1bb 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/var_stride_4.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/var_stride_4.c
@@ -16,8 +16,7 @@ f (TYPE *x, TYPE *y, int n, int m)
 /* { dg-final { scan-assembler {\tldr\tw[0-9]+} } } */
 /* { dg-final { scan-assembler {\tstr\tw[0-9]+} } } */
 /* Should multiply by (257-1)*4 rather than (VF-1)*4.  */
-/* { dg-final { scan-assembler-times {\tsbfiz\tx[0-9]+, x2, 10, 32\n} 1 } } */
-/* { dg-final { scan-assembler-times {\tsbfiz\tx[0-9]+, x3, 10, 32\n} 1 } } */
+/* { dg-final { scan-assembler-times {\t(?:lsl\tx[0-9]+, x[0-9]+, 
10|sbfiz\tx[0-9]+, x[0-9]+, 10, 32)\n} 2 } } */
 /* { dg-final { scan-assembler {\tcmp\tw2, 0} } } */
 /* { dg-final { scan-assembler {\tcmp\tw3, 0} } } */
 /* { dg-final { scan-assembler-times {\tcsel\tx[0-9]+} 4 } } */


[gcc r13-9384] Fortran: fix initialization of allocatable non-deferred character [PR59252]

2025-02-20 Thread Harald Anlauf via Gcc-cvs
https://gcc.gnu.org/g:0c3061fe7367b378eb8adf4845fde914faca1f40

commit r13-9384-g0c3061fe7367b378eb8adf4845fde914faca1f40
Author: Harald Anlauf 
Date:   Fri Feb 7 21:21:10 2025 +0100

Fortran: fix initialization of allocatable non-deferred character [PR59252]

PR fortran/59252

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_trans_subcomponent_assign): Initialize
allocatable non-deferred character with NULL properly.

gcc/testsuite/ChangeLog:

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

(cherry picked from commit 818c36a85e3faec5442eb26799bfa3bba7764b36)

Diff:
---
 gcc/fortran/trans-expr.cc|  8 +++-
 gcc/testsuite/gfortran.dg/allocatable_char_1.f90 | 47 
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 69317c53c71f..161c588be998 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -9037,9 +9037,13 @@ gfc_trans_subcomponent_assign (tree dest, gfc_component 
* cm,
   tmp = gfc_trans_alloc_subarray_assign (tmp, cm, expr);
   gfc_add_expr_to_block (&block, tmp);
 }
-  else if (init && cm->attr.allocatable && expr->expr_type == EXPR_NULL)
+  else if (cm->attr.allocatable && expr->expr_type == EXPR_NULL
+  && (init
+  || (cm->ts.type == BT_CHARACTER
+  && !(cm->ts.deferred || cm->attr.pdt_string
 {
-  /* NULL initialization for allocatable components.  */
+  /* NULL initialization for allocatable components.
+Deferred-length character is dealt with later.  */
   gfc_add_modify (&block, dest, fold_convert (TREE_TYPE (dest),
  null_pointer_node));
 }
diff --git a/gcc/testsuite/gfortran.dg/allocatable_char_1.f90 
b/gcc/testsuite/gfortran.dg/allocatable_char_1.f90
new file mode 100644
index ..1d6c25c4942d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/allocatable_char_1.f90
@@ -0,0 +1,47 @@
+! { dg-do run }
+! { dg-additional-options "-fdump-tree-original" }
+!
+! PR fortran/59252
+
+module mod
+  implicit none
+
+  type t1
+ character(256), allocatable :: label
+  end type t1
+
+  type t2
+ type(t1),   allocatable :: appv(:)
+  end type t2
+
+contains
+  subroutine construct(res)
+type(t2), allocatable, intent(inout) :: res
+if (.not. allocated(res)) allocate(res)
+  end subroutine construct
+
+  subroutine construct_appv(appv)
+type(t1), allocatable, intent(inout) :: appv(:)
+if (.not. allocated(appv)) allocate(appv(20))
+  end subroutine construct_appv
+
+  type(t1) function foo () result (res)
+  end function foo
+end module mod
+
+program testy
+  use mod
+  implicit none
+  type(t2), allocatable :: res
+  type(t1)  :: s
+
+  ! original test from pr59252
+  call construct (res)
+  call construct_appv(res%appv)
+  deallocate (res)
+
+  ! related test from pr118747 comment 2:
+  s = foo ()
+end program testy
+
+! { dg-final { scan-tree-dump-not "__builtin_memmove" "original" } }


[gcc r15-7657] sarif-replay: improve error for unescaped braces in messages (§3.11.5)

2025-02-20 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:5a30a3aba065f6e683bc429da44437676662e113

commit r15-7657-g5a30a3aba065f6e683bc429da44437676662e113
Author: David Malcolm 
Date:   Thu Feb 20 17:10:53 2025 -0500

sarif-replay: improve error for unescaped braces in messages (§3.11.5)

Spotted via https://github.com/llvm/llvm-project/issues/128024

gcc/ChangeLog:
* libsarifreplay.cc
(sarif_replayer::make_plain_text_within_result_message): Capture
which json::string was used.  When reporting on unescaped "{" or
"}" in SARIF message strings, use that string rather than the
message object, and refer the user to §3.11.5 ("Messages with
placeholders") rather than §3.11.11 ("arguments").  Ideally we'd
place the error at the precise character, but that can't be done
without reworking json-parsing.cc's lexer::lex_string, which is
too invasive for stage 4.
(sarif_replayer::get_plain_text_from_mfms): Capture which
json::string was used.
(sarif_replayer::lookup_plain_text_within_result_message):
Likewise.

gcc/testsuite/ChangeLog:
* sarif-replay.dg/2.1.0-invalid/3.11.11-malformed-placeholder.sarif:
Rename to...
* sarif-replay.dg/2.1.0-invalid/3.11.5-unescaped-braces.sarif:
...this.  Update expected subsection in error message, and
expected underline in quoted JSON.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/libsarifreplay.cc  | 43 --
 ...eholder.sarif => 3.11.5-unescaped-braces.sarif} |  4 +-
 2 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/gcc/libsarifreplay.cc b/gcc/libsarifreplay.cc
index cc051dcd485c..ce42bdace3ca 100644
--- a/gcc/libsarifreplay.cc
+++ b/gcc/libsarifreplay.cc
@@ -272,12 +272,14 @@ private:
   const char *
   lookup_plain_text_within_result_message (const json::object 
*tool_component_obj,
   const json::object &message_obj,
-  const json::object *rule_obj);
+  const json::object *rule_obj,
+  const json::string *&out_js_str);
 
   // "multiformatMessageString" object (§3.12).
   const char *
   get_plain_text_from_mfms (json::value &mfms_val,
-   const property_spec_ref &prop);
+   const property_spec_ref &prop,
+   const json::string *&out_js_str);
 
   // "run" object (§3.14)
   enum status
@@ -1367,13 +1369,17 @@ make_plain_text_within_result_message (const 
json::object *tool_component_obj,
   const json::object &message_obj,
   const json::object *rule_obj)
 {
+  const json::string *js_str = nullptr;
   const char *original_text
 = lookup_plain_text_within_result_message (tool_component_obj,
   message_obj,
-  rule_obj);
+  rule_obj,
+  js_str);
   if (!original_text)
 return label_text::borrow (nullptr);
 
+  gcc_assert (js_str);
+
   /* Look up any arguments for substituting into placeholders.  */
   const property_spec_ref arguments_prop ("message", "arguments", "3.11.11");
   const json::array *arguments
@@ -1425,7 +1431,9 @@ make_plain_text_within_result_message (const json::object 
*tool_component_obj,
}
  else
{
- report_invalid_sarif (message_obj, arguments_prop,
+ const spec_ref msgs_with_placeholders ("3.11.5");
+ gcc_assert (js_str);
+ report_invalid_sarif (*js_str, msgs_with_placeholders,
"unescaped '%c' within message string",
ch);
  return label_text::borrow (nullptr);
@@ -1450,11 +1458,14 @@ make_plain_text_within_result_message (const 
json::object *tool_component_obj,
 
 /* Handle a value that should be a multiformatMessageString object (§3.12).
Complain using prop if MFMS_VAL is not an object.
-   Return get the "text" value (or nullptr, and complain).  */
+   Return get the "text" value (or nullptr, and complain).
+   If the result is non-null, write the json::string that was actually used
+   to OUT_JS_STR.  */
 
 const char *
 sarif_replayer::get_plain_text_from_mfms (json::value &mfms_val,
- const property_spec_ref &prop)
+ const property_spec_ref &prop,
+ const json::string *&out_js_str)
 {
   auto mfms_obj = require_object (mfms_val, prop);
   if (!mfms_obj)
@@ -1465,6 +1476,7 @@ sarif_replayer::get_plain_text_from_mfms (

[gcc r15-7659] diagnostics: add comments about global_dc

2025-02-20 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:4e9ee99647ebb9a7cab1497d78477f75d1157ac5

commit r15-7659-g4e9ee99647ebb9a7cab1497d78477f75d1157ac5
Author: David Malcolm 
Date:   Thu Feb 20 17:10:54 2025 -0500

diagnostics: add comments about global_dc

No functional change intended.

gcc/ChangeLog:
* diagnostic-core.h: Add comments making clear that these
functions implicitly use global_dc.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-core.h | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/gcc/diagnostic-core.h b/gcc/diagnostic-core.h
index 8724fa2fd211..1e89c9fac5e6 100644
--- a/gcc/diagnostic-core.h
+++ b/gcc/diagnostic-core.h
@@ -1,6 +1,6 @@
 /* Declarations of core diagnostic functionality for code that does
not need to deal with diagnostic contexts or diagnostic info
-   structures.
+   structures.  These functions implicitly use global_dc.
Copyright (C) 1998-2025 Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -39,7 +39,7 @@ typedef enum
   DK_ANY,
 } diagnostic_t;
 
-/* RAII-style class for grouping related diagnostics.  */
+/* RAII-style class for grouping related diagnostics within global_dc.  */
 
 class auto_diagnostic_group
 {
@@ -48,7 +48,7 @@ class auto_diagnostic_group
   ~auto_diagnostic_group ();
 };
 
-/* RAII-style class for nesting hierarchical diagnostics.
+/* RAII-style class for nesting hierarchical diagnostics within global_dc.
Any diagnostics emitted within the lifetime of this object
will be treated as one level of nesting deeper than diagnostics
emitted outside the lifetime of the object.  */
@@ -88,6 +88,9 @@ extern const char *progname;
 
 extern const char *trim_filename (const char *);
 
+/* Various functions for emitting diagnostics follow.
+   All of these implicitly use global_dc.  */
+
 /* If we haven't already defined a front-end-specific diagnostics
style, use the generic one.  */
 #ifndef GCC_DIAG_STYLE


[gcc r15-7658] sarif-replay: add testcase for empty input file

2025-02-20 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:c5f541e40aca2d36c8a2a731e6b811aa1ad9b38f

commit r15-7658-gc5f541e40aca2d36c8a2a731e6b811aa1ad9b38f
Author: David Malcolm 
Date:   Thu Feb 20 17:10:54 2025 -0500

sarif-replay: add testcase for empty input file

gcc/testsuite/ChangeLog:
* sarif-replay.dg/malformed-json/empty.sarif: New test.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/testsuite/sarif-replay.dg/malformed-json/empty.sarif | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/testsuite/sarif-replay.dg/malformed-json/empty.sarif 
b/gcc/testsuite/sarif-replay.dg/malformed-json/empty.sarif
new file mode 100644
index ..070677e3cf7f
--- /dev/null
+++ b/gcc/testsuite/sarif-replay.dg/malformed-json/empty.sarif
@@ -0,0 +1,2 @@
+/* Empty file (apart from these comments).  */
+/* { dg-error "expected a JSON value but got EOF" "" { target *-*-* } 3 } */


[gcc r15-7645] libstdc++: Use init_priority attribute for tzdb globals [PR118811]

2025-02-20 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:99f57446e63b8ebeaeeae8dc48981cd5f1dfb831

commit r15-7645-g99f57446e63b8ebeaeeae8dc48981cd5f1dfb831
Author: Jonathan Wakely 
Date:   Wed Feb 12 17:29:59 2025 +

libstdc++: Use init_priority attribute for tzdb globals [PR118811]

When linking statically to libstdc++.a (or to libstdc++_nonshared.a in
the RHEL devtoolset compiler) there's a static initialization order
problem where user code might be constructed before the
std::chrono::tzdb_list globals, and so might try to use them after
they've already been destroyed.

Use the init_priority attribute on those globals so that they are
initialized early. Since r15-7511-g4e7f74225116e7 we can disable the
warnings for using a reserved priority using a diagnostic pragma.

libstdc++-v3/ChangeLog:

PR libstdc++/118811
* src/c++20/tzdb.cc (tzdb_list::_Node): Use init_priority
attribute on static data members.
* testsuite/std/time/tzdb_list/pr118811.cc: New test.

Diff:
---
 libstdc++-v3/src/c++20/tzdb.cc | 11 ++
 .../testsuite/std/time/tzdb_list/pr118811.cc   | 25 ++
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc
index 7e8cce7ce8cf..c3bb6a12ccc1 100644
--- a/libstdc++-v3/src/c++20/tzdb.cc
+++ b/libstdc++-v3/src/c++20/tzdb.cc
@@ -133,6 +133,8 @@ namespace std::chrono
 // of this type gives them access to the private members of time_zone
 // and tzdb, without needing them declared in the  header.
 
+// The tzdb_list singleton. This doesn't contain the actual linked list,
+// but it has member functions that give access to it.
 static tzdb_list _S_the_list;
 
 #if USE_ATOMIC_SHARED_PTR
@@ -177,15 +179,16 @@ namespace std::chrono
   // Implementation of the private constructor used for the singleton object.
   constexpr tzdb_list::tzdb_list(nullptr_t) { }
 
-  // The tzdb_list singleton. This doesn't contain the actual linked list,
-  // but it has member functions that give access to it.
+#pragma GCC diagnostic ignored "-Wprio-ctor-dtor"
+
+  [[gnu::init_priority(99)]]
   constinit tzdb_list tzdb_list::_Node::_S_the_list(nullptr);
 
-  // Shared pointer to the first Node in the list.
+  [[gnu::init_priority(99)]]
   constinit tzdb_list::_Node::head_ptr 
tzdb_list::_Node::_S_head_owner{nullptr};
 
 #if USE_ATOMIC_LIST_HEAD
-  // Lock-free access to the first Node in the list.
+  [[gnu::init_priority(99)]]
   constinit atomic tzdb_list::_Node::_S_head_cache{nullptr};
 #endif
 
diff --git a/libstdc++-v3/testsuite/std/time/tzdb_list/pr118811.cc 
b/libstdc++-v3/testsuite/std/time/tzdb_list/pr118811.cc
new file mode 100644
index ..3968be3f0eca
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/time/tzdb_list/pr118811.cc
@@ -0,0 +1,25 @@
+// { dg-do run { target c++20 } }
+// { dg-require-effective-target tzdb }
+// { dg-require-effective-target cxx11_abi }
+// { dg-require-static-libstdcxx }
+// { dg-additional-options "-static-libstdc++" }
+
+#include 
+
+struct Global
+{
+  Global()
+  {
+(void) std::chrono::current_zone(); // initialize tzdb on first use
+  }
+
+  ~Global()
+  {
+(void) std::chrono::current_zone(); // attempt to use it again on exit
+  }
+
+} global;
+
+int main()
+{
+}


[gcc r15-7646] libstdc++: Remove workaround for reserved init_priority warnings

2025-02-20 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:29eb6f8f41e0530f7ecb93cb66d3a35e0344bc1d

commit r15-7646-g29eb6f8f41e0530f7ecb93cb66d3a35e0344bc1d
Author: Jonathan Wakely 
Date:   Fri Feb 14 15:28:32 2025 +

libstdc++: Remove workaround for reserved init_priority warnings

Since r15-7511-g4e7f74225116e7 we can disable the warnings for using a
reserved priority using a diagnostic pragma. That means we no longer
need to put globals using that attribute into separate files that get
included.

This replaces the two uses of such separate files by moving the variable
definition into the source file and adding the diagnostic pragma.

libstdc++-v3/ChangeLog:

* src/c++17/memory_resource.cc (default_res): Define here
instead of including default_resource.h.
* src/c++98/globals_io.cc (__ioinit): Define here instead of
including ios_base_init.h.
* src/c++17/default_resource.h: Removed.
* src/c++98/ios_base_init.h: Removed.

Diff:
---
 libstdc++-v3/src/c++17/default_resource.h | 15 ---
 libstdc++-v3/src/c++17/memory_resource.cc |  5 -
 libstdc++-v3/src/c++98/globals_io.cc  | 11 ++-
 libstdc++-v3/src/c++98/ios_base_init.h| 13 -
 4 files changed, 14 insertions(+), 30 deletions(-)

diff --git a/libstdc++-v3/src/c++17/default_resource.h 
b/libstdc++-v3/src/c++17/default_resource.h
deleted file mode 100644
index f8d03d7d3bca..
--- a/libstdc++-v3/src/c++17/default_resource.h
+++ /dev/null
@@ -1,15 +0,0 @@
-// This is only in a header so we can use the system_header pragma,
-// to suppress the warning caused by using a reserved init_priority.
-#pragma GCC system_header
-
-#ifndef _GLIBCXX_HAS_GTHREADS
-# error "This file should not be included for this build"
-#elif ATOMIC_POINTER_LOCK_FREE == 2
-# error "This file should not be included for this build"
-#elif defined __GTHREAD_MUTEX_INIT
-# error "This file should not be included for this build"
-#endif
-
-struct {
-  atomic_mem_res obj = &newdel_res.obj;
-} default_res __attribute__ ((init_priority (100)));
diff --git a/libstdc++-v3/src/c++17/memory_resource.cc 
b/libstdc++-v3/src/c++17/memory_resource.cc
index 2b6bfbd4dd33..0e984f27b827 100644
--- a/libstdc++-v3/src/c++17/memory_resource.cc
+++ b/libstdc++-v3/src/c++17/memory_resource.cc
@@ -149,7 +149,10 @@ namespace pmr
 #ifdef _GLIBCXX_ATOMIC_MEM_RES_CAN_BE_CONSTANT_INITIALIZED
 __constinit constant_init default_res{&newdel_res.obj};
 #else
-# include "default_resource.h"
+# pragma GCC diagnostic ignored "-Wprio-ctor-dtor"
+struct {
+  atomic_mem_res obj = &newdel_res.obj;
+} default_res __attribute__ ((init_priority (100)));
 #endif
   } // namespace
 
diff --git a/libstdc++-v3/src/c++98/globals_io.cc 
b/libstdc++-v3/src/c++98/globals_io.cc
index 6dc6bf40fe27..e30edf7eae2f 100644
--- a/libstdc++-v3/src/c++98/globals_io.cc
+++ b/libstdc++-v3/src/c++98/globals_io.cc
@@ -69,7 +69,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   fake_wostream wclog;
 #endif
 
-#include "ios_base_init.h"
+// If the target supports init priorities, set up a static object in the
+// compiled library to perform the  initialization once and
+// sufficiently early (so that it happens before any other global
+// constructor when statically linking with libstdc++.a), instead of
+// doing so in (each TU that includes) .
+// This needs to be done in the same TU that defines the stream objects.
+#if _GLIBCXX_USE_INIT_PRIORITY_ATTRIBUTE
+#pragma GCC diagnostic ignored "-Wprio-ctor-dtor"
+static ios_base::Init __ioinit __attribute__((init_priority(90)));
+#endif
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
diff --git a/libstdc++-v3/src/c++98/ios_base_init.h 
b/libstdc++-v3/src/c++98/ios_base_init.h
deleted file mode 100644
index f7edfc846258..
--- a/libstdc++-v3/src/c++98/ios_base_init.h
+++ /dev/null
@@ -1,13 +0,0 @@
-// This is only in a header so we can use the system_header pragma,
-// to suppress the warning caused by using a reserved init_priority.
-#pragma GCC system_header
-
-// If the target supports init priorities, set up a static object in the
-// compiled library to perform the  initialization once and
-// sufficiently early (so that it happens before any other global
-// constructor when statically linking with libstdc++.a), instead of
-// doing so in (each TU that includes) .
-// This needs to be done in the same TU that defines the stream objects.
-#if _GLIBCXX_USE_INIT_PRIORITY_ATTRIBUTE
-static ios_base::Init __ioinit __attribute__((init_priority(90)));
-#endif


[gcc/devel/omp/gcc-14] GCN, nvptx: Support '--enable-languages=all'

2025-02-20 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:2e2e7f904afc7c0d2d37430b4dc5355e561a3add

commit 2e2e7f904afc7c0d2d37430b4dc5355e561a3add
Author: Thomas Schwinge 
Date:   Wed Feb 19 09:30:45 2025 +0100

GCN, nvptx: Support '--enable-languages=all'

..., where "support" means that the build doesn't fail, but it doesn't mean
that all target libraries get built and we get pretty test results for the
additional languages.

* configure.ac (unsupported_languages) [GCN, nvptx]: Add 'ada'.
(noconfigdirs) [GCN, nvptx]: Add 'target-libobjc',
'target-libffi', 'target-libgo'.
* configure: Regenerate.

(cherry picked from commit ab35fc0d897011c6de075e000d1e0388e6359d4e)

Diff:
---
 ChangeLog.omp | 10 ++
 configure | 39 ++-
 configure.ac  | 39 ++-
 3 files changed, 86 insertions(+), 2 deletions(-)

diff --git a/ChangeLog.omp b/ChangeLog.omp
index 1b54affbe80a..8caf51a64e58 100644
--- a/ChangeLog.omp
+++ b/ChangeLog.omp
@@ -1,3 +1,13 @@
+2025-02-20  Thomas Schwinge  
+
+   Backported from trunk:
+   2025-02-19  Thomas Schwinge  
+
+   * configure.ac (unsupported_languages) [GCN, nvptx]: Add 'ada'.
+   (noconfigdirs) [GCN, nvptx]: Add 'target-libobjc',
+   'target-libffi', 'target-libgo'.
+   * configure: Regenerate.
+
 2018-12-20  Maciej W. Rozycki  
 
* Makefile.def (lang_env_dependencies): Disable `cxx' dependency
diff --git a/configure b/configure
index 3b0abeb8b2e4..81ac2cf87a6a 100755
--- a/configure
+++ b/configure
@@ -3443,6 +3443,21 @@ if test "${ENABLE_LIBSTDCXX}" = "default" ; then
   esac
 fi
 
+# Disable Ada/GNAT on systems where it is known to not work.
+# For testing, you can override this with --enable-languages=ada.
+case ,${enable_languages}, in
+  *,ada,*)
+;;
+  *)
+  case "${target}" in
+amdgcn*-*-* \
+| nvptx*-*-* )
+  unsupported_languages="$unsupported_languages ada"
+  ;;
+  esac
+  ;;
+esac
+
 # Disable C++ on systems where it is known to not work.
 # For testing, you can override this with --enable-languages=c++.
 case ,${enable_languages}, in
@@ -3471,6 +3486,16 @@ case ,${enable_languages}, in
   ;;
 esac
 
+# Disable libobjc for some systems where it is known to not work.
+case "${target}" in
+  amdgcn*-*-*)
+noconfigdirs="$noconfigdirs target-libobjc"
+;;
+  nvptx*-*-*)
+noconfigdirs="$noconfigdirs target-libobjc"
+;;
+esac
+
 # Disable D on systems where it is known to not work.
 # For testing, you can override this with --enable-languages=d.
 case ,${enable_languages}, in
@@ -3551,6 +3576,9 @@ case "${target}" in
   alpha*-*-*vms*)
 noconfigdirs="$noconfigdirs target-libffi"
 ;;
+  amdgcn*-*-*)
+noconfigdirs="$noconfigdirs target-libffi"
+;;
   arm*-*-freebsd*)
 noconfigdirs="$noconfigdirs target-libffi"
 ;;
@@ -3594,6 +3622,9 @@ case "${target}" in
   mmix-*-*)
 noconfigdirs="$noconfigdirs target-libffi"
 ;;
+  nvptx*-*-*)
+noconfigdirs="$noconfigdirs target-libffi"
+;;
   powerpc-*-aix*)
 ;;
   rs6000-*-aix*)
@@ -3644,9 +3675,15 @@ if test x$enable_libgo = x; then
 *-*-cygwin* | *-*-mingw*)
noconfigdirs="$noconfigdirs target-libgo"
;;
+amdgcn*-*-*)
+   noconfigdirs="$noconfigdirs target-libgo"
+   ;;
 bpf-*-*)
 noconfigdirs="$noconfigdirs target-libgo"
 ;;
+nvptx*-*-*)
+   noconfigdirs="$noconfigdirs target-libgo"
+   ;;
 esac
 fi
 
@@ -4029,7 +4066,7 @@ case "${target}" in
 noconfigdirs="$noconfigdirs gprof"
 ;;
   nvptx*-*-*)
-noconfigdirs="$noconfigdirs target-libssp target-libstdc++-v3 
target-libobjc"
+noconfigdirs="$noconfigdirs target-libssp target-libstdc++-v3"
 ;;
   sh-*-*)
 case "${target}" in
diff --git a/configure.ac b/configure.ac
index 042681c27be5..9b338c4c5861 100644
--- a/configure.ac
+++ b/configure.ac
@@ -675,6 +675,21 @@ if test "${ENABLE_LIBSTDCXX}" = "default" ; then
   esac
 fi
 
+# Disable Ada/GNAT on systems where it is known to not work.
+# For testing, you can override this with --enable-languages=ada.
+case ,${enable_languages}, in
+  *,ada,*)
+;;
+  *)
+  case "${target}" in
+amdgcn*-*-* \
+| nvptx*-*-* )
+  unsupported_languages="$unsupported_languages ada"
+  ;;
+  esac
+  ;;
+esac
+
 # Disable C++ on systems where it is known to not work.
 # For testing, you can override this with --enable-languages=c++.
 case ,${enable_languages}, in
@@ -703,6 +718,16 @@ case ,${enable_languages}, in
   ;;
 esac
 
+# Disable libobjc for some systems where it is known to not work.
+case "${target}" in
+  amdgcn*-*-*)
+noconfigdirs="$noconfigdirs target-libobjc"
+;;
+  nvptx*-*-*)
+noconfigdirs="$noconfigdirs target-libobjc"
+;;
+esac
+
 # Disable D on systems where it is known to not work.
 # For testing, you can override this with --enab