[gcc r16-134] OpenMP, GCN: Add interop-hsa testcase

2025-04-25 Thread Andrew Stubbs via Gcc-cvs
https://gcc.gnu.org/g:8d84ea28510054fbbb8a2b7441916bd75e29163f

commit r16-134-g8d84ea28510054fbbb8a2b7441916bd75e29163f
Author: Andrew Stubbs 
Date:   Thu Apr 24 16:50:08 2025 +

OpenMP, GCN: Add interop-hsa testcase

This testcase ensures that the interop HSA support is sufficient to run
a kernel manually on the same device.

libgomp/ChangeLog:

* testsuite/libgomp.c/interop-hsa.c: New test.

Diff:
---
 libgomp/testsuite/libgomp.c/interop-hsa.c | 203 ++
 1 file changed, 203 insertions(+)

diff --git a/libgomp/testsuite/libgomp.c/interop-hsa.c 
b/libgomp/testsuite/libgomp.c/interop-hsa.c
new file mode 100644
index ..cf8bc90bb9c0
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/interop-hsa.c
@@ -0,0 +1,203 @@
+/* { dg-additional-options "-ldl" } */
+/* { dg-require-effective-target offload_device_gcn } */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../../include/hsa.h"
+#include "../../config/gcn/libgomp-gcn.h"
+
+#define STACKSIZE (100 * 1024)
+#define HEAPSIZE (10 * 1024 * 1024)
+#define ARENASIZE HEAPSIZE
+
+/* This code fragment must be optimized or else the host-fallback kernel has
+ * invalid ASM inserts.  The rest of the file can be compiled safely at -O0.  
*/
+#pragma omp declare target
+uintptr_t __attribute__((optimize("O1")))
+get_kernel_ptr ()
+{
+  uintptr_t val;
+  if (!omp_is_initial_device ())
+/* "main._omp_fn.0" is the name GCC gives the first OpenMP target
+ * region in the "main" function.
+ * The ".kd" suffix is added by the LLVM assembler when it creates the
+ * kernel meta-data, and this is what we need to launch a kernel.  */
+asm ("s_getpc_b64 %0\n\t"
+"s_add_u32 %L0, %L0, main._omp_fn.0.kd@rel32@lo+4\n\t"
+"s_addc_u32 %H0, %H0, main._omp_fn.0.kd@rel32@hi+4"
+: "=Sg"(val));
+  return val;
+}
+#pragma omp end declare target
+
+int
+main(int argc, char** argv)
+{
+
+  /* Load the HSA runtime DLL.  */
+  void *hsalib = dlopen ("libhsa-runtime64.so.1", RTLD_LAZY);
+  assert (hsalib);
+
+  hsa_status_t (*hsa_signal_create) (hsa_signal_value_t initial_value,
+uint32_t num_consumers,
+const hsa_agent_t *consumers,
+hsa_signal_t *signal)
+= dlsym (hsalib, "hsa_signal_create");
+  assert (hsa_signal_create);
+
+  uint64_t (*hsa_queue_load_write_index_relaxed) (const hsa_queue_t *queue)
+= dlsym (hsalib, "hsa_queue_load_write_index_relaxed");
+  assert (hsa_queue_load_write_index_relaxed);
+
+  void (*hsa_signal_store_relaxed) (hsa_signal_t signal,
+   hsa_signal_value_t value)
+= dlsym (hsalib, "hsa_signal_store_relaxed");
+  assert (hsa_signal_store_relaxed);
+
+  hsa_signal_value_t (*hsa_signal_wait_relaxed) (hsa_signal_t signal,
+hsa_signal_condition_t 
condition,
+hsa_signal_value_t 
compare_value,
+uint64_t timeout_hint,
+hsa_wait_state_t 
wait_state_hint)
+= dlsym (hsalib, "hsa_signal_wait_relaxed");
+  assert (hsa_signal_wait_relaxed);
+
+  void (*hsa_queue_store_write_index_relaxed) (const hsa_queue_t *queue,
+  uint64_t value)
+= dlsym (hsalib, "hsa_queue_store_write_index_relaxed");
+  assert (hsa_queue_store_write_index_relaxed);
+
+  hsa_status_t (*hsa_signal_destroy) (hsa_signal_t signal)
+= dlsym (hsalib, "hsa_signal_destroy");
+  assert (hsa_signal_destroy);
+
+  /* Set up the device data environment.  */
+  int test_data_value = 0;
+#pragma omp target enter data map(test_data_value)
+
+  /* Get the interop details.  */
+  int device_num = omp_get_default_device();
+  hsa_agent_t *gpu_agent;
+  hsa_queue_t *hsa_queue = NULL;
+
+  omp_interop_t interop = omp_interop_none;
+#pragma omp interop init(target, targetsync, prefer_type("hsa"): interop) 
device(device_num)
+  assert (interop != omp_interop_none);
+
+  omp_interop_rc_t retcode;
+  omp_interop_fr_t fr = omp_get_interop_int (interop, omp_ipr_fr_id, &retcode);
+  assert (retcode == omp_irc_success);
+  assert (fr == omp_ifr_hsa);
+
+  gpu_agent = omp_get_interop_ptr(interop, omp_ipr_device, &retcode);
+  assert (retcode == omp_irc_success);
+
+  hsa_queue = omp_get_interop_ptr(interop, omp_ipr_targetsync, &retcode);
+  assert (retcode == omp_irc_success);
+  assert (hsa_queue);
+
+  /* Call an offload kernel via OpenMP/libgomp.
+   *
+   * This kernel serves two purposes:
+   *   1) Lookup the device-side load-address of itself (thus avoiding the
+   *   need to access the libgomp internals).
+   *   2) Count how many times it is called.
+   * We then call it once using OpenMP, and once manually, and check
+   * the counter reads "2".  */
+  uint64_t kernel_object = 

[gcc r15-9587] s390: Allow 5+ argument tail-calls in some special cases [PR119873]

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

commit r15-9587-ga36dd9ee5bb1d2f2f19b8d935db29468a35bb47e
Author: Jakub Jelinek 
Date:   Thu Apr 24 23:44:28 2025 +0200

s390: Allow 5+ argument tail-calls in some special cases [PR119873]

protobuf (and therefore firefox too) currently doesn't build on s390*-linux.
The problem is that it uses [[clang::musttail]] attribute heavily, and in
llvm (IMHO llvm bug) [[clang::musttail]] calls with 5+ arguments on
s390*-linux are silently accepted and result in a normal non-tail call.
In GCC we just reject those because the target hook refuses to tail call it
(IMHO the right behavior).
Now, the reason why that happens is as s390_function_ok_for_sibcall attempts
to explain, the 5th argument (assuming normal <= wordsize integer or pointer
arguments, nothing that needs 2+ registers) is passed in %r6 which is not
call clobbered, so we can't do tail call when we'd have to change content
of that register and then caller would assume %r6 content didn't change and
use it again.
In the protobuf case though, the 5th argument is always passed through
from the caller to the musttail callee unmodified, so one can actually
emit just jg tail_called_function or perhaps tweak some registers but
keep %r6 untouched, and in that case I think it is just fine to tail call
it (at least unless the stack slots used for 6+ argument can't be modified
by the callee in the ABI and nothing checks for that).

So, the following patch checks for this special case, where the argument
which uses %r6 is passed in a single register and it is passed default
definition of SSA_NAME of a PARM_DECL with the same DECL_INCOMING_RTL.

It won't really work at -O0 but should work for -O1 and above, at least when
one doesn't really try to modify the parameter conditionally and hope it 
will
be optimized away in the end.

2025-04-24  Jakub Jelinek  
Stefan Schulze Frielinghaus  

PR target/119873
* config/s390/s390.cc (s390_call_saved_register_used): Don't return
true if default definition of PARM_DECL SSA_NAME of the same 
register
is passed in call saved register.
(s390_function_ok_for_sibcall): Adjust comment.

* gcc.target/s390/pr119873-1.c: New test.
* gcc.target/s390/pr119873-2.c: New test.
* gcc.target/s390/pr119873-3.c: New test.
* gcc.target/s390/pr119873-4.c: New test.

(cherry picked from commit 567684733e0c4f28158e19b72f4e7f660ad81561)

Diff:
---
 gcc/config/s390/s390.cc| 22 +++---
 gcc/testsuite/gcc.target/s390/pr119873-1.c | 11 +++
 gcc/testsuite/gcc.target/s390/pr119873-2.c | 17 +
 gcc/testsuite/gcc.target/s390/pr119873-3.c | 27 +++
 gcc/testsuite/gcc.target/s390/pr119873-4.c | 27 +++
 5 files changed, 101 insertions(+), 3 deletions(-)

diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index d82b16ea9ce0..3cb2b5c1fa17 100644
--- a/gcc/config/s390/s390.cc
+++ b/gcc/config/s390/s390.cc
@@ -14496,7 +14496,22 @@ s390_call_saved_register_used (tree call_expr)
 
  for (reg = 0; reg < nregs; reg++)
if (!call_used_or_fixed_reg_p (reg + REGNO (parm_rtx)))
- return true;
+ {
+   rtx parm;
+   /* Allow passing through unmodified value from caller,
+  see PR119873.  */
+   if (CALL_EXPR_MUST_TAIL_CALL (call_expr)
+   && TREE_CODE (parameter) == SSA_NAME
+   && SSA_NAME_IS_DEFAULT_DEF (parameter)
+   && SSA_NAME_VAR (parameter)
+   && TREE_CODE (SSA_NAME_VAR (parameter)) == PARM_DECL
+   && (parm = DECL_INCOMING_RTL (SSA_NAME_VAR (parameter)))
+   && REG_P (parm)
+   && REGNO (parm) == REGNO (parm_rtx)
+   && REG_NREGS (parm) == REG_NREGS (parm_rtx))
+ break;
+   return true;
+ }
}
   else if (GET_CODE (parm_rtx) == PARALLEL)
{
@@ -14543,8 +14558,9 @@ s390_function_ok_for_sibcall (tree decl, tree exp)
 return false;
 
   /* Register 6 on s390 is available as an argument register but unfortunately
- "caller saved". This makes functions needing this register for arguments
- not suitable for sibcalls.  */
+ "caller saved".  This makes functions needing this register for arguments
+ not suitable for sibcalls, unless the same value is passed from the
+ caller.  */
   return !s390_call_saved_register_used (exp);
 }
 
diff --git a/gcc/testsuite/gcc.target/s390/pr119873-1.c 
b/gcc/testsuite/gcc.target/s390/pr119873-1.c
new file mode 100644
index ..7a9a988526b5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/pr119873-

[gcc r12-11069] vect: Enforce dr_with_seg_len::align precondition [PR116125]

2025-04-25 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:a895b98c6722277c5129dd5d813bbb2e8ac9c98f

commit r12-11069-ga895b98c6722277c5129dd5d813bbb2e8ac9c98f
Author: Richard Sandiford 
Date:   Fri Apr 25 12:04:46 2025 +0100

vect: Enforce dr_with_seg_len::align precondition [PR116125]

tree-data-refs.cc uses alignment information to try to optimise
the code generated for alias checks.  The assumption for "normal"
non-grouped, full-width scalar accesses was that the access size
would be a multiple of the alignment.  As Richi notes in the PR,
this is a documented precondition of dr_with_seg_len:

  /* The minimum common alignment of DR's start address, SEG_LEN and
 ACCESS_SIZE.  */
  unsigned int align;

PR115192 was a case in which this assumption didn't hold.  The access
was part of an aligned 4-element group, but only the first 2 elements
of the group were accessed.  The alignment was therefore double the
access size.

In r15-820-ga0fe4fb1c8d78045 I'd "fixed" that by capping the
alignment in one of the output routines.  But I think that was
misconceived.  The precondition means that we should cap the
alignment at source instead.

Failure to do that caused a similar wrong code bug in this PR,
where the alignment comes from a short bitfield access rather
than from a group access.

gcc/
PR tree-optimization/116125
* tree-vect-data-refs.cc (vect_prune_runtime_alias_test_list): Make
the dr_with_seg_len alignment fields describe tha access sizes as
well as the pointer alignment.
* tree-data-ref.cc (create_intersect_range_checks): Don't compensate
for invalid alignment fields here.

gcc/testsuite/
PR tree-optimization/116125
* gcc.dg/vect/pr116125.c: New test.

(cherry picked from commit e8651b80aeb86da935035e218747a6b41b611497)

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr116125.c | 30 ++
 gcc/tree-data-ref.cc |  2 --
 gcc/tree-vect-data-refs.cc   | 10 +-
 3 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr116125.c 
b/gcc/testsuite/gcc.dg/vect/pr116125.c
new file mode 100644
index ..eab9efdc061b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr116125.c
@@ -0,0 +1,30 @@
+#include "tree-vect.h"
+
+struct st
+{
+  unsigned int num : 8;
+};
+
+void __attribute__((noipa))
+mem_overlap (struct st *a, struct st *b)
+{
+  for (int i = 0; i < 9; i++)
+a[i].num = b[i].num + 1;
+}
+
+int
+main (void)
+{
+  check_vect ();
+
+  struct st a[9] = {};
+
+  // input a = 0, 0, 0, 0, 0, 0, 0, 0, 0
+  mem_overlap (&a[1], a);
+
+  // output a = 0, 1, 2, 3, 4, 5, 6, 7, 8
+  if (a[2].num == 2)
+return 0;
+  else
+__builtin_abort ();
+}
diff --git a/gcc/tree-data-ref.cc b/gcc/tree-data-ref.cc
index 996f8217e286..7227a4ac47d5 100644
--- a/gcc/tree-data-ref.cc
+++ b/gcc/tree-data-ref.cc
@@ -2634,8 +2634,6 @@ create_intersect_range_checks (class loop *loop, tree 
*cond_expr,
 if the maximum value of one segment is equal to the minimum
 value of the other.  */
   min_align = std::min (dr_a.align, dr_b.align);
-  min_align = std::min (min_align, known_alignment (dr_a.access_size));
-  min_align = std::min (min_align, known_alignment (dr_b.access_size));
   cmp_code = LT_EXPR;
 }
 
diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc
index 7af01c6806e3..e1440b06da07 100644
--- a/gcc/tree-vect-data-refs.cc
+++ b/gcc/tree-vect-data-refs.cc
@@ -19,6 +19,7 @@ You should have received a copy of the GNU General Public 
License
 along with GCC; see the file COPYING3.  If not see
 .  */
 
+#define INCLUDE_ALGORITHM
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
@@ -3662,7 +3663,7 @@ vect_prune_runtime_alias_test_list (loop_vec_info 
loop_vinfo)
   poly_uint64 lower_bound;
   tree segment_length_a, segment_length_b;
   unsigned HOST_WIDE_INT access_size_a, access_size_b;
-  unsigned int align_a, align_b;
+  unsigned HOST_WIDE_INT align_a, align_b;
 
   /* Ignore the alias if the VF we chose ended up being no greater
 than the dependence distance.  */
@@ -3819,6 +3820,13 @@ vect_prune_runtime_alias_test_list (loop_vec_info 
loop_vinfo)
   stmt_info_b->stmt);
}
 
+  /* dr_with_seg_len requires the alignment to apply to the segment length
+and access size, not just the start address.  The access size can be
+smaller than the pointer alignment for grouped accesses and bitfield
+references; see PR115192 and PR116125 respectively.  */
+  align_a = std::min (align_a, least_bit_hwi (access_size_a));
+  align_b = std::min (align_b, least_bit_hwi (access_size_b));
+
   dr_with_seg_len dr_a (dr_info_a->dr, segment_length_a,
 

[gcc r12-11070] Avoid using POINTER_DIFF_EXPR for overlap checks [PR119399]

2025-04-25 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:d419ea32d8968d8e88d0e7f5d8ecc57d610a5a3b

commit r12-11070-gd419ea32d8968d8e88d0e7f5d8ecc57d610a5a3b
Author: Richard Sandiford 
Date:   Fri Apr 25 12:04:47 2025 +0100

Avoid using POINTER_DIFF_EXPR for overlap checks [PR119399]

In r10-4803-g8489e1f45b50600c I'd used POINTER_DIFF_EXPR to subtract
the two pointers involved in an overlap test.  I'm not sure whether
I'd specifically chosen that over MINUS_EXPR or not; if so, the only
reason I can think of is that it is probably faster on targets with
PSImode pointers.  Regardless, as the PR points out, subtracting
unrelated pointers using POINTER_DIFF_EXPR is undefined behaviour.

gcc/
PR tree-optimization/119399
* tree-data-ref.cc (create_waw_or_war_checks): Use a MINUS_EXPR
on two converted pointers, rather than converting a 
POINTER_DIFF_EXPR
on the pointers.

gcc/testsuite/
PR tree-optimization/119399
* gcc.dg/vect/pr119399.c: New test.

(cherry picked from commit 4c8c373495d7d863dfb7102726ac3b4b41685df4)

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr119399.c | 10 ++
 gcc/tree-data-ref.cc |  7 ---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr119399.c 
b/gcc/testsuite/gcc.dg/vect/pr119399.c
new file mode 100644
index ..8d868f44b672
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr119399.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-vect-raw" } */
+
+void foo(int *p, int *q, int n)
+{
+  for (int i = 0; i < n; i++)
+p[i] = q[i] + 1;
+}
+
+/* { dg-final { scan-tree-dump-not {

[gcc r16-137] libstdc++: Constrain formatter for thread::id [PR119918]

2025-04-25 Thread Tomasz Kaminski via Gcc-cvs
https://gcc.gnu.org/g:74605294950e4a49627fb71fdedefea176f5ecf7

commit r16-137-g74605294950e4a49627fb71fdedefea176f5ecf7
Author: Tomasz Kamiński 
Date:   Thu Apr 24 09:32:24 2025 +0200

libstdc++: Constrain formatter for thread::id [PR119918]

This patch add constraint __formatter::__char to _CharT type parameter
of formatter specialization, matching the constraint
of formatting of integer/pointers that are used as native handles.

The dependency on  header, is changed to .
To achieve that, formatting of pointers is extracted from void const*
specialization to internal __formatter_ptr<_CharT>, that can be forward
declared.

Finally, the handle representation is now printed directly to __fc.out(),
by the formatter for handle type. To support this, internal formatters
can now be constructed from _Spec object as alternative to invoking parse
method.

PR libstdc++/119918

libstdc++-v3/ChangeLog:

* include/bits/formatfwd.h (__format::_Align): Moved from 
std/format.
(std::__throw_format_error, __format::__formatter_str)
(__format::__formatter_ptr): Declare.
* include/std/format (__format::_Align): Moved to bits/formatfwd.h.
(__formatter_int::__formatter_int): Define.
(__format::__formatter_ptr): Extracted from formatter for const 
void*.
(std::formatter, formatter)
(std::formatter): Delegate to 
__formatter_ptr<_CharT>.
* include/std/thread (std::formatter): Constrain
_CharT template parameter.
(formatter::parse): Specify default aligment, 
and
qualify __throw_format_error to disable ADL.
(formatter::format): Use formatters to write 
directly
to output.
* testsuite/30_threads/thread/id/output.cc: Tests for formatting 
thread::id
representing not-a-thread with padding and formattable concept.

Reviewed-by: Jonathan Wakely 
Signed-off-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/include/bits/formatfwd.h  |  21 +-
 libstdc++-v3/include/std/format| 257 +++--
 libstdc++-v3/include/std/thread|  45 ++--
 .../testsuite/30_threads/thread/id/output.cc   |  30 +++
 4 files changed, 210 insertions(+), 143 deletions(-)

diff --git a/libstdc++-v3/include/bits/formatfwd.h 
b/libstdc++-v3/include/bits/formatfwd.h
index 9ba658b078a5..12ae2ad2ac08 100644
--- a/libstdc++-v3/include/bits/formatfwd.h
+++ b/libstdc++-v3/include/bits/formatfwd.h
@@ -57,6 +57,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template struct formatter;
 
 /// @cond undocumented
+  [[noreturn]]
+  inline void
+  __throw_format_error(const char* __what);
+
 namespace __format
 {
 #ifdef _GLIBCXX_USE_WCHAR_T
@@ -67,6 +71,19 @@ namespace __format
 concept __char = same_as<_CharT, char>;
 #endif
 
+  enum _Align {
+_Align_default,
+_Align_left,
+_Align_right,
+_Align_centre,
+  };
+
+  template struct _Spec;
+
+  template<__char _CharT> struct __formatter_str;
+  template<__char _CharT> struct __formatter_int;
+  template<__char _CharT> struct __formatter_ptr;
+
   template>,
@@ -107,9 +124,6 @@ namespace __format
 {
   __f.set_debug_format();
 };
-
-  template<__char _CharT>
-struct __formatter_int;
 } // namespace __format
 /// @endcond
 
@@ -141,7 +155,6 @@ namespace __format
 }
 #endif // format_ranges
 
-
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 #endif // __glibcxx_format
diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 7d3067098bef..86c93f0e6ebd 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -491,13 +491,6 @@ namespace __format
 _Pres_esc = 0xf,  // For strings, charT and ranges
   };
 
-  enum _Align {
-_Align_default,
-_Align_left,
-_Align_right,
-_Align_centre,
-  };
-
   enum _Sign {
 _Sign_default,
 _Sign_plus,
@@ -1440,6 +1433,13 @@ namespace __format
   static constexpr _Pres_type _AsBool = _Pres_s;
   static constexpr _Pres_type _AsChar = _Pres_c;
 
+  __formatter_int() = default;
+
+  constexpr
+  __formatter_int(_Spec<_CharT> __spec) noexcept
+  : _M_spec(__spec)
+  { }
+
   constexpr typename basic_format_parse_context<_CharT>::iterator
   _M_do_parse(basic_format_parse_context<_CharT>& __pc, _Pres_type __type)
   {
@@ -2387,6 +2387,134 @@ namespace __format
   _Spec<_CharT> _M_spec{};
 };
 
+  template<__format::__char _CharT>
+struct __formatter_ptr
+{
+  __formatter_ptr() = default;
+
+  constexpr
+  __formatter_ptr(_Spec<_CharT> __spec) noexcept
+  : _M_spec(__spec)
+  { }
+
+  constexpr typename basic_format_parse_context<_CharT>::iterator
+  parse(basic_format_parse_context<_CharT>& __pc)
+  {
+   __format::_Spec<_CharT> __spec{};
+ 

[gcc r16-136] libstdc++: Define __cpp_lib_format_ranges in format header [PR109162]

2025-04-25 Thread Tomasz Kaminski via Libstdc++-cvs
https://gcc.gnu.org/g:8b6cc2064306ba506b61f3e224829219033a9373

commit r16-136-g8b6cc2064306ba506b61f3e224829219033a9373
Author: Tomasz Kamiński 
Date:   Tue Apr 22 09:56:42 2025 +0200

libstdc++: Define __cpp_lib_format_ranges in format header [PR109162]

As P2286R8 and P2585R1 as now fully implemented, we now define
__cpp_lib_format_ranges feature test macro with __cpp_lib_format_ranges.
This macro is provided only in .

Uses of internal __glibcxx_format_ranges are also updated.

PR libstdc++/109162

libstdc++-v3/ChangeLog:

* include/bits/version.def (format_ranges): Remove no_stdname and
update value.
* include/bits/version.h: Regenerate.
* src/c++23/std.cc.in: Replace __glibcxx_format_ranges with
__cpp_lib_format_ranges.
* testsuite/std/format/formatter/lwg3944.cc: Likewise.
* testsuite/std/format/parse_ctx.cc: Likewise.
* testsuite/std/format/string.cc: Likewise.
* testsuite/std/format/ranges/feature_test.cc: New test.

Reviewed-by: Jonathan Wakely 
Signed-off-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/include/bits/version.def| 3 +--
 libstdc++-v3/include/bits/version.h  | 3 ++-
 libstdc++-v3/src/c++23/std.cc.in | 6 ++
 libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc   | 2 +-
 libstdc++-v3/testsuite/std/format/parse_ctx.cc   | 2 +-
 libstdc++-v3/testsuite/std/format/ranges/feature_test.cc | 9 +
 libstdc++-v3/testsuite/std/format/string.cc  | 2 +-
 7 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/libstdc++-v3/include/bits/version.def 
b/libstdc++-v3/include/bits/version.def
index 0afaf0dec244..737b3f421bf7 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -1416,9 +1416,8 @@ ftms = {
   // 202207 P2286R8 Formatting Ranges
   // 202207 P2585R1 Improving default container formatting
   // LWG3750 Too many papers bump __cpp_lib_format
-  no_stdname = true; // TODO remove
   values = {
-v = 1; // TODO 202207
+v = 202207;
 cxxmin = 23;
 hosted = yes;
   };
diff --git a/libstdc++-v3/include/bits/version.h 
b/libstdc++-v3/include/bits/version.h
index 980fee641e9d..59ff0cee0436 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -1562,8 +1562,9 @@
 
 #if !defined(__cpp_lib_format_ranges)
 # if (__cplusplus >= 202100L) && _GLIBCXX_HOSTED
-#  define __glibcxx_format_ranges 1L
+#  define __glibcxx_format_ranges 202207L
 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_format_ranges)
+#   define __cpp_lib_format_ranges 202207L
 #  endif
 # endif
 #endif /* !defined(__cpp_lib_format_ranges) && 
defined(__glibcxx_want_format_ranges) */
diff --git a/libstdc++-v3/src/c++23/std.cc.in b/libstdc++-v3/src/c++23/std.cc.in
index ea50496b057c..930a489ff44b 100644
--- a/libstdc++-v3/src/c++23/std.cc.in
+++ b/libstdc++-v3/src/c++23/std.cc.in
@@ -1319,8 +1319,7 @@ export namespace std
   using std::format_to_n;
   using std::format_to_n_result;
   using std::formatted_size;
-// FIXME __cpp_lib_format_ranges
-#if __cplusplus > 202002L
+#if __cpp_lib_format_ranges
   using std::formattable;
 #endif
   using std::formatter;
@@ -1336,8 +1335,7 @@ export namespace std
   using std::wformat_context;
   using std::wformat_parse_context;
   using std::wformat_string;
-// FIXME __cpp_lib_format_ranges
-#ifdef __glibcxx_format_ranges
+#ifdef __cpp_lib_format_ranges
   using std::format_kind;
   using std::range_format;
   using std::range_formatter;
diff --git a/libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc 
b/libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc
index 1f3edc9cb030..07e63af56529 100644
--- a/libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc
+++ b/libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc
@@ -18,7 +18,7 @@ void test_lwg3944()
   std::format(L"{}", "hello"); // { dg-error "here" }
   std::format(L"{}", std::string_view("hello")); // { dg-error "here" }
   std::format(L"{}", std::string("hello")); // { dg-error "here" }
-#ifdef __glibcxx_format_ranges
+#ifdef __cpp_lib_format_ranges
   // LWG 3944 does not change this, it's still valid.
   std::format(L"{}", std::vector{'h', 'e', 'l', 'l', 'o'});
 #endif
diff --git a/libstdc++-v3/testsuite/std/format/parse_ctx.cc 
b/libstdc++-v3/testsuite/std/format/parse_ctx.cc
index b338ac7b762d..b5dd7cdba782 100644
--- a/libstdc++-v3/testsuite/std/format/parse_ctx.cc
+++ b/libstdc++-v3/testsuite/std/format/parse_ctx.cc
@@ -108,7 +108,7 @@ is_std_format_spec_for(std::string_view spec)
   }
 }
 
-#if __glibcxx_format_ranges
+#if __cpp_lib_format_ranges
 constexpr bool escaped_strings_supported = true;
 #else
 constexpr bool escaped_strings_supported = false;
diff --git a/libstdc++-v3/testsuite/std/format/ranges/feature_test.cc 
b/libstdc++-v3/testsuite/st

[gcc r16-135] libstdc++: Implement formatters for queue, priority_queue and stack [PR109162]

2025-04-25 Thread Tomasz Kaminski via Libstdc++-cvs
https://gcc.gnu.org/g:bacf741a92a9a84becd23542b73186da4e4acbf6

commit r16-135-gbacf741a92a9a84becd23542b73186da4e4acbf6
Author: Tomasz Kamiński 
Date:   Fri Apr 18 14:56:39 2025 +0200

libstdc++: Implement formatters for queue, priority_queue and stack 
[PR109162]

This patch implements formatter specializations for standard container 
adaptors
(queue, priority_queue and stack) from P2286R8.

To be able to access the protected `c` member, the adaptors befriend
corresponding formatter specializations. Note that such specialization
may be disable if the container is formattable, in such case
specializations are unharmful.

As in the case of previous commits, the signatures of the user-facing parse
and format methods of the provided formatters deviate from the standard by
constraining types of parameters:
 * _CharT is constrained __formatter::__char
 * basic_format_parse_context<_CharT> for parse argument
 * basic_format_context<_Out, _CharT> for format second argument
The standard specifies all above as unconstrained types. In particular
_CharT constrain, allow us to befriend all allowed specializations.

Furthermore the standard specifies these formatters as delegating to
formatter, charT>, which in turn
delegates to range_formatter. This patch avoids one level of indirection,
and dependency of ranges::ref_view.  This is technically observable if
user specializes formatter> where PD is program defined
container, but I do not think this is the case worth extra indirection.

This patch also moves the formattable and it's dependencies to the 
formatfwd.h,
so it can be used in adapters formatters, without including format header.
The definition of _Iter_for is changed from alias to denoting
back_insert_iterator>, to struct with type nested 
typedef
that points to same type, that is forward declared.

PR libstdc++/109162

libstdc++-v3/ChangeLog:

* include/bits/formatfwd.h (__format::__parsable_with)
(__format::__formattable_with, __format::__formattable_impl)
(__format::__has_debug_format, __format::__const_formattable_range)
(__format::__maybe_const_range, __format::__maybe_const)
(std::formattable): Moved from std/format.
(__format::Iter_for, std::range_formatter): Forward declare.
* include/bits/stl_queue.h (std::formatter): Forward declare.
(std::queue, std::priority_queue): Befriend formatter 
specializations.
* include/bits/stl_stack.h (std::formatter): Forward declare.
(std::stack): Befriend formatter specializations.
* include/std/format (__format::_Iter_for): Define as struct with
(__format::__parsable_with, __format::__formattable_with)
(__format::__formattable_impl, __format::__has_debug_format)
(_format::__const_formattable_range, __format::__maybe_const_range)
(__format::__maybe_const, std::formattable): Moved to 
bits/formatfwd.h.
(std::range_formatter): Remove default argument specified in 
declaration
in bits/formatfwd.h.
* include/std/queue: Include bits/version.h before bits/stl_queue.h.
(formatter, _CharT>)
(formatter, _CharT>): 
Define.
* include/std/stack: Include bits/version.h before bits/stl_stack.h
(formatter, _CharT>): Define.
* testsuite/std/format/ranges/adaptors.cc: New test.

Reviewed-by: Jonathan Wakely 
Signed-off-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/include/bits/formatfwd.h  |  78 +++
 libstdc++-v3/include/bits/stl_queue.h  |  14 ++
 libstdc++-v3/include/bits/stl_stack.h  |   9 ++
 libstdc++-v3/include/std/format|  76 ++
 libstdc++-v3/include/std/queue |  80 ++-
 libstdc++-v3/include/std/stack |  48 ++-
 .../testsuite/std/format/ranges/adaptors.cc| 156 +
 7 files changed, 387 insertions(+), 74 deletions(-)

diff --git a/libstdc++-v3/include/bits/formatfwd.h 
b/libstdc++-v3/include/bits/formatfwd.h
index a6b5ac8c8ce1..9ba658b078a5 100644
--- a/libstdc++-v3/include/bits/formatfwd.h
+++ b/libstdc++-v3/include/bits/formatfwd.h
@@ -37,6 +37,12 @@
 //  must have been included before this header:
 #ifdef __glibcxx_format // C++ >= 20 && HOSTED
 
+#include 
+#include 
+#if __glibcxx_format_ranges // C++ >= 23 && HOSTED
+#  include   // input_range, range_reference_t
+#endif
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -50,6 +56,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // [format.formatter], formatter
   template struct formatter;
 
+/// @cond undocumented
 namespace __format
 {
 #ifdef _GLIBCXX_USE_WCHAR_T
@@ -60,9 +67,80 @@ namespace __format
 concept

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

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

commit ac84ab7066626410dfe17804c7abd090e875ba3b
Merge: 8f87d3d9a9a5 a36dd9ee5bb1
Author: Jakub Jelinek 
Date:   Fri Apr 25 13:30:19 2025 +0200

Merge commit 'r15-9587-ga36dd9ee5bb1d2f2f19b8d935db29468a35bb47e' into 
redhat/gcc-15-branch

Diff:

 ChangeLog  |   15 +
 c++tools/ChangeLog |4 +
 config/ChangeLog   |4 +
 configure  |   19 +-
 configure.ac   |   19 +-
 contrib/ChangeLog  |4 +
 contrib/gennews|1 +
 contrib/header-tools/ChangeLog |4 +
 contrib/reghunt/ChangeLog  |4 +
 contrib/regression/ChangeLog   |4 +
 fixincludes/ChangeLog  |4 +
 gcc/BASE-VER   |2 +-
 gcc/ChangeLog  |   56 +
 gcc/DATESTAMP  |2 +-
 gcc/DEV-PHASE  |1 -
 gcc/ada/ChangeLog  |4 +
 gcc/analyzer/ChangeLog |4 +
 gcc/c-family/ChangeLog |4 +
 gcc/c/ChangeLog|4 +
 gcc/cobol/ChangeLog|4 +
 gcc/common.opt |5 +-
 gcc/config/aarch64/aarch64-c.cc|1 +
 gcc/config/aarch64/aarch64-cores.def   |2 +-
 gcc/config/rs6000/rs6000.cc|   11 +-
 gcc/config/s390/s390.cc|   22 +-
 gcc/cp/ChangeLog   |4 +
 gcc/d/ChangeLog|4 +
 gcc/doc/invoke.texi|   13 +
 gcc/flag-types.h   |3 +-
 gcc/fortran/ChangeLog  |   14 +
 gcc/fortran/resolve.cc |   49 +-
 gcc/go/ChangeLog   |4 +
 gcc/jit/ChangeLog  |4 +
 gcc/lto/ChangeLog  |4 +
 gcc/m2/ChangeLog   |4 +
 gcc/objc/ChangeLog |4 +
 gcc/objcp/ChangeLog|4 +
 gcc/opts.cc|6 +-
 gcc/po/ChangeLog   |   12 +
 gcc/po/gcc.pot | 9382 ++--
 gcc/po/sv.po   |  392 +-
 gcc/rust/ChangeLog |4 +
 gcc/testsuite/ChangeLog|   61 +
 gcc/testsuite/g++.dg/opt/pr119327.C|   16 +
 gcc/testsuite/gcc.dg/completion-2.c|1 -
 gcc/testsuite/gcc.dg/tree-ssa/predcom-8.c  |2 +-
 gcc/testsuite/gcc.dg/vect/vect-early-break_38.c|1 +
 gcc/testsuite/gcc.misc-tests/gcov-31.c |2 +-
 .../gcc.target/aarch64/pragma_cpp_predefs_4.c  |   15 +
 gcc/testsuite/gcc.target/s390/pr119873-1.c |   11 +
 gcc/testsuite/gcc.target/s390/pr119873-2.c |   17 +
 gcc/testsuite/gcc.target/s390/pr119873-3.c |   27 +
 gcc/testsuite/gcc.target/s390/pr119873-4.c |   27 +
 .../gfortran.dg/do_concurrent_all_clauses.f90  |2 +-
 gcc/testsuite/gfortran.dg/pr119836_1.f90   |   18 +
 gcc/testsuite/gfortran.dg/pr119836_2.f90   |   21 +
 gcc/testsuite/gfortran.dg/pr119836_3.f90   |   30 +
 gcc/testsuite/gfortran.dg/pr119836_4.f90   |   30 +
 gnattools/ChangeLog|4 +
 gotools/ChangeLog  |4 +
 include/ChangeLog  |4 +
 libada/ChangeLog   |4 +
 libatomic/ChangeLog|4 +
 libbacktrace/ChangeLog |4 +
 libcc1/ChangeLog   |4 +
 libcody/ChangeLog  |4 +
 libcpp/ChangeLog   |4 +
 libcpp/po/ChangeLog|4 +
 libdecnumber/ChangeLog |4 +
 libffi/ChangeLog   |4 +
 libgcc/ChangeLog   |4 +
 libgcc/config/avr/libf7/ChangeLog  |4 +
 libgcc/config/libbid/ChangeLog |4 +
 libgcobol/ChangeLog|4 +
 libgfortran/ChangeLog  |4 +
 libgm2/ChangeLog   |4 +
 libgomp/ChangeL

[gcc/redhat/heads/gcc-15-branch] (31 commits) Merge commit 'r15-9587-ga36dd9ee5bb1d2f2f19b8d935db29468a35

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

 ac84ab706662... Merge commit 'r15-9587-ga36dd9ee5bb1d2f2f19b8d935db29468a35

It previously pointed to:

 8f87d3d9a9a5... Merge commit 'r15-9557-gd88b917325546cee24a544dc05cbfbef0fe

Diff:

Summary of changes (added commits):
---

  ac84ab7... Merge commit 'r15-9587-ga36dd9ee5bb1d2f2f19b8d935db29468a35
  a36dd9e... s390: Allow 5+ argument tail-calls in some special cases [P (*)
  00cc972... rs6000: Ignore OPTION_MASK_SAVE_TOC_INDIRECT differences in (*)
  1fde851... Adjust gcc_release for id href web transformations (*)
  2434f8b... Bump BASE-VER (*)
  1b30603... Update ChangeLog and version files for release (*)
  fbc59a9... Update gennews for GCC 15. (*)
  71cc99b... Daily bump. (*)
  f873125... opts.cc: Use opts rather than opts_set for validating -fipa (*)
  340a9f8... opts.cc Simplify handling of explicit -flto-partition= and  (*)
  682550f... Regenerate gcc.pot (*)
  3483a2b... Fortran: Fix checking for IMPURE in DO CONCURRENT. (*)
  51ed76f... Update gcc sv.po (*)
  b2f5a66... testsuite: AMDGCN test for vect-early-break_38.c as well to (*)
  f58f528... Daily bump. (*)
  9ef56cd... aarch64: Define __ARM_FEATURE_FAMINMAX (*)
  63bda37... Revert "libstdc++: Optimize std::projected

[gcc r14-11685] libbacktrace: Add hpux fileline support

2025-04-25 Thread John David Anglin via Gcc-cvs
https://gcc.gnu.org/g:57f930fa9774ab3ec7479fc85d70135df271a8b0

commit r14-11685-g57f930fa9774ab3ec7479fc85d70135df271a8b0
Author: John David Anglin 
Date:   Thu Apr 10 10:00:13 2025 -0400

libbacktrace: Add hpux fileline support

Fixes libstdc++ stacktrace tests.

2025-04-10  John David Anglin  

libbacktrace/ChangeLog:
* fileline.c (hpux_get_executable_path): New.
(fileline_initialize): Add pass to get hpux executable path.

Diff:
---
 libbacktrace/fileline.c | 36 +++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/libbacktrace/fileline.c b/libbacktrace/fileline.c
index 68e80c6d2742..767e08e87b89 100644
--- a/libbacktrace/fileline.c
+++ b/libbacktrace/fileline.c
@@ -47,6 +47,10 @@ POSSIBILITY OF SUCH DAMAGE.  */
 #include 
 #endif
 
+#ifdef __hpux__
+#include 
+#endif
+
 #ifdef HAVE_WINDOWS_H
 #ifndef WIN32_MEAN_AND_LEAN
 #define WIN32_MEAN_AND_LEAN
@@ -66,6 +70,33 @@ POSSIBILITY OF SUCH DAMAGE.  */
 #define getexecname() NULL
 #endif
 
+#ifdef __hpux__
+static char *
+hpux_get_executable_path (struct backtrace_state *state,
+ backtrace_error_callback error_callback, void *data)
+{
+  struct shl_descriptor *desc;
+  size_t len = sizeof (struct shl_descriptor);
+
+  desc = backtrace_alloc (state, len, error_callback, data);
+  if (desc == NULL)
+return NULL;
+
+  if (shl_get_r (0, desc) == -1)
+{
+  backtrace_free (state, desc, len, error_callback, data);
+  return NULL;
+}
+
+  return desc->filename;
+}
+
+#else
+
+#define hpux_get_executable_path(state, error_callback, data) NULL
+
+#endif
+
 #if !defined (HAVE_KERN_PROC_ARGS) && !defined (HAVE_KERN_PROC)
 
 #define sysctl_exec_name1(state, error_callback, data) NULL
@@ -245,7 +276,7 @@ fileline_initialize (struct backtrace_state *state,
 
   descriptor = -1;
   called_error_callback = 0;
-  for (pass = 0; pass < 10; ++pass)
+  for (pass = 0; pass < 11; ++pass)
 {
   int does_not_exist;
 
@@ -285,6 +316,9 @@ fileline_initialize (struct backtrace_state *state,
case 9:
  filename = windows_get_executable_path (buf, error_callback, data);
  break;
+   case 10:
+ filename = hpux_get_executable_path (state, error_callback, data);
+ break;
default:
  abort ();
}


[gcc r16-139] s390: Allow 5+ argument tail-calls in some -m31 -mzarch special cases [PR119873]

2025-04-25 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:3d156c9e9bdaf351f77e3348b7d0d75e08f65580

commit r16-139-g3d156c9e9bdaf351f77e3348b7d0d75e08f65580
Author: Jakub Jelinek 
Date:   Fri Apr 25 14:42:01 2025 +0200

s390: Allow 5+ argument tail-calls in some -m31 -mzarch special cases 
[PR119873]

Here is a patch to handle the PARALLEL case too.
I think we can just use rtx_equal_p there, because it will always use
SImode in the EXPR_LIST REGs in that case.

2025-04-25  Jakub Jelinek  

PR target/119873
* config/s390/s390.cc (s390_call_saved_register_used): Don't return
true if default definition of PARM_DECL SSA_NAME of the same 
register
is passed in call saved register in the PARALLEL case either.

* gcc.target/s390/pr119873-5.c: New test.

Diff:
---
 gcc/config/s390/s390.cc| 12 +++-
 gcc/testsuite/gcc.target/s390/pr119873-5.c | 11 +++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index 0e9140ed5a0a..e3edf8595131 100644
--- a/gcc/config/s390/s390.cc
+++ b/gcc/config/s390/s390.cc
@@ -14524,7 +14524,17 @@ s390_call_saved_register_used (tree call_expr)
  gcc_assert (REG_NREGS (r) == 1);
 
  if (!call_used_or_fixed_reg_p (REGNO (r)))
-   return true;
+   {
+ rtx parm;
+ if (TREE_CODE (parameter) == SSA_NAME
+ && SSA_NAME_IS_DEFAULT_DEF (parameter)
+ && SSA_NAME_VAR (parameter)
+ && TREE_CODE (SSA_NAME_VAR (parameter)) == PARM_DECL
+ && (parm = DECL_INCOMING_RTL (SSA_NAME_VAR (parameter)))
+ && rtx_equal_p (parm_rtx, parm))
+   break;
+ return true;
+   }
}
}
 }
diff --git a/gcc/testsuite/gcc.target/s390/pr119873-5.c 
b/gcc/testsuite/gcc.target/s390/pr119873-5.c
new file mode 100644
index ..b5a7950d62b4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/pr119873-5.c
@@ -0,0 +1,11 @@
+/* PR target/119873 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -m31 -mzarch" } */
+
+extern void foo (int x, int y, int z, long long w, int v);
+
+void
+bar (int x, int y, int z, long long w, int v)
+{
+  [[gnu::musttail]] return foo (x, y, z, w, v);
+}


[gcc r15-9590] s390: Allow 5+ argument tail-calls in some -m31 -mzarch special cases [PR119873]

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

commit r15-9590-gf36ec88aa85a1a8f4ec300dfcd862fc4fbca1c53
Author: Jakub Jelinek 
Date:   Fri Apr 25 14:42:01 2025 +0200

s390: Allow 5+ argument tail-calls in some -m31 -mzarch special cases 
[PR119873]

Here is a patch to handle the PARALLEL case too.
I think we can just use rtx_equal_p there, because it will always use
SImode in the EXPR_LIST REGs in that case.

2025-04-25  Jakub Jelinek  

PR target/119873
* config/s390/s390.cc (s390_call_saved_register_used): Don't return
true if default definition of PARM_DECL SSA_NAME of the same 
register
is passed in call saved register in the PARALLEL case either.

* gcc.target/s390/pr119873-5.c: New test.

(cherry picked from commit 3d156c9e9bdaf351f77e3348b7d0d75e08f65580)

Diff:
---
 gcc/config/s390/s390.cc| 13 -
 gcc/testsuite/gcc.target/s390/pr119873-5.c | 11 +++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index 3cb2b5c1fa17..901e2613a762 100644
--- a/gcc/config/s390/s390.cc
+++ b/gcc/config/s390/s390.cc
@@ -14525,7 +14525,18 @@ s390_call_saved_register_used (tree call_expr)
  gcc_assert (REG_NREGS (r) == 1);
 
  if (!call_used_or_fixed_reg_p (REGNO (r)))
-   return true;
+   {
+ rtx parm;
+ if (CALL_EXPR_MUST_TAIL_CALL (call_expr)
+ && TREE_CODE (parameter) == SSA_NAME
+ && SSA_NAME_IS_DEFAULT_DEF (parameter)
+ && SSA_NAME_VAR (parameter)
+ && TREE_CODE (SSA_NAME_VAR (parameter)) == PARM_DECL
+ && (parm = DECL_INCOMING_RTL (SSA_NAME_VAR (parameter)))
+ && rtx_equal_p (parm_rtx, parm))
+   break;
+ return true;
+   }
}
}
 }
diff --git a/gcc/testsuite/gcc.target/s390/pr119873-5.c 
b/gcc/testsuite/gcc.target/s390/pr119873-5.c
new file mode 100644
index ..b5a7950d62b4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/pr119873-5.c
@@ -0,0 +1,11 @@
+/* PR target/119873 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -m31 -mzarch" } */
+
+extern void foo (int x, int y, int z, long long w, int v);
+
+void
+bar (int x, int y, int z, long long w, int v)
+{
+  [[gnu::musttail]] return foo (x, y, z, w, v);
+}


[gcc r16-142] libstdc++: Minimalize temporary allocations when width is specified [PR109162]

2025-04-25 Thread Tomasz Kaminski via Libstdc++-cvs
https://gcc.gnu.org/g:01e5ef3e8b91288f5d387a27708f9f8979a50edf

commit r16-142-g01e5ef3e8b91288f5d387a27708f9f8979a50edf
Author: Tomasz Kamiński 
Date:   Wed Apr 23 13:17:09 2025 +0200

libstdc++: Minimalize temporary allocations when width is specified 
[PR109162]

When width parameter is specified for formatting range, tuple or escaped
presentation of string, we used to format characters to temporary string,
and write produce sequence padded according to the spec. However, once the
estimated width of formatted representation of input is larger than the 
value
of spec width, it can be written directly to the output. This limits size of
required allocation, especially for large ranges.

Similarly, if precision (maximum) width is provided for string presentation,
only a prefix of sequence with estimated width not greater than precision, 
needs
to be buffered.

To realize above, this commit implements a new _Padding_sink specialization.
This sink holds an output iterator, a value of padding width, (optionally)
maximum width and a string buffer inherited from _Str_sink.
Then any incoming characters are treated in one of following ways, 
depending of
estimated width W of written sequence:
* written to string if W is smaller than padding width and maximum width 
(if present)
* ignored, if W is greater than maximum width
* written to output iterator, if W is greater than padding width

The padding sink is used instead of _Str_sink in __format::__format_padded,
__formatter_str::_M_format_escaped functions.

Furthermore __formatter_str::_M_format implementation was reworked, to:
* reduce number of instantiations by delegating to _Rg& and const _Rg& 
overloads,
* non-debug presentation is written to _Out directly or via _Padding_sink
* if maximum width is specified for debug format with non-unicode encoding,
  string size is limited to that number.

PR libstdc++/109162

libstdc++-v3/ChangeLog:

* include/bits/formatfwd.h (__simply_formattable_range): Moved from
std/format.
* include/std/format (__formatter_str::_format): Extracted escaped
string handling to separate method...
(__formatter_str::_M_format_escaped): Use __Padding_sink.
(__formatter_str::_M_format): Adjusted implementation.
(__formatter_str::_S_trunc): Extracted as namespace function...
(__format::_truncate): Extracted from __formatter_str::_S_trunc.
(__format::_Seq_sink): Removed forward declarations, made members
protected and non-final.
(_Seq_sink::_M_trim): Define.
(_Seq_sink::_M_span): Renamed from view.
(_Seq_sink::view): Returns string_view instead of span.
(__format::_Str_sink): Moved after _Seq_sink.
(__format::__format_padded): Use _Padding_sink.
* testsuite/std/format/debug.cc: Add timeout and new tests.
* testsuite/std/format/ranges/sequence.cc: Specify unicode as
encoding and new tests.
* testsuite/std/format/ranges/string.cc: Likewise.
* testsuite/std/format/tuple.cc: Likewise.

Reviewed-by: Jonathan Wakely 
Signed-off-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/include/bits/formatfwd.h  |   8 +
 libstdc++-v3/include/std/format| 399 +++--
 libstdc++-v3/testsuite/std/format/debug.cc | 388 +++-
 .../testsuite/std/format/ranges/sequence.cc| 116 ++
 libstdc++-v3/testsuite/std/format/ranges/string.cc |  63 
 libstdc++-v3/testsuite/std/format/tuple.cc |  93 +
 6 files changed, 961 insertions(+), 106 deletions(-)

diff --git a/libstdc++-v3/include/bits/formatfwd.h 
b/libstdc++-v3/include/bits/formatfwd.h
index 12ae2ad2ac08..3fa01ad1eab7 100644
--- a/libstdc++-v3/include/bits/formatfwd.h
+++ b/libstdc++-v3/include/bits/formatfwd.h
@@ -145,6 +145,14 @@ namespace __format
   = ranges::input_range
  && formattable, _CharT>;
 
+  // _Rg& and const _Rg& are both formattable and use same formatter
+  // specialization for their references.
+  template
+concept __simply_formattable_range
+  = __const_formattable_range<_Rg, _CharT>
+ && same_as>,
+remove_cvref_t>>;
+
   template
 using __maybe_const_range
   = __conditional_t<__const_formattable_range<_Rg, _CharT>, const _Rg, 
_Rg>;
diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 86c93f0e6ebd..69d8d189db62 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -56,7 +56,7 @@
 #include   // input_range, range_reference_t
 #include   // subrange
 #include  // ranges::copy
-#include  // back_insert_iterator
+#include  // back_insert_iterator, counted_iterator
 #include  // __is_pair
 #incl

[gcc r16-141] libstdc++: Replace leftover std::queue with Adaptor in ranges/adaptors.cc.

2025-04-25 Thread Tomasz Kaminski via Gcc-cvs
https://gcc.gnu.org/g:b115ae245a6afbe86756be9056c4365cd0811b88

commit r16-141-gb115ae245a6afbe86756be9056c4365cd0811b88
Author: Tomasz Kamiński 
Date:   Fri Apr 25 14:55:30 2025 +0200

libstdc++: Replace leftover std::queue with Adaptor in ranges/adaptors.cc.

This was leftover from  work-in-progress state, where only std::queue was
tested.

libstdc++-v3/ChangeLog:

* testsuite/std/format/ranges/adaptors.cc: Updated test.

Diff:
---
 libstdc++-v3/testsuite/std/format/ranges/adaptors.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/std/format/ranges/adaptors.cc 
b/libstdc++-v3/testsuite/std/format/ranges/adaptors.cc
index 854c7eef5bdd..daa73aa39bfb 100644
--- a/libstdc++-v3/testsuite/std/format/ranges/adaptors.cc
+++ b/libstdc++-v3/testsuite/std/format/ranges/adaptors.cc
@@ -88,7 +88,7 @@ test_output()
   VERIFY( res == WIDEN("==[0x03, 0x02, 0x01]===") );
 
   // Sequence output is always used
-  std::queue<_CharT, std::basic_string<_CharT>> qs(
+  Adaptor<_CharT, std::basic_string<_CharT>> qs(
 std::from_range,
 std::basic_string_view<_CharT>(WIDEN("321")));


[gcc r16-145] icf: Remove nop code from sem_function::init.

2025-04-25 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:ad2da347ae41ce8f328fce7fb3a2355fdd9abe4b

commit r16-145-gad2da347ae41ce8f328fce7fb3a2355fdd9abe4b
Author: Andrew Pinski 
Date:   Mon Mar 24 22:27:30 2025 -0700

icf: Remove nop code from sem_function::init.

Here we had:
  node = node;
Which does nothing so let's remove it.

gcc/ChangeLog:

* ipa-icf.cc (sem_function::init): Remove assignment of node from 
itself.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/ipa-icf.cc | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/ipa-icf.cc b/gcc/ipa-icf.cc
index 3fccc620a82f..c273032cae2d 100644
--- a/gcc/ipa-icf.cc
+++ b/gcc/ipa-icf.cc
@@ -1367,7 +1367,6 @@ sem_function::init (ipa_icf_gimple::func_checker *checker)
   gcc_assert (SSANAMES (func));
 
   ssa_names_size = SSANAMES (func)->length ();
-  node = node;
 
   decl = fndecl;
   region_tree = func->eh->region_tree;


[gcc r16-146] icf: Remove unused constructors of sem_function and sem_variable

2025-04-25 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:b1109c22d78002f9ed4ef30fb275d7beb7554199

commit r16-146-gb1109c22d78002f9ed4ef30fb275d7beb7554199
Author: Andrew Pinski 
Date:   Mon Mar 24 22:32:54 2025 -0700

icf: Remove unused constructors of sem_function and sem_variable

The constructors for sem_function and sem_variable that just
passes the bitmap obstack and NOT the cgraph node was unused
so let's remove it.

gcc/ChangeLog:

* ipa-icf.cc (sem_function::sem_function): Remove
the obstack argument version one.
(sem_variable::sem_variable): Likewise.
* ipa-icf.h (sem_function): Remove ctor for
obstack argument only one.
(sem_variable): Likewise.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/ipa-icf.cc | 14 --
 gcc/ipa-icf.h  |  5 -
 2 files changed, 19 deletions(-)

diff --git a/gcc/ipa-icf.cc b/gcc/ipa-icf.cc
index c273032cae2d..b354fb1e704c 100644
--- a/gcc/ipa-icf.cc
+++ b/gcc/ipa-icf.cc
@@ -233,16 +233,6 @@ void sem_item::set_hash (hashval_t hash)
 
 hash_map sem_item::m_type_hash_cache;
 
-/* Semantic function constructor that uses STACK as bitmap memory stack.  */
-
-sem_function::sem_function (bitmap_obstack *stack)
-  : sem_item (FUNC, stack), memory_access_types (), m_alias_sets_hash (0),
-m_checker (NULL), m_compared_func (NULL)
-{
-  bb_sizes.create (0);
-  bb_sorted.create (0);
-}
-
 sem_function::sem_function (cgraph_node *node, bitmap_obstack *stack)
   : sem_item (FUNC, node, stack), memory_access_types (),
 m_alias_sets_hash (0), m_checker (NULL), m_compared_func (NULL)
@@ -1646,10 +1636,6 @@ sem_function::bb_dict_test (vec *bb_dict, int 
source, int target)
 return (*bb_dict)[source] == target;
 }
 
-sem_variable::sem_variable (bitmap_obstack *stack): sem_item (VAR, stack)
-{
-}
-
 sem_variable::sem_variable (varpool_node *node, bitmap_obstack *stack)
 : sem_item (VAR, node, stack)
 {
diff --git a/gcc/ipa-icf.h b/gcc/ipa-icf.h
index c2854ed44960..4c9094c19506 100644
--- a/gcc/ipa-icf.h
+++ b/gcc/ipa-icf.h
@@ -308,8 +308,6 @@ private:
 class sem_function: public sem_item
 {
 public:
-  /* Semantic function constructor that uses STACK as bitmap memory stack.  */
-  sem_function (bitmap_obstack *stack);
 
   /*  Constructor based on callgraph node _NODE.
   Bitmap STACK is used for memory allocation.  */
@@ -419,9 +417,6 @@ private:
 class sem_variable: public sem_item
 {
 public:
-  /* Semantic variable constructor that uses STACK as bitmap memory stack.  */
-  sem_variable (bitmap_obstack *stack);
-
   /*  Constructor based on callgraph node _NODE.
   Bitmap STACK is used for memory allocation.  */


[gcc r16-144] phiopt: Remove calls.h include [PR119811]

2025-04-25 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:c565e0d3c4ad7c58697f3661269483ce6067e313

commit r16-144-gc565e0d3c4ad7c58697f3661269483ce6067e313
Author: Andrew Pinski 
Date:   Fri Apr 18 17:10:12 2025 -0700

phiopt: Remove calls.h include [PR119811]

When the patch, 
https://gcc.gnu.org/pipermail/gcc-patches/2024-August/660807.html was rewroked 
into r15-3047-g404d947d8ddd3c,
the include for calls.h was still included and missed that it was no longer 
needed.

Pushed as obvious.

PR tree-optimization/119811
gcc/ChangeLog:

* tree-ssa-phiopt.cc: Remove calls.h include.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/tree-ssa-phiopt.cc | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index a194bf675e4e..e27166c55a5b 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -54,7 +54,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "dbgcnt.h"
 #include "tree-ssa-propagate.h"
 #include "tree-ssa-dce.h"
-#include "calls.h"
 #include "tree-ssa-loop-niter.h"
 
 /* Return the singleton PHI in the SEQ of PHIs for edges E0 and E1. */


[gcc r16-147] libstdc++: Rename std::latch data member

2025-04-25 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:79ad792bf04dfa1109d1afdae93cee9fb457439b

commit r16-147-g79ad792bf04dfa1109d1afdae93cee9fb457439b
Author: Jonathan Wakely 
Date:   Thu Jan 30 12:07:48 2025 +

libstdc++: Rename std::latch data member

Rename _M_a to match the name of the exposition-only data member shown
in the standard, i.e. 'counter'.

libstdc++-v3/ChangeLog:

* include/std/latch (latch::_M_a): Rename to _M_counter.

Reviewed-by: Tomasz Kamiński 

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

diff --git a/libstdc++-v3/include/std/latch b/libstdc++-v3/include/std/latch
index cf648545629d..dc147c24bbe2 100644
--- a/libstdc++-v3/include/std/latch
+++ b/libstdc++-v3/include/std/latch
@@ -62,7 +62,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 constexpr explicit
 latch(ptrdiff_t __expected) noexcept
-: _M_a(__expected)
+: _M_counter(__expected)
 { __glibcxx_assert(__expected >= 0 && __expected <= max()); }
 
 ~latch() = default;
@@ -74,23 +74,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 count_down(ptrdiff_t __update = 1)
 {
   __glibcxx_assert(__update >= 0 && __update <= max());
-  auto const __old = __atomic_impl::fetch_sub(&_M_a, __update,
+  auto const __old = __atomic_impl::fetch_sub(&_M_counter, __update,
  memory_order::release);
   if (std::cmp_equal(__old, __update))
-   __atomic_impl::notify_all(&_M_a);
+   __atomic_impl::notify_all(&_M_counter);
   else
__glibcxx_assert(std::cmp_less(__update, __old));
 }
 
 _GLIBCXX_ALWAYS_INLINE bool
 try_wait() const noexcept
-{ return __atomic_impl::load(&_M_a, memory_order::acquire) == 0; }
+{ return __atomic_impl::load(&_M_counter, memory_order::acquire) == 0; }
 
 _GLIBCXX_ALWAYS_INLINE void
 wait() const noexcept
 {
   auto const __pred = [this] { return this->try_wait(); };
-  std::__atomic_wait_address(&_M_a, __pred);
+  std::__atomic_wait_address(&_M_counter, __pred);
 }
 
 _GLIBCXX_ALWAYS_INLINE void
@@ -102,7 +102,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   private:
 alignas(__detail::__platform_wait_alignment)
-  __detail::__platform_wait_t _M_a;
+  __detail::__platform_wait_t _M_counter;
   };
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace


[gcc r16-125] Update gennews for GCC 15.

2025-04-25 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:865d0f23d2ba08b3b6df6066e7dc5e807a14f5fa

commit r16-125-g865d0f23d2ba08b3b6df6066e7dc5e807a14f5fa
Author: Jakub Jelinek 
Date:   Fri Apr 25 09:53:35 2025 +0200

Update gennews for GCC 15.

2025-04-25  Jakub Jelinek  

* gennews (files): Add files for GCC 15.

Diff:
---
 contrib/gennews | 1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/gennews b/contrib/gennews
index bb5ac92b8a84..6eab091f30ed 100755
--- a/contrib/gennews
+++ b/contrib/gennews
@@ -23,6 +23,7 @@
 
 website=http://gcc.gnu.org/
 files="
+gcc-15/index.html gcc-15/changes.html
 gcc-14/index.html gcc-14/changes.html
 gcc-13/index.html gcc-13/changes.html
 gcc-12/index.html gcc-12/changes.html


[gcc r15-9582] Update gennews for GCC 15.

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

commit r15-9582-gfbc59a9ba1be0da9879b3747ad727ab240de65b4
Author: Jakub Jelinek 
Date:   Fri Apr 25 09:53:35 2025 +0200

Update gennews for GCC 15.

2025-04-25  Jakub Jelinek  

* gennews (files): Add files for GCC 15.

(cherry picked from commit 865d0f23d2ba08b3b6df6066e7dc5e807a14f5fa)

Diff:
---
 contrib/gennews | 1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/gennews b/contrib/gennews
index bb5ac92b8a84..6eab091f30ed 100755
--- a/contrib/gennews
+++ b/contrib/gennews
@@ -23,6 +23,7 @@
 
 website=http://gcc.gnu.org/
 files="
+gcc-15/index.html gcc-15/changes.html
 gcc-14/index.html gcc-14/changes.html
 gcc-13/index.html gcc-13/changes.html
 gcc-12/index.html gcc-12/changes.html


[gcc r16-126] Adjust gcc_release for id href web transformations

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

commit r16-126-gfef3a3c8b5d35c7a8eeae67f95a264a90120dd29
Author: Jakub Jelinek 
Date:   Fri Apr 25 10:23:15 2025 +0200

Adjust gcc_release for id href web transformations

We now have some script which transforms e.g.
GCC 15.1
line in gcc-15/changes.html to
GCC 15.1

This unfortunately breaks the gcc_release script, which looks for
GCC 15.1 appearing in gennews after optional blanks from the start of
the line in the NEWS file, which is no longer the case, there is
[129]GCC 15.1
or something like that with an URL later on
 129. https://gcc.gnu.org/gcc-15/changes.html#15.1

The following patch handles this.

2025-04-25  Jakub Jelinek  

* gcc_release: Allow optional \[[0-9]+\] before GCC major.minor
in the NEWS file.

Diff:
---
 maintainer-scripts/gcc_release | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/maintainer-scripts/gcc_release b/maintainer-scripts/gcc_release
index 2ead4a754647..c7af3fdcb31e 100755
--- a/maintainer-scripts/gcc_release
+++ b/maintainer-scripts/gcc_release
@@ -141,7 +141,7 @@ build_sources() {
 "in gcc-${RELEASE_MAJOR}/index.html"
 
 sed -n -e "/^${thischanges}/,/^${previndex}/p" NEWS |\
-  grep -q "^[[:blank:]]*GCC ${RELEASE_MAJOR}.${RELEASE_MINOR}" ||\
+  grep -q "^[[:blank:]]*\(\[[0-9]\{1,\}\][[:blank:]]*\)\{0,1\}GCC 
${RELEASE_MAJOR}.${RELEASE_MINOR}" ||\
   error "GCC ${RELEASE_MAJOR}.${RELEASE_MINOR} not mentioned "\
 "in gcc-${RELEASE_MAJOR}/changes.html"


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression coarray_critical_1

2025-04-25 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:b8e75f1426a057c3b47ef2d7cb4fed5f3249159f

commit b8e75f1426a057c3b47ef2d7cb4fed5f3249159f
Author: Mikael Morin 
Date:   Fri Apr 25 10:30:53 2025 +0200

Correction régression coarray_critical_1

Diff:
---
 gcc/fortran/trans-decl.cc | 8 
 1 file changed, 8 deletions(-)

diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 326c687bf4fd..067a33c2994f 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -1258,14 +1258,6 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym)
   suppress_warning (GFC_TYPE_ARRAY_SIZE (type));
 }
 
-  if (POINTER_TYPE_P (type))
-{
-  gcc_assert (GFC_ARRAY_TYPE_P (TREE_TYPE (type)));
-  gcc_assert (TYPE_LANG_SPECIFIC (type)
- == TYPE_LANG_SPECIFIC (TREE_TYPE (type)));
-  type = TREE_TYPE (type);
-}
-
   if (! COMPLETE_TYPE_P (type) && GFC_TYPE_ARRAY_SIZE (type))
 {
   tree size, range;


[gcc r15-9584] Bump BASE-VER

2025-04-25 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:2434f8b1fbe842ac5a1bd36fade4da89cc01

commit r15-9584-g2434f8b1fbe842ac5a1bd36fade4da89cc01
Author: Jakub Jelinek 
Date:   Fri Apr 25 11:14:05 2025 +0200

Bump BASE-VER

2025-04-25  Jakub Jelinek  

* BASE-VER: Set to 15.1.1.

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

diff --git a/gcc/BASE-VER b/gcc/BASE-VER
index d14dfbac3692..68a28303f2b0 100644
--- a/gcc/BASE-VER
+++ b/gcc/BASE-VER
@@ -1 +1 @@
-15.1.0
+15.1.1


[gcc r15-9585] Adjust gcc_release for id href web transformations

2025-04-25 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:1fde851e9a4e124cb6818a2b9fe9ab6b9a6bab9b

commit r15-9585-g1fde851e9a4e124cb6818a2b9fe9ab6b9a6bab9b
Author: Jakub Jelinek 
Date:   Fri Apr 25 10:23:15 2025 +0200

Adjust gcc_release for id href web transformations

We now have some script which transforms e.g.
GCC 15.1
line in gcc-15/changes.html to
GCC 15.1

This unfortunately breaks the gcc_release script, which looks for
GCC 15.1 appearing in gennews after optional blanks from the start of
the line in the NEWS file, which is no longer the case, there is
[129]GCC 15.1
or something like that with an URL later on
 129. https://gcc.gnu.org/gcc-15/changes.html#15.1

The following patch handles this.

2025-04-25  Jakub Jelinek  

* gcc_release: Allow optional \[[0-9]+\] before GCC major.minor
in the NEWS file.

(cherry picked from commit fef3a3c8b5d35c7a8eeae67f95a264a90120dd29)

Diff:
---
 maintainer-scripts/gcc_release | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/maintainer-scripts/gcc_release b/maintainer-scripts/gcc_release
index 2ead4a754647..c7af3fdcb31e 100755
--- a/maintainer-scripts/gcc_release
+++ b/maintainer-scripts/gcc_release
@@ -141,7 +141,7 @@ build_sources() {
 "in gcc-${RELEASE_MAJOR}/index.html"
 
 sed -n -e "/^${thischanges}/,/^${previndex}/p" NEWS |\
-  grep -q "^[[:blank:]]*GCC ${RELEASE_MAJOR}.${RELEASE_MINOR}" ||\
+  grep -q "^[[:blank:]]*\(\[[0-9]\{1,\}\][[:blank:]]*\)\{0,1\}GCC 
${RELEASE_MAJOR}.${RELEASE_MINOR}" ||\
   error "GCC ${RELEASE_MAJOR}.${RELEASE_MINOR} not mentioned "\
 "in gcc-${RELEASE_MAJOR}/changes.html"


[gcc r16-150] Fortran: fix procedure pointer handling with -fcheck=pointer [PR102900]

2025-04-25 Thread Harald Anlauf via Gcc-cvs
https://gcc.gnu.org/g:cc8d86ee4680d56eefeb76a8f2f752282e2631e3

commit r16-150-gcc8d86ee4680d56eefeb76a8f2f752282e2631e3
Author: Harald Anlauf 
Date:   Thu Apr 24 21:28:35 2025 +0200

Fortran: fix procedure pointer handling with -fcheck=pointer [PR102900]

PR fortran/102900

gcc/fortran/ChangeLog:

* trans-decl.cc (gfc_generate_function_code): Use sym->result
when generating fake result decl for functions returning
allocatable or pointer results.
* trans-expr.cc (gfc_conv_procedure_call): When checking the
pointer status of an actual argument passed to a non-allocatable,
non-pointer dummy which is of type CLASS, do not check the
class container of the actual if it is just a procedure pointer.
(gfc_trans_pointer_assignment): Fix treatment of assignment to
NULL of a procedure pointer.

gcc/testsuite/ChangeLog:

* gfortran.dg/proc_ptr_52.f90: Add -fcheck=pointer to options.
* gfortran.dg/proc_ptr_57.f90: New test.

Diff:
---
 gcc/fortran/trans-decl.cc |  6 +++---
 gcc/fortran/trans-expr.cc | 10 +
 gcc/testsuite/gfortran.dg/proc_ptr_52.f90 |  1 +
 gcc/testsuite/gfortran.dg/proc_ptr_57.f90 | 36 +++
 4 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index ee48a820f285..43bd7be54cb7 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -8079,13 +8079,13 @@ gfc_generate_function_code (gfc_namespace * ns)
   || sym->result->ts.u.derived->attr.alloc_comp
   || sym->result->ts.u.derived->attr.pointer_comp))
  || (sym->result->ts.type == BT_CLASS
- && (CLASS_DATA (sym)->attr.allocatable
- || CLASS_DATA (sym)->attr.class_pointer
+ && (CLASS_DATA (sym->result)->attr.allocatable
+ || CLASS_DATA (sym->result)->attr.class_pointer
  || CLASS_DATA (sym->result)->attr.alloc_comp
  || CLASS_DATA (sym->result)->attr.pointer_comp
{
  artificial_result_decl = true;
- result = gfc_get_fake_result_decl (sym, 0);
+ result = gfc_get_fake_result_decl (sym->result, 0);
}
 
   if (result != NULL_TREE && sym->attr.function && !sym->attr.pointer)
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 19e5669b9ee9..8d9448eb9b6d 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -8145,7 +8145,7 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
goto end_pointer_check;
 
  tmp = parmse.expr;
- if (fsym && fsym->ts.type == BT_CLASS)
+ if (fsym && fsym->ts.type == BT_CLASS && !attr.proc_pointer)
{
  if (POINTER_TYPE_P (TREE_TYPE (tmp)))
tmp = build_fold_indirect_ref_loc (input_location, tmp);
@@ -10912,9 +10912,11 @@ gfc_trans_pointer_assignment (gfc_expr * expr1, 
gfc_expr * expr2)
   gfc_init_se (&lse, NULL);
 
   /* Usually testing whether this is not a proc pointer assignment.  */
-  non_proc_ptr_assign = !(gfc_expr_attr (expr1).proc_pointer
-   && expr2->expr_type == EXPR_VARIABLE
-   && expr2->symtree->n.sym->attr.flavor == FL_PROCEDURE);
+  non_proc_ptr_assign
+= !(gfc_expr_attr (expr1).proc_pointer
+   && ((expr2->expr_type == EXPR_VARIABLE
+&& expr2->symtree->n.sym->attr.flavor == FL_PROCEDURE)
+   || expr2->expr_type == EXPR_NULL));
 
   /* Check whether the expression is a scalar or not; we cannot use
  expr1->rank as it can be nonzero for proc pointers.  */
diff --git a/gcc/testsuite/gfortran.dg/proc_ptr_52.f90 
b/gcc/testsuite/gfortran.dg/proc_ptr_52.f90
index cb7cf7040a9d..421d2479cd67 100644
--- a/gcc/testsuite/gfortran.dg/proc_ptr_52.f90
+++ b/gcc/testsuite/gfortran.dg/proc_ptr_52.f90
@@ -1,4 +1,5 @@
 ! { dg-do run }
+! { dg-additional-options "-fcheck=pointer" }
 !
 ! Test the fix for PRs93924 & 93925.
 !
diff --git a/gcc/testsuite/gfortran.dg/proc_ptr_57.f90 
b/gcc/testsuite/gfortran.dg/proc_ptr_57.f90
new file mode 100644
index ..7ecb88f172cb
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/proc_ptr_57.f90
@@ -0,0 +1,36 @@
+! { dg-do compile }
+! { dg-additional-options "-fcheck=pointer" }
+!
+! PR fortran/102900
+
+module cs
+  implicit none
+  interface
+ function classStar_map_ifc() result(y)
+   import
+   class(*), pointer :: y
+ end function classStar_map_ifc
+  end interface
+
+contains
+
+   function selector()
+ procedure(classStar_map_ifc), pointer :: selector
+ selector => NULL()
+   end function selector
+
+   function selector_result() result(f)
+ procedure(classStar_map_ifc), pointer :: f
+ f => NULL()
+   end function selec

[gcc/devel/omp/gcc-14] OpenMP: Constructors and destructors for "declare target" static aggregates

2025-04-25 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:0367df9d4fc07c95f08a6a499f36c96851cbe832

commit 0367df9d4fc07c95f08a6a499f36c96851cbe832
Author: Tobias Burnus 
Date:   Wed Aug 7 19:31:19 2024 +0200

OpenMP: Constructors and destructors for "declare target" static aggregates

This commit also compile-time expands (__builtin_)omp_is_initial_device for
both Fortran and C/C++ (unless, -fno-builtin-omp_is_initial_device is used).
But the main change is:

This commit adds support for running constructors and destructors for
static (file-scope) aggregates for C++ objects which are marked with
"declare target" directives on OpenMP offload targets.

Before this commit, space is allocated on the target for such aggregates,
but nothing ever constructs them properly, so they end up zero-initialised.

(See the new test static-aggr-constructor-destructor-3.C for a reason
why running constructors on the target is preferable to e.g. constructing
on the host and then copying the resulting object to the target.)

2024-08-07  Julian Brown  
Tobias Burnus  

gcc/ChangeLog:

* builtins.def (DEF_GOMP_BUILTIN_COMPILER): Define
DEF_GOMP_BUILTIN_COMPILER to handle the non-prefix version.
* gimple-fold.cc (gimple_fold_builtin_omp_is_initial_device): New.
(gimple_fold_builtin): Call it.
* omp-builtins.def (BUILT_IN_OMP_IS_INITIAL_DEVICE): Define.
* tree.cc (get_file_function_name): Support names for on-target
constructor/destructor functions.

gcc/cp/
* decl2.cc (tree-inline.h): Include.
(static_init_fini_fns): Bump to four entries. Update comment.
(start_objects, start_partial_init_fini_fn): Add 'omp_target'
parameter. Support "declare target" decls. Update forward 
declaration.
(emit_partial_init_fini_fn): Add 'host_fn' parameter. Return tree 
for
the created function. Support "declare target".
(OMP_SSDF_IDENTIFIER): New macro.
(partition_vars_for_init_fini): Support partitioning "declare 
target"
variables also.
(generate_ctor_or_dtor_function): Add 'omp_target' parameter. 
Support
"declare target" decls.
(c_parse_final_cleanups): Support constructors/destructors on OpenMP
offload targets.

gcc/fortran/ChangeLog:

* gfortran.h (gfc_option_t): Add disable_omp_is_initial_device.
* lang.opt (fbuiltin-): Add.
* options.cc (gfc_handle_option): Handle
-fno-builtin-omp_is_initial_device.
* f95-lang.cc (gfc_init_builtin_functions): Handle
DEF_GOMP_BUILTIN_COMPILER.
* trans-decl.cc (gfc_get_extern_function_decl): Add code to use
DEF_GOMP_BUILTIN_COMPILER for 'omp_is_initial_device'.

libgomp/ChangeLog:

* testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C: New 
test.
* testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C: New 
test.
* testsuite/libgomp.c++/static-aggr-constructor-destructor-3.C: New 
test.
* testsuite/libgomp.c-c++-common/target-is-initial-host.c: New test.
* testsuite/libgomp.c-c++-common/target-is-initial-host-2.c: New 
test.
* testsuite/libgomp.fortran/target-is-initial-host.f: New test.
* testsuite/libgomp.fortran/target-is-initial-host.f90: New test.
* testsuite/libgomp.fortran/target-is-initial-host-2.f90: New test.

Co-authored-by: Tobias Burnus 
(cherry picked from commit f1bfba3a9b3f31e3e06bfd1911c9f223869ea03f)

Diff:
---
 gcc/ChangeLog.omp  |  12 ++
 gcc/builtins.def   |   4 +
 gcc/cp/ChangeLog.omp   |  18 ++
 gcc/cp/decl2.cc| 229 +
 gcc/fortran/ChangeLog.omp  |  15 ++
 gcc/fortran/f95-lang.cc|   9 +
 gcc/fortran/gfortran.h |   1 +
 gcc/fortran/lang.opt   |   4 +
 gcc/fortran/options.cc |  12 ++
 gcc/fortran/trans-decl.cc  |   9 +
 gcc/gimple-fold.cc |  20 ++
 gcc/omp-builtins.def   |   4 +
 gcc/tree.cc|   6 +-
 libgomp/ChangeLog.omp  |  13 ++
 .../static-aggr-constructor-destructor-1.C |  72 +++
 .../static-aggr-constructor-destructor-2.C |  50 +
 .../static-aggr-constructor-destructor-3.C |  36 
 .../target-is-initial-host-2.c |  43 
 .../libgomp.c-c++-common/target-is-initial-host.c  |  42 
 .../libgomp.fortran/target-is-initial-host-2.f90   |  37 
 .../li

[gcc/devel/omp/gcc-14] GCN, nvptx offloading: Host/device compatibility: Itanium C++ ABI, DSO Object Destruction API [PR119

2025-04-25 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:591d91c2b74c44dbb382fd5d89c0f4ae6f5f7238

commit 591d91c2b74c44dbb382fd5d89c0f4ae6f5f7238
Author: Thomas Schwinge 
Date:   Wed Apr 23 10:51:48 2025 +0200

GCN, nvptx offloading: Host/device compatibility: Itanium C++ ABI, DSO 
Object Destruction API [PR119853, PR119854]

'__dso_handle' for '__cxa_atexit', '__cxa_finalize'.  See
.

PR target/119853
PR target/119854
libgcc/
* config/gcn/crt0.c (_fini_array): Call
'__GCC_offload___cxa_finalize'.
* config/nvptx/gbl-ctors.c (__static_do_global_dtors): Likewise.
libgomp/
* target-cxa-dso-dtor.c: New.
* config/accel/target-cxa-dso-dtor.c: Likewise.
* Makefile.am (libgomp_la_SOURCES): Add it.
* Makefile.in: Regenerate.
* testsuite/libgomp.c++/target-cdtor-1.C: New.
* testsuite/libgomp.c++/target-cdtor-2.C: Likewise.

(cherry picked from commit aafe942227baf8c2bcd4cac2cb150e49a4b895a9)

Diff:
---
 libgcc/ChangeLog.omp   |  11 ++
 libgcc/config/gcn/crt0.c   |  32 ++
 libgcc/config/nvptx/gbl-ctors.c|  16 +++
 libgomp/ChangeLog.omp  |  12 +++
 libgomp/Makefile.am|   2 +-
 libgomp/Makefile.in|   9 +-
 libgomp/config/accel/target-cxa-dso-dtor.c |  62 +++
 libgomp/target-cxa-dso-dtor.c  |   3 +
 libgomp/testsuite/libgomp.c++/target-cdtor-1.C | 104 ++
 libgomp/testsuite/libgomp.c++/target-cdtor-2.C | 140 +
 10 files changed, 386 insertions(+), 5 deletions(-)

diff --git a/libgcc/ChangeLog.omp b/libgcc/ChangeLog.omp
index 86f6e57e762b..1e23c08b2097 100644
--- a/libgcc/ChangeLog.omp
+++ b/libgcc/ChangeLog.omp
@@ -1,3 +1,14 @@
+2025-04-25  Thomas Schwinge  
+
+   Backported from trunk:
+   2025-04-25  Thomas Schwinge  
+
+   PR target/119853
+   PR target/119854
+   * config/gcn/crt0.c (_fini_array): Call
+   '__GCC_offload___cxa_finalize'.
+   * config/nvptx/gbl-ctors.c (__static_do_global_dtors): Likewise.
+
 2025-04-17  Thomas Schwinge  
 
Backported from trunk:
diff --git a/libgcc/config/gcn/crt0.c b/libgcc/config/gcn/crt0.c
index 99460529b614..d20152ec5f16 100644
--- a/libgcc/config/gcn/crt0.c
+++ b/libgcc/config/gcn/crt0.c
@@ -24,6 +24,28 @@ typedef long long size_t;
 /* Provide an entry point symbol to silence a linker warning.  */
 void _start() {}
 
+
+#define PR119369_fixed 0
+
+
+/* Host/device compatibility: '__cxa_finalize'.  Dummy; if necessary,
+   overridden via libgomp 'target-cxa-dso-dtor.c'.  */
+
+#if PR119369_fixed
+extern void __GCC_offload___cxa_finalize (void *) __attribute__((weak));
+#else
+void __GCC_offload___cxa_finalize (void *) __attribute__((weak));
+
+void __attribute__((weak))
+__GCC_offload___cxa_finalize (void *dso_handle __attribute__((unused)))
+{
+}
+#endif
+
+/* There are no DSOs; this is the main program.  */
+static void * const __dso_handle = 0;
+
+
 #ifdef USE_NEWLIB_INITFINI
 
 extern void __libc_init_array (void) __attribute__((weak));
@@ -38,6 +60,11 @@ void _init_array()
 __attribute__((amdgpu_hsa_kernel ()))
 void _fini_array()
 {
+#if PR119369_fixed
+  if (__GCC_offload___cxa_finalize)
+#endif
+__GCC_offload___cxa_finalize (__dso_handle);
+
   __libc_fini_array ();
 }
 
@@ -70,6 +97,11 @@ void _init_array()
 __attribute__((amdgpu_hsa_kernel ()))
 void _fini_array()
 {
+#if PR119369_fixed
+  if (__GCC_offload___cxa_finalize)
+#endif
+__GCC_offload___cxa_finalize (__dso_handle);
+
   size_t count;
   size_t i;
 
diff --git a/libgcc/config/nvptx/gbl-ctors.c b/libgcc/config/nvptx/gbl-ctors.c
index a56d64f8ef82..f29998001ef4 100644
--- a/libgcc/config/nvptx/gbl-ctors.c
+++ b/libgcc/config/nvptx/gbl-ctors.c
@@ -31,6 +31,20 @@
 extern int atexit (void (*function) (void));
 
 
+/* Host/device compatibility: '__cxa_finalize'.  Dummy; if necessary,
+   overridden via libgomp 'target-cxa-dso-dtor.c'.  */
+
+extern void __GCC_offload___cxa_finalize (void *);
+
+void __attribute__((weak))
+__GCC_offload___cxa_finalize (void *dso_handle __attribute__((unused)))
+{
+}
+
+/* There are no DSOs; this is the main program.  */
+static void * const __dso_handle = 0;
+
+
 /* Handler functions ('static', in contrast to the 'gbl-ctors.h'
prototypes).  */
 
@@ -49,6 +63,8 @@ static void __static_do_global_dtors (void);
 static void
 __static_do_global_dtors (void)
 {
+  __GCC_offload___cxa_finalize (__dso_handle);
+
   func_ptr *p = __DTOR_LIST__;
   ++p;
   for (; *p; ++p)
diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 1ddd03e9e70e..264a4d727a0e 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -3,6 +3,18 @@
Backported from trunk:
2025-04-25  Thomas Schwinge  
 
+   PR target/119

[gcc/devel/omp/gcc-14] openmp: Fix handling of declare target statics with array type which need destruction [PR118876]

2025-04-25 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:caacc841ee735e094e3e7c3b8b067a969006b4df

commit caacc841ee735e094e3e7c3b8b067a969006b4df
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.

(cherry picked from commit 86a4af2793393e47af6b78cb7094c97914890091)

Diff:
---
 gcc/cp/ChangeLog.omp | 18 ++
 gcc/cp/cp-tree.h |  2 +-
 gcc/cp/decl.cc   | 20 +++-
 gcc/cp/decl2.cc  | 12 +++-
 gcc/testsuite/ChangeLog.omp  |  8 
 gcc/testsuite/g++.dg/gomp/pr118876.C |  6 ++
 6 files changed, 55 insertions(+), 11 deletions(-)

diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index feb6eab350b3..659c56a282ad 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -1,5 +1,23 @@
 2025-04-25  Thomas Schwinge  
 
+   Backported from trunk:
+   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.
+
Backported from trunk:
2024-08-07  Julian Brown  
Tobias Burnus  
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 37f4ecb08296..386698cc40e1 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -7089,7 +7089,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 e3ed0d5c9a4d..b91c88805945 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -93,7 +93,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 (bool);
+static tree start_cleanup_fn (bool, bool);
 static void end_cleanup_fn (void);
 static tree cp_make_fname_decl (location_t, tree, int);
 static void initialize_predefined_identifiers (void);
@@ -10004,7 +10004,7 @@ get_dso_handle_node (void)
 static GTY(()) int start_cleanup_cnt;
 
 static tree
-start_cleanup_fn (bool ob_parm)
+start_cleanup_fn (bool ob_parm, bool omp_target)
 {
   char name[32];
 
@@ -10014,7 +10014,8 @@ start_cleanup_fn (bool ob_parm)
   push_lang_context (lang_name_c);
 
   /* Build the name of the function.  */
-  sprintf (name, "__tcf_%d", start_cleanup_cnt++);
+  sprintf (name, "%s_%d",
+  (omp_target ? "__omp_tcf" : "__tcf"), start_cleanup_cnt++);
   tree fntype = TREE_TYPE (ob_parm ? get_cxa_atexit_fn_ptr_type ()
  

[gcc/devel/omp/gcc-14] Adjust 'libgomp.c++/target-exceptions-pr118794-1.C' for 'targetm.arm_eabi_unwinder' [PR118794]

2025-04-25 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ff45d02ee9e05baeb6fa3b61b0b214762b49aac7

commit ff45d02ee9e05baeb6fa3b61b0b214762b49aac7
Author: Thomas Schwinge 
Date:   Tue Apr 22 13:41:22 2025 +0200

Adjust 'libgomp.c++/target-exceptions-pr118794-1.C' for 
'targetm.arm_eabi_unwinder' [PR118794]

Fix-up for commit aa3e72f943032e5f074b2bd2fd06d130dda8760b
"Add test cases for exception handling constructs in dead code for GCN, 
nvptx target and OpenMP 'target' offloading [PR118794]":
we need to adjust for configurations with 'targetm.arm_eabi_unwinder', as 
per:

gcc/config/arm/arm.cc:#define TARGET_ARM_EABI_UNWINDER true
gcc/config/c6x/c6x.cc:#define TARGET_ARM_EABI_UNWINDER true

..., which for ARM is conditional to '#if ARM_UNWIND_INFO' (defined in
'gcc/config/arm/bpabi.h', used for various GCC configurations), and for
C6x unconditional.

This gets us:

--- target-exceptions-pr118794-1.C.269t.optimized
+++ target-exceptions-pr118794-1.C.270t.optimized
[...]
 __attribute__((omp declare target))
 void f ()
[...]
   gimple_call <__dt_comp , NULL, &c>
-  gimple_call <__builtin_eh_pointer, _7, 2>
-  gimple_call <__builtin_unwind_resume, NULL, _7>
+  gimple_call <__builtin_cxa_end_cleanup, NULL>

 }
[...]

PR target/118794
libgomp/
* testsuite/libgomp.c++/target-exceptions-pr118794-1.C: Adjust for
'targetm.arm_eabi_unwinder'.
* 
testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C:
Likewise.
* 
testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-nvptx.C:
Likewise.

(cherry picked from commit 8a1f5424b04130f88e9dcd5cbecd58300bc5166e)

Diff:
---
 libgomp/ChangeLog.omp | 11 +++
 .../target-exceptions-pr118794-1-offload-sorry-GCN.C  |  6 --
 .../target-exceptions-pr118794-1-offload-sorry-nvptx.C|  6 --
 libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1.C  |  6 --
 4 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 94dcb8e1a36d..316aa05156c9 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,5 +1,16 @@
 2025-04-25  Thomas Schwinge  
 
+   Backported from trunk:
+   2025-04-25  Thomas Schwinge  
+
+   PR target/118794
+   * testsuite/libgomp.c++/target-exceptions-pr118794-1.C: Adjust for
+   'targetm.arm_eabi_unwinder'.
+   * 
testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C:
+   Likewise.
+   * 
testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-nvptx.C:
+   Likewise.
+
Backported from trunk:
2024-08-09  Thomas Schwinge  
 
diff --git 
a/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C
 
b/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C
index 3cdedf48529e..d4dccf167fbb 100644
--- 
a/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C
+++ 
b/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C
@@ -14,8 +14,10 @@
 
 /* In this specific C++ arrangement, distilled from PR118794, GCC synthesizes
'__builtin_eh_pointer', '__builtin_unwind_resume' calls as dead code in 'f':
-   { dg-final { scan-tree-dump-times {gimple_call <__builtin_eh_pointer, } 1 
optimized } }
-   { dg-final { scan-tree-dump-times {gimple_call <__builtin_unwind_resume, } 
1 optimized } }
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_eh_pointer, } 1 
optimized { target { ! { arm_eabi || tic6x-*-* } } } } }
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_unwind_resume, } 
1 optimized { target { ! { arm_eabi || tic6x-*-* } } } } }
+   ..., just 'targetm.arm_eabi_unwinder' is different:
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_cxa_end_cleanup, 
} 1 optimized { target { arm_eabi || tic6x-*-* } } } }
{ dg-final { only_for_offload_target amdgcn-amdhsa 
scan-offload-tree-dump-times {gimple_call <__builtin_eh_pointer, } 1 optimized 
} }
{ dg-final { only_for_offload_target amdgcn-amdhsa 
scan-offload-tree-dump-times {gimple_call <__builtin_unwind_resume, } 1 
optimized } }
Given '-O0' and '-foffload-options=-mno-fake-exceptions', offload 
compilation fails:
diff --git 
a/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-nvptx.C
 
b/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-nvptx.C
index ef996cfff7fa..724e34bd9234 100644
--- 
a/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-nvptx.C
+++ 
b/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-nvptx.C
@@ -14,8 +14,10 @@
 
 /* In this specific C++ arrangement, distilled from PR118794, GCC synthesizes
'__buil

[gcc/devel/omp/gcc-14] Add 'libgomp.c-c++-common/target-cdtor-1.c'

2025-04-25 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:efe9d34bd9a6a702f9142c1a875ebda1531b9b41

commit efe9d34bd9a6a702f9142c1a875ebda1531b9b41
Author: Thomas Schwinge 
Date:   Wed Apr 23 17:35:29 2025 +0200

Add 'libgomp.c-c++-common/target-cdtor-1.c'

libgomp/
* testsuite/libgomp.c-c++-common/target-cdtor-1.c: New.

(cherry picked from commit 40ce48e87c1e7344c622c8eb6bed53f1311f5a0a)

Diff:
---
 libgomp/ChangeLog.omp  |  5 ++
 .../libgomp.c-c++-common/target-cdtor-1.c  | 89 ++
 2 files changed, 94 insertions(+)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index cfa267e6d889..1ddd03e9e70e 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,5 +1,10 @@
 2025-04-25  Thomas Schwinge  
 
+   Backported from trunk:
+   2025-04-25  Thomas Schwinge  
+
+   * testsuite/libgomp.c-c++-common/target-cdtor-1.c: New.
+
Backported from trunk:
2025-04-25  Andrew Pinski  
Thomas Schwinge  
diff --git a/libgomp/testsuite/libgomp.c-c++-common/target-cdtor-1.c 
b/libgomp/testsuite/libgomp.c-c++-common/target-cdtor-1.c
new file mode 100644
index ..e6099cf23b88
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-c++-common/target-cdtor-1.c
@@ -0,0 +1,89 @@
+/* Offloaded 'constructor' and 'destructor' functions.  */
+
+#include 
+
+#pragma omp declare target
+
+static void
+__attribute__((constructor))
+initHD1()
+{
+  __builtin_printf("%s, %d\n", __FUNCTION__, omp_is_initial_device());
+}
+
+static void
+__attribute__((constructor))
+initHD2()
+{
+  __builtin_printf("%s, %d\n", __FUNCTION__, omp_is_initial_device());
+}
+
+static void
+__attribute__((destructor))
+finiHD1()
+{
+  __builtin_printf("%s, %d\n", __FUNCTION__, omp_is_initial_device());
+}
+
+static void
+__attribute__((destructor))
+finiHD2()
+{
+  __builtin_printf("%s, %d\n", __FUNCTION__, omp_is_initial_device());
+}
+
+#pragma omp end declare target
+
+static void
+__attribute__((constructor))
+initH1()
+{
+  __builtin_printf("%s, %d\n", __FUNCTION__, omp_is_initial_device());
+}
+
+static void
+__attribute__((destructor))
+finiH2()
+{
+  __builtin_printf("%s, %d\n", __FUNCTION__, omp_is_initial_device());
+}
+
+int main()
+{
+  int c = 0;
+
+  __builtin_printf("%s:%d, %d\n", __FUNCTION__, ++c, omp_is_initial_device());
+
+#pragma omp target map(c)
+  {
+__builtin_printf("%s:%d, %d\n", __FUNCTION__, ++c, 
omp_is_initial_device());
+  }
+
+#pragma omp target map(c)
+  {
+__builtin_printf("%s:%d, %d\n", __FUNCTION__, ++c, 
omp_is_initial_device());
+  }
+
+  __builtin_printf("%s:%d, %d\n", __FUNCTION__, ++c, omp_is_initial_device());
+
+  return 0;
+}
+
+/* The order is undefined, in which same-priority 'constructor' functions, and 
'destructor' functions are run.
+   { dg-output {init[^,]+, 1[\r\n]+} }
+   { dg-output {init[^,]+, 1[\r\n]+} }
+   { dg-output {init[^,]+, 1[\r\n]+} }
+   { dg-output {main:1, 1[\r\n]+} }
+   { dg-output {initHD[^,]+, 0[\r\n]+} { target offload_device } }
+   { dg-output {initHD[^,]+, 0[\r\n]+} { target offload_device } }
+   { dg-output {main:2, 1[\r\n]+} { target { ! offload_device } } }
+   { dg-output {main:2, 0[\r\n]+} { target offload_device } }
+   { dg-output {main:3, 1[\r\n]+} { target  { ! offload_device } } }
+   { dg-output {main:3, 0[\r\n]+} { target offload_device } }
+   { dg-output {main:4, 1[\r\n]+} }
+   { dg-output {finiHD[^,]+, 0[\r\n]+} { target offload_device } }
+   { dg-output {finiHD[^,]+, 0[\r\n]+} { target offload_device } }
+   { dg-output {fini[^,]+, 1[\r\n]+} }
+   { dg-output {fini[^,]+, 1[\r\n]+} }
+   { dg-output {fini[^,]+, 1[\r\n]+} }
+*/


[gcc/devel/omp/gcc-14] openmp: Fix up cloning of dynamic C++ initializers for OpenMP target [PR119370]

2025-04-25 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:b1fc2243dfd0bd87414a0e2b729b74f43ffd28cc

commit b1fc2243dfd0bd87414a0e2b729b74f43ffd28cc
Author: Jakub Jelinek 
Date:   Thu Mar 20 09:06:17 2025 +0100

openmp: Fix up cloning of dynamic C++ initializers for OpenMP target 
[PR119370]

The following testcase ICEs, because we emit the dynamic initialization 
twice,
once for host and once for target initialization, and although we use
copy_tree_body_r to unshare it, e.g. for the array initializers it can 
contain
TARGET_EXPRs with local temporaries (or local temporaries alone).
Now, these temporaries were created when current_function_decl was NULL,
they are outside of any particular function, so they have DECL_CONTEXT NULL.
That is normally fine, gimple_add_tmp_var will set DECL_CONTEXT for them
later on to the host __static_init* function into which they are gimplified.
The problem is that the copy_tree_body_r cloning happens before that (and 
has
to, gimplification is destructive and so we couldn't gimplify the same tree
again in __omp_static_init* function) and uses auto_var_in_fn_p to see what
needs to be remapped.  But that means it doesn't remap temporaries with
NULL DECL_CONTEXT and having the same temporaries in two different functions
results in ICEs (sure, one can e.g. use parent function's temporaries in a
nested function).

The following patch just arranges to set DECL_CONTEXT on the temporaries
to the host dynamic initialization function, so that they get remapped.
If gimplification cared whether DECL_CONTEXT is NULL or not, we could
remember those that we've changed in a vector and undo it afterwards,
but seems it doesn't really care.

2025-03-20  Jakub Jelinek  

PR c++/119370
* decl2.cc (set_context_for_auto_vars_r): New function.
(emit_partial_init_fini_fn): Call walk_tree with that function
on &init before walk_tree with copy_tree_body_r.

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

(cherry picked from commit e0b3eeb67f6d3bfe95591d8fb0c7dfd3f1b3b4ef)

Diff:
---
 gcc/cp/ChangeLog.omp |  8 
 gcc/cp/decl2.cc  | 18 ++
 gcc/testsuite/ChangeLog.omp  |  6 ++
 gcc/testsuite/g++.dg/gomp/pr119370.C | 10 ++
 4 files changed, 42 insertions(+)

diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index 659c56a282ad..4cc1ad2df527 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -1,5 +1,13 @@
 2025-04-25  Thomas Schwinge  
 
+   Backported from trunk:
+   2025-03-20  Jakub Jelinek  
+
+   PR c++/119370
+   * decl2.cc (set_context_for_auto_vars_r): New function.
+   (emit_partial_init_fini_fn): Call walk_tree with that function
+   on &init before walk_tree with copy_tree_body_r.
+
Backported from trunk:
2025-02-25  Jakub Jelinek  
 
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index b1754fb8f6c2..02e1bfff979b 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -4398,6 +4398,23 @@ one_static_initialization_or_destruction (bool initp, 
tree decl, tree init,
   DECL_STATIC_FUNCTION_P (current_function_decl) = 0;
 }
 
+/* Helper for emit_partial_init_fini_fn OpenMP target handling, called via
+   walk_tree.  Set DECL_CONTEXT on any automatic temporaries which still
+   have it NULL to id->src_fn, so that later copy_tree_body_r can remap those.
+   Otherwise DECL_CONTEXT would be set only during gimplification of the host
+   fn and when copy_tree_body_r doesn't remap those, we'd ICE during the
+   target fn gimplification because the same automatic VAR_DECL can't be
+   used in multiple functions (with the exception of nested functions).  */
+
+static tree
+set_context_for_auto_vars_r (tree *tp, int *, void *data)
+{
+  copy_body_data *id = (copy_body_data *) data;
+  if (auto_var_in_fn_p (*tp, NULL_TREE) && DECL_ARTIFICIAL (*tp))
+DECL_CONTEXT (*tp) = id->src_fn;
+  return NULL_TREE;
+}
+
 /* Generate code to do the initialization or destruction of the decls in VARS,
a TREE_LIST of VAR_DECL with static storage duration.
Whether initialization or destruction is performed is specified by INITP.  
*/
@@ -4451,6 +4468,7 @@ emit_partial_init_fini_fn (bool initp, unsigned priority, 
tree vars,
  id.transform_new_cfg = true;
  id.transform_return_to_modify = false;
  id.eh_lp_nr = 0;
+ walk_tree (&init, set_context_for_auto_vars_r, &id, NULL);
  walk_tree (&init, copy_tree_body_r, &id, NULL);
}
   /* Do one initialization or destruction.  */
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index d13b5d1f4287..af82bfa9262f 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,5 +1,11 @@
 2025-04-25  Thomas Schwinge  
 
+   Backported from trunk:
+   2025-03-20  Jakub Jelinek  
+
+   PR c++/119370
+   * g++.dg/go

[gcc(refs/users/omachota/heads/rtl-ssa-dce)] rtl-ssa-dce: remove c style code

2025-04-25 Thread Ondrej Machota via Gcc-cvs
https://gcc.gnu.org/g:f166c9141b6dc2094bef42d5b632da8b608f7a34

commit f166c9141b6dc2094bef42d5b632da8b608f7a34
Author: Ondřej Machota 
Date:   Fri Apr 25 21:57:46 2025 +0200

rtl-ssa-dce: remove c style code

Diff:
---
 gcc/dce.cc | 453 +
 1 file changed, 61 insertions(+), 392 deletions(-)

diff --git a/gcc/dce.cc b/gcc/dce.cc
index 02da64c7669a..70c9faf27c59 100644
--- a/gcc/dce.cc
+++ b/gcc/dce.cc
@@ -1318,7 +1318,6 @@ public:
 
 } // namespace
 
-// This struct could help to remove unordered_set for rtl ssa dce
 struct offset_bitmap {
   private:
 const int m_offset;
@@ -1361,7 +1360,7 @@ private:
   void mark_prelive_insn(insn_info *, auto_vec&);
   auto_vec mark_prelive();
   void mark();
-  // void propagate_dead_phis();
+  std::unordered_set propagate_dead_phis();
   void reset_dead_debug_insn(insn_info *);
   void reset_dead_debug();
   void sweep();
@@ -1415,36 +1414,35 @@ rtl_ssa_dce::is_rtx_prelive(const_rtx insn) {
   gcc_assert(insn != nullptr);
 
   if (CALL_P (insn)
-/* We cannot delete pure or const sibling calls because it is
-  hard to see the result.  */
+// We cannot delete pure or const sibling calls because it is
+// hard to see the result.
 && (!SIBLING_CALL_P (insn))
-/* We can delete dead const or pure calls as long as they do not
-  infinite loop.  */
+// We can delete dead const or pure calls as long as they do not
+// infinite loop.
 && (RTL_CONST_OR_PURE_CALL_P (insn) && !RTL_LOOPING_CONST_OR_PURE_CALL_P 
(insn))
-/* Don't delete calls that may throw if we cannot do so.  */
+// Don't delete calls that may throw if we cannot do so.
 && can_delete_call (insn))
   return false;
 
   if (!NONJUMP_INSN_P (insn))
-/* This handles jumps, notes, call_insns, debug_insns, ... */
+// This handles jumps, notes, call_insns, debug_insns, ...
 return true;
 
-  /* Only rtx_insn should be handled here */
+  // Only rtx_insn should be handled here
   gcc_assert(GET_CODE(insn) == INSN);
 
-  /* Don't delete insns that may throw if we cannot do so.  */
+  // Don't delete insns that may throw if we cannot do so.
   if (!cfun->can_delete_dead_exceptions && !insn_nothrow_p (insn)  && 
can_alter_cfg)
 return true;
  
-  /* Callee-save restores are needed.  */
+  // Callee-save restores are needed.
   if (RTX_FRAME_RELATED_P (insn) && crtl->shrink_wrapped_separate 
   && find_reg_note (insn, REG_CFA_RESTORE, NULL))
 return true;
 
   rtx body = PATTERN(insn);
   switch (GET_CODE(body)) {
-// Clobbers are handled inside is_prelive
-case CLOBBER: // gcc/gcc/testsuite/gcc.c-torture/compile/2605-1.c
+case CLOBBER:
 case USE:
 case VAR_LOCATION:
   return true;
@@ -1462,12 +1460,14 @@ rtl_ssa_dce::is_rtx_prelive(const_rtx insn) {
 
 bool
 rtl_ssa_dce::is_prelive(insn_info *insn) {
-  // Phi insns and debug insns are never prelive, bb head and end contain 
-  // artificial uses that we need to mark as prelive
-  if (insn->is_bb_head() || insn->is_bb_end())
+  // bb head and end contain artificial uses that we need to mark as prelive
+  // debug instructions are also prelive, however, they are not added to the
+  // worklist
+  if (insn->is_bb_head() || insn->is_bb_end() || insn->is_debug_insn())
 return true;
 
-  if (insn->is_artificial() || insn->is_debug_insn())
+  // Phi instructions are never prelive
+  if (insn->is_artificial())
 return false;
 
   gcc_assert (insn->is_real());
@@ -1478,18 +1478,18 @@ rtl_ssa_dce::is_prelive(insn_info *insn) {
 
 gcc_assert(def->is_reg());
 
-/* gcc.c-torture/execute/2503-1.c - flags register is unused. Not all
-   hard registers should be marked... */
+// we should not delete the frame pointer because of the dward2frame pass
+if (frame_pointer_needed && def->regno() == HARD_FRAME_POINTER_REGNUM)
+  return true;
  
-/* this ignores clobbers, which is probably fine */
+// skip clobbers, they are handled inside is_rtx_prelive
 if (def->kind() == access_kind::CLOBBER)
-  return true;
+  continue;
 
 gcc_assert (def->kind() == access_kind::SET);
 
-/* needed by gcc.c-torture/execute/pr51447.c */
-if (HARD_REGISTER_NUM_P (def->regno())
-&& global_regs[def->regno()])
+// needed by gcc.c-torture/execute/pr51447.c
+if (HARD_REGISTER_NUM_P (def->regno()) && global_regs[def->regno()])
   return true;
 
 unsigned int picreg = PIC_OFFSET_TABLE_REGNUM;
@@ -1508,6 +1508,11 @@ rtl_ssa_dce::mark_prelive_insn(insn_info *insn, 
auto_vec &worklist)
 fprintf(dump_file, "Insn %d marked as prelive\n", insn->uid());
 
   m_marked.emplace(insn);
+  // debug instruction are not added to worklist not to wake up possibly dead
+  // instructions 
+  if (insn->is_debug_insn())
+return;
+
   for (use_info *use : insn->uses()) {
 set_info* set = use->def();
 if (set)
@@ -1538,11 +1543,10 @@ rtl_ssa_dce::mark() {
   while (

[gcc/devel/omp/gcc-14] libgomp/libgomp.texi: Mention -fno-builtin-omp_is_initial_device

2025-04-25 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:cdd32ab06889da013d2cde51bf537695e8795a76

commit cdd32ab06889da013d2cde51bf537695e8795a76
Author: Tobias Burnus 
Date:   Thu Aug 8 14:24:59 2024 +0200

libgomp/libgomp.texi: Mention -fno-builtin-omp_is_initial_device

libgomp/ChangeLog:

* libgomp.texi (omp_is_initial_device): Mention
-fno-builtin-omp_is_initial_device and folding by default.

(cherry picked from commit 8b5a8b1f60e7d1a51429f118e0fb3d851abe6cd4)

Diff:
---
 libgomp/ChangeLog.omp | 6 ++
 libgomp/libgomp.texi  | 4 
 2 files changed, 10 insertions(+)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 6e99c7107c89..09cc7278e191 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -3,6 +3,12 @@
Backported from trunk:
2024-08-08  Tobias Burnus  
 
+   * libgomp.texi (omp_is_initial_device): Mention
+   -fno-builtin-omp_is_initial_device and folding by default.
+
+   Backported from trunk:
+   2024-08-08  Tobias Burnus  
+
* testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C: Split
scan-tree-dump into with and without target offload_target_any.
* testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C:
diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 5190a04f6648..5c87769273c5 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -1819,6 +1819,10 @@ This function returns @code{true} if currently running 
on the host device,
 @code{false} otherwise.  Here, @code{true} and @code{false} represent
 their language-specific counterparts.
 
+Note that in GCC this value is already folded to a constant in the compiler;
+compile with @option{-fno-builtin-omp_is_initial_device} if a run-time function
+is desired.
+
 @item @emph{C/C++}:
 @multitable @columnfractions .20 .80
 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}


[gcc r16-149] c++: pruning non-captures in noexcept lambda [PR119764]

2025-04-25 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:44e31eb265ba1984638908466a88095744a88709

commit r16-149-g44e31eb265ba1984638908466a88095744a88709
Author: Jason Merrill 
Date:   Mon Apr 14 12:18:06 2025 -0400

c++: pruning non-captures in noexcept lambda [PR119764]

The patch for PR87185 fixed the ICE without fixing the underlying problem,
that we were failing to find the declaration of the capture proxy that we
are trying to decide whether to prune.  Fixed by looking at the right index
in stmt_list_stack.

Since this changes captures, it changes the ABI of noexcept lambdas; we
haven't worked hard to maintain lambda capture ABI, but it's easy enough to
control here.

PR c++/119764
PR c++/87185

gcc/cp/ChangeLog:

* lambda.cc (insert_capture_proxy): Handle noexcept lambda.
(prune_lambda_captures): Likewise, in ABI v21.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/lambda/lambda-noexcept1.C: New test.

Diff:
---
 gcc/cp/lambda.cc   | 41 ++
 .../g++.dg/cpp0x/lambda/lambda-noexcept1.C | 10 ++
 2 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc
index b2e0ecdd67eb..a2bed9fb36aa 100644
--- a/gcc/cp/lambda.cc
+++ b/gcc/cp/lambda.cc
@@ -348,7 +348,11 @@ insert_capture_proxy (tree var)
 
   /* And put a DECL_EXPR in the STATEMENT_LIST for the same block.  */
   var = build_stmt (DECL_SOURCE_LOCATION (var), DECL_EXPR, var);
-  tree stmt_list = (*stmt_list_stack)[1];
+  /* The first stmt_list is from start_preparsed_function.  Then there's a
+ possible stmt_list from begin_eh_spec_block, then the one from the
+ lambda's outer {}.  */
+  unsigned index = 1 + use_eh_spec_block (current_function_decl);
+  tree stmt_list = (*stmt_list_stack)[index];
   gcc_assert (stmt_list);
   append_to_statement_list_force (var, &stmt_list);
 }
@@ -1859,11 +1863,10 @@ prune_lambda_captures (tree body)
   cp_walk_tree_without_duplicates (&body, mark_const_cap_r, &const_vars);
 
   tree bind_expr = expr_single (DECL_SAVED_TREE (lambda_function (lam)));
-  if (bind_expr && TREE_CODE (bind_expr) == MUST_NOT_THROW_EXPR)
+  bool noexcept_p = (bind_expr
+&& TREE_CODE (bind_expr) == MUST_NOT_THROW_EXPR);
+  if (noexcept_p)
 bind_expr = expr_single (TREE_OPERAND (bind_expr, 0));
-  /* FIXME: We don't currently handle noexcept lambda captures correctly,
- so bind_expr may not be set; see PR c++/119764.  */
-  gcc_assert (!bind_expr || TREE_CODE (bind_expr) == BIND_EXPR);
 
   tree *fieldp = &TYPE_FIELDS (LAMBDA_EXPR_CLOSURE (lam));
   for (tree *capp = &LAMBDA_EXPR_CAPTURE_LIST (lam); *capp; )
@@ -1872,11 +1875,23 @@ prune_lambda_captures (tree body)
   if (tree var = var_to_maybe_prune (cap))
{
  tree **use = const_vars.get (var);
- if (use && TREE_CODE (**use) == DECL_EXPR)
+ if (TREE_CODE (**use) == DECL_EXPR)
{
  /* All uses of this capture were folded away, leaving only the
 proxy declaration.  */
 
+ if (noexcept_p)
+   {
+ /* We didn't handle noexcept lambda captures correctly before
+the fix for PR c++/119764.  */
+ if (abi_version_crosses (21))
+   warning_at (location_of (lam), OPT_Wabi, "%qD is no longer"
+   " captured in noexcept lambda in ABI v21 "
+   "(GCC 16)", var);
+ if (!abi_version_at_least (21))
+   goto next;
+   }
+
  /* Splice the capture out of LAMBDA_EXPR_CAPTURE_LIST.  */
  *capp = TREE_CHAIN (cap);
 
@@ -1894,14 +1909,11 @@ prune_lambda_captures (tree body)
 
  /* And maybe out of the vars declared in the containing
 BIND_EXPR, if it's listed there.  */
- if (bind_expr)
-   {
- tree *bindp = &BIND_EXPR_VARS (bind_expr);
- while (*bindp && *bindp != DECL_EXPR_DECL (**use))
-   bindp = &DECL_CHAIN (*bindp);
- if (*bindp)
-   *bindp = DECL_CHAIN (*bindp);
-   }
+ tree *bindp = &BIND_EXPR_VARS (bind_expr);
+ while (*bindp && *bindp != DECL_EXPR_DECL (**use))
+   bindp = &DECL_CHAIN (*bindp);
+ if (*bindp)
+   *bindp = DECL_CHAIN (*bindp);
 
  /* And remove the capture proxy declaration.  */
  **use = void_node;
@@ -1909,6 +1921,7 @@ prune_lambda_captures (tree body)
}
}
 
+next:
   capp = &TREE_CHAIN (cap);
 }
 }
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-noexcept1.C 
b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-noexcept1.C
new file mode 100644
index ..d7445569801e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lamb

[gcc/devel/omp/gcc-14] Revert 'OpenMP: Constructors and destructors for "declare target" static aggregates'

2025-04-25 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:14568217c74206c9c5d033050fba6fe2ab57bb05

commit 14568217c74206c9c5d033050fba6fe2ab57bb05
Author: Thomas Schwinge 
Date:   Fri Apr 25 16:39:39 2025 +0200

Revert 'OpenMP: Constructors and destructors for "declare target" static 
aggregates'

... in preparation of cherry-picking the upstream trunk changes.

This reverts commit 9127b4db9c58f48e0b47816d64e22c21404136b3.

gcc/
Revert:
2023-05-12  Julian Brown  

* omp-builtins.def (BUILT_IN_OMP_IS_INITIAL_DEVICE): New builtin.
* tree.cc (get_file_function_name): Support names for on-target
constructor/destructor functions.
gcc/cp/
Revert:
2023-05-12  Julian Brown  

* decl2.cc (tree-inline.h): Include.
(static_init_fini_fns): Bump to four entries. Update comment.
(start_objects, start_partial_init_fini_fn): Add 'omp_target'
parameter. Support "declare target" decls. Update forward 
declaration.
(emit_partial_init_fini_fn): Add 'host_fn' parameter. Return tree 
for
the created function. Support "declare target".
(OMP_SSDF_IDENTIFIER): New macro.
(partition_vars_for_init_fini): Support partitioning "declare 
target"
variables also.
(generate_ctor_or_dtor_function): Add 'omp_target' parameter. 
Support
"declare target" decls.
(c_parse_final_cleanups): Support constructors/destructors on OpenMP
offload targets.
libgomp/
Revert:
2023-05-12  Julian Brown  

* testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C: New
test.
* testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C: New
test.
* testsuite/libgomp.c++/static-aggr-constructor-destructor-3.C: New
test.

Diff:
---
 gcc/ChangeLog.omp  |   9 +
 gcc/cp/ChangeLog.omp   |  19 ++
 gcc/cp/decl2.cc| 241 -
 gcc/omp-builtins.def   |   2 -
 gcc/tree.cc|   6 +-
 libgomp/ChangeLog.omp  |  12 +
 .../static-aggr-constructor-destructor-1.C |  28 ---
 .../static-aggr-constructor-destructor-2.C |  31 ---
 .../static-aggr-constructor-destructor-3.C |  36 ---
 9 files changed, 80 insertions(+), 304 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 2ec578ce6d0a..58bf5d9515a1 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,12 @@
+2025-04-25  Thomas Schwinge  
+
+   Revert:
+   2023-05-12  Julian Brown  
+
+   * omp-builtins.def (BUILT_IN_OMP_IS_INITIAL_DEVICE): New builtin.
+   * tree.cc (get_file_function_name): Support names for on-target
+   constructor/destructor functions.
+
 2025-04-17  Kwok Cheung Yeung  
 
* langhooks-def.h (lhd_omp_deep_mapping): Add new argument.
diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index 80b4344a1b5b..a689be1e3f89 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -1,3 +1,22 @@
+2025-04-25  Thomas Schwinge  
+
+   Revert:
+   2023-05-12  Julian Brown  
+
+   * decl2.cc (tree-inline.h): Include.
+   (static_init_fini_fns): Bump to four entries. Update comment.
+   (start_objects, start_partial_init_fini_fn): Add 'omp_target'
+   parameter. Support "declare target" decls. Update forward declaration.
+   (emit_partial_init_fini_fn): Add 'host_fn' parameter. Return tree for
+   the created function. Support "declare target".
+   (OMP_SSDF_IDENTIFIER): New macro.
+   (partition_vars_for_init_fini): Support partitioning "declare target"
+   variables also.
+   (generate_ctor_or_dtor_function): Add 'omp_target' parameter. Support
+   "declare target" decls.
+   (c_parse_final_cleanups): Support constructors/destructors on OpenMP
+   offload targets.
+
 2025-04-17  Kwok Cheung Yeung  
 
* parser.cc (cp_parser_omp_clause_map): Apply iterator to push and
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 56b222412b86..b30003cccd9f 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -50,22 +50,20 @@ along with GCC; see the file COPYING3.  If not see
 #include "asan.h"
 #include "optabs-query.h"
 #include "omp-general.h"
-#include "tree-inline.h"
 
 /* Id for dumping the raw trees.  */
 int raw_dump_id;
  
 extern cpp_reader *parse_in;
 
-static tree start_objects (bool, unsigned, bool, bool);
+static tree start_objects (bool, unsigned, bool);
 static tree finish_objects (bool, unsigned, tree, bool = true);
-static tree start_partial_init_fini_fn (bool, unsigned, unsigned, bool);
+static tree start_partial_init_fini_fn (bool, unsigned, unsigned);
 static void finish_partial_init

[gcc/devel/omp/gcc-14] libgomp.c++/static-aggr-constructor-destructor-{1, 2}.C: Fix scan-tree-dump

2025-04-25 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:e55aa018ba1c5ce3f756e56489b7007e736aa5a8

commit e55aa018ba1c5ce3f756e56489b7007e736aa5a8
Author: Tobias Burnus 
Date:   Thu Aug 8 10:42:25 2024 +0200

libgomp.c++/static-aggr-constructor-destructor-{1,2}.C: Fix scan-tree-dump

In principle, the optimized dump should be the same on the host, but as
'nohost' is not handled, is is present. However when ENABLE_OFFLOADING is
false, it is handled early enough to remove the function.

libgomp/ChangeLog:

* testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C: 
Split
scan-tree-dump into with and without target offload_target_any.
* testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C:
Likewise.

(cherry picked from commit e3a6dec326a127ad549246435b9d3835e9a32407)

Diff:
---
 libgomp/ChangeLog.omp|  8 
 .../libgomp.c++/static-aggr-constructor-destructor-1.C   | 15 ---
 .../libgomp.c++/static-aggr-constructor-destructor-2.C   | 16 +---
 3 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index df075af91530..6e99c7107c89 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,5 +1,13 @@
 2025-04-25  Thomas Schwinge  
 
+   Backported from trunk:
+   2024-08-08  Tobias Burnus  
+
+   * testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C: Split
+   scan-tree-dump into with and without target offload_target_any.
+   * testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C:
+   Likewise.
+
Backported from trunk:
2024-08-07  Julian Brown  
Tobias Burnus  
diff --git 
a/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C 
b/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C
index 403a071c0c01..b5aafc8cabc2 100644
--- a/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C
+++ b/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C
@@ -9,9 +9,18 @@
 
 // { dg-final { scan-tree-dump-not "omp_is_initial_device" "optimized" } }
 // { dg-final { scan-tree-dump-not "__omp_target_static_init_and_destruction" 
"optimized" } }
-// FIXME: should be '-not' not '-times' 1:
-// { dg-final { scan-tree-dump-times "void _GLOBAL__off_I_v1" 1 "optimized" } }
-// { dg-final { scan-tree-dump-times "__attribute__\\(\\(\[^\n\r]*omp declare 
target nohost" 1 "optimized" } }
+
+// (A) No offloading configured: The symbols aren't present
+// Caveat: They are present with -foffload=disable - or offloading
+// configured but none of the optional offload packages/binaries installed.
+// But the 'offload_target_any' check cannot distinguish those
+// { dg-final { scan-tree-dump-not "void _GLOBAL__off_I_v1" "optimized" { 
target { ! offload_target_any } } } }
+// { dg-final { scan-tree-dump-not "__attribute__\\(\\(\[^\n\r]*omp declare 
target nohost" "optimized" { target { ! offload_target_any } } } }
+
+// (B) With offload configured (and compiling for an offload target)
+// the symbols are present (missed optimization). Hence: FIXME.
+// { dg-final { scan-tree-dump-times "void _GLOBAL__off_I_v1" 1 "optimized" { 
target offload_target_any } } }
+// { dg-final { scan-tree-dump-times "__attribute__\\(\\(\[^\n\r]*omp declare 
target nohost" 1 "optimized" { target offload_target_any } } }
 
 // { dg-final { only_for_offload_target amdgcn-amdhsa 
scan-offload-tree-dump-not "omp_initial_device;" "optimized" { target 
offload_target_amdgcn } } }
 // { dg-final { only_for_offload_target amdgcn-amdhsa scan-offload-tree-dump 
"v1\\._x = 5;" "optimized" { target offload_target_amdgcn } } }
diff --git 
a/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C 
b/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C
index 6dd4260a522c..9652a721bbe2 100644
--- a/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C
+++ b/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C
@@ -9,9 +9,19 @@
 
 // { dg-final { scan-tree-dump-not "omp_is_initial_device" "optimized" } }
 // { dg-final { scan-tree-dump-not "__omp_target_static_init_and_destruction" 
"optimized" } }
-// FIXME: should be '-not' not '-times' 1:
-// { dg-final { scan-tree-dump-times "void _GLOBAL__off_I_" 1 "optimized" } }
-// { dg-final { scan-tree-dump-times "__attribute__\\(\\(\[^\n\r]*omp declare 
target nohost" 1 "optimized" } }
+
+// (A) No offloading configured: The symbols aren't present
+// Caveat: They are present with -foffload=disable - or offloading
+// configured but none of the optional offload packages/binaries installed.
+// But the 'offload_target_any' check cannot distinguish those
+// { dg-final { scan-tree-dump-not "void _GLOBAL__off_I_v1" "optimized" { 
target { ! offload_target_any } } } }
+// { dg-final { scan-tree-dump-not "__attribute__\\(\\(\[^\n\

[gcc/devel/omp/gcc-14] GCN: Properly switch sections in 'gcn_hsa_declare_function_name' [PR119737]

2025-04-25 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:48ff90a2f1c10634cad5edf43f40f31feafb8607

commit 48ff90a2f1c10634cad5edf43f40f31feafb8607
Author: Andrew Pinski 
Date:   Mon Apr 21 22:32:26 2025 +

GCN: Properly switch sections in 'gcn_hsa_declare_function_name' [PR119737]

There are GCN/C++ target as well as offloading codes, where the hard-coded
section names in 'gcn_hsa_declare_function_name' do not fit, and assembly 
thus
fails:

LLVM ERROR: Size expression must be absolute.

This commit progresses GCN target:

[-FAIL: g++.dg/init/call1.C  -std=gnu++17 (internal compiler error: 
Aborted signal terminated program as)-]
[-FAIL:-]{+PASS:+} g++.dg/init/call1.C  -std=gnu++17 (test for excess 
errors)
[-UNRESOLVED:-]{+PASS:+} g++.dg/init/call1.C  -std=gnu++17 
[-compilation failed to produce executable-]{+execution test+}
[-FAIL: g++.dg/init/call1.C  -std=gnu++26 (internal compiler error: 
Aborted signal terminated program as)-]
[-FAIL:-]{+PASS:+} g++.dg/init/call1.C  -std=gnu++26 (test for excess 
errors)
[-UNRESOLVED:-]{+PASS:+} g++.dg/init/call1.C  -std=gnu++26 
[-compilation failed to produce executable-]{+execution test+}
UNSUPPORTED: g++.dg/init/call1.C  -std=gnu++98: exception handling not 
supported

..., and GCN offloading:

[-XFAIL: libgomp.c++/target-exceptions-throw-1.C (internal compiler 
error: Aborted signal terminated program as)-]
[-XFAIL: libgomp.c++/target-exceptions-throw-1.C PR119737 at line 7 
(test for bogus messages, line )-]
[-XFAIL:-]{+PASS:+} libgomp.c++/target-exceptions-throw-1.C (test for 
excess errors)
[-UNRESOLVED:-]{+PASS:+} libgomp.c++/target-exceptions-throw-1.C 
[-compilation failed to produce executable-]{+execution test+}
{+PASS: libgomp.c++/target-exceptions-throw-1.C output pattern test+}

[-XFAIL: libgomp.c++/target-exceptions-throw-2.C (internal compiler 
error: Aborted signal terminated program as)-]
[-XFAIL: libgomp.c++/target-exceptions-throw-2.C PR119737 at line 7 
(test for bogus messages, line )-]
[-XFAIL:-]{+PASS:+} libgomp.c++/target-exceptions-throw-2.C (test for 
excess errors)
[-UNRESOLVED:-]{+PASS:+} libgomp.c++/target-exceptions-throw-2.C 
[-compilation failed to produce executable-]{+execution test+}
{+PASS: libgomp.c++/target-exceptions-throw-2.C output pattern test+}

[-XFAIL: libgomp.oacc-c++/exceptions-throw-1.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
(internal compiler error: Aborted signal terminated program as)-]
[-XFAIL: libgomp.oacc-c++/exceptions-throw-1.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
PR119737 at line 7 (test for bogus messages, line )-]
[-XFAIL:-]{+PASS:+} libgomp.oacc-c++/exceptions-throw-1.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
(test for excess errors)
[-UNRESOLVED:-]{+PASS:+} libgomp.oacc-c++/exceptions-throw-1.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
[-compilation failed to produce executable-]{+execution test+}
{+PASS: libgomp.oacc-c++/exceptions-throw-1.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
output pattern test+}

[-XFAIL: libgomp.oacc-c++/exceptions-throw-2.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
(internal compiler error: Aborted signal terminated program as)-]
[-XFAIL: libgomp.oacc-c++/exceptions-throw-2.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
PR119737 at line 9 (test for bogus messages, line )-]
[-XFAIL:-]{+PASS:+} libgomp.oacc-c++/exceptions-throw-2.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
(test for excess errors)
[-UNRESOLVED:-]{+PASS:+} libgomp.oacc-c++/exceptions-throw-2.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
[-compilation failed to produce executable-]{+execution test+}
{+PASS: libgomp.oacc-c++/exceptions-throw-2.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
output pattern test+}

PR target/119737
gcc/
* config/gcn/gcn.cc (gcn_hsa_declare_function_name): Properly
switch sections.
libgomp/
* testsuite/libgomp.c++/target-exceptions-throw-1.C: Remove
PR119737 XFAILing.
* testsuite/libgomp.c++/target-exceptions-throw-2.C: Likewise.
* testsuite/libgomp.oacc-c++/exceptions-throw-1.C: Likewise.
* testsuite/libgomp.oacc-c++/exceptions-throw-2.C: Likewise.

Co-authored-by: Thomas Schwinge 
(cherry picked from commit dfc43afe719898c3eafbed37fac7e6809d8b97ab)

Diff:
---
 gcc/ChangeLog.omp |  8 
 gcc/config/g

[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression pdt_7

2025-04-25 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:8c1fb2fc15706cb466d5eb7279b56baecf6962bd

commit 8c1fb2fc15706cb466d5eb7279b56baecf6962bd
Author: Mikael Morin 
Date:   Fri Apr 25 20:39:06 2025 +0200

Correction régression pdt_7

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

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 4c3df7b646c4..87e119dbc4be 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -3840,6 +3840,7 @@ gfc_set_pdt_array_descriptor (stmtblock_t *block, tree 
desc,
   tree upper = tse.expr;
   gfc_conv_descriptor_ubound_set (block, desc, gfc_rank_cst[i], upper);
   size = gfc_evaluate_now (size, block);
+  size = fold_convert_loc (input_location, gfc_array_index_type, size);
   gfc_conv_descriptor_spacing_set (block, desc, gfc_rank_cst[i], size);
   offset = fold_build2_loc (input_location, MINUS_EXPR,
gfc_array_index_type, offset, size);


[gcc r16-154] libstdc++: Micro-optimization for std::addressof

2025-04-25 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:c91eb5a5c13f149126f53a7d54bab37ffba936b1

commit r16-154-gc91eb5a5c13f149126f53a7d54bab37ffba936b1
Author: Jonathan Wakely 
Date:   Fri Apr 25 15:49:22 2025 +0100

libstdc++: Micro-optimization for std::addressof

Currently std::addressof calls std::__addressof which uses
__builtin_addressof. This leads to me prefering std::__addressof in some
code, to avoid the extra hop. But it's not as though the implementation
of std::__addressof is complicated and reusing it avoids any code
duplication.

So let's just make std::addressof use the built-in directly, and then we
only need to use std::__addressof in C++98 code. (Transitioning existing
uses of std::__addressof to std::addressof isn't included in this
change.)

The front end does fold std::addressof with -ffold-simple-inlines but
this change still seems worthwhile.

libstdc++-v3/ChangeLog:

* include/bits/move.h (addressof): Use __builtin_addressof
directly.

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

diff --git a/libstdc++-v3/include/bits/move.h b/libstdc++-v3/include/bits/move.h
index e91b003e6955..085ca074fc88 100644
--- a/libstdc++-v3/include/bits/move.h
+++ b/libstdc++-v3/include/bits/move.h
@@ -174,7 +174,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 [[__nodiscard__,__gnu__::__always_inline__]]
 inline _GLIBCXX17_CONSTEXPR _Tp*
 addressof(_Tp& __r) noexcept
-{ return std::__addressof(__r); }
+{ return __builtin_addressof(__r); }
 
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
   // 2598. addressof works on temporaries


[gcc r16-153] libstdc++: Remove c++26 dg-error lines for -Wdelete-incomplete errors

2025-04-25 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:0cb46354359cfb6c71cc0b66a72a89b9f666ec29

commit r16-153-g0cb46354359cfb6c71cc0b66a72a89b9f666ec29
Author: Jonathan Wakely 
Date:   Fri Apr 25 15:57:56 2025 +0100

libstdc++: Remove c++26 dg-error lines for -Wdelete-incomplete errors

This fixes:
FAIL: tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc  -std=gnu++26  
(test for errors, line 283)
FAIL: tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc  -std=gnu++26  
(test for errors, line 305)

This is another consequence of r16-133-g8acea9ffa82ed8 which prevents
the -Wdelete-incomplete errors that happen after the first error.

libstdc++-v3/ChangeLog:

* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc:
Remove dg-error directives for additional c++26 errors.

Diff:
---
 .../testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc | 3 ---
 1 file changed, 3 deletions(-)

diff --git 
a/libstdc++-v3/testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc 
b/libstdc++-v3/testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc
index 7b5ede4f00a9..03fad1486c7c 100644
--- 
a/libstdc++-v3/testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc
+++ 
b/libstdc++-v3/testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc
@@ -39,9 +39,6 @@ void test01()
   // { dg-error "incomplete" "" { target *-*-* } 600 }
 }
 
-// { dg-error "-Wdelete-incomplete" "" { target c++26 } 283 }
-// { dg-error "-Wdelete-incomplete" "" { target c++26 } 305 }
-
 // Ignore additional diagnostic given with -Wsystem-headers:
 // { dg-prune-output "has incomplete type" }
 // { dg-prune-output "possible problem detected" }


[gcc r16-156] libstdc++: Use markdown in some Doxygen comments

2025-04-25 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:c0136555e9974383a0a2256987d24bfbae2f2c10

commit r16-156-gc0136555e9974383a0a2256987d24bfbae2f2c10
Author: Jonathan Wakely 
Date:   Fri Apr 25 16:14:19 2025 +0100

libstdc++: Use markdown in some Doxygen comments

libstdc++-v3/ChangeLog:

* include/bits/ptr_traits.h (to_address): Use markdown for
formatting in Doxygen comments.

Diff:
---
 libstdc++-v3/include/bits/ptr_traits.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/bits/ptr_traits.h 
b/libstdc++-v3/include/bits/ptr_traits.h
index d3c176524268..4308669e03b7 100644
--- a/libstdc++-v3/include/bits/ptr_traits.h
+++ b/libstdc++-v3/include/bits/ptr_traits.h
@@ -223,7 +223,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   /**
* @brief Obtain address referenced by a pointer to an object
* @param __ptr A pointer to an object
-   * @return @c __ptr
+   * @return `__ptr`
* @ingroup pointer_abstractions
   */
   template
@@ -239,8 +239,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   /**
* @brief Obtain address referenced by a pointer to an object
* @param __ptr A pointer to an object
-   * @return @c pointer_traits<_Ptr>::to_address(__ptr) if that expression is
- well-formed, otherwise @c to_address(__ptr.operator->())
+   * @return `pointer_traits<_Ptr>::to_address(__ptr)` if that expression is
+   * well-formed, otherwise `to_address(__ptr.operator->())`.
* @ingroup pointer_abstractions
   */
   template


[gcc r16-155] libstdc++: Add some makefile dependencies

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

commit r16-155-gcd4306a7f223ddd472e518925e0d4e0f0258331b
Author: Jonathan Wakely 
Date:   Thu Apr 10 12:56:43 2025 +0100

libstdc++: Add some makefile dependencies

This ensures that wstring-inst.o and similar files will be rebuilt when
string-inst.cc changes.

libstdc++-v3/ChangeLog:

* src/c++11/Makefile.am: Add prerequisites for targets that
depend on string-inst.cc.
* src/c++11/Makefile.in: Regenerate.

Diff:
---
 libstdc++-v3/src/c++11/Makefile.am | 8 
 libstdc++-v3/src/c++11/Makefile.in | 8 
 2 files changed, 16 insertions(+)

diff --git a/libstdc++-v3/src/c++11/Makefile.am 
b/libstdc++-v3/src/c++11/Makefile.am
index b39115832e2f..26d6fa0e01ae 100644
--- a/libstdc++-v3/src/c++11/Makefile.am
+++ b/libstdc++-v3/src/c++11/Makefile.am
@@ -168,7 +168,15 @@ localename.lo: localename.cc
 localename.o: localename.cc
$(CXXCOMPILE) -fchar8_t -c $<
 
+wstring-inst.lo: wstring-inst.cc string-inst.cc
+wstring-inst.o: wstring-inst.cc string-inst.cc
+
 if ENABLE_DUAL_ABI
+cow-string-inst.lo: cow-string-inst.cc string-inst.cc
+cow-string-inst.o: cow-string-inst.cc string-inst.cc
+cow-wstring-inst.lo: cow-wstring-inst.cc string-inst.cc
+cow-wstring-inst.o: cow-wstring-inst.cc string-inst.cc
+
 # Rewrite the type info for __ios_failure.
 rewrite_ios_failure_typeinfo = sed -e 
'/^_*_ZTISt13__ios_failure:/,/_ZTVN10__cxxabiv120__si_class_type_infoE/s/_ZTVN10__cxxabiv120__si_class_type_infoE/_ZTVSt19__iosfail_type_info/'
 
diff --git a/libstdc++-v3/src/c++11/Makefile.in 
b/libstdc++-v3/src/c++11/Makefile.in
index 770e948a98af..dafdb260ec16 100644
--- a/libstdc++-v3/src/c++11/Makefile.in
+++ b/libstdc++-v3/src/c++11/Makefile.in
@@ -896,6 +896,14 @@ localename.lo: localename.cc
 localename.o: localename.cc
$(CXXCOMPILE) -fchar8_t -c $<
 
+wstring-inst.lo: wstring-inst.cc string-inst.cc
+wstring-inst.o: wstring-inst.cc string-inst.cc
+
+@enable_dual_abi_t...@cow-string-inst.lo: cow-string-inst.cc string-inst.cc
+@ENABLE_DUAL_ABI_TRUE@cow-string-inst.o: cow-string-inst.cc string-inst.cc
+@enable_dual_abi_t...@cow-wstring-inst.lo: cow-wstring-inst.cc string-inst.cc
+@ENABLE_DUAL_ABI_TRUE@cow-wstring-inst.o: cow-wstring-inst.cc string-inst.cc
+
 @ENABLE_DUAL_ABI_TRUE@cxx11-ios_failure-lt.s: cxx11-ios_failure.cc
 @ENABLE_DUAL_ABI_TRUE@ $(LTCXXCOMPILE) -gno-as-loc-support -S $< -o 
tmp-cxx11-ios_failure-lt.s
 @ENABLE_DUAL_ABI_TRUE@ -test -f tmp-cxx11-ios_failure-lt.o && mv -f 
tmp-cxx11-ios_failure-lt.o tmp-cxx11-ios_failure-lt.s


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression pr59586.f

2025-04-25 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:e25b835425e292e84ccb9bcfa67bde9e14ad926d

commit e25b835425e292e84ccb9bcfa67bde9e14ad926d
Author: Mikael Morin 
Date:   Fri Apr 25 19:08:46 2025 +0200

Correction régression pr59586.f

Diff:
---
 gcc/fortran/trans-decl.cc  | 2 +-
 gcc/fortran/trans-types.cc | 3 +++
 gcc/fortran/trans.h| 1 +
 3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 80c00d132b2a..9b91cc29d395 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -1260,7 +1260,7 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym)
 
   if (! COMPLETE_TYPE_P (type)
   && GFC_TYPE_ARRAY_SIZE (type)
-  && GFC_DECL_PACKED_ARRAY (decl))
+  && GFC_TYPE_PACKED_ARRAY (type))
 {
   tree size, range;
 
diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index d67a64b363ab..dd8c306b3b32 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -2019,6 +2019,9 @@ gfc_get_nodesc_array_type (tree etype, gfc_array_spec * 
as, gfc_packed packed,
   if (packed != PACKED_NO)
 GFC_TYPE_ARRAY_ELEM_LEN (type) = TYPE_SIZE_UNIT (etype);
 
+  if (packed == PACKED_FULL || packed == PACKED_STATIC)
+GFC_TYPE_PACKED_ARRAY (type) = 1;
+
   GFC_TYPE_ARRAY_RANK (type) = as->rank;
   GFC_TYPE_ARRAY_CORANK (type) = as->corank;
   GFC_TYPE_ARRAY_DTYPE (type) = NULL_TREE;
diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h
index a7054571e24f..dafc6d33a12d 100644
--- a/gcc/fortran/trans.h
+++ b/gcc/fortran/trans.h
@@ -1103,6 +1103,7 @@ struct GTY(()) lang_decl {
 #define GFC_ARRAY_TYPE_P(node) TYPE_LANG_FLAG_2(node)
 /* Fortran CLASS type.  */
 #define GFC_CLASS_TYPE_P(node) TYPE_LANG_FLAG_4(node)
+#define GFC_TYPE_PACKED_ARRAY(node) TYPE_LANG_FLAG_5(node)
 /* The GFC_TYPE_ARRAY_* members are present in both descriptor and
descriptorless array types.  */
 #define GFC_TYPE_ARRAY_LBOUND(node, dim) \


[gcc r16-128] GCN: Properly switch sections in 'gcn_hsa_declare_function_name' [PR119737]

2025-04-25 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:dfc43afe719898c3eafbed37fac7e6809d8b97ab

commit r16-128-gdfc43afe719898c3eafbed37fac7e6809d8b97ab
Author: Andrew Pinski 
Date:   Mon Apr 21 22:32:26 2025 +

GCN: Properly switch sections in 'gcn_hsa_declare_function_name' [PR119737]

There are GCN/C++ target as well as offloading codes, where the hard-coded
section names in 'gcn_hsa_declare_function_name' do not fit, and assembly 
thus
fails:

LLVM ERROR: Size expression must be absolute.

This commit progresses GCN target:

[-FAIL: g++.dg/init/call1.C  -std=gnu++17 (internal compiler error: 
Aborted signal terminated program as)-]
[-FAIL:-]{+PASS:+} g++.dg/init/call1.C  -std=gnu++17 (test for excess 
errors)
[-UNRESOLVED:-]{+PASS:+} g++.dg/init/call1.C  -std=gnu++17 
[-compilation failed to produce executable-]{+execution test+}
[-FAIL: g++.dg/init/call1.C  -std=gnu++26 (internal compiler error: 
Aborted signal terminated program as)-]
[-FAIL:-]{+PASS:+} g++.dg/init/call1.C  -std=gnu++26 (test for excess 
errors)
[-UNRESOLVED:-]{+PASS:+} g++.dg/init/call1.C  -std=gnu++26 
[-compilation failed to produce executable-]{+execution test+}
UNSUPPORTED: g++.dg/init/call1.C  -std=gnu++98: exception handling not 
supported

..., and GCN offloading:

[-XFAIL: libgomp.c++/target-exceptions-throw-1.C (internal compiler 
error: Aborted signal terminated program as)-]
[-XFAIL: libgomp.c++/target-exceptions-throw-1.C PR119737 at line 7 
(test for bogus messages, line )-]
[-XFAIL:-]{+PASS:+} libgomp.c++/target-exceptions-throw-1.C (test for 
excess errors)
[-UNRESOLVED:-]{+PASS:+} libgomp.c++/target-exceptions-throw-1.C 
[-compilation failed to produce executable-]{+execution test+}
{+PASS: libgomp.c++/target-exceptions-throw-1.C output pattern test+}

[-XFAIL: libgomp.c++/target-exceptions-throw-2.C (internal compiler 
error: Aborted signal terminated program as)-]
[-XFAIL: libgomp.c++/target-exceptions-throw-2.C PR119737 at line 7 
(test for bogus messages, line )-]
[-XFAIL:-]{+PASS:+} libgomp.c++/target-exceptions-throw-2.C (test for 
excess errors)
[-UNRESOLVED:-]{+PASS:+} libgomp.c++/target-exceptions-throw-2.C 
[-compilation failed to produce executable-]{+execution test+}
{+PASS: libgomp.c++/target-exceptions-throw-2.C output pattern test+}

[-XFAIL: libgomp.oacc-c++/exceptions-throw-1.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
(internal compiler error: Aborted signal terminated program as)-]
[-XFAIL: libgomp.oacc-c++/exceptions-throw-1.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
PR119737 at line 7 (test for bogus messages, line )-]
[-XFAIL:-]{+PASS:+} libgomp.oacc-c++/exceptions-throw-1.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
(test for excess errors)
[-UNRESOLVED:-]{+PASS:+} libgomp.oacc-c++/exceptions-throw-1.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
[-compilation failed to produce executable-]{+execution test+}
{+PASS: libgomp.oacc-c++/exceptions-throw-1.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
output pattern test+}

[-XFAIL: libgomp.oacc-c++/exceptions-throw-2.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
(internal compiler error: Aborted signal terminated program as)-]
[-XFAIL: libgomp.oacc-c++/exceptions-throw-2.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
PR119737 at line 9 (test for bogus messages, line )-]
[-XFAIL:-]{+PASS:+} libgomp.oacc-c++/exceptions-throw-2.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
(test for excess errors)
[-UNRESOLVED:-]{+PASS:+} libgomp.oacc-c++/exceptions-throw-2.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
[-compilation failed to produce executable-]{+execution test+}
{+PASS: libgomp.oacc-c++/exceptions-throw-2.C 
-DACC_DEVICE_TYPE_radeon=1 -DACC_MEM_SHARED=0 -foffload=amdgcn-amdhsa  -O2  
output pattern test+}

PR target/119737
gcc/
* config/gcn/gcn.cc (gcn_hsa_declare_function_name): Properly
switch sections.
libgomp/
* testsuite/libgomp.c++/target-exceptions-throw-1.C: Remove
PR119737 XFAILing.
* testsuite/libgomp.c++/target-exceptions-throw-2.C: Likewise.
* testsuite/libgomp.oacc-c++/exceptions-throw-1.C: Likewise.
* testsuite/libgomp.oacc-c++/exceptions-throw-2.C: Likewise.

Co-authored-by: Thomas Schwinge 

Diff:
---
 gcc/config/gcn/gcn.cc | 6 +++---
 libgomp/testsuite/libgomp.c++/target-exceptions-throw-1.C | 3 ---
 libgomp/test

[gcc r16-129] Add 'libgomp.c-c++-common/target-cdtor-1.c'

2025-04-25 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:40ce48e87c1e7344c622c8eb6bed53f1311f5a0a

commit r16-129-g40ce48e87c1e7344c622c8eb6bed53f1311f5a0a
Author: Thomas Schwinge 
Date:   Wed Apr 23 17:35:29 2025 +0200

Add 'libgomp.c-c++-common/target-cdtor-1.c'

libgomp/
* testsuite/libgomp.c-c++-common/target-cdtor-1.c: New.

Diff:
---
 .../libgomp.c-c++-common/target-cdtor-1.c  | 89 ++
 1 file changed, 89 insertions(+)

diff --git a/libgomp/testsuite/libgomp.c-c++-common/target-cdtor-1.c 
b/libgomp/testsuite/libgomp.c-c++-common/target-cdtor-1.c
new file mode 100644
index ..e6099cf23b88
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-c++-common/target-cdtor-1.c
@@ -0,0 +1,89 @@
+/* Offloaded 'constructor' and 'destructor' functions.  */
+
+#include 
+
+#pragma omp declare target
+
+static void
+__attribute__((constructor))
+initHD1()
+{
+  __builtin_printf("%s, %d\n", __FUNCTION__, omp_is_initial_device());
+}
+
+static void
+__attribute__((constructor))
+initHD2()
+{
+  __builtin_printf("%s, %d\n", __FUNCTION__, omp_is_initial_device());
+}
+
+static void
+__attribute__((destructor))
+finiHD1()
+{
+  __builtin_printf("%s, %d\n", __FUNCTION__, omp_is_initial_device());
+}
+
+static void
+__attribute__((destructor))
+finiHD2()
+{
+  __builtin_printf("%s, %d\n", __FUNCTION__, omp_is_initial_device());
+}
+
+#pragma omp end declare target
+
+static void
+__attribute__((constructor))
+initH1()
+{
+  __builtin_printf("%s, %d\n", __FUNCTION__, omp_is_initial_device());
+}
+
+static void
+__attribute__((destructor))
+finiH2()
+{
+  __builtin_printf("%s, %d\n", __FUNCTION__, omp_is_initial_device());
+}
+
+int main()
+{
+  int c = 0;
+
+  __builtin_printf("%s:%d, %d\n", __FUNCTION__, ++c, omp_is_initial_device());
+
+#pragma omp target map(c)
+  {
+__builtin_printf("%s:%d, %d\n", __FUNCTION__, ++c, 
omp_is_initial_device());
+  }
+
+#pragma omp target map(c)
+  {
+__builtin_printf("%s:%d, %d\n", __FUNCTION__, ++c, 
omp_is_initial_device());
+  }
+
+  __builtin_printf("%s:%d, %d\n", __FUNCTION__, ++c, omp_is_initial_device());
+
+  return 0;
+}
+
+/* The order is undefined, in which same-priority 'constructor' functions, and 
'destructor' functions are run.
+   { dg-output {init[^,]+, 1[\r\n]+} }
+   { dg-output {init[^,]+, 1[\r\n]+} }
+   { dg-output {init[^,]+, 1[\r\n]+} }
+   { dg-output {main:1, 1[\r\n]+} }
+   { dg-output {initHD[^,]+, 0[\r\n]+} { target offload_device } }
+   { dg-output {initHD[^,]+, 0[\r\n]+} { target offload_device } }
+   { dg-output {main:2, 1[\r\n]+} { target { ! offload_device } } }
+   { dg-output {main:2, 0[\r\n]+} { target offload_device } }
+   { dg-output {main:3, 1[\r\n]+} { target  { ! offload_device } } }
+   { dg-output {main:3, 0[\r\n]+} { target offload_device } }
+   { dg-output {main:4, 1[\r\n]+} }
+   { dg-output {finiHD[^,]+, 0[\r\n]+} { target offload_device } }
+   { dg-output {finiHD[^,]+, 0[\r\n]+} { target offload_device } }
+   { dg-output {fini[^,]+, 1[\r\n]+} }
+   { dg-output {fini[^,]+, 1[\r\n]+} }
+   { dg-output {fini[^,]+, 1[\r\n]+} }
+*/


[gcc r16-130] GCN, nvptx offloading: Host/device compatibility: Itanium C++ ABI, DSO Object Destruction API [PR119

2025-04-25 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:aafe942227baf8c2bcd4cac2cb150e49a4b895a9

commit r16-130-gaafe942227baf8c2bcd4cac2cb150e49a4b895a9
Author: Thomas Schwinge 
Date:   Wed Apr 23 10:51:48 2025 +0200

GCN, nvptx offloading: Host/device compatibility: Itanium C++ ABI, DSO 
Object Destruction API [PR119853, PR119854]

'__dso_handle' for '__cxa_atexit', '__cxa_finalize'.  See
.

PR target/119853
PR target/119854
libgcc/
* config/gcn/crt0.c (_fini_array): Call
'__GCC_offload___cxa_finalize'.
* config/nvptx/gbl-ctors.c (__static_do_global_dtors): Likewise.
libgomp/
* target-cxa-dso-dtor.c: New.
* config/accel/target-cxa-dso-dtor.c: Likewise.
* Makefile.am (libgomp_la_SOURCES): Add it.
* Makefile.in: Regenerate.
* testsuite/libgomp.c++/target-cdtor-1.C: New.
* testsuite/libgomp.c++/target-cdtor-2.C: Likewise.

Diff:
---
 libgcc/config/gcn/crt0.c   |  32 ++
 libgcc/config/nvptx/gbl-ctors.c|  16 +++
 libgomp/Makefile.am|   2 +-
 libgomp/Makefile.in|   7 +-
 libgomp/config/accel/target-cxa-dso-dtor.c |  62 +++
 libgomp/target-cxa-dso-dtor.c  |   3 +
 libgomp/testsuite/libgomp.c++/target-cdtor-1.C | 104 ++
 libgomp/testsuite/libgomp.c++/target-cdtor-2.C | 140 +
 8 files changed, 363 insertions(+), 3 deletions(-)

diff --git a/libgcc/config/gcn/crt0.c b/libgcc/config/gcn/crt0.c
index dbd6749a47fa..cc23e214cf98 100644
--- a/libgcc/config/gcn/crt0.c
+++ b/libgcc/config/gcn/crt0.c
@@ -24,6 +24,28 @@ typedef long long size_t;
 /* Provide an entry point symbol to silence a linker warning.  */
 void _start() {}
 
+
+#define PR119369_fixed 0
+
+
+/* Host/device compatibility: '__cxa_finalize'.  Dummy; if necessary,
+   overridden via libgomp 'target-cxa-dso-dtor.c'.  */
+
+#if PR119369_fixed
+extern void __GCC_offload___cxa_finalize (void *) __attribute__((weak));
+#else
+void __GCC_offload___cxa_finalize (void *) __attribute__((weak));
+
+void __attribute__((weak))
+__GCC_offload___cxa_finalize (void *dso_handle __attribute__((unused)))
+{
+}
+#endif
+
+/* There are no DSOs; this is the main program.  */
+static void * const __dso_handle = 0;
+
+
 #ifdef USE_NEWLIB_INITFINI
 
 extern void __libc_init_array (void) __attribute__((weak));
@@ -38,6 +60,11 @@ void _init_array()
 __attribute__((amdgpu_hsa_kernel ()))
 void _fini_array()
 {
+#if PR119369_fixed
+  if (__GCC_offload___cxa_finalize)
+#endif
+__GCC_offload___cxa_finalize (__dso_handle);
+
   __libc_fini_array ();
 }
 
@@ -70,6 +97,11 @@ void _init_array()
 __attribute__((amdgpu_hsa_kernel ()))
 void _fini_array()
 {
+#if PR119369_fixed
+  if (__GCC_offload___cxa_finalize)
+#endif
+__GCC_offload___cxa_finalize (__dso_handle);
+
   size_t count;
   size_t i;
 
diff --git a/libgcc/config/nvptx/gbl-ctors.c b/libgcc/config/nvptx/gbl-ctors.c
index 26268116ee0a..10954ee3ab65 100644
--- a/libgcc/config/nvptx/gbl-ctors.c
+++ b/libgcc/config/nvptx/gbl-ctors.c
@@ -31,6 +31,20 @@
 extern int atexit (void (*function) (void));
 
 
+/* Host/device compatibility: '__cxa_finalize'.  Dummy; if necessary,
+   overridden via libgomp 'target-cxa-dso-dtor.c'.  */
+
+extern void __GCC_offload___cxa_finalize (void *);
+
+void __attribute__((weak))
+__GCC_offload___cxa_finalize (void *dso_handle __attribute__((unused)))
+{
+}
+
+/* There are no DSOs; this is the main program.  */
+static void * const __dso_handle = 0;
+
+
 /* Handler functions ('static', in contrast to the 'gbl-ctors.h'
prototypes).  */
 
@@ -49,6 +63,8 @@ static void __static_do_global_dtors (void);
 static void
 __static_do_global_dtors (void)
 {
+  __GCC_offload___cxa_finalize (__dso_handle);
+
   func_ptr *p = __DTOR_LIST__;
   ++p;
   for (; *p; ++p)
diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index e3202aeb0e05..19479aea4622 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -70,7 +70,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
target.c splay-tree.c libgomp-plugin.c oacc-parallel.c oacc-host.c \
oacc-init.c oacc-mem.c oacc-async.c oacc-plugin.c oacc-cuda.c \
priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \
-   oacc-target.c target-indirect.c
+   oacc-target.c target-indirect.c target-cxa-dso-dtor.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 2a0a842af52d..6d22b3d3bfd0 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -219,7 +219,8 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
oacc-parallel.lo oacc-host.lo oacc-init.lo oacc-mem.lo \
oacc-async.lo oacc-plugin.lo oacc-cuda.lo priority_queue.lo \
af

[gcc r16-138] libstdc++: Remove c++98_only dg-error

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

commit r16-138-ge59ddd33242cf7fe02be9025c052c880f74c615b
Author: Jonathan Wakely 
Date:   Fri Apr 25 12:35:01 2025 +0100

libstdc++: Remove c++98_only dg-error

This fixes
FAIL: 22_locale/ctype/is/string/89728_neg.cc  -std=gnu++98  (test for 
errors, line )

Since r16-133-g8acea9ffa82ed8 we don't keep issuing more errors after
the first one, so this dg-error no longer matches anything.

libstdc++-v3/ChangeLog:

* testsuite/22_locale/ctype/is/string/89728_neg.cc: Remove
dg-error for c++98_only effective target.

Diff:
---
 libstdc++-v3/testsuite/22_locale/ctype/is/string/89728_neg.cc | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/22_locale/ctype/is/string/89728_neg.cc 
b/libstdc++-v3/testsuite/22_locale/ctype/is/string/89728_neg.cc
index a34b2aed9710..24aba99376f2 100644
--- a/libstdc++-v3/testsuite/22_locale/ctype/is/string/89728_neg.cc
+++ b/libstdc++-v3/testsuite/22_locale/ctype/is/string/89728_neg.cc
@@ -18,7 +18,6 @@
 // .
 
 // { dg-error "invalid use of incomplete type" "" { target *-*-* } 0 }
-// { dg-error "invalid 'static_cast'" "" { target c++98_only } 0 }
 
 #include 


[gcc r15-9588] libstdc++: Implement formatters for queue, priority_queue and stack [PR109162]

2025-04-25 Thread Tomasz Kaminski via Gcc-cvs
https://gcc.gnu.org/g:5bd02daf8430ecce1d7fd847ef4fc9c369179542

commit r15-9588-g5bd02daf8430ecce1d7fd847ef4fc9c369179542
Author: Tomasz Kamiński 
Date:   Fri Apr 18 14:56:39 2025 +0200

libstdc++: Implement formatters for queue, priority_queue and stack 
[PR109162]

This patch implements formatter specializations for standard container 
adaptors
(queue, priority_queue and stack) from P2286R8.

To be able to access the protected `c` member, the adaptors befriend
corresponding formatter specializations. Note that such specialization
may be disable if the container is formattable, in such case
specializations are unharmful.

As in the case of previous commits, the signatures of the user-facing parse
and format methods of the provided formatters deviate from the standard by
constraining types of parameters:
 * _CharT is constrained __formatter::__char
 * basic_format_parse_context<_CharT> for parse argument
 * basic_format_context<_Out, _CharT> for format second argument
The standard specifies all above as unconstrained types. In particular
_CharT constrain, allow us to befriend all allowed specializations.

Furthermore the standard specifies these formatters as delegating to
formatter, charT>, which in turn
delegates to range_formatter. This patch avoids one level of indirection,
and dependency of ranges::ref_view.  This is technically observable if
user specializes formatter> where PD is program defined
container, but I do not think this is the case worth extra indirection.

This patch also moves the formattable and it's dependencies to the 
formatfwd.h,
so it can be used in adapters formatters, without including format header.
The definition of _Iter_for is changed from alias to denoting
back_insert_iterator>, to struct with type nested 
typedef
that points to same type, that is forward declared.

PR libstdc++/109162

libstdc++-v3/ChangeLog:

* include/bits/formatfwd.h (__format::__parsable_with)
(__format::__formattable_with, __format::__formattable_impl)
(__format::__has_debug_format, __format::__const_formattable_range)
(__format::__maybe_const_range, __format::__maybe_const)
(std::formattable): Moved from std/format.
(__format::Iter_for, std::range_formatter): Forward declare.
* include/bits/stl_queue.h (std::formatter): Forward declare.
(std::queue, std::priority_queue): Befriend formatter 
specializations.
* include/bits/stl_stack.h (std::formatter): Forward declare.
(std::stack): Befriend formatter specializations.
* include/std/format (__format::_Iter_for): Define as struct with
(__format::__parsable_with, __format::__formattable_with)
(__format::__formattable_impl, __format::__has_debug_format)
(_format::__const_formattable_range, __format::__maybe_const_range)
(__format::__maybe_const, std::formattable): Moved to 
bits/formatfwd.h.
(std::range_formatter): Remove default argument specified in 
declaration
in bits/formatfwd.h.
* include/std/queue: Include bits/version.h before bits/stl_queue.h.
(formatter, _CharT>)
(formatter, _CharT>): 
Define.
* include/std/stack: Include bits/version.h before bits/stl_stack.h
(formatter, _CharT>): Define.
* testsuite/std/format/ranges/adaptors.cc: New test.

Reviewed-by: Jonathan Wakely 
Signed-off-by: Tomasz Kamiński 
(cherry picked from commit 3d808ede38b959d283baaed1864434392eeb41e3)

Diff:
---
 libstdc++-v3/include/bits/formatfwd.h  |  78 +++
 libstdc++-v3/include/bits/stl_queue.h  |  14 ++
 libstdc++-v3/include/bits/stl_stack.h  |   9 ++
 libstdc++-v3/include/std/format|  76 ++
 libstdc++-v3/include/std/queue |  80 ++-
 libstdc++-v3/include/std/stack |  48 ++-
 .../testsuite/std/format/ranges/adaptors.cc| 156 +
 7 files changed, 387 insertions(+), 74 deletions(-)

diff --git a/libstdc++-v3/include/bits/formatfwd.h 
b/libstdc++-v3/include/bits/formatfwd.h
index a6b5ac8c8ce1..9ba658b078a5 100644
--- a/libstdc++-v3/include/bits/formatfwd.h
+++ b/libstdc++-v3/include/bits/formatfwd.h
@@ -37,6 +37,12 @@
 //  must have been included before this header:
 #ifdef __glibcxx_format // C++ >= 20 && HOSTED
 
+#include 
+#include 
+#if __glibcxx_format_ranges // C++ >= 23 && HOSTED
+#  include   // input_range, range_reference_t
+#endif
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -50,6 +56,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // [format.formatter], formatter
   template struct formatter;
 
+/// @cond undocumented
 namespace __format
 {
 #ifd

[gcc r15-9589] libstdc++: Define __cpp_lib_format_ranges in format header [PR109162]

2025-04-25 Thread Tomasz Kaminski via Libstdc++-cvs
https://gcc.gnu.org/g:17e0decc1dbf827747aebfa0573cc8e50969ae3f

commit r15-9589-g17e0decc1dbf827747aebfa0573cc8e50969ae3f
Author: Tomasz Kamiński 
Date:   Tue Apr 22 09:56:42 2025 +0200

libstdc++: Define __cpp_lib_format_ranges in format header [PR109162]

As P2286R8 and P2585R1 as now fully implemented, we now define
__cpp_lib_format_ranges feature test macro with __cpp_lib_format_ranges.
This macro is provided only in .

Uses of internal __glibcxx_format_ranges are also updated.

PR libstdc++/109162

libstdc++-v3/ChangeLog:

* include/bits/version.def (format_ranges): Remove no_stdname and
update value.
* include/bits/version.h: Regenerate.
* src/c++23/std.cc.in: Replace __glibcxx_format_ranges with
__cpp_lib_format_ranges.
* testsuite/std/format/formatter/lwg3944.cc: Likewise.
* testsuite/std/format/parse_ctx.cc: Likewise.
* testsuite/std/format/string.cc: Likewise.
* testsuite/std/format/ranges/feature_test.cc: New test.

Reviewed-by: Jonathan Wakely 
Signed-off-by: Tomasz Kamiński 
(cherry picked from commit 049fefd7e1501ac9dcc66a5ef6c34cea0331dc43)

Diff:
---
 libstdc++-v3/include/bits/version.def| 3 +--
 libstdc++-v3/include/bits/version.h  | 3 ++-
 libstdc++-v3/src/c++23/std.cc.in | 6 ++
 libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc   | 2 +-
 libstdc++-v3/testsuite/std/format/parse_ctx.cc   | 2 +-
 libstdc++-v3/testsuite/std/format/ranges/feature_test.cc | 9 +
 libstdc++-v3/testsuite/std/format/string.cc  | 2 +-
 7 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/libstdc++-v3/include/bits/version.def 
b/libstdc++-v3/include/bits/version.def
index 0afaf0dec244..737b3f421bf7 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -1416,9 +1416,8 @@ ftms = {
   // 202207 P2286R8 Formatting Ranges
   // 202207 P2585R1 Improving default container formatting
   // LWG3750 Too many papers bump __cpp_lib_format
-  no_stdname = true; // TODO remove
   values = {
-v = 1; // TODO 202207
+v = 202207;
 cxxmin = 23;
 hosted = yes;
   };
diff --git a/libstdc++-v3/include/bits/version.h 
b/libstdc++-v3/include/bits/version.h
index 980fee641e9d..59ff0cee0436 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -1562,8 +1562,9 @@
 
 #if !defined(__cpp_lib_format_ranges)
 # if (__cplusplus >= 202100L) && _GLIBCXX_HOSTED
-#  define __glibcxx_format_ranges 1L
+#  define __glibcxx_format_ranges 202207L
 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_format_ranges)
+#   define __cpp_lib_format_ranges 202207L
 #  endif
 # endif
 #endif /* !defined(__cpp_lib_format_ranges) && 
defined(__glibcxx_want_format_ranges) */
diff --git a/libstdc++-v3/src/c++23/std.cc.in b/libstdc++-v3/src/c++23/std.cc.in
index 5e18ad739083..6da6d3829149 100644
--- a/libstdc++-v3/src/c++23/std.cc.in
+++ b/libstdc++-v3/src/c++23/std.cc.in
@@ -1315,8 +1315,7 @@ export namespace std
   using std::format_to_n;
   using std::format_to_n_result;
   using std::formatted_size;
-// FIXME __cpp_lib_format_ranges
-#if __cplusplus > 202002L
+#if __cpp_lib_format_ranges
   using std::formattable;
 #endif
   using std::formatter;
@@ -1332,8 +1331,7 @@ export namespace std
   using std::wformat_context;
   using std::wformat_parse_context;
   using std::wformat_string;
-// FIXME __cpp_lib_format_ranges
-#ifdef __glibcxx_format_ranges
+#ifdef __cpp_lib_format_ranges
   using std::format_kind;
   using std::range_format;
   using std::range_formatter;
diff --git a/libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc 
b/libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc
index 1f3edc9cb030..07e63af56529 100644
--- a/libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc
+++ b/libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc
@@ -18,7 +18,7 @@ void test_lwg3944()
   std::format(L"{}", "hello"); // { dg-error "here" }
   std::format(L"{}", std::string_view("hello")); // { dg-error "here" }
   std::format(L"{}", std::string("hello")); // { dg-error "here" }
-#ifdef __glibcxx_format_ranges
+#ifdef __cpp_lib_format_ranges
   // LWG 3944 does not change this, it's still valid.
   std::format(L"{}", std::vector{'h', 'e', 'l', 'l', 'o'});
 #endif
diff --git a/libstdc++-v3/testsuite/std/format/parse_ctx.cc 
b/libstdc++-v3/testsuite/std/format/parse_ctx.cc
index b338ac7b762d..b5dd7cdba782 100644
--- a/libstdc++-v3/testsuite/std/format/parse_ctx.cc
+++ b/libstdc++-v3/testsuite/std/format/parse_ctx.cc
@@ -108,7 +108,7 @@ is_std_format_spec_for(std::string_view spec)
   }
 }
 
-#if __glibcxx_format_ranges
+#if __cpp_lib_format_ranges
 constexpr bool escaped_strings_supported = true;
 #else
 constexpr bool escaped_strings_supported = false;
diff --git a/libstdc++-v

[gcc r16-127] Adjust 'libgomp.c++/target-exceptions-pr118794-1.C' for 'targetm.arm_eabi_unwinder' [PR118794]

2025-04-25 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:8a1f5424b04130f88e9dcd5cbecd58300bc5166e

commit r16-127-g8a1f5424b04130f88e9dcd5cbecd58300bc5166e
Author: Thomas Schwinge 
Date:   Tue Apr 22 13:41:22 2025 +0200

Adjust 'libgomp.c++/target-exceptions-pr118794-1.C' for 
'targetm.arm_eabi_unwinder' [PR118794]

Fix-up for commit aa3e72f943032e5f074b2bd2fd06d130dda8760b
"Add test cases for exception handling constructs in dead code for GCN, 
nvptx target and OpenMP 'target' offloading [PR118794]":
we need to adjust for configurations with 'targetm.arm_eabi_unwinder', as 
per:

gcc/config/arm/arm.cc:#define TARGET_ARM_EABI_UNWINDER true
gcc/config/c6x/c6x.cc:#define TARGET_ARM_EABI_UNWINDER true

..., which for ARM is conditional to '#if ARM_UNWIND_INFO' (defined in
'gcc/config/arm/bpabi.h', used for various GCC configurations), and for
C6x unconditional.

This gets us:

--- target-exceptions-pr118794-1.C.269t.optimized
+++ target-exceptions-pr118794-1.C.270t.optimized
[...]
 __attribute__((omp declare target))
 void f ()
[...]
   gimple_call <__dt_comp , NULL, &c>
-  gimple_call <__builtin_eh_pointer, _7, 2>
-  gimple_call <__builtin_unwind_resume, NULL, _7>
+  gimple_call <__builtin_cxa_end_cleanup, NULL>

 }
[...]

PR target/118794
libgomp/
* testsuite/libgomp.c++/target-exceptions-pr118794-1.C: Adjust for
'targetm.arm_eabi_unwinder'.
* 
testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C:
Likewise.
* 
testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-nvptx.C:
Likewise.

Diff:
---
 .../libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C| 6 --
 .../libgomp.c++/target-exceptions-pr118794-1-offload-sorry-nvptx.C  | 6 --
 libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1.C| 6 --
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git 
a/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C
 
b/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C
index 3cdedf48529e..d4dccf167fbb 100644
--- 
a/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C
+++ 
b/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-GCN.C
@@ -14,8 +14,10 @@
 
 /* In this specific C++ arrangement, distilled from PR118794, GCC synthesizes
'__builtin_eh_pointer', '__builtin_unwind_resume' calls as dead code in 'f':
-   { dg-final { scan-tree-dump-times {gimple_call <__builtin_eh_pointer, } 1 
optimized } }
-   { dg-final { scan-tree-dump-times {gimple_call <__builtin_unwind_resume, } 
1 optimized } }
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_eh_pointer, } 1 
optimized { target { ! { arm_eabi || tic6x-*-* } } } } }
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_unwind_resume, } 
1 optimized { target { ! { arm_eabi || tic6x-*-* } } } } }
+   ..., just 'targetm.arm_eabi_unwinder' is different:
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_cxa_end_cleanup, 
} 1 optimized { target { arm_eabi || tic6x-*-* } } } }
{ dg-final { only_for_offload_target amdgcn-amdhsa 
scan-offload-tree-dump-times {gimple_call <__builtin_eh_pointer, } 1 optimized 
} }
{ dg-final { only_for_offload_target amdgcn-amdhsa 
scan-offload-tree-dump-times {gimple_call <__builtin_unwind_resume, } 1 
optimized } }
Given '-O0' and '-foffload-options=-mno-fake-exceptions', offload 
compilation fails:
diff --git 
a/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-nvptx.C
 
b/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-nvptx.C
index ef996cfff7fa..724e34bd9234 100644
--- 
a/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-nvptx.C
+++ 
b/libgomp/testsuite/libgomp.c++/target-exceptions-pr118794-1-offload-sorry-nvptx.C
@@ -14,8 +14,10 @@
 
 /* In this specific C++ arrangement, distilled from PR118794, GCC synthesizes
'__builtin_eh_pointer', '__builtin_unwind_resume' calls as dead code in 'f':
-   { dg-final { scan-tree-dump-times {gimple_call <__builtin_eh_pointer, } 1 
optimized } }
-   { dg-final { scan-tree-dump-times {gimple_call <__builtin_unwind_resume, } 
1 optimized } }
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_eh_pointer, } 1 
optimized { target { ! { arm_eabi || tic6x-*-* } } } } }
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_unwind_resume, } 
1 optimized { target { ! { arm_eabi || tic6x-*-* } } } } }
+   ..., just 'targetm.arm_eabi_unwinder' is different:
+   { dg-final { scan-tree-dump-times {gimple_call <__builtin_cxa_end_cleanup, 
} 1 optimized { target { arm_eabi || tic6x-*-* } } } }
{ dg-final { only_for_offload_target nvptx-none 
scan-offload-tree-dump-times {gimple_call <__b

[gcc r16-131] libstdc++: Add _M_key_compare helper to associative containers

2025-04-25 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:876d1a22dfaf873d167bd2ffad190a1d07a81b22

commit r16-131-g876d1a22dfaf873d167bd2ffad190a1d07a81b22
Author: Jonathan Wakely 
Date:   Thu Apr 24 14:58:58 2025 +0100

libstdc++: Add _M_key_compare helper to associative containers

In r10-452-ge625ccc21a91f3 I noted that we don't have an accessor for
invoking _M_impl._M_key_compare in the associative containers. That
meant that the static assertions to check for valid comparison functions
were squirrelled away in _Rb_tree::_S_key instead. As Jason noted in
https://gcc.gnu.org/pipermail/gcc-patches/2025-April/681436.html this
means that the static assertions fail later than we'd like.

This change adds a new _Rb_tree::_M_key_compare member function which
invokes the _M_impl._M_key_compare function object, and then moves the
static_assert from _S_key into _M_key_compare. Now if the static_assert
fails, that's the first error we get, before the "no match for call" and
and "invalid conversion" errors.

Because the new function is const-qualified, we now treat LWG 2542 as a
DR for older standards, requiring the comparison function to be const
invocable. Previously we only enforced the LWG 2542 rule for C++17 and
later.

I did consider deprecating support for comparisons which aren't const
invocable, something like this:

  // Before LWG 2542 it wasn't strictly necessary for _Compare to be
  // const invocable, if you only used non-const container members.
  // Define a non-const overload for pre-C++17, deprecated for C++11/14.
  #if __cplusplus < 201103L
  bool
  _M_key_compare(const _Key& __k1, const _Key& __k2)
  { return _M_impl._M_key_compare(__k1, __k2); }
  #elif __cplusplus < 201703L
  template
[[__deprecated__("support for comparison functions that are not "
 "const invocable is deprecated")]]
__enable_if_t<
__and_<__is_invocable<_Compare&, const _Key1&, const _Key2&>,
   __not_<__is_invocable>>::value,
   bool>
_M_key_compare(const _Key1& __k1, const _Key2& __k2)
{
  static_assert(
__is_invocable<_Compare&, const _Key&, const _Key&>::value,
"comparison object must be invocable with two arguments of key type"
  );
  return _M_impl._M_key_compare(__k1, __k2);
}
  #endif

But I decided that this isn't necessary, because we've been enforcing
the C++17 rule since GCC 8.4 and 9.2, and C++17 has been the default
since GCC 11.1. Users have had plenty of time to fix their invalid
comparison functions.

libstdc++-v3/ChangeLog:

* include/bits/stl_tree.h (_Rb_tree::_M_key_compare): New member
function to invoke comparison function.
(_Rb_tree): Use new member function instead of accessing the
comparison function directly.

Reviewed-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/include/bits/stl_tree.h | 106 ---
 1 file changed, 49 insertions(+), 57 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_tree.h 
b/libstdc++-v3/include/bits/stl_tree.h
index 6b35f99a25a3..6caf937cca95 100644
--- a/libstdc++-v3/include/bits/stl_tree.h
+++ b/libstdc++-v3/include/bits/stl_tree.h
@@ -1390,27 +1390,25 @@ namespace __rb_tree
   _M_end() const _GLIBCXX_NOEXCEPT
   { return this->_M_impl._M_header._M_base_ptr(); }
 
-  static const _Key&
-  _S_key(const _Node& __node)
-  {
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 2542. Missing const requirements for associative containers
+  template
+   bool
+   _M_key_compare(const _Key1& __k1, const _Key2& __k2) const
+   {
 #if __cplusplus >= 201103L
-   // If we're asking for the key we're presumably using the comparison
-   // object, and so this is a good place to sanity check it.
-   static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{},
- "comparison object must be invocable "
- "with two arguments of key type");
-# if __cplusplus >= 201703L
-   // _GLIBCXX_RESOLVE_LIB_DEFECTS
-   // 2542. Missing const requirements for associative containers
-   if constexpr (__is_invocable<_Compare&, const _Key&, const _Key&>{})
+ // Enforce this here with a user-friendly message.
  static_assert(
- is_invocable_v,
- "comparison object must be invocable as const");
-# endif // C++17
-#endif // C++11
+   __is_invocable::value,
+   "comparison object must be invocable with two arguments of key type"
+ );
+#endif
+ return _M_impl._M_key_compare(__k1, __k2);
+   }
 
-   return _KeyOfValue()(*__node._M_valptr());
-  }
+  static const _Key&
+  _S_key(const _Node& __node)
+  { return _KeyOfValue()(*__node._M_valptr()); }
 
   stat

[gcc r16-132] libstdc++: Improve diagnostics for std::packaged_task invocable checks

2025-04-25 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:901900bc37566c59b4eb62c1427f3150b800d8a0

commit r16-132-g901900bc37566c59b4eb62c1427f3150b800d8a0
Author: Jonathan Wakely 
Date:   Thu Apr 24 21:55:16 2025 +0100

libstdc++: Improve diagnostics for std::packaged_task invocable checks

Moving the static_assert that checks is_invocable_r_v into _Task_state
means it is checked when we instantiate that class template.

Replacing the __create_task_state function with a static member function
_Task_state::_S_create ensures we instantiate _Task_state and trigger
the static_assert immediately, not deep inside the implementation of
std::allocate_shared. This results in shorter diagnostics that don't
show deeply-nested template instantiations before the static_assert
failure.

Placing the static_assert at class scope also helps us to fail earlier
than waiting until when the _Task_state::_M_run virtual function is
instantiated. That also makes the diagnostics shorter and easier to read
(although for C++11 and C++14 modes the class-scope static_assert
doesn't check is_invocable_r, so dangling references aren't detected
until _M_run is instantiated).

libstdc++-v3/ChangeLog:

* include/std/future (__future_base::_Task_state): Check
invocable requirement here.
(__future_base::_Task_state::_S_create): New static member
function.
(__future_base::_Task_state::_M_reset): Use _S_create.
(__create_task_state): Remove.
(packaged_task): Use _Task_state::_S_create instead of
__create_task_state.
* testsuite/30_threads/packaged_task/cons/dangling_ref.cc:
Adjust dg-error patterns.
* testsuite/30_threads/packaged_task/cons/lwg4154_neg.cc:
Likewise.

Reviewed-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/include/std/future| 66 +++---
 .../30_threads/packaged_task/cons/dangling_ref.cc  |  3 +-
 .../30_threads/packaged_task/cons/lwg4154_neg.cc   | 10 ++--
 3 files changed, 38 insertions(+), 41 deletions(-)

diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future
index b7ab233b85f0..080690064a91 100644
--- a/libstdc++-v3/include/std/future
+++ b/libstdc++-v3/include/std/future
@@ -1486,12 +1486,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 struct __future_base::_Task_state<_Fn, _Alloc, _Res(_Args...)> final
 : __future_base::_Task_state_base<_Res(_Args...)>
 {
+#ifdef __cpp_lib_is_invocable // C++ >= 17
+  static_assert(is_invocable_r_v<_Res, _Fn&, _Args...>);
+#else
+  static_assert(__is_invocable<_Fn&, _Args...>::value,
+   "_Fn& is invocable with _Args...");
+#endif
+
   template
_Task_state(_Fn2&& __fn, const _Alloc& __a)
: _Task_state_base<_Res(_Args...)>(__a),
  _M_impl(std::forward<_Fn2>(__fn), __a)
{ }
 
+  template
+   static shared_ptr<_Task_state_base<_Res(_Args...)>>
+   _S_create(_Fn2&& __fn, const _Alloc& __a)
+   {
+ return std::allocate_shared<_Task_state>(__a,
+  std::forward<_Fn2>(__fn),
+  __a);
+   }
+
 private:
   virtual void
   _M_run(_Args&&... __args)
@@ -1515,7 +1531,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 
   virtual shared_ptr<_Task_state_base<_Res(_Args...)>>
-  _M_reset();
+  _M_reset()
+  { return _S_create(std::move(_M_impl._M_fn), _M_impl); }
 
   struct _Impl : _Alloc
   {
@@ -1525,38 +1542,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Fn _M_fn;
   } _M_impl;
 };
-
-  template>
-shared_ptr<__future_base::_Task_state_base<_Signature>>
-__create_task_state(_Fn&& __fn, const _Alloc& __a = _Alloc())
-{
-  typedef typename decay<_Fn>::type _Fn2;
-  typedef __future_base::_Task_state<_Fn2, _Alloc, _Signature> _State;
-  return std::allocate_shared<_State>(__a, std::forward<_Fn>(__fn), __a);
-}
-
-  template
-shared_ptr<__future_base::_Task_state_base<_Res(_Args...)>>
-__future_base::_Task_state<_Fn, _Alloc, _Res(_Args...)>::_M_reset()
-{
-  return __create_task_state<_Res(_Args...)>(std::move(_M_impl._M_fn),
-static_cast<_Alloc&>(_M_impl));
-}
   /// @endcond
 
   /// packaged_task
   template
 class packaged_task<_Res(_ArgTypes...)>
 {
-  typedef __future_base::_Task_state_base<_Res(_ArgTypes...)> _State_type;
+  using _State_type = __future_base::_Task_state_base<_Res(_ArgTypes...)>;
   shared_ptr<_State_type>   _M_state;
 
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
   // 3039. Unnecessary decay in thread and packaged_task
   template>
-   using __not_same
- = typename enable_if::value>::type;
+   using __not_same = __enable_if_t::value>;
+
+  // _GLIB

[gcc r16-133] c++: bad pending_template recursion

2025-04-25 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:8acea9ffa82ed84bbf15d75b9dd034b2bb82724e

commit r16-133-g8acea9ffa82ed84bbf15d75b9dd034b2bb82724e
Author: Jason Merrill 
Date:   Fri Apr 18 18:00:34 2025 -0400

c++: bad pending_template recursion

limit_bad_template_recursion currently avoids immediate instantiation of
templates from uses in an already ill-formed instantiation, but we still can
get unnecessary recursive instantiation in pending_templates if the
instantiation was queued before the error.

Initially this regressed several libstdc++ tests which seemed to rely on a
static_assert in a function called from another that is separately 
ill-formed.
For instance, in the 48101_neg.cc tests, we first got an error in find(), 
then
later instantiate _S_key() (called from find) and got the static_assert 
error
from there. r16-131-g876d1a22dfaf87 and r16-132-g901900bc37566c changed
the library code (and tests) to make the expected static_assert errors
happen earlier.

gcc/cp/ChangeLog:

* cp-tree.h (struct tinst_level): Add had_errors bit.
* pt.cc (push_tinst_level_loc): Clear it.
(pop_tinst_level): Set it.
(reopen_tinst_level): Check it.
(instantiate_pending_templates): Call limit_bad_template_recursion.

gcc/testsuite/ChangeLog:

* g++.dg/template/recurse5.C: New test.

Diff:
---
 gcc/cp/cp-tree.h | 10 --
 gcc/cp/pt.cc | 10 --
 gcc/testsuite/g++.dg/template/recurse5.C | 17 +
 3 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 7798efba3dba..856202c65dd6 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -6755,8 +6755,14 @@ struct GTY((chain_next ("%h.next"))) tinst_level {
   /* The location where the template is instantiated.  */
   location_t locus;
 
-  /* errorcount + sorrycount when we pushed this level.  */
-  unsigned short errors;
+  /* errorcount + sorrycount when we pushed this level.  If the value
+ overflows, it will always seem like we currently have more errors, so we
+ will limit template recursion even from non-erroneous templates.  In a TU
+ with over 32k errors, that's fine.  */
+  unsigned short errors : 15;
+
+  /* set in pop_tinst_level if there have been errors since we pushed.  */
+  bool had_errors : 1;
 
   /* Count references to this object.  If refcount reaches
  refcount_infinity value, we don't increment or decrement the
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index a71705fd085b..e8d342f99f6d 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -11418,6 +11418,7 @@ push_tinst_level_loc (tree tldcl, tree targs, 
location_t loc)
   new_level->targs = targs;
   new_level->locus = loc;
   new_level->errors = errorcount + sorrycount;
+  new_level->had_errors = false;
   new_level->next = NULL;
   new_level->refcount = 0;
   new_level->path = new_level->visible = nullptr;
@@ -11468,6 +11469,9 @@ pop_tinst_level (void)
   /* Restore the filename and line number stashed away when we started
  this instantiation.  */
   input_location = current_tinst_level->locus;
+  if (unsigned errs = errorcount + sorrycount)
+if (errs > current_tinst_level->errors)
+  current_tinst_level->had_errors = true;
   set_refcount_ptr (current_tinst_level, current_tinst_level->next);
   --tinst_depth;
 }
@@ -11487,7 +11491,7 @@ reopen_tinst_level (struct tinst_level *level)
 
   set_refcount_ptr (current_tinst_level, level);
   pop_tinst_level ();
-  if (current_tinst_level)
+  if (current_tinst_level && !current_tinst_level->had_errors)
 current_tinst_level->errors = errorcount+sorrycount;
 
   tree decl = level->maybe_get_node ();
@@ -28072,7 +28076,9 @@ instantiate_pending_templates (int retries)
  tree instantiation = reopen_tinst_level ((*t)->tinst);
  bool complete = false;
 
- if (TYPE_P (instantiation))
+ if (limit_bad_template_recursion (instantiation))
+   /* Do nothing.  */;
+ else if (TYPE_P (instantiation))
{
  if (!COMPLETE_TYPE_P (instantiation))
{
diff --git a/gcc/testsuite/g++.dg/template/recurse5.C 
b/gcc/testsuite/g++.dg/template/recurse5.C
new file mode 100644
index ..7bfe5239f0a4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/recurse5.C
@@ -0,0 +1,17 @@
+// Test that we don't bother to instantiate add since there were errors in
+// checked_add.
+
+template  T add (T t) { return t+1; } // { dg-bogus "no match" }
+
+template  T checked_add (T t)
+{
+  add (t);
+  return t+1;  // { dg-error "no match" }
+}
+
+struct A { };
+
+int main()
+{
+  checked_add (A());
+}


[gcc r15-9586] rs6000: Ignore OPTION_MASK_SAVE_TOC_INDIRECT differences in inlining decisions [PR119327]

2025-04-25 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:00cc9725634f5547bbe29e0b7f94b87d0fe03e4b

commit r15-9586-g00cc9725634f5547bbe29e0b7f94b87d0fe03e4b
Author: Jakub Jelinek 
Date:   Tue Apr 22 21:27:28 2025 +0200

rs6000: Ignore OPTION_MASK_SAVE_TOC_INDIRECT differences in inlining 
decisions [PR119327]

The following testcase FAILs because the always_inline function can't
be inlined.
The rs6000 backend has similarly to other targets a hook which rejects
inlining which would bring in new ISAs which aren't there in the caller.
And this hook rejects this because of OPTION_MASK_SAVE_TOC_INDIRECT
differences.
This flag is set if explicitly requested or by default depending on
whether the current function looks hot (or at least not cold):
  if ((rs6000_isa_flags_explicit & OPTION_MASK_SAVE_TOC_INDIRECT) == 0
  && flag_shrink_wrap_separate
  && optimize_function_for_speed_p (cfun))
rs6000_isa_flags |= OPTION_MASK_SAVE_TOC_INDIRECT;
The target nodes that are being compared here are actually the default
target node (which was created when cfun was NULL) vs. one that was
created for the always_inline function when it wasn't NULL, so one
doesn't have it, the other does.
In any case, this flag feels like a tuning decision rather than hard
ISA requirement and I see no problems why we couldn't inline
even explicit -msave-toc-indirect function into -mno-save-toc-indirect
or vice versa.
We already ignore OPTION_MASK_P{8,10}_FUSION which are also more
like tuning flags.

2025-04-22  Jakub Jelinek  

PR target/119327
* config/rs6000/rs6000.cc (rs6000_can_inline_p): Ignore also
OPTION_MASK_SAVE_TOC_INDIRECT differences.

* g++.dg/opt/pr119327.C: New test.

(cherry picked from commit 4b62cf555b5446cb02fc471519cf1afa09e1a108)

Diff:
---
 gcc/config/rs6000/rs6000.cc | 11 +++
 gcc/testsuite/g++.dg/opt/pr119327.C | 16 
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 737c3d6f7c75..12dbde2bc630 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -25765,10 +25765,13 @@ rs6000_can_inline_p (tree caller, tree callee)
}
 }
 
-  /* Ignore -mpower8-fusion and -mpower10-fusion options for inlining
- purposes.  */
-  callee_isa &= ~(OPTION_MASK_P8_FUSION | OPTION_MASK_P10_FUSION);
-  explicit_isa &= ~(OPTION_MASK_P8_FUSION | OPTION_MASK_P10_FUSION);
+  /* Ignore -mpower8-fusion, -mpower10-fusion and -msave-toc-indirect options
+ for inlining purposes.  */
+  HOST_WIDE_INT ignored_isas = (OPTION_MASK_P8_FUSION
+   | OPTION_MASK_P10_FUSION
+   | OPTION_MASK_SAVE_TOC_INDIRECT);
+  callee_isa &= ~ignored_isas;
+  explicit_isa &= ~ignored_isas;
 
   /* The callee's options must be a subset of the caller's options, i.e.
  a vsx function may inline an altivec function, but a no-vsx function
diff --git a/gcc/testsuite/g++.dg/opt/pr119327.C 
b/gcc/testsuite/g++.dg/opt/pr119327.C
new file mode 100644
index ..598ae1c8bfeb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr119327.C
@@ -0,0 +1,16 @@
+// PR target/119327
+// { dg-do compile { target c++11 } }
+// { dg-options "-Os" }
+
+#pragma GCC optimize "fp-contract=off"
+
+template 
+void
+foo (T f)
+{
+  f ();
+}
+
+struct S {
+  S () { [] {}; foo ([] __attribute__((always_inline)) {}); }
+} s;


[gcc r16-140] modulo-sched: reject loop conditions when not decrementing with one [PR 116479]

2025-04-25 Thread Andre Simoes Dias Vieira via Gcc-cvs
https://gcc.gnu.org/g:8073fa147248aa67c11227f922d91d784659077e

commit r16-140-g8073fa147248aa67c11227f922d91d784659077e
Author: Andre Vieira 
Date:   Fri Apr 25 14:02:43 2025 +0100

modulo-sched: reject loop conditions when not decrementing with one [PR 
116479]

In the commit titled 'doloop: Add support for predicated vectorized loops' 
the
doloop_condition_get function was changed to accept loops with decrements
larger than 1.  This patch rejects such loops for modulo-sched.

gcc/ChangeLog:

PR rtl-optimization/116479
* modulo-sched.cc (doloop_register_get): Reject conditions with
decrements that are not 1.

gcc/testsuite/ChangeLog:

* gcc.dg/pr116479.c: New test.

Diff:
---
 gcc/modulo-sched.cc |  8 +++-
 gcc/testsuite/gcc.dg/pr116479.c | 26 ++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/gcc/modulo-sched.cc b/gcc/modulo-sched.cc
index 08af5a929e14..002346778f44 100644
--- a/gcc/modulo-sched.cc
+++ b/gcc/modulo-sched.cc
@@ -356,7 +356,13 @@ doloop_register_get (rtx_insn *head, rtx_insn *tail)
 reg = XEXP (condition, 0);
   else if (GET_CODE (XEXP (condition, 0)) == PLUS
   && REG_P (XEXP (XEXP (condition, 0), 0)))
-reg = XEXP (XEXP (condition, 0), 0);
+{
+  if (CONST_INT_P (XEXP (condition, 1))
+ && INTVAL (XEXP (condition, 1)) == -1)
+   reg = XEXP (XEXP (condition, 0), 0);
+  else
+   return NULL_RTX;
+}
   else
 gcc_unreachable ();
 
diff --git a/gcc/testsuite/gcc.dg/pr116479.c b/gcc/testsuite/gcc.dg/pr116479.c
new file mode 100644
index ..dbbcb9aaf575
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116479.c
@@ -0,0 +1,26 @@
+/* PR 116479 */
+/* { dg-do run { target { bitint } } } */
+/* { dg-additional-options "-O -funroll-loops -finline-stringops 
-fmodulo-sched --param=max-iterations-computation-cost=637924687 -std=c23" } */
+
+#if __BITINT_MAXWIDTH__ >= 13577
+_BitInt (13577) b;
+
+void
+foo (char *ret)
+{
+  __builtin_memset (&b, 4, 697);
+  *ret = 0;
+}
+#endif
+
+int
+main ()
+{
+#if __BITINT_MAXWIDTH__ >= 13577
+  char x;
+  foo (&x);
+  for (unsigned i = 0; i < sizeof (x); i++)
+if (x != 0)
+  __builtin_abort ();
+#endif
+}


[gcc r16-148] c++: add -fabi-version=21

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

commit r16-148-gb13bb5045c5010f38169b9786819a024f64fb59d
Author: Jason Merrill 
Date:   Tue Apr 22 16:37:30 2025 -0400

c++: add -fabi-version=21

I'm about to add a bugfix that changes the ABI of noexcept lambdas, so first
let's add the new ABI version.  And I think it's time to update the
compatibility version; let's bump to GCC 13, before the addition of concepts
mangling.

gcc/ChangeLog:

* common.opt: Add ABI v21.

gcc/c-family/ChangeLog:

* c-opts.cc (c_common_post_options): Bump default ABI to 21
and compat ABI to 18.

gcc/testsuite/ChangeLog:

* g++.dg/abi/macro0.C: Update for -fabi-version=21.

Diff:
---
 gcc/common.opt| 3 +++
 gcc/c-family/c-opts.cc| 6 +++---
 gcc/testsuite/g++.dg/abi/macro0.C | 2 +-
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index e3fa0dacec4c..d10a6b7e533a 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1061,6 +1061,9 @@ Driver Undocumented
 ; 20: Fix mangling of lambdas in static data member initializers.
 ; Default in G++ 15.
 ;
+; 21:
+; Default in G++ 16.
+;
 ; Additional positive integers will be assigned as new versions of
 ; the ABI become the default version of the ABI.
 fabi-version=
diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index d43b3aef1024..40163821948b 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -1084,9 +1084,9 @@ c_common_post_options (const char **pfilename)
 
   /* Change flag_abi_version to be the actual current ABI level, for the
  benefit of c_cpp_builtins, and to make comparison simpler.  */
-  const int latest_abi_version = 20;
-  /* Generate compatibility aliases for ABI v13 (8.2) by default.  */
-  const int abi_compat_default = 13;
+  const int latest_abi_version = 21;
+  /* Generate compatibility aliases for ABI v18 (GCC 13) by default.  */
+  const int abi_compat_default = 18;
 
 #define clamp(X) if (X == 0 || X > latest_abi_version) X = latest_abi_version
   clamp (flag_abi_version);
diff --git a/gcc/testsuite/g++.dg/abi/macro0.C 
b/gcc/testsuite/g++.dg/abi/macro0.C
index f6a57c11ae70..3dd44fcbae90 100644
--- a/gcc/testsuite/g++.dg/abi/macro0.C
+++ b/gcc/testsuite/g++.dg/abi/macro0.C
@@ -1,6 +1,6 @@
 // This testcase will need to be kept in sync with c_common_post_options.
 // { dg-options "-fabi-version=0" }
 
-#if __GXX_ABI_VERSION != 1020
+#if __GXX_ABI_VERSION != 1021
 #error "Incorrect value of __GXX_ABI_VERSION"
 #endif


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression auto_char_dummy_array_3

2025-04-25 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:20f2e28a0de001cce1518fb847eb6a58e6521e9a

commit 20f2e28a0de001cce1518fb847eb6a58e6521e9a
Author: Mikael Morin 
Date:   Fri Apr 25 11:46:54 2025 +0200

Correction régression auto_char_dummy_array_3

Diff:
---
 gcc/fortran/trans-array.cc | 29 +++--
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 0b0fcb36c8ea..b6688af5953d 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -6266,15 +6266,6 @@ gfc_trans_auto_array_allocation (tree decl, gfc_symbol * 
sym,
}
 }
 
-  if (onstack)
-{
-  gfc_add_init_cleanup (block, gfc_finish_block (&init), NULL_TREE,
-   back);
-  return;
-}
-
-  type = TREE_TYPE (type);
-
   gcc_assert (!sym->attr.use_assoc);
   gcc_assert (!sym->module);
 
@@ -6282,17 +6273,23 @@ gfc_trans_auto_array_allocation (tree decl, gfc_symbol 
* sym,
   && !INTEGER_CST_P (sym->ts.u.cl->backend_decl))
 gfc_conv_string_length (sym->ts.u.cl, NULL, &init);
 
+  if (!onstack)
+type = TREE_TYPE (type);
+
   size = gfc_trans_array_bounds (type, sym, &offset, &init);
 
+  /* Set offset of the array.  */
+  if (VAR_P (GFC_TYPE_ARRAY_OFFSET (type)))
+gfc_add_modify (&init, GFC_TYPE_ARRAY_OFFSET (type), offset);
+
   /* Don't actually allocate space for Cray Pointees.  */
-  if (sym->attr.cray_pointee)
+  if (onstack || sym->attr.cray_pointee)
 {
-  if (VAR_P (GFC_TYPE_ARRAY_OFFSET (type)))
-   gfc_add_modify (&init, GFC_TYPE_ARRAY_OFFSET (type), offset);
-
-  gfc_add_init_cleanup (block, gfc_finish_block (&init), NULL_TREE);
+  gfc_add_init_cleanup (block, gfc_finish_block (&init), NULL_TREE,
+   onstack && back);
   return;
 }
+
   if (sym->attr.omp_allocate)
 {
   size = gfc_evaluate_now (size, &init);
@@ -6322,10 +6319,6 @@ gfc_trans_auto_array_allocation (tree decl, gfc_symbol * 
sym,
   space = NULL_TREE;
 }
 
-  /* Set offset of the array.  */
-  if (VAR_P (GFC_TYPE_ARRAY_OFFSET (type)))
-gfc_add_modify (&init, GFC_TYPE_ARRAY_OFFSET (type), offset);
-
   /* Automatic arrays should not have initializers.  */
   gcc_assert (!sym->value);


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression repack_arrays_1

2025-04-25 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:e2cf3a9b8827810f5db6ec53acc193a50dff8923

commit e2cf3a9b8827810f5db6ec53acc193a50dff8923
Author: Mikael Morin 
Date:   Fri Apr 25 15:51:31 2025 +0200

Correction régression repack_arrays_1

Diff:
---
 gcc/fortran/trans-array.cc | 6 ++
 gcc/fortran/trans-decl.cc  | 4 +++-
 gcc/fortran/trans-types.cc | 2 +-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index b6688af5953d..e32f92387d60 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -6276,6 +6276,12 @@ gfc_trans_auto_array_allocation (tree decl, gfc_symbol * 
sym,
   if (!onstack)
 type = TREE_TYPE (type);
 
+  if (!GFC_TYPE_ARRAY_ELEM_LEN (type))
+{
+  gfc_add_init_cleanup (block, gfc_finish_block (&init), NULL_TREE);
+  return;
+}
+
   size = gfc_trans_array_bounds (type, sym, &offset, &init);
 
   /* Set offset of the array.  */
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 067a33c2994f..80c00d132b2a 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -1258,7 +1258,9 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym)
   suppress_warning (GFC_TYPE_ARRAY_SIZE (type));
 }
 
-  if (! COMPLETE_TYPE_P (type) && GFC_TYPE_ARRAY_SIZE (type))
+  if (! COMPLETE_TYPE_P (type)
+  && GFC_TYPE_ARRAY_SIZE (type)
+  && GFC_DECL_PACKED_ARRAY (decl))
 {
   tree size, range;
 
diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index 92d592f52f12..d67a64b363ab 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -1866,7 +1866,7 @@ gfc_get_nodesc_array_type (tree etype, gfc_array_spec * 
as, gfc_packed packed,
   mpz_init_set_ui (stride, 1);
   mpz_init (spc);
 
-  bool known_spacing = INTEGER_CST_P (TYPE_SIZE_UNIT (etype));
+  bool known_spacing = packed != PACKED_NO && INTEGER_CST_P (TYPE_SIZE_UNIT 
(etype));
   if (known_spacing)
 {
   wide_int elem_len = wi::to_wide (TYPE_SIZE_UNIT (etype));


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression derived_comp_array_ref_7

2025-04-25 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:c1f4971573c1d070f3e4af5a00d571f7d680a294

commit c1f4971573c1d070f3e4af5a00d571f7d680a294
Author: Mikael Morin 
Date:   Fri Apr 25 17:54:23 2025 +0200

Correction régression derived_comp_array_ref_7

Diff:
---
 gcc/fortran/trans-expr.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 709a5420aae6..364123ce3ed5 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -9218,7 +9218,8 @@ gfc_trans_subarray_assign (tree dest, gfc_component * cm, 
gfc_expr * expr)
   lss_array->offset = gfc_conv_array_offset (dest);
   for (n = 0; n < cm->as->rank; n++)
 {
-  lss_array->start[n] = gfc_conv_array_lbound (dest, n);
+  lss_array->start[n] = lss_array->lbound[n] = gfc_conv_array_lbound 
(dest, n);
+  lss_array->spacing[n] = gfc_conv_array_spacing (dest, n);
   lss_array->stride[n] = gfc_index_one_node;
 
   mpz_init (lss_array->shape[n]);


[gcc/devel/omp/gcc-14] OpenMP: Constructors and destructors for "declare target" static aggregates: Fix effective-target ke

2025-04-25 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:8b55d116b8f4c19696e534fb3a850a9beac396c4

commit 8b55d116b8f4c19696e534fb3a850a9beac396c4
Author: Thomas Schwinge 
Date:   Fri Aug 9 11:23:15 2024 +0200

OpenMP: Constructors and destructors for "declare target" static 
aggregates: Fix effective-target keyword in test cases

(Most of) the tests added in commit f1bfba3a9b3f31e3e06bfd1911c9f223869ea03f
"OpenMP: Constructors and destructors for "declare target" static 
aggregates"
had a mismatch between dump file production and its scanning; the former 
needs
to use 'offload_target_nvptx' (like 'offload_target_amdgcn'), not
'offload_device_nvptx'.

libgomp/
* testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C:
Fix effective-target keyword.
* testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C:
Likewise.
* testsuite/libgomp.c-c++-common/target-is-initial-host-2.c:
Likewise.
* testsuite/libgomp.c-c++-common/target-is-initial-host.c:
Likewise.
* testsuite/libgomp.fortran/target-is-initial-host-2.f90:
Likewise.
* testsuite/libgomp.fortran/target-is-initial-host.f: Likewise.
* testsuite/libgomp.fortran/target-is-initial-host.f90: Likewise.

(cherry picked from commit 9f5d22e3e2b8e4532896a4f3837cb86006d5930c)

Diff:
---
 libgomp/ChangeLog.omp| 16 
 .../libgomp.c++/static-aggr-constructor-destructor-1.C   |  2 +-
 .../libgomp.c++/static-aggr-constructor-destructor-2.C   |  2 +-
 .../libgomp.c-c++-common/target-is-initial-host-2.c  |  2 +-
 .../libgomp.c-c++-common/target-is-initial-host.c|  2 +-
 .../libgomp.fortran/target-is-initial-host-2.f90 |  2 +-
 .../testsuite/libgomp.fortran/target-is-initial-host.f   |  2 +-
 .../testsuite/libgomp.fortran/target-is-initial-host.f90 |  2 +-
 8 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 09cc7278e191..94dcb8e1a36d 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,5 +1,21 @@
 2025-04-25  Thomas Schwinge  
 
+   Backported from trunk:
+   2024-08-09  Thomas Schwinge  
+
+   * testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C:
+   Fix effective-target keyword.
+   * testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C:
+   Likewise.
+   * testsuite/libgomp.c-c++-common/target-is-initial-host-2.c:
+   Likewise.
+   * testsuite/libgomp.c-c++-common/target-is-initial-host.c:
+   Likewise.
+   * testsuite/libgomp.fortran/target-is-initial-host-2.f90:
+   Likewise.
+   * testsuite/libgomp.fortran/target-is-initial-host.f: Likewise.
+   * testsuite/libgomp.fortran/target-is-initial-host.f90: Likewise.
+
Backported from trunk:
2024-08-08  Tobias Burnus  
 
diff --git 
a/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C 
b/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C
index b5aafc8cabc2..a704e39411da 100644
--- a/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C
+++ b/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-1.C
@@ -1,6 +1,6 @@
 // { dg-do run }
 // { dg-additional-options "-fdump-tree-gimple -fdump-tree-optimized" }
-// { dg-additional-options -foffload-options=-fdump-tree-optimized { target { 
offload_device_nvptx || offload_target_amdgcn } } }
+// { dg-additional-options -foffload-options=-fdump-tree-optimized { target { 
offload_target_nvptx || offload_target_amdgcn } } }
 
 // { dg-final { scan-tree-dump-times "omp_is_initial_device" 1 "gimple" } }
 // { dg-final { scan-tree-dump-times "_GLOBAL__off_I_v1" 1 "gimple" } }
diff --git 
a/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C 
b/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C
index 9652a721bbe2..de481aadd34e 100644
--- a/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C
+++ b/libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-2.C
@@ -1,6 +1,6 @@
 // { dg-do run }
 // { dg-additional-options "-fdump-tree-gimple -fdump-tree-optimized" }
-// { dg-additional-options -foffload-options=-fdump-tree-optimized { target { 
offload_device_nvptx || offload_target_amdgcn } } }
+// { dg-additional-options -foffload-options=-fdump-tree-optimized { target { 
offload_target_nvptx || offload_target_amdgcn } } }
 
 // { dg-final { scan-tree-dump-times "omp_is_initial_device" 1 "gimple" } }
 // { dg-final { scan-tree-dump-times "_GLOBAL__off_I_v1" 1 "gimple" } }
diff --git a/libgomp/testsuite/libgomp.c-c++-common/target-is-initial-host-2.c 
b/libgomp/testsuite/libgomp.c-c++-common/target-is-initial-host-2.c
index 313d188a871a..eabc394c8cf8 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/target-is-initial-host-2.c
+++ b/libgomp/testsuite/libgomp.c-c++-commo

[gcc r16-151] gimple: Fix comment before gimple_cond_make_false/gimple_cond_make_true

2025-04-25 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:996729efbf6d0dd9684f5e598a0069d20d3bc26b

commit r16-151-g996729efbf6d0dd9684f5e598a0069d20d3bc26b
Author: Andrew Pinski 
Date:   Wed Apr 23 13:48:16 2025 -0700

gimple: Fix comment before gimple_cond_make_false/gimple_cond_make_true

I noticed the comments and the code don't match.
The correct form is:
'if (0 != 0)': false
and
'if (1 != 0)': true

That is always NE and always 0 as the second operand.

Also there is a spello for statement in the comment in
front of gimple_cond_true_p.

Pushed as obvious.

gcc/ChangeLog:

* gimple.h (gimple_cond_make_false): Fix comment.
(gimple_cond_make_true): Likewise.
(gimple_cond_true_p): Fix spello for statement in comment.

Signed-off-by: Andrew Pinski 

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

diff --git a/gcc/gimple.h b/gcc/gimple.h
index 112e5ae472d0..7e3086f5632e 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -3829,7 +3829,7 @@ gimple_cond_false_label (const gcond *gs)
 }
 
 
-/* Set the conditional COND_STMT to be of the form 'if (1 == 0)'.  */
+/* Set the conditional COND_STMT to be of the form 'if (0 != 0)'.  */
 
 inline void
 gimple_cond_make_false (gcond *gs)
@@ -3840,7 +3840,7 @@ gimple_cond_make_false (gcond *gs)
 }
 
 
-/* Set the conditional COND_STMT to be of the form 'if (1 == 1)'.  */
+/* Set the conditional COND_STMT to be of the form 'if (1 != 0)'.  */
 
 inline void
 gimple_cond_make_true (gcond *gs)
@@ -3850,7 +3850,7 @@ gimple_cond_make_true (gcond *gs)
   gs->subcode = NE_EXPR;
 }
 
-/* Check if conditional statemente GS is of the form 'if (1 == 1)',
+/* Check if conditional statement GS is of the form 'if (1 == 1)',
   'if (0 == 0)', 'if (1 != 0)' or 'if (0 != 1)' */
 
 inline bool


[gcc r16-152] match: Move `(cmp (cond @0 @1 @2) @3)` simplification after the bool compare simplifcation

2025-04-25 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:4f7b3c241120169bca44f0eee22847c3ca334bab

commit r16-152-g4f7b3c241120169bca44f0eee22847c3ca334bab
Author: Andrew Pinski 
Date:   Tue Apr 22 15:13:39 2025 -0700

match: Move `(cmp (cond @0 @1 @2) @3)` simplification after the bool 
compare simplifcation

This moves the `(cmp (cond @0 @1 @2) @3)` simplifcation to be after the 
boolean comparison
simplifcations so that we don't end up simplifing into the same thing for a 
GIMPLE_COND.

gcc/ChangeLog:

* match.pd: Move `(cmp (cond @0 @1 @2) @3)` simplifcation after
the bool comparison simplifications.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/match.pd | 31 +--
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index ba036e528370..0fe90a6edc46 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -7759,20 +7759,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (cmp (bit_and@2 @0 integer_pow2p@1) @1)
   (icmp @2 { build_zero_cst (TREE_TYPE (@0)); })))
 
-#if GIMPLE
-/* From fold_binary_op_with_conditional_arg handle the case of
-   rewriting (a ? b : c) > d to a ? (b > d) : (c > d) when the
-   compares simplify.  */
-(for cmp (simple_comparison)
- (simplify
-  (cmp:c (cond @0 @1 @2) @3)
-  /* Do not move possibly trapping operations into the conditional as this
- pessimizes code and causes gimplification issues when applied late.  */
-  (if (!FLOAT_TYPE_P (TREE_TYPE (@3))
-   || !operation_could_trap_p (cmp, true, false, @3))
-   (cond @0 (cmp! @1 @3) (cmp! @2 @3)
-#endif
-
 (for cmp (ge lt)
 /* x < 0 ? ~y : y into (x >> (prec-1)) ^ y. */
 /* x >= 0 ? ~y : y into ~((x >> (prec-1)) ^ y). */
@@ -8119,6 +8105,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
replace if (x == 0) with tem = ~x; if (tem != 0) which is
clearly less optimal and which we'll transform again in forwprop.  */
 
+#if GIMPLE
+/* From fold_binary_op_with_conditional_arg handle the case of
+   rewriting (a ? b : c) > d to a ? (b > d) : (c > d) when the
+   compares simplify.
+   This should be after the boolean comparison simplification so
+   that it can remove the outer comparison before appling it to
+   the inner condtional operands.  */
+(for cmp (simple_comparison)
+ (simplify
+  (cmp:c (cond @0 @1 @2) @3)
+  /* Do not move possibly trapping operations into the conditional as this
+ pessimizes code and causes gimplification issues when applied late.  */
+  (if (!FLOAT_TYPE_P (TREE_TYPE (@3))
+   || !operation_could_trap_p (cmp, true, false, @3))
+   (cond @0 (cmp! @1 @3) (cmp! @2 @3)
+#endif
+
 /* Transform comparisons of the form (X & Y) CMP 0 to X CMP2 Z
where ~Y + 1 == pow2 and Z = ~Y.  */
 (for cst (VECTOR_CST INTEGER_CST)


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression intent_out_14

2025-04-25 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:f47246af4ce670afb122bfe8fd73bdb9e32fd4f3

commit f47246af4ce670afb122bfe8fd73bdb9e32fd4f3
Author: Mikael Morin 
Date:   Fri Apr 25 21:06:48 2025 +0200

Correction régression intent_out_14

Diff:
---
 gcc/fortran/trans-array.cc | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index e32f92387d60..3c28052afb85 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -9782,6 +9782,10 @@ tree
 gfc_deallocate_alloc_comp (gfc_symbol * der_type, tree decl, int rank,
   int caf_mode)
 {
+  if (DECL_P (decl)
+  && DECL_LANG_SPECIFIC (decl)
+  && GFC_DECL_SAVED_DESCRIPTOR (decl))
+decl = GFC_DECL_SAVED_DESCRIPTOR (decl);
   return structure_alloc_comps (der_type, decl, NULL_TREE, rank,
DEALLOCATE_ALLOC_COMP,
GFC_STRUCTURE_CAF_MODE_ENABLE_COARRAY | 
caf_mode,


[gcc r16-158] testsuite: Skip tests incompatible with generic thunk support

2025-04-25 Thread Dimitar Dimitrov via Gcc-cvs
https://gcc.gnu.org/g:b1cb7a5e273eb3442259981216295d286a7892c7

commit r16-158-gb1cb7a5e273eb3442259981216295d286a7892c7
Author: Dimitar Dimitrov 
Date:   Sat Jan 11 18:03:15 2025 +0200

testsuite: Skip tests incompatible with generic thunk support

Some backends do not define TARGET_ASM_OUTPUT_MI_THUNK.  But the generic
thunk support cannot emit code for calling variadic methods of
multiple-inheritance classes.  Example error for pru-unknown-elf:

 .../gcc/gcc/testsuite/g++.dg/ipa/pr83549.C:7:24: error: generic thunk code 
fails for method 'virtual void C::_ZThn4_N1C3fooEz(...)' which uses '...'

Disable the affected tests for all targets which do not define
TARGET_ASM_OUTPUT_MI_THUNK.

Ensured that test results with and without this patch for
x86_64-pc-linux-gnu are the same.

gcc/ChangeLog:

* doc/sourcebuild.texi: Document variadic_mi_thunk effective
target check.

gcc/testsuite/ChangeLog:

* g++.dg/ipa/pr83549.C: Require effective target
variadic_mi_thunk.
* g++.dg/ipa/pr83667.C: Ditto.
* g++.dg/torture/pr81812.C: Ditto.
* g++.old-deja/g++.jason/thunk3.C: Ditto.
* lib/target-supports.exp
(check_effective_target_variadic_mi_thunk): New function.

Signed-off-by: Dimitar Dimitrov 

Diff:
---
 gcc/doc/sourcebuild.texi  |  3 +++
 gcc/testsuite/g++.dg/ipa/pr83549.C|  1 +
 gcc/testsuite/g++.dg/ipa/pr83667.C|  1 +
 gcc/testsuite/g++.dg/torture/pr81812.C|  1 +
 gcc/testsuite/g++.old-deja/g++.jason/thunk3.C |  3 ++-
 gcc/testsuite/lib/target-supports.exp | 31 +++
 6 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 0bd987371562..65eeeccb264c 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2957,6 +2957,9 @@ Target supports @code{sysconf}.
 @item trampolines
 Target supports trampolines.
 
+@item variadic_mi_thunk
+Target supports C++ virtual variadic function calls with multiple inheritance.
+
 @item two_plus_gigs
 Target supports linking programs with 2+GiB of data.
 
diff --git a/gcc/testsuite/g++.dg/ipa/pr83549.C 
b/gcc/testsuite/g++.dg/ipa/pr83549.C
index 90cf8fe7e0d7..3b4547b71dfc 100644
--- a/gcc/testsuite/g++.dg/ipa/pr83549.C
+++ b/gcc/testsuite/g++.dg/ipa/pr83549.C
@@ -1,5 +1,6 @@
 // PR ipa/83549
 // { dg-do compile }
+// { dg-require-effective-target variadic_mi_thunk }
 // { dg-options "-O2" }
 
 struct A { virtual ~A (); };
diff --git a/gcc/testsuite/g++.dg/ipa/pr83667.C 
b/gcc/testsuite/g++.dg/ipa/pr83667.C
index a8a5a5adb3ad..ec91a2ebd33d 100644
--- a/gcc/testsuite/g++.dg/ipa/pr83667.C
+++ b/gcc/testsuite/g++.dg/ipa/pr83667.C
@@ -1,6 +1,7 @@
 // { dg-require-alias "" }
 // { dg-options "-fdump-ipa-inline" }
 // c++/83667 ICE dumping a static thunk when TARGET_USE_LOCAL_THUNK_ALIAS_P
+// { dg-require-effective-target variadic_mi_thunk }
 
 
 struct a
diff --git a/gcc/testsuite/g++.dg/torture/pr81812.C 
b/gcc/testsuite/g++.dg/torture/pr81812.C
index b5c621d2beb2..80aed8eb2b67 100644
--- a/gcc/testsuite/g++.dg/torture/pr81812.C
+++ b/gcc/testsuite/g++.dg/torture/pr81812.C
@@ -1,4 +1,5 @@
 // { dg-xfail-if "PR108277" { arm_thumb1 } }
+// { dg-require-effective-target variadic_mi_thunk }
 
 struct Error {
   virtual void error(... ) const;
diff --git a/gcc/testsuite/g++.old-deja/g++.jason/thunk3.C 
b/gcc/testsuite/g++.old-deja/g++.jason/thunk3.C
index 4e684f9367d3..e894194db1f9 100644
--- a/gcc/testsuite/g++.old-deja/g++.jason/thunk3.C
+++ b/gcc/testsuite/g++.old-deja/g++.jason/thunk3.C
@@ -1,5 +1,6 @@
 // { dg-do run }
-// { dg-skip-if "fails with generic thunk support" { rs6000-*-* powerpc-*-eabi 
v850-*-* sh-*-* h8*-*-* xtensa*-*-* m32r*-*-* lm32-*-* } }
+// { dg-skip-if "fails with generic thunk support" { rs6000-*-* powerpc-*-eabi 
sh-*-* xtensa*-*-* } }
+// { dg-require-effective-target variadic_mi_thunk }
 // Test that variadic function calls using thunks work right.
 // Note that this will break on any target that uses the generic thunk
 //  support, because it doesn't support variadic functions.
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index 16bb2ae44264..287e51bbfc66 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -659,6 +659,37 @@ proc check_effective_target_trampolines { } {
 return 1
 }
 
+# Return 1 if target supports calling virtual variadic methods
+# of multi-inheritance classes.
+
+proc check_effective_target_variadic_mi_thunk { } {
+# These targets do not implement TARGET_ASM_OUTPUT_MI_THUNK.
+if { [istarget avr-*-*]
+|| [istarget bpf-*-*]
+|| [istarget fr30-*-*]
+|| [istarget ft32-*-*]
+|| [istarget amdgcn-*-*]
+|| [istarget h8300-*-*]
+|| [istarget iq2000-*-*]
+

[gcc r16-157] testsuite: Add require target for SJLJ exception implementation

2025-04-25 Thread Dimitar Dimitrov via Gcc-cvs
https://gcc.gnu.org/g:07b29ef00b7bbe985da62159306361faec2c3a20

commit r16-157-g07b29ef00b7bbe985da62159306361faec2c3a20
Author: Dimitar Dimitrov 
Date:   Sat Jan 18 17:10:43 2025 +0200

testsuite: Add require target for SJLJ exception implementation

Testcases for musttail call optimization fail on pru-unknown-elf:
  FAIL: c-c++-common/musttail14.c  -std=gnu++17 (test for excess errors)
  Excess errors:
  .../gcc/gcc/testsuite/c-c++-common/musttail14.c:37:14: error: cannot 
tail-call: caller uses sjlj exceptions

Silence these errors by disabling the tests if target uses SJLJ for
implementing exceptions.  Use a new effective target check for this.

Ensured that test results with and without this patch for
x86_64-pc-linux-gnu are the same.

gcc/ChangeLog:

* doc/sourcebuild.texi: Document effective target
using_sjlj_exceptions.

gcc/testsuite/ChangeLog:

* c-c++-common/musttail14.c: Disable test if effective target
using_sjlj_exceptions.
* c-c++-common/musttail22.c: Ditto.
* g++.dg/musttail8.C: Ditto.
* g++.dg/musttail9.C: Ditto.
* g++.dg/opt/musttail3.C: Ditto.
* g++.dg/opt/musttail4.C: Ditto.
* g++.dg/opt/musttail5.C: Ditto.
* g++.dg/opt/pr119613.C: Ditto.
* lib/target-supports.exp
(check_effective_target_using_sjlj_exceptions): New check.

Signed-off-by: Dimitar Dimitrov 

Diff:
---
 gcc/doc/sourcebuild.texi|  3 +++
 gcc/testsuite/c-c++-common/musttail14.c |  2 +-
 gcc/testsuite/c-c++-common/musttail22.c |  2 +-
 gcc/testsuite/g++.dg/musttail8.C|  2 +-
 gcc/testsuite/g++.dg/musttail9.C|  2 +-
 gcc/testsuite/g++.dg/opt/musttail3.C|  2 +-
 gcc/testsuite/g++.dg/opt/musttail4.C|  2 +-
 gcc/testsuite/g++.dg/opt/musttail5.C|  2 +-
 gcc/testsuite/g++.dg/opt/pr119613.C |  2 +-
 gcc/testsuite/lib/target-supports.exp   | 12 
 10 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index c29cd3f5207e..0bd987371562 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -3012,6 +3012,9 @@ Note that this is orthogonal to effective-target 
@code{exceptions_enabled}.
 Testing configuration has exception handling enabled.
 Note that this is orthogonal to effective-target @code{exceptions}.
 
+@item using_sjlj_exceptions
+Target uses @code{setjmp} and @code{longjmp} for implementing exceptions.
+
 @item fgraphite
 Target supports Graphite optimizations.
 
diff --git a/gcc/testsuite/c-c++-common/musttail14.c 
b/gcc/testsuite/c-c++-common/musttail14.c
index 56a52b8638bd..5bda742b36f3 100644
--- a/gcc/testsuite/c-c++-common/musttail14.c
+++ b/gcc/testsuite/c-c++-common/musttail14.c
@@ -1,5 +1,5 @@
 /* PR tree-optimization/118430 */
-/* { dg-do compile { target musttail } } */
+/* { dg-do compile { target { musttail && { ! using_sjlj_exceptions } } } } */
 /* { dg-options "-O2 -fdump-tree-optimized" } */
 /* { dg-final { scan-tree-dump-times "  \[^\n\r]* = bar \\\(\[^\n\r]*\\\); 
\\\[tail call\\\] \\\[must tail call\\\]" 1 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "  \[^\n\r]* = freddy \\\(\[^\n\r]*\\\); 
\\\[tail call\\\] \\\[must tail call\\\]" 1 "optimized" } } */
diff --git a/gcc/testsuite/c-c++-common/musttail22.c 
b/gcc/testsuite/c-c++-common/musttail22.c
index eb812494f44d..7dc0f199ea92 100644
--- a/gcc/testsuite/c-c++-common/musttail22.c
+++ b/gcc/testsuite/c-c++-common/musttail22.c
@@ -1,5 +1,5 @@
 /* PR tree-optimization/118430 */
-/* { dg-do compile { target musttail } } */
+/* { dg-do compile { target { musttail && { ! using_sjlj_exceptions } } } } */
 /* { dg-options "-O2 -fdump-tree-optimized" } */
 /* { dg-final { scan-tree-dump-times "  \[^\n\r]* = bar \\\(\[^\n\r]*\\\); 
\\\[tail call\\\] \\\[must tail call\\\]" 1 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "  \[^\n\r]* = freddy \\\(\[^\n\r]*\\\); 
\\\[tail call\\\] \\\[must tail call\\\]" 1 "optimized" } } */
diff --git a/gcc/testsuite/g++.dg/musttail8.C b/gcc/testsuite/g++.dg/musttail8.C
index 0f1b68bd2695..18de9c87935d 100644
--- a/gcc/testsuite/g++.dg/musttail8.C
+++ b/gcc/testsuite/g++.dg/musttail8.C
@@ -1,4 +1,4 @@
-/* { dg-do compile { target { musttail } } } */
+/* { dg-do compile { target { musttail && { ! using_sjlj_exceptions } } } } */
 /* { dg-options "-std=gnu++11" } */
 /* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */
 
diff --git a/gcc/testsuite/g++.dg/musttail9.C b/gcc/testsuite/g++.dg/musttail9.C
index 85937dcdcd31..1c3a744a4e43 100644
--- a/gcc/testsuite/g++.dg/musttail9.C
+++ b/gcc/testsuite/g++.dg/musttail9.C
@@ -1,4 +1,4 @@
-/* { dg-do compile { target { musttail } } } */
+/* { dg-do compile { target { musttail && { ! using_sjlj_exceptions } } } } */
 /* { dg-options "-std=gnu++11" } */
 /* { dg-additional-options "-fd

[gcc r16-160] simplify-rtx: Simplify `(zero_extend (and x CST))` -> (and (subreg x) CST)

2025-04-25 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:e6f89d78c1a7528e93458278e35d365544a18c26

commit r16-160-ge6f89d78c1a7528e93458278e35d365544a18c26
Author: Andrew Pinski 
Date:   Wed Feb 5 14:44:25 2025 -0800

simplify-rtx: Simplify `(zero_extend (and x CST))` -> (and (subreg x) CST)

This adds the simplification of a ZERO_EXTEND of an AND. This optimization
was already handled in combine via combine_simplify_rtx and the handling
there of compound_operations (ZERO_EXTRACT).

Build and tested for aarch64-linux-gnu.
Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

* simplify-rtx.cc (simplify_context::simplify_unary_operation_1) 
:
Add simplifcation for and with a constant.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/simplify-rtx.cc | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index 88d31a71c05a..06b52ca80037 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -1709,6 +1709,17 @@ simplify_context::simplify_unary_operation_1 (rtx_code 
code, machine_mode mode,
   if (GET_MODE (op) == mode)
return op;
 
+  /* (zero_extend:SI (and:QI X (const))) -> (and:SI (lowpart:SI X) const)
+where const does not sign bit set. */
+  if (GET_CODE (op) == AND
+ && CONST_INT_P (XEXP (op, 1))
+ && INTVAL (XEXP (op, 1)) > 0)
+   {
+ rtx tem = rtl_hooks.gen_lowpart_no_emit (mode, XEXP (op, 0));
+ if (tem)
+   return simplify_gen_binary (AND, mode, tem, XEXP (op, 1));
+   }
+
   /* Check for a zero extension of a subreg of a promoted
 variable, where the promotion is zero-extended, and the
 target mode is the same as the variable's promotion.  */