Skip to content

Commit 8d1c01c

Browse files
committed
gccrs: FIX ICE when working with HIR::BareFunctionType
Fixes #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>
1 parent a0b21c9 commit 8d1c01c

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

gcc/rust/hir/rust-hir-dump.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2440,7 +2440,9 @@ Dump::visit (BareFunctionType &e)
24402440
end_field ("params");
24412441
}
24422442

2443-
visit_field ("return_type", e.get_return_type ());
2443+
if (e.has_return_type ())
2444+
visit_field ("return_type", e.get_return_type ());
2445+
24442446
put_field ("is_variadic", std::to_string (e.get_is_variadic ()));
24452447
end ("BareFunctionType");
24462448
}

gcc/rust/hir/tree/rust-hir-type.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ BareFunctionType::BareFunctionType (BareFunctionType const &other)
268268
for_lifetimes (other.for_lifetimes),
269269
function_qualifiers (other.function_qualifiers), params (other.params),
270270
is_variadic (other.is_variadic),
271-
return_type (other.return_type->clone_type ())
271+
return_type (other.has_return_type () ? other.return_type->clone_type ()
272+
: nullptr)
272273
{}
273274

274275
BareFunctionType &
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub trait Trait {
2+
pub fn nrvo(init: fn()) -> [u8; 4096] {
3+
let mut buf = [0; 4096];
4+
5+
buf
6+
}
7+
}

0 commit comments

Comments
 (0)