-
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
Returning [i128::MIN; 1] from a function actually returns [0i128; 1] #101585
Comments
I wonder if rust/compiler/rustc_codegen_ssa/src/mir/rvalue.rs Lines 90 to 94 in 8778809
It does look to be inappropriately turning the repeat into a memset (when looking at the llvm IR) |
https://godbolt.org/z/4xz1d4Tz9 pub fn min_array_ok() -> [i128; 1] {
[i128::MIN]
}
pub fn min_array_nok() -> [i128; 1] {
[i128::MIN; 1]
} with define void @_ZN7example12min_array_ok17h64ef6889d5bfe023E(ptr sret([1 x i128]) %0) unnamed_addr #0 !dbg !6 {
start:
%1 = getelementptr inbounds [1 x i128], ptr %0, i64 0, i64 0, !dbg !11
store i128 -170141183460469231731687303715884105728, ptr %1, align 8, !dbg !11
ret void, !dbg !12
}
define void @_ZN7example13min_array_nok17h5f347fb6a42ac96fE(ptr sret([1 x i128]) %0) unnamed_addr #0 !dbg !13 {
start:
%1 = getelementptr inbounds [1 x i128], ptr %0, i64 0, i64 0, !dbg !14
call void @llvm.memset.p0.i64(ptr align 8 %1, i8 0, i64 16, i1 false), !dbg !14
ret void, !dbg !15
} Which does not seem right. We shouldn't be emitting a memset to 0 there. |
This program hits an LLVM assertion if compiled with an LLVM that has assertions enabled:
|
This appeared in A bisection between those two stable releases points to a group of old PR but I can't really pinpoint one :/
|
pub fn min_array_nok() -> [i128; 1] {
[std::i128::MIN; 1]
} fails even under 1.26. And before that, i128 didn't even exist. So this has been a problem since 128 bit ints were introduced, as far as I can see. |
Thank you for the analysis and the fix :) |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-critical |
Array created using repeat expression
[i128::MIN; 1]
and returned from a function actually returns[0i128; 1]
.Interestingly the problem does not happen when using the list syntax
[i128::MIN]
to create the array.I tried this code:
I expected to see this happen: the second
assert_eq
should passInstead, this happened: the second
assert_eq
fails screaming thatMeta
Problem exists on stable, beta and nightly
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: