public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] gccrs: fix ICE with recursive function calls
@ 2023-05-02  7:10 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-05-02  7:10 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:727056301b2124649daacc29a23bb4b357a25173

commit 727056301b2124649daacc29a23bb4b357a25173
Author: Philip Herron <herron.philip@googlemail.com>
Date:   Thu Apr 20 12:33:55 2023 +0100

    gccrs: fix ICE with recursive function calls
    
    Fixes #2136
    
    gcc/rust/ChangeLog:
    
            * backend/rust-compile-item.cc (CompileItem::visit): remove bad checks
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/issue-2136-1.rs: New test.
            * rust/compile/issue-2136-2.rs: New test.
    
    Signed-off-by: Philip Herron <herron.philip@googlemail.com>

Diff:
---
 gcc/rust/backend/rust-compile-item.cc      | 14 ++------------
 gcc/testsuite/rust/compile/issue-2136-1.rs | 14 ++++++++++++++
 gcc/testsuite/rust/compile/issue-2136-2.rs | 13 +++++++++++++
 3 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc
index e1e2bb6d5a0..c57acdf9872 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -147,18 +147,8 @@ CompileItem::visit (HIR::Function &function)
   if (ctx->lookup_function_decl (fntype->get_ty_ref (), &lookup,
 				 fntype->get_id (), fntype, asm_name))
     {
-      // has this been added to the list then it must be finished
-      if (ctx->function_completed (lookup))
-	{
-	  tree dummy = NULL_TREE;
-	  if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &dummy))
-	    {
-	      ctx->insert_function_decl (fntype, lookup);
-	    }
-
-	  reference = address_expression (lookup, ref_locus);
-	  return;
-	}
+      reference = address_expression (lookup, ref_locus);
+      return;
     }
 
   if (fntype->has_subsititions_defined ())
diff --git a/gcc/testsuite/rust/compile/issue-2136-1.rs b/gcc/testsuite/rust/compile/issue-2136-1.rs
new file mode 100644
index 00000000000..fcf1efcd171
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2136-1.rs
@@ -0,0 +1,14 @@
+pub trait Foo {
+    fn foo();
+}
+
+impl Foo for u16 {
+    fn foo() {
+        // { dg-warning "infinite recursion detected" "" { target *-*-* } .-1 }
+        <u16 as Foo>::foo()
+    }
+}
+
+fn main() {
+    <u16>::foo();
+}
diff --git a/gcc/testsuite/rust/compile/issue-2136-2.rs b/gcc/testsuite/rust/compile/issue-2136-2.rs
new file mode 100644
index 00000000000..7317f3f5151
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2136-2.rs
@@ -0,0 +1,13 @@
+struct S;
+
+impl S {
+    fn foo(self) {
+        // { dg-warning "infinite recursion detected" "" { target *-*-* } .-1 }
+        self.foo();
+    }
+}
+
+fn main() {
+    let a = S;
+    a.foo();
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-02  7:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-02  7:10 [gcc/devel/rust/master] gccrs: fix ICE with recursive function calls Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).