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

Rust programming giving signal 4 (Illegal instruction) while modifying value inside a match statement #19367

Closed
daboross opened this issue Nov 28, 2014 · 3 comments
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Comments

@daboross
Copy link
Contributor

I'm getting "An unknown error occurred" when trying to use a value that I got out of a match statement - when I set the thing being matched upon to None.

Here's the code to reproduce this:

struct Client {
    option: Option<String>,
}

fn main() {
    let mut client = Client {
        option: Some("address".into_string())
    };
    let address = match client.option {
        Some(v) => {
            // This seems to make 'v' invalid, but still lets me use it
            client.option = None;
            v
        },
        None => return
    };
    println!("Cloning")
    // This is where the error occurs
    address.clone();
}

The output when running via cargo:

$ cargo run
   Compiling test-irc v0.0.1 (file:///home/daboross/Projects/Rust/Learn/test-irc)
     Running `target/test-irc`
Cloning
An unknown error occurred

To learn more, run the command again with --verbose.

The output when running via gdb:

Starting program: /home/daboross/Projects/Rust/test-irc/target/test-irc 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Cloning

Program received signal SIGSEGV, Segmentation fault.
0x000055555555bf0e in ptr::write::h984757489268428869 ()

Here's a rust playpen share with the code in it: http://is.gd/GCa24t

This occurs when using the above code in the playpen, though here are my system details in case it matters:

$ rustc --version=verbose
rustc 0.13.0-nightly (fac5a0767 2014-11-26 22:37:06 +0000)
binary: rustc
commit-hash: fac5a07679cac21a580badc84b755b8df0f975cf
commit-date: 2014-11-26 22:37:06 +0000
host: x86_64-unknown-linux-gnu
release: 0.13.0-nightly
$ uname -a
Linux M14x 3.13.0-39-generic #66-Ubuntu SMP Tue Oct 28 13:30:27 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: elementary OS
Description:    elementary OS Freya
Release:    0.3
Codename:   freya
@daboross
Copy link
Contributor Author

Noting that when using --opt-level 1, there is no error, but it does occur with --opt-level 0, --opt-level 2, --opt-level 3, and without a --opt-level parameter.

@huonw huonw added I-nominated I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. labels Nov 28, 2014
@huonw
Copy link
Member

huonw commented Nov 28, 2014

cc @luqmana, I have a feeling this is related to the by-value optimisations you(I think?) added a while ago.

stl on IRC gave a slight variation:

struct S { o: Option<String> }

fn main() {
    let mut s = S{ o: Some("right".into_string()) };  
    let b = match s.o {
        Some(v) => {
            s.o = Some("wrong".into_string());
            v
        }
        None => String::new(),
    }; 
    println!("{}", b);
}

It prints wrong.

daboross added a commit to daboross/zaldinar that referenced this issue Nov 28, 2014
…s_message function, and fix a SIGSEGV (see rust-lang/rust#19367).

Note that at this point the bot is still not completely functional, as it does not have any listeners - so it doesn't respond to 004 or PING or PRIVMSG
@luqmana
Copy link
Member

luqmana commented Dec 5, 2014

Yea... I know what's wrong here (basically same issue as in #15571). Fun fact, it'd also fail if that were tuple indexing. Anyways, I'll have a fix up soon.

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.
Projects
None yet
3 participants