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

3.2_f32 formatted as 0 on powerpc64le #96306

Closed
NobodyXu opened this issue Apr 22, 2022 · 29 comments
Closed

3.2_f32 formatted as 0 on powerpc64le #96306

NobodyXu opened this issue Apr 22, 2022 · 29 comments
Labels
C-bug Category: This is a bug. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness O-PowerPC Target: PowerPC processors P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@NobodyXu
Copy link
Contributor

NobodyXu commented Apr 22, 2022

In my PR ParkMyCar/compact_str#16 , when formatting 3.2 using std, it gives me 0 on target powerpc64le instead of 3.2 (it works on all other target).

P.S. ryu also format it as 0.0 on it dtolnay/ryu#47

@NobodyXu NobodyXu added the C-bug Category: This is a bug. label Apr 22, 2022
@mbartlett21
Copy link
Contributor

Did you mean dtolnay/ryu#47 for the ryu issue?

@rustbot label +O-PowerPC

@rustbot rustbot added the O-PowerPC Target: PowerPC processors label Apr 23, 2022
@NobodyXu
Copy link
Contributor Author

NobodyXu commented Apr 23, 2022

Did you mean dtolnay/ryu#47 for the ryu issue?

Oh yes, thank you for pointing this out

@NobodyXu
Copy link
Contributor Author

I just tried to reproduce this on my own x86_64 linux box by running:

cross +nightly test --release --all-features --manifest-path=compact_str/Cargo.toml --target powerpc-unknown-linux-gnu

however, all tests passed without problem...

But the test running on github action still failed on powerpc64le

@nagisa nagisa added the I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness label Apr 23, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 23, 2022
@nagisa
Copy link
Member

nagisa commented Apr 23, 2022

Marked this as I-unsound though I don’t really have a definite culprit here. Historically these sorts of problems have been caused by calling convention mismatches, codegen failures or some other similarly scary and “has potential to cause other code to break much more terribly” problem.

@nagisa nagisa added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 23, 2022
@nagisa
Copy link
Member

nagisa commented Apr 23, 2022

I just tried to reproduce this on my own x86_64 linux box by running:

You used a 32-bit PPC target here. Does this reproduce with a powerpc64le target?

cross +nightly test --release --all-features --manifest-path=compact_str/Cargo.toml --target powerpc64le-unknown-linux-gnu

@NobodyXu
Copy link
Contributor Author

cross +nightly test --release --all-features --manifest-path=compact_str/Cargo.toml --target powerpc64le-unknown-linux-gnu

Thanks for pointing this out again!

With the updated command, I was able to reproduce that.

@NobodyXu
Copy link
Contributor Author

NobodyXu commented Apr 24, 2022

Now I was also able to reproduce it using this:

fn main() {
    println!("{}", 3.2_f32);
}

And it gives me 0 using cross +nightly run --release --target powerpc64le-unknown-linux-gnu (the --release flag can be omitted).

@NobodyXu
Copy link
Contributor Author

This is the assembly I get:

0000000000008d50 <tests::main>:
    8d50: 09 00 4c 3c  	addis 2, 12, 9
    8d54: b0 f1 42 38  	addi 2, 2, -3664
    8d58: a6 02 08 7c  	mflr 0
    8d5c: 10 00 01 f8  	std 0, 16(1)
    8d60: 51 ff 21 f8  	stdu 1, -176(1)
    8d64: fd ff 62 3c  	addis 3, 2, -3
    8d68: 6c c4 63 38  	addi 3, 3, -15252
    8d6c: 4d fb ff 4b  	bl 0x88b8
    8d70: 00 00 00 60  	nop
    8d74: 60 00 81 f8  	std 4, 96(1)
    8d78: 68 00 61 f8  	std 3, 104(1)
    8d7c: 60 00 61 e8  	ld 3, 96(1)
    8d80: 68 00 81 e8  	ld 4, 104(1)
    8d84: a0 00 81 f8  	std 4, 160(1)
    8d88: a8 00 61 f8  	std 3, 168(1)
    8d8c: a0 00 c1 38  	addi 6, 1, 160
    8d90: ff ff 62 3c  	addis 3, 2, -1
    8d94: c0 48 83 38  	addi 4, 3, 18624
    8d98: 70 00 61 38  	addi 3, 1, 112
    8d9c: 02 00 a0 38  	li 5, 2
    8da0: 01 00 e0 38  	li 7, 1
    8da4: c5 fd ff 4b  	bl 0x8b68
    8da8: 00 00 00 60  	nop
    8dac: 70 00 61 38  	addi 3, 1, 112
    8db0: 59 77 01 48  	bl 0x20508
    8db4: 00 00 00 60  	nop
    8db8: b0 00 21 38  	addi 1, 1, 176
    8dbc: 10 00 01 e8  	ld 0, 16(1)
    8dc0: a6 03 08 7c  	mtlr 0
    8dc4: 20 00 80 4e  	blr
		...
    8dd4: 00 00 00 60  	nop
    8dd8: 00 00 00 60  	nop
    8ddc: 00 00 00 60  	nop

@apiraino
Copy link
Contributor

apiraino commented May 3, 2022

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-critical

@rustbot rustbot added P-critical Critical priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels May 3, 2022
@pnkfelix
Copy link
Member

pnkfelix commented May 4, 2022

@NobodyXu any chance you can run your test on older versions of the compiler? If this is a regression, then one can even use a tool like https://github.com/rust-lang/cargo-bisect-rustc to identify the point where the regression was injected.

@NobodyXu
Copy link
Contributor Author

NobodyXu commented May 4, 2022

@NobodyXu any chance you can run your test on older versions of the compiler? If this is a regression, then one can even use a tool like https://github.com/rust-lang/cargo-bisect-rustc to identify the point where the regression was injected.

Yes, but since I don't have a power pc, I will have to use cross and cargo-hack to perform regression testing as cross does not work wit cargo-bisect-rustc cross-rs/cross#699

@NobodyXu
Copy link
Contributor Author

NobodyXu commented May 4, 2022

It seems that the bug is fixed on cargo 1.62.0-nightly (f63f23ff1 2022-04-28), ran using command cross +nightly run --target powerpc64le-unknown-linux-gnu (using --release does not change this behavior).

@NobodyXu
Copy link
Contributor Author

NobodyXu commented May 4, 2022

cargo 1.60.0 (d1fd9fe 2022-03-01) also passed the test, ran using command cross run --target powerpc64le-unknown-linux-gnu (using --release does not change this behavior).

@NobodyXu
Copy link
Contributor Author

NobodyXu commented May 5, 2022

I think we need more regression tests in rustc, having float parsing being broken and randomly fixed isn't a sustainable approach to support powerpc64le.

@NobodyXu
Copy link
Contributor Author

NobodyXu commented May 5, 2022

There are still some strange bugs for float on powerpc64le here:

    assert_eq!("-inf", f32::NEG_INFINITY.to_compact_str());

failed with:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"-inf"`,
 right: `"inf"`', compact_str/src/tests.rs:664:5

This works on all other platforms except for powerpc64le.

@apiraino
Copy link
Contributor

apiraino commented May 5, 2022

Re-evaluating priority as per T-compiler meeting on Zulip

@rustbot label +P-high -P-critical

@rustbot rustbot added P-high High priority and removed P-critical Critical priority labels May 5, 2022
@pnkfelix
Copy link
Member

pnkfelix commented May 5, 2022

Those are definitely some worrisome points you raise, @NobodyXu !

I'm hoping someone can help investigate them, and it would certainly be great to flesh out our tests here some more

@NobodyXu
Copy link
Contributor Author

NobodyXu commented May 15, 2022

There are still some strange bugs for float on powerpc64le here:

    assert_eq!("-inf", f32::NEG_INFINITY.to_compact_str());

failed with:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"-inf"`,
 right: `"inf"`', compact_str/src/tests.rs:664:5

This works on all other platforms except for powerpc64le.

On cargo 1.62.0-nightly (3f052d8ee 2022-05-12), the problem described above is fixed.

Edit:

According to the CI log, it's reintroduced on 1.63.0-nightly (42e1761c7 2022-05-15).

@NobodyXu
Copy link
Contributor Author

NobodyXu commented May 16, 2022

@pnkfelix IMO we absolutely need more unit tests for it, as I just witnessed the regression of f32::NEG_INFINITY again on 1.63.0-nightly.

This strange regression that coming back makes it impossible to use compact_str or other crates that depends on the float formatting on powerpc64le reliably.

Edit:

Fixed again on cargo 1.63.0-nightly (3f052d8ee 2022-05-12)

@Emilgardis
Copy link
Contributor

Emilgardis commented Jun 16, 2022

The issues mentioned here might've been issues with QEMU 3.0.1 and fixed with QEMU 5.1.0 (or earlier, 5.1.0 is the version used by latest unreleased cross today), see discussion in cross-rs/cross#803 (comment)

It seems this specific case has not been tested on real hardware, but on newer QEMU versions this works just fine.

EDIT:
For anyone that is hitting this issue while using cross, I highly recommend you try out the new version.

if you're using the Github action actions-rs/cargo you can try out the newer version of cross by adding

- run: cargo install --git https://github.com/cross-rs/cross

before your cargo test/run/build invocation.

We're hoping to land these changes this month so that this will not have to be done.

@NobodyXu
Copy link
Contributor Author

Out of curiosity, does rust-lang run CI on actual powerpc machine?

If not, then is this the reason for powerpc to be a tier 2 platform?

@nagisa
Copy link
Member

nagisa commented Jun 16, 2022 via email

@nagisa
Copy link
Member

nagisa commented Jun 16, 2022

FWIW I’ve just tested the affected crate on a real ppc64le-linux machine running a POWER9 chip. All of 1.58.0, 1.59.0, 1.60.0, 1.61.0, nightly-2022-05-{11,15} successfully ran

cargo +$VER test --release --all-features --manifest-path=compact_str/Cargo.toml --target powerpc64le-unknown-linux-gnu -- --include-ignored

to completion at both master and 0ed53d042202550091a71980458d18cbb3919e64.

@NobodyXu
Copy link
Contributor Author

FWIW I’ve just tested the affected crate on a real ppc64le-linux machine running a POWER9 chip. All of 1.58.0, 1.59.0, 1.60.0, 1.61.0, nightly-2022-05-{11,15} successfully ran

cargo +$VER test --release --all-features --manifest-path=compact_str/Cargo.toml --target powerpc64le-unknown-linux-gnu -- --include-ignored

to completion at both master and 0ed53d042202550091a71980458d18cbb3919e64.

It currently has tests disabled on powerpc, you would need to manually enable it.

@NobodyXu
Copy link
Contributor Author

NobodyXu commented Jun 17, 2022

@nagisa You would need to remove the cfg here (not ignoreed).

The implementation uses crate ryu to provide better performance.
It will still be able to detect compiler bugs on powerpc though, just that sometimes it gives even stranger bugs.

@NobodyXu
Copy link
Contributor Author

@nagisa Checkout this repository I used to reproduce the bug.

@nagisa
Copy link
Member

nagisa commented Jun 17, 2022

As I wrote in the comment above, I tested the commit 0ed53d042202550091a71980458d18cbb3919e64 which removes the cfg in question as well. Was that insufficient?

@NobodyXu
Copy link
Contributor Author

Was that insufficient?

That's sufficient.
Sorry I missed that part.

@pnkfelix
Copy link
Member

Discussed in P-high review

It appears that this problem is resolved, according to the comments here.

Therefore, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness O-PowerPC Target: PowerPC processors P-high High priority 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

7 participants