Rust-GCC / Rust-GCC/gccrs

ICE (Segmentation fault) when deriving Default on enum with multiple #[default] attributes

Open
#3,712 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
20h 2m
Merged PRs (30d)
66

Description

Summary

When compiling Rust code that contains an enum with multiple #[default] attributes using gccrs, the compiler crashes with a segmentation fault instead of emitting appropriate error messages. This behavior differs from rustc, which correctly reports "multiple declared defaults" and provides diagnostic suggestions.

Reproducer

I tried this code:

#[derive(Default)]
enum A {
    #[default]
    #[default]
    A,
    #[default]
    B,
}

#[derive(Default)]
enum E {
    #[default]
    A,
    #[default]
    A,
}

macro_rules! m {
    { $($id:ident)* } => {
        #[derive(Default)]
        enum F {
            $(
                #[default]
                $id,
            )*
        }
    }
}

m! { A B }
Does the code make use of any (1.49) nightly feature ?
  • Nightly
Godbolt link

https://godbolt.org/z/WrPqvYc7G

Actual behavior

:1:3: sorry, unimplemented: uninmplemented builtin derive macro
1 | #[derive(Default)]
| ^~~~~~
:10:3: sorry, unimplemented: uninmplemented builtin derive macro
10 | #[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

The compiler should emit errors for multiple #[default] attributes. No internal compiler errors or crashes should occur.

GCC Version

14.0.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the crash with the Rust enum and macro examples in the issue, then inspect the expansion path named in the backtrace: Rust::ExpandVisitor::expand_macro_children, expand_inner_items, and Session::expansion. Done means multiple #[default] attributes produce diagnostics like rustc without an internal compiler error or segmentation fault.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.