[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Correction régressions inline_sum_*

2025-02-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:760ecd9ae33669f076a0651174c32f271af778e3

commit 760ecd9ae33669f076a0651174c32f271af778e3
Author: Mikael Morin 
Date:   Fri Feb 14 18:55:55 2025 +0100

Correction régressions inline_sum_*

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

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index c8e5fa60067a..e8606846a4eb 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -8167,7 +8167,7 @@ late_set_loop_bounds (gfc_loopinfo *loop)
 }
 
   for (loop = loop->nested; loop; loop = loop->next)
-set_loop_bounds (loop);
+late_set_loop_bounds (loop);
 }


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Correction régression class_assign_4.f90

2025-02-15 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:3ba31387b9add5dcadb617191746e8a36304a0be

commit 3ba31387b9add5dcadb617191746e8a36304a0be
Author: Mikael Morin 
Date:   Sat Feb 15 18:29:16 2025 +0100

Correction régression class_assign_4.f90

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

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index e8606846a4eb..a17eef4243ff 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -3616,12 +3616,6 @@ get_class_info_from_ss (stmtblock_t * pre, gfc_ss *ss, 
tree *eltype,
  tmp2 = gfc_class_len_get (class_expr);
  gfc_add_modify (pre, tmp, tmp2);
}
-
-  if (rhs_function)
-   {
- tmp = gfc_class_data_get (class_expr);
- gfc_conv_descriptor_offset_set (pre, tmp, gfc_index_zero_node);
-   }
 }
   else if (rhs_ss->info->data.array.descriptor)
{


[gcc r15-7571] [PR tree-optimization/98028] Use relationship between operands to simplify SUB_OVERFLOW

2025-02-15 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:42a22b801d4ad654e420495fafc4d29d113f00eb

commit r15-7571-g42a22b801d4ad654e420495fafc4d29d113f00eb
Author: Jakub Jelinek 
Date:   Sat Feb 15 16:45:21 2025 -0700

[PR tree-optimization/98028] Use relationship between operands to simplify 
SUB_OVERFLOW

So this is a fairly old regression, but with all the ranger work that's been
done, it's become easy to resolve.

The basic idea here is to use known relationships between two operands of a
SUB_OVERFLOW IFN to statically compute the overflow state and ultimately 
allow
turning the IFN into simple arithmetic (or for the tests in this BZ elide 
the
arithmetic entirely).

The regression example is when the two inputs are known equal.  In that case
the subtraction will never overflow.But there's a few other cases we can
handle as well.

a == b -> never overflows
a > b  -> never overflows when A and B are unsigned
a >= b -> never overflows when A and B are unsigned
a < b  -> always overflows when A and B are unsigned

Bootstrapped and regression tested on x86, and regression tested on the 
usual
cross platforms.

This is Jakub's version of the vr-values.cc fix rather than Jeff's.

PR tree-optimization/98028
gcc/
* vr-values.cc (check_for_binary_op_overflow): Try to use a known
relationship betwen op0/op1 to statically determine overflow state.

gcc/testsuite
* gcc.dg/tree-ssa/pr98028.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/tree-ssa/pr98028.c | 26 ++
 gcc/vr-values.cc| 33 +
 2 files changed, 59 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr98028.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr98028.c
new file mode 100644
index ..4e371b692354
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr98028.c
@@ -0,0 +1,26 @@
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+unsigned f1(unsigned i, unsigned j) {
+  if (j != i) __builtin_unreachable();
+  return __builtin_sub_overflow_p(i, j, (unsigned)0);
+}
+
+unsigned f2(unsigned i, unsigned j) {
+  if (j > i) __builtin_unreachable();
+  return __builtin_sub_overflow_p(i, j, (unsigned)0);
+}
+
+unsigned f3(unsigned i, unsigned j) {
+  if (j >= i) __builtin_unreachable();
+  return __builtin_sub_overflow_p(i, j, (unsigned)0);
+}
+
+unsigned f4(unsigned i, unsigned j) {
+  if (j <= i) __builtin_unreachable();
+  return __builtin_sub_overflow_p(i, j, (unsigned)0);
+}
+
+/* { dg-final { scan-tree-dump-times "return 0" 3 optimized } } */
+/* { dg-final { scan-tree-dump-times "return 1" 1 optimized } } */
+/* { dg-final { scan-tree-dump-not "SUB_OVERFLOW" optimized } } */
+/* { dg-final { scan-tree-dump-not "IMAGPART_EXPR" optimized } } */
diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc
index ed590138fe8f..6603d90c392c 100644
--- a/gcc/vr-values.cc
+++ b/gcc/vr-values.cc
@@ -85,6 +85,20 @@ check_for_binary_op_overflow (range_query *query,
  enum tree_code subcode, tree type,
  tree op0, tree op1, bool *ovf, gimple *s = NULL)
 {
+  relation_kind rel = VREL_VARYING;
+  /* For subtraction see if relations could simplify it.  */
+  if (s
+  && subcode == MINUS_EXPR
+  && types_compatible_p (TREE_TYPE (op0), TREE_TYPE (op1)))
+{
+  rel = query->relation().query (s, op0, op1);
+  /* The result of the infinite precision subtraction of
+the same values will be always 0.  That will fit into any result
+type.  */
+  if (rel == VREL_EQ)
+return true;
+}
+
   int_range_max vr0, vr1;
   if (!query->range_of_expr (vr0, op0, s) || vr0.undefined_p ())
 vr0.set_varying (TREE_TYPE (op0));
@@ -96,6 +110,25 @@ check_for_binary_op_overflow (range_query *query,
   tree vr1min = wide_int_to_tree (TREE_TYPE (op1), vr1.lower_bound ());
   tree vr1max = wide_int_to_tree (TREE_TYPE (op1), vr1.upper_bound ());
 
+  /* If op1 is not negative, op0 - op1 in infinite precision for op0 >= op1
+ will be always in [0, op0] and so if vr0max - vr1min fits into type,
+ there won't be any overflow.  */
+  if ((rel == VREL_GT || rel == VREL_GE)
+  && tree_int_cst_sgn (vr1min) >= 0
+  && !arith_overflowed_p (MINUS_EXPR, type, vr0max, vr1min))
+return true;
+
+  /* If op1 is not negative, op0 - op1 in infinite precision for op0 < op1
+ will be always in [-inf, -1] and so will always overflow if type is
+ unsigned.  */
+  if (rel == VREL_LT
+  && tree_int_cst_sgn (vr1min) >= 0
+  && TYPE_UNSIGNED (type))
+{
+  *ovf = true;
+  return true;
+}
+
   *ovf = arith_overflowed_p (subcode, type, vr0min,
 subcode == MINUS_EXPR ? vr1max : vr1min);
   if (arith_overflowed_p (subcode, type, vr0max,


[gcc r15-7573] x86: Properly find the maximum stack slot alignment

2025-02-15 Thread H.J. Lu via Gcc-cvs
https://gcc.gnu.org/g:11902be7a57c0ccf03786aa0255fffaf0f54dbf9

commit r15-7573-g11902be7a57c0ccf03786aa0255fffaf0f54dbf9
Author: H.J. Lu 
Date:   Tue Mar 14 11:41:51 2023 -0700

x86: Properly find the maximum stack slot alignment

Don't assume that stack slots can only be accessed by stack or frame
registers.  We first find all registers defined by stack or frame
registers.  Then check memory accesses by such registers, including
stack and frame registers.

gcc/

PR target/109780
PR target/109093
* config/i386/i386.cc (ix86_update_stack_alignment): New.
(ix86_find_all_reg_use_1): Likewise.
(ix86_find_all_reg_use): Likewise.
(ix86_find_max_used_stack_alignment): Also check memory accesses
from registers defined by stack or frame registers.

gcc/testsuite/

PR target/109780
PR target/109093
* g++.target/i386/pr109780-1.C: New test.
* gcc.target/i386/pr109093-1.c: Likewise.
* gcc.target/i386/pr109780-1.c: Likewise.
* gcc.target/i386/pr109780-2.c: Likewise.
* gcc.target/i386/pr109780-3.c: Likewise.

Signed-off-by: H.J. Lu 

Diff:
---
 gcc/config/i386/i386.cc| 177 +
 gcc/testsuite/g++.target/i386/pr109780-1.C |  72 
 gcc/testsuite/gcc.target/i386/pr109093-1.c |  33 ++
 gcc/testsuite/gcc.target/i386/pr109780-1.c |  14 +++
 gcc/testsuite/gcc.target/i386/pr109780-2.c |  21 
 gcc/testsuite/gcc.target/i386/pr109780-3.c |  46 
 6 files changed, 342 insertions(+), 21 deletions(-)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 3128973ba79c..fafd4a511a3c 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -8466,6 +8466,107 @@ output_probe_stack_range (rtx reg, rtx end)
   return "";
 }
 
+/* Update the maximum stack slot alignment from memory alignment in
+   PAT.  */
+
+static void
+ix86_update_stack_alignment (rtx, const_rtx pat, void *data)
+{
+  /* This insn may reference stack slot.  Update the maximum stack slot
+ alignment.  */
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, pat, ALL)
+if (MEM_P (*iter))
+  {
+   unsigned int alignment = MEM_ALIGN (*iter);
+   unsigned int *stack_alignment
+ = (unsigned int *) data;
+   if (alignment > *stack_alignment)
+ *stack_alignment = alignment;
+   break;
+  }
+}
+
+/* Helper function for ix86_find_all_reg_use.  */
+
+static void
+ix86_find_all_reg_use_1 (rtx set, HARD_REG_SET &stack_slot_access,
+auto_bitmap &worklist)
+{
+  rtx dest = SET_DEST (set);
+  if (!REG_P (dest))
+return;
+
+  rtx src = SET_SRC (set);
+  if (MEM_P (src) || CONST_SCALAR_INT_P (src))
+return;
+
+  if (TEST_HARD_REG_BIT (stack_slot_access, REGNO (dest)))
+return;
+
+  /* Add this register to stack_slot_access.  */
+  add_to_hard_reg_set (&stack_slot_access, Pmode, REGNO (dest));
+  bitmap_set_bit (worklist, REGNO (dest));
+}
+
+/* Find all registers defined with REG.  */
+
+static void
+ix86_find_all_reg_use (HARD_REG_SET &stack_slot_access,
+  unsigned int reg, auto_bitmap &worklist)
+{
+  for (df_ref ref = DF_REG_USE_CHAIN (reg);
+   ref != NULL;
+   ref = DF_REF_NEXT_REG (ref))
+{
+  if (DF_REF_IS_ARTIFICIAL (ref))
+   continue;
+
+  rtx_insn *insn = DF_REF_INSN (ref);
+
+  if (!NONJUMP_INSN_P (insn))
+   continue;
+
+  rtx set = single_set (insn);
+  if (set)
+   ix86_find_all_reg_use_1 (set, stack_slot_access, worklist);
+
+  rtx pat = PATTERN (insn);
+  if (GET_CODE (pat) != PARALLEL)
+   continue;
+
+  for (int i = 0; i < XVECLEN (pat, 0); i++)
+   {
+ rtx exp = XVECEXP (pat, 0, i);
+ switch (GET_CODE (exp))
+   {
+   case ASM_OPERANDS:
+   case CLOBBER:
+   case PREFETCH:
+   case USE:
+ break;
+   case UNSPEC:
+   case UNSPEC_VOLATILE:
+ for (int j = XVECLEN (exp, 0) - 1; j >= 0; j--)
+   {
+ rtx x = XVECEXP (exp, 0, j);
+ if (GET_CODE (x) == SET)
+   ix86_find_all_reg_use_1 (x, stack_slot_access,
+worklist);
+   }
+ break;
+   case SET:
+ ix86_find_all_reg_use_1 (exp, stack_slot_access,
+  worklist);
+ break;
+   default:
+ gcc_unreachable ();
+ break;
+   }
+   }
+}
+}
+
 /* Set stack_frame_required to false if stack frame isn't required.
Update STACK_ALIGNMENT to the largest alignment, in bits, of stack
slot used if stack frame is required and CHECK_STACK_SLOT is true.  */
@@ -8484,10 +8585,6 @@ ix86_find_max_used_stack_al

[gcc r15-7564] sarif-replay: handle the 'fixes' property (§3.27.30)

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

commit r15-7564-gd0d5204afff226ffc5d329b8e4734dda081dd9b4
Author: David Malcolm 
Date:   Sat Feb 15 08:18:19 2025 -0500

sarif-replay: handle the 'fixes' property (§3.27.30)

This adds support to sarif-replay to display fix-it hints
stored in GCC's SARIF output.

gcc/ChangeLog:
* libsarifreplay.cc (sarif_replayer::handle_result_obj): Call
handle_fix_object if we see a single-element "fixes" array.
(sarif_replayer::handle_fix_object): New.
(sarif_replayer::handle_artifact_change_object): New.

gcc/testsuite/ChangeLog:
* sarif-replay.dg/2.1.0-valid/3.27.30-fixes-1.sarif: New test.
* sarif-replay.dg/2.1.0-valid/3.27.30-fixes-2.sarif: New test.
* sarif-replay.dg/2.1.0-valid/3.27.30-fixes-3.sarif: New test.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/libsarifreplay.cc  | 117 -
 .../2.1.0-valid/3.27.30-fixes-1.sarif  |  55 ++
 .../2.1.0-valid/3.27.30-fixes-2.sarif  |  39 +++
 .../2.1.0-valid/3.27.30-fixes-3.sarif  |  39 +++
 4 files changed, 248 insertions(+), 2 deletions(-)

diff --git a/gcc/libsarifreplay.cc b/gcc/libsarifreplay.cc
index 21d8e6ce7cf7..cc051dcd485c 100644
--- a/gcc/libsarifreplay.cc
+++ b/gcc/libsarifreplay.cc
@@ -346,6 +346,16 @@ private:
   lookup_rule_by_id_in_component (const char *rule_id,
  const json::object &tool_component_obj);
 
+  // "fix" object (§3.55)
+  enum status
+  handle_fix_object (libgdiagnostics::diagnostic &diag,
+const json::object &fix_obj);
+
+  // "artifactChange" object (§3.56)
+  enum status
+  handle_artifact_change_object (libgdiagnostics::diagnostic &diag,
+const json::object &change_obj);
+
   /* Support functions.  */
 
   /* Report an error to m_control_mgr about JV violating REF,
@@ -1012,7 +1022,6 @@ should_add_rule_p (const char *rule_id_str, const char 
*url)
- doesn't yet handle "taxa" property (§3.27.8)
- handling of "level" property (§3.27.10) doesn't yet support the
  full logic for when "level" is absent.
-   - doesn't yet handle "fixes" property (§3.27.30)
- doesn't yet support multithreaded flows (§3.36.3)
 */
 
@@ -1200,6 +1209,17 @@ sarif_replayer::handle_result_obj (const json::object 
&result_obj,
}
 }
 
+  // §3.27.30 "fixes" property
+  const property_spec_ref prop_fixes ("result", "fixes", "3.27.30");
+  if (auto fixes_arr
+  = get_optional_property (result_obj, prop_fixes))
+{
+  // We only support a single fix
+  if (fixes_arr->length () == 1)
+   if (auto fix_obj = require_object (*fixes_arr->get (0), prop_fixes))
+ handle_fix_object (err, *fix_obj);
+}
+
   err.finish ("%s", text.get ());
 
   // Flush any notes
@@ -1211,7 +1231,6 @@ sarif_replayer::handle_result_obj (const json::object 
&result_obj,
 }
 
   return status::ok;
-
 }
 
 /*  If ITER_SRC starts with a placeholder as per §3.11.5, advance ITER_SRC
@@ -2049,6 +2068,100 @@ lookup_rule_by_id_in_component (const char *rule_id,
   return nullptr;
 }
 
+// "fix" object (§3.55)
+
+enum status
+sarif_replayer::handle_fix_object (libgdiagnostics::diagnostic &diag,
+  const json::object &fix_obj)
+{
+  const property_spec_ref changes ("fix", "artifactChanges", "3.55.3");
+  auto changes_arr = get_required_property (fix_obj, changes);
+  if (!changes_arr)
+return status::err_invalid_sarif;
+
+  for (auto element : *changes_arr)
+{
+  const json::object *change_obj
+   = require_object_for_element (*element, changes);
+  if (!change_obj)
+   return status::err_invalid_sarif;
+  enum status s = handle_artifact_change_object (diag, *change_obj);
+  if (s != status::ok)
+   return s;
+}
+  return status::ok;
+}
+
+// "artifactChange" object (§3.56)
+
+enum status
+sarif_replayer::
+handle_artifact_change_object (libgdiagnostics::diagnostic &diag,
+  const json::object &change_obj)
+{
+  const property_spec_ref location
+("artifactChange", "artifactLocation", "3.56.2");
+  auto artifact_loc_obj
+= get_required_property (change_obj, location);
+  if (!artifact_loc_obj)
+return status::err_invalid_sarif;
+
+  libgdiagnostics::file file;
+  enum status s = handle_artifact_location_object (*artifact_loc_obj, file);
+  if (s != status::ok)
+return s;
+
+  const property_spec_ref replacements
+("artifactChange", "replacements", "3.56.3");
+  auto replacements_arr
+= get_required_property (change_obj, replacements);
+  if (!replacements_arr)
+return status::err_invalid_sarif;
+  for (auto element : *replacements_arr)
+{
+  // 3.57 replacement object
+  const json::object *replacement_obj
+   = require_object_for_element (*elemen

[gcc r15-7565] RISC-V: testsuite: Fix reduc-[89].c again.

2025-02-15 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:ad3de70fd863e32ea6440bcb613ffe2c58c2dae8

commit r15-7565-gad3de70fd863e32ea6440bcb613ffe2c58c2dae8
Author: Robin Dapp 
Date:   Sat Feb 15 08:44:51 2025 -0700

RISC-V: testsuite: Fix reduc-[89].c again.

my last fix wasn't sufficient.  This patch just scans for the scalar
insns now.

Going to commit as obvious if the CI is happy.

Regards
 Robin

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/reduc/reduc-8.c: Scan for add.
* gcc.target/riscv/rvv/autovec/reduc/reduc-9.c: Scan for fadd.

Diff:
---
 gcc/testsuite/gcc.target/riscv/rvv/autovec/reduc/reduc-8.c | 2 +-
 gcc/testsuite/gcc.target/riscv/rvv/autovec/reduc/reduc-9.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/reduc/reduc-8.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/reduc/reduc-8.c
index 518f0c33cc4e..1e5dc236a184 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/reduc/reduc-8.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/reduc/reduc-8.c
@@ -12,4 +12,4 @@ add_loop (int *x, int n, int res)
   return res;
 }
 
-/* { dg-final { scan-assembler-times 
{vslide1up\.vx\s+v[0-9]+,\s*v[0-9]+,\s*[a-x0-9]+} 1 } } */
+/* { dg-final { scan-assembler-times {add\s+[a-x0-9]+,\s*[a-x0-9]+,a2} 1 } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/reduc/reduc-9.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/reduc/reduc-9.c
index a5bb8dcccb81..b5a1e8de0094 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/reduc/reduc-9.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/reduc/reduc-9.c
@@ -12,4 +12,4 @@ add_loop (float *x, int n, float res)
   return res;
 }
 
-/* { dg-final { scan-assembler-times 
{vfslide1up\.vf\s+v[0-9]+,\s*v[0-9]+,\s*[a-x0-9]+} 1 } } */
+/* { dg-final { scan-assembler-times {fadd\.s\s+f[a-x0-9]+,\s*f[a-x0-9]+,fa0} 
1 } } */


[gcc r15-7566] [PATCH] RISC-V: testsuite: Adjust pr117722.c scan.

2025-02-15 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:f9868e623fc80c6c6260c9dc6c7280db90433207

commit r15-7566-gf9868e623fc80c6c6260c9dc6c7280db90433207
Author: Robin Dapp 
Date:   Sat Feb 15 08:48:06 2025 -0700

[PATCH] RISC-V: testsuite: Adjust pr117722.c scan.

the test scanned for vmin and vmax instead of vminu and vmaxu.
This patch fixes that.

Will commit as obvious once the CI is OK with it.

Regards
 Robin

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/pr117722.c: Scan for vminu and
vmaxu.

Diff:
---
 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr117722.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr117722.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr117722.c
index b675930818e1..f255ceb2cee6 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr117722.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr117722.c
@@ -18,6 +18,6 @@ int pixel_sad_n(unsigned char *pix1, unsigned char *pix2, int 
n)
   return sum;
 }
 
-/* { dg-final { scan-assembler {vmin\.v} } } */
-/* { dg-final { scan-assembler {vmax\.v} } } */
+/* { dg-final { scan-assembler {vminu\.v} } } */
+/* { dg-final { scan-assembler {vmaxu\.v} } } */
 /* { dg-final { scan-assembler {vsub\.v} } } */


[gcc r15-7553] libstdc++: Combine three tests into one

2025-02-15 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:08f70200ce01eea42eed7c6fcdcf300a8812be95

commit r15-7553-g08f70200ce01eea42eed7c6fcdcf300a8812be95
Author: Jonathan Wakely 
Date:   Wed Feb 12 19:52:01 2025 +

libstdc++: Combine three tests into one

Instead of a test with { target c++11_only } and another with
c++14_only and another with c++17 we can have a single test that uses
{ target c++11 }. This avoids needing to make edits to three very
similar tests.

Also fix the signatures for std::cbegin and std::cend which had the
wrong expression in the trailing-return-type and were missing their
constexpr and conditional noexcept (which were always present even in
C++14). That was wrong in two files, but now only needs to be fixed in
one place!

libstdc++-v3/ChangeLog:

* testsuite/24_iterators/headers/iterator/range_access_c++11.cc:
Removed.
* testsuite/24_iterators/headers/iterator/range_access_c++14.cc:
Removed.
* testsuite/24_iterators/headers/iterator/range_access_c++17.cc:
Removed.
* testsuite/24_iterators/headers/iterator/range_access.cc:
New test.

Diff:
---
 .../24_iterators/headers/iterator/range_access.cc  | 107 +
 .../headers/iterator/range_access_c++11.cc |  40 
 .../headers/iterator/range_access_c++14.cc |  64 
 .../headers/iterator/range_access_c++17.cc |  63 
 4 files changed, 107 insertions(+), 167 deletions(-)

diff --git 
a/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access.cc 
b/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access.cc
new file mode 100644
index ..23676ad1d7a3
--- /dev/null
+++ b/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access.cc
@@ -0,0 +1,107 @@
+// { dg-do compile { target c++11 } }
+
+// Copyright (C) 2010-2025 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library 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.
+
+// This library 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 this library; see the file COPYING3.  If not see
+// .
+
+#include 
+
+#ifdef _GLIBCXX_RELEASE
+// Conditional noexcept on these functions is a libstdc++ extension
+# define NOTHROW(F) noexcept(noexcept(c.F()))
+#else
+# define NOTHROW(F)
+#endif
+
+#if __cplusplus >= 201703L
+# define CONSTEXPR_17 constexpr
+#else
+# define CONSTEXPR_17
+#endif
+
+#if __cplusplus >= 201402L
+# define CONSTEXPR_14 constexpr
+#else
+# define CONSTEXPR_14
+#endif
+
+namespace std
+{
+  template
+CONSTEXPR_17 auto
+begin(C& c) NOTHROW(begin) -> decltype(c.begin());
+  template
+CONSTEXPR_17 auto
+begin(const C& c) NOTHROW(begin) -> decltype(c.begin());
+
+  template
+CONSTEXPR_17 auto
+end(C& c) NOTHROW(end) -> decltype(c.end());
+  template
+CONSTEXPR_17 auto
+end(const C& c) NOTHROW(end) -> decltype(c.end());
+
+  template
+CONSTEXPR_14 T*
+begin(T (&array)[N]) noexcept;
+  template
+CONSTEXPR_14 T*
+end(T (&array)[N]) noexcept;
+
+#if __cplusplus >= 201402L
+  template
+constexpr auto
+cbegin(const C& c) noexcept(noexcept(std::begin(c))) -> 
decltype(c.begin());
+  template
+constexpr auto
+cend(const C& c) noexcept(noexcept(std::end(c)))-> decltype(c.end());
+
+  template
+CONSTEXPR_17 auto
+rbegin(C& c) -> decltype(c.rbegin());
+  template
+CONSTEXPR_17 auto
+rbegin(const C& c) -> decltype(c.rbegin());
+
+  template
+CONSTEXPR_17 auto
+rend(C& c) -> decltype(c.rend());
+  template
+CONSTEXPR_17 auto
+rend(const C& c) -> decltype(c.rend());
+
+  template
+CONSTEXPR_17 reverse_iterator
+rbegin(T (&array)[N]) noexcept;
+  template
+CONSTEXPR_17 reverse_iterator
+rend(T (&array)[N]) noexcept;
+
+  template
+CONSTEXPR_17 reverse_iterator
+rbegin(initializer_list) noexcept;
+  template
+CONSTEXPR_17 reverse_iterator
+rend(initializer_list) noexcept;
+
+  template
+CONSTEXPR_17 auto
+crbegin(const C& c) -> decltype(std::rbegin(c));
+  template
+CONSTEXPR_17 auto
+cend(const C& c) -> decltype(std::rend(c));
+#endif // C++14
+}
diff --git 
a/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access_c++11.cc 
b/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access_c++11.cc
deleted file mode 100644
index 50f580531120..
--- a/libstdc++-v3/testsuite/24_iterators/headers/ite

[gcc r15-7554] libstdc++: Add conditional noexcept to remaining range access functions

2025-02-15 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:7bc72a3d209d60803ac7a8ea8d725dcc2c747259

commit r15-7554-g7bc72a3d209d60803ac7a8ea8d725dcc2c747259
Author: Jonathan Wakely 
Date:   Wed Feb 12 19:43:05 2025 +

libstdc++: Add conditional noexcept to remaining range access functions

Add conditional noexcept to the remaining range access functions that
were not changed in r15-5669-g8692cb10e82e72. This is now being proposed
for C++26 by P3623R0 (not published yet).

libstdc++-v3/ChangeLog:

* include/bits/range_access.h (rbegin, rend, crbegin, crend):
Add conditional noexcept, as per P3623R0.
* testsuite/24_iterators/headers/iterator/range_access.cc: Add
noexcept-specifier to rbegin, rend, crbegin and crend
declarations.

Diff:
---
 libstdc++-v3/include/bits/range_access.h   | 18 --
 .../24_iterators/headers/iterator/range_access.cc  | 22 +++---
 2 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/libstdc++-v3/include/bits/range_access.h 
b/libstdc++-v3/include/bits/range_access.h
index 9295c0fa2ade..e0afee41f090 100644
--- a/libstdc++-v3/include/bits/range_access.h
+++ b/libstdc++-v3/include/bits/range_access.h
@@ -153,7 +153,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 [[__nodiscard__, __gnu__::__always_inline__]]
 inline _GLIBCXX17_CONSTEXPR auto
-rbegin(_Container& __cont) -> decltype(__cont.rbegin())
+rbegin(_Container& __cont) noexcept(noexcept(__cont.rbegin()))
+  -> decltype(__cont.rbegin())
 { return __cont.rbegin(); }
 
   /**
@@ -164,7 +165,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 [[__nodiscard__, __gnu__::__always_inline__]]
 inline _GLIBCXX17_CONSTEXPR auto
-rbegin(const _Container& __cont) -> decltype(__cont.rbegin())
+rbegin(const _Container& __cont) noexcept(noexcept(__cont.rbegin()))
+  -> decltype(__cont.rbegin())
 { return __cont.rbegin(); }
 
   /**
@@ -175,7 +177,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 [[__nodiscard__, __gnu__::__always_inline__]]
 inline _GLIBCXX17_CONSTEXPR auto
-rend(_Container& __cont) -> decltype(__cont.rend())
+rend(_Container& __cont) noexcept(noexcept(__cont.rend()))
+  -> decltype(__cont.rend())
 { return __cont.rend(); }
 
   /**
@@ -186,7 +189,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 [[__nodiscard__, __gnu__::__always_inline__]]
 inline _GLIBCXX17_CONSTEXPR auto
-rend(const _Container& __cont) -> decltype(__cont.rend())
+rend(const _Container& __cont) noexcept(noexcept(__cont.rend()))
+  -> decltype(__cont.rend())
 { return __cont.rend(); }
 
   /**
@@ -241,7 +245,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 [[__nodiscard__, __gnu__::__always_inline__]]
 inline _GLIBCXX17_CONSTEXPR auto
-crbegin(const _Container& __cont) -> decltype(std::rbegin(__cont))
+crbegin(const _Container& __cont) noexcept(noexcept(std::rbegin(__cont)))
+  -> decltype(std::rbegin(__cont))
 { return std::rbegin(__cont); }
 
   /**
@@ -252,7 +257,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 [[__nodiscard__, __gnu__::__always_inline__]]
 inline _GLIBCXX17_CONSTEXPR auto
-crend(const _Container& __cont) -> decltype(std::rend(__cont))
+crend(const _Container& __cont) noexcept(noexcept(std::rend(__cont)))
+  -> decltype(std::rend(__cont))
 { return std::rend(__cont); }
 
 #endif // C++14
diff --git 
a/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access.cc 
b/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access.cc
index 23676ad1d7a3..982cb16f79ba 100644
--- a/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access.cc
+++ b/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access.cc
@@ -21,7 +21,7 @@
 
 #ifdef _GLIBCXX_RELEASE
 // Conditional noexcept on these functions is a libstdc++ extension
-# define NOTHROW(F) noexcept(noexcept(c.F()))
+# define NOTHROW(F) noexcept(noexcept(F))
 #else
 # define NOTHROW(F)
 #endif
@@ -42,17 +42,17 @@ namespace std
 {
   template
 CONSTEXPR_17 auto
-begin(C& c) NOTHROW(begin) -> decltype(c.begin());
+begin(C& c) NOTHROW(c.begin()) -> decltype(c.begin());
   template
 CONSTEXPR_17 auto
-begin(const C& c) NOTHROW(begin) -> decltype(c.begin());
+begin(const C& c) NOTHROW(c.begin()) -> decltype(c.begin());
 
   template
 CONSTEXPR_17 auto
-end(C& c) NOTHROW(end) -> decltype(c.end());
+end(C& c) NOTHROW(c.end()) -> decltype(c.end());
   template
 CONSTEXPR_17 auto
-end(const C& c) NOTHROW(end) -> decltype(c.end());
+end(const C& c) NOTHROW(c.end()) -> decltype(c.end());
 
   template
 CONSTEXPR_14 T*
@@ -71,17 +71,17 @@ namespace std
 
   template
 CONSTEXPR_17 auto
-rbegin(C& c) -> decltype(c.rbegin());
+rbegin(C& c) NOTHROW(c.rbegin()) -> decltype(c.rbegin());
   template
 CONSTEXPR_17 auto
-rbegin(const C& c) -> decltype(c.rbegin());
+

[gcc r15-7555] libstdc++: Simplify and comment std::jthread extension [PR100612]

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

commit r15-7555-ge9ed0a05fddaba4e5257beaddb7cbaf31607a784
Author: Jonathan Wakely 
Date:   Thu Feb 13 00:26:27 2025 +

libstdc++: Simplify and comment std::jthread extension [PR100612]

Use a requires-clause on the partial specialization of the
__pmf_expects_stop_token variable template, which is used for the
extension that allows constructing std::jthread with a
pointer-to-member-function that accepts a std::stop_token argument.

Also add a comment referring to the related Bugzilla PR.

libstdc++-v3/ChangeLog:

PR libstdc++/100612
* include/std/thread (__pmf_expects_stop_token): Constrain
variable template specialization with concept. Add comment.

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

diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread
index 7ded2a7aea43..d2f91ad89953 100644
--- a/libstdc++-v3/include/std/thread
+++ b/libstdc++-v3/include/std/thread
@@ -123,13 +123,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// @cond undocumented
 #ifndef __STRICT_ANSI__
+// As an extension we support invoking a pointer-to-member-function that
+// expects a stop_token as the first argument. See PR libstdc++/100612.
 template
   constexpr bool __pmf_expects_stop_token = false;
 
 template
+  requires is_member_function_pointer_v>
   constexpr bool __pmf_expects_stop_token<_Callable, _Obj, _Args...>
-   = __and_>,
-is_invocable<_Callable, _Obj, stop_token, _Args...>>::value;
+   = is_invocable_v<_Callable, _Obj, stop_token, _Args...>;
 #endif
 /// @endcond


[gcc r15-7556] libstdc++: Remove unused header from

2025-02-15 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:7698d2079ba7eb37b0cd7f7bb04f7c956da9db08

commit r15-7556-g7698d2079ba7eb37b0cd7f7bb04f7c956da9db08
Author: Jonathan Wakely 
Date:   Thu Feb 13 10:33:50 2025 +

libstdc++: Remove unused header from 

libstdc++-v3/ChangeLog:

* include/bits/shared_ptr_base.h: Do not include .

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

diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h 
b/libstdc++-v3/include/bits/shared_ptr_base.h
index 0e60408cc8db..053857b4c29f 100644
--- a/libstdc++-v3/include/bits/shared_ptr_base.h
+++ b/libstdc++-v3/include/bits/shared_ptr_base.h
@@ -61,7 +61,6 @@
 #include 
 #include 
 #if __cplusplus >= 202002L
-# include   // __bit_floor
 # include 
 # include  // std::align
 # include 


[gcc r15-7551] nvptx: Tag 'gcc/config/nvptx/nvptx.cc:nvptx_record_needed_fndecl' as 'static'

2025-02-15 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:8f386aadec70624f13b48dfddc4a8f689ccc505f

commit r15-7551-g8f386aadec70624f13b48dfddc4a8f689ccc505f
Author: Thomas Schwinge 
Date:   Mon Dec 19 15:05:53 2022 +0100

nvptx: Tag 'gcc/config/nvptx/nvptx.cc:nvptx_record_needed_fndecl' as 
'static'

As of Subversion r231013 (Git commit 
00e5241831c1227615a45b7bcba29c393671cb3f)
"[PTX] Another libcall patch", only used 'nvptx_record_needed_fndecl' is
locally.

gcc/
* config/nvptx/nvptx.cc (nvptx_record_needed_fndecl): Tag as
'static'.

Diff:
---
 gcc/config/nvptx/nvptx.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index af952a29796d..64de2b1cc9be 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -1220,7 +1220,7 @@ nvptx_record_libfunc (rtx callee, rtx retval, rtx pat)
is prototyped, record it now.  Otherwise record it as needed at end
of compilation, when we might have more information about it.  */
 
-void
+static void
 nvptx_record_needed_fndecl (tree decl)
 {
   if (TYPE_ARG_TYPES (TREE_TYPE (decl)) == NULL_TREE)


[gcc r15-7552] Fix PR 118884, Lapack build failure.

2025-02-15 Thread Thomas Kテカnig via Gcc-cvs
https://gcc.gnu.org/g:fd00010ba21c04bddb20aef52f62de5636075067

commit r15-7552-gfd00010ba21c04bddb20aef52f62de5636075067
Author: Thomas Koenig 
Date:   Sat Feb 15 11:38:05 2025 +0100

Fix PR 118884, Lapack build failure.

The fix for PR 118845 introduced new checks, which in turn exposed
a case where the typespec information on a symbol generated symbol
was not set.  This led to an apparent type of BT_UNKNOWN, and hence
an error.  Fixed as obvoius and simple.

gcc/fortran/ChangeLog:

* frontend-passes.cc (check_externals_procedure): Copy
typespec from old to new symbol.

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/fortran/frontend-passes.cc |  1 +
 gcc/testsuite/gfortran.dg/interface_54.f90 | 12 
 2 files changed, 13 insertions(+)

diff --git a/gcc/fortran/frontend-passes.cc b/gcc/fortran/frontend-passes.cc
index 6b470b83e21a..20bf6e127ffc 100644
--- a/gcc/fortran/frontend-passes.cc
+++ b/gcc/fortran/frontend-passes.cc
@@ -5727,6 +5727,7 @@ check_externals_procedure (gfc_symbol *sym, locus *loc,
   gcc_assert (new_sym);
   new_sym->attr = sym->attr;
   new_sym->attr.if_source = IFSRC_DECL;
+  new_sym->ts = sym->ts;
   gfc_current_ns = gsym->ns;
 
   gfc_get_formal_from_actual_arglist (new_sym, actual);
diff --git a/gcc/testsuite/gfortran.dg/interface_54.f90 
b/gcc/testsuite/gfortran.dg/interface_54.f90
new file mode 100644
index ..98318cae8881
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/interface_54.f90
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! PR 118884 - this used to be rejected due to confused interface
+! checking.
+
+subroutine cget24
+  external cslect
+  logical cslect
+
+  call cgeesx(cslect)
+  if( cslect() ) print *,"foo"
+  call cgeesx(cslect)
+end subroutine cget24


[gcc r15-7567] [PATCH] rx: allow cmpstrnsi len to be zero

2025-02-15 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:11cc336eed42892b7cfc2bfcf7b3f3f86f61787a

commit r15-7567-g11cc336eed42892b7cfc2bfcf7b3f3f86f61787a
Author: Keith Packard 
Date:   Sat Feb 15 09:17:41 2025 -0700

[PATCH] rx: allow cmpstrnsi len to be zero

The SCMPU instruction doesn't change the C and Z flags when the
incoming length is zero, which means the insn will produce a
value based upon the existing flag values.

As a quick kludge, adjust these flags to ensure a zero result in this
case.

gcc/
* config/rx/rx.md (rx_cmpstrn): Correctly handle len=0 case.

Diff:
---
 gcc/config/rx/rx.md | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/config/rx/rx.md b/gcc/config/rx/rx.md
index 89211585c9ce..edb2c96603f5 100644
--- a/gcc/config/rx/rx.md
+++ b/gcc/config/rx/rx.md
@@ -2590,7 +2590,9 @@
(clobber (reg:SI 3))
(clobber (reg:CC CC_REG))]
   "rx_allow_string_insns"
-  "scmpu   ; Perform the string comparison
+  "setpsw  z   ; Set flags in case len is zero
+   setpsw  c
+   scmpu   ; Perform the string comparison
mov #-1, %0  ; Set up -1 result (which cannot be created
 ; by the SC insn)
bnc?+   ; If Carry is not set skip over


[gcc r15-7568] [PATCH] RISC-V: Fix some widen-complicate tests.

2025-02-15 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:d7a835a5309db81a129b0151c7e5deb25b0ec55c

commit r15-7568-gd7a835a5309db81a129b0151c7e5deb25b0ec55c
Author: Robin Dapp 
Date:   Sat Feb 15 09:21:34 2025 -0700

[PATCH] RISC-V: Fix some widen-complicate tests.

this patch adds two bridge patterns for combine in order to fix the
widen-complicate tests that regressed since GCC 14.

They key is to allow combination with a ephemeral binary-operation insn
that widens its first operand.  This can subsequently be combined two
a double-widening insn.  If the combination doesn't happen we fall back
to the original non-combined two insns.  We have been doing the same
thing for multiply-add patterns for a while.

There are still remaining tests of a similar kind that fail.  The issue
there is indeed that combine (now) lacks the capability to continue in
cases where there is no apparent local progress but two or three
seemingly no-progress combinations would help us get a better "global" 
result.

late_combine cannot rescue us here either because it only performs a
propagation if the source can be propagated into all its uses which is
not the case here.  What we might need to do is create internal functions
for those widening operations and combine/simplify at gimple-level already.

I have done testing on rv64gcv_zvl512b but on an older local commit.
Curious what the CI has to say about it now.

Regards
 Robin

gcc/ChangeLog:

* config/riscv/autovec-opt.md
(*single_widen_first_):
New combine "bridge" pattern.

Diff:
---
 gcc/config/riscv/autovec-opt.md | 56 -
 1 file changed, 55 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/autovec-opt.md b/gcc/config/riscv/autovec-opt.md
index 53431863441c..0c3b0cc7e05f 100644
--- a/gcc/config/riscv/autovec-opt.md
+++ b/gcc/config/riscv/autovec-opt.md
@@ -638,6 +638,34 @@
 }
 [(set_attr "type" "viwalu")])
 
+; This is a bridge pattern for combine.  Although we do not have a
+; pattern that extends just the first operand it helps combine bridge
+; the gap to the pred_dual_widen insns.
+; If combination fails it will just expand two a separate extend and
+; a binop again.
+(define_insn_and_split "*single_widen_first_sub"
+  [(set (match_operand:VWEXTI 0 "register_operand")
+   (minus:VWEXTI
+ (any_extend:VWEXTI
+   (match_operand: 1 "register_operand"))
+ (match_operand:VWEXTI 2 "register_operand")))]
+  "TARGET_VECTOR && can_create_pseudo_p ()"
+  "#"
+  "&& 1"
+  [(const_int 0)]
+{
+  insn_code extend_icode = code_for_pred_vf2 (, mode);
+  rtx tmp = gen_reg_rtx (mode);
+  rtx extend_ops[] = {tmp, operands[1]};
+  riscv_vector::emit_vlmax_insn (extend_icode, riscv_vector::UNARY_OP, 
extend_ops);
+
+  rtx ops[] = {operands[0], tmp, operands[2]};
+  insn_code icode = code_for_pred (MINUS, mode);
+  riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, ops);
+  DONE;
+}
+[(set_attr "type" "vector")])
+
 (define_insn_and_split "*single_widen_add"
   [(set (match_operand:VWEXTI 0 "register_operand")
(plus:VWEXTI
@@ -674,7 +702,8 @@
   insn_code extend_icode = code_for_pred_vf2 (, mode);
   rtx tmp = gen_reg_rtx (mode);
   rtx extend_ops[] = {tmp, operands[2]};
-  riscv_vector::emit_vlmax_insn (extend_icode, riscv_vector::UNARY_OP, 
extend_ops);
+  riscv_vector::emit_vlmax_insn (extend_icode, riscv_vector::UNARY_OP,
+extend_ops);
 
   rtx ops[] = {operands[0], operands[1], tmp};
   insn_code icode = code_for_pred (MULT, mode);
@@ -771,6 +800,31 @@
 }
 [(set_attr "type" "vfwalu")])
 
+; This is a bridge pattern for combine (see above).
+(define_insn_and_split "*single_widen_first_sub"
+  [(set (match_operand:VWEXTF 0 "register_operand")
+   (minus:VWEXTF
+ (float_extend:VWEXTF
+   (match_operand: 1 "register_operand"))
+ (match_operand:VWEXTF 2 "register_operand")))]
+  "TARGET_VECTOR && can_create_pseudo_p ()"
+  "#"
+  "&& 1"
+  [(const_int 0)]
+{
+  insn_code extend_icode = code_for_pred_extend (mode);
+  rtx tmp = gen_reg_rtx (mode);
+  rtx extend_ops[] = {tmp, operands[1]};
+  riscv_vector::emit_vlmax_insn (extend_icode, riscv_vector::UNARY_OP,
+extend_ops);
+
+  rtx ops[] = {operands[0], tmp, operands[2]};
+  insn_code icode = code_for_pred (MINUS, mode);
+  riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP_FRM_DYN, ops);
+  DONE;
+}
+[(set_attr "type" "vector")])
+
 ;; This combine pattern does not correspond to an single instruction,
 ;; i.e. there is no vfwmul.wv instruction. This is a temporary pattern
 ;; produced by a combine pass and if there is no further combine into


[gcc r15-7562] sarif-replay: handle relatedLocations without messages (§3.27.22)

2025-02-15 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:79c311d42f846f3e65e012d66e5d8fde4c3b1958

commit r15-7562-g79c311d42f846f3e65e012d66e5d8fde4c3b1958
Author: David Malcolm 
Date:   Sat Feb 15 08:15:58 2025 -0500

sarif-replay: handle relatedLocations without messages (§3.27.22)

Given the .sarif output from e.g.:

  too-many-arguments.c: In function 'test_known_fn':
  too-many-arguments.c:14:3: error: too many arguments to function 'fn_a'; 
expected 0, have 1
 14 |   fn_a (42);
|   ^~~~  ~~
  too-many-arguments.c:8:13: note: declared here
  8 | extern void fn_a ();
| ^~~~

the underlining of the stray argument (the "42") is captured in
'relatedLocations' (§3.27.22) but previously sarif-replay would not
display this:

  In function 'test_known_fn':
  too-many-arguments.c:14:3: error: too many arguments to function 'fn_a'; 
expected 0, have 1 [error]
 14 |   fn_a (42);
|   ^~~~
  too-many-arguments.c:8:13: note: declared here
  8 | extern void fn_a ();
| ^~~~

With this patch sarif-replay handles the relatedLocations element as
a secondary location in libgdiagnostics, and correctly underlines
the "42":

  In function 'test_known_fn':
  too-many-arguments.c:14:3: error: too many arguments to function 'fn_a'; 
expected 0, have 1 [error]
 14 |   fn_a (42);
|   ^~~~  ~~
  too-many-arguments.c:8:13: note: declared here
  8 | extern void fn_a ();
| ^~~~

gcc/ChangeLog:
* libsarifreplay.cc (sarif_replayer::handle_result_obj): Treat any
relatedLocations without messages as secondary ranges within the
diagnostic.  Doing so requires stashing the notes until after
the diagnostic has been finished, so that relatedLocations can be
walked in one pass.

gcc/testsuite/ChangeLog:
* sarif-replay.dg/2.1.0-valid/unlabelled-secondary-locations.sarif:
New test.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/libsarifreplay.cc  | 22 ++--
 .../unlabelled-secondary-locations.sarif   | 60 ++
 2 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/gcc/libsarifreplay.cc b/gcc/libsarifreplay.cc
index 075dadba41f2..e2d09088a4a6 100644
--- a/gcc/libsarifreplay.cc
+++ b/gcc/libsarifreplay.cc
@@ -998,7 +998,6 @@ add_any_annotations (libgdiagnostics::diagnostic &diag,
- doesn't yet handle "taxa" property (§3.27.8)
- handling of "level" property (§3.27.10) doesn't yet support the
  full logic for when "level" is absent.
-   - doesn't yet handle "relatedLocations" property (§3.27.22)
- doesn't yet handle "fixes" property (§3.27.30)
- doesn't yet support multithreaded flows (§3.36.3)
 */
@@ -1127,9 +1126,9 @@ sarif_replayer::handle_result_obj (const json::object 
&result_obj,
   add_any_annotations (err, annotations);
   if (path.m_inner)
 err.take_execution_path (std::move (path));
-  err.finish ("%s", text.get ());
 
   // §3.27.22 relatedLocations property
+  std::vector> notes;
   const property_spec_ref prop_related_locations
 ("result", "relatedLocations", "3.27.22");
   if (auto related_locations_arr
@@ -1172,11 +1171,28 @@ sarif_replayer::handle_result_obj (const json::object 
&result_obj,
  note.set_location (physical_loc);
  note.set_logical_location (logical_loc);
  add_any_annotations (note, annotations);
- note.finish ("%s", text.get ());
+ notes.push_back ({std::move (note), std::move (text)});
+   }
+ else
+   {
+ /* Treat related locations without a message as a secondary
+range.  */
+ if (physical_loc.m_inner)
+   err.add_location (physical_loc);
}
}
 }
 
+  err.finish ("%s", text.get ());
+
+  // Flush any notes
+  for (auto &iter : notes)
+{
+  auto ¬e = iter.first;
+  auto &text = iter.second;
+  note.finish ("%s", text.get ());
+}
+
   return status::ok;
 
 }
diff --git 
a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/unlabelled-secondary-locations.sarif
 
b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/unlabelled-secondary-locations.sarif
new file mode 100644
index ..251e2fd2e786
--- /dev/null
+++ 
b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/unlabelled-secondary-locations.sarif
@@ -0,0 +1,60 @@
+{"$schema": 
"https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json";,
+ "version": "2.1.0",
+ "runs": [{"tool": {"driver": {"name": "GNU C23",
+   "fullName": "GNU C23 (GCC) version 15.0.1 
20250203 (experimental) (x86_64-pc-linux-gnu)",
+   "version": "15.0.1 20250203 (experimental)",
+   "informationUri": "https:/

[gcc r15-7563] sarif-replay: don't add trailing " [error]"

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

commit r15-7563-gd022a068e0c8587b2570147b738cb2781242f162
Author: David Malcolm 
Date:   Sat Feb 15 08:17:09 2025 -0500

sarif-replay: don't add trailing " [error]"

Our SARIF output supplies "error" for the rule ID for DK_ERROR,
since a value is required, but it's not useful to print in sarif-replay.

Filter it out.

gcc/ChangeLog:
* libsarifreplay.cc (should_add_rule_p): New.
(sarif_replayer::handle_result_obj): Use it to filter out rules
that don't make sense.

gcc/testsuite/ChangeLog:
* sarif-replay.dg/2.1.0-valid/3.28.6-annotations-1.sarif: Update
expected output to remove trailing " [error]".
* sarif-replay.dg/2.1.0-valid/unlabelled-secondary-locations.sarif:
Likewise.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/libsarifreplay.cc | 19 ++-
 .../2.1.0-valid/3.28.6-annotations-1.sarif|  3 +--
 .../2.1.0-valid/unlabelled-secondary-locations.sarif  |  3 +--
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/gcc/libsarifreplay.cc b/gcc/libsarifreplay.cc
index e2d09088a4a6..21d8e6ce7cf7 100644
--- a/gcc/libsarifreplay.cc
+++ b/gcc/libsarifreplay.cc
@@ -992,6 +992,20 @@ add_any_annotations (libgdiagnostics::diagnostic &diag,
   diag.add_location (annotation.m_phys_loc);
 }
 
+static bool
+should_add_rule_p (const char *rule_id_str, const char *url)
+{
+  if (url)
+return true;
+
+  /* GCC's sarif output uses "error" for "ruleId", which is already
+ captured in the "level", so don't add a rule for that.  */
+  if (!strcmp (rule_id_str, "error"))
+return false;
+
+  return true;
+}
+
 /* Process a result object (SARIF v2.1.0 section 3.27).
Known limitations:
- doesn't yet handle "ruleIndex" property (§3.27.6)
@@ -1119,7 +1133,10 @@ sarif_replayer::handle_result_obj (const json::object 
&result_obj,
 prop_help_uri))
url = url_val->get_string ();
}
-  err.add_rule (rule_id->get_string (), url);
+
+  const char *rule_id_str = rule_id->get_string ();
+  if (should_add_rule_p (rule_id_str, url))
+   err.add_rule (rule_id_str, url);
 }
   err.set_location (physical_loc);
   err.set_logical_location (logical_loc);
diff --git 
a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/3.28.6-annotations-1.sarif 
b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/3.28.6-annotations-1.sarif
index 4ff6e07ab4d4..fd7e2be44811 100644
--- a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/3.28.6-annotations-1.sarif
+++ b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/3.28.6-annotations-1.sarif
@@ -37,11 +37,10 @@
 /* Verify that we underline and label the ranges for the
"annotations" above.  */
 /* { dg-begin-multiline-output "" }
-bad-binary-ops-highlight-colors.c:19:23: error: invalid operands to binary + 
(have ‘S’ {aka ‘struct s’} and ‘T’ {aka ‘struct t’}) [error]
+bad-binary-ops-highlight-colors.c:19:23: error: invalid operands to binary + 
(have ‘S’ {aka ‘struct s’} and ‘T’ {aka ‘struct t’})
19 |   return callee_4a () + callee_4b ();
   |   ^ 
   |  |  |
   |  |  T {aka struct t}
   |  S {aka struct s}
{ dg-end-multiline-output "" } */
-// TODO: trailing [error]
diff --git 
a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/unlabelled-secondary-locations.sarif
 
b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/unlabelled-secondary-locations.sarif
index 251e2fd2e786..d462bf8045a9 100644
--- 
a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/unlabelled-secondary-locations.sarif
+++ 
b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/unlabelled-secondary-locations.sarif
@@ -50,11 +50,10 @@
 /* Verify that we underline the "42" here.  */
 /* { dg-begin-multiline-output "" }
 In function 'test_known_fn':
-too-many-arguments.c:5:3: error: too many arguments to function 'fn_a'; 
expected 0, have 1 [error]
+too-many-arguments.c:5:3: error: too many arguments to function 'fn_a'; 
expected 0, have 1
 5 |   fn_a (42);
   |   ^~~~  ~~
 too-many-arguments.c:1:13: note: declared here
 1 | extern void fn_a ();
   | ^~~~
{ dg-end-multiline-output "" } */
-// TODO: trailing [error]


[gcc r15-7561] sarif-replay: display annotations as labelled ranges (§3.28.6) [PR118881]

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

commit r15-7561-ga1f63ea36e9c9f2f66980dccc76d18cf781716a7
Author: David Malcolm 
Date:   Sat Feb 15 08:13:06 2025 -0500

sarif-replay: display annotations as labelled ranges (§3.28.6) [PR118881]

In our .sarif output from e.g.:

  bad-binary-op.c: In function ‘test_4’:
  bad-binary-op.c:19:23: error: invalid operands to binary + (have ‘S’ {aka 
‘struct s’} and ‘T’ {aka ‘struct t’})
 19 |   return callee_4a () + callee_4b ();
|   ^ 
|  |  |
|  |  T {aka struct t}
|  S {aka struct s}

the labelled ranges are captured in the 'annotations' property of the
'location' object (§3.28.6).

However sarif-replay emits just:

  In function 'test_4':
  bad-binary-op.c:19:23: error: invalid operands to binary + (have ‘S’ {aka 
‘struct s’} and ‘T’ {aka ‘struct t’}) [error]
 19 |   return callee_4a () + callee_4b ();
|   ^

missing the labelled ranges.

This patch adds support to sarif-replay for the 'annotations' property;
with this patch we emit:

  In function 'test_4':
  bad-binary-op.c:19:23: error: invalid operands to binary + (have ‘S’ {aka 
‘struct s’} and ‘T’ {aka ‘struct t’}) [error]
 19 |   return callee_4a () + callee_4b ();
|   ^ 
|  |  |
|  |  T {aka struct t}
|  S {aka struct s}

thus showing the labelled ranges.

Doing so requires adding a new entrypoint to libgdiagnostics:
  diagnostic_physical_location_get_file
Given that we haven't yet released a stable version and that
sarif-replay is built together with libgdiagnostics I didn't
bother updating the ABI version.

gcc/ChangeLog:
PR sarif-replay/118881
* doc/libgdiagnostics/topics/physical-locations.rst: Add
diagnostic_physical_location_get_file.
* libgdiagnostics++.h (physical_location::get_file): New wrapper.
(diagnostic::add_location): Likewise.
* libgdiagnostics.cc (diagnostic_manager::get_file_by_name): New.
(diagnostic_physical_location::get_file): New.
(diagnostic_physical_location_get_file): New.
* libgdiagnostics.h (diagnostic_physical_location_get_file): New.
* libgdiagnostics.map (diagnostic_physical_location_get_file): New.
* libsarifreplay.cc (class annotation): New.
(add_any_annotations): New.
(sarif_replayer::handle_result_obj): Collect vectors of
annotations in the calls to handle_location_object and apply them
to "err" and to "note" as appropriate.
(sarif_replayer::handle_thread_flow_location_object): Pass nullptr
for annotations.
(sarif_replayer::handle_location_object): Handle §3.28.6
"annotations" property, using it to populate a new
"out_annotations" param.

gcc/testsuite/ChangeLog:
PR sarif-replay/118881
* sarif-replay.dg/2.1.0-valid/3.28.6-annotations-1.sarif: New test.

Signed-off-by: David Malcolm 

Diff:
---
 .../libgdiagnostics/topics/physical-locations.rst  |  5 ++
 gcc/libgdiagnostics++.h| 19 +
 gcc/libgdiagnostics.cc | 33 
 gcc/libgdiagnostics.h  |  6 ++
 gcc/libgdiagnostics.map|  2 +
 gcc/libsarifreplay.cc  | 94 --
 .../2.1.0-valid/3.28.6-annotations-1.sarif | 47 +++
 7 files changed, 201 insertions(+), 5 deletions(-)

diff --git a/gcc/doc/libgdiagnostics/topics/physical-locations.rst 
b/gcc/doc/libgdiagnostics/topics/physical-locations.rst
index fec4a8f221b0..099e27e98224 100644
--- a/gcc/doc/libgdiagnostics/topics/physical-locations.rst
+++ b/gcc/doc/libgdiagnostics/topics/physical-locations.rst
@@ -198,6 +198,11 @@ are at the parentheses.
 
TODO: example of output
 
+.. function::  diagnostic_file *diagnostic_physical_location_get_file (const 
diagnostic_physical_location *physical_loc)
+
+   Get the :type:`diagnostic_file` associated with a given physical location.
+
+
 Associating diagnostics with locations
 **
 
diff --git a/gcc/libgdiagnostics++.h b/gcc/libgdiagnostics++.h
index af75113678c4..39477a0bc4ac 100644
--- a/gcc/libgdiagnostics++.h
+++ b/gcc/libgdiagnostics++.h
@@ -93,6 +93,8 @@ public:
   : m_inner (location)
   {}
 
+  file get_file () const;
+
   const diagnostic_physical_location *m_inner;
 };
 
@@ -199,6 +201,9 @@ public:
   void
   set_location (physical_location loc);
 
+  void
+  add_location (physical_locat

[gcc r15-7569] Fortran: gfortran allows type(C_ptr) in I/O list

2025-02-15 Thread Jerry DeLisle via Gcc-cvs
https://gcc.gnu.org/g:12771b1d77aef71f9eceead9b46323292f3dd7e4

commit r15-7569-g12771b1d77aef71f9eceead9b46323292f3dd7e4
Author: Jerry DeLisle 
Date:   Thu Feb 13 20:19:56 2025 -0800

Fortran: gfortran allows type(C_ptr) in I/O list

Before this patch, gfortran was accepting invalid use of
type(c_ptr) in I/O statements. The fix affects several
existing test cases so no new test case needed.

Existing tests were modified to pass by either using the
transfer function to convert to an acceptable value or
using an assignment to a like type (non-I/O).

PR fortran/117430

gcc/fortran/ChangeLog:

* resolve.cc (resolve_transfer): Change gfc_notify_std to
gfc_error.

gcc/testsuite/ChangeLog:

* gfortran.dg/c_loc_test_17.f90: Use an assignment rather than
PRINT.
* gfortran.dg/c_ptr_tests_10.f03: Use a transfer function.
* gfortran.dg/c_ptr_tests_16.f90: Use an assignment.
* gfortran.dg/c_ptr_tests_9.f03: Use a transfer function.
* gfortran.dg/init_flag_17.f90: Likewise.
* gfortran.dg/pr32601_1.f03: Use an assignment.

Diff:
---
 gcc/fortran/resolve.cc   | 4 ++--
 gcc/testsuite/gfortran.dg/c_loc_test_17.f90  | 4 ++--
 gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03 | 5 ++---
 gcc/testsuite/gfortran.dg/c_ptr_tests_16.f90 | 4 ++--
 gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03  | 6 +++---
 gcc/testsuite/gfortran.dg/init_flag_17.f90   | 5 ++---
 gcc/testsuite/gfortran.dg/pr32601_1.f03  | 4 ++--
 7 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 1a4799dac78f..3d3f117216ca 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -11824,8 +11824,8 @@ resolve_transfer (gfc_code *code)
  the component to be printed to help debugging.  */
   if (ts->u.derived->ts.f90_type == BT_VOID)
{
- if (!gfc_notify_std (GFC_STD_GNU, "Data transfer element at %L "
-  "cannot have PRIVATE components", &code->loc))
+ gfc_error ("Data transfer element at %L "
+"cannot have PRIVATE components", &code->loc);
return;
}
   else if (derived_inaccessible (ts->u.derived) && dtio_sub == NULL)
diff --git a/gcc/testsuite/gfortran.dg/c_loc_test_17.f90 
b/gcc/testsuite/gfortran.dg/c_loc_test_17.f90
index 4c2a7d657ee1..b302d538d9f2 100644
--- a/gcc/testsuite/gfortran.dg/c_loc_test_17.f90
+++ b/gcc/testsuite/gfortran.dg/c_loc_test_17.f90
@@ -1,5 +1,4 @@
 ! { dg-do compile }
-! { dg-options "" }
 !
 ! PR fortran/56378
 ! PR fortran/52426
@@ -24,5 +23,6 @@ contains
 end module
 
 use iso_c_binding
-print *, c_loc([1]) ! { dg-error "Argument X at .1. to C_LOC shall have either 
the POINTER or the TARGET attribute" }
+type(c_ptr) :: i
+i = c_loc([1]) ! { dg-error "Argument X at .1. to C_LOC shall have either the 
POINTER or the TARGET attribute" }
 end
diff --git a/gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03 
b/gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03
index 4ce1c6809e40..1c81e19ca782 100644
--- a/gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03
+++ b/gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03
@@ -1,13 +1,12 @@
 ! { dg-do run }
-! { dg-options "-std=gnu" }
 ! This test case exists because gfortran had an error in converting the 
 ! expressions for the derived types from iso_c_binding in some cases.
 module c_ptr_tests_10
-  use, intrinsic :: iso_c_binding, only: c_ptr, c_null_ptr
+  use, intrinsic :: iso_c_binding, only: c_ptr, c_null_ptr, c_intptr_t
 
 contains
   subroutine sub0() bind(c)
-print *, 'c_null_ptr is: ', c_null_ptr
+print *, 'c_null_ptr is: ', transfer (cptr, 0_C_INTPTR_T)
   end subroutine sub0
 end module c_ptr_tests_10
 
diff --git a/gcc/testsuite/gfortran.dg/c_ptr_tests_16.f90 
b/gcc/testsuite/gfortran.dg/c_ptr_tests_16.f90
index 68c1da161a07..d1f74857c78f 100644
--- a/gcc/testsuite/gfortran.dg/c_ptr_tests_16.f90
+++ b/gcc/testsuite/gfortran.dg/c_ptr_tests_16.f90
@@ -22,13 +22,13 @@ end program test
 subroutine bug1
use ISO_C_BINDING
implicit none
-   type(c_ptr) :: m
+   type(c_ptr) :: m, i
type mytype
  integer a, b, c
end type mytype
type(mytype) x
print *, transfer(32512, x)  ! Works.
-   print *, transfer(32512, m)  ! Caused ICE.
+   i = transfer(32512, m)  ! Caused ICE.
 end subroutine bug1 
 
 subroutine bug6
diff --git a/gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03 
b/gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03
index 5a32553b8c59..60bf32802cb0 100644
--- a/gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03
+++ b/gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03
@@ -4,7 +4,7 @@
 ! done to c_ptr and c_funptr (translating them to void *) works in the case 
 ! where a component of a type is of type c_ptr or c_funptr.  
 module c_ptr_tests_9
-  use, intrinsic :: iso_c_binding, only: c_ptr, c_null_ptr
+  use, intrinsic :: iso_c_bi

[gcc r15-7570] Fortran: passing of derived type to VALUE, OPTIONAL dummy argument [PR118080]

2025-02-15 Thread Harald Anlauf via Gcc-cvs
https://gcc.gnu.org/g:8859dce9037bcb242819305f02e16edbea38923c

commit r15-7570-g8859dce9037bcb242819305f02e16edbea38923c
Author: Harald Anlauf 
Date:   Sat Feb 15 20:36:15 2025 +0100

Fortran: passing of derived type to VALUE,OPTIONAL dummy argument [PR118080]

For scalar OPTIONAL dummy arguments with the VALUE attribute, gfortran
passes a hidden flag to denote presence or absence of the actual argument
for intrinsic types.  Extend this treatment to derived type (user-defined
as well as from intrinsic module ISO_C_BINDING).

PR fortran/118080

gcc/fortran/ChangeLog:

* gfortran.texi: Adjust documentation.
* trans-decl.cc (create_function_arglist): Adjust to pass hidden
presence flag also for derived type dummies with VALUE,OPTIONAL
attribute.
* trans-expr.cc (gfc_conv_expr_present): Expect hidden presence
flag also for derived type dummies with VALUE,OPTIONAL attribute.
(conv_cond_temp): Adjust to allow derived types.
(conv_dummy_value): Extend to handle derived type dummies with
VALUE,OPTIONAL attribute.
(gfc_conv_procedure_call): Adjust for actual arguments passed to
derived type dummies with VALUE,OPTIONAL attribute.
* trans-types.cc (gfc_get_function_type): Adjust fndecl for
hidden presence flag.

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/fortran/gfortran.texi  |   1 +
 gcc/fortran/trans-decl.cc  |   8 +-
 gcc/fortran/trans-expr.cc  |  39 +--
 gcc/fortran/trans-types.cc |   5 +-
 gcc/testsuite/gfortran.dg/value_optional_2.f90 | 338 +
 5 files changed, 368 insertions(+), 23 deletions(-)

diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index ab8a4cb590fe..fa7f563ba2ae 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -3960,6 +3960,7 @@ passed by value.
 
 For @code{OPTIONAL} dummy arguments, an absent argument is denoted
 by a NULL pointer, except for scalar dummy arguments of intrinsic type
+or derived type (but not @code{CLASS}) and
 that have the @code{VALUE} attribute.  For those, a hidden Boolean
 argument (@code{logical(kind=C_bool),value}) is used to indicate
 whether the argument is present.
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 83f8130afd87..0acf0e9adb78 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -2775,8 +2775,7 @@ create_function_arglist (gfc_symbol * sym)
   for (f = gfc_sym_get_dummy_args (sym); f; f = f->next)
 if (f->sym != NULL
&& f->sym->attr.optional && f->sym->attr.value
-   && !f->sym->attr.dimension && f->sym->ts.type != BT_CLASS
-   && !gfc_bt_struct (f->sym->ts.type))
+   && !f->sym->attr.dimension && f->sym->ts.type != BT_CLASS)
   hidden_typelist = TREE_CHAIN (hidden_typelist);
 
   for (f = gfc_sym_get_dummy_args (sym); f; f = f->next)
@@ -2858,12 +2857,11 @@ create_function_arglist (gfc_symbol * sym)
type = gfc_sym_type (f->sym);
}
}
-  /* For scalar intrinsic types, VALUE passes the value,
+  /* For scalar intrinsic types or derived types, VALUE passes the value,
 hence, the optional status cannot be transferred via a NULL pointer.
 Thus, we will use a hidden argument in that case.  */
   if (f->sym->attr.optional && f->sym->attr.value
- && !f->sym->attr.dimension && f->sym->ts.type != BT_CLASS
- && !gfc_bt_struct (f->sym->ts.type))
+ && !f->sym->attr.dimension && f->sym->ts.type != BT_CLASS)
{
   tree tmp;
   strcpy (&name[1], f->sym->name);
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 1329efcd6eb5..9d29fe751165 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -2132,10 +2132,9 @@ gfc_conv_expr_present (gfc_symbol * sym, bool 
use_saved_desc)
   gcc_assert (sym->attr.dummy);
   orig_decl = decl = gfc_get_symbol_decl (sym);
 
-  /* Intrinsic scalars with VALUE attribute which are passed by value
- use a hidden argument to denote the present status.  */
-  if (sym->attr.value && !sym->attr.dimension
-  && sym->ts.type != BT_CLASS && !gfc_bt_struct (sym->ts.type))
+  /* Intrinsic scalars and derived types with VALUE attribute which are passed
+ by value use a hidden argument to denote the presence status.  */
+  if (sym->attr.value && !sym->attr.dimension && sym->ts.type != BT_CLASS)
 {
   char name[GFC_MAX_SYMBOL_LEN + 2];
   tree tree_name;
@@ -6458,13 +6457,13 @@ post_call:
 
 /* Create "conditional temporary" to handle scalar dummy variables with the
OPTIONAL+VALUE attribute that shall not be dereferenced.  Use null value
-   as fallback.  Only instances of intrinsic basic type

[gcc r15-7550] RISC-V: Bugfix ICE for RVV intrinisc when using no-extension parameters

2025-02-15 Thread Ma Jin via Gcc-cvs
https://gcc.gnu.org/g:25a103feb3056bc483a1558af315be452060035b

commit r15-7550-g25a103feb3056bc483a1558af315be452060035b
Author: Jin Ma 
Date:   Fri Feb 14 14:58:49 2025 +0800

RISC-V: Bugfix ICE for RVV intrinisc when using no-extension parameters

When using riscv_v_abi, the return and arguments of the function should
be adequately checked to avoid ICE.

PR target/118872

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_fntype_abi): Strengthen the logic
of the check to avoid missing the error report.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/pr118872.c: New test.

Reviewed-by: Palmer Dabbelt 
Signed-off-by: Jin Ma 

Diff:
---
 gcc/config/riscv/riscv.cc  | 10 +++---
 gcc/testsuite/gcc.target/riscv/rvv/base/pr118872.c | 13 +
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 6e14126e3a4a..9bf7713139f6 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -6479,9 +6479,13 @@ riscv_fntype_abi (const_tree fntype)
   /* Implement the vector calling convention.  For more details please
  reference the below link.
  https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/389  */
-  if (riscv_return_value_is_vector_type_p (fntype)
- || riscv_arguments_is_vector_type_p (fntype)
- || riscv_vector_cc_function_p (fntype))
+  bool validate_v_abi_p = false;
+
+  validate_v_abi_p |= riscv_return_value_is_vector_type_p (fntype);
+  validate_v_abi_p |= riscv_arguments_is_vector_type_p (fntype);
+  validate_v_abi_p |= riscv_vector_cc_function_p (fntype);
+
+  if (validate_v_abi_p)
 return riscv_v_abi ();
 
   return default_function_abi;
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr118872.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/pr118872.c
new file mode 100644
index ..adb54d648a52
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr118872.c
@@ -0,0 +1,13 @@
+/* Test that we do not have ice when compile */
+/* { dg-do assemble } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O2"  { target { rv64 } } } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32d -O2"  { target { rv32 } } } */
+
+#include 
+
+vfloat32m2_t foo (vfloat16m1_t a, size_t vl)
+{
+  return __riscv_vfwcvt_f_f_v_f32m2(a, vl);
+}
+
+/* { dg-error "argument type 'vfloat16m1_t' requires the zvfhmin or zvfh ISA 
extension" "" { target { "riscv*-*-*" } } 0 } */


[gcc r15-7557] Remove defunct web site for site of Fortran preprocessor.

2025-02-15 Thread Thomas Kテカnig via Gcc-cvs
https://gcc.gnu.org/g:bf84e5e64662f8f0fdebfc0212e32bfca678f9eb

commit r15-7557-gbf84e5e64662f8f0fdebfc0212e32bfca678f9eb
Author: Andrew Pinski 
Date:   Sat Feb 15 13:22:54 2025 +0100

Remove defunct web site for site of Fortran preprocessor.

gcc/fortran/ChangeLog:

PR fortran/118159
* invoke.texi: Remove mention of defunct web site for Coco.

Diff:
---
 gcc/fortran/invoke.texi | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi
index c461f57d1f4a..0b50508dd1c2 100644
--- a/gcc/fortran/invoke.texi
+++ b/gcc/fortran/invoke.texi
@@ -666,8 +666,7 @@ include code for these additional kind types: 
@code{__GFC_INT_1__},
 While CPP is the de facto standard for preprocessing Fortran code,
 Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
 Conditional Compilation, which is not widely used and not directly
-supported by the GNU Fortran compiler.  You can use the program coco
-to preprocess such files (@uref{http://www.daniellnagle.com/coco.html}).
+supported by the GNU Fortran compiler.
 
 The following options control preprocessing of Fortran code:


[gcc r15-7558] c++: NRVO, constexpr, lambda [PR118053]

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

commit r15-7558-gde66529f2e7bb24fb2b61b82e6a953f3f6c12902
Author: Jason Merrill 
Date:   Sat Feb 15 10:48:17 2025 +0100

c++: NRVO, constexpr, lambda [PR118053]

Here during constant evaluation we encounter a VAR_DECL with DECL_VALUE_EXPR
of the RESULT_DECL, where the latter has been adjusted for
pass-by-invisible-reference.  We already had the code to deal with this, we
just need to use it in the non-capture case of DECL_VALUE_EXPR as well.

PR c++/118053

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_constant_expression): Generalize
DECL_VALUE_EXPR invisiref handling.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/constexpr-lambda1.C: New test.

Diff:
---
 gcc/cp/constexpr.cc| 19 ++-
 gcc/testsuite/g++.dg/cpp1y/constexpr-lambda1.C | 20 
 2 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 299b13456873..59dd0668af3f 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -7683,18 +7683,19 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, 
tree t,
 definition, so don't try to look at the closure.  But if the
 captured variable is constant, try to evaluate it directly. */
  r = DECL_CAPTURED_VARIABLE (t);
- tree type = TREE_TYPE (t);
- if (TYPE_REF_P (type) != TYPE_REF_P (TREE_TYPE (r)))
-   {
- /* Adjust r to match the reference-ness of t.  */
- if (TYPE_REF_P (type))
-   r = build_address (r);
- else
-   r = convert_from_reference (r);
-   }
}
  else
r = DECL_VALUE_EXPR (t);
+
+ tree type = TREE_TYPE (t);
+ if (TYPE_REF_P (type) != TYPE_REF_P (TREE_TYPE (r)))
+   {
+ /* Adjust r to match the reference-ness of t.  */
+ if (TYPE_REF_P (type))
+   r = build_address (r);
+ else
+   r = convert_from_reference (r);
+   }
  return cxx_eval_constant_expression (ctx, r, lval, non_constant_p,
   overflow_p);
}
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-lambda1.C 
b/gcc/testsuite/g++.dg/cpp1y/constexpr-lambda1.C
new file mode 100644
index ..68152e26b899
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-lambda1.C
@@ -0,0 +1,20 @@
+// PR c++/118053
+// { dg-do compile { target c++14 } }
+
+template  struct vector {
+  _Tp * _M_finish;
+  vector(_Tp);
+  vector(const vector &);
+  constexpr auto back() { return *_M_finish; }
+};
+template  void
+run(Funct funct) { funct(1); }
+
+vector
+runner() try {
+  vector vec{1};
+  run([&](auto) { vec.back(); });
+  return vec;
+} catch (...) {
+  return 1;
+}


[gcc r15-7560] c++/modules: Don't treat template parameters as TU-local [PR118846]

2025-02-15 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:9f1f4efc06f43b1ba8c1cf5a31d5b73d6a2bb12d

commit r15-7560-g9f1f4efc06f43b1ba8c1cf5a31d5b73d6a2bb12d
Author: Nathaniel Shead 
Date:   Wed Feb 12 19:15:22 2025 +1100

c++/modules: Don't treat template parameters as TU-local [PR118846]

There are two separate issues making various template parameters behave
as if they were TU-local.

Firstly, the TU-local detection code uses WILDCARD_TYPE_P to check for
types that are not yet concrete; for some reason UNBOUND_CLASS_TEMPLATE
is not on that list.  I don't see any particular reason why it shouldn't
be, so this patch adds it; this may solve other latent issues as well.

Secondly, the TEMPLATE_DECL for a type with expressions involving
TEMPLATE_TEMPLATE_PARM_Ps is currently always constrained to internal
linkage, because the result does not have TREE_PUBLIC set. Rather than
messing with TREE_PUBLIC here, I think rather we just should ensure that
we only attempt to constrain visiblity of templates of type, variable,
or function decls.

PR c++/118846

gcc/cp/ChangeLog:

* cp-tree.h (WILDCARD_TYPE_P): Include UNBOUND_CLASS_TEMPLATE.
* decl2.cc (min_vis_expr_r): Don't assume a TEMPLATE_DECL will
be a function or variable.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr118846_a.C: New test.
* g++.dg/modules/pr118846_b.C: New test.

Signed-off-by: Nathaniel Shead 
Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/cp-tree.h  |  1 +
 gcc/cp/decl2.cc   | 22 ++
 gcc/testsuite/g++.dg/modules/pr118846_a.C | 18 ++
 gcc/testsuite/g++.dg/modules/pr118846_b.C | 10 ++
 4 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index d87cc1555b7a..84bcbf29fa02 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -2325,6 +2325,7 @@ enum languages { lang_c, lang_cplusplus };
|| TREE_CODE (T) == TYPENAME_TYPE   \
|| TREE_CODE (T) == TYPEOF_TYPE \
|| TREE_CODE (T) == BOUND_TEMPLATE_TEMPLATE_PARM\
+   || TREE_CODE (T) == UNBOUND_CLASS_TEMPLATE  \
|| TREE_CODE (T) == DECLTYPE_TYPE   \
|| TREE_CODE (T) == TRAIT_TYPE  \
|| TREE_CODE (T) == DEPENDENT_OPERATOR_TYPE \
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 0217a8e24740..476e1a8abba2 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -2813,6 +2813,19 @@ min_vis_expr_r (tree *tp, int */*walk_subtrees*/, void 
*data)
   tree t = *tp;
   if (TREE_CODE (t) == PTRMEM_CST)
 t = PTRMEM_CST_MEMBER (t);
+
+  if (TREE_CODE (t) == TEMPLATE_DECL)
+{
+  if (DECL_ALIAS_TEMPLATE_P (t) || concept_definition_p (t))
+   /* FIXME: We don't maintain TREE_PUBLIC / DECL_VISIBILITY for
+  alias templates so we can't trust it here (PR107906).  Ditto
+  for concepts.  */
+   return NULL_TREE;
+  t = DECL_TEMPLATE_RESULT (t);
+  if (!t)
+   return NULL_TREE;
+}
+
   switch (TREE_CODE (t))
 {
 case CAST_EXPR:
@@ -2824,17 +2837,10 @@ min_vis_expr_r (tree *tp, int */*walk_subtrees*/, void 
*data)
 case NEW_EXPR:
 case CONSTRUCTOR:
 case LAMBDA_EXPR:
+case TYPE_DECL:
   tpvis = type_visibility (TREE_TYPE (t));
   break;
 
-case TEMPLATE_DECL:
-  if (DECL_ALIAS_TEMPLATE_P (t) || concept_definition_p (t))
-   /* FIXME: We don't maintain TREE_PUBLIC / DECL_VISIBILITY for
-  alias templates so we can't trust it here (PR107906).  Ditto
-  for concepts.  */
-   break;
-  t = DECL_TEMPLATE_RESULT (t);
-  /* Fall through.  */
 case VAR_DECL:
 case FUNCTION_DECL:
   if (decl_constant_var_p (t))
diff --git a/gcc/testsuite/g++.dg/modules/pr118846_a.C 
b/gcc/testsuite/g++.dg/modules/pr118846_a.C
new file mode 100644
index ..bbbdde78457d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr118846_a.C
@@ -0,0 +1,18 @@
+// PR c++/118846
+// { dg-additional-options "-fmodules" }
+// { dg-module-cmi M }
+
+export module M;
+
+template  struct integral_constant { static constexpr int value = N; };
+template  class> constexpr int cx_count_if() { return 0; }
+template  class P> struct mp_count_if_impl {
+  using type = integral_constant()>;
+};
+
+template  class> struct consume {
+  static constexpr bool value = true;
+};
+template  struct use {
+  using type = consume;
+};
diff --git a/gcc/testsuite/g++.dg/modules/pr118846_b.C 
b/gcc/testsuite/g++.dg/modules/pr118846_b.C
new file mode 100644
index ..a2f288946304
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr118846_b.C
@@ -0,0 +1,10 @@
+// PR c++/118846
+// { dg-additional-options "-fmodules" }
+
+module M;
+
+template  struct S {
+  template  struct fn {};
+};
+static_assert(mp_count_if_impl::type::value == 0);
+static_assert(

[gcc r15-7559] testsuite: tweak constexpr-lamda1.C [PR118053]

2025-02-15 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:741073460b9a850ca85b01509e08bf72900b6c8a

commit r15-7559-g741073460b9a850ca85b01509e08bf72900b6c8a
Author: Jason Merrill 
Date:   Sat Feb 15 13:28:37 2025 +0100

testsuite: tweak constexpr-lamda1.C [PR118053]

I forgot to add the -O necessary to reproduce the bug before pushing the
fix.

PR c++/118053

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/constexpr-lambda1.C: Add -O.

Diff:
---
 gcc/testsuite/g++.dg/cpp1y/constexpr-lambda1.C | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-lambda1.C 
b/gcc/testsuite/g++.dg/cpp1y/constexpr-lambda1.C
index 68152e26b899..dca3920ddc0c 100644
--- a/gcc/testsuite/g++.dg/cpp1y/constexpr-lambda1.C
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-lambda1.C
@@ -1,5 +1,6 @@
 // PR c++/118053
 // { dg-do compile { target c++14 } }
+// { dg-additional-options -O }
 
 template  struct vector {
   _Tp * _M_finish;