Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault when matching on enums #38002

Closed
justinj opened this issue Nov 25, 2016 · 4 comments
Closed

Segfault when matching on enums #38002

justinj opened this issue Nov 25, 2016 · 4 comments
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@justinj
Copy link

justinj commented Nov 25, 2016

This code (playground link) gives me a segfault on the current beta:

#[derive(Clone, Copy)]
enum Bar {
    C
}

#[derive(Clone, Copy)]
enum Foo {
    A {},
    B {
        y: f64,
        z: Bar
    },
}

fn f(s: &Foo) {
    match s {
        &Foo::A {} => {
        },
        &Foo::B { y: _y, z: ref _side } => {
        }
    }
}

const LIST: [(usize, Foo); 2] = [
    (51, Foo::B {
        y: 0.,
        z: Bar::C
    }),
    (52, Foo::B {
        y: 0.,
        z: Bar::C
    }),
];

pub fn main() {
    for &r in LIST.iter() {
        let (i, s) = r;
        println!("{}", i);
        f(&s);
    }
}

I've reduced it as much as I can, even removing the A constructor on the enum causes it to work.

I expect the output to be

51
52

(which it is on stable),
but instead I get

51
0
<segfault>
@sfackler sfackler added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Nov 25, 2016
@sfackler
Copy link
Member

Appears to be broken on nightly as well - I get a stack overflow on x86_64 darwin.

@sfackler sfackler added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 25, 2016
@frewsxcv
Copy link
Member

FWIW, I don't get a segfault on beta or nightly with the playpen, I just get this output for both:

51
0

@TimNN
Copy link
Contributor

TimNN commented Nov 26, 2016

The stackoverflow on x86_64 darwin goes away for me on any -C opt-level>0.

@TimNN
Copy link
Contributor

TimNN commented Nov 26, 2016

This strongly reminds me of #37222 and #36401.

arielb1 added a commit to arielb1/rust that referenced this issue Nov 27, 2016
bors added a commit that referenced this issue Nov 27, 2016
don't double-apply variant padding to const enums

`build_const_struct` already returns the struct with padding - don't double-apply it in the `General` case.

This should hopefully be the last time we have this sort of bug.

Fixes #38002.

Beta-nominating because regression.

r? @eddyb
brson pushed a commit to brson/rust that referenced this issue Dec 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants