Skip to content

Commit c68c4b5

Browse files
authoredDec 18, 2017
Rollup merge of rust-lang#46812 - kennytm:fix-align-offset-sign, r=petrochenkov
Fix the wrong subtraction in align_offset intrinsic. Given how the stage0 implementation in rust-lang#43903 is written, as well as that in the RFC, I suppose the current implementation has a typo. cc rust-lang#44488, cc @oli-obk.
2 parents 325d9fb + 749d8a8 commit c68c4b5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed
 

‎src/librustc_trans/intrinsic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
406406
let zero = C_null(bcx.ccx.isize_ty());
407407
// `offset == 0`
408408
let is_zero = bcx.icmp(llvm::IntPredicate::IntEQ, offset, zero);
409-
// `if offset == 0 { 0 } else { offset - align }`
410-
bcx.select(is_zero, zero, bcx.sub(offset, align))
409+
// `if offset == 0 { 0 } else { align - offset }`
410+
bcx.select(is_zero, zero, bcx.sub(align, offset))
411411
}
412412
name if name.starts_with("simd_") => {
413413
match generic_simd_intrinsic(bcx, name,
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(align_offset)]
12+
13+
fn main() {
14+
let x = 1 as *const u8;
15+
assert_eq!(x.align_offset(8), 7);
16+
}

0 commit comments

Comments
 (0)
Please sign in to comment.