]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: fix ICE with recursive function calls
authorPhilip Herron <herron.philip@googlemail.com>
Thu, 20 Apr 2023 11:33:55 +0000 (12:33 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:34:13 +0000 (18:34 +0100)
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>
gcc/rust/backend/rust-compile-item.cc
gcc/testsuite/rust/compile/issue-2136-1.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/issue-2136-2.rs [new file with mode: 0644]

index 4b37b15f87ebe2e94aaf331831f463dc2b453bff..d953e4b13672fd5d2e1cea03c1f5b98ad26044fa 100644 (file)
@@ -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 (file)
index 0000000..fcf1efc
--- /dev/null
@@ -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 (file)
index 0000000..7317f3f
--- /dev/null
@@ -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();
+}