diff options
| author | kennytm <kennytm@gmail.com> | 2017-12-18 22:52:24 +0800 |
|---|---|---|
| committer | kennytm <kennytm@gmail.com> | 2017-12-18 22:52:24 +0800 |
| commit | 749d8a880f4502f2d8104bfb1faf15c38fd72d53 (patch) | |
| tree | 8932a53229d918430d8781d18aecb0a4e72d258d | |
| parent | a3a7203e2c9ed30a501da86f3fa1f9efe707ac94 (diff) | |
| download | rust-749d8a880f4502f2d8104bfb1faf15c38fd72d53.tar.gz rust-749d8a880f4502f2d8104bfb1faf15c38fd72d53.zip | |
Fix the wrong subtraction in align_offset intrinsic.
| -rw-r--r-- | src/librustc_trans/intrinsic.rs | 4 | ||||
| -rw-r--r-- | src/test/run-pass/align-offset-sign.rs | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/librustc_trans/intrinsic.rs b/src/librustc_trans/intrinsic.rs index f1cb8b224b3..3cd60e7f1bc 100644 --- a/src/librustc_trans/intrinsic.rs +++ b/src/librustc_trans/intrinsic.rs @@ -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, diff --git a/src/test/run-pass/align-offset-sign.rs b/src/test/run-pass/align-offset-sign.rs new file mode 100644 index 00000000000..aaa0419d061 --- /dev/null +++ b/src/test/run-pass/align-offset-sign.rs @@ -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); +} |
