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

odd issue with #fmt and floats #1388

Closed
erickt opened this issue Dec 27, 2011 · 2 comments
Closed

odd issue with #fmt and floats #1388

erickt opened this issue Dec 27, 2011 · 2 comments

Comments

@erickt
Copy link
Contributor

erickt commented Dec 27, 2011

I've run into a rather weird error with #fmt and floats:

use std;
import std::io;

fn main() {
    let f = -0.550153;
    let s = #fmt("%f", f);
    io::println(s);
}

Incorrectly prints out 0. But if we instead write:

use std;
import std::io;

fn main() {
    let f = -0.550153;
    let s = #fmt("%f", f);
    io::println(s);
    io::println("before " + s + " after");
}

It prints out:

-0.550152
before -0.550152 after
@erickt
Copy link
Contributor Author

erickt commented Dec 27, 2011

There is definitely something weird going on. Probably some memory corruption somewhere. Here's another example:

use std;
import std::io;

fn foo(num: float) -> str {
    assert num < 0.0;
    ret "";
}

fn main() {
    let f = -0.550153;
    log(error, f);
    assert f < 0.0;
    let s = foo(f);
    io::println(s);
    io::println("before " + s + " after");
}

Prints out this scary message:

rust: -0.550153
rust: 0
rust: upcall fail 'Assertion x < 0.0 failed', foo.rs:6
rust: domain main @0x10082a200 root task failed

Even spookier, if you comment out one of the io::println, this bug goes away:

use std;
import std::io;

fn foo(x: float) -> str {
    log(error, x);
    assert x < 0.0;
    ret "";
}

fn main() {
    let f = -0.550153;
    log(error, f);
    assert f < 0.0;
    let s = foo(f);
    io::println(s);
    //io::println("before " + s + " after");
}

Prints out:

rust: -0.550153
rust: -0.550153

@graydon
Copy link
Contributor

graydon commented Dec 29, 2011

This is stack-growth related. The bug goes away when you run with RUST_MIN_STACK=0x1000 ./testcase

Will dig into why that is true tomorrow.

bors added a commit that referenced this issue Apr 18, 2013
Like I commented in #2043, I can't reproduce the weirdness from #1388 on either mac or linux (x84_64) and pushing to try gives all green.

That's 128 less bytes to have to keep in the stack for every call to __morestack.
bjorn3 added a commit to bjorn3/rust that referenced this issue Aug 9, 2023
Pass `preserve_frame_pointers` to Cranelift
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