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

Fatal runtime error and illegal instruction when compiling with LTO #11683

Closed
dotdash opened this issue Jan 20, 2014 · 4 comments · Fixed by #11711
Closed

Fatal runtime error and illegal instruction when compiling with LTO #11683

dotdash opened this issue Jan 20, 2014 · 4 comments · Fixed by #11711

Comments

@dotdash
Copy link
Contributor

dotdash commented Jan 20, 2014

After reading http://thornydev.blogspot.co.uk/2014/01/chinese-whispers-in-rust.html I tried to compile the example code with -Z lto. The resulting binary crashes with a fatal runtime error.

Code:

static N:int = 100000;

//
// Chinese Whispers in Rust
// Based on example by Rob Pike
// in http://www.youtube.com/watch?v=f6kdp27TYZs
//
fn main() {
    let (leftmost_port, leftmost_chan) = Chan::new();
    let mut leftc: Chan<int> = leftmost_chan;
    let mut rightp: Port<int>;

    for _ in range(0, N) {
        let (right_port, right_chan) = Chan::new();
        rightp = right_port;
        let c = leftc;
        let p = rightp;
        do spawn {
            whisper(c, p);
        }
        leftc = right_chan;
    }
    let rightmost_chan = leftc;
    do spawn {
        rightmost_chan.send(1);
    }
    println!("{}", leftmost_port.recv());
}

fn whisper(left: Chan<int>, right: Port<int>) {
    left.send( right.recv() + 1 );
}

Output without LTO:

$ ./chinese 
100001

Output with LTO:

$ ./chinese 



There are not many persons who know what wonders are opened to them in the
stories and visions of their youth; for when as children we listen and dream,
we think but half-formed thoughts, and when as men we try to remember, we are
dulled and prosaic with the poison of life. But some of us awake in the night
with strange phantasms of enchanted hills and gardens, of fountains that sing
in the sun, of golden cliffs overhanging murmuring seas, of plains that stretch
down to sleeping cities of bronze and stone, and of shadowy companies of heroes
that ride caparisoned white horses along the edges of thick forests; and then
we know that we have looked back through the ivory gates into that world of
wonder which was ours before we were wise and unhappy.

fatal runtime error:  assertion failed: !ptr.is_null()
Illegal instruction

Sometimes the error message is printed more than once.

@dotdash
Copy link
Contributor Author

dotdash commented Jan 20, 2014

A smaller example that also triggers the error:

fn main() {
    let (p, c) = Chan::<int>::new();

    do spawn {
        c.send(1);
    }
    println!("{}", p.recv());
}

@alexcrichton
Copy link
Member

What system are you running on and can you provide the exact invocations of rustc? I'm unable to reproduce this on OSX and linux so far.

@dotdash
Copy link
Contributor Author

dotdash commented Jan 21, 2014

Reproduced on two (quite similar) i7-3770(K) systems. Both running an up-to-date Debian Sid.
uname -a says Linux bs 3.12-1-amd64 #1 SMP Debian 3.12.6-2 (2013-12-29) x86_64 GNU/Linux

I just noticed that it doesn't fail if you don't pass -O.

Invocation that triggers the failure:

bs@bs:rust-play $ rustc -O -Z lto issue11683.rs
bs@bs:rust-play $ ./issue11683 
1
bs@bs:rust-play $ ./issue11683 
1
bs@bs:rust-play $ ./issue11683 
1


There are not many persons who know what wonders are opened to them in the
stories and visions of their youth; for when as children we listen and dream,
we think but half-formed thoughts, and when as men we try to remember, we are
dulled and prosaic with the poison of life. But some of us awake in the night
with strange phantasms of enchanted hills and gardens, of fountains that sing
in the sun, of golden cliffs overhanging murmuring seas, of plains that stretch
down to sleeping cities of bronze and stone, and of shadowy companies of heroes
that ride caparisoned white horses along the edges of thick forests; and then
we know that we have looked back through the ivory gates into that world of
wonder which was ours before we were wise and unhappy.

fatal runtime error:  assertion failed: !ptr.is_null()
Illegal instruction

@alexcrichton
Copy link
Member

Well then. That's 6 hours of my life I'll never get back :)

Not exactly the bug I was expecting to find...

bors added a commit that referenced this issue Jan 22, 2014
There's lots of fun rationale in the comments of the diff.

Closes #11683
flip1995 pushed a commit to flip1995/rust that referenced this issue Oct 21, 2023
…flip1995

Deserialize `Msrv` directly in `Conf`

Gives the error a span pointing to the invalid config value

Also puts `Conf` itself in the `OnceLock` rather than just the `Msrv` for [the `register_late_mod_pass` work](rust-lang#116731) since it will be used from two different callbacks

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants