Rust-GCC / gccrs

GCC Front-End for Rust
https://rust-gcc.github.io/
GNU General Public License v2.0
2.34k stars 149 forks source link

Union pattern matching causes ICE #3108

Open tamaroning opened 1 month ago

tamaroning commented 1 month ago

https://godbolt.org/z/3bxKGWver

Code

union MyUnion {
    f1: u32,
}

fn f(u: MyUnion) -> i32 {
    unsafe {
        match u {
            MyUnion { f1: 10 } => { 0 }
            _ => { 1 }
        }
    }
}

pub fn main() {}

Meta

Error output

Expect to compile successfully but got ICE:

crab1: internal compiler error: in visit, at rust/backend/rust-compile-pattern.cc:563
0x278bc0c internal_error(char const*, ...)
    ???:0
0xadc501 fancy_abort(char const*, int, char const*)
    ???:0
0xe86535 Rust::Compile::CompilePatternBindings::visit(Rust::HIR::StructPattern&)
    ???:0
0xe94c02 Rust::Compile::CompileExpr::visit(Rust::HIR::MatchExpr&)
    ???:0
0xe8f5a4 Rust::Compile::CompileExpr::Compile(Rust::HIR::Expr*, Rust::Compile::Context*)
    ???:0
0xe9e156 Rust::Compile::CompileBlock::visit(Rust::HIR::BlockExpr&)
    ???:0
0xe9e3fd Rust::Compile::CompileBlock::compile(Rust::HIR::BlockExpr*, Rust::Compile::Context*, Bvariable*)
    ???:0
0xe9144f Rust::Compile::CompileExpr::visit(Rust::HIR::BlockExpr&)
    ???:0
0xe8f5a4 Rust::Compile::CompileExpr::Compile(Rust::HIR::Expr*, Rust::Compile::Context*)
    ???:0
0xeb3694 Rust::Compile::HIRCompileBase::compile_function_body(tree_node*, Rust::HIR::BlockExpr&, Rust::TyTy::BaseType*)
    ???:0
0xeb6269 Rust::Compile::HIRCompileBase::compile_function(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Rust::HIR::SelfParam&, std::vector<Rust::HIR::FunctionParam, std::allocator<Rust::HIR::FunctionParam> >&, Rust::HIR::FunctionQualifiers const&, Rust::HIR::Visibility&, std::vector<Rust::AST::Attribute, std::allocator<Rust::AST::Attribute> >&, unsigned int, Rust::HIR::BlockExpr*, Rust::Resolver::CanonicalPath const&, Rust::TyTy::FnType*)
    ???:0
0xe8c328 Rust::Compile::CompileItem::visit(Rust::HIR::Function&)
    ???:0
0xc374f9 Rust::Compile::CompileCrate::go()
    ???:0
0xc37578 Rust::Compile::CompileCrate::Compile(Rust::HIR::Crate&, Rust::Compile::Context*)
    ???:0
0xc31914 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
...
Backtrace

``` crab1: internal compiler error: in visit, at rust/backend/rust-compile-pattern.cc:563 0x278bc0c internal_error(char const*, ...) ???:0 0xadc501 fancy_abort(char const*, int, char const*) ???:0 0xe86535 Rust::Compile::CompilePatternBindings::visit(Rust::HIR::StructPattern&) ???:0 0xe94c02 Rust::Compile::CompileExpr::visit(Rust::HIR::MatchExpr&) ???:0 0xe8f5a4 Rust::Compile::CompileExpr::Compile(Rust::HIR::Expr*, Rust::Compile::Context*) ???:0 0xe9e156 Rust::Compile::CompileBlock::visit(Rust::HIR::BlockExpr&) ???:0 0xe9e3fd Rust::Compile::CompileBlock::compile(Rust::HIR::BlockExpr*, Rust::Compile::Context*, Bvariable*) ???:0 0xe9144f Rust::Compile::CompileExpr::visit(Rust::HIR::BlockExpr&) ???:0 0xe8f5a4 Rust::Compile::CompileExpr::Compile(Rust::HIR::Expr*, Rust::Compile::Context*) ???:0 0xeb3694 Rust::Compile::HIRCompileBase::compile_function_body(tree_node*, Rust::HIR::BlockExpr&, Rust::TyTy::BaseType*) ???:0 0xeb6269 Rust::Compile::HIRCompileBase::compile_function(std::__cxx11::basic_string, std::allocator > const&, Rust::HIR::SelfParam&, std::vector >&, Rust::HIR::FunctionQualifiers const&, Rust::HIR::Visibility&, std::vector >&, unsigned int, Rust::HIR::BlockExpr*, Rust::Resolver::CanonicalPath const&, Rust::TyTy::FnType*) ???:0 0xe8c328 Rust::Compile::CompileItem::visit(Rust::HIR::Function&) ???:0 0xc374f9 Rust::Compile::CompileCrate::go() ???:0 0xc37578 Rust::Compile::CompileCrate::Compile(Rust::HIR::Crate&, Rust::Compile::Context*) ???:0 0xc31914 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 for instructions. Compiler returned: 1 ```

tamaroning commented 1 month ago

Can someone assign this issue and #3070 to me?

tamaroning commented 1 month ago

Similar case which causes ICE https://godbolt.org/z/5fKb44T5a

liamnaddell commented 1 month ago

@tamaroning , one thing I've done to make sure efforts aren't duplicated is to create draft commits with the issue tagged in the title, that makes it so that whenever you push, it puts a message onto the issue saying that I'm working on it. EX: https://github.com/Rust-GCC/gccrs/issues/3045

tamaroning commented 1 month ago

Thanks :)