Skip to content

gccrs: Fix ICE cloning trait functions without return types#4532

Merged
CohenArthur merged 1 commit into
Rust-GCC:masterfrom
Lishin1215:3972
Apr 27, 2026
Merged

gccrs: Fix ICE cloning trait functions without return types#4532
CohenArthur merged 1 commit into
Rust-GCC:masterfrom
Lishin1215:3972

Conversation

@Lishin1215
Copy link
Copy Markdown
Contributor

@Lishin1215 Lishin1215 commented Apr 20, 2026

Fixes #3972

gcc/rust/ChangeLog:

	* hir/tree/rust-hir-item.cc (TraitFunctionDecl::TraitFunctionDecl): 
	Handle null return types in copy constructor.
	(TraitFunctionDecl::operator=): Likewise.

gcc/testsuite/ChangeLog:

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

@Lishin1215
Copy link
Copy Markdown
Contributor Author

Hi, I think this could fix #3972.
Please let me know if this approach makes sense!

@dkm
Copy link
Copy Markdown
Member

dkm commented Apr 21, 2026

Hello!
Thank you for your contribution!

We're trying to have commit log be a bit more descriptive of the changes. You should also link to the issue you're fixing :)

Can you please describe in a few words what the change are doing? A bit of why, what and how :) Thanks!

@Lishin1215
Copy link
Copy Markdown
Contributor Author

@dkm
Thanks!
I've updated the commit message with a more detailed description and added a link to the issue.
Please let me know if this works.

Fixes Rust-GCC#3972.

Trait functions without an explicit return type can have a null
`return_type` in `TraitFunctionDecl`. When such declarations are copied,
the copy constructor and assignment operator currently try to clone the
return type unconditionally, and this can lead to an ICE.

Handle this case by keeping `nullptr` when there is no return type to
clone. Also add a regression test for the example from Rust-GCC#3972.

gcc/rust/ChangeLog:

	* hir/tree/rust-hir-item.cc (TraitFunctionDecl::TraitFunctionDecl):
	Handle null return types in copy constructor.
	(TraitFunctionDecl::operator=): Likewise.

gcc/testsuite/ChangeLog:

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

Signed-off-by: lishin <lishin1008@gmail.com>
Copy link
Copy Markdown
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that looks good to me, thank you @Lishin1215!

@CohenArthur CohenArthur added this pull request to the merge queue Apr 27, 2026
Merged via the queue into Rust-GCC:master with commit 5c4de7f Apr 27, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

segfault in Rust::HIR::TraitFunctionDecl::TraitFunctionDecl

3 participants