Rust-GCC / gccrs

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

Parser ICE on syntax error in match arm block #1210

Open dafaust opened 2 years ago

dafaust commented 2 years ago

I tried this code:

enum E {
    One,
    Two,
    Other
}

fn foo (x: E) -> i32 {
    let mut y = 0;

    match x {
        E::One => {
            y = 1,
        }
        E::Two => {
            y = 2;
        }
        _ => {}
    }

    return y;
}

fn main () {
    let x = E::One;
    let y = foo (x);
}

I expected to see this happen:

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `,`
  --> bad.rs:12:18
   |
12 |             y = 1,
   |                  ^ expected one of `.`, `;`, `?`, `}`, or an operator

error: aborting due to previous error

Instead, this happened:

rust1: internal compiler error: Segmentation fault
0x15c4a2f crash_signal
    ../../gccrs/gcc/toplev.cc:322
0x7f86dfc0591f ???
    ./signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
0xe9df8a Rust::Parser<Rust::Lexer>::parse_expr_stmt_with_block(std::vector<Rust::AST::Attribute, std::allocator<Rust::AST::Attribute> >)
    ../../gccrs/gcc/rust/parse/rust-parse-impl.h:7276
0xe928dd Rust::Parser<Rust::Lexer>::parse_expr_stmt(std::vector<Rust::AST::Attribute, std::allocator<Rust::AST::Attribute> >, Rust::ParseRestrictions)
    ../../gccrs/gcc/rust/parse/rust-parse-impl.h:7137
0xe721da Rust::Parser<Rust::Lexer>::parse_expr_with_block(std::vector<Rust::AST::Attribute, std::allocator<Rust::AST::Attribute> >)
    ../../gccrs/gcc/rust/parse/rust-parse-impl.h:7225
0xe48f1c Rust::Parser<Rust::Lexer>::parse_stmt_or_expr_without_block()
    ../../gccrs/gcc/rust/parse/rust-parse-impl.h:11730
0xe39973 Rust::Parser<Rust::Lexer>::parse_block_expr(std::vector<Rust::AST::Attribute, std::allocator<Rust::AST::Attribute> >, Location)
    ../../gccrs/gcc/rust/parse/rust-parse-impl.h:7454
0xe2bed9 Rust::Parser<Rust::Lexer>::parse_function(Rust::AST::Visibility, std::vector<Rust::AST::Attribute, std::allocator<Rust::AST::Attribute> >)
    ../../gccrs/gcc/rust/parse/rust-parse-impl.h:2698
0xe15316 Rust::Parser<Rust::Lexer>::parse_item(bool)
    ../../gccrs/gcc/rust/parse/rust-parse-impl.h:1061
0xe082a4 Rust::Parser<Rust::Lexer>::parse_items()
    ../../gccrs/gcc/rust/parse/rust-parse-impl.h:403
0xec1225 Rust::Parser<Rust::Lexer>::parse_crate()
    ../../gccrs/gcc/rust/parse/rust-parse-impl.h:432
0xeb6cbe Rust::Session::parse_file(char const*)
    ../../gccrs/gcc/rust/rust-session-manager.cc:647
0xeb6731 Rust::Session::parse_files(int, char const**)
    ../../gccrs/gcc/rust/rust-session-manager.cc:572
0xd95a34 grs_langhook_parse_file
    ../../gccrs/gcc/rust/rust-lang.cc:174

Meta

philberty commented 2 years ago

This change might have affected this: https://github.com/Rust-GCC/gccrs/pull/1144/files#diff-0ec0ef9112d5a4a50636e9fde592f348f936f51b4139796976c7ad1608f935f8

commit fe10ca37aba8f3cb9bfaa9dd01bdb1329317cf21 related to #1081