RE: [PATCH v2 2/2] RISC-V: Add testcases for signed scalar SAT_ADD IMM form 2

2025-07-01 Thread Li, Pan2
Ok, but please use "Add" instead of "add" in change log before commit, I 
suppose xuli can help to commit patches.

> * gcc.target/riscv/sat/sat_arith.h: add signed scalar SAT_ADD IMM form2.

Pan

-Original Message-
From: Ciyan Pan  
Sent: Tuesday, July 1, 2025 2:19 PM
To: gcc-patches@gcc.gnu.org
Cc: kito.ch...@gmail.com; richard.guent...@gmail.com; tamar.christ...@arm.com; 
juzhe.zh...@rivai.ai; Li, Pan2 ; jeffreya...@gmail.com; 
rdapp@gmail.com; panciyan 
Subject: [PATCH v2 2/2] RISC-V: Add testcases for signed scalar SAT_ADD IMM 
form 2

From: panciyan 

This patch adds testcase for form2, as shown below:

T __attribute__((noinline))  \
sat_s_add_imm_##T##_fmt_2##_##INDEX (T x)\
{\
  T sum = (T)((UT)x + (UT)IMM);   \
  return ((x ^ sum) < 0 && (x ^ IMM) >= 0) ? \
(-(T)(x < 0) ^ MAX) : sum; \
}

Passed the rv64gcv regression test.

Signed-off-by: Ciyan Pan 
gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat/sat_arith.h: add signed scalar SAT_ADD IMM form2.
* gcc.target/riscv/sat/sat_s_add_imm-2-i16.c: New test.
* gcc.target/riscv/sat/sat_s_add_imm-2-i32.c: New test.
* gcc.target/riscv/sat/sat_s_add_imm-2-i64.c: New test.
* gcc.target/riscv/sat/sat_s_add_imm-2-i8.c: New test.
* gcc.target/riscv/sat/sat_s_add_imm-run-2-i16.c: New test.
* gcc.target/riscv/sat/sat_s_add_imm-run-2-i32.c: New test.
* gcc.target/riscv/sat/sat_s_add_imm-run-2-i64.c: New test.
* gcc.target/riscv/sat/sat_s_add_imm-run-2-i8.c: New test.
* gcc.target/riscv/sat/sat_s_add_imm_type_check-2-i16.c: New test.
* gcc.target/riscv/sat/sat_s_add_imm_type_check-2-i32.c: New test.
* gcc.target/riscv/sat/sat_s_add_imm_type_check-2-i8.c: New test.

---
 .../gcc.target/riscv/sat/sat_arith.h  | 12 
 .../riscv/sat/sat_s_add_imm-2-i16.c   | 57 +++
 .../riscv/sat/sat_s_add_imm-2-i32.c   | 54 ++
 .../riscv/sat/sat_s_add_imm-2-i64.c   | 48 
 .../gcc.target/riscv/sat/sat_s_add_imm-2-i8.c | 49 
 .../riscv/sat/sat_s_add_imm-run-2-i16.c   | 48 
 .../riscv/sat/sat_s_add_imm-run-2-i32.c   | 48 
 .../riscv/sat/sat_s_add_imm-run-2-i64.c   | 48 
 .../riscv/sat/sat_s_add_imm-run-2-i8.c| 49 
 .../sat/sat_s_add_imm_type_check-2-i16.c  |  9 +++
 .../sat/sat_s_add_imm_type_check-2-i32.c  |  9 +++
 .../riscv/sat/sat_s_add_imm_type_check-2-i8.c |  9 +++
 12 files changed, 440 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/sat/sat_s_add_imm-2-i16.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/sat/sat_s_add_imm-2-i32.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/sat/sat_s_add_imm-2-i64.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/sat/sat_s_add_imm-2-i8.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/sat/sat_s_add_imm-run-2-i16.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/sat/sat_s_add_imm-run-2-i32.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/sat/sat_s_add_imm-run-2-i64.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/sat/sat_s_add_imm-run-2-i8.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_s_add_imm_type_check-2-i16.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_s_add_imm_type_check-2-i32.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_s_add_imm_type_check-2-i8.c

diff --git a/gcc/testsuite/gcc.target/riscv/sat/sat_arith.h 
b/gcc/testsuite/gcc.target/riscv/sat/sat_arith.h
index 6e97cae96e6..84f013ffa95 100644
--- a/gcc/testsuite/gcc.target/riscv/sat/sat_arith.h
+++ b/gcc/testsuite/gcc.target/riscv/sat/sat_arith.h
@@ -227,6 +227,18 @@ sat_s_add_imm_##T##_fmt_1##_##INDEX (T x) \
 #define RUN_SAT_S_ADD_IMM_FMT_1(INDEX, T, x, expect) \
   if (sat_s_add_imm##_##T##_fmt_1##_##INDEX(x) != expect) __builtin_abort ()
 
+#define DEF_SAT_S_ADD_IMM_FMT_2(INDEX, T, UT, IMM, MIN, MAX) \
+T __attribute__((noinline))  \
+sat_s_add_imm_##T##_fmt_2##_##INDEX (T x)\
+{\
+  T sum = (T)((UT)x + (UT)IMM);   \
+  return ((x ^ sum) < 0 && (x ^ IMM) >= 0) ? \
+(-(T)(x < 0) ^ MAX) : sum; \
+}
+
+#define RUN_SAT_S_ADD_IMM_FMT_2(INDEX, T, x, expect) \
+  if (sat_s_add_imm##_##T##_fmt_2##_##INDEX(x) != expect) __builtin_abort ()
+
 
/**/
 /* Saturation Sub (Unsigned and Signed)   
*/
 
/**/
diff --git a/gcc/testsuite/gcc.target/riscv/s

[PATCH] testsuite: Fix up gcc.target/powerpc/builtin_altivec_tr_stxvr_runnable.c test [PR120919]

2025-07-01 Thread Jakub Jelinek
Hi!

This test seems to fail when testing with
RUNTESTFLAGS="--target_board=unix/'{,-fstack-protector-strong}'"
on power10.
In my reading of the test and the instructions emitted by the
builtins, it invokes UB 4 times, each time overwriting one byte
after some variable (sc, then ss, then si and then sll).
If we are lucky, like at -O0 -mcpu=power10, there is just padding
there or something that doesn't make the tests fail, if unlucky
like with -O0 -mcpu=power10 -fstack-protector-strong,
&sc + 1 == &expected_sc
and so it overwrites the expected_sc variable.

The following patch fixes that by using arrays of 2 elements, so that
the overwriting of 1 byte happens to the part of the same variable.

Tested on powerpc64le-linux both without and with -fstack-protector-strong,
ok for trunk and 15.2/14.4?

2025-07-01  Jakub Jelinek  

PR testsuite/120919
* gcc.target/powerpc/builtin_altivec_tr_stxvr_runnable.c (main): Change
sc, ss, si and sll vars from scalars to arrays of 2 elements,
initialize and test just the first one though.

--- gcc/testsuite/gcc.target/powerpc/builtin_altivec_tr_stxvr_runnable.c.jj 
2023-06-03 15:32:05.230399713 +0200
+++ gcc/testsuite/gcc.target/powerpc/builtin_altivec_tr_stxvr_runnable.c
2025-07-01 17:03:03.026845771 +0200
@@ -27,10 +27,10 @@ int
 main () {
   int i;
   signed long sl;
-  signed char sc, expected_sc;
-  signed short ss, expected_ss;
-  signed int si, expected_si;
-  signed long long int sll, expected_sll;
+  signed char sc[2], expected_sc;
+  signed short ss[2], expected_ss;
+  signed int si[2], expected_si;
+  signed long long int sll[2], expected_sll;
   signed char *psc;
   signed short *pss;
   signed int *psi;
@@ -41,56 +41,56 @@ main () {
   printf("Data to store [%d] = 0x%llx %llx\n", i, val.ull[1], val.ull[0]);
 #endif
 
-  psc = ≻
-  pss = &ss;
-  psi = &si;
-  psll = &sll;
+  psc = &sc[0];
+  pss = &ss[0];
+  psi = &si[0];
+  psll = &sll[0];
 
   sl = 1;
-  sc = 0xA1;
+  sc[0] = 0xA1;
   expected_sc = 0xA1;
   __builtin_altivec_tr_stxvrbx (store_data, sl, psc);
 
-  if (expected_sc != sc & 0xFF)
+  if (expected_sc != sc[0] & 0xFF)
 #if DEBUG
 printf(" ERROR: Signed char = 0x%x doesn't match expected value 0x%x\n",
-  sc & 0xFF, expected_sc);
+  sc[0] & 0xFF, expected_sc);
 #else
 abort();
 #endif
 
-  ss = 0x52;
+  ss[0] = 0x52;
   expected_ss = 0x1752;
   __builtin_altivec_tr_stxvrhx (store_data, sl, pss);
 
-  if (expected_ss != ss & 0x)
+  if (expected_ss != ss[0] & 0x)
 #if DEBUG
 printf(" ERROR: Signed short = 0x%x doesn't match expected value 0x%x\n",
-  ss, expected_ss) & 0x;
+  ss[0], expected_ss) & 0x;
 #else
 abort();
 #endif
 
-  si = 0x21;
+  si[0] = 0x21;
   expected_si = 0x54321721;
   __builtin_altivec_tr_stxvrwx (store_data, sl, psi);
 
-  if (expected_si != si)
+  if (expected_si != si[0])
 #if DEBUG
 printf(" ERROR: Signed int = 0x%x doesn't match expected value 0x%x\n",
-  si, expected_si);
+  si[0], expected_si);
 #else
 abort();
 #endif
 
-  sll = 0x12FFULL;
+  sll[0] = 0x12FFULL;
   expected_sll = 0xdcba9876543217FF;
   __builtin_altivec_tr_stxvrdx (store_data, sl, psll);
 
-  if (expected_sll != sll)
+  if (expected_sll != sll[0])
 #if DEBUG
 printf(" ERROR: Signed long long int = 0x%llx doesn't match expected value 
0x%llx\n",
-  sll, expected_sll);
+  sll[0], expected_sll);
 #else
 abort();
 #endif

Jakub



[PATCH 1/2] doc: Clarify mode of else operand for vec_mask_load_lanesmn

2025-07-01 Thread Alex Coplan
This extends the documentation of the vec_mask_load_lanes optab to
explicitly state that the mode of the else operand is n, i.e. the mode
of a single subvector.

OK to install?

Thanks,
Alex

gcc/ChangeLog:

* doc/md.texi (Standard Names): Clarify mode of else operand for
vec_mask_load_lanesmn optab.
---
 gcc/doc/md.texi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index 2a1f9919c5b..28159b2e820 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -4997,8 +4997,8 @@ This pattern is not allowed to @code{FAIL}.
 Like @samp{vec_load_lanes@var{m}@var{n}}, but takes an additional
 mask operand (operand 2) that specifies which elements of the destination
 vectors should be loaded.  Other elements of the destination vectors are
-taken from operand 3, which is an else operand similar to the one in
-@code{maskload}.
+taken from operand 3, which is an else operand in the subvector mode
+@var{n}, similar to the one in @code{maskload}.
 The operation is equivalent to:
 
 @smallexample


Re: [PATCH] c-family: Check backend for argument alignment on stack

2025-07-01 Thread H.J. Lu
On Tue, Jul 1, 2025 at 9:37 PM Jason Merrill  wrote:
>
> On 6/30/25 7:03 PM, H.J. Lu wrote:
> > On Mon, Jun 30, 2025 at 10:36 PM Jason Merrill  wrote:
> >>
> >> On 6/28/25 7:00 AM, H.J. Lu wrote:
> >>> Since a backend may ignore user type alignment for arguments passed on
> >>> stack, check backend for argument alignment on stack when evaluating
> >>> __alignof.
> >>
> >> I assume that's reflected in DECL_ALIGN, so could we just add PARM_DECL to
> >
> > No.  targetm.calls.function_arg_boundary may have special handling for it.
>
> Why wouldn't we adjust DECL_ALIGN of the PARM_DECL to reflect the actual
> alignment of the argument?  Are you saying it could be different from
> one call to another?

Function argument alignment is different from other places in memory if
the main variant type alignment is different:

tatic unsigned int
ix86_function_arg_boundary (machine_mode mode, const_tree type)
{
  unsigned int align;
  if (type)
{
  /* Since the main variant type is used for call, we convert it to
 the main variant type.  */
  type = TYPE_MAIN_VARIANT (type);
  align = TYPE_ALIGN (type);
  if (TYPE_EMPTY_P (type))
return PARM_BOUNDARY;
}

> >>>else if (VAR_OR_FUNCTION_DECL_P (expr))
> >>>  t = size_int (DECL_ALIGN_UNIT (expr));
> >>
> >> ?
> >>
> >> Jason
> >>
> >
> >
>


-- 
H.J.


Re: [PATCH] c++, libstdc++, v2: Implement C++26 P2830R10 - Constexpr Type Ordering

2025-07-01 Thread Jason Merrill

On 6/26/25 6:33 AM, Jakub Jelinek wrote:

On Wed, Jun 25, 2025 at 10:58:59PM +0200, Maciej Cencora wrote:

update of std module is missing.


Here is an updated patch which adds the std module part and while I was
changing the patch, I've also added value_type/type and the 2 operators
to std::type_order.

Interdiff from the last patch is:
--- libstdc++-v3/libsupc++/compare  2025-06-25 16:18:25.221710493 +0200
+++ libstdc++-v3/libsupc++/compare  2025-06-25 16:18:25.221710493 +0200
@@ -1271,6 +1271,10 @@
  struct type_order
  {
static constexpr strong_ordering value = __builtin_type_order(_Tp, _Up);
+  using value_type = strong_ordering;
+  using type = type_order<_Tp, _Up>;
+  constexpr operator value_type() const noexcept { return value; }
+  constexpr value_type operator()() const noexcept { return value; }
  };
  
/// @ingroup variable_templates

--- libstdc++-v3/src/c++23/std.cc.in.jj 2025-06-12 15:50:51.400821105 +0200
+++ libstdc++-v3/src/c++23/std.cc.in2025-06-26 07:37:06.90208 +0200
@@ -888,6 +888,10 @@ export namespace std
using std::partial_order;
using std::strong_order;
using std::weak_order;
+#if __glibcxx_type_order >= 202506L
+  using std::type_order;
+  using std::type_order_v;
+#endif
  }
  
  // 28.4 


Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?


The gcc parts are OK.


Though, now that I look at it again, perhaps both
#if __glibcxx_type_order >= 202506L
in the patch should have been
#if __cpp_lib_type_order >= 202506L

Can change that.

2025-06-26  Jakub Jelinek  

gcc/cp/
* cp-trait.def: Implement C++26 P2830R10 - Constexpr Type Ordering.
(TYPE_ORDER): New.
* method.cc (type_order_value): Define.
* cp-tree.h (type_order_value): Declare.
* semantics.cc (trait_expr_value): Use gcc_unreachable also
for CPTK_TYPE_ORDER, adjust comment.
(finish_trait_expr): Handle CPTK_TYPE_ORDER.
* constraint.cc (diagnose_trait_expr): Likewise.
gcc/testsuite/
* g++.dg/cpp26/type-order1.C: New test.
* g++.dg/cpp26/type-order2.C: New test.
* g++.dg/cpp26/type-order3.C: New test.
libstdc++-v3/
* include/bits/version.def (type_order): New.
* include/bits/version.h: Regenerate.
* libsupc++/compare: Define __glibcxx_want_type_order before
including bits/version.h.
(std::type_order, std::type_order_v): New trait and template variable.
* src/c++23/std.cc.in (std::type_order, std::type_order_v): Export.
* testsuite/18_support/comparisons/type_order/1.cc: New test.

--- gcc/cp/method.cc.jj 2025-06-25 16:04:51.611158952 +0200
+++ gcc/cp/method.cc2025-06-25 16:09:32.017556551 +0200
@@ -3951,5 +3951,26 @@ num_artificial_parms_for (const_tree fn)
return count;
  }
  
+/* Return value of the __builtin_type_order trait.  */

+
+tree
+type_order_value (tree type1, tree type2)
+{
+  tree rettype = lookup_comparison_category (cc_strong_ordering);
+  if (rettype == error_mark_node)
+return rettype;
+  int ret;
+  if (type1 == type2)
+ret = 0;
+  else
+{
+  const char *name1 = ASTRDUP (mangle_type_string (type1));
+  const char *name2 = mangle_type_string (type2);
+  ret = strcmp (name1, name2);
+}
+  return lookup_comparison_result (cc_strong_ordering, rettype,
+  ret == 0 ? 0 : ret > 0 ? 1 : 2);
+}
+
  
  #include "gt-cp-method.h"

--- gcc/cp/cp-tree.h.jj 2025-06-25 16:04:51.610158965 +0200
+++ gcc/cp/cp-tree.h2025-06-25 16:09:32.019556525 +0200
@@ -7557,6 +7557,8 @@ extern bool ctor_omit_inherited_parms (
  extern tree locate_ctor   (tree);
  extern tree implicitly_declare_fn   (special_function_kind, tree,
 bool, tree, tree);
+extern tree type_order_value   (tree, tree);
+
  /* In module.cc  */
  class module_state; /* Forward declare.  */
  inline bool modules_p () { return flag_modules != 0; }
--- gcc/cp/semantics.cc.jj  2025-06-25 16:04:51.633158669 +0200
+++ gcc/cp/semantics.cc 2025-06-25 16:09:32.021556500 +0200
@@ -13593,8 +13593,10 @@ trait_expr_value (cp_trait_kind kind, tr
  case CPTK_IS_DEDUCIBLE:
return type_targs_deducible_from (type1, type2);
  
-/* __array_rank is handled in finish_trait_expr. */

+/* __array_rank and __builtin_type_order are handled in
+   finish_trait_expr.  */
  case CPTK_RANK:
+case CPTK_TYPE_ORDER:
gcc_unreachable ();
  
  #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \

@@ -13724,6 +13726,12 @@ finish_trait_expr (location_t loc, cp_tr
tree trait_expr = make_node (TRAIT_EXPR);
if (kind == CPTK_RANK)
TREE_TYPE (trait_expr) = size_type_node;
+  else if (kind == CPTK_TYPE_ORDER)
+   {
+ tree val = type_order_value (type1, type1);
+ if (val != error_mark_node)
+   TREE_TYPE (trait

Re: [PATCH v7 7/9] AArch64: precommit test for CMPBR instructions

2025-07-01 Thread Richard Sandiford
Richard Sandiford  writes:
> Karl Meakin  writes:
>> +// If the branch destination is out of range (1KiB), we have to generate an
>> +// extra B instruction (which can handle larger displacements) and branch 
>> around
>> +// it
>> +int far_branch(i32 x, i32 y) {
>> +  volatile int z = 0;
>> +  if (x == y) {
>
> It might be worth making this:
>
>   if (__builtin_expect (x == y, 0)) {

Gah, I meant:

  if (__builtin_expect (x == y, 1)) {

sorry!  The branch should be assumed untaken, and so the condition
should be assumed true.

> as a way of ensuring that nothing tries to "optimise" the code by
> inverting the branch (and avoiding the far branch).


RE: [COMMITTED] cobol: Normalize generating and using function_decls.

2025-07-01 Thread Robert Dubner
Oi.  Rainer, I have lost track of when %zu is okay, and when it isn't.  Jim 
has been making adjustments to printf formatting; I haven't been paying 
close attention.  The statement you report came about because I made the 
wrong choice when deconflicting a merge of my stuff and Jim's, and I must 
have chosen the wrong one.

I guess I should discuss this with Jim to get the benefit of his work on 
this.  There must be *some* general solution to the problem of formatting a 
size_t.

As for gcobol.clean...  Jim and I Had Words about this one, so you can know 
that he is on your side.  This is a case where I am not trying to fix the 
world's problems.  I am trying to fix *mine*.  Sometimes I want to be sure 
that I have completely rebuilt all of gcc/cobol and all of libgcobol, but 
without flushing gcc completely, and I want the command to be simple and 
easy to remember.  (The difference is a 13-second build of gcc/cobol and 
libgcobol versus a four-minute complete build of gcc.)

Maybe I should rename it "dubner.clean", or "donotuse.clean".

> -Original Message-
> From: Rainer Orth 
> Sent: Monday, June 30, 2025 10:27
> To: Robert Dubner 
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: [COMMITTED] cobol: Normalize generating and using
> function_decls.
>
> Hi Robert,
>
> > These changes have been shown to generate more sensible code on both
> > x86_64.
> >
> > On x86_64-pc-linux, a bootstrap build of --enable-languages=c,c++,cobol
> > succeeded.
>
> this patch has one change (not listed in ChangeLog) that broke 32-bit
> Solaris bootstrap:
>
> diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y
> index f0faaa41577..660b0b4c4c2 100644
> --- a/gcc/cobol/parse.y
> +++ b/gcc/cobol/parse.y
> @@ -12359,7 +12359,7 @@ numstr2i( const char input[], radix_t radix ) {
>  return output;
>}
>if( erc == -1 ) {
> -yywarn("'%s' was accepted as %zu", input, integer);
> +yywarn("'%s' was accepted as %ld", input, integer);
>}
>return output;
>  }
>
> This causes
>
> /vol/gcc/src/hg/master/local/gcc/cobol/parse.y: In function ‘real_value
> numstr2i(const char*, radix_t)’:
> /vol/gcc/src/hg/master/local/gcc/cobol/parse.y:12362:12: error: format
> ‘%ld’ expects argument of type ‘long int’, but argument 3 has type
> ‘std::size_t’ {aka ‘unsigned int’} [-Werror=format=]
> 12362 | yywarn("'%s' was accepted as %ld", input, integer);
>   |^~ ~~~
>   |   |
>   |   std::size_t {aka
> unsigned int}
>
> Returning to %zu obviously fixes this.
>
> Besides, I noticed
>
> diff --git a/gcc/cobol/Make-lang.in b/gcc/cobol/Make-lang.in
> index bec81a6acc0..18eb3b0f1e5 100644
> --- a/gcc/cobol/Make-lang.in
> +++ b/gcc/cobol/Make-lang.in
> @@ -353,6 +353,13 @@ cobol.srcman:
>
>  cobol.mostlyclean:
>
> +gcobol.clean:
> +# This is intended for non-general use.  It is a last-ditch effort to
> flush
> +# out all oject files and executable code for gcobol and libgcobol,
> causing
> +# a complete rebuild of all executable code.
> + rm -fr gcobol cobol1 cobol/*\
> + ../*/libgcobol/*
> +
>
> This is at least incomplete: in multilib builds, there are more
> instances of libgcobol in //libgcobol.
>
>   Rainer
>
> --
> --
> ---
> Rainer Orth, Center for Biotechnology, Bielefeld University


[PATCH v2] RISC-V: Updated march , that aligned with mips-p8700

2025-07-01 Thread Umesh Kalappa
Refactored ccmov insn rtl template to use code_iterator and fixed the
indentation.

No regressions are found for "runtest --tool gcc 
--target_board='riscv-sim/-mabi=lp64d/-mtune=mips-p8700/-O2 ' riscv.exp"

*config/riscv/riscv-cores.def(RISCV_CORE):Updated the supported march.
*config/riscv/riscv-ext-mips.def(DEFINE_RISCV_EXT):
 New file added for mips conditional mov extension.
*config/riscv/riscv-ext.def: Likewise.
*config/riscv/t-riscv:Generates riscv-ext.opt
*config/riscv/riscv-ext.opt: Generated file.
*config/riscv/riscv.cc(riscv_expand_conditional_move):Updated for mips 
cmov
 and outlined some code that handle arch cond move.
*config/riscv/riscv.md(movcc):updated expand for MIPS CCMOV.
*config/riscv/mips-insn.md:New file for mips-p8700 ccmov insn.
*testsuite/gcc.target/riscv/mipscondmov.c:Test file for mips.ccmov insn.
*gcc/doc/riscv-ext.texi:Updated for mips cmov.
---
 gcc/config/riscv/mips-insn.md|  37 +++
 gcc/config/riscv/riscv-cores.def |   3 +-
 gcc/config/riscv/riscv-ext-mips.def  |  35 ++
 gcc/config/riscv/riscv-ext.def   |   1 +
 gcc/config/riscv/riscv-ext.opt   |   4 +
 gcc/config/riscv/riscv.cc| 107 +--
 gcc/config/riscv/riscv.md|   3 +-
 gcc/config/riscv/t-riscv |   3 +-
 gcc/doc/riscv-ext.texi   |   4 +
 gcc/testsuite/gcc.target/riscv/mipscondmov.c |  30 ++
 10 files changed, 190 insertions(+), 37 deletions(-)
 create mode 100644 gcc/config/riscv/mips-insn.md
 create mode 100644 gcc/config/riscv/riscv-ext-mips.def
 create mode 100644 gcc/testsuite/gcc.target/riscv/mipscondmov.c

diff --git a/gcc/config/riscv/mips-insn.md b/gcc/config/riscv/mips-insn.md
new file mode 100644
index 000..b9ea1c7363c
--- /dev/null
+++ b/gcc/config/riscv/mips-insn.md
@@ -0,0 +1,37 @@
+;; Machine description for MIPS custom instructions.
+;; Copyright (C) 2025 Free Software Foundation, Inc.
+
+;; This file is part of GCC.
+
+;; GCC is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+
+;; GCC is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GCC; see the file COPYING3.  If not see
+;; .
+
+(define_insn "*movcc_bitmanip"
+  [(set (match_operand:GPR 0 "register_operand" "=r")
+   (if_then_else:GPR
+ (any_eq:X (match_operand:X 1 "register_operand" "r")
+(match_operand:X 2 "const_0_operand" "J"))
+(match_operand:GPR 3 "reg_or_0_operand" "rJ")
+(match_operand:GPR 4 "reg_or_0_operand" "rJ")))]
+  "TARGET_XMIPSCMOV"
+{ 
+  enum rtx_code code = ;
+  if (code == NE)
+return "mips.ccmov\t%0,%1,%z3,%z4";
+  else
+return "mips.ccmov\t%0,%1,%z4,%z3"; 
+}
+[(set_attr "type" "condmove")
+ (set_attr "mode" "")])
+
diff --git a/gcc/config/riscv/riscv-cores.def b/gcc/config/riscv/riscv-cores.def
index 2096c0095d4..98f347034fb 100644
--- a/gcc/config/riscv/riscv-cores.def
+++ b/gcc/config/riscv/riscv-cores.def
@@ -169,7 +169,6 @@ RISCV_CORE("xiangshan-kunminghu",   
"rv64imafdcbvh_sdtrig_sha_shcounterenw_"
  "zvfhmin_zvkt_zvl128b_zvl32b_zvl64b",
  "xiangshan-kunminghu")
 
-RISCV_CORE("mips-p8700",   "rv64imafd_zicsr_zmmul_"
- "zaamo_zalrsc_zba_zbb",
+RISCV_CORE("mips-p8700",  "rv64imfd_zicsr_zifencei_zalrsc_zba_zbb",
  "mips-p8700")
 #undef RISCV_CORE
diff --git a/gcc/config/riscv/riscv-ext-mips.def 
b/gcc/config/riscv/riscv-ext-mips.def
new file mode 100644
index 000..f24507139f6
--- /dev/null
+++ b/gcc/config/riscv/riscv-ext-mips.def
@@ -0,0 +1,35 @@
+/* MIPS extension definition file for RISC-V.
+   Copyright (C) 2025 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.
+
+Please run `make riscv-regen` in build folder to

Re: [PATCH v2] libstdc++: Lift locale initialization in main chrono format loop [PR110739]

2025-07-01 Thread Tomasz Kaminski
On Tue, Jul 1, 2025 at 4:57 PM Tomasz Kamiński  wrote:

> This patch lifts locale initialization from locale-specific handling
> methods
> into _M_format_to function, and pass the locale by const reference.
> To avoid unnecessary computation of locale::classic(), we use
> _Optional_locale,
> and emplace into it only for localized formatting (_M_spec._M_localized)
> or if
> chrono-spec contains locale specific specifiers
> (_M_spec._M_locale_specific).
> The later is constructs locale::classic() in more cases that strictly
> necessary,
> as only subset of locale specific specifiers (%a, %A, %b, %B, %c, %p, %r)
> needs
> locale, while _M_locale_specific is also set for %x,%X and when O/E
> modifiers are
> used. However, none of default outputs are affects, so I believe this is
> acceptable.
>
The alternative here  would be to pass _Optional_locale reference to this
function,
and add if (!__oloc.has_value()) __oloc = locale::classic(). Let me know if
that would
be your preference.

>
> In _M_S we no longer guard querying of numpuct facet, with check that
> requires
> potentially equally expensive construction of locale::classic. We also mark
> localized path as unlikely.
>
> The _M_locale method is no longer used in __formatter_chrono, and thus was
> moved to __formatter_duration.
>
> libstdc++-v3/ChangeLog:
>
> * include/bits/chrono_io.h (__formatter_chrono::_M_format_to):
> Compute locale and pass it to specifiers method.
> (__formatter_chrono::_M_a_A, __formatter_chrono::_M_b_B)
> (__formatter_chrono::_M_c, __formatter_chrono::_M_p)
> (__formatter_chrono::_M_r): Accept locale instead of format
> context.
> (__formatter_chrono::_M_subsecs): Call __ctx.locale() directly,
> instead of _M_locale and do not compare with locale::classic().
> Add [[unlikely]] attributes.
> (__formatter_chrono::_M_locale): Move to __formatter_duration.
> (__formatter_duration::_M_locale): Moved from __formatter_chrono.
> ---
> v2 updates the commit message text only in hope to make it more readable.
>
>  libstdc++-v3/include/bits/chrono_io.h | 71 ---
>  1 file changed, 43 insertions(+), 28 deletions(-)
>
> diff --git a/libstdc++-v3/include/bits/chrono_io.h
> b/libstdc++-v3/include/bits/chrono_io.h
> index bcf9830fb9e..a25cb9ada01 100644
> --- a/libstdc++-v3/include/bits/chrono_io.h
> +++ b/libstdc++-v3/include/bits/chrono_io.h
> @@ -964,10 +964,16 @@ namespace __format
> return std::move(__out);
>   };
>
> + _Optional_locale __loc;
> + if (_M_spec._M_localized)
> +   __loc = __fc.locale();
> + else if (_M_spec._M_locale_specific)
> +   __loc = locale::classic();
> +
>   struct tm __tm{};
>   bool __use_locale_fmt = false;
>   if (_M_spec._M_localized && _M_spec._M_locale_specific)
> -   if (__fc.locale() != locale::classic())
> +   if (__loc.value() != locale::classic())
>   {
> __use_locale_fmt = true;
>
> @@ -1004,7 +1010,7 @@ namespace __format
> {
>   _CharT __c = *__first++;
>   if (__use_locale_fmt && _S_localized_spec(__c, __mod))
> [[unlikely]]
> -   __out = _M_locale_fmt(std::move(__out), __fc.locale(),
> +   __out = _M_locale_fmt(std::move(__out), __loc.value(),
>   __tm, __c, __mod);
>   else switch (__c)
> {
> @@ -1014,15 +1020,17 @@ namespace __format
>   break;
> case 'a':
> case 'A':
> - __out = _M_a_A(__t._M_weekday, std::move(__out), __fc,
> __c == 'A');
> + __out = _M_a_A(__t._M_weekday, std::move(__out),
> +__loc.value(), __c == 'A');
>   break;
> case 'b':
> case 'h':
> case 'B':
> - __out = _M_b_B(__t._M_month, std::move(__out), __fc, __c
> == 'B');
> + __out = _M_b_B(__t._M_month, std::move(__out),
> +__loc.value(), __c == 'B');
>   break;
> case 'c':
> - __out = _M_c(__t, std::move(__out), __fc);
> + __out = _M_c(__t, std::move(__out), __loc.value());
>   break;
> case 'C':
> case 'y':
> @@ -1058,7 +1066,7 @@ namespace __format
>   __out = _M_M(__t._M_minutes, __print_sign());
>   break;
> case 'p':
> - __out = _M_p(__t._M_hours, std::move(__out), __fc);
> + __out = _M_p(__t._M_hours, std::move(__out),
> __loc.value());
>   break;
> case 'q':
>   __out = _M_q(__t._M_unit_suffix, std::move(__out));
> @@ -1067,7 +1075,7 @@ namespace __format
>   __out = _M_Q(__t, __print_sig

Re: [PATCH v6 1/3][Middle-end] Provide more contexts for -Warray-bounds, -Wstringop-*warning messages due to code movements from compiler transformation (Part 1) [PR109071,PR85788,PR88771,PR106762,PR1

2025-07-01 Thread Qing Zhao


> On Jul 1, 2025, at 03:14, Richard Biener  wrote:
> 
> On Mon, Jun 30, 2025 at 10:37 PM Qing Zhao  wrote:
>> 
>> Hi, David,
>> 
>> Thank you for the info.
>> 
>> Yes, this does sound like a general issue in this area.
>> 
>> Is there any mechanism in GCC currently that records such original source 
>> code information for IRs
>> after the compiler transformation?
>> 
>> If not, shall we add such information in the IR for this purpose? Is doing 
>> this very expensive?
>> 
>>> On Jun 30, 2025, at 12:23, David Malcolm  wrote:
>>> 
>>> On Mon, 2025-06-30 at 16:47 +, Qing Zhao wrote:
>>> 
>>> [...snip...]
>>> 
 The output with -fdiagnostics-show-context=1 is:
 
 /home/opc/Work/GCC/latest-gcc-
 write/gcc/testsuite/gcc.dg/pr109071_7.c: In function ‘foo’:
 /home/opc/Work/GCC/latest-gcc-
 write/gcc/testsuite/gcc.dg/pr109071_7.c:12:6: warning: array
 subscript -1 is below array bounds of ‘int[10]’ [-Warray-bounds=]
   12 | a[i] = -1; /* { dg-warning "is below array bounds of" }
 */
  | ~^~~
  ‘foo’: events 1-2
   11 |   if (i == -1)
  |  ^
  |  |
  |  (1) when the condition is evaluated to true
>>> 
>>> Looks great, but one caution: presumably "true" in this context refers
>>> to the state of the IR when the warning is emitted, rather than what
>>> the user wrote.  I've run into this in the analyzer;
>>> see PR analyzer/100116 (which I don't have a good solution for, alas).
>>> 
>>> Is there a way to get at the original sense of the condition, in terms
>>> of what the user wrote?  I'm guessing that this has been canonicalized
>>> away long before the middle-end warnings see this.
>> 
>> As long as such information is lost during transformation, there is no way 
>> to get
>> the original source code, I guess.
> 
> We could try to track condition inversions done with a flag on the gcond.
> For example we canonicalize
> 
>  if (bool_var == 0)
> 
> to
> 
> if (bool_var != 0)
> 
> with the true/false sense of the edges swapped.
One flag is enough for such transformation. 
> 
> Instead of "when the condition is evaluated to true" we could also
> print "when execution continues to" and then point to the first
> stmt location we can find on the path executed.

This is doable, but I guess the information might be confusing to user too. 
> 
> Note we'll also turn
> 
>   if (a)
> if (b)
>   {
>   ...
> 
> into
> 
>  tem = a && b;
>  if (tem)
>{
> ...
> 
> where the location of the if retained is usually the outer one and the
> split out part might or might not have sensible locations.  That's also
> an issue for debugging of course.

However, for such cases, we might need a new data structure to record 
the original condition statements and attach it to the gcond  in order to 
get the original source code information. 

Each transformation that might change the condition need to be investigated and
maintain such new data structure.  This might be quite tedious and error-prone. 
> 
> Caret locations and thus "paths" will always have this kind of issues.
> Another variant might be to collect a predicate expression up to
> user variables and print "when `a && b' evaluates to true/false"
> for the above case instead.

Yes, this is a good workaround too. 

And there should be other transformations that might change the conditions, 
in addition to the existing compiler transformations,  there might be new 
transformations
 that will be added later to change the conditions too.

> 
> I think we need to amend the documentation a bit about these
> kind of pitfalls.  

Yes. This is necessary. 

> And fixup locations we put on stmts eventually.

Yes, looks like a big project…

Qing


> 
> Richard.
> 
>> Not sure whether the LOCATION_T can include such information?
>>> 
>>> Or perhaps the message for (1) could say exactly what condition it
>>> considers to be true e.g.
>>> (1) when the condition "i == -1" is evaluated to true
>>> or somesuch, which might give the user a better clue if the sense of
>>> the conditional has been reversed during canonicalization/optimization.
>> 
>> This looks like a reasonable workaround based on the current IR.
>>> 
>>> Caveat: I didn't reread the latest version of your patch, but am just
>>> assuming it's looking at the cfg edge flags when the warning is
>>> emitted; sorry if I'm making a false assumption here.
>> 
>> Yes, that’s right.  You made good assumptions here -:).
>> 
>> thanks.
>> 
>> Qing
>>> 
 
>>> Dave




[COMMITTED] cobol: Update test case for intrinsic function syntax.

2025-07-01 Thread Robert Dubner
A recent update to the COBOL syntax checker resulted in this test case
failing, so it needed to be fixed.

>From f6c187a4f34b6925196279fd623f9f1396385a18 Mon Sep 17 00:00:00 2001
From: Robert Dubner mailto:rdub...@symas.com
Date: Tue, 1 Jul 2025 11:07:18 -0400
Subject: [PATCH] cobol: Update test case for intrinsic function syntax.

gcc/testsuite/ChangeLog:

* cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.cob:
Append INTRINSIC keyword.
---
 .../group2/Intrinsics_without_FUNCTION_keyword__2_.cob| 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git
a/gcc/testsuite/cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.co
b
b/gcc/testsuite/cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.co
b
index b94adf58026..39a0c5b33da 100644
---
a/gcc/testsuite/cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.co
b
+++
b/gcc/testsuite/cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.co
b
@@ -5,8 +5,8 @@
ENVIRONMENT  DIVISION.
CONFIGURATIONSECTION.
REPOSITORY.
-   FUNCTION PI
-   FUNCTION E.
+   FUNCTION PI INTRINSIC
+   FUNCTION E  INTRINSIC.
DATA DIVISION.
WORKING-STORAGE  SECTION.
01  ZPIC 99V99.
-- 
2.34.1



[PATCH 2/2] aarch64: Drop const_int from aarch64_maskload_else_operand

2025-07-01 Thread Alex Coplan
The "else operand" to maskload should always be a const_vector, never a
const_int.

This was just an issue I noticed while looking through the code, I don't
have a testcase which shows a concrete problem due to this.

Testing of that change alone showed ICEs with load lanes vectorization
and SVE.  That turned out to be because the backend pattern was missing
a mode for the else operand (causing the middle-end to choose a
const_int during expansion), fixed thusly.  That in turn exposed an
issue with the unpredicated load lanes expander which was using the
wrong mode for the else operand, so fixed that too.

Bootstrapped/tested on aarch64-linux-gnu, OK for trunk?

Thanks,
Alex

gcc/ChangeLog:

* config/aarch64/aarch64-sve.md
(vec_load_lanes): Expand else operand in
subvector mode, as per optab documentation.
(vec_mask_load_lanes): Add missing mode for
operand 3.
* config/aarch64/predicates.md (aarch64_maskload_else_operand):
Remove const_int.
---
 gcc/config/aarch64/aarch64-sve.md | 4 ++--
 gcc/config/aarch64/predicates.md  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-sve.md b/gcc/config/aarch64/aarch64-sve.md
index 450975dd088..4aecb3a6bf8 100644
--- a/gcc/config/aarch64/aarch64-sve.md
+++ b/gcc/config/aarch64/aarch64-sve.md
@@ -1344,7 +1344,7 @@ (define_expand "vec_load_lanes"
   "TARGET_SVE"
   {
 operands[2] = aarch64_ptrue_reg (mode);
-operands[3] = CONST0_RTX (mode);
+operands[3] = CONST0_RTX (mode);
   }
 )
 
@@ -1354,7 +1354,7 @@ (define_insn "vec_mask_load_lanes"
 	(unspec:SVE_STRUCT
 	  [(match_operand: 2 "register_operand" "Upl")
 	   (match_operand:SVE_STRUCT 1 "memory_operand" "m")
-	   (match_operand 3 "aarch64_maskload_else_operand")]
+	   (match_operand: 3 "aarch64_maskload_else_operand")]
 	  UNSPEC_LDN))]
   "TARGET_SVE"
   "ld\t%0, %2/z, %1"
diff --git a/gcc/config/aarch64/predicates.md b/gcc/config/aarch64/predicates.md
index d8e9725a1b6..32056daf329 100644
--- a/gcc/config/aarch64/predicates.md
+++ b/gcc/config/aarch64/predicates.md
@@ -1076,5 +1076,5 @@ (define_predicate "aarch64_granule16_simm9"
 		&& !(INTVAL (op) & 0xf)")))
 
 (define_predicate "aarch64_maskload_else_operand"
-  (and (match_code "const_int,const_vector")
+  (and (match_code "const_vector")
(match_test "op == CONST0_RTX (GET_MODE (op))")))


Re: [PATCH] s390: Add -fno-stack-protector to 3 tests

2025-07-01 Thread Jakub Jelinek
On Tue, Jul 01, 2025 at 03:47:53PM +0200, Stefan Schulze Frielinghaus wrote:
> In the past years I have started to use more and more function body
> checks whenever gcc emits optimal code for a function.  With that I
> wanted to make sure that we do not regress like introducing unnecessary
> extends or whatever which might not have been caught by only testing the
> "interesting"/actual part of a patch.  Thus, as long as those function
> body checks are stable enough, i.e., not subject to insn reordering or
> the like, I would like to make use of them in the future, too.   That
> being said I'm wondering whether it would make sense to automatically
> add option -fno-stack-protector for tests which make use function-body
> checks?  If the testsuite infrastructure doesn't provide this
> functionality trivially, I will try to keep this in mind and always add
> the option manually.

I think even better would be to make the check-function-body UNSUPPORTED
if there is no explicit -f{,no-}stack-protector* among
dg-options/dg-additional-options and the option is still used.
Because the test can be also dg-do run and it might be useful to run the
test.

Or another way could be just add a new effective target whether any kind of
-fstack-protector{,-strong,-all} is enabled and guard the
check-function-body directives explicitly with negation of that effective
target.  Or perhaps have no_stack_protection effective target and use that
to guard some directives manually.

Jakub



Re: [PATCH v4 2/6] dwarf: create annotation DIEs for btf tags

2025-07-01 Thread David Faust



On 7/1/25 01:02, Richard Biener wrote:
> On Mon, Jun 30, 2025 at 9:12 PM David Faust  wrote:
>>
>>
>>
>> On 6/30/25 06:11, Richard Biener wrote:
 +static void
 +gen_btf_decl_tag_dies (tree t, dw_die_ref target, dw_die_ref context_die)
 +{
 +  if (t == NULL_TREE || !DECL_P (t) || !target)
 +return;
 +
 +  tree attr = lookup_attribute ("btf_decl_tag", DECL_ATTRIBUTES (t));
 +  if (attr == NULL_TREE)
 +return;
 +
 +  gen_btf_tag_dies (attr, target, context_die);
 +
 +  /* Strip the decl tag attribute once we have created the annotation DIEs
 + to avoid attempting process it multiple times.  Global variable
 + declarations may reach this function more than once.  */
 +  DECL_ATTRIBUTES (t)
 += remove_attribute ("btf_decl_tag", DECL_ATTRIBUTES (t));
>>> I do not like modifying trees as part of dwarf2out.  You should be able to
>>> see whether a DIE already has the respective attribute applied?
>>
>> Yes, you're right. For decl_tag the case is simple and better handled by
>> consulting the hash table. Simple fix and this remove_attribute can be
>> deleted.
>>
>> Understood re: modifying trees in dwarf2out. I agree it's not ideal.
>>
>> For this case the remove_attribute can be deleted. For the two below,
>> one is already immediately restored and the other could be as well so
>> that there are no lasting changes in the tree at all.
>>
>> I will explain the reasoning some more below.
>>
>>>
 +}
 +
  /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
 entry that chains the modifiers specified by CV_QUALS in front of the
 given type.  REVERSE is true if the type is to be interpreted in the
 @@ -13674,6 +13894,7 @@ modified_type_die (tree type, int cv_quals, bool 
 reverse,
tree item_type = NULL;
tree qualified_type;
tree name, low, high;
 +  tree tags;
dw_die_ref mod_scope;
struct array_descr_info info;
/* Only these cv-qualifiers are currently handled.  */
 @@ -13783,10 +14004,62 @@ modified_type_die (tree type, int cv_quals, bool 
 reverse,
   dquals &= cv_qual_mask;
   if ((dquals & ~cv_quals) != TYPE_UNQUALIFIED
   || (cv_quals == dquals && DECL_ORIGINAL_TYPE (name) != type))
 -   /* cv-unqualified version of named type.  Just use
 -  the unnamed type to which it refers.  */
 -   return modified_type_die (DECL_ORIGINAL_TYPE (name), cv_quals,
 - reverse, context_die);
 +   {
 + tree dtags = lookup_attribute ("btf_type_tag",
 +TYPE_ATTRIBUTES (dtype));
 + if ((tags = lookup_attribute ("btf_type_tag",
 +   TYPE_ATTRIBUTES (type)))
 + && !attribute_list_equal (tags, dtags))
 +   {
 + /* Use of a typedef with additional btf_type_tags.
 +Create a new typedef DIE to which we can attach the
 +additional type_tag DIEs without disturbing other 
 users of
 +the underlying typedef.  */
 + dw_die_ref mod_die = modified_type_die (dtype, cv_quals,
 + reverse, 
 context_die);
 + mod_die = clone_die (mod_die);
 + add_child_die (comp_unit_die (), mod_die);
 + if (!lookup_type_die (type))
 +   equate_type_number_to_die (type, mod_die);
 +
 + /* 'tags' is an accumulated list of type_tag attributes
 +for the typedef'd type on both sides of the typedef.
 +'dtags' is the set of type_tag attributes only 
 appearing
 +in the typedef itself.
 +Find the set of type_tags only on the _use_ of the
 +typedef, i.e. (tags - dtags).  By construction these
 +additional type_tags have been chained onto the head 
 of
 +the attribute list of the original typedef.  */
 + tree t = tags;
 + bool altered_chain = false;
 + while (t)
 +   {
 + if (TREE_CHAIN (t) == dtags)
 +   {
 + TREE_CHAIN (t) = NULL_TREE;
 + altered_chain = true;
 + break;
 +   }
 + t = TREE_CHAIN (t);
 +   }
>>> And this might be part of that and should thus split out, or be part
>>> of gen_btf_type_tag_dies itself?  I expected the hashtable to
>>> cover the DIEs w

Re: [PATCH] testsuite, powerpc: Fix vsx-vectorize-* after alignment peeling [PR118567]

2025-07-01 Thread Jakub Jelinek
On Tue, Jul 01, 2025 at 12:04:04PM -0500, Segher Boessenkool wrote:
> On Mon, Feb 17, 2025 at 02:28:50PM +, Alex Coplan wrote:
> > After the recent alignment peeling enhancements in the vectorizer we
> > started vectorizing the "checking" loops (that check for the right
> > result) in gcc.target/powerpc/vsx-vectorize-*.c,  thus skewing the
> > expected counts of various scan-dump-times tests (causing them to FAIL).
> > This adds #pragma GCC novector above the relevant loops to prevent them
> > from being vectorized, thereby fixing the test failures.
> 
> It is fundamentally incorrect to add a "novector" attribute to testcases
> called "vsx-vectorize-*".  Even if it is just to some part of the code;
> if you want to only test some part of code, put it in a different file.
> 
> If the testcases are less than stellar (and pretty much anything using
> scan-assembler-times is!), fix *that*?

All the 8 testcases have
/* Taken from vect/vect-95.c.  */
comment and
gcc.dg/vect/vect-95.c test uses that pragma already:
__attribute__ ((noinline))
void bar (float *pd, float *pa, float *pb, float *pc)
{
  int i;

  /* check results:  */
#pragma GCC novector
  for (i = 0; i < N; i++)
{
  if (pa[i] != (pb[i] * pc[i]))
abort ();
  if (pd[i] != 5.0)
abort ();
}

  return;
}

That said, unlike gcc.dg/vect/vect-95.c test, all these 8 are
/* { dg-do compile } */
test, so I fail to understand why they have definitions (rather than
declarations) of bar and main.  Or perhaps vsx-vectorize-*.c could
be dg-do compile and with just bar declaration and main1 definition,
and then have 8 further tests that include those and include the 2 headers,
define bar and main and are dg-do run rather than dg-do compile and don't
scan any dumps.

Jakub



[PATCH] AArch64: Use correct cost for shifted halfword load/stores

2025-07-01 Thread Wilco Dijkstra
Since all Armv9 cores support shifted LDRH/STRH, use the correct cost of zero
for these.

Passes regress, OK for commit?

gcc:
* config/aarch64/tuning_models/generic_armv9_a.h
(generic_armv9_a_addrcost_table): Use zero cost for himode.

---

diff --git a/gcc/config/aarch64/tuning_models/generic_armv9_a.h 
b/gcc/config/aarch64/tuning_models/generic_armv9_a.h
index 
f76a2506f3841a05a89285e50ad96c8665732955..9eb1a20d3c4e5d5a3b6c8bf8a2c341a82ac8f7da
 100644
--- a/gcc/config/aarch64/tuning_models/generic_armv9_a.h
+++ b/gcc/config/aarch64/tuning_models/generic_armv9_a.h
@@ -26,7 +26,7 @@
 static const struct cpu_addrcost_table generic_armv9_a_addrcost_table =
 {
 {
-  1, /* hi  */
+  0, /* hi  */
   0, /* si  */
   0, /* di  */
   1, /* ti  */



Re: [PATCH v2] RISC-V: Updated march , that aligned with mips-p8700

2025-07-01 Thread Maciej W. Rozycki
On Tue, 1 Jul 2025, Umesh Kalappa wrote:

>   *config/riscv/riscv-cores.def(RISCV_CORE):Updated the supported march.
>   *config/riscv/riscv-ext-mips.def(DEFINE_RISCV_EXT):
>New file added for mips conditional mov extension.
>   *config/riscv/riscv-ext.def: Likewise.
>   *config/riscv/t-riscv:Generates riscv-ext.opt
>   *config/riscv/riscv-ext.opt: Generated file.
>   *config/riscv/riscv.cc(riscv_expand_conditional_move):Updated for mips 
> cmov
>and outlined some code that handle arch cond move.
>   *config/riscv/riscv.md(movcc):updated expand for MIPS CCMOV.
>   *config/riscv/mips-insn.md:New file for mips-p8700 ccmov insn.
>   *testsuite/gcc.target/riscv/mipscondmov.c:Test file for mips.ccmov insn.
>   *gcc/doc/riscv-ext.texi:Updated for mips cmov.

 You need to add spaces throughout this ChangeLog entry; cf. 
.  
Our commit hook may actually reject the entry as it stands.

> diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> index bbc7547d385..2e14f084a5c 100644
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -5468,6 +5472,68 @@ riscv_expand_conditional_branch (rtx label, rtx_code 
> code, rtx op0, rtx op1)
>emit_jump_insn (gen_condjump (condition, label));
>  }
>  
> +/* canonicalization of the comparands.  */
> +void
> +canonicalize_comparands (rtx_code code, rtx *op0, rtx *op1)
> +{
> +  /* An integer comparison must be comparing WORD_MODE objects.
> + Extend the comparison arguments as necessary.  */
> +  if ((INTEGRAL_MODE_P (GET_MODE (*op0)) && GET_MODE (*op0) != word_mode)
> +  || (INTEGRAL_MODE_P (GET_MODE (*op1)) && GET_MODE (*op1) != word_mode))
> +riscv_extend_comparands (code, op0, op1);
> +
> +  /* We might have been handed back a SUBREG.  Just to make things
> + easy, force it into a REG.  */
> +  if (!REG_P (*op0) && !CONST_INT_P (*op0))
> +*op0 = force_reg (word_mode, *op0);
> +  if (!REG_P (*op1) && !CONST_INT_P (*op1))
> +*op1 = force_reg (word_mode, *op1);
> +}
> +
> +/* Emit target specific conditional move like TARGET_XMIPSCMOV etc.  */
> +bool
> +riscv_target_conditional_move (rtx dest, rtx op0, rtx op1, rtx_code code,
> + rtx cons, rtx alt)
> +{
> +  machine_mode dst_mode = GET_MODE (dest);
> +  rtx target;
> +
> +  /* force the operands to the register.  */
> +  cons = force_reg (dst_mode, cons);
> +  alt = force_reg (dst_mode, alt);
> +
> +  if (TARGET_XMIPSCMOV)
> +{
> +  if (code == EQ || code == NE)
> + {
> +   op0 = riscv_zero_if_equal (op0, op1);
> +   op1 = const0_rtx;
> + }
> + else
> +  {

 Still spaces here rather than a tab here, visible as misalignment between 
this brace and ones with the block immediately above.

> + target = gen_reg_rtx (GET_MODE (op0));
> + riscv_emit_int_order_test (code, 0, target, op0, op1);
> + op0 = target;
> + op1 = const0_rtx;
> + code = NE;
> +  }

 Likewise.  FWIW I tend to run `s//\t/' over chunks of code being 
added or updated when I'm not sure white space is correct (or when I do 
know it's not, such as when pasted with gpm from another virtual console).  
How to apply that replacement will depend on the text editor you use.

> + riscv_emit_int_compare (&code, &op0, &op1);
> + rtx cond = gen_rtx_fmt_ee (code, GET_MODE (op0), op0, op1);
> + emit_insn (gen_rtx_SET (dest, gen_rtx_IF_THEN_ELSE (dst_mode,
> +   cond, cons, alt)));
> + return true;
> +}
> +  // TARGET_SFB_ALU || TARGET_XTHEADCONDMOV

 Do we allow C++-style comments nowadays?  I think they used to be a 
no-no, but maybe it's not the case anymore.

  Maciej


[PATCH] libstdc++: construct bitset from string_view (P2697) [PR119742]

2025-07-01 Thread Nathan Myers
Add a bitset constructor from string_view, with other arguments
matching the constructor from string. Test in ways that exercise
code paths not checked in existing tests for other constructors.
Fix existing tests that would fail to detect incorrect exception
behavior.

libstdc++-v3/ChangeLog:
PR libstdc++/119742
* include/bits/version.def: new preprocessor symbol
* include/bits/version.h: new preprocessor symbol
* include/std/bitset: new constructor
* testsuite/20_util/bitset/cons/1.cc: fix
* testsuite/20_util/bitset/cons/6282.cc: fix
* testsuite/20_util/bitset/cons/string_view.cc: new tests
* testsuite/20_util/bitset/cons/string_view_wide.cc: new tests
---
 libstdc++-v3/include/bits/version.def |   8 ++
 libstdc++-v3/include/bits/version.h   |  10 ++
 libstdc++-v3/include/std/bitset   |  49 +++
 .../testsuite/20_util/bitset/cons/1.cc|   1 +
 .../testsuite/20_util/bitset/cons/6282.cc |   5 +-
 .../20_util/bitset/cons/string_view.cc| 132 ++
 .../20_util/bitset/cons/string_view_wide.cc   |   8 ++
 7 files changed, 210 insertions(+), 3 deletions(-)
 create mode 100644 libstdc++-v3/testsuite/20_util/bitset/cons/string_view.cc
 create mode 100644 
libstdc++-v3/testsuite/20_util/bitset/cons/string_view_wide.cc

diff --git a/libstdc++-v3/include/bits/version.def 
b/libstdc++-v3/include/bits/version.def
index 880586e9126..d82585e1238 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -2012,6 +2012,14 @@ ftms = {
   };
 };
 
+ftms = {
+  name = bitset  // ...construct from string_view
+  values = {
+v = 202306;
+cxxmin = 26;
+  };
+};
+
 // Standard test specifications.
 stds[97] = ">= 199711L";
 stds[03] = ">= 199711L";
diff --git a/libstdc++-v3/include/bits/version.h 
b/libstdc++-v3/include/bits/version.h
index 4300adb2276..c0d3cbe623f 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -2253,4 +2253,14 @@
 #endif /* !defined(__cpp_lib_sstream_from_string_view) && 
defined(__glibcxx_want_sstream_from_string_view) */
 #undef __glibcxx_want_sstream_from_string_view
 
+#if !defined(__cpp_lib_bitset)
+# if (__cplusplus >  202302L)
+#  define __glibcxx_bitset 202306L
+#  if defined(__glibcxx_want_all) || defined(__glibcxx_want_bitset)
+#   define __cpp_lib_bitset 202306L
+#  endif
+# endif
+#endif /* !defined(__cpp_lib_bitset) && defined(__glibcxx_want_bitset) */
+#undef __glibcxx_bitset
+
 #undef __glibcxx_want_all
diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset
index 8b5d270c2a9..f4947902384 100644
--- a/libstdc++-v3/include/std/bitset
+++ b/libstdc++-v3/include/std/bitset
@@ -61,8 +61,13 @@
 #endif
 
 #define __glibcxx_want_constexpr_bitset
+#define __glibcxx_want_bitset  // ...construct from string_view
 #include 
 
+#ifdef __cpp_lib_bitset // ...construct from string_view
+# include 
+#endif
+
 #define _GLIBCXX_BITSET_BITS_PER_WORD  (__CHAR_BIT__ * __SIZEOF_LONG__)
 #define _GLIBCXX_BITSET_WORDS(__n) \
   ((__n) / _GLIBCXX_BITSET_BITS_PER_WORD + \
@@ -831,6 +836,24 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   }
 #endif // HOSTED
 
+#ifdef __cpp_lib_bitset
+  template
+  constexpr void
+  _M_check_initial_position(
+   std::basic_string_view<_CharT, _Traits> __s,
+   typename std::basic_string_view<_CharT, _Traits>::size_type __position
+  ) const
+  {
+# if _GLIBCXX_HOSTED
+   if (__position > __s.size())
+ __throw_out_of_range_fmt(__N("bitset::bitset: __position "
+  "(which is %zu) > __s.size() "
+  "(which is %zu)"),
+  __position, __s.size());
+# endif
+  }
+#endif
+
   _GLIBCXX23_CONSTEXPR
   void _M_check(size_t __position, const char *__s) const
   {
@@ -1008,6 +1031,32 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
}
 #endif // HOSTED
 
+#ifdef __cpp_lib_bitset
+  /**
+   *  Use a subset of a string view.
+   *  @param  __s  A string_view of a sequence of @a 0 and @a 1 characters.
+   *  @param  __position  Index of the first character in @a __s to use.
+   *  @param  __nThe maximum number of characters from @a __s to use.
+   *  @throw std::out_of_range If @a __position is bigger the size
+   *  of @a __s.
+   *  @throw  std::invalid_argument  If a character appears in the string
+   * which is neither @a 0 nor @a 1.
+   */
+  template
+   constexpr explicit
+   bitset(std::basic_string_view<_CharT, _Traits> __s,
+ std::basic_string_view<_CharT, _Traits>::size_type __position = 0,
+ std::basic_string_view<_CharT, _Traits>::size_type __n =
+   std::basic_string_view<_CharT, _Traits>::npos,
+ _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'))
+   : _Base()
+   {
+

[PATCH] libstdc++: make range view ctors explicit (P2711) [PR119744]

2025-07-01 Thread Nathan Myers
Make range view constructors explicit, per P2711. Technically, this
is a breaking change, but it is unlikely to break any production
code, as reliance on non-explicit construction is unidiomatic..

libstdc++-v3/ChangeLog
PR libstdc++/119744
* include/std/ranges: view ctors become explicit
---
 libstdc++-v3/include/std/ranges | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 210ac8274fc..f764aa7512e 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -660,7 +660,7 @@ namespace ranges
   : _M_value(__value)
   { }
 
-  constexpr
+  constexpr explicit
   iota_view(type_identity_t<_Winc> __value,
type_identity_t<_Bound> __bound)
   : _M_value(__value), _M_bound(__bound)
@@ -669,19 +669,19 @@ namespace ranges
  __glibcxx_assert( bool(__value <= __bound) );
   }
 
-  constexpr
+  constexpr explicit
   iota_view(_Iterator __first, _Iterator __last)
requires same_as<_Winc, _Bound>
: iota_view(__first._M_value, __last._M_value)
   { }
 
-  constexpr
+  constexpr explicit
   iota_view(_Iterator __first, unreachable_sentinel_t __last)
requires same_as<_Bound, unreachable_sentinel_t>
: iota_view(__first._M_value, __last)
   { }
 
-  constexpr
+  constexpr explicit
   iota_view(_Iterator __first, _Sentinel __last)
requires (!same_as<_Winc, _Bound>) && (!same_as<_Bound, 
unreachable_sentinel_t>)
: iota_view(__first._M_value, __last._M_bound)
@@ -1811,7 +1811,7 @@ namespace views::__adaptor
  && default_initializable<_Pred>)
= default;
 
-  constexpr
+  constexpr explicit
   filter_view(_Vp __base, _Pred __pred)
: _M_base(std::move(__base)), _M_pred(std::move(__pred))
   { }
@@ -2188,7 +2188,7 @@ namespace views::__adaptor
 && default_initializable<_Fp>)
= default;
 
-  constexpr
+  constexpr explicit
   transform_view(_Vp __base, _Fp __fun)
: _M_base(std::move(__base)), _M_fun(std::move(__fun))
   { }
@@ -2323,7 +2323,7 @@ namespace views::__adaptor
 public:
   take_view() requires default_initializable<_Vp> = default;
 
-  constexpr
+  constexpr explicit
   take_view(_Vp __base, range_difference_t<_Vp> __count)
: _M_base(std::move(__base)), _M_count(std::move(__count))
   { }
@@ -2562,7 +2562,7 @@ namespace views::__adaptor
  && default_initializable<_Pred>)
= default;
 
-  constexpr
+  constexpr explicit
   take_while_view(_Vp __base, _Pred __pred)
: _M_base(std::move(__base)), _M_pred(std::move(__pred))
   { }
@@ -2650,7 +2650,7 @@ namespace views::__adaptor
 public:
   drop_view() requires default_initializable<_Vp> = default;
 
-  constexpr
+  constexpr explicit
   drop_view(_Vp __base, range_difference_t<_Vp> __count)
: _M_base(std::move(__base)), _M_count(__count)
   { __glibcxx_assert(__count >= 0); }
@@ -2804,7 +2804,7 @@ namespace views::__adaptor
  && default_initializable<_Pred>)
= default;
 
-  constexpr
+  constexpr explicit
   drop_while_view(_Vp __base, _Pred __pred)
: _M_base(std::move(__base)), _M_pred(std::move(__pred))
   { }
@@ -3641,7 +3641,7 @@ namespace views::__adaptor
  && default_initializable<_Pattern>)
= default;
 
-  constexpr
+  constexpr explicit
   lazy_split_view(_Vp __base, _Pattern __pattern)
: _M_base(std::move(__base)), _M_pattern(std::move(__pattern))
   { }
@@ -3649,7 +3649,7 @@ namespace views::__adaptor
   template
requires constructible_from<_Vp, views::all_t<_Range>>
  && constructible_from<_Pattern, single_view>>
-   constexpr
+   constexpr explicit
lazy_split_view(_Range&& __r, range_value_t<_Range> __e)
  : _M_base(views::all(std::forward<_Range>(__r))),
_M_pattern(views::single(std::move(__e)))
@@ -3766,7 +3766,7 @@ namespace views::__adaptor
   && default_initializable<_Pattern>)
   = default;
 
-constexpr
+constexpr explicit
 split_view(_Vp __base, _Pattern __pattern)
   : _M_base(std::move(__base)), _M_pattern(std::move(__pattern))
 { }
@@ -3774,7 +3774,7 @@ namespace views::__adaptor
 template
   requires constructible_from<_Vp, views::all_t<_Range>>
&& constructible_from<_Pattern, single_view>>
-constexpr
+constexpr explicit
 split_view(_Range&& __r, range_value_t<_Range> __e)
   : _M_base(views::all(std::forward<_Range>(__r))),
_M_pattern(views::single(std::move(__e)))
@@ -7295,7 +7295,7 @@ namespace views::__adaptor
   

RE: [COMMITTED] cobol: Normalize generating and using function_decls.

2025-07-01 Thread Robert Dubner
> -Original Message-
> From: Rainer Orth 
> Sent: Monday, June 30, 2025 10:27
> To: Robert Dubner 
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: [COMMITTED] cobol: Normalize generating and using
> function_decls.
>
> Hi Robert,
>
> > These changes have been shown to generate more sensible code on both
> > x86_64.
> >
> > On x86_64-pc-linux, a bootstrap build of --enable-languages=c,c++,cobol
> > succeeded.
>
> this patch has one change (not listed in ChangeLog) that broke 32-bit
> Solaris bootstrap:
>
> diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y
> index f0faaa41577..660b0b4c4c2 100644
> --- a/gcc/cobol/parse.y
> +++ b/gcc/cobol/parse.y
> @@ -12359,7 +12359,7 @@ numstr2i( const char input[], radix_t radix ) {
>  return output;
>}
>if( erc == -1 ) {
> -yywarn("'%s' was accepted as %zu", input, integer);
> +yywarn("'%s' was accepted as %ld", input, integer);
>}
>return output;
>  }
>
> This causes
>
> /vol/gcc/src/hg/master/local/gcc/cobol/parse.y: In function ‘real_value
> numstr2i(const char*, radix_t)’:
> /vol/gcc/src/hg/master/local/gcc/cobol/parse.y:12362:12: error: format
> ‘%ld’ expects argument of type ‘long int’, but argument 3 has type
> ‘std::size_t’ {aka ‘unsigned int’} [-Werror=format=]
> 12362 | yywarn("'%s' was accepted as %ld", input, integer);
>   |^~ ~~~
>   |   |
>   |   std::size_t {aka
> unsigned int}
>
> Returning to %zu obviously fixes this.

The fix has been pushed.

>
> Besides, I noticed
>
> diff --git a/gcc/cobol/Make-lang.in b/gcc/cobol/Make-lang.in
> index bec81a6acc0..18eb3b0f1e5 100644
> --- a/gcc/cobol/Make-lang.in
> +++ b/gcc/cobol/Make-lang.in
> @@ -353,6 +353,13 @@ cobol.srcman:
>
>  cobol.mostlyclean:
>
> +gcobol.clean:
> +# This is intended for non-general use.  It is a last-ditch effort to
> flush
> +# out all oject files and executable code for gcobol and libgcobol,
> causing
> +# a complete rebuild of all executable code.
> + rm -fr gcobol cobol1 cobol/*\
> + ../*/libgcobol/*
> +
>
> This is at least incomplete: in multilib builds, there are more
> instances of libgcobol in //libgcobol.
>
>   Rainer
>
> --
> --
> ---
> Rainer Orth, Center for Biotechnology, Bielefeld University


Re: [PATCH] c++: Fix FMV return type ambiguation

2025-07-01 Thread Jason Merrill

On 6/30/25 4:25 AM, Alfie Richards wrote:

Hi Jeff,

Yes agreed, I've respun this to be standalone and moved the relevant test
from another patch to this.

Sending again for reapproval in an abbundance of caution.

Regr tested on Aarch64 and x86.

Thanks,
Alfie

-- >8 --

Add logic for the case of two FMV annotated functions with identical
signature other than the return type.

Previously this was ignored, this changes the behavior to emit a diagnostic.

gcc/cp/ChangeLog:
PR c++/119498
* decl.cc (duplicate_decls): Change logic to not always exclude FMV
annotated functions in cases of return type non-ambiguation.

gcc/testsuite/ChangeLog:
PR c++/119498
* g++.target/aarch64/pr119498.C: New test.
---
  gcc/cp/decl.cc  |  7 +--
  gcc/testsuite/g++.target/aarch64/pr119498.C | 19 +++
  2 files changed, 24 insertions(+), 2 deletions(-)
  create mode 100644 gcc/testsuite/g++.target/aarch64/pr119498.C

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 83c8e283b56..20ff1b9f166 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -2014,8 +2014,11 @@ duplicate_decls (tree newdecl, tree olddecl, bool 
hiding, bool was_hidden)
}
  /* For function versions, params and types match, but they
 are not ambiguous.  */
- else if ((!DECL_FUNCTION_VERSIONED (newdecl)
-   && !DECL_FUNCTION_VERSIONED (olddecl))
+ else if (((!DECL_FUNCTION_VERSIONED (newdecl)
+&& !DECL_FUNCTION_VERSIONED (olddecl))
+   || !comptypes (TREE_TYPE (TREE_TYPE (newdecl)),
+  TREE_TYPE (TREE_TYPE (olddecl)),
+  COMPARE_STRICT))


You could use same_type_p instead of comptypes (..., COMPARE_STRICT)

You probably want to use fndecl_declared_return_type like decls_match.

Jason



Re: [PATCH] libstdc++: Make debug iterator pointer sequence const [PR116369]

2025-07-01 Thread Jonathan Wakely
On Mon, 16 Jun 2025 at 18:36, François Dumont  wrote:
>
> I eventually wonder if it is such a big deal to add the new symbols for 
> _GLIBCXX_DEBUG mode.

I like this version much more than the one trying to duplicate symbols with asm.


> Here is the patch doing this. It avoids to add many const_cast which is what 
> we are trying to achieve here.

I'm still not really sure if this is worth it though - is it fixing a
bug or a correctness problem? (using const_cast is safe if the objects
aren't actually const)

All the new tests already pass, even without this patch. Are these
just tests for const member functions that we aren't currently testing
at all?


> I've updated the PR keeping 2 commits so that if this last step is not good I 
> can just drop it.
>
> I even updated the versioned namespace mode breaking this mode abi, I think 
> it's fine, no ?

Yes that's fine.


>
> François
>
>
>
> On 08/06/2025 22:00, François Dumont wrote:
>
> Here is a new attempt preserving symbols.
>
> libstdc++: Make debug iterator pointer sequence const [PR116369]
>
> In revision a35dd276cbf6236e08bcf6e56e62c2be41cf6e3c the debug sequence
> have been made mutable to allow attach iterators to const containers.
> This change completes this fix by also declaring debug unordered container
> members mutable.
>
> Additionally the debug iterator sequence is now a pointer-to-const and so
> _Safe_sequence_base _M_attach and all other methods are const qualified.
> Not-const methods exported are preserved for abi backward compatibility. 
> The
> new const methods are calling the latter thanks to a safe use of 
> const_cast.
>
> libstdc++-v3/ChangeLog:
>
> PR c++/116369
> * include/debug/safe_base.h
> (_Safe_iterator_base::_M_sequence): Declare as pointer-to-const.
> (_Safe_iterator_base::_M_attach, _M_attach_single): New, take 
> pointer-to-const
> _Safe_sequence_base.
> (_Safe_sequence_base::_M_detach_all, _M_detach_singular, 
> _M_revalidate_singular)
> (_M_swap, _M_get_mutex): New, const qualified.
> (_Safe_sequence_base::_M_attach, _M_attach_single, _M_detach, 
> _M_detach_single):
> const qualify.
> * include/debug/safe_container.h (_Safe_container<>::_M_cont): 
> Add const qualifier.
> (_Safe_container<>::_M_swap_base): New.
> (_Safe_container(_Safe_container&&, const _Alloc&, 
> std::false_type)):
> Adapt to use latter.
> (_Safe_container<>::operator=(_Safe_container&&)): Likewise.
> (_Safe_container<>::_M_swap): Likewise and take parameter as 
> const reference.
> * include/debug/safe_unordered_base.h
> (_Safe_local_iterator_base::_M_safe_container): New.
> (_Safe_local_iterator_base::_Safe_local_iterator_base): Take
> _Safe_unordered_container_base as pointer-to-const.
> (_Safe_unordered_container_base::_M_attach, _M_attach_single): 
> New, take
> container as _Safe_unordered_container_base pointer-to-const.
> (_Safe_unordered_container_base::_M_local_iterators, 
> _M_const_local_iterators):
> Add mutable.
> (_Safe_unordered_container_base::_M_detach_all, _M_swap): New, 
> const qualify.
> (_Safe_unordered_container_base::_M_attach_local, 
> _M_attach_local_single)
> (_M_detach_local, _M_detach_local_single): Add const qualifier.
> * include/debug/safe_iterator.h (_Safe_iterator<>::_M_attach, 
> _M_attach_single):
> Take _Safe_sequence_base as pointer-to-const.
> (_Safe_iterator<>::_M_get_sequence): Add const_cast and comment 
> about it.
> * include/debug/safe_local_iterator.h (_Safe_local_iterator<>): 
> Replace usages
> of _M_sequence member by _M_safe_container().
> (_Safe_local_iterator<>::_M_attach, _M_attach_single): Take
> _Safe_unordered_container_base as pointer-to-const.
> (_Safe_local_iterator<>::_M_get_sequence): Rename into...
> (_Safe_local_iterator<>::_M_get_ucontainer): ...this. Add 
> necessary const_cast and
> comment to explain it.
> (_Safe_local_iterator<>::_M_is_begin, _M_is_end): Adapt.
> * include/debug/safe_local_iterator.tcc: Adapt.
> * include/debug/safe_sequence.h
> (_Safe_sequence<>::_M_invalidate_if, _M_transfer_from_if): Add 
> const qualifier.
> * include/debug/safe_sequence.tcc: Adapt.
> * include/debug/deque (std::__debug::deque::erase): Adapt to use 
> new const
> qualified methods.
> * include/debug/formatter.h: Adapt.
> * include/debug/forward_list (_Safe_forward_list::_M_this): Add 
> const
> qualification.
> (_Safe_forward_list::_M_swap_aux): Rename into...
> (_Safe_forward_list::

Re: [PATCH v2 1/5] libstdc++: Check prerequisites of layout_*::operator().

2025-07-01 Thread Jonathan Wakely
On Tue, 1 Jul 2025 at 11:32, Tomasz Kaminski  wrote:
>
> Hi,
> More of the review will be later, but I have noticed that you have added 
> preconditions checks
> to the layouts, and then avoid checking them inside the operator[] of the 
> mdspan. This is general
> sounds good.
>
> However, the precondition on mdspan::operator[] is now hardened: 
> https://eel.is/c++draft/views.multidim#mdspan.mdspan.members-3.
> This implies that breaking this precondition is a contract violation, and 
> thus the user may expect a contract violation handler to be invoked
> for it. Amongst the information provided to the handler via 
> contract_violation object (https://eel.is/c++draft/support.contract.violation)
> is source_location, that includes the name.

Even without contracts, our __glibcxx_assert macro includes the
__PRETTY_FUNCTION__ string in the abort message.

> Given that I think we want to always check the extents in operator[] of 
> mdspan, and thus remove
> the checks from layout (to avoid duplication).

I think it's probably QoI whether the contract checks happen directly
in the operator[] function or in something that it calls. If doing the
checks in operator[] has no extra runtime cost (e.g. due to them
getting duplicated), then I think it is better to do them there, so
that errors are reported from the "correct" place. But if it hurts
performance, I don't think it's essential to check them there.


>
> Hope, the above makes sense.
>
> Regards,
> Tomasz
>
> On Fri, Jun 27, 2025 at 11:12 AM Luc Grosheintz  
> wrote:
>>
>> Previously the prerequisite that the arguments passed to operator() are
>> a multi-dimensional index (of extents()) was not checked.
>>
>> This commit adds the __glibcxx_asserts and the required tests.
>>
>> libstdc++-v3/ChangeLog:
>>
>> * include/std/mdspan: Check prerequisites of
>> layout_*::operator().
>> * testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc:
>> Add tests for prerequisites.
>>
>> Signed-off-by: Luc Grosheintz 
>> ---
>>  libstdc++-v3/include/std/mdspan   |  4 +++
>>  .../mdspan/layouts/class_mandate_neg.cc   | 26 +++
>>  2 files changed, 30 insertions(+)
>>
>> diff --git a/libstdc++-v3/include/std/mdspan 
>> b/libstdc++-v3/include/std/mdspan
>> index c72a64094b7..39d02ac08df 100644
>> --- a/libstdc++-v3/include/std/mdspan
>> +++ b/libstdc++-v3/include/std/mdspan
>> @@ -441,6 +441,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>> _IndexType __mult = 1;
>> auto __update = [&, __pos = 0u](_IndexType __idx) mutable
>>   {
>> +   __glibcxx_assert(cmp_less(__idx, __exts.extent(__pos)));
>> __res += __idx * __mult;
>> __mult *= __exts.extent(__pos);
>> ++__pos;
>> @@ -651,6 +652,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>> auto __update = [&, __pos = __exts.rank()](_IndexType) mutable
>>   {
>> --__pos;
>> +   __glibcxx_assert(cmp_less(__ind_arr[__pos],
>> + __exts.extent(__pos)));
>> __res += __ind_arr[__pos] * __mult;
>> __mult *= __exts.extent(__pos);
>>   };
>> @@ -822,6 +825,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>>   {
>> auto __update = [&, __pos = 0u](_IndexType __idx) mutable
>>   {
>> +   __glibcxx_assert(cmp_less(__idx, 
>> __m.extents().extent(__pos)));
>> __res += __idx * __m.stride(__pos++);
>>   };
>> (__update(__indices), ...);
>> diff --git 
>> a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc 
>> b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc
>> index 7091153daba..f5aab22aff0 100644
>> --- 
>> a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc
>> +++ 
>> b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc
>> @@ -45,4 +45,30 @@ auto b5 = B<5, std::layout_stride, std::layout_right>();  
>> // { dg-error "require
>>  auto b6 = B<6, std::layout_stride, std::layout_left>();   // { dg-error 
>> "required from" }
>>  auto b7 = B<7, std::layout_stride, std::layout_stride>(); // { dg-error 
>> "required from" }
>>
>> +template
>> +  constexpr bool
>> +  test_linear_index_0d()
>> +  {
>> +auto m = typename Layout::mapping>{};
>> +(void) m(0); // { dg-error "expansion of" }
>> +return true;
>> +  }
>> +static_assert(test_linear_index_0d()); // { dg-error 
>> "expansion of" }
>> +static_assert(test_linear_index_0d()); // { dg-error 
>> "expansion of" }
>> +static_assert(test_linear_index_0d()); // { dg-error 
>> "expansion of" }
>> +
>> +template
>> +  constexpr bool
>> +  test_linear_index_3d()
>> +  {
>> +auto m = typename Layout::mapping>{};
>> +(void) m(2, 5, 5); // { dg-error "expansion of" }
>> +return true;
>> +  }
>> +static_assert(test_linear_index_3d()); // { dg-error 
>>

[COMMITTED] cobol: Repair printf format of size_t.

2025-07-01 Thread Robert Dubner
>From 4e8cb6fb26abc2601850577d13bbc669beee0290 Mon Sep 17 00:00:00 2001
From: Robert Dubner 
Date: Tue, 1 Jul 2025 12:02:21 -0400
Subject: [PATCH] cobol: Repair printf format of size_t.

gcc/cobol/ChangeLog:

* parse.y: printf() of size_t is %zu, not %ld.
---
 gcc/cobol/parse.y | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y
index 57a41bbca71..74637c9641f 100644
--- a/gcc/cobol/parse.y
+++ b/gcc/cobol/parse.y
@@ -12404,7 +12404,7 @@ numstr2i( const char input[], radix_t radix ) {
 return output;
   }
   if( erc == -1 ) {
-yywarn("'%s' was accepted as %ld", input, integer);
+yywarn("'%s' was accepted as %zu", input, integer);
   }
   return output;
 }
-- 
2.34.1



Re: [PATCH] testsuite: Fix up gcc.target/powerpc/builtin_altivec_tr_stxvr_runnable.c test [PR120919]

2025-07-01 Thread Segher Boessenkool
Hi!

On Tue, Jul 01, 2025 at 05:16:45PM +0200, Jakub Jelinek wrote:
> This test seems to fail when testing with
> RUNTESTFLAGS="--target_board=unix/'{,-fstack-protector-strong}'"
> on power10.

Please mention near the start of the commit message (like, in the
subject already!) that the testcase did UB, and this patch fixes it?

> In my reading of the test and the instructions emitted by the
> builtins, it invokes UB 4 times, each time overwriting one byte
> after some variable (sc, then ss, then si and then sll).

Yup.

> If we are lucky, like at -O0 -mcpu=power10, there is just padding
> there or something that doesn't make the tests fail, if unlucky
> like with -O0 -mcpu=power10 -fstack-protector-strong,
> &sc + 1 == &expected_sc
> and so it overwrites the expected_sc variable.

Testcases do not always catch issues they were not designed for :-)

> The following patch fixes that by using arrays of 2 elements, so that
> the overwriting of 1 byte happens to the part of the same variable.
> 
> Tested on powerpc64le-linux both without and with -fstack-protector-strong,
> ok for trunk and 15.2/14.4?

Okay everywhere (with a better commit message).  Thanks!


Segher


> 2025-07-01  Jakub Jelinek  
> 
>   PR testsuite/120919
>   * gcc.target/powerpc/builtin_altivec_tr_stxvr_runnable.c (main): Change
>   sc, ss, si and sll vars from scalars to arrays of 2 elements,
>   initialize and test just the first one though.
> 
> --- gcc/testsuite/gcc.target/powerpc/builtin_altivec_tr_stxvr_runnable.c.jj   
> 2023-06-03 15:32:05.230399713 +0200
> +++ gcc/testsuite/gcc.target/powerpc/builtin_altivec_tr_stxvr_runnable.c  
> 2025-07-01 17:03:03.026845771 +0200
> @@ -27,10 +27,10 @@ int
>  main () {
>int i;
>signed long sl;
> -  signed char sc, expected_sc;
> -  signed short ss, expected_ss;
> -  signed int si, expected_si;
> -  signed long long int sll, expected_sll;
> +  signed char sc[2], expected_sc;
> +  signed short ss[2], expected_ss;
> +  signed int si[2], expected_si;
> +  signed long long int sll[2], expected_sll;
>signed char *psc;
>signed short *pss;
>signed int *psi;
> @@ -41,56 +41,56 @@ main () {
>printf("Data to store [%d] = 0x%llx %llx\n", i, val.ull[1], val.ull[0]);
>  #endif
>  
> -  psc = ≻
> -  pss = &ss;
> -  psi = &si;
> -  psll = &sll;
> +  psc = &sc[0];
> +  pss = &ss[0];
> +  psi = &si[0];
> +  psll = &sll[0];
>  
>sl = 1;
> -  sc = 0xA1;
> +  sc[0] = 0xA1;
>expected_sc = 0xA1;
>__builtin_altivec_tr_stxvrbx (store_data, sl, psc);
>  
> -  if (expected_sc != sc & 0xFF)
> +  if (expected_sc != sc[0] & 0xFF)
>  #if DEBUG
>  printf(" ERROR: Signed char = 0x%x doesn't match expected value 0x%x\n",
> -sc & 0xFF, expected_sc);
> +sc[0] & 0xFF, expected_sc);
>  #else
>  abort();
>  #endif
>  
> -  ss = 0x52;
> +  ss[0] = 0x52;
>expected_ss = 0x1752;
>__builtin_altivec_tr_stxvrhx (store_data, sl, pss);
>  
> -  if (expected_ss != ss & 0x)
> +  if (expected_ss != ss[0] & 0x)
>  #if DEBUG
>  printf(" ERROR: Signed short = 0x%x doesn't match expected value 0x%x\n",
> -ss, expected_ss) & 0x;
> +ss[0], expected_ss) & 0x;
>  #else
>  abort();
>  #endif
>  
> -  si = 0x21;
> +  si[0] = 0x21;
>expected_si = 0x54321721;
>__builtin_altivec_tr_stxvrwx (store_data, sl, psi);
>  
> -  if (expected_si != si)
> +  if (expected_si != si[0])
>  #if DEBUG
>  printf(" ERROR: Signed int = 0x%x doesn't match expected value 0x%x\n",
> -si, expected_si);
> +si[0], expected_si);
>  #else
>  abort();
>  #endif
>  
> -  sll = 0x12FFULL;
> +  sll[0] = 0x12FFULL;
>expected_sll = 0xdcba9876543217FF;
>__builtin_altivec_tr_stxvrdx (store_data, sl, psll);
>  
> -  if (expected_sll != sll)
> +  if (expected_sll != sll[0])
>  #if DEBUG
>  printf(" ERROR: Signed long long int = 0x%llx doesn't match expected 
> value 0x%llx\n",
> -sll, expected_sll);
> +sll[0], expected_sll);
>  #else
>  abort();
>  #endif
> 
>   Jakub


Re: [PATCH RFC] libgcc: don't use a weak ref for __cxa_finalize

2025-07-01 Thread Jason Merrill

On 7/1/25 10:57 AM, Florian Weimer wrote:

* Jason Merrill:


On 6/30/25 5:22 PM, Florian Weimer wrote:

* Jason Merrill:


On 6/28/25 3:17 PM, Florian Weimer wrote:

* Jason Merrill:


Since r10-6069[1] we control the call to __cxa_finalize with
DEFAULT_USE_CXA_ATEXIT, so there's no need to also declare it as a weak
reference; if the target has __cxa_atexit, it must also have __cxa_finalize.



I expect that most targets do not need __cxa_finalize.  They can run
the registered destructors directly, without waiting for a call to
__cxa_finalize.


AFAICT glibc still uses __cxa_finalize to run destructors on dlclose;
at least that's what its comment says.

Yes, but for most target processors, there is a variety of targets
which
don't do this (no dlclose …), hence “most targets” is still true.
Maybe. 8-)


But if those targets don't have dlclose, they don't need __cxa_atexit
and should (and probably do) leave default_use_cxa_atexit off in
config.gcc.


Hmm, that's a fair point.  I didn't realize that they could use atexit
directly.


I think with your patch, libc will is always linked in as well,
assuming that it's the source of the __cxa_finalize definition.


True, so that's not a difference for __cxa_atexit targets.

Existing targets that reuse the glibc toolchain will have to do
something about __cxa_finalize after your change goes in, though.


If they're linking shared libraries (which seems unlikely in your
bootloader scenario below).


It just occurred to me that linking shared libraries usually doesn't use
-Wl,-z,defs yet, so you would just get underlinking as before.  So
-nostartfiles probably is not needed after all.


I'm not sure if that's what our users expect.  Common practice is to
use *-linux-gnu targets to build bootloaders, kernels and whatnot
using the same toolchain, and not create a separate *-none target
with different configure options.  I think that's … not great for
full libc targets (where the toolchain may end up supporting
GNU-style symbol versions, but the dynamic linker does not).  But for
more limited bootloader-type scenarios (no full libc, no dynamic
linking), it evidently works quite well so far.


Interesting point, are there in fact such packages that rely on
-fno-use-cxa-atexit?


I found this one:




That has a comment that it's probably wrong and should be removed.  The 
patch that added it claimed that it was to avoid an undefined symbol 
error for plain atexit (not __cxa_atexit), which makes no sense.



Possibly more could be discovered by poking around in Debian Code Search
.


Thanks for the pointer.  Outside of compiler testsuites:

https://sources.debian.org/src/scalene/1.5.51-1/vendor/printf/Makefile/#L146
https://sources.debian.org/src/pico-sdk/2.1.1-1/src/rp2_common/pico_cxx_options/CMakeLists.txt/?hl=25#L25

These look either unneeded for embedded use or wrong when used on a 
hosted system; the target toolchain will already disable the flag if 
appropriate.  Possibly these uses date back to before that was true.


https://sources.debian.org/src/intel-graphics-compiler/1.0.17791.18-1/IGC/CMakeLists.txt/?hl=1097#L1097

This claims to be working around a bug in Android __cxa_atexit. 
Hopefully that has been fixed by now.


https://sources.debian.org/src/intel-gmmlib/22.7.2+ds1-1/Source/GmmLib/Linux.cmake/?hl=129#L129
https://sources.debian.org/src/intel-media-driver/25.2.3+dfsg1-1/media_driver/cmake/linux/media_compile_flags_linux.cmake/?hl=99#L99

I'm guessing these are cargo cult copying from the instance above, 
wrongly passed on from android to linux configurations.


So, some packages that are using the flag incorrectly might be 
encouraged to stop doing so (if they care about the warning).  It 
doesn't seem that any of these would actually break.


Jason



Re: [PATCH] testsuite, powerpc: Fix vsx-vectorize-* after alignment peeling [PR118567]

2025-07-01 Thread Segher Boessenkool
Hi!

On Tue, Jul 01, 2025 at 08:39:26PM +0200, Jakub Jelinek wrote:
> On Tue, Jul 01, 2025 at 12:04:04PM -0500, Segher Boessenkool wrote:
> > On Mon, Feb 17, 2025 at 02:28:50PM +, Alex Coplan wrote:
> > > After the recent alignment peeling enhancements in the vectorizer we
> > > started vectorizing the "checking" loops (that check for the right
> > > result) in gcc.target/powerpc/vsx-vectorize-*.c,  thus skewing the
> > > expected counts of various scan-dump-times tests (causing them to FAIL).
> > > This adds #pragma GCC novector above the relevant loops to prevent them
> > > from being vectorized, thereby fixing the test failures.
> > 
> > It is fundamentally incorrect to add a "novector" attribute to testcases
> > called "vsx-vectorize-*".  Even if it is just to some part of the code;
> > if you want to only test some part of code, put it in a different file.
> > 
> > If the testcases are less than stellar (and pretty much anything using
> > scan-assembler-times is!), fix *that*?
> 
> All the 8 testcases have
> /* Taken from vect/vect-95.c.  */
> comment and
> gcc.dg/vect/vect-95.c test uses that pragma already:

Yeah.  But that has very unpredictable results *in the best case*.

And in any acceptable case any such thing will be documented to say what
it is for!  No surprising thing is ever obvious.

> __attribute__ ((noinline))
> void bar (float *pd, float *pa, float *pb, float *pc)
> {
>   int i;
> 
>   /* check results:  */
> #pragma GCC novector
>   for (i = 0; i < N; i++)
> {
>   if (pa[i] != (pb[i] * pc[i]))
> abort ();
>   if (pd[i] != 5.0)
> abort ();
> }
> 
>   return;
> }
> 
> That said, unlike gcc.dg/vect/vect-95.c test, all these 8 are
> /* { dg-do compile } */
> test, so I fail to understand why they have definitions (rather than
> declarations) of bar and main.

Plain inertia?

No tests become good tests without effort.  And tests that are not good
tests require constant maintenance!

> Or perhaps vsx-vectorize-*.c could
> be dg-do compile and with just bar declaration and main1 definition,
> and then have 8 further tests that include those and include the 2 headers,
> define bar and main and are dg-do run rather than dg-do compile and don't
> scan any dumps.

It isn't very clear what to decide to do, all those tests (like so very
many other tests) do not contain the by far most important piece of
information that should be there in any test: they do not say what they
intend to test!

So if anything happens (like, unrelated changes caused the instruction
counts here to change, a very common occurrence with
scan-assembler-times tests, those things are usually inherently
unstable), it won't clear to anyone what made the test fail, or how to
make it pass again.

Adding intrinsics (like pragmas) without considering how to make the
testcases actually better (instead of merley seemingly passing again)
is not the way forward.


Segher


[PATCH] Fortran: fix minor issues with coarrays

2025-07-01 Thread Harald Anlauf

Dear all,

the attached patch fixes the following minor issues found by running
f951 under valgrind for the just added new testcases coindexed_6.f90
and coindexed_7.f90:

- minor front-end memleaks with non-freed strings and lost GMP variables
 (these are simple and obvious fixes)

- an inconsistency between pure/elemental functions being either
 non-intrinsic or intrinsic.  Checking for the latter was likely missed
 from the beginning.

No new testcase.

Regtested on x86_64-pc-linux-gnu.  OK for mainline?

Thanks,
Harald

From 1630d24e3e1d3ab5ae6450da0da555f4eed6339c Mon Sep 17 00:00:00 2001
From: Harald Anlauf 
Date: Tue, 1 Jul 2025 21:41:53 +0200
Subject: [PATCH] Fortran: fix minor issues with coarrays

gcc/fortran/ChangeLog:

	* coarray.cc (check_add_new_component): Treat pure and elemental
	intrinsic functions the same as non-intrinsic ones.
	(create_caf_add_data_parameter_type): Fix front-end memleaks.
	* trans-intrinsic.cc (conv_caf_func_index): Likewise.
---
 gcc/fortran/coarray.cc | 7 +--
 gcc/fortran/trans-intrinsic.cc | 2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/coarray.cc b/gcc/fortran/coarray.cc
index 6914697c78b..ef8fd4e42d0 100644
--- a/gcc/fortran/coarray.cc
+++ b/gcc/fortran/coarray.cc
@@ -697,7 +697,10 @@ check_add_new_component (gfc_symbol *type, gfc_expr *e, gfc_symbol *add_data)
 	  break;
 	case EXPR_FUNCTION:
 	  if (!e->symtree->n.sym->attr.pure
-	  && !e->symtree->n.sym->attr.elemental)
+	  && !e->symtree->n.sym->attr.elemental
+	  && !(e->value.function.isym
+		   && (e->value.function.isym->pure
+		   || e->value.function.isym->elemental)))
 	/* Treat non-pure/non-elemental functions.  */
 	check_add_new_comp_handle_array (e, type, add_data);
 	  else
@@ -743,7 +746,6 @@ create_caf_add_data_parameter_type (gfc_expr *expr, gfc_namespace *ns,
   add_data->as->lower[0]
 = gfc_get_constant_expr (BT_INTEGER, gfc_default_integer_kind,
 			 &expr->where);
-  mpz_init (add_data->as->lower[0]->value.integer);
   mpz_set_si (add_data->as->lower[0]->value.integer, 1);
 
   for (gfc_ref *ref = expr->ref; ref; ref = ref->next)
@@ -763,6 +765,7 @@ create_caf_add_data_parameter_type (gfc_expr *expr, gfc_namespace *ns,
   type->declared_at = expr->where;
   gfc_set_sym_referenced (type);
   gfc_commit_symbol (type);
+  free (name);
   return type;
 }
 
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index fce5ee28de8..f1bfd3eee51 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -1052,7 +1052,7 @@ conv_caf_func_index (stmtblock_t *block, gfc_namespace *ns, const char *pat,
   index_st->n.sym->value
 = gfc_get_constant_expr (BT_INTEGER, gfc_default_integer_kind,
 			 &gfc_current_locus);
-  mpz_init_set_si (index_st->n.sym->value->value.integer, -1);
+  mpz_set_si (index_st->n.sym->value->value.integer, -1);
   index_st->n.sym->ts.type = BT_INTEGER;
   index_st->n.sym->ts.kind = gfc_default_integer_kind;
   gfc_set_sym_referenced (index_st->n.sym);
-- 
2.43.0



Re: [PATCH] Fortran: fix minor issues with coarrays

2025-07-01 Thread Jerry D

On 7/1/25 12:51 PM, Harald Anlauf wrote:

Dear all,

the attached patch fixes the following minor issues found by running
f951 under valgrind for the just added new testcases coindexed_6.f90
and coindexed_7.f90:

- minor front-end memleaks with non-freed strings and lost GMP variables
  (these are simple and obvious fixes)

- an inconsistency between pure/elemental functions being either
  non-intrinsic or intrinsic.  Checking for the latter was likely missed
  from the beginning.

No new testcase.

Regtested on x86_64-pc-linux-gnu.  OK for mainline?

Thanks,
Harald



Yes, OK, straight-forward.

Thanks,

Jerry


Re: [PATCH] Fortran: fix minor issues with coarrays

2025-07-01 Thread Harald Anlauf

Am 01.07.25 um 21:54 schrieb Jerry D:

On 7/1/25 12:51 PM, Harald Anlauf wrote:

Dear all,

the attached patch fixes the following minor issues found by running
f951 under valgrind for the just added new testcases coindexed_6.f90
and coindexed_7.f90:

- minor front-end memleaks with non-freed strings and lost GMP variables
  (these are simple and obvious fixes)

- an inconsistency between pure/elemental functions being either
  non-intrinsic or intrinsic.  Checking for the latter was likely missed
  from the beginning.

No new testcase.

Regtested on x86_64-pc-linux-gnu.  OK for mainline?

Thanks,
Harald



Yes, OK, straight-forward.

Thanks,

Jerry



Thanks, Jerry!

Pushed as r16-1903-gfc029f5d34168c.

Hope it doesn't interfere with Andre's work...

Harald




[Ada] Fix PR ada/120705

2025-07-01 Thread Eric Botcazou
This fixes an assertion failure for the Finalizable aspect applied on a tagged 
type with discriminant-dependent component.

Tested on x86-64/Linux, applied on the mainline and 15 branch.


2025-07-01  Eric Botcazou  

PR ada/120705
* exp_ch6.adb (Needs_BIP_Collection): Always return False if the
type has relaxed finalization.


2025-07-01  Eric Botcazou  

* gnat.dg/specs/finalizable2.ads: New test.

-- 
Eric Botcazoudiff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index 26302baad64..621619220a0 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -9575,9 +9575,8 @@ package body Exp_Ch6 is
   --  such build-in-place functions, primitive or not.
 
   return not Restriction_Active (No_Finalization)
-and then ((Needs_Finalization (Typ)
-and then not Has_Relaxed_Finalization (Typ))
-  or else Is_Tagged_Type (Typ))
+and then (Needs_Finalization (Typ) or else Is_Tagged_Type (Typ))
+and then not Has_Relaxed_Finalization (Typ)
 and then not Has_Foreign_Convention (Typ);
end Needs_BIP_Collection;
 
-- { dg-do compile }
-- { dg-options "-gnatX0" }

package Finalizable2 is

   type Root is abstract tagged limited null record
  with Finalizable => (Initialize => Initialize);

   procedure Initialize (this : in out Root) is abstract;

   type Ext (L : Natural) is new Root with record
  A : String (1 .. L);
   end record;

   overriding procedure Initialize (this : in out Ext) is null;

   function Make return Ext is (L => 3, A => "asd");

   Obj : Ext := Make;

end Finalizable2;


Re: [PATCH] aarch64: Enable selective LDAPUR generation for cores with RCPC2

2025-07-01 Thread Richard Sandiford
Soumya AR  writes:
> From 2a2c3e3683aaf3041524df166fc6f8cf20895a0b Mon Sep 17 00:00:00 2001
> From: Soumya AR 
> Date: Mon, 30 Jun 2025 12:17:30 -0700
> Subject: [PATCH] aarch64: Enable selective LDAPUR generation for cores with
>  RCPC2
>
> This patch adds the ability to fold the address computation into the 
> addressing
> mode for LDAPR instructions using LDAPUR when RCPC2 is available.
>
> LDAPUR emission is controlled by the tune flag enable_ldapur, to enable it on 
> a
> per-core basis. Earlier, the following code:
>
> uint64_t
> foo (std::atomic *x)
> {
>   return x[1].load(std::memory_order_acquire);
> }
>
> would generate:
>
> foo(std::atomic*):
>   add x0, x0, 8
>   ldapr   x0, [x0]
>   ret
>
> but now generates:
>
> foo(std::atomic*):
>   ldapur  x0, [x0, 8]
>   ret
>
> The patch was bootstrapped and regtested on aarch64-linux-gnu, no regression.
> OK for mainline?
>
> Signed-off-by: Soumya AR 
>
> gcc/ChangeLog:
>
>   * config/aarch64/aarch64-tuning-flags.def (AARCH64_EXTRA_TUNING_OPTION):
>   Add the enable_ldapur flag to conwtrol LDAPUR emission.
>   * config/aarch64/aarch64.h (TARGET_ENABLE_LDAPUR): Use new flag.
>   * config/aarch64/aarch64.md (any): Add ldapur_enable attribute.
>   * config/aarch64/atomics.md: (aarch64_atomic_load_rcpc): Modify
>   to emit LDAPUR for cores with RCPC2 when enable_ldapur is set.
>   (*aarch64_atomic_load_rcpc_zext): Likewise.
>   (*aarch64_atomic_load_rcpc_sext): Modified to emit LDAPURS
>   for addressing with offsets.
>
> gcc/testsuite/ChangeLog:
>
>   * gcc.target/aarch64/ldapur.c: New test.

Thanks for doing this.  It generally looks good, but a couple of comments
below:

> ---
>  gcc/config/aarch64/aarch64-tuning-flags.def |  2 +
>  gcc/config/aarch64/aarch64.h|  5 ++
>  gcc/config/aarch64/aarch64.md   | 11 +++-
>  gcc/config/aarch64/atomics.md   | 22 +---
>  gcc/testsuite/gcc.target/aarch64/ldapur.c   | 61 +
>  5 files changed, 92 insertions(+), 9 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/aarch64/ldapur.c
>
> diff --git a/gcc/config/aarch64/aarch64-tuning-flags.def 
> b/gcc/config/aarch64/aarch64-tuning-flags.def
> index f2c916e9d77..5bf54165306 100644
> --- a/gcc/config/aarch64/aarch64-tuning-flags.def
> +++ b/gcc/config/aarch64/aarch64-tuning-flags.def
> @@ -44,6 +44,8 @@ AARCH64_EXTRA_TUNING_OPTION ("avoid_cross_loop_fma", 
> AVOID_CROSS_LOOP_FMA)
>  
>  AARCH64_EXTRA_TUNING_OPTION ("fully_pipelined_fma", FULLY_PIPELINED_FMA)
>  
> +AARCH64_EXTRA_TUNING_OPTION ("enable_ldapur", ENABLE_LDAPUR)
> +

Let's see what others say, but personally, I think this would be better
as an opt-out, such as avoid_ldapur.  The natural default seems to be to use
the extra addressing capacity when it's available and have CPUs explicitly
flag when they don't want that.

A good, conservatively correct, default would probably be to add avoid_ldapur
to every *current* CPU that includes rcpc2 and then separately remove it
from those that are known not to need it.  In that sense, it's more work
for current CPUs than the current patch, but it should ease the impact
on future CPUs.

>  /* Enable is the target prefers to use a fresh register for predicate outputs
> rather than re-use an input predicate register.  */
>  AARCH64_EXTRA_TUNING_OPTION ("avoid_pred_rmw", AVOID_PRED_RMW)
> diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
> index e8bd8c73c12..08ad8350fbc 100644
> --- a/gcc/config/aarch64/aarch64.h
> +++ b/gcc/config/aarch64/aarch64.h
> @@ -490,6 +490,11 @@ constexpr auto AARCH64_FL_DEFAULT_ISA_MODE 
> ATTRIBUTE_UNUSED
>(bool (aarch64_tune_params.extra_tuning_flags \
>& AARCH64_EXTRA_TUNE_CHEAP_FPMR_WRITE))
>  
> +/* Enable folding address computation into LDAPUR when RCPC2 is available.  
> */
> +#define TARGET_ENABLE_LDAPUR (TARGET_RCPC2 \
> +   && (aarch64_tune_params.extra_tuning_flags \
> +   & AARCH64_EXTRA_TUNE_ENABLE_LDAPUR))
> +
>  /* Combinatorial tests.  */
>  
>  #define TARGET_SVE2_OR_SME2 \
> diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
> index e11e13033d2..76dc0e82c2a 100644
> --- a/gcc/config/aarch64/aarch64.md
> +++ b/gcc/config/aarch64/aarch64.md
> @@ -482,6 +482,8 @@
>  ;; clobber for SVE predicates.
>  (define_attr "pred_clobber" "any,no,yes" (const_string "any"))
>  
> +(define_attr "ldapur_enable" "any,no,yes" (const_string "any"))
> +
>  ;; [For compatibility with Arm in pipeline models]
>  ;; Attribute that specifies whether or not the instruction touches fp
>  ;; registers.
> @@ -506,7 +508,14 @@
> (eq_attr "pred_clobber" "yes")
> (match_test "TARGET_SVE_PRED_CLOBBER"))
>   (eq_attr "pred_clobber" "any"))
> -
> +  (ior
> + (and
> +   (eq_attr "ldapur_enable" "no")
> +   (match_test "!TARGET_ENABLE_LDAPUR"))
> + (and
> +   (eq_attr "ldapur_

Re: [PATCH] testsuite, powerpc: Fix vsx-vectorize-* after alignment peeling [PR118567]

2025-07-01 Thread Segher Boessenkool
Hi!

On Mon, Feb 17, 2025 at 02:28:50PM +, Alex Coplan wrote:
> After the recent alignment peeling enhancements in the vectorizer we
> started vectorizing the "checking" loops (that check for the right
> result) in gcc.target/powerpc/vsx-vectorize-*.c,  thus skewing the
> expected counts of various scan-dump-times tests (causing them to FAIL).
> This adds #pragma GCC novector above the relevant loops to prevent them
> from being vectorized, thereby fixing the test failures.

It is fundamentally incorrect to add a "novector" attribute to testcases
called "vsx-vectorize-*".  Even if it is just to some part of the code;
if you want to only test some part of code, put it in a different file.

If the testcases are less than stellar (and pretty much anything using
scan-assembler-times is!), fix *that*?


Segher


Re: [PATCH] libstdc++: Make debug iterator pointer sequence const [PR116369]

2025-07-01 Thread Jonathan Wakely
On Mon, 23 Jun 2025 at 18:19, François Dumont  wrote:
>
> Hi
>
> Even if you have no time to review this for now could you only answer the 
> question below that is to say:
>
> Should the current _GLIBCXX_INLINE_VERSION abi be preserved ?

No, that's not necessary


>
> Thanks
>
> On 16/06/2025 19:36, François Dumont wrote:
>
> I eventually wonder if it is such a big deal to add the new symbols for 
> _GLIBCXX_DEBUG mode.
>
> Here is the patch doing this. It avoids to add many const_cast which is what 
> we are trying to achieve here.
>
> I've updated the PR keeping 2 commits so that if this last step is not good I 
> can just drop it.
>
> I even updated the versioned namespace mode breaking this mode abi, I think 
> it's fine, no ?
>
> François
>
>
>
> On 08/06/2025 22:00, François Dumont wrote:
>
> Here is a new attempt preserving symbols.
>
> libstdc++: Make debug iterator pointer sequence const [PR116369]
>
> In revision a35dd276cbf6236e08bcf6e56e62c2be41cf6e3c the debug sequence
> have been made mutable to allow attach iterators to const containers.
> This change completes this fix by also declaring debug unordered container
> members mutable.
>
> Additionally the debug iterator sequence is now a pointer-to-const and so
> _Safe_sequence_base _M_attach and all other methods are const qualified.
> Not-const methods exported are preserved for abi backward compatibility. 
> The
> new const methods are calling the latter thanks to a safe use of 
> const_cast.
>
> libstdc++-v3/ChangeLog:
>
> PR c++/116369
> * include/debug/safe_base.h
> (_Safe_iterator_base::_M_sequence): Declare as pointer-to-const.
> (_Safe_iterator_base::_M_attach, _M_attach_single): New, take 
> pointer-to-const
> _Safe_sequence_base.
> (_Safe_sequence_base::_M_detach_all, _M_detach_singular, 
> _M_revalidate_singular)
> (_M_swap, _M_get_mutex): New, const qualified.
> (_Safe_sequence_base::_M_attach, _M_attach_single, _M_detach, 
> _M_detach_single):
> const qualify.
> * include/debug/safe_container.h (_Safe_container<>::_M_cont): 
> Add const qualifier.
> (_Safe_container<>::_M_swap_base): New.
> (_Safe_container(_Safe_container&&, const _Alloc&, 
> std::false_type)):
> Adapt to use latter.
> (_Safe_container<>::operator=(_Safe_container&&)): Likewise.
> (_Safe_container<>::_M_swap): Likewise and take parameter as 
> const reference.
> * include/debug/safe_unordered_base.h
> (_Safe_local_iterator_base::_M_safe_container): New.
> (_Safe_local_iterator_base::_Safe_local_iterator_base): Take
> _Safe_unordered_container_base as pointer-to-const.
> (_Safe_unordered_container_base::_M_attach, _M_attach_single): 
> New, take
> container as _Safe_unordered_container_base pointer-to-const.
> (_Safe_unordered_container_base::_M_local_iterators, 
> _M_const_local_iterators):
> Add mutable.
> (_Safe_unordered_container_base::_M_detach_all, _M_swap): New, 
> const qualify.
> (_Safe_unordered_container_base::_M_attach_local, 
> _M_attach_local_single)
> (_M_detach_local, _M_detach_local_single): Add const qualifier.
> * include/debug/safe_iterator.h (_Safe_iterator<>::_M_attach, 
> _M_attach_single):
> Take _Safe_sequence_base as pointer-to-const.
> (_Safe_iterator<>::_M_get_sequence): Add const_cast and comment 
> about it.
> * include/debug/safe_local_iterator.h (_Safe_local_iterator<>): 
> Replace usages
> of _M_sequence member by _M_safe_container().
> (_Safe_local_iterator<>::_M_attach, _M_attach_single): Take
> _Safe_unordered_container_base as pointer-to-const.
> (_Safe_local_iterator<>::_M_get_sequence): Rename into...
> (_Safe_local_iterator<>::_M_get_ucontainer): ...this. Add 
> necessary const_cast and
> comment to explain it.
> (_Safe_local_iterator<>::_M_is_begin, _M_is_end): Adapt.
> * include/debug/safe_local_iterator.tcc: Adapt.
> * include/debug/safe_sequence.h
> (_Safe_sequence<>::_M_invalidate_if, _M_transfer_from_if): Add 
> const qualifier.
> * include/debug/safe_sequence.tcc: Adapt.
> * include/debug/deque (std::__debug::deque::erase): Adapt to use 
> new const
> qualified methods.
> * include/debug/formatter.h: Adapt.
> * include/debug/forward_list (_Safe_forward_list::_M_this): Add 
> const
> qualification.
> (_Safe_forward_list::_M_swap_aux): Rename into...
> (_Safe_forward_list::_S_swap_aux): ...this and take sequence as 
> const reference.
> (forward_list<>::resize): Adapt to use const methods.
>  

Re: [PATCH] aarch64: Enable selective LDAPUR generation for cores with RCPC2

2025-07-01 Thread Kyrylo Tkachov


> On 1 Jul 2025, at 17:36, Richard Sandiford  wrote:
> 
> Soumya AR  writes:
>> From 2a2c3e3683aaf3041524df166fc6f8cf20895a0b Mon Sep 17 00:00:00 2001
>> From: Soumya AR 
>> Date: Mon, 30 Jun 2025 12:17:30 -0700
>> Subject: [PATCH] aarch64: Enable selective LDAPUR generation for cores with
>> RCPC2
>> 
>> This patch adds the ability to fold the address computation into the 
>> addressing
>> mode for LDAPR instructions using LDAPUR when RCPC2 is available.
>> 
>> LDAPUR emission is controlled by the tune flag enable_ldapur, to enable it 
>> on a
>> per-core basis. Earlier, the following code:
>> 
>> uint64_t
>> foo (std::atomic *x)
>> {
>>  return x[1].load(std::memory_order_acquire);
>> }
>> 
>> would generate:
>> 
>> foo(std::atomic*):
>> add x0, x0, 8
>> ldapr   x0, [x0]
>> ret
>> 
>> but now generates:
>> 
>> foo(std::atomic*):
>> ldapur  x0, [x0, 8]
>> ret
>> 
>> The patch was bootstrapped and regtested on aarch64-linux-gnu, no regression.
>> OK for mainline?
>> 
>> Signed-off-by: Soumya AR 
>> 
>> gcc/ChangeLog:
>> 
>> * config/aarch64/aarch64-tuning-flags.def (AARCH64_EXTRA_TUNING_OPTION):
>> Add the enable_ldapur flag to conwtrol LDAPUR emission.
>> * config/aarch64/aarch64.h (TARGET_ENABLE_LDAPUR): Use new flag.
>> * config/aarch64/aarch64.md (any): Add ldapur_enable attribute.
>> * config/aarch64/atomics.md: (aarch64_atomic_load_rcpc): Modify
>> to emit LDAPUR for cores with RCPC2 when enable_ldapur is set.
>> (*aarch64_atomic_load_rcpc_zext): Likewise.
>> (*aarch64_atomic_load_rcpc_sext): Modified to emit LDAPURS
>> for addressing with offsets.
>> 
>> gcc/testsuite/ChangeLog:
>> 
>> * gcc.target/aarch64/ldapur.c: New test.
> 
> Thanks for doing this.  It generally looks good, but a couple of comments
> below:
> 
>> ---
>> gcc/config/aarch64/aarch64-tuning-flags.def |  2 +
>> gcc/config/aarch64/aarch64.h|  5 ++
>> gcc/config/aarch64/aarch64.md   | 11 +++-
>> gcc/config/aarch64/atomics.md   | 22 +---
>> gcc/testsuite/gcc.target/aarch64/ldapur.c   | 61 +
>> 5 files changed, 92 insertions(+), 9 deletions(-)
>> create mode 100644 gcc/testsuite/gcc.target/aarch64/ldapur.c
>> 
>> diff --git a/gcc/config/aarch64/aarch64-tuning-flags.def 
>> b/gcc/config/aarch64/aarch64-tuning-flags.def
>> index f2c916e9d77..5bf54165306 100644
>> --- a/gcc/config/aarch64/aarch64-tuning-flags.def
>> +++ b/gcc/config/aarch64/aarch64-tuning-flags.def
>> @@ -44,6 +44,8 @@ AARCH64_EXTRA_TUNING_OPTION ("avoid_cross_loop_fma", 
>> AVOID_CROSS_LOOP_FMA)
>> 
>> AARCH64_EXTRA_TUNING_OPTION ("fully_pipelined_fma", FULLY_PIPELINED_FMA)
>> 
>> +AARCH64_EXTRA_TUNING_OPTION ("enable_ldapur", ENABLE_LDAPUR)
>> +
> 
> Let's see what others say, but personally, I think this would be better
> as an opt-out, such as avoid_ldapur.  The natural default seems to be to use
> the extra addressing capacity when it's available and have CPUs explicitly
> flag when they don't want that.
> 
> A good, conservatively correct, default would probably be to add avoid_ldapur
> to every *current* CPU that includes rcpc2 and then separately remove it
> from those that are known not to need it.  In that sense, it's more work
> for current CPUs than the current patch, but it should ease the impact
> on future CPUs.

LLVM used to do this folding by default everywhere until it was discovered that 
it hurts various CPUs.
So they’ve taken the approach you describe, and disable the folding explicitly 
for:
neoverse-v2 neoverse-v3 cortex-x3 cortex-x4 cortex-x925 
I don’t know for sure if those are the only CPUs where this applies.
They also disable the folding for generic tuning when -march is between armv8.4 
- armv8.7/armv9.2.
I guess we can do the same in GCC.

Thanks,
Kyrill

> 
>> /* Enable is the target prefers to use a fresh register for predicate outputs
>>rather than re-use an input predicate register.  */
>> AARCH64_EXTRA_TUNING_OPTION ("avoid_pred_rmw", AVOID_PRED_RMW)
>> diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
>> index e8bd8c73c12..08ad8350fbc 100644
>> --- a/gcc/config/aarch64/aarch64.h
>> +++ b/gcc/config/aarch64/aarch64.h
>> @@ -490,6 +490,11 @@ constexpr auto AARCH64_FL_DEFAULT_ISA_MODE 
>> ATTRIBUTE_UNUSED
>>   (bool (aarch64_tune_params.extra_tuning_flags \
>>  & AARCH64_EXTRA_TUNE_CHEAP_FPMR_WRITE))
>> 
>> +/* Enable folding address computation into LDAPUR when RCPC2 is available.  
>> */
>> +#define TARGET_ENABLE_LDAPUR (TARGET_RCPC2 \
>> +   && (aarch64_tune_params.extra_tuning_flags \
>> +   & AARCH64_EXTRA_TUNE_ENABLE_LDAPUR))
>> +
>> /* Combinatorial tests.  */
>> 
>> #define TARGET_SVE2_OR_SME2 \
>> diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
>> index e11e13033d2..76dc0e82c2a 100644
>> --- a/gcc/config/aarch64/aarch64.md
>> +++ b/gcc/config/aarch64/aarch64.md
>> @@ -482,6 +482,8 @@
>> ;; clobber for SVE predicates.
>> (define_attr "pred_clobber" "any,no,yes" (const_string "any"))
>> 
>> +(define_attr "l

[PATCH, V3] Add -mcpu=future to the PowerPC

2025-07-01 Thread Michael Meissner
This patch adds the support that can be used in developing GCC support
for potential future PowerPC processors.

These changes are being added so that hardware designers can evaluate
potential new features to be added to the PowerPC processors in the
future.  It may be these features will be incorporated into real
hardware using a different name in the future. Or it may be these
features will not be incoporated into actual PowerPC hardware in the
future.

At the moment, I have not added a new processor, and I'm using the
power11 for tuning defaults and such.  When we are ready to add new
tuning rules a potential future processor, we will add the support for
the new processor.

I have tested these patches on both big endian and little endian
PowerPC servers, with no regressions.  Can I check these patchs into
the trunk?

2025-07-01  Michael Meissner  

gcc/

* config/rs6000/rs6000-c.cc (rs6000_target_modify_macros): If
-mcpu=future, define _ARCH_FUTURE.
* config/rs6000/rs6000-cpus.def (FUTURE_MASKS_SERVER): New macro.
(POWERPC_MASKS): Add OPTION_MASK_FUTURE.
(future cpu): Add 'future' cpu.
* config/rs6000/rs6000-tables.opt: Regenerate.
* config/rs6000/rs6000.opt (-mfuture-internal): New internal option to
indicate the user used -mcpu=future.

gcc/testsuite/

* gcc.target/powerpc/future-1.c: New test.
* gcc.target/powerpc/future-2.c: Likewise.
---
 gcc/config/rs6000/rs6000-c.cc   |  2 ++
 gcc/config/rs6000/rs6000-cpus.def   |  9 
 gcc/config/rs6000/rs6000-tables.opt | 11 ++
 gcc/config/rs6000/rs6000.opt|  6 ++
 gcc/testsuite/gcc.target/powerpc/future-1.c | 13 +++
 gcc/testsuite/gcc.target/powerpc/future-2.c | 24 +
 6 files changed, 61 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/future-1.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/future-2.c

diff --git a/gcc/config/rs6000/rs6000-c.cc b/gcc/config/rs6000/rs6000-c.cc
index d3b0a566821..6757a2477ad 100644
--- a/gcc/config/rs6000/rs6000-c.cc
+++ b/gcc/config/rs6000/rs6000-c.cc
@@ -437,6 +437,8 @@ rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT 
flags)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR10");
   if ((flags & OPTION_MASK_POWER11) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR11");
+  if ((flags & OPTION_MASK_FUTURE) != 0)
+rs6000_define_or_undefine_macro (define_p, "_ARCH_FUTURE");
   if ((flags & OPTION_MASK_SOFT_FLOAT) != 0)
 rs6000_define_or_undefine_macro (define_p, "_SOFT_FLOAT");
   if ((flags & OPTION_MASK_RECIP_PRECISION) != 0)
diff --git a/gcc/config/rs6000/rs6000-cpus.def 
b/gcc/config/rs6000/rs6000-cpus.def
index 4a1037616d7..de30f8cd397 100644
--- a/gcc/config/rs6000/rs6000-cpus.def
+++ b/gcc/config/rs6000/rs6000-cpus.def
@@ -83,6 +83,10 @@
 #define POWER11_MASKS_SERVER (ISA_3_1_MASKS_SERVER \
  | OPTION_MASK_POWER11)
 
+/* Potential future cpu bits.  */
+#define FUTURE_MASKS_SERVER (POWER11_MASKS_SERVER  \
+ | OPTION_MASK_FUTURE)
+
 /* Flags that need to be turned off if -mno-vsx.  */
 #define OTHER_VSX_VECTOR_MASKS (OPTION_MASK_EFFICIENT_UNALIGNED_VSX\
 | OPTION_MASK_FLOAT128_KEYWORD \
@@ -119,6 +123,7 @@
 | OPTION_MASK_FLOAT128_HW  \
 | OPTION_MASK_FLOAT128_KEYWORD \
 | OPTION_MASK_FPRND\
+| OPTION_MASK_FUTURE   \
 | OPTION_MASK_POWER10  \
 | OPTION_MASK_POWER11  \
 | OPTION_MASK_P10_FUSION   \
@@ -249,6 +254,10 @@ RS6000_CPU ("power9", PROCESSOR_POWER9, MASK_POWERPC64 | 
ISA_3_0_MASKS_SERVER
| OPTION_MASK_HTM)
 RS6000_CPU ("power10", PROCESSOR_POWER10, MASK_POWERPC64 | 
ISA_3_1_MASKS_SERVER)
 RS6000_CPU ("power11", PROCESSOR_POWER11, MASK_POWERPC64 | 
POWER11_MASKS_SERVER)
+
+/* At present, we are not providing a unique processor option for -mcpu=future.
+   Until we define these changes, just use the power11 defaults.  */
+RS6000_CPU ("future", PROCESSOR_POWER11, MASK_POWERPC64 | FUTURE_MASKS_SERVER)
 RS6000_CPU ("powerpc", PROCESSOR_POWERPC, 0)
 RS6000_CPU ("powerpc64", PROCESSOR_POWERPC64, OPTION_MASK_PPC_GFXOPT
| MASK_POWERPC64)
diff --git a/gcc/config/rs6000/rs6000-tables.opt 
b/gcc/config/rs6000/rs6000-tables.opt
index f5bbed5ea74..518324e7aea 100644
--- a/gcc/config/rs6000/rs6000-tables.opt
+++ b/gcc/config/rs6000/rs6000-tables.opt
@@ -189,14 +189,17 @@ EnumValue
 Enum(rs6000_cpu_opt_value) String(power11) Value(53)
 
 EnumValue
-Enum(rs6000_cpu_opt_value) String(powerpc) Value(54)
+Enum

[PATCH v3 1/4] Internal-fn: Introduce new IFN_SAT_MUL for unsigned int

2025-07-01 Thread pan2 . li
From: Pan Li 

This patch would like to add the middle-end presentation for the
unsigend saturation mul.  Aka set the result of mul to the max
when overflow.

Take uint8_t as example, we will have:

* SAT_MUL (1, 127)   => 127.
* SAT_MUL (2, 127)   => 254.
* SAT_MUL (3, 127)   => 255.
* SAT_MUL (255, 127) => 255.

Given below example for uint16_t from uint128_t

  #define DEF_SAT_U_MUL_FMT_1(NT, WT) \
  NT __attribute__((noinline))\
  sat_u_mul_##NT##_from_##WT##_fmt_1 (NT a, NT b) \
  {   \
WT x = (WT)a * (WT)b; \
NT max = -1;  \
if (x > (WT)(max))\
  return max; \
else  \
  return (NT)x;   \
  }

  DEF_SAT_U_MUL_FMT_1(uint16_t, uint128_t)

Before this patch:
  15   │[local count: 1073741824]:
  16   │   _1 = (__int128 unsigned) a_4(D);
  17   │   _2 = (__int128 unsigned) b_5(D);
  18   │   _9 = (unsigned long) _1;
  19   │   _10 = (unsigned long) _2;
  20   │   x_6 = _9 w* _10;
  21   │   _7 = MIN_EXPR ;
  22   │   _3 = (uint8_t) _7;
  23   │   return _3;

After this patch:
   9   │[local count: 1073741824]:
  10   │   _3 = .SAT_MUL (a_4(D), b_5(D)); [tail call]
  11   │   return _3;

gcc/ChangeLog:

* internal-fn.cc (commutative_binary_fn_p): Add new case
for SAT_MUL.
* internal-fn.def (SAT_MUL): Add new IFN_SAT_MUL.
* optabs.def (OPTAB_NL): Remove fixed point limitation.

Signed-off-by: Pan Li 
---
 gcc/internal-fn.cc  | 1 +
 gcc/internal-fn.def | 1 +
 gcc/optabs.def  | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/internal-fn.cc b/gcc/internal-fn.cc
index 3f4ac937367..184f72132cc 100644
--- a/gcc/internal-fn.cc
+++ b/gcc/internal-fn.cc
@@ -4423,6 +4423,7 @@ commutative_binary_fn_p (internal_fn fn)
 case IFN_ADD_OVERFLOW:
 case IFN_MUL_OVERFLOW:
 case IFN_SAT_ADD:
+case IFN_SAT_MUL:
 case IFN_VEC_WIDEN_PLUS:
 case IFN_VEC_WIDEN_PLUS_LO:
 case IFN_VEC_WIDEN_PLUS_HI:
diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def
index 8edfa3540f8..914ee9f278c 100644
--- a/gcc/internal-fn.def
+++ b/gcc/internal-fn.def
@@ -282,6 +282,7 @@ DEF_INTERNAL_SIGNED_OPTAB_FN (MULHRS, ECF_CONST | 
ECF_NOTHROW, first,
 
 DEF_INTERNAL_SIGNED_OPTAB_FN (SAT_ADD, ECF_CONST, first, ssadd, usadd, binary)
 DEF_INTERNAL_SIGNED_OPTAB_FN (SAT_SUB, ECF_CONST, first, sssub, ussub, binary)
+DEF_INTERNAL_SIGNED_OPTAB_FN (SAT_MUL, ECF_CONST, first, ssmul, usmul, binary)
 
 DEF_INTERNAL_SIGNED_OPTAB_FN (SAT_TRUNC, ECF_CONST, first, sstrunc, ustrunc, 
unary_convert)
 
diff --git a/gcc/optabs.def b/gcc/optabs.def
index 0c1435d4ecd..ea049378112 100644
--- a/gcc/optabs.def
+++ b/gcc/optabs.def
@@ -135,7 +135,7 @@ OPTAB_NX(smul_optab, "mul$F$a3")
 OPTAB_VL(smulv_optab, "mulv$I$a3", MULT, "mul", '3', gen_intv_fp_libfunc)
 OPTAB_VX(smulv_optab, "mul$F$a3")
 OPTAB_NL(ssmul_optab, "ssmul$Q$a3", SS_MULT, "ssmul", '3', 
gen_signed_fixed_libfunc)
-OPTAB_NL(usmul_optab, "usmul$Q$a3", US_MULT, "usmul", '3', 
gen_unsigned_fixed_libfunc)
+OPTAB_NL(usmul_optab, "usmul$a3", US_MULT, "usmul", '3', 
gen_unsigned_fixed_libfunc)
 OPTAB_NL(sdiv_optab, "div$a3", DIV, "div", '3', 
gen_int_fp_signed_fixed_libfunc)
 OPTAB_VL(sdivv_optab, "divv$I$a3", DIV, "divv", '3', gen_int_libfunc)
 OPTAB_VX(sdivv_optab, "div$F$a3")
-- 
2.43.0



[PATCH v3 2/4] Widening-Mul: Support unsigned scalar SAT_MUL form 1

2025-07-01 Thread pan2 . li
From: Pan Li 

This patch would like to try to match the SAT_MUL during
widening-mul pass, aka below pattern.

  NT __attribute__((noinline))
  sat_u_mul_##NT##_fmt_1 (NT a, NT b)
  {
uint128_t x = (uint128_t)a * (uint128_t)b;
NT max = -1;
if (x > (uint128_t)(max))
  return max;
else
  return (NT)x;
  }

while the NT can be uint8_t, uint16_t, uint32_t and uint64_t.

gcc/ChangeLog:

* match.pd: Add new match pattern for unsigned SAT_MUL.
* tree-ssa-math-opts.cc (gimple_unsigned_integer_sat_mul):
new decl for pattern match func.
(match_unsigned_saturation_mul): Add new func to match unsigned
SAT_MUL.
(math_opts_dom_walker::after_dom_children): Try to match
unsigned SAT_MUL on NOP.

Signed-off-by: Pan Li 
---
 gcc/match.pd  | 31 +++
 gcc/tree-ssa-math-opts.cc | 26 ++
 2 files changed, 57 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index f4416d9172c..c8addf9b421 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3572,6 +3572,37 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 || (wi::eq_p (int_cst_1, itype_max) && wi::eq_p (int_cst_2, limit_1)))
 && wi::eq_p (int_cst_3, otype_max)))
 
+/* Saturation mult for unsigned integer.  */
+(if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type))
+  (match (unsigned_integer_sat_mul @0 @1)
+   /* SAT_U_MUL (X, Y) = {
+   WT x = (WT)a * (WT)b;
+   T max = -1;
+   if (x > (WT)(max))
+ return max;
+   else
+ return (T)x;
+  }
+  while WT is uint128_t, T is uint8_t, uint16_t, uint32_t or uint64_t.  */
+   (convert@4 (min (widen_mult:c@3 (convert@5 (convert @0))
+  (convert@6 (convert @1)))
+  INTEGER_CST@2))
+   (if (types_match (type, @0, @1) && types_match (type, @4))
+(with
+ {
+  unsigned prec = TYPE_PRECISION (type);
+  unsigned widen_prec = TYPE_PRECISION (TREE_TYPE (@3));
+  unsigned cvt5_prec = TYPE_PRECISION (TREE_TYPE (@5));
+  unsigned cvt6_prec = TYPE_PRECISION (TREE_TYPE (@6));
+  unsigned hw_int_prec = sizeof (HOST_WIDE_INT) * 8;
+  wide_int c2 = wi::to_wide (@2);
+  wide_int max = wi::mask (prec, false, widen_prec);
+  bool c2_is_max_p = wi::eq_p (c2, max);
+  bool widen_mult_p = cvt5_prec == cvt6_prec && hw_int_prec == cvt5_prec;
+ }
+ (if (widen_prec > prec && c2_is_max_p && widen_mult_p)
+)
+
 /* The boundary condition for case 10: IMM = 1:
SAT_U_SUB = X >= IMM ? (X - IMM) : 0.
simplify (X != 0 ? X + ~0 : 0) to X - (X != 0).  */
diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc
index 4cfcc420fea..ca98205d58f 100644
--- a/gcc/tree-ssa-math-opts.cc
+++ b/gcc/tree-ssa-math-opts.cc
@@ -4064,6 +4064,7 @@ arith_overflow_check_p (gimple *stmt, gimple *cast_stmt, 
gimple *&use_stmt,
 extern bool gimple_unsigned_integer_sat_add (tree, tree*, tree (*)(tree));
 extern bool gimple_unsigned_integer_sat_sub (tree, tree*, tree (*)(tree));
 extern bool gimple_unsigned_integer_sat_trunc (tree, tree*, tree (*)(tree));
+extern bool gimple_unsigned_integer_sat_mul (tree, tree*, tree (*)(tree));
 
 extern bool gimple_signed_integer_sat_add (tree, tree*, tree (*)(tree));
 extern bool gimple_signed_integer_sat_sub (tree, tree*, tree (*)(tree));
@@ -4216,6 +4217,30 @@ match_unsigned_saturation_sub (gimple_stmt_iterator 
*gsi, gassign *stmt)
ops[0], ops[1]);
 }
 
+/*
+ * Try to match saturation unsigned mul.
+ *   _1 = (unsigned int) a_6(D);
+ *   _2 = (unsigned int) b_7(D);
+ *   x_8 = _1 * _2;
+ *   overflow_9 = x_8 > 255;
+ *   _3 = (unsigned char) overflow_9;
+ *   _4 = -_3;
+ *   _5 = (unsigned char) x_8;
+ *   _10 = _4 | _5;
+ *   =>
+ *   _10 = .SAT_SUB (a_6, b_7);  */
+
+static void
+match_unsigned_saturation_mul (gimple_stmt_iterator *gsi, gassign *stmt)
+{
+  tree ops[2];
+  tree lhs = gimple_assign_lhs (stmt);
+
+  if (gimple_unsigned_integer_sat_mul (lhs, ops, NULL))
+build_saturation_binary_arith_call_and_replace (gsi, IFN_SAT_MUL, lhs,
+   ops[0], ops[1]);
+}
+
 /*
  * Try to match saturation unsigned sub.
  *   [local count: 1073741824]:
@@ -6469,6 +6494,7 @@ math_opts_dom_walker::after_dom_children (basic_block bb)
  break;
 
case NOP_EXPR:
+ match_unsigned_saturation_mul (&gsi, as_a (stmt));
  match_unsigned_saturation_trunc (&gsi, as_a (stmt));
  match_saturation_add_with_assign (&gsi, as_a (stmt));
  break;
-- 
2.43.0



[PATCH v3 0/4] Support unsigned scalar SAT_MUL from uint128_t

2025-07-01 Thread pan2 . li
From: Pan Li 

This patch series would like to support the unsigned SAT_MUL with
the help of uint128_t.  Aka:

NT __attribute__((noinline))
sat_u_mul_##NT##_fmt_1 (NT a, NT b)
{
  uint128_t x = (uint128_t)a * (uint128_t)b;
  NT max = -1;
  if (x > (uint128_t)(max))
return max;
  else
return (NT)x;
}

while NT can be uint8_t, uint16_t, uint32_t and uint64_t.

Before this patch:
  15   │[local count: 1073741824]:
  16   │   _1 = (__int128 unsigned) a_4(D);
  17   │   _2 = (__int128 unsigned) b_5(D);
  18   │   _9 = (unsigned long) _1;
  19   │   _10 = (unsigned long) _2;
  20   │   x_6 = _9 w* _10;
  21   │   _7 = MIN_EXPR ;
  22   │   _3 = (uint8_t) _7;
  23   │   return _3;

After this patch:
   9   │[local count: 1073741824]:
  10   │   _3 = .SAT_MUL (a_4(D), b_5(D)); [tail call]
  11   │   return _3;

The below test suites are passed for this patch:
1. The rv64gcv fully regression tests.
2. The x86 bootstrap tests.
3. The x86 fully regression tests.

Pan Li (4):
  Internal-fn: Introduce new IFN_SAT_MUL for unsigned int
  Widening-Mul: Support unsigned scalar SAT_MUL form 1
  RISC-V: Implement unsigned scalar SAT_MUL from uint128_t
  RISC-V: Add test cases for unsigned scalar SAT_MUL from uint128_t

 gcc/config/riscv/riscv-protos.h   |  1 +
 gcc/config/riscv/riscv.cc | 82 +++
 gcc/config/riscv/riscv.md | 11 +++
 gcc/internal-fn.cc|  1 +
 gcc/internal-fn.def   |  1 +
 gcc/match.pd  | 31 +++
 gcc/optabs.def|  2 +-
 .../gcc.target/riscv/sat/sat_arith.h  | 23 ++
 .../gcc.target/riscv/sat/sat_arith_data.h | 62 ++
 .../riscv/sat/sat_u_mul-1-u16-from-u128.c | 11 +++
 .../riscv/sat/sat_u_mul-1-u32-from-u128.c | 11 +++
 .../riscv/sat/sat_u_mul-1-u64-from-u128.c | 11 +++
 .../riscv/sat/sat_u_mul-1-u8-from-u128.c  | 11 +++
 .../riscv/sat/sat_u_mul-run-1-u16-from-u128.c | 16 
 .../riscv/sat/sat_u_mul-run-1-u32-from-u128.c | 16 
 .../riscv/sat/sat_u_mul-run-1-u64-from-u128.c | 16 
 .../riscv/sat/sat_u_mul-run-1-u8-from-u128.c  | 16 
 gcc/tree-ssa-math-opts.cc | 26 ++
 18 files changed, 347 insertions(+), 1 deletion(-)
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-1-u16-from-u128.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-1-u32-from-u128.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-1-u64-from-u128.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-1-u8-from-u128.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-run-1-u16-from-u128.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-run-1-u32-from-u128.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-run-1-u64-from-u128.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-run-1-u8-from-u128.c

-- 
2.43.0



[PATCH v3 4/4] RISC-V: Add test cases for unsigned scalar SAT_MUL from uint128_t

2025-07-01 Thread pan2 . li
From: Pan Li 

Add run and tree-optimized check for unsigned scalar SAT_MUL from
uint128_t.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat/sat_arith.h: Add test helper macros.
* gcc.target/riscv/sat/sat_arith_data.h: Add test data for
run test.
* gcc.target/riscv/sat/sat_u_mul-1-u16-from-u128.c: New test.
* gcc.target/riscv/sat/sat_u_mul-1-u32-from-u128.c: New test.
* gcc.target/riscv/sat/sat_u_mul-1-u64-from-u128.c: New test.
* gcc.target/riscv/sat/sat_u_mul-1-u8-from-u128.c: New test.
* gcc.target/riscv/sat/sat_u_mul-run-1-u16-from-u128.c: New test.
* gcc.target/riscv/sat/sat_u_mul-run-1-u32-from-u128.c: New test.
* gcc.target/riscv/sat/sat_u_mul-run-1-u64-from-u128.c: New test.
* gcc.target/riscv/sat/sat_u_mul-run-1-u8-from-u128.c: New test.

Signed-off-by: Pan Li 
---
 .../gcc.target/riscv/sat/sat_arith.h  | 23 +++
 .../gcc.target/riscv/sat/sat_arith_data.h | 62 +++
 .../riscv/sat/sat_u_mul-1-u16-from-u128.c | 11 
 .../riscv/sat/sat_u_mul-1-u32-from-u128.c | 11 
 .../riscv/sat/sat_u_mul-1-u64-from-u128.c | 11 
 .../riscv/sat/sat_u_mul-1-u8-from-u128.c  | 11 
 .../riscv/sat/sat_u_mul-run-1-u16-from-u128.c | 16 +
 .../riscv/sat/sat_u_mul-run-1-u32-from-u128.c | 16 +
 .../riscv/sat/sat_u_mul-run-1-u64-from-u128.c | 16 +
 .../riscv/sat/sat_u_mul-run-1-u8-from-u128.c  | 16 +
 10 files changed, 193 insertions(+)
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-1-u16-from-u128.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-1-u32-from-u128.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-1-u64-from-u128.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-1-u8-from-u128.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-run-1-u16-from-u128.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-run-1-u32-from-u128.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-run-1-u64-from-u128.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-run-1-u8-from-u128.c

diff --git a/gcc/testsuite/gcc.target/riscv/sat/sat_arith.h 
b/gcc/testsuite/gcc.target/riscv/sat/sat_arith.h
index 6e97cae96e6..055b4cea140 100644
--- a/gcc/testsuite/gcc.target/riscv/sat/sat_arith.h
+++ b/gcc/testsuite/gcc.target/riscv/sat/sat_arith.h
@@ -4,6 +4,8 @@
 #include 
 #include 
 
+typedef __uint128_t uint128_t;
+
 
/**/
 /* Saturation Add (unsigned and signed)   
*/
 
/**/
@@ -636,4 +638,25 @@ sat_s_trunc_##WT##_to_##NT##_fmt_8 (WT x) \
 #define RUN_SAT_S_TRUNC_FMT_8(NT, WT, x) sat_s_trunc_##WT##_to_##NT##_fmt_8 (x)
 #define RUN_SAT_S_TRUNC_FMT_8_WRAP(NT, WT, x) RUN_SAT_S_TRUNC_FMT_8(NT, WT, x)
 
+/**/
+/* Saturation Mult (unsigned and signed)  */
+/**/
+
+#define DEF_SAT_U_MUL_FMT_1(NT, WT) \
+NT __attribute__((noinline))\
+sat_u_mul_##NT##_from_##WT##_fmt_1 (NT a, NT b) \
+{   \
+  WT x = (WT)a * (WT)b; \
+  NT max = -1;  \
+  if (x > (WT)(max))\
+return max; \
+  else  \
+return (NT)x;   \
+}
+
+#define DEF_SAT_U_MUL_FMT_1_WRAP(NT, WT) DEF_SAT_U_MUL_FMT_1(NT, WT)
+#define RUN_SAT_U_MUL_FMT_1(NT, WT, a, b) \
+  sat_u_mul_##NT##_from_##WT##_fmt_1 (a, b)
+#define RUN_SAT_U_MUL_FMT_1_WRAP(NT, WT, a, b) RUN_SAT_U_MUL_FMT_1(NT, WT, a, 
b)
+
 #endif
diff --git a/gcc/testsuite/gcc.target/riscv/sat/sat_arith_data.h 
b/gcc/testsuite/gcc.target/riscv/sat/sat_arith_data.h
index f1006889d21..bd33ff1769a 100644
--- a/gcc/testsuite/gcc.target/riscv/sat/sat_arith_data.h
+++ b/gcc/testsuite/gcc.target/riscv/sat/sat_arith_data.h
@@ -12,6 +12,7 @@
 
 #define TEST_BINARY_STRUCT_NAME(T, NAME) test_##T##_##NAME##_s
 #define TEST_BINARY_STRUCT_DECL(T, NAME) struct TEST_BINARY_STRUCT_NAME(T, 
NAME)
+#define TEST_BINARY_STRUCT_DECL_WRAP(T, NAME) TEST_BINARY_STRUCT_DECL(T, NAME)
 #define TEST_BINARY_STRUCT(T, NAME)   \
   struct TEST_BINARY_STRUCT_NAME(T, NAME) \
 { \
@@ -37,6 +38,11 @@ TEST_BINARY_STRUCT (uint16_t, usadd)
 TEST_BINARY_STRUCT (uint32_t, usadd)
 TEST_BINARY_STRUCT (uint64_t, usadd)
 
+TEST_BINARY_STRUCT (uint8_t, usmul)
+TEST_BINARY_STRUCT (uint16_t, usmul)
+TEST_BINARY_STRUCT (uint32_t, usmul)
+TEST_BINARY_STRUCT (uint64_t, usmul)
+
 TEST_BINARY_STRUCT (int8_t,  ssadd)

[PATCH v3 3/4] RISC-V: Implement unsigned scalar SAT_MUL from uint128_t

2025-07-01 Thread pan2 . li
From: Pan Li 

This patch would like to implement the SAT_MUL scalar unsigned from
uint128_t, aka:

  NT __attribute__((noinline))
  sat_u_mul_##NT##_fmt_1 (NT a, NT b)
  {
uint128_t x = (uint128_t)a * (uint128_t)b;
NT max = -1;
if (x > (uint128_t)(max))
  return max;
else
  return (NT)x;
  }

Take uint64_t and uint8_t as example:

Before this patch for uint8_t:
  10   │ sat_u_mul_uint8_t_from_uint128_t_fmt_1:
  11   │ mulhu   a5,a0,a1
  12   │ mul a0,a0,a1
  13   │ bne a5,zero,.L3
  14   │ li  a5,255
  15   │ bleua0,a5,.L4
  16   │ .L3:
  17   │ li  a0,255
  18   │ .L4:
  19   │ andia0,a0,0xff
  20   │ ret

After this patch for uint8_t:
  10   │ sat_u_mul_uint8_t_from_uint128_t_fmt_1:
  11   │ mul a0,a0,a1
  12   │ li  a5,255
  13   │ sltua5,a5,a0
  14   │ neg a5,a5
  15   │ or  a0,a0,a5
  16   │ andia0,a0,0xff
  17   │ ret

Before this patch for uint64_t:
  10   │ sat_u_mul_uint64_t_from_uint128_t_fmt_1:
  11   │ mulhu   a5,a0,a1
  12   │ mul a0,a0,a1
  13   │ beq a5,zero,.L4
  14   │ li  a0,-1
  15   │ .L4:
  16   │ ret

After this patch for uint64_t:
  10   │ sat_u_mul_uint64_t_from_uint128_t_fmt_1:
  11   │ mulhsu  a5,a1,a0
  12   │ mul a0,a0,a1
  13   │ sneza5,a5
  14   │ neg a5,a5
  15   │ or  a0,a0,a5
  16   │ ret

gcc/ChangeLog:

* config/riscv/riscv-protos.h (riscv_expand_usmul): Add new func
decl.
* config/riscv/riscv.cc (riscv_expand_xmode_usmul): Add new func
to expand Xmode SAT_MUL.
(riscv_expand_non_xmode_usmul): Ditto but for non-Xmode.
(riscv_expand_usmul): Add new func to implment SAT_MUL.
* config/riscv/riscv.md (usmul3): Add new pattern to match
standard name usmul.

Signed-off-by: Pan Li 
---
 gcc/config/riscv/riscv-protos.h |  1 +
 gcc/config/riscv/riscv.cc   | 82 +
 gcc/config/riscv/riscv.md   | 11 +
 3 files changed, 94 insertions(+)

diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index a0331204479..38f63ea8424 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -137,6 +137,7 @@ extern void riscv_expand_usadd (rtx, rtx, rtx);
 extern void riscv_expand_ssadd (rtx, rtx, rtx);
 extern void riscv_expand_ussub (rtx, rtx, rtx);
 extern void riscv_expand_sssub (rtx, rtx, rtx);
+extern void riscv_expand_usmul (rtx, rtx, rtx);
 extern void riscv_expand_ustrunc (rtx, rtx);
 extern void riscv_expand_sstrunc (rtx, rtx);
 extern int riscv_register_move_cost (machine_mode, reg_class_t, reg_class_t);
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index bbc7547d385..36f66f8b899 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -13265,6 +13265,88 @@ riscv_expand_sssub (rtx dest, rtx x, rtx y)
   emit_move_insn (dest, gen_lowpart (mode, xmode_dest));
 }
 
+/* Implement the Xmode usmul.
+
+   b = SAT_MUL (a, b);
+   =>
+   _1 = a * b;
+   _2 = mulhu (a, b);
+   _overflow_p = _2 == 0;
+   _mask = - _overflow_p;
+   b = _1 | _mask;
+ */
+
+static void
+riscv_expand_xmode_usmul (rtx dest, rtx x, rtx y)
+{
+  machine_mode mode = GET_MODE (dest);
+
+  gcc_assert (mode == Xmode);
+
+  rtx mul = gen_reg_rtx (Xmode);
+  rtx mulhu = gen_reg_rtx (Xmode);
+  rtx overflow_p = gen_reg_rtx (Xmode);
+
+  riscv_emit_binary (MULT, mul, x, y);
+
+  if (TARGET_64BIT)
+emit_insn (gen_usmuldi3_highpart (mulhu, x, y));
+  else
+emit_insn (gen_usmulsi3_highpart (mulhu, x, y));
+
+  riscv_emit_binary (NE, overflow_p, mulhu, CONST0_RTX (Xmode));
+  riscv_emit_unary (NEG, overflow_p, overflow_p);
+  riscv_emit_binary (IOR, dest, mul, overflow_p);
+}
+
+/* Implement the non-Xmode usmul.
+
+   b = SAT_MUL (a, b);
+   =>
+   _1 = a * b;
+   _max = (T)-1
+   _overflow_p = _1 > _max;
+   _mask = - _overflow_p;
+   b = _1 | _mask;
+ */
+
+static void
+riscv_expand_non_xmode_usmul (rtx dest, rtx x, rtx y)
+{
+  machine_mode mode = GET_MODE (dest);
+  unsigned bitsize = GET_MODE_BITSIZE (mode).to_constant ();
+
+  gcc_assert (mode != Xmode);
+
+  rtx xmode_x = riscv_extend_to_xmode_reg (x, mode, ZERO_EXTEND);
+  rtx xmode_y = riscv_extend_to_xmode_reg (y, mode, ZERO_EXTEND);
+  rtx xmode_mul = gen_reg_rtx (Xmode);
+  rtx mul_max = gen_reg_rtx (Xmode);
+  rtx overflow_p = gen_reg_rtx (Xmode);
+
+  HOST_WIDE_INT max = ((uint64_t)1 << bitsize) - 1;
+
+  emit_move_insn (mul_max, GEN_INT (max));
+  riscv_emit_binary (MULT, xmode_mul, xmode_x, xmode_y);
+
+  riscv_emit_binary (LTU, overflow_p, mul_max, xmode_mul);
+  riscv_emit_unary (NEG, overflow_p, overflow_p);
+  riscv_emit_binary (IOR, xmode_mul, xmode_mul, overflow_p);
+
+  emit_move_insn (dest, gen_lowpart (mode, xmode_mul));
+}
+
+/* Implements the unsigned saturation mult standard name usmul for int mode.  
*/
+
+void
+riscv_expand_usmul (rtx dest, rtx x, rtx y)
+{
+  if (GET_MODE (dest) == Xmode)
+return riscv

Re: [PATCH] c-family: Check backend for argument alignment on stack

2025-07-01 Thread Jason Merrill

On 6/30/25 7:03 PM, H.J. Lu wrote:

On Mon, Jun 30, 2025 at 10:36 PM Jason Merrill  wrote:


On 6/28/25 7:00 AM, H.J. Lu wrote:

Since a backend may ignore user type alignment for arguments passed on
stack, check backend for argument alignment on stack when evaluating
__alignof.


I assume that's reflected in DECL_ALIGN, so could we just add PARM_DECL to


No.  targetm.calls.function_arg_boundary may have special handling for it.


Why wouldn't we adjust DECL_ALIGN of the PARM_DECL to reflect the actual 
alignment of the argument?  Are you saying it could be different from 
one call to another?



   else if (VAR_OR_FUNCTION_DECL_P (expr))
 t = size_int (DECL_ALIGN_UNIT (expr));


?

Jason








Re: [PATCH v2 1/5] libstdc++: Check prerequisites of layout_*::operator().

2025-07-01 Thread Luc Grosheintz



On 7/1/25 12:30, Tomasz Kaminski wrote:

Hi,
More of the review will be later, but I have noticed that you have added
preconditions checks
to the layouts, and then avoid checking them inside the operator[] of the
mdspan. This is general
sounds good.

However, the precondition on mdspan::operator[] is now hardened:
https://eel.is/c++draft/views.multidim#mdspan.mdspan.members-3.
This implies that breaking this precondition is a contract violation, and
thus the user may expect a contract violation handler to be invoked
for it. Amongst the information provided to the handler via
contract_violation object (
https://eel.is/c++draft/support.contract.violation)
is source_location, that includes the name. Given that I think we want to
always check the extents in operator[] of mdspan, and thus remove
the checks from layout (to avoid duplication).

Hope, the above makes sense.


Thank you, makes sense. I've always been reading N4950 when implementing
the C++23 parts of mdspan. However, it makes sense to already prepare for
the hardening coming in C++26.

If I understand correctly, you'd like to do a second round of reviewing.
I'll wait with v3 until you clearly tell me to submit the next iteration.



Regards,
Tomasz

On Fri, Jun 27, 2025 at 11:12 AM Luc Grosheintz 
wrote:


Previously the prerequisite that the arguments passed to operator() are
a multi-dimensional index (of extents()) was not checked.

This commit adds the __glibcxx_asserts and the required tests.

libstdc++-v3/ChangeLog:

 * include/std/mdspan: Check prerequisites of
 layout_*::operator().
 * testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc:
 Add tests for prerequisites.

Signed-off-by: Luc Grosheintz 
---
  libstdc++-v3/include/std/mdspan   |  4 +++
  .../mdspan/layouts/class_mandate_neg.cc   | 26 +++
  2 files changed, 30 insertions(+)

diff --git a/libstdc++-v3/include/std/mdspan
b/libstdc++-v3/include/std/mdspan
index c72a64094b7..39d02ac08df 100644
--- a/libstdc++-v3/include/std/mdspan
+++ b/libstdc++-v3/include/std/mdspan
@@ -441,6 +441,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 _IndexType __mult = 1;
 auto __update = [&, __pos = 0u](_IndexType __idx) mutable
   {
+   __glibcxx_assert(cmp_less(__idx, __exts.extent(__pos)));
 __res += __idx * __mult;
 __mult *= __exts.extent(__pos);
 ++__pos;
@@ -651,6 +652,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 auto __update = [&, __pos = __exts.rank()](_IndexType) mutable
   {
 --__pos;
+   __glibcxx_assert(cmp_less(__ind_arr[__pos],
+ __exts.extent(__pos)));
 __res += __ind_arr[__pos] * __mult;
 __mult *= __exts.extent(__pos);
   };
@@ -822,6 +825,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   {
 auto __update = [&, __pos = 0u](_IndexType __idx) mutable
   {
+   __glibcxx_assert(cmp_less(__idx,
__m.extents().extent(__pos)));
 __res += __idx * __m.stride(__pos++);
   };
 (__update(__indices), ...);
diff --git
a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc
b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc
index 7091153daba..f5aab22aff0 100644
---
a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc
+++
b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc
@@ -45,4 +45,30 @@ auto b5 = B<5, std::layout_stride,
std::layout_right>();  // { dg-error "require
  auto b6 = B<6, std::layout_stride, std::layout_left>();   // { dg-error
"required from" }
  auto b7 = B<7, std::layout_stride, std::layout_stride>(); // { dg-error
"required from" }

+template
+  constexpr bool
+  test_linear_index_0d()
+  {
+auto m = typename Layout::mapping>{};
+(void) m(0); // { dg-error "expansion of" }
+return true;
+  }
+static_assert(test_linear_index_0d()); // { dg-error
"expansion of" }
+static_assert(test_linear_index_0d()); // { dg-error
"expansion of" }
+static_assert(test_linear_index_0d()); // { dg-error
"expansion of" }
+
+template
+  constexpr bool
+  test_linear_index_3d()
+  {
+auto m = typename Layout::mapping>{};
+(void) m(2, 5, 5); // { dg-error "expansion of" }
+return true;
+  }
+static_assert(test_linear_index_3d()); // { dg-error
"expansion of" }
+static_assert(test_linear_index_3d()); // { dg-error
"expansion of" }
+static_assert(test_linear_index_3d()); // { dg-error
"expansion of" }
+
  // { dg-prune-output "must be representable as index_type" }
+// { dg-prune-output "non-constant condition for static assertion" }
+// { dg-prune-output "__glibcxx_assert" }
--
2.49.0








Re: [PATCH v2 4/5] libstdc++: Implement mdspan and tests.

2025-07-01 Thread Tomasz Kaminski
On Tue, Jul 1, 2025 at 3:44 PM Luc Grosheintz 
wrote:

>
>
> On 7/1/25 12:44, Tomasz Kaminski wrote:
> > Few initial comments. I will do a full-review with checks against wording
> > later today or tomorrow.
> >
> > On Fri, Jun 27, 2025 at 11:37 AM Luc Grosheintz <
> luc.groshei...@gmail.com>
> > wrote:
> >
> >> Implements the class mdspan as described in N4950, i.e. without P3029.
> >> It also adds tests for mdspan.
> >>
> >> libstdc++-v3/ChangeLog:
> >>
> >>  * include/std/mdspan (mdspan): New class.
> >>  * src/c++23/std.cc.in: Add std::mdspan.
> >>  * testsuite/23_containers/mdspan/class_mandate_neg.cc: New
> test.
> >>  * testsuite/23_containers/mdspan/mdspan.cc: New test.
> >>  * testsuite/23_containers/mdspan/layout_like.h: Add class
> >>  LayoutLike which models a user-defined layout.
> >>
> >> Signed-off-by: Luc Grosheintz 
> >> ---
> >>   libstdc++-v3/include/std/mdspan   | 282 +
> >>   libstdc++-v3/src/c++23/std.cc.in  |   3 +-
> >>   .../23_containers/mdspan/class_mandate_neg.cc |  58 ++
> >>   .../23_containers/mdspan/layout_like.h|  63 ++
> >>   .../testsuite/23_containers/mdspan/mdspan.cc  | 540 ++
> >>   5 files changed, 945 insertions(+), 1 deletion(-)
> >>   create mode 100644
> >> libstdc++-v3/testsuite/23_containers/mdspan/class_mandate_neg.cc
> >>   create mode 100644
> >> libstdc++-v3/testsuite/23_containers/mdspan/layout_like.h
> >>   create mode 100644
> libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc
> >>
> >> diff --git a/libstdc++-v3/include/std/mdspan
> >> b/libstdc++-v3/include/std/mdspan
> >> index e198d65bba3..852f881971e 100644
> >> --- a/libstdc++-v3/include/std/mdspan
> >> +++ b/libstdc++-v3/include/std/mdspan
> >> @@ -1052,6 +1052,288 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >> { return __p + __i; }
> >>   };
> >>
> >> +  namespace __mdspan
> >> +  {
> >> +template
> >> +  constexpr bool
> >> +  __is_multi_index(const _Extents& __exts, span<_IndexType, _Nm>
> >> __indices)
> >> +  {
> >> +   static_assert(__exts.rank() == _Nm);
> >> +   for (size_t __i = 0; __i < __exts.rank(); ++__i)
> >> + if (__indices[__i] >= __exts.extent(__i))
> >> +   return false;
> >> +   return true;
> >> +  }
> >> +  }
> >> +
> >> +  template >> +  typename _LayoutPolicy = layout_right,
> >> +  typename _AccessorPolicy = default_accessor<_ElementType>>
> >> +class mdspan
> >> +{
> >> +  static_assert(!is_array_v<_ElementType>,
> >> +   "ElementType must not be an array type");
> >> +  static_assert(!is_abstract_v<_ElementType>,
> >> +   "ElementType must not be an abstract class type");
> >> +  static_assert(__mdspan::__is_extents<_Extents>,
> >> +   "Extents must be a specialization of std::extents");
> >> +  static_assert(is_same_v<_ElementType,
> >> + typename _AccessorPolicy::element_type>);
> >> +
> >> +public:
> >> +  using extents_type = _Extents;
> >> +  using layout_type = _LayoutPolicy;
> >> +  using accessor_type = _AccessorPolicy;
> >> +  using mapping_type = typename layout_type::template
> >> mapping;
> >> +  using element_type = _ElementType;
> >> +  using value_type = remove_cv_t;
> >> +  using index_type = typename extents_type::index_type;
> >> +  using size_type = typename extents_type::size_type;
> >> +  using rank_type = typename extents_type::rank_type;
> >> +  using data_handle_type = typename
> accessor_type::data_handle_type;
> >> +  using reference = typename accessor_type::reference;
> >> +
> >> +  static constexpr rank_type
> >> +  rank() noexcept { return extents_type::rank(); }
> >> +
> >> +  static constexpr rank_type
> >> +  rank_dynamic() noexcept { return extents_type::rank_dynamic(); }
> >> +
> >> +  static constexpr size_t
> >> +  static_extent(rank_type __r) noexcept
> >> +  { return extents_type::static_extent(__r); }
> >> +
> >> +  constexpr index_type
> >> +  extent(rank_type __r) const noexcept { return
> >> extents().extent(__r); }
> >> +
> >> +  constexpr
> >> +  mdspan()
> >> +  requires (rank_dynamic() > 0 &&
> >> + is_default_constructible_v &&
> >> + is_default_constructible_v &&
> >> + is_default_constructible_v)
> >> +  : _M_accessor{}, _M_mapping{}, _M_handle{}
> >> +  { }
> >> +
> >> +  constexpr
> >> +  mdspan(const mdspan& __other) = default;
> >> +
> >> +  constexpr
> >> +  mdspan(mdspan&& __other) = default;
> >> +
> >> +  template<__mdspan::__valid_index_type...
> _OIndexTypes>
> >> +   requires ((sizeof...(_OIndexTypes) == rank()
> >> +  || sizeof...(_OIndexTypes) == rank_dynamic())
> >> +   && is_constructible_v
> >> +   && is_default_constructible_v)
> >> +   constexpr explicit
> >> +   mdspan(data_handle_

Re: [PATCH] testsuite: i386: Fix gcc.target/i386/preserve-none-1.c on Solaris/x86

2025-07-01 Thread H.J. Lu
On Tue, Jul 1, 2025 at 4:47 PM Rainer Orth  
wrote:
>
> The new gcc.target/i386/preserve-none-1.c test currently FAILs on
> Solaris/x86:
>
> FAIL: gcc.target/i386/preserve-none-1.c scan-assembler-not movq
>
> It needs -fomit-frame-pointer which this patch adds.
>
> Tested on i386-pc-solaris2.11 and x86_64-pc-linux-gnu.
>
> Ok for trunk?

Yes.

> Rainer
>
> --
> -
> Rainer Orth, Center for Biotechnology, Bielefeld University
>
>
> 2025-06-27  Rainer Orth  
>
> gcc/testsuite:
> * gcc.target/i386/preserve-none-1.c (dg-options): Add
> -fomit-frame-pointer.
>


-- 
H.J.


Re: [PATCH] s390: Add -fno-stack-protector to 3 tests

2025-07-01 Thread Stefan Schulze Frielinghaus
Hi Jakub,

On Tue, Jul 01, 2025 at 02:50:04PM +0200, Jakub Jelinek wrote:
> Hi!
> 
> In Fedora/RHEL we usually test with
> make check RUNTESTFLAGS="--target_board=unix/'{,-fstack-protector-strong}'"
> because -fstack-protector-strong is used when building pretty much all the
> packages.
> 
> In the past Marek Polacek has committed tweaks to various tests to make
> them PASS in such testing, see e.g. r14-6276 or r14-2200.
> These 3 tests FAIL with -fstack-protector-strong on s390x because they
> use check-function-bodies and aren't prepared for the extra
> -fstack-protector-{strong,all} extra code in the prologue/epilogue.

In the past years I have started to use more and more function body
checks whenever gcc emits optimal code for a function.  With that I
wanted to make sure that we do not regress like introducing unnecessary
extends or whatever which might not have been caught by only testing the
"interesting"/actual part of a patch.  Thus, as long as those function
body checks are stable enough, i.e., not subject to insn reordering or
the like, I would like to make use of them in the future, too.   That
being said I'm wondering whether it would make sense to automatically
add option -fno-stack-protector for tests which make use function-body
checks?  If the testsuite infrastructure doesn't provide this
functionality trivially, I will try to keep this in mind and always add
the option manually.

> 
> The following patch should fix that.
> 
> Ok for trunk/15.2?

Ok.

Thanks,
Stefan


[PATCH v2] libstdc++: Lift locale initialization in main chrono format loop [PR110739]

2025-07-01 Thread Tomasz Kamiński
This patch lifts locale initialization from locale-specific handling methods
into _M_format_to function, and pass the locale by const reference.
To avoid unnecessary computation of locale::classic(), we use _Optional_locale,
and emplace into it only for localized formatting (_M_spec._M_localized) or if
chrono-spec contains locale specific specifiers (_M_spec._M_locale_specific).
The later is constructs locale::classic() in more cases that strictly necessary,
as only subset of locale specific specifiers (%a, %A, %b, %B, %c, %p, %r) needs
locale, while _M_locale_specific is also set for %x,%X and when O/E modifiers 
are
used. However, none of default outputs are affects, so I believe this is
acceptable.

In _M_S we no longer guard querying of numpuct facet, with check that requires
potentially equally expensive construction of locale::classic. We also mark
localized path as unlikely.

The _M_locale method is no longer used in __formatter_chrono, and thus was
moved to __formatter_duration.

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (__formatter_chrono::_M_format_to):
Compute locale and pass it to specifiers method.
(__formatter_chrono::_M_a_A, __formatter_chrono::_M_b_B)
(__formatter_chrono::_M_c, __formatter_chrono::_M_p)
(__formatter_chrono::_M_r): Accept locale instead of format context.
(__formatter_chrono::_M_subsecs): Call __ctx.locale() directly,
instead of _M_locale and do not compare with locale::classic().
Add [[unlikely]] attributes.
(__formatter_chrono::_M_locale): Move to __formatter_duration.
(__formatter_duration::_M_locale): Moved from __formatter_chrono.
---
v2 updates the commit message text only in hope to make it more readable.

 libstdc++-v3/include/bits/chrono_io.h | 71 ---
 1 file changed, 43 insertions(+), 28 deletions(-)

diff --git a/libstdc++-v3/include/bits/chrono_io.h 
b/libstdc++-v3/include/bits/chrono_io.h
index bcf9830fb9e..a25cb9ada01 100644
--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -964,10 +964,16 @@ namespace __format
return std::move(__out);
  };
 
+ _Optional_locale __loc;
+ if (_M_spec._M_localized)
+   __loc = __fc.locale();
+ else if (_M_spec._M_locale_specific)
+   __loc = locale::classic();
+
  struct tm __tm{};
  bool __use_locale_fmt = false;
  if (_M_spec._M_localized && _M_spec._M_locale_specific)
-   if (__fc.locale() != locale::classic())
+   if (__loc.value() != locale::classic())
  {
__use_locale_fmt = true;
 
@@ -1004,7 +1010,7 @@ namespace __format
{
  _CharT __c = *__first++;
  if (__use_locale_fmt && _S_localized_spec(__c, __mod)) 
[[unlikely]]
-   __out = _M_locale_fmt(std::move(__out), __fc.locale(),
+   __out = _M_locale_fmt(std::move(__out), __loc.value(),
  __tm, __c, __mod);
  else switch (__c)
{
@@ -1014,15 +1020,17 @@ namespace __format
  break;
case 'a':
case 'A':
- __out = _M_a_A(__t._M_weekday, std::move(__out), __fc, __c == 
'A');
+ __out = _M_a_A(__t._M_weekday, std::move(__out),
+__loc.value(), __c == 'A');
  break;
case 'b':
case 'h':
case 'B':
- __out = _M_b_B(__t._M_month, std::move(__out), __fc, __c == 
'B');
+ __out = _M_b_B(__t._M_month, std::move(__out),
+__loc.value(), __c == 'B');
  break;
case 'c':
- __out = _M_c(__t, std::move(__out), __fc);
+ __out = _M_c(__t, std::move(__out), __loc.value());
  break;
case 'C':
case 'y':
@@ -1058,7 +1066,7 @@ namespace __format
  __out = _M_M(__t._M_minutes, __print_sign());
  break;
case 'p':
- __out = _M_p(__t._M_hours, std::move(__out), __fc);
+ __out = _M_p(__t._M_hours, std::move(__out), __loc.value());
  break;
case 'q':
  __out = _M_q(__t._M_unit_suffix, std::move(__out));
@@ -1067,7 +1075,7 @@ namespace __format
  __out = _M_Q(__t, __print_sign(), __fc);
  break;
case 'r':
- __out = _M_r(__t, __print_sign(), __fc);
+ __out = _M_r(__t, __print_sign(), __loc.value());
  break;
case 'R':
case 'X':
@@ -1146,10 +1154,10 @@ namespace __format
  return std::move(__out);
}
 
-  template
+  template
_OutIter
_M_a_A(chrono::weekday __wd, _OutIter __out,
- 

Re: [PATCH RFC] libgcc: don't use a weak ref for __cxa_finalize

2025-07-01 Thread Florian Weimer
* Jason Merrill:

> On 6/30/25 5:22 PM, Florian Weimer wrote:
>> * Jason Merrill:
>> 
>>> On 6/28/25 3:17 PM, Florian Weimer wrote:
 * Jason Merrill:

> Since r10-6069[1] we control the call to __cxa_finalize with
> DEFAULT_USE_CXA_ATEXIT, so there's no need to also declare it as a weak
> reference; if the target has __cxa_atexit, it must also have 
> __cxa_finalize.
>> 
 I expect that most targets do not need __cxa_finalize.  They can run
 the registered destructors directly, without waiting for a call to
 __cxa_finalize.
>>>
>>> AFAICT glibc still uses __cxa_finalize to run destructors on dlclose;
>>> at least that's what its comment says.
>> Yes, but for most target processors, there is a variety of targets
>> which
>> don't do this (no dlclose …), hence “most targets” is still true.
>> Maybe. 8-)
>
> But if those targets don't have dlclose, they don't need __cxa_atexit
> and should (and probably do) leave default_use_cxa_atexit off in
> config.gcc.

Hmm, that's a fair point.  I didn't realize that they could use atexit
directly.

 I think with your patch, libc will is always linked in as well,
 assuming that it's the source of the __cxa_finalize definition.
>>>
>>> True, so that's not a difference for __cxa_atexit targets.
>> Existing targets that reuse the glibc toolchain will have to do
>> something about __cxa_finalize after your change goes in, though.
>
> If they're linking shared libraries (which seems unlikely in your
> bootloader scenario below).

It just occurred to me that linking shared libraries usually doesn't use
-Wl,-z,defs yet, so you would just get underlinking as before.  So
-nostartfiles probably is not needed after all.

>> I'm not sure if that's what our users expect.  Common practice is to
>> use *-linux-gnu targets to build bootloaders, kernels and whatnot
>> using the same toolchain, and not create a separate *-none target
>> with different configure options.  I think that's … not great for
>> full libc targets (where the toolchain may end up supporting
>> GNU-style symbol versions, but the dynamic linker does not).  But for
>> more limited bootloader-type scenarios (no full libc, no dynamic
>> linking), it evidently works quite well so far.
>
> Interesting point, are there in fact such packages that rely on
> -fno-use-cxa-atexit?

I found this one:



Possibly more could be discovered by poking around in Debian Code Search
.

Thanks,
Florian



[PATCH] i386: Change Diamond Rapids feature detect when model number could not be distinguished

2025-07-01 Thread Haochen Jiang
Hi all,

We will use AMX-FP8 for DMR since it is a smaller and more unique feature.

Ok for trunk and backport to GCC 15?

Thx,
Haochen

gcc/ChangeLog:

* config/i386/driver-i386.cc (host_detect_local_cpu): Change
to AMX-FP8 for Diamond Rapids.
---
 gcc/config/i386/driver-i386.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/i386/driver-i386.cc b/gcc/config/i386/driver-i386.cc
index 63c7d79326d..fe71f550075 100644
--- a/gcc/config/i386/driver-i386.cc
+++ b/gcc/config/i386/driver-i386.cc
@@ -600,7 +600,7 @@ const char *host_detect_local_cpu (int argc, const char 
**argv)
  if (has_feature (FEATURE_AVX512F))
{
  /* Assume Diamond Rapids.  */
- if (has_feature (FEATURE_AMX_TRANSPOSE))
+ if (has_feature (FEATURE_AMX_FP8))
cpu = "diamondrapids";
  /* Assume Granite Rapids D.  */
  else if (has_feature (FEATURE_AMX_COMPLEX))
-- 
2.31.1



RE: [PATCH] i386: Change Diamond Rapids feature detect when model number could not be distinguished

2025-07-01 Thread Liu, Hongtao



> -Original Message-
> From: Jiang, Haochen 
> Sent: Wednesday, July 2, 2025 11:10 AM
> To: gcc-patches@gcc.gnu.org
> Cc: Liu, Hongtao ; ubiz...@gmail.com
> Subject: [PATCH] i386: Change Diamond Rapids feature detect when model
> number could not be distinguished
> 
> Hi all,
> 
> We will use AMX-FP8 for DMR since it is a smaller and more unique feature.
> 
> Ok for trunk and backport to GCC 15?
Ok.
> 
> Thx,
> Haochen
> 
> gcc/ChangeLog:
> 
>   * config/i386/driver-i386.cc (host_detect_local_cpu): Change
>   to AMX-FP8 for Diamond Rapids.
> ---
>  gcc/config/i386/driver-i386.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gcc/config/i386/driver-i386.cc b/gcc/config/i386/driver-i386.cc
> index 63c7d79326d..fe71f550075 100644
> --- a/gcc/config/i386/driver-i386.cc
> +++ b/gcc/config/i386/driver-i386.cc
> @@ -600,7 +600,7 @@ const char *host_detect_local_cpu (int argc, const
> char **argv)
> if (has_feature (FEATURE_AVX512F))
>   {
> /* Assume Diamond Rapids.  */
> -   if (has_feature (FEATURE_AMX_TRANSPOSE))
> +   if (has_feature (FEATURE_AMX_FP8))
>   cpu = "diamondrapids";
> /* Assume Granite Rapids D.  */
> else if (has_feature (FEATURE_AMX_COMPLEX))
> --
> 2.31.1



[PATCH] RISC-V: testsuite: Skip tests providing -march/-mcpu for ILP32E/ILP64E ABIs

2025-07-01 Thread Dimitar Dimitrov
Some test cases explicitly set -march or -mcpu with extensions which
are not compatible with the E ABI variants.  This leads to spurious
errors when toolchain has been configured for RV32E base ISA and
ILP32E ABI:
  cc1: error: ILP32E ABI does not support the 'D' extension

Also, test gcc.target/riscv/rvv/base/pr119164.c implicitly requires
rv64 since it explicitly selects -march=rv64gcv_zvl256b:
  cc1: error: ABI requires '-march=rv32'

Testing done:
 - Ensured cross riscv64-unknown-linux-gnu has no difference in test
   output with and without the patch.
 - For riscv32-unknown-elf  there are no new failures. Test case pr119164.c
   no longer fails and is now marked as unsupported.

Ok for trunk?

Signed-off-by: Dimitar Dimitrov 
---
 gcc/testsuite/gcc.target/riscv/mcpu-xt-c908.c  | 2 +-
 gcc/testsuite/gcc.target/riscv/mcpu-xt-c908v.c | 2 +-
 gcc/testsuite/gcc.target/riscv/mcpu-xt-c910.c  | 2 +-
 gcc/testsuite/gcc.target/riscv/mcpu-xt-c910v2.c| 2 +-
 gcc/testsuite/gcc.target/riscv/mcpu-xt-c920.c  | 2 +-
 gcc/testsuite/gcc.target/riscv/mcpu-xt-c920v2.c| 2 +-
 gcc/testsuite/gcc.target/riscv/pr118241.c  | 2 +-
 gcc/testsuite/gcc.target/riscv/pr120223.c  | 2 +-
 gcc/testsuite/gcc.target/riscv/rvv/base/pr119164.c | 2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c908.c 
b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c908.c
index cb28baf1ce7..4ad82a81dec 100644
--- a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c908.c
+++ b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c908.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do compile { target { ! riscv_abi_e } } } */
 /* { dg-skip-if "-march given" { *-*-* } { "-march=*" } } */
 /* { dg-options "-mcpu=xt-c908" { target { rv64 } } } */
 /* XuanTie C908 => rv64imafdc_zicbom_zicbop_zicboz_zicntr_zicsr_zifencei_
diff --git a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c908v.c 
b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c908v.c
index 1b1ee188229..bb9e3109920 100644
--- a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c908v.c
+++ b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c908v.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do compile { target { ! riscv_abi_e } } } */
 /* { dg-skip-if "-march given" { *-*-* } { "-march=*" } } */
 /* { dg-options "-mcpu=xt-c908v" { target { rv64 } } } */
 /* XuanTie C908v => rv64imafdcv_zicbom_zicbop_zicboz_zicntr_zicsr_zifencei_
diff --git a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c910.c 
b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c910.c
index 1e276659c3e..397e7b19267 100644
--- a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c910.c
+++ b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c910.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do compile { target { ! riscv_abi_e } } } */
 /* { dg-skip-if "-march given" { *-*-* } { "-march=*" } } */
 /* { dg-options "-mcpu=xt-c910" { target { rv64 } } } */
 /* XuanTie C910 => rv64imafdc_zicntr_zicsr_zifencei_zihpm_zfh_xtheadba_
diff --git a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c910v2.c 
b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c910v2.c
index 6a54f098878..9e39c9f89eb 100644
--- a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c910v2.c
+++ b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c910v2.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do compile { target { ! riscv_abi_e } } } */
 /* { dg-skip-if "-march given" { *-*-* } { "-march=*" } } */
 /* { dg-options "-mcpu=xt-c910v2" { target { rv64 } } } */
 /* XuanTie C910v2 => rv64imafdc_zicbom_zicbop_zicboz_zicntr_zicond_zicsr_
diff --git a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c920.c 
b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c920.c
index 6bcd687e742..4cce90a1e94 100644
--- a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c920.c
+++ b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c920.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do compile { target { ! riscv_abi_e } } } */
 /* { dg-skip-if "-march given" { *-*-* } { "-march=*" } } */
 /* { dg-options "-mcpu=xt-c920" { target { rv64 } } } */
 /* XuanTie c920 => 
rv64imafdc_zicntr_zicsr_zifencei_zihpm_zfh_"xtheadba_xtheadbb_xtheadbs_xtheadcmo_xtheadcondmov_xtheadfmemidx_xtheadmac_xtheadmemidx_xtheadmempair_xtheadsync_xtheadvector
 */
diff --git a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c920v2.c 
b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c920v2.c
index 36a6267849b..1f21d07f37a 100644
--- a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c920v2.c
+++ b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c920v2.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do compile { target { ! riscv_abi_e } } } */
 /* { dg-skip-if "-march given" { *-*-* } { "-march=*" } } */
 /* { dg-options "-mcpu=xt-c920v2" { target { rv64 } } } */
 /* XuanTie C920v2 => 
rv64imafdcv_zicbom_zicbop_zicboz_zicntr_zicond_zicsr_zifencei 
_zihintntl_zihintpause_zihpm_zawrs_zfa_zfbfmin_zfh_zca_zcb_zcd_zba_zbb_zbc_zbs_zvfbfmin_zvfbfwma_zvfh_sscofpmf_sstc_svinval_svnapot_svpbmt_xtheadba_xtheadbb_xtheadbs_xtheadcmo_xtheadcondmov_xtheadfmemidx_xtheadsync_xtheadvdot
 */
diff --git a/gcc/testsuite/gcc.target/riscv/pr

Re: [PATCH 1/1] [RFC][AutoFDO] Propagate information to outline copies if not inlined

2025-07-01 Thread Dhruv Chawla

On 02/07/25 07:26, Kugan Vivekanandarajah wrote:





Given the latest few patches that you have committed, is this patch necessary
anymore? I have not fully understood the new logic as I was on holiday last
week, but it looks like the propagation is occurring correctly now?



I think you are referring to the patch “Avoid some lost AFDO profiles with LTO” 
which introduces pass_ipa_auto_profile_offline. I dont think it does offline 
functions !afdo_callsite_hot_enough_for_early_inline.  However, it should be 
easier now as the early_inline is moved out of auto-profile.


Hmm, I was referring to the "Fix afdo profiles for functions that
was not early-inlined" patch which introduces the

void
autofdo_source_profile::offline_unrealized_inlines ()

function. This seems to merge profiles to offline definitions, and it
is called from the main auto_profile function.



Thanks,
Kugan



--
Regards,
Dhruv


Re: [PATCH] RISC-V: testsuite: Skip tests providing -march/-mcpu for ILP32E/ILP64E ABIs

2025-07-01 Thread Kito Cheng
OK :)

On Wed, Jul 2, 2025 at 12:22 PM Dimitar Dimitrov  wrote:
>
> Some test cases explicitly set -march or -mcpu with extensions which
> are not compatible with the E ABI variants.  This leads to spurious
> errors when toolchain has been configured for RV32E base ISA and
> ILP32E ABI:
>   cc1: error: ILP32E ABI does not support the 'D' extension
>
> Also, test gcc.target/riscv/rvv/base/pr119164.c implicitly requires
> rv64 since it explicitly selects -march=rv64gcv_zvl256b:
>   cc1: error: ABI requires '-march=rv32'
>
> Testing done:
>  - Ensured cross riscv64-unknown-linux-gnu has no difference in test
>output with and without the patch.
>  - For riscv32-unknown-elf  there are no new failures. Test case pr119164.c
>no longer fails and is now marked as unsupported.
>
> Ok for trunk?
>
> Signed-off-by: Dimitar Dimitrov 
> ---
>  gcc/testsuite/gcc.target/riscv/mcpu-xt-c908.c  | 2 +-
>  gcc/testsuite/gcc.target/riscv/mcpu-xt-c908v.c | 2 +-
>  gcc/testsuite/gcc.target/riscv/mcpu-xt-c910.c  | 2 +-
>  gcc/testsuite/gcc.target/riscv/mcpu-xt-c910v2.c| 2 +-
>  gcc/testsuite/gcc.target/riscv/mcpu-xt-c920.c  | 2 +-
>  gcc/testsuite/gcc.target/riscv/mcpu-xt-c920v2.c| 2 +-
>  gcc/testsuite/gcc.target/riscv/pr118241.c  | 2 +-
>  gcc/testsuite/gcc.target/riscv/pr120223.c  | 2 +-
>  gcc/testsuite/gcc.target/riscv/rvv/base/pr119164.c | 2 +-
>  9 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c908.c 
> b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c908.c
> index cb28baf1ce7..4ad82a81dec 100644
> --- a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c908.c
> +++ b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c908.c
> @@ -1,4 +1,4 @@
> -/* { dg-do compile } */
> +/* { dg-do compile { target { ! riscv_abi_e } } } */
>  /* { dg-skip-if "-march given" { *-*-* } { "-march=*" } } */
>  /* { dg-options "-mcpu=xt-c908" { target { rv64 } } } */
>  /* XuanTie C908 => rv64imafdc_zicbom_zicbop_zicboz_zicntr_zicsr_zifencei_
> diff --git a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c908v.c 
> b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c908v.c
> index 1b1ee188229..bb9e3109920 100644
> --- a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c908v.c
> +++ b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c908v.c
> @@ -1,4 +1,4 @@
> -/* { dg-do compile } */
> +/* { dg-do compile { target { ! riscv_abi_e } } } */
>  /* { dg-skip-if "-march given" { *-*-* } { "-march=*" } } */
>  /* { dg-options "-mcpu=xt-c908v" { target { rv64 } } } */
>  /* XuanTie C908v => rv64imafdcv_zicbom_zicbop_zicboz_zicntr_zicsr_zifencei_
> diff --git a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c910.c 
> b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c910.c
> index 1e276659c3e..397e7b19267 100644
> --- a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c910.c
> +++ b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c910.c
> @@ -1,4 +1,4 @@
> -/* { dg-do compile } */
> +/* { dg-do compile { target { ! riscv_abi_e } } } */
>  /* { dg-skip-if "-march given" { *-*-* } { "-march=*" } } */
>  /* { dg-options "-mcpu=xt-c910" { target { rv64 } } } */
>  /* XuanTie C910 => rv64imafdc_zicntr_zicsr_zifencei_zihpm_zfh_xtheadba_
> diff --git a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c910v2.c 
> b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c910v2.c
> index 6a54f098878..9e39c9f89eb 100644
> --- a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c910v2.c
> +++ b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c910v2.c
> @@ -1,4 +1,4 @@
> -/* { dg-do compile } */
> +/* { dg-do compile { target { ! riscv_abi_e } } } */
>  /* { dg-skip-if "-march given" { *-*-* } { "-march=*" } } */
>  /* { dg-options "-mcpu=xt-c910v2" { target { rv64 } } } */
>  /* XuanTie C910v2 => rv64imafdc_zicbom_zicbop_zicboz_zicntr_zicond_zicsr_
> diff --git a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c920.c 
> b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c920.c
> index 6bcd687e742..4cce90a1e94 100644
> --- a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c920.c
> +++ b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c920.c
> @@ -1,4 +1,4 @@
> -/* { dg-do compile } */
> +/* { dg-do compile { target { ! riscv_abi_e } } } */
>  /* { dg-skip-if "-march given" { *-*-* } { "-march=*" } } */
>  /* { dg-options "-mcpu=xt-c920" { target { rv64 } } } */
>  /* XuanTie c920 => 
> rv64imafdc_zicntr_zicsr_zifencei_zihpm_zfh_"xtheadba_xtheadbb_xtheadbs_xtheadcmo_xtheadcondmov_xtheadfmemidx_xtheadmac_xtheadmemidx_xtheadmempair_xtheadsync_xtheadvector
>  */
> diff --git a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c920v2.c 
> b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c920v2.c
> index 36a6267849b..1f21d07f37a 100644
> --- a/gcc/testsuite/gcc.target/riscv/mcpu-xt-c920v2.c
> +++ b/gcc/testsuite/gcc.target/riscv/mcpu-xt-c920v2.c
> @@ -1,4 +1,4 @@
> -/* { dg-do compile } */
> +/* { dg-do compile { target { ! riscv_abi_e } } } */
>  /* { dg-skip-if "-march given" { *-*-* } { "-march=*" } } */
>  /* { dg-options "-mcpu=xt-c920v2" { target { rv64 } } } */
>  /* XuanTie C920v2 => 
> rv64imafdcv_zicbom_zicbop_zicboz_zicntr_zicond_zicsr_zifencei 
> _zihintntl_zi

Re: [RFC PATCH v2 3/3] Add -ftarget-clones-table option support

2025-07-01 Thread Yangyu Chen



> On 30 Jun 2025, at 17:55, Alfie Richards  wrote:
> 
> On 29/06/2025 19:57, Yangyu Chen wrote:
>> This patch adds support for target_clones table option. The
>> target_clones table option allows users to specify multiple versions
>> of a function and select the version at runtime based on the specified
>> table.
>> The target clone table is a JSON object where function names serve as
>> keys, and their values are nested objects. Each nested object maps
>> architecture names to lists of target clone attributes. This structure
>> allows specifying function clones for different architectures. Below is
>> an example:
>> ```
>> {
>>   "foo": {
>> "x86_64": ["avx2", "avx512f"],
>> "riscv64": ["arch=+v", "arch=+zba,+zbb", ...],
>> ... // more architectures
>>   },
>>   // more functions
>> }
>> ```
>> A example of the table is as follows on RISC-V:
>> C source code "ror32.c":
>> ```
>> void ror32(unsigned int *a, unsigned int b, unsigned long size) {
>>   for (unsigned long i = 0; i < size; i++) {
>> a[i] = a[i] >> b | (a[i] << (32 - b));
>>   }
>> }
>> ```
>> Table "ror32.target_clones":
>> ```
>> {
>>   "ror32": {
>> "riscv64": ["arch=+zvbb,+zbb", "arch=+zbb"]
>>   }
>> }
>> ```
>> Then use: gcc -O3 -ftarget-clones-table=ror32.target_clones -S ror32.c
>> to compile the source code. This will generate 3 versions and its IFUNC
>> resolver for the ror32 function which is "arch=+zvbb,+zbb" and
>> "arch=+zbb" and the default version.
>> Signed-off-by: Yangyu Chen 
>> gcc/ChangeLog:
>> * Makefile.in: Add -DTARGET_NAME to CFLAGS-multiple_target.o.
>> * common.opt: Add target clone table option.
>> * multiple_target.cc (expand_target_clones): Add support for
>> target_clones table option.
>> (init_clone_map): Ditto.
>> (ipa_target_clone): Ditto.
>> ---
>>  gcc/Makefile.in|   1 +
>>  gcc/common.opt |   7 +++
>>  gcc/multiple_target.cc | 124 -
>>  3 files changed, 129 insertions(+), 3 deletions(-)
>> diff --git a/gcc/Makefile.in b/gcc/Makefile.in
>> index 9535804f7fb..9bf633367e2 100644
>> --- a/gcc/Makefile.in
>> +++ b/gcc/Makefile.in
>> @@ -2682,6 +2682,7 @@ s-bversion: BASE-VER
>>   $(STAMP) s-bversion
>>CFLAGS-toplev.o += -DTARGET_NAME=\"$(target_noncanonical)\"
>> +CFLAGS-multiple_target.o += -DTARGET_NAME=\"$(target_noncanonical)\"
>>  CFLAGS-tree-diagnostic-client-data-hooks.o += 
>> -DTARGET_NAME=\"$(target_noncanonical)\"
>>  CFLAGS-optinfo-emit-json.o += -DTARGET_NAME=\"$(target_noncanonical)\" 
>> $(ZLIBINC)
>>  CFLAGS-analyzer/engine.o += $(ZLIBINC)
>> diff --git a/gcc/common.opt b/gcc/common.opt
>> index a76a6920b54..45d49a92b5f 100644
>> --- a/gcc/common.opt
>> +++ b/gcc/common.opt
>> @@ -2692,6 +2692,13 @@ fprofile-reorder-functions
>>  Common Var(flag_profile_reorder_functions) Optimization
>>  Enable function reordering that improves code placement.
>>  +ftarget-clones-table=
>> +Common Joined RejectNegative Var(target_clones_table)
>> +Enable target clones attributes specified in the JSON file.
>> +
>> +Variable
>> +const char *target_clones_table = NULL
>> +
>>  fpatchable-function-entry=
>>  Common Var(flag_patchable_function_entry) Joined Optimization
>>  Insert NOP instructions at each function entry.
>> diff --git a/gcc/multiple_target.cc b/gcc/multiple_target.cc
>> index d25277c0a93..b5e52d5b91f 100644
>> --- a/gcc/multiple_target.cc
>> +++ b/gcc/multiple_target.cc
>> @@ -21,6 +21,10 @@ along with GCC; see the file COPYING3.  If not see
>>  .  */
>>#include "config.h"
>> +#include 
>> +#define INCLUDE_MAP
>> +#define INCLUDE_STRING
>> +#define INCLUDE_SSTREAM
>>  #include "system.h"
>>  #include "coretypes.h"
>>  #include "backend.h"
>> @@ -38,6 +42,7 @@ along with GCC; see the file COPYING3.  If not see
>>  #include "gimple-walk.h"
>>  #include "tree-inline.h"
>>  #include "intl.h"
>> +#include "json-parsing.h"
>>/* Walker callback that replaces all FUNCTION_DECL of a function that's
>> going to be versioned.  */
>> @@ -311,7 +316,8 @@ create_target_clone (cgraph_node *node, bool definition, 
>> char *name,
>> create the appropriate clone for each valid target attribute.  */
>>static bool
>> -expand_target_clones (struct cgraph_node *node, bool definition)
>> +expand_target_clones (struct cgraph_node *node, bool definition,
>> +   std::map  &clone_map)
>>  {
>>int i;
>>/* Parsing target attributes separated by TARGET_CLONES_ATTR_SEPARATOR.  
>> */
>> @@ -319,7 +325,24 @@ expand_target_clones (struct cgraph_node *node, bool 
>> definition)
>>  DECL_ATTRIBUTES (node->decl));
>>/* No targets specified.  */
>>if (!attr_target)
>> -return false;
>> +{
> 
> This seems to only apply the file specified versions if there is no attribute 
> in the source code. I think this could be confusing to users.
> 
> My preference would be to merge the source code attr versions and the JSON 
> file versions, but if you would rather not do that then I

[PATCH] check-function-bodies: Support "^[0-9]+:"

2025-07-01 Thread H.J. Lu
While working on

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120881

I tried to use check-function-bodies to verify that

1: call mcount

generated by "-pg" is placed at the function entry.  Add "^[0-9]+:" to
check-function-bodies to allow:

1: call mcount

PR testsuite/120881
* lib/scanasm.exp (check-function-bodies): Allow "^[0-9]+:".

OK for master?

Thanks.

-- 
H.J.
From 42dc904c7e155eae1893152b8db46e697136 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" 
Date: Wed, 2 Jul 2025 08:51:47 +0800
Subject: [PATCH] check-function-bodies: Support "^[0-9]+:"

While working on

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120881

I tried to use check-function-bodies to verify that

1:	call	mcount

generated by "-pg" is placed at the function entry.  Add "^[0-9]+:" to
check-function-bodies to allow:

1:	call	mcount

	PR testsuite/120881
	* lib/scanasm.exp (check-function-bodies): Allow "^[0-9]+:".

Signed-off-by: H.J. Lu 
---
 gcc/testsuite/lib/scanasm.exp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp
index 97935cb23c3..a2311de5704 100644
--- a/gcc/testsuite/lib/scanasm.exp
+++ b/gcc/testsuite/lib/scanasm.exp
@@ -1109,6 +1109,8 @@ proc check-function-bodies { args } {
 		append function_regexp ".*"
 	} elseif { [regexp {^\.L} $line] } {
 		append function_regexp $line "\n"
+	} elseif { [regexp {^[0-9]+:} $line] } {
+		append function_regexp $line "\n"
 	} else {
 		append function_regexp $config(line_prefix) $line "\n"
 	}
-- 
2.50.0



[PATCH] tail-call: Allow tail recusion for classes with RVO (TREE_ADDRESSABLE set) [PR120871]

2025-07-01 Thread Andrew Pinski
With struct returns, we normally get a decl on the LHS of the call expression
that will be tail called and we can match things up there easy.
With TREE_ADDRESSABLE set on the type, things get more complex.
Instead we get:
```
  *_6(D) = get_s (1); [return slot optimization]
...
  return _6(D);
```

So we have to match _6 as being the ssa name for the result decl, make sure RSO 
is set
and match MEM_REF with a zero offset if we want to do tail calls.

This is also the first step in allowing tail calls in this case too;  I will 
expand
the patch for PR71761 to handle the taill call later on.

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

PR tree-optimization/120871

gcc/ChangeLog:

* tree-tailcall.cc (find_tail_calls): Allow a MEM_REF
with a zero offset with RSO set on the call and with
the MEM_REF is of the result decl default definition.

gcc/testsuite/ChangeLog:

* g++.dg/opt/tail-call-1.C: New test.

Signed-off-by: Andrew Pinski 
---
 gcc/testsuite/g++.dg/opt/tail-call-1.C | 19 +
 gcc/tree-tailcall.cc   | 37 --
 2 files changed, 48 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/opt/tail-call-1.C

diff --git a/gcc/testsuite/g++.dg/opt/tail-call-1.C 
b/gcc/testsuite/g++.dg/opt/tail-call-1.C
new file mode 100644
index 000..eee5287f4aa
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/tail-call-1.C
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-tailr-details " } */
+/* PR tree-optimization/120871 */
+
+struct Slice {
+const char* data;
+unsigned long size;
+~Slice() throw();
+};
+Slice get_s_impl();
+Slice get_s(bool t)
+{
+  if (!t)
+return get_s(!t);
+  return Slice();
+}
+
+/* Should be able to eliminate the tail recusion in get_s. */
+/* { dg-final { scan-tree-dump-times "Eliminated tail recursion in" 1 "tailr1" 
} } */
diff --git a/gcc/tree-tailcall.cc b/gcc/tree-tailcall.cc
index d6d28302211..dbf70f54956 100644
--- a/gcc/tree-tailcall.cc
+++ b/gcc/tree-tailcall.cc
@@ -715,14 +715,23 @@ find_tail_calls (basic_block bb, struct tailcall **ret, 
bool only_musttail,
  struct.  In this case we won't have a temporary here, but we need
  to carry out the side effect anyway, so tailcall is impossible.
 
- ??? In some situations (when the struct is returned in memory via
- invisible argument) we could deal with this, e.g. by passing 'p'
- itself as that argument to foo, but it's too early to do this here,
- and expand_call() will not handle it anyway.  If it ever can, then
- we need to revisit this here, to allow that situation.  */
+ If the call has RSO set and the lhs is a mem of the result decl of
+ the current function, we can handle this case.
+ That is if we have:
+ *_2(D) = function (...) [Return Slot Optimization];
+ This can handled by the middle-end and the tail recursion path.  */
   if (ass_var
-  && !is_gimple_reg (ass_var)
-  && !auto_var_in_fn_p (ass_var, cfun->decl))
+  && gimple_call_return_slot_opt_p (call)
+  && TREE_CODE (ass_var) == MEM_REF
+  && integer_zerop (TREE_OPERAND (ass_var, 1))
+  && TREE_CODE (TREE_OPERAND (ass_var, 0)) == SSA_NAME
+  && SSA_NAME_IS_DEFAULT_DEF (TREE_OPERAND (ass_var, 0))
+  && SSA_NAME_VAR (TREE_OPERAND (ass_var, 0))
+  && TREE_CODE (SSA_NAME_VAR (TREE_OPERAND (ass_var, 0))) == RESULT_DECL)
+;
+  else if (ass_var
+  && !is_gimple_reg (ass_var)
+  && !auto_var_in_fn_p (ass_var, cfun->decl))
 {
   maybe_error_musttail (call, _("return value in memory"), diag_musttail);
   return;
@@ -1098,7 +1107,19 @@ find_tail_calls (basic_block bb, struct tailcall **ret, 
bool only_musttail,
 {
   bool ok = false;
   value_range val;
-  if (ass_var == NULL_TREE && !tail_recursion)
+  /* If we have return _N;, then this can match
+up with MEM_REF<_N, 0>.
+RSO is already verfied to be set on the call above.  */
+  if (ass_var
+ && TREE_CODE (ret_var) == SSA_NAME
+ && SSA_NAME_IS_DEFAULT_DEF (ret_var)
+ && SSA_NAME_VAR (ret_var)
+ && TREE_CODE (SSA_NAME_VAR (ret_var)) == RESULT_DECL
+ && TREE_CODE (ass_var) == MEM_REF
+ && integer_zerop (TREE_OPERAND (ass_var, 1))
+ && TREE_OPERAND (ass_var, 0) == ret_var)
+   ok = true;
+  else if (ass_var == NULL_TREE && !tail_recursion)
{
  tree other_value = NULL_TREE;
  /* If we have a function call that we know the return value is the 
same
-- 
2.43.0



Re: [PATCH 1/1] [RFC][AutoFDO] Propagate information to outline copies if not inlined

2025-07-01 Thread Kugan Vivekanandarajah


> 
> Given the latest few patches that you have committed, is this patch necessary
> anymore? I have not fully understood the new logic as I was on holiday last
> week, but it looks like the propagation is occurring correctly now?
> 

I think you are referring to the patch “Avoid some lost AFDO profiles with LTO” 
which introduces pass_ipa_auto_profile_offline. I dont think it does offline 
functions !afdo_callsite_hot_enough_for_early_inline.  However, it should be 
easier now as the early_inline is moved out of auto-profile. 

Thanks,
Kugan



[PATCH v2] configury: replace autoconf obsolete macros [PR103459]

2025-07-01 Thread Pietro Monteiro
Autoreconf -Wall complains about obsolete macros, so replace them according to
the autoconf documentation[0].

This patch doesn't fully fix all warnings because I focused on doing simple
fixes and keeping the changes to the generated files to a minimum.

Bootstrapped and retested on x86_64-linux-gnu.

[0]: 
https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Obsolete-Macros.html

PR bootstrap/103459

ChangeLog:

* configure: Regenerate.
* configure.ac: Replace AC_CANONICAL_SYSTEM with AC_CANONICAL_TARGET.
Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE.  Replace AC_TRY_LINK with
AC_LINK_IFELSE.

c++tools/ChangeLog:

* configure: Regenerate.
* configure.ac: Replace AC_CANONICAL_SYSTEM with AC_CANONICAL_TARGET.

config/ChangeLog:

* acx.m4: Remove uses of AC_CHECK_TOOL_PREFIX.  Replace AC_TRY_COMPILE
with AC_COMPILE_IFELSE.
* asmcfi.m4: Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE.
* bitfields.m4: Likewise.
* cet.m4: Replace AC_TRY_LINK with AC_LINK_IFELSE.  Replace AC_TRY_RUN
with AC_RUN_IFELSE.
* codeset.m4: Replace AC_TRY_LINK with AC_LINK_IFELSE.
* enable.m4: Replace AC_HELP_STRING with AS_HELP_STRING.
* gcc-plugin.m4: Replace AC_TRY_LINK with AC_LINK_IFELSE.
* hwcaps.m4: Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE.  Replace
AC_TRY_LINK with AC_LINK_IFELSE.
* isl.m4: Replace AC_TRY_LINK with AC_LINK_IFELSE.
* lcmessage.m4:Replace AC_TRY_LINK with AC_LINK_IFELSE.
* lthostflags.m4: Replace AC_CANONICAL_SYSTEM with AC_CANONICAL_HOST.
* no-executables.m4: Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE.
Replace AC_TRY_LINK with AC_LINK_IFELSE.
* po.m4: Replace AC_OUTPUT_COMMANDS with AC_CONFIG_COMMANDS.
* tls.m4: Add explicit 4th argument to AC_LINK_IFELSE.

fixincludes/ChangeLog:

* configure: Regenerate.
* configure.ac: Replace AC_CANONICAL_SYSTEM with AC_CANONICAL_TARGET.

gcc/ChangeLog:

* acinclude.m4: Replace AC_FOREACH with m4_foreach_w.  Replace
AC_TRY_LINK with AC_LINK_IFELSE.
* configure: Regenerate.
* configure.ac: Replace AC_HELP_STRING with AS_HELP_STRING.  Replace
AC_PROG_LIBTOOL with LT_INIT.

gnattools/ChangeLog:

* configure.ac: Replace AC_HELP_STRING with AS_HELP_STRING.

gotools/ChangeLog:

* configure: Regenerate.
* configure.ac: Replace AC_CANONICAL_SYSTEM with AC_CANONICAL_TARGET.

libada/ChangeLog:

* configure.ac: Replace AC_HELP_STRING with AS_HELP_STRING.

libatomic/ChangeLog:

* acinclude.m4: Replace AC_ERROR with AS_MSG_ERROR.  Replace AC_TRY_LINK
with AC_LINK_IFELSE.  Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE.
Replace AC_TRY_RUN with AC_RUN_IFELSE.
* configure.ac: Replace AM_PROG_LIBTOOL with LT_INIT.  Replace
AC_STDC_HEADERS with AC_HEADER_STDC.

libbacktrace/ChangeLog:

* configure: Regenerate.
* configure.ac: Replace AC_CANONICAL_SYSTEM with AC_CANONICAL_TARGET.
Remove redundant AM_PROG_LIBTOOL.

libcc1/ChangeLog:

* configure: Regenerate.
* configure.ac: Replace AC_CANONICAL_SYSTEM with AC_CANONICAL_TARGET.
Remove redundant AM_PROG_LIBTOOL.

libcpp/ChangeLog:

* configure: Regenerate.
* configure.ac: Replace AC_CANONICAL_SYSTEM with AC_CANONICAL_TARGET.
Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE.

libgcc/ChangeLog:

* configure: Regenerate.
* configure.ac: Replace AC_HELP_STRING with AS_HELP_STRING.  Replace
AC_TRY_COMPILE with AC_COMPILE_IFELSE.

libgcobol/ChangeLog:

* configure: Regenerate.
* configure.ac: Remove redundant AM_PROG_LIBTOOL.

libgfortran/ChangeLog:

* acinclude.m4: Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE.
* configure.ac: Replace AC_LANG_C with AC_LANG([C]).  Replace
AM_PROG_LIBTOOL with LT_INIT.

libgm2/ChangeLog:

* acinclude.m4: Replace AC_HELP_STRING with AS_HELP_STRING.  Replace
AC_LANG_SAVE AC_LANG_CPLUSPLUS (...) AC_LANG_RESTORE with
AC_LANG_PUSH([C++]) (...) AC_LANG_POP([C++]).  Replace AC_TRY_LINK with
AC_LINK_IFELSE.  Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE.
* configure: Regenerate.
* configure.ac: Replace AC_HELP_STRING AS_HELP_STRING.  Remove redundant
AM_PROG_LIBTOOL.  Replace AC_LANG_C with AC_LANG([C]).  Replace
AC_FOREACH with m4_foreach_w.

libgomp/ChangeLog:

* acinclude.m4: Replace AC_TRY_LINK with AC_LINK_IFELSE.  Replace
AC_TRY_COMPILE with AC_COMPILE_IFELSE.  Replace AC_HELP_STRING with
AS_HELP_STRING.  Replace AC_TRY_RUN with AC_RUN_IFELSE.
* configure: Regenerate.
* configure.ac: Replace AM_PROG_LIBTOOL with LT_INIT.  Replace
AC_STDC_HEADERS with AC_HEADER_STDC.  Replace _AC_COMPUTE_INT with
AC_COMPUTE_INT.

libgrust/ChangeLog:

Re: [PATCH] configury: replace autoconf obsolete macros [PR/103459]

2025-07-01 Thread Pietro Monteiro
On Fri, Jun 13, 2025, at 5:01 PM, Joseph Myers wrote:
> On Fri, 13 Jun 2025, Pietro Monteiro wrote:
>
>> > Adding this \ at end of file looks suspect.
>> >
>> > OK with that ChangeLog entry fixed and the stray \ at end of file removed 
>> > (assuming the same output files are still generated after that change).
>> 
>> I applied the patch on top of trunk (), removed the stray '\' from 
>> config/asmcfi.m4. Regenerating all autoconf/automake files showed no 
>> difference from the patch.
>> 
>> Should I send a v2 with the correction or can  a maintainer fix it before 
>> committing?
>
> My expectation when approving a patch with fixes is that the submitter 
> makes the fixes, retests as necessary and commits the fixed patch.

I'm sorry I didn't reply earlier. A change has been committed to one of the 
configure.ac files so I'll send a v2. As for committing it I'm afraid I'm don't 
have write access to the the git repository.

> Joseph S. Myers
> josmy...@redhat.com

thanks,
Pietro


[PATCH] libstdc++: Members missing in std::numeric_limits

2025-07-01 Thread Mateusz Zych
Hello libstdc++ Team!

I have recently found a bug in libstdc++, that is,
the std::numeric_limits<> template specializations for integer-class types
are missing some of static data members,
which results in compilation errors of valid C++ code:

   - Compiler Explorer: https://godbolt.org/z/E7z4WYfj4

Since adding missing member constants, which are the most relevant to
integer-like types,
was not a lot of code, I have prepared a Git patch with relevant changes.

I hope this patch is useful, Mateusz Zych
From 1e83287bbd6adf6ad8f483bd2f891692e0bed0c7 Mon Sep 17 00:00:00 2001
From: Mateusz Zych 
Date: Wed, 2 Jul 2025 01:51:40 +0300
Subject: [PATCH] libstdc++: Added missing member constants to numeric_limits
 specializations for integer-class types.

25.3.4.4 Concept weakly_incrementable  [iterator.concept.winc]

  (5) For every integer-class type I,
  let B(I) be a unique hypothetical extended integer type
  of the same signedness with the same width as I.

  [Note 2: The corresponding
   hypothetical specialization numeric_limits
   meets the requirements on
   numeric_limits specializations for integral types.]

 (11) For every (possibly cv-qualified) integer-class type I,
  numeric_limits is specialized such that:

  - each static data member m
has the same value as numeric_limits::m, and

  - each static member function f
returns I(numeric_limits::f()).

libstdc++-v3/ChangeLog:

	* include/bits/max_size_type.h
	(numeric_limits<__max_size_type>): New static data members.
	(numeric_limits<__max_diff_type>): Likewise.
---
 libstdc++-v3/include/bits/max_size_type.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libstdc++-v3/include/bits/max_size_type.h b/libstdc++-v3/include/bits/max_size_type.h
index 73a6d141d5b..bc7700506a2 100644
--- a/libstdc++-v3/include/bits/max_size_type.h
+++ b/libstdc++-v3/include/bits/max_size_type.h
@@ -775,6 +775,9 @@ namespace ranges
   static constexpr bool is_signed = false;
   static constexpr bool is_integer = true;
   static constexpr bool is_exact = true;
+  static constexpr bool is_bounded = true;
+  static constexpr bool is_modulo = true;
+  static constexpr bool radix = 2;
   static constexpr int digits
 	= __gnu_cxx::__int_traits<_Sp::__rep>::__digits + 1;
   static constexpr int digits10
@@ -802,6 +805,9 @@ namespace ranges
   static constexpr bool is_signed = true;
   static constexpr bool is_integer = true;
   static constexpr bool is_exact = true;
+  static constexpr bool is_bounded = true;
+  static constexpr bool is_modulo = false;
+  static constexpr bool radix = 2;
   static constexpr int digits = numeric_limits<_Sp>::digits - 1;
   static constexpr int digits10
 	= static_cast(digits * numbers::ln2 / numbers::ln10);
-- 
2.48.1



Re: [PATCH V1] RISC-V:Add the MIPS P8700 conditional move extension instruction support.

2025-07-01 Thread Umesh Kalappa
>>Look in contrib/  I think his work is still in there.
thank you @Jeff Law   ,the  check_GNU_style.sh was
helpful to fix the indent/spaces issues :

~U

On Tue, Jul 1, 2025 at 4:03 AM Jeff Law  wrote:

>
>
> On 6/30/25 12:04 AM, Umesh Kalappa wrote:
> > Thank you @Jeff Law   for the comments and
> >
> >  >>I suspect there's something goofy in the indentation in the block
> above.
> >   like clang-format ,does gcc have a code formatter we can use ?
> Not really.  Martin Liska (IIRC, and no longer working on GCC) made a
> valiant attempt to produce a clang-format configuration file for gcc
> sources.  But I don't know it's state.  35+ years of working on GCC and
> it's formatting is just how I write code these days :-0
>
> Look in contrib/  I think his work is still in there.
>
> Jeff
>
>
>


[PATCH] c++, v4: Fix up cp_build_array_ref COND_EXPR handling [PR120471]

2025-07-01 Thread Jakub Jelinek
On Mon, Jun 30, 2025 at 04:56:47PM -0400, Jason Merrill wrote:
> On 6/30/25 4:24 PM, Jakub Jelinek wrote:
> > On Mon, Jun 30, 2025 at 03:55:46PM -0400, Jason Merrill wrote:
> > > Might go with my earlier !TREE_SIDE_EFFECTS && tree_invariant_p 
> > > suggestion?
> > 
> > If you mean the following, it passes the 2 testcases and I can surely
> > bootstrap/regtest it tonight.
> 
> Yes, that's what I meant, but did you also see my other two comments in the
> body of the patch?

Sorry for missing those.

Here is an updated patch with address_invariant_p function and doing
ARRAY_TYPE and POINTER_TYPE_P checks just once on TREE_TYPE (array).
Compared to what tree_invariant_p_1 was doing before, had to add
STRIP_ANY_LOCATION_WRAPPER (t); before the return line.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2025-07-01  Jakub Jelinek  

PR c++/120471
gcc/
* tree.h (address_invariant_p): New function.
* tree.cc (address_invariant_p): New function.
(tree_invariant_p_1): Use it for ADDR_EXPR handling.  Formatting
tweak.
gcc/cp/
* typeck.cc (cp_build_array_ref) : If idx is not
INTEGER_CST, don't optimize the case (but cp_default_conversion on
array early if it has ARRAY_TYPE) or use
SAVE_EXPR , SAVE_EXPR , SAVE_EXPR  as new op0 depending
on flag_strong_eval_order and whether op1 and op2 are arrays with
invariant address or tree invariant pointers.  Formatting fixes.
gcc/testsuite/
* g++.dg/ubsan/pr120471.C: New test.
* g++.dg/parse/pr120471.C: New test.

--- gcc/tree.h.jj   2025-06-27 19:00:14.288493687 +0200
+++ gcc/tree.h  2025-06-30 23:05:01.647732780 +0200
@@ -5347,6 +5347,10 @@ extern tree staticp (tree);
 
 extern tree save_expr (tree);
 
+/* Return true if T is an object with invariant address.  */
+
+extern bool address_invariant_p (tree);
+
 /* Return true if T is function-invariant.  */
 
 extern bool tree_invariant_p (tree);
--- gcc/tree.cc.jj  2025-06-27 19:00:14.287493699 +0200
+++ gcc/tree.cc 2025-06-30 23:07:46.499662441 +0200
@@ -4015,6 +4015,38 @@ decl_address_ip_invariant_p (const_tree
   return false;
 }
 
+/* Return true if T is an object with invariant address.  */
+
+bool
+address_invariant_p (tree t)
+{
+  while (handled_component_p (t))
+{
+  switch (TREE_CODE (t))
+   {
+   case ARRAY_REF:
+   case ARRAY_RANGE_REF:
+ if (!tree_invariant_p (TREE_OPERAND (t, 1))
+ || TREE_OPERAND (t, 2) != NULL_TREE
+ || TREE_OPERAND (t, 3) != NULL_TREE)
+   return false;
+ break;
+
+   case COMPONENT_REF:
+ if (TREE_OPERAND (t, 2) != NULL_TREE)
+   return false;
+ break;
+
+   default:
+ break;
+   }
+  t = TREE_OPERAND (t, 0);
+}
+
+  STRIP_ANY_LOCATION_WRAPPER (t);
+  return CONSTANT_CLASS_P (t) || decl_address_invariant_p (t);
+}
+
 
 /* Return true if T is function-invariant (internal function, does
not handle arithmetic; that's handled in skip_simple_arithmetic and
@@ -4023,10 +4055,7 @@ decl_address_ip_invariant_p (const_tree
 static bool
 tree_invariant_p_1 (tree t)
 {
-  tree op;
-
-  if (TREE_CONSTANT (t)
-  || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
+  if (TREE_CONSTANT (t) || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
 return true;
 
   switch (TREE_CODE (t))
@@ -4036,30 +4065,7 @@ tree_invariant_p_1 (tree t)
   return true;
 
 case ADDR_EXPR:
-  op = TREE_OPERAND (t, 0);
-  while (handled_component_p (op))
-   {
- switch (TREE_CODE (op))
-   {
-   case ARRAY_REF:
-   case ARRAY_RANGE_REF:
- if (!tree_invariant_p (TREE_OPERAND (op, 1))
- || TREE_OPERAND (op, 2) != NULL_TREE
- || TREE_OPERAND (op, 3) != NULL_TREE)
-   return false;
- break;
-
-   case COMPONENT_REF:
- if (TREE_OPERAND (op, 2) != NULL_TREE)
-   return false;
- break;
-
-   default:;
-   }
- op = TREE_OPERAND (op, 0);
-   }
-
-  return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
+  return address_invariant_p (TREE_OPERAND (t, 0));
 
 default:
   break;
--- gcc/cp/typeck.cc.jj 2025-06-30 22:30:59.513417507 +0200
+++ gcc/cp/typeck.cc2025-06-30 23:13:27.497379696 +0200
@@ -4001,13 +4001,61 @@ cp_build_array_ref (location_t loc, tree
   }
 
 case COND_EXPR:
-  ret = build_conditional_expr
-  (loc, TREE_OPERAND (array, 0),
-  cp_build_array_ref (loc, TREE_OPERAND (array, 1), idx,
-  complain),
-  cp_build_array_ref (loc, TREE_OPERAND (array, 2), idx,
-  complain),
-  complain);
+  tree op0, op1, op2;
+  op0 = TREE_OPERAND (array, 0);
+  op1 = TREE_OPERAND (array, 1);
+  op2 = TREE_OPERAND (array, 1);
+  if (T

Re: [PATCH 1/2] allow contraction to synthetic single-element vector FMA

2025-07-01 Thread Richard Biener
On Mon, Jun 30, 2025 at 7:05 PM Alexander Monakov  wrote:
>
>
> On Mon, 30 Jun 2025, Richard Biener wrote:
>
> > > * gcc.target/i386/pr116979.c
> > >
> > > Here we check that FMA is used for complex multiplication. This is a case
> > > where use of FMA is detrimental for accuracy, but I guess we can choose
> > > to preserve the status quo. I can look into teaching
> > > expand_complex_multiplication to emit FMAs.
> >
> > Yeah, I guess that's within -ffp-contract=on constraints.  When you say it's
> > detrimental for accuracy, is that a general statement for complex multiply
> > lowering?  If so we possibly do not want FMAs?
>
> We may want FMAs when completely disregarding accuracy for speed 
> (-ffast-math),
> but otherwise, yes, I meant that in general our strategy is not good. We are
> lowering complex multiplication by components
>
>   (x + yi)*(z + wi) = (x*z - y*w) + (x*w + y*z)i
>
> and when FMA is available, we end up with something like
>
>   fma(x, z, -y*w)
>
> for the real part and likewise fma(x, w, y*z) for the imaginary part, which is
> asymmetrical with respect to operands, and, for instance, yields wrong results
> for conjugate vectors: take z=x and w=-y, then imaginary part fma(x, w, y*z) 
> is
> fma(x, -y, y*x), which is negated round-off tail of y*x, but should be zero.
>
> FMA is useful for improving accuracy of sum/difference of two products, where
> you'd compute x*w + y*z as
>
>   xw = x*w
>   xw_tail = fma(x, w, -xw)
>   tmp = fma(y, z, xw)
>   return tmp + xw_tail
>
> but apart from this, I'd say we don't want to emit FMAs in
> expand_complex_multiplication. LLVM seems to produce FMAs for complex product
> only under -ffp-contract=fast.
>
> What are the next steps here, then?

For this case I would then suggest to not change complex lowering to emit
FMAs and adjust the testcases to pass -ffp-contract=fast instead, possibly
even add a testcase variant with -ffp-contract=on checking FMAs are not
used with a rationale present in a comment.

Richard.

>
> Thank you.
> Alexander


[COMMITTED 29/42] ada: Add "continue" GNAT extension

2025-07-01 Thread Marc Poulhiès
From: Ronan Desplanques 

This extension adds "continue" as a nonreserved keyword, and this is the
first occurrence of a nonreserved keyword in GNAT, which causes this
patch to add unusual overload resolution code.

New node kinds are introduced, but since they are entirely transformed
into existing constructs during expansion, back ends that don't turn off
expansion do not need to be updated.

gcc/ada/ChangeLog:

* doc/gnat_rm/gnat_language_extensions.rst: Document new extension.
* gen_il-fields.ads (Opt_Field_Enum): Add new fields.
* gen_il-types.ads (N_Loop_Flow_Statement, N_Continue_Statement): New
node kinds.
* gen_il-gen-gen_nodes.adb (N_Loop_Flow_Statement): New abstract node
kind.
(N_Continue_Statement): New node kind.
(N_Exit_Statement): Reparent below N_Loop_Flow_Statement.
* sinfo.ads (N_Continue_Statement): Add description.
* sinfo-utils.ads (Loop_Flow_Keyword): New function.
* sinfo-utils.adb (Loop_Flow_Keyword): New function.
* gen_il-gen-gen_entities.adb (E_Loop): Add new field.
* einfo.ads (Continue_Mark): Document new field.
* sprint.adb (Sprint_Node_Actual): Update for new node kind.
* snames.ads-tmpl: Add new keyword.
* par-ch5.adb (P_Continue_Statement, Parse_Loop_Flow_Statement): New
functions.
(P_Sequence_Of_Statements): Handle continue statements.
(P_Exit_Statement): Use Parse_Loop_Flow_Statement.
* sem.adb (Analyze): Handle new node kind.
* sem_ch5.adb (Analyze_Loop_Flow_Statement): New function.
(Analyze_Continue_Statement): New procedure.
(Analyze_Exit_Statement): Use new Analyze_Loop_Flow_Statement function.
* sem_ch5.ads (Analyze_Continue_Statement): New procedure.
* expander.adb (Expand): Handle new node kind.
* exp_ch5.ads (Expand_N_Continue_Statement): New procedure.
* exp_ch5.adb (Expand_Loop_Flow_Statement): New procedure.
(Expand_N_Continue_Statement): New procedure.
(Expand_N_Exit_Statement): Use new Expand_Loop_Flow_Statement
procedure.
(Build_Formal_Container_Iteration): Always reuse original loop entity.
* gnat_rm.texi: Regenerate.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 .../doc/gnat_rm/gnat_language_extensions.rst  |  16 +
 gcc/ada/einfo.ads |   8 +
 gcc/ada/exp_ch5.adb   | 117 ++-
 gcc/ada/exp_ch5.ads   |   1 +
 gcc/ada/expander.adb  |   3 +
 gcc/ada/gen_il-fields.ads |   2 +
 gcc/ada/gen_il-gen-gen_entities.adb   |   3 +-
 gcc/ada/gen_il-gen-gen_nodes.adb  |  15 +-
 gcc/ada/gen_il-types.ads  |   2 +
 gcc/ada/gnat_rm.texi  |  84 +++--
 gcc/ada/par-ch5.adb   | 105 --
 gcc/ada/sem.adb   |   3 +
 gcc/ada/sem_ch5.adb   | 322 +-
 gcc/ada/sem_ch5.ads   |   1 +
 gcc/ada/sinfo-utils.adb   |  13 +
 gcc/ada/sinfo-utils.ads   |   4 +
 gcc/ada/sinfo.ads |  26 ++
 gcc/ada/snames.ads-tmpl   |   1 +
 gcc/ada/sprint.adb|   4 +-
 19 files changed, 551 insertions(+), 179 deletions(-)

diff --git a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst 
b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
index bdc4e675488..f31317942c2 100644
--- a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
+++ b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
@@ -1777,3 +1777,19 @@ If an exception is raised in the finally part, it cannot 
be caught by the ``exce
 Abort/ATC (asynchronous transfer of control) cannot interrupt a finally block, 
nor prevent its
 execution, that is the finally block must be executed in full even if the 
containing task is
 aborted, or if the control is transferred out of the block.
+
+Continue statement
+--
+
+The ``continue`` keyword makes it possible to stop execution of a loop 
iteration
+and continue with the next one. A continue statement has the same syntax
+(except "exit" is replaced with "continue"), static semantics, and legality
+rules as an exit statement. The difference is in the dynamic semantics: where 
an
+exit statement would cause a transfer of control that completes the (implicitly
+or explicitly) specified loop_statement, a continue statement would instead
+cause a transfer of control that completes only the current iteration of that
+loop_statement, like a goto statement targeting a label following the last
+statement in the sequence of statements of the specified loop_statement.
+
+Note that ``continue`` is a keyword but it is not a reserved word. This is a
+configuration that does not exist in standard Ada.
diff --git a/gcc/ada/einfo.ads b/gcc/ada/ein

[COMMITTED 31/42] ada: Add GNAT LLVM selection in GPR project file.

2025-07-01 Thread Marc Poulhiès
From: Artur Pietrek 

gcc/ada/ChangeLog:

* doc/gnat_ugn/building_executable_programs_with_gnat.rst: add
GNAT LLVM explicit selection in GPR file
* gnat_ugn.texi: Regenerate.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 .../doc/gnat_ugn/building_executable_programs_with_gnat.rst| 3 +++
 gcc/ada/gnat_ugn.texi  | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst 
b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
index b99eba7537c..fdf19481a6f 100644
--- a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
+++ b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
@@ -8128,6 +8128,9 @@ We provide two options that you can use to build code 
with GNAT LLVM:
   which version of GNAT built that file because it contains either
   :code:`GNAT` or :code:`GNAT-LLVM`.
 
+  You can also explicitly select GNAT LLVM in your existing GPR project
+  file by adding :code:`for Toolchain_Name("Ada") use "GNAT_LLVM";`
+
 .. only:: PRO
 
 If your project uses one of the libraries packaged with the GCC
diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi
index c706d8b555f..6cd0bed8d67 100644
--- a/gcc/ada/gnat_ugn.texi
+++ b/gcc/ada/gnat_ugn.texi
@@ -17664,6 +17664,9 @@ file with @code{gprconfig} and using it with 
@code{gprbuild}; see the
 can determine from the first line of the @code{.ali} file
 which version of GNAT built that file because it contains either
 @code{GNAT} or @code{GNAT-LLVM}.
+
+You can also explicitly select GNAT LLVM in your existing GPR project
+file by adding @code{for Toolchain_Name("Ada") use "GNAT_LLVM";}
 @end itemize
 
 
-- 
2.43.0



Re: [Fortran, Patch, PR120843, v2] Fix reject valid, because of inconformable coranks

2025-07-01 Thread Andre Vehreschild
Hi Harald,

thanks for the review. Committed as gcc-16-1885-g1b0930e9046.

Will backport to gcc-15 in about a week.

Thanks again.

Regards,
Andre

On Mon, 30 Jun 2025 22:31:08 +0200
Harald Anlauf  wrote:

> Am 30.06.25 um 15:25 schrieb Andre Vehreschild:
> > Hi all,
> > 
> > here now the version of the patch that seems to be more complete.
> > 
> > Regtests ok on x86_64-pc-linux-gnu / F41. Ok for mainline and later
> > backport to gcc-15?  
> 
> This looks good to me.  OK for both.
> 
> Thanks for the patch!
> 
> Harald
> 
> > Regards,
> > Andre
> > 
> > On Fri, 27 Jun 2025 15:44:20 +0200
> > Andre Vehreschild  wrote:
> >   
> >> I take this patch back. It seems to be incomplete.
> >>
> >> - Andre
> >>
> >> On Fri, 27 Jun 2025 14:45:36 +0200
> >> Andre Vehreschild  wrote:
> >>  
> >>> Hi all,
> >>>
> >>> this patch fixes a reject valid when the coranks of two operands do not
> >>> match and no coindex is given. I.e. when only an implicit this_image
> >>> co-ref is used.
> >>>
> >>> Regtests ok on x86_64-pc-linux-gnu / F41. Ok for mainline?
> >>>
> >>> Regards,
> >>>   Andre  
> >>
> >>  
> > 
> >   
> 


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 


Re: [PATCH v7 2/9] AArch64: reformat branch instruction rules

2025-07-01 Thread Richard Sandiford
Karl Meakin  writes:
> @@ -729,30 +729,31 @@ (define_expand "cbranch4"
>   (match_operator 0 "aarch64_comparison_operator"
>[(match_operand:GPF_F16 1 "register_operand")
> (match_operand:GPF_F16 2 "aarch64_fp_compare_operand")])
> - (label_ref (match_operand 3 "" ""))
> + (label_ref (match_operand 3))
>   (pc)))]
>""
> -  "
> +  {
>operands[1] = aarch64_gen_compare_reg (GET_CODE (operands[0]), operands[1],
>operands[2]);
>operands[2] = const0_rtx;
> -  "
> +  }
>  )

I was going to make this change locally before pushing, since it's
so trivial, but: could you indent the code between the braces by two
extra spaces while you're there?  The current indentation seems
"more wrong" with braces than quotes.

Thanks,
Richard


[COMMITTED 35/42] ada: Warn on untagged record type equality

2025-07-01 Thread Marc Poulhiès
From: Javier Miranda 

The frontend reports a warning when no component of an untagged
record type U is a record type, and the type C of some of its
components has defined its user-defined equality operator "=".

The warning is reported because it may be surprising that, following
RM 4.5.2 (24/3), the predefined "=" of the component type C takes
precedence over its user-defined "=" when objects of the record
type R are compared.

gcc/ada/ChangeLog:

* exp_ch3.adb (Build_Untagged_Record_Equality): Report the
warning when no component of an untagged record type U is a
record type, and the type C of some of its components has
defined its user-defined equality operator "=".
* exp_ch4.adb (Expand_Composite_Equality): Report the warning
calling Warn_On_Ignored_Equality_Operator.
* sem_warn.ads (Warn_On_Ignored_Equality_Operator): New subprogram.
* sem_warn.adb (Warn_On_Ignored_Equality_Operator): Factorize code
reporting the warning.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch3.adb  | 28 
 gcc/ada/exp_ch4.adb  | 15 +++
 gcc/ada/sem_warn.adb | 18 ++
 gcc/ada/sem_warn.ads |  9 +
 4 files changed, 62 insertions(+), 8 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index bdadac6cc13..4e2bef32a35 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -69,6 +69,7 @@ with Sem_Res;use Sem_Res;
 with Sem_SCIL;   use Sem_SCIL;
 with Sem_Type;   use Sem_Type;
 with Sem_Util;   use Sem_Util;
+with Sem_Warn;   use Sem_Warn;
 with Sinfo;  use Sinfo;
 with Sinfo.Nodes;use Sinfo.Nodes;
 with Sinfo.Utils;use Sinfo.Utils;
@@ -77,6 +78,7 @@ with Snames; use Snames;
 with Tbuild; use Tbuild;
 with Ttypes; use Ttypes;
 with Validsw;use Validsw;
+with Warnsw; use Warnsw;
 
 package body Exp_Ch3 is
 
@@ -5157,6 +5159,32 @@ package body Exp_Ch3 is
  if Is_Library_Level_Entity (Typ) then
 Set_Is_Public (Op);
  end if;
+
+  --  Otherwise, the result is defined in terms of the primitive equals
+  --  operator (RM 4.5.2 (24/3)). Report a warning if some component of
+  --  the untagged record has defined a user-defined "=", because it can
+  --  be surprising that the predefined "=" takes precedence over it.
+  --  This warning is not reported when Build_Eq is True because the
+  --  expansion of the built body will call Expand_Composite_Equality
+  --  that will report it if necessary.
+
+  elsif Warn_On_Ignored_Equality then
+ Comp := First_Component (Typ);
+
+ while Present (Comp) loop
+if Present (User_Defined_Eq (Etype (Comp)))
+  and then not Is_Record_Type (Etype (Comp))
+  and then not Is_Intrinsic_Subprogram
+ (User_Defined_Eq (Etype (Comp)))
+then
+   Warn_On_Ignored_Equality_Operator
+ (Typ  => Typ,
+  Comp_Typ => Etype (Comp),
+  Loc  => Sloc (User_Defined_Eq (Etype (Comp;
+end if;
+
+Next_Component (Comp);
+ end loop;
   end if;
end Build_Untagged_Record_Equality;
 
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index ce90f33aeda..c9040bf5ba0 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -2470,21 +2470,20 @@ package body Exp_Ch4 is
 
  declare
 Op : constant Entity_Id := Find_Primitive_Eq (Comp_Type);
+
  begin
-if Warn_On_Ignored_Equality
-  and then Present (Op)
+if Present (Op)
   and then not In_Predefined_Unit (Base_Type (Comp_Type))
   and then not Is_Intrinsic_Subprogram (Op)
 then
pragma Assert
  (Is_First_Subtype (Outer_Type)
or else Is_Generic_Actual_Type (Outer_Type));
-   Error_Msg_Node_2 := Comp_Type;
-   Error_Msg_N
- ("?_q?""="" for type & uses predefined ""="" for }",
-  Outer_Type);
-   Error_Msg_Sloc := Sloc (Op);
-   Error_Msg_N ("\?_q?""="" # is ignored here", Outer_Type);
+
+   Warn_On_Ignored_Equality_Operator
+ (Typ  => Outer_Type,
+  Comp_Typ => Comp_Type,
+  Loc  => Sloc (Op));
 end if;
  end;
 
diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 32eee3370e2..156afc92307 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -3464,6 +3464,24 @@ package body Sem_Warn is
   end if;
end Warn_On_Constant_Valid_Condition;
 
+   ---
+   -- Warn_On_Ignored_Equality_Operator --
+   ---
+
+   procedure Warn_On_Ignored_Equality_Operator
+ (Typ  

[COMMITTED 38/42] ada: Fix couple of issues in System.Value_D.Integer_To_Decimal function

2025-07-01 Thread Marc Poulhiès
From: Eric Botcazou 

The first issue is that the function would wrongly raise Constraint_Error
on the edge case where Val = 2**(Int'Size - 1) and Minus is not set.

The second issue is that the function takes a long time to deal with huge
negative exponents.

The change also contains minor consistency fixes for its counterpart that
is present in System.Value_F, namely Integer_To_Fixed.

gcc/ada/ChangeLog:

* libgnat/s-valued.adb (Integer_To_Decimal): Deal specifically with
Val = 2**(Int'Size - 1) if Minus is not set.  Exit the loops when V
saturates to 0 in the case of (huge) negative exponents.  Use Base
instead of B consistently in unsigned computations.
* libgnat/s-valuef.adb (Integer_To_Fixed): Use Base instead of B
consistently in unsigned computations.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/s-valued.adb | 42 +++-
 gcc/ada/libgnat/s-valuef.adb | 12 +--
 2 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/gcc/ada/libgnat/s-valued.adb b/gcc/ada/libgnat/s-valued.adb
index 57d5c04ab10..4f2e1020466 100644
--- a/gcc/ada/libgnat/s-valued.adb
+++ b/gcc/ada/libgnat/s-valued.adb
@@ -131,27 +131,39 @@ package body System.Value_D is
 
   --  Local variables
 
-  E : Uns := Uns (Extra2 / Base);
+  V : Uns  := Val;
+  S : Integer  := ScaleB;
+  E : Unsigned := Extra2 / Base;
 
begin
+  --  The implementation of Value_R uses fully symmetric arithmetics
+  --  but here we cannot handle 2**(Int'Size - 1) if Minus is not set.
+
+  if V = 2**(Int'Size - 1) and then not Minus then
+ E := Unsigned (V rem Uns (Base));
+ V := V / Uns (Base);
+ S := S + 1;
+  end if;
+
   --  If the base of the value is 10 or its scaling factor is zero, then
   --  add the scales (they are defined in the opposite sense) and apply
   --  the result to the value, checking for overflow in the process.
 
-  if Base = 10 or else ScaleB = 0 then
- declare
-S : Integer := ScaleB + Scale;
-V : Uns := Val;
-
+  if Base = 10 or else S = 0 then
  begin
+S := S + Scale;
+
 while S < 0 loop
+   if V = 0 then
+  exit;
+   end if;
V := V / 10;
S := S + 1;
 end loop;
 
 while S > 0 loop
-   if V <= (Uns'Last - E) / 10 then
-  V := V * 10 + E;
+   if V <= (Uns'Last - Uns (E)) / 10 then
+  V := V * 10 + Uns (E);
   S := S - 1;
   E := 0;
else
@@ -167,10 +179,7 @@ package body System.Value_D is
 
   else
  declare
-B : constant Int := Int (Base);
-S : constant Integer := ScaleB;
-
-V : Uns := Val;
+B : constant Int := Int (Base);
 
 Y, Z, Q, R : Int;
 
@@ -186,7 +195,10 @@ package body System.Value_D is
   Z := Safe_Expont (B, LS, 10 ** Integer'Max (0, -Scale));
 
   for J in 1 .. LS loop
- V := V / Uns (B);
+ if V = 0 then
+exit;
+ end if;
+ V := V / Uns (Base);
   end loop;
end;
 
@@ -201,8 +213,8 @@ package body System.Value_D is
   Z := 10 ** Integer'Max (0, -Scale);
 
   for J in 1 .. LS loop
- if V <= (Uns'Last - E) / Uns (B) then
-V := V * Uns (B) + E;
+ if V <= (Uns'Last - Uns (E)) / Uns (Base) then
+V := V * Uns (Base) + Uns (E);
 E := 0;
  else
 Bad_Value (Str);
diff --git a/gcc/ada/libgnat/s-valuef.adb b/gcc/ada/libgnat/s-valuef.adb
index 03821aa4c1f..6ea22117432 100644
--- a/gcc/ada/libgnat/s-valuef.adb
+++ b/gcc/ada/libgnat/s-valuef.adb
@@ -236,8 +236,8 @@ package body System.Value_F is
   --  but here we cannot handle 2**(Int'Size - 1) if Minus is not set.
 
   if V = 2**(Int'Size - 1) and then not Minus then
- E := Unsigned (V rem Uns (B)) * Base + E / Base;
- V := V / Uns (B);
+ E := Unsigned (V rem Uns (Base)) * Base + E / Base;
+ V := V / Uns (Base);
  S := S + 1;
   end if;
 
@@ -261,8 +261,8 @@ package body System.Value_F is
   E := 0;
   exit;
end if;
-   E := Unsigned (V rem Uns (B)) * Base + E / Base;
-   V := V / Uns (B);
+   E := Unsigned (V rem Uns (Base)) * Base + E / Base;
+   V := V / Uns (Base);
 end loop;
  end;
 
@@ -277,8 +277,8 @@ package body System.Value_F is
 Z := Num;
 
 for J in 1 .. LS loop
-   if V <= (Uns'Last 

[COMMITTED 03/42] ada: Remove wrong optimization in frontend inlining of procedure calls

2025-07-01 Thread Marc Poulhiès
From: Piotr Trojanek 

When using obsolete frontend inlining (switch -gnatN), we must always rewrite
the procedure call into a single block node. Otherwise, the copy-back of
parameters passed by-copy is inserted before the inlined procedure body, which
causes wrong code to be generated.

gcc/ada/ChangeLog:

* inline.adb (Rewrite_Procedure_Call): Replace with a simple rewriting
of procedure call into a single block node, i.e. remove broken
optimization.
* sem_util.adb (Next_Actual): Adapt GNATprove-specific code that peeks
into inlined calls.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/inline.adb   | 35 +--
 gcc/ada/sem_util.adb |  2 +-
 2 files changed, 2 insertions(+), 35 deletions(-)

diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb
index 72b998961be..e8eeebd2d00 100644
--- a/gcc/ada/inline.adb
+++ b/gcc/ada/inline.adb
@@ -3397,10 +3397,6 @@ package body Inline is
   --  If the function body is a single expression, replace call with
   --  expression, else insert block appropriately.
 
-  procedure Rewrite_Procedure_Call (N : Node_Id; Blk : Node_Id);
-  --  If procedure body has no local variables, inline body without
-  --  creating block, otherwise rewrite call with block.
-
   -
   -- Make_Exit_Label --
   -
@@ -3785,35 +3781,6 @@ package body Inline is
  end if;
   end Rewrite_Function_Call;
 
-  
-  -- Rewrite_Procedure_Call --
-  
-
-  procedure Rewrite_Procedure_Call (N : Node_Id; Blk : Node_Id) is
- HSS : constant Node_Id := Handled_Statement_Sequence (Blk);
-
-  begin
- --  If there is a transient scope for N, this will be the scope of the
- --  actions for N, and the statements in Blk need to be within this
- --  scope. For example, they need to have visibility on the constant
- --  declarations created for the formals.
-
- --  If N needs no transient scope, and if there are no declarations in
- --  the inlined body, we can do a little optimization and insert the
- --  statements for the body directly after N, and rewrite N to a
- --  null statement, instead of rewriting N into a full-blown block
- --  statement.
-
- if not Scope_Is_Transient
-   and then Is_Empty_List (Declarations (Blk))
- then
-Insert_List_After (N, Statements (HSS));
-Rewrite (N, Make_Null_Statement (Loc));
- else
-Rewrite (N, Blk);
- end if;
-  end Rewrite_Procedure_Call;
-
--  Start of processing for Expand_Inlined_Call
 
begin
@@ -4273,7 +4240,7 @@ package body Inline is
   end;
 
   if Ekind (Subp) = E_Procedure then
- Rewrite_Procedure_Call (N, Blk);
+ Rewrite (N, Blk);
 
   else
  Rewrite_Function_Call (N, Blk);
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index af7e48b1eca..4e3c6255e31 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -25019,7 +25019,7 @@ package body Sem_Util is
 --  In case of a call rewritten in GNATprove mode while "inlining
 --  for proof" go to the original call.
 
-elsif Nkind (Par) = N_Null_Statement then
+elsif Nkind (Par) in N_Null_Statement | N_Block_Statement then
pragma Assert
  (GNATprove_Mode
 and then
-- 
2.43.0



Re: [PATCH] gcc: middle-end opt for trigonometric pi-based functions builtins

2025-07-01 Thread Jakub Jelinek
On Sat, Jun 28, 2025 at 02:19:59AM +, Yuao Ma wrote:
> > signbit is documented to be a macro, so please don't declare
> > int signbit (double);
> > function in the testcase and instead of signbit use __builtin_signbit.
> 
> This is indeed my negligence. Done.
> 
> If everything looks good, could you please help me merge this patch? Thank 
> you!

Committed in r16-1839.

I don't have mpfr 4.2.0 yet, so didn't test myself with it.

Jakub



Re: [PATCH] Fix "void debug (const tree_node *ptr)"

2025-07-01 Thread Richard Biener
On Tue, Jul 1, 2025 at 2:23 AM H.J. Lu  wrote:
>
> Calling "debug (const tree_node *ptr)" does nothing.  Change it to
> call debug_tree so that we can do this in gdb:
>
> (gdb) whatis type
> type = const_tree
> (gdb) call debug (type)
>   size  bitsizety
> pe> constant 32>
> unit-size  size
> type> constant 4>
> align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 
> 0x7fffe982
> f2a0 precision:32
> pointer_to_this >
> (gdb)

OK.

> PR debug/120902
> * print-tree.cc (debug with const tree_node *): Call debug_tree
> instead of debug.
>
>
> --
> H.J.


Re: [PATCH] aarch64: Sync `aarch64-sys-regs.def' with Binutils.

2025-07-01 Thread Kyrylo Tkachov


> On 17 Jun 2025, at 12:19, Kyrylo Tkachov  wrote:
> 
> 
> 
>> On 4 Apr 2025, at 20:28, ezra.sito...@arm.com wrote:
>> 
>> From: Ezra Sitorus 
>> 
>> This patch updates `aarch64-sys-regs.def', bringing it into sync with
>> the Binutils source after this change:
>> https://sourceware.org/pipermail/binutils/2025-March/139894.html
> 
> Ok. I think these changes are considered obvious.
> Do you need someone to push the patch for you?
> 

I’ve pushed this patch to trunk after a bootstrap on aarch64-linux.
Thanks,
Kyrill

> Thanks,
> Kyrill
> 
>> 
>> gcc/ChangeLog:
>> * config/aarch64/aarch64-sys-regs.def: Copy from Binutils.
>> ---
>> Tested on aarch64-none-linux-gnu
>> 
>> gcc/config/aarch64/aarch64-sys-regs.def | 16 
>> 1 file changed, 8 insertions(+), 8 deletions(-)
>> 
>> diff --git a/gcc/config/aarch64/aarch64-sys-regs.def 
>> b/gcc/config/aarch64/aarch64-sys-regs.def
>> index 8b65673a5d6..dbfe3adf996 100644
>> --- a/gcc/config/aarch64/aarch64-sys-regs.def
>> +++ b/gcc/config/aarch64/aarch64-sys-regs.def
>> @@ -572,12 +572,12 @@
>>  SYSREG ("mdrar_el1", CPENC (2,0,1,0,0), F_REG_READ, AARCH64_NO_FEATURES)
>>  SYSREG ("mdscr_el1", CPENC (2,0,0,2,2), 0, AARCH64_NO_FEATURES)
>>  SYSREG ("mdselr_el1", CPENC (2,0,0,4,2), F_ARCHEXT, AARCH64_FEATURE 
>> (DEBUGv8p9))
>> -  SYSREG ("mecid_a0_el2", CPENC (3,4,10,8,1), 0, AARCH64_NO_FEATURES)
>> -  SYSREG ("mecid_a1_el2", CPENC (3,4,10,8,3), 0, AARCH64_NO_FEATURES)
>> -  SYSREG ("mecid_p0_el2", CPENC (3,4,10,8,0), 0, AARCH64_NO_FEATURES)
>> -  SYSREG ("mecid_p1_el2", CPENC (3,4,10,8,2), 0, AARCH64_NO_FEATURES)
>> -  SYSREG ("mecid_rl_a_el3", CPENC (3,6,10,10,1), 0, AARCH64_NO_FEATURES)
>> -  SYSREG ("mecidr_el2", CPENC (3,4,10,8,7), F_REG_READ, AARCH64_NO_FEATURES)
>> +  SYSREG ("mecid_a0_el2", CPENC (3,4,10,8,1), F_ARCHEXT, AARCH64_FEATURE 
>> (V8_7A))
>> +  SYSREG ("mecid_a1_el2", CPENC (3,4,10,8,3), F_ARCHEXT, AARCH64_FEATURE 
>> (V8_7A))
>> +  SYSREG ("mecid_p0_el2", CPENC (3,4,10,8,0), F_ARCHEXT, AARCH64_FEATURE 
>> (V8_7A))
>> +  SYSREG ("mecid_p1_el2", CPENC (3,4,10,8,2), F_ARCHEXT, AARCH64_FEATURE 
>> (V8_7A))
>> +  SYSREG ("mecid_rl_a_el3", CPENC (3,6,10,10,1), F_ARCHEXT, AARCH64_FEATURE 
>> (V8_7A))
>> +  SYSREG ("mecidr_el2", CPENC (3,4,10,8,7), F_REG_READ|F_ARCHEXT, 
>> AARCH64_FEATURE (V8_7A))
>>  SYSREG ("mfar_el3", CPENC (3,6,6,0,5), 0, AARCH64_NO_FEATURES)
>>  SYSREG ("midr_el1", CPENC (3,0,0,0,0), F_REG_READ, AARCH64_NO_FEATURES)
>>  SYSREG ("mpam0_el1", CPENC (3,0,10,5,1), 0, AARCH64_NO_FEATURES)
>> @@ -1145,8 +1145,8 @@
>>  SYSREG ("vbar_el2", CPENC (3,4,12,0,0), 0, AARCH64_NO_FEATURES)
>>  SYSREG ("vbar_el3", CPENC (3,6,12,0,0), 0, AARCH64_NO_FEATURES)
>>  SYSREG ("vdisr_el2", CPENC (3,4,12,1,1), F_ARCHEXT, AARCH64_FEATURE (RAS))
>> -  SYSREG ("vmecid_a_el2", CPENC (3,4,10,9,1), 0, AARCH64_NO_FEATURES)
>> -  SYSREG ("vmecid_p_el2", CPENC (3,4,10,9,0), 0, AARCH64_NO_FEATURES)
>> +  SYSREG ("vmecid_a_el2", CPENC (3,4,10,9,1), F_ARCHEXT, AARCH64_FEATURE 
>> (V8_7A))
>> +  SYSREG ("vmecid_p_el2", CPENC (3,4,10,9,0), F_ARCHEXT, AARCH64_FEATURE 
>> (V8_7A))
>>  SYSREG ("vmpidr_el2", CPENC (3,4,0,0,5), 0, AARCH64_NO_FEATURES)
>>  SYSREG ("vncr_el2", CPENC (3,4,2,2,0), F_ARCHEXT, AARCH64_FEATURE (V8_4A))
>>  SYSREG ("vpidr_el2", CPENC (3,4,0,0,0), 0, AARCH64_NO_FEATURES)
>> -- 
>> 2.45.2
>> 
> 



Re: [PATCH] tailc: Handle musttail in case of non-cleaned-up cleanups, especially ASan related [PR120608]

2025-07-01 Thread Jakub Jelinek
On Tue, Jul 01, 2025 at 11:23:48AM +0200, Richard Biener wrote:
> > Given that empty_eh_cleanup handles already almost everything, just
> > didn't know how to handle the resx to internal step which was quite
> > trivial, I thought it will be easier not to reorder cleanup_eh pass,
> > especially for 15.2 backport and when I have no idea what went wrong
> > in the pr106190 testcase (the ICE is about not finding some region).
> 
> I see.  Fine with me then.  It's a bit of a whack-a-mole with musttail,
> esp. wrt sanitizers ...

It is :(.

Jakub



Re: [PATCH] tailc: Handle musttail in case of non-cleaned-up cleanups, especially ASan related [PR120608]

2025-07-01 Thread Richard Biener
On Tue, 1 Jul 2025, Jakub Jelinek wrote:

> On Tue, Jul 01, 2025 at 10:43:09AM +0200, Richard Biener wrote:
> > > The following patch fixes that by
> > > 1) moving the musttail pass 2 passes earlier (this is mostly just
> > >for -O0/-Og, for normal optimization levels musttail calls are
> > >handled in the tailc pass), i.e. across the sanopt and cleanup_eh
> > >passes
> > 
> > didn't we have other cases where cleanup_eh was required for musttail
> > to work?  So I think we want to have that before musttail?  We should
> > be able to swap sanopt and eh_cleanup?
> 
> I think we've discussed we want to try for GCC 16 cleanup_eh somewhere in
> the -O1+ optimization pass set, in between IPA and tailc (and I'll try to do
> that at some point during stage1).
> 
> I've actually tried
> --- gcc/passes.def2025-06-30 22:16:11.258688529 +0200
> +++ gcc/passes.def2025-07-01 10:47:37.020634803 +0200
> @@ -444,9 +444,9 @@ along with GCC; see the file COPYING3.
>NEXT_PASS (pass_lower_switch_O0);
>NEXT_PASS (pass_asan_O0);
>NEXT_PASS (pass_tsan_O0);
> -  NEXT_PASS (pass_sanopt);
>NEXT_PASS (pass_cleanup_eh);
>NEXT_PASS (pass_musttail);
> +  NEXT_PASS (pass_sanopt);
>NEXT_PASS (pass_lower_resx);
>NEXT_PASS (pass_nrv);
>NEXT_PASS (pass_gimple_isel);
> together with the non-empty_eh_cleanup tree-tailcall.cc changes from the
> patch, but that resulted in the following ICE:
> /home/jakub/src/gcc/gcc/testsuite/gcc.dg/asan/pr106190.c: In function 'main':
> /home/jakub/src/gcc/gcc/testsuite/gcc.dg/asan/pr106190.c:6:1: internal 
> compiler error: in expand_builtin_eh_common, at except.cc:2097
> 0x2dc62cf internal_error(char const*, ...)
> ../../gcc/diagnostic-global-context.cc:517
> 0xeaeced fancy_abort(char const*, int, char const*)
> ../../gcc/diagnostic.cc:1810
> 0x81940a expand_builtin_eh_common
> ../../gcc/except.cc:2097
> 0x11ad909 expand_builtin_eh_pointer(tree_node*)
> ../../gcc/except.cc:2108
> 0x11deac2 expand_expr_real_1(tree_node*, rtx_def*, machine_mode, 
> expand_modifier, rtx_def**, bool)
> ../../gcc/expr.cc:12535
> 0x11ecddd store_expr(tree_node*, rtx_def*, int, bool, bool)
> ../../gcc/expr.cc:6762
> 0x11efb28 expand_assignment(tree_node*, tree_node*, bool)
> ../../gcc/expr.cc:6483
> 0x11efb28 expand_assignment(tree_node*, tree_node*, bool)
> ../../gcc/expr.cc:5971
> 0x1093629 expand_call_stmt
> ../../gcc/cfgexpand.cc:3202
> 0x1093629 expand_gimple_stmt_1
> ../../gcc/cfgexpand.cc:4276
> 0x1093629 expand_gimple_stmt
> ../../gcc/cfgexpand.cc:4423
> 0x1095617 expand_gimple_basic_block
> ../../gcc/cfgexpand.cc:6539
> 0x1097a07 execute
> ../../gcc/cfgexpand.cc:7286
> 
> Given that empty_eh_cleanup handles already almost everything, just
> didn't know how to handle the resx to internal step which was quite
> trivial, I thought it will be easier not to reorder cleanup_eh pass,
> especially for 15.2 backport and when I have no idea what went wrong
> in the pr106190 testcase (the ICE is about not finding some region).

I see.  Fine with me then.  It's a bit of a whack-a-mole with musttail,
esp. wrt sanitizers ...

Richard.


Re: [PATCH v7 8/9] AArch64: rules for CMPBR instructions

2025-07-01 Thread Richard Sandiford
Karl Meakin  writes:
> @@ -763,6 +784,68 @@ (define_expand "cbranchcc4"
>""
>  )
>  
> +;; Emit a `CB (register)` or `CB (immediate)` instruction.
> +;; The immediate range depends on the comparison code.
> +;; Comparisons against immediates outside this range fall back to
> +;; CMP + B.
> +(define_insn "aarch64_cb"
> +  [(set (pc) (if_then_else (INT_CMP
> +  (match_operand:GPI 0 "register_operand" "r")
> +  (match_operand:GPI 1 "nonmemory_operand"
> +   "r"))
> +(label_ref (match_operand 2))
> +(pc)))]
> +  "TARGET_CMPBR && aarch64_cb_rhs (, operands[1])"
> +  {
> +if (get_attr_far_branch (insn) == FAR_BRANCH_YES)
> +  return aarch64_gen_far_branch (operands, 2, "L",
> + "cb\\t%0, %1, 
> ");
> +else
> +  return "cb\\t%0, %1, %l2";
> +  }
> +  [(set_attr "type" "branch")
> +   (set (attr "length")
> + (if_then_else (and (ge (minus (match_dup 2) (pc))
> +(const_int BRANCH_LEN_N_1Kib))
> +(lt (minus (match_dup 2) (pc))
> +(const_int BRANCH_LEN_P_1Kib)))
> +   (const_int 4)
> +   (const_int 8)))
> +   (set (attr "far_branch")
> + (if_then_else (and (ge (minus (match_dup 2) (pc))
> +(const_int BRANCH_LEN_N_1Kib))
> +(lt (minus (match_dup 2) (pc))
> +(const_int BRANCH_LEN_P_1Kib)))
> +   (const_string "no")
> +   (const_string "yes")))]
> +)
> +
> +;; Emit a `CBB (register)` or `CBH (register)` instruction.
> +(define_insn "aarch64_cb"
> +  [(set (pc) (if_then_else (INT_CMP
> +  (match_operand:SHORT 0 "register_operand" "r")
> +  (match_operand:SHORT 1 "aarch64_reg_or_zero" "rZ"))
> +(label_ref (match_operand 2))
> +(pc)))]
> +  "TARGET_CMPBR"
> +  "cb\\t%0, %1, %l2"

This instruction also needs to handle far branches, in a similar way
to the GPI one.  (It would be good to have a test for that too).

Why does the code for u32_x0_uge_64 etc. not change?  I would have
expected 64 to be in range for that, whether it's treated as >= 64
or as > 63.

Otherwise it looks good, thanks.

Richard


[committed] testsuite: Fix up pr119318.c test for big-endian [PR120082]

2025-07-01 Thread Jakub Jelinek
Hi!

The test is not endianess clean, x[0] is supposed to be ((__int128)0x19)<<32
on little endian - 0x19 is in the second vector elt - but ((__int128)0x19)<<64
on big endian.  I've added also verification of int and __int128 sizes just
in case we have say 16-bit or 64-bit int target with __int128 type, or
pdp endian gets __int128 support.

Tested on x86_64-linux and s390x-linux, committed to trunk and 15.2 as
obvious.

2025-07-01  Jakub Jelinek  

PR ipa/119318
PR testsuite/120082
* gcc.dg/ipa/pr119318.c (main): Expect different result on big endian
from little endian, on unexpected endianness or int/int128 sizes don't
test anything.  Formatting fixes.

--- gcc/testsuite/gcc.dg/ipa/pr119318.c.jj  2025-04-15 12:26:06.484323860 
+0200
+++ gcc/testsuite/gcc.dg/ipa/pr119318.c 2025-07-01 11:54:40.941287695 +0200
@@ -30,8 +30,14 @@ int
 main ()
 {
   W x = foo (0, (V) { 0, 5 });
-  for (unsigned i = 0; i < sizeof(x)/sizeof(x[0]); i++)
+  for (unsigned i = 0; i < sizeof (x) / sizeof (x[0]); i++)
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_INT__ == 4 && 
__SIZEOF_INT128__ == 16
 if (x[i] != (i ? 0 : 0x19))
-  __builtin_abort();
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __SIZEOF_INT__ == 4 && 
__SIZEOF_INT128__ == 16
+if (x[i] != (i ? 0 : ((__int128) 0x19) << 64))
+#else
+if (0)
+#endif
+  __builtin_abort ();
   return 0;
 }

Jakub



[PATCH] testsuite: i386: Fix gcc.target/i386/preserve-none-1.c on Solaris/x86

2025-07-01 Thread Rainer Orth
The new gcc.target/i386/preserve-none-1.c test currently FAILs on
Solaris/x86:

FAIL: gcc.target/i386/preserve-none-1.c scan-assembler-not movq

It needs -fomit-frame-pointer which this patch adds.

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

Ok for trunk?

Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


2025-06-27  Rainer Orth  

gcc/testsuite:
* gcc.target/i386/preserve-none-1.c (dg-options): Add
-fomit-frame-pointer.

# HG changeset patch
# Parent  54ec79ca33792aac1acac9125048044977a56ee4
testsuite: i386: Fix gcc.target/i386/preserve-none-1.c on Solaris/x86

diff --git a/gcc/testsuite/gcc.target/i386/preserve-none-1.c b/gcc/testsuite/gcc.target/i386/preserve-none-1.c
--- a/gcc/testsuite/gcc.target/i386/preserve-none-1.c
+++ b/gcc/testsuite/gcc.target/i386/preserve-none-1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile { target { ! ia32 } } } */
-/* { dg-options "-O2" } */
+/* { dg-options "-O2 -fomit-frame-pointer" } */
 
 extern void boring(void);
 


Re: [PATCH] libstdc++: Implement ranges::shift_left/right from P2440R1

2025-07-01 Thread Jonathan Wakely
On Mon, 30 Jun 2025 at 22:16, Patrick Palka  wrote:
>
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk?
>
> Btw, any thoughts on PR105611 which reports std::shift_left/right's use
> of the three-parameter version of ranges::next (on legacy iterators) is
> sketchy?  Should we define a three-parameter std::__next analog for
> legacy iterators and use that instead?

I suppose we could do, but I find it hard to care about the corner
cases where ranges::next isn't optimal.

This patch for the ranges shift algos is OK for trunk (two comments
below, but they aren't asking for changes).

>
> -- >8 --
>
> The implementation is essentially a copy of std::shift_left/right
> (defined directly above) with the following changes:
>
>  - check bidirectional_iterator instead of iterator_category
>  - for shift_left, return {__first, X} instead of X
>  - for shift_right, return {X, ranges::next(__first, __last)} instead of X
>  - use the Ranges versions of move_backward, move and iter_swap
>  - don't bother std::move'ing any iterators, it's unnecessary since all
>iterators are forward, makes the code less readable, and introduces
>subtle use-after-move bugs in some code paths
>
> In passing guard the std::shift_left/right implementations with
> __glibcxx_shift as well.
>
> libstdc++-v3/ChangeLog:
>
> * include/bits/ranges_algo.h (shift_left, shift_right): Guard
> with __glibcxx_shift >= 201806L.
> (ranges::__shift_left_fn, ranges::shift_left): Define for C++23.
> (ranges::__shift_right_fn, ranges::shift_right): Likewise.
> * include/bits/version.def (shift): Update for C++23.
> * include/bits/version.h: Regenerate.
> * testsuite/25_algorithms/shift_left/constrained.cc: New test,
> based off of 1.cc.
> * testsuite/25_algorithms/shift_right/constrained.cc: New test,
> based off of 1.cc.
> ---
>  libstdc++-v3/include/bits/ranges_algo.h   | 121 ++
>  libstdc++-v3/include/bits/version.def |   4 +
>  libstdc++-v3/include/bits/version.h   |   7 +-
>  .../25_algorithms/shift_left/constrained.cc   | 105 +++
>  .../25_algorithms/shift_right/constrained.cc  | 104 +++
>  5 files changed, 340 insertions(+), 1 deletion(-)
>  create mode 100644 
> libstdc++-v3/testsuite/25_algorithms/shift_left/constrained.cc
>  create mode 100644 
> libstdc++-v3/testsuite/25_algorithms/shift_right/constrained.cc
>
> diff --git a/libstdc++-v3/include/bits/ranges_algo.h 
> b/libstdc++-v3/include/bits/ranges_algo.h
> index 5aca6e8d864d..9bb84332d8e1 100644
> --- a/libstdc++-v3/include/bits/ranges_algo.h
> +++ b/libstdc++-v3/include/bits/ranges_algo.h
> @@ -4261,6 +4261,7 @@ namespace ranges
>  #endif // __glibcxx_ranges_fold
>  } // namespace ranges
>
> +#if __glibcxx_shift >= 201806L // C++ >= 20
>template
>  constexpr _ForwardIterator
>  shift_left(_ForwardIterator __first, _ForwardIterator __last,
> @@ -4351,6 +4352,126 @@ namespace ranges
> }
> }
>  }
> +#endif
> +
> +namespace ranges
> +{
> +#if __glibcxx_shift >= 202202L // C++ >= 23
> +  struct __shift_left_fn
> +  {
> +template _Sent>
> +  constexpr subrange<_Iter>
> +  operator()(_Iter __first, _Sent __last, iter_difference_t<_Iter> __n) 
> const
> +  {
> +   __glibcxx_assert(__n >= 0);
> +   if (__n == 0)
> + return {__first, ranges::next(__first, __last)};
> +
> +   auto __mid = ranges::next(__first, __n, __last);
> +   if (__mid == __last)
> + return {__first, __first};
> +   return {__first, ranges::move(__mid, __last, __first).out};
> +  }
> +
> +template
> +  requires permutable>
> +  constexpr borrowed_subrange_t<_Range>
> +  operator()(_Range&& __r, range_difference_t<_Range> __n) const
> +  { return (*this)(ranges::begin(__r), ranges::end(__r), __n); }
> +  };
> +
> +  inline constexpr __shift_left_fn shift_left{};
> +
> +  struct __shift_right_fn
> +  {
> +template _Sent>
> +  constexpr subrange<_Iter>
> +  operator()(_Iter __first, _Sent __last, iter_difference_t<_Iter> __n) 
> const
> +  {
> +   _Iter __lasti = ranges::next(__first, __last);
> +   return {_S_impl(__first, __lasti, __n), __lasti};
> +  }
> +
> +template
> +  static constexpr _Iter
> +  _S_impl(_Iter __first, _Iter __last, iter_difference_t<_Iter> __n)
> +  {
> +   __glibcxx_assert(__n >= 0);
> +   if (__n == 0)
> + return __first;
> +
> +   if constexpr (bidirectional_iterator<_Iter>)
> + {
> +   auto __mid = ranges::next(__last, -__n, __first);

I wondered if using ranges::prev(__last, __n, __first) would avoid
possible overflow for n == numeric_limits::min() but we just do -n in
ranges::prev too so it's identical anyway.

> +   if (__mid == __first)
> + return __last;
> +
> +   return ranges::move_backward(__first, __mid, __last).out;
> +

Re: [PATCH 1/1] libstdc++: Implement default_accessor from mdspan.

2025-07-01 Thread Tomasz Kaminski
On Mon, Jun 30, 2025 at 4:27 PM Jonathan Wakely  wrote:

> On Mon, 30 Jun 2025 at 11:48, Tomasz Kaminski  wrote:
> >
> >
> >
> > On Mon, Jun 30, 2025 at 9:58 AM Tomasz Kaminski 
> wrote:
> >>
> >>
> >>
> >> On Mon, Jun 30, 2025 at 9:25 AM Luc Grosheintz <
> luc.groshei...@gmail.com> wrote:
> >>>
> >>> libstdc++-v3/ChangeLog:
> >>>
> >>> * include/std/mdspan (default_accessor): New class.
> >>> * src/c++23/std.cc.in: Register default_accessor.
> >>> * testsuite/23_containers/mdspan/accessors/default.cc: New
> test.
> >>> * testsuite/23_containers/mdspan/accessors/default_neg.cc: New
> test.
> >>>
> >>> Signed-off-by: Luc Grosheintz 
> >>> ---
> >>>
> >>> Version of v5 with all local changes included.
> >>
> >> LGTM, tested locally and now running a full test suite.
> >> Once it will get approval from Jonathan, I will handle merging it.
> >
> > All test passed.
>
> OK for trunk, thank you both.
>
Patch now merged to trunk. I hope to review mdspan itself this week.

>
> >>
> >>
> >>>
> >>>
> >>>  libstdc++-v3/include/std/mdspan   | 31 ++
> >>>  libstdc++-v3/src/c++23/std.cc.in  |  3 +-
> >>>  .../23_containers/mdspan/accessors/default.cc | 99 +++
> >>>  .../mdspan/accessors/default_neg.cc   | 23 +
> >>>  4 files changed, 155 insertions(+), 1 deletion(-)
> >>>  create mode 100644
> libstdc++-v3/testsuite/23_containers/mdspan/accessors/default.cc
> >>>  create mode 100644
> libstdc++-v3/testsuite/23_containers/mdspan/accessors/default_neg.cc
> >>>
> >>> diff --git a/libstdc++-v3/include/std/mdspan
> b/libstdc++-v3/include/std/mdspan
> >>> index 6dc2441f80b..c72a64094b7 100644
> >>> --- a/libstdc++-v3/include/std/mdspan
> >>> +++ b/libstdc++-v3/include/std/mdspan
> >>> @@ -1004,6 +1004,37 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >>>[[no_unique_address]] _S_strides_t _M_strides;
> >>>  };
> >>>
> >>> +  template
> >>> +struct default_accessor
> >>> +{
> >>> +  static_assert(!is_array_v<_ElementType>,
> >>> +   "ElementType must not be an array type");
> >>> +  static_assert(!is_abstract_v<_ElementType>,
> >>> +   "ElementType must not be an abstract class type");
> >>> +
> >>> +  using offset_policy = default_accessor;
> >>> +  using element_type = _ElementType;
> >>> +  using reference = element_type&;
> >>> +  using data_handle_type = element_type*;
> >>> +
> >>> +  constexpr
> >>> +  default_accessor() noexcept = default;
> >>> +
> >>> +  template
> >>> +   requires is_convertible_v<_OElementType(*)[],
> element_type(*)[]>
> >>> +   constexpr
> >>> +   default_accessor(default_accessor<_OElementType>) noexcept
> >>> +   { }
> >>> +
> >>> +  constexpr reference
> >>> +  access(data_handle_type __p, size_t __i) const noexcept
> >>> +  { return __p[__i]; }
> >>> +
> >>> +  constexpr data_handle_type
> >>> +  offset(data_handle_type __p, size_t __i) const noexcept
> >>> +  { return __p + __i; }
> >>> +};
> >>> +
> >>>  _GLIBCXX_END_NAMESPACE_VERSION
> >>>  }
> >>>  #endif
> >>> diff --git a/libstdc++-v3/src/c++23/std.cc.in
> b/libstdc++-v3/src/c++23/std.cc.in
> >>> index 9336118f5d9..e692caaa5f9 100644
> >>> --- a/libstdc++-v3/src/c++23/std.cc.in
> >>> +++ b/libstdc++-v3/src/c++23/std.cc.in
> >>> @@ -1850,7 +1850,8 @@ export namespace std
> >>>using std::layout_left;
> >>>using std::layout_right;
> >>>using std::layout_stride;
> >>> -  // FIXME layout_left_padded, layout_right_padded, default_accessor
> and mdspan
> >>> +  using std::default_accessor;
> >>> +  // FIXME layout_left_padded, layout_right_padded, aligned_accessor
> and mdspan
> >>>  }
> >>>  #endif
> >>>
> >>> diff --git
> a/libstdc++-v3/testsuite/23_containers/mdspan/accessors/default.cc
> b/libstdc++-v3/testsuite/23_containers/mdspan/accessors/default.cc
> >>> new file mode 100644
> >>> index 000..c036f8ad10f
> >>> --- /dev/null
> >>> +++ b/libstdc++-v3/testsuite/23_containers/mdspan/accessors/default.cc
> >>> @@ -0,0 +1,99 @@
> >>> +// { dg-do run { target c++23 } }
> >>> +#include 
> >>> +
> >>> +#include 
> >>> +
> >>> +constexpr size_t dyn = std::dynamic_extent;
> >>> +
> >>> +template
> >>> +  constexpr void
> >>> +  test_accessor_policy()
> >>> +  {
> >>> +static_assert(std::copyable);
> >>> +static_assert(std::is_nothrow_move_constructible_v);
> >>> +static_assert(std::is_nothrow_move_assignable_v);
> >>> +static_assert(std::is_nothrow_swappable_v);
> >>> +  }
> >>> +
> >>> +constexpr bool
> >>> +test_access()
> >>> +{
> >>> +  std::default_accessor accessor;
> >>> +  std::array a{10, 11, 12, 13, 14};
> >>> +  VERIFY(accessor.access(a.data(), 0) == 10);
> >>> +  VERIFY(accessor.access(a.data(), 4) == 14);
> >>> +  return true;
> >>> +}
> >>> +
> >>> +constexpr bool
> >>> +test_offset()
> >>> +{
> >>> +  std::default_accessor accessor;
> >>> +  std::array a{10, 11, 12, 13, 14};
> >>> +  VERIFY(accessor.offset(a.data(),

Re: [PATCH v7 7/9] AArch64: precommit test for CMPBR instructions

2025-07-01 Thread Richard Sandiford
Karl Meakin  writes:
> Commit the test file `cmpbr.c` before rules for generating the new
> instructions are added, so that the changes in codegen are more obvious
> in the next commit.
>
> gcc/testsuite/ChangeLog:
>
>   * lib/target-supports.exp: Add `cmpbr` to the list of extensions.
>   * gcc.target/aarch64/cmpbr.c: New test.
> ---
>  gcc/testsuite/gcc.target/aarch64/cmpbr.c | 1877 ++
>  gcc/testsuite/lib/target-supports.exp|   14 +-
>  2 files changed, 1885 insertions(+), 6 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/aarch64/cmpbr.c
>
> diff --git a/gcc/testsuite/gcc.target/aarch64/cmpbr.c 
> b/gcc/testsuite/gcc.target/aarch64/cmpbr.c
> new file mode 100644
> index 000..9ca376a8f33
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/aarch64/cmpbr.c
> @@ -0,0 +1,1877 @@
> +// Test that the instructions added by FEAT_CMPBR are emitted
> +// { dg-do compile }
> +// { dg-do-if assemble { target aarch64_asm_cmpbr_ok } }
> +// { dg-options "-march=armv9.5-a+cmpbr -O2" }
> +// { dg-final { check-function-bodies "**" "*/" "" { target *-*-* } 
> {\.L[0-9]+} } }
> +
> +#include 
> +
> +typedef uint8_t u8;
> +typedef int8_t i8;
> +
> +typedef uint16_t u16;
> +typedef int16_t i16;
> +
> +typedef uint32_t u32;
> +typedef int32_t i32;
> +
> +typedef uint64_t u64;
> +typedef int64_t i64;
> +
> +int taken();
> +int not_taken();
> +
> +#define COMPARE(ty, name, op, rhs)   
>   \
> +  int ty##_x0_##name##_##rhs(ty x0, ty x1) { 
>   \
> +return (x0 op rhs) ? taken() : not_taken();  
>   \
> +  }
> +
> +#define COMPARE_ALL(unsigned_ty, signed_ty, rhs) 
>   \
> +  COMPARE(unsigned_ty, eq, ==, rhs); 
>   \
> +  COMPARE(unsigned_ty, ne, !=, rhs); 
>   \
> + 
>   \
> +  COMPARE(unsigned_ty, ult, <, rhs); 
>   \
> +  COMPARE(unsigned_ty, ule, <=, rhs);
>   \
> +  COMPARE(unsigned_ty, ugt, >, rhs); 
>   \
> +  COMPARE(unsigned_ty, uge, >=, rhs);
>   \
> + 
>   \
> +  COMPARE(signed_ty, slt, <, rhs);   
>   \
> +  COMPARE(signed_ty, sle, <=, rhs);  
>   \
> +  COMPARE(signed_ty, sgt, >, rhs);   
>   \
> +  COMPARE(signed_ty, sge, >=, rhs);
> +
> +//  CBB (register) 
> +COMPARE_ALL(u8, i8, x1);
> +
> +//  CBH (register) 
> +COMPARE_ALL(u16, i16, x1);
> +
> +//  CB (register) 
> +COMPARE_ALL(u32, i32, x1);
> +COMPARE_ALL(u64, i64, x1);
> +
> +//  CB (immediate) 
> +COMPARE_ALL(u32, i32, 42);
> +COMPARE_ALL(u64, i64, 42);
> +
> +//  Special cases 
> +// Comparisons against the immediate 0 can be done for all types,
> +// because we can use the wzr/xzr register as one of the operands.
> +// However, we should prefer to use CBZ/CBNZ or TBZ/TBNZ when possible,
> +// because they have larger range.
> +COMPARE_ALL(u8, i8, 0);
> +COMPARE_ALL(u16, i16, 0);
> +COMPARE_ALL(u32, i32, 0);
> +COMPARE_ALL(u64, i64, 0);
> +
> +// CBB and CBH cannot have immediate operands.
> +// Instead we have to do a MOV+CB.
> +COMPARE_ALL(u8, i8, 42);
> +COMPARE_ALL(u16, i16, 42);
> +
> +// 64 is out of the range for immediate operands (0 to 63).
> +// * For 8/16-bit types, use a MOV+CB as above.
> +// * For 32/64-bit types, use a CMP+B instead,
> +//   because B has a longer range than CB.
> +COMPARE_ALL(u8, i8, 64);
> +COMPARE_ALL(u16, i16, 64);
> +COMPARE_ALL(u32, i32, 64);
> +COMPARE_ALL(u64, i64, 64);
> +
> +// 4098 is out of the range for CMP (0 to 4095, optionally shifted by left 
> by 12
> +// bits), but it can be materialized in a single MOV.
> +COMPARE_ALL(u16, i16, 4098);
> +COMPARE_ALL(u32, i32, 4098);
> +COMPARE_ALL(u64, i64, 4098);
> +
> +// If the branch destination is out of range (1KiB), we have to generate an
> +// extra B instruction (which can handle larger displacements) and branch 
> around
> +// it
> +int far_branch(i32 x, i32 y) {
> +  volatile int z = 0;
> +  if (x == y) {

It might be worth making this:

  if (__builtin_expect (x == y, 0)) {

as a way of ensuring that nothing tries to "optimise" the code by
inverting the branch (and avoiding the far branch).

> +// clang-format off
> +#define STORE_2()   z = 0; z = 0;
> +#define STORE_4()   STORE_2();   STORE_2();
> +#define STORE_8()   STORE_4();   STORE_4();
> +#define STORE_16()  STORE_8();   STORE_8();
> +#define STORE_32()  STORE_16();  STORE_16();
> +#define STORE_64()  STORE_32();  STORE_32();
> +#define STORE_128() STORE_

[COMMITTED 39/42] ada: Disallow underscore before exponent

2025-07-01 Thread Marc Poulhiès
From: Tonu Naks 

Underscore is allowed only between digits. The current implementattion
was considering 'E' as a digit even if it was not in the range of
Base and could denote exponent only.

gcc/ada/ChangeLog:

* libgnat/s-valuer.adb (Scan_Decimal_Digits,
Scan_Integral_Digits): fix condition for rejecting
underscore.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/s-valuer.adb | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/libgnat/s-valuer.adb b/gcc/ada/libgnat/s-valuer.adb
index b8073c060b4..961dda47d77 100644
--- a/gcc/ada/libgnat/s-valuer.adb
+++ b/gcc/ada/libgnat/s-valuer.adb
@@ -287,7 +287,9 @@ package body System.Value_R is
 if Digit = Underscore and then Index + 1 <= Max then
 
Digit := As_Digit (Str (Index + 1));
-   if Digit in Valid_Digit then
+   if Digit in Valid_Digit and then
+  (Digit /= E_Digit or else Base > E_Digit)
+   then
   Index := Index + 1;
else
   return;
@@ -437,7 +439,9 @@ package body System.Value_R is
 
 if Digit = Underscore and then Index + 1 <= Max then
Digit := As_Digit (Str (Index + 1));
-   if Digit in Valid_Digit then
+   if Digit in Valid_Digit and then
+  (Digit /= E_Digit or else Base > E_Digit)
+   then
   Index := Index + 1;
else
   return;
-- 
2.43.0



Re: [PATCH] tailc: Handle musttail in case of non-cleaned-up cleanups, especially ASan related [PR120608]

2025-07-01 Thread Jakub Jelinek
On Tue, Jul 01, 2025 at 10:55:00AM +0200, Jakub Jelinek wrote:
> I've actually tried
> --- gcc/passes.def2025-06-30 22:16:11.258688529 +0200
> +++ gcc/passes.def2025-07-01 10:47:37.020634803 +0200
> @@ -444,9 +444,9 @@ along with GCC; see the file COPYING3.
>NEXT_PASS (pass_lower_switch_O0);
>NEXT_PASS (pass_asan_O0);
>NEXT_PASS (pass_tsan_O0);
> -  NEXT_PASS (pass_sanopt);
>NEXT_PASS (pass_cleanup_eh);
>NEXT_PASS (pass_musttail);
> +  NEXT_PASS (pass_sanopt);
>NEXT_PASS (pass_lower_resx);
>NEXT_PASS (pass_nrv);
>NEXT_PASS (pass_gimple_isel);
> together with the non-empty_eh_cleanup tree-tailcall.cc changes from the
> patch, but that resulted in the following ICE:
> /home/jakub/src/gcc/gcc/testsuite/gcc.dg/asan/pr106190.c: In function 'main':
> /home/jakub/src/gcc/gcc/testsuite/gcc.dg/asan/pr106190.c:6:1: internal 
> compiler error: in expand_builtin_eh_common, at except.cc:2097
> 0x2dc62cf internal_error(char const*, ...)
> ../../gcc/diagnostic-global-context.cc:517
> 0xeaeced fancy_abort(char const*, int, char const*)
> ../../gcc/diagnostic.cc:1810
> 0x81940a expand_builtin_eh_common
> ../../gcc/except.cc:2097
> 0x11ad909 expand_builtin_eh_pointer(tree_node*)
> ../../gcc/except.cc:2108
> 0x11deac2 expand_expr_real_1(tree_node*, rtx_def*, machine_mode, 
> expand_modifier, rtx_def**, bool)
> ../../gcc/expr.cc:12535
> 0x11ecddd store_expr(tree_node*, rtx_def*, int, bool, bool)
> ../../gcc/expr.cc:6762
> 0x11efb28 expand_assignment(tree_node*, tree_node*, bool)
> ../../gcc/expr.cc:6483
> 0x11efb28 expand_assignment(tree_node*, tree_node*, bool)
> ../../gcc/expr.cc:5971
> 0x1093629 expand_call_stmt
> ../../gcc/cfgexpand.cc:3202
> 0x1093629 expand_gimple_stmt_1
> ../../gcc/cfgexpand.cc:4276
> 0x1093629 expand_gimple_stmt
> ../../gcc/cfgexpand.cc:4423
> 0x1095617 expand_gimple_basic_block
> ../../gcc/cfgexpand.cc:6539
> 0x1097a07 execute
> ../../gcc/cfgexpand.cc:7286
> 
> Given that empty_eh_cleanup handles already almost everything, just
> didn't know how to handle the resx to internal step which was quite
> trivial, I thought it will be easier not to reorder cleanup_eh pass,
> especially for 15.2 backport and when I have no idea what went wrong
> in the pr106190 testcase (the ICE is about not finding some region).

Just guessing, but the sanopt pass on that case removes quite a lot of basic
blocks etc. and perhaps expansion relies on the EH stuff being cleaned up
before expansion.  When it is done before sanopt, it can't clean up some
stuff yet.
Tested also
--- gcc/passes.def.jj   2025-06-30 21:48:31.063723401 +0200
+++ gcc/passes.def  2025-07-01 11:22:50.484144188 +0200
@@ -444,9 +444,10 @@ along with GCC; see the file COPYING3.
   NEXT_PASS (pass_lower_switch_O0);
   NEXT_PASS (pass_asan_O0);
   NEXT_PASS (pass_tsan_O0);
-  NEXT_PASS (pass_sanopt);
   NEXT_PASS (pass_cleanup_eh);
   NEXT_PASS (pass_musttail);
+  NEXT_PASS (pass_sanopt);
+  NEXT_PASS (pass_cleanup_eh);
   NEXT_PASS (pass_lower_resx);
   NEXT_PASS (pass_nrv);
   NEXT_PASS (pass_gimple_isel);

and that works, but the empty_eh_cleanup change seems better to me than
repeating the pass so close.

Jakub



[COMMITTED 23/42] ada: use __builtin_alloca for alloca on vxworks

2025-07-01 Thread Marc Poulhiès
From: Alexandre Oliva 

Several adaint.c functions call alloca, but vxworks doesn't declare
it.  Use the GCC builtin.

gcc/ada/ChangeLog:

* adaint.c [__vxworks] (alloca): Redirect to builtin.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/adaint.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c
index 2f5bbf31f79..adc39517280 100644
--- a/gcc/ada/adaint.c
+++ b/gcc/ada/adaint.c
@@ -63,6 +63,10 @@
 #include 
 #include  /* for isalpha */
 
+#ifndef alloca
+#define alloca(n) __builtin_alloca(n)
+#endif
+
 #if defined (__mips_vxworks)
 #include "cacheLib.h"
 #endif /* __mips_vxworks */
-- 
2.43.0



Re: [PATCH v3] AArch64 SIMD: convert mvn+shrn into mvni+subhn

2025-07-01 Thread Richard Sandiford
Remi Machet  writes:
> Attached is the updated patch for the aarch64 conversion of some 
> mvn+shrn patterns into a mvni+subhn. Hopefully attachment fixes the tab 
> issues, the cover letter was updated to better explain what the patch 
> does, code was changed to use emit_move_insn, and testcase was cleaned 
> up per Richard and Alex's suggestions.

LGTM, thanks.  Pushed to trunk.

Richard


[PING][PATCH v2 0/1] aarch64: Add support for unpacked SVE FP comparisons

2025-07-01 Thread Spencer Abson
Gentle ping for this patch.

Thanks,
Spencer

On Mon, Jun 16, 2025 at 08:13:02PM +, Spencer Abson wrote:
> Here is a V2 of patch 04/14 from the unpacked FP patch series [1], with the
> changes discussed in that thread applied.  The tests are also now based on VLA
> codegen.
> 
> Bootstrapped & regtested on aarch64-linux-gnu.  OK for master?
> 
> Thanks,
> Spencer
> 
> [1] 
> https://inbox.sourceware.org/gcc-patches/20250602100707.2659-1-spencer.ab...@arm.com/
> 
> Spencer Abson (1):
>   aarch64: Add support for unpacked SVE FP comparisons
> 
>  gcc/config/aarch64/aarch64-sve.md |  18 +-
>  gcc/config/aarch64/aarch64.cc |  56 +-
>  .../gcc.target/aarch64/sve/unpacked_fcm_1.c   | 602 ++
>  .../gcc.target/aarch64/sve/unpacked_fcm_2.c   |  47 ++
>  4 files changed, 698 insertions(+), 25 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/unpacked_fcm_1.c
>  create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/unpacked_fcm_2.c
> 
> -- 
> 2.34.1
> 


Re: [PATCH v2 5/5] libstdc++: Make mdspan nothrow movable.

2025-07-01 Thread Luc Grosheintz

You're right, I remember checking this; but it appears I conned
myself. I've reverted the change to , do you want to keep
the tests?

On 7/1/25 12:35, Tomasz Kaminski wrote:

Hi,

I do not think that the change is necessary, as for the functions default
on the first declaration
(as in the case for the constructors/assigments for mdpsan) have noexcept
specifier deduced
from it body. In other words, I think the test should pass, without adding
the complicated noexcept
conditions.

Regards,
Tomasz

On Fri, Jun 27, 2025 at 11:19 AM Luc Grosheintz 
wrote:


If all members of mdspan are nothrow movable, then mdspan can also
be nothrow movable. The standard doesn't specify that mdspan must be
nothrow movable (when possible). Nothrow movable enables containers
to use move operations even if they have a strong exception guarantee.

This commit strenghtens the exception guarantees for mdspan, making
it nothrow movable if all it's members are nothrow movable.

libstdc++-v3/ChangeLog:

 * include/std/mdspan (mdspan): Make nothrow movable, if all
 members are nothrow movable.
 * testsuite/23_containers/mdspan/mdspan.cc: Test nothrow movable
 property.

Signed-off-by: Luc Grosheintz 
---
  libstdc++-v3/include/std/mdspan   | 10 +++-
  .../testsuite/23_containers/mdspan/mdspan.cc  | 53 ++-
  2 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/std/mdspan
b/libstdc++-v3/include/std/mdspan
index 852f881971e..563aa312f8a 100644
--- a/libstdc++-v3/include/std/mdspan
+++ b/libstdc++-v3/include/std/mdspan
@@ -1119,7 +1119,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
mdspan(const mdspan& __other) = default;

constexpr
-  mdspan(mdspan&& __other) = default;
+  mdspan(mdspan&& __other)
+  noexcept(is_nothrow_move_constructible_v
+ && is_nothrow_move_constructible_v
+ && is_nothrow_move_constructible_v) = default;

template<__mdspan::__valid_index_type... _OIndexTypes>
 requires ((sizeof...(_OIndexTypes) == rank()
@@ -1197,7 +1200,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator=(const mdspan& __other) = default;

constexpr mdspan&
-  operator=(mdspan&& __other) = default;
+  operator=(mdspan&& __other)
+  noexcept(is_nothrow_move_assignable_v
+ && is_nothrow_move_assignable_v
+ && is_nothrow_move_assignable_v) = default;

template<__mdspan::__valid_index_type... _OIndexTypes>
 requires (sizeof...(_OIndexTypes) == rank())
diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc
b/libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc
index d2672878d69..6d8f32ff103 100644
--- a/libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc
+++ b/libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc
@@ -310,11 +310,29 @@ test_from_int_like()
verify(std::mdspan(storage.data(), shape_view));
  }

-template
+template
class OpaqueAccessor
{
  struct Handle
  {
+  constexpr
+  Handle(T * other)
+  : ptr(other)
+  { }
+
+  constexpr
+  Handle(const Handle&) noexcept(NothrowConstructible) = default;
+
+  constexpr
+  Handle(Handle&&) noexcept(NothrowConstructible) = default;
+
+  constexpr Handle&
+  operator=(const Handle&) noexcept(NothrowAssignable) = default;
+
+  constexpr Handle&
+  operator=(Handle&&) noexcept(NothrowAssignable) = default;
+
T * ptr;
  };

@@ -489,6 +507,37 @@ test_swap()
return true;
  }

+template
+constexpr void
+test_nothrow_movable()
+{
+  using Layout = std::layout_left;
+  using Extents = std::dextents;
+  using Accessor = OpaqueAccessor;
+  using Handle = Accessor::data_handle_type;
+  static_assert(std::is_nothrow_move_assignable_v);
+  static_assert(std::is_nothrow_move_constructible_v);
+  static_assert(std::is_nothrow_move_assignable_v == Assignable);
+  static_assert(std::is_nothrow_move_constructible_v ==
Constructible);
+
+  using MDSpan = std::mdspan;
+  static_assert(std::is_nothrow_move_assignable_v == Assignable);
+  static_assert(std::is_nothrow_move_constructible_v ==
Constructible);
+}
+
+constexpr void
+test_nothrow_movable_all()
+{
+  using MDSpan = std::mdspan>;
+  static_assert(std::is_nothrow_move_assignable_v);
+  static_assert(std::is_nothrow_move_constructible_v);
+
+  test_nothrow_movable();
+  test_nothrow_movable();
+  test_nothrow_movable();
+  test_nothrow_movable();
+}
+
  int
  main()
  {
@@ -536,5 +585,7 @@ main()

test_swap();
static_assert(test_swap());
+
+  test_nothrow_movable_all();
return 0;
  }
--
2.49.0








Re: [PATCH v4 2/6] dwarf: create annotation DIEs for btf tags

2025-07-01 Thread Richard Biener
On Mon, Jun 30, 2025 at 9:12 PM David Faust  wrote:
>
>
>
> On 6/30/25 06:11, Richard Biener wrote:
> >> +static void
> >> +gen_btf_decl_tag_dies (tree t, dw_die_ref target, dw_die_ref context_die)
> >> +{
> >> +  if (t == NULL_TREE || !DECL_P (t) || !target)
> >> +return;
> >> +
> >> +  tree attr = lookup_attribute ("btf_decl_tag", DECL_ATTRIBUTES (t));
> >> +  if (attr == NULL_TREE)
> >> +return;
> >> +
> >> +  gen_btf_tag_dies (attr, target, context_die);
> >> +
> >> +  /* Strip the decl tag attribute once we have created the annotation DIEs
> >> + to avoid attempting process it multiple times.  Global variable
> >> + declarations may reach this function more than once.  */
> >> +  DECL_ATTRIBUTES (t)
> >> += remove_attribute ("btf_decl_tag", DECL_ATTRIBUTES (t));
> > I do not like modifying trees as part of dwarf2out.  You should be able to
> > see whether a DIE already has the respective attribute applied?
>
> Yes, you're right. For decl_tag the case is simple and better handled by
> consulting the hash table. Simple fix and this remove_attribute can be
> deleted.
>
> Understood re: modifying trees in dwarf2out. I agree it's not ideal.
>
> For this case the remove_attribute can be deleted. For the two below,
> one is already immediately restored and the other could be as well so
> that there are no lasting changes in the tree at all.
>
> I will explain the reasoning some more below.
>
> >
> >> +}
> >> +
> >>  /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
> >> entry that chains the modifiers specified by CV_QUALS in front of the
> >> given type.  REVERSE is true if the type is to be interpreted in the
> >> @@ -13674,6 +13894,7 @@ modified_type_die (tree type, int cv_quals, bool 
> >> reverse,
> >>tree item_type = NULL;
> >>tree qualified_type;
> >>tree name, low, high;
> >> +  tree tags;
> >>dw_die_ref mod_scope;
> >>struct array_descr_info info;
> >>/* Only these cv-qualifiers are currently handled.  */
> >> @@ -13783,10 +14004,62 @@ modified_type_die (tree type, int cv_quals, bool 
> >> reverse,
> >>   dquals &= cv_qual_mask;
> >>   if ((dquals & ~cv_quals) != TYPE_UNQUALIFIED
> >>   || (cv_quals == dquals && DECL_ORIGINAL_TYPE (name) != type))
> >> -   /* cv-unqualified version of named type.  Just use
> >> -  the unnamed type to which it refers.  */
> >> -   return modified_type_die (DECL_ORIGINAL_TYPE (name), cv_quals,
> >> - reverse, context_die);
> >> +   {
> >> + tree dtags = lookup_attribute ("btf_type_tag",
> >> +TYPE_ATTRIBUTES (dtype));
> >> + if ((tags = lookup_attribute ("btf_type_tag",
> >> +   TYPE_ATTRIBUTES (type)))
> >> + && !attribute_list_equal (tags, dtags))
> >> +   {
> >> + /* Use of a typedef with additional btf_type_tags.
> >> +Create a new typedef DIE to which we can attach the
> >> +additional type_tag DIEs without disturbing other 
> >> users of
> >> +the underlying typedef.  */
> >> + dw_die_ref mod_die = modified_type_die (dtype, cv_quals,
> >> + reverse, 
> >> context_die);
> >> + mod_die = clone_die (mod_die);
> >> + add_child_die (comp_unit_die (), mod_die);
> >> + if (!lookup_type_die (type))
> >> +   equate_type_number_to_die (type, mod_die);
> >> +
> >> + /* 'tags' is an accumulated list of type_tag attributes
> >> +for the typedef'd type on both sides of the typedef.
> >> +'dtags' is the set of type_tag attributes only 
> >> appearing
> >> +in the typedef itself.
> >> +Find the set of type_tags only on the _use_ of the
> >> +typedef, i.e. (tags - dtags).  By construction these
> >> +additional type_tags have been chained onto the head 
> >> of
> >> +the attribute list of the original typedef.  */
> >> + tree t = tags;
> >> + bool altered_chain = false;
> >> + while (t)
> >> +   {
> >> + if (TREE_CHAIN (t) == dtags)
> >> +   {
> >> + TREE_CHAIN (t) = NULL_TREE;
> >> + altered_chain = true;
> >> + break;
> >> +   }
> >> + t = TREE_CHAIN (t);
> >> +   }
> > And this might be part of that and should thus split out, or be part
> > of gen_btf_type_tag_dies itself?  I expected the hashtable to
> > cover the DIEs we have for existing chains of tags?
>
> OK, this can move int

[COMMITTED 30/42] ada: Small tweak to latest change

2025-07-01 Thread Marc Poulhiès
From: Eric Botcazou 

Unlike RTE, RTU_Entity alone does not cause the unit to be loaded.

gcc/ada/ChangeLog:

* exp_ch7.adb (Shift_Address_For_Descriptor): Add dummy variable
to make sure that System_Storage_Elements is loaded.

Tested on x86_64-pc-linux-gnu, committed on master.

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

diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
index 9abdcc18a57..4d2b8348048 100644
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -8868,7 +8868,9 @@ package body Exp_Ch7 is
   Typ: Entity_Id;
   Op_Nam : Name_Id) return Node_Id
is
-  Loc : constant Source_Ptr := Sloc (Addr);
+  Loc   : constant Source_Ptr := Sloc (Addr);
+  Dummy : constant Entity_Id  := RTE (RE_Storage_Offset);
+  --  Make sure System_Storage_Elements is loaded for RTU_Entity
 
begin
   --  Generate:
-- 
2.43.0



[COMMITTED 10/42] ada: Remove dead assignment

2025-07-01 Thread Marc Poulhiès
From: Eric Botcazou 

The assignment sets the Etype of a node to itsef.

gcc/ada/ChangeLog:

* sem_ch4.adb (Analyze_Allocator): Do not set Etype to itself.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch4.adb | 2 --
 1 file changed, 2 deletions(-)

diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index ec48edda9f4..89beb2b9a7e 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -594,8 +594,6 @@ package body Sem_Ch4 is
  --  part of the allocator. It is fully analyzed and resolved when
  --  the allocator is resolved with the context type.
 
- Set_Etype  (E, Type_Id);
-
   --  Case where allocator has a subtype indication
 
   else
-- 
2.43.0



[COMMITTED 15/42] ada: Improve Warning_Treated_As_Error

2025-07-01 Thread Marc Poulhiès
From: Viljar Indus 

gcc/ada/ChangeLog:

* errout.adb (Error_Msg_Internal): Use the new
Warning_Treated_As_Error function.
* erroutc.adb (Get_Warning_Option): Add new version of this
function that operates on the Error_Msg_Object directly instead
of the Error_Id. Update the existing function to call the new
version interanlly.
(Get_Warning_Tag): Likewise.
(Warning_Treated_As_Error): Add a new method that combines the
checks for the error message itself and its tag.
* erroutc.ads (Get_Warning_Option): Add new spec.
(Get_Warning_Option): Likewise.
(Get_Warning_Option): Likewise.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/errout.adb  |  3 +--
 gcc/ada/erroutc.adb | 30 --
 gcc/ada/erroutc.ads |  8 +++-
 3 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
index 58ba6be6189..ae7df04b91f 100644
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -1417,8 +1417,7 @@ package body Errout is
 
   Errors.Table (Cur_Msg).Warn_Err :=
 Error_Msg_Kind in Warning | Style
-and then (Warning_Treated_As_Error (Msg_Buffer (1 .. Msglen))
-  or else Warning_Treated_As_Error (Get_Warning_Tag (Cur_Msg))
+and then (Warning_Treated_As_Error (Errors.Table (Cur_Msg))
   or else Is_Runtime_Raise);
 
   --  If immediate errors mode set, output error message now. Also output
diff --git a/gcc/ada/erroutc.adb b/gcc/ada/erroutc.adb
index fa4dcb80ff4..26988dc8488 100644
--- a/gcc/ada/erroutc.adb
+++ b/gcc/ada/erroutc.adb
@@ -361,11 +361,16 @@ package body Erroutc is

 
function Get_Warning_Option (Id : Error_Msg_Id) return String is
-  Is_Style : constant Boolean := Errors.Table (Id).Kind in Style;
-  Warn_Chr : constant String (1 .. 2) := Errors.Table (Id).Warn_Chr;
+   begin
+  return Get_Warning_Option (Errors.Table (Id));
+   end Get_Warning_Option;
+
+   function Get_Warning_Option (E : Error_Msg_Object) return String is
+  Is_Style : constant Boolean := E.Kind in Style;
+  Warn_Chr : constant String (1 .. 2) := E.Warn_Chr;
 
begin
-  if Has_Switch_Tag (Errors.Table (Id))
+  if Has_Switch_Tag (E)
 and then Warn_Chr (1) /= '?'
   then
  if Warn_Chr = "$ " then
@@ -387,11 +392,16 @@ package body Erroutc is
-
 
function Get_Warning_Tag (Id : Error_Msg_Id) return String is
-  Warn_Chr : constant String (1 .. 2) := Errors.Table (Id).Warn_Chr;
-  Option   : constant String  := Get_Warning_Option (Id);
+   begin
+  return Get_Warning_Tag (Errors.Table (Id));
+   end Get_Warning_Tag;
+
+   function Get_Warning_Tag (E : Error_Msg_Object) return String is
+  Warn_Chr : constant String (1 .. 2) := E.Warn_Chr;
+  Option   : constant String  := Get_Warning_Option (E);
 
begin
-  if Has_Switch_Tag (Id) then
+  if Has_Switch_Tag (E) then
  if Warn_Chr = "? " then
 return "[enabled by default]";
  elsif Warn_Chr = "* " then
@@ -2117,6 +2127,14 @@ package body Erroutc is
   return False;
end Warning_Treated_As_Error;
 
+   function Warning_Treated_As_Error (E : Error_Msg_Object) return Boolean is
+
+   begin
+  return
+Warning_Treated_As_Error (E.Text.all)
+or else Warning_Treated_As_Error (Get_Warning_Tag (E));
+   end Warning_Treated_As_Error;
+
-
-- Warnings_Suppressed --
-
diff --git a/gcc/ada/erroutc.ads b/gcc/ada/erroutc.ads
index b5d0578f99f..94fcddd84a4 100644
--- a/gcc/ada/erroutc.ads
+++ b/gcc/ada/erroutc.ads
@@ -626,11 +626,13 @@ package Erroutc is
--  are marked with the Deleted flag set to True.
 
function Get_Warning_Option (Id : Error_Msg_Id) return String;
+   function Get_Warning_Option (E : Error_Msg_Object) return String;
--  Returns the warning switch causing this warning message or an empty
--  string is there is none..
 
function Get_Warning_Tag (Id : Error_Msg_Id) return String;
-   --  Given an error message ID, return tag showing warning message class, or
+   function Get_Warning_Tag (E : Error_Msg_Object) return String;
+   --  Given an error message, return tag showing warning message class, or
--  the null string if this option is not enabled or this is not a warning.
 
procedure Increase_Error_Msg_Count (E : Error_Msg_Object);
@@ -872,6 +874,10 @@ package Erroutc is
--  given by Warning_As_Error pragmas, as stored in the Warnings_As_Errors
--  table.
 
+   function Warning_Treated_As_Error (E : Error_Msg_Object) return Boolean;
+   --  Returns true if a Warning_As_Error pragma matches either the error text
+   --  or the warning tag of the message.
+
procedure Write_Error_Summary;
--  Write error summary
 
-- 
2.43.0



[COMMITTED 36/42] ada: Fix for compiler crash on function return with Relaxed_Finalization parts

2025-07-01 Thread Marc Poulhiès
From: Gary Dismukes 

The compiler crashes on compiling a return statement of a function whose result
type has a component whose type is specified with Relaxed_Finalization. The
compiler was attempting to retrieve a nonexistent BIP_Collection extra formal
from the enclosing function, which may not exist in the case of result types
with Relaxed_Finalization.

gcc/ada/ChangeLog:

* exp_ch3.adb (Build_Heap_Or_Pool_Allocator): Test not 
Has_Relaxed_Finalization
as a guard against retrieving BIP_Collection formal (and related code).

Tested on x86_64-pc-linux-gnu, committed on master.

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

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 4e2bef32a35..7c18f81cb07 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -6981,7 +6981,9 @@ package body Exp_Ch3 is
 
  --  Processing for objects that require finalization actions
 
- if Needs_Finalization (Ret_Typ) then
+ if Needs_Finalization (Ret_Typ)
+   and then not Has_Relaxed_Finalization (Ret_Typ)
+ then
 declare
Decls   : constant List_Id := New_List;
Fin_Coll_Id : constant Entity_Id :=
-- 
2.43.0



[COMMITTED 14/42] ada: Remove Count_Compile_Time_Pragma_Warnings

2025-07-01 Thread Marc Poulhiès
From: Viljar Indus 

Use a live counter Compile_Time_Pragma_Warnings to keep track of
those messages instead of using a method to count them in the end.

gcc/ada/ChangeLog:

* atree.ads: Add Compile_Time_Pragma_Warnings for counting
compile time warnings.
* errout.adb (Initialize): Initialize Compile_Time_Pragma_Warnings.
(Output_Messages): Use Compile_Time_Pragma_Warnings instead of
Count_Compile_Time_Pragma_Warnings.
* erroutc.adb (Compilation_Errors): Likewise.
(Count_Compile_Time_Pragma_Warnings): Removed.
(Decrease_Error_Msg_Count): Update Compile_Time_Pragma_Warnings.
(Increase_Error_Msg_Count): Likewise.
(Write_Error_Summary): Use Compile_Time_Pragma_Warnings instead of
Count_Compile_Time_Pragma_Warnings.
* erroutc.ads (Count_Compile_Time_Pragma_Warnings): Removed.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/atree.ads   |  3 +++
 gcc/ada/errout.adb  | 19 ++-
 gcc/ada/erroutc.adb | 43 ++-
 gcc/ada/erroutc.ads |  4 
 4 files changed, 23 insertions(+), 46 deletions(-)

diff --git a/gcc/ada/atree.ads b/gcc/ada/atree.ads
index 802db870933..e17eecc04d0 100644
--- a/gcc/ada/atree.ads
+++ b/gcc/ada/atree.ads
@@ -175,6 +175,9 @@ package Atree is
--  Number of warnings changed into errors as a result of matching a pattern
--  given in a Warning_As_Error configuration pragma.
 
+   Compile_Time_Pragma_Warnings : Nat := 0;
+   --  Number of warnings that come from a Compile_Time_Warning pragma
+
Configurable_Run_Time_Violations : Nat := 0;
--  Count of configurable run time violations so far. This is used to
--  suppress certain cascaded error messages when we know that we may not
diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
index c1ceaf2815b..58ba6be6189 100644
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -2120,6 +2120,7 @@ package body Errout is
   Warnings_Treated_As_Errors := 0;
   Warnings_Detected := 0;
   Warnings_As_Errors_Count := 0;
+  Compile_Time_Pragma_Warnings := 0;
 
   --  Initialize warnings tables
 
@@ -3126,19 +3127,11 @@ package body Errout is
   end if;
 
   if Warning_Mode = Treat_As_Error then
- declare
-Compile_Time_Pragma_Warnings : constant Nat :=
-   Count_Compile_Time_Pragma_Warnings;
-Total : constant Int := Total_Errors_Detected + Warnings_Detected
-   - Compile_Time_Pragma_Warnings;
---  We need to protect against a negative Total here, because
---  if a pragma Compile_Time_Warning occurs in dead code, it
---  gets counted in Compile_Time_Pragma_Warnings but not in
---  Warnings_Detected.
- begin
-Total_Errors_Detected := Int'Max (Total, 0);
-Warnings_Detected := Compile_Time_Pragma_Warnings;
- end;
+ Total_Errors_Detected :=
+   Total_Errors_Detected
+   + Warnings_Detected
+   - Compile_Time_Pragma_Warnings;
+ Warnings_Detected := Compile_Time_Pragma_Warnings;
   end if;
end Output_Messages;
 
diff --git a/gcc/ada/erroutc.adb b/gcc/ada/erroutc.adb
index 26095520fa1..fa4dcb80ff4 100644
--- a/gcc/ada/erroutc.adb
+++ b/gcc/ada/erroutc.adb
@@ -237,10 +237,10 @@ package body Erroutc is
   --  Compile_Time_Warning pragma as an error. Warnings_Count is the sum
   --  of both "normal" and Compile_Time_Warning warnings. This means that
   --  there are only one or more non-Compile_Time_Warning warnings when
-  --  Warnings_Count is greater than Count_Compile_Time_Pragma_Warnings.
+  --  Warnings_Count is greater than Compile_Time_Pragma_Warnings.
 
   elsif Warning_Mode = Treat_As_Error
- and then Warnings_Count > Count_Compile_Time_Pragma_Warnings
+ and then Warnings_Count > Compile_Time_Pragma_Warnings
   then
  return True;
   end if;
@@ -248,26 +248,6 @@ package body Erroutc is
   return False;
end Compilation_Errors;
 
-   
-   -- Count_Compile_Time_Pragma_Warnings  --
-   
-
-   function Count_Compile_Time_Pragma_Warnings return Int is
-  Result : Int := 0;
-   begin
-  for J in 1 .. Errors.Last loop
- begin
-if Errors.Table (J).Kind = Warning
-   and then Errors.Table (J).Compile_Time_Pragma
-   and then not Errors.Table (J).Deleted
-then
-   Result := Result + 1;
-end if;
- end;
-  end loop;
-  return Result;
-   end Count_Compile_Time_Pragma_Warnings;
-
--
-- Decrease_Error_Msg_Count --
--
@@ -286,6 +266,11 @@ package body Erroutc is
Warnings_Treated_As_Errors := Warnings_Treated_As_Errors - 1;
 end if;
 
+

[COMMITTED 41/42] ada: Fix ALI elaboration flags for ghost compilation units

2025-07-01 Thread Marc Poulhiès
From: Piotr Trojanek 

When GNAT was compiling a ghost unit, the ALI file wrongly suggested that this
unit includes elaboration code, which caused linking errors to non-existing
elaboration counters. This was because elaboration code is only detected in
Gigi, which is skipped for ignored ghost units, because we don't generate
object code for them

gcc/ada/ChangeLog:

* gnat1drv.adb (Gnat1drv): Do minimal decoration of the spec and body
of an ignored ghost compilation unit.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/gnat1drv.adb | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/gnat1drv.adb b/gcc/ada/gnat1drv.adb
index ec57cd23731..52063c8067f 100644
--- a/gcc/ada/gnat1drv.adb
+++ b/gcc/ada/gnat1drv.adb
@@ -1352,7 +1352,15 @@ begin
 --  Exit the gnat driver with success, otherwise external builders
 --  such as gnatmake and gprbuild will treat the compilation of an
 --  ignored Ghost unit as a failure. Be sure we produce an empty
---  object file for the unit.
+--  object file for the unit, while indicating for the ALI file
+--  generation that neither spec or body has elaboration code
+--  (which in ordinary compilation is indicated in Gigi).
+
+Set_Has_No_Elaboration_Code (Main_Unit_Node);
+
+if Present (Library_Unit (Main_Unit_Node)) then
+   Set_Has_No_Elaboration_Code (Library_Unit (Main_Unit_Node));
+end if;
 
 Ecode := E_Success;
 Back_End.Gen_Or_Update_Object_File;
-- 
2.43.0



[COMMITTED 27/42] ada: Correct comment in s-valuen.ads

2025-07-01 Thread Marc Poulhiès
From: Aleksandra Pasek 

gcc/ada/ChangeLog:

* libgnat/s-valuen.ads: Correct comment.

Tested on x86_64-pc-linux-gnu, committed on master.

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

diff --git a/gcc/ada/libgnat/s-valuen.ads b/gcc/ada/libgnat/s-valuen.ads
index 047ded6204b..a57ee5567ac 100644
--- a/gcc/ada/libgnat/s-valuen.ads
+++ b/gcc/ada/libgnat/s-valuen.ads
@@ -30,8 +30,8 @@
 --
 
 --  This package is used to compute the Value attribute for enumeration types
---  other than those in packages Standard and System. See unit Exp_Imgv for
---  details of the format of constructed image tables.
+--  other than those in package Standard. See unit Exp_Imgv for details of the
+--  format of constructed image tables.
 
 generic
 
-- 
2.43.0



[COMMITTED 11/42] ada: Remove spurious warnings about No_Exception_Propagation in GNATprove mode

2025-07-01 Thread Marc Poulhiès
From: Martin Clochard 

gcc/ada/ChangeLog:

* frontend.adb (Frontend): do not override GNATprove's setting for
Warn_On_Non_Local_Exception

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/frontend.adb | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/frontend.adb b/gcc/ada/frontend.adb
index d5376788ce4..564f153c982 100644
--- a/gcc/ada/frontend.adb
+++ b/gcc/ada/frontend.adb
@@ -368,11 +368,12 @@ begin
   --  If we have restriction No_Exception_Propagation, and we did not have
   --  an explicit switch turning off Warn_On_Non_Local_Exception, then turn
   --  on this warning by default if we have encountered an exception
-  --  handler.
+  --  handler. We do not override the setting of GNATprove.
 
   if Restriction_Check_Required (No_Exception_Propagation)
 and then not No_Warn_On_Non_Local_Exception
 and then Exception_Handler_Encountered
+and then not GNATprove_Mode
   then
  Warn_On_Non_Local_Exception := True;
   end if;
-- 
2.43.0



[COMMITTED 26/42] ada: include string.h

2025-07-01 Thread Marc Poulhiès
From: Alexandre Oliva 

__gnat_install_handler calls strncmp when __HANDLE_VXSIM_SC is
defined, so string.h needs to be included, and gcc-14 enforces this
requirement.

gcc/ada/ChangeLog:

* init.c: Include string.h.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/init.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/ada/init.c b/gcc/ada/init.c
index 1be90ec5812..35b77736a60 100644
--- a/gcc/ada/init.c
+++ b/gcc/ada/init.c
@@ -47,6 +47,7 @@
 #ifdef __vxworks
 #include "vxWorks.h"
 #include "version.h" /* for _WRS_VXWORKS_MAJOR */
+#include  /* for strncmp */
 #endif
 
 #ifdef __ANDROID__
-- 
2.43.0



[COMMITTED 18/42] ada: Handle Warnings_As_Errors the same way.

2025-07-01 Thread Marc Poulhiès
From: Viljar Indus 

There are multiple scenarios where warnings can be turned into
errors. However internally they should always be handled the
same way and we should not rely on additional counters and variables
to handle the different behaviours.

These different types of converted warnings have however been
emitted differently historically. This information is stored in
the Warn_Err attribute which now stores the reason for the conversion
so that the printers know how to handle those scenarios.

Based on the reason these warnings are printed in different ways:
* If converted by pragma Warning_As_Error then it should print the
message with an error prefix and a [warning-as-error] tag.
* If it is a run time warning converted by -gnatwE then the message
should be printed with just an error prefix.
* if the warning was converted by -gnatwe then the message should be
printed with a warning prefix.

gcc/ada/ChangeLog:

* atree.ads (Compile_Time_Pragma_Warnings): Removed.
* errout.adb (Initialize): Remove initialization for
Compile_Time_Pragma_Warnings.
(Error_Msg_Internal): Use Warning_As_Error_Kind in the
Error_Msg_Object. Set its value based on the reason the
warning was changed to an error.
(Write_JSON_Span): Adjust the code for Warn_Err.
(Output_Messages): Update the calculation for actual warnings
and errors by just using Warnings_Treated_As_Errors.
(Set_Msg_Text): Simply mark that we are dealing with a
run time message here. Move the code for the Warning_Mode to
Error_Msg_Internal.
* erroutc-pretty_emitter.adb (Write_Error_Msg_Line): Adjust the code
for Warn_Err. Use the Warn_As_Err_Tag token.
* erroutc.adb (Compilation_Errors): Simplify the implementation so
that it only checks for errors and warnings treated as errors.
(Decrease_Error_Msg_Count): Remove the count for
Compile_Time_Pragma_Warnings.
(dmsg): Adjust the code for changes to Warn_Err.
(Increase_Error_Msg_Count): Likewise and remove the count for
Compile_Time_Pragma_Warnings.
(Output_Msg_Text): Warnings converted to error by the
Warning_As_Error pragma and -gnatwE now use the error prefix
in their messages but only warnings changed by the pragma get
the [warning-as-error] tag.
(Output_Text_Within): Adjust the variable name for
Is_Runtime_Raise_Msg.
(Write_Error_Summary): Adjust printing of warnings so that it
just uses the counts for Warnings_Detected and
Warnings_Treated_As_Errors.
* erroutc.ads (Is_Runtime_Raise): renamed to Is_Runtime_Raise_Msg.
(Warning_As_Error_Kind): New type for marking the warning message
is treated as an error which also captures the reason for the
change. Historically each of the reasons will have a different way
of displaying the warning message.
(Error_Msg_Object.Warn_Err): Change type to Warning_As_Error_Kind.
(Kind_To_String): Warnings treated as errors originating from
the pragma or -gnatwE will return error where as warnings
originating from -gnatwe will return warning.
(Compilation_Errors): Update the documentation.
(Warn_As_Err_Tag): Constant string to be used when printing warnings
as errors.
* errutil.adb (Error_Msg): Adjust the code for Warn_Err.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/atree.ads  |   3 -
 gcc/ada/errout.adb |  46 +-
 gcc/ada/erroutc-pretty_emitter.adb |   4 +-
 gcc/ada/erroutc.adb| 135 -
 gcc/ada/erroutc.ads|  40 ++---
 gcc/ada/errutil.adb|   4 +-
 6 files changed, 92 insertions(+), 140 deletions(-)

diff --git a/gcc/ada/atree.ads b/gcc/ada/atree.ads
index e17eecc04d0..802db870933 100644
--- a/gcc/ada/atree.ads
+++ b/gcc/ada/atree.ads
@@ -175,9 +175,6 @@ package Atree is
--  Number of warnings changed into errors as a result of matching a pattern
--  given in a Warning_As_Error configuration pragma.
 
-   Compile_Time_Pragma_Warnings : Nat := 0;
-   --  Number of warnings that come from a Compile_Time_Warning pragma
-
Configurable_Run_Time_Violations : Nat := 0;
--  Count of configurable run time violations so far. This is used to
--  suppress certain cascaded error messages when we know that we may not
diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
index ae7df04b91f..472fbbe6cb2 100644
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -1400,7 +1400,7 @@ package body Errout is
   Line=> Get_Physical_Line_Number (Sptr),
   Col => Get_Column_Number (Sptr),
   Compile_Time_Pragma => Is_Compile_Time_Msg,
-  Warn_Err=> False, -- reset below
+  Warn_Err=> None, -- reset below
   Wa

[COMMITTED 05/42] ada: Small cleanup in the finalization machinery

2025-07-01 Thread Marc Poulhiès
From: Eric Botcazou 

The generic finalization machinery and the finalization machinery for
transient objects disagree on which controlled objects should be finalized
indirectly, i.e. through an access value: the former only considers return
objects of (selected) function calls, whereas the latter considers all
objects designated by a reference, which means that it must be careful
about not finalizing them twice.

The discrepancy does not seem to cause problems in practice, but is awkward
and creates additional work for the finalization machinery for transient
objects, as well as code duplication.

gcc/ada/ChangeLog:

* exp_util.ads (Is_Finalizable_Access): New predicate.
(Is_Non_BIP_Func_Call): Delete.
(Is_Secondary_Stack_BIP_Func_Call): Likewise.
* exp_util.adb (Is_Finalizable_Access): New predicate.
(Initialized_By_Aliased_BIP_Func_Call): Delete.
(Initialized_By_Reference): Likewise.
(Is_Aliased): Only consider the nontransient object serviced by
the transient scope.
(Is_Part_Of_BIP_Return_Statement): Minor tweak.
(Is_Finalizable_Transient): Remove calls to Initialized_By_Reference
and Initialized_By_Aliased_BIP_Func_Call.
Call Is_Finalizable_Access for access objects.
(Is_Non_BIP_Func_Call): Delete.
(Is_Secondary_Stack_BIP_Func_Call): Likewise.
(Requires_Cleanup_Actions): Call Is_Finalizable_Access for access
objects.
(Side_Effect_Free): Return True for N_Reference.
* exp_ch7.adb (Build_Finalizer.Process_Declarations): Call
Is_Finalizable_Access for access objects.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch7.adb  |  17 +--
 gcc/ada/exp_util.adb | 348 +++
 gcc/ada/exp_util.ads |  15 +-
 3 files changed, 127 insertions(+), 253 deletions(-)

diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
index 1c569b90dd2..5fec6915997 100644
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -2466,7 +2466,6 @@ package body Exp_Ch7 is
  --  Local variables
 
  Decl: Node_Id;
- Expr: Node_Id;
  Obj_Id  : Entity_Id;
  Obj_Typ : Entity_Id;
  Pack_Id : Entity_Id;
@@ -2516,7 +2515,6 @@ package body Exp_Ch7 is
 elsif Nkind (Decl) = N_Object_Declaration then
Obj_Id  := Defining_Identifier (Decl);
Obj_Typ := Base_Type (Etype (Obj_Id));
-   Expr:= Expression (Decl);
 
--  Bypass any form of processing for objects which have their
--  finalization disabled. This applies only to objects at the
@@ -2572,21 +2570,10 @@ package body Exp_Ch7 is
   Processing_Actions
 (Decl, Strict => not Has_Relaxed_Finalization (Obj_Typ));
 
-   --  The object is of the form:
-   --Obj : Access_Typ := Non_BIP_Function_Call'reference;
-
-   --Obj : Access_Typ :=
-   --BIP_Function_Call (BIPalloc => 2, ...)'reference;
+   --  The object is an access-to-controlled that must be finalized
 
elsif Is_Access_Type (Obj_Typ)
- and then Needs_Finalization
-(Available_View (Designated_Type (Obj_Typ)))
- and then Present (Expr)
- and then
-   (Is_Secondary_Stack_BIP_Func_Call (Expr)
- or else
-   (Is_Non_BIP_Func_Call (Expr)
- and then not Is_Related_To_Func_Return (Obj_Id)))
+ and then Is_Finalizable_Access (Decl)
then
   Processing_Actions
 (Decl,
diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 0606db4edae..ffaf4541146 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -8869,6 +8869,83 @@ package body Exp_Util is
   and then Is_Return_Object (Defining_Entity (Par)));
end Is_Expression_Of_Func_Return;
 
+   ---
+   -- Is_Finalizable_Access --
+   ---
+
+   function Is_Finalizable_Access (Decl : Node_Id) return Boolean is
+  Obj   : constant Entity_Id := Defining_Identifier (Decl);
+  Typ   : constant Entity_Id := Base_Type (Etype (Obj));
+  Desig : constant Entity_Id := Available_View (Designated_Type (Typ));
+  Expr  : constant Node_Id   := Expression (Decl);
+
+  Secondary_Stack_Val : constant Uint :=
+UI_From_Int (BIP_Allocation_Form'Pos (Secondary_Stack));
+
+  Actual : Node_Id;
+  Call   : Node_Id;
+  Formal : Node_Id;
+  Param  : Node_Id;
+
+   begin
+  --  The prerequisite is a reference to a controlled object
+
+  if No (Expr)
+or else Nkind (Expr) /= N_Reference
+or else not Needs_Finalization (Desig)
+  then
+ return False;
+  end if;
+
+  Call := U

[COMMITTED 19/42] ada: Document sanitizers in mixed-language applications

2025-07-01 Thread Marc Poulhiès
From: Jose Ruiz 

gcc/ada/ChangeLog:

* doc/gnat_ugn/gnat_and_program_execution.rst: Add the
documentation about benefits of using sanitizers in
mixed-language applications.
* gnat_ugn.texi: Regenerate.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 .../gnat_ugn/gnat_and_program_execution.rst   |  55 +++-
 gcc/ada/gnat_ugn.texi | 298 +++---
 2 files changed, 239 insertions(+), 114 deletions(-)

diff --git a/gcc/ada/doc/gnat_ugn/gnat_and_program_execution.rst 
b/gcc/ada/doc/gnat_ugn/gnat_and_program_execution.rst
index 58c00e56f5c..031fafcfa5a 100644
--- a/gcc/ada/doc/gnat_ugn/gnat_and_program_execution.rst
+++ b/gcc/ada/doc/gnat_ugn/gnat_and_program_execution.rst
@@ -4186,7 +4186,7 @@ It can detect the following types of problems:
   Block5 (Block5'Last) := 5;  --  Outside the object
end Wrong_Size_Overlay;
 
-  If the code is built with the :switch:`-fsanitize=address` and :switch:`-g`` 
options,
+  If the code is built with the :switch:`-fsanitize=address` and :switch:`-g` 
options,
   the following error is shown at execution time:
 
 ::
@@ -4403,3 +4403,56 @@ detect the following types of problems:
 ::
 
 float_cast_overflow.adb:5:20: runtime error: 3.40282e+38 is outside 
the range of representable values of type 'integer'
+
+Sanitizers in mixed-language applications
+-
+
+Most of the checks performed by sanitizers operate at a global level, which
+means they can detect issues even when they span across language boundaries.
+This applies notably to:
+
+* All checks performed by the AddressSanitizer: wrong memory overlays, buffer
+  overflows, uses after lifetime, memory leaks. These checks apply globally,
+  regardless of where the objects are allocated or defined, or where they are
+  destroyed
+
+* Wrong alignment checks performed by the UndefinedBehaviorSanitizer. It will
+  check whether an object created in a given language is accessed in another
+  with an incompatible alignment
+
+An interesting case that highlights the benefit of global sanitization is a
+buffer overflow caused by a mismatch in language bindings. Consider the
+following C function, which allocates an array of 4 characters:
+
+  .. code-block:: c
+
+ char *get_str (void) {
+char *str = malloc (4 * sizeof (char));
+ }
+
+This function is then bound to Ada code, which incorrectly assumes the buffer
+is of size 5:
+
+  .. code-block:: ada
+
+ type Buffer is array (1 .. 5) of Character;
+
+ function Get_Str return access Buffer
+with Import => True, Convention => C, External_Name => "get_str";
+
+ Str : access Buffer := Get_Str;
+ Ch  : Character := S (S'Last);  -- Detected by AddressSanitizer 
as erroneous
+
+On the Ada side, accessing ``Str (5)`` appears valid because the array type
+declares five elements. However, the actual memory allocated in C only holds
+four. This mismatch is not detectable by Ada run-time checks, because Ada has
+no visibility into how the memory was allocated.
+
+However, the AddressSanitizer will detect the heap buffer overflow at runtime,
+halting execution and providing a clear diagnostic:
+
+::
+
+...
+SUMMARY: AddressSanitizer: heap-buffer-overflow buffer_overflow.adb:20 
in _ada_buffer_overflow
+...
diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi
index 977d80c9b5e..c706d8b555f 100644
--- a/gcc/ada/gnat_ugn.texi
+++ b/gcc/ada/gnat_ugn.texi
@@ -420,6 +420,7 @@ Sanitizers for Ada
 
 * AddressSanitizer:: 
 * UndefinedBehaviorSanitizer:: 
+* Sanitizers in mixed-language applications:: 
 
 Platform-Specific Information
 
@@ -22906,6 +22907,7 @@ features or low-level operations.
 @menu
 * AddressSanitizer:: 
 * UndefinedBehaviorSanitizer:: 
+* Sanitizers in mixed-language applications:: 
 
 @end menu
 
@@ -22953,7 +22955,7 @@ end Wrong_Size_Overlay;
 @end example
 @end quotation
 
-If the code is built with the @code{-fsanitize=address} and @code{-g`} options,
+If the code is built with the @code{-fsanitize=address} and @code{-g} options,
 the following error is shown at execution time:
 
 @quotation
@@ -23088,7 +23090,7 @@ SUMMARY: AddressSanitizer: 4 byte(s) leaked in 1 
allocation(s).
 @end quotation
 @end itemize
 
-@node UndefinedBehaviorSanitizer,,AddressSanitizer,Sanitizers for Ada
+@node UndefinedBehaviorSanitizer,Sanitizers in mixed-language 
applications,AddressSanitizer,Sanitizers for Ada
 @anchor{gnat_ugn/gnat_and_program_execution 
id65}@anchor{1ba}@anchor{gnat_ugn/gnat_and_program_execution 
undefinedbehaviorsanitizer}@anchor{1bb}
 @subsection UndefinedBehaviorSanitizer
 
@@ -23220,11 +23222,81 @@ float_cast_overflow.adb:5:20: runtime error: 
3.40282e+38 is outside the range of
 @end quotation
 @end itemize
 
+@node Sanitizers in mixed-language 
applications,,UndefinedBehaviorSanitizer,Sanitizers for Ada
+@anchor{gnat_ugn

  1   2   >