[gcc r15-3187] expand: Use the correct mode for store flags for popcount [PR116480]

2024-08-26 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:53b86cac7e77ddff4e8a215408f7331ebc5bf22c

commit r15-3187-g53b86cac7e77ddff4e8a215408f7331ebc5bf22c
Author: Andrew Pinski 
Date:   Sun Aug 25 10:10:06 2024 -0700

expand: Use the correct mode for store flags for popcount [PR116480]

When expanding popcount used for equal to 1 (or rather 
__builtin_stdc_has_single_bit),
the wrong mode was bsing used for the mode of the store flags. We were 
using the mode
of the argument to popcount but since popcount's return value is always 
int, the mode
of the expansion here should have been the mode of the return type rater 
than the argument.

Built and tested on aarch64-linux-gnu with no regressions.
Also bootstrapped and tested on x86_64-linux-gnu.

PR middle-end/116480

gcc/ChangeLog:

* internal-fn.cc (expand_POPCOUNT): Use the correct mode
for store flags.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr116480-1.c: New test.
* gcc.dg/torture/pr116480-2.c: New test.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/internal-fn.cc| 3 ++-
 gcc/testsuite/gcc.dg/torture/pr116480-1.c | 8 
 gcc/testsuite/gcc.dg/torture/pr116480-2.c | 8 
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/gcc/internal-fn.cc b/gcc/internal-fn.cc
index a96e61e527c0..89da13b38ce1 100644
--- a/gcc/internal-fn.cc
+++ b/gcc/internal-fn.cc
@@ -5311,6 +5311,7 @@ expand_POPCOUNT (internal_fn fn, gcall *stmt)
   bool nonzero_arg = integer_zerop (gimple_call_arg (stmt, 1));
   tree type = TREE_TYPE (arg);
   machine_mode mode = TYPE_MODE (type);
+  machine_mode lhsmode = TYPE_MODE (TREE_TYPE (lhs));
   do_pending_stack_adjust ();
   start_sequence ();
   expand_unary_optab_fn (fn, stmt, popcount_optab);
@@ -5318,7 +5319,7 @@ expand_POPCOUNT (internal_fn fn, gcall *stmt)
   end_sequence ();
   start_sequence ();
   rtx plhs = expand_normal (lhs);
-  rtx pcmp = emit_store_flag (NULL_RTX, EQ, plhs, const1_rtx, mode, 0, 0);
+  rtx pcmp = emit_store_flag (NULL_RTX, EQ, plhs, const1_rtx, lhsmode, 0, 0);
   if (pcmp == NULL_RTX)
 {
 fail:
diff --git a/gcc/testsuite/gcc.dg/torture/pr116480-1.c 
b/gcc/testsuite/gcc.dg/torture/pr116480-1.c
new file mode 100644
index ..15a5727941cf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr116480-1.c
@@ -0,0 +1,8 @@
+/* { dg-do compile { target int128 } } */
+
+int
+foo(unsigned __int128 b)
+{
+  return __builtin_popcountg(b) == 1;
+}
+
diff --git a/gcc/testsuite/gcc.dg/torture/pr116480-2.c 
b/gcc/testsuite/gcc.dg/torture/pr116480-2.c
new file mode 100644
index ..7bf690283b4d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr116480-2.c
@@ -0,0 +1,8 @@
+/* { dg-do compile { target bitint } } */
+
+int
+foo(unsigned _BitInt(127) b)
+{
+  return __builtin_popcountg(b) == 1;
+}
+


[gcc r15-3188] Match: Add int type fits check for .SAT_ADD imm operand

2024-08-26 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:3b78aa3e316a22b4ae477c91866d47f654f129b1

commit r15-3188-g3b78aa3e316a22b4ae477c91866d47f654f129b1
Author: Pan Li 
Date:   Sat Aug 24 10:16:28 2024 +0800

Match: Add int type fits check for .SAT_ADD imm operand

This patch would like to add strict check for imm operand of .SAT_ADD
matching.  We have no type checking for imm operand in previous, which
may result in unexpected IL to be catched by .SAT_ADD pattern.

We leverage the int_fits_type_p here to make sure the imm operand is
a int type fits the result type of the .SAT_ADD.  For example:

Fits uint8_t:
uint8_t a;
uint8_t sum = .SAT_ADD (a, 12);
uint8_t sum = .SAT_ADD (a, 12u);
uint8_t sum = .SAT_ADD (a, 126u);
uint8_t sum = .SAT_ADD (a, 128u);
uint8_t sum = .SAT_ADD (a, 228);
uint8_t sum = .SAT_ADD (a, 223u);

Not fits uint8_t:
uint8_t a;
uint8_t sum = .SAT_ADD (a, -1);
uint8_t sum = .SAT_ADD (a, 256u);
uint8_t sum = .SAT_ADD (a, 257);

The below test suite are passed for this patch:
* The rv64gcv fully regression test.
* The x86 bootstrap test.
* The x86 fully regression test.

gcc/ChangeLog:

* match.pd: Add int_fits_type_p check for .SAT_ADD imm operand.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat_arith.h: Add test helper macros.
* gcc.target/riscv/sat_u_add_imm-11.c: Adjust test case for imm.
* gcc.target/riscv/sat_u_add_imm-12.c: Ditto.
* gcc.target/riscv/sat_u_add_imm-15.c: Ditto.
* gcc.target/riscv/sat_u_add_imm-16.c: Ditto.
* gcc.target/riscv/sat_u_add_imm_type_check-1.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-10.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-11.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-12.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-13.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-14.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-15.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-16.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-17.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-18.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-19.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-2.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-20.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-21.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-22.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-23.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-24.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-25.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-26.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-27.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-28.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-29.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-3.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-30.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-31.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-32.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-33.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-34.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-35.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-36.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-37.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-38.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-39.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-4.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-40.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-41.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-42.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-43.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-44.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-45.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-46.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-47.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-48.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-49.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-5.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-50.c: New test.
* gcc.target/riscv/sat_u_add_imm_

[gcc r15-3189] vect: Fix STMT_VINFO_DEF_TYPE check for odd/even widen mult [PR116348]

2024-08-26 Thread Xi Ruoyao via Gcc-cvs
https://gcc.gnu.org/g:d3e71b99194bff878d3bf3b35f9528a350d10df9

commit r15-3189-gd3e71b99194bff878d3bf3b35f9528a350d10df9
Author: Xi Ruoyao 
Date:   Thu Aug 22 21:18:29 2024 +0800

vect: Fix STMT_VINFO_DEF_TYPE check for odd/even widen mult [PR116348]

After fixing PR116142 some code started to trigger an ICE with -O3
-march=znver4.  Per Richard Biener who actually made this fix:

"supportable_widening_operation fails at transform time - that's likely
because vectorizable_reduction "puns" defs to internal_def"

so the check should use STMT_VINFO_REDUC_DEF instead of checking if
STMT_VINFO_DEF_TYPE is vect_reduction_def.

gcc/ChangeLog:

PR tree-optimization/116348
* tree-vect-stmts.cc (supportable_widening_operation): Use
STMT_VINFO_REDUC_DEF (x) instead of
STMT_VINFO_DEF_TYPE (x) == vect_reduction_def.

gcc/testsuite/ChangeLog:

PR tree-optimization/116348
* gcc.c-torture/compile/pr116438.c: New test.

Co-authored-by: Richard Biener 

Diff:
---
 gcc/testsuite/gcc.c-torture/compile/pr116438.c | 14 ++
 gcc/tree-vect-stmts.cc |  3 +--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.c-torture/compile/pr116438.c 
b/gcc/testsuite/gcc.c-torture/compile/pr116438.c
new file mode 100644
index ..97ab0181ab8b
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr116438.c
@@ -0,0 +1,14 @@
+/* { dg-additional-options "-march=znver4" { target x86_64-*-* i?86-*-* } } */
+
+int *a;
+int b;
+long long c, d;
+void
+e (int f)
+{
+  for (; f; f++)
+{
+  d += (long long)a[f] * b;
+  c += (long long)a[f] * 3;
+}
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 385e63163c24..9eb73a599339 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -14193,8 +14193,7 @@ supportable_widening_operation (vec_info *vinfo,
  by STMT is only directly used in the reduction statement.  */
  tree lhs = gimple_assign_lhs (vect_orig_stmt (stmt_info)->stmt);
  stmt_vec_info use_stmt_info = loop_info->lookup_single_use (lhs);
- if (use_stmt_info
- && STMT_VINFO_DEF_TYPE (use_stmt_info) == vect_reduction_def)
+ if (use_stmt_info && STMT_VINFO_REDUC_DEF (use_stmt_info))
return true;
 }
   c1 = VEC_WIDEN_MULT_LO_EXPR;


[gcc r15-3190] Delay edge removal in forwprop

2024-08-26 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:03b802e14f497e393e6437b7df5be1c690ddf1df

commit r15-3190-g03b802e14f497e393e6437b7df5be1c690ddf1df
Author: Richard Biener 
Date:   Mon Aug 26 13:21:57 2024 +0200

Delay edge removal in forwprop

SSA forwprop has switch simplification code that calls remove edge
and as side-effect releases dominator info.  For a followup we want
to retain that so the following delays removing edges until the end
of the pass.  As usual we have to deal with parts of the edge
vanishing due to EH/abnormal pruning so record edges as basic-block
index pairs and remove them only when they are still there.

* tree-ssa-forwprop.cc (simplify_gimple_switch_label_vec):
Delay removing edges and releasing dominator info, instead
record into edges_to_remove vector.
(simplify_gimple_switch): Pass through vector of to remove
edges.
(pass_forwprop::execute): Likewise.  Remove queued edges.

Diff:
---
 gcc/tree-ssa-forwprop.cc | 34 +-
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 959138cf..e7342b4dc092 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -972,7 +972,8 @@ forward_propagate_addr_expr (tree name, tree rhs, bool 
parent_single_use_p)
have values outside the range of the new type.  */
 
 static void
-simplify_gimple_switch_label_vec (gswitch *stmt, tree index_type)
+simplify_gimple_switch_label_vec (gswitch *stmt, tree index_type,
+ vec > &edges_to_remove)
 {
   unsigned int branch_num = gimple_switch_num_labels (stmt);
   auto_vec labels (branch_num);
@@ -1026,11 +1027,8 @@ simplify_gimple_switch_label_vec (gswitch *stmt, tree 
index_type)
   for (ei = ei_start (gimple_bb (stmt)->succs); (e = ei_safe_edge (ei)); )
{
  if (! bitmap_bit_p (target_blocks, e->dest->index))
-   {
- remove_edge (e);
- cfg_changed = true;
- free_dominance_info (CDI_DOMINATORS);
-   }
+   edges_to_remove.safe_push (std::make_pair (e->src->index,
+  e->dest->index));
  else
ei_next (&ei);
} 
@@ -1042,7 +1040,8 @@ simplify_gimple_switch_label_vec (gswitch *stmt, tree 
index_type)
the condition which we may be able to optimize better.  */
 
 static bool
-simplify_gimple_switch (gswitch *stmt)
+simplify_gimple_switch (gswitch *stmt,
+   vec > &edges_to_remove)
 {
   /* The optimization that we really care about is removing unnecessary
  casts.  That will let us do much better in propagating the inferred
@@ -1078,7 +1077,8 @@ simplify_gimple_switch (gswitch *stmt)
  && (!max || int_fits_type_p (max, ti)))
{
  gimple_switch_set_index (stmt, def);
- simplify_gimple_switch_label_vec (stmt, ti);
+ simplify_gimple_switch_label_vec (stmt, ti,
+   edges_to_remove);
  update_stmt (stmt);
  return true;
}
@@ -3518,6 +3518,7 @@ pass_forwprop::execute (function *fun)
 |= EDGE_EXECUTABLE;
   auto_vec to_fixup;
   auto_vec to_remove;
+  auto_vec, 10> edges_to_remove;
   auto_bitmap simple_dce_worklist;
   auto_bitmap need_ab_cleanup;
   to_purge = BITMAP_ALLOC (NULL);
@@ -4024,7 +4025,8 @@ pass_forwprop::execute (function *fun)
  }
 
case GIMPLE_SWITCH:
- changed = simplify_gimple_switch (as_a  (stmt));
+ changed = simplify_gimple_switch (as_a  (stmt),
+   edges_to_remove);
  break;
 
case GIMPLE_COND:
@@ -4173,6 +4175,20 @@ pass_forwprop::execute (function *fun)
   cfg_changed |= gimple_purge_all_dead_abnormal_call_edges (need_ab_cleanup);
   BITMAP_FREE (to_purge);
 
+  /* Remove edges queued from switch stmt simplification.  */
+  for (auto ep : edges_to_remove)
+{
+  basic_block src = BASIC_BLOCK_FOR_FN (fun, ep.first);
+  basic_block dest = BASIC_BLOCK_FOR_FN (fun, ep.second);
+  edge e;
+  if (src && dest && (e = find_edge (src, dest)))
+   {
+ free_dominance_info (CDI_DOMINATORS);
+ remove_edge (e);
+ cfg_changed = true;
+   }
+}
+
   if (get_range_query (fun) != get_global_range_query ())
 disable_ranger (fun);


[gcc r15-3191] tree-optimization/116460 - improve forwprop compile-time

2024-08-26 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:0ceeb9926d69dbb382622a8eae9eef7ed8ac3e97

commit r15-3191-g0ceeb9926d69dbb382622a8eae9eef7ed8ac3e97
Author: Richard Biener 
Date:   Mon Aug 26 10:01:44 2024 +0200

tree-optimization/116460 - improve forwprop compile-time

The following improves forwprop block reachability which I noticed
when debugging PR116460 and what is also noted in the comment.  It
avoids processing blocks in natural loops determined unreachable,
thereby making the issue in PR116460 latent.

PR tree-optimization/116460
* tree-ssa-forwprop.cc (pass_forwprop::execute): Do not
process blocks in unreachable natural loops.

Diff:
---
 gcc/tree-ssa-forwprop.cc | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index e7342b4dc092..2964420ad1a1 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -3498,6 +3498,8 @@ pass_forwprop::execute (function *fun)
 
   cfg_changed = false;
 
+  calculate_dominance_info (CDI_DOMINATORS);
+
   /* Combine stmts with the stmts defining their operands.  Do that
  in an order that guarantees visiting SSA defs before SSA uses.  */
   lattice.create (num_ssa_names);
@@ -3537,12 +3539,11 @@ pass_forwprop::execute (function *fun)
   FOR_EACH_EDGE (e, ei, bb->preds)
{
  if ((e->flags & EDGE_EXECUTABLE)
- /* With dominators we could improve backedge handling
-when e->src is dominated by bb.  But for irreducible
-regions we have to take all backedges conservatively.
-We can handle single-block cycles as we know the
-dominator relationship here.  */
- || bb_to_rpo[e->src->index] > i)
+ /* We can handle backedges in natural loops correctly but
+for irreducible regions we have to take all backedges
+conservatively when we did not visit the source yet.  */
+ || (bb_to_rpo[e->src->index] > i
+ && !dominated_by_p (CDI_DOMINATORS, e->src, e->dest)))
{
  any = true;
  break;


[gcc r15-3192] libcpp: deduplicate definition of padding size

2024-08-26 Thread Alexander Monakov via Gcc-cvs
https://gcc.gnu.org/g:a8260ebeae0f817bc7adf99cf62b604b1e2d3895

commit r15-3192-ga8260ebeae0f817bc7adf99cf62b604b1e2d3895
Author: Alexander Monakov 
Date:   Sat Aug 24 17:37:13 2024 +0300

libcpp: deduplicate definition of padding size

Tie together the two functions that ensure tail padding with
search_line_ssse3 via CPP_BUFFER_PADDING macro.

libcpp/ChangeLog:

* internal.h (CPP_BUFFER_PADDING): New macro; use it ...
* charset.cc (_cpp_convert_input): ...here, and ...
* files.cc (read_file_guts): ...here, and ...
* lex.cc (search_line_ssse3): here.

Diff:
---
 libcpp/charset.cc | 7 +--
 libcpp/files.cc   | 6 +-
 libcpp/internal.h | 7 +++
 libcpp/lex.cc | 4 ++--
 4 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/libcpp/charset.cc b/libcpp/charset.cc
index 79072877cbf7..fd57f6139804 100644
--- a/libcpp/charset.cc
+++ b/libcpp/charset.cc
@@ -3093,7 +3093,7 @@ _cpp_convert_input (cpp_reader *pfile, const char 
*input_charset,
   struct cset_converter input_cset;
   struct _cpp_strbuf to;
   unsigned char *buffer;
-  size_t pad;
+  size_t pad = CPP_BUFFER_PADDING;
 
   input_cset = init_iconv_desc (pfile, SOURCE_CHARSET, input_charset);
   if (input_cset.func == convert_no_conversion)
@@ -3130,11 +3130,6 @@ _cpp_convert_input (cpp_reader *pfile, const char 
*input_charset,
}
 }
 
-#ifdef HAVE_SSSE3
-  pad = 64;
-#else
-  pad = 16;
-#endif
   /* Resize buffer if we allocated substantially too much, or if we
  don't have enough space for the following padding, which allows
  search_line_fast to use (possibly misaligned) vector loads.  */
diff --git a/libcpp/files.cc b/libcpp/files.cc
index 3775091d259e..fc66b9c3d73a 100644
--- a/libcpp/files.cc
+++ b/libcpp/files.cc
@@ -732,11 +732,7 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file, 
location_t loc,
the majority of C source files.  */
 size = 8 * 1024;
 
-#ifdef HAVE_SSSE3
-  pad = 64;
-#else
-  pad = 16;
-#endif
+  pad = CPP_BUFFER_PADDING;
   /* The '+ PAD' here is space for the final '\n' and PAD-1 bytes of padding,
  allowing search_line_fast to use (possibly misaligned) vector loads.  */
   buf = XNEWVEC (uchar, size + pad);
diff --git a/libcpp/internal.h b/libcpp/internal.h
index a20215c57095..ad0a5d5d4e34 100644
--- a/libcpp/internal.h
+++ b/libcpp/internal.h
@@ -322,6 +322,13 @@ struct _cpp_line_note
   unsigned int type;
 };
 
+/* Tail padding required by search_line_fast alternatives.  */
+#ifdef HAVE_SSSE3
+#define CPP_BUFFER_PADDING 64
+#else
+#define CPP_BUFFER_PADDING 16
+#endif
+
 /* Represents the contents of a file cpplib has read in.  */
 struct cpp_buffer
 {
diff --git a/libcpp/lex.cc b/libcpp/lex.cc
index f2d47d112b92..7f0f8d07735b 100644
--- a/libcpp/lex.cc
+++ b/libcpp/lex.cc
@@ -359,8 +359,8 @@ search_line_ssse3 (const uchar *s, const uchar *end 
ATTRIBUTE_UNUSED)
 "host character encoding is ASCII");
 
   v16qi d1, d2, t1, t2;
-  /* Unaligned loads.  Reading beyond the final newline is safe,
- since files.cc:read_file_guts pads the allocation.  */
+  /* Unaligned loads, potentially using padding after the final newline.  */
+  static_assert (CPP_BUFFER_PADDING >= 64, "");
   d1 = *(const v16qi_u *)s;
   d2 = *(const v16qi_u *)(s + 16);
   unsigned m1, m2, found;


[gcc r15-3193] Fix bootstap-errors due to enabling -gvariable-location-views

2024-08-26 Thread Bernd Edlinger via Gcc-cvs
https://gcc.gnu.org/g:eb63f9580f0220e347034ef337dbc93d12931d6c

commit r15-3193-geb63f9580f0220e347034ef337dbc93d12931d6c
Author: Bernd Edlinger 
Date:   Sat Aug 24 08:37:53 2024 +0200

Fix bootstap-errors due to enabling -gvariable-location-views

This recent change triggered various bootstap-errors, mostly on
x86 targets because line info advance address entries were output
in the wrong section table.
The switch to the wrong line table happened in dwarfout_set_ignored_loc.
It must use the same section as the earlier called
dwarf2out_switch_text_section.

But also ft32-elf was affected, because the assembler choked on
something simple as ".2byte .LM2-.LM1", but fortunately it is
able to use native location views, the configure test was just
not executed because the ft32 "nop" instruction was missing.

gcc/ChangeLog:

PR debug/116470
* configure.ac: Add the "nop" instruction for cpu type ft32.
* configure: Regenerate.
* dwarf2out.cc (dwarf2out_set_ignored_loc): Use the correct
line info section.

Diff:
---
 gcc/configure| 2 +-
 gcc/configure.ac | 2 +-
 gcc/dwarf2out.cc | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/configure b/gcc/configure
index 557ea5fa3ac9..3d301b6ecd3d 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -31398,7 +31398,7 @@ esac
 case "$cpu_type" in
   aarch64 | alpha | arc | arm | avr | bfin | cris | csky | i386 | loongarch | 
m32c \
   | m68k | microblaze | mips | nds32 | nios2 | pa | riscv | rs6000 | score | 
sparc \
-  | visium | xstormy16 | xtensa)
+  | visium | xstormy16 | xtensa | ft32)
 insn="nop"
 ;;
   ia64 | s390)
diff --git a/gcc/configure.ac b/gcc/configure.ac
index eaa01d0d7e56..8a2d2b0438e7 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -5610,7 +5610,7 @@ esac
 case "$cpu_type" in
   aarch64 | alpha | arc | arm | avr | bfin | cris | csky | i386 | loongarch | 
m32c \
   | m68k | microblaze | mips | nds32 | nios2 | pa | riscv | rs6000 | score | 
sparc \
-  | visium | xstormy16 | xtensa)
+  | visium | xstormy16 | xtensa | ft32)
 insn="nop"
 ;;
   ia64 | s390)
diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 633900b035fe..3f040da33a63 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -28939,7 +28939,7 @@ dwarf2out_set_ignored_loc (unsigned int line, unsigned 
int column,
   dw_fde_ref fde = cfun->fde;
 
   fde->ignored_debug = false;
-  set_cur_line_info_table (function_section (fde->decl));
+  set_cur_line_info_table (current_function_section ());
 
   dwarf2out_source_line (line, column, filename, 0, true);
 }


[gcc r15-3194] Remove an unneeded include that was added by mistake.

2024-08-26 Thread Andi Kleen via Gcc-cvs
https://gcc.gnu.org/g:cc372be5d0a8a1665bc5f716458f326b5afad43f

commit r15-3194-gcc372be5d0a8a1665bc5f716458f326b5afad43f
Author: Andi Kleen 
Date:   Mon Aug 26 08:12:45 2024 -0700

Remove an unneeded include that was added by mistake.

gcc/ChangeLog:

* tree-if-conv.cc: Remove unneeded include from last change.

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

diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc
index 5aac65cfbd18..735e47763de1 100644
--- a/gcc/tree-if-conv.cc
+++ b/gcc/tree-if-conv.cc
@@ -124,7 +124,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-vectorizer.h"
 #include "tree-eh.h"
 #include "cgraph.h"
-#include "print-tree.h"
 
 /* For lang_hooks.types.type_for_mode.  */
 #include "langhooks.h"


[gcc r15-3195] c++: Check template parameters in member class template specialization [PR115716]

2024-08-26 Thread Simon Martin via Gcc-cvs
https://gcc.gnu.org/g:26ee954476bef7328d2cf45928c3c9b84df77178

commit r15-3195-g26ee954476bef7328d2cf45928c3c9b84df77178
Author: Simon Martin 
Date:   Sun Aug 25 21:59:31 2024 +0200

c++: Check template parameters in member class template specialization 
[PR115716]

We currently ICE upon the following invalid code, because we don't check
that the template parameters in a member class template specialization
are correct.

=== cut here ===
template  struct x {
  template  struct y {
typedef T result2;
  };
};
template<> template struct x::y {
  typedef double result2;
};
int main() {
  x::y::result2 xxx2;
}
=== cut here ===

This patch fixes the PR by calling redeclare_class_template.

PR c++/115716

gcc/cp/ChangeLog:

* pt.cc (maybe_process_partial_specialization): Call
redeclare_class_template.

gcc/testsuite/ChangeLog:

* g++.dg/template/spec42.C: New test.
* g++.dg/template/spec43.C: New test.

Diff:
---
 gcc/cp/pt.cc   |  5 +
 gcc/testsuite/g++.dg/template/spec42.C | 17 +
 gcc/testsuite/g++.dg/template/spec43.C | 18 ++
 3 files changed, 40 insertions(+)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index bc3ad5edcc59..24a6241d3a51 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -1173,6 +1173,11 @@ maybe_process_partial_specialization (tree type)
   type, inst);
}
 
+ /* Make sure that the specialization is valid.  */
+ if (!redeclare_class_template (type, current_template_parms,
+current_template_constraints ()))
+   return error_mark_node;
+
  /* Mark TYPE as a specialization.  And as a result, we only
 have one level of template argument for the innermost
 class template.  */
diff --git a/gcc/testsuite/g++.dg/template/spec42.C 
b/gcc/testsuite/g++.dg/template/spec42.C
new file mode 100644
index ..cac1264fc9f2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/spec42.C
@@ -0,0 +1,17 @@
+// PR c++/115716
+// { dg-do compile }
+template  struct x {
+  template  struct y { // { dg-note "used 1 template parameter" }
+typedef T result2;
+  };
+};
+
+template<>
+template
+struct x::y { // { dg-error "redeclared with 2 template parameters" }
+  typedef double result2;
+};
+
+int main() {
+  x::y::result2 xxx2;
+}
diff --git a/gcc/testsuite/g++.dg/template/spec43.C 
b/gcc/testsuite/g++.dg/template/spec43.C
new file mode 100644
index ..d33659dd5063
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/spec43.C
@@ -0,0 +1,18 @@
+// PR c++/115716
+// { dg-do compile { target c++20 } }
+template  struct x {
+  template  struct y { // { dg-note "original" }
+typedef T result2;
+  };
+};
+
+template<>
+template
+requires true
+struct x::y { // { dg-error "different constraints" }
+  typedef double result2;
+};
+
+int main() {
+  x::y::result2 xxx2;
+}


[gcc r15-3196] json.h: fix typo in comment

2024-08-26 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:b835710328847a8b1bc0c1258dd4a6d059988f79

commit r15-3196-gb835710328847a8b1bc0c1258dd4a6d059988f79
Author: David Malcolm 
Date:   Mon Aug 26 12:24:21 2024 -0400

json.h: fix typo in comment

gcc/ChangeLog:
* json.h: Fix typo in comment about missing INCLUDE_MEMORY.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/json.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/json.h b/gcc/json.h
index 21f71fe1c4ab..0bafa5fbea3f 100644
--- a/gcc/json.h
+++ b/gcc/json.h
@@ -27,7 +27,7 @@ along with GCC; see the file COPYING3.  If not see
json.h.  */
 
 #ifndef INCLUDE_MEMORY
-# error "You must define INCLUDE_MEMORY before including system.h to use 
make-unique.h"
+# error "You must define INCLUDE_MEMORY before including system.h to use 
json.h"
 #endif
 
 /* Implementation of JSON, a lightweight data-interchange format.


[gcc r15-3197] pretty-print: fixes to selftests

2024-08-26 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:276cc4324b9e8d97fb1018d7b78cc0ed7e77f902

commit r15-3197-g276cc4324b9e8d97fb1018d7b78cc0ed7e77f902
Author: David Malcolm 
Date:   Mon Aug 26 12:24:21 2024 -0400

pretty-print: fixes to selftests

Add selftest coverage for %{ and %} in pretty-print.cc

No functional change intended.

gcc/ChangeLog:
* pretty-print.cc (selftest::test_urls): Make static.
(selftest::test_urls_from_braces): New.
(selftest::test_null_urls): Make static.
(selftest::test_urlification): Likewise.
(selftest::pretty_print_cc_tests): Call test_urls_from_braces.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/pretty-print.cc | 39 +++
 1 file changed, 35 insertions(+), 4 deletions(-)

diff --git a/gcc/pretty-print.cc b/gcc/pretty-print.cc
index 64713803dbe7..1d91da828212 100644
--- a/gcc/pretty-print.cc
+++ b/gcc/pretty-print.cc
@@ -3135,7 +3135,7 @@ test_prefixes_and_wrapping ()
 
 /* Verify that URL-printing works as expected.  */
 
-void
+static void
 test_urls ()
 {
   {
@@ -3169,9 +3169,40 @@ test_urls ()
   }
 }
 
+static void
+test_urls_from_braces ()
+{
+  {
+pretty_printer pp;
+pp.set_url_format (URL_FORMAT_NONE);
+pp_printf (&pp, "before %{text%} after",
+   "http://example.com";);
+ASSERT_STREQ ("before text after",
+ pp_formatted_text (&pp));
+  }
+
+  {
+pretty_printer pp;
+pp.set_url_format (URL_FORMAT_ST);
+pp_printf (&pp, "before %{text%} after",
+   "http://example.com";);
+ASSERT_STREQ ("before \33]8;;http://example.com\33\\text\33]8;;\33\\ 
after",
+ pp_formatted_text (&pp));
+  }
+
+  {
+pretty_printer pp;
+pp.set_url_format (URL_FORMAT_BEL);
+pp_printf (&pp, "before %{text%} after",
+   "http://example.com";);
+ASSERT_STREQ ("before \33]8;;http://example.com\atext\33]8;;\a after",
+ pp_formatted_text (&pp));
+  }
+}
+
 /* Verify that we gracefully reject null URLs.  */
 
-void
+static void
 test_null_urls ()
 {
   {
@@ -3221,8 +3252,7 @@ pp_printf_with_urlifier (pretty_printer *pp,
   va_end (ap);
 }
 
-
-void
+static void
 test_urlification ()
 {
   class test_urlifier : public urlifier
@@ -3424,6 +3454,7 @@ pretty_print_cc_tests ()
   test_pp_format ();
   test_prefixes_and_wrapping ();
   test_urls ();
+  test_urls_from_braces ();
   test_null_urls ();
   test_urlification ();
   test_utf8 ();


[gcc r15-3199] testsuite: add event IDs to multithreaded event plugin test

2024-08-26 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:6a1c359e28442cb86ed40e0d432814b5807e7640

commit r15-3199-g6a1c359e28442cb86ed40e0d432814b5807e7640
Author: David Malcolm 
Date:   Mon Aug 26 12:24:22 2024 -0400

testsuite: add event IDs to multithreaded event plugin test

Add test coverage of "%@" in event messages in a multithreaded
execution path.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic-test-paths-multithreaded-inline-events.c:
Update expected output.
* gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py:
Likewise.
* 
gcc.dg/plugin/diagnostic-test-paths-multithreaded-separate-events.c:
Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_paths.c
(test_diagnostic_path::add_event_2): Return the id of the added
event.
(test_diagnostic_path::add_event_2_with_event_id): New.
(example_4): Add event IDs to the deadlock messages indicating
where the locks where acquired.

Signed-off-by: David Malcolm 

Diff:
---
 ...nostic-test-paths-multithreaded-inline-events.c |  4 +-
 .../diagnostic-test-paths-multithreaded-sarif.py   |  4 +-
 ...stic-test-paths-multithreaded-separate-events.c |  4 +-
 .../gcc.dg/plugin/diagnostic_plugin_test_paths.c   | 46 +++---
 4 files changed, 38 insertions(+), 20 deletions(-)

diff --git 
a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-inline-events.c
 
b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-inline-events.c
index 333ef7359440..b306bcc1a0f3 100644
--- 
a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-inline-events.c
+++ 
b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-inline-events.c
@@ -58,7 +58,7 @@ Thread: 'Thread 1'
|   NN |   acquire_lock_b ();
|  |   ^
|  |   |
-   |  |   (5) deadlocked due to waiting for lock b in thread 1...
+   |  |   (5) deadlocked due to waiting for lock b in thread 1 
(acquired by thread 2 at (4))...
|
 
 Thread: 'Thread 2'
@@ -67,6 +67,6 @@ Thread: 'Thread 2'
|   NN |   acquire_lock_a ();
|  |   ^
|  |   |
-   |  |   (6) ...whilst waiting for lock a in thread 2
+   |  |   (6) ...whilst waiting for lock a in thread 2 (acquired 
by thread 1 at (2))
|
  { dg-end-multiline-output "" } */
diff --git 
a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py 
b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py
index cff78aa8ac8e..cb00faf1532a 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py
@@ -95,7 +95,7 @@ def test_result(sarif):
 == "lock a is now held by thread 1"
 assert tf0['locations'][2]['executionOrder'] == 5
 assert tf0['locations'][2]['location']['message']['text'] \
-== "deadlocked due to waiting for lock b in thread 1..."
+== "deadlocked due to waiting for lock b in thread 1 (acquired by 
thread 2 at (4))..."
 
 assert len(tf1['locations']) == 3
 assert tf1['locations'][0]['executionOrder'] == 3
@@ -106,4 +106,4 @@ def test_result(sarif):
 == "lock b is now held by thread 2"
 assert tf1['locations'][2]['executionOrder'] == 6
 assert tf1['locations'][2]['location']['message']['text'] \
-== "...whilst waiting for lock a in thread 2"
+== "...whilst waiting for lock a in thread 2 (acquired by thread 1 at 
(2))"
diff --git 
a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-separate-events.c
 
b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-separate-events.c
index 914918bb9e16..90464320b8e7 100644
--- 
a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-separate-events.c
+++ 
b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-separate-events.c
@@ -7,12 +7,12 @@ extern void acquire_lock_b(void);
 void foo ()
 { /* { dg-message "\\(1\\) entering 'foo'" } */
   acquire_lock_a (); /* { dg-message "\\(2\\) lock a is now held by thread 1" 
} */
-  acquire_lock_b (); /* { dg-message "\\(5\\) deadlocked due to waiting for 
lock b in thread 1\.\.\." } */
+  acquire_lock_b (); /* { dg-message "\\(5\\) deadlocked due to waiting for 
lock b in thread 1 \\(acquired by thread 2 at \\(4\\)\\)\.\.\." } */
 }
 
 void bar ()
 { /* { dg-message "\\(3\\) entering 'bar'" } */
   acquire_lock_b (); /* { dg-message "\\(4\\) lock b is now held by thread 2" 
} */
   acquire_lock_a (); /* { dg-warning "deadlock due to inconsistent lock 
acquisition order" } */
-  /* { dg-message "\\(6\\) \.\.\.whilst waiting for lock a in thread 2" "" { 
target *-*-* } .-1 } */
+  /* { dg-message "\\(6\\) \.\.\.whilst waiting for lock a in thread 2 
\\(acquired by 

[gcc r15-3200] diagnostics: consolidate on_{begin, end}_diagnostic into on_report_diagnostic

2024-08-26 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:ac707d30ce449f30c6018829d443956fdd653f4c

commit r15-3200-gac707d30ce449f30c6018829d443956fdd653f4c
Author: David Malcolm 
Date:   Mon Aug 26 12:24:22 2024 -0400

diagnostics: consolidate on_{begin,end}_diagnostic into on_report_diagnostic

Previously diagnostic_context::report_diagnostic had, after the call to
pp_format (phases 1 and 2 of formatting the message):

  m_output_format->on_begin_diagnostic (*diagnostic);
  pp_output_formatted_text (this->printer, m_urlifier);
  if (m_show_cwe)
print_any_cwe (*diagnostic);
  if (m_show_rules)
print_any_rules (*diagnostic);
  if (m_show_option_requested)
  print_option_information (*diagnostic, orig_diag_kind);
  m_output_format->on_end_diagnostic (*diagnostic, orig_diag_kind);

This patch replaces all of the above with a single call to

  m_output_format->on_report_diagnostic (*diagnostic, orig_diag_kind);

moving responsibility for phase 3 of formatting and printing the result
from diagnostic_context to the output format.

This simplifies diagnostic_context::report_diagnostic and allows us to
move the code that prints CWEs, rules, and option information in textual
form from diagnostic_context to diagnostic_text_output_format, where it
belongs.

No functional change intended.

gcc/ChangeLog:
* diagnostic-format-json.cc
(json_output_format::on_begin_diagnostic): Delete.
(json_output_format::on_end_diagnostic): Rename to...
(json_output_format::on_report_diagnostic): ...this and add call
to pp_output_formatted_text.
(diagnostic_output_format_init_json): Drop unnecessary calls
to disable textual printing of CWEs, rules, and options.
* diagnostic-format-sarif.cc (sarif_builder::end_diagnostic):
Rename to...
(sarif_builder::on_report_diagnostic): ...this and add call to
pp_output_formatted_text.
(sarif_output_format::on_begin_diagnostic): Delete.
(sarif_output_format::on_end_diagnostic): Rename to...
(sarif_output_format::on_report_diagnostic): ...this and update
call to m_builder accordingly.
(diagnostic_output_format_init_sarif): Drop unnecessary calls
to disable textual printing of CWEs, rules, and options.
* diagnostic.cc (diagnostic_context::print_any_cwe): Convert to...
(diagnostic_text_output_format::print_any_cwe): ...this.
(diagnostic_context::print_any_rules): Convert to...
(diagnostic_text_output_format::print_any_rules): ...this.
(diagnostic_context::print_option_information): Convert to...
(diagnostic_text_output_format::print_option_information):
...this.
(diagnostic_context::report_diagnostic): Replace calls to the
output format's on_begin_diagnostic, to pp_output_formatted_text,
printing CWE, rules, option info, and the call to the format's
on_end_diagnostic with a call to the format's
on_report_diagnostic.
(diagnostic_text_output_format::on_begin_diagnostic): Delete.
(diagnostic_text_output_format::on_end_diagnostic): Delete.
(diagnostic_text_output_format::on_report_diagnostic): New vfunc,
which effectively does the on_begin_diagnostic, the call to
pp_output_formatted_text, the calls for printing CWE, rules,
option info, and the call to the diagnostic_finalizer.
* diagnostic.h (diagnostic_output_format::on_begin_diagnostic):
Delete.
(diagnostic_output_format::on_end_diagnostic): Delete.
(diagnostic_output_format::on_report_diagnostic): New.
(diagnostic_text_output_format::on_begin_diagnostic): Delete.
(diagnostic_text_output_format::on_end_diagnostic): Delete.
(diagnostic_text_output_format::on_report_diagnostic): New.
(class diagnostic_context): Add friend class
diagnostic_text_output_format.
(diagnostic_context::get_urlifier): New accessor.
(diagnostic_context::print_any_cwe): Move decl...
(diagnostic_text_output_format::print_any_cwe): ...to here.
(diagnostic_context::print_any_rules): Move decl...
(diagnostic_text_output_format::print_any_rules): ...to here.
(diagnostic_context::print_option_information): Move decl...
(diagnostic_text_output_format::print_option_information): ...to
here.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-json.cc  |  24 ++--
 gcc/diagnostic-format-sarif.cc |  34 ++
 gcc/diagnostic.cc  | 261 +
 gcc/diagnostic.h   |  28 +++--
 4 files changed, 171 insertions(+), 176

[gcc r15-3201] diagnostics: move output formats from diagnostic.{c, h} to their own files

2024-08-26 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:92c5265d22afaac146b2a7ecbc3dac9fc3382877

commit r15-3201-g92c5265d22afaac146b2a7ecbc3dac9fc3382877
Author: David Malcolm 
Date:   Mon Aug 26 12:24:22 2024 -0400

diagnostics: move output formats from diagnostic.{c,h} to their own files

In particular, move the classic text output code to a
diagnostic-text.cc (analogous to -json.cc and -sarif.cc).

No functional change intended.

gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add diagnostic-format-text.o.
* diagnostic-format-json.cc: Include "diagnostic-format.h".
* diagnostic-format-sarif.cc: Likewise.
* diagnostic-format-text.cc: New file, using material from
diagnostics.cc.
* diagnostic-global-context.cc: Include
"diagnostic-format.h".
* diagnostic-format-text.h: New file, using material from
diagnostics.h.
* diagnostic-format.h: New file, using material from
diagnostics.h.
* diagnostic.cc: Include "diagnostic-format.h" and
"diagnostic-format-text.h".
(diagnostic_text_output_format::~diagnostic_text_output_format):
Move to diagnostic-format-text.cc.
(diagnostic_text_output_format::on_report_diagnostic): Likewise.
(diagnostic_text_output_format::on_diagram): Likewise.
(diagnostic_text_output_format::print_any_cwe): Likewise.
(diagnostic_text_output_format::print_any_rules): Likewise.
(diagnostic_text_output_format::print_option_information):
Likewise.
* diagnostic.h (class diagnostic_output_format): Move to
diagnostic-format.h.
(class diagnostic_text_output_format): Move to
diagnostic-format-text.h.
(diagnostic_output_format_init): Move to
diagnostic-format.h.
(diagnostic_output_format_init_json_stderr): Likewise.
(diagnostic_output_format_init_json_file): Likewise.
(diagnostic_output_format_init_sarif_stderr): Likewise.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
* gcc.cc: Include "diagnostic-format.h".
* opts.cc: Include "diagnostic-format.h".

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic_group_plugin.c: Include
"diagnostic-format-text.h".

Signed-off-by: David Malcolm 

Diff:
---
 gcc/Makefile.in|   1 +
 gcc/diagnostic-format-json.cc  |   1 +
 gcc/diagnostic-format-sarif.cc |   1 +
 gcc/diagnostic-format-text.cc  | 209 +
 gcc/diagnostic-format-text.h   |  56 ++
 gcc/diagnostic-format.h|  83 
 gcc/diagnostic-global-context.cc   |   1 +
 gcc/diagnostic.cc  | 176 +
 gcc/diagnostic.h   |  85 +
 gcc/gcc.cc |   1 +
 gcc/opts.cc|   1 +
 .../gcc.dg/plugin/diagnostic_group_plugin.c|   1 +
 12 files changed, 359 insertions(+), 257 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 8fba8f7db6a2..68fda1a75918 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1821,6 +1821,7 @@ OBJS = \
 OBJS-libcommon = diagnostic-spec.o diagnostic.o diagnostic-color.o \
diagnostic-format-json.o \
diagnostic-format-sarif.o \
+   diagnostic-format-text.o \
diagnostic-global-context.o \
diagnostic-macro-unwinding.o \
diagnostic-path.o \
diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index f2e9d0d79e51..c94f5f73bb5a 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "selftest-diagnostic.h"
 #include "diagnostic-metadata.h"
 #include "diagnostic-path.h"
+#include "diagnostic-format.h"
 #include "json.h"
 #include "selftest.h"
 #include "logical-location.h"
diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index 554bf3cb2d5c..59d9cd721839 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -29,6 +29,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "diagnostic.h"
 #include "diagnostic-metadata.h"
 #include "diagnostic-path.h"
+#include "diagnostic-format.h"
 #include "json.h"
 #include "cpplib.h"
 #include "logical-location.h"
diff --git a/gcc/diagnostic-format-text.cc b/gcc/diagnostic-format-text.cc
new file mode 100644
index ..b984803ff380
--- /dev/null
+++ b/gcc/diagnostic-format-text.cc
@@ -0,0 +1,209 @@
+/* Classic text-based output of diagnostics.
+   Copyright (C) 1999-202

[gcc r15-3198] testsuite: generalize support for Python tests for SARIF output

2024-08-26 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:aa3b950291119a2b107e3a82bb4ad35a2baa2105

commit r15-3198-gaa3b950291119a2b107e3a82bb4ad35a2baa2105
Author: David Malcolm 
Date:   Mon Aug 26 12:24:21 2024 -0400

testsuite: generalize support for Python tests for SARIF output

In r15-2354-g4d1f71d49e396c I added the ability to use Python to write
tests of SARIF output via a new "run-sarif-pytest" based
on "run-gcov-pytest", with a sarif.py support script in
testsuite/gcc.dg/sarif-output.

This followup patch:
(a) removes the limitation of such tests needing to be in
testsuite/gcc.dg/sarif-output by moving sarif.py to testsuite/lib
and adding logic to add that directory to PYTHONPATH when invoking
pytest.

(b) uses this to replace fragile regexp-based tests in
gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.c with
Python logic that verifies the structure within the generated JSON,
and to add test coverage for SARIF output relating to GCC plugins.

gcc/ChangeLog:
* diagnostic-format-sarif.cc: Add comments noting that we don't
yet capture any diagnostic_metadata::rules associated with a
diagnostic.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic-test-metadata-sarif.c: New test,
based on diagnostic-test-metadata.c.
* gcc.dg/plugin/diagnostic-test-metadata-sarif.py: New script.
* gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.c:
Replace scan-sarif-file directives with run-sarif-pytest, to
run...
* gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py:
...this new test.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add
diagnostic-test-metadata-sarif.c.
* gcc.dg/sarif-output/sarif.py: Move to...
* lib/sarif.py: ...here.
* lib/scansarif.exp (run-sarif-pytest): Prepend "lib" to
PYTHONPATH before running python scripts.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-sarif.cc |   6 +-
 .../gcc.dg/plugin/diagnostic-test-metadata-sarif.c |  17 
 .../plugin/diagnostic-test-metadata-sarif.py   |  55 +++
 .../diagnostic-test-paths-multithreaded-sarif.c|  17 +---
 .../diagnostic-test-paths-multithreaded-sarif.py   | 109 +
 gcc/testsuite/gcc.dg/plugin/plugin.exp |   4 +-
 .../{gcc.dg/sarif-output => lib}/sarif.py  |   0
 gcc/testsuite/lib/scansarif.exp|  16 +++
 8 files changed, 208 insertions(+), 16 deletions(-)

diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index 963a185f6ced..1d99c904ff0c 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -580,7 +580,9 @@ public:
  (SARIF v2.1.0 section 3.27.13).
- doesn't capture -Werror cleanly
- doesn't capture inlining information (can SARIF handle this?)
-   - doesn't capture macro expansion information (can SARIF handle this?).  */
+   - doesn't capture macro expansion information (can SARIF handle this?).
+   - doesn't capture any diagnostic_metadata::rules associated with
+ a diagnostic.  */
 
 class sarif_builder
 {
@@ -1522,6 +1524,8 @@ sarif_builder::make_result_object (diagnostic_context 
&context,
}
 
   diagnostic.metadata->maybe_add_sarif_properties (*result_obj);
+
+  /* We don't yet support diagnostic_metadata::rule.  */
 }
 
   /* "level" property (SARIF v2.1.0 section 3.27.10).  */
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-metadata-sarif.c 
b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-metadata-sarif.c
new file mode 100644
index ..246a8429090d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-metadata-sarif.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-fdiagnostics-format=sarif-file" } */
+
+extern char *gets (char *s);
+
+void test_cwe (void)
+{
+  char buf[1024];
+  gets (buf);
+}
+
+/* Verify that some JSON was written to a file with the expected name.  */
+/* { dg-final { verify-sarif-file } } */
+
+/* Use a Python script to verify various properties about the generated
+   .sarif file:
+   { dg-final { run-sarif-pytest diagnostic-test-metadata-sarif.c 
"diagnostic-test-metadata-sarif.py" } } */
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-metadata-sarif.py 
b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-metadata-sarif.py
new file mode 100644
index ..959e6f2e9942
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-metadata-sarif.py
@@ -0,0 +1,55 @@
+# We expect a warning with this textual form:
+#
+# . PATH/diagnostic-test-metadata-sarif.c: In function 'test_cwe':
+# . PATH/diagnostic-test-metadata-sarif.c:8:3: warning: never use 'gets' 
[CWE-242] [STR34-C]
+
+from sarif import *
+
+import pytest
+
+@pytest.fixture(scope='function', autouse=True)
+def sarif():
+retu

[gcc r15-3202] coroutines: diagnose usage of alloca in coroutines

2024-08-26 Thread Arsen Arsenovic via Gcc-cvs
https://gcc.gnu.org/g:c73d7f3c66c0b5865edd6880cd0d6be723cfbb8d

commit r15-3202-gc73d7f3c66c0b5865edd6880cd0d6be723cfbb8d
Author: Arsen Arsenović 
Date:   Fri Aug 2 13:17:40 2024 +0200

coroutines: diagnose usage of alloca in coroutines

We do not support it currently, and the resulting memory can only be
used inside a single resumption, so best not confuse the user with it.

PR c++/115858 - Incompatibility of coroutines and alloca()

gcc/ChangeLog:

* coroutine-passes.cc (execute_early_expand_coro_ifns): Emit a
sorry if a statement is an alloca call.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr115858.C: New test.

Diff:
---
 gcc/coroutine-passes.cc| 10 ++
 gcc/testsuite/g++.dg/coroutines/pr115858.C | 23 +++
 2 files changed, 33 insertions(+)

diff --git a/gcc/coroutine-passes.cc b/gcc/coroutine-passes.cc
index c0d6eca7c070..9124ecae5916 100644
--- a/gcc/coroutine-passes.cc
+++ b/gcc/coroutine-passes.cc
@@ -29,6 +29,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple.h"
 #include "tree-pass.h"
 #include "ssa.h"
+#include "calls.h"
 #include "cgraph.h"
 #include "pretty-print.h"
 #include "diagnostic-core.h"
@@ -306,6 +307,15 @@ execute_early_expand_coro_ifns (void)
   {
gimple *stmt = gsi_stmt (gsi);
 
+   /* Tell the user about 'alloca', we don't support it yet.  */
+   if (gimple_alloca_call_p (stmt))
+ {
+   sorry_at (gimple_location (stmt),
+ "% is not yet supported in coroutines");
+   gsi_next (&gsi);
+   continue;
+ }
+
if (!is_gimple_call (stmt) || !gimple_call_internal_p (stmt))
  {
gsi_next (&gsi);
diff --git a/gcc/testsuite/g++.dg/coroutines/pr115858.C 
b/gcc/testsuite/g++.dg/coroutines/pr115858.C
new file mode 100644
index ..3dfe820dbdfd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/coroutines/pr115858.C
@@ -0,0 +1,23 @@
+#include 
+
+struct task
+{
+  struct promise_type
+  {
+void return_void () {}
+task get_return_object () { return {}; }
+void unhandled_exception () {}
+std::suspend_never initial_suspend () { return {}; }
+std::suspend_never final_suspend () noexcept { return {}; }
+  };
+};
+
+task
+f ()
+{
+  void* a = __builtin_alloca (10);
+  // { dg-message "sorry, unimplemented: 'alloca' is not yet supported in 
coroutines" "" { target *-*-* } {.-1} }
+  void* b = __builtin_alloca_with_align (10, 16);
+  // { dg-message "sorry, unimplemented: 'alloca' is not yet supported in 
coroutines" "" { target *-*-* } {.-1} }
+  co_return;
+}


[gcc r15-3203] c++/coros: do not assume coros don't nest [PR113457]

2024-08-26 Thread Arsen Arsenovic via Gcc-cvs
https://gcc.gnu.org/g:5cca7517c5868b7b9aa13992145eb6082ac5d5b9

commit r15-3203-g5cca7517c5868b7b9aa13992145eb6082ac5d5b9
Author: Arsen Arsenović 
Date:   Fri Aug 23 20:19:05 2024 +0200

c++/coros: do not assume coros don't nest [PR113457]

In the testcase presented in the PR, during template expansion, an
tsubst of an operand causes a lambda coroutine to be processed, causing
it to get an initial suspend and final suspend.  The code for assigning
awaitable var names (get_awaitable_var) assumed that the sequence Is ->
Is -> Fs -> Fs is impossible (i.e. that one could only 'open' one
coroutine before closing it at a time), and reset the counter used for
unique numbering each time a final suspend occured.  This assumption is
false in a few cases, usually when lambdas are involved.

Instead of storing this counter in a static-storage variable, we can
store it in coroutine_info.  This struct is local to each function, so
we don't need to worry about "cross-contamination" nor resetting.

PR c++/113457

gcc/cp/ChangeLog:

* coroutines.cc (struct coroutine_info): Add integer field
awaitable_number.  This is a counter used for assigning unique
names to awaitable temporaries.
(get_awaitable_var): Use awaitable_number from coroutine_info
instead of the static int awn.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr113457-1.C: New test.
* g++.dg/coroutines/pr113457.C: New test.

Diff:
---
 gcc/cp/coroutines.cc |  19 ++-
 gcc/testsuite/g++.dg/coroutines/pr113457-1.C |  25 
 gcc/testsuite/g++.dg/coroutines/pr113457.C   | 178 +++
 3 files changed, 216 insertions(+), 6 deletions(-)

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index c3e08221cc91..5bfd7943fb81 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -96,6 +96,10 @@ struct GTY((for_user)) coroutine_info
   tree return_void;   /* The expression for p.return_void() if it exists.  */
   location_t first_coro_keyword; /* The location of the keyword that made this
function into a coroutine.  */
+
+  /* Temporary variable number assigned by get_awaitable_var.  */
+  int awaitable_number = 0;
+
   /* Flags to avoid repeated errors for per-function issues.  */
   bool coro_ret_type_error_emitted;
   bool coro_promise_error_emitted;
@@ -995,15 +999,18 @@ enum suspend_point_kind {
 static tree
 get_awaitable_var (suspend_point_kind suspend_kind, tree v_type)
 {
-  static int awn = 0;
+  auto cinfo = get_coroutine_info (current_function_decl);
+  gcc_checking_assert (cinfo);
   char *buf;
   switch (suspend_kind)
 {
-  default: buf = xasprintf ("Aw%d", awn++); break;
-  case CO_YIELD_SUSPEND_POINT: buf =  xasprintf ("Yd%d", awn++); break;
-  case INITIAL_SUSPEND_POINT: buf =  xasprintf ("Is"); break;
-  case FINAL_SUSPEND_POINT: buf =  xasprintf ("Fs"); awn = 0; break;
-  }
+default: buf = xasprintf ("Aw%d", cinfo->awaitable_number++); break;
+case CO_YIELD_SUSPEND_POINT:
+  buf = xasprintf ("Yd%d", cinfo->awaitable_number++);
+  break;
+case INITIAL_SUSPEND_POINT: buf = xasprintf ("Is"); break;
+case FINAL_SUSPEND_POINT: buf = xasprintf ("Fs"); break;
+}
   tree ret = get_identifier (buf);
   free (buf);
   ret = build_lang_decl (VAR_DECL, ret, v_type);
diff --git a/gcc/testsuite/g++.dg/coroutines/pr113457-1.C 
b/gcc/testsuite/g++.dg/coroutines/pr113457-1.C
new file mode 100644
index ..fcf67e15271c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/coroutines/pr113457-1.C
@@ -0,0 +1,25 @@
+// https://gcc.gnu.org/PR113457
+#include 
+
+struct coro
+{
+  struct promise_type
+  {
+std::suspend_never initial_suspend ();
+std::suspend_never final_suspend () noexcept;
+void return_void ();
+void unhandled_exception ();
+coro get_return_object ();
+  };
+};
+
+struct not_quite_suspend_never : std::suspend_never
+{};
+
+coro
+foo ()
+{
+  co_await std::suspend_never{},
+[] () -> coro { co_return; },
+co_await not_quite_suspend_never{};
+}
diff --git a/gcc/testsuite/g++.dg/coroutines/pr113457.C 
b/gcc/testsuite/g++.dg/coroutines/pr113457.C
new file mode 100644
index ..add45a2f8921
--- /dev/null
+++ b/gcc/testsuite/g++.dg/coroutines/pr113457.C
@@ -0,0 +1,178 @@
+// https://gcc.gnu.org/PR113457
+namespace std {
+template  _Up __declval(int);
+template  auto declval() noexcept -> decltype(__declval<_Tp>(0));
+template  struct remove_cv {
+  using type = __remove_cv(_Tp);
+};
+template  using remove_cv_t = typename remove_cv<_Tp>::type;
+template  struct remove_reference {
+  using type = __remove_reference(_Tp);
+};
+template 
+using remove_reference_t = typename remove_reference<_Tp>::type;
+template  inline constexpr bool is_array_v = __is_array(_Tp);
+template  struct remove_cvref {};
+namespace ranges 

[gcc r15-3204] combine.cc (make_more_copies): Copy attributes from the original pseudo, PR115883

2024-08-26 Thread Hans-Peter Nilsson via Gcc-cvs
https://gcc.gnu.org/g:5031df5d1f4954304c618efd2de029edc6b3699f

commit r15-3204-g5031df5d1f4954304c618efd2de029edc6b3699f
Author: Hans-Peter Nilsson 
Date:   Mon Jul 8 03:55:27 2024 +0200

combine.cc (make_more_copies): Copy attributes from the original pseudo, 
PR115883

The first of the late-combine passes, propagates some of the copies
made during the (in-time-)combine pass in make_more_copies into the
users of the "original" pseudo registers and removes the "old"
pseudos.  That effectively removes attributes such as REG_POINTER,
which matter to LRA.  The quoted PR is for an ICE-manifesting bug that
was exposed by the late-combine pass and went back to hiding with this
patch until commit r15-2937-g3673b7054ec2, the fix for PR116236, when
it was actually fixed.  To wit, this patch is only incidentally
related to that bug.

In other words, the REG_POINTER attribute should not be required for
LRA to work correctly.  This patch merely corrects state for those
propagated register-uses to ante late-combine.

For reasons not investigated, this fixes a failing test
"FAIL: gcc.dg/guality/pr54200.c -Og -DPREVENT_OPTIMIZATION line 20 z == 3"
for x86_64-linux-gnu.

PR middle-end/115883
* combine.cc (make_more_copies): Copy attributes from the original
pseudo to the new copy.

Diff:
---
 gcc/combine.cc | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/gcc/combine.cc b/gcc/combine.cc
index 40e92941e428..fef06a6cdc08 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -15102,6 +15102,12 @@ make_more_copies (void)
continue;
 
  rtx new_reg = gen_reg_rtx (GET_MODE (dest));
+
+ /* The "original" pseudo copies have important attributes
+attached, like pointerness.  We want that for these copies
+too, for use by insn recognition and later passes.  */
+ set_reg_attrs_from_value (new_reg, dest);
+
  rtx_insn *new_insn = gen_move_insn (new_reg, src);
  SET_SRC (set) = new_reg;
  emit_insn_before (new_insn, insn);


[gcc r15-3205] MIPS: Include missing mips16.S in libgcc/lib1funcs.S

2024-08-26 Thread YunQiang Su via Gcc-cvs
https://gcc.gnu.org/g:9522fc8bb7812f2ad50eb038e0938bfd958e730f

commit r15-3205-g9522fc8bb7812f2ad50eb038e0938bfd958e730f
Author: YunQiang Su 
Date:   Fri Aug 23 23:46:16 2024 +0800

MIPS: Include missing mips16.S in libgcc/lib1funcs.S

mips16.S was missing since
commit 29b74545531f6afbee9fc38c267524326dbfbedf
Date:   Thu Jun 1 10:14:24 2023 +0800

MIPS: Add speculation_barrier support

Without mips16.S included, some symbols will miss for mips16, and
so some software will fail to build.

libgcc/ChangeLog:

* config/mips/lib1funcs.S: Includes mips16.S.

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

diff --git a/libgcc/config/mips/lib1funcs.S b/libgcc/config/mips/lib1funcs.S
index fa8114b37d9c..324a84e78467 100644
--- a/libgcc/config/mips/lib1funcs.S
+++ b/libgcc/config/mips/lib1funcs.S
@@ -19,7 +19,7 @@ a copy of the GCC Runtime Library Exception along with this 
program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 .  */
 
-//#include "mips16.S"
+#include "mips16.S"
 
 #ifdef L_speculation_barrier


[gcc r14-10613] MIPS: Include missing mips16.S in libgcc/lib1funcs.S

2024-08-26 Thread YunQiang Su via Gcc-cvs
https://gcc.gnu.org/g:75892d97979f397a66730b97e8279941169e0316

commit r14-10613-g75892d97979f397a66730b97e8279941169e0316
Author: YunQiang Su 
Date:   Fri Aug 23 23:46:16 2024 +0800

MIPS: Include missing mips16.S in libgcc/lib1funcs.S

mips16.S was missing since
commit 29b74545531f6afbee9fc38c267524326dbfbedf
Date:   Thu Jun 1 10:14:24 2023 +0800

MIPS: Add speculation_barrier support

Without mips16.S included, some symbols will miss for mips16, and
so some software will fail to build.

libgcc/ChangeLog:

* config/mips/lib1funcs.S: Includes mips16.S.

(cherry picked from commit 9522fc8bb7812f2ad50eb038e0938bfd958e730f)

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

diff --git a/libgcc/config/mips/lib1funcs.S b/libgcc/config/mips/lib1funcs.S
index fa8114b37d9c..324a84e78467 100644
--- a/libgcc/config/mips/lib1funcs.S
+++ b/libgcc/config/mips/lib1funcs.S
@@ -19,7 +19,7 @@ a copy of the GCC Runtime Library Exception along with this 
program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 .  */
 
-//#include "mips16.S"
+#include "mips16.S"
 
 #ifdef L_speculation_barrier


[gcc r15-3206] c++/modules: Clean up include translation [PR110980]

2024-08-26 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:98608342932e8951a4c8db3e9df79f9187424d53

commit r15-3206-g98608342932e8951a4c8db3e9df79f9187424d53
Author: Nathaniel Shead 
Date:   Thu Aug 22 21:04:11 2024 +1000

c++/modules: Clean up include translation [PR110980]

Currently the handling of include translation is confusing to read,
using a tri-state integer without much clarity on what different states
mean.  This patch cleans this up to use explicit enumerators indicating
the different possible states instead, and fixes a bug where the option
'-flang-info-include-translate' ended being accidentally unusable.

PR c++/110980

gcc/cp/ChangeLog:

* module.cc (maybe_translate_include): Clean up.

gcc/testsuite/ChangeLog:

* g++.dg/modules/inc-xlate-2_a.H: New test.
* g++.dg/modules/inc-xlate-2_b.H: New test.
* g++.dg/modules/inc-xlate-3.h: New test.
* g++.dg/modules/inc-xlate-3_a.H: New test.

Signed-off-by: Nathaniel Shead 

Diff:
---
 gcc/cp/module.cc | 23 ++-
 gcc/testsuite/g++.dg/modules/inc-xlate-2_a.H |  3 +++
 gcc/testsuite/g++.dg/modules/inc-xlate-2_b.H |  5 +
 gcc/testsuite/g++.dg/modules/inc-xlate-3.h   |  2 ++
 gcc/testsuite/g++.dg/modules/inc-xlate-3_a.H |  5 +
 5 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 07477d33955c..4cd7e1c284b8 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -20118,15 +20118,19 @@ maybe_translate_include (cpp_reader *reader, 
line_maps *lmaps, location_t loc,
   size_t len = strlen (path);
   path = canonicalize_header_name (NULL, loc, true, path, len);
   auto packet = mapper->IncludeTranslate (path, Cody::Flags::None, len);
-  int xlate = false;
+
+  enum class xlate_kind {
+unknown, text, import,
+  } translate = xlate_kind::unknown;
+
   if (packet.GetCode () == Cody::Client::PC_BOOL)
-xlate = -int (packet.GetInteger ());
+translate = packet.GetInteger () ? xlate_kind::text : xlate_kind::unknown;
   else if (packet.GetCode () == Cody::Client::PC_PATHNAME)
 {
   /* Record the CMI name for when we do the import.  */
   module_state *import = get_module (build_string (len, path));
   import->set_filename (packet);
-  xlate = +1;
+  translate = xlate_kind::import;
 }
   else
 {
@@ -20136,9 +20140,9 @@ maybe_translate_include (cpp_reader *reader, line_maps 
*lmaps, location_t loc,
 }
 
   bool note = false;
-  if (note_include_translate_yes && xlate > 1)
+  if (note_include_translate_yes && translate == xlate_kind::import)
 note = true;
-  else if (note_include_translate_no && xlate == 0)
+  else if (note_include_translate_no && translate == xlate_kind::unknown)
 note = true;
   else if (note_includes)
 /* We do not expect the note_includes vector to be large, so O(N)
@@ -20148,15 +20152,16 @@ maybe_translate_include (cpp_reader *reader, 
line_maps *lmaps, location_t loc,
note = true;
 
   if (note)
-inform (loc, xlate
+inform (loc, translate == xlate_kind::import
? G_("include %qs translated to import")
-   : G_("include %qs processed textually") , path);
+   : G_("include %qs processed textually"), path);
 
-  dump () && dump (xlate ? "Translating include to import"
+  dump () && dump (translate == xlate_kind::import
+  ? "Translating include to import"
   : "Keeping include as include");
   dump.pop (0);
 
-  if (!(xlate > 0))
+  if (translate != xlate_kind::import)
 return nullptr;
   
   /* Create the translation text.  */
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-2_a.H 
b/gcc/testsuite/g++.dg/modules/inc-xlate-2_a.H
new file mode 100644
index ..d6a4866a6766
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/inc-xlate-2_a.H
@@ -0,0 +1,3 @@
+// PR c++/110980
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-2_b.H 
b/gcc/testsuite/g++.dg/modules/inc-xlate-2_b.H
new file mode 100644
index ..f04dd430feca
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/inc-xlate-2_b.H
@@ -0,0 +1,5 @@
+// PR c++/110980
+// { dg-additional-options "-fmodule-header -flang-info-include-translate" }
+// { dg-module-cmi {} }
+
+#include "inc-xlate-2_a.H"  // { dg-message "translated to import" }
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-3.h 
b/gcc/testsuite/g++.dg/modules/inc-xlate-3.h
new file mode 100644
index ..c0584bada0c2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/inc-xlate-3.h
@@ -0,0 +1,2 @@
+// PR c++/110980
+// Just an empty file to be an include target.
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-3_a.H 
b/gcc/testsuite/g++.dg/modules/inc-xlate-3_a.H
new file mode 100644
index ..47772089149a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/inc-xlate-3_a.H
@@ -0,0 +1,5 @

[gcc r15-3207] c++/modules: Fix include translation for already-seen headers [PR99243]

2024-08-26 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:215ff991a8681f968823b913e1c79a32d339c097

commit r15-3207-g215ff991a8681f968823b913e1c79a32d339c097
Author: Nathaniel Shead 
Date:   Thu Aug 22 20:41:54 2024 +1000

c++/modules: Fix include translation for already-seen headers [PR99243]

After importing a header unit we learn about and setup any header
modules that we transitively depend on.  However, this causes
'set_filename' to fail an assertion if we then come across this header
as an #include and attempt to translate it into a module.  We still need
to do this translation so that libcpp learns that this is a header unit,
but we shouldn't error just because we've already seen it as an import.

Instead this patch merely checks and errors to handle the case of a
broken mapper implementation which supplies a different CMI path from
the one we already got.

As a drive-by fix, also make failing to find the CMI for a module be a
fatal error: any further errors in the TU are unlikely to be helpful.

PR c++/99243

gcc/cp/ChangeLog:

* module.cc (module_state::set_filename): Handle repeated calls
to 'set_filename' as long as the CMI path matches.
(maybe_translate_include): Adjust comment.

gcc/testsuite/ChangeLog:

* g++.dg/modules/map-2.C: Prune additional fatal error message.
* g++.dg/modules/inc-xlate-4_a.H: New test.
* g++.dg/modules/inc-xlate-4_b.H: New test.
* g++.dg/modules/inc-xlate-4_c.H: New test.

Signed-off-by: Nathaniel Shead 

Diff:
---
 gcc/cp/module.cc | 18 +-
 gcc/testsuite/g++.dg/modules/inc-xlate-4_a.H |  5 +
 gcc/testsuite/g++.dg/modules/inc-xlate-4_b.H |  5 +
 gcc/testsuite/g++.dg/modules/inc-xlate-4_c.H |  6 ++
 gcc/testsuite/g++.dg/modules/map-2.C |  3 ++-
 5 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 4cd7e1c284b8..95c2405fcd47 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -20086,14 +20086,21 @@ canonicalize_header_name (cpp_reader *reader, 
location_t loc, bool unquoted,
 
 void module_state::set_filename (const Cody::Packet &packet)
 {
-  gcc_checking_assert (!filename);
   if (packet.GetCode () == Cody::Client::PC_PATHNAME)
-filename = xstrdup (packet.GetString ().c_str ());
+{
+  /* If we've seen this import before we better have the same CMI.  */
+  const std::string &path = packet.GetString ();
+  if (!filename)
+   filename = xstrdup (packet.GetString ().c_str ());
+  else if (filename != path)
+   error_at (loc, "mismatching compiled module interface: "
+ "had %qs, got %qs", filename, path.c_str ());
+}
   else
 {
   gcc_checking_assert (packet.GetCode () == Cody::Client::PC_ERROR);
-  error_at (loc, "unknown Compiled Module Interface: %s",
-   packet.GetString ().c_str ());
+  fatal_error (loc, "unknown compiled module interface: %s",
+  packet.GetString ().c_str ());
 }
 }
 
@@ -20127,7 +20134,8 @@ maybe_translate_include (cpp_reader *reader, line_maps 
*lmaps, location_t loc,
 translate = packet.GetInteger () ? xlate_kind::text : xlate_kind::unknown;
   else if (packet.GetCode () == Cody::Client::PC_PATHNAME)
 {
-  /* Record the CMI name for when we do the import.  */
+  /* Record the CMI name for when we do the import.
+We may already know about this import, but libcpp doesn't yet.  */
   module_state *import = get_module (build_string (len, path));
   import->set_filename (packet);
   translate = xlate_kind::import;
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-4_a.H 
b/gcc/testsuite/g++.dg/modules/inc-xlate-4_a.H
new file mode 100644
index ..8afb49d01a5a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/inc-xlate-4_a.H
@@ -0,0 +1,5 @@
+// PR c++/99243
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
+
+void foo();
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-4_b.H 
b/gcc/testsuite/g++.dg/modules/inc-xlate-4_b.H
new file mode 100644
index ..0e67566f5716
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/inc-xlate-4_b.H
@@ -0,0 +1,5 @@
+// PR c++/99243
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
+
+#include "inc-xlate-4_a.H"
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-4_c.H 
b/gcc/testsuite/g++.dg/modules/inc-xlate-4_c.H
new file mode 100644
index ..c2fa647bce84
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/inc-xlate-4_c.H
@@ -0,0 +1,6 @@
+// PR c++/99243
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
+
+#include "inc-xlate-4_b.H"
+#include "inc-xlate-4_a.H"
diff --git a/gcc/testsuite/g++.dg/modules/map-2.C 
b/gcc/testsuite/g++.dg/modules/map-2.C
index 94d3f7a1a41d..3f95aea36705 100644
--- a/gcc/testsuite/g++.dg/modul

[gcc r15-3208] RISC-V: Support IMM for operand 1 of ussub pattern

2024-08-26 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:a1062b0c07bb729cf6a1fff34929d22e5d5b633d

commit r15-3208-ga1062b0c07bb729cf6a1fff34929d22e5d5b633d
Author: Pan Li 
Date:   Mon Aug 26 15:58:52 2024 +0800

RISC-V: Support IMM for operand 1 of ussub pattern

This patch would like to allow IMM for the operand 1 of ussub pattern.
Aka .SAT_SUB(x, 22) as the below example.

Form 2:
  #define DEF_SAT_U_SUB_IMM_FMT_2(T, IMM) \
  T __attribute__((noinline)) \
  sat_u_sub_imm##IMM##_##T##_fmt_2 (T x)  \
  {   \
return x >= (T)IMM ? x - (T)IMM : 0;  \
  }

DEF_SAT_U_SUB_IMM_FMT_2(uint64_t, 1022)

It is almost the as support imm for operand 0 of ussub pattern, but
allow the second operand to be imm insted of the first operand.

The below test suites are passed for this patch:
1. The rv64gcv fully regression test.

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_expand_ussub): Gen xmode for the
second operand, aka y in parameter.
* config/riscv/riscv.md (ussub3): Allow const_int for operand 
2.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat_arith.h: Add test helper macros.
* gcc.target/riscv/sat_u_sub_imm-5.c: New test.
* gcc.target/riscv/sat_u_sub_imm-5_1.c: New test.
* gcc.target/riscv/sat_u_sub_imm-5_2.c: New test.
* gcc.target/riscv/sat_u_sub_imm-6.c: New test.
* gcc.target/riscv/sat_u_sub_imm-6_1.c: New test.
* gcc.target/riscv/sat_u_sub_imm-6_2.c: New test.
* gcc.target/riscv/sat_u_sub_imm-7.c: New test.
* gcc.target/riscv/sat_u_sub_imm-7_1.c: New test.
* gcc.target/riscv/sat_u_sub_imm-7_2.c: New test.
* gcc.target/riscv/sat_u_sub_imm-8.c: New test.
* gcc.target/riscv/sat_u_sub_imm-run-5.c: New test.
* gcc.target/riscv/sat_u_sub_imm-run-6.c: New test.
* gcc.target/riscv/sat_u_sub_imm-run-7.c: New test.
* gcc.target/riscv/sat_u_sub_imm-run-8.c: New test.

Signed-off-by: Pan Li 

Diff:
---
 gcc/config/riscv/riscv.cc  |  2 +-
 gcc/config/riscv/riscv.md  |  2 +-
 gcc/testsuite/gcc.target/riscv/sat_arith.h |  9 
 gcc/testsuite/gcc.target/riscv/sat_u_sub_imm-5.c   | 19 
 gcc/testsuite/gcc.target/riscv/sat_u_sub_imm-5_1.c | 19 
 gcc/testsuite/gcc.target/riscv/sat_u_sub_imm-5_2.c | 19 
 gcc/testsuite/gcc.target/riscv/sat_u_sub_imm-6.c   | 20 
 gcc/testsuite/gcc.target/riscv/sat_u_sub_imm-6_1.c | 21 +
 gcc/testsuite/gcc.target/riscv/sat_u_sub_imm-6_2.c | 22 +
 gcc/testsuite/gcc.target/riscv/sat_u_sub_imm-7.c   | 19 
 gcc/testsuite/gcc.target/riscv/sat_u_sub_imm-7_1.c | 21 +
 gcc/testsuite/gcc.target/riscv/sat_u_sub_imm-7_2.c | 22 +
 gcc/testsuite/gcc.target/riscv/sat_u_sub_imm-8.c   | 18 +++
 .../gcc.target/riscv/sat_u_sub_imm-run-5.c | 55 ++
 .../gcc.target/riscv/sat_u_sub_imm-run-6.c | 55 ++
 .../gcc.target/riscv/sat_u_sub_imm-run-7.c | 54 +
 .../gcc.target/riscv/sat_u_sub_imm-run-8.c | 48 +++
 17 files changed, 423 insertions(+), 2 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 90a6e936558d..1f544c1287ec 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -11965,7 +11965,7 @@ riscv_expand_ussub (rtx dest, rtx x, rtx y)
 {
   machine_mode mode = GET_MODE (dest);
   rtx xmode_x = riscv_gen_unsigned_xmode_reg (x, mode);
-  rtx xmode_y = gen_lowpart (Xmode, y);
+  rtx xmode_y = riscv_gen_unsigned_xmode_reg (y, mode);
   rtx xmode_lt = gen_reg_rtx (Xmode);
   rtx xmode_minus = gen_reg_rtx (Xmode);
   rtx xmode_dest = gen_reg_rtx (Xmode);
diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index a94705a8e7cc..3289ed2155ad 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -4370,7 +4370,7 @@
 (define_expand "ussub3"
   [(match_operand:ANYI 0 "register_operand")
(match_operand:ANYI 1 "reg_or_int_operand")
-   (match_operand:ANYI 2 "register_operand")]
+   (match_operand:ANYI 2 "reg_or_int_operand")]
   ""
   {
 riscv_expand_ussub (operands[0], operands[1], operands[2]);
diff --git a/gcc/testsuite/gcc.target/riscv/sat_arith.h 
b/gcc/testsuite/gcc.target/riscv/sat_arith.h
index 4eca73586c87..c8ff8320d824 100644
--- a/gcc/testsuite/gcc.target/riscv/sat_arith.h
+++ b/gcc/testsuite/gcc.target/riscv/sat_arith.h
@@ -224,6 +224,13 @@ sat_u_sub_imm##IMM##_##T##_fmt_1 (T y)  \
   return (T)IMM >= y ? (T)IMM - y : 0;  \
 }
 
+#define DEF_SAT_U_SUB_IMM_FMT_2(T, IMM) \
+T __attribute__((noinline)) \
+sat_u_sub_imm##IMM##_##T##_fmt_2 (T x)  \
+{   \
+  return x >= (T)IMM ? x - (T)IMM : 0;  \
+}
+
 #d

[gcc r15-3209] Fix another inline7.c test failure on sparc targets

2024-08-26 Thread Bernd Edlinger via Gcc-cvs
https://gcc.gnu.org/g:103127cd9398d140222c9da44715d447641bf791

commit r15-3209-g103127cd9398d140222c9da44715d447641bf791
Author: Bernd Edlinger 
Date:   Mon Aug 26 18:06:52 2024 +0200

Fix another inline7.c test failure on sparc targets

This new test was reported to be still failing on sparc targets.
Here the number of DW_AT_ranges dropped to zero.
The test should pass on this architecture with -Os, -O2 and -O3.
I tried to improve also different known problematic targets,
where only one subroutine had DW_AT_ranges:
Those are armhf (arm with hard float), powerpc and powerpc64.
The best option is to use -Os: So far the only one, where
all two inline instances in this test had two DW_AT_ranges.

gcc/testsuite/ChangeLog:

PR other/116462
* gcc.dg/debug/dwarf2/inline7.c: Switch to -Os optimization.

Diff:
---
 gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c 
b/gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c
index 083df5b586cd..8b2fa1210adf 100644
--- a/gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c
@@ -1,6 +1,6 @@
 /* Verify that at least one of both inline instances have
a DW_AT_ranges but no extra DW_TAG_lexical_block.  */
-/* { dg-options "-O -gdwarf -dA" } */
+/* { dg-options "-Os -gdwarf -dA" } */
 /* { dg-do compile } */
 /* { dg-final { scan-assembler-times "\\(DIE \\(\[^\n\]*\\) 
DW_TAG_inlined_subroutine" 2 } } */
 /* { dg-final { scan-assembler " DW_AT_ranges" } } */