ICE + unimplemented #[derive(Default)] causes segmentation fault
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 2.9k
- Forks
- 231
- Avg merge
- 19h 55m
- Merged PRs (30d)
- 67
Description
Summary
When compiling code using #[derive(Default)], GCC-RS 14.0.1 fails with an internal compiler error (segmentation fault), while rustc-nightly compiles successfully with warnings.
Reproducer
I tried this code:
#![feature(type_changing_struct_update)]
use std::borrow::Cow;
use std::marker::PhantomData;
#[derive(Default)]
struct NonGeneric {
field1: usize,
}
#[derive(Default)]
struct Generic<T, U> {
field1: T,
field2: U,
}
#[derive(Default)]
struct MoreGeneric<'a, const N: usize> {
field1: PhantomData<[u32; N]>,
field2: Cow<'a, str>,
}
fn main() {
let _default1 = NonGeneric { ..Default::default() };
let _default2: Generic<i32, f32> = Generic { ..Default::default() };
let _default3: MoreGeneric<'static, 12> = MoreGeneric { ..Default::default() };
}
Does the code make use of any (1.49) nightly feature ?
- Nightly
Godbolt link
https://godbolt.org/z/8MEKG3caq
Actual behavior
:6:3: sorry, unimplemented: uninmplemented builtin derive macro
6 | #[derive(Default)]
| ^~~~~~
:11:3: sorry, unimplemented: uninmplemented builtin derive macro
11 | #[derive(Default)]
| ^~~~~~
:17:3: sorry, unimplemented: uninmplemented builtin derive macro
17 | #[derive(Default)]
| ^~~~~~
crab1: internal compiler error: Segmentation fault
0x2e9eb6c internal_error(char const*, ...)
???:0
0x1157677 void Rust::ExpandVisitor::expand_macro_children<std::vector<std::unique_ptr<Rust::AST::Item, std::default_deleteRust::AST::Item >, std::allocator<std::unique_ptr<Rust::AST::Item, std::default_deleteRust::AST::Item > > >, std::unique_ptr<Rust::AST::Item, std::default_deleteRust::AST::Item > >(std::vector<std::unique_ptr<Rust::AST::Item, std::default_deleteRust::AST::Item >, std::allocator<std::unique_ptr<Rust::AST::Item, std::default_deleteRust::AST::Item > > >&, std::function<std::unique_ptr<Rust::AST::Item, std::default_deleteRust::AST::Item > (Rust::AST::SingleASTNode)>)
???:0
0x1154628 Rust::ExpandVisitor::expand_inner_items(std::vector<std::unique_ptr<Rust::AST::Item, std::default_deleteRust::AST::Item >, std::allocator<std::unique_ptr<Rust::AST::Item, std::default_deleteRust::AST::Item > > >&)
???:0
0x1094f9d Rust::Session::expansion(Rust::AST::Crate&)
???:0
0x109a238 Rust::Session::compile_crate(char const*)
???:0
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See https://gcc.gnu.org/bugs/ for instructions.
Compiler returned: 1
Expected behavior
Successful compilation with warnings about unused variables/structs (as in rustc-nightly), not a compiler crash.
GCC Version
14.0.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the supplied Rust reproducer with GCC-RS 14.0.1 and compare its behavior with rustc-nightly. Read the reported Rust::ExpandVisitor::expand_macro_children, expand_inner_items, and Rust::Session::expansion entry points. Done means #[derive(Default)] no longer causes an internal compiler error or segmentation fault and the reproducer compiles with the expected warnings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100