]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: FIX ICE when working with HIR::BareFunctionType
authorPhilip Herron <herron.philip@googlemail.com>
Fri, 28 Mar 2025 17:42:07 +0000 (17:42 +0000)
committerPhilip Herron <philip.herron@embecosm.com>
Fri, 28 Mar 2025 18:34:27 +0000 (18:34 +0000)
Fixes Rust-GCC#3615

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): check has type
* hir/tree/rust-hir-type.cc (BareFunctionType::BareFunctionType): likewise

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/hir/rust-hir-dump.cc
gcc/rust/hir/tree/rust-hir-type.cc
gcc/testsuite/rust/compile/issue-3615.rs [new file with mode: 0644]

index 983922c73e31df1f96a1b31f9fd15443bde0447d..b6dcf184ae4ebc3066ba1ebde3c35c9a31bc819e 100644 (file)
@@ -2440,7 +2440,9 @@ Dump::visit (BareFunctionType &e)
       end_field ("params");
     }
 
-  visit_field ("return_type", e.get_return_type ());
+  if (e.has_return_type ())
+    visit_field ("return_type", e.get_return_type ());
+
   put_field ("is_variadic", std::to_string (e.get_is_variadic ()));
   end ("BareFunctionType");
 }
index 689d86b7372b2d23480b96bcc56e3f0150e7ed2b..6a6c319fc98ee018db076f184ceb34cb0d372564 100644 (file)
@@ -268,7 +268,8 @@ BareFunctionType::BareFunctionType (BareFunctionType const &other)
     for_lifetimes (other.for_lifetimes),
     function_qualifiers (other.function_qualifiers), params (other.params),
     is_variadic (other.is_variadic),
-    return_type (other.return_type->clone_type ())
+    return_type (other.has_return_type () ? other.return_type->clone_type ()
+                                         : nullptr)
 {}
 
 BareFunctionType &
diff --git a/gcc/testsuite/rust/compile/issue-3615.rs b/gcc/testsuite/rust/compile/issue-3615.rs
new file mode 100644 (file)
index 0000000..e5c5072
--- /dev/null
@@ -0,0 +1,7 @@
+pub trait Trait {
+    pub fn nrvo(init: fn()) -> [u8; 4096] {
+        let mut buf = [0; 4096];
+
+        buf
+    }
+}