Closed
Description
When compiling the following code (which is a minimized version of impl_to_primitive_int_to_int!
from libcore/num/mod.rs) on AArch64 with rustc from 2015-01-24, the output is unfortunately NO :(
use std::num::Int;
fn main() {
let n = 960 as i64;
let min_value: i32 = Int::min_value();
if min_value as i64 <= n {
println!("OK :)");
} else {
println!("NO :(")
}
}
The disassembled code of main
starts as:
00000000000071ec <_ZN4main20h2d56baed33734ff2faaE>:
71ec: a9be6ffc stp x28, x27, [sp,#-32]!
71f0: a9017bfd stp x29, x30, [sp,#16]
71f4: 910043fd add x29, sp, #0x10
71f8: d10443ff sub sp, sp, #0x110
71fc: b27a0fe8 orr x8, xzr, #0x3c0
7200: f81e83a8 str x8, [x29,#-24]
7204: 94000048 bl 7324 <_ZN3num7i32.Int9min_value20hb9150aaae7f1b75agpbE>
7208: b81e43a0 str w0, [x29,#-28]
720c: b89e43a8 ldrsw x8, [x29,#-28]
7210: 2a0803e0 mov w0, w8
7214: 2a0003e8 mov w8, w0
7218: f85e83a9 ldr x9, [x29,#-24]
721c: eb09011f cmp x8, x9
The problem is with the two moves at 0x7210
and 0x7214
, which erroneously clear the top 32 bits of x8
, which thus becomes 0x80000000
instead of the expected 0xffffffff80000000
.
The error was first found in the rustup_20150109 branch of Servo (servo/servo#4716), but the latest Rust also exhibits the problem (as shown above).