[gcc r15-8514] gccrs: Use name resolver 2.0 for module descendance checks

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:2a44562d0b65d9ec13d00f7eba87fe77cb1c6af3

commit r15-8514-g2a44562d0b65d9ec13d00f7eba87fe77cb1c6af3
Author: Owen Avery 
Date:   Sat Oct 26 20:52:31 2024 -0400

gccrs: Use name resolver 2.0 for module descendance checks

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-reporter.cc:
Include rust-immutable-name-resolution-context.h.
(is_child_module): Use ForeverStack::is_module_descendant if name
resolution 2.0 is enabled.
* resolve/rust-forever-stack.h
(ForeverStack::is_module_descendant): Add.
(ForeverStack::dfs_node): Add.
* resolve/rust-forever-stack.hxx
(ForeverStack::dfs_rib): Use ForeverStack::dfs_node.
(ForeverStack::dfs_node): Add.
(ForeverStack::is_module_descendant): Add.

Signed-off-by: Owen Avery 

Diff:
---
 .../checks/errors/privacy/rust-privacy-reporter.cc |  9 +
 gcc/rust/resolve/rust-forever-stack.h  | 10 ++
 gcc/rust/resolve/rust-forever-stack.hxx| 41 ++
 3 files changed, 53 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc 
b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
index 1ee2097b3835..fa2de9c3f400 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
@@ -22,6 +22,7 @@
 #include "rust-hir-stmt.h"
 #include "rust-hir-item.h"
 #include "rust-attribute-values.h"
+#include "rust-immutable-name-resolution-context.h"
 
 namespace Rust {
 namespace Privacy {
@@ -93,6 +94,14 @@ static bool
 is_child_module (Analysis::Mappings &mappings, NodeId parent,
 NodeId possible_child)
 {
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  return nr_ctx.values.is_module_descendant (parent, possible_child);
+}
+
   auto children = mappings.lookup_module_children (parent);
 
   if (!children)
diff --git a/gcc/rust/resolve/rust-forever-stack.h 
b/gcc/rust/resolve/rust-forever-stack.h
index 8c5e207a70d4..28509259497b 100644
--- a/gcc/rust/resolve/rust-forever-stack.h
+++ b/gcc/rust/resolve/rust-forever-stack.h
@@ -521,6 +521,12 @@ public:
 
   std::string as_debug_string ();
 
+  /**
+   * Used to check if a module is a descendant of another module
+   * Intended for use in the privacy checker
+   */
+  bool is_module_descendant (NodeId parent, NodeId child) const;
+
 private:
   /**
* A link between two Nodes in our trie data structure. This class represents
@@ -635,6 +641,10 @@ private:
   tl::optional dfs_rib (Node &starting_point, NodeId to_find);
   tl::optional dfs_rib (const Node &starting_point,
 NodeId to_find) const;
+  // FIXME: Documentation
+  tl::optional dfs_node (Node &starting_point, NodeId to_find);
+  tl::optional dfs_node (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 5a5a7c73f32b..31f8ba498b32 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -625,13 +625,33 @@ ForeverStack::to_canonical_path (NodeId id) const
 template 
 tl::optional
 ForeverStack::dfs_rib (ForeverStack::Node &starting_point, NodeId 
to_find)
+{
+  return dfs_node (starting_point, to_find).map ([] (Node &x) -> Rib & {
+return x.rib;
+  });
+}
+
+template 
+tl::optional
+ForeverStack::dfs_rib (const ForeverStack::Node &starting_point,
+ NodeId to_find) const
+{
+  return dfs_node (starting_point, to_find).map ([] (Node &x) -> Rib & {
+return x.rib;
+  });
+}
+
+template 
+tl::optional::Node &>
+ForeverStack::dfs_node (ForeverStack::Node &starting_point,
+  NodeId to_find)
 {
   if (starting_point.id == to_find)
-return starting_point.rib;
+return starting_point;
 
   for (auto &child : starting_point.children)
 {
-  auto candidate = dfs_rib (child.second, to_find);
+  auto candidate = dfs_node (child.second, to_find);
 
   if (candidate.has_value ())
return candidate;
@@ -641,16 +661,16 @@ ForeverStack::dfs_rib (ForeverStack::Node 
&starting_point, NodeId to_find)
 }
 
 template 
-tl::optional
-ForeverStack::dfs_rib (const ForeverStack::Node &starting_point,
- NodeId to_find) const
+tl::optional::Node &>
+ForeverStack::dfs_node (const ForeverStack::Node &starting_point,
+  NodeId to_find) const
 {
   if (starting_point.id == to_find)
-return starting_point.rib;
+return starting_point;
 
   for (auto &child : starting_point.children)
 {
-  auto candidate = dfs_rib (child.second, to_find);
+  auto candidate = dfs_node (chi

[gcc/devel/omp/gcc-14] ipa: target clone and mangling alias [PR114992]

2025-03-21 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:5dd8e647bedacb443aa5a11e26d6748ee6ddff1e

commit 5dd8e647bedacb443aa5a11e26d6748ee6ddff1e
Author: Jason Merrill 
Date:   Thu Mar 20 12:57:15 2025 -0400

ipa: target clone and mangling alias [PR114992]

Since the mangling of the second lambda changed (previously we counted all
lambdas, now we only count lambdas with the same signature), we
generate_mangling_alias for handler for backward compatibility.
Since handler is COMDAT, resolve_alias puts the alias in the same comdat
group as handler itself.  Then create_dispatcher_calls tries to add the
alias to the same comdat group as the dispatcher, but it's already in a
same_comdat_group, so we ICE.

It seems like we're just missing a remove_from_same_comdat_group before
add_to_same_comdat_group.

PR c++/114992

gcc/ChangeLog:

* multiple_target.cc (create_dispatcher_calls):
remove_from_same_comdat_group before add_to_same_comdat_group.

gcc/testsuite/ChangeLog:

* g++.target/i386/mangling-alias1.C: New test.

(cherry picked from commit ab716829da7c885b97ac2649c7c0ff5c7703ffa5)

Diff:
---
 gcc/multiple_target.cc  |  6 +-
 gcc/testsuite/g++.target/i386/mangling-alias1.C | 16 
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/multiple_target.cc b/gcc/multiple_target.cc
index 60958a56c92d..b173044cbee1 100644
--- a/gcc/multiple_target.cc
+++ b/gcc/multiple_target.cc
@@ -155,7 +155,11 @@ create_dispatcher_calls (struct cgraph_node *node)
  symtab_node *source = ref->referring;
  source->create_reference (inode, IPA_REF_ALIAS);
  if (inode->get_comdat_group ())
-   source->add_to_same_comdat_group (inode);
+   {
+ if (source->same_comdat_group)
+   source->remove_from_same_comdat_group ();
+ source->add_to_same_comdat_group (inode);
+   }
}
  else
gcc_unreachable ();
diff --git a/gcc/testsuite/g++.target/i386/mangling-alias1.C 
b/gcc/testsuite/g++.target/i386/mangling-alias1.C
new file mode 100644
index ..70264e2b64e6
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/mangling-alias1.C
@@ -0,0 +1,16 @@
+// PR c++/114992
+// { dg-do compile { target { c++11 && x86_64-*-* } } }
+// { dg-require-ifunc }
+
+template 
+__attribute__((target_clones("avx2", "default")))
+void handler(Callable) {}
+
+inline int func()
+{
+  auto l1 = [](int) {}; // different lambda signature
+  handler([]() {}); // so this one needs a mangling alias
+  return 42;
+}
+
+int g = func();


[gcc/devel/omp/gcc-14] Daily bump.

2025-03-21 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:c2ebdabe205f1f626d624fd9a406aacb844f2131

commit c2ebdabe205f1f626d624fd9a406aacb844f2131
Author: GCC Administrator 
Date:   Fri Mar 21 00:22:55 2025 +

Daily bump.

Diff:
---
 gcc/DATESTAMP   | 2 +-
 gcc/cp/ChangeLog| 7 +++
 gcc/d/ChangeLog | 5 +
 gcc/testsuite/ChangeLog | 5 +
 libphobos/ChangeLog | 5 +
 5 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/gcc/DATESTAMP b/gcc/DATESTAMP
index b76e7dd64105..2340aa0f8622 100644
--- a/gcc/DATESTAMP
+++ b/gcc/DATESTAMP
@@ -1 +1 @@
-20250320
+20250321
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 2f237d2d966d..db1c9a996bb3 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2025-03-20  Simon Martin  
+
+   PR c++/114292
+   * tree.cc (cp_walk_subtrees): Walk the type of DECL_EXPR
+   declarations, as well as the TYPE_{MIN,MAX}_VALUE of
+   INTEGER_TYPEs for template declarations.
+
 2025-03-19  Jason Merrill  
 
Backported from master:
diff --git a/gcc/d/ChangeLog b/gcc/d/ChangeLog
index d594befd2582..09d64cbb72a8 100644
--- a/gcc/d/ChangeLog
+++ b/gcc/d/ChangeLog
@@ -1,3 +1,8 @@
+2025-03-20  Iain Buclaw  
+
+   * dmd/MERGE: Merge upstream dmd af92b68a81.
+   * dmd/VERSION: Bump version to v2.108.1.
+
 2025-03-11  Iain Buclaw  
 
Backported from master:
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 1b63659d0f38..164daee64dd6 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2025-03-20  Simon Martin  
+
+   PR c++/114292
+   * g++.dg/cpp1y/lambda-ice4.C: New test.
+
 2025-03-19  Jason Merrill  
 
Backported from master:
diff --git a/libphobos/ChangeLog b/libphobos/ChangeLog
index 19ec39251e88..54218981adff 100644
--- a/libphobos/ChangeLog
+++ b/libphobos/ChangeLog
@@ -1,3 +1,8 @@
+2025-03-20  Iain Buclaw  
+
+   * libdruntime/MERGE: Merge upstream druntime af92b68a81.
+   * src/MERGE: Merge upstream phobos c970ca67f.
+
 2025-03-10  Iain Buclaw  
 
PR d/119112


[gcc r15-8581] gccrs: lang-item: Add Option::{None, Some}, Iterator::next, IntoIter::into_iter

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:f8aa5ececd42ad2cefa837a99756300f41bc4d5a

commit r15-8581-gf8aa5ececd42ad2cefa837a99756300f41bc4d5a
Author: Arthur Cohen 
Date:   Mon Dec 16 14:17:29 2024 +0100

gccrs: lang-item: Add Option::{None, Some}, Iterator::next, 
IntoIter::into_iter

gcc/rust/ChangeLog:

* util/rust-lang-item.h: Add new lang items.
* util/rust-lang-item.cc: Likewise.

Diff:
---
 gcc/rust/util/rust-lang-item.cc | 6 ++
 gcc/rust/util/rust-lang-item.h  | 9 +
 2 files changed, 15 insertions(+)

diff --git a/gcc/rust/util/rust-lang-item.cc b/gcc/rust/util/rust-lang-item.cc
index 216202af9266..c4c1d1c093ab 100644
--- a/gcc/rust/util/rust-lang-item.cc
+++ b/gcc/rust/util/rust-lang-item.cc
@@ -92,6 +92,12 @@ const BiMap 
Rust::LangItem::lang_items = {{
   {"str", Kind::STR},
   {"f32_runtime", Kind::F32_RUNTIME},
   {"f64_runtime", Kind::F64_RUNTIME},
+
+  {"Some", Kind::OPTION_SOME},
+  {"None", Kind::OPTION_NONE},
+
+  {"into_iter", Kind::INTOITER_INTOITER},
+  {"next", Kind::ITERATOR_NEXT},
 }};
 
 tl::optional
diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h
index 66d26d03907c..9e432e2ccc6e 100644
--- a/gcc/rust/util/rust-lang-item.h
+++ b/gcc/rust/util/rust-lang-item.h
@@ -26,6 +26,9 @@ namespace Rust {
 class LangItem
 {
 public:
+  // FIXME: We should clean up that enum to make it more inline with the list 
of
+  // lang-items in Rust 1.49
+  // 
https://github.com/rust-lang/rust/blob/1.49.0/compiler/rustc_hir/src/lang_items.rs
   enum class Kind
   {
 // 
https://github.com/rust-lang/rust/blob/master/library/core/src/ops/arith.rs
@@ -117,6 +120,12 @@ public:
 STR,
 F32_RUNTIME,
 F64_RUNTIME,
+
+OPTION_SOME,
+OPTION_NONE,
+
+INTOITER_INTOITER,
+ITERATOR_NEXT,
   };
 
   static const BiMap lang_items;


[gcc r15-8642] Fortran: Fix freeing procedure pointer components [PR119380]

2025-03-21 Thread Andre Vehreschild via Gcc-cvs
https://gcc.gnu.org/g:a5c69abf1384ec6163cd5e14146e8b3876e8b95c

commit r15-8642-ga5c69abf1384ec6163cd5e14146e8b3876e8b95c
Author: Andre Vehreschild 
Date:   Fri Mar 21 09:13:29 2025 +0100

Fortran: Fix freeing procedure pointer components [PR119380]

PR fortran/119380

gcc/fortran/ChangeLog:

* trans-array.cc (structure_alloc_comps): Prevent freeing of
procedure pointer components.

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/fortran/trans-array.cc |  2 +-
 gcc/testsuite/gfortran.dg/proc_ptr_comp_54.f90 | 30 ++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index e9eacf201283..960613167f72 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -10109,7 +10109,7 @@ structure_alloc_comps (gfc_symbol * der_type, tree 
decl, tree dest,
  else
{
  attr = &c->attr;
- if (attr->pointer)
+ if (attr->pointer || attr->proc_pointer)
continue;
}
 
diff --git a/gcc/testsuite/gfortran.dg/proc_ptr_comp_54.f90 
b/gcc/testsuite/gfortran.dg/proc_ptr_comp_54.f90
new file mode 100644
index ..f5b7fa84955d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/proc_ptr_comp_54.f90
@@ -0,0 +1,30 @@
+!{ dg-do run }
+
+! Do not free procedure pointer components.
+! Contributed by Damian Rouson  
+
+  implicit none
+
+  type foo_t
+integer, allocatable :: i_
+procedure(f), pointer, nopass :: f_
+procedure(c), pointer, nopass :: c_
+  end type
+
+  class(foo_t), allocatable :: ff
+
+  associate(foo => foo_t(1,f))
+  end associate
+
+contains
+
+  function f()
+logical, allocatable :: f
+f = .true.
+  end function
+
+  function c()
+class(foo_t), allocatable :: c
+allocate(c)
+  end function
+end


[gcc r15-8481] Fortran: Fix double free on polymorphic array dummy argument [PR119349]

2025-03-21 Thread Andre Vehreschild via Gcc-cvs
https://gcc.gnu.org/g:0f344846a62c8863375909d8d6b435b4b5fd35a0

commit r15-8481-g0f344846a62c8863375909d8d6b435b4b5fd35a0
Author: Andre Vehreschild 
Date:   Thu Mar 20 13:37:21 2025 +0100

Fortran: Fix double free on polymorphic array dummy argument [PR119349]

Calling elemental routines with polymorphic formals leads to generation
of a temporary polymorphic variable and code for its deallocation.
Sourcing this element from an array constructor the latter now is
prevented from generating a second deallocation.

PR fortran/119349

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_conv_procedure_call): Prevent deallocation
of array temporary for polymorphic temporary argument.

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/fortran/trans-expr.cc  |  6 +-
 gcc/testsuite/gfortran.dg/class_79.f90 | 25 +
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index d965539f11e7..923d46cb47c9 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -7994,7 +7994,11 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
  gfc_add_expr_to_block (&se->post, local_tmp);
}
 
- if (!finalized && !e->must_finalize)
+ /* Items of array expressions passed to a polymorphic formal arguments
+create their own clean up, so prevent double free.  */
+ if (!finalized && !e->must_finalize
+ && !(e->expr_type == EXPR_ARRAY && fsym
+  && fsym->ts.type == BT_CLASS))
{
  bool scalar_res_outside_loop;
  scalar_res_outside_loop = e->expr_type == EXPR_FUNCTION
diff --git a/gcc/testsuite/gfortran.dg/class_79.f90 
b/gcc/testsuite/gfortran.dg/class_79.f90
new file mode 100644
index ..a2226e47aff3
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/class_79.f90
@@ -0,0 +1,25 @@
+!{ dg-do run }
+
+! Check double free on array constructor in argument list is fixed.
+! Contributed by Damian Rouson  
+program pr119349
+  implicit none
+  
+  type string_t
+character(len=:), allocatable :: string_
+  end type
+
+  print *, true([string()])
+
+contains
+
+  type(string_t) function string()
+string%string_ = ""
+  end function
+
+  logical elemental function true(rhs)
+class(string_t), intent(in) :: rhs
+true = .true.
+  end function
+
+end program


[gcc(refs/users/omachota/heads/rtl-ssa-dce)] rtl-ssa: dce another prelive conditions

2025-03-21 Thread Ondrej Machota via Gcc-cvs
https://gcc.gnu.org/g:0a294fa7512b77426e8a5106f9679439a7729f74

commit 0a294fa7512b77426e8a5106f9679439a7729f74
Author: Ondřej Machota 
Date:   Tue Feb 25 08:44:25 2025 +0100

rtl-ssa: dce another prelive conditions

Diff:
---
 gcc/dce.cc | 125 -
 1 file changed, 100 insertions(+), 25 deletions(-)

diff --git a/gcc/dce.cc b/gcc/dce.cc
index 49bc4c3c6780..f51f27dbd143 100644
--- a/gcc/dce.cc
+++ b/gcc/dce.cc
@@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public 
License
 along with GCC; see the file COPYING3.  If not see
 .  */
 
+#include 
+#include 
 #define INCLUDE_ALGORITHM
 #define INCLUDE_FUNCTIONAL
 #define INCLUDE_ARRAY
@@ -1305,13 +1307,29 @@ public:
 } // namespace
 
 
+bool sets_global_register(const_rtx rtx) {
+  auto code = GET_CODE(rtx);
+  if (GET_RTX_CLASS(code) != RTX_INSN)
+return false;
+
+  return sets_global_register(static_cast(rtx));
+}
+
+// We should mark stack registers
 bool sets_global_register(rtx_insn* insn) {
   rtx set = single_set(insn);
   if (!set)
 return false;
 
   rtx dest = SET_DEST(set);
-  if (REG_P(dest) && HARD_REGISTER_NUM_P(REGNO(dest)) && 
global_regs[REGNO(dest)]) {
+
+  // TODO : rewrite to simple return
+  std::cerr << "first pseudo: " << FIRST_PSEUDO_REGISTER << '\n';
+  std::cerr << "register: " << REGNO(dest) << "\n";
+  debug(insn);
+  // If I understand correctly, global_regs[i] is 1 iff reg i is used
+  if (REG_P(dest) && HARD_REGISTER_NUM_P(REGNO(dest))) { // && 
global_regs[REGNO(dest)]
+std::cerr << "sets_global_register: true\n";
 return true;
   }
 
@@ -1329,6 +1347,7 @@ bool is_control_flow(rtx_code code) {
 case RETURN:
 case SIMPLE_RETURN:
 case EH_RETURN:
+case LABEL_REF:
   return true;
 
 default:
@@ -1336,13 +1355,66 @@ bool is_control_flow(rtx_code code) {
   }
 }
 
-bool handle_rtl_previle(rtx_insn *insn) {
-  // TODO : handle everything except parallel
+bool is_unary_mem_modification(rtx_code code) {
+  switch (code) {
+case PRE_DEC:
+case PRE_INC:
+case POST_DEC:
+case POST_INC:
+case PRE_MODIFY:
+case POST_MODIFY:
+  return true;
+
+default:
+  return false;
+  }
+}
+
+bool is_rtx_insn_prelive(const_rtx rtx) {
+  if (rtx == nullptr) {
+return false;
+  }
+
+  auto code = GET_CODE(rtx);
+  if (is_control_flow(code))
+return true;
+
+  // Mark set of a global register
+  if (sets_global_register(rtx)) // check rtx_class with GET_RTX_CLASS if 
RTX_ISNS and convert if needed
+return true;
+
+  // Call is inside side_effects_p - how to mark parameter registers?
+  if (volatile_refs_p(rtx) || can_throw_internal(rtx) || BARRIER_P(rtx) || 
code == PREFETCH)
+return true;
+
+  if (is_unary_mem_modification(code))
+return true;
+
+  // TODO : parallel, {pre,post}_{int,dec}, {pre,post}_modify, 
may_trap_or_fault_p
+  // Parallel is handled by volatile_refs_p
+
+  switch (code) {
+
+  }
+
+  const char *const fmt = GET_RTX_FORMAT (code);
+  for (size_t i = 0; i < GET_RTX_LENGTH(code); ++i) {
+if (fmt[i] == 'e' && is_rtx_insn_prelive(XEXP(rtx, i))) {
+  return true;
+} else if (fmt[i] == 'E') {
+  for (size_t j = 0; j < XVECLEN(rtx, i); ++j) {
+if (is_rtx_insn_prelive(XVECEXP(rtx, i, j)))
+  return true;
+  }
+}
+  }
+
+  return false;
 }
 
 bool is_prelive(insn_info *insn)
 {
-  if (insn->is_artificial()) // phis are never prelive
+  if (insn->is_artificial()) // phis are never prelive, bb head + end are 
artificial
 return false;
 
   /*
@@ -1377,8 +1449,8 @@ bool is_prelive(insn_info *insn)
   // We need to describe all possible prelive instructions, a list of all the 
instructions is inside `rtl.def`
 
   // Control flow
-  auto rtl_code = GET_CODE(rtl);
-  if (is_control_flow(rtl_code))
+  auto code = GET_CODE(rtl);
+  if (is_control_flow(code))
 return true;
 
   // Mark set of a global register
@@ -1386,9 +1458,16 @@ bool is_prelive(insn_info *insn)
 return true;
 
   // Call is inside side_effects_p
-  if (volatile_refs_p(rtl) || can_throw_internal(rtl) || BARRIER_P(rtl) || 
rtl_code == PREFETCH)
+  std::cerr << "Prelive: " << GET_RTX_NAME(code) << '\n';
+  // debug(insn);
+  debug(rtl);
+  if (volatile_refs_p(rtl) || can_throw_internal(rtl) || BARRIER_P(rtl) || 
code == PREFETCH)
 return true;
 
+  if (code == PARALLEL) {
+
+  }
+
   // TODO : handle parallel, {pre,post}_{int,dec}, {pre,post}_modify
 
   return false;
@@ -1421,9 +1500,7 @@ rtl_ssa_dce_mark_live(insn_info *info, vec 
&worklist, std::unordere
 {
   int info_uid = info->uid();
   if (dump_file)
-  {
 fprintf(dump_file, "  Adding insn %d to worklist\n", info_uid);
-  }
 
   marked.emplace(info);
   worklist.safe_push(info);
@@ -1436,10 +1513,6 @@ rtl_ssa_dce_prelive(std::unordered_set 
marked)
   auto_vec worklist;
   for (insn_info *insn = crtl->ssa->first_insn(); insn; insn = next)
   {
-if (dump_fil

[gcc(refs/users/omachota/heads/rtl-ssa-dce)] rtl-ssa-dce: add may_trap_or_fault_p as another prelive condition

2025-03-21 Thread Ondrej Machota via Gcc-cvs
https://gcc.gnu.org/g:703df50da1f6c45a756c7c265e0326bbb1582cde

commit 703df50da1f6c45a756c7c265e0326bbb1582cde
Author: Ondřej Machota 
Date:   Sun Mar 16 12:41:31 2025 +0100

rtl-ssa-dce: add may_trap_or_fault_p as another prelive condition

Diff:
---
 gcc/dce.cc | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gcc/dce.cc b/gcc/dce.cc
index 58d763314778..091e5c620f5b 100644
--- a/gcc/dce.cc
+++ b/gcc/dce.cc
@@ -1476,7 +1476,12 @@ bool is_rtx_insn_prelive(rtx_insn *insn) {
   if (GET_CODE(body) == CLOBBER) // 
gcc/gcc/testsuite/gcc.c-torture/compile/2605-1.c
 return true;
 
-  if (side_effects_with_mem(body) || can_throw_internal(body))
+  // may_trap_or_fault_p helps a lot to pass some tests from 
RUNTESTSFLAGS=execute.exp
+  // e. g. this one: testsuite/gcc.c-torture/execute/20020418-1.c
+  // TODO : debug the testcase
+  // It seems that the issue was due to trap_if rtl insn and fixed with 
may_trap_or_fault_p
+  // What about can_throw_internal?
+  if (side_effects_with_mem(body) || can_throw_internal(body) || 
may_trap_or_fault_p(body))
 return true;
 
   // TODO : parallel, {pre,post}_{int,dec}, {pre,post}_modify, 
may_trap_or_fault_p
@@ -1526,6 +1531,8 @@ bool is_prelive(insn_info *insn)
 static void
 rtl_ssa_dce_init()
 {
+  // internal compiler error: gcc.c-torture/execute/20040811-1.c - 
rtl_ssa::function_info::add_phi_nodes
+
   calculate_dominance_info(CDI_DOMINATORS);
   // here we create ssa form for function
   crtl->ssa = new rtl_ssa::function_info(cfun);


[gcc r15-8624] gccrs: mappings: Add get_lang_item_node

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:4d0cfd5b6f179081ab5fa412a8dd1d7762e9403c

commit r15-8624-g4d0cfd5b6f179081ab5fa412a8dd1d7762e9403c
Author: Arthur Cohen 
Date:   Thu Dec 26 23:00:08 2024 +

gccrs: mappings: Add get_lang_item_node

This method errors out if the lang item has not been declared yet.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::get_lang_item_node): New.
* util/rust-hir-map.h: New function.

Diff:
---
 gcc/rust/util/rust-hir-map.cc | 10 ++
 gcc/rust/util/rust-hir-map.h  |  1 +
 2 files changed, 11 insertions(+)

diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index f11a77954aef..b94591e014c4 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -1299,5 +1299,15 @@ Mappings::lookup_lang_item_node (LangItem::Kind 
item_type)
   return it->second;
 }
 
+NodeId
+Mappings::get_lang_item_node (LangItem::Kind item_type)
+{
+  if (auto lookup = lookup_lang_item_node (item_type))
+return *lookup;
+
+  rust_fatal_error (UNKNOWN_LOCATION, "failed to find lang item %qs",
+   LangItem::ToString (item_type).c_str ());
+}
+
 } // namespace Analysis
 } // namespace Rust
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index aba51be4827f..21e532812ff7 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -261,6 +261,7 @@ public:
 
   void insert_lang_item_node (LangItem::Kind item_type, NodeId node_id);
   tl::optional lookup_lang_item_node (LangItem::Kind item_type);
+  NodeId get_lang_item_node (LangItem::Kind item_type);
 
   // This will fatal_error when this lang item does not exist
   DefId get_lang_item (LangItem::Kind item_type, location_t locus);


[gcc r15-8585] gccrs: Fix NR2.0 compiler ICE caused by Generics in Enums

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:c4271707ce700bc87c2772fffa9aa1bc8432c6aa

commit r15-8585-gc4271707ce700bc87c2772fffa9aa1bc8432c6aa
Author: Liam Naddell 
Date:   Tue Dec 17 11:48:03 2024 -0500

gccrs: Fix NR2.0 compiler ICE caused by Generics in Enums

gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc:
Change the late name resolver to enter proper lexical scope during 
typechecking
* resolve/rust-late-name-resolver-2.0.h:
Add needed prototype to header
* resolve/rust-toplevel-name-resolver-2.0.cc:
Add generic parameters to enum's scoped RIB to allow for proper 
name resolution on types.

gcc/testsuite/ChangeLog:
* rust/compile/issue-3304.rs:
Add small test for generics+enums combination for NR2.0

Signed-off-by: Liam Naddell 

Diff:
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc |  7 +++
 gcc/rust/resolve/rust-late-name-resolver-2.0.h  |  1 +
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc |  9 +
 gcc/testsuite/rust/compile/issue-3304.rs| 10 ++
 4 files changed, 27 insertions(+)

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 40f067319b57..38515cdc0fde 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -295,6 +295,13 @@ Late::visit (AST::StructStruct &s)
   ctx.scoped (Rib::Kind::Item, s.get_node_id (), s_vis);
 }
 
+void
+Late::visit (AST::Enum &s)
+{
+  auto s_vis = [this, &s] () { AST::DefaultASTVisitor::visit (s); };
+  ctx.scoped (Rib::Kind::Item, s.get_node_id (), s_vis);
+}
+
 void
 Late::visit (AST::StructExprStruct &s)
 {
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 6f1191662cc2..1dbca3648da9 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -52,6 +52,7 @@ public:
   void visit (AST::StructExprStructBase &) override;
   void visit (AST::StructExprStructFields &) override;
   void visit (AST::StructStruct &) override;
+  void visit (AST::Enum &) override;
   void visit (AST::GenericArgs &) override;
   void visit (AST::GenericArg &);
 
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 a2f695e54f68..a76c098f2df3 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -332,6 +332,15 @@ TopLevel::visit (AST::EnumItemDiscriminant &variant)
 void
 TopLevel::visit (AST::Enum &enum_item)
 {
+  auto generic_vis = [this, &enum_item] () {
+for (auto &g : enum_item.get_generic_params ())
+  {
+   g->accept_vis (*this);
+  }
+  };
+
+  ctx.scoped (Rib::Kind::Item, enum_item.get_node_id (), generic_vis);
+
   insert_or_error_out (enum_item.get_identifier (), enum_item,
   Namespace::Types);
 
diff --git a/gcc/testsuite/rust/compile/issue-3304.rs 
b/gcc/testsuite/rust/compile/issue-3304.rs
new file mode 100644
index ..6ab614fa2d5d
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3304.rs
@@ -0,0 +1,10 @@
+// { dg-additional-options "-frust-name-resolution-2.0" }
+#[lang = "sized"]
+trait Sized {}
+
+pub enum ROption {
+RSome(T),
+RNone,
+}
+
+fn main() {}


[gcc r15-8616] gccrs: ast: Fix warning about copy elision for moved expr

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:592540266306438fe61e8951cfc2df577dcf2112

commit r15-8616-g592540266306438fe61e8951cfc2df577dcf2112
Author: Arthur Cohen 
Date:   Thu Dec 26 21:31:21 2024 +

gccrs: ast: Fix warning about copy elision for moved expr

gcc/rust/ChangeLog:

* ast/rust-ast.cc (BlockExpr::normalize_tail_expr): Remove 
overzealous
std::move

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

diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 25e522bf948d..45189a1a4b37 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -4270,7 +4270,7 @@ BlockExpr::normalize_tail_expr ()
 
  if (!stmt.is_semicolon_followed ())
{
- expr = std::move (stmt.take_expr ());
+ expr = stmt.take_expr ();
  statements.pop_back ();
}
}


[gcc r15-8644] Add 'gcc.target/nvptx/alias-unsupported-1.c'

2025-03-21 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:6d3a48baac33e9ccd6ea02012078fefd48181af3

commit r15-8644-g6d3a48baac33e9ccd6ea02012078fefd48181af3
Author: Thomas Schwinge 
Date:   Tue Mar 18 16:14:42 2025 +0100

Add 'gcc.target/nvptx/alias-unsupported-1.c'

... testing for the GCC/nvptx "alias definitions not supported" error
diagnostic.

gcc/testsuite/
* gcc.target/nvptx/alias-unsupported-1.c: New.

Diff:
---
 gcc/testsuite/gcc.target/nvptx/alias-unsupported-1.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/gcc/testsuite/gcc.target/nvptx/alias-unsupported-1.c 
b/gcc/testsuite/gcc.target/nvptx/alias-unsupported-1.c
new file mode 100644
index ..47b30bd928b4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/alias-unsupported-1.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-additional-options -mno-alias } */
+
+void __f ()
+{
+}
+
+void f () __attribute__ ((alias ("__f")));
+/* { dg-error {alias definitions not supported} {} { target *-*-* } .-1 } */


[gcc r15-8497] gccrs: Fix variable shadowing in late resolution 2.0

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:2dbdf9b77247fc2813e37c63924c6c8739b4a0a7

commit r15-8497-g2dbdf9b77247fc2813e37c63924c6c8739b4a0a7
Author: Owen Avery 
Date:   Sun Oct 27 13:32:09 2024 -0400

gccrs: 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 43f33dfab021..5fd49e7c2c9e 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 r15-8489] libstdc++: Use formatting locale for std::time_put formats

2025-03-21 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:3c7f2fd8c4b330029c935f2785a5da9395355d7d

commit r15-8489-g3c7f2fd8c4b330029c935f2785a5da9395355d7d
Author: Jonathan Wakely 
Date:   Wed Mar 19 19:38:15 2025 +

libstdc++: Use formatting locale for std::time_put formats

When using std::time_put to format a chrono value, we should imbue the
formatting locale into the stream. This ensures that when
std::time_put::do_put uses a ctype or __timepunct facet from the locale,
it gets the correct facets.

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (__formatter_chrono::_M_locale_fmt):
Imbue locale into ostringstream.
* testsuite/std/time/format/localized.cc: Check that correct
locale is used for call to time_put::put.

Reviewed-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/include/bits/chrono_io.h  |  1 +
 .../testsuite/std/time/format/localized.cc | 33 ++
 2 files changed, 34 insertions(+)

diff --git a/libstdc++-v3/include/bits/chrono_io.h 
b/libstdc++-v3/include/bits/chrono_io.h
index c16b555df290..55ebd4ee0610 100644
--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -1697,6 +1697,7 @@ namespace __format
  char __fmt, char __mod) const
{
  basic_ostringstream<_CharT> __os;
+ __os.imbue(__loc);
  const auto& __tp = use_facet>(__loc);
  __tp.put(__os, __os, _S_space, &__tm, __fmt, __mod);
  if (__os)
diff --git a/libstdc++-v3/testsuite/std/time/format/localized.cc 
b/libstdc++-v3/testsuite/std/time/format/localized.cc
index 393d0d200e45..7fde97f9ae15 100644
--- a/libstdc++-v3/testsuite/std/time/format/localized.cc
+++ b/libstdc++-v3/testsuite/std/time/format/localized.cc
@@ -13,6 +13,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -81,10 +82,42 @@ test_en()
 }
 }
 
+void
+test_locale_imbued()
+{
+  // Custom time_put facet which returns %b string for %Om.
+  // The %b string will come from io.getloc() which should be
+  // the formatting locale using by std::format.
+  struct TimePut : std::time_put
+  {
+iter_type
+do_put(iter_type out, std::ios_base& io, char_type fill, const tm* t,
+  char format, char modifier) const override
+{
+  if (format == 'm' && modifier == 'O')
+   format = 'b';
+  return std::time_put::do_put(out, io, fill, t, format, 0);
+}
+  };
+
+  auto m = std::chrono::March;
+
+  std::locale fr(ISO_8859(1,fr_FR));
+  std::locale fr2(fr, new TimePut);
+  auto s1 = std::format(fr2, "{:L%Om}", m); // should be %b in fr_FR locale
+  VERIFY( s1 == std::format(fr, "{:L}", m) );
+
+  std::locale es(ISO_8859(1,es_ES));
+  std::locale es2(es, new TimePut);
+  auto s2 = std::format(es2, "{:L%Om}", m); // should be %b in es_ES locale
+  VERIFY( s2 == std::format(es, "{:L}", m) );
+}
+
 int main()
 {
   test_ru();
   test_es();
   test_fr();
   test_en();
+  test_locale_imbued();
 }


[gcc r15-8493] fnsplit: Set musttail call during function splitting if there are musttail calls [PR119376]

2025-03-21 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:589c94da22ec71fe8518878e801e88b05deffe18

commit r15-8493-g589c94da22ec71fe8518878e801e88b05deffe18
Author: Jakub Jelinek 
Date:   Fri Mar 21 12:17:45 2025 +0100

fnsplit: Set musttail call during function splitting if there are musttail 
calls [PR119376]

The just posted inliner patch can regress musttail calls if we perform
function splitting and then inline the outlined body back into the original
(or inline both the small function and outlined large body into something
else).
If there are any musttail calls, I think we need to call the outlined
body using a musttail call, so that the inliner will preserve musttail
attributes in the body.

2025-03-21  Jakub Jelinek  

PR ipa/119376
* ipa-split.cc (split_function): Call gimple_call_set_must_tail
on the call to outlined partition if has_musttail and
!add_tsan_func_exit.

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

Diff:
---
 gcc/ipa-split.cc |  2 ++
 gcc/testsuite/g++.dg/opt/musttail1.C | 35 +++
 2 files changed, 37 insertions(+)

diff --git a/gcc/ipa-split.cc b/gcc/ipa-split.cc
index ff562e2a636f..729fb79af52c 100644
--- a/gcc/ipa-split.cc
+++ b/gcc/ipa-split.cc
@@ -1473,6 +1473,8 @@ split_function (basic_block return_bb, class split_point 
*split_point,
args_to_pass[i] = arg;
   }
   call = gimple_build_call_vec (node->decl, args_to_pass);
+  if (cur_node->get_fun ()->has_musttail && !add_tsan_func_exit)
+gimple_call_set_must_tail (call, true);
   gimple_set_block (call, DECL_INITIAL (current_function_decl));
   args_to_pass.release ();
 
diff --git a/gcc/testsuite/g++.dg/opt/musttail1.C 
b/gcc/testsuite/g++.dg/opt/musttail1.C
new file mode 100644
index ..5fe8ab6bd392
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/musttail1.C
@@ -0,0 +1,35 @@
+// PR ipa/119376
+// { dg-do compile { target musttail } }
+// { dg-options "-O2 -fdump-tree-optimized" }
+// { dg-final { scan-tree-dump-times "  \[^\n\r]* = foo \\\(\[^\n\r]*\\\); 
\\\[tail call\\\] \\\[must tail call\\\]" 2 "optimized" } }
+// { dg-final { scan-tree-dump-times "  \[^\n\r]* = foo \\\(\[^\n\r]*\\\); 
\\\[tail call\\\]" 3 "optimized" } }
+
+int foo (int x);
+typedef int (*F) (int);
+int v;
+
+inline int
+bar (int x)
+{
+  if (__builtin_expect (x == 42, 1))
+return 1;
+  [[gnu::musttail]] return foo (x + v * (x | v) * (x & v) * (x - v) * (x + v * 
v));
+}
+
+int
+baz (int x)
+{
+  [[gnu::musttail]] return bar (x);
+}
+
+int
+qux (int x)
+{
+  return bar (x + 1);
+}
+
+F
+corge ()
+{
+  return &bar;
+}


[gcc r13-9441] c++: Don't prune constant capture proxies only used in array dimensions [PR114292]

2025-03-21 Thread Simon Martin via Gcc-cvs
https://gcc.gnu.org/g:65e998d172e006cdf0dd4d58f83784a5fed61fc5

commit r13-9441-g65e998d172e006cdf0dd4d58f83784a5fed61fc5
Author: Simon Martin 
Date:   Fri Mar 21 07:02:20 2025 +0100

c++: Don't prune constant capture proxies only used in array dimensions 
[PR114292]

We currently ICE upon the following valid (under -Wno-vla) code

=== cut here ===
void f(int c) {
  constexpr int r = 4;
  [&](auto) { int t[r * c]; }(0);
}
=== cut here ===

When parsing the lambda body, and more specifically the multiplication,
we mark the lambda as LAMBDA_EXPR_CAPTURE_OPTIMIZED, which indicates to
prune_lambda_captures that it might be possible to optimize out some
captures.

The problem is that prune_lambda_captures then misses the use of the r
capture (because neither walk_tree_1 nor cp_walk_subtrees walks the
dimensions of array types - here "r * c"), hence believes the capture
can be pruned... and we trip on an assert when instantiating the lambda.

This patch changes cp_walk_subtrees so that (1) when walking a
DECL_EXPR, it also walks the DECL's type, and (2) when walking an
INTEGER_TYPE and processing a template declaration, it also walks its
TYPE_{MIN,MAX}_VALUE.

PR c++/114292

gcc/cp/ChangeLog:

* tree.cc (cp_walk_subtrees): Walk the type of DECL_EXPR
declarations, as well as the TYPE_{MIN,MAX}_VALUE of
INTEGER_TYPEs for template declarations.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/lambda-ice4.C: New test.

(cherry picked from commit f86d274ab76fdd89d7afd9b2eab28f3a61749cfb)

Diff:
---
 gcc/cp/tree.cc   | 10 +
 gcc/testsuite/g++.dg/cpp1y/lambda-ice4.C | 63 
 2 files changed, 73 insertions(+)

diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index c35f15baca2b..8ccb4ba70615 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -5663,6 +5663,7 @@ cp_walk_subtrees (tree *tp, int *walk_subtrees_p, 
walk_tree_fn func,
  && !TREE_STATIC (TREE_OPERAND (*tp, 0)
{
  tree decl = TREE_OPERAND (*tp, 0);
+ WALK_SUBTREE (TREE_TYPE (decl));
  WALK_SUBTREE (DECL_INITIAL (decl));
  WALK_SUBTREE (DECL_SIZE (decl));
  WALK_SUBTREE (DECL_SIZE_UNIT (decl));
@@ -5713,6 +5714,15 @@ cp_walk_subtrees (tree *tp, int *walk_subtrees_p, 
walk_tree_fn func,
   WALK_SUBTREE (STATIC_ASSERT_MESSAGE (*tp));
   break;
 
+case INTEGER_TYPE:
+  if (processing_template_decl)
+   {
+ /* Removed from walk_type_fields in r119481.  */
+ WALK_SUBTREE (TYPE_MIN_VALUE (*tp));
+ WALK_SUBTREE (TYPE_MAX_VALUE (*tp));
+   }
+  break;
+
 default:
   return NULL_TREE;
 }
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-ice4.C 
b/gcc/testsuite/g++.dg/cpp1y/lambda-ice4.C
new file mode 100644
index ..d8b7af9f9920
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/lambda-ice4.C
@@ -0,0 +1,63 @@
+// PR c++/114292
+// { dg-do "compile" { target c++14 } }
+// { dg-additional-options "-Wno-vla" }
+
+#define ASSERT_CAPTURE_NUMBER(Lambda, NumCaptures) \
+  { \
+auto oneCapture = [&](auto) { int t[c]; }; \
+const auto sizeOneCapture = sizeof (oneCapture); \
+const auto expected = NumCaptures ? NumCaptures * sizeOneCapture : 1; \
+static_assert (sizeof (Lambda) == expected, ""); \
+  }
+
+template
+struct Want_a_Typedef { typedef int Type[r*c]; };
+
+void foo (int c)
+{
+  constexpr int r = 4;
+
+  // This used to ICE.
+  auto ice_1 = [&](auto) { int t[c * r]; };
+  ice_1 (0);
+  ASSERT_CAPTURE_NUMBER (ice_1, 2);
+
+  // Another ICE identified following a great question in the patch submission
+  // mail thread.
+  auto ice_2 = [&](auto) { typedef int MyT[c*r]; };
+  ice_2 (0);
+  ASSERT_CAPTURE_NUMBER (ice_2, 2);
+
+  // All those worked already, but were not covered by any test - do it here.
+  auto ok_0 = [&](auto) { typedef int MyT[c*r]; MyT t; };
+  ok_0 (0);
+  ASSERT_CAPTURE_NUMBER (ok_0, 2);
+
+  auto ok_1 = [&](auto) { Want_a_Typedef::Type t; };
+  ok_1 (0);
+  ASSERT_CAPTURE_NUMBER (ok_1, 0);
+
+  auto ok_2 = [&](auto) { int t[c]; };
+  ok_2 (0);
+  ASSERT_CAPTURE_NUMBER (ok_2, 1);
+
+  auto ok_3 = [&](auto) { int n = r * c; int t[n]; };
+  ok_3 (0);
+  ASSERT_CAPTURE_NUMBER (ok_3, 2);
+
+  auto ok_4 = [&](auto) { int t[r]; };
+  ok_4 (0);
+  ASSERT_CAPTURE_NUMBER (ok_4, 0);
+
+  auto ok_5 = [&](auto) { int t[c * 4]; };
+  ok_5 (0);
+  ASSERT_CAPTURE_NUMBER (ok_5, 1);
+
+  auto ok_6 = [&](auto) { int t[1]; };
+  ok_6 (0);
+  ASSERT_CAPTURE_NUMBER (ok_6, 0);
+
+  auto ok_7 = [&](auto) { int t[c * r]; };
+  ok_7 (0);
+  ASSERT_CAPTURE_NUMBER (ok_7, 2);
+}


[gcc r15-8579] gccrs: typecheck: Add note about erorring out on additional trait bounds.

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:36dfbd985e7060bafc78aca8b85f9d71dac503c3

commit r15-8579-g36dfbd985e7060bafc78aca8b85f9d71dac503c3
Author: Arthur Cohen 
Date:   Wed Dec 25 11:07:17 2024 +

gccrs: typecheck: Add note about erorring out on additional trait bounds.

If additional trait bounds aren't auto traits, then the typechecker
must error out (Rust-GCC#3008)

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-type.cc: Add TODO note.

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

diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc 
b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index e9859a71f832..e9207effafb7 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -757,6 +757,11 @@ TypeCheckType::visit (HIR::TraitObjectType &type)
   std::vector specified_bounds;
   for (auto &bound : type.get_type_param_bounds ())
 {
+  // TODO: here we need to check if there are additional bounds that aren't
+  // auto traits. this is an error. for example, `dyn A + Sized + Sync` is
+  // okay, because Sized and Sync are both auto traits but `dyn A + Copy +
+  // Clone` is not okay and should error out.
+
   if (bound->get_bound_type ()
  != HIR::TypeParamBound::BoundType::TRAITBOUND)
continue;


[gcc r15-8576] gccrs: typecheck-path: Fix typo (reciever -> receiver)

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:bb110608484fe488e7cfed42d9c7dee37032a1d8

commit r15-8576-gbb110608484fe488e7cfed42d9c7dee37032a1d8
Author: Arthur Cohen 
Date:   Fri Dec 20 11:29:32 2024 +

gccrs: typecheck-path: Fix typo (reciever -> receiver)

gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.cc: Fix typos.
* typecheck/rust-hir-path-probe.h: Likewise.
* typecheck/rust-hir-type-check-path.cc: Likewise.

Diff:
---
 gcc/rust/typecheck/rust-hir-path-probe.cc  |  4 ++--
 gcc/rust/typecheck/rust-hir-path-probe.h   |  2 +-
 gcc/rust/typecheck/rust-hir-type-check-path.cc | 10 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-path-probe.cc 
b/gcc/rust/typecheck/rust-hir-path-probe.cc
index 2e9ad95dde3d..1148b24b0107 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.cc
+++ b/gcc/rust/typecheck/rust-hir-path-probe.cc
@@ -168,7 +168,7 @@ PathProbeType::Probe (const TyTy::BaseType *receiver,
   if (!probe_bounds)
 return probe.candidates;
 
-  if (!probe.is_reciever_generic ())
+  if (!probe.is_receiver_generic ())
 {
   std::vector> probed_bounds
= TypeBoundsProbe::Probe (receiver);
@@ -433,7 +433,7 @@ PathProbeType::union_bounds (
 }
 
 bool
-PathProbeType::is_reciever_generic () const
+PathProbeType::is_receiver_generic () const
 {
   const TyTy::BaseType *root = receiver->get_root ();
   bool receiver_is_type_param = root->get_kind () == TyTy::TypeKind::PARAM;
diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h 
b/gcc/rust/typecheck/rust-hir-path-probe.h
index 09a6492596d3..59ffeb114e0a 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.h
+++ b/gcc/rust/typecheck/rust-hir-path-probe.h
@@ -145,7 +145,7 @@ protected:
 const std::vector> b)
 const;
 
-  bool is_reciever_generic () const;
+  bool is_receiver_generic () const;
 
   const TyTy::BaseType *receiver;
   const HIR::PathIdentSegment &search;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc 
b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index 4746e7d730da..4c7dec1dea38 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -354,13 +354,13 @@ TypeCheckExpr::resolve_segments (NodeId 
root_resolved_node_id,
 {
   NodeId resolved_node_id = root_resolved_node_id;
   TyTy::BaseType *prev_segment = tyseg;
-  bool reciever_is_generic = prev_segment->get_kind () == 
TyTy::TypeKind::PARAM;
-  bool reciever_is_dyn = prev_segment->get_kind () == TyTy::TypeKind::DYNAMIC;
+  bool receiver_is_generic = prev_segment->get_kind () == 
TyTy::TypeKind::PARAM;
+  bool receiver_is_dyn = prev_segment->get_kind () == TyTy::TypeKind::DYNAMIC;
 
   for (size_t i = offset; i < segments.size (); i++)
 {
   HIR::PathExprSegment &seg = segments.at (i);
-  bool probe_impls = !reciever_is_generic;
+  bool probe_impls = !receiver_is_generic;
 
   // probe the path is done in two parts one where we search impls if no
   // candidate is found then we search extensions from traits
@@ -435,7 +435,7 @@ TypeCheckExpr::resolve_segments (NodeId 
root_resolved_node_id,
}
}
 
-  if (associated_impl_block != nullptr && !reciever_is_dyn)
+  if (associated_impl_block != nullptr && !receiver_is_dyn)
{
  // associated types
  HirId impl_block_id
@@ -492,7 +492,7 @@ TypeCheckExpr::resolve_segments (NodeId 
root_resolved_node_id,
  if (tyseg->get_kind () == TyTy::TypeKind::ERROR)
return;
}
-  else if (tyseg->needs_generic_substitutions () && !reciever_is_generic)
+  else if (tyseg->needs_generic_substitutions () && !receiver_is_generic)
{
  location_t locus = seg.get_locus ();
  tyseg = SubstMapper::InferSubst (tyseg, locus);


[gcc r15-8577] gccrs: parser: Add testcases for multiline strings

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:f30ba73582e4c53d4936e9c091d60b187a276373

commit r15-8577-gf30ba73582e4c53d4936e9c091d60b187a276373
Author: Arthur Cohen 
Date:   Wed Dec 25 17:02:38 2024 +

gccrs: parser: Add testcases for multiline strings

Regression checks for Rust-GCC#1399

gcc/testsuite/ChangeLog:

* rust/compile/multiline-string.rs: New test.
* rust/execute/torture/multiline-string.rs: New test.

Diff:
---
 gcc/testsuite/rust/compile/multiline-string.rs | 14 ++
 gcc/testsuite/rust/execute/torture/multiline-string.rs | 15 +++
 2 files changed, 29 insertions(+)

diff --git a/gcc/testsuite/rust/compile/multiline-string.rs 
b/gcc/testsuite/rust/compile/multiline-string.rs
new file mode 100644
index ..fcd6fa812ed2
--- /dev/null
+++ b/gcc/testsuite/rust/compile/multiline-string.rs
@@ -0,0 +1,14 @@
+fn main() {
+let _a = "gcc
+
+rs";
+
+let _b = "rust
+
+c
+gcc
+
+
+
+rs";
+}
diff --git a/gcc/testsuite/rust/execute/torture/multiline-string.rs 
b/gcc/testsuite/rust/execute/torture/multiline-string.rs
new file mode 100644
index ..4d22f991ad35
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/multiline-string.rs
@@ -0,0 +1,15 @@
+// { dg-output "gcc\n\nrs\n" }
+
+extern "C" {
+fn printf(fmt: *const i8, ...);
+}
+
+fn main() -> i32 {
+let a = "gcc
+
+rs\0";
+
+unsafe { printf("%s\n\0" as *const str as *const i8, a as *const str as 
*const i8); }
+
+0
+}


[gcc r15-8615] gccrs: Remove dead code related to external functions

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:3a82942eaa26060e02bcd1bafc6820d1399ac335

commit r15-8615-g3a82942eaa26060e02bcd1bafc6820d1399ac335
Author: Owen Avery 
Date:   Fri Jan 10 15:50:25 2025 -0500

gccrs: Remove dead code related to external functions

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc
(TokenCollector::visit): Remove visitor for NamedFunctionParam.
* ast/rust-ast-collector.h
(TokenCollector::visit): Likewise.
* ast/rust-ast-full-decls.h
(class NamedFunctionParam): Remove forward declaration.
* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Remove visitor for
NamedFunctionParam.
* ast/rust-ast-visitor.h
(DefaultASTVisitor::visit): Likewise.
* ast/rust-ast.cc
(NamedFunctionParam::as_string): Remove.
* ast/rust-item.h
(class NamedFunctionParam): Remove.
(class ExternalFunctionItem): Remove.
* parse/rust-parse-impl.h
(Parser::parse_named_function_param): Remove.
(Parser::parse_named_function_params): Remove.
* parse/rust-parse.h
(Parser::parse_named_function_param): Remove.
(Parser::parse_named_function_params): Remove.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/ast/rust-ast-collector.cc |  23 ---
 gcc/rust/ast/rust-ast-collector.h  |   1 -
 gcc/rust/ast/rust-ast-full-decls.h |   1 -
 gcc/rust/ast/rust-ast-visitor.cc   |   8 -
 gcc/rust/ast/rust-ast-visitor.h|   1 -
 gcc/rust/ast/rust-ast.cc   |  16 --
 gcc/rust/ast/rust-item.h   | 297 -
 gcc/rust/parse/rust-parse-impl.h   | 100 -
 gcc/rust/parse/rust-parse.h|   4 -
 9 files changed, 451 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-collector.cc 
b/gcc/rust/ast/rust-ast-collector.cc
index bc76deb9a6d5..320611614e92 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -250,29 +250,6 @@ TokenCollector::visit (Visibility &vis)
 }
 }
 
-void
-TokenCollector::visit (NamedFunctionParam ¶m)
-{
-  auto name = param.get_name ();
-  if (!param.is_variadic ())
-{
-  push (
-   Rust::Token::make_identifier (param.get_locus (), std::move (name)));
-  push (Rust::Token::make (COLON, UNDEF_LOCATION));
-  visit (param.get_type ());
-}
-  else
-{
-  if (name != "")
-   {
- push (Rust::Token::make_identifier (param.get_locus (),
- std::move (name)));
- push (Rust::Token::make (COLON, UNDEF_LOCATION));
-   }
-  push (Rust::Token::make (ELLIPSIS, UNDEF_LOCATION));
-}
-}
-
 void
 TokenCollector::visit (std::vector> ¶ms)
 {
diff --git a/gcc/rust/ast/rust-ast-collector.h 
b/gcc/rust/ast/rust-ast-collector.h
index 32a5bd33da7c..30aff9851051 100644
--- a/gcc/rust/ast/rust-ast-collector.h
+++ b/gcc/rust/ast/rust-ast-collector.h
@@ -210,7 +210,6 @@ public:
   void visit (TupleField &field);
   void visit (StructField &field);
   void visit (SimplePathSegment &segment);
-  void visit (NamedFunctionParam ¶m);
   void visit (MacroRule &rule);
   void visit (WhereClause &rule);
   void visit (std::vector &for_lifetimes);
diff --git a/gcc/rust/ast/rust-ast-full-decls.h 
b/gcc/rust/ast/rust-ast-full-decls.h
index 80d217e0c528..9359248aabd5 100644
--- a/gcc/rust/ast/rust-ast-full-decls.h
+++ b/gcc/rust/ast/rust-ast-full-decls.h
@@ -202,7 +202,6 @@ class TraitImpl;
 class ExternalItem;
 class ExternalTypeItem;
 class ExternalStaticItem;
-class NamedFunctionParam;
 class ExternBlock;
 
 // rust-macro.h
diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index d10ca6ca07b0..6959c49d66a5 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -1060,14 +1060,6 @@ DefaultASTVisitor::visit (AST::ExternalStaticItem &item)
   visit (item.get_type ());
 }
 
-void
-DefaultASTVisitor::visit (AST::NamedFunctionParam ¶m)
-{
-  visit_outer_attrs (param);
-  if (!param.is_variadic ())
-visit (param.get_type ());
-}
-
 void
 DefaultASTVisitor::visit (AST::ExternBlock &block)
 {
diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index 7e3423cd4930..a7c1cc9c62bb 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -428,7 +428,6 @@ public:
   virtual void visit (AST::WhereClause &where);
   virtual void visit (AST::StructField &field);
   virtual void visit (AST::TupleField &field);
-  virtual void visit (AST::NamedFunctionParam ¶m);
   virtual void visit (AST::MacroRule &rule);
   virtual void visit (AST::MacroInvocData &data);
   virtual void visit (AST::MacroTranscriber &transcriber);
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 06a7a097cfb7..25e522bf948d 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -2997,22 +2997,6 

[gcc r15-8595] gccrs: nr2.0: Improve default, top-level, and late resolvers

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:c35aa64fbf71c11d30c7a9f8c37a9fc07ada8a7b

commit r15-8595-gc35aa64fbf71c11d30c7a9f8c37a9fc07ada8a7b
Author: Owen Avery 
Date:   Thu Jan 2 05:55:38 2025 -0500

gccrs: nr2.0: Improve default, top-level, and late resolvers

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc
(DefaultResolver::visit): Make sure to scope visitation of the
children of type definition items.
* resolve/rust-default-resolver.h
(DefaultResolver::visit): Add overrides for TupleStruct, Union,
and TypeAlias.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Remove override for Enum.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Rely more on DefaultResolver::visit.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Remove override for BlockExpr.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-default-resolver.cc  | 35 ---
 gcc/rust/resolve/rust-default-resolver.h   |  3 ++
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc|  7 ---
 gcc/rust/resolve/rust-late-name-resolver-2.0.h |  1 -
 .../resolve/rust-toplevel-name-resolver-2.0.cc | 50 +-
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h |  1 -
 gcc/testsuite/rust/compile/nr2/exclude |  9 
 7 files changed, 41 insertions(+), 65 deletions(-)

diff --git a/gcc/rust/resolve/rust-default-resolver.cc 
b/gcc/rust/resolve/rust-default-resolver.cc
index 57b1cc448158..7528e7950e64 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -88,27 +88,48 @@ DefaultResolver::visit (AST::TraitImpl &impl)
 void
 DefaultResolver::visit (AST::StructStruct &type)
 {
-  // do we need to scope anything here? no, right?
+  auto inner_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
 
-  // we also can't visit `StructField`s by default, so there's nothing to do -
-  // correct? or should we do something like
+  ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
+ inner_fn, type.get_struct_name ());
+}
 
-  AST::DefaultASTVisitor::visit (type);
+void
+DefaultResolver::visit (AST::TupleStruct &type)
+{
+  auto inner_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
 
-  // FIXME: ???
+  ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
+ inner_fn, type.get_struct_name ());
 }
 
 void
 DefaultResolver::visit (AST::Enum &type)
 {
-  // FIXME: Do we need to scope anything by default?
-
   auto variant_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
 
   ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
  variant_fn, type.get_identifier ());
 }
 
+void
+DefaultResolver::visit (AST::Union &type)
+{
+  auto inner_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
+
+  ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
+ inner_fn, type.get_identifier ());
+}
+
+void
+DefaultResolver::visit (AST::TypeAlias &type)
+{
+  auto inner_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
+
+  ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
+ inner_fn, type.get_new_type_name ());
+}
+
 void
 DefaultResolver::visit (AST::ClosureExprInner &expr)
 {
diff --git a/gcc/rust/resolve/rust-default-resolver.h 
b/gcc/rust/resolve/rust-default-resolver.h
index 9fcddd158513..587d7d458034 100644
--- a/gcc/rust/resolve/rust-default-resolver.h
+++ b/gcc/rust/resolve/rust-default-resolver.h
@@ -52,7 +52,10 @@ public:
 
   // type dec nodes, which visit their fields or variants by default
   void visit (AST::StructStruct &) override;
+  void visit (AST::TupleStruct &) override;
   void visit (AST::Enum &) override;
+  void visit (AST::Union &) override;
+  void visit (AST::TypeAlias &) override;
 
   // Visitors that visit their expression node(s)
   void visit (AST::ClosureExprInner &) override;
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 86fd5f121738..bb099ab68aec 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -308,13 +308,6 @@ Late::visit (AST::StructStruct &s)
   ctx.scoped (Rib::Kind::Item, s.get_node_id (), s_vis);
 }
 
-void
-Late::visit (AST::Enum &s)
-{
-  auto s_vis = [this, &s] () { AST::DefaultASTVisitor::visit (s); };
-  ctx.scoped (Rib::Kind::Item, s.get_node_id (), s_vis);
-}
-
 void
 Late::visit (AST::StructExprStruct &s)
 {
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h 
b/gcc/rust/resolve

[gcc r15-8606] gccrs: Visit the trait paths of trait implementations

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:76565cabf2842b7dff20f4a3cbe2808fec7d15da

commit r15-8606-g76565cabf2842b7dff20f4a3cbe2808fec7d15da
Author: Owen Avery 
Date:   Sat Dec 28 15:58:41 2024 -0500

gccrs: Visit the trait paths of trait implementations

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): When visiting a TraitImpl, visit its
trait path.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/ast/rust-ast-visitor.cc   |  1 +
 gcc/testsuite/rust/compile/nr2/exclude | 46 --
 2 files changed, 1 insertion(+), 46 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index 32e8025e9b28..d10ca6ca07b0 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -1039,6 +1039,7 @@ DefaultASTVisitor::visit (AST::TraitImpl &impl)
   if (impl.has_where_clause ())
 visit (impl.get_where_clause ());
   visit (impl.get_type ());
+  visit (impl.get_trait_path ());
   visit_inner_attrs (impl);
   for (auto &item : impl.get_impl_items ())
 visit (item);
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 9b1ee7ceaf99..9b490c18bab4 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -13,7 +13,6 @@ cfg4.rs
 cfg5.rs
 closure_no_type_anno.rs
 complex-path1.rs
-complex_qualified_path_in_expr.rs
 const-issue1440.rs
 const_generics_3.rs
 const_generics_4.rs
@@ -21,12 +20,8 @@ const_generics_5.rs
 const_generics_7.rs
 derive_empty.rs
 derive_macro1.rs
-derive_macro3.rs
-derive_macro4.rs
-derive_macro6.rs
 expected_type_args2.rs
 feature_rust_attri0.rs
-for_lifetimes.rs
 format_args_basic_expansion.rs
 generic-default1.rs
 generics1.rs
@@ -38,9 +33,6 @@ generics5.rs
 generics6.rs
 generics9.rs
 if_let_expr.rs
-issue-1019.rs
-issue-1034.rs
-issue-1129-2.rs
 issue-1130.rs
 issue-1173.rs
 issue-1272.rs
@@ -52,24 +44,12 @@ issue-1786.rs
 issue-1893.rs
 issue-1901.rs
 issue-1981.rs
-issue-2019-1.rs
-issue-2019-2.rs
-issue-2019-3.rs
 issue-2036.rs
-issue-2037.rs
 issue-2043.rs
-issue-2070.rs
-issue-2135.rs
-issue-2136-1.rs
 issue-2136-2.rs
-issue-2139.rs
 issue-2142.rs
-issue-2165.rs
-issue-2166.rs
 issue-2238.rs
-issue-2304.rs
 issue-2330.rs
-issue-2478.rs
 issue-2479.rs
 issue-2723-1.rs
 issue-2723-2.rs
@@ -80,10 +60,8 @@ issue-2812.rs
 issue-850.rs
 issue-852.rs
 issue-855.rs
-issue-925.rs
 iterators1.rs
 lookup_err1.rs
-macros/mbe/macro-issue1400.rs
 macros/mbe/macro13.rs
 macros/mbe/macro15.rs
 macros/mbe/macro23.rs
@@ -111,7 +89,6 @@ name_resolution4.rs
 nested_macro_use1.rs
 nested_macro_use2.rs
 nested_macro_use3.rs
-non_member_const.rs
 not_find_value_in_scope.rs
 parse_associated_type_as_generic_arg.rs
 parse_associated_type_as_generic_arg2.rs
@@ -135,17 +112,10 @@ redef_error5.rs
 self-path1.rs
 self-path2.rs
 sizeof-stray-infer-var-bug.rs
-stmt_with_block_dot.rs
 struct-expr-parse.rs
-traits1.rs
-traits12.rs
-traits2.rs
 traits3.rs
-traits4.rs
-traits5.rs
 traits6.rs
 traits7.rs
-traits8.rs
 type-bindings1.rs
 unconstrained_type_param.rs
 undeclared_label.rs
@@ -154,27 +124,13 @@ use_2.rs
 v0-mangle1.rs
 v0-mangle2.rs
 while_break_expr.rs
-negative_impls.rs
 exhaustiveness1.rs
 exhaustiveness2.rs
 exhaustiveness3.rs
-trait13.rs
-trait14.rs
 issue-2324-1.rs
 issue-2324-2.rs
-issue-2987.rs
-issue-3045-1.rs
-issue-3045-2.rs
 issue-3046.rs
-issue-3030.rs
-issue-3035.rs
-issue-3139-1.rs
 issue-3139-2.rs
-issue-3139-3.rs
-issue-3036.rs
-issue-2951.rs
-issue-2203.rs
-issue-2499.rs
 issue-3032-1.rs
 issue-3032-2.rs
 # https://github.com/Rust-GCC/gccrs/issues/3189
@@ -184,13 +140,11 @@ issue-3033.rs
 issue-3009.rs
 issue-2953-2.rs
 issue-1773.rs
-issue-2905-1.rs
 issue-2905-2.rs
 issue-2907.rs
 issue-2423.rs
 issue-266.rs
 additional-trait-bounds2.rs
-auto_traits2.rs
 auto_traits3.rs
 issue-3140.rs
 cmp1.rs


[gcc r15-8612] gccrs: Revert "gcc/rust/ChangeLog:"

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:29367fe699afe6a385e311b90f9c3850b19744ac

commit r15-8612-g29367fe699afe6a385e311b90f9c3850b19744ac
Author: CohenArthur 
Date:   Fri Jan 10 15:26:39 2025 +0100

gccrs: Revert "gcc/rust/ChangeLog:"

This reverts commit 600fd806b8821ea24103ea0f31d666077245c6b7.

Diff:
---
 gcc/rust/ast/rust-collect-lang-items.cc | 7 ++-
 gcc/rust/util/rust-attributes.cc| 8 
 gcc/rust/util/rust-attributes.h | 2 --
 3 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/gcc/rust/ast/rust-collect-lang-items.cc 
b/gcc/rust/ast/rust-collect-lang-items.cc
index ec6919dca14e..50d134a429f5 100644
--- a/gcc/rust/ast/rust-collect-lang-items.cc
+++ b/gcc/rust/ast/rust-collect-lang-items.cc
@@ -40,7 +40,12 @@ get_lang_item_attr (const T &maybe_lang_item)
  continue;
}
 
-  if (Analysis::Attributes::is_lang_item (str_path, attr))
+  bool is_lang_item = str_path == Values::Attributes::LANG
+ && attr.has_attr_input ()
+ && attr.get_attr_input ().get_attr_input_type ()
+  == AST::AttrInput::AttrInputType::LITERAL;
+
+  if (is_lang_item)
{
  auto &literal
= static_cast (attr.get_attr_input ());
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 0234903ba585..9f63234112c5 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -37,14 +37,6 @@ Attributes::is_known (const std::string &attribute_path)
 
   return !lookup.is_error ();
 }
-bool
-Attributes::is_lang_item (const std::string &attribute_path,
- const AST::Attribute &attr)
-{
-  return ((attribute_path == Values::Attributes::LANG) && attr.has_attr_input 
()
- && (attr.get_attr_input ().get_attr_input_type ()
- == AST::AttrInput::AttrInputType::LITERAL));
-}
 
 using Attrs = Values::Attributes;
 
diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h
index 30f9eef213bc..c928c8eb9d26 100644
--- a/gcc/rust/util/rust-attributes.h
+++ b/gcc/rust/util/rust-attributes.h
@@ -29,8 +29,6 @@ class Attributes
 {
 public:
   static bool is_known (const std::string &attribute_path);
-  static bool is_lang_item (const std::string &attribute_path,
-   const AST::Attribute &attr);
 };
 
 enum CompilerPass


[gcc r15-8623] gccrs: lang-item: Add LangItem::PrettyString

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:5702b0a24e64082bcfd19372a67ef7699d033d22

commit r15-8623-g5702b0a24e64082bcfd19372a67ef7699d033d22
Author: Arthur Cohen 
Date:   Thu Dec 26 22:45:12 2024 +

gccrs: lang-item: Add LangItem::PrettyString

Which formats a lang item as it appears in source code.

gcc/rust/ChangeLog:

* util/rust-lang-item.cc (LangItem::PrettyString): New.
* util/rust-lang-item.h: New.

Diff:
---
 gcc/rust/util/rust-lang-item.cc | 6 ++
 gcc/rust/util/rust-lang-item.h  | 1 +
 2 files changed, 7 insertions(+)

diff --git a/gcc/rust/util/rust-lang-item.cc b/gcc/rust/util/rust-lang-item.cc
index 4a6090961443..e038e900f947 100644
--- a/gcc/rust/util/rust-lang-item.cc
+++ b/gcc/rust/util/rust-lang-item.cc
@@ -118,6 +118,12 @@ LangItem::ToString (LangItem::Kind type)
   return str.value ();
 }
 
+std::string
+LangItem::PrettyString (LangItem::Kind type)
+{
+  return "#[lang = \"" + LangItem::ToString (type) + "\"]";
+}
+
 LangItem::Kind
 LangItem::OperatorToLangItem (ArithmeticOrLogicalOperator op)
 {
diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h
index 62b15d7b3fc5..f947f3f021c0 100644
--- a/gcc/rust/util/rust-lang-item.h
+++ b/gcc/rust/util/rust-lang-item.h
@@ -134,6 +134,7 @@ public:
 
   static tl::optional Parse (const std::string &item);
   static std::string ToString (Kind type);
+  static std::string PrettyString (Kind type);
   static Kind OperatorToLangItem (ArithmeticOrLogicalOperator op);
   static Kind
   CompoundAssignmentOperatorToLangItem (ArithmeticOrLogicalOperator op);


[gcc r15-8608] gccrs: gcc/rust/ChangeLog:

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:7fd30073101a94bcbe29bab6ca45b05ab74542aa

commit r15-8608-g7fd30073101a94bcbe29bab6ca45b05ab74542aa
Author: Om Swaroop Nayak <96killera...@gmail.com>
Date:   Wed Jan 1 09:02:02 2025 -0800

gccrs: gcc/rust/ChangeLog:

* ast/rust-collect-lang-items.cc (get_lang_item_attr): "removed 
checker fn"
* util/rust-attributes.cc (Attributes::is_lang_item): "added fn"
* util/rust-attributes.h: "added fn"

Signed-off-by: Om Swaroop Nayak <96killera...@gmail.com>

Diff:
---
 gcc/rust/ast/rust-collect-lang-items.cc | 7 +--
 gcc/rust/util/rust-attributes.cc| 8 
 gcc/rust/util/rust-attributes.h | 2 ++
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/ast/rust-collect-lang-items.cc 
b/gcc/rust/ast/rust-collect-lang-items.cc
index 50d134a429f5..ec6919dca14e 100644
--- a/gcc/rust/ast/rust-collect-lang-items.cc
+++ b/gcc/rust/ast/rust-collect-lang-items.cc
@@ -40,12 +40,7 @@ get_lang_item_attr (const T &maybe_lang_item)
  continue;
}
 
-  bool is_lang_item = str_path == Values::Attributes::LANG
- && attr.has_attr_input ()
- && attr.get_attr_input ().get_attr_input_type ()
-  == AST::AttrInput::AttrInputType::LITERAL;
-
-  if (is_lang_item)
+  if (Analysis::Attributes::is_lang_item (str_path, attr))
{
  auto &literal
= static_cast (attr.get_attr_input ());
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 9f63234112c5..0234903ba585 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -37,6 +37,14 @@ Attributes::is_known (const std::string &attribute_path)
 
   return !lookup.is_error ();
 }
+bool
+Attributes::is_lang_item (const std::string &attribute_path,
+ const AST::Attribute &attr)
+{
+  return ((attribute_path == Values::Attributes::LANG) && attr.has_attr_input 
()
+ && (attr.get_attr_input ().get_attr_input_type ()
+ == AST::AttrInput::AttrInputType::LITERAL));
+}
 
 using Attrs = Values::Attributes;
 
diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h
index c928c8eb9d26..30f9eef213bc 100644
--- a/gcc/rust/util/rust-attributes.h
+++ b/gcc/rust/util/rust-attributes.h
@@ -29,6 +29,8 @@ class Attributes
 {
 public:
   static bool is_known (const std::string &attribute_path);
+  static bool is_lang_item (const std::string &attribute_path,
+   const AST::Attribute &attr);
 };
 
 enum CompilerPass


[gcc r15-8626] gccrs: ast-collector: Fix tuple struct pattern collection

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:5d3afe339b907749e65c369ca3814c7d6c2c216f

commit r15-8626-g5d3afe339b907749e65c369ca3814c7d6c2c216f
Author: Arthur Cohen 
Date:   Fri Jan 3 14:28:07 2025 +

gccrs: ast-collector: Fix tuple struct pattern collection

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Visit tuple 
pattern items as
separated by commas.

Diff:
---
 gcc/rust/ast/rust-ast-collector.cc | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-collector.cc 
b/gcc/rust/ast/rust-ast-collector.cc
index 4c9c360c04d2..978de648a583 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -2470,10 +2470,7 @@ TokenCollector::visit (StructPattern &pattern)
 void
 TokenCollector::visit (TupleStructItemsNoRange &pattern)
 {
-  for (auto &pat : pattern.get_patterns ())
-{
-  visit (pat);
-}
+  visit_items_joined_by_separator (pattern.get_patterns ());
 }
 
 void


[gcc r15-8590] gccrs: tychk: Add more support for additional trait bounds in functions

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:161b9e9828b84b75f64aa0ffdadcefe920c1ed0d

commit r15-8590-g161b9e9828b84b75f64aa0ffdadcefe920c1ed0d
Author: Arthur Cohen 
Date:   Wed Dec 25 18:13:43 2024 +

gccrs: tychk: Add more support for additional trait bounds in functions

This commit correctly lowers and typechecks parenthesized types, which are 
used for trait objects with additional bounds.

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-type.cc (ResolveType::visit): New 
visitor to handle
ParenthesizedType.
* resolve/rust-ast-resolve-type.h: Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): 
Likewise.
* typecheck/rust-hir-type-check-type.h: Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/auto_traits2.rs: New test.
* rust/compile/auto_traits3.rs: New test.
* rust/compile/nr2/exclude: Add auto_traits2 test.

Diff:
---
 gcc/rust/resolve/rust-ast-resolve-type.cc  |  6 +
 gcc/rust/resolve/rust-ast-resolve-type.h   |  3 +++
 gcc/rust/typecheck/rust-hir-type-check-type.cc |  6 +
 gcc/rust/typecheck/rust-hir-type-check-type.h  |  4 +--
 gcc/testsuite/rust/compile/auto_traits2.rs | 26 
 gcc/testsuite/rust/compile/auto_traits3.rs | 34 ++
 gcc/testsuite/rust/compile/nr2/exclude |  2 ++
 7 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc 
b/gcc/rust/resolve/rust-ast-resolve-type.cc
index cb5a18d5d477..1d004b1ba9bb 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-type.cc
@@ -50,6 +50,12 @@ ResolveType::visit (AST::TraitObjectType &type)
 }
 }
 
+void
+ResolveType::visit (AST::ParenthesisedType &type)
+{
+  resolved_node = ResolveType::go (*type.get_type_in_parens ());
+}
+
 void
 ResolveType::visit (AST::ReferenceType &type)
 {
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h 
b/gcc/rust/resolve/rust-ast-resolve-type.h
index 518c0d80b14d..5e8cdb11b2d7 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -24,6 +24,7 @@
 #include "rust-diagnostics.h"
 #include "rust-hir-map.h"
 #include "rust-path.h"
+#include "rust-type.h"
 #include "util/rust-hir-map.h"
 
 namespace Rust {
@@ -143,6 +144,8 @@ public:
 
   void visit (AST::TraitObjectType &type) override;
 
+  void visit (AST::ParenthesisedType &type) override;
+
   void visit (AST::SliceType &type) override;
 
 private:
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc 
b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 4ea1a493fa80..859cdfedcd0b 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -790,6 +790,12 @@ TypeCheckType::visit (HIR::TraitObjectType &type)
   std::move (specified_bounds));
 }
 
+void
+TypeCheckType::visit (HIR::ParenthesisedType &type)
+{
+  translated = TypeCheckType::Resolve (type.get_type_in_parens ());
+}
+
 void
 TypeCheckType::visit (HIR::ArrayType &type)
 {
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.h 
b/gcc/rust/typecheck/rust-hir-type-check-type.h
index bf5589cbbabd..1da01b869ddc 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.h
@@ -59,6 +59,7 @@ public:
   void visit (HIR::InferredType &type) override;
   void visit (HIR::NeverType &type) override;
   void visit (HIR::TraitObjectType &type) override;
+  void visit (HIR::ParenthesisedType &type) override;
 
   void visit (HIR::TypePathSegmentFunction &segment) override
   { /* TODO */
@@ -69,9 +70,6 @@ public:
   void visit (HIR::ImplTraitType &type) override
   { /* TODO */
   }
-  void visit (HIR::ParenthesisedType &type) override
-  { /* TODO */
-  }
   void visit (HIR::ImplTraitTypeOneBound &type) override
   { /* TODO */
   }
diff --git a/gcc/testsuite/rust/compile/auto_traits2.rs 
b/gcc/testsuite/rust/compile/auto_traits2.rs
new file mode 100644
index ..7d0dcc11cd2a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/auto_traits2.rs
@@ -0,0 +1,26 @@
+#![feature(optin_builtin_traits)]
+
+pub unsafe auto trait Send {}
+#[lang = "sync"]
+pub unsafe auto trait Sync {}
+
+trait A {
+fn a_method(&self) {}
+}
+
+fn foo(a: &(dyn A + Send + Sync)) {
+a.a_method();
+}
+
+struct S;
+
+impl A for S {
+fn a_method(&self) {}
+}
+
+fn main() {
+let s = S;
+
+foo(&s); // { dg-error "bounds not satisfied" }
+ // { dg-error "mismatched type" "" { target *-*-* } .-1 }
+}
diff --git a/gcc/testsuite/rust/compile/auto_traits3.rs 
b/gcc/testsuite/rust/compile/auto_traits3.rs
new file mode 100644
index ..81c39ecda7f4
--- /dev/null
+++ b/gcc/testsuite/rust/compile/auto_traits3.rs
@@ -0,0 +1,34 @@
+#![feature(optin_builtin_traits)]
+
+pub unsafe auto trait Send {}
+#[lang = "sync"]
+pub unsafe au

[gcc r15-8591] gccrs: nr2.0: Resolve type aliases inside trait definitions

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:c583545a9adaba0ab9d369f82b5f9bb1577e5f6e

commit r15-8591-gc583545a9adaba0ab9d369f82b5f9bb1577e5f6e
Author: Owen Avery 
Date:   Thu Jan 2 05:29:03 2025 -0500

gccrs: nr2.0: Resolve type aliases inside trait definitions

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Add visitor for TraitItemType.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Likewise.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery 

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

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 6d52fcaaac85..4833233e0258 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -109,6 +109,15 @@ TopLevel::visit (AST::Trait &trait)
   DefaultResolver::visit (trait);
 }
 
+void
+TopLevel::visit (AST::TraitItemType &trait_item)
+{
+  insert_or_error_out (trait_item.get_identifier ().as_string (), trait_item,
+  Namespace::Types);
+
+  DefaultResolver::visit (trait_item);
+}
+
 template 
 static void
 insert_macros (std::vector ¯os, NameResolutionContext &ctx)
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 7f4e29585de3..f540ab9ae61d 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -148,6 +148,7 @@ private:
 
   void visit (AST::Module &module) override;
   void visit (AST::Trait &trait) override;
+  void visit (AST::TraitItemType &trait_item) override;
   void visit (AST::MacroRulesDefinition ¯o) override;
   void visit (AST::Function &function) override;
   void visit (AST::BlockExpr &expr) override;
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index e23669f309b4..da5880d9a57c 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -74,8 +74,6 @@ issue-2139.rs
 issue-2142.rs
 issue-2165.rs
 issue-2166.rs
-issue-2190-1.rs
-issue-2190-2.rs
 issue-2238.rs
 issue-2304.rs
 issue-2330.rs
@@ -85,7 +83,6 @@ issue-2723-1.rs
 issue-2723-2.rs
 issue-2772-2.rs
 issue-2775.rs
-issue-2747.rs
 issue-2782.rs
 issue-2812.rs
 issue-850.rs
@@ -98,7 +95,6 @@ macros/mbe/macro-issue1233.rs
 macros/mbe/macro-issue1400.rs
 macros/mbe/macro13.rs
 macros/mbe/macro15.rs
-macros/mbe/macro20.rs
 macros/mbe/macro23.rs
 macros/mbe/macro40.rs
 macros/mbe/macro43.rs
@@ -198,7 +194,6 @@ iflet.rs
 issue-3033.rs
 issue-3009.rs
 issue-2323.rs
-issue-2953-1.rs
 issue-2953-2.rs
 issue-1773.rs
 issue-2905-1.rs


[gcc r15-8602] gccrs: match arms are a LUB

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:8ce8781f29b425bb20dd4fcdd3981de9aa57131b

commit r15-8602-g8ce8781f29b425bb20dd4fcdd3981de9aa57131b
Author: Philip Herron 
Date:   Thu Jan 9 16:47:47 2025 +

gccrs: match arms are a LUB

Unify rules are not the same as coercion rules. The coercion of ! is
allowed to any type but not for a unify site which is different.

Match arms are another least upper bound coercion.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): implement 
coercion
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): 
this is an LUB
* typecheck/rust-unify.cc (UnifyRules::go): remove unify ! coercion

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/backend/rust-compile-expr.cc  | 13 -
 gcc/rust/typecheck/rust-hir-type-check-expr.cc |  7 ---
 gcc/rust/typecheck/rust-unify.cc   | 10 --
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index b40aa33866ea..353a498dc4ef 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1156,8 +1156,19 @@ CompileExpr::visit (HIR::MatchExpr &expr)
  location_t arm_locus = kase_arm.get_locus ();
  tree kase_expr_tree = CompileExpr::Compile (kase.get_expr (), ctx);
  tree result_reference = Backend::var_expression (tmp, arm_locus);
+
+ TyTy::BaseType *actual = nullptr;
+ bool ok = ctx->get_tyctx ()->lookup_type (
+   kase.get_expr ().get_mappings ().get_hirid (), &actual);
+ rust_assert (ok);
+
+ tree coerced_result
+   = coercion_site (kase.get_expr ().get_mappings ().get_hirid (),
+kase_expr_tree, actual, expr_tyty,
+expr.get_locus (), arm_locus);
+
  tree assignment
-   = Backend::assignment_statement (result_reference, kase_expr_tree,
+   = Backend::assignment_statement (result_reference, coerced_result,
 arm_locus);
  ctx->add_statement (assignment);
 
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc 
b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 7899b1a7943a..113f43f6c724 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1532,9 +1532,10 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr)
   for (size_t i = 1; i < kase_block_tys.size (); i++)
 {
   TyTy::BaseType *kase_ty = kase_block_tys.at (i);
-  infered = unify_site (expr.get_mappings ().get_hirid (),
-   TyTy::TyWithLocation (infered),
-   TyTy::TyWithLocation (kase_ty), expr.get_locus ());
+  infered
+   = coercion_site (expr.get_mappings ().get_hirid (),
+TyTy::TyWithLocation (infered),
+TyTy::TyWithLocation (kase_ty), expr.get_locus ());
 }
 }
 
diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc
index 8159c7d52bba..b779e7d46143 100644
--- a/gcc/rust/typecheck/rust-unify.cc
+++ b/gcc/rust/typecheck/rust-unify.cc
@@ -17,7 +17,6 @@
 // .
 
 #include "rust-unify.h"
-#include "rust-tyty.h"
 
 namespace Rust {
 namespace Resolver {
@@ -238,15 +237,6 @@ UnifyRules::go ()
}
 }
 
-  // The never type should always get coerced to the type it's being matched
-  // against, so in that case, ltype. This avoids doing the same check in all
-  // the `expect_*` functions.
-  // However, this does not work if we have an annoying ltype - like INFER.
-  // TODO: Is ltype == Infer the only special case here? What about 
projections?
-  // references?
-  if (rtype->get_kind () == TyTy::NEVER && ltype->get_kind () != TyTy::INFER)
-return ltype->clone ();
-
   switch (ltype->get_kind ())
 {
 case TyTy::INFER:


[gcc r15-8586] gccrs: nr2.0: Handle "Self" properly in trait definitions

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:6ac790d2dbba1c13a7ae637560d82aba1ec77038

commit r15-8586-g6ac790d2dbba1c13a7ae637560d82aba1ec77038
Author: Owen Avery 
Date:   Tue Dec 24 16:02:40 2024 -0500

gccrs: nr2.0: Handle "Self" properly in trait definitions

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Visit implicit Self parameters of
traits.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Resolve implicit Self parameters of traits.
* resolve/rust-late-name-resolver-2.0.h:
(Late::visit): Add trait visitor.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Insert resolutions for Self type parameters
as well.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/ast/rust-ast-visitor.cc|  2 ++
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 13 +
 gcc/rust/resolve/rust-late-name-resolver-2.0.h  |  1 +
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc |  7 ++-
 gcc/testsuite/rust/compile/nr2/exclude  |  2 --
 5 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index a390aa20bcb9..32e8025e9b28 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -997,6 +997,8 @@ DefaultASTVisitor::visit (AST::Trait &trait)
 
   visit_inner_attrs (trait);
 
+  visit (trait.get_implicit_self ());
+
   for (auto &generic : trait.get_generic_params ())
 visit (generic);
 
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 38515cdc0fde..86fd5f121738 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -288,6 +288,19 @@ Late::visit (AST::TypePath &type)
   DefaultResolver::visit (type);
 }
 
+void
+Late::visit (AST::Trait &trait)
+{
+  // kind of weird how this is done
+  // names are resolved to the node id of trait.get_implicit_self ()
+  // which is then resolved to the node id of trait
+  // we set up the latter mapping here
+  ctx.map_usage (Usage (trait.get_implicit_self ().get_node_id ()),
+Definition (trait.get_node_id ()));
+
+  DefaultResolver::visit (trait);
+}
+
 void
 Late::visit (AST::StructStruct &s)
 {
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 1dbca3648da9..803a5ec1c006 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -48,6 +48,7 @@ public:
   void visit (AST::PathInExpression &) override;
   void visit (AST::LangItemPath &) override;
   void visit (AST::TypePath &) override;
+  void visit (AST::Trait &) override;
   void visit (AST::StructExprStruct &) override;
   void visit (AST::StructExprStructBase &) override;
   void visit (AST::StructExprStructFields &) override;
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 a76c098f2df3..6d52fcaaac85 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -280,11 +280,8 @@ TopLevel::visit (AST::StructStruct &struct_item)
 void
 TopLevel::visit (AST::TypeParam &type_param)
 {
-  // Hacky and weird, find a better solution
-  // We should probably not even insert self in the first place ?
-  if (type_param.get_type_representation ().as_string () != "Self")
-insert_or_error_out (type_param.get_type_representation (), type_param,
-Namespace::Types);
+  insert_or_error_out (type_param.get_type_representation (), type_param,
+  Namespace::Types);
 }
 
 void
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 8bdcc8ac3388..2a5bc94b6463 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -79,7 +79,6 @@ issue-2190-2.rs
 issue-2238.rs
 issue-2304.rs
 issue-2330.rs
-issue-2375.rs
 issue-2478.rs
 issue-2479.rs
 issue-2723-1.rs
@@ -182,7 +181,6 @@ issue-2987.rs
 issue-3045-1.rs
 issue-3045-2.rs
 issue-3046.rs
-unknown-associated-item.rs
 issue-3030.rs
 issue-3035.rs
 issue-3139-1.rs


[gcc r15-8640] gccrs: derive(Clone): Add lang item typepaths failure testcases to nr2 exclude

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:adba3fff2d4e5538b2f924f11e947a6c13fcfaac

commit r15-8640-gadba3fff2d4e5538b2f924f11e947a6c13fcfaac
Author: Arthur Cohen 
Date:   Wed Jan 15 10:41:28 2025 +

gccrs: derive(Clone): Add lang item typepaths failure testcases to nr2 
exclude

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Add failing lang item typepaths tests.
* rust/execute/torture/derive_macro4.rs: Mark Clone as lang item.

Diff:
---
 gcc/testsuite/rust/compile/nr2/exclude  | 5 +
 gcc/testsuite/rust/execute/torture/derive_macro4.rs | 1 +
 2 files changed, 6 insertions(+)

diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 1a9c8e7113a3..60322f3276a9 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -146,4 +146,9 @@ cmp1.rs
 derive_clone_enum1.rs
 derive_clone_enum2.rs
 derive_clone_enum3.rs
+derive_macro4.rs
+derive_macro6.rs
+issue-2987.rs
+issue-3139-1.rs
+issue-3139-3.rs
 # please don't delete the trailing newline
diff --git a/gcc/testsuite/rust/execute/torture/derive_macro4.rs 
b/gcc/testsuite/rust/execute/torture/derive_macro4.rs
index c355ac7905f5..38c4808574a3 100644
--- a/gcc/testsuite/rust/execute/torture/derive_macro4.rs
+++ b/gcc/testsuite/rust/execute/torture/derive_macro4.rs
@@ -1,6 +1,7 @@
 #[lang = "sized"]
 pub trait Sized {}
 
+#[lang = "clone"]
 pub trait Clone {
 fn clone(&self) -> Self;
 }


[gcc r15-8609] gccrs: Add ForeverStackStore

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:469d668f6fac45dcd72182d1075285c761acac94

commit r15-8609-g469d668f6fac45dcd72182d1075285c761acac94
Author: Owen Avery 
Date:   Thu Nov 14 19:57:42 2024 -0500

gccrs: Add ForeverStackStore

ForeverStackStore is meant to partially unify the internal states of
per-namespace ForeverStack instances. This commit does not contain
modifications to ForeverStack which would allow it to rely on a
ForeverStackStore to store nodes, but a future commit should address
this.

gcc/rust/ChangeLog:

* Make-lang.in: Handle rust-forever-stack.cc.
* resolve/rust-forever-stack.h
(class ForeverStackStore): Add.
* resolve/rust-forever-stack.cc: New file, based on
rust-forever-stack.hxx.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/Make-lang.in  |   1 +
 gcc/rust/resolve/rust-forever-stack.cc | 318 +
 gcc/rust/resolve/rust-forever-stack.h  | 151 
 3 files changed, 470 insertions(+)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 8771cdf91e1e..b6f3a35e4e6f 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -146,6 +146,7 @@ GRS_OBJS = \
 rust/rust-ast-resolve-path.o \
 rust/rust-ast-resolve-stmt.o \
 rust/rust-ast-resolve-struct-expr-field.o \
+rust/rust-forever-stack.o \
 rust/rust-hir-type-check.o \
 rust/rust-privacy-check.o \
 rust/rust-privacy-ctx.o \
diff --git a/gcc/rust/resolve/rust-forever-stack.cc 
b/gcc/rust/resolve/rust-forever-stack.cc
new file mode 100644
index ..725ae0ea0188
--- /dev/null
+++ b/gcc/rust/resolve/rust-forever-stack.cc
@@ -0,0 +1,318 @@
+// Copyright (C) 2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3.  If not see
+// .
+
+#include "expected.h"
+#include "rust-ast.h"
+#include "rust-diagnostics.h"
+#include "rust-forever-stack.h"
+#include "rust-rib.h"
+#include "optional.h"
+
+namespace Rust {
+namespace Resolver2_0 {
+
+bool
+ForeverStackStore::Node::is_root () const
+{
+  return !parent.has_value ();
+}
+
+bool
+ForeverStackStore::Node::is_leaf () const
+{
+  return children.empty ();
+}
+
+NodeId
+ForeverStackStore::Node::get_id () const
+{
+  return id;
+}
+
+ForeverStackStore::Node &
+ForeverStackStore::Node::insert_child (NodeId id, tl::optional 
path,
+  Rib::Kind kind)
+{
+  auto res = children.insert ({Link (id, path), Node (kind, id, *this)});
+
+  rust_debug ("inserting link: Link(%d [%s]): existed? %s", id,
+ path.has_value () ? path.value ().as_string ().c_str ()
+   : "",
+ !res.second ? "yes" : "no");
+
+  // sanity check on rib kind
+  // pick the value rib, since all ribs should have the same kind anyways
+  rust_assert (res.second || res.first->second.value_rib.kind == kind);
+
+  // verify, if we're using an existing node, our paths don't contradict
+  if (!res.second && path.has_value ())
+{
+  auto other_path = res.first->first.path;
+  rust_assert (!other_path.has_value ()
+  || other_path.value ().as_string ()
+   == path.value ().as_string ());
+}
+
+  return res.first->second;
+}
+
+tl::optional
+ForeverStackStore::Node::get_child (const Identifier &path)
+{
+  for (auto &ent : children)
+{
+  if (ent.first.path.has_value ()
+ && ent.first.path->as_string () == path.as_string ())
+   return ent.second;
+}
+  return tl::nullopt;
+}
+
+tl::optional
+ForeverStackStore::Node::get_child (const Identifier &path) const
+{
+  for (auto &ent : children)
+{
+  if (ent.first.path.has_value ()
+ && ent.first.path->as_string () == path.as_string ())
+   return ent.second;
+}
+  return tl::nullopt;
+}
+
+tl::optional
+ForeverStackStore::Node::get_parent ()
+{
+  return parent;
+}
+
+tl::optional
+ForeverStackStore::Node::get_parent () const
+{
+  if (parent)
+return *parent;
+  return tl::nullopt;
+}
+
+tl::optional
+ForeverStackStore::Node::get_parent_path () const
+{
+  if (parent.has_value ())
+for (auto &ent : parent->children)
+  if (ent.first.id == id && ent.first.path.has_value ())
+   return ent.first.path.value ();
+  return tl::nullopt;
+}
+
+Rib &
+ForeverStackStore::Node::get_rib (Names

[gcc r15-8610] gccrs: testsuite: Fix missing handling of little endian.

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:ffecc9a97247b73de657a1fc0c81cf824bfd72c6

commit r15-8610-gffecc9a97247b73de657a1fc0c81cf824bfd72c6
Author: Arthur Cohen 
Date:   Thu Jan 18 17:24:01 2024 +0100

gccrs: testsuite: Fix missing handling of little endian.

Some failures occur in the testsuite because we
did not account for the little-endian case.

gcc/testsuite/ChangeLog:

* rust/compile/issue-1446.rs: Add swap_bytes function.
* rust/compile/iterators1.rs: Remove unused {to, from}_le functions.

Diff:
---
 gcc/testsuite/rust/compile/issue-1446.rs | 10 +-
 gcc/testsuite/rust/compile/iterators1.rs | 18 --
 2 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/gcc/testsuite/rust/compile/issue-1446.rs 
b/gcc/testsuite/rust/compile/issue-1446.rs
index 8bfa42b9dace..969ad380ee69 100644
--- a/gcc/testsuite/rust/compile/issue-1446.rs
+++ b/gcc/testsuite/rust/compile/issue-1446.rs
@@ -1,3 +1,11 @@
+// fake function
+pub fn swap_bytes(this: u32) -> u32 {
+(((this) & 0xff00) >> 24)
+| (((this) & 0x00ff) >> 8)
+| (((this) & 0xff00) << 8)
+| (((this) & 0x00ff) << 24)
+}
+
 pub fn to_le(this: u32) -> u32 {
 #[cfg(target_endian = "little")]
 {
@@ -5,6 +13,6 @@ pub fn to_le(this: u32) -> u32 {
 }
 #[cfg(not(target_endian = "little"))]
 {
-this.swap_bytes()
+swap_bytes(this)
 }
 }
diff --git a/gcc/testsuite/rust/compile/iterators1.rs 
b/gcc/testsuite/rust/compile/iterators1.rs
index 35fea5a04938..1141758b14a7 100644
--- a/gcc/testsuite/rust/compile/iterators1.rs
+++ b/gcc/testsuite/rust/compile/iterators1.rs
@@ -232,24 +232,6 @@ macro_rules! impl_uint {
 }
 }
 
-pub fn to_le(self) -> Self {
-#[cfg(target_endian = "little")]
-{
-self
-}
-}
-
-pub const fn from_le_bytes(bytes: [u8; 
mem::size_of::()]) -> Self {
-Self::from_le(Self::from_ne_bytes(bytes))
-}
-
-pub const fn from_le(x: Self) -> Self {
-#[cfg(target_endian = "little")]
-{
-x
-}
-}
-
 pub const fn from_ne_bytes(bytes: [u8; 
mem::size_of::()]) -> Self {
 unsafe { mem::transmute(bytes) }
 }


[gcc r14-11430] libstdc++: Correct statement about default -std option

2025-03-21 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:084dacc2054ae633f0fea13d72001d50e08719f7

commit r14-11430-g084dacc2054ae633f0fea13d72001d50e08719f7
Author: Jonathan Wakely 
Date:   Wed Mar 19 23:27:24 2025 +

libstdc++: Correct statement about default -std option

The default is -std=gnu++17 now, not -std=gnu++14.

libstdc++-v3/ChangeLog:

* doc/xml/manual/test.xml: Fix default for -std option.
* doc/html/manual/test.html: Regenerate.

(cherry picked from commit b93e60e7901526d7df2d8c0f5e0e46c57e8e3771)

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

diff --git a/libstdc++-v3/doc/html/manual/test.html 
b/libstdc++-v3/doc/html/manual/test.html
index 3657997fad46..b8a3b9545a7b 100644
--- a/libstdc++-v3/doc/html/manual/test.html
+++ b/libstdc++-v3/doc/html/manual/test.html
@@ -343,11 +343,11 @@ cat 27_io/objects/char/3_xin.in | 
a.out-O3 but 
with
   different -std options:
-make check 
'RUNTESTFLAGS=--target_board=unix/-O3\"{-std=gnu++98,-std=gnu++11,-std=gnu++14}\"'
+make check 
'RUNTESTFLAGS=--target_board=unix/-O3\"{-std=gnu++98,-std=gnu++11,-std=gnu++17}\"'
   N.B. that set of variations could also be written as
   unix/-O3\"{-std=gnu++98,-std=gnu++11,}\" so 
that
   the third variation would use the default for -std
-  (which is -std=gnu++14 as of GCC 6).
+  (which is -std=gnu++17 as of GCC 11).
 
   Since GCC 14, the libstdc++ testsuite has built-in support for running
   tests with more than one -std, similar to 
the G++ tests.
diff --git a/libstdc++-v3/doc/xml/manual/test.xml 
b/libstdc++-v3/doc/xml/manual/test.xml
index 40926946fe7a..eb340277def5 100644
--- a/libstdc++-v3/doc/xml/manual/test.xml
+++ b/libstdc++-v3/doc/xml/manual/test.xml
@@ -589,11 +589,11 @@ cat 27_io/objects/char/3_xin.in | a.out
   tests multiple times in different variations. For example, to run the
   entire testsuite three times using -O3 but with
   different -std options:
-make check 
'RUNTESTFLAGS=--target_board=unix/-O3\"{-std=gnu++98,-std=gnu++11,-std=gnu++14}\"'
+make check 
'RUNTESTFLAGS=--target_board=unix/-O3\"{-std=gnu++98,-std=gnu++11,-std=gnu++17}\"'
   N.B. that set of variations could also be written as
   unix/-O3\"{-std=gnu++98,-std=gnu++11,}\" so that
   the third variation would use the default for -std
-  (which is -std=gnu++14 as of GCC 6).
+  (which is -std=gnu++17 as of GCC 11).
 
 
 


[gcc r14-11429] libstdc++: Fix comment typo

2025-03-21 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:e7a0f04ddb708320403c7477679fbeae3638820d

commit r14-11429-ge7a0f04ddb708320403c7477679fbeae3638820d
Author: Jakub Jelinek 
Date:   Thu Mar 20 10:36:29 2025 +0100

libstdc++: Fix comment typo

Another IEE typo.

2025-03-20  Jakub Jelinek  

* testsuite/18_support/numeric_limits/traps.cc (main): Fix comment
typo.

(cherry picked from commit d458020e19b686e0d46320e7d26fa876c19965a0)

Diff:
---
 libstdc++-v3/testsuite/18_support/numeric_limits/traps.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/18_support/numeric_limits/traps.cc 
b/libstdc++-v3/testsuite/18_support/numeric_limits/traps.cc
index a4b30fd01c3f..adb2dba9f8fc 100644
--- a/libstdc++-v3/testsuite/18_support/numeric_limits/traps.cc
+++ b/libstdc++-v3/testsuite/18_support/numeric_limits/traps.cc
@@ -48,7 +48,7 @@ int main()
 For floating points, trapping is a different, more complicated
 story.  If is_iecxxx is true, then division by zero would not trap
 (infinity).  If is_iecxxx is false, we don't know (VAX may trap for
-0/0 -- I have to check).  For most cases (i.e. IEE-754), trapping
+0/0 -- I have to check).  For most cases (i.e. IEEE-754), trapping
 for floating points have to do with whether there is a support for
 signaling NaN.
 - Gaby.


[gcc r15-8482] make sources coretypes.h and tree.h clean

2025-03-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:a62893d71c5f48fd7780957e1ad1a4f38f351728

commit r15-8482-ga62893d71c5f48fd7780957e1ad1a4f38f351728
Author: Richard Biener 
Date:   Wed Mar 19 15:09:03 2025 +0100

make sources coretypes.h and tree.h clean

The following removes HOWEVER_GCC_DEFINES_TREE and the alternate
definition of tree from symbols.h and instead ensures that both
coretypes.h and tree.h are included where required.  This required
putting GCCs own 'NONE' in a scoped enum (see separate patch) and
renaming the cobol use of UNSIGNED, SIGNED and BLOCK which conflict
with enums from tree.h.

There's a few things in conflict with options.h defines, notably
cobol_dialect and cobol_exceptions but also yy_flex_debug (wherever
that comes from).  I've chosen to simply #undef those where
appropriate.  I've refrained from putting the coretypes.h and
tree.h includes in cobol-system.h since not all files require this.

This helps in making use of real.h instead of using _Float128.

PR cobol/119241
gcc/cobol/
* symbols.h: Do not typedef tree.
* cdf.y: Include coretypes.h and tree.h.
* symbols.cc: Likewise.
* symfind.cc: Likewise.
* util.cc: Likewise.
* parse.y: Include coretypes.h and tree.h where appropriate.
Rename BLOCK to COB_BLOCK, SIGNED to COB_SIGNED, UNSIGNED
to COB_UNSIGNED.
* scan.l: Likewise.
* token_names.h: Likewise.
* cobol1.cc: Do not define HOWEVER_GCC_DEFINES_TREE.
* except.cc: Likewise.
* genapi.cc: Likewise.
* gengen.cc: Likewise.
* genmath.cc: Likewise.
* genutil.cc: Likewise.
* structs.cc: Likewise.

Diff:
---
 gcc/cobol/cdf.y |  3 +++
 gcc/cobol/cobol1.cc |  1 -
 gcc/cobol/except.cc |  1 -
 gcc/cobol/genapi.cc |  2 --
 gcc/cobol/gengen.cc |  1 -
 gcc/cobol/genmath.cc|  1 -
 gcc/cobol/genutil.cc|  1 -
 gcc/cobol/parse.y   | 24 +++-
 gcc/cobol/scan.l| 13 -
 gcc/cobol/structs.cc|  1 -
 gcc/cobol/symbols.cc|  4 
 gcc/cobol/symbols.h |  5 -
 gcc/cobol/symfind.cc|  3 +++
 gcc/cobol/token_names.h |  6 +++---
 gcc/cobol/util.cc   |  5 -
 15 files changed, 40 insertions(+), 31 deletions(-)

diff --git a/gcc/cobol/cdf.y b/gcc/cobol/cdf.y
index 12d11e78116e..c44ee5ee0723 100644
--- a/gcc/cobol/cdf.y
+++ b/gcc/cobol/cdf.y
@@ -30,6 +30,9 @@
 %{
 
 #include "cobol-system.h"
+#include "coretypes.h"
+#include "tree.h"
+#undef yy_flex_debug
 #include "../../libgcobol/ec.h"
 #include "../../libgcobol/common-defs.h"
 #include "util.h"
diff --git a/gcc/cobol/cobol1.cc b/gcc/cobol/cobol1.cc
index 08af367e2264..0d07c460d416 100644
--- a/gcc/cobol/cobol1.cc
+++ b/gcc/cobol/cobol1.cc
@@ -29,7 +29,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "langhooks-def.h"
 #include "target.h"
 #include "stringpool.h"
-#define HOWEVER_GCC_DEFINES_TREE 1
 #include "../../libgcobol/ec.h"
 #include "../../libgcobol/common-defs.h"
 #include "util.h"
diff --git a/gcc/cobol/except.cc b/gcc/cobol/except.cc
index 5374201b4c82..ba49f78d897f 100644
--- a/gcc/cobol/except.cc
+++ b/gcc/cobol/except.cc
@@ -32,7 +32,6 @@
 #include "cobol-system.h"
 #include "coretypes.h"
 #include "tree.h"
-#define HOWEVER_GCC_DEFINES_TREE 1
 #include "../../libgcobol/ec.h"
 #include "../../libgcobol/common-defs.h"
 #include "util.h"
diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc
index a4abbd13ab6a..8f4f9b213705 100644
--- a/gcc/cobol/genapi.cc
+++ b/gcc/cobol/genapi.cc
@@ -35,8 +35,6 @@
 #include "stringpool.h"
 #include "diagnostic-core.h"
 
-#define HOWEVER_GCC_DEFINES_TREE 1
-
 #include "../../libgcobol/ec.h"
 #include "../../libgcobol/common-defs.h"
 #include "util.h"
diff --git a/gcc/cobol/gengen.cc b/gcc/cobol/gengen.cc
index 2796b7facdbd..ffb64c8993d9 100644
--- a/gcc/cobol/gengen.cc
+++ b/gcc/cobol/gengen.cc
@@ -95,7 +95,6 @@
 #include "toplev.h"
 #include "function.h"
 #include "fold-const.h"
-#define HOWEVER_GCC_DEFINES_TREE 1
 #include "../../libgcobol/ec.h"
 #include "../../libgcobol/common-defs.h"
 #include "util.h"
diff --git a/gcc/cobol/genmath.cc b/gcc/cobol/genmath.cc
index 42f01cda6eec..56254e88cc6c 100644
--- a/gcc/cobol/genmath.cc
+++ b/gcc/cobol/genmath.cc
@@ -30,7 +30,6 @@
 #include "cobol-system.h"
 #include "coretypes.h"
 #include "tree.h"
-#define HOWEVER_GCC_DEFINES_TREE 1
 #include "../../libgcobol/ec.h"
 #include "../../libgcobol/common-defs.h"
 #include "util.h"
diff --git a/gcc/cobol/genutil.cc b/gcc/cobol/genutil.cc
index c0e6631bb760..f8bf7bc34b76 100644
--- a/gcc/cobol/genutil.cc
+++ b/gcc/cobol/genutil.cc
@@ -30,7 +30,6 @@
 #include "cobol-system.h"
 #include "coretypes.h"
 #include "tree.h"
-#define HOWEVER_GCC_DEFINES_TREE 1
 #include "../../libgcobol/ec.h"
 #include "../../libgcobol/common-defs.h"
 #include "util.h"
diff --g

[gcc r15-8485] libstdc++: Add views::cache_latest and views::to_input to std module

2025-03-21 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:ced873be918186a98d69dcdd89bb0240973b0f1a

commit r15-8485-gced873be918186a98d69dcdd89bb0240973b0f1a
Author: Jonathan Wakely 
Date:   Thu Mar 20 18:48:20 2025 +

libstdc++: Add views::cache_latest and views::to_input to std module

Also export the tuple-like helpers from , and the
std::from_range_t and std::from_range tag.

libstdc++-v3/ChangeLog:

* src/c++23/std.cc.in (tuple_element, tuple_element_t)
(tuple_size, tuple_size_v, get): Export.
(ranges::cache_latest_view, views::cache_latest): Export.
(ranges::to_input_view, views::to_input): Export.
(from_range_t, from_range): Export.

Reviewed-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/src/c++23/std.cc.in | 23 ---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/src/c++23/std.cc.in b/libstdc++-v3/src/c++23/std.cc.in
index c0b7e1dc7271..12253b95c5a5 100644
--- a/libstdc++-v3/src/c++23/std.cc.in
+++ b/libstdc++-v3/src/c++23/std.cc.in
@@ -924,6 +924,13 @@ export namespace std
   using std::sqrt;
   using std::tan;
   using std::tanh;
+#if __cpp_lib_tuple_like >= 202311L
+  using std::tuple_element;
+  using std::tuple_element_t;
+  using std::tuple_size;
+  using std::tuple_size_v;
+  using std::get;
+#endif
 }
 export namespace std::inline literals::inline complex_literals
 {
@@ -2383,14 +2390,24 @@ export namespace std
 using ranges::enumerate_view;
 namespace views { using views::enumerate; }
 #endif
-#if __cpp_lib_ranges_to_container // C++ >= 23
-using ranges::to;
-#endif // __cpp_lib_ranges_to_container
 #if __cpp_lib_ranges_concat // C++ >= C++26
 using ranges::concat_view;
 namespace views { using views::concat; }
+#endif
+#if __cpp_lib_ranges_cache_latest // C++ >= C++26
+using ranges::cache_latest_view;
+namespace views { using views::cache_latest; }
+#endif
+#if __glibcxx_ranges_to_input // C++ >= 26
+using ranges::to_input_view;
+namespace views { using views::to_input; }
 #endif
   }
+#if __glibcxx_ranges_to_container // C++ >= 23
+  namespace ranges { using ranges::to; }
+  using std::from_range_t;
+  using std::from_range;
+#endif
 }
 
 // 


[gcc r15-8510] gccrs: Remove usage of Resolver::get_builtin_types

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:447d38419914eb287ce9413d90fe17f80ece3df2

commit r15-8510-g447d38419914eb287ce9413d90fe17f80ece3df2
Author: Owen Avery 
Date:   Fri Nov 1 12:58:44 2024 -0400

gccrs: Remove usage of Resolver::get_builtin_types

gcc/rust/ChangeLog:

* backend/rust-compile-context.cc
(Context::setup_builtins): Use TypeCheckContext::get_builtins
instead of Resolver::get_builtin_types,
TypeCheckContext::lookup_type_by_node_id, and
TypeCheckContext::lookup_type.
* typecheck/rust-hir-type-check.h
(TypeCheckContext::get_builtins): Add.
* typecheck/rust-typecheck-context.cc
(TypeCheckContext::get_builtins): Add.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/backend/rust-compile-context.cc | 15 ++-
 gcc/rust/typecheck/rust-hir-type-check.h |  1 +
 gcc/rust/typecheck/rust-typecheck-context.cc |  6 ++
 3 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-context.cc 
b/gcc/rust/backend/rust-compile-context.cc
index c80f95649f12..86f089440ac0 100644
--- a/gcc/rust/backend/rust-compile-context.cc
+++ b/gcc/rust/backend/rust-compile-context.cc
@@ -33,19 +33,8 @@ Context::Context ()
 void
 Context::setup_builtins ()
 {
-  auto builtins = resolver->get_builtin_types ();
-  for (auto it = builtins.begin (); it != builtins.end (); it++)
-{
-  HirId ref;
-  bool ok = tyctx->lookup_type_by_node_id ((*it)->get_node_id (), &ref);
-  rust_assert (ok);
-
-  TyTy::BaseType *lookup;
-  ok = tyctx->lookup_type (ref, &lookup);
-  rust_assert (ok);
-
-  TyTyResolveCompile::compile (this, lookup);
-}
+  for (auto &builtin : tyctx->get_builtins ())
+TyTyResolveCompile::compile (this, builtin.get ());
 }
 
 hashval_t
diff --git a/gcc/rust/typecheck/rust-hir-type-check.h 
b/gcc/rust/typecheck/rust-hir-type-check.h
index fa49e0689f30..5b1fe220890b 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.h
+++ b/gcc/rust/typecheck/rust-hir-type-check.h
@@ -135,6 +135,7 @@ public:
   bool lookup_builtin (NodeId id, TyTy::BaseType **type);
   bool lookup_builtin (std::string name, TyTy::BaseType **type);
   void insert_builtin (HirId id, NodeId ref, TyTy::BaseType *type);
+  const std::vector> &get_builtins () const;
 
   void insert_type (const Analysis::NodeMapping &mappings,
TyTy::BaseType *type);
diff --git a/gcc/rust/typecheck/rust-typecheck-context.cc 
b/gcc/rust/typecheck/rust-typecheck-context.cc
index 8f7a8a4f48f8..0fb8224861ea 100644
--- a/gcc/rust/typecheck/rust-typecheck-context.cc
+++ b/gcc/rust/typecheck/rust-typecheck-context.cc
@@ -73,6 +73,12 @@ TypeCheckContext::insert_builtin (HirId id, NodeId ref, 
TyTy::BaseType *type)
   builtins.push_back (std::unique_ptr (type));
 }
 
+const std::vector> &
+TypeCheckContext::get_builtins () const
+{
+  return builtins;
+}
+
 void
 TypeCheckContext::insert_type (const Analysis::NodeMapping &mappings,
   TyTy::BaseType *type)


[gcc r15-8516] gccrs: fix ICE for placeholder which is not setup

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:87e4dcd782013a10de2a1cac8ff0364e5ff06bda

commit r15-8516-g87e4dcd782013a10de2a1cac8ff0364e5ff06bda
Author: Philip Herron 
Date:   Tue Nov 5 17:35:37 2024 +

gccrs: fix ICE for placeholder which is not setup

We can have a case where the placeholder is not configred and the
can_resolve check is not detecting this case which can lead to ICE.

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (PlaceholderType::can_resolve): check for 
empty mappings

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/typecheck/rust-tyty.cc | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 1812c618dcb4..068e39021183 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -3543,7 +3543,17 @@ bool
 PlaceholderType::can_resolve () const
 {
   auto context = Resolver::TypeCheckContext::get ();
-  return context->lookup_associated_type_mapping (get_ty_ref (), nullptr);
+
+  BaseType *lookup = nullptr;
+  HirId mapping;
+
+  if (!context->lookup_associated_type_mapping (get_ty_ref (), &mapping))
+return false;
+
+  if (!context->lookup_type (mapping, &lookup))
+return false;
+
+  return lookup != nullptr;
 }
 
 BaseType *


[gcc r15-8556] gccrs: add checks for division by zero and left shift overflow

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:5ac2f2864ca65d691ab461f1a176e80028aaee76

commit r15-8556-g5ac2f2864ca65d691ab461f1a176e80028aaee76
Author: Philip Herron 
Date:   Mon Dec 2 13:54:29 2024 +

gccrs: add checks for division by zero and left shift overflow

These are ported from the c-family code c-warn.cc and c/c-typchk.cc

Fixes Rust-GCC#2394

gcc/rust/ChangeLog:

* backend/rust-constexpr.cc (eval_store_expression): check for null
(eval_call_expression): remove bad warning
* rust-gcc.cc (arithmetic_or_logical_expression): add warnings

gcc/testsuite/ChangeLog:

* rust/compile/issue-2394.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/backend/rust-constexpr.cc   |  8 +---
 gcc/rust/rust-gcc.cc | 11 +++
 gcc/testsuite/rust/compile/issue-2394.rs | 14 ++
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/backend/rust-constexpr.cc 
b/gcc/rust/backend/rust-constexpr.cc
index bfd7d959aa88..2f2bbbd921d1 100644
--- a/gcc/rust/backend/rust-constexpr.cc
+++ b/gcc/rust/backend/rust-constexpr.cc
@@ -2929,8 +2929,13 @@ eval_store_expression (const constexpr_ctx *ctx, tree t, 
bool lval,
}
 }
 
+  if (*non_constant_p)
+return t;
+
   /* Don't share a CONSTRUCTOR that might be changed later.  */
   init = unshare_constructor (init);
+  if (init == NULL_TREE)
+return t;
 
   if (*valp && TREE_CODE (*valp) == CONSTRUCTOR
   && TREE_CODE (init) == CONSTRUCTOR)
@@ -3585,9 +3590,6 @@ eval_call_expression (const constexpr_ctx *ctx, tree t, 
bool lval,
  result = *ctx->global->values.get (res);
  if (result == NULL_TREE && !*non_constant_p)
{
- if (!ctx->quiet)
-   error ("% call flows off the end "
-  "of the function");
  *non_constant_p = true;
}
}
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 59983ede97d7..7da5e2c56377 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -1106,6 +1106,17 @@ arithmetic_or_logical_expression 
(ArithmeticOrLogicalOperator op, tree left,
   if (floating_point && extended_type != NULL_TREE)
 ret = convert (original_type, ret);
 
+  if (op == ArithmeticOrLogicalOperator::DIVIDE
+  && (integer_zerop (right) || fixed_zerop (right)))
+{
+  rust_error_at (location, "division by zero");
+}
+  else if (op == ArithmeticOrLogicalOperator::LEFT_SHIFT
+  && (compare_tree_int (right, TYPE_PRECISION (TREE_TYPE (ret))) >= 0))
+{
+  rust_error_at (location, "left shift count >= width of type");
+}
+
   return ret;
 }
 
diff --git a/gcc/testsuite/rust/compile/issue-2394.rs 
b/gcc/testsuite/rust/compile/issue-2394.rs
new file mode 100644
index ..92f7afc6507a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2394.rs
@@ -0,0 +1,14 @@
+const A: i32 = (1 / 0);
+// { dg-error "division by zero" "" { target *-*-* } .-1 }
+
+fn main() {
+let a = 1 / 0;
+// { dg-error "division by zero" "" { target *-*-* } .-1 }
+
+let b = 3;
+let c = b / 0;
+// { dg-error "division by zero" "" { target *-*-* } .-1 }
+
+let a = 1 << 500;
+// { dg-error "left shift count >= width of type" "" { target *-*-* } .-1 }
+}


[gcc r15-8538] gccrs: Handle type path segments during late resolution 2.0

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:6d4154ed96f4fe9c9218a4be6587991577e6b314

commit r15-8538-g6d4154ed96f4fe9c9218a4be6587991577e6b314
Author: Owen Avery 
Date:   Tue Nov 19 16:09:01 2024 -0500

gccrs: Handle type path segments during late resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Call DefaultResolver::visit when visiting
TypePath.

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 | 2 ++
 gcc/testsuite/rust/compile/nr2/exclude  | 2 --
 2 files changed, 2 insertions(+), 2 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 850f96aef896..3af8496288dd 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -263,6 +263,8 @@ Late::visit (AST::TypePath &type)
   Definition (resolved->get_node_id ()));
   else
 rust_unreachable ();
+
+  DefaultResolver::visit (type);
 }
 
 void
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 2e956960dad6..3dbebc703c4f 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -42,7 +42,6 @@ generics3.rs
 generics4.rs
 generics5.rs
 generics6.rs
-generics7.rs
 generics8.rs
 generics9.rs
 if_let_expr.rs
@@ -83,7 +82,6 @@ issue-2165.rs
 issue-2166.rs
 issue-2190-1.rs
 issue-2190-2.rs
-issue-2195.rs
 issue-2238.rs
 issue-2304.rs
 issue-2330.rs


[gcc r15-8554] gccrs: Remove bad assertion in name resolution

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:02bdd68e7daf59a0081ad9b05b5a17624d620dc3

commit r15-8554-g02bdd68e7daf59a0081ad9b05b5a17624d620dc3
Author: Philip Herron 
Date:   Mon Dec 2 14:10:11 2024 +

gccrs: Remove bad assertion in name resolution

This was a handy debug assertion but only works for valid rust code. This
needs to handle the case where the type is not resolved which is a valid
case.

Fixes Rust-GCC#2423

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): remove 
assertions

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 can't handle this
* rust/compile/issue-2423.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/resolve/rust-ast-resolve-item.cc | 30 --
 gcc/testsuite/rust/compile/issue-2423.rs  | 14 ++
 gcc/testsuite/rust/compile/nr2/exclude|  1 +
 3 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc 
b/gcc/rust/resolve/rust-ast-resolve-item.cc
index 2861fb94d9fd..245523ae5aa8 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-item.cc
@@ -582,7 +582,14 @@ ResolveItem::visit (AST::InherentImpl &impl_block)
   // Setup paths
   CanonicalPath self_cpath = CanonicalPath::create_empty ();
   bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_type (), 
self_cpath);
-  rust_assert (ok);
+  if (!ok)
+{
+  resolver->get_name_scope ().pop ();
+  resolver->get_type_scope ().pop ();
+  resolver->get_label_scope ().pop ();
+  return;
+}
+
   rust_debug ("AST::InherentImpl resolve Self: {%s}",
  self_cpath.get ().c_str ());
 
@@ -671,12 +678,17 @@ ResolveItem::visit (AST::TraitImpl &impl_block)
   return;
 }
 
-  bool ok;
   // setup paths
   CanonicalPath canonical_trait_type = CanonicalPath::create_empty ();
-  ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path (),
-  canonical_trait_type);
-  rust_assert (ok);
+  bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path (),
+   canonical_trait_type);
+  if (!ok)
+{
+  resolver->get_name_scope ().pop ();
+  resolver->get_type_scope ().pop ();
+  resolver->get_label_scope ().pop ();
+  return;
+}
 
   rust_debug ("AST::TraitImpl resolve trait type: {%s}",
  canonical_trait_type.get ().c_str ());
@@ -684,7 +696,13 @@ ResolveItem::visit (AST::TraitImpl &impl_block)
   CanonicalPath canonical_impl_type = CanonicalPath::create_empty ();
   ok = ResolveTypeToCanonicalPath::go (impl_block.get_type (),
   canonical_impl_type);
-  rust_assert (ok);
+  if (!ok)
+{
+  resolver->get_name_scope ().pop ();
+  resolver->get_type_scope ().pop ();
+  resolver->get_label_scope ().pop ();
+  return;
+}
 
   rust_debug ("AST::TraitImpl resolve self: {%s}",
  canonical_impl_type.get ().c_str ());
diff --git a/gcc/testsuite/rust/compile/issue-2423.rs 
b/gcc/testsuite/rust/compile/issue-2423.rs
new file mode 100644
index ..ae7897c11709
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2423.rs
@@ -0,0 +1,14 @@
+impl NonExistant {
+// { dg-error "failed to resolve" "" { target *-*-* } .-1 }
+fn test() {}
+}
+
+impl NotFound for NonExistant {
+// { dg-error "failed to resolve" "" { target *-*-* } .-1 }
+fn test() {}
+}
+
+trait A {}
+
+impl A for NotFound {}
+// { dg-error "failed to resolve" "" { target *-*-* } .-1 }
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 00ac704fec2f..bf4506f25d25 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -206,4 +206,5 @@ issue-1773.rs
 issue-2905-1.rs
 issue-2905-2.rs
 issue-2907.rs
+issue-2423.rs
 # please don't delete the trailing newline


[gcc r15-8539] gccrs: Use nr2.0 in typechecker

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:54cec5aa5abda724740136024dad184885180d71

commit r15-8539-g54cec5aa5abda724740136024dad184885180d71
Author: Owen Avery 
Date:   Tue Nov 19 15:10:09 2024 -0500

gccrs: Use nr2.0 in typechecker

I probably missed a few spots, but this should cover most of the type
checker.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc: Add includes.
(TypeCheckExpr::visit): Use name resolver 2.0.
(TypeCheckExpr::resolve_operator_overload): Likewise.
(TypeCheckExpr::resolve_fn_trait_call): Likewise.
* typecheck/rust-hir-type-check-path.cc
(TypeCheckExpr::visit): Likewise.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-type.cc
(TypeCheckType::resolve_segments): Likewise.
(ResolveWhereClauseItem::visit): Likewise.
(TypeCheckType::visit): Avoid usage of
Resolver::get_unit_type_node_id when handling TupleType, use
name resolver 2.0 when handling QualifiedPathInType.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-expr.cc |  45 -
 gcc/rust/typecheck/rust-hir-type-check-path.cc |  27 +-
 gcc/rust/typecheck/rust-hir-type-check-type.cc | 122 ++---
 gcc/testsuite/rust/compile/nr2/exclude |   4 -
 4 files changed, 155 insertions(+), 43 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc 
b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index d9f0361389f6..03922bb554ce 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -27,6 +27,10 @@
 #include "rust-hir-type-check-stmt.h"
 #include "rust-hir-type-check-item.h"
 #include "rust-type-util.h"
+#include "rust-immutable-name-resolution-context.h"
+
+// for flag_name_resolution_2_0
+#include "options.h"
 
 namespace Rust {
 namespace Resolver {
@@ -1238,8 +1242,17 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
   // store the expected fntype
   context->insert_type (expr.get_method_name ().get_mappings (), lookup);
 
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx = const_cast (
+   Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+
+  nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid 
()),
+   Resolver2_0::Definition (resolved_node_id));
+}
   // set up the resolved name on the path
-  if (resolver->get_name_scope ().decl_was_declared_here (resolved_node_id))
+  else if (resolver->get_name_scope ().decl_was_declared_here (
+resolved_node_id))
 {
   resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
  resolved_node_id);
@@ -1821,8 +1834,19 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind 
lang_item_type,
   context->insert_operator_overload (expr.get_mappings ().get_hirid (), type);
 
   // set up the resolved name on the path
-  resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
- resolved_node_id);
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx = const_cast (
+   Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+
+  nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid 
()),
+   Resolver2_0::Definition (resolved_node_id));
+}
+  else
+{
+  resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
+ resolved_node_id);
+}
 
   // return the result of the function back
   infered = function_ret_tyty;
@@ -1991,8 +2015,19 @@ TypeCheckExpr::resolve_fn_trait_call (HIR::CallExpr 
&expr,
   context->insert_operator_overload (expr.get_mappings ().get_hirid (), fn);
 
   // set up the resolved name on the path
-  resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
- resolved_node_id);
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx = const_cast (
+   Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+
+  nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid 
()),
+   Resolver2_0::Definition (resolved_node_id));
+}
+  else
+{
+  resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
+ resolved_node_id);
+}
 
   // return the result of the function back
   *result = function_ret_tyty;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc 
b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index cc79e4d49956..cd0e941edd6d 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -153,8 +153,20 @@ TypeCheckExpr::

[gcc r15-8564] gccrs: ast: Add LangItemPath class

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:c482c358e3a724c8e258a3fc58230b931dd64747

commit r15-8564-gc482c358e3a724c8e258a3fc58230b931dd64747
Author: Arthur Cohen 
Date:   Wed Dec 4 15:09:58 2024 +0100

gccrs: ast: Add LangItemPath class

This commit adds a new kind of Path, changes the base Path class and turns 
TypePath
into a child of the base Path class.

gcc/rust/ChangeLog:

* ast/rust-path.h (class LangItemPath): New.
(class TypePath): Adapt to accomodate LangItemPath.
* ast/rust-ast.cc (TraitImpl::as_string): Use new checks for lang 
items.
(QualifiedPathType::as_string): Likewise.
(FormatArgs::set_outer_attrs): Likewise.
* ast/rust-item.h (class TraitImpl): Likewise.

Diff:
---
 gcc/rust/ast/rust-ast.cc |  4 +--
 gcc/rust/ast/rust-item.h | 28 +++
 gcc/rust/ast/rust-path.h | 73 +++-
 3 files changed, 71 insertions(+), 34 deletions(-)

diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 1d52352daaa9..f1298d0f3e95 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -1299,7 +1299,7 @@ TraitImpl::as_string () const
   else
 str += "false";
 
-  str += "\n TypePath (to trait): " + trait_path.as_string ();
+  str += "\n TypePath (to trait): " + trait_path->as_string ();
 
   str += "\n Type (struct to impl on): " + trait_type->as_string ();
 
@@ -1561,7 +1561,7 @@ QualifiedPathType::as_string () const
   str += type_to_invoke_on->as_string ();
 
   if (has_as_clause ())
-str += " as " + trait_path.as_string ();
+str += " as " + trait_path->as_string ();
 
   return str + ">";
 }
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 6611707a9a67..a6276a72d8df 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -3172,7 +3172,7 @@ class TraitImpl : public Impl
 {
   bool has_unsafe;
   bool has_exclam;
-  TypePath trait_path;
+  std::unique_ptr trait_path;
 
   // bool has_impl_items;
   std::vector> impl_items;
@@ -3184,7 +3184,7 @@ public:
   bool has_impl_items () const { return !impl_items.empty (); }
 
   // Mega-constructor
-  TraitImpl (TypePath trait_path, bool is_unsafe, bool has_exclam,
+  TraitImpl (std::unique_ptr trait_path, bool is_unsafe, bool has_exclam,
 std::vector> impl_items,
 std::vector> generic_params,
 std::unique_ptr trait_type, WhereClause where_clause,
@@ -3197,10 +3197,26 @@ public:
   trait_path (std::move (trait_path)), impl_items (std::move (impl_items))
   {}
 
+  // Helper constructor with a typepath
+  TraitImpl (TypePath trait_path, bool is_unsafe, bool has_exclam,
+std::vector> impl_items,
+std::vector> generic_params,
+std::unique_ptr trait_type, WhereClause where_clause,
+Visibility vis, std::vector inner_attrs,
+std::vector outer_attrs, location_t locus)
+: Impl (std::move (generic_params), std::move (trait_type),
+   std::move (where_clause), std::move (vis), std::move (inner_attrs),
+   std::move (outer_attrs), locus),
+  has_unsafe (is_unsafe), has_exclam (has_exclam),
+  trait_path (std::unique_ptr (new TypePath (trait_path))),
+  impl_items (std::move (impl_items))
+  {}
+
   // Copy constructor with vector clone
   TraitImpl (TraitImpl const &other)
 : Impl (other), has_unsafe (other.has_unsafe),
-  has_exclam (other.has_exclam), trait_path (other.trait_path)
+  has_exclam (other.has_exclam),
+  trait_path (other.trait_path->clone_path ())
   {
 impl_items.reserve (other.impl_items.size ());
 for (const auto &e : other.impl_items)
@@ -3211,7 +3227,7 @@ public:
   TraitImpl &operator= (TraitImpl const &other)
   {
 Impl::operator= (other);
-trait_path = other.trait_path;
+trait_path = other.trait_path->clone_path ();
 has_unsafe = other.has_unsafe;
 has_exclam = other.has_exclam;
 
@@ -3242,10 +3258,10 @@ public:
   }
 
   // TODO: is this better? Or is a "vis_block" better?
-  TypePath &get_trait_path ()
+  Path &get_trait_path ()
   {
 // TODO: assert that trait path is not empty?
-return trait_path;
+return *trait_path;
   }
 
 protected:
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index 2cad39554946..bece60f95edd 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -589,6 +589,7 @@ public:
   {
 LangItem,
 Regular,
+Type,
   };
 
   virtual Kind get_path_kind () const = 0;
@@ -598,8 +599,8 @@ public:
 return Pattern::Kind::Path;
   }
 
-  location_t get_locus () const override final { return locus; }
-  NodeId get_node_id () const override final { return node_id; }
+  location_t get_locus () const override { return locus; }
+  NodeId get_node_id () const override { return node_id; }
 
   std::unique_ptr clone_path ()
   {
@@ -661,11 +662,12 @@ public:
 class LangItemPath : public Path
 {
   NodeId 

[gcc r15-8553] gccrs: ast: Use StackedContexts class in ContextualASTVisitor

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:a6ad5cdc87c9c7f023351d1c3fa0ac12198928b2

commit r15-8553-ga6ad5cdc87c9c7f023351d1c3fa0ac12198928b2
Author: Arthur Cohen 
Date:   Tue Nov 26 16:39:04 2024 +

gccrs: ast: Use StackedContexts class in ContextualASTVisitor

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.h: Replace context with StackedContexts.
* ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): Use new 
APIs.
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): 
Likewise.

Diff:
---
 gcc/rust/ast/rust-ast-visitor.cc  | 16 
 gcc/rust/ast/rust-ast-visitor.h   | 10 --
 gcc/rust/checks/errors/rust-ast-validation.cc | 20 
 3 files changed, 20 insertions(+), 26 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index 8f53e528131a..a390aa20bcb9 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -1453,33 +1453,33 @@ DefaultASTVisitor::visit (AST::VariadicParam ¶m)
 void
 ContextualASTVisitor::visit (AST::Crate &crate)
 {
-  push_context (Context::CRATE);
+  ctx.enter (Kind::CRATE);
   DefaultASTVisitor::visit (crate);
-  pop_context ();
+  ctx.exit ();
 }
 
 void
 ContextualASTVisitor::visit (AST::InherentImpl &impl)
 {
-  push_context (Context::INHERENT_IMPL);
+  ctx.enter (Kind::INHERENT_IMPL);
   DefaultASTVisitor::visit (impl);
-  pop_context ();
+  ctx.exit ();
 }
 
 void
 ContextualASTVisitor::visit (AST::TraitImpl &impl)
 {
-  push_context (Context::TRAIT_IMPL);
+  ctx.enter (Kind::TRAIT_IMPL);
   DefaultASTVisitor::visit (impl);
-  pop_context ();
+  ctx.exit ();
 }
 
 void
 ContextualASTVisitor::visit (AST::Trait &trait)
 {
-  push_context (Context::TRAIT);
+  ctx.enter (Kind::TRAIT);
   DefaultASTVisitor::visit (trait);
-  pop_context ();
+  ctx.exit ();
 }
 
 } // namespace AST
diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index 50b93016d62a..7e3423cd4930 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -26,6 +26,7 @@
 #include "rust-item.h"
 #include "rust-path.h"
 #include "rust-system.h"
+#include "rust-stacked-contexts.h"
 
 namespace Rust {
 namespace AST {
@@ -452,7 +453,7 @@ public:
 class ContextualASTVisitor : public DefaultASTVisitor
 {
 protected:
-  enum class Context
+  enum class Kind
   {
 FUNCTION,
 INHERENT_IMPL,
@@ -461,6 +462,7 @@ protected:
 MODULE,
 CRATE,
   };
+
   using DefaultASTVisitor::visit;
 
   virtual void visit (AST::Crate &crate) override;
@@ -476,11 +478,7 @@ protected:
 DefaultASTVisitor::visit (item);
   }
 
-  std::vector context;
-
-  void push_context (Context ctx) { context.push_back (ctx); }
-
-  void pop_context () { context.pop_back (); }
+  StackedContexts ctx;
 };
 
 } // namespace AST
diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc 
b/gcc/rust/checks/errors/rust-ast-validation.cc
index 7938286ffb58..59b28057bab5 100644
--- a/gcc/rust/checks/errors/rust-ast-validation.cc
+++ b/gcc/rust/checks/errors/rust-ast-validation.cc
@@ -56,7 +56,7 @@ ASTValidation::visit (AST::LoopLabel &label)
 void
 ASTValidation::visit (AST::ConstantItem &const_item)
 {
-  if (!const_item.has_expr () && context.back () != Context::TRAIT_IMPL)
+  if (!const_item.has_expr () && ctx.peek () != Kind::TRAIT_IMPL)
 {
   rust_error_at (const_item.get_locus (),
 "associated constant in % without body");
@@ -82,23 +82,19 @@ ASTValidation::visit (AST::Function &function)
   "functions cannot be both % and %");
 
   if (qualifiers.is_const ()
-  && (context.back () == Context::TRAIT_IMPL
- || context.back () == Context::TRAIT))
+  && (ctx.peek () == Kind::TRAIT_IMPL || ctx.peek () == Kind::TRAIT))
 rust_error_at (function.get_locus (), ErrorCode::E0379,
   "functions in traits cannot be declared %");
 
   // may change soon
   if (qualifiers.is_async ()
-  && (context.back () == Context::TRAIT_IMPL
- || context.back () == Context::TRAIT))
+  && (ctx.peek () == Kind::TRAIT_IMPL || ctx.peek () == Kind::TRAIT))
 rust_error_at (function.get_locus (), ErrorCode::E0706,
   "functions in traits cannot be declared %");
 
   // if not an associated function but has a self parameter
-  if (context.back () != Context::TRAIT
-  && context.back () != Context::TRAIT_IMPL
-  && context.back () != Context::INHERENT_IMPL
-  && function.has_self_param ())
+  if (ctx.peek () != Kind::TRAIT && ctx.peek () != Kind::TRAIT_IMPL
+  && ctx.peek () != Kind::INHERENT_IMPL && function.has_self_param ())
 rust_error_at (
   function.get_self_param ().get_locus (),
   "% parameter is only allowed in associated functions");
@@ -140,11 +136,11 @@ ASTValidation::visit (AST::Function &function)
 {
   if (!function.has_body ())
{
- if (context.back () == Context::INH

[gcc r15-8541] gccrs: fix crashes in hir dump since move to references

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:6e90ff47c658f5a5e97b4b3ae1501efb6e076303

commit r15-8541-g6e90ff47c658f5a5e97b4b3ae1501efb6e076303
Author: Philip Herron 
Date:   Thu Nov 21 17:27:31 2024 +

gccrs: fix crashes in hir dump since move to references

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): add guards

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/hir/rust-hir-dump.cc | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index 81cb881268f8..1b48b294008c 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -359,7 +359,8 @@ Dump::do_matcharm (MatchArm &e)
   // FIXME Can't remember how to handle that. Let's see later.
   // do_outer_attrs(e);
   visit_collection ("match_arm_patterns", e.get_patterns ());
-  visit_field ("guard_expr", e.get_guard_expr ());
+  if (e.has_match_arm_guard ())
+visit_field ("guard_expr", e.get_guard_expr ());
   end ("MatchArm");
 }
 
@@ -1264,7 +1265,8 @@ Dump::visit (BlockExpr &e)
 
   visit_collection ("statements", e.get_statements ());
 
-  visit_field ("expr", e.get_final_expr ());
+  if (e.has_final_expr ())
+visit_field ("expr", e.get_final_expr ());
 
   end ("BlockExpr");
 }
@@ -1489,7 +1491,8 @@ Dump::visit (TypeParam &e)
 
   visit_collection ("type_param_bounds", e.get_type_param_bounds ());
 
-  visit_field ("type", e.get_type ());
+  if (e.has_type ())
+visit_field ("type", e.get_type ());
 
   end ("TypeParam");
 }
@@ -1655,7 +1658,8 @@ Dump::visit (Function &e)
   put_field ("function_params", "empty");
 }
 
-  visit_field ("return_type", e.get_return_type ());
+  if (e.has_function_return_type ())
+visit_field ("return_type", e.get_return_type ());
 
   if (!e.has_where_clause ())
 put_field ("where_clause", "none");


[gcc r15-8500] gccrs: Use name resolution 2.0 in TraitItemReference

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:a36220b6d31f68569c0c0de82ae5b6acfcd51a4a

commit r15-8500-ga36220b6d31f68569c0c0de82ae5b6acfcd51a4a
Author: Owen Avery 
Date:   Sun Oct 27 15:55:48 2024 -0400

gccrs: 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 45cb75d87fe0..51ab87d14b8a 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 r15-8499] gccrs: Rename some PathIdentSegment functions

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:3fe905ebf21a67a63d70a336ef87ae06fd8d5e63

commit r15-8499-g3fe905ebf21a67a63d70a336ef87ae06fd8d5e63
Author: Owen Avery 
Date:   Sat Oct 26 15:05:43 2024 -0400

gccrs: 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 202266878467..bc76deb9a6d5 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 98fde5a26068..2cad39554946 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 r15-8503] gccrs: Fix name resolution 2.0 definition lookups in unsafe checker

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:ea163c6fe0021e0c6a6d984ebe62d77e31a44c51

commit r15-8503-gea163c6fe0021e0c6a6d984ebe62d77e31a44c51
Author: Owen Avery 
Date:   Wed Oct 9 00:16:27 2024 -0400

gccrs: 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 4c8db3a554e7..9ab18e2f6564 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 r15-8496] gccrs: Insert trait names during toplevel resolution 2.0

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:bf1d58686b282f00271e5afeff168ca84abde821

commit r15-8496-gbf1d58686b282f00271e5afeff168ca84abde821
Author: Owen Avery 
Date:   Wed Oct 16 00:40:01 2024 -0400

gccrs: 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 a0d8492b7eb6..fff3769cd70b 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-8527] gccrs: Refactor HIR with optionals, references & newtypes

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:d123f43e42f623dfd7dbe63f484197a99ea7f9ed

commit r15-8527-gd123f43e42f623dfd7dbe63f484197a99ea7f9ed
Author: Pierre-Emmanuel Patry 
Date:   Fri Mar 8 14:42:10 2024 +0100

gccrs: Refactor HIR with optionals, references & newtypes

The HIR made heavy use of pair and other unamed types which can be
difficult to read.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc: Use FnParam getter.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* backend/rust-compile-intrinsic.cc: Likewise.
* backend/rust-compile-type.cc: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc 
(PrivacyReporter::visit):
Only visit childrens if not missing.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Use
a reference instead of a raw pointer.
* hir/tree/rust-hir-expr.h: Add presence function for return
expression.
* hir/tree/rust-hir-item.h: Remove take_param_name.
* hir/tree/rust-hir.h: Make mapping getter const.
* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): Use
getter.
* typecheck/rust-hir-type-check-expr.cc: Likewise.
* typecheck/rust-hir-type-check-implitem.cc: Use FnParam vector 
instead
of std::pair of Pattern and BaseType.
* typecheck/rust-hir-type-check-item.cc: Likewise.
* typecheck/rust-hir-type-check.cc: Likewise.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Use 
getters.
(TypeCheckMethodCallExpr::check): Likewise.
* typecheck/rust-tyty-cmp.h: Likewise.
* typecheck/rust-tyty.cc: Use FnParam.
* typecheck/rust-tyty.h (class FnParam): Add FnParam to handle 
function
parameters instead of handling std::pairs.
* typecheck/rust-unify.cc (UnifyRules::expect_fndef): Use getters.
(UnifyRules::expect_fnptr): Likewise.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/backend/rust-compile-base.cc  |  2 +-
 gcc/rust/backend/rust-compile-expr.cc  |  4 +-
 gcc/rust/backend/rust-compile-intrinsic.cc | 17 +++---
 gcc/rust/backend/rust-compile-type.cc  |  4 +-
 .../checks/errors/privacy/rust-privacy-reporter.cc | 11 ++--
 gcc/rust/checks/errors/rust-unsafe-checker.cc  |  2 +-
 gcc/rust/hir/tree/rust-hir-expr.h  |  2 +
 gcc/rust/hir/tree/rust-hir-item.h  |  2 -
 gcc/rust/hir/tree/rust-hir.h   |  5 +-
 gcc/rust/typecheck/rust-hir-dot-operator.cc|  2 +-
 gcc/rust/typecheck/rust-hir-type-check-expr.cc |  4 +-
 gcc/rust/typecheck/rust-hir-type-check-implitem.cc | 28 -
 gcc/rust/typecheck/rust-hir-type-check-item.cc |  6 +-
 gcc/rust/typecheck/rust-hir-type-check.cc  | 18 +++---
 gcc/rust/typecheck/rust-tyty-call.cc   | 16 ++---
 gcc/rust/typecheck/rust-tyty-cmp.h |  6 +-
 gcc/rust/typecheck/rust-tyty.cc| 30 +-
 gcc/rust/typecheck/rust-tyty.h | 69 ++
 gcc/rust/typecheck/rust-unify.cc   |  6 +-
 19 files changed, 122 insertions(+), 112 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-base.cc 
b/gcc/rust/backend/rust-compile-base.cc
index 598f2e2e451b..80ea7a4ec954 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -711,7 +711,7 @@ HIRCompileBase::compile_function (
   for (auto &referenced_param : function_params)
 {
   auto &tyty_param = fntype->param_at (i++);
-  auto param_tyty = tyty_param.second;
+  auto param_tyty = tyty_param.get_type ();
   auto compiled_param_type = TyTyResolveCompile::compile (ctx, param_tyty);
 
   location_t param_locus = referenced_param.get_locus ();
diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index c46bda954adf..107ca2eadf5d 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1267,7 +1267,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
 
 const TyTy::FnType *fn = static_cast (base);
 auto ¶m = fn->param_at (index);
-*result = param.second;
+*result = param.get_type ();
 
 return true;
   };
@@ -1401,7 +1401,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
   // assignments are coercion sites so lets convert the rvalue if
   // necessary, offset from the already adjusted implicit self
   bool ok;
-  TyTy::BaseType *expected = fntype->param_at (i + 1).second;
+  TyTy::BaseType *expected = fntype->param_at (i + 1).get_type ();
 
   TyTy::BaseType *actual = nullptr;
   ok = ctx->get_tyctx ()->lookup_type (
diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc 
b/gcc/rust/backend/rust-compile-intrinsic.cc
index b

[gcc r15-8549] gccrs: lang-items: Move comment about arithmetic lang items

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:0b4732e7916b83455230635e1926c0ebe886c5d8

commit r15-8549-g0b4732e7916b83455230635e1926c0ebe886c5d8
Author: Arthur Cohen 
Date:   Mon Nov 25 12:21:05 2024 +0100

gccrs: lang-items: Move comment about arithmetic lang items

gcc/rust/ChangeLog:

* util/rust-lang-item.h: Fix comment location to align with other 
comments.

Diff:
---
 gcc/rust/util/rust-lang-item.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h
index 951e4a3ceaf4..92c70bbddf44 100644
--- a/gcc/rust/util/rust-lang-item.h
+++ b/gcc/rust/util/rust-lang-item.h
@@ -23,12 +23,12 @@
 
 namespace Rust {
 
-// https://github.com/rust-lang/rust/blob/master/library/core/src/ops/arith.rs
 class LangItem
 {
 public:
   enum class Kind
   {
+// 
https://github.com/rust-lang/rust/blob/master/library/core/src/ops/arith.rs
 ADD,
 SUBTRACT,
 MULTIPLY,


[gcc r15-8518] gccrs: Improve handling of implicit Self parameter in AST

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:c92c217c86cc2023146d6f14c8eb7732b560c175

commit r15-8518-gc92c217c86cc2023146d6f14c8eb7732b560c175
Author: Owen Avery 
Date:   Mon Nov 4 15:05:03 2024 -0500

gccrs: Improve handling of implicit Self parameter in AST

gcc/rust/ChangeLog:

* ast/rust-item.h
(Trait::self_param): Add.
(Trait::Trait): Initialize self_param.
(Trait::operator=): Copy self_param.
(Trait::insert_implicit_self): Remove.
(Trait::get_implicit_self): Add.
* hir/rust-ast-lower-item.cc
(ASTLoweringItem::visit): Make sure implicit self is still
lowered to HIR.
* resolve/rust-ast-resolve-item.cc
(ResolveItem::visit): Adjust handling of implicit self.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Add commit to Trait visitor
mentioning that implicit self is not visited.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Remove call to Trait::insert_implicit_self.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.
* rust/link/generic_function_0.rs: No longer expect failure.
* rust/link/trait_import_0.rs: Likewise.
* rust/link/trait_import_1.rs
(trait Sized): Add.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/ast/rust-item.h   | 23 +++---
 gcc/rust/hir/rust-ast-lower-item.cc|  6 ++
 gcc/rust/resolve/rust-ast-resolve-item.cc  | 12 +++
 gcc/rust/resolve/rust-early-name-resolver.cc   |  2 ++
 .../resolve/rust-toplevel-name-resolver-2.0.cc | 17 
 gcc/testsuite/rust/compile/nr2/exclude |  9 -
 gcc/testsuite/rust/link/generic_function_0.rs  |  3 ---
 gcc/testsuite/rust/link/trait_import_0.rs  |  3 ---
 gcc/testsuite/rust/link/trait_import_1.rs  |  3 +++
 9 files changed, 21 insertions(+), 57 deletions(-)

diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 2ae7c44398bc..6611707a9a67 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -2831,6 +2831,7 @@ class Trait : public VisItem
   bool has_auto;
   Identifier name;
   std::vector> generic_params;
+  TypeParam self_param;
   std::vector> type_param_bounds;
   WhereClause where_clause;
   std::vector inner_attrs;
@@ -2870,7 +2871,7 @@ public:
 std::vector inner_attrs, location_t locus)
 : VisItem (std::move (vis), std::move (outer_attrs)),
   has_unsafe (is_unsafe), has_auto (is_auto), name (std::move (name)),
-  generic_params (std::move (generic_params)),
+  generic_params (std::move (generic_params)), self_param ({"Self"}, 
locus),
   type_param_bounds (std::move (type_param_bounds)),
   where_clause (std::move (where_clause)),
   inner_attrs (std::move (inner_attrs)),
@@ -2880,8 +2881,9 @@ public:
   // Copy constructor with vector clone
   Trait (Trait const &other)
 : VisItem (other), has_unsafe (other.has_unsafe), has_auto 
(other.has_auto),
-  name (other.name), where_clause (other.where_clause),
-  inner_attrs (other.inner_attrs), locus (other.locus)
+  name (other.name), self_param (other.self_param),
+  where_clause (other.where_clause), inner_attrs (other.inner_attrs),
+  locus (other.locus)
   {
 generic_params.reserve (other.generic_params.size ());
 for (const auto &e : other.generic_params)
@@ -2901,6 +2903,7 @@ public:
   {
 VisItem::operator= (other);
 name = other.name;
+self_param = other.self_param;
 has_unsafe = other.has_unsafe;
 has_auto = other.has_auto;
 where_clause = other.where_clause;
@@ -2968,19 +2971,7 @@ public:
 
   WhereClause &get_where_clause () { return where_clause; }
 
-  void insert_implict_self (std::unique_ptr &¶m)
-  {
-std::vector> new_list;
-new_list.reserve (generic_params.size () + 1);
-
-new_list.push_back (std::move (param));
-for (auto &p : generic_params)
-  {
-   new_list.push_back (std::move (p));
-  }
-
-generic_params = std::move (new_list);
-  }
+  AST::TypeParam &get_implicit_self () { return self_param; }
 
 protected:
   /* Use covariance to implement clone function as returning this object
diff --git a/gcc/rust/hir/rust-ast-lower-item.cc 
b/gcc/rust/hir/rust-ast-lower-item.cc
index 171737ab0293..ae938d986589 100644
--- a/gcc/rust/hir/rust-ast-lower-item.cc
+++ b/gcc/rust/hir/rust-ast-lower-item.cc
@@ -572,6 +572,12 @@ ASTLoweringItem::visit (AST::Trait &trait)
   generic_params = lower_generic_params (trait.get_generic_params ());
 }
 
+  // TODO: separate "Self" from normal generic parameters
+  //   in HIR as well as in AST?
+  HIR::GenericParam *self_param
+= ASTLowerGenericParam::translate (trait.get_implicit_self ());
+  generic_params.emplace (generic_params.b

[gcc r15-8531] gccrs: FnParam cloning now keeps projections

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:ba71c9d3b565fd4a493e1ddcf7a9584e1b33c0c6

commit r15-8531-gba71c9d3b565fd4a493e1ddcf7a9584e1b33c0c6
Author: Pierre-Emmanuel Patry 
Date:   Tue Nov 19 15:37:56 2024 +0100

gccrs: FnParam cloning now keeps projections

FnParam type where monomorphized during cloning.

gcc/rust/ChangeLog:

* typecheck/rust-tyty.h: Reverse monomorphization during cloning and
make a new function to explicitly monomorphize.
* typecheck/rust-tyty.cc: Use monomorphization when required.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/typecheck/rust-tyty.cc | 2 +-
 gcc/rust/typecheck/rust-tyty.h  | 5 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index e2f1361a78e0..1073dfa6adc9 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -597,7 +597,7 @@ BaseType::monomorphized_clone () const
 {
   std::vector cloned_params;
   for (auto &p : fn->get_params ())
-   cloned_params.push_back (p.clone ());
+   cloned_params.push_back (p.monomorphized_clone ());
 
   BaseType *retty = fn->get_return_type ()->monomorphized_clone ();
   return new FnType (fn->get_ref (), fn->get_ty_ref (), fn->get_id (),
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 4d1a082f80d3..94f7bce00f82 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -791,6 +791,11 @@ public:
   void set_type (BaseType *new_type) { type = new_type; }
 
   FnParam clone () const
+  {
+return FnParam (pattern->clone_pattern (), type->clone ());
+  }
+
+  FnParam monomorphized_clone () const
   {
 return FnParam (pattern->clone_pattern (), type->monomorphized_clone ());
   }


[gcc r15-8530] gccrs: Fix Generic type retrieval

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:a99d29095028be7a68c876d6124b8e845fc80fef

commit r15-8530-ga99d29095028be7a68c876d6124b8e845fc80fef
Author: Pierre-Emmanuel Patry 
Date:   Fri Nov 8 12:01:15 2024 +0100

gccrs: Fix Generic type retrieval

gcc/rust/ChangeLog:

* hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): Forward
an optional to the constructor.
* hir/tree/rust-hir-item.cc (TypeParam::TypeParam): Use an optional
in the constructor.
(TypeParam::operator=): Ensure the TypeParam has a type properly.
(TypeParam::get_type_mappings): Likewise.
* hir/tree/rust-hir-item.h: Wrap the type smart pointer into an
optional.
* hir/tree/rust-hir.cc (TypeParam::as_string): Unwrap optional type
correctly.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/hir/rust-ast-lower-type.cc | 10 +-
 gcc/rust/hir/tree/rust-hir-item.cc  | 19 +++
 gcc/rust/hir/tree/rust-hir-item.h   | 14 --
 gcc/rust/hir/tree/rust-hir.cc   |  2 +-
 4 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/gcc/rust/hir/rust-ast-lower-type.cc 
b/gcc/rust/hir/rust-ast-lower-type.cc
index 7d6ac5ddffa3..5836c1ac1487 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -17,6 +17,7 @@
 // .
 
 #include "rust-ast-lower-type.h"
+#include "optional.h"
 #include "rust-attribute-values.h"
 
 namespace Rust {
@@ -502,9 +503,9 @@ ASTLowerGenericParam::visit (AST::TypeParam ¶m)
}
 }
 
-  HIR::Type *type = param.has_type ()
- ? ASTLoweringType::translate (param.get_type ())
- : nullptr;
+  auto type = param.has_type () ? tl::optional (std::unique_ptr (
+   ASTLoweringType::translate (param.get_type (
+   : tl::nullopt;
 
   auto crate_num = mappings.get_current_crate ();
   Analysis::NodeMapping mapping (crate_num, param.get_node_id (),
@@ -514,8 +515,7 @@ ASTLowerGenericParam::visit (AST::TypeParam ¶m)
   translated
 = new HIR::TypeParam (mapping, param.get_type_representation (),
  param.get_locus (), std::move (type_param_bounds),
- std::unique_ptr (type),
- param.get_outer_attrs ());
+ std::move (type), param.get_outer_attrs ());
 }
 
 HIR::TypeParamBound *
diff --git a/gcc/rust/hir/tree/rust-hir-item.cc 
b/gcc/rust/hir/tree/rust-hir-item.cc
index f81f1eae1343..cff06d35269d 100644
--- a/gcc/rust/hir/tree/rust-hir-item.cc
+++ b/gcc/rust/hir/tree/rust-hir-item.cc
@@ -17,6 +17,7 @@
 // .
 
 #include "rust-hir-item.h"
+#include "optional.h"
 
 namespace Rust {
 namespace HIR {
@@ -25,7 +26,7 @@ TypeParam::TypeParam (
   Analysis::NodeMapping mappings, Identifier type_representation,
   location_t locus,
   std::vector> type_param_bounds,
-  std::unique_ptr, AST::AttrVec outer_attrs)
+  tl::optional> type, AST::AttrVec outer_attrs)
   : GenericParam (mappings), outer_attrs (std::move (outer_attrs)),
 type_representation (std::move (type_representation)),
 type_param_bounds (std::move (type_param_bounds)), type (std::move (type)),
@@ -37,8 +38,10 @@ TypeParam::TypeParam (TypeParam const &other)
 type_representation (other.type_representation), locus (other.locus)
 {
   // guard to prevent null pointer dereference
-  if (other.type != nullptr)
-type = other.type->clone_type ();
+  if (other.has_type ())
+type = {other.type.value ()->clone_type ()};
+  else
+type = tl::nullopt;
 
   type_param_bounds.reserve (other.type_param_bounds.size ());
   for (const auto &e : other.type_param_bounds)
@@ -54,10 +57,10 @@ TypeParam::operator= (TypeParam const &other)
   mappings = other.mappings;
 
   // guard to prevent null pointer dereference
-  if (other.type != nullptr)
-type = other.type->clone_type ();
+  if (other.has_type ())
+type = {other.type.value ()->clone_type ()};
   else
-type = nullptr;
+type = tl::nullopt;
 
   type_param_bounds.reserve (other.type_param_bounds.size ());
   for (const auto &e : other.type_param_bounds)
@@ -69,8 +72,8 @@ TypeParam::operator= (TypeParam const &other)
 Analysis::NodeMapping
 TypeParam::get_type_mappings () const
 {
-  rust_assert (type != nullptr);
-  return type->get_mappings ();
+  rust_assert (type.has_value ());
+  return type.value ()->get_mappings ();
 }
 
 std::vector> &
diff --git a/gcc/rust/hir/tree/rust-hir-item.h 
b/gcc/rust/hir/tree/rust-hir-item.h
index bb300e9ed234..0fda1672b747 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -19,6 +19,7 @@
 #ifndef RUST_HIR_ITEM_H
 #define RUST_HIR_ITEM_H
 
+#include "optional.h"
 #include "rust-abi.h"
 #include "rust-hir-stmt.h"
 #include "rust-common.h"
@@ -102,14 +103,13 @@ class TypeParam : public GenericParam
   s

[gcc r15-8535] gccrs: Use default constructor for default arguments

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:2d480fe8697463fda0c8ab5c5c363015c9f88aa0

commit r15-8535-g2d480fe8697463fda0c8ab5c5c363015c9f88aa0
Author: Pierre-Emmanuel Patry 
Date:   Wed Nov 20 13:19:15 2024 +0100

gccrs: Use default constructor for default arguments

GCC 4.8 complains about the initializer list.

gcc/rust/ChangeLog:

* typecheck/rust-tyty.h: Change initializer list to default 
constructor
call.

Signed-off-by: Pierre-Emmanuel Patry 

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

diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 94f7bce00f82..49cd00c91742 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -657,7 +657,7 @@ public:
   std::vector subst_refs,
   SubstitutionArgumentMappings generic_arguments
   = SubstitutionArgumentMappings::error (),
-  RegionConstraints region_constraints = {},
+  RegionConstraints region_constraints = RegionConstraints{},
   std::set refs = std::set ())
 : BaseType (ref, ref, TypeKind::ADT, ident, refs),
   SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),
@@ -670,7 +670,7 @@ public:
   std::vector subst_refs,
   SubstitutionArgumentMappings generic_arguments
   = SubstitutionArgumentMappings::error (),
-  RegionConstraints region_constraints = {},
+  RegionConstraints region_constraints = RegionConstraints{},
   std::set refs = std::set ())
 : BaseType (ref, ty_ref, TypeKind::ADT, ident, refs),
   SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),
@@ -683,7 +683,7 @@ public:
   std::vector subst_refs, ReprOptions repr,
   SubstitutionArgumentMappings generic_arguments
   = SubstitutionArgumentMappings::error (),
-  RegionConstraints region_constraints = {},
+  RegionConstraints region_constraints = RegionConstraints{},
   std::set refs = std::set ())
 : BaseType (ref, ty_ref, TypeKind::ADT, ident, refs),
   SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),


[gcc r15-8569] gccrs: nr2.0: Resolve lang item paths properly.

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:89640686a29f8b3f256454b9c53a72c629efbe39

commit r15-8569-g89640686a29f8b3f256454b9c53a72c629efbe39
Author: Arthur Cohen 
Date:   Fri Nov 29 12:35:37 2024 +0100

gccrs: nr2.0: Resolve lang item paths properly.

gcc/rust/ChangeLog:

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

Diff:
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 20 
 gcc/rust/resolve/rust-late-name-resolver-2.0.h  |  1 +
 2 files changed, 21 insertions(+)

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 3af8496288dd..ac5f1c575461 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -18,6 +18,7 @@
 
 #include "optional.h"
 #include "rust-ast-full.h"
+#include "rust-diagnostics.h"
 #include "rust-hir-map.h"
 #include "rust-late-name-resolver-2.0.h"
 #include "rust-default-resolver.h"
@@ -247,6 +248,25 @@ Late::visit (AST::PathInExpression &expr)
 Definition (resolved->get_node_id ()));
 }
 
+void
+Late::visit (AST::LangItemPath &type)
+{
+  auto &mappings = Rust::Analysis::Mappings::get ();
+  auto lang_item = mappings.lookup_lang_item_node (type.get_lang_item_kind ());
+
+  if (!lang_item)
+{
+  rust_fatal_error (
+   type.get_locus (), "use of undeclared lang item %qs",
+   LangItem::ToString (type.get_lang_item_kind ()).c_str ());
+  return;
+}
+
+  ctx.map_usage (Usage (type.get_node_id ()), Definition (lang_item.value ()));
+
+  DefaultResolver::visit (type);
+}
+
 void
 Late::visit (AST::TypePath &type)
 {
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 79572fbc4fac..6f1191662cc2 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -46,6 +46,7 @@ public:
   // resolutions
   void visit (AST::IdentifierExpr &) override;
   void visit (AST::PathInExpression &) override;
+  void visit (AST::LangItemPath &) override;
   void visit (AST::TypePath &) override;
   void visit (AST::StructExprStruct &) override;
   void visit (AST::StructExprStructBase &) override;


[gcc r15-8512] gccrs: fix bad type inference on local patterns

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:389756b2ac97beeb72cd160eeefee5ea381e55e9

commit r15-8512-g389756b2ac97beeb72cd160eeefee5ea381e55e9
Author: Philip Herron 
Date:   Mon Nov 4 14:43:25 2024 +

gccrs: fix bad type inference on local patterns

We do not need to inject inference variables on generic patterns
with generic blocks. This will just cause unconstrained inference
variables as they may not unify against something.

Fixes Rust-GCC#2323

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-path.cc 
(TypeCheckExpr::resolve_root_path): dont infer here

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-path.cc | 3 ++-
 gcc/testsuite/rust/compile/issue-2323.rs   | 9 +
 gcc/testsuite/rust/compile/nr2/exclude | 1 +
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc 
b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index 231ddd604db2..7b934b38eb37 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -245,6 +245,7 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression 
&expr, size_t *offset,
 
   auto seg_is_module = mappings.lookup_module (ref).has_value ();
   auto seg_is_crate = mappings.is_local_hirid_crate (ref);
+  auto seg_is_pattern = mappings.lookup_hir_pattern (ref).has_value ();
   if (seg_is_module || seg_is_crate)
{
  // A::B::C::this_is_a_module::D::E::F
@@ -321,7 +322,7 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression 
&expr, size_t *offset,
  if (lookup->get_kind () == TyTy::TypeKind::ERROR)
return new TyTy::ErrorType (expr.get_mappings ().get_hirid ());
}
-  else if (lookup->needs_generic_substitutions ())
+  else if (lookup->needs_generic_substitutions () && !seg_is_pattern)
{
  lookup = SubstMapper::InferSubst (lookup, expr.get_locus ());
}
diff --git a/gcc/testsuite/rust/compile/issue-2323.rs 
b/gcc/testsuite/rust/compile/issue-2323.rs
new file mode 100644
index ..02a3f90b4d81
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2323.rs
@@ -0,0 +1,9 @@
+#[lang = "sized"]
+trait Sized {}
+
+pub struct S(T);
+
+pub fn foo(x: T) {
+let y = S(x);
+y.0;
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 4ba27d31f88b..eaa2a1e0d0bc 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -222,4 +222,5 @@ if_let_expr_simple.rs
 iflet.rs
 issue-3033.rs
 issue-3009.rs
+issue-2323.rs
 # please don't delete the trailing newline


[gcc(refs/users/omachota/heads/rtl-ssa-dce)] rtl-ssa-dce: mark global regs as prelive with ssa

2025-03-21 Thread Ondrej Machota via Gcc-cvs
https://gcc.gnu.org/g:44402e206e07ebeb817ac8587a87fe8438cb0b0e

commit 44402e206e07ebeb817ac8587a87fe8438cb0b0e
Author: Ondřej Machota 
Date:   Tue Mar 18 22:55:02 2025 +0100

rtl-ssa-dce: mark global regs as prelive with ssa

Diff:
---
 gcc/dce.cc | 100 -
 1 file changed, 45 insertions(+), 55 deletions(-)

diff --git a/gcc/dce.cc b/gcc/dce.cc
index 42b63cbcfb81..62ab115455c0 100644
--- a/gcc/dce.cc
+++ b/gcc/dce.cc
@@ -1306,15 +1306,6 @@ public:
 
 } // namespace
 
-
-bool sets_global_register(const_rtx rtx) {
-  auto code = GET_CODE(rtx);
-  if (GET_RTX_CLASS(code) != RTX_INSN)
-return false;
-
-  return sets_global_register(static_cast(rtx));
-}
-
 // We should mark stack registers
 // use HARD_FRAME_POINTER_REGNUM, REGNO_PTR_FRAME_P
 // muzeme mit parallel, ktery ma napr. dva single sety, nebo asm statement
@@ -1327,12 +1318,12 @@ bool sets_global_register(rtx_insn* insn) {
   rtx dest = SET_DEST(set);
 
   // TODO : rewrite to simple return
-  //std::cerr << "first pseudo: " << FIRST_PSEUDO_REGISTER << '\n';
+  std::cerr << "first pseudo: " << FIRST_PSEUDO_REGISTER << '\n';
   //std::cerr << "register: " << REGNO(dest) << "\n";
   //debug(insn);
   // If I understand correctly, global_regs[i] is 1 iff reg i is used
   if (REG_P(dest) && HARD_REGISTER_NUM_P(REGNO(dest))) { // && 
global_regs[REGNO(dest)]
-//std::cerr << "sets_global_register: true\n";
+std::cerr << "sets_global_register: true\n";
 return true;
   }
 
@@ -1378,10 +1369,6 @@ bool side_effects_with_mem (const_rtx x)
 case ASM_OPERANDS:
return true;
 
-// This should rather by RTX_BODY in is_rtx_insn_prelive - like global 
clobber
-// case USE:
-  // return true;
-
 default:
   break;
 }
@@ -1451,8 +1438,8 @@ bool is_rtx_insn_prelive(rtx_insn *insn) {
 return true;
 
   // Mark set of a global register
-  if (sets_global_register(insn)) // check rtx_class with GET_RTX_CLASS if 
RTX_ISNS and convert if needed
-return true;
+  // if (sets_global_register(insn)) // check rtx_class with GET_RTX_CLASS if 
RTX_ISNS and convert if needed
+  //   return true;
 
   rtx body = PATTERN(insn);
   if (GET_CODE(body) == CLOBBER) // 
gcc/gcc/testsuite/gcc.c-torture/compile/2605-1.c
@@ -1472,7 +1459,7 @@ bool is_rtx_insn_prelive(rtx_insn *insn) {
   // It seems that the issue was due to trap_if rtl insn and fixed with 
may_trap_or_fault_p
   // What about can_throw_internal?
   // || can_throw_internal(body) - testy na ntb prochazi
-  if (side_effects_with_mem(body)) // || may_trap_or_fault_p(body))
+  if (side_effects_with_mem(body)) // || may_trap_or_fault_p(body)) // 
replaced by TRAP_IF
 return true;
 
   return false;
@@ -1506,39 +1493,28 @@ bool is_prelive(insn_info *insn)
   gcc_assert (insn->is_real());
   auto rtl = insn->rtl();
 
-  if (!INSN_P(rtl)) // This might be useless
-return false;
+  for (auto&& __def : insn->defs()) {
+def_info * def = __def;
+if (!def->is_reg()) {
+  continue;
+}
+
+// this ignore clobbers, which is probably fine
+if (def->kind() == access_kind::SET && HARD_REGISTER_NUM_P(def->regno())) {
+  // We might try to write something like def->regno() == REGNO 
(pic_offset_table_rtx) ...
+  // TODO : else if (DF_REF_REG (def) == pic_offset_table_rtx && REGNO 
(pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
+  // std::cerr << "hello, dear hard register! regno: " << def->regno() << 
"\n";
+  // debug(rtl);
+  return true;
+}
+  }
 
-  auto res = is_rtx_insn_prelive(rtl);
+  // auto res = is_rtx_insn_prelive(rtl);
   //std::cerr << "Trying to mark insn: " << insn->uid() << " as prelive: " << 
res << '\n';
 
   return is_rtx_insn_prelive(rtl);
 }
 
-static void
-rtl_ssa_dce_init()
-{
-  // internal compiler error: gcc.c-torture/execute/20040811-1.c - 
rtl_ssa::function_info::add_phi_nodes
-
-  calculate_dominance_info(CDI_DOMINATORS);
-  // here we create ssa form for function
-  crtl->ssa = new rtl_ssa::function_info(cfun);
-}
-
-static void
-rtl_ssa_dce_done()
-{
-  free_dominance_info(CDI_DOMINATORS);
-  if (crtl->ssa->perform_pending_updates())
-cleanup_cfg(0);
-
-  delete crtl->ssa;
-  crtl->ssa = nullptr;
-
-  if (dump_file)
-fprintf(dump_file, "\nFinished running rtl_ssa_dce\n\n");
-}
-
 static void
 rtl_ssa_dce_mark_live(insn_info *info, vec &worklist, 
std::unordered_set &marked)
 {
@@ -1558,18 +1534,8 @@ rtl_ssa_dce_prelive(std::unordered_set 
&marked)
   for (insn_info *insn = crtl->ssa->first_insn(); insn; insn = next)
   {
 next = insn->next_any_insn();
-/*
-I would like to mark visited instruction with something like plf (Pass 
local flags) as in gimple
-
-This file contains some useful functions: e.g. marked_insn_p, mark_insn
-mark_insn does much more than I want now...
-It does quite a useful job. If rtl_insn is a call and it is obsolete, it 
will find call arguments.
-*/
-
 if (is_prelive

[gcc r13-9442] ipa: target clone and mangling alias [PR114992]

2025-03-21 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:41db4716a5603052df626a1ab911b0b3fab322b2

commit r13-9442-g41db4716a5603052df626a1ab911b0b3fab322b2
Author: Jason Merrill 
Date:   Thu Mar 20 12:57:15 2025 -0400

ipa: target clone and mangling alias [PR114992]

Since the mangling of the second lambda changed (previously we counted all
lambdas, now we only count lambdas with the same signature), we
generate_mangling_alias for handler for backward compatibility.
Since handler is COMDAT, resolve_alias puts the alias in the same comdat
group as handler itself.  Then create_dispatcher_calls tries to add the
alias to the same comdat group as the dispatcher, but it's already in a
same_comdat_group, so we ICE.

It seems like we're just missing a remove_from_same_comdat_group before
add_to_same_comdat_group.

PR c++/114992

gcc/ChangeLog:

* multiple_target.cc (create_dispatcher_calls):
remove_from_same_comdat_group before add_to_same_comdat_group.

gcc/testsuite/ChangeLog:

* g++.target/i386/mangling-alias1.C: New test.

(cherry picked from commit ab716829da7c885b97ac2649c7c0ff5c7703ffa5)

Diff:
---
 gcc/multiple_target.cc  |  6 +-
 gcc/testsuite/g++.target/i386/mangling-alias1.C | 16 
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/multiple_target.cc b/gcc/multiple_target.cc
index a2ed048d7dd2..cc9f66f2decb 100644
--- a/gcc/multiple_target.cc
+++ b/gcc/multiple_target.cc
@@ -159,7 +159,11 @@ create_dispatcher_calls (struct cgraph_node *node)
  symtab_node *source = ref->referring;
  source->create_reference (inode, IPA_REF_ALIAS);
  if (inode->get_comdat_group ())
-   source->add_to_same_comdat_group (inode);
+   {
+ if (source->same_comdat_group)
+   source->remove_from_same_comdat_group ();
+ source->add_to_same_comdat_group (inode);
+   }
}
  else
gcc_unreachable ();
diff --git a/gcc/testsuite/g++.target/i386/mangling-alias1.C 
b/gcc/testsuite/g++.target/i386/mangling-alias1.C
new file mode 100644
index ..70264e2b64e6
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/mangling-alias1.C
@@ -0,0 +1,16 @@
+// PR c++/114992
+// { dg-do compile { target { c++11 && x86_64-*-* } } }
+// { dg-require-ifunc }
+
+template 
+__attribute__((target_clones("avx2", "default")))
+void handler(Callable) {}
+
+inline int func()
+{
+  auto l1 = [](int) {}; // different lambda signature
+  handler([]() {}); // so this one needs a mangling alias
+  return 42;
+}
+
+int g = func();


[gcc r15-8529] gccrs: Fixes some tests appearing with a moved variant

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:6246f658336099f328078f92f277ed461c3bb7e5

commit r15-8529-g6246f658336099f328078f92f277ed461c3bb7e5
Author: Pierre-Emmanuel Patry 
Date:   Mon Oct 28 18:08:52 2024 +0100

gccrs: Fixes some tests appearing with a moved variant

A variant being moved lead to a null being created and a segfault later
down the line.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Call getter
instead of size function.
* checks/errors/privacy/rust-privacy-reporter.cc 
(PrivacyReporter::visit):
Only check privacy if the type is present.
* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Use an 
optional.
* hir/tree/rust-hir-generic-param.h: Assert type before getting it.
* hir/tree/rust-hir-item.h: Assert pointers before dereference, fix
has_type condition.
* hir/tree/rust-hir-path.h: Add more assertions.
* hir/tree/rust-hir-stmt.cc: Change constructor with optionals.
* hir/tree/rust-hir-stmt.h: Use optionals over smart pointers to
emphasize these fields might be missing.
* hir/tree/rust-hir.cc (LetStmt::as_string): Use getters.
* typecheck/rust-hir-type-check-expr.cc: Clone structures to prevent
parent's fields from being nulled by the move operation.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Use
optionals.
* typecheck/rust-tyty.cc: Likewise.
* typecheck/rust-tyty.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/backend/rust-compile-expr.cc  |  2 +-
 .../checks/errors/privacy/rust-privacy-reporter.cc |  6 +-
 gcc/rust/hir/rust-ast-lower-stmt.cc| 20 ---
 gcc/rust/hir/tree/rust-hir-generic-param.h |  6 +-
 gcc/rust/hir/tree/rust-hir-item.h  | 69 ++
 gcc/rust/hir/tree/rust-hir-path.h  | 18 +-
 gcc/rust/hir/tree/rust-hir-stmt.cc | 26 
 gcc/rust/hir/tree/rust-hir-stmt.h  | 40 +
 gcc/rust/hir/tree/rust-hir.cc  |  4 +-
 gcc/rust/typecheck/rust-hir-type-check-expr.cc |  5 +-
 gcc/rust/typecheck/rust-hir-type-check-item.cc |  7 ++-
 gcc/rust/typecheck/rust-tyty.cc| 40 ++---
 gcc/rust/typecheck/rust-tyty.h | 12 +++-
 13 files changed, 189 insertions(+), 66 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index 107ca2eadf5d..673acdeefb51 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1200,7 +1200,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
   // this assumes all fields are in order from type resolution and if a
   // base struct was specified those fields are filed via accessors
   std::vector arguments;
-  for (size_t i = 0; i < expr.get_arguments ().size (); i++)
+  for (size_t i = 0; i < expr.num_params (); i++)
{
  auto &argument = expr.get_arguments ().at (i);
  auto rvalue = CompileExpr::Compile (*argument, ctx);
diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc 
b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
index 71030e5c7efa..3413e5ab3dd7 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
@@ -741,9 +741,11 @@ PrivacyReporter::visit (HIR::EmptyStmt &)
 void
 PrivacyReporter::visit (HIR::LetStmt &stmt)
 {
-  check_type_privacy (stmt.get_type ());
+  if (stmt.has_type ())
+check_type_privacy (stmt.get_type ());
 
-  stmt.get_init_expr ().accept_vis (*this);
+  if (stmt.has_init_expr ())
+stmt.get_init_expr ().accept_vis (*this);
 }
 
 void
diff --git a/gcc/rust/hir/rust-ast-lower-stmt.cc 
b/gcc/rust/hir/rust-ast-lower-stmt.cc
index c3594594bf1e..5a825fd11390 100644
--- a/gcc/rust/hir/rust-ast-lower-stmt.cc
+++ b/gcc/rust/hir/rust-ast-lower-stmt.cc
@@ -16,6 +16,7 @@
 // along with GCC; see the file COPYING3.  If not see
 // .
 
+#include "optional.h"
 #include "rust-ast-lower-item.h"
 #include "rust-ast-lower-stmt.h"
 #include "rust-ast-lower-type.h"
@@ -68,12 +69,16 @@ ASTLoweringStmt::visit (AST::LetStmt &stmt)
 {
   HIR::Pattern *variables
 = ASTLoweringPattern::translate (stmt.get_pattern (), true);
-  HIR::Type *type = stmt.has_type ()
- ? ASTLoweringType::translate (stmt.get_type ())
- : nullptr;
-  HIR::Expr *init_expression
-= stmt.has_init_expr () ? ASTLoweringExpr::translate (stmt.get_init_expr 
())
-   : nullptr;
+
+  auto type
+= stmt.has_type () ? tl::optional> (
+   std::unique_ptr (ASTLoweringType::translate (stmt.get_type (
+  : tl::nullopt;
+ 

[gcc r15-8544] gccrs: Prepend crate name to functions with nr2

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:42f94641509b3a1dd9b084cb4b7b50ba43d513e9

commit r15-8544-g42f94641509b3a1dd9b084cb4b7b50ba43d513e9
Author: Pierre-Emmanuel Patry 
Date:   Mon Nov 25 14:24:21 2024 +0100

gccrs: Prepend crate name to functions with nr2

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc: Prepend crate name to function's ir
name.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove passing tests from exclude list.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/backend/rust-compile-base.cc  | 11 ++-
 gcc/testsuite/rust/compile/nr2/exclude |  6 --
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-base.cc 
b/gcc/rust/backend/rust-compile-base.cc
index 80ea7a4ec954..fb4aace95559 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -25,7 +25,8 @@
 #include "rust-compile-type.h"
 #include "rust-constexpr.h"
 #include "rust-diagnostics.h"
-#include "rust-expr.h" // for AST::AttrInputLiteral
+#include "rust-expr.h" // for AST::AttrInputLiteral
+#include "rust-hir-map.h"
 #include "rust-macro.h" // for AST::MetaNameValueStr
 #include "rust-hir-path-probe.h"
 #include "rust-type-util.h"
@@ -39,6 +40,9 @@
 #include "tree.h"
 #include "print-tree.h"
 
+// rust-name-resolution-2.0
+#include "options.h"
+
 namespace Rust {
 namespace Compile {
 
@@ -667,6 +671,11 @@ HIRCompileBase::compile_function (
 }
   std::string asm_name = fn_name;
 
+  auto &mappings = Analysis::Mappings::get ();
+
+  if (flag_name_resolution_2_0)
+ir_symbol_name = mappings.get_current_crate_name () + "::" + 
ir_symbol_name;
+
   unsigned int flags = 0;
   tree fndecl = Backend::function (compiled_fn_type, ir_symbol_name,
   "" /* asm_name */, flags, locus);
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 6c589e4ab4e5..b282f05637d2 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -1,7 +1,3 @@
-attr-mismatch-crate-name.rs
-attr_deprecated.rs
-attr_deprecated_2.rs
-bad=file-name.rs
 bounds1.rs
 break-rust2.rs
 break-rust3.rs
@@ -45,7 +41,6 @@ generics6.rs
 generics8.rs
 generics9.rs
 if_let_expr.rs
-infer-crate-name.rs
 issue-1019.rs
 issue-1031.rs
 issue-1034.rs
@@ -156,7 +151,6 @@ redef_error6.rs
 self-path1.rs
 self-path2.rs
 sizeof-stray-infer-var-bug.rs
-specify-crate-name.rs
 stmt_with_block_dot.rs
 struct-expr-parse.rs
 traits1.rs


[gcc r15-8495] gccrs: Fix bad recursive operator overload call

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:0c0f33bc439a98f9923a48be592bb9a2be540ac3

commit r15-8495-g0c0f33bc439a98f9923a48be592bb9a2be540ac3
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 bdfd9879111d..419703353752 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 ec331cf6e95c..91842df85b22 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 ba22eaff4410..dfdf85a141db 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

[gcc r15-8522] gccrs: asm: Fix clang warnings

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:1e12ef057250e1d3a4a53697862bc270d9cfa45c

commit r15-8522-g1e12ef057250e1d3a4a53697862bc270d9cfa45c
Author: Arthur Cohen 
Date:   Wed Nov 6 15:19:55 2024 +0100

gccrs: asm: Fix clang warnings

Fixes a couple of warnings thrown by clang, with mismatched class/struct
usages and unused members.

gcc/rust/ChangeLog:

* ast/rust-expr.h: Remove invalid usage of `struct`.
* backend/rust-compile-asm.h: Remove unused `translated` member.
* backend/rust-compile-asm.cc (CompileAsm::CompileAsm): Remove usage
of `translated` member.
* checks/errors/rust-unsafe-checker.h: Mark visitor as `override`.
* hir/tree/rust-hir-expr.h (struct AnonConst): Remove unused `locus`
member.

Diff:
---
 gcc/rust/ast/rust-expr.h | 24 
 gcc/rust/backend/rust-compile-asm.cc |  5 ++---
 gcc/rust/backend/rust-compile-asm.h  |  2 --
 gcc/rust/checks/errors/rust-unsafe-checker.h |  2 +-
 gcc/rust/hir/tree/rust-hir-expr.h|  4 ++--
 5 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 438d3d3b86eb..483e599652bb 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4810,14 +4810,14 @@ public:
   rust_assert (this->expr != nullptr);
 }
 
-In (const struct In &other)
+In (const In &other)
 {
   reg = other.reg;
 
   expr = other.expr->clone_expr ();
 }
 
-In operator= (const struct In &other)
+In operator= (const In &other)
 {
   reg = other.reg;
   expr = other.expr->clone_expr ();
@@ -4843,14 +4843,14 @@ public:
   rust_assert (this->expr != nullptr);
 }
 
-Out (const struct Out &other)
+Out (const Out &other)
 {
   reg = other.reg;
   late = other.late;
   expr = other.expr->clone_expr ();
 }
 
-Out operator= (const struct Out &other)
+Out operator= (const Out &other)
 {
   reg = other.reg;
   late = other.late;
@@ -4876,14 +4876,14 @@ public:
   rust_assert (this->expr != nullptr);
 }
 
-InOut (const struct InOut &other)
+InOut (const InOut &other)
 {
   reg = other.reg;
   late = other.late;
   expr = other.expr->clone_expr ();
 }
 
-InOut operator= (const struct InOut &other)
+InOut operator= (const InOut &other)
 {
   reg = other.reg;
   late = other.late;
@@ -4913,7 +4913,7 @@ public:
   rust_assert (this->out_expr != nullptr);
 }
 
-SplitInOut (const struct SplitInOut &other)
+SplitInOut (const SplitInOut &other)
 {
   reg = other.reg;
   late = other.late;
@@ -4921,7 +4921,7 @@ public:
   out_expr = other.out_expr->clone_expr ();
 }
 
-SplitInOut operator= (const struct SplitInOut &other)
+SplitInOut operator= (const SplitInOut &other)
 {
   reg = other.reg;
   late = other.late;
@@ -4953,12 +4953,12 @@ public:
 {
   rust_assert (this->expr != nullptr);
 }
-Sym (const struct Sym &other)
+Sym (const Sym &other)
 {
   expr = std::unique_ptr (other.expr->clone_expr ());
 }
 
-Sym operator= (const struct Sym &other)
+Sym operator= (const Sym &other)
 {
   expr = std::unique_ptr (other.expr->clone_expr ());
   return *this;
@@ -4981,12 +4981,12 @@ public:
   if (label_name.has_value ())
this->label_name = label_name.value ();
 }
-Label (const struct Label &other)
+Label (const Label &other)
 {
   expr = std::unique_ptr (other.expr->clone_expr ());
 }
 
-Label operator= (const struct Label &other)
+Label operator= (const Label &other)
 {
   expr = std::unique_ptr (other.expr->clone_expr ());
   return *this;
diff --git a/gcc/rust/backend/rust-compile-asm.cc 
b/gcc/rust/backend/rust-compile-asm.cc
index e85d08d05792..be553a3e70f9 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -3,9 +3,8 @@
 namespace Rust {
 namespace Compile {
 
-CompileAsm::CompileAsm (Context *ctx)
-  : HIRCompileBase (ctx), translated (error_mark_node)
-{}
+CompileAsm::CompileAsm (Context *ctx) : HIRCompileBase (ctx) {}
+
 tree
 CompileAsm::tree_codegen_asm (HIR::InlineAsm &expr)
 {
diff --git a/gcc/rust/backend/rust-compile-asm.h 
b/gcc/rust/backend/rust-compile-asm.h
index 402d950844c2..4abd24eded4a 100644
--- a/gcc/rust/backend/rust-compile-asm.h
+++ b/gcc/rust/backend/rust-compile-asm.h
@@ -28,8 +28,6 @@ namespace Compile {
 class CompileAsm : private HIRCompileBase
 {
 private:
-  tree translated;
-
   // RELEVANT MEMBER FUNCTIONS
 
   // The limit is 5 because it stands for the 5 things that the C version of
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.h 
b/gcc/rust/checks/errors/rust-unsafe-checker.h
index 96ccdc03c53c..8dc6ab790716 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.h
+++ b/gcc

[gcc r15-8534] gccrs: Add optional template arguments to please GCC4.8

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:1d628b8920ebf3d2c4244b02ab91297b5a0151dd

commit r15-8534-g1d628b8920ebf3d2c4244b02ab91297b5a0151dd
Author: Pierre-Emmanuel Patry 
Date:   Wed Nov 20 01:44:28 2024 +0100

gccrs: Add optional template arguments to please GCC4.8

Clang on macos as well as GCC 4.8 complains when those templates are
missing.

gcc/rust/ChangeLog:

* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Add template
to tl::optional.
* hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): 
Likewise.
* typecheck/rust-hir-type-check-type.cc 
(TypeResolveGenericParam::visit):
Likewise.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/hir/rust-ast-lower-expr.cc| 5 +++--
 gcc/rust/hir/rust-ast-lower-type.cc| 8 +---
 gcc/rust/typecheck/rust-hir-type-check-type.cc | 4 +++-
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc 
b/gcc/rust/hir/rust-ast-lower-expr.cc
index 2954a31d9f44..b45b5f925df7 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.cc
+++ b/gcc/rust/hir/rust-ast-lower-expr.cc
@@ -517,8 +517,9 @@ ASTLoweringExpr::visit (AST::StructExprStructFields 
&struct_expr)
 {
   HIR::Expr *translated_base = ASTLoweringExpr::translate (
struct_expr.get_struct_base ().get_base_struct ());
-  base = tl::optional (Rust::make_unique (
-   std::unique_ptr (translated_base)));
+  base = tl::optional> (
+   Rust::make_unique (
+ std::unique_ptr (translated_base)));
 }
 
   auto const &in_fields = struct_expr.get_fields ();
diff --git a/gcc/rust/hir/rust-ast-lower-type.cc 
b/gcc/rust/hir/rust-ast-lower-type.cc
index 5836c1ac1487..58c93b9e25dd 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -503,9 +503,11 @@ ASTLowerGenericParam::visit (AST::TypeParam ¶m)
}
 }
 
-  auto type = param.has_type () ? tl::optional (std::unique_ptr (
-   ASTLoweringType::translate (param.get_type (
-   : tl::nullopt;
+  tl::optional> type = tl::nullopt;
+  if (param.has_type ())
+type
+  = tl::optional> (std::unique_ptr (
+   ASTLoweringType::translate (param.get_type (;
 
   auto crate_num = mappings.get_current_crate ();
   Analysis::NodeMapping mapping (crate_num, param.get_node_id (),
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc 
b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 089a5af121a0..6e859e5d7196 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -829,7 +829,9 @@ TypeResolveGenericParam::visit (HIR::TypeParam ¶m)
HIR::TraitBound &b = static_cast (*bound);
 
TyTy::TypeBoundPredicate predicate = get_predicate_from_bound (
- b.get_path (), tl::optional (std::ref (*implicit_self_bound)),
+ b.get_path (),
+ tl::optional> (
+   std::ref (*implicit_self_bound)),
  b.get_polarity ());
if (!predicate.is_error ())
  {


[gcc r15-8487] cobol: Rename COB_{BLOCK, UNSIGNED, SIGNED} to {BLOCK, UNSIGNED, SIGNED}_kw for consistency

2025-03-21 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:3355e44dd2b35488facfec66aad628c5999c89d6

commit r15-8487-g3355e44dd2b35488facfec66aad628c5999c89d6
Author: Jakub Jelinek 
Date:   Fri Mar 21 10:48:10 2025 +0100

cobol: Rename COB_{BLOCK,UNSIGNED,SIGNED} to {BLOCK,UNSIGNED,SIGNED}_kw for 
consistency

On Wed, Mar 19, 2025 at 06:03:24PM -0400, James K. Lowden wrote:
> Elsewhere in the parser where there was a conflict like that, I renamed
> the token.  For example, the COBOL word TRUE uses a token named
> TRUE_kw.  I don't mind either way; your solution has less impact on the
> parser.

I think consistency is good and when it is a suffix rather than prefix,
it also sorts alphabetically together with the actual keywords.

2025-03-21  Jakub Jelinek  

* parse.y: Rename COB_BLOCK to BLOCK_kw, COB_SIGNED to SIGNED_kw and
COB_UNSIGNED to UNSIGNED_kw.
* scan.l: Likewise.
* token_names.h: Regenerate.

Diff:
---
 gcc/cobol/parse.y   | 18 +-
 gcc/cobol/scan.l| 10 +-
 gcc/cobol/token_names.h |  8 
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y
index 010538887369..c436469f570a 100644
--- a/gcc/cobol/parse.y
+++ b/gcc/cobol/parse.y
@@ -408,7 +408,7 @@
 
BASED BASECONVERT
BEFORE BINARY BIT BIT_OF "BIT-OF" BIT_TO_CHAR 
"BIT-TO-CHAR"
-   BLANK COB_BLOCK
+   BLANK BLOCK_kw
BOOLEAN_OF_INTEGER "BOOLEAN-OF-INTEGER"
BOTTOM BY
BYTE BYTE_LENGTH "BYTE-LENGTH"
@@ -613,7 +613,7 @@
NONE NORMAL NUMBERS
PREFIXED PREVIOUS PROHIBITED RELATION REQUIRED
REVERSE_VIDEO ROUNDING
-   SECONDS SECURE SHORT COB_SIGNED
+   SECONDS SECURE SHORT SIGNED_kw
STANDARD_BINARY "STANDARD-BINARY"
STANDARD_DECIMAL "STANDARD-DECIMAL"
STATEMENT STEP STRUCTURE
@@ -621,7 +621,7 @@
TOWARD_LESSER "TOWARD-LESSER"
TRUNCATION
UCS_4 "UCS-4"
-   UNDERLINE COB_UNSIGNED
+   UNDERLINE UNSIGNED_kw
UTF_16 "UTF-16"
UTF_8 "UTF-8"
 
@@ -1014,7 +1014,7 @@
 
 BACKWARD BASED BASECONVERT
BEFORE BINARY BIT BIT_OF BIT_TO_CHAR
-BLANK COB_BLOCK
+BLANK BLOCK_kw
BOOLEAN_OF_INTEGER
BOTTOM BY
BYTE BYTE_LENGTH
@@ -1228,7 +1228,7 @@
 NONE NORMAL NUMBERS
 PREFIXED PREVIOUS PROHIBITED RELATION REQUIRED
 REVERSE_VIDEO ROUNDING
-SECONDS SECURE SHORT COB_SIGNED
+SECONDS SECURE SHORT SIGNED_kw
STANDARD_BINARY
 STANDARD_DECIMAL
STATEMENT STEP STRUCTURE
@@ -1236,7 +1236,7 @@
TOWARD_LESSER
TRUNCATION
 UCS_4
-   UNDERLINE COB_UNSIGNED
+   UNDERLINE UNSIGNED_kw
UTF_16
UTF_8
 
@@ -2907,7 +2907,7 @@ fd_clause:  record_desc
 }
 ;
 
-block_desc: COB_BLOCK contains rec_contains chars_recs
+block_desc: BLOCK_kw contains rec_contains chars_recs
 ;
 rec_contains:   NUMSTR[min] {
   ssize_t n;
@@ -6528,7 +6528,7 @@ context_word:   APPLY   { static char s[] 
="APPLY";
  $$ = s; } // screen description entry
 |   SHORT  { static char s[] ="SHORT";
  $$ = s; } // DYNAMIC LENGTH STRUCTURE 
clause
-|   COB_SIGNED { static char s[] ="SIGNED";
+|   SIGNED_kw  { static char s[] ="SIGNED";
  $$ = s; } // DYNAMIC LENGTH STRUCTURE 
clause and USAGE clause
 |   STANDARD_BINARY{ static char s[] ="STANDARD-BINARY";
  $$ = s; } // ARITHMETIC clause
@@ -6554,7 +6554,7 @@ context_word:   APPLY   { static char s[] 
="APPLY";
  $$ = s; } // ALPHABET clause
 |   UNDERLINE  { static char s[] ="UNDERLINE";
  $$ = s; } // screen description entry 
and SET attribute statement
-|   COB_UNSIGNED   { static char s[] ="UNSIGNED";
+|   UNSIGNED_kw{ static char s

[gcc(refs/users/omachota/heads/rtl-ssa-dce)] rtl-ssa: Create new dce pass

2025-03-21 Thread Ondrej Machota via Gcc-cvs
https://gcc.gnu.org/g:a4eff4f9b65f6adb0730a8a7b1945c649b157908

commit a4eff4f9b65f6adb0730a8a7b1945c649b157908
Author: Ondřej Machota 
Date:   Mon Apr 29 21:38:47 2024 +0200

rtl-ssa: Create new dce pass

Diff:
---
 gcc/dce.cc  | 41 +
 gcc/dce.h   |  1 +
 gcc/passes.def  |  2 +-
 gcc/tree-pass.h |  1 +
 4 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/gcc/dce.cc b/gcc/dce.cc
index 6a6a845f2343..514b9fc809cf 100644
--- a/gcc/dce.cc
+++ b/gcc/dce.cc
@@ -1302,3 +1302,44 @@ make_pass_fast_rtl_dce (gcc::context *ctxt)
 {
   return new pass_fast_rtl_dce (ctxt);
 }
+
+namespace {
+
+const pass_data pass_data_rtl_ssa_dce = {
+  RTL_PASS,  /* type */
+  "rtl_ssa_dce",  /* name */
+  OPTGROUP_NONE,  /* optinfo_flags */
+  TV_DCE,/* tv_id */
+  0, /* properties_required */
+  0, /* properties_provided */
+  0, /* properties_destroyed */
+  0, /* todo_flags_start */
+  TODO_df_finish, /* todo_flags_finish */
+};
+
+class pass_rtl_ssa_dce : public rtl_opt_pass
+{
+public:
+  pass_rtl_ssa_dce (gcc::context *ctxt)
+: rtl_opt_pass (pass_data_rtl_ssa_dce, ctxt)
+  {}
+
+  /* opt_pass methods: */
+  bool gate (function *) final override { return flag_dce; }
+
+  unsigned int execute (function *) final override
+  {
+if (dump_file)
+  fprintf (dump_file, "pass_rtl_ssa_dce called\n");
+return 0;
+  }
+
+}; // class pass_fast_rtl_dce
+
+} // namespace
+
+rtl_opt_pass *
+make_pass_rtl_ssa_dce (gcc::context *ctxt)
+{
+  return new pass_rtl_ssa_dce (ctxt);
+}
diff --git a/gcc/dce.h b/gcc/dce.h
index fc92be3f51b2..167d3065369c 100644
--- a/gcc/dce.h
+++ b/gcc/dce.h
@@ -23,5 +23,6 @@ along with GCC; see the file COPYING3.  If not see
 extern void run_word_dce (void);
 extern void run_fast_dce (void);
 extern void run_fast_df_dce (void);
+extern void run_rtl_ssa_dce (void);
 
 #endif /* GCC_DCE_H */
diff --git a/gcc/passes.def b/gcc/passes.def
index 9fd85a35a63d..51ce7276da28 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -531,7 +531,7 @@ along with GCC; see the file COPYING3.  If not see
  NEXT_PASS (pass_regrename);
  NEXT_PASS (pass_fold_mem_offsets);
  NEXT_PASS (pass_cprop_hardreg);
- NEXT_PASS (pass_fast_rtl_dce);
+ NEXT_PASS (pass_rtl_ssa_dce);
  NEXT_PASS (pass_reorder_blocks);
  NEXT_PASS (pass_leaf_regs);
  NEXT_PASS (pass_split_before_sched2);
diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
index 217c31fbb09b..65639302875c 100644
--- a/gcc/tree-pass.h
+++ b/gcc/tree-pass.h
@@ -566,6 +566,7 @@ extern rtl_opt_pass *make_pass_jump2 (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_lower_subreg (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_cse (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_fast_rtl_dce (gcc::context *ctxt);
+extern rtl_opt_pass *make_pass_rtl_ssa_dce (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_ud_rtl_dce (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_rtl_dce (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_rtl_dse1 (gcc::context *ctxt);


[gcc r15-8573] gccrs: implement the TuplePattern and use it for function patterns

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:18d289ca2b1996aa76b902432941e88fa3497b6d

commit r15-8573-g18d289ca2b1996aa76b902432941e88fa3497b6d
Author: Philip Herron 
Date:   Fri Dec 13 15:51:55 2024 +

gccrs: implement the TuplePattern and use it for function patterns

In order to handle the tuple pattern of: fn test ((x _) : (i32, i32)) -> 
i32 { x }
we need to recognize that ABI wise this function still takes a tuple as the 
parameter
to this function its just how we can address the "pattern" of the tuple 
changes.

So reall if this was C it would look like:

  void test (struct tuple_type __prameter)
  {
return __parameter.0
  }

The code here reuses our existing pattern code so that we generate these 
implicit
bindings of the paramter with a field access so any time x is referenced 
it's really
just emplacing __parameter.0 for the field access into the struct which is 
a tuple.

Fixes Rust-GCC#2847

gcc/rust/ChangeLog:

* backend/rust-compile-fnparam.cc (CompileFnParam::visit): compile 
tuple patterns
(CompileSelfParam::compile): update return type
(CompileFnParam::create_tmp_param_var): return Bvariable not tree 
to stop ICE
* backend/rust-compile-fnparam.h: update prototype
* backend/rust-compile-pattern.cc (CompilePatternBindings::visit): 
implement TuplePattern
* backend/rust-compile-pattern.h: update prototype

gcc/testsuite/ChangeLog:

* rust/compile/issue-2847.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/backend/rust-compile-fnparam.cc | 31 
 gcc/rust/backend/rust-compile-fnparam.h  |  4 +-
 gcc/rust/backend/rust-compile-pattern.cc | 86 
 gcc/rust/backend/rust-compile-pattern.h  |  2 +-
 gcc/testsuite/rust/compile/issue-2847.rs |  8 +++
 5 files changed, 117 insertions(+), 14 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-fnparam.cc 
b/gcc/rust/backend/rust-compile-fnparam.cc
index c00092d219e2..b40065e110d1 100644
--- a/gcc/rust/backend/rust-compile-fnparam.cc
+++ b/gcc/rust/backend/rust-compile-fnparam.cc
@@ -68,25 +68,36 @@ CompileFnParam::visit (HIR::WildcardPattern &pattern)
   compiled_param = Backend::parameter_variable (fndecl, "_", decl_type, locus);
 }
 
+void
+CompileFnParam::visit (HIR::TuplePattern &pattern)
+{
+  compiled_param = create_tmp_param_var (decl_type);
+  CompilePatternBindings::Compile (
+pattern, Backend::var_expression (compiled_param, locus), ctx);
+}
+
 void
 CompileFnParam::visit (HIR::StructPattern &pattern)
 {
-  tree tmp_param_var = create_tmp_param_var (decl_type);
-  CompilePatternBindings::Compile (pattern, tmp_param_var, ctx);
+  compiled_param = create_tmp_param_var (decl_type);
+  CompilePatternBindings::Compile (
+pattern, Backend::var_expression (compiled_param, locus), ctx);
 }
 
 void
 CompileFnParam::visit (HIR::TupleStructPattern &pattern)
 {
-  tree tmp_param_var = create_tmp_param_var (decl_type);
-  CompilePatternBindings::Compile (pattern, tmp_param_var, ctx);
+  compiled_param = create_tmp_param_var (decl_type);
+  CompilePatternBindings::Compile (
+pattern, Backend::var_expression (compiled_param, locus), ctx);
 }
 
 void
 CompileFnParam::visit (HIR::ReferencePattern &pattern)
 {
-  tree tmp_param_var = create_tmp_param_var (decl_type);
-  CompilePatternBindings::Compile (pattern, tmp_param_var, ctx);
+  compiled_param = create_tmp_param_var (decl_type);
+  CompilePatternBindings::Compile (
+pattern, Backend::var_expression (compiled_param, locus), ctx);
 }
 
 Bvariable *
@@ -102,7 +113,7 @@ CompileSelfParam::compile (Context *ctx, tree fndecl, 
HIR::SelfParam &self,
   return Backend::parameter_variable (fndecl, "self", decl_type, locus);
 }
 
-tree
+Bvariable *
 CompileFnParam::create_tmp_param_var (tree decl_type)
 {
   // generate the anon param
@@ -110,10 +121,8 @@ CompileFnParam::create_tmp_param_var (tree decl_type)
   std::string cpp_str_identifier = std::string (IDENTIFIER_POINTER 
(tmp_ident));
 
   decl_type = Backend::immutable_type (decl_type);
-  compiled_param = Backend::parameter_variable (fndecl, cpp_str_identifier,
-   decl_type, locus);
-
-  return Backend::var_expression (compiled_param, locus);
+  return Backend::parameter_variable (fndecl, cpp_str_identifier, decl_type,
+ locus);
 }
 
 } // namespace Compile
diff --git a/gcc/rust/backend/rust-compile-fnparam.h 
b/gcc/rust/backend/rust-compile-fnparam.h
index 82a705fde7b9..189216c9ba49 100644
--- a/gcc/rust/backend/rust-compile-fnparam.h
+++ b/gcc/rust/backend/rust-compile-fnparam.h
@@ -47,12 +47,12 @@ public:
   void visit (HIR::QualifiedPathInExpression &) override {}
   void visit (HIR::RangePattern &) override {}
   void visit (HIR::SlicePattern &) override {}
-  void visit (HIR::TuplePattern &) override {}
+  void visit (HIR::Tup

[gcc(refs/users/omachota/heads/rtl-ssa-dce)] rtl-ssa: dce some prelive conditions

2025-03-21 Thread Ondrej Machota via Gcc-cvs
https://gcc.gnu.org/g:a7cb3a2146967afb3ea16590347e7197090cd18a

commit a7cb3a2146967afb3ea16590347e7197090cd18a
Author: Ondřej Machota 
Date:   Fri Feb 21 14:11:36 2025 +0100

rtl-ssa: dce some prelive conditions

Diff:
---
 gcc/dce.cc | 321 +
 1 file changed, 239 insertions(+), 82 deletions(-)

diff --git a/gcc/dce.cc b/gcc/dce.cc
index ed3231d91404..909e47b99195 100644
--- a/gcc/dce.cc
+++ b/gcc/dce.cc
@@ -17,8 +17,10 @@ You should have received a copy of the GNU General Public 
License
 along with GCC; see the file COPYING3.  If not see
 .  */
 
+#include 
 #define INCLUDE_ALGORITHM
 #define INCLUDE_FUNCTIONAL
+#define INCLUDE_ARRAY
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
@@ -30,7 +32,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "rtl-ssa.h"
 #include "memmodel.h"
 #include "tm_p.h"
-#include "emit-rtl.h"  /* FIXME: Can go away once crtl is moved to rtl.h.  */
+#include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h.  */
 #include "cfgrtl.h"
 #include "cfgbuild.h"
 #include "cfgcleanup.h"
@@ -39,6 +41,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-pass.h"
 #include "dbgcnt.h"
 #include "rtl-iter.h"
+#include 
 
 using namespace rtl_ssa;
 
@@ -1303,128 +1306,282 @@ public:
 } // namespace
 
 
-bool is_inherently_live(insn_info *insn) {
+bool sets_global_register(rtx_insn* insn) {
+  rtx set = single_set(insn);
+  if (!set)
+return false;
 
+  rtx dest = SET_DEST(set);
+  if (REG_P(dest) && HARD_REGISTER_NUM_P(REGNO(dest)) && 
global_regs[REGNO(dest)]) {
+return true;
+  }
+
+  return false;
 }
 
-static void rti_ssa_dce_() {
+bool is_prelive(insn_info *insn)
+{
+  if (insn->is_artificial()) // phis are never prelive
+return false;
+
+  /*
+   * There are a few functions we can use to detect if an instruction is
+   * inherently live:
+   * rtlanal.cc:
+   *  bool side_effects_p (const_rtx x);
+   *  bool volatile_insn_p (const_rtx x);
+   *
+   * rtlanal.h
+   *  bool has_side_effects (); inside class rtx_properties
+   *
+   * dce.cc:
+   *  static bool deletable_insn_p_1(rtx body); uses bool volatile_insn_p 
(const_rtx x);
+   *  static bool deletable_insn_p(rtx_insn *insn, bool fast, bitmap 
arg_stores);
+   * 
+   * Possibly the most accurate way would be to rewrite `static bool
+   * deletable_insn_p(rtx_insn *insn, bool fast, bitmap arg_stores);`
+   * 
+  */
+
+  // Now, we only have to handle rtx insns
+  assert(insn->is_real());
+  auto rtl = insn->rtl();
+
+  if (!INSN_P(rtl)) // This might be useless
+return false;
+
+  rtx pat = PATTERN(rtl); // if we use this instead of rtl, then rtl notes 
wont be checked
   
+  // TODO : join if statements
+
+  if (JUMP_P(rtl))
+return true;
+
+  // We need to describe all possible prelive instructions, a list of all the 
instructions is inside `rtl.def`
+
+  // Mark set of a global register
+  if (sets_global_register(rtl))
+return true;
+
+  // Call is inside side_effects_p
+  if (side_effects_p(rtl) || volatile_refs_p(rtl) || can_throw_internal(rtl))
+return true;
+
+  return false;
 }
 
 static void
-rtl_ssa_dce_init ()
+rtl_ssa_dce_init()
 {
-calculate_dominance_info (CDI_DOMINATORS);
-crtl->ssa = new rtl_ssa::function_info (cfun);
+  calculate_dominance_info(CDI_DOMINATORS);
+  // here we create ssa form for function
+  crtl->ssa = new rtl_ssa::function_info(cfun);
 }
 
 static void
-rtl_ssa_dce_done ()
+rtl_ssa_dce_done()
 {
-free_dominance_info (CDI_DOMINATORS);
-if (crtl->ssa->perform_pending_updates ())
-  cleanup_cfg (0);
+  free_dominance_info(CDI_DOMINATORS);
+  if (crtl->ssa->perform_pending_updates())
+cleanup_cfg(0);
 
-delete crtl->ssa;
-crtl->ssa = nullptr;
+  delete crtl->ssa;
+  crtl->ssa = nullptr;
 
-if (dump_file)
-  fprintf (dump_file, "\nFinished running rtl_ssa_dce\n\n");
+  if (dump_file)
+fprintf(dump_file, "\nFinished running rtl_ssa_dce\n\n");
 }
 
-static unsigned int
-rtl_ssa_dce ()
+static void
+rtl_ssa_dce_mark_live(insn_info *info, vec &worklist, 
std::unordered_set marked)
 {
-rtl_ssa_dce_init ();
+  int info_uid = info->uid();
+  if (dump_file)
+  {
+fprintf(dump_file, "  Adding insn %d to worklist\n", info_uid);
+  }
 
-insn_info *next;
-sbitmap marked;
-auto_vec worklist;
-for (insn_info *insn = crtl->ssa->first_insn (); insn; insn = next)
+  marked.emplace(info);
+  worklist.safe_push(info);
+}
+
+static auto_vec
+rtl_ssa_dce_prelive(std::unordered_set marked)
+{
+  insn_info *next;
+  auto_vec worklist;
+  for (insn_info *insn = crtl->ssa->first_insn(); insn; insn = next)
+  {
+if (dump_file)
 {
-  next = insn->next_any_insn ();
-  auto *rtl = insn->rtl();
-  /*
-  I would like to mark visited instruction with something like plf (Pass 
local flags) as in gimple
-
-  This file contains some useful functions: e.g. mark

[gcc r14-11431] gimple: sccopy: Don't increment i after vec::unordered_remove()

2025-03-21 Thread Filip Kastl via Gcc-cvs
https://gcc.gnu.org/g:13950737746e6d6503ad7f1df5a8c47010857ff8

commit r14-11431-g13950737746e6d6503ad7f1df5a8c47010857ff8
Author: Filip Kastl 
Date:   Thu Mar 20 11:54:59 2025 +0100

gimple: sccopy: Don't increment i after vec::unordered_remove()

I increment the index variable in a loop even when I do
vec::unordered_remove() which causes the vector traversal to miss some
elements.  Mikael notified me of this mistake I made in my last patch.

gcc/ChangeLog:

* gimple-ssa-sccopy.cc (scc_copy_prop::propagate): Don't
increment after vec::unordered_remove().

Reported-by: Mikael Morin 
Signed-off-by: Filip Kastl 
(cherry picked from commit a1363f8dd8037d40e9fbf04c2ba8d6d3e7e5c269)

Diff:
---
 gcc/gimple-ssa-sccopy.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-ssa-sccopy.cc b/gcc/gimple-ssa-sccopy.cc
index d4d06f3b13e7..f7e121992e5f 100644
--- a/gcc/gimple-ssa-sccopy.cc
+++ b/gcc/gimple-ssa-sccopy.cc
@@ -554,9 +554,11 @@ sccopy_propagate ()
 get removed.  That means parts of CFG get removed.  Those may
 contain copy statements.  For that reason we prune SCCs here.  */
   unsigned i;
-  for (i = 0; i < scc.length (); i++)
+  for (i = 0; i < scc.length ();)
if (gimple_bb (scc[i]) == NULL)
  scc.unordered_remove (i);
+   else
+ i++;
   if (scc.is_empty ())
{
  scc.release ();


[gcc r15-8657] libgomp/plugin: Add initial interop support to nvptx + gcn

2025-03-21 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:41b9c3b848c8cbe9cb4b9d923c4e569767284e28

commit r15-8657-g41b9c3b848c8cbe9cb4b9d923c4e569767284e28
Author: Tobias Burnus 
Date:   Fri Mar 21 21:39:42 2025 +0100

libgomp/plugin: Add initial interop support to nvptx + gcn

The interop directive operates on an opaque object that represents a
foreign runtime. This commit adds support for
this to the two offloading plugins.

For nvptx, it supports cuda, cuda_driver and hip; the latter is AMD's
version of CUDA which for Nvidia devices boils down to normal CUDA.
Thus, at the end for this limited use, cuda/cuda_driver/hip are all
the same - and for plugin-nvptx.c, the they differ only in terms of
what gets fr_id, fr_name and get_interop_type_desc return.

For gcn, it supports hip and hsa.

Regarding get-mapped-ptr-1.c: That's actually a fix for the
GOMP_interop commit r15-8654-g99e2906ae255fc that added
GOMP_DEVICE_DEFAULT_OMP_61 alias omp_default_device, which is
a conforming device number. But that test used -5 as check for a
non-conforming device number.

libgomp/ChangeLog:

* plugin/plugin-gcn.c (_LIBGOMP_PLUGIN_INCLUDE): Define.
(struct hsa_runtime_fn_info): Add two queue functions.
(hipError_t, hipCtx_t, hipStream_s, hipStream_t): New types.
(struct hip_runtime_fn_info): New.
(hip_runtime_lib, hip_fns): New global vars.
(init_environment_variables): Handle hip_runtime_lib.
(init_hsa_runtime_functions): Load the two queue functions.
(init_hip_runtime_functions, GOMP_OFFLOAD_interop,
GOMP_OFFLOAD_get_interop_int, GOMP_OFFLOAD_get_interop_ptr,
GOMP_OFFLOAD_get_interop_str,
GOMP_OFFLOAD_get_interop_type_desc): New.
* plugin/plugin-nvptx.c (_LIBGOMP_PLUGIN_INCLUDE): Define.
(GOMP_OFFLOAD_interop, GOMP_OFFLOAD_get_interop_int,
GOMP_OFFLOAD_get_interop_ptr, GOMP_OFFLOAD_get_interop_str,
GOMP_OFFLOAD_get_interop_type_desc): New.
* testsuite/libgomp.c/interop-fr-1.c: New test.
* testsuite/libgomp.c-c++-common/get-mapped-ptr-1.c: Use -6
not -5 as non-conforming device number.

Diff:
---
 libgomp/plugin/plugin-gcn.c| 464 -
 libgomp/plugin/plugin-nvptx.c  | 302 +++
 .../libgomp.c-c++-common/get-mapped-ptr-1.c|   2 +-
 libgomp/testsuite/libgomp.c/interop-fr-1.c | 577 +
 4 files changed, 1342 insertions(+), 3 deletions(-)

diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c
index 5c65778191a6..4b42a597cbdd 100644
--- a/libgomp/plugin/plugin-gcn.c
+++ b/libgomp/plugin/plugin-gcn.c
@@ -41,7 +41,9 @@
 #include 
 #include 
 #include 
+#define _LIBGOMP_PLUGIN_INCLUDE 1
 #include "libgomp-plugin.h"
+#undef _LIBGOMP_PLUGIN_INCLUDE
 #include "config/gcn/libgomp-gcn.h"  /* For struct output.  */
 #include "gomp-constants.h"
 #include 
@@ -190,6 +192,8 @@ struct hsa_runtime_fn_info
   uint64_t (*hsa_queue_add_write_index_release_fn) (const hsa_queue_t *queue,
uint64_t value);
   uint64_t (*hsa_queue_load_read_index_acquire_fn) (const hsa_queue_t *queue);
+  uint64_t (*hsa_queue_load_read_index_relaxed_fn) (const hsa_queue_t *queue);
+  uint64_t (*hsa_queue_load_write_index_relaxed_fn) (const hsa_queue_t *queue);
   void (*hsa_signal_store_relaxed_fn) (hsa_signal_t signal,
   hsa_signal_value_t value);
   void (*hsa_signal_store_release_fn) (hsa_signal_t signal,
@@ -216,6 +220,25 @@ struct hsa_runtime_fn_info
  const hsa_signal_t *dep_signals, hsa_signal_t completion_signal);
 };
 
+/* As an HIP runtime is dlopened, following structure defines function
+   pointers utilized by the interop feature of this plugin.
+   Add suffient type declarations to get this work.  */
+
+typedef int hipError_t;  /* Actually an enum; 0 == success. */
+typedef void* hipCtx_t;
+struct hipStream_s;
+typedef struct hipStream_s* hipStream_t;
+
+struct hip_runtime_fn_info
+{
+  hipError_t (*hipStreamCreate_fn) (hipStream_t *);
+  hipError_t (*hipStreamDestroy_fn) (hipStream_t);
+  hipError_t (*hipStreamSynchronize_fn) (hipStream_t);
+  hipError_t (*hipCtxGetCurrent_fn) (hipCtx_t *ctx);
+  hipError_t (*hipSetDevice_fn) (int deviceId);
+  hipError_t (*hipGetDevice_fn) (int *deviceId);
+};
+
 /* Structure describing the run-time and grid properties of an HSA kernel
lauch.  This needs to match the format passed to GOMP_OFFLOAD_run.  */
 
@@ -553,9 +576,11 @@ struct hsa_context_info
 static struct hsa_context_info hsa_context;
 
 /* HSA runtime functions that are initialized in init_hsa_context.  */
-
 static struct hsa_runtime_fn_info hsa_fns;
 
+/* HIP runtime functions that are initialized in init_hip_runtime_functions.  
*/
+static struct hip_runtime_fn_info hip_fns;
+
 

[gcc r15-8643] testsuite/lib/libgomp.exp: compile with -fdiagnostics-plain-output

2025-03-21 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:12db61156f6d8539afb4e3570e23cd9f6a178cd0

commit r15-8643-g12db61156f6d8539afb4e3570e23cd9f6a178cd0
Author: Tobias Burnus 
Date:   Fri Mar 21 13:54:49 2025 +0100

testsuite/lib/libgomp.exp: compile with -fdiagnostics-plain-output

libgomp.exp added -fno-diagnostics-show-caret and -fdiagnostics-color=never
as 'additional_flags' for compilation. However, it turned out that this now
is insufficient as the [...] part of diagnostics have a hyperlink URL.

Solution: Use the -fdiagnostics-plain-output flag instead, added in commit
r11-2701-g129a1319c0ab73. This flag currently implies the following flags:
   -fno-diagnostics-show-caret
   -fno-diagnostics-show-line-numbers
   -fdiagnostics-color=never
   -fdiagnostics-urls=never
   -fdiagnostics-path-format=separate-events
   -fdiagnostics-text-art-charset=none
   -fno-diagnostics-show-event-links

libgomp/ChangeLog:

* testsuite/lib/libgomp.exp (libgomp_init): Add
-fdiagnostics-plain-output to additional_flags; remove
-fno-diagnostics-show-caret and -fdiagnostics-color=never.

Diff:
---
 libgomp/testsuite/lib/libgomp.exp | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/libgomp/testsuite/lib/libgomp.exp 
b/libgomp/testsuite/lib/libgomp.exp
index fd21371dce81..bc38e3ca6d98 100644
--- a/libgomp/testsuite/lib/libgomp.exp
+++ b/libgomp/testsuite/lib/libgomp.exp
@@ -233,11 +233,8 @@ proc libgomp_init { args } {
 # error-message parsing machinery.
 lappend ALWAYS_CFLAGS "additional_flags=-fmessage-length=0"
 
-# Disable caret
-lappend ALWAYS_CFLAGS "additional_flags=-fno-diagnostics-show-caret"
-
-# Disable color diagnostics
-lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
+# Disable caret, color, URL diagnostics
+lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-plain-output"
 
 # Help GCC to find offload compilers' 'mkoffload'.
 global offload_additional_options


[gcc r15-8650] Fortran: Implement the F2018 reduce intrinsic [PR85836]

2025-03-21 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:94fa9f4d27bac577ecab43379a31fa28b146d6d9

commit r15-8650-g94fa9f4d27bac577ecab43379a31fa28b146d6d9
Author: Paul Thomas 
Date:   Fri Mar 21 16:20:21 2025 +

Fortran:  Implement the F2018 reduce intrinsic [PR85836]

2025-03-21  Paul Thomas  

gcc/fortran
PR fortran/85836
* check.cc (get_ul_from_cst_cl): New function used in
check_operation.
(check_operation): New function used in check_reduce and
check_co_reduce.
(gfc_check_co_reduce): Use it.
(gfc_check_reduce): New function.
(gfc_check_rename): Add prototype for intrinsic with 6 arguments.
* gfortran.h : Add isym id for reduce and prototype for f6.
* intrinsic.cc (do_check): Add another argument expression and use
it in the call to the six argument specific check.
(add_sym_6): New function.
(add_functions): Add the discription of the reduce intrinsic and
add it to the intrinsic list.
* intrinsic.h : Add prototypes for gfc_check_reduce and
gfc_resolve_reduce.
* iresolve.cc (generate_reduce_op_wrapper): Generate a wrapper
subroutine for the 'operation' function to enable the library
implementation to be type agnostic and use pointer arithmetic
throughout.
(gfc_resolve_reduce): New function.
* trans-expr.cc (gfc_conv_procedure_call): Add flag for scalar
reduce. Generate a return variable 'sr' for scalar reduce, pass its
address to the library function and return it as the scalar result.
* trans-intrinsic.cc (gfc_conv_intrinsic_function): Array valued
reduce is called in same way as reshape. Fall through for call to
the scalar version.

gcc/testsuite/
PR fortran/85836
* gfortran.dg/reduce_1.f90: New test
* gfortran.dg/reduce_2.f90: New test

libgfortran/
PR libfortran/85836
* Makefile.am : Add reduce.c
* Makefile.in : Regenerated
* gfortran.map : Add _gfortran_reduce, _gfortran_reduce_scalar,
_gfortran_reduce_c and _gfortran_reduce_scalar_c to the list.
* intrinsics/reduce.c (reduce, reduce_scalar, reduce_c,
reduce_scalar_c): New functions and prototypes

Diff:
---
 gcc/fortran/check.cc   | 159 --
 gcc/fortran/gfortran.h |   3 +
 gcc/fortran/intrinsic.cc   |  65 +++-
 gcc/fortran/intrinsic.h|   4 +
 gcc/fortran/iresolve.cc| 214 
 gcc/fortran/trans-expr.cc  |  30 +++-
 gcc/fortran/trans-intrinsic.cc |   3 +
 gcc/testsuite/gfortran.dg/reduce_1.f90 | 202 +++
 gcc/testsuite/gfortran.dg/reduce_2.f90 | 145 +
 libgfortran/Makefile.am|   1 +
 libgfortran/Makefile.in|   7 +-
 libgfortran/gfortran.map   |   4 +
 libgfortran/intrinsics/reduce.c| 286 +
 13 files changed, 1070 insertions(+), 53 deletions(-)

diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc
index 35458643835c..d2c8816da2b4 100644
--- a/gcc/fortran/check.cc
+++ b/gcc/fortran/check.cc
@@ -2442,31 +2442,24 @@ gfc_check_co_broadcast (gfc_expr *a, gfc_expr 
*source_image, gfc_expr *stat,
 }
 
 
-bool
-gfc_check_co_reduce (gfc_expr *a, gfc_expr *op, gfc_expr *result_image,
-gfc_expr *stat, gfc_expr *errmsg)
+/* Helper function for character arguments in gfc_check_[co_]reduce.  */
+
+static unsigned long
+get_ul_from_cst_cl (const gfc_charlen *cl)
+{
+  return cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
+? mpz_get_ui (cl->length->value.integer) : 0;
+};
+
+
+/* Checks shared between co_reduce and reduce.  */
+static bool
+check_operation (gfc_expr *op, gfc_expr *a, bool is_co_reduce)
 {
   symbol_attribute attr;
   gfc_formal_arglist *formal;
   gfc_symbol *sym;
 
-  if (a->ts.type == BT_CLASS)
-{
-  gfc_error ("The A argument at %L of CO_REDUCE shall not be polymorphic",
-&a->where);
-  return false;
-}
-
-  if (gfc_expr_attr (a).alloc_comp)
-{
-  gfc_error ("Support for the A argument at %L with allocatable components"
- " is not yet implemented", &a->where);
-  return false;
-}
-
-  if (!check_co_collective (a, result_image, stat, errmsg, true))
-return false;
-
   if (!gfc_resolve_expr (op))
 return false;
 
@@ -2483,8 +2476,9 @@ gfc_check_co_reduce (gfc_expr *a, gfc_expr *op, gfc_expr 
*result_image,
   /* None of the intrinsics fulfills the criteria of taking two arguments,
 returning the same type and kind as the arguments and being permitted
 as actual argument.  */
-  gfc_error ("Intrinsic function %s at %L i

[gcc r15-8574] gccrs: Made changes to AST::TraitImpl constructor for TypePath

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:6b27b7807545d985abde8a332c9f37e0d8657fb8

commit r15-8574-g6b27b7807545d985abde8a332c9f37e0d8657fb8
Author: Sri Ganesh Thota 
Date:   Tue Dec 10 18:38:27 2024 +0530

gccrs: Made changes to AST::TraitImpl constructor for TypePath

gcc/rust/ChangeLog:

* ast/rust-item.h: I have changed helper constructor for typepath
to be a delegating constructor.

Signed-off-by: Sri Ganesh Thota 

Diff:
---
 gcc/rust/ast/rust-item.h | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index dca4aab45c83..6b77449eb8d4 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -3197,19 +3197,18 @@ public:
   trait_path (std::move (trait_path)), impl_items (std::move (impl_items))
   {}
 
-  // Helper constructor with a typepath
+  // Delegating constructor for TypePath
   TraitImpl (TypePath trait_path, bool is_unsafe, bool has_exclam,
 std::vector> impl_items,
 std::vector> generic_params,
 std::unique_ptr trait_type, WhereClause where_clause,
 Visibility vis, std::vector inner_attrs,
 std::vector outer_attrs, location_t locus)
-: Impl (std::move (generic_params), std::move (trait_type),
-   std::move (where_clause), std::move (vis), std::move (inner_attrs),
-   std::move (outer_attrs), locus),
-  has_unsafe (is_unsafe), has_exclam (has_exclam),
-  trait_path (std::unique_ptr (new TypePath (trait_path))),
-  impl_items (std::move (impl_items))
+: TraitImpl (std::unique_ptr (new TypePath (trait_path)), is_unsafe,
+has_exclam, std::move (impl_items), std::move (generic_params),
+std::move (trait_type), std::move (where_clause),
+std::move (vis), std::move (inner_attrs),
+std::move (outer_attrs), locus)
   {}
 
   // Copy constructor with vector clone


[gcc r15-8599] gccrs: nr2.0: Resolve Self inside impl blocks

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:2fa9719068774ab7ec5ed4cbe95cfe30fa94dbb1

commit r15-8599-g2fa9719068774ab7ec5ed4cbe95cfe30fa94dbb1
Author: Owen Avery 
Date:   Tue Jan 7 14:03:13 2025 -0500

gccrs: nr2.0: Resolve Self inside impl blocks

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Insert a definition for Self when visiting
InherentImpl and TraitImpl instances.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Add visitors for InherentImpl and TraitImpl.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery 

Diff:
---
 .../resolve/rust-toplevel-name-resolver-2.0.cc | 26 ++
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h |  2 ++
 gcc/testsuite/rust/compile/nr2/exclude |  3 ---
 3 files changed, 28 insertions(+), 3 deletions(-)

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 4aca709263c6..4c6664f104b4 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -103,6 +103,32 @@ TopLevel::visit (AST::Trait &trait)
   DefaultResolver::visit (trait);
 }
 
+void
+TopLevel::visit (AST::InherentImpl &impl)
+{
+  auto inner_fn = [this, &impl] () {
+insert_or_error_out (Identifier ("Self", impl.get_type ().get_locus ()),
+impl.get_type (), Namespace::Types);
+
+AST::DefaultASTVisitor::visit (impl);
+  };
+
+  ctx.scoped (Rib::Kind::TraitOrImpl, impl.get_node_id (), inner_fn);
+}
+
+void
+TopLevel::visit (AST::TraitImpl &impl)
+{
+  auto inner_fn = [this, &impl] () {
+insert_or_error_out (Identifier ("Self", impl.get_type ().get_locus ()),
+impl.get_type (), Namespace::Types);
+
+AST::DefaultASTVisitor::visit (impl);
+  };
+
+  ctx.scoped (Rib::Kind::TraitOrImpl, impl.get_node_id (), inner_fn);
+}
+
 void
 TopLevel::visit (AST::TraitItemType &trait_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 64d2174a7bee..fabcb5bf7073 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -148,6 +148,8 @@ private:
 
   void visit (AST::Module &module) override;
   void visit (AST::Trait &trait) override;
+  void visit (AST::InherentImpl &impl) override;
+  void visit (AST::TraitImpl &impl) override;
   void visit (AST::TraitItemType &trait_item) override;
   void visit (AST::MacroRulesDefinition ¯o) override;
   void visit (AST::Function &function) override;
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index af7d105debc3..9b1ee7ceaf99 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -39,13 +39,11 @@ generics6.rs
 generics9.rs
 if_let_expr.rs
 issue-1019.rs
-issue-1031.rs
 issue-1034.rs
 issue-1129-2.rs
 issue-1130.rs
 issue-1173.rs
 issue-1272.rs
-issue-1289.rs
 issue-1447.rs
 issue-1483.rs
 issue-1725-1.rs
@@ -85,7 +83,6 @@ issue-855.rs
 issue-925.rs
 iterators1.rs
 lookup_err1.rs
-macros/mbe/macro-issue1233.rs
 macros/mbe/macro-issue1400.rs
 macros/mbe/macro13.rs
 macros/mbe/macro15.rs


[gcc r15-8601] gccrs: Allow float type to be casted as integer type

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:1cad5f2bed18f673112e3b256c64c836fde2550a

commit r15-8601-g1cad5f2bed18f673112e3b256c64c836fde2550a
Author: Nobel 
Date:   Sat Dec 21 23:56:39 2024 +0545

gccrs: Allow float type to be casted as integer type

gccrs now should be able to cast float types as numeric.

gcc/rust/ChangeLog:

* typecheck/rust-casts.cc (TypeCastRules::cast_rules): Add rule.

gcc/testsuite/ChangeLog:

* rust/compile/cast_float_as_integer.rs: New test.

Signed-off-by: Nobel Singh 

Diff:
---
 gcc/rust/typecheck/rust-casts.cc|  6 ++
 gcc/testsuite/rust/compile/cast_float_as_integer.rs | 10 ++
 2 files changed, 16 insertions(+)

diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc
index 694cbaa5db60..90bdef1fd3c1 100644
--- a/gcc/rust/typecheck/rust-casts.cc
+++ b/gcc/rust/typecheck/rust-casts.cc
@@ -235,6 +235,12 @@ TypeCastRules::cast_rules ()
 case TyTy::TypeKind::FLOAT:
   switch (to.get_ty ()->get_kind ())
{
+   case TyTy::TypeKind::USIZE:
+   case TyTy::TypeKind::ISIZE:
+   case TyTy::TypeKind::UINT:
+   case TyTy::TypeKind::INT:
+ return TypeCoercionRules::CoercionResult{{}, to.get_ty ()->clone ()};
+
case TyTy::TypeKind::FLOAT:
  return TypeCoercionRules::CoercionResult{{}, to.get_ty ()->clone ()};
 
diff --git a/gcc/testsuite/rust/compile/cast_float_as_integer.rs 
b/gcc/testsuite/rust/compile/cast_float_as_integer.rs
new file mode 100644
index ..e6b86db8a664
--- /dev/null
+++ b/gcc/testsuite/rust/compile/cast_float_as_integer.rs
@@ -0,0 +1,10 @@
+// { dg-options "-w" }
+fn main(){
+let foo:f64 = 13.37;
+let _ = foo as i64;
+let _ = foo as u64;
+let _ = foo as isize;
+let _ = foo as usize;
+let _ = foo as i8;
+let _ = foo as u8;
+}


[gcc r15-8618] gccrs: collect-lang-items: Display attribute upon error finding it

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:20d4c59e248faf86d34c2525901951ee88163a66

commit r15-8618-g20d4c59e248faf86d34c2525901951ee88163a66
Author: Arthur Cohen 
Date:   Fri Jan 3 15:45:39 2025 +

gccrs: collect-lang-items: Display attribute upon error finding it

gcc/rust/ChangeLog:

* ast/rust-collect-lang-items.cc (get_lang_item_attr): Show unknown 
attribute upon error.

Diff:
---
 gcc/rust/ast/rust-collect-lang-items.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/ast/rust-collect-lang-items.cc 
b/gcc/rust/ast/rust-collect-lang-items.cc
index 50d134a429f5..168123ee56eb 100644
--- a/gcc/rust/ast/rust-collect-lang-items.cc
+++ b/gcc/rust/ast/rust-collect-lang-items.cc
@@ -36,7 +36,8 @@ get_lang_item_attr (const T &maybe_lang_item)
   const auto &str_path = attr.get_path ().as_string ();
   if (!Analysis::Attributes::is_known (str_path))
{
- rust_error_at (attr.get_locus (), "unknown attribute");
+ rust_error_at (attr.get_locus (), "unknown attribute %qs",
+str_path.c_str ());
  continue;
}


[gcc r15-8617] gccrs: attributes: Add #[derive] as a built-in attribute

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:1d0be889267e3b3c58d97148640c0d46bc19253e

commit r15-8617-g1d0be889267e3b3c58d97148640c0d46bc19253e
Author: Arthur Cohen 
Date:   Fri Jan 3 15:45:57 2025 +

gccrs: attributes: Add #[derive] as a built-in attribute

gcc/rust/ChangeLog:

* util/rust-attribute-values.h: Declare new attribute value.
* util/rust-attributes.cc: Use it.

Diff:
---
 gcc/rust/util/rust-attribute-values.h | 1 +
 gcc/rust/util/rust-attributes.cc  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/gcc/rust/util/rust-attribute-values.h 
b/gcc/rust/util/rust-attribute-values.h
index ef01e67dc528..9ef5cc52e81a 100644
--- a/gcc/rust/util/rust-attribute-values.h
+++ b/gcc/rust/util/rust-attribute-values.h
@@ -29,6 +29,7 @@ public:
   static constexpr auto &COLD = "cold";
   static constexpr auto &CFG = "cfg";
   static constexpr auto &CFG_ATTR = "cfg_attr";
+  static constexpr auto &DERIVE_ATTR = "derive";
   static constexpr auto &DEPRECATED = "deprecated";
   static constexpr auto &ALLOW = "allow";
   static constexpr auto &ALLOW_INTERNAL_UNSTABLE = "allow_internal_unstable";
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 9f63234112c5..03452c75bd8a 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -46,6 +46,7 @@ static const BuiltinAttrDefinition __definitions[]
  {Attrs::COLD, CODE_GENERATION},
  {Attrs::CFG, EXPANSION},
  {Attrs::CFG_ATTR, EXPANSION},
+ {Attrs::DERIVE_ATTR, EXPANSION},
  {Attrs::DEPRECATED, STATIC_ANALYSIS},
  {Attrs::ALLOW, STATIC_ANALYSIS},
  {Attrs::ALLOW_INTERNAL_UNSTABLE, STATIC_ANALYSIS},


[gcc r15-8652] Fortran: Fix typo in error message.

2025-03-21 Thread Jerry DeLisle via Gcc-cvs
https://gcc.gnu.org/g:00cbf03029267b3bdfb696aa09c9a36dbeeb51aa

commit r15-8652-g00cbf03029267b3bdfb696aa09c9a36dbeeb51aa
Author: Jerry DeLisle 
Date:   Fri Mar 21 10:13:37 2025 -0700

Fortran: Fix typo in error message.

PR fortran/119403

gcc/fortran/ChangeLog:

* interface.cc (compare_parameter): Fix typo.

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

diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc
index c59ed1f5306c..6258a41cb596 100644
--- a/gcc/fortran/interface.cc
+++ b/gcc/fortran/interface.cc
@@ -2494,7 +2494,7 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
{
  if (formal->attr.artificial)
gfc_error_opt (0, "Interface mismatch in dummy procedure "
-  "at %L conflichts with %L: %s", &actual->where,
+  "at %L conflicts with %L: %s", &actual->where,
   &formal->declared_at, err);
  else
gfc_error_opt (0, "Interface mismatch in dummy procedure %qs at 
"


[gcc r15-8494] icf: Punt for musttail call flag differences in ICF [PR119376]

2025-03-21 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:28caa267dc757d80ffe37d638d981d3572c164ae

commit r15-8494-g28caa267dc757d80ffe37d638d981d3572c164ae
Author: Jakub Jelinek 
Date:   Fri Mar 21 12:18:35 2025 +0100

icf: Punt for musttail call flag differences in ICF [PR119376]

The following testcase shows we were ignoring musttail flags on calls
when deciding if two functions are the same.
That can result in problems in both directions, either we silently
lose musttail attribute because there is a similar function without it
earlier and then we e.g. don't diagnose if it can't be tail called
or don't try harder to do a tail call, or we get it even in functions
which didn't have it before.

The following patch for now just punts if it differs.  Perhaps we could
just merge it and get musttail flag if any of the merged functions had
one in such position, but it feels to me that it is now too late in GCC 15
cycle to play with this.

2025-03-21  Jakub Jelinek  

PR ipa/119376
* ipa-icf-gimple.cc (func_checker::compare_gimple_call): Return 
false
for gimple_call_must_tail_p mismatches.

* c-c++-common/musttail27.c: New test.

Diff:
---
 gcc/ipa-icf-gimple.cc   |  3 ++-
 gcc/testsuite/c-c++-common/musttail27.c | 31 +++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/gcc/ipa-icf-gimple.cc b/gcc/ipa-icf-gimple.cc
index 51ca8a3e1143..ac169868076c 100644
--- a/gcc/ipa-icf-gimple.cc
+++ b/gcc/ipa-icf-gimple.cc
@@ -708,7 +708,8 @@ func_checker::compare_gimple_call (gcall *s1, gcall *s2)
   || gimple_call_from_thunk_p (s1) != gimple_call_from_thunk_p (s2)
   || gimple_call_from_new_or_delete (s1) != gimple_call_from_new_or_delete 
(s2)
   || gimple_call_va_arg_pack_p (s1) != gimple_call_va_arg_pack_p (s2)
-  || gimple_call_alloca_for_var_p (s1) != gimple_call_alloca_for_var_p 
(s2))
+  || gimple_call_alloca_for_var_p (s1) != gimple_call_alloca_for_var_p (s2)
+  || gimple_call_must_tail_p (s1) != gimple_call_must_tail_p (s2))
 return false;
 
   unsigned check_arg_types_from = 0;
diff --git a/gcc/testsuite/c-c++-common/musttail27.c 
b/gcc/testsuite/c-c++-common/musttail27.c
new file mode 100644
index ..2a92bcbdfa7d
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/musttail27.c
@@ -0,0 +1,31 @@
+/* PR ipa/119376 */
+/* { dg-do compile { target musttail } } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times "  \[^\n\r]* = foo \\\(\[^\n\r]*\\\); 
\\\[tail call\\\] \\\[must tail call\\\]" 2 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "  \[^\n\r]* = foo \\\(\[^\n\r]*\\\); 
\\\[tail call\\\]" 4 "optimized" } } */
+
+int foo (int);
+
+int
+bar (int x)
+{
+  [[gnu::musttail]] return foo (x + 1);
+}
+
+int
+baz (int x)
+{
+  return foo (x + 1);
+}
+
+int
+qux (int x)
+{
+  return foo (x + 2);
+}
+
+int
+corge (int x)
+{
+  [[gnu::musttail]] return foo (x + 2);
+}


[gcc r15-8659] libgomp.fortran/get-mapped-ptr-1.f90: Use -6 for non-conf dev number

2025-03-21 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:c264df142a850b47135c0c4639d3a539b23149c5

commit r15-8659-gc264df142a850b47135c0c4639d3a539b23149c5
Author: Tobias Burnus 
Date:   Sat Mar 22 00:36:44 2025 +0100

libgomp.fortran/get-mapped-ptr-1.f90: Use -6 for non-conf dev number

This is a fix for the GOMP_interop commit r15-8654-g99e2906ae255fc that
added GOMP_DEVICE_DEFAULT_OMP_61 alias omp_default_device, which is a
conforming device number. But that test used -5 as check for a
non-conforming device number.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/get-mapped-ptr-1.f90: Use -6
not -5 as non-conforming device number.

Diff:
---
 libgomp/testsuite/libgomp.fortran/get-mapped-ptr-1.f90 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libgomp/testsuite/libgomp.fortran/get-mapped-ptr-1.f90 
b/libgomp/testsuite/libgomp.fortran/get-mapped-ptr-1.f90
index 9b6334f50d84..be60accbfecd 100644
--- a/libgomp/testsuite/libgomp.fortran/get-mapped-ptr-1.f90
+++ b/libgomp/testsuite/libgomp.fortran/get-mapped-ptr-1.f90
@@ -19,7 +19,7 @@ program main
   if (omp_target_associate_ptr (c_loc (q), p, c_sizeof (q), &
 0_c_size_t, d) == 0) then
 
-if(c_associated (omp_get_mapped_ptr (c_loc (q), -5))) &
+if(c_associated (omp_get_mapped_ptr (c_loc (q), -6))) &
   stop 1
 
 if(c_associated (omp_get_mapped_ptr (c_loc (q), &


[gcc/devel/omp/gcc-14] Fix spurious visibility error with partially parameterized formal package

2025-03-21 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:0e3fd8c1e2adaa176205df556d91800e5070c073

commit 0e3fd8c1e2adaa176205df556d91800e5070c073
Author: Eric Botcazou 
Date:   Wed Mar 19 08:22:33 2025 +0100

Fix spurious visibility error with partially parameterized formal package

This is not a regression but the issue is quite annoying and the fix is
trivial.  The problem is that a formal parameter covered by a box in the
formal package is not visible in the instance when it comes after another
formal parameter that is also a formal package.

It comes from a discrepancy internal to Instantiate_Formal_Package, where
a specific construct (the abbreviated instance) built for the nested formal
package discombobulates the processing done for the outer formal package.

gcc/ada/
* gen_il-gen-gen_nodes.adb (N_Formal_Package_Declaration): Use
N_Declaration instead of Node_Kind as ancestor.
* sem_ch12.adb (Get_Formal_Entity): Remove obsolete alternative.
(Instantiate_Formal_Package): Take into account the abbreviated
instances in the main loop running over the actuals of the local
package created for the formal package.

gcc/testsuite/
* gnat.dg/generic_inst14.adb: New test.
* gnat.dg/generic_inst14_pkg.ads: New helper.
* gnat.dg/generic_inst14_pkg-child.ads: Likewise.

Diff:
---
 gcc/ada/gen_il-gen-gen_nodes.adb   |  2 +-
 gcc/ada/sem_ch12.adb   | 31 ++
 gcc/testsuite/gnat.dg/generic_inst14.adb   | 20 ++
 gcc/testsuite/gnat.dg/generic_inst14_pkg-child.ads | 27 +++
 gcc/testsuite/gnat.dg/generic_inst14_pkg.ads   | 16 +++
 5 files changed, 90 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/gen_il-gen-gen_nodes.adb b/gcc/ada/gen_il-gen-gen_nodes.adb
index 722800254987..09fbf41cc57f 100644
--- a/gcc/ada/gen_il-gen-gen_nodes.adb
+++ b/gcc/ada/gen_il-gen-gen_nodes.adb
@@ -1441,7 +1441,7 @@ begin -- Gen_IL.Gen.Gen_Nodes
 
Cc (N_Formal_Ordinary_Fixed_Point_Definition, Node_Kind);
 
-   Cc (N_Formal_Package_Declaration, Node_Kind,
+   Cc (N_Formal_Package_Declaration, N_Declaration,
(Sy (Defining_Identifier, Node_Id),
 Sy (Name, Node_Id, Default_Empty),
 Sy (Generic_Associations, List_Id, Default_No_List),
diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index c06377ab4c9c..c04a8795d583 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -10677,6 +10677,7 @@ package body Sem_Ch12 is
 
   function Get_Formal_Entity (N : Node_Id) return Entity_Id is
  Kind : constant Node_Kind := Nkind (Original_Node (N));
+
   begin
  case Kind is
 when N_Formal_Object_Declaration =>
@@ -10691,9 +10692,6 @@ package body Sem_Ch12 is
 when N_Formal_Package_Declaration =>
return Defining_Identifier (Original_Node (N));
 
-when N_Generic_Package_Declaration =>
-   return Defining_Identifier (Original_Node (N));
-
 --  All other declarations are introduced by semantic analysis and
 --  have no match in the actual.
 
@@ -10932,6 +10930,26 @@ package body Sem_Ch12 is
   end if;
 
   Next_Non_Pragma (Formal_Node);
+
+  --  If the actual of the local package created for the formal
+  --  is itself an instantiated formal package, then it could
+  --  have given rise to additional declarations, see the code
+  --  dealing with conformance checking below.
+
+  if Nkind (Actual_Of_Formal) = N_Package_Renaming_Declaration
+and then Requires_Conformance_Checking
+   (Declaration_Node
+ (Associated_Formal_Package
+   (Defining_Entity (Actual_Of_Formal
+  then
+ Next (Actual_Of_Formal);
+ pragma Assert
+   (Nkind (Actual_Of_Formal) = N_Package_Declaration);
+ Next (Actual_Of_Formal);
+ pragma Assert
+   (Nkind (Actual_Of_Formal) = N_Package_Instantiation);
+  end if;
+
   Next (Actual_Of_Formal);
 
   --  A formal subprogram may be overloaded, so advance in
@@ -10987,11 +11005,14 @@ package body Sem_Ch12 is
  --  checking, because it contains formal declarations for those
  --  defaulted parameters, and those should not reach the back-end.
 
+ --  This processing needs to be synchronized with the pattern matching
+ --  done in the main loop of the above block that starts with the test
+ --  on Requires_Conformance_Checking.
+
  if Requires_Conformance_Checking (Formal) then
 declare
   

[gcc/devel/omp/gcc-14] d: Merge upstream dmd, druntime af92b68a81, phobos c970ca67f

2025-03-21 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:1be389b92d77ca668fc4393ad0eea019986430d8

commit 1be389b92d77ca668fc4393ad0eea019986430d8
Author: Iain Buclaw 
Date:   Thu Mar 20 01:09:13 2025 +0100

d: Merge upstream dmd, druntime af92b68a81, phobos c970ca67f

D front-end changes:

- Import dmd v2.108.1.

D runtime changes:

- Import druntime v2.108.1.

Phobos changes:

- Import phobos v2.108.1.

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd af92b68a81.
* dmd/VERSION: Bump version to v2.108.1.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime af92b68a81.
* src/MERGE: Merge upstream phobos c970ca67f.

Diff:
---
 gcc/d/dmd/MERGE|   2 +-
 gcc/d/dmd/VERSION  |   2 +-
 gcc/d/dmd/cparse.d |  70 --
 gcc/d/dmd/escape.d |  16 +-
 gcc/d/dmd/expressionsem.d  |   3 +-
 gcc/d/dmd/initsem.d|  17 +-
 gcc/d/dmd/traits.d |   2 +-
 .../gdc.test/compilable/returnscope_without_safe.d |  16 ++
 gcc/testsuite/gdc.test/compilable/test24479.d  |  35 +++
 .../gdc.test/runnable/imports/issue18919b.d|   6 +
 gcc/testsuite/gdc.test/runnable/issue18919.d   |   4 +
 gcc/testsuite/gdc.test/runnable/test24498.d|  21 ++
 libphobos/libdruntime/MERGE|   2 +-
 .../libdruntime/core/internal/array/construction.d |  17 +-
 libphobos/src/MERGE|   2 +-
 libphobos/src/std/internal/test/range.d|  91 +++
 libphobos/src/std/logger/core.d|   6 +-
 libphobos/src/std/range/package.d  | 262 ++---
 18 files changed, 508 insertions(+), 66 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index dc47db87a80c..4041ed9ea765 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-b65767825f365dbc153457fc86e1054b03196c6d
+af92b68a81888702896620db1d10ee477b6b31e8
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/gcc/d/dmd/VERSION b/gcc/d/dmd/VERSION
index 5868b8749552..99582f5e05fa 100644
--- a/gcc/d/dmd/VERSION
+++ b/gcc/d/dmd/VERSION
@@ -1 +1 @@
-v2.108.0
+v2.108.1
diff --git a/gcc/d/dmd/cparse.d b/gcc/d/dmd/cparse.d
index aeedb493efc3..bfd28c475202 100644
--- a/gcc/d/dmd/cparse.d
+++ b/gcc/d/dmd/cparse.d
@@ -1919,6 +1919,14 @@ final class CParser(AST) : Parser!AST
 auto s = cparseFunctionDefinition(id, dt.isTypeFunction(), 
specifier);
 typedefTab.setDim(typedefTabLengthSave);
 symbols = symbolsSave;
+if (specifier.mod & MOD.x__stdcall)
+{
+// If this function is __stdcall, wrap it in a 
LinkDeclaration so that
+// it's extern(Windows) when imported in D.
+auto decls = new AST.Dsymbols(1);
+(*decls)[0] = s;
+s = new AST.LinkDeclaration(s.loc, LINK.windows, decls);
+}
 symbols.push(s);
 return;
 }
@@ -2071,13 +2079,14 @@ final class CParser(AST) : Parser!AST
 }
 }
 s = applySpecifier(s, specifier);
-if (level == LVL.local)
+if (level == LVL.local || (specifier.mod & MOD.x__stdcall))
 {
-// Wrap the declaration in `extern (C) { declaration }`
+// Wrap the declaration in `extern (C/Windows) { 
declaration }`
 // Necessary for function pointers, but harmless to apply 
to all.
 auto decls = new AST.Dsymbols(1);
 (*decls)[0] = s;
-s = new AST.LinkDeclaration(s.loc, linkage, decls);
+const lkg = specifier.mod & MOD.x__stdcall ? LINK.windows 
: linkage;
+s = new AST.LinkDeclaration(s.loc, lkg, decls);
 }
 symbols.push(s);
 }
@@ -5860,13 +5869,15 @@ final class CParser(AST) : Parser!AST
 
 const(char)* endp = &slice[length - 7];
 
+AST.Dsymbols newSymbols;
+
 size_t[void*] defineTab;// hash table of #define's turned into 
Symbol's
-// indexed by Identifier, returns index 
into symbols[]
+// indexed by Identifier, returns index 
into newSymbols[]
 // The memory for this is leaked
 
-void addVar(AST.Dsymbol s)
+void addSym(AST.Dsymbol s)
 {
-//printf("addVar() %s\n", s.toChars());
+//printf("addSym() %s\n", s.toChars());
 if (auto v = s.is

[gcc/devel/omp/gcc-14] gimple: sccopy: Don't increment i after vec::unordered_remove()

2025-03-21 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:4e7772294074b78a4f06061ed53c605d8c98bbeb

commit 4e7772294074b78a4f06061ed53c605d8c98bbeb
Author: Filip Kastl 
Date:   Thu Mar 20 11:54:59 2025 +0100

gimple: sccopy: Don't increment i after vec::unordered_remove()

I increment the index variable in a loop even when I do
vec::unordered_remove() which causes the vector traversal to miss some
elements.  Mikael notified me of this mistake I made in my last patch.

gcc/ChangeLog:

* gimple-ssa-sccopy.cc (scc_copy_prop::propagate): Don't
increment after vec::unordered_remove().

Reported-by: Mikael Morin 
Signed-off-by: Filip Kastl 
(cherry picked from commit a1363f8dd8037d40e9fbf04c2ba8d6d3e7e5c269)

Diff:
---
 gcc/gimple-ssa-sccopy.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-ssa-sccopy.cc b/gcc/gimple-ssa-sccopy.cc
index d4d06f3b13e7..f7e121992e5f 100644
--- a/gcc/gimple-ssa-sccopy.cc
+++ b/gcc/gimple-ssa-sccopy.cc
@@ -554,9 +554,11 @@ sccopy_propagate ()
 get removed.  That means parts of CFG get removed.  Those may
 contain copy statements.  For that reason we prune SCCs here.  */
   unsigned i;
-  for (i = 0; i < scc.length (); i++)
+  for (i = 0; i < scc.length ();)
if (gimple_bb (scc[i]) == NULL)
  scc.unordered_remove (i);
+   else
+ i++;
   if (scc.is_empty ())
{
  scc.release ();


[gcc/devel/omp/gcc-14] c++: mangling of array new [PR119316]

2025-03-21 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:a05efb217f98ff08e00d4630213de91cdcdf86d6

commit a05efb217f98ff08e00d4630213de91cdcdf86d6
Author: Jason Merrill 
Date:   Wed Mar 19 05:15:00 2025 -0400

c++: mangling of array new [PR119316]

Because we build an array type to represent an array new, we hit a VLA
error in compute_array_index_type for a variable length array new.  To avoid
this, let's build the MINUS_EXPR and index type directly.

I also noticed that the non-constant case in write_array_type was assuming
MINUS_EXPR without verifying it, so I added a checking_assert.

I also noticed that Clang doesn't mangle the length of an array new at all,
so I opened https://github.com/itanium-cxx-abi/cxx-abi/issues/199 to clarify
this.

PR c++/119316

gcc/cp/ChangeLog:

* mangle.cc (write_expression) [NEW_EXPR]: Avoid using
compute_array_index_type.
(write_array_type): Add checking_assert.

gcc/testsuite/ChangeLog:

* g++.dg/abi/mangle-new1.C: New test.

(cherry picked from commit 80e1dac3849b134ebd5e0151e9c9e4b8b091de72)

Diff:
---
 gcc/cp/mangle.cc   | 13 ++---
 gcc/testsuite/g++.dg/abi/mangle-new1.C | 10 ++
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc
index c6e4562cfee2..a997cbbbdb38 100644
--- a/gcc/cp/mangle.cc
+++ b/gcc/cp/mangle.cc
@@ -3629,10 +3629,15 @@ write_expression (tree expr)
 
   if (nelts)
{
- tree domain;
  ++processing_template_decl;
- domain = compute_array_index_type (NULL_TREE, nelts,
-tf_warning_or_error);
+ /* Avoid compute_array_index_type complaints about
+non-constant nelts.  */
+ tree max = cp_build_binary_op (input_location, MINUS_EXPR,
+fold_convert (sizetype, nelts),
+size_one_node,
+tf_warning_or_error);
+ max = maybe_constant_value (max);
+ tree domain = build_index_type (max);
  type = build_cplus_array_type (type, domain);
  --processing_template_decl;
}
@@ -4197,6 +4202,8 @@ write_array_type (const tree type)
}
  else
{
+ gcc_checking_assert (TREE_CODE (max) == MINUS_EXPR
+  && integer_onep (TREE_OPERAND (max, 1)));
  max = TREE_OPERAND (max, 0);
  write_expression (max);
}
diff --git a/gcc/testsuite/g++.dg/abi/mangle-new1.C 
b/gcc/testsuite/g++.dg/abi/mangle-new1.C
new file mode 100644
index ..bb3ea9b2e96f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/mangle-new1.C
@@ -0,0 +1,10 @@
+// PR c++/119316
+// { dg-do compile { target c++11 } }
+
+template  struct A { };
+template
+auto foo(unsigned n) -> A
+{ return {}; }
+int main() { foo(5); }
+
+// { dg-final { scan-assembler {_Z3fooIiE1AIXszna_Afp__T_EEEj} } }


[gcc/devel/omp/gcc-14] libstdc++: Fix "IEE" typo in comment in std::time_put::do_put

2025-03-21 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:183110c3189ae3f1c64789618cbb3b8c1d71c139

commit 183110c3189ae3f1c64789618cbb3b8c1d71c139
Author: Jonathan Wakely 
Date:   Wed Mar 19 23:26:10 2025 +

libstdc++: Fix "IEE" typo in comment in std::time_put::do_put

libstdc++-v3/ChangeLog:

* include/bits/locale_facets_nonio.tcc (time_put::do_put): Fix
typo in comment.

(cherry picked from commit b8e39b4c33ce74c243e467391f6cc0144d4a9477)

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

diff --git a/libstdc++-v3/include/bits/locale_facets_nonio.tcc 
b/libstdc++-v3/include/bits/locale_facets_nonio.tcc
index fa250c1ae3d7..6c94aa1d5591 100644
--- a/libstdc++-v3/include/bits/locale_facets_nonio.tcc
+++ b/libstdc++-v3/include/bits/locale_facets_nonio.tcc
@@ -1648,7 +1648,7 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
   const size_t __maxlen = 128;
   char_type __res[__maxlen];
 
-  // NB: In IEE 1003.1-200x, and perhaps other locale models, it
+  // NB: In IEEE 1003.1-200x, and perhaps other locale models, it
   // is possible that the format character will be longer than one
   // character. Possibilities include 'E' or 'O' followed by a
   // format character: if __mod is not the default argument, assume


[gcc/devel/omp/gcc-14] Fix misoptimization at -O2 in LTO mode

2025-03-21 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:af9e28ba3de1eddf0a9506927217a2fd72aabcb9

commit af9e28ba3de1eddf0a9506927217a2fd72aabcb9
Author: Eric Botcazou 
Date:   Wed Mar 19 08:55:04 2025 +0100

Fix misoptimization at -O2 in LTO mode

This is a regression in recent releases. The problem is that the IPA mod/ref
pass looks through the (nominal) type of a pointer-to-discriminated-type
parameter in a call to a subprogram in order to see the (actual) type used
for the dereferences of the parameter in the callee, which is a
pointer-to-constrained-subtype.

Historically the discriminated type is marked with the may_alias attribute
because of the symmetric effect for the argument in the caller, so we mark
the constrained subtype with the attribute now for the sake of the callee.

gcc/ada/
* gcc-interface/decl.cc (gnat_to_gnu_entity) : Set
the may_alias attribute if a specific GCC type is built.

Diff:
---
 gcc/ada/gcc-interface/decl.cc | 8 
 1 file changed, 8 insertions(+)

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index ca174bff0097..53b5e5962181 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -3564,6 +3564,14 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree 
gnu_expr, bool definition)
  TYPE_PACKED (gnu_type) = TYPE_PACKED (gnu_base_type);
  TYPE_REVERSE_STORAGE_ORDER (gnu_type)
= Reverse_Storage_Order (gnat_entity);
+
+ /* Do the same for subtypes as for the base type, since pointers
+to them may symmetrically also point to the latter.  */
+ prepend_one_attribute
+   (&attr_list, ATTR_MACHINE_ATTRIBUTE,
+get_identifier ("may_alias"), NULL_TREE,
+gnat_entity);
+
  process_attributes (&gnu_type, &attr_list, true, gnat_entity);
 
  /* Set the size, alignment and alias set of the type to match


[gcc/devel/omp/gcc-14] libstdc++: Fix comment typo

2025-03-21 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:2a88778a1d6740854d20de4a31853e71bb9127ba

commit 2a88778a1d6740854d20de4a31853e71bb9127ba
Author: Jakub Jelinek 
Date:   Thu Mar 20 10:36:29 2025 +0100

libstdc++: Fix comment typo

Another IEE typo.

2025-03-20  Jakub Jelinek  

* testsuite/18_support/numeric_limits/traps.cc (main): Fix comment
typo.

(cherry picked from commit d458020e19b686e0d46320e7d26fa876c19965a0)

Diff:
---
 libstdc++-v3/testsuite/18_support/numeric_limits/traps.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/18_support/numeric_limits/traps.cc 
b/libstdc++-v3/testsuite/18_support/numeric_limits/traps.cc
index a4b30fd01c3f..adb2dba9f8fc 100644
--- a/libstdc++-v3/testsuite/18_support/numeric_limits/traps.cc
+++ b/libstdc++-v3/testsuite/18_support/numeric_limits/traps.cc
@@ -48,7 +48,7 @@ int main()
 For floating points, trapping is a different, more complicated
 story.  If is_iecxxx is true, then division by zero would not trap
 (infinity).  If is_iecxxx is false, we don't know (VAX may trap for
-0/0 -- I have to check).  For most cases (i.e. IEE-754), trapping
+0/0 -- I have to check).  For most cases (i.e. IEEE-754), trapping
 for floating points have to do with whether there is a support for
 signaling NaN.
 - Gaby.


[gcc/devel/omp/gcc-14] libstdc++: Correct statement about default -std option

2025-03-21 Thread Tobias Burnus via Libstdc++-cvs
https://gcc.gnu.org/g:ec67907501be0ec4b7587dacd8946ea9b38df0f7

commit ec67907501be0ec4b7587dacd8946ea9b38df0f7
Author: Jonathan Wakely 
Date:   Wed Mar 19 23:27:24 2025 +

libstdc++: Correct statement about default -std option

The default is -std=gnu++17 now, not -std=gnu++14.

libstdc++-v3/ChangeLog:

* doc/xml/manual/test.xml: Fix default for -std option.
* doc/html/manual/test.html: Regenerate.

(cherry picked from commit b93e60e7901526d7df2d8c0f5e0e46c57e8e3771)

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

diff --git a/libstdc++-v3/doc/html/manual/test.html 
b/libstdc++-v3/doc/html/manual/test.html
index 3657997fad46..b8a3b9545a7b 100644
--- a/libstdc++-v3/doc/html/manual/test.html
+++ b/libstdc++-v3/doc/html/manual/test.html
@@ -343,11 +343,11 @@ cat 27_io/objects/char/3_xin.in | 
a.out-O3 but 
with
   different -std options:
-make check 
'RUNTESTFLAGS=--target_board=unix/-O3\"{-std=gnu++98,-std=gnu++11,-std=gnu++14}\"'
+make check 
'RUNTESTFLAGS=--target_board=unix/-O3\"{-std=gnu++98,-std=gnu++11,-std=gnu++17}\"'
   N.B. that set of variations could also be written as
   unix/-O3\"{-std=gnu++98,-std=gnu++11,}\" so 
that
   the third variation would use the default for -std
-  (which is -std=gnu++14 as of GCC 6).
+  (which is -std=gnu++17 as of GCC 11).
 
   Since GCC 14, the libstdc++ testsuite has built-in support for running
   tests with more than one -std, similar to 
the G++ tests.
diff --git a/libstdc++-v3/doc/xml/manual/test.xml 
b/libstdc++-v3/doc/xml/manual/test.xml
index 40926946fe7a..eb340277def5 100644
--- a/libstdc++-v3/doc/xml/manual/test.xml
+++ b/libstdc++-v3/doc/xml/manual/test.xml
@@ -589,11 +589,11 @@ cat 27_io/objects/char/3_xin.in | a.out
   tests multiple times in different variations. For example, to run the
   entire testsuite three times using -O3 but with
   different -std options:
-make check 
'RUNTESTFLAGS=--target_board=unix/-O3\"{-std=gnu++98,-std=gnu++11,-std=gnu++14}\"'
+make check 
'RUNTESTFLAGS=--target_board=unix/-O3\"{-std=gnu++98,-std=gnu++11,-std=gnu++17}\"'
   N.B. that set of variations could also be written as
   unix/-O3\"{-std=gnu++98,-std=gnu++11,}\" so that
   the third variation would use the default for -std
-  (which is -std=gnu++14 as of GCC 6).
+  (which is -std=gnu++17 as of GCC 11).
 
 
 


[gcc(refs/users/omachota/heads/rtl-ssa-dce)] rtl-ssa: dce fix marking

2025-03-21 Thread Ondrej Machota via Gcc-cvs
https://gcc.gnu.org/g:5e62c115654300d61bb880a9c054eac4eedba147

commit 5e62c115654300d61bb880a9c054eac4eedba147
Author: Ondřej Machota 
Date:   Tue Mar 11 11:03:56 2025 +0100

rtl-ssa: dce fix marking

Diff:
---
 gcc/dce.cc | 77 ++
 1 file changed, 67 insertions(+), 10 deletions(-)

diff --git a/gcc/dce.cc b/gcc/dce.cc
index 21a7f23507af..d1558f2a9798 100644
--- a/gcc/dce.cc
+++ b/gcc/dce.cc
@@ -1585,6 +1585,57 @@ rtl_ssa_dce_mark()
 {
   std::unordered_set marked{};
   auto worklist = rtl_ssa_dce_prelive(marked);
+  auto_vec worklist_new{};
+  for (auto && item : worklist) {
+insn_info * insn = item;
+for (auto&& use : insn->uses()) {
+  set_info* set = use->def();
+  if (set) {
+worklist_new.safe_push(set);
+  }
+}
+  }
+
+  while (!worklist_new.is_empty()) {
+set_info* set = worklist_new.pop();
+insn_info* insn = set->insn();
+if (!insn) {
+  continue;
+}
+
+if (!(marked.count(insn) > 0))
+{
+  marked.emplace(insn);
+}
+
+// use_array uses = insn->uses();
+if (insn->is_phi()) {
+  phi_info* pi = as_a (set);
+  
+  for (auto && input : pi->inputs()) {
+use_info* use = input;
+set_info* parent_set = use->def();
+if (!parent_set) { // Clobber...
+  continue;
+}
+
+worklist_new.safe_push(parent_set);
+  }
+} else {
+  if (dump_file)
+fprintf(dump_file, "  Adding insn %d to worklist - mark\n", 
insn->uid());
+  
+  for (auto && use__ : insn->uses()) {
+use_info * use = use__;
+set_info* parent_set = use->def();
+if (!parent_set) {
+  continue;
+}
+
+worklist_new.safe_push(parent_set);
+  }
+}
+  }
 
   if (dump_file)
 fprintf(dump_file, "Finished inherently live, marking parents\n");
@@ -1623,17 +1674,23 @@ rtl_ssa_dce_mark()
   // debug(use);
   // std::cerr << '\n';
   
-  
-  insn_info *parent_insn = use->def()->insn();
-  if (parent_insn->is_phi()) { // this is weird...
-// debug(use->def());
-phi_info * pi = as_a (use->def());
-// std::cerr << "phi inputs: " << pi->num_inputs() << '\n';
-for (auto&& input: pi->inputs()) {
-  use_info* phi_use = input;
-  std::cerr << "Via phi insn: " << phi_use->def()->insn()->uid() << 
'\n';
-}
+  set_info* set = use->def();
+  if (!set) {
+continue;
+  }
+  insn_info *parent_insn = set->insn();
+  if (!parent_insn) {
+continue;
   }
+  // if (parent_insn->is_phi()) { // this is weird...
+  //   // debug(use->def());
+  //   phi_info * pi = as_a (use->def());
+  //   // std::cerr << "phi inputs: " << pi->num_inputs() << '\n';
+  //   for (auto&& input: pi->inputs()) {
+  // use_info* phi_use = input;
+  // std::cerr << "Via phi insn: " << phi_use->def()->insn()->uid() << 
'\n';
+  //   }
+  // }
   int parent_insn_uid = parent_insn->uid();
   // propage that some instruction in chain is live from bottom to top
   if (dump_file)


[gcc r15-8647] c++: fix return type of __cxa_bad_array_new_length

2025-03-21 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:cb537f0d838bac376bfe5e6d765e19cd3af01031

commit r15-8647-gcb537f0d838bac376bfe5e6d765e19cd3af01031
Author: Jason Merrill 
Date:   Thu Mar 20 09:55:40 2025 -0400

c++: fix return type of __cxa_bad_array_new_length

We were lying about the return type, but that's not necessary; we already
need to handle a COND_EXPR where one side is void for THROW_EXPR.

This fixes an execution failure on nvptx:
error: Prototype doesn't match for '__cxa_throw_bad_array_new_length'

gcc/cp/ChangeLog:

* init.cc (throw_bad_array_new_length): Returns void.

Diff:
---
 gcc/cp/init.cc | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index ce6e58e05f2f..e589e45e8916 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -2810,8 +2810,7 @@ diagnose_uninitialized_cst_or_ref_member (tree type, bool 
using_new, bool compla
 }
 
 /* Call __cxa_bad_array_new_length to indicate that the size calculation
-   overflowed.  Pretend it returns sizetype so that it plays nicely in the
-   COND_EXPR.  */
+   overflowed.  */
 
 tree
 throw_bad_array_new_length (void)
@@ -2823,7 +2822,7 @@ throw_bad_array_new_length (void)
   fn = get_global_binding (name);
   if (!fn)
fn = push_throw_library_fn
- (name, build_function_type_list (sizetype, NULL_TREE));
+ (name, build_function_type_list (void_type_node, NULL_TREE));
 }
 
   return build_cxx_call (fn, 0, NULL, tf_warning_or_error);


[gcc(refs/users/omachota/heads/rtl-ssa-dce)] rtl-ssa-dce: improve marking, but still not correct

2025-03-21 Thread Ondrej Machota via Gcc-cvs
https://gcc.gnu.org/g:622c367a5fc67ebbda55c02aba391d86738dc6ad

commit 622c367a5fc67ebbda55c02aba391d86738dc6ad
Author: Ondřej Machota 
Date:   Wed Mar 12 13:12:43 2025 +0100

rtl-ssa-dce: improve marking, but still not correct

Diff:
---
 gcc/dce.cc | 211 +
 1 file changed, 113 insertions(+), 98 deletions(-)

diff --git a/gcc/dce.cc b/gcc/dce.cc
index d1558f2a9798..cfa58f21dc03 100644
--- a/gcc/dce.cc
+++ b/gcc/dce.cc
@@ -1390,10 +1390,12 @@ bool side_effects_with_mem (const_rtx x)
   return true;
 
 case MEM: // We might want tu return true iff volatile or mem is a 
destination
+  // write or possible null read
 case ASM_INPUT:
 case ASM_OPERANDS:
return true;
 
+// This should rather by RTX_BODY in is_rtx_insn_prelive - like global 
clobber
 case USE:
   return true;
 
@@ -1471,6 +1473,9 @@ bool is_rtx_insn_prelive(rtx_insn *insn) {
 return true;
 
   rtx body = PATTERN(insn);
+  if (GET_CODE(body) == CLOBBER) // 
~/Documents/gcc/gcc/testsuite/gcc.c-torture/compile/2605-1.c
+return true;
+
   if (side_effects_with_mem(body) || can_throw_internal(body))
 return true;
 
@@ -1588,6 +1593,7 @@ rtl_ssa_dce_mark()
   auto_vec worklist_new{};
   for (auto && item : worklist) {
 insn_info * insn = item;
+std::cerr << "cp Current: " << insn->uid() << '\n';
 for (auto&& use : insn->uses()) {
   set_info* set = use->def();
   if (set) {
@@ -1603,118 +1609,119 @@ rtl_ssa_dce_mark()
   continue;
 }
 
-if (!(marked.count(insn) > 0))
-{
-  marked.emplace(insn);
-}
+/*
+ * TODO : a phi insn might be visited more times due to having more phi 
nodes
+ * Either we have to mark phi nodes or do not mark phi insn
+*/
+std::cerr << "Current: " << insn->uid() << '\n';
+// if (insn->uid() == -21) {
+  // std::cerr << "Insn -21 phi? " << insn->is_phi() << '\n';
+// }
 
-// use_array uses = insn->uses();
-if (insn->is_phi()) {
-  phi_info* pi = as_a (set);
-  
-  for (auto && input : pi->inputs()) {
-use_info* use = input;
-set_info* parent_set = use->def();
-if (!parent_set) { // Clobber...
-  continue;
-}
-
-worklist_new.safe_push(parent_set);
-  }
-} else {
-  if (dump_file)
-fprintf(dump_file, "  Adding insn %d to worklist - mark\n", 
insn->uid());
-  
-  for (auto && use__ : insn->uses()) {
-use_info * use = use__;
-set_info* parent_set = use->def();
-if (!parent_set) {
-  continue;
-}
-
-worklist_new.safe_push(parent_set);
-  }
+if ((marked.count(insn) > 0)) {
+  continue;
 }
-  }
 
-  if (dump_file)
-fprintf(dump_file, "Finished inherently live, marking parents\n");
-  while (!worklist.is_empty())
-  {
-insn_info *insn = worklist.pop();
+marked.emplace(insn);
+
 use_array uses = insn->uses();
 if (insn->is_phi()) {
-  std::cerr << "Phi : "<< insn->uid() << " - uses: " << insn->num_uses() 
<< ", defs:" << insn->num_defs() << '\n';
-  for (auto&& use : uses) {
-debug(use);
-std::cerr << '\n';
-  }
-} else if (insn->is_artificial()) {
-  std::cerr << "Artificial " << insn->uid() << " - uses: " << 
insn->num_uses() << ", defs:" << insn->num_defs() << '\n';
-  for (auto&& use : uses) {
-debug(use);
-std::cerr << '\n';
-  }
+  phi_info* pi = as_a (set);
+  uses = pi->inputs();
 }
 
 if (dump_file)
-  fprintf(dump_file, "Looking at: %d, uses: %d\n", insn->uid(), 
uses.size());
-
-//std::cerr << "Insn: " << insn->uid() << ", uses: " << uses.size() << 
'\n';
-  std::cerr << "Current: " << insn->uid() << '\n';
-for (size_t i = 0; i < uses.size(); i++)
-{
-  // debug(uses[i]);
-  use_info* use = uses[i];
-  // debug(use->def());
-  // if (use->def() != nullptr) {
-  //   std::cerr << use->def()->insn()->uid() << '\n';
-  // }
-  // std::cerr << '\n';
-  // debug(use);
-  // std::cerr << '\n';
-  
-  set_info* set = use->def();
-  if (!set) {
+  fprintf(dump_file, "  Adding insn %d to worklist - mark\n", insn->uid());
+
+for (auto && use__ : uses) {
+  use_info * use = use__;
+  set_info* parent_set = use->def();
+  if (!parent_set) {
 continue;
   }
-  insn_info *parent_insn = set->insn();
-  if (!parent_insn) {
-continue;
-  }
-  // if (parent_insn->is_phi()) { // this is weird...
-  //   // debug(use->def());
-  //   phi_info * pi = as_a (use->def());
-  //   // std::cerr << "phi inputs: " << pi->num_inputs() << '\n';
-  //   for (auto&& input: pi->inputs()) {
-  // use_info* phi_use = input;
-  // std::cerr << "Via phi insn: " << phi_use->def()->insn()->uid() << 
'\n';
-  //   }
-  // }
-  int parent_insn_uid = par

[gcc r14-11428] libstdc++: Fix "IEE" typo in comment in std::time_put::do_put

2025-03-21 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:b685234cb5dc54caa751ce81e841143fa0398d99

commit r14-11428-gb685234cb5dc54caa751ce81e841143fa0398d99
Author: Jonathan Wakely 
Date:   Wed Mar 19 23:26:10 2025 +

libstdc++: Fix "IEE" typo in comment in std::time_put::do_put

libstdc++-v3/ChangeLog:

* include/bits/locale_facets_nonio.tcc (time_put::do_put): Fix
typo in comment.

(cherry picked from commit b8e39b4c33ce74c243e467391f6cc0144d4a9477)

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

diff --git a/libstdc++-v3/include/bits/locale_facets_nonio.tcc 
b/libstdc++-v3/include/bits/locale_facets_nonio.tcc
index fa250c1ae3d7..6c94aa1d5591 100644
--- a/libstdc++-v3/include/bits/locale_facets_nonio.tcc
+++ b/libstdc++-v3/include/bits/locale_facets_nonio.tcc
@@ -1648,7 +1648,7 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
   const size_t __maxlen = 128;
   char_type __res[__maxlen];
 
-  // NB: In IEE 1003.1-200x, and perhaps other locale models, it
+  // NB: In IEEE 1003.1-200x, and perhaps other locale models, it
   // is possible that the format character will be longer than one
   // character. Possibilities include 'E' or 'O' followed by a
   // format character: if __mod is not the default argument, assume


[gcc r15-8655] c++: add fixed test [PR119378]

2025-03-21 Thread Patrick Palka via Gcc-cvs
https://gcc.gnu.org/g:6ed38b98456725f042e75fde7da16c60e22c08d8

commit r15-8655-g6ed38b98456725f042e75fde7da16c60e22c08d8
Author: Patrick Palka 
Date:   Fri Mar 21 15:23:49 2025 -0400

c++: add fixed test [PR119378]

Fixed by r15-123 (specifically the change to set processing_template_decl
when tsubsting UNBOUND_CLASS_TEMPLATE).

PR c++/119378

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/testsuite/g++.dg/template/friend85.C | 16 
 1 file changed, 16 insertions(+)

diff --git a/gcc/testsuite/g++.dg/template/friend85.C 
b/gcc/testsuite/g++.dg/template/friend85.C
new file mode 100644
index ..5cf839111931
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/friend85.C
@@ -0,0 +1,16 @@
+// PR c++/119378
+
+template
+struct A {
+  template
+  struct B;
+};
+
+template
+struct C {
+  template
+  template
+  friend class A::B;
+};
+
+template struct C;


[gcc r14-11432] ipa: target clone and mangling alias [PR114992]

2025-03-21 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:8a624a127990aee47d02b3d64892f8de9031975e

commit r14-11432-g8a624a127990aee47d02b3d64892f8de9031975e
Author: Jason Merrill 
Date:   Thu Mar 20 12:57:15 2025 -0400

ipa: target clone and mangling alias [PR114992]

Since the mangling of the second lambda changed (previously we counted all
lambdas, now we only count lambdas with the same signature), we
generate_mangling_alias for handler for backward compatibility.
Since handler is COMDAT, resolve_alias puts the alias in the same comdat
group as handler itself.  Then create_dispatcher_calls tries to add the
alias to the same comdat group as the dispatcher, but it's already in a
same_comdat_group, so we ICE.

It seems like we're just missing a remove_from_same_comdat_group before
add_to_same_comdat_group.

PR c++/114992

gcc/ChangeLog:

* multiple_target.cc (create_dispatcher_calls):
remove_from_same_comdat_group before add_to_same_comdat_group.

gcc/testsuite/ChangeLog:

* g++.target/i386/mangling-alias1.C: New test.

(cherry picked from commit ab716829da7c885b97ac2649c7c0ff5c7703ffa5)

Diff:
---
 gcc/multiple_target.cc  |  6 +-
 gcc/testsuite/g++.target/i386/mangling-alias1.C | 16 
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/multiple_target.cc b/gcc/multiple_target.cc
index 60958a56c92d..b173044cbee1 100644
--- a/gcc/multiple_target.cc
+++ b/gcc/multiple_target.cc
@@ -155,7 +155,11 @@ create_dispatcher_calls (struct cgraph_node *node)
  symtab_node *source = ref->referring;
  source->create_reference (inode, IPA_REF_ALIAS);
  if (inode->get_comdat_group ())
-   source->add_to_same_comdat_group (inode);
+   {
+ if (source->same_comdat_group)
+   source->remove_from_same_comdat_group ();
+ source->add_to_same_comdat_group (inode);
+   }
}
  else
gcc_unreachable ();
diff --git a/gcc/testsuite/g++.target/i386/mangling-alias1.C 
b/gcc/testsuite/g++.target/i386/mangling-alias1.C
new file mode 100644
index ..70264e2b64e6
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/mangling-alias1.C
@@ -0,0 +1,16 @@
+// PR c++/114992
+// { dg-do compile { target { c++11 && x86_64-*-* } } }
+// { dg-require-ifunc }
+
+template 
+__attribute__((target_clones("avx2", "default")))
+void handler(Callable) {}
+
+inline int func()
+{
+  auto l1 = [](int) {}; // different lambda signature
+  handler([]() {}); // so this one needs a mangling alias
+  return 42;
+}
+
+int g = func();


[gcc r15-8654] OpenMP: 'interop' construct - add ME support + target-independent libgomp

2025-03-21 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:99e2906ae255fc7b8edb008d7cd47b28b078a809

commit r15-8654-g99e2906ae255fc7b8edb008d7cd47b28b078a809
Author: Paul-Antoine Arras 
Date:   Thu Mar 13 17:16:41 2025 +0100

OpenMP: 'interop' construct - add ME support + target-independent libgomp

This patch partially enables use of the OpenMP interop construct by adding
middle end support, mostly in the omplower pass, and in the 
target-independent
part of the libgomp runtime. It follows up on previous patches for C, C++ 
and
Fortran front ends support. The full interop feature requires another patch 
to
enable foreign runtime support in libgomp plugins.

gcc/ChangeLog:

* builtin-types.def
(BT_FN_VOID_INT_INT_PTR_PTR_PTR_INT_PTR_INT_PTR_UINT_PTR): New.
* gimple-low.cc (lower_stmt): Handle GIMPLE_OMP_INTEROP.
* gimple-pretty-print.cc (dump_gimple_omp_interop): New function.
(pp_gimple_stmt_1): Handle GIMPLE_OMP_INTEROP.
* gimple.cc (gimple_build_omp_interop): New function.
(gimple_copy): Handle GIMPLE_OMP_INTEROP.
* gimple.def (GIMPLE_OMP_INTEROP): Define.
* gimple.h (gimple_build_omp_interop): Declare.
(gimple_omp_interop_clauses): New function.
(gimple_omp_interop_clauses_ptr): Likewise.
(gimple_omp_interop_set_clauses): Likewise.
(gimple_return_set_retval): Handle GIMPLE_OMP_INTEROP.
* gimplify.cc (gimplify_scan_omp_clauses): Handle OMP_CLAUSE_INIT,
OMP_CLAUSE_USE and OMP_CLAUSE_DESTROY.
(gimplify_omp_interop): New function.
(gimplify_expr): Replace sorry with call to gimplify_omp_interop.
* omp-builtins.def (BUILT_IN_GOMP_INTEROP): Define.
* omp-low.cc (scan_sharing_clauses): Handle OMP_CLAUSE_INIT,
OMP_CLAUSE_USE and OMP_CLAUSE_DESTROY.
(scan_omp_1_stmt): Handle GIMPLE_OMP_INTEROP.
(lower_omp_interop_action_clauses): New function.
(lower_omp_interop): Likewise.
(lower_omp_1): Handle GIMPLE_OMP_INTEROP.

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_clause_destroy): Make addressable.
(c_parser_omp_clause_init): Make addressable.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_clause_init): Make addressable.

gcc/fortran/ChangeLog:

* trans-openmp.cc (gfc_trans_omp_clauses): Make OMP_CLAUSE_DESTROY 
and
OMP_CLAUSE_INIT addressable.
* types.def 
(BT_FN_VOID_INT_INT_PTR_PTR_PTR_INT_PTR_INT_PTR_UINT_PTR):
New.

include/ChangeLog:

* gomp-constants.h (GOMP_DEVICE_DEFAULT_OMP_61, GOMP_INTEROP_TARGET,
GOMP_INTEROP_TARGETSYNC, GOMP_INTEROP_FLAG_NOWAIT): Define.

libgomp/ChangeLog:

* icv-device.c (omp_set_default_device): Check
GOMP_DEVICE_DEFAULT_OMP_61.
* libgomp-plugin.h (struct interop_obj_t): New.
(enum gomp_interop_flag): New.
(GOMP_OFFLOAD_interop): Declare.
(GOMP_OFFLOAD_get_interop_int): Declare.
(GOMP_OFFLOAD_get_interop_ptr): Declare.
(GOMP_OFFLOAD_get_interop_str): Declare.
(GOMP_OFFLOAD_get_interop_type_desc): Declare.
* libgomp.h (_LIBGOMP_OMP_LOCK_DEFINED): Define.
(struct gomp_device_descr): Add interop_func, get_interop_int_func,
get_interop_ptr_func, get_interop_str_func, 
get_interop_type_desc_func.
* libgomp.map: Add GOMP_interop.
* libgomp_g.h (GOMP_interop): Declare.
* target.c (resolve_device): Handle GOMP_DEVICE_DEFAULT_OMP_61.
(omp_get_interop_int): Replace stub with actual implementation.
(omp_get_interop_ptr): Likewise.
(omp_get_interop_str): Likewise.
(omp_get_interop_type_desc): Likewise.
(struct interop_data_t): Define.
(gomp_interop_internal): New function.
(GOMP_interop): Likewise.
(gomp_load_plugin_for_device): Load symbols for get_interop_int,
get_interop_ptr, get_interop_str and get_interop_type_desc.
* testsuite/libgomp.c-c++-common/interop-1.c: New test.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/interop-1.c: Remove dg-prune-output "sorry".
* c-c++-common/gomp/interop-2.c: Likewise.
* c-c++-common/gomp/interop-3.c: Likewise.
* c-c++-common/gomp/interop-4.c: Remove dg-message "not supported".
* g++.dg/gomp/interop-5.C: Likewise.
* gfortran.dg/gomp/interop-4.f90: Likewise.
* c-c++-common/gomp/interop-5.c: New test.
* gfortran.dg/gomp/interop-5.f90: New test.

Co-authored-by: Tobias Burnus 

Diff:
---
 gcc/builtin-types.def  |   3 +
 gcc/c/c-parser.cc  

[gcc r15-8542] gccrs: empty match expressions should resolve to !

2025-03-21 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:e4a92d706b30fb2e5c39161dc1ff9f4eabbec983

commit r15-8542-ge4a92d706b30fb2e5c39161dc1ff9f4eabbec983
Author: Philip Herron 
Date:   Thu Nov 21 17:36:34 2024 +

gccrs: empty match expressions should resolve to !

This is a special case in Rust and the ! type can unify with pretty much
anything its almost a inference variable and a unit-type for special cases.

Fixes Rust-GCC/gccrs#3231
Fixes Rust-GCC/gccrs#2567

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (check_match_scrutinee): check for 
empty match
(CompileExpr::visit): fix assertion
* checks/errors/rust-hir-pattern-analysis.cc 
(check_match_usefulness): check for empty
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): 
resolve to !

gcc/testsuite/ChangeLog:

* rust/compile/exhaustiveness1.rs: remove bad check
* rust/compile/issue-2567-1.rs: New test.
* rust/compile/issue-2567-2.rs: New test.
* rust/compile/issue-2567-3.rs: New test.
* rust/compile/issue-3231.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/backend/rust-compile-expr.cc   | 21 ++---
 gcc/rust/checks/errors/rust-hir-pattern-analysis.cc |  3 +++
 gcc/rust/typecheck/rust-hir-type-check-expr.cc  | 12 
 gcc/testsuite/rust/compile/exhaustiveness1.rs   |  4 +---
 gcc/testsuite/rust/compile/issue-2567-1.rs  |  8 
 gcc/testsuite/rust/compile/issue-2567-2.rs  |  8 
 gcc/testsuite/rust/compile/issue-2567-3.rs  |  8 
 gcc/testsuite/rust/compile/issue-3231.rs|  8 
 8 files changed, 58 insertions(+), 14 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index 7ea2a6755221..e0fb1da3feb3 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1013,17 +1013,7 @@ check_match_scrutinee (HIR::MatchExpr &expr, Context 
*ctx)
   || scrutinee_kind == TyTy::TypeKind::TUPLE
   || scrutinee_kind == TyTy::TypeKind::REF);
 
-  if (scrutinee_kind == TyTy::TypeKind::ADT)
-{
-  // this will need to change but for now the first pass implementation,
-  // lets assert this is the case
-  TyTy::ADTType *adt = static_cast (scrutinee_expr_tyty);
-  if (adt->is_enum ())
-   rust_assert (adt->number_of_variants () > 0);
-  else
-   rust_assert (adt->number_of_variants () == 1);
-}
-  else if (scrutinee_kind == TyTy::TypeKind::FLOAT)
+  if (scrutinee_kind == TyTy::TypeKind::FLOAT)
 {
   // FIXME: CASE_LABEL_EXPR does not support floating point types.
   // Find another way to compile these.
@@ -1064,6 +1054,15 @@ CompileExpr::visit (HIR::MatchExpr &expr)
   return;
 }
 
+  // if the result of this expression is meant to be never type then we can
+  // optimise this away but there is the case where match arms resolve to !
+  // because of return statements we need to special case this
+  if (!expr.has_match_arms () && expr_tyty->is ())
+{
+  translated = unit_expression (expr.get_locus ());
+  return;
+}
+
   fncontext fnctx = ctx->peek_fn ();
   Bvariable *tmp = NULL;
   tree enclosing_scope = ctx->peek_enclosing_scope ();
diff --git a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc 
b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
index 617d754c1819..db1e72725565 100644
--- a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
+++ b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
@@ -1530,6 +1530,9 @@ void
 check_match_usefulness (Resolver::TypeCheckContext *ctx,
TyTy::BaseType *scrutinee_ty, HIR::MatchExpr &expr)
 {
+  if (!expr.has_match_arms ())
+return;
+
   // Lower the arms to a more convenient representation.
   std::vector rows;
   for (auto &arm : expr.get_match_cases ())
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc 
b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 03922bb554ce..5a96c359d7c5 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1456,6 +1456,18 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr)
   TyTy::BaseType *scrutinee_tyty
 = TypeCheckExpr::Resolve (expr.get_scrutinee_expr ());
 
+  // https://github.com/Rust-GCC/gccrs/issues/3231#issuecomment-2462660048
+  // 
https://github.com/rust-lang/rust/blob/3d1dba830a564d1118361345d7ada47a05241f45/compiler/rustc_hir_typeck/src/_match.rs#L32-L36
+  if (!expr.has_match_arms ())
+{
+  // this is a special case where rustc returns !
+  TyTy::BaseType *lookup = nullptr;
+  bool ok = context->lookup_builtin ("!", &lookup);
+  rust_assert (ok);
+  infered = lookup->clone ();
+  return;
+}
+
   bool saw_error = false;
   std::vector kase_block_tys;
   for (auto &kase : expr.ge

[gcc r15-8651] ipa: target clone and mangling alias [PR114992]

2025-03-21 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:ab716829da7c885b97ac2649c7c0ff5c7703ffa5

commit r15-8651-gab716829da7c885b97ac2649c7c0ff5c7703ffa5
Author: Jason Merrill 
Date:   Thu Mar 20 12:57:15 2025 -0400

ipa: target clone and mangling alias [PR114992]

Since the mangling of the second lambda changed (previously we counted all
lambdas, now we only count lambdas with the same signature), we
generate_mangling_alias for handler for backward compatibility.
Since handler is COMDAT, resolve_alias puts the alias in the same comdat
group as handler itself.  Then create_dispatcher_calls tries to add the
alias to the same comdat group as the dispatcher, but it's already in a
same_comdat_group, so we ICE.

It seems like we're just missing a remove_from_same_comdat_group before
add_to_same_comdat_group.

PR c++/114992

gcc/ChangeLog:

* multiple_target.cc (create_dispatcher_calls):
remove_from_same_comdat_group before add_to_same_comdat_group.

gcc/testsuite/ChangeLog:

* g++.target/i386/mangling-alias1.C: New test.

Diff:
---
 gcc/multiple_target.cc  |  6 +-
 gcc/testsuite/g++.target/i386/mangling-alias1.C | 16 
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/multiple_target.cc b/gcc/multiple_target.cc
index d8becf4d9a96..d25277c0a930 100644
--- a/gcc/multiple_target.cc
+++ b/gcc/multiple_target.cc
@@ -155,7 +155,11 @@ create_dispatcher_calls (struct cgraph_node *node)
  symtab_node *source = ref->referring;
  source->create_reference (inode, IPA_REF_ALIAS);
  if (inode->get_comdat_group ())
-   source->add_to_same_comdat_group (inode);
+   {
+ if (source->same_comdat_group)
+   source->remove_from_same_comdat_group ();
+ source->add_to_same_comdat_group (inode);
+   }
}
  else
gcc_unreachable ();
diff --git a/gcc/testsuite/g++.target/i386/mangling-alias1.C 
b/gcc/testsuite/g++.target/i386/mangling-alias1.C
new file mode 100644
index ..70264e2b64e6
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/mangling-alias1.C
@@ -0,0 +1,16 @@
+// PR c++/114992
+// { dg-do compile { target { c++11 && x86_64-*-* } } }
+// { dg-require-ifunc }
+
+template 
+__attribute__((target_clones("avx2", "default")))
+void handler(Callable) {}
+
+inline int func()
+{
+  auto l1 = [](int) {}; // different lambda signature
+  handler([]() {}); // so this one needs a mangling alias
+  return 42;
+}
+
+int g = func();


[gcc/devel/omp/gcc-14] c++: tweak for -Wrange-loop-construct [PR116731]

2025-03-21 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:fb9ba80b91b5328e43eeaf83cafe150ee861043d

commit fb9ba80b91b5328e43eeaf83cafe150ee861043d
Author: Marek Polacek 
Date:   Tue Sep 17 16:58:37 2024 -0400

c++: tweak for -Wrange-loop-construct [PR116731]

This PR reports that the warning would be better off using a check
for trivially constructible rather than trivially copyable.

LLVM accepted a similar fix:
https://github.com/llvm/llvm-project/issues/47355

PR c++/116731

gcc/cp/ChangeLog:

* parser.cc (warn_for_range_copy): Check if TYPE is trivially
constructible, not copyable.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wrange-loop-construct3.C: New test.

Reviewed-by: Jason Merrill 
(cherry picked from commit 6ac4e2f4b2ca9980670e7d3815a9140730df1005)

Diff:
---
 gcc/cp/parser.cc   |  8 +--
 gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C | 57 ++
 2 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index b1a29c8f1b52..5461719370c9 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -14494,11 +14494,13 @@ warn_for_range_copy (tree decl, tree expr)
   else if (!CP_TYPE_CONST_P (type))
 return;
 
-  /* Since small trivially copyable types are cheap to copy, we suppress the
- warning for them.  64B is a common size of a cache line.  */
+  /* Since small trivially constructible types are cheap to construct, we
+ suppress the warning for them.  64B is a common size of a cache line.  */
+  tree vec = make_tree_vec (1);
+  TREE_VEC_ELT (vec, 0) = TREE_TYPE (expr);
   if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST
   || (tree_to_uhwi (TYPE_SIZE_UNIT (type)) <= 64
- && trivially_copyable_p (type)))
+ && is_trivially_xible (INIT_EXPR, type, vec)))
 return;
 
   /* If we can initialize a reference directly, suggest that to avoid the
diff --git a/gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C 
b/gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C
new file mode 100644
index ..3d9d0c9088e6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wrange-loop-construct3.C
@@ -0,0 +1,57 @@
+// PR c++/116731
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wrange-loop-construct" }
+
+void
+f0 ()
+{
+  struct S {
+char a[64];
+S& operator=(const S&) { return *this; };
+  };
+
+  S arr[8];
+  for (const auto r : arr)
+(void) r;
+}
+
+void
+f1 ()
+{
+  struct S {
+char a[65];
+S& operator=(const S&) { return *this; };
+  };
+
+  S arr[8];
+  for (const auto r : arr) // { dg-warning "creates a copy" }
+(void) r;
+}
+
+void
+f2 ()
+{
+  struct S {
+char a[64];
+S& operator=(const S&) { return *this; };
+~S() { }
+  };
+
+  S arr[8];
+  for (const auto r : arr) // { dg-warning "creates a copy" }
+(void) r;
+}
+
+void
+f3 ()
+{
+  struct S {
+char a[65];
+S& operator=(const S&) { return *this; };
+~S() { }
+  };
+
+  S arr[8];
+  for (const auto r : arr) // { dg-warning "creates a copy" }
+(void) r;
+}


[gcc/devel/omp/gcc-14] Daily bump.

2025-03-21 Thread Tobias Burnus via Libstdc++-cvs
https://gcc.gnu.org/g:f4594472d1b74994495b5e45adb766f1268edb55

commit f4594472d1b74994495b5e45adb766f1268edb55
Author: GCC Administrator 
Date:   Wed Mar 19 00:22:50 2025 +

Daily bump.

Diff:
---
 gcc/DATESTAMP   |  2 +-
 gcc/cp/ChangeLog| 33 +
 gcc/testsuite/ChangeLog | 32 
 libstdc++-v3/ChangeLog  | 15 +++
 4 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/gcc/DATESTAMP b/gcc/DATESTAMP
index c0dd0682172c..22523f5c82fe 100644
--- a/gcc/DATESTAMP
+++ b/gcc/DATESTAMP
@@ -1 +1 @@
-20250318
+20250319
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index e7fcdb51ad45..6ba470b5302f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,36 @@
+2025-03-18  Jason Merrill  
+
+   Backported from master:
+   2025-03-18  Jason Merrill  
+
+   PR c++/119194
+   * decl2.cc (min_vis_expr_r) [ADDR_EXPR]: New case.
+
+2025-03-18  Marek Polacek  
+
+   Backported from master:
+   2025-03-18  Marek Polacek  
+
+   PR c++/119344
+   * typeck.cc (cp_build_binary_op): Use cp_save_expr instead of save_expr.
+
+2025-03-18  Marek Polacek  
+
+   Backported from master:
+   2025-03-18  Marek Polacek  
+
+   PR c++/118104
+   * pt.cc (use_pack_expansion_extra_args_p): Remove an assert.
+
+2025-03-18  Marek Polacek  
+
+   Backported from master:
+   2024-09-26  Marek Polacek  
+
+   PR c++/116731
+   * parser.cc (warn_for_range_copy): Check if TYPE is trivially
+   constructible, not copyable.
+
 2025-03-12  Marek Polacek  
 
Backported from master:
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 43d3b33883d1..dfbe378844a0 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,35 @@
+2025-03-18  Jason Merrill  
+
+   Backported from master:
+   2025-03-18  Jason Merrill  
+
+   PR c++/119194
+   * g++.dg/template/linkage7.C: New test.
+
+2025-03-18  Marek Polacek  
+
+   Backported from master:
+   2025-03-18  Marek Polacek  
+
+   PR c++/119344
+   * g++.dg/conversion/ptrmem10.C: New test.
+
+2025-03-18  Marek Polacek  
+
+   Backported from master:
+   2025-03-18  Marek Polacek  
+
+   PR c++/118104
+   * g++.dg/cpp0x/alias-decl-variadic3.C: New test.
+
+2025-03-18  Marek Polacek  
+
+   Backported from master:
+   2024-09-26  Marek Polacek  
+
+   PR c++/116731
+   * g++.dg/warn/Wrange-loop-construct3.C: New test.
+
 2025-03-12  Marek Polacek  
 
Backported from master:
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 90d665fc3f8c..1fdf4607d768 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,18 @@
+2025-03-18  Patrick Palka  
+
+   Backported from master:
+   2025-02-28  Patrick Palka  
+
+   PR libstdc++/112490
+   * include/bits/stl_iterator.h (basic_const_iterator::operator<):
+   Replace non-dependent basic_const_iterator function parameter with
+   a dependent one of type basic_const_iterator<_It3> where _It3
+   matches _It.
+   (basic_const_iterator::operator>): Likewise.
+   (basic_const_iterator::operator<=): Likewise.
+   (basic_const_iterator::operator>=): Likewise.
+   * testsuite/24_iterators/const_iterator/112490.cc: New test.
+
 2025-03-05  Tomasz Kamiński  
 
Backported from master:


  1   2   >