-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
getting parity of signed integer maximum or minimum results in stack overflow #37991
Comments
Note that literals don't invoke the bug: assert_eq!(127i8 % 2, 1);
assert_eq!(-9223372036854775808i64 % 2, 0); |
When I look at the stack, it seems to look like a MIR issue... |
The stack trace looks like this:
|
cc @eddyb |
The minimal reproduction is The stack trace may suggest some cycle at the MIR level, which would be weird, or accidental recursion. EDIT: ah, here's the signedness' relevance: bb0: {
StorageLive(_2);
_2 = core::num::<impl i64>::max_value() -> bb1;
}
bb1: {
_3 = Eq(const 2i64, const 0i64);
assert(!_3, "attempt to calculate the remainder with a divisor of zero") -> bb2;
}
bb2: {
_4 = Eq(const 2i64, const -1i64);
_5 = Eq(_2, const -9223372036854775808i64);
_6 = BitAnd(_4, _5);
assert(!_6, "attempt to calculate the remainder with overflow") -> bb3;
}
bb3: {
_1 = Rem(_2, const 2i64);
StorageDead(_2);
} |
triage: P-high |
@eddyb any luck tracking this down? |
Found the culprit: when we don't want to steal the call, we're not taking the destination out of the clone. The reason the "stealing" case is complex in the first place is to get the |
@eddyb will backport for 1.15 on feb 2. |
#38408 is a duplicate, so whoever fixes this should check that out too. |
This needs to be fixed and backported soon. Release is feb 2. I'd like this backported by the third week of jan at latest. |
I'll give it a try later today. |
Sorry, I think the code is too unfamiliar to me. I don't want to fix it anymore :) @arielb1 do you want to take over? |
promotion of MIR terminators used to try to promote the destination it is trying to promote, leading to stack overflow. Fixes rust-lang#37991.
fix promotion of MIR terminators promotion of MIR terminators used to try to promote the destination it is trying to promote, leading to stack overflow. Also clean up the code in `promote_temp` a bit to make it more understandable. Fixes #37991. cc @nikomatsakis r? @eddyb
promotion of MIR terminators used to try to promote the destination it is trying to promote, leading to stack overflow. Fixes rust-lang#37991.
Some examples that cause rustc to overflow its stack:
Give error message at compile time:
Gives a stack overflow too if you use
i8
,i16
,i32
, but it can't be reproduced with unsigned types.Also, this doesn't reproduce the stack overflow either:
This dates back to at least rustc 1.12 stable, and is reproducible with recent nightly as well.
The text was updated successfully, but these errors were encountered: