Skip to content

Commit

Permalink
Rollup merge of rust-lang#46812 - kennytm:fix-align-offset-sign, r=pe…
Browse files Browse the repository at this point in the history
…trochenkov

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.
  • Loading branch information
GuillaumeGomez authored Dec 18, 2017
2 parents 325d9fb + 749d8a8 commit c68c4b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/librustc_trans/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
let zero = C_null(bcx.ccx.isize_ty());
// `offset == 0`
let is_zero = bcx.icmp(llvm::IntPredicate::IntEQ, offset, zero);
// `if offset == 0 { 0 } else { offset - align }`
bcx.select(is_zero, zero, bcx.sub(offset, align))
// `if offset == 0 { 0 } else { align - offset }`
bcx.select(is_zero, zero, bcx.sub(align, offset))
}
name if name.starts_with("simd_") => {
match generic_simd_intrinsic(bcx, name,
Expand Down
16 changes: 16 additions & 0 deletions src/test/run-pass/align-offset-sign.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(align_offset)]

fn main() {
let x = 1 as *const u8;
assert_eq!(x.align_offset(8), 7);
}

0 comments on commit c68c4b5

Please sign in to comment.