[gcc r15-4766] c: Add C2Y N3370 - Case range expressions support [PR117021]

2024-10-30 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:abcfe1e51c18b14d324586f1d9d50e8238497865

commit r15-4766-gabcfe1e51c18b14d324586f1d9d50e8238497865
Author: Jakub Jelinek 
Date:   Wed Oct 30 07:59:52 2024 +0100

c: Add C2Y N3370 - Case range expressions support [PR117021]

The following patch adds the C2Y N3370 paper support.
We had the case ranges as a GNU extension for decades, so this patch
simply:
1) adds different diagnostics when it is used in C (depending on flag_isoc2y
   and pedantic and warn_c23_c2y_compat)
2) emits a pedwarn in C if in a range conversion changes the value of
   the low or high bounds and in that case doesn't emit -Woverflow and
   similar warnings anymore if the pedwarn has been diagnosed
3) changes the handling of empty ranges both in C and C++; previously
   we just warned but let the values be still looked up in the splay
   tree/entered into it (and let only gimplification throw away those
   empty cases), so e.g. case -6 ... -8: break; case -6: break;
   complained about duplicate case label.  But that actually isn't
   duplicate case label, case -6 ... -8: stands for nothing at all
   and that is how it is treated later on (thrown away)

2024-10-30  Jakub Jelinek  

PR c/117021
gcc/c-family/
* c-common.cc (c_add_case_label): Emit different diagnostics for C
on case ranges.  Diagnose for C using pedwarn conversions of range
expressions changing value and don't emit further conversion
diagnostics if the pedwarn has been diagnosed.  For empty ranges
bail out after emitting warning, don't add anything into splay
trees nor add a CASE_LABEL_EXPR.
gcc/testsuite/
* gcc.dg/switch-6.c: Expect different diagnostics.  Add -std=gnu23
to dg-options.
* gcc.dg/switch-7.c: Expect different diagnostics.  Add -std=c23
to dg-options.
* gcc.dg/gnu23-switch-1.c: New test.
* gcc.dg/gnu23-switch-2.c: New test.
* gcc.dg/c23-switch-1.c: New test.
* gcc.dg/c2y-switch-1.c: New test.
* gcc.dg/c2y-switch-2.c: New test.
* gcc.dg/c2y-switch-3.c: New test.

Diff:
---
 gcc/c-family/c-common.cc  |  46 +++-
 gcc/testsuite/gcc.dg/c23-switch-1.c   | 100 ++
 gcc/testsuite/gcc.dg/c2y-switch-1.c   |  89 ++
 gcc/testsuite/gcc.dg/c2y-switch-2.c   | 100 ++
 gcc/testsuite/gcc.dg/c2y-switch-3.c   |  40 ++
 gcc/testsuite/gcc.dg/gnu23-switch-1.c | 100 ++
 gcc/testsuite/gcc.dg/gnu23-switch-2.c |  89 ++
 gcc/testsuite/gcc.dg/switch-6.c   |   4 +-
 gcc/testsuite/gcc.dg/switch-7.c   |   4 +-
 9 files changed, 565 insertions(+), 7 deletions(-)

diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index f7feb21f70e5..06be2a37b4f6 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -5186,13 +5186,41 @@ c_add_case_label (location_t loc, splay_tree cases, 
tree cond,
 
   /* Case ranges are a GNU extension.  */
   if (high_value)
-pedwarn (loc, OPT_Wpedantic,
-"range expressions in switch statements are non-standard");
+{
+  if (c_dialect_cxx ())
+   pedwarn (loc, OPT_Wpedantic,
+"range expressions in switch statements are non-standard");
+  else if (warn_c23_c2y_compat > 0)
+   {
+ if (pedantic && !flag_isoc2y)
+   pedwarn (loc, OPT_Wc23_c2y_compat,
+"ISO C does not support range expressions in switch "
+"statements before C2Y");
+ else
+   warning_at (loc, OPT_Wc23_c2y_compat,
+   "ISO C does not support range expressions in switch "
+   "statements before C2Y");
+   }
+  else if (warn_c23_c2y_compat && pedantic && !flag_isoc2y)
+   pedwarn (loc, OPT_Wpedantic,
+"ISO C does not support range expressions in switch "
+"statements before C2Y");
+}
 
   type = TREE_TYPE (cond);
   if (low_value)
 {
   low_value = check_case_value (loc, low_value);
+  tree tem = NULL_TREE;
+  if (high_value
+ && !c_dialect_cxx ()
+ && low_value != error_mark_node
+ && !int_fits_type_p (low_value, type)
+ && pedwarn (loc, OPT_Wpedantic,
+ "conversion of %qE to %qT in range expression changes "
+ "value to %qE", low_value, type,
+ (tem = fold_convert (type, low_value
+   low_value = tem;
   low_value = convert_and_check (loc, type, low_value);
   low_value = fold (low_value);
   if (low_value == error_mark_node)
@@ -5201,6 +5229,15 @@ c_add_case_label (location_t loc, splay_tree cases, tree 
cond,
   if (high_value)
 {
   hig

[gcc r15-4772] Remove dead part of bool pattern recognition

2024-10-30 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:e8c3d0f7c19f506c20a621573d4d50497bc79e3c

commit r15-4772-ge8c3d0f7c19f506c20a621573d4d50497bc79e3c
Author: Richard Biener 
Date:   Sat Oct 26 14:29:17 2024 +0200

Remove dead part of bool pattern recognition

Given we no longer want vcond[u]{,_eq} and VEC_COND_EXPR or COND_EXPR
with embedded GENERIC comparisons the whole check_bool_pattern
and adjust_bool_stmts machinery is dead.  It is effectively dead
after r15-4713-g0942bb85fc5573 and the following patch removes it.

* tree-vect-patterns.cc (check_bool_pattern): Remove.
(adjust_bool_pattern_cast): Likewise.
(adjust_bool_pattern): Likewise.
(sort_after_uid): Likewise.
(adjust_bool_stmts): Likewise.
(vect_recog_bool_pattern): Remove calls to check_bool_pattern
and fold as if it returns false.

Diff:
---
 gcc/tree-vect-patterns.cc | 385 --
 1 file changed, 34 insertions(+), 351 deletions(-)

diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index 302101fa6a0e..945e7d2dc45d 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -5360,300 +5360,6 @@ vect_recog_mod_var_pattern (vec_info *vinfo,
 }
 
 
-/* Helper function of vect_recog_bool_pattern.  Called recursively, return
-   true if bool VAR can and should be optimized that way.  Assume it shouldn't
-   in case it's a result of a comparison which can be directly vectorized into
-   a vector comparison.  Fills in STMTS with all stmts visited during the
-   walk.  */
-
-static bool
-check_bool_pattern (tree var, vec_info *vinfo, hash_set &stmts)
-{
-  tree rhs1;
-  enum tree_code rhs_code;
-
-  stmt_vec_info def_stmt_info = vect_get_internal_def (vinfo, var);
-  if (!def_stmt_info)
-return false;
-
-  gassign *def_stmt = dyn_cast  (def_stmt_info->stmt);
-  if (!def_stmt)
-return false;
-
-  if (stmts.contains (def_stmt))
-return true;
-
-  rhs1 = gimple_assign_rhs1 (def_stmt);
-  rhs_code = gimple_assign_rhs_code (def_stmt);
-  switch (rhs_code)
-{
-case SSA_NAME:
-  if (! check_bool_pattern (rhs1, vinfo, stmts))
-   return false;
-  break;
-
-CASE_CONVERT:
-  if (!VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (rhs1)))
-   return false;
-  if (! check_bool_pattern (rhs1, vinfo, stmts))
-   return false;
-  break;
-
-case BIT_NOT_EXPR:
-  if (! check_bool_pattern (rhs1, vinfo, stmts))
-   return false;
-  break;
-
-case BIT_AND_EXPR:
-case BIT_IOR_EXPR:
-case BIT_XOR_EXPR:
-  if (! check_bool_pattern (rhs1, vinfo, stmts)
- || ! check_bool_pattern (gimple_assign_rhs2 (def_stmt), vinfo, stmts))
-   return false;
-  break;
-
-default:
-  return false;
-}
-
-  bool res = stmts.add (def_stmt);
-  /* We can't end up recursing when just visiting SSA defs but not PHIs.  */
-  gcc_assert (!res);
-
-  return true;
-}
-
-
-/* Helper function of adjust_bool_pattern.  Add a cast to TYPE to a previous
-   stmt (SSA_NAME_DEF_STMT of VAR) adding a cast to STMT_INFOs
-   pattern sequence.  */
-
-static tree
-adjust_bool_pattern_cast (vec_info *vinfo,
- tree type, tree var, stmt_vec_info stmt_info)
-{
-  gimple *cast_stmt = gimple_build_assign (vect_recog_temp_ssa_var (type, 
NULL),
-  NOP_EXPR, var);
-  append_pattern_def_seq (vinfo, stmt_info, cast_stmt,
- get_vectype_for_scalar_type (vinfo, type));
-  return gimple_assign_lhs (cast_stmt);
-}
-
-/* Helper function of vect_recog_bool_pattern.  Do the actual transformations.
-   VAR is an SSA_NAME that should be transformed from bool to a wider integer
-   type, OUT_TYPE is the desired final integer type of the whole pattern.
-   STMT_INFO is the info of the pattern root and is where pattern stmts should
-   be associated with.  DEFS is a map of pattern defs.  */
-
-static void
-adjust_bool_pattern (vec_info *vinfo, tree var, tree out_type,
-stmt_vec_info stmt_info, hash_map  &defs)
-{
-  gimple *stmt = SSA_NAME_DEF_STMT (var);
-  enum tree_code rhs_code, def_rhs_code;
-  tree itype, cond_expr, rhs1, rhs2, irhs1, irhs2;
-  location_t loc;
-  gimple *pattern_stmt, *def_stmt;
-  tree trueval = NULL_TREE;
-
-  rhs1 = gimple_assign_rhs1 (stmt);
-  rhs2 = gimple_assign_rhs2 (stmt);
-  rhs_code = gimple_assign_rhs_code (stmt);
-  loc = gimple_location (stmt);
-  switch (rhs_code)
-{
-case SSA_NAME:
-CASE_CONVERT:
-  irhs1 = *defs.get (rhs1);
-  itype = TREE_TYPE (irhs1);
-  pattern_stmt
-   = gimple_build_assign (vect_recog_temp_ssa_var (itype, NULL),
-  SSA_NAME, irhs1);
-  break;
-
-case BIT_NOT_EXPR:
-  irhs1 = *defs.get (rhs1);
-  itype = TREE_TYPE (irhs1);
-  pattern_stmt
-   = gimple_build_assign (vect_recog_temp_ssa_var (itype, NULL),
-  BIT_XOR

[gcc r15-4773] arm: [MVE intrinsics] Remove unused builtins qualifiers

2024-10-30 Thread Christophe Lyon via Gcc-cvs
https://gcc.gnu.org/g:df11cb0bc4ef9f12c2315c2833be3900a2847965

commit r15-4773-gdf11cb0bc4ef9f12c2315c2833be3900a2847965
Author: Christophe Lyon 
Date:   Wed Oct 30 09:50:16 2024 +

arm: [MVE intrinsics] Remove unused builtins qualifiers

After the re-implementation of MVE vld/vst intrinsics, a few builtins
qualifiers became useless.

This patch removes them to restore bootstrap (otherwise the build
fails because of 'defined but not used' errors.

gcc/ChangeLog:

* config/arm/arm-builtins.cc (STRS_QUALIFIERS): Delete.
(STRU_QUALIFIERS): Delete.
(STRS_P_QUALIFIERS): Delete.
(STRU_P_QUALIFIERS): Delete.
(LDRS_QUALIFIERS): Delete.
(LDRU_QUALIFIERS): Delete.
(LDRS_Z_QUALIFIERS): Delete.
(LDRU_Z_QUALIFIERS): Delete.

Diff:
---
 gcc/config/arm/arm-builtins.cc | 41 -
 1 file changed, 41 deletions(-)

diff --git a/gcc/config/arm/arm-builtins.cc b/gcc/config/arm/arm-builtins.cc
index 0f16503e92dd..6ee1563c02f0 100644
--- a/gcc/config/arm/arm-builtins.cc
+++ b/gcc/config/arm/arm-builtins.cc
@@ -610,16 +610,6 @@ 
arm_quadop_unone_unone_unone_none_pred_qualifiers[SIMD_MAX_BUILTIN_ARGS]
 #define QUADOP_UNONE_UNONE_UNONE_NONE_PRED_QUALIFIERS \
   (arm_quadop_unone_unone_unone_none_pred_qualifiers)
 
-static enum arm_type_qualifiers
-arm_strs_qualifiers[SIMD_MAX_BUILTIN_ARGS]
-  = { qualifier_void, qualifier_pointer, qualifier_none };
-#define STRS_QUALIFIERS (arm_strs_qualifiers)
-
-static enum arm_type_qualifiers
-arm_stru_qualifiers[SIMD_MAX_BUILTIN_ARGS]
-  = { qualifier_void, qualifier_pointer, qualifier_unsigned };
-#define STRU_QUALIFIERS (arm_stru_qualifiers)
-
 static enum arm_type_qualifiers
 arm_strss_qualifiers[SIMD_MAX_BUILTIN_ARGS]
   = { qualifier_void, qualifier_pointer, qualifier_unsigned,
@@ -643,17 +633,6 @@ arm_strsbu_qualifiers[SIMD_MAX_BUILTIN_ARGS]
   qualifier_unsigned};
 #define STRSBU_QUALIFIERS (arm_strsbu_qualifiers)
 
-static enum arm_type_qualifiers
-arm_strs_p_qualifiers[SIMD_MAX_BUILTIN_ARGS]
-  = { qualifier_void, qualifier_pointer, qualifier_none, qualifier_predicate};
-#define STRS_P_QUALIFIERS (arm_strs_p_qualifiers)
-
-static enum arm_type_qualifiers
-arm_stru_p_qualifiers[SIMD_MAX_BUILTIN_ARGS]
-  = { qualifier_void, qualifier_pointer, qualifier_unsigned,
-  qualifier_predicate};
-#define STRU_P_QUALIFIERS (arm_stru_p_qualifiers)
-
 static enum arm_type_qualifiers
 arm_strsu_p_qualifiers[SIMD_MAX_BUILTIN_ARGS]
   = { qualifier_void, qualifier_pointer, qualifier_unsigned,
@@ -688,16 +667,6 @@ arm_ldrgs_qualifiers[SIMD_MAX_BUILTIN_ARGS]
   = { qualifier_none, qualifier_pointer, qualifier_unsigned};
 #define LDRGS_QUALIFIERS (arm_ldrgs_qualifiers)
 
-static enum arm_type_qualifiers
-arm_ldrs_qualifiers[SIMD_MAX_BUILTIN_ARGS]
-  = { qualifier_none, qualifier_pointer};
-#define LDRS_QUALIFIERS (arm_ldrs_qualifiers)
-
-static enum arm_type_qualifiers
-arm_ldru_qualifiers[SIMD_MAX_BUILTIN_ARGS]
-  = { qualifier_unsigned, qualifier_pointer};
-#define LDRU_QUALIFIERS (arm_ldru_qualifiers)
-
 static enum arm_type_qualifiers
 arm_ldrgbs_qualifiers[SIMD_MAX_BUILTIN_ARGS]
   = { qualifier_none, qualifier_unsigned, qualifier_immediate};
@@ -732,16 +701,6 @@ arm_ldrgu_z_qualifiers[SIMD_MAX_BUILTIN_ARGS]
   qualifier_predicate};
 #define LDRGU_Z_QUALIFIERS (arm_ldrgu_z_qualifiers)
 
-static enum arm_type_qualifiers
-arm_ldrs_z_qualifiers[SIMD_MAX_BUILTIN_ARGS]
-  = { qualifier_none, qualifier_pointer, qualifier_predicate};
-#define LDRS_Z_QUALIFIERS (arm_ldrs_z_qualifiers)
-
-static enum arm_type_qualifiers
-arm_ldru_z_qualifiers[SIMD_MAX_BUILTIN_ARGS]
-  = { qualifier_unsigned, qualifier_pointer, qualifier_predicate};
-#define LDRU_Z_QUALIFIERS (arm_ldru_z_qualifiers)
-
 static enum arm_type_qualifiers
 arm_ldrgbwbxu_qualifiers[SIMD_MAX_BUILTIN_ARGS]
   = { qualifier_unsigned, qualifier_unsigned, qualifier_immediate};


[gcc r15-4774] Fortran: fix several front-end memleaks

2024-10-30 Thread Harald Anlauf via Gcc-cvs
https://gcc.gnu.org/g:b8291710e3a6d9f116fc9d4afba444ad697937f2

commit r15-4774-gb8291710e3a6d9f116fc9d4afba444ad697937f2
Author: Harald Anlauf 
Date:   Tue Oct 29 21:52:27 2024 +0100

Fortran: fix several front-end memleaks

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_trans_class_init_assign): Free intermediate
gfc_expr's.
* trans.cc (get_final_proc_ref): Likewise.
(get_elem_size): Likewise.
(gfc_add_finalizer_call): Likewise.

Diff:
---
 gcc/fortran/trans-expr.cc | 2 ++
 gcc/fortran/trans.cc  | 5 +
 2 files changed, 7 insertions(+)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index ff8cde93ef4f..ddbb5ecf068a 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -1890,6 +1890,8 @@ gfc_trans_class_init_assign (gfc_code *code)
 }
 
   gfc_add_expr_to_block (&block, tmp);
+  gfc_free_expr (lhs);
+  gfc_free_expr (rhs);
 
   return gfc_finish_block (&block);
 }
diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc
index 58b93e233a1c..1a0ba6370586 100644
--- a/gcc/fortran/trans.cc
+++ b/gcc/fortran/trans.cc
@@ -1128,6 +1128,9 @@ get_final_proc_ref (gfc_se *se, gfc_expr *expr, tree 
class_container)
 
   if (POINTER_TYPE_P (TREE_TYPE (se->expr)))
 se->expr = build_fold_indirect_ref_loc (input_location, se->expr);
+
+  if (expr->ts.type != BT_DERIVED && !using_class_container)
+gfc_free_expr (final_wrapper);
 }
 
 
@@ -1155,6 +1158,7 @@ get_elem_size (gfc_se *se, gfc_expr *expr, tree 
class_container)
 
   gfc_conv_expr (se, class_size);
   gcc_assert (se->post.head == NULL_TREE);
+  gfc_free_expr (class_size);
 }
 }
 
@@ -1467,6 +1471,7 @@ gfc_add_finalizer_call (stmtblock_t *block, gfc_expr 
*expr2,
 
   gfc_add_expr_to_block (block, tmp);
   gfc_add_block_to_block (block, &final_se.post);
+  gfc_free_expr (expr);
 
   return true;
 }


[gcc r14-10852] Fix ICE due to subreg:us_truncate.

2024-10-30 Thread hongtao Liu via Gcc-cvs
https://gcc.gnu.org/g:71a0cf699b6a2dc03abec53aeafab8b70db2bb07

commit r14-10852-g71a0cf699b6a2dc03abec53aeafab8b70db2bb07
Author: liuhongt 
Date:   Tue Oct 29 02:09:39 2024 -0700

Fix ICE due to subreg:us_truncate.

Force_operand issues an ICE when input
is (subreg:DI (us_truncate:V8QI)), it's probably because it's an
invalid rtx, So refine backend patterns for that.

gcc/ChangeLog:

PR target/117318
* config/i386/sse.md (*avx512vl_v2div2qi2_mask_store_1):
Rename to ..
(avx512vl_v2div2qi2_mask_store_1): .. this.
(avx512vl_v2div2qi2_mask_store_2): Change to
define_expand.
(*avx512vl_v4qi2_mask_store_1): Rename to ..
(avx512vl_v4qi2_mask_store_1): .. this.
(avx512vl_v4qi2_mask_store_2): Change to
define_expand.
(*avx512vl_v8qi2_mask_store_1): Rename to ..
(avx512vl_v8qi2_mask_store_1): .. this.
(avx512vl_v8qi2_mask_store_2): Change to
define_expand.
(*avx512vl_v4hi2_mask_store_1): Rename to ..
(avx512vl_v4hi2_mask_store_1): .. this.
(avx512vl_v4hi2_mask_store_2): Change to
define_expand.
(*avx512vl_v2div2hi2_mask_store_1): Rename to ..
(avx512vl_v2div2hi2_mask_store_1): .. this.
(avx512vl_v2div2hi2_mask_store_2): Change to
define_expand.
(*avx512vl_v2div2si2_mask_store_1): Rename to ..
(avx512vl_v2div2si2_mask_store_1): .. this.
(avx512vl_v2div2si2_mask_store_2): Change to
define_expand.
(*avx512f_v8div16qi2_mask_store_1): Rename to ..
(avx512f_v8div16qi2_mask_store_1): .. this.
(avx512f_v8div16qi2_mask_store_2): Change to
define_expand.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr117318.c: New test.

(cherry picked from commit bc0eeccf27a084461a2d5661e23468350acb43da)

Diff:
---
 gcc/config/i386/sse.md   | 268 +++
 gcc/testsuite/gcc.target/i386/pr117318.c |  12 ++
 2 files changed, 110 insertions(+), 170 deletions(-)

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index e186b6ad452d..436c1574d232 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -14590,7 +14590,7 @@
(set_attr "prefix" "evex")
(set_attr "mode" "TI")])
 
-(define_insn "*avx512vl_v2div2qi2_mask_store_1"
+(define_insn "avx512vl_v2div2qi2_mask_store_1"
   [(set (match_operand:V2QI 0 "memory_operand" "=m")
  (vec_merge:V2QI
(any_truncate:V2QI
@@ -14604,28 +14604,19 @@
(set_attr "prefix" "evex")
(set_attr "mode" "TI")])
 
-(define_insn_and_split "avx512vl_v2div2qi2_mask_store_2"
-  [(set (match_operand:HI 0 "memory_operand")
-   (subreg:HI
- (vec_merge:V2QI
-   (any_truncate:V2QI
- (match_operand:V2DI 1 "register_operand"))
-   (vec_select:V2QI
- (subreg:V4QI
-   (vec_concat:V2HI
- (match_dup 0)
- (const_int 0)) 0)
- (parallel [(const_int 0) (const_int 1)]))
-   (match_operand:QI 2 "register_operand")) 0))]
-  "TARGET_AVX512VL && ix86_pre_reload_split ()"
-  "#"
-  "&& 1"
-  [(set (match_dup 0)
-   (vec_merge:V2QI
- (any_truncate:V2QI (match_dup 1))
- (match_dup 0)
- (match_dup 2)))]
-  "operands[0] = adjust_address_nv (operands[0], V2QImode, 0);")
+(define_expand "avx512vl_v2div2qi2_mask_store_2"
+  [(match_operand:HI 0 "memory_operand")
+   (any_truncate:V2QI
+ (match_operand:V2DI 1 "register_operand"))
+   (match_operand:QI 2 "register_operand")]
+  "TARGET_AVX512VL"
+{
+  operands[0] = adjust_address_nv (operands[0], V2QImode, 0);
+  emit_insn (gen_avx512vl_v2div2qi2_mask_store_1 (operands[0],
+   operands[1],
+   operands[2]));
+  DONE;
+})
 
 (define_insn "*avx512vl_v4qi2_store_1"
   [(set (match_operand:V4QI 0 "memory_operand" "=m")
@@ -14694,7 +14685,7 @@
(set_attr "prefix" "evex")
(set_attr "mode" "TI")])
 
-(define_insn "*avx512vl_v4qi2_mask_store_1"
+(define_insn "avx512vl_v4qi2_mask_store_1"
   [(set (match_operand:V4QI 0 "memory_operand" "=m")
(vec_merge:V4QI
  (any_truncate:V4QI
@@ -14708,29 +14699,19 @@
(set_attr "prefix" "evex")
(set_attr "mode" "TI")])
 
-(define_insn_and_split "avx512vl_v4qi2_mask_store_2"
-  [(set (match_operand:SI 0 "memory_operand")
-   (subreg:SI
- (vec_merge:V4QI
-   (any_truncate:V4QI
- (match_operand:VI4_128_8_256 1 "register_operand"))
-   (vec_select:V4QI
- (subreg:V8QI
-   (vec_concat:V2SI
- (match_dup 0)
- (const_int 0)) 0)
- (parallel [(const_int 0) (const_int 1)
-   

[gcc r15-4779] [RISC-V] Aggressively hoist VXRM assignments

2024-10-30 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:a65e1487cda969e4763ae84577bf3e0d9e2b34aa

commit r15-4779-ga65e1487cda969e4763ae84577bf3e0d9e2b34aa
Author: Jeff Law 
Date:   Wed Oct 30 07:43:22 2024 -0600

[RISC-V] Aggressively hoist VXRM assignments

So a while back I was looking at pixel_avg for RISC-V where we try to
use vaaddu for the halfword-ceiling-average step.  The problem with
vaaddu is that you must set VXRM to a suitable rounding mode as it has
an undetermined state at function entry or after a function call.

It turns out some designs will fully flush their pipelines on a write to
VXRM which you can imagine is incredibly expensive.

VXRM assignments are handled by an LCM based algorithm to find "optimal"
placement points based on what insns in the stream need VXRM assignments
and the particular mode they need.

Unfortunately in pixel_avg an LCM algorithm only allows hoisting out of
the innermost loop, but not the outer loop.  The core issue is that LCM
does not allow any speculation and there are paths which would bypass
the inner loop (which don't actually trigger at runtime IIRC).

The expectation is that VXRM assignments should be exceedingly rare and
needing more than one mode even rarer.  So hoisting more aggressively
seems like a reasonable thing to do, but we don't want to burn too much
time trying to do something fancy.

So what this patch does is scan the IL once collecting any VXRM needs.
If the current function has precisely one VXRM mode needed, then we
pretend (for the sake of LCM) that the first instruction in the function
also has that need.

By doing so the VXRM assignment is essentially anticipated everywhere in
the function.  The standard LCM algorithm is run and has enough
information to hoist the VXRM assignment more aggressively, most often
to the prologue.

This helps the BPI in a measurable way (IIRC it was 2-3%).  It probably
helps some of the SiFive designs, but I've been told they still benefit
from the longer sequence of shifts & adds, hoisting just isn't enough
for those designs.  The Ventana design basically doesn't care where the
VXRM assignment is.  Point is we may want to have a tuning knob for the
patterns which need VXRM (vaadd[u], vasub[u]) at some point in the near
future.

Bootstrapped and regression tested on riscv64 and regression tested on
riscv32-elf and riscv64-elf.  We've been using this internally for a
while a while on spec as well.   Obviously I'll wait for the pre-commit
tester to do its thing.

gcc/
* config/riscv/riscv.cc (singleton_vxrm_need): New function.
(riscv_mode_needed): See if there is a singleton need and if so,
claim it happens on the first insn in the chain.

Diff:
---
 gcc/config/riscv/riscv.cc | 69 +++
 1 file changed, 69 insertions(+)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index be7c29f274d6..8443b29fb8f5 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -11807,6 +11807,65 @@ riscv_frm_mode_needed (rtx_insn *cur_insn, int code)
   return mode;
 }
 
+/* If the current function needs a single VXRM mode, return it.  Else
+   return VXRM_MODE_NONE.
+
+   This is called on the first insn in the chain and scans the full function
+   once to collect VXRM mode settings.  If a single mode is needed, it will
+   often be better to set it once at the start of the function rather than
+   at an anticipation point.  */
+static int
+singleton_vxrm_need (void)
+{
+  /* Only needed for vector code.  */
+  if (!TARGET_VECTOR)
+return VXRM_MODE_NONE;
+
+  /* If ENTRY has more than once successor, then don't optimize, just to
+ keep things simple.  */
+  if (EDGE_COUNT (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs) > 1)
+return VXRM_MODE_NONE;
+
+  /* Walk the IL noting if VXRM is needed and if there's more than one
+ mode needed.  */
+  bool found = false;
+  int saved_vxrm_mode;
+  for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
+{
+  if (!INSN_P (insn) || DEBUG_INSN_P (insn))
+   continue;
+
+  int code = recog_memoized (insn);
+  if (code < 0)
+   continue;
+
+  int vxrm_mode = get_attr_vxrm_mode (insn);
+  if (vxrm_mode == VXRM_MODE_NONE)
+   continue;
+
+  /* If this is the first VXRM need, note it.  */
+  if (!found)
+   {
+ saved_vxrm_mode = vxrm_mode;
+ found = true;
+ continue;
+   }
+
+  /* Not the first VXRM need.  If this is different than
+the saved need, then we're not going to be able to
+optimize and we can stop scanning now.  */
+  if (saved_vxrm_mode != vxrm_mode)
+   return VXRM_MODE_NONE;
+
+  /* Same mode as we've seen, keep scanning.  */
+}
+
+  /* If we got here we scanned the whole function.  If

[gcc r15-4775] Fix ICE due to subreg:us_truncate.

2024-10-30 Thread hongtao Liu via Gcc-cvs
https://gcc.gnu.org/g:bc0eeccf27a084461a2d5661e23468350acb43da

commit r15-4775-gbc0eeccf27a084461a2d5661e23468350acb43da
Author: liuhongt 
Date:   Tue Oct 29 02:09:39 2024 -0700

Fix ICE due to subreg:us_truncate.

Force_operand issues an ICE when input
is (subreg:DI (us_truncate:V8QI)), it's probably because it's an
invalid rtx, So refine backend patterns for that.

gcc/ChangeLog:

PR target/117318
* config/i386/sse.md (*avx512vl_v2div2qi2_mask_store_1):
Rename to ..
(avx512vl_v2div2qi2_mask_store_1): .. this.
(avx512vl_v2div2qi2_mask_store_2): Change to
define_expand.
(*avx512vl_v4qi2_mask_store_1): Rename to ..
(avx512vl_v4qi2_mask_store_1): .. this.
(avx512vl_v4qi2_mask_store_2): Change to
define_expand.
(*avx512vl_v8qi2_mask_store_1): Rename to ..
(avx512vl_v8qi2_mask_store_1): .. this.
(avx512vl_v8qi2_mask_store_2): Change to
define_expand.
(*avx512vl_v4hi2_mask_store_1): Rename to ..
(avx512vl_v4hi2_mask_store_1): .. this.
(avx512vl_v4hi2_mask_store_2): Change to
define_expand.
(*avx512vl_v2div2hi2_mask_store_1): Rename to ..
(avx512vl_v2div2hi2_mask_store_1): .. this.
(avx512vl_v2div2hi2_mask_store_2): Change to
define_expand.
(*avx512vl_v2div2si2_mask_store_1): Rename to ..
(avx512vl_v2div2si2_mask_store_1): .. this.
(avx512vl_v2div2si2_mask_store_2): Change to
define_expand.
(*avx512f_v8div16qi2_mask_store_1): Rename to ..
(avx512f_v8div16qi2_mask_store_1): .. this.
(avx512f_v8div16qi2_mask_store_2): Change to
define_expand.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr117318.c: New test.

Diff:
---
 gcc/config/i386/sse.md   | 268 +++
 gcc/testsuite/gcc.target/i386/pr117318.c |  12 ++
 2 files changed, 110 insertions(+), 170 deletions(-)

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 2345015db1b3..36f8567b66fd 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -15439,7 +15439,7 @@
(set_attr "prefix" "evex")
(set_attr "mode" "TI")])
 
-(define_insn "*avx512vl_v2div2qi2_mask_store_1"
+(define_insn "avx512vl_v2div2qi2_mask_store_1"
   [(set (match_operand:V2QI 0 "memory_operand" "=m")
  (vec_merge:V2QI
(any_truncate:V2QI
@@ -15453,28 +15453,19 @@
(set_attr "prefix" "evex")
(set_attr "mode" "TI")])
 
-(define_insn_and_split "avx512vl_v2div2qi2_mask_store_2"
-  [(set (match_operand:HI 0 "memory_operand")
-   (subreg:HI
- (vec_merge:V2QI
-   (any_truncate:V2QI
- (match_operand:V2DI 1 "register_operand"))
-   (vec_select:V2QI
- (subreg:V4QI
-   (vec_concat:V2HI
- (match_dup 0)
- (const_int 0)) 0)
- (parallel [(const_int 0) (const_int 1)]))
-   (match_operand:QI 2 "register_operand")) 0))]
-  "TARGET_AVX512VL && ix86_pre_reload_split ()"
-  "#"
-  "&& 1"
-  [(set (match_dup 0)
-   (vec_merge:V2QI
- (any_truncate:V2QI (match_dup 1))
- (match_dup 0)
- (match_dup 2)))]
-  "operands[0] = adjust_address_nv (operands[0], V2QImode, 0);")
+(define_expand "avx512vl_v2div2qi2_mask_store_2"
+  [(match_operand:HI 0 "memory_operand")
+   (any_truncate:V2QI
+ (match_operand:V2DI 1 "register_operand"))
+   (match_operand:QI 2 "register_operand")]
+  "TARGET_AVX512VL"
+{
+  operands[0] = adjust_address_nv (operands[0], V2QImode, 0);
+  emit_insn (gen_avx512vl_v2div2qi2_mask_store_1 (operands[0],
+   operands[1],
+   operands[2]));
+  DONE;
+})
 
 (define_insn "*avx512vl_v4qi2_store_1"
   [(set (match_operand:V4QI 0 "memory_operand" "=m")
@@ -15543,7 +15534,7 @@
(set_attr "prefix" "evex")
(set_attr "mode" "TI")])
 
-(define_insn "*avx512vl_v4qi2_mask_store_1"
+(define_insn "avx512vl_v4qi2_mask_store_1"
   [(set (match_operand:V4QI 0 "memory_operand" "=m")
(vec_merge:V4QI
  (any_truncate:V4QI
@@ -15557,29 +15548,19 @@
(set_attr "prefix" "evex")
(set_attr "mode" "TI")])
 
-(define_insn_and_split "avx512vl_v4qi2_mask_store_2"
-  [(set (match_operand:SI 0 "memory_operand")
-   (subreg:SI
- (vec_merge:V4QI
-   (any_truncate:V4QI
- (match_operand:VI4_128_8_256 1 "register_operand"))
-   (vec_select:V4QI
- (subreg:V8QI
-   (vec_concat:V2SI
- (match_dup 0)
- (const_int 0)) 0)
- (parallel [(const_int 0) (const_int 1)
-(const_int 2) (const_int 3)]))
-   (match_operand:QI 2 "register_opera

[gcc r15-4778] c++, contracts: Only check contracts attributes [PR116607].

2024-10-30 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:673d6b2cbf610508d315526f4963793a343a2070

commit r15-4778-g673d6b2cbf610508d315526f4963793a343a2070
Author: Iain Sandoe 
Date:   Wed Oct 30 10:29:49 2024 +

c++, contracts: Only check contracts attributes [PR116607].

The ICE described in the PR is caused by not filtering out non-
contract attributes before making the has_active_contract_condition
test.  Fixed, as suggested by Andrew Pinski, by just using the
existing CONTRACT_CHAIN () macro to advance through the list.

PR c++/116607

gcc/cp/ChangeLog:

* contracts.cc (has_active_contract_condition): Use the
CONTRACT_CHAIN macro to advance through the attribute list.

gcc/testsuite/ChangeLog:

* g++.dg/contracts/pr116607.C: New test.

Signed-off-by: Iain Sandoe 

Diff:
---
 gcc/cp/contracts.cc   | 2 +-
 gcc/testsuite/g++.dg/contracts/pr116607.C | 6 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc
index 2a55b87bd036..113469b49f7d 100644
--- a/gcc/cp/contracts.cc
+++ b/gcc/cp/contracts.cc
@@ -1494,7 +1494,7 @@ contract_active_p (tree contract)
 static bool
 has_active_contract_condition (tree d, tree_code c)
 {
-  for (tree as = DECL_CONTRACTS (d) ; as != NULL_TREE; as = TREE_CHAIN (as))
+  for (tree as = DECL_CONTRACTS (d) ; as != NULL_TREE; as = CONTRACT_CHAIN 
(as))
 {
   tree contract = TREE_VALUE (TREE_VALUE (as));
   if (TREE_CODE (contract) == c && contract_active_p (contract))
diff --git a/gcc/testsuite/g++.dg/contracts/pr116607.C 
b/gcc/testsuite/g++.dg/contracts/pr116607.C
new file mode 100644
index ..726a5bcf646d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/contracts/pr116607.C
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++20 -fcontracts " }
+struct a {
+  __attribute__((no_sanitize("")))
+  int f(int) [[pre:true]];
+};
+int a::f(int) { return 0; }
\ No newline at end of file


[gcc r15-4780] c: Diagnose char argument to __builtin_stdc_*

2024-10-30 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:d7f2c1bff6993cba1e46fd6902776778612c290d

commit r15-4780-gd7f2c1bff6993cba1e46fd6902776778612c290d
Author: Jakub Jelinek 
Date:   Wed Oct 30 14:51:02 2024 +0100

c: Diagnose char argument to __builtin_stdc_*

When working on __builtin_stdc_rotate_*, I've noticed that while the
second argument to those is explicitly allowed to have char type,
the first argument to all the stdc_* type-generic functions is
- standard unsigned integer type, excluding bool;
- extended unsigned integer type;
- or, bit-precise unsigned integer type whose width matches a standard
  or extended integer type, excluding bool.
but the __builtin_stdc_* lowering code was diagnosing just
!INTEGRAL_TYPE_P
ENUMERAL_TYPE
BOOLEAN_TYPE
!TYPE_UNSIGNED
Now, with -funsigned-char plain char type is TYPE_UNSIGNED, yet it isn't
allowed because it isn't standard unsigned integer type, nor
extended unsigned integer type, nor bit-precise unsigned integer type.

The following patch diagnoses char arguments and adds testsuite coverage
for that.

Or should I make it a pedwarn instead?

2024-10-30  Jakub Jelinek  

gcc/c/
* c-parser.cc (c_parser_postfix_expression): Diagnose if
first __builtin_stdc_* argument has char type even when
-funsigned-char.
gcc/testsuite/
* gcc.dg/builtin-stdc-bit-3.c: New test.
* gcc.dg/builtin-stdc-rotate-3.c: New test.

Diff:
---
 gcc/c/c-parser.cc|  8 
 gcc/testsuite/gcc.dg/builtin-stdc-bit-3.c| 21 +
 gcc/testsuite/gcc.dg/builtin-stdc-rotate-3.c |  9 +
 3 files changed, 38 insertions(+)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 88dd0be855c2..90c33970fda3 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -12382,6 +12382,14 @@ c_parser_postfix_expression (c_parser *parser)
expr.set_error ();
break;
  }
+   if (TYPE_MAIN_VARIANT (TREE_TYPE (arg_p->value))
+   == char_type_node)
+ {
+   error_at (loc, "argument 1 in call to function "
+ "%qs has % type", name);
+   expr.set_error ();
+   break;
+ }
tree arg = arg_p->value;
tree type = TYPE_MAIN_VARIANT (TREE_TYPE (arg));
/* Expand:
diff --git a/gcc/testsuite/gcc.dg/builtin-stdc-bit-3.c 
b/gcc/testsuite/gcc.dg/builtin-stdc-bit-3.c
new file mode 100644
index ..bb73768840df
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-stdc-bit-3.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-funsigned-char" } */
+
+void
+foo (void)
+{
+  __builtin_stdc_leading_zeros ((char) 0); /* { dg-error "argument 
1 in call to function '__builtin_stdc_leading_zeros' has 'char' type" } */
+  __builtin_stdc_leading_ones ((char) 0);  /* { dg-error "argument 
1 in call to function '__builtin_stdc_leading_ones' has 'char' type" } */
+  __builtin_stdc_trailing_zeros ((char) 0);/* { dg-error "argument 
1 in call to function '__builtin_stdc_trailing_zeros' has 'char' type" } */
+  __builtin_stdc_trailing_ones ((char) 0); /* { dg-error "argument 
1 in call to function '__builtin_stdc_trailing_ones' has 'char' type" } */
+  __builtin_stdc_first_leading_zero ((char) 0);/* { dg-error 
"argument 1 in call to function '__builtin_stdc_first_leading_zero' has 'char' 
type" } */
+  __builtin_stdc_first_leading_one ((char) 0); /* { dg-error "argument 
1 in call to function '__builtin_stdc_first_leading_one' has 'char' type" } */
+  __builtin_stdc_first_trailing_zero ((char) 0);   /* { dg-error "argument 
1 in call to function '__builtin_stdc_first_trailing_zero' has 'char' type" } */
+  __builtin_stdc_first_trailing_one ((char) 0);/* { dg-error 
"argument 1 in call to function '__builtin_stdc_first_trailing_one' has 'char' 
type" } */
+  __builtin_stdc_count_zeros ((char) 0);   /* { dg-error "argument 
1 in call to function '__builtin_stdc_count_zeros' has 'char' type" } */
+  __builtin_stdc_count_ones ((char) 0);/* { dg-error 
"argument 1 in call to function '__builtin_stdc_count_ones' has 'char' type" } 
*/
+  __builtin_stdc_has_single_bit ((char) 0);/* { dg-error "argument 
1 in call to function '__builtin_stdc_has_single_bit' has 'char' type" } */
+  __builtin_stdc_bit_width ((char) 0); /* { dg-error "argument 
1 in call to function '__builtin_stdc_bit_width' has 'char' type" } */
+  __builtin_stdc_bit_floor ((char) 0); /* { dg-error "argument 
1 in call to function '__builtin_stdc_bit_floor' has 'char' type" } */
+  __builtin_stdc_bit_ceil ((char) 0);  /* { dg-error "argument 
1 in call to function '__builtin_stdc_bit_ceil' has 'char' type" } */
+}
d

[gcc r14-10856] jit: fix leak of pending_assemble_externals_set [PR117275]

2024-10-30 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:acc0b9ff9cf1bcfed63812ca223251485b6471b7

commit r14-10856-gacc0b9ff9cf1bcfed63812ca223251485b6471b7
Author: David Malcolm 
Date:   Wed Oct 30 16:11:41 2024 -0400

jit: fix leak of pending_assemble_externals_set [PR117275]

My recent r15-4580-g779c0390e3b57d fix for resetting state in
varasm.cc introduced some noise to "make selftest-valgrind" and,
presumably, a memory leak in libgccjit:

==2462086== 160 (56 direct, 104 indirect) bytes in 1 blocks are definitely 
lost in loss record 248 of 352
==2462086==at 0x5270E7D: operator new(unsigned long) 
(vg_replace_malloc.c:342)
==2462086==by 0x1D1EB89: init_varasm_once() (varasm.cc:6806)
==2462086==by 0x181C845: backend_init() (toplev.cc:1826)
==2462086==by 0x181D41A: do_compile() (toplev.cc:2193)
==2462086==by 0x181D99C: toplev::main(int, char**) (toplev.cc:2371)
==2462086==by 0x378391D: main (main.cc:39)

Fixed thusly.

gcc/ChangeLog:
PR jit/117275
* varasm.cc (process_pending_assemble_externals): Reset
pending_assemble_externals_set to nullptr after deleting it.
(varasm_cc_finalize): Delete pending_assemble_externals_set.

Signed-off-by: David Malcolm 
(cherry picked from commit 7f41203f08b9948c1c636dc9d66571121c6c7793)
Signed-off-by: David Malcolm 

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

diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index 75f7694f03d6..0a0da8c142ea 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -2567,6 +2567,7 @@ process_pending_assemble_externals (void)
   pending_assemble_externals_processed = true;
   pending_libcall_symbols = NULL_RTX;
   delete pending_assemble_externals_set;
+  pending_assemble_externals_set = nullptr;
 #endif
 }
 
@@ -8748,6 +8749,7 @@ varasm_cc_finalize ()
 
 #ifdef ASM_OUTPUT_EXTERNAL
   pending_assemble_externals_processed = false;
+  delete pending_assemble_externals_set;
   pending_assemble_externals_set = nullptr;
 #endif


[gcc r14-10855] jit: reset state in varasm.cc [PR117275]

2024-10-30 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:70f911bf547326a7b9ae6e116c65c22ce0cd0e65

commit r14-10855-g70f911bf547326a7b9ae6e116c65c22ce0cd0e65
Author: David Malcolm 
Date:   Wed Oct 30 16:11:40 2024 -0400

jit: reset state in varasm.cc [PR117275]

PR jit/117275 reports various jit test failures seen on
powerpc64le-unknown-linux-gnu due to hitting this assertion
in varasm.cc on the 2nd compilation in a process:

#2  0x763e67d0 in assemble_external_libcall (fun=0x72a4b1d8)
at ../../src/gcc/varasm.cc:2650
2650  gcc_assert (!pending_assemble_externals_processed);
(gdb) p pending_assemble_externals_processed
$1 = true

We're not properly resetting state in varasm.cc after a compile
for libgccjit.

Fixed thusly.

gcc/ChangeLog:
PR jit/117275
* toplev.cc (toplev::finalize): Call varasm_cc_finalize.
* varasm.cc (varasm_cc_finalize): New.
* varasm.h (varasm_cc_finalize): New decl.

Signed-off-by: David Malcolm 
(cherry picked from commit 779c0390e3b57d1eebd41bbfe43d1f329c91de6c)
Signed-off-by: David Malcolm 

Diff:
---
 gcc/toplev.cc |  1 +
 gcc/varasm.cc | 53 +
 gcc/varasm.h  |  2 ++
 3 files changed, 56 insertions(+)

diff --git a/gcc/toplev.cc b/gcc/toplev.cc
index 2cd4096558e4..01c72a5e3af0 100644
--- a/gcc/toplev.cc
+++ b/gcc/toplev.cc
@@ -2374,6 +2374,7 @@ toplev::finalize (void)
   ira_costs_cc_finalize ();
   tree_cc_finalize ();
   reginfo_cc_finalize ();
+  varasm_cc_finalize ();
 
   /* save_decoded_options uses opts_obstack, so these must
  be cleaned up together.  */
diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index b67a0b524dbf..75f7694f03d6 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -8709,4 +8709,57 @@ handle_vtv_comdat_section (section *sect, const_tree 
decl ATTRIBUTE_UNUSED)
   switch_to_comdat_section(sect, DECL_NAME (decl));
 }
 
+void
+varasm_cc_finalize ()
+{
+  first_global_object_name = nullptr;
+  weak_global_object_name = nullptr;
+
+  const_labelno = 0;
+  size_directive_output = 0;
+
+  last_assemble_variable_decl = NULL_TREE;
+  first_function_block_is_cold = false;
+  saw_no_split_stack = false;
+  text_section = nullptr;
+  data_section = nullptr;
+  readonly_data_section = nullptr;
+  sdata_section = nullptr;
+  ctors_section = nullptr;
+  dtors_section = nullptr;
+  bss_section = nullptr;
+  sbss_section = nullptr;
+  tls_comm_section = nullptr;
+  comm_section = nullptr;
+  lcomm_section = nullptr;
+  bss_noswitch_section = nullptr;
+  exception_section = nullptr;
+  eh_frame_section = nullptr;
+  in_section = nullptr;
+  in_cold_section_p = false;
+  cold_function_name = NULL_TREE;
+  unnamed_sections = nullptr;
+  section_htab = nullptr;
+  object_block_htab = nullptr;
+  anchor_labelno = 0;
+  shared_constant_pool = nullptr;
+  pending_assemble_externals = NULL_TREE;
+  pending_libcall_symbols = nullptr;
+
+#ifdef ASM_OUTPUT_EXTERNAL
+  pending_assemble_externals_processed = false;
+  pending_assemble_externals_set = nullptr;
+#endif
+
+  weak_decls = NULL_TREE;
+  initial_trampoline = nullptr;
+  const_desc_htab = nullptr;
+  weakref_targets = NULL_TREE;
+  alias_pairs = nullptr;
+  tm_clone_hash = nullptr;
+  trampolines_created = 0;
+  elf_init_array_section = nullptr;
+  elf_fini_array_section = nullptr;
+}
+
 #include "gt-varasm.h"
diff --git a/gcc/varasm.h b/gcc/varasm.h
index d9311dc370bb..f00ac7f3e5c9 100644
--- a/gcc/varasm.h
+++ b/gcc/varasm.h
@@ -81,4 +81,6 @@ extern rtx assemble_trampoline_template (void);
 
 extern void switch_to_comdat_section (section *, tree);
 
+extern void varasm_cc_finalize ();
+
 #endif  // GCC_VARASM_H


[gcc r14-10854] testsuite, jit: fix test-error-pr63969-missing-driver.c

2024-10-30 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:771873f0a95162236ab6a237db1b142a39b2f9b9

commit r14-10854-g771873f0a95162236ab6a237db1b142a39b2f9b9
Author: David Malcolm 
Date:   Wed Oct 30 16:11:40 2024 -0400

testsuite, jit: fix test-error-pr63969-missing-driver.c

jit.dg/test-error-pr63969-missing-driver.c tries to break PATH and
verify that an error is generated when using an external driver.

However it does this by unsetting PATH, and so the test could
accidentally find the driver if the system supplies a default and the
driver happens to be installed in that path (reported as rhbz#2318021).

Fix the test by instead setting PATH to a bogus value.

gcc/testsuite/ChangeLog:
* jit.dg/test-error-pr63969-missing-driver.c (create_code): When
breaking PATH, use setenv with a bogus value, rather than
unsetenv, in case the system uses a default path that contains
the driver binary.

Signed-off-by: David Malcolm 
(cherry picked from commit f8dcb559e615dbb4557a23363f9532a3544a7241)
Signed-off-by: David Malcolm 

Diff:
---
 gcc/testsuite/jit.dg/test-error-pr63969-missing-driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/jit.dg/test-error-pr63969-missing-driver.c 
b/gcc/testsuite/jit.dg/test-error-pr63969-missing-driver.c
index 733522310deb..152e236443cc 100644
--- a/gcc/testsuite/jit.dg/test-error-pr63969-missing-driver.c
+++ b/gcc/testsuite/jit.dg/test-error-pr63969-missing-driver.c
@@ -28,7 +28,7 @@ create_code (gcc_jit_context *ctxt, void *user_data)
   /* Break PATH, so that the driver can't be found
  by gcc::jit::playback::context::compile ()
  within gcc_jit_context_compile.  */
-  unsetenv ("PATH");
+  setenv ("PATH", "/this/is/not/a/valid/path", 1);
 }
 
 void


[gcc r15-4784] syscall: don't define syscall stub on Hurd

2024-10-30 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:aad9de322774c25e80f3ade6ecd96f45b62bf40a

commit r15-4784-gaad9de322774c25e80f3ade6ecd96f45b62bf40a
Author: Ian Lance Taylor 
Date:   Tue Oct 29 15:39:02 2024 -0700

syscall: don't define syscall stub on Hurd

Patch from Samuel Thibault.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/623415

Diff:
---
 gcc/go/gofrontend/MERGE | 2 +-
 libgo/go/syscall/syscall_funcs.go   | 4 ++--
 libgo/go/syscall/syscall_funcs_stubs.go | 4 ++--
 libgo/runtime/go-nosys.c| 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index c39aca9b1b00..59badf80f40b 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-092668d6ce6d7b3aff6797247cd53dc44319c558
+f9ea9801058aa98a421784da12b76cda0b4c6cf2
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/go/syscall/syscall_funcs.go 
b/libgo/go/syscall/syscall_funcs.go
index a906fa5a42e9..fc14cb18286b 100644
--- a/libgo/go/syscall/syscall_funcs.go
+++ b/libgo/go/syscall/syscall_funcs.go
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build darwin || dragonfly || freebsd || hurd || linux || netbsd || 
openbsd || solaris
-// +build darwin dragonfly freebsd hurd linux netbsd openbsd solaris
+//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || 
solaris
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris
 
 package syscall
 
diff --git a/libgo/go/syscall/syscall_funcs_stubs.go 
b/libgo/go/syscall/syscall_funcs_stubs.go
index 11f12bd9ae3c..e37a6483b02b 100644
--- a/libgo/go/syscall/syscall_funcs_stubs.go
+++ b/libgo/go/syscall/syscall_funcs_stubs.go
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build aix || rtems
-// +build aix rtems
+//go:build aix || hurd || rtems
+// +build aix hurd rtems
 
 // These are stubs.
 
diff --git a/libgo/runtime/go-nosys.c b/libgo/runtime/go-nosys.c
index 30222df78159..cd3e7664ca06 100644
--- a/libgo/runtime/go-nosys.c
+++ b/libgo/runtime/go-nosys.c
@@ -504,7 +504,7 @@ strerror_r (int errnum, char *buf, size_t buflen)
 
 #endif /* ! HAVE_STRERROR_R */
 
-#ifndef HAVE_SYSCALL
+#if !defined(HAVE_SYSCALL) && !defined(__GNU__) /* GNU/Hurd already has a stub 
*/
 int
 syscall(int number __attribute__ ((unused)), ...)
 {


[gcc r15-4785] c: Do not document C23 support as experimental and incomplete

2024-10-30 Thread Joseph Myers via Gcc-cvs
https://gcc.gnu.org/g:857145bf9a2168c8037820148b8894fbd74a823b

commit r15-4785-g857145bf9a2168c8037820148b8894fbd74a823b
Author: Joseph Myers 
Date:   Wed Oct 30 18:50:11 2024 +

c: Do not document C23 support as experimental and incomplete

Since C23 support is substantially feature-complete, update
documentation to no longer refer to it as experimental and incomplete.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/
* doc/cpp.texi (__STDC_VERSION__): Do not refer to C23 support as
experimental.
* doc/invoke.texi (std=c23, std=gnu23): Do not document as
experimental and incomplete.
* doc/standards.texi: Do not refer to C23 support as experimental
and incomplete.

gcc/c-family/
* c.opt (std=c23, std=gnu23, std=iso9899:2024): Do not mark as
experimental and incomplete.

Diff:
---
 gcc/c-family/c.opt | 6 +++---
 gcc/doc/cpp.texi   | 2 +-
 gcc/doc/invoke.texi| 6 ++
 gcc/doc/standards.texi | 6 +++---
 4 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 3fd331cda829..e2c01083aec2 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -2590,7 +2590,7 @@ Conform to the ISO 2017 C standard (published in 2018).
 
 std=c23
 C ObjC
-Conform to the ISO 2023 C standard draft (expected to be published in 2024) 
(experimental and incomplete support).
+Conform to the ISO 2023 C standard draft (expected to be published in 2024).
 
 std=c2x
 C ObjC Alias(std=c23)
@@ -2692,7 +2692,7 @@ Conform to the ISO 2017 C standard (published in 2018) 
with GNU extensions.
 
 std=gnu23
 C ObjC
-Conform to the ISO 2023 C standard draft (expected to be published in 2024) 
with GNU extensions (experimental and incomplete support).
+Conform to the ISO 2023 C standard draft (expected to be published in 2024) 
with GNU extensions.
 
 std=gnu2x
 C ObjC Alias(std=gnu23)
@@ -2748,7 +2748,7 @@ Conform to the ISO 2017 C standard (published in 2018).
 
 std=iso9899:2024
 C ObjC Alias(std=c23)
-Conform to the ISO 2023 C standard draft (expected to be published in 2024) 
(experimental and incomplete support).
+Conform to the ISO 2023 C standard draft (expected to be published in 2024).
 
 stdlib=
 Driver C++ ObjC++ Common Condition(ENABLE_STDLIB_OPTION) Var(flag_stdlib_kind) 
Joined Enum(stdlib_kind) RejectNegative Init(1)
diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi
index db3a075c5a96..a83aa263df0f 100644
--- a/gcc/doc/cpp.texi
+++ b/gcc/doc/cpp.texi
@@ -1887,7 +1887,7 @@ the 1999 revision of the C standard; the value 
@code{201112L}
 signifies the 2011 revision of the C standard; the value
 @code{201710L} signifies the 2017 revision of the C standard (which is
 otherwise identical to the 2011 version apart from correction of
-defects).  The value @code{202311L} is used for the experimental
+defects).  The value @code{202311L} is used for the
 @option{-std=c23} and @option{-std=gnu23} modes.  An unspecified value
 larger than @code{202311L} is used for the experimental
 @option{-std=c2y} and @option{-std=gnu2y} modes.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 07920e07b4d1..19c148a7d6fa 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -2480,8 +2480,7 @@ applied with @option{-std=c11}) and a new value of
 @itemx c2x
 @itemx iso9899:2024
 ISO C23, the 2023 revision of the ISO C standard (expected to be
-published in 2024).  The support for this version is experimental and
-incomplete.  The name @samp{c2x} is deprecated.
+published in 2024).  The name @samp{c2x} is deprecated.
 
 @item c2y
 The next version of the ISO C standard, still under development.  The
@@ -2506,8 +2505,7 @@ GNU dialect of ISO C17.  This is the default for C code.
 
 @item gnu23
 @itemx gnu2x
-GNU dialect of ISO C23.  The support for this version is experimental
-and incomplete.  The name @samp{gnu2x} is deprecated.
+GNU dialect of ISO C23.  The name @samp{gnu2x} is deprecated.
 
 @item gnu2y
 The next version of the ISO C standard, still under development, plus
diff --git a/gcc/doc/standards.texi b/gcc/doc/standards.texi
index 484fbb10352d..4ef28e910d77 100644
--- a/gcc/doc/standards.texi
+++ b/gcc/doc/standards.texi
@@ -115,10 +115,10 @@ known as @dfn{C17} and is supported with 
@option{-std=c17} or
 @option{-std=c11}, and the only difference between the options is the
 value of @code{__STDC_VERSION__}.
 
-A fifth version of the C standard, known as @dfn{C23}, is under
-development and expected to be published in 2024 as ISO/IEC 9899:2024.
+A fifth version of the C standard, known as @dfn{C23}, is
+expected to be published in 2024 as ISO/IEC 9899:2024.
 (While in development, drafts of this standard version were referred
-to as @dfn{C2X}.)  Experimental and incomplete support for this is
+to as @dfn{C2X}.)  Support for this is
 enabled with @option{-std=c23} or @option{-std=iso9899:2024}.
 
 A further version of

[gcc/devel/rust/master] Use name resolver 2.0 for compiling break/continue

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:b7eb4b0af5ed4e1ab29d5638689194026b4e33e8

commit b7eb4b0af5ed4e1ab29d5638689194026b4e33e8
Author: Owen Avery 
Date:   Tue Oct 15 14:56:04 2024 -0400

Use name resolver 2.0 for compiling break/continue

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc
(CompileExpr::visit): Use name resolver 2.0 to lookup label
definitions for break and continue statements when name
resolution 2.0 is enabled.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/backend/rust-compile-expr.cc | 41 +++
 1 file changed, 37 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index 505303640cf6..12c2fc883fca 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -753,8 +753,24 @@ CompileExpr::visit (HIR::BreakExpr &expr)
   if (expr.has_label ())
 {
   NodeId resolved_node_id = UNKNOWN_NODEID;
-  if (!ctx->get_resolver ()->lookup_resolved_label (
-   expr.get_label ().get_mappings ().get_nodeid (), &resolved_node_id))
+  if (flag_name_resolution_2_0)
+   {
+ auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ if (auto id
+ = nr_ctx.lookup (expr.get_label ().get_mappings ().get_nodeid ()))
+   resolved_node_id = *id;
+   }
+  else
+   {
+ NodeId tmp = UNKNOWN_NODEID;
+ if (ctx->get_resolver ()->lookup_resolved_label (
+   expr.get_label ().get_mappings ().get_nodeid (), &tmp))
+   resolved_node_id = tmp;
+   }
+
+  if (resolved_node_id == UNKNOWN_NODEID)
{
  rust_error_at (
expr.get_label ().get_locus (),
@@ -799,8 +815,25 @@ CompileExpr::visit (HIR::ContinueExpr &expr)
   if (expr.has_label ())
 {
   NodeId resolved_node_id = UNKNOWN_NODEID;
-  if (!ctx->get_resolver ()->lookup_resolved_label (
-   expr.get_label ().get_mappings ().get_nodeid (), &resolved_node_id))
+  if (flag_name_resolution_2_0)
+   {
+ auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ if (auto id
+ = nr_ctx.lookup (expr.get_label ().get_mappings ().get_nodeid ()))
+   resolved_node_id = *id;
+   }
+  else
+   {
+ NodeId tmp = UNKNOWN_NODEID;
+
+ if (ctx->get_resolver ()->lookup_resolved_label (
+   expr.get_label ().get_mappings ().get_nodeid (), &tmp))
+   resolved_node_id = tmp;
+   }
+
+  if (resolved_node_id == UNKNOWN_NODEID)
{
  rust_error_at (
expr.get_label ().get_locus (),


[gcc/devel/rust/master] Fix name resolution 2.0 definition lookups in unsafe checker

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:4564a4f159110c5c60cf65e48bcfe9f0418a13a3

commit 4564a4f159110c5c60cf65e48bcfe9f0418a13a3
Author: Owen Avery 
Date:   Wed Oct 9 00:16:27 2024 -0400

Fix name resolution 2.0 definition lookups in unsafe checker

gcc/rust/ChangeLog:

* checks/errors/rust-unsafe-checker.cc: Add includes.
(UnsafeChecker::visit): Use 2.0 version of resolver when name
resolution 2.0 is enabled.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/checks/errors/rust-unsafe-checker.cc | 42 ---
 gcc/testsuite/rust/compile/nr2/exclude|  6 
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc 
b/gcc/rust/checks/errors/rust-unsafe-checker.cc
index af3cd80245d1..3bf72428aadb 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.cc
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc
@@ -23,6 +23,10 @@
 #include "rust-hir-item.h"
 #include "rust-attribute-values.h"
 #include "rust-system.h"
+#include "rust-immutable-name-resolution-context.h"
+
+// for flag_name_resolution_2_0
+#include "options.h"
 
 namespace Rust {
 namespace HIR {
@@ -216,8 +220,23 @@ UnsafeChecker::visit (PathInExpression &path)
   NodeId ast_node_id = path.get_mappings ().get_nodeid ();
   NodeId ref_node_id;
 
-  if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
-return;
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  auto resolved = nr_ctx.lookup (ast_node_id);
+
+  if (!resolved.has_value ())
+   return;
+
+  ref_node_id = resolved.value ();
+}
+  else
+{
+  if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
+   return;
+}
 
   if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))
 {
@@ -418,8 +437,23 @@ UnsafeChecker::visit (CallExpr &expr)
   // There are no unsafe types, and functions are defined in the name resolver.
   // If we can't find the name, then we're dealing with a type and should 
return
   // early.
-  if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
-return;
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  auto resolved = nr_ctx.lookup (ast_node_id);
+
+  if (!resolved.has_value ())
+   return;
+
+  ref_node_id = resolved.value ();
+}
+  else
+{
+  if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
+   return;
+}
 
   if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))
 {
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 450fc254452d..47d651b22bdf 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -191,12 +191,6 @@ traits9.rs
 type-bindings1.rs
 unconstrained_type_param.rs
 undeclared_label.rs
-unsafe1.rs
-unsafe11.rs
-unsafe2.rs
-unsafe3.rs
-unsafe6.rs
-unsafe7.rs
 use_1.rs
 use_2.rs
 v0-mangle1.rs


[gcc/devel/rust/master] Make const references to ForeverStack more useful

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:d833d233c205a5bd19bb9a3d8254b2f24cf2ce22

commit d833d233c205a5bd19bb9a3d8254b2f24cf2ce22
Author: Owen Avery 
Date:   Mon Oct 21 18:35:30 2024 -0400

Make const references to ForeverStack more useful

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h
(ForeverStack::to_canonical_path): Make const.
(ForeverStack::to_rib): Add const overload.
(ForeverStack::reverse_iter): Add const overloads.
(ForeverStack::ConstDfsResult): Add.
(ForeverStack::dfs): Add const overload.
(ForeverStack::dfs_rib): Likewise.
* resolve/rust-forever-stack.hxx
(ForeverStack::reverse_iter): Add const overloads.
(ForeverStack::dfs): Add const overload.
(ForeverStack::to_canonical_path): Make const.
(ForeverStack::dfs_rib): Likewise.
(ForeverStack::to_rib): Add const overload.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-forever-stack.h   | 15 +-
 gcc/rust/resolve/rust-forever-stack.hxx | 91 +++--
 2 files changed, 102 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/resolve/rust-forever-stack.h 
b/gcc/rust/resolve/rust-forever-stack.h
index 2dcabc2c66df..b084807dd321 100644
--- a/gcc/rust/resolve/rust-forever-stack.h
+++ b/gcc/rust/resolve/rust-forever-stack.h
@@ -513,10 +513,11 @@ public:
   tl::optional resolve_path (const std::vector &segments);
 
   // FIXME: Documentation
-  tl::optional to_canonical_path (NodeId id);
+  tl::optional to_canonical_path (NodeId id) const;
 
   // FIXME: Documentation
   tl::optional to_rib (NodeId rib_id);
+  tl::optional to_rib (NodeId rib_id) const;
 
   std::string as_debug_string ();
 
@@ -579,9 +580,12 @@ private:
 
   /* Reverse iterate on `Node`s from the cursor, in an outwards fashion */
   void reverse_iter (std::function lambda);
+  void reverse_iter (std::function lambda) const;
 
   /* Reverse iterate on `Node`s from a specified one, in an outwards fashion */
   void reverse_iter (Node &start, std::function lambda);
+  void reverse_iter (const Node &start,
+std::function lambda) const;
 
   Node &cursor ();
   const Node &cursor () const;
@@ -617,11 +621,20 @@ private:
 Node &first;
 std::string second;
   };
+  struct ConstDfsResult
+  {
+const Node &first;
+std::string second;
+  };
 
   // FIXME: Documentation
   tl::optional dfs (Node &starting_point, NodeId to_find);
+  tl::optional dfs (const Node &starting_point,
+   NodeId to_find) const;
   // FIXME: Documentation
   tl::optional dfs_rib (Node &starting_point, NodeId to_find);
+  tl::optional dfs_rib (const Node &starting_point,
+NodeId to_find) const;
 };
 
 } // namespace Resolver2_0
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx 
b/gcc/rust/resolve/rust-forever-stack.hxx
index 9aa2f89907ee..42a63f6fd704 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -192,6 +192,14 @@ ForeverStack::reverse_iter (std::function lambda)
   return reverse_iter (cursor (), lambda);
 }
 
+template 
+void
+ForeverStack::reverse_iter (
+  std::function lambda) const
+{
+  return reverse_iter (cursor (), lambda);
+}
+
 template 
 void
 ForeverStack::reverse_iter (Node &start,
@@ -212,6 +220,26 @@ ForeverStack::reverse_iter (Node &start,
 }
 }
 
+template 
+void
+ForeverStack::reverse_iter (
+  const Node &start, std::function lambda) const
+{
+  auto *tmp = &start;
+
+  while (true)
+{
+  auto keep_going = lambda (*tmp);
+  if (keep_going == KeepGoing::No)
+   return;
+
+  if (tmp->is_root ())
+   return;
+
+  tmp = &tmp->parent.value ();
+}
+}
+
 template 
 typename ForeverStack::Node &
 ForeverStack::cursor ()
@@ -507,22 +535,53 @@ ForeverStack::dfs (ForeverStack::Node 
&starting_point, NodeId to_find)
   return tl::nullopt;
 }
 
+template 
+tl::optional::ConstDfsResult>
+ForeverStack::dfs (const ForeverStack::Node &starting_point,
+ NodeId to_find) const
+{
+  auto values = starting_point.rib.get_values ();
+
+  for (auto &kv : values)
+{
+  for (auto id : kv.second.ids_shadowable)
+   if (id == to_find)
+ return {{starting_point, kv.first}};
+  for (auto id : kv.second.ids_non_shadowable)
+   if (id == to_find)
+ return {{starting_point, kv.first}};
+  for (auto id : kv.second.ids_globbed)
+   if (id == to_find)
+ return {{starting_point, kv.first}};
+}
+
+  for (auto &child : starting_point.children)
+{
+  auto candidate = dfs (child.second, to_find);
+
+  if (candidate.has_value ())
+   return candidate;
+}
+
+  return tl::nullopt;
+}
+
 template 
 tl::optional
-ForeverStack::to_canonical_path (NodeId id)
+ForeverStack::to_canonical_path (NodeId id) const
 {
   // find the id in the current forever stac

[gcc/devel/rust/master] Use name resolver 2.0 in CompileTraitItem

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:98f04ecc1c36598de2706e194c650c8bbd2c2c37

commit 98f04ecc1c36598de2706e194c650c8bbd2c2c37
Author: Owen Avery 
Date:   Sat Oct 26 19:53:42 2024 -0400

Use name resolver 2.0 in CompileTraitItem

gcc/rust/ChangeLog:

* backend/rust-compile-implitem.cc
(CompileTraitItem::visit): Use name resolver 2.0 (when enabled)
to obtain canonical paths for instances of TraitItemConst and
TraitItemFunc.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/backend/rust-compile-implitem.cc | 36 +++
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-implitem.cc 
b/gcc/rust/backend/rust-compile-implitem.cc
index deac9d20f245..73b977f76872 100644
--- a/gcc/rust/backend/rust-compile-implitem.cc
+++ b/gcc/rust/backend/rust-compile-implitem.cc
@@ -27,8 +27,22 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant)
   rust_assert (concrete != nullptr);
   TyTy::BaseType *resolved_type = concrete;
 
-  auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
-constant.get_mappings ().get_nodeid ());
+  tl::optional canonical_path;
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  canonical_path = nr_ctx.values.to_canonical_path (
+   constant.get_mappings ().get_nodeid ());
+}
+  else
+{
+  canonical_path = ctx->get_mappings ().lookup_canonical_path (
+   constant.get_mappings ().get_nodeid ());
+}
+
+  rust_assert (canonical_path);
 
   HIR::Expr *const_value_expr = constant.get_expr ().get ();
   tree const_expr
@@ -75,8 +89,22 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func)
   fntype->override_context ();
 }
 
-  auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
-func.get_mappings ().get_nodeid ());
+  tl::optional canonical_path;
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  canonical_path
+   = nr_ctx.values.to_canonical_path (func.get_mappings ().get_nodeid ());
+}
+  else
+{
+  canonical_path = ctx->get_mappings ().lookup_canonical_path (
+   func.get_mappings ().get_nodeid ());
+}
+
+  rust_assert (canonical_path);
 
   // FIXME: How do we get the proper visibility here?
   auto vis = HIR::Visibility (HIR::Visibility::VisType::PUBLIC);


[gcc/devel/rust/master] Resolve SelfParam in name resolution 2.0

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:d800490dd996bdcb50bc9159801c2bb72c1c116b

commit d800490dd996bdcb50bc9159801c2bb72c1c116b
Author: Owen Avery 
Date:   Fri Oct 4 12:56:16 2024 -0400

Resolve SelfParam in name resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Handle SelfParam.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 12 
 gcc/rust/resolve/rust-late-name-resolver-2.0.h  |  1 +
 gcc/testsuite/rust/compile/nr2/exclude  |  4 
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index b85b6bc619cf..8319a9fe311a 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -164,6 +164,18 @@ Late::visit (AST::IdentifierPattern &identifier)
  identifier.get_node_id ());
 }
 
+void
+Late::visit (AST::SelfParam ¶m)
+{
+  // handle similar to AST::IdentifierPattern
+
+  DefaultResolver::visit (param);
+  // FIXME: this location should be a bit off
+  // ex: would point to the begining of "mut self" instead of the "self"
+  std::ignore = ctx.values.insert (Identifier ("self", param.get_locus ()),
+  param.get_node_id ());
+}
+
 void
 Late::visit (AST::IdentifierExpr &expr)
 {
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
index 1cdf2ec3f60d..81c3a046bf4f 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -41,6 +41,7 @@ public:
   // TODO: Do we need this?
   // void visit (AST::Method &) override;
   void visit (AST::IdentifierPattern &) override;
+  void visit (AST::SelfParam &) override;
 
   // resolutions
   void visit (AST::IdentifierExpr &) override;
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index f4304dae1d85..b4799edd4f5b 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -34,7 +34,6 @@ derive_macro6.rs
 expected_type_args2.rs
 expected_type_args3.rs
 feature_rust_attri0.rs
-feature_rust_attri1.rs
 for_lifetimes.rs
 format_args_basic_expansion.rs
 generic-default1.rs
@@ -54,13 +53,11 @@ infer-crate-name.rs
 issue-1019.rs
 issue-1031.rs
 issue-1034.rs
-issue-1128.rs
 issue-1129-2.rs
 issue-1130.rs
 issue-1165.rs
 issue-1173.rs
 issue-1235.rs
-issue-1237.rs
 issue-1272.rs
 issue-1289.rs
 issue-1447.rs
@@ -167,7 +164,6 @@ redef_error2.rs
 redef_error4.rs
 redef_error5.rs
 redef_error6.rs
-rustc_attr1.rs
 self-path1.rs
 self-path2.rs
 sizeof-stray-infer-var-bug.rs


[gcc/devel/rust/master] Improve path handling while testing name resolution 2.0

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:c220250e93a4b4312fd98fc74d718bc1c25e8e4e

commit c220250e93a4b4312fd98fc74d718bc1c25e8e4e
Author: Owen Avery 
Date:   Wed Oct 16 20:18:48 2024 -0400

Improve path handling while testing name resolution 2.0

gcc/testsuite/ChangeLog:

* rust/compile/nr2/compile.exp: Handle paths using "file join"
and "file split".
* rust/compile/nr2/exclude: Remove debug-diagnostics-on.rs.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/testsuite/rust/compile/nr2/compile.exp | 18 +-
 gcc/testsuite/rust/compile/nr2/exclude |  5 -
 2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/gcc/testsuite/rust/compile/nr2/compile.exp 
b/gcc/testsuite/rust/compile/nr2/compile.exp
index 0afe36c3c403..f2724f6c4544 100644
--- a/gcc/testsuite/rust/compile/nr2/compile.exp
+++ b/gcc/testsuite/rust/compile/nr2/compile.exp
@@ -44,23 +44,23 @@ namespace eval rust-nr2-ns {
 # Run tests in directories
 # Manually specifying these, in case some other test file
 # does something weird
-set test_dirs {. compile macros/builtin macros/mbe macros/proc}
+set test_dirs {{} {macros builtin} {macros mbe} {macros proc}}
 
 set tests_expect_ok ""
 set tests_expect_err ""
 
 foreach test_dir $test_dirs {
-foreach test [lsort [glob -nocomplain -tails -directory 
$srcdir/$subdir/../$test_dir *.rs]] {
-   if {$test_dir == "."} {
-   set test_lbl $test
-   } else {
-   set test_lbl "$test_dir/$test"
-}
+set directory [list {*}[file split $srcdir] {*}[file split $subdir]]
+   set directory [lreplace $directory end end]
+   set directory [list {*}$directory {*}$test_dir]
+foreach test [lsort [glob -nocomplain -tails -directory [file join 
{*}$directory] *.rs]] {
+   # use '/' as the path seperator for entries in the exclude file
+   set test_lbl [join [list {*}$test_dir $test] "/"]
set idx [lsearch -exact -sorted $exclude $test_lbl]
if {$idx == -1} {
-   lappend tests_expect_ok $srcdir/$subdir/../$test_dir/$test
+   lappend tests_expect_ok [file join {*}$directory $test]
} else {
-   lappend tests_expect_err $srcdir/$subdir/../$test_dir/$test
+   lappend tests_expect_err [file join {*}$directory $test]
set exclude [lreplace $exclude $idx $idx]
}
}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 57bcca0a60e5..450fc254452d 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -1,8 +1,3 @@
-# relies on exact source file path match
-# TODO: patch this file or nr2/compile.exp to handle this
-debug-diagnostics-on.rs
-
-# main list
 attr-mismatch-crate-name.rs
 attr_deprecated.rs
 attr_deprecated_2.rs


[gcc/devel/rust/master] Use name resolution 2.0 in TraitResolver

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:5ad1d886a97c271aa7e069ac9c699c0797079de0

commit 5ad1d886a97c271aa7e069ac9c699c0797079de0
Author: Owen Avery 
Date:   Sat Oct 26 19:43:11 2024 -0400

Use name resolution 2.0 in TraitResolver

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc: Add includes.
(TraitResolver::resolve_path_to_trait):
Use name resolution 2.0 resolver when enabled.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/typecheck/rust-hir-trait-resolve.cc | 24 ++--
 gcc/testsuite/rust/compile/nr2/exclude   |  2 --
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc 
b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 3e41d2f5a614..3e66e7591c7d 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -20,6 +20,10 @@
 #include "rust-hir-type-check-expr.h"
 #include "rust-substitution-mapper.h"
 #include "rust-type-util.h"
+#include "rust-immutable-name-resolution-context.h"
+
+// used for flag_name_resolution_2_0
+#include "options.h"
 
 namespace Rust {
 namespace Resolver {
@@ -110,8 +114,24 @@ TraitResolver::resolve_path_to_trait (const HIR::TypePath 
&path,
  HIR::Trait **resolved) const
 {
   NodeId ref;
-  if (!resolver->lookup_resolved_type (path.get_mappings ().get_nodeid (),
-  &ref))
+  bool ok;
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  auto ref_opt = nr_ctx.lookup (path.get_mappings ().get_nodeid ());
+
+  if ((ok = ref_opt.has_value ()))
+   ref = *ref_opt;
+}
+  else
+{
+  ok = resolver->lookup_resolved_type (path.get_mappings ().get_nodeid (),
+  &ref);
+}
+
+  if (!ok)
 {
   rust_error_at (path.get_locus (), "Failed to resolve path to node-id");
   return false;
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 424ad6860945..f4304dae1d85 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -65,7 +65,6 @@ issue-1272.rs
 issue-1289.rs
 issue-1447.rs
 issue-1483.rs
-issue-1589.rs
 issue-1725-1.rs
 issue-1725-2.rs
 issue-1786.rs
@@ -175,7 +174,6 @@ sizeof-stray-infer-var-bug.rs
 specify-crate-name.rs
 stmt_with_block_dot.rs
 struct-expr-parse.rs
-trait-cycle.rs
 traits1.rs
 traits10.rs
 traits11.rs


[gcc/devel/rust/master] Use name resolution 2.0 in TraitItemReference

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:f9f690f500da1a8ae712ce9bcba4986b1c6e7206

commit f9f690f500da1a8ae712ce9bcba4986b1c6e7206
Author: Owen Avery 
Date:   Sun Oct 27 15:55:48 2024 -0400

Use name resolution 2.0 in TraitItemReference

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check.cc: Add includes.
(TraitItemReference::get_type_from_fn): Use
ForeverStack::to_canonical_path when name resolution 2.0 is
enabled.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check.cc | 23 +--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc 
b/gcc/rust/typecheck/rust-hir-type-check.cc
index 129576f75823..99d1dba1d59f 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check.cc
@@ -23,6 +23,10 @@
 #include "rust-hir-type-check-item.h"
 #include "rust-hir-type-check-pattern.h"
 #include "rust-hir-type-check-struct-field.h"
+#include "rust-immutable-name-resolution-context.h"
+
+// for flag_name_resolution_2_0
+#include "options.h"
 
 extern bool
 saw_errors (void);
@@ -299,8 +303,23 @@ TraitItemReference::get_type_from_fn (/*const*/ 
HIR::TraitItemFunc &fn) const
 }
 
   auto &mappings = Analysis::Mappings::get ();
-  auto canonical_path
-= mappings.lookup_canonical_path (fn.get_mappings ().get_nodeid ());
+
+  tl::optional canonical_path;
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  canonical_path
+   = nr_ctx.values.to_canonical_path (fn.get_mappings ().get_nodeid ());
+}
+  else
+{
+  canonical_path
+   = mappings.lookup_canonical_path (fn.get_mappings ().get_nodeid ());
+}
+
+  rust_assert (canonical_path);
 
   RustIdent ident{*canonical_path, fn.get_locus ()};
   auto resolved = new TyTy::FnType (


[gcc/devel/rust/master] rust: Desugar IfLet* into MatchExpr

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:5fe9110bbf425f3a41f02ca191e5a34d34520712

commit 5fe9110bbf425f3a41f02ca191e5a34d34520712
Author: Marc Poulhiès 
Date:   Wed Jun 12 21:58:26 2024 +0200

rust: Desugar IfLet* into MatchExpr

Replace the "regular" AST->HIR lowering for IfLet* with a desugaring
into a MatchExpr.

Desugar a simple if let:

   if let Some(y) = some_value {
 bar();
   }

into:

   match some_value {
 Some(y) => {bar();},
 _ => ()
   }

Same applies for IfLetExprConseqElse (if let with an else block).

Desugar:

   if let Some(y) = some_value {
 bar();
   } else {
 baz();
   }

into:

   match some_value {
 Some(y) => {bar();},
 _ => {baz();}
   }

Fixes https://github.com/Rust-GCC/gccrs/issues/1177

gcc/rust/ChangeLog:

* backend/rust-compile-block.h: Adjust after removal of
HIR::IfLetExpr and HIR::IfLetExprConseqElse.
* backend/rust-compile-expr.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::visit): Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h:
Likewise.
* checks/errors/borrowck/rust-bir-builder-struct.h: Likewise.
* checks/errors/borrowck/rust-function-collector.h: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::visit):
Likewise.
* checks/errors/rust-const-checker.h: Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit):
Likewise.
* checks/errors/rust-unsafe-checker.h: Likewise.
* hir/rust-ast-lower-block.h (ASTLoweringIfLetBlock::translate):
Change return type.
* hir/rust-ast-lower.cc (ASTLoweringIfLetBlock::desugar_iflet):
New.
(ASTLoweringIfLetBlock::visit(AST::IfLetExpr &)): Adjust and use
desugar_iflet.
* hir/rust-ast-lower.h: Add comment.
* hir/rust-hir-dump.cc (Dump::do_ifletexpr): Remove.
(Dump::visit(IfLetExpr&)): Remove.
(Dump::visit(IfLetExprConseqElse&)): Remove.
* hir/rust-hir-dump.h (Dump::do_ifletexpr): Remove.
(Dump::visit(IfLetExpr&)): Remove.
(Dump::visit(IfLetExprConseqElse&)): Remove.
* hir/tree/rust-hir-expr.h (class IfLetExpr): Remove.
(class IfLetExprConseqElse): Remove.
* hir/tree/rust-hir-full-decls.h (class IfLetExpr): Remove.
(class IfLetExprConseqElse): Remove.
* hir/tree/rust-hir-visitor.h: Adjust after removal of
HIR::IfLetExpr and HIR::IfLetExprConseqElse.
* hir/tree/rust-hir.cc (IfLetExpr::as_string): Remove.
(IfLetExprConseqElse::as_string): Remove.
(IfLetExpr::accept_vis): Remove.
(IfLetExprConseqElse::accept_vis): Remove.
* hir/tree/rust-hir.h: Adjust after removal of HIR::IfLetExpr and
HIR::IfLetExprConseqElse.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.
* checks/errors/rust-hir-pattern-analysis.cc
(PatternChecker::visit (IfLetExpr &)): Remove.
(PatternChecker::visit (IfLetExprConseqElse &)): Remove.
* checks/errors/rust-hir-pattern-analysis.h (visit(IfLetExpr &)): 
Remove.
(visit(IfLetExprConseqElse &)): Remove.

gcc/testsuite/ChangeLog:

* rust/compile/if_let_expr.rs: Adjust.
* rust/compile/if_let_expr_simple.rs: New test.
* rust/compile/iflet.rs: New test.
* rust/execute/torture/iflet.rs: New test.
* rust/compile/nr2/exclude: Add iflet.rs and if_let_expr_simple.rs

Signed-off-by: Marc Poulhiès 

Diff:
---
 gcc/rust/backend/rust-compile-block.h  |   4 -
 gcc/rust/backend/rust-compile-expr.h   |   2 -
 .../errors/borrowck/rust-bir-builder-expr-stmt.cc  |  12 --
 .../errors/borrowck/rust-bir-builder-expr-stmt.h   |   2 -
 .../borrowck/rust-bir-builder-lazyboolexpr.h   |   8 -
 .../errors/borrowck/rust-bir-builder-struct.h  |   2 -
 .../errors/borrowck/rust-function-collector.h  |   2 -
 .../checks/errors/privacy/rust-privacy-reporter.cc |  15 --
 .../checks/errors/privacy/rust-privacy-reporter.h  |   2 -
 gcc/rust/checks/errors/rust-const-checker.cc   |  16 --
 gcc/rust/checks/errors/rust-const-checker.h|   2 -
 .../checks/errors/rust-hir-pattern-analysis.cc |  16 --
 gcc/

[gcc/devel/rust/master] Use name resolver 2.0 in MarkLive

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:20ef2821922d1db2f5455f8dbf455f2f6764739c

commit 20ef2821922d1db2f5455f8dbf455f2f6764739c
Author: Owen Avery 
Date:   Tue Oct 15 15:34:28 2024 -0400

Use name resolver 2.0 in MarkLive

gcc/rust/ChangeLog:

* checks/lints/rust-lint-marklive.cc
(MarkLive::visit_path_segment): Use name resolver 2.0 when
enabled.
(MarkLive::visit): Likewise.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/checks/lints/rust-lint-marklive.cc | 31 +
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/checks/lints/rust-lint-marklive.cc 
b/gcc/rust/checks/lints/rust-lint-marklive.cc
index 47f5540c0295..00fefbb6182e 100644
--- a/gcc/rust/checks/lints/rust-lint-marklive.cc
+++ b/gcc/rust/checks/lints/rust-lint-marklive.cc
@@ -155,7 +155,17 @@ MarkLive::visit_path_segment (HIR::PathExprSegment seg)
   //
   // We should mark them alive all and ignoring other kind of segments.
   // If the segment we dont care then just return false is fine
-  if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  if (auto id = nr_ctx.lookup (ast_node_id))
+   ref_node_id = *id;
+  else
+   return false;
+}
+  else if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
 {
   if (!resolver->lookup_resolved_type (ast_node_id, &ref_node_id))
return false;
@@ -232,9 +242,22 @@ MarkLive::visit (HIR::TupleIndexExpr &expr)
 void
 MarkLive::visit (HIR::TypeAlias &alias)
 {
-  NodeId ast_node_id;
-  resolver->lookup_resolved_type (
-alias.get_type_aliased ()->get_mappings ().get_nodeid (), &ast_node_id);
+  NodeId ast_node_id = UNKNOWN_NODEID;
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  if (auto id = nr_ctx.lookup (
+   alias.get_type_aliased ()->get_mappings ().get_nodeid ()))
+   ast_node_id = *id;
+}
+  else
+{
+  resolver->lookup_resolved_type (
+   alias.get_type_aliased ()->get_mappings ().get_nodeid (), &ast_node_id);
+}
+
   if (auto hid = mappings.lookup_node_to_hir (ast_node_id))
 mark_hir_id (*hid);
   else


[gcc/devel/rust/master] Load unloaded modules during toplevel resolution 2.0

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:bcc83c32a74b5bb3fd8c29a7ba15022d38c739e7

commit bcc83c32a74b5bb3fd8c29a7ba15022d38c739e7
Author: Owen Avery 
Date:   Tue Oct 15 22:24:29 2024 -0400

Load unloaded modules during toplevel resolution 2.0

This may load conditionally compiled modules too eagerly.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Load unloaded modules before attempting to
visit their items.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove issue-1089.rs.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 11 +++
 gcc/testsuite/rust/compile/nr2/exclude  |  1 -
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index c4dfdb29f7f7..9a561453d0ee 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -76,6 +76,17 @@ TopLevel::visit (AST::Module &module)
 {
   insert_or_error_out (module.get_name (), module, Namespace::Types);
 
+  // Parse the module's items if they haven't been expanded and the file
+  // should be parsed (i.e isn't hidden behind an untrue or impossible cfg
+  // directive
+  // TODO: make sure this is right
+  // TODO: avoid loading items if cfg attributes are present?
+  //   might not be needed if this runs after early resolution?
+  // This was copied from the old early resolver method
+  // 'accumulate_escaped_macros'
+  if (module.get_kind () == AST::Module::UNLOADED)
+module.load_items ();
+
   auto sub_visitor = [this, &module] () {
 for (auto &item : module.get_items ())
   item->accept_vis (*this);
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index f91cf3132c79..a698164fbd56 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -62,7 +62,6 @@ infer-crate-name.rs
 issue-1019.rs
 issue-1031.rs
 issue-1034.rs
-issue-1089.rs
 issue-1128.rs
 issue-1129-2.rs
 issue-1130.rs


[gcc/devel/rust/master] gccrs: Fix bad recursive operator overload call

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:8f23349aaf7ba6da4687ac2f4e00a0b680e0842a

commit 8f23349aaf7ba6da4687ac2f4e00a0b680e0842a
Author: Philip Herron 
Date:   Fri Oct 11 17:53:50 2024 +0100

gccrs: Fix bad recursive operator overload call

When we are typechecking the impl block for DerefMut for &mut T
the implementation follows the usual operator overload check
but this ended up just resolving directly to the Trait definition
which ends up being recursive which we usually handle. The issue
we had is that a dereference call can be for either the DEREF
or DEREF_MUT lang item here it was looking for a recurisve call
to the DEREF lang item but we were in the DEREF_MUT lang item
so this case was not accounted for.

Fixes #3032

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.h: new get locus helper
* typecheck/rust-hir-trait-resolve.cc 
(AssociatedImplTrait::get_locus): implemention
* typecheck/rust-hir-type-check-expr.cc 
(TypeCheckExpr::resolve_operator_overload):
fix overload

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3032-1.rs: New test.
* rust/compile/issue-3032-2.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/typecheck/rust-hir-trait-reference.h  |  2 +
 gcc/rust/typecheck/rust-hir-trait-resolve.cc   |  6 +++
 gcc/rust/typecheck/rust-hir-type-check-expr.cc | 21 +++---
 gcc/testsuite/rust/compile/issue-3032-1.rs | 58 ++
 gcc/testsuite/rust/compile/issue-3032-2.rs | 49 ++
 gcc/testsuite/rust/compile/nr2/exclude |  4 +-
 6 files changed, 134 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.h 
b/gcc/rust/typecheck/rust-hir-trait-reference.h
index a34463d35749..b35227dcff51 100644
--- a/gcc/rust/typecheck/rust-hir-trait-reference.h
+++ b/gcc/rust/typecheck/rust-hir-trait-reference.h
@@ -246,6 +246,8 @@ public:
 
   HIR::ImplBlock *get_impl_block ();
 
+  location_t get_locus () const;
+
   TyTy::BaseType *get_self ();
   const TyTy::BaseType *get_self () const;
 
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc 
b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 9f07f547c9cd..3e41d2f5a614 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -669,6 +669,12 @@ AssociatedImplTrait::reset_associated_types ()
   trait->clear_associated_types ();
 }
 
+location_t
+AssociatedImplTrait::get_locus () const
+{
+  return impl->get_locus ();
+}
+
 Analysis::NodeMapping
 TraitItemReference::get_parent_trait_mappings () const
 {
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc 
b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 62bbd25d4850..49f1bbb1a614 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1822,10 +1822,20 @@ TypeCheckExpr::resolve_operator_overload 
(LangItem::Kind lang_item_type,
   HIR::ImplBlock *parent = impl_item.first;
   HIR::Function *fn = impl_item.second;
 
-  if (parent->has_trait_ref ()
- && fn->get_function_name ().as_string ().compare (
-  associated_item_name)
-  == 0)
+  bool is_deref = lang_item_type == LangItem::Kind::DEREF
+ || lang_item_type == LangItem::Kind::DEREF_MUT;
+  bool is_deref_match = fn->get_function_name ().as_string ().compare (
+ LangItem::ToString (LangItem::Kind::DEREF))
+ == 0
+   || fn->get_function_name ().as_string ().compare (
+LangItem::ToString (LangItem::Kind::DEREF_MUT))
+== 0;
+
+  bool is_recursive_op
+   = fn->get_function_name ().as_string ().compare (associated_item_name)
+   == 0
+ || (is_deref && is_deref_match);
+  if (parent->has_trait_ref () && is_recursive_op)
{
  TraitReference *trait_reference
= TraitResolver::Lookup (*parent->get_trait_ref ().get ());
@@ -1842,7 +1852,8 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind 
lang_item_type,
 
  bool is_lang_item_impl
= trait_reference->get_mappings ().get_defid ()
- == respective_lang_item_id;
+   == respective_lang_item_id
+ || (is_deref && is_deref_match);
  bool self_is_lang_item_self
= fntype->get_self_type ()->is_equal (*adjusted_self);
  bool recursive_operator_overload
diff --git a/gcc/testsuite/rust/compile/issue-3032-1.rs 
b/gcc/testsuite/rust/compile/issue-3032-1.rs
new file mode 100644
index ..e9eb02794ce4
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3032-1.rs
@@ -0,0 +1,58 @@
+#![feature(negative_impls)]
+

[gcc/devel/rust/master] Handle external static items in toplevel resolver 2.0

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:d222c9356e47765b6872443b9b8d4ed8bf73d085

commit d222c9356e47765b6872443b9b8d4ed8bf73d085
Author: Owen Avery 
Date:   Tue Oct 15 23:42:41 2024 -0400

Handle external static items in toplevel resolver 2.0

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Handle ExternalStaticItem.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Likewise.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 7 +++
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h  | 1 +
 2 files changed, 8 insertions(+)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 9a561453d0ee..2193544a6640 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -264,6 +264,13 @@ TopLevel::visit (AST::StaticItem &static_item)
   Namespace::Values);
 }
 
+void
+TopLevel::visit (AST::ExternalStaticItem &static_item)
+{
+  insert_or_error_out (static_item.get_identifier ().as_string (), static_item,
+  Namespace::Values);
+}
+
 void
 TopLevel::visit (AST::StructStruct &struct_item)
 {
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
index 557fa949b402..ce84cd392fea 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -152,6 +152,7 @@ private:
   void visit (AST::Function &function) override;
   void visit (AST::BlockExpr &expr) override;
   void visit (AST::StaticItem &static_item) override;
+  void visit (AST::ExternalStaticItem &static_item) override;
   void visit (AST::StructStruct &struct_item) override;
   void visit (AST::TupleStruct &tuple_struct) override;
   void visit (AST::EnumItem &variant) override;


[gcc/devel/rust/master] Use name resolver 2.0 in const checker

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:120b23495f5844e3b1a42f8f1c8b957325ceaec1

commit 120b23495f5844e3b1a42f8f1c8b957325ceaec1
Author: Owen Avery 
Date:   Tue Oct 15 15:33:46 2024 -0400

Use name resolver 2.0 in const checker

gcc/rust/ChangeLog:

* checks/errors/rust-const-checker.cc: Add includes.
(ConstChecker::visit): Use name resolver 2.0 to lookup
function definitions when name resolution 2.0 is enabled.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/checks/errors/rust-const-checker.cc | 16 +++-
 gcc/testsuite/rust/compile/nr2/exclude   |  3 ---
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/checks/errors/rust-const-checker.cc 
b/gcc/rust/checks/errors/rust-const-checker.cc
index 27b32b111523..d3c25b566b90 100644
--- a/gcc/rust/checks/errors/rust-const-checker.cc
+++ b/gcc/rust/checks/errors/rust-const-checker.cc
@@ -22,6 +22,10 @@
 #include "rust-hir-stmt.h"
 #include "rust-hir-item.h"
 #include "rust-system.h"
+#include "rust-immutable-name-resolution-context.h"
+
+// for flag_name_resolution_2_0
+#include "options.h"
 
 namespace Rust {
 namespace HIR {
@@ -354,8 +358,18 @@ ConstChecker::visit (CallExpr &expr)
   NodeId ast_node_id = expr.get_fnexpr ()->get_mappings ().get_nodeid ();
   NodeId ref_node_id;
 
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  if (auto id = nr_ctx.lookup (ast_node_id))
+   ref_node_id = *id;
+  else
+   return;
+}
   // We don't care about types here
-  if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
+  else if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
 return;
 
   if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index a698164fbd56..ecef6d2bb259 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -27,8 +27,6 @@ closure_no_type_anno.rs
 complex-path1.rs
 complex_qualified_path_in_expr.rs
 const-issue1440.rs
-const1.rs
-const3.rs
 const_generics_3.rs
 const_generics_4.rs
 const_generics_5.rs
@@ -38,7 +36,6 @@ derive_macro1.rs
 derive_macro3.rs
 derive_macro4.rs
 derive_macro6.rs
-diagnostic_underline.rs
 expected_type_args2.rs
 expected_type_args3.rs
 feature_rust_attri0.rs


[gcc/devel/rust/master] Fix variable shadowing in late resolution 2.0

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:e52fa08837fbaf78bdfa2cde7710e4572f70eccd

commit e52fa08837fbaf78bdfa2cde7710e4572f70eccd
Author: Owen Avery 
Date:   Sun Oct 27 13:32:09 2024 -0400

Fix variable shadowing in late resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Visit the initialization expressions of let
statements before visiting their patterns.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 10 --
 gcc/testsuite/rust/compile/nr2/exclude  |  3 ---
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index 0fe2902f2f8f..b85b6bc619cf 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -126,8 +126,14 @@ Late::new_label (Identifier name, NodeId id)
 void
 Late::visit (AST::LetStmt &let)
 {
-  // so we don't need that method
-  DefaultResolver::visit (let);
+  DefaultASTVisitor::visit_outer_attrs (let);
+  if (let.has_type ())
+visit (let.get_type ());
+  // visit expression before pattern
+  // this makes variable shadowing work properly
+  if (let.has_init_expr ())
+visit (let.get_init_expr ());
+  visit (let.get_pattern ());
 
   // how do we deal with the fact that `let a = blipbloup` should look for a
   // label and cannot go through function ribs, but `let a = blipbloup()` can?
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 383950ca8635..c96fde25fc5a 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -74,10 +74,8 @@ issue-1589.rs
 issue-1725-1.rs
 issue-1725-2.rs
 issue-1786.rs
-issue-1813.rs
 issue-1893.rs
 issue-1901.rs
-issue-1930.rs
 issue-1981.rs
 issue-2019-1.rs
 issue-2019-2.rs
@@ -142,7 +140,6 @@ match4.rs
 match5.rs
 match9.rs
 method2.rs
-multi_reference_type.rs
 multiple_bindings1.rs
 multiple_bindings2.rs
 name_resolution2.rs


[gcc/devel/rust/master] Add a newline to the end of nr2/exclude

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:7a23231a7b939f88c764e73d71755871b514d286

commit 7a23231a7b939f88c764e73d71755871b514d286
Author: Owen Avery 
Date:   Thu Oct 24 14:20:29 2024 -0400

Add a newline to the end of nr2/exclude

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Add trailing newline along with
comment.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/testsuite/rust/compile/nr2/exclude | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index c96fde25fc5a..57bcca0a60e5 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -233,4 +233,5 @@ issue-2951.rs
 issue-2203.rs
 issue-2499.rs
 issue-3032-1.rs
-issue-3032-2.rs
\ No newline at end of file
+issue-3032-2.rs
+# please don't delete the trailing newline


[gcc/devel/rust/master] Rename some PathIdentSegment functions

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:549fe6d3a01109f6189b1bda9fd4478051062810

commit 549fe6d3a01109f6189b1bda9fd4478051062810
Author: Owen Avery 
Date:   Sat Oct 26 15:05:43 2024 -0400

Rename some PathIdentSegment functions

This makes PathIdentSegment more similar to other classes used to
represent path segments.

gcc/rust/ChangeLog:

* ast/rust-path.h
(PathIdentSegment::is_super_segment): Rename to...
(PathIdentSegment::is_super_path_seg): ...here.
(PathIdentSegment::is_crate_segment): Rename to...
(PathIdentSegment::is_crate_path_seg): ...here.
(PathIdentSegment::is_lower_self): Rename to...
(PathIdentSegment::is_lower_self_seg): ...here.
(PathIdentSegment::is_big_self): Rename to...
(PathIdentSegment::is_big_self_seg): ...here.

(PathExprSegment::is_super_path_seg): Handle renames.
(PathExprSegment::is_crate_path_seg): Likewise.
(PathExprSegment::is_lower_self_seg): Likewise.
(TypePathSegment::is_crate_path_seg): Likewise.
(TypePathSegment::is_super_path_seg): Likewise.
(TypePathSegment::is_big_self_seg): Likewise.
(TypePathSegment::is_lower_self_seg): Likewise.
* ast/rust-ast-collector.cc
(TokenCollector::visit): Likewise.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/ast/rust-ast-collector.cc |  8 
 gcc/rust/ast/rust-path.h   | 31 ---
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-collector.cc 
b/gcc/rust/ast/rust-ast-collector.cc
index a1306463e250..8f66742d1196 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -711,19 +711,19 @@ TokenCollector::visit (TypePath &path)
 void
 TokenCollector::visit (PathIdentSegment &segment)
 {
-  if (segment.is_super_segment ())
+  if (segment.is_super_path_seg ())
 {
   push (Rust::Token::make (SUPER, segment.get_locus ()));
 }
-  else if (segment.is_crate_segment ())
+  else if (segment.is_crate_path_seg ())
 {
   push (Rust::Token::make (CRATE, segment.get_locus ()));
 }
-  else if (segment.is_lower_self ())
+  else if (segment.is_lower_self_seg ())
 {
   push (Rust::Token::make (SELF, segment.get_locus ()));
 }
-  else if (segment.is_big_self ())
+  else if (segment.is_big_self_seg ())
 {
   push (Rust::Token::make (SELF_ALIAS, segment.get_locus ()));
 }
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index 5ca2c7f4394a..2df1506923d7 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -55,10 +55,16 @@ public:
 
   location_t get_locus () const { return locus; }
 
-  bool is_super_segment () const { return as_string ().compare ("super") == 0; 
}
-  bool is_crate_segment () const { return as_string ().compare ("crate") == 0; 
}
-  bool is_lower_self () const { return as_string ().compare ("self") == 0; }
-  bool is_big_self () const { return as_string ().compare ("Self") == 0; }
+  bool is_super_path_seg () const
+  {
+return as_string ().compare ("super") == 0;
+  }
+  bool is_crate_path_seg () const
+  {
+return as_string ().compare ("crate") == 0;
+  }
+  bool is_lower_self_seg () const { return as_string ().compare ("self") == 0; 
}
+  bool is_big_self_seg () const { return as_string ().compare ("Self") == 0; }
 };
 
 // A binding of an identifier to a type used in generic arguments in paths
@@ -560,17 +566,17 @@ public:
 
   bool is_super_path_seg () const
   {
-return !has_generic_args () && get_ident_segment ().is_super_segment ();
+return !has_generic_args () && get_ident_segment ().is_super_path_seg ();
   }
 
   bool is_crate_path_seg () const
   {
-return !has_generic_args () && get_ident_segment ().is_crate_segment ();
+return !has_generic_args () && get_ident_segment ().is_crate_path_seg ();
   }
 
   bool is_lower_self_seg () const
   {
-return !has_generic_args () && get_ident_segment ().is_lower_self ();
+return !has_generic_args () && get_ident_segment ().is_lower_self_seg ();
   }
 };
 
@@ -950,16 +956,19 @@ public:
 
   bool is_crate_path_seg () const
   {
-return get_ident_segment ().is_crate_segment ();
+return get_ident_segment ().is_crate_path_seg ();
   }
   bool is_super_path_seg () const
   {
-return get_ident_segment ().is_super_segment ();
+return get_ident_segment ().is_super_path_seg ();
+  }
+  bool is_big_self_seg () const
+  {
+return get_ident_segment ().is_big_self_seg ();
   }
-  bool is_big_self_seg () const { return get_ident_segment ().is_big_self (); }
   bool is_lower_self_seg () const
   {
-return get_ident_segment ().is_lower_self ();
+return get_ident_segment ().is_lower_self_seg ();
   }
 };


[gcc/devel/rust/master] Use name resolver 2.0 in pattern checker

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:e7de54ddae5de2d38495dc98c3dd8a31a5092f62

commit e7de54ddae5de2d38495dc98c3dd8a31a5092f62
Author: Owen Avery 
Date:   Tue Oct 15 15:34:06 2024 -0400

Use name resolver 2.0 in pattern checker

gcc/rust/ChangeLog:

* checks/errors/rust-hir-pattern-analysis.cc: Add includes.
(PatternChecker::visit): Use name resolver 2.0 when enabled.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/checks/errors/rust-hir-pattern-analysis.cc | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc 
b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
index fdbc6e8d2ec0..f46f429e9306 100644
--- a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
+++ b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
@@ -26,6 +26,10 @@
 #include "rust-mapping-common.h"
 #include "rust-system.h"
 #include "rust-tyty.h"
+#include "rust-immutable-name-resolution-context.h"
+
+// for flag_name_resolution_2_0
+#include "options.h"
 
 namespace Rust {
 namespace Analysis {
@@ -234,7 +238,17 @@ PatternChecker::visit (CallExpr &expr)
 
   NodeId ast_node_id = expr.get_fnexpr ()->get_mappings ().get_nodeid ();
   NodeId ref_node_id;
-  if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  if (auto id = nr_ctx.lookup (ast_node_id))
+   ref_node_id = *id;
+  else
+   return;
+}
+  else if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
 return;
 
   if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))


[gcc/devel/rust/master] Insert trait names during toplevel resolution 2.0

2024-10-30 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:daa5fd371387a77ca6c4e9fba8cacd854c11cad2

commit daa5fd371387a77ca6c4e9fba8cacd854c11cad2
Author: Owen Avery 
Date:   Wed Oct 16 00:40:01 2024 -0400

Insert trait names during toplevel resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Insert trait names into the type namespace.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 2193544a6640..a5e6c83a0378 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -120,6 +120,9 @@ TopLevel::visit (AST::Trait &trait)
   trait.insert_implict_self (
 std::unique_ptr (implicit_self));
 
+  insert_or_error_out (trait.get_identifier ().as_string (), trait,
+  Namespace::Types);
+
   DefaultResolver::visit (trait);
 }


[gcc r15-4783] Remove sys/user time in -ftime-report

2024-10-30 Thread Andi Kleen via Gcc-cvs
https://gcc.gnu.org/g:a2cd5d1f106f4dce3a93aede00cf082f144464be

commit r15-4783-ga2cd5d1f106f4dce3a93aede00cf082f144464be
Author: Andi Kleen 
Date:   Wed Oct 2 13:13:21 2024 -0700

Remove sys/user time in -ftime-report

Retrieving sys/user time in timevars is quite expensive because it
always needs a system call. Only getting the wall time is much
cheaper because operating systems have optimized paths for this.

The sys time isn't that interesting for a compiler and wall time
is usually close to user time except when the system is overloaded.
On the other hand when it is not wall time is more accurate because
it has less overhead.

For building tramp3d with -O0 the -ftime-report overhead drops from
18% to 3%. For -O2 it drops from 8% to not measurable.

I changed the code to use gettimeofday as a fallback for clock_gettime
CLOCK_MONOTONIC.  If a host has neither of those the time will not
be measured. Previously clock was the fallback.

This removes a lot of code in timevar.cc:

 gcc/timevar.cc | 167 
++---
 gcc/timevar.h  |  10 +---

 2 files changed, 17 insertions(+), 160 deletions(-)

gcc/ChangeLog:

* timevar.cc (struct tms): Remove.
(RUSAGE_SELF): Remove.
(TICKS_PER_SECOND): Remove.
(USE_TIMES): Remove.
(HAVE_USER_TIME): Remove.
(HAVE_SYS_TIME): Remove.
(HAVE_WALL_TIME): Remove.
(USE_GETRUSAGE): Remove.
(USE_CLOCK): Remove.
(NANOSEC_PER_SEC): Remove.
(TICKS_TO_NANOSEC): Remove.
(CLOCKS_TO_NANOSEC): Remove.
(timer::named_items::push): Remove sys/user.
(get_time): Remove clock and times and getruage code.
(timevar_accumulate): Remove sys/user.
(timevar_diff): Dito.
(timer::validate_phases): Dito.
(timer::print_row): Dito.
(timer::all_zero): Dito.
(timer::print): Dito.
(make_json_for_timevar_time_def): Dito.
* timevar.h (struct timevar_time_def): Dito.

Diff:
---
 gcc/timevar.cc | 189 +++--
 gcc/timevar.h  |  10 +--
 2 files changed, 22 insertions(+), 177 deletions(-)

diff --git a/gcc/timevar.cc b/gcc/timevar.cc
index 68bcf44864f9..4a57e74230d3 100644
--- a/gcc/timevar.cc
+++ b/gcc/timevar.cc
@@ -26,84 +26,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "options.h"
 #include "json.h"
 
-#ifndef HAVE_CLOCK_T
-typedef int clock_t;
-#endif
-
-#ifndef HAVE_STRUCT_TMS
-struct tms
-{
-  clock_t tms_utime;
-  clock_t tms_stime;
-  clock_t tms_cutime;
-  clock_t tms_cstime;
-};
-#endif
-
-#ifndef RUSAGE_SELF
-# define RUSAGE_SELF 0
-#endif
-
-/* Calculation of scale factor to convert ticks to seconds.
-   We mustn't use CLOCKS_PER_SEC except with clock().  */
-#if HAVE_SYSCONF && defined _SC_CLK_TCK
-# define TICKS_PER_SECOND sysconf (_SC_CLK_TCK) /* POSIX 1003.1-1996 */
-#else
-# ifdef CLK_TCK
-#  define TICKS_PER_SECOND CLK_TCK /* POSIX 1003.1-1988; obsolescent */
-# else
-#  ifdef HZ
-#   define TICKS_PER_SECOND HZ  /* traditional UNIX */
-#  else
-#   define TICKS_PER_SECOND 100 /* often the correct value */
-#  endif
-# endif
-#endif
-
-/* Prefer times to getrusage to clock (each gives successively less
-   information).  */
-#ifdef HAVE_TIMES
-# if defined HAVE_DECL_TIMES && !HAVE_DECL_TIMES
-  extern clock_t times (struct tms *);
-# endif
-# define USE_TIMES
-# define HAVE_USER_TIME
-# define HAVE_SYS_TIME
-# define HAVE_WALL_TIME
-#else
-#ifdef HAVE_GETRUSAGE
-# if defined HAVE_DECL_GETRUSAGE && !HAVE_DECL_GETRUSAGE
-  extern int getrusage (int, struct rusage *);
-# endif
-# define USE_GETRUSAGE
-# define HAVE_USER_TIME
-# define HAVE_SYS_TIME
-#else
-#ifdef HAVE_CLOCK
-# if defined HAVE_DECL_CLOCK && !HAVE_DECL_CLOCK
-  extern clock_t clock (void);
-# endif
-# define USE_CLOCK
-# define HAVE_USER_TIME
-#endif
-#endif
-#endif
-
-/* libc is very likely to have snuck a call to sysconf() into one of
-   the underlying constants, and that can be very slow, so we have to
-   precompute them.  Whose wonderful idea was it to make all those
-   _constants_ variable at run time, anyway?  */
-#define NANOSEC_PER_SEC 10
-#ifdef USE_TIMES
-static uint64_t ticks_to_nanosec;
-#define TICKS_TO_NANOSEC (NANOSEC_PER_SEC / TICKS_PER_SECOND)
-#endif
-
-#ifdef USE_CLOCK
-static uint64_t clocks_to_nanosec;
-#define CLOCKS_TO_NANOSEC (NANOSEC_PER_SEC / CLOCKS_PER_SEC)
-#endif
-
 /* Non-NULL if timevars should be used.  In GCC, this happens with
the -ftime-report flag.  */
 
@@ -181,8 +103,6 @@ timer::named_items::push (const char *item_name)
   timer::timevar_def *def = &m_hash_map.get_or_insert (item_name, &existed);
   if (!existed)
 {
-  def->elapsed.user = 0;
-  def->elapsed.sys = 0;
   def->elapsed.wall = 0;

[gcc r14-10853] aarch64: Assume alias conflict if common address reg changes [PR116783]

2024-10-30 Thread Alex Coplan via Gcc-cvs
https://gcc.gnu.org/g:434483ac32a08d1f3608c26fe2da302f0e09d6a2

commit r14-10853-g434483ac32a08d1f3608c26fe2da302f0e09d6a2
Author: Alex Coplan 
Date:   Wed Oct 30 13:46:12 2024 +

aarch64: Assume alias conflict if common address reg changes [PR116783]

As the PR shows, pair fusion was tricking memory_modified_in_insn_p into
returning false when a common base register (in this case, x1) was
modified between the mem and the store insn.  This lead to wrong code as
the accesses really did alias.

To avoid this sort of problem, this patch avoids invoking RTL alias
analysis altogether (and assume an alias conflict) if the two insns to
be compared share a common address register R, and the insns see different
definitions of R (i.e. it was modified in between).

This is a backport (but not a straight cherry pick) of
r15-4518-gc0e54ce1999ccf2241f74c5188b11b92e5aedc1f.

gcc/ChangeLog:

PR rtl-optimization/116783
* config/aarch64/aarch64-ldp-fusion.cc
(def_walker::cand_addr_uses): New.
(def_walker::def_walker): Add parameter for candidate address
uses.
(def_walker::alias_conflict_p): Declare.
(def_walker::addr_reg_conflict_p): New.
(def_walker::conflict_p): New.
(store_walker::store_walker): Add parameter for candidate
address uses and pass to base ctor.
(store_walker::conflict_p): Rename to ...
(store_walker::alias_conflict_p): ... this.
(load_walker::load_walker): Add parameter for candidate
address uses and pass to base ctor.
(load_walker::conflict_p): Rename to ...
(load_walker::alias_conflict_p): ... this.
(ldp_bb_info::try_fuse_pair): Collect address register
uses for candidate insns and pass down to alias walkers.

gcc/testsuite/ChangeLog:

PR rtl-optimization/116783
* g++.dg/torture/pr116783.C: New test.

Diff:
---
 gcc/config/aarch64/aarch64-ldp-fusion.cc | 127 ---
 gcc/testsuite/g++.dg/torture/pr116783.C  |  98 
 2 files changed, 213 insertions(+), 12 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-ldp-fusion.cc 
b/gcc/config/aarch64/aarch64-ldp-fusion.cc
index 1fc25e389cfe..f32d30d54c5c 100644
--- a/gcc/config/aarch64/aarch64-ldp-fusion.cc
+++ b/gcc/config/aarch64/aarch64-ldp-fusion.cc
@@ -2173,11 +2173,80 @@ protected:
 
   def_iter_t def_iter;
   insn_info *limit;
-  def_walker (def_info *def, insn_info *limit) :
-def_iter (def), limit (limit) {}
+
+  // Array of register uses from the candidate insn which occur in MEMs.
+  use_array cand_addr_uses;
+
+  def_walker (def_info *def, insn_info *limit, use_array addr_uses) :
+def_iter (def), limit (limit), cand_addr_uses (addr_uses) {}
 
   virtual bool iter_valid () const { return *def_iter; }
 
+  // Implemented in {load,store}_walker.
+  virtual bool alias_conflict_p (int &budget) const = 0;
+
+  // Return true if the current (walking) INSN () uses a register R inside a
+  // MEM, where R is also used inside a MEM by the (static) candidate insn, and
+  // those uses see different definitions of that register.  In this case we
+  // can't rely on RTL alias analysis, and for now we conservatively assume 
that
+  // there is an alias conflict.  See PR116783.
+  bool addr_reg_conflict_p () const
+  {
+use_array curr_insn_uses = insn ()->uses ();
+auto cand_use_iter = cand_addr_uses.begin ();
+auto insn_use_iter = curr_insn_uses.begin ();
+while (cand_use_iter != cand_addr_uses.end ()
+  && insn_use_iter != curr_insn_uses.end ())
+  {
+   auto insn_use = *insn_use_iter;
+   auto cand_use = *cand_use_iter;
+   if (insn_use->regno () > cand_use->regno ())
+ cand_use_iter++;
+   else if (insn_use->regno () < cand_use->regno ())
+ insn_use_iter++;
+   else
+ {
+   // As it stands I believe the alias code (memory_modified_in_insn_p)
+   // doesn't look at insn notes such as REG_EQU{IV,AL}, so it should
+   // be safe to skip over uses that only occur in notes.
+   if (insn_use->includes_address_uses ()
+   && !insn_use->only_occurs_in_notes ()
+   && insn_use->def () != cand_use->def ())
+ {
+   if (dump_file)
+ {
+   fprintf (dump_file,
+"assuming aliasing of cand i%d and i%d:\n"
+"-> insns see different defs of common addr reg 
r%u\n"
+"-> ",
+cand_use->insn ()->uid (), insn_use->insn ()->uid 
(),
+insn_use->regno ());
+
+   // Note that while the following sequence could be made more
+   // concise by eliding pp_string calls into 

[gcc r15-4786] [PATCH] Adjust param_vect_max_version_for_alias_checks

2024-10-30 Thread Kugan Vivekanandarajah via Gcc-cvs
https://gcc.gnu.org/g:5be5c66071b407a767856b8fa300ede54fcf11b4

commit r15-4786-g5be5c66071b407a767856b8fa300ede54fcf11b4
Author: Kugan Vivekanandarajah 
Date:   Thu Oct 31 07:20:49 2024 +1100

[PATCH] Adjust param_vect_max_version_for_alias_checks

This patch sets param_vect_max_version_for_alias_checks to 15.
This was causing GCC to miss vectorization opportunities for an application,
making it slower than LLVM by about ~14%.

Original default of 10 itself is arbitary. Given that, GCC's vectoriser does
consideres cost of alias checks, increasing this param is reasonable.

In this case we need a value of at teast 11 whereas the current
default is 10.

gcc/ChangeLog:

* params.opt: Adjust param_vect_max_version_for_alias_checks

gcc/testsuite/ChangeLog:

* g++.dg/alias-checks.C: New test.

Signed-off-by: Kugan Vivekanandarajah 

Diff:
---
 gcc/params.opt  |  2 +-
 gcc/testsuite/g++.dg/alias-checks.C | 85 +
 2 files changed, 86 insertions(+), 1 deletion(-)

diff --git a/gcc/params.opt b/gcc/params.opt
index 24f440bbe71f..7c572774df24 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -1187,7 +1187,7 @@ Common Joined UInteger 
Var(param_vect_max_peeling_for_alignment) Init(-1) Intege
 Maximum number of loop peels to enhance alignment of data references in a loop.
 
 -param=vect-max-version-for-alias-checks=
-Common Joined UInteger Var(param_vect_max_version_for_alias_checks) Init(10) 
Param Optimization
+Common Joined UInteger Var(param_vect_max_version_for_alias_checks) Init(15) 
Param Optimization
 Bound on number of runtime checks inserted by the vectorizer's loop versioning 
for alias check.
 
 -param=vect-max-version-for-alignment-checks=
diff --git a/gcc/testsuite/g++.dg/alias-checks.C 
b/gcc/testsuite/g++.dg/alias-checks.C
new file mode 100644
index ..ee0ac535399d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/alias-checks.C
@@ -0,0 +1,85 @@
+
+// { dg-do compile }
+// { dg-require-effective-target c++17 }
+// { dg-require-effective-target vect_double }
+// { dg-options "-O3 -fdump-tree-vect-all" }
+
+#include 
+#include 
+#include 
+void DoIfClause(double *l, double *r, const double *m2, const double *m1,
+const double *c, const double *p1, const double *p2, int istart, int 
iend)
+{
+constexpr double w5alpha[3][3] = {{1.0 / 3.0, -7.0 / 6.0, 11.0 / 6.0},
+{-1.0 / 6.0, 5.0 / 6.0, 1.0 / 3.0},
+{1.0 / 3.0, 5.0 / 6.0, -1.0 / 6.0}};
+constexpr double w5gamma[3] = {0.1, 0.6, 0.3};
+constexpr double eps = 1e-100;
+constexpr double thirteen_thirds = 13.0 / 3.0;
+
+for (int i = istart; i <= iend; ++i) {
+const double q0 = m2[i];
+const double q1 = m1[i];
+const double q2 = c[i];
+const double q3 = p1[i];
+const double q4 = p2[i];
+double &ql = l[i];
+double &qr = r[i];
+double a = q0 - 2 * q1 + q2;
+double b = q0 - 4.0 * q1 + 3.0 * q2;
+double beta0 = thirteen_thirds * a * a + b * b + eps;
+a = q1 - 2.0 * q2 + q3;
+b = q3 - q1;
+double beta1 = thirteen_thirds * a * a + b * b + eps;
+a = q2 - 2.0 * q3 + q4;
+b = q4 - 4.0 * q3 + 3.0 * q2;
+double beta2 = thirteen_thirds * a * a + b * b + eps;
+const double tau5 = std::abs(beta2 - beta0);
+
+beta0 = (beta0 + tau5) / beta0;
+beta1 = (beta1 + tau5) / beta1;
+beta2 = (beta2 + tau5) / beta2;
+
+double w0 = w5gamma[0] * beta0 + eps;
+double w1 = w5gamma[1] * beta1 + eps;
+double w2 = w5gamma[2] * beta2 + eps;
+double wsum = 1.0 / (w0 + w1 + w2);
+ql = w0 * (w5alpha[0][0] * q0 + w5alpha[0][1] * q1 + w5alpha[0][2] * 
q2);
+ql += w1 * (w5alpha[1][0] * q1 + w5alpha[1][1] * q2 + w5alpha[1][2] * 
q3);
+ql += w2 * (w5alpha[2][0] * q2 + w5alpha[2][1] * q3 + w5alpha[2][2] * 
q4);
+ql *= wsum;
+const double alpha_l = 3.0 * wsum * w0 * w1 * w2 /
+(w5gamma[2] * w0 * w1 + w5gamma[1] * w0 * w2 +
+ w5gamma[0] * w1 * w2) +
+eps;
+
+w0 = w5gamma[0] * beta2 + eps;
+w1 = w5gamma[1] * beta1 + eps;
+w2 = w5gamma[2] * beta0 + eps;
+wsum = 1.0 / (w0 + w1 + w2);
+qr = w0 * (w5alpha[0][0] * q4 + w5alpha[0][1] * q3 + w5alpha[0][2] * 
q2);
+qr += w1 * (w5alpha[1][0] * q3 + w5alpha[1][1] * q2 + w5alpha[1][2] * 
q1);
+qr += w2 * (w5alpha[2][0] * q2 + w5alpha[2][1] * q1 + w5alpha[2][2] * 
q0);
+qr *= wsum;
+const double alpha_r = 3.0 * wsum * w0 * w1 * w2 /
+(w5gamma[2] * w0 * w1 + w5gamma[1] * w0 * w2 +
+ w5gamma[0] * w1 * w2) +
+eps;
+
+double dq = q3 - q2;
+{
+const double dm = q2 - q1;
+const double dp = dq;
+const double dc = (dm * dp > 0.0) * 0.5 * (dm + dp);
+   

[gcc r15-4787] [PATCH] Fix SLP when ifcvt versioned loop is not vectorized

2024-10-30 Thread Kugan Vivekanandarajah via Gcc-cvs
https://gcc.gnu.org/g:acba8b3d8dec0124c8b3a7e112b3a784a5091214

commit r15-4787-gacba8b3d8dec0124c8b3a7e112b3a784a5091214
Author: Kugan Vivekanandarajah 
Date:   Thu Oct 31 07:23:10 2024 +1100

[PATCH] Fix SLP when ifcvt versioned loop is not vectorized

When ifcvt version a loop, it sets dont_vectorize to the scalar loop. If the
vector loop is not vectorized and removed, the scalar loop is still left 
with
dont_vectorize. As a result, BB vectorization will not happen.

This patch resets dont_vectorize to scalar loop when IFN_LOOP_VECTORIZED
is set to false.

gcc/ChangeLog:

* tree-vectorizer.cc (pass_vectorize::execute): Reset dont_vectorize
to scalar loop when setting IFN_LOOP_VECTORIZED to false.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/bb-slp-77.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/vect/bb-slp-77.c | 74 +++
 gcc/tree-vectorizer.cc|  2 +
 2 files changed, 76 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-77.c 
b/gcc/testsuite/gcc.dg/vect/bb-slp-77.c
new file mode 100644
index ..b2cc1d114f10
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/bb-slp-77.c
@@ -0,0 +1,74 @@
+
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_int } */
+#include 
+#include 
+
+
+typedef struct {
+uint16_t d;
+uint16_t m;
+uint8_t val1[4];
+uint8_t val2[16];
+} st1;
+
+typedef struct {
+float d;
+float s;
+int8_t val2[32];
+} st2;
+
+float table[1 << 16];
+
+inline static float foo(uint16_t f) {
+uint16_t s;
+memcpy(&s, &f, sizeof(uint16_t));
+return table[s];
+}
+
+
+void test(const int n, float * restrict s, const void * restrict vx, const 
void * restrict vy) {
+const int nb = n / 32;
+
+
+const st1 * restrict x = vx;
+const st2 * restrict y = vy;
+
+float sumf = 0.0;
+
+for (int i = 0; i < nb; i++) {
+uint32_t val1;
+memcpy(&val1, x[i].val1, sizeof(val1));
+
+int sumi0 = 0;
+int sumi1 = 0;
+
+if (val1) {
+for (int j = 0; j < 16; ++j) {
+const uint8_t xh_0 = ((val1 >> (j)) << 4) & 0x10;
+const uint8_t xh_1 = ((val1 >> (j + 12)) ) & 0x10;
+
+const int32_t x0 = (x[i].val2[j] & 0xF) | xh_0;
+const int32_t x1 = (x[i].val2[j] >> 4) | xh_1;
+
+sumi0 += (x0 * y[i].val2[j]);
+sumi1 += (x1 * y[i].val2[j + 16]);
+}
+} else {
+for (int j = 0; j < 16; ++j) {
+const int32_t x0 = (x[i].val2[j] & 0xF);
+const int32_t x1 = (x[i].val2[j] >> 4);
+
+sumi0 += (x0 * y[i].val2[j]);
+sumi1 += (x1 * y[i].val2[j + 16]);
+}
+}
+
+int sumi = sumi0 + sumi1;
+sumf += (foo(x[i].d)*y[i].d)*sumi + foo(x[i].m)*y[i].s;
+}
+
+*s = sumf;
+}
+
+/* { dg-final { scan-tree-dump-times "optimized: basic block" 1 "slp1"  { 
target { { vect_int_mult && vect_element_align } && { ! powerpc*-*-* } } } } } 
*/
diff --git a/gcc/tree-vectorizer.cc b/gcc/tree-vectorizer.cc
index af112f212fe2..16fa0ec1bb77 100644
--- a/gcc/tree-vectorizer.cc
+++ b/gcc/tree-vectorizer.cc
@@ -1326,6 +1326,7 @@ pass_vectorize::execute (function *fun)
if (g)
  {
fold_loop_internal_call (g, boolean_false_node);
+   loop->dont_vectorize = false;
ret |= TODO_cleanup_cfg;
g = NULL;
  }
@@ -1335,6 +1336,7 @@ pass_vectorize::execute (function *fun)
if (g)
  {
fold_loop_internal_call (g, boolean_false_node);
+   loop->dont_vectorize = false;
ret |= TODO_cleanup_cfg;
  }
  }


[gcc r12-10793] Fix ICE due to subreg:us_truncate.

2024-10-30 Thread hongtao Liu via Gcc-cvs
https://gcc.gnu.org/g:d0a932fb53ccdf5155db90632901c55446b8

commit r12-10793-gd0a932fb53ccdf5155db90632901c55446b8
Author: liuhongt 
Date:   Tue Oct 29 02:09:39 2024 -0700

Fix ICE due to subreg:us_truncate.

Force_operand issues an ICE when input
is (subreg:DI (us_truncate:V8QI)), it's probably because it's an
invalid rtx, So refine backend patterns for that.

gcc/ChangeLog:

PR target/117318
* config/i386/sse.md (*avx512vl_v2div2qi2_mask_store_1):
Rename to ..
(avx512vl_v2div2qi2_mask_store_1): .. this.
(avx512vl_v2div2qi2_mask_store_2): Change to
define_expand.
(*avx512vl_v4qi2_mask_store_1): Rename to ..
(avx512vl_v4qi2_mask_store_1): .. this.
(avx512vl_v4qi2_mask_store_2): Change to
define_expand.
(*avx512vl_v8qi2_mask_store_1): Rename to ..
(avx512vl_v8qi2_mask_store_1): .. this.
(avx512vl_v8qi2_mask_store_2): Change to
define_expand.
(*avx512vl_v4hi2_mask_store_1): Rename to ..
(avx512vl_v4hi2_mask_store_1): .. this.
(avx512vl_v4hi2_mask_store_2): Change to
define_expand.
(*avx512vl_v2div2hi2_mask_store_1): Rename to ..
(avx512vl_v2div2hi2_mask_store_1): .. this.
(avx512vl_v2div2hi2_mask_store_2): Change to
define_expand.
(*avx512vl_v2div2si2_mask_store_1): Rename to ..
(avx512vl_v2div2si2_mask_store_1): .. this.
(avx512vl_v2div2si2_mask_store_2): Change to
define_expand.
(*avx512f_v8div16qi2_mask_store_1): Rename to ..
(avx512f_v8div16qi2_mask_store_1): .. this.
(avx512f_v8div16qi2_mask_store_2): Change to
define_expand.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr117318.c: New test.

(cherry picked from commit bc0eeccf27a084461a2d5661e23468350acb43da)

Diff:
---
 gcc/config/i386/sse.md   | 268 +++
 gcc/testsuite/gcc.target/i386/pr117318.c |  12 ++
 2 files changed, 110 insertions(+), 170 deletions(-)

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index c94c8eceb338..3ad96f321a67 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -13853,7 +13853,7 @@
(set_attr "prefix" "evex")
(set_attr "mode" "TI")])
 
-(define_insn "*avx512vl_v2div2qi2_mask_store_1"
+(define_insn "avx512vl_v2div2qi2_mask_store_1"
   [(set (match_operand:V2QI 0 "memory_operand" "=m")
  (vec_merge:V2QI
(any_truncate:V2QI
@@ -13867,28 +13867,19 @@
(set_attr "prefix" "evex")
(set_attr "mode" "TI")])
 
-(define_insn_and_split "avx512vl_v2div2qi2_mask_store_2"
-  [(set (match_operand:HI 0 "memory_operand")
-   (subreg:HI
- (vec_merge:V2QI
-   (any_truncate:V2QI
- (match_operand:V2DI 1 "register_operand"))
-   (vec_select:V2QI
- (subreg:V4QI
-   (vec_concat:V2HI
- (match_dup 0)
- (const_int 0)) 0)
- (parallel [(const_int 0) (const_int 1)]))
-   (match_operand:QI 2 "register_operand")) 0))]
-  "TARGET_AVX512VL && ix86_pre_reload_split ()"
-  "#"
-  "&& 1"
-  [(set (match_dup 0)
-   (vec_merge:V2QI
- (any_truncate:V2QI (match_dup 1))
- (match_dup 0)
- (match_dup 2)))]
-  "operands[0] = adjust_address_nv (operands[0], V2QImode, 0);")
+(define_expand "avx512vl_v2div2qi2_mask_store_2"
+  [(match_operand:HI 0 "memory_operand")
+   (any_truncate:V2QI
+ (match_operand:V2DI 1 "register_operand"))
+   (match_operand:QI 2 "register_operand")]
+  "TARGET_AVX512VL"
+{
+  operands[0] = adjust_address_nv (operands[0], V2QImode, 0);
+  emit_insn (gen_avx512vl_v2div2qi2_mask_store_1 (operands[0],
+   operands[1],
+   operands[2]));
+  DONE;
+})
 
 (define_insn "*avx512vl_v4qi2_store_1"
   [(set (match_operand:V4QI 0 "memory_operand" "=m")
@@ -13957,7 +13948,7 @@
(set_attr "prefix" "evex")
(set_attr "mode" "TI")])
 
-(define_insn "*avx512vl_v4qi2_mask_store_1"
+(define_insn "avx512vl_v4qi2_mask_store_1"
   [(set (match_operand:V4QI 0 "memory_operand" "=m")
(vec_merge:V4QI
  (any_truncate:V4QI
@@ -13971,29 +13962,19 @@
(set_attr "prefix" "evex")
(set_attr "mode" "TI")])
 
-(define_insn_and_split "avx512vl_v4qi2_mask_store_2"
-  [(set (match_operand:SI 0 "memory_operand")
-   (subreg:SI
- (vec_merge:V4QI
-   (any_truncate:V4QI
- (match_operand:VI4_128_8_256 1 "register_operand"))
-   (vec_select:V4QI
- (subreg:V8QI
-   (vec_concat:V2SI
- (match_dup 0)
- (const_int 0)) 0)
- (parallel [(const_int 0) (const_int 1)
-   

[gcc r15-4776] libstdc++: Define __memcpyable as true

2024-10-30 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:30563d8978a39c402a425e958b5b51936ee76cff

commit r15-4776-g30563d8978a39c402a425e958b5b51936ee76cff
Author: Jonathan Wakely 
Date:   Thu Oct 24 11:06:42 2024 +0100

libstdc++: Define __memcpyable as true

This allows optimizing copying ranges of floating-point types when they
have the same size and representation, e.g. between _Float32 and float
when we know that float uses the same IEEE binary32 format as _Float32.

On some targets double and long double both use IEEE binary64 format so
we could enable memcpy between those types, but we don't have existing
macros to check for that case.

libstdc++-v3/ChangeLog:

* include/bits/cpp_type_traits.h (__memcpyable): Add
specializations for compatible floating-point types.

Reviewed-by: Patrick Palka 

Diff:
---
 libstdc++-v3/include/bits/cpp_type_traits.h | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h 
b/libstdc++-v3/include/bits/cpp_type_traits.h
index 2f9ce75e82c2..e412f8d07703 100644
--- a/libstdc++-v3/include/bits/cpp_type_traits.h
+++ b/libstdc++-v3/include/bits/cpp_type_traits.h
@@ -472,6 +472,8 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
   template struct __memcpyable_integer;
 
   // For heterogeneous types, allow memcpy between equal-sized integers.
+  // N.B. we cannot do the same for equal-sized enums, they're not assignable.
+  // We cannot do it for pointers, because derived-to-base can adjust offset.
   template
 struct __memcpyable<_Tp*, _Up*>
 {
@@ -554,6 +556,27 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
 struct __memcpyable_integer { enum { __width = 128 }; };
 #endif
 
+#if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
+  template<>
+struct __memcpyable<_Float32*, float*> { enum { __value = true }; };
+  template<>
+struct __memcpyable { enum { __value = true }; };
+#endif
+
+#if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
+  template<>
+struct __memcpyable<_Float64*, double*> { enum { __value = true }; };
+  template<>
+struct __memcpyable { enum { __value = true }; };
+#endif
+
+#if defined(__STDCPP_FLOAT128_T__) && 
defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128)
+  template<>
+struct __memcpyable<_Float128*, long double*> { enum { __value = true }; };
+  template<>
+struct __memcpyable { enum { __value = true }; };
+#endif
+
   // Whether two iterator types can be used with memcmp.
   // This trait only says it's well-formed to use memcmp, not that it
   // gives the right answer for a given algorithm. So for example, std::equal


[gcc r15-4777] libstdc++: Define config macros for additional IEEE formats

2024-10-30 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:e2692b9ea7bde28de2a31a3580ce9dcc25e42fa4

commit r15-4777-ge2692b9ea7bde28de2a31a3580ce9dcc25e42fa4
Author: Jonathan Wakely 
Date:   Thu Oct 24 11:40:42 2024 +0100

libstdc++: Define config macros for additional IEEE formats

Some targets use IEEE binary64 for both double and long double, which
means we could use memmove to optimize a std::copy from a range of
double to a range of long double. We currently have no config macro to
detect when long double is binary64, so add that to .

This also adds config macros for the case where double and long double
both use the same binary32 format as float, which is true for the avr
target. No specializations of __memcpyable for that case are added by
this patch, but they could be added later.

libstdc++-v3/ChangeLog:

* include/bits/c++config (_GLIBCXX_DOUBLE_IS_IEEE_BINARY32):
Define.
(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY64): Define.
(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY32): Define.
* include/bits/cpp_type_traits.h (__memcpyable): Define
specializations when double and long double are compatible.

Reviewed-by: Patrick Palka 

Diff:
---
 libstdc++-v3/include/bits/c++config | 21 ++---
 libstdc++-v3/include/bits/cpp_type_traits.h |  7 +++
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index b87a3527f24b..1076803a8655 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -836,25 +836,40 @@ namespace std
 # endif
 #endif
 
-// Define if float has the IEEE binary32 format.
 #if __FLT_MANT_DIG__ == 24 \
   && __FLT_MIN_EXP__ == -125 \
   && __FLT_MAX_EXP__ == 128
+// Define if float has the IEEE binary32 format.
 # define _GLIBCXX_FLOAT_IS_IEEE_BINARY32 1
 #endif
 
-// Define if double has the IEEE binary64 format.
 #if __DBL_MANT_DIG__ == 53 \
   && __DBL_MIN_EXP__ == -1021 \
   && __DBL_MAX_EXP__ == 1024
+// Define if double has the IEEE binary64 format.
 # define _GLIBCXX_DOUBLE_IS_IEEE_BINARY64 1
+#elif __FLT_MANT_DIG__ == 24 \
+  && __FLT_MIN_EXP__ == -125 \
+  && __FLT_MAX_EXP__ == 128
+// Define if double has the IEEE binary32 format.
+# define _GLIBCXX_DOUBLE_IS_IEEE_BINARY32 1
 #endif
 
-// Define if long double has the IEEE binary128 format.
 #if __LDBL_MANT_DIG__ == 113 \
   && __LDBL_MIN_EXP__ == -16381 \
   && __LDBL_MAX_EXP__ == 16384
+// Define if long double has the IEEE binary128 format.
 # define _GLIBCXX_LDOUBLE_IS_IEEE_BINARY128 1
+#elif __LDBL_MANT_DIG__ == 53 \
+  && __LDBL_MIN_EXP__ == -1021 \
+  && __LDBL_MAX_EXP__ == 1024
+// Define if long double has the IEEE binary64 format.
+# define _GLIBCXX_LDOUBLE_IS_IEEE_BINARY64 1
+#elif __LDBL_MANT_DIG__ == 24 \
+  && __LDBL_MIN_EXP__ == -125 \
+  && __LDBL_MAX_EXP__ == 128
+// Define if long double has the IEEE binary32 format.
+# define _GLIBCXX_LDOUBLE_IS_IEEE_BINARY32 1
 #endif
 
 #if defined __cplusplus && defined __BFLT16_DIG__
diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h 
b/libstdc++-v3/include/bits/cpp_type_traits.h
index e412f8d07703..e5a5efece42d 100644
--- a/libstdc++-v3/include/bits/cpp_type_traits.h
+++ b/libstdc++-v3/include/bits/cpp_type_traits.h
@@ -556,6 +556,13 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
 struct __memcpyable_integer { enum { __width = 128 }; };
 #endif
 
+#if _GLIBCXX_DOUBLE_IS_IEEE_BINARY64 && _GLIBCXX_LDOUBLE_IS_IEEE_BINARY64
+  template<>
+struct __memcpyable { enum { __value = true }; };
+  template<>
+struct __memcpyable { enum { __value = true }; };
+#endif
+
 #if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
   template<>
 struct __memcpyable<_Float32*, float*> { enum { __value = true }; };


[gcc r15-4767] i386: Use assign_stack_temp instead of assign_386_stack_local with SLOT_TEMP

2024-10-30 Thread Uros Bizjak via Gcc-cvs
https://gcc.gnu.org/g:ee09fcc4e37a80d1c5cc0b08144bb1c2c4424747

commit r15-4767-gee09fcc4e37a80d1c5cc0b08144bb1c2c4424747
Author: Uros Bizjak 
Date:   Wed Oct 30 08:17:15 2024 +0100

i386: Use assign_stack_temp instead of assign_386_stack_local with SLOT_TEMP

It is better to use assign_stack_temp instead of assign_386_stack_local
with SLOT_TEMP because assign_stack_temp also shares sub-space of stack
slots (e.g. HImode temp shares stack slot with SImode stack slot).

Use assign_386_stack_local only for special stack slots (SLOT_STV_TEMP that
can be nested inside other stack temp access, SLOT_FLOATxFDI_387 that has
relaxed alignment constraint) or slots that can't be shared (SLOT_CW_*).

The patch removes SLOT_TEMP. assign_stack_temp should be used instead.

gcc/ChangeLog:

* config/i386/i386.h (enum ix86_stack_slot): Remove SLOT_TEMP.
* config/i386/i386-expand.cc (ix86_expand_builtin)
: Use assign_stack_temp instead of
assign_386_stack_local with SLOT_TEMP.
: Ditto.
(ix86_expand_divmod_libfunc): Ditto.
* config/i386/i386.md (floatunssi2): Ditto.
* config/i386/sync.md (atomic_load): Ditto.
(atomic_store): Ditto.

Diff:
---
 gcc/config/i386/i386-expand.cc | 6 +++---
 gcc/config/i386/i386.h | 3 +--
 gcc/config/i386/i386.md| 2 +-
 gcc/config/i386/sync.md| 4 ++--
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index 36011cc6b355..0de0e8427314 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -13738,13 +13738,13 @@ ix86_expand_builtin (tree exp, rtx target, rtx 
subtarget,
 
 case IX86_BUILTIN_LDMXCSR:
   op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
-  target = assign_386_stack_local (SImode, SLOT_TEMP);
+  target = assign_stack_temp (SImode, GET_MODE_SIZE (SImode));
   emit_move_insn (target, op0);
   emit_insn (gen_sse_ldmxcsr (target));
   return 0;
 
 case IX86_BUILTIN_STMXCSR:
-  target = assign_386_stack_local (SImode, SLOT_TEMP);
+  target = assign_stack_temp (SImode, GET_MODE_SIZE (SImode));
   emit_insn (gen_sse_stmxcsr (target));
   return copy_to_mode_reg (SImode, target);
 
@@ -25743,7 +25743,7 @@ ix86_expand_divmod_libfunc (rtx libfunc, machine_mode 
mode,
rtx op0, rtx op1,
rtx *quot_p, rtx *rem_p)
 {
-  rtx rem = assign_386_stack_local (mode, SLOT_TEMP);
+  rtx rem = assign_stack_temp (mode, GET_MODE_SIZE (mode));
 
   rtx quot = emit_library_call_value (libfunc, NULL_RTX, LCT_NORMAL,
  mode, op0, mode, op1, mode,
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 2dcd8803a08e..51934400951f 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2539,8 +2539,7 @@ enum ix86_fpcmp_strategy {
 
 enum ix86_stack_slot
 {
-  SLOT_TEMP = 0,
-  SLOT_CW_STORED,
+  SLOT_CW_STORED = 0,
   SLOT_CW_ROUNDEVEN,
   SLOT_CW_TRUNC,
   SLOT_CW_FLOOR,
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index e4d1c56ea542..fb6aaa815056 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -6282,7 +6282,7 @@
 {
   emit_insn (gen_floatunssi2_i387_with_xmm
  (operands[0], operands[1],
-  assign_386_stack_local (DImode, SLOT_TEMP)));
+  assign_stack_temp (DImode, GET_MODE_SIZE (DImode;
   DONE;
 }
   if (!TARGET_AVX512F)
diff --git a/gcc/config/i386/sync.md b/gcc/config/i386/sync.md
index f2b3ba0aa7aa..f03d418c3692 100644
--- a/gcc/config/i386/sync.md
+++ b/gcc/config/i386/sync.md
@@ -170,7 +170,7 @@
   if (mode == DImode && !TARGET_64BIT)
 emit_insn (gen_atomic_loaddi_fpu
   (operands[0], operands[1],
-   assign_386_stack_local (DImode, SLOT_TEMP)));
+   assign_stack_temp (DImode, GET_MODE_SIZE (DImode;
   else
 {
   rtx dst = operands[0];
@@ -251,7 +251,7 @@
 out to be significantly larger than this plus a barrier.  */
   emit_insn (gen_atomic_storedi_fpu
 (operands[0], operands[1],
- assign_386_stack_local (DImode, SLOT_TEMP)));
+ assign_stack_temp (DImode, GET_MODE_SIZE (DImode;
 }
   else
 {


[gcc r15-4781] Fix function multiversioning dispatcher link error with LTO

2024-10-30 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:875279ff3ee3b4135401286b8378087a24fd0f8d

commit r15-4781-g875279ff3ee3b4135401286b8378087a24fd0f8d
Author: Yangyu Chen 
Date:   Wed Oct 30 14:33:57 2024 +

Fix function multiversioning dispatcher link error with LTO

We forgot to apply DECL_EXTERNAL to __init_cpu_features_resolver decl. When
building with LTO, the linker cannot find the
__init_cpu_features_resolver.lto_priv* symbol, causing the link error.

This patch gets this fixed by adding DECL_EXTERNAL to the decl. To avoid 
used
but never defined warning for this symbol, we also mark TREE_PUBLIC to the 
decl.
We should also mark the decl having hidden visibility. And fix the 
attribute in
the same way for __aarch64_cpu_features identifier.

Minimal steps to reproduce the bug:

echo '__attribute__((target_clones("default", "aes"))) void func1() { }' > 
1.c
echo '__attribute__((target_clones("default", "aes"))) void func2() { }' > 
2.c
echo 'void func1();void func2();int main(){func1();func2();return 0;}' > 
main.c
gcc -flto -c 1.c 2.c
gcc -flto main.c 1.o 2.o

Fixes: 0cfde688e213 ("[aarch64] Add function multiversioning support")
Signed-off-by: Yangyu Chen 

gcc/ChangeLog:

* config/aarch64/aarch64.cc (dispatch_function_versions): Adding
DECL_EXTERNAL, TREE_PUBLIC and hidden DECL_VISIBILITY to
__init_cpu_features_resolver and __aarch64_cpu_features.

Diff:
---
 gcc/config/aarch64/aarch64.cc | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index df170d875f60..0fa7927d821a 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -20463,6 +20463,10 @@ dispatch_function_versions (tree dispatch_decl,
   tree init_fn_id = get_identifier ("__init_cpu_features_resolver");
   tree init_fn_decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
  init_fn_id, init_fn_type);
+  DECL_EXTERNAL (init_fn_decl) = 1;
+  TREE_PUBLIC (init_fn_decl) = 1;
+  DECL_VISIBILITY (init_fn_decl) = VISIBILITY_HIDDEN;
+  DECL_VISIBILITY_SPECIFIED (init_fn_decl) = 1;
   tree arg1 = DECL_ARGUMENTS (dispatch_decl);
   tree arg2 = TREE_CHAIN (arg1);
   ifunc_cpu_init_stmt = gimple_build_call (init_fn_decl, 2, arg1, arg2);
@@ -20482,6 +20486,9 @@ dispatch_function_versions (tree dispatch_decl,
get_identifier ("__aarch64_cpu_features"),
global_type);
   DECL_EXTERNAL (global_var) = 1;
+  TREE_PUBLIC (global_var) = 1;
+  DECL_VISIBILITY (global_var) = VISIBILITY_HIDDEN;
+  DECL_VISIBILITY_SPECIFIED (global_var) = 1;
   tree mask_var = create_tmp_var (long_long_unsigned_type_node);
 
   tree component_expr = build3 (COMPONENT_REF, long_long_unsigned_type_node,


[gcc r15-4782] Remove vectorizer finish_cost wrapper

2024-10-30 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:8f9348361c552e4e65ef7dc3e7788ce51a5b91c3

commit r15-4782-g8f9348361c552e4e65ef7dc3e7788ce51a5b91c3
Author: Richard Biener 
Date:   Wed Oct 30 13:06:08 2024 +0100

Remove vectorizer finish_cost wrapper

The inline function wraps the vector_cost class API and no longer is
a good representation of the query style of that class which makes it
also difficult to extend.

* tree-vectorizer.h (finish_cost): Inline everywhere and remove.
* tree-vect-loop.cc (vect_estimate_min_profitable_iters):
Inline finish_cost.
* tree-vect-slp.cc (vect_bb_vectorization_profitable_p): Likewise.

Diff:
---
 gcc/tree-vect-loop.cc | 10 +++---
 gcc/tree-vect-slp.cc  | 11 ++-
 gcc/tree-vectorizer.h | 19 +--
 3 files changed, 14 insertions(+), 26 deletions(-)

diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index b8e155b90f81..df89edac036d 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -4984,9 +4984,13 @@ vect_estimate_min_profitable_iters (loop_vec_info 
loop_vinfo,
 }
 
   /* Complete the target-specific cost calculations.  */
-  finish_cost (loop_vinfo->vector_costs, loop_vinfo->scalar_costs,
-  &vec_prologue_cost, &vec_inside_cost, &vec_epilogue_cost,
-  suggested_unroll_factor);
+  loop_vinfo->vector_costs->finish_cost (loop_vinfo->scalar_costs);
+  vec_prologue_cost = loop_vinfo->vector_costs->prologue_cost ();
+  vec_inside_cost = loop_vinfo->vector_costs->body_cost ();
+  vec_epilogue_cost = loop_vinfo->vector_costs->epilogue_cost ();
+  if (suggested_unroll_factor)
+*suggested_unroll_factor
+  = loop_vinfo->vector_costs->suggested_unroll_factor ();
 
   if (suggested_unroll_factor && *suggested_unroll_factor > 1
   && LOOP_VINFO_MAX_VECT_FACTOR (loop_vinfo) != MAX_VECTORIZATION_FACTOR
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index a7f064bb0edf..21fd4c8dc09e 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -8859,9 +8859,8 @@ vect_bb_vectorization_profitable_p (bb_vec_info bb_vinfo,
}
   while (si < li_scalar_costs.length ()
 && li_scalar_costs[si].first == sl);
-  unsigned dummy;
-  finish_cost (scalar_target_cost_data, nullptr,
-  &dummy, &scalar_cost, &dummy);
+  scalar_target_cost_data->finish_cost (nullptr);
+  scalar_cost = scalar_target_cost_data->body_cost ();
 
   /* Complete the target-specific vector cost calculation.  */
   class vector_costs *vect_target_cost_data = init_cost (bb_vinfo, false);
@@ -8872,8 +8871,10 @@ vect_bb_vectorization_profitable_p (bb_vec_info bb_vinfo,
}
   while (vi < li_vector_costs.length ()
 && li_vector_costs[vi].first == vl);
-  finish_cost (vect_target_cost_data, scalar_target_cost_data,
-  &vec_prologue_cost, &vec_inside_cost, &vec_epilogue_cost);
+  vect_target_cost_data->finish_cost (scalar_target_cost_data);
+  vec_prologue_cost = vect_target_cost_data->prologue_cost ();
+  vec_inside_cost = vect_target_cost_data->body_cost ();
+  vec_epilogue_cost = vect_target_cost_data->epilogue_cost ();
   delete scalar_target_cost_data;
   delete vect_target_cost_data;
 
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index b51771f836ca..24227a69d4ac 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -1897,7 +1897,7 @@ extern void dump_stmt_cost (FILE *, int, enum 
vect_cost_for_stmt,
stmt_vec_info, slp_tree, tree, int, unsigned,
enum vect_cost_model_location);
 
-/* Alias targetm.vectorize.add_stmt_cost.  */
+/* Dump and add costs.  */
 
 inline unsigned
 add_stmt_cost (vector_costs *costs, int count,
@@ -1923,8 +1923,6 @@ add_stmt_cost (vector_costs *costs, int count, enum 
vect_cost_for_stmt kind,
   return add_stmt_cost (costs, count, kind, NULL, NULL, NULL_TREE, 0, where);
 }
 
-/* Alias targetm.vectorize.add_stmt_cost.  */
-
 inline unsigned
 add_stmt_cost (vector_costs *costs, stmt_info_for_cost *i)
 {
@@ -1932,21 +1930,6 @@ add_stmt_cost (vector_costs *costs, stmt_info_for_cost 
*i)
i->vectype, i->misalign, i->where);
 }
 
-/* Alias targetm.vectorize.finish_cost.  */
-
-inline void
-finish_cost (vector_costs *costs, const vector_costs *scalar_costs,
-unsigned *prologue_cost, unsigned *body_cost,
-unsigned *epilogue_cost, unsigned *suggested_unroll_factor = NULL)
-{
-  costs->finish_cost (scalar_costs);
-  *prologue_cost = costs->prologue_cost ();
-  *body_cost = costs->body_cost ();
-  *epilogue_cost = costs->epilogue_cost ();
-  if (suggested_unroll_factor)
-*suggested_unroll_factor = costs->suggested_unroll_factor ();
-}
-
 inline void
 add_stmt_costs (vector_costs *costs, stmt_vector_for_cost *cost_vec)
 {


[gcc r15-4788] libstdc++: Fix some typos and grammatical errors in docs

2024-10-30 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:96566cc46d633c2026976e585b5743e880a8f99b

commit r15-4788-g96566cc46d633c2026976e585b5743e880a8f99b
Author: Jonathan Wakely 
Date:   Wed Oct 30 21:10:58 2024 +

libstdc++: Fix some typos and grammatical errors in docs

Also remove some redundant 'void' parameters from code examples.

libstdc++-v3/ChangeLog:

* doc/xml/manual/using_exceptions.xml: Fix typos and grammatical
errors.
* doc/html/manual/using_exceptions.html: Regenerate.

Diff:
---
 libstdc++-v3/doc/html/manual/using_exceptions.html | 12 ++--
 libstdc++-v3/doc/xml/manual/using_exceptions.xml   | 12 ++--
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/using_exceptions.html 
b/libstdc++-v3/doc/html/manual/using_exceptions.html
index 706b27e14793..eb4501b1f6ba 100644
--- a/libstdc++-v3/doc/html/manual/using_exceptions.html
+++ b/libstdc++-v3/doc/html/manual/using_exceptions.html
@@ -158,7 +158,7 @@ exception neutrality and exception safety.
   Doing without
 C++ is a language that strives to be as efficient as is possible
 in delivering features. As such, considerable care is used by both
-language implementer and designers to make sure unused features
+language implementer and designers to make sure unused features do
 not impose hidden or unexpected costs. The GNU system tries to be
 as flexible and as configurable as possible. So, it should come as
 no surprise that GNU C++ provides an optional language extension,
@@ -166,7 +166,7 @@ exception neutrality and exception safety.
 implicitly generated magic necessary to
 support try and catch blocks
 and thrown objects. (Language support
-for -fno-exceptions is documented in the GCC 
+for -fno-exceptions is documented in the GCC
 https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options";
 target="_top">manual.)
   Before detailing the library support
 for -fno-exceptions, first a passing note on
@@ -179,7 +179,7 @@ exception neutrality and exception safety.
 uses try or catch, you
 shouldn't use -fno-exceptions.
   
-And what it to be gained, tinkering in the back alleys with a
+And what is to be gained, tinkering in the back alleys with a
 language like this? Exception handling overhead can be measured
 in the size of the executable binary, and varies with the
 capabilities of the underlying operating system and specific
@@ -216,15 +216,15 @@ exception neutrality and exception safety.
 # define __throw_exception_again
 #endif
 
-  In addition, for every object derived from
+  In addition, for most of the classes derived from
   class exception, there exists a corresponding
   function with C language linkage. An example:
 
 #if __cpp_exceptions
-  void __throw_bad_exception(void)
+  void __throw_bad_exception()
   { throw bad_exception(); }
 #else
-  void __throw_bad_exception(void)
+  void __throw_bad_exception()
   { abort(); }
 #endif
 
diff --git a/libstdc++-v3/doc/xml/manual/using_exceptions.xml 
b/libstdc++-v3/doc/xml/manual/using_exceptions.xml
index ab42c8099399..ac2ba9dffd45 100644
--- a/libstdc++-v3/doc/xml/manual/using_exceptions.xml
+++ b/libstdc++-v3/doc/xml/manual/using_exceptions.xml
@@ -274,7 +274,7 @@ exception neutrality and exception safety.
   
 C++ is a language that strives to be as efficient as is possible
 in delivering features. As such, considerable care is used by both
-language implementer and designers to make sure unused features
+language implementer and designers to make sure unused features do
 not impose hidden or unexpected costs. The GNU system tries to be
 as flexible and as configurable as possible. So, it should come as
 no surprise that GNU C++ provides an optional language extension,
@@ -282,7 +282,7 @@ exception neutrality and exception safety.
 implicitly generated magic necessary to
 support try and catch blocks
 and thrown objects. (Language support
-for -fno-exceptions is documented in the GCC 
+for -fno-exceptions is documented in the GCC
 http://www.w3.org/1999/xlink"; 
xlink:href="https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options";>manual.)
   
 
@@ -299,7 +299,7 @@ exception neutrality and exception safety.
   
 
   
-And what it to be gained, tinkering in the back alleys with a
+And what is to be gained, tinkering in the back alleys with a
 language like this? Exception handling overhead can be measured
 in the size of the executable binary, and varies with the
 capabilities of the underlying operating system and specific
@@ -344,17 +344,17 @@ exception neutrality and exception safety.
 
 
 
-  In addition, for every object derived from
+  In addition, for most of the classes derived from
   class exception, there exists a corresponding
   function with C language linkage. An example:
 
 
 
 #if __cpp_excepti

[gcc r15-4789] libstdc++: Fix copy&paste comments in vector range tests

2024-10-30 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:5e26a340b228caac04d5c33bceae0a5b7861d1b7

commit r15-4789-g5e26a340b228caac04d5c33bceae0a5b7861d1b7
Author: Jonathan Wakely 
Date:   Wed Oct 30 19:27:54 2024 +

libstdc++: Fix copy&paste comments in vector range tests

These comments were copied from the std::vector tests, but the
value_type is not bool in these ones.

libstdc++-v3/ChangeLog:

* testsuite/23_containers/vector/cons/from_range.cc: Fix copy &
paste error in comment.
* testsuite/23_containers/vector/modifiers/append_range.cc:
Likewise.
* testsuite/23_containers/vector/modifiers/assign/assign_range.cc:
Likewise.
* testsuite/23_containers/vector/modifiers/insert/insert_range.cc:
Likewise.

Diff:
---
 libstdc++-v3/testsuite/23_containers/vector/cons/from_range.cc  | 2 +-
 libstdc++-v3/testsuite/23_containers/vector/modifiers/append_range.cc   | 2 +-
 .../testsuite/23_containers/vector/modifiers/assign/assign_range.cc | 2 +-
 .../testsuite/23_containers/vector/modifiers/insert/insert_range.cc | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/from_range.cc 
b/libstdc++-v3/testsuite/23_containers/vector/cons/from_range.cc
index e91465f5a711..ed2e3ca6ba1e 100644
--- a/libstdc++-v3/testsuite/23_containers/vector/cons/from_range.cc
+++ b/libstdc++-v3/testsuite/23_containers/vector/cons/from_range.cc
@@ -80,7 +80,7 @@ test_ranges()
   do_test_a>();
   do_test_a>();
 
-  // Not lvalue-convertible to bool
+  // Not lvalue-convertible to int
   struct C {
 C(int v) : val(v) { }
 operator int() && { return val; }
diff --git 
a/libstdc++-v3/testsuite/23_containers/vector/modifiers/append_range.cc 
b/libstdc++-v3/testsuite/23_containers/vector/modifiers/append_range.cc
index 24a5c7d0e7cc..5725cd2ad483 100644
--- a/libstdc++-v3/testsuite/23_containers/vector/modifiers/append_range.cc
+++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/append_range.cc
@@ -69,7 +69,7 @@ test_ranges()
   do_test_a>();
   do_test_a>();
 
-  // Not lvalue-convertible to bool
+  // Not lvalue-convertible to int
   struct C {
 C(int v) : val(v) { }
 operator int() && { return val; }
diff --git 
a/libstdc++-v3/testsuite/23_containers/vector/modifiers/assign/assign_range.cc 
b/libstdc++-v3/testsuite/23_containers/vector/modifiers/assign/assign_range.cc
index 4e8d8af1614a..db3b06cfbc06 100644
--- 
a/libstdc++-v3/testsuite/23_containers/vector/modifiers/assign/assign_range.cc
+++ 
b/libstdc++-v3/testsuite/23_containers/vector/modifiers/assign/assign_range.cc
@@ -90,7 +90,7 @@ test_ranges()
   do_test_a>();
   do_test_a>();
 
-  // Not lvalue-convertible to bool
+  // Not lvalue-convertible to int
   struct C {
 C(int v) : val(v) { }
 operator int() && { return val; }
diff --git 
a/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/insert_range.cc 
b/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/insert_range.cc
index 30219f5da02f..68218e94f28b 100644
--- 
a/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/insert_range.cc
+++ 
b/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/insert_range.cc
@@ -80,7 +80,7 @@ test_ranges()
   do_test_a>();
   do_test_a>();
 
-  // Not lvalue-convertible to bool
+  // Not lvalue-convertible to int
   struct C {
 C(int v) : val(v) { }
 operator int() && { return val; }


[gcc r13-9157] Fix ICE due to subreg:us_truncate.

2024-10-30 Thread hongtao Liu via Gcc-cvs
https://gcc.gnu.org/g:28ea5a4ec3e9e49439fdb912ef4edeebfdae881d

commit r13-9157-g28ea5a4ec3e9e49439fdb912ef4edeebfdae881d
Author: liuhongt 
Date:   Tue Oct 29 02:09:39 2024 -0700

Fix ICE due to subreg:us_truncate.

Force_operand issues an ICE when input
is (subreg:DI (us_truncate:V8QI)), it's probably because it's an
invalid rtx, So refine backend patterns for that.

gcc/ChangeLog:

PR target/117318
* config/i386/sse.md (*avx512vl_v2div2qi2_mask_store_1):
Rename to ..
(avx512vl_v2div2qi2_mask_store_1): .. this.
(avx512vl_v2div2qi2_mask_store_2): Change to
define_expand.
(*avx512vl_v4qi2_mask_store_1): Rename to ..
(avx512vl_v4qi2_mask_store_1): .. this.
(avx512vl_v4qi2_mask_store_2): Change to
define_expand.
(*avx512vl_v8qi2_mask_store_1): Rename to ..
(avx512vl_v8qi2_mask_store_1): .. this.
(avx512vl_v8qi2_mask_store_2): Change to
define_expand.
(*avx512vl_v4hi2_mask_store_1): Rename to ..
(avx512vl_v4hi2_mask_store_1): .. this.
(avx512vl_v4hi2_mask_store_2): Change to
define_expand.
(*avx512vl_v2div2hi2_mask_store_1): Rename to ..
(avx512vl_v2div2hi2_mask_store_1): .. this.
(avx512vl_v2div2hi2_mask_store_2): Change to
define_expand.
(*avx512vl_v2div2si2_mask_store_1): Rename to ..
(avx512vl_v2div2si2_mask_store_1): .. this.
(avx512vl_v2div2si2_mask_store_2): Change to
define_expand.
(*avx512f_v8div16qi2_mask_store_1): Rename to ..
(avx512f_v8div16qi2_mask_store_1): .. this.
(avx512f_v8div16qi2_mask_store_2): Change to
define_expand.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr117318.c: New test.

(cherry picked from commit bc0eeccf27a084461a2d5661e23468350acb43da)

Diff:
---
 gcc/config/i386/sse.md   | 268 +++
 gcc/testsuite/gcc.target/i386/pr117318.c |  12 ++
 2 files changed, 110 insertions(+), 170 deletions(-)

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 50cc5882dbb2..bceb5afbbcd5 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -14038,7 +14038,7 @@
(set_attr "prefix" "evex")
(set_attr "mode" "TI")])
 
-(define_insn "*avx512vl_v2div2qi2_mask_store_1"
+(define_insn "avx512vl_v2div2qi2_mask_store_1"
   [(set (match_operand:V2QI 0 "memory_operand" "=m")
  (vec_merge:V2QI
(any_truncate:V2QI
@@ -14052,28 +14052,19 @@
(set_attr "prefix" "evex")
(set_attr "mode" "TI")])
 
-(define_insn_and_split "avx512vl_v2div2qi2_mask_store_2"
-  [(set (match_operand:HI 0 "memory_operand")
-   (subreg:HI
- (vec_merge:V2QI
-   (any_truncate:V2QI
- (match_operand:V2DI 1 "register_operand"))
-   (vec_select:V2QI
- (subreg:V4QI
-   (vec_concat:V2HI
- (match_dup 0)
- (const_int 0)) 0)
- (parallel [(const_int 0) (const_int 1)]))
-   (match_operand:QI 2 "register_operand")) 0))]
-  "TARGET_AVX512VL && ix86_pre_reload_split ()"
-  "#"
-  "&& 1"
-  [(set (match_dup 0)
-   (vec_merge:V2QI
- (any_truncate:V2QI (match_dup 1))
- (match_dup 0)
- (match_dup 2)))]
-  "operands[0] = adjust_address_nv (operands[0], V2QImode, 0);")
+(define_expand "avx512vl_v2div2qi2_mask_store_2"
+  [(match_operand:HI 0 "memory_operand")
+   (any_truncate:V2QI
+ (match_operand:V2DI 1 "register_operand"))
+   (match_operand:QI 2 "register_operand")]
+  "TARGET_AVX512VL"
+{
+  operands[0] = adjust_address_nv (operands[0], V2QImode, 0);
+  emit_insn (gen_avx512vl_v2div2qi2_mask_store_1 (operands[0],
+   operands[1],
+   operands[2]));
+  DONE;
+})
 
 (define_insn "*avx512vl_v4qi2_store_1"
   [(set (match_operand:V4QI 0 "memory_operand" "=m")
@@ -14142,7 +14133,7 @@
(set_attr "prefix" "evex")
(set_attr "mode" "TI")])
 
-(define_insn "*avx512vl_v4qi2_mask_store_1"
+(define_insn "avx512vl_v4qi2_mask_store_1"
   [(set (match_operand:V4QI 0 "memory_operand" "=m")
(vec_merge:V4QI
  (any_truncate:V4QI
@@ -14156,29 +14147,19 @@
(set_attr "prefix" "evex")
(set_attr "mode" "TI")])
 
-(define_insn_and_split "avx512vl_v4qi2_mask_store_2"
-  [(set (match_operand:SI 0 "memory_operand")
-   (subreg:SI
- (vec_merge:V4QI
-   (any_truncate:V4QI
- (match_operand:VI4_128_8_256 1 "register_operand"))
-   (vec_select:V4QI
- (subreg:V8QI
-   (vec_concat:V2SI
- (match_dup 0)
- (const_int 0)) 0)
- (parallel [(const_int 0) (const_int 1)
-

[gcc r15-4791] gimple: Remove special handling of COND_EXPR for COMPARISON_CLASS_P [PR116949, PR114785]

2024-10-30 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:b60031e8f9f8fe89ec0cb600d0e3dc5b799c825f

commit r15-4791-gb60031e8f9f8fe89ec0cb600d0e3dc5b799c825f
Author: Andrew Pinski 
Date:   Tue Oct 29 14:43:42 2024 -0700

gimple: Remove special handling of COND_EXPR for COMPARISON_CLASS_P 
[PR116949, PR114785]

After r13-707-g68e0063397ba82, COND_EXPR for gimple assign no longer could 
contain a comparison.
The vectorizer was builting gimple assigns with comparison until 
r15-4695-gd17e672ce82e69
(which added an assert to make sure it no longer builds it).

So let's remove the special handling COND_EXPR in a few places and add an 
assert to
gimple_build_assign_1 to make sure we don't build a gimple assign any more 
with a comparison.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

PR middle-end/114785
PR middle-end/116949
* gimple-match-exports.cc (maybe_push_res_to_seq): Remove special
handling of COMPARISON_CLASS_P in COND_EXPR/VEC_COND_EXPR.
(gimple_extract): Likewise.
* gimple-walk.cc (walk_stmt_load_store_addr_ops): Likewise.
* gimple.cc (gimple_build_assign_1): Add assert for COND_EXPR
so its 1st operand is not a comparison.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/gimple-match-exports.cc | 12 +---
 gcc/gimple-walk.cc  | 11 ---
 gcc/gimple.cc   |  3 +++
 3 files changed, 4 insertions(+), 22 deletions(-)

diff --git a/gcc/gimple-match-exports.cc b/gcc/gimple-match-exports.cc
index 77d225825cfa..bc8038c19f05 100644
--- a/gcc/gimple-match-exports.cc
+++ b/gcc/gimple-match-exports.cc
@@ -489,12 +489,6 @@ maybe_push_res_to_seq (gimple_match_op *res_op, gimple_seq 
*seq, tree res)
&& SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[i]))
   return NULL_TREE;
 
-  if (num_ops > 0 && COMPARISON_CLASS_P (ops[0]))
-for (unsigned int i = 0; i < 2; ++i)
-  if (TREE_CODE (TREE_OPERAND (ops[0], i)) == SSA_NAME
- && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (ops[0], i)))
-   return NULL_TREE;
-
   if (res_op->code.is_tree_code ())
 {
   auto code = tree_code (res_op->code);
@@ -786,11 +780,7 @@ gimple_extract (gimple *stmt, gimple_match_op *res_op,
}
  case GIMPLE_TERNARY_RHS:
{
- tree rhs1 = gimple_assign_rhs1 (stmt);
- if (code == COND_EXPR && COMPARISON_CLASS_P (rhs1))
-   rhs1 = valueize_condition (rhs1);
- else
-   rhs1 = valueize_op (rhs1);
+ tree rhs1 = valueize_op (gimple_assign_rhs1 (stmt));
  tree rhs2 = valueize_op (gimple_assign_rhs2 (stmt));
  tree rhs3 = valueize_op (gimple_assign_rhs3 (stmt));
  res_op->set_op (code, type, rhs1, rhs2, rhs3);
diff --git a/gcc/gimple-walk.cc b/gcc/gimple-walk.cc
index 9f768ca20fda..00520319aa90 100644
--- a/gcc/gimple-walk.cc
+++ b/gcc/gimple-walk.cc
@@ -835,17 +835,6 @@ walk_stmt_load_store_addr_ops (gimple *stmt, void *data,
;
  else if (TREE_CODE (op) == ADDR_EXPR)
ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
- /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
-tree with two operands.  */
- else if (i == 1 && COMPARISON_CLASS_P (op))
-   {
- if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
-   ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
-  0), op, data);
- if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
-   ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
-  0), op, data);
-   }
}
 }
   else if (gcall *call_stmt = dyn_cast  (stmt))
diff --git a/gcc/gimple.cc b/gcc/gimple.cc
index eeb1badff5fc..f7b313be40e3 100644
--- a/gcc/gimple.cc
+++ b/gcc/gimple.cc
@@ -475,6 +475,9 @@ gimple_build_assign_1 (tree lhs, enum tree_code subcode, 
tree op1,
 gimple_build_with_ops_stat (GIMPLE_ASSIGN, (unsigned)subcode, num_ops
PASS_MEM_STAT));
   gimple_assign_set_lhs (p, lhs);
+  /* For COND_EXPR, op1 should not be a comparison. */
+  if (op1 && subcode == COND_EXPR)
+gcc_assert (!COMPARISON_CLASS_P  (op1));
   gimple_assign_set_rhs1 (p, op1);
   if (op2)
 {


[gcc r15-4792] testsuite: fix syntax in Wstringop-overflow-59.c

2024-10-30 Thread Sam James via Gcc-cvs
https://gcc.gnu.org/g:2dcb174385fd366282bf34bf95adbf918d5befda

commit r15-4792-g2dcb174385fd366282bf34bf95adbf918d5befda
Author: Sam James 
Date:   Thu Oct 31 01:37:47 2024 +

testsuite: fix syntax in Wstringop-overflow-59.c

Fix quoting issues, escaping, and dg directive types.

There were two issues here:
1) The incorrect quoting in an earlier dg-message was covering up that the
syntax in the next part was wrong;
2) Fix dg-warning -> dg-message to correctly pick up the notes. Once 1) was
fixed, this was exposed.

With this, I get:
```
+PASS: gcc.dg/Wstringop-overflow-59.c note (test for warnings, line 192)
+PASS: gcc.dg/Wstringop-overflow-59.c note (test for warnings, line 193)
```

gcc/testsuite/ChangeLog:
PR middle-end/92936

* gcc.dg/Wstringop-overflow-59.c: Fix dg-* syntax.

Diff:
---
 gcc/testsuite/gcc.dg/Wstringop-overflow-59.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-59.c 
b/gcc/testsuite/gcc.dg/Wstringop-overflow-59.c
index b6265e37c865..88aac3a3678a 100644
--- a/gcc/testsuite/gcc.dg/Wstringop-overflow-59.c
+++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-59.c
@@ -172,8 +172,8 @@ void memset_malloc_2_same_size (int i)
 if (i < 1)
   i = 1;
 
-char a4_1[4]; // { dg-message "at offset \\\[1, 4] into 
destination object 'a4_1" "note" }
-char a4_2[4]; // { dg-message "at offset \\\[1, 4] into 
destination object 'a4_2" "note" }
+char a4_1[4]; // { dg-message "at offset \\\[1, 4] into 
destination object 'a4_1'" "note" }
+char a4_2[4]; // { dg-message "at offset \\\[1, 4] into 
destination object 'a4_2'" "note" }
 char *p4 = cond1 ? a4_1 : a4_2;
 char *p4_i = p4 + i;
 
@@ -189,8 +189,8 @@ void memset_malloc_2_off (void)
   int i2 = SR (2, INT_MAX);
 
   {
-char a5[5];   // { dg-warning "at offset [1, 5] into 
destination object 'a5'
-char a7[7];   // { dg-warning "at offset [2, 7] into 
destination object 'a7'
+char a5[5];   // { dg-message "at offset \\\[1, 5] into 
destination object 'a5'" "note" }
+char a7[7];   // { dg-message "at offset \\\[2, 7] into 
destination object 'a7'" "note" }
 char *p5_p1 = a5 + i1;
 char *p7_p2 = a7 + i2;
 char *p5_7 = cond1 ? p5_p1 : p7_p2;


[gcc r15-4768] Fortran: Move pr115070.f90 to ieee directory [PR117335].

2024-10-30 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:6f0f202b9f2bc45d82dc3e524508f7a8849be60f

commit r15-4768-g6f0f202b9f2bc45d82dc3e524508f7a8849be60f
Author: Paul Thomas 
Date:   Wed Oct 30 07:49:52 2024 +

Fortran: Move pr115070.f90 to ieee directory [PR117335].

2024-10-30  Paul Thomas  

gcc/testsuite/
PR fortran/117335
* gfortran.dg/pr115070.f90: Delete.
* gfortran.dg/ieee/pr115070.f90: Moved to ieee directory to
prevent failures on incompatible architectures.

Diff:
---
 gcc/testsuite/gfortran.dg/{ => ieee}/pr115070.f90 | 0
 1 file changed, 0 insertions(+), 0 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/pr115070.f90 
b/gcc/testsuite/gfortran.dg/ieee/pr115070.f90
similarity index 100%
rename from gcc/testsuite/gfortran.dg/pr115070.f90
rename to gcc/testsuite/gfortran.dg/ieee/pr115070.f90


[gcc r15-4769] genmatch: Fix build on hppa64-hpux [PR117348]

2024-10-30 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:cd5535494c567c3dff4b935b7443d893914e9b9c

commit r15-4769-gcd5535494c567c3dff4b935b7443d893914e9b9c
Author: Jakub Jelinek 
Date:   Wed Oct 30 09:58:26 2024 +0100

genmatch: Fix build on hppa64-hpux [PR117348]

Apparently autoconf defines the HAVE_DECL_* macros to 0
rather than not defining them at all, so defined(HAVE_DECL_FMEMOPEN)
test doesn't do much.

The following patch fixes it by testing HAVE_DECL_FMEMOPEN
for being non-zero instead.

2024-10-30  Jakub Jelinek  

PR middle-end/117348
* genmatch.cc: Replace defined(HAVE_DECL_FMEMOPEN)
test with HAVE_DECL_FMEMOPEN.

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

diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc
index 170bf6162b5d..9a0817b8ee31 100644
--- a/gcc/genmatch.cc
+++ b/gcc/genmatch.cc
@@ -585,7 +585,7 @@ diag_vfprintf (FILE *f, int err_no, const char *msg, 
va_list *ap)
   fprintf (f, "%s", q);
 }
 
-#if defined(GENMATCH_SELFTESTS) && defined(HAVE_DECL_FMEMOPEN)
+#if defined(GENMATCH_SELFTESTS) && HAVE_DECL_FMEMOPEN
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wsuggest-attribute=format"


[gcc r15-4770] function: Call do_pending_stack_adjust in assign_parms [PR117296]

2024-10-30 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:fccef0c4ed0119ac53940bdb3838052339cf14a2

commit r15-4770-gfccef0c4ed0119ac53940bdb3838052339cf14a2
Author: Jakub Jelinek 
Date:   Wed Oct 30 09:59:22 2024 +0100

function: Call do_pending_stack_adjust in assign_parms [PR117296]

Functions called by assign_parms call emit_block_move in two places,
so on some targets can be expanded as calls and can result in pending
stack adjustment.

Now, during expansion we normally call do_pending_stack_adjust at the end
of expansion of each basic block or before emitting code that will branch
and/or has labels, and when emitting labels we assert that there are no
pending stack adjustments.

assign_parms is expanded before the first basic block and if the first
basic block starts with a label and at least one of those emit_block_move
calls resulted in the need of pending stack adjustments, we ICE when
emitting that label.

The following patch fixes that by calling do_pending_stack_adjust after
after the assign_parms potential emit_block_move calls.

2024-10-30  Jakub Jelinek  

PR target/117296
* function.cc (assign_parms): Call do_pending_stack_adjust.

* gcc.target/i386/pr117296.c: New test.

Diff:
---
 gcc/function.cc  |  2 ++
 gcc/testsuite/gcc.target/i386/pr117296.c | 12 
 2 files changed, 14 insertions(+)

diff --git a/gcc/function.cc b/gcc/function.cc
index d91551120a65..73490f0da10a 100644
--- a/gcc/function.cc
+++ b/gcc/function.cc
@@ -3747,6 +3747,8 @@ assign_parms (tree fndecl)
  now that all parameters have been copied out of hard registers.  */
   emit_insn (all.first_conversion_insn);
 
+  do_pending_stack_adjust ();
+
   /* Estimate reload stack alignment from scalar return mode.  */
   if (SUPPORTS_STACK_ALIGNMENT)
 {
diff --git a/gcc/testsuite/gcc.target/i386/pr117296.c 
b/gcc/testsuite/gcc.target/i386/pr117296.c
new file mode 100644
index ..1b4f6e806913
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr117296.c
@@ -0,0 +1,12 @@
+/* PR target/117296 */
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+/* { dg-additional-options "-mtune=k6 -mstringop-strategy=libcall 
-ffloat-store" { target ia32 } } */
+
+int x;
+
+void
+foo (_Complex double c)
+{
+ lab:;
+}


[gcc r15-4771] [MAINTAINERS] Add myself to write after approval and DCO.

2024-10-30 Thread Soumya AR via Gcc-cvs
https://gcc.gnu.org/g:91577f0c8d955bc670ee76d1a8851df336bf240c

commit r15-4771-g91577f0c8d955bc670ee76d1a8851df336bf240c
Author: Soumya AR 
Date:   Wed Oct 30 14:27:46 2024 +0530

[MAINTAINERS] Add myself to write after approval and DCO.

ChangeLog:

* MAINTAINERS: Add myself to write after approval and DCO.

Diff:
---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 1074886f4419..7da332323dcd 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -334,6 +334,7 @@ Ajit Kumar Agarwal  aagarwa 

 Pedro Alves palves  
 John David Anglin   danglin 
 Harald Anlauf   anlauf  
+Soumya AR   soumyaa 
 Paul-Antoine Arras  parras  
 Arsen Arsenović arsen   
 Raksit Ashokraksit  
@@ -921,6 +922,7 @@ Certificate of Origin Version 1.1.  See 
https://gcc.gnu.org/dco.html for more
 information.
 
 
+Soumya AR   
 Juergen Christ  
 Robin Dapp  
 Robin Dapp