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

Weird behavior when comparing function pointers #54695

Closed
VictorKoenders opened this issue Sep 30, 2018 · 1 comment
Closed

Weird behavior when comparing function pointers #54695

VictorKoenders opened this issue Sep 30, 2018 · 1 comment

Comments

@VictorKoenders
Copy link

VictorKoenders commented Sep 30, 2018

As per the discussion on twitter

This piece of code in release mode has weird behavior when comparing 2 pointers twice. This behavior happens only in release mode and does appear on stable.

It looks like a LLVM optimization to me, @eddyb thinks it "might be an accidental optimization"

fn foo(_: i32) -> i32 {
    1
}
fn bar(_: i32) -> i32 {
    1
}

fn main() {
    let x: fn(i32) -> i32 = foo;
    let y: fn(i32) -> i32 = bar;
    
    if x == y {
        println!("true")
    } else {
        println!("false {:?}", x);
    }

    if x == y {
        println!("true")
    } else {
        println!("false {:?}", x);
    }
}
false 0x55eabbd342f0
true

play.rust-lang.org link

@sfackler
Copy link
Member

Duplicate of #54685.

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

No branches or pull requests

2 participants