fix unsafe warnings

This commit is contained in:
Jorge Aparicio 2016-10-07 17:48:37 -05:00
parent fd69beba29
commit c82403551d
7 changed files with 16 additions and 22 deletions

View File

@ -25,7 +25,4 @@ compiler-rt = { path = "compiler-rt" }
c = []
weak = ["rlibc/weak"]
[profile.dev]
debug-assertions = false
[workspace]

View File

@ -29,13 +29,14 @@ case $1 in
esac
# Verify that there are no undefined symbols to `panic` within our implementations
# TODO(#79) fix the undefined references problem for debug-assertions+lto
case $1 in
thumb*)
xargo rustc --features c --target $1 --bin intrinsics -- -C lto
RUSTFLAGS="-C debug-assertions=no" xargo rustc --features c --target $1 --bin intrinsics -- -C lto
xargo rustc --features c --target $1 --bin intrinsics --release -- -C lto
;;
*)
cargo rustc --features c --target $1 --bin intrinsics -- -C lto
RUSTFLAGS="-C debug-assertions=no" cargo rustc --features c --target $1 --bin intrinsics -- -C lto
cargo rustc --features c --target $1 --bin intrinsics --release -- -C lto
;;
esac

View File

@ -308,9 +308,7 @@ fn run() {
// We use volatile load/stores to prevent LLVM from optimizing away the intrinsics during LTO
macro_rules! arg {
() => {
unsafe {
ptr::read_volatile(0x0 as *const _)
}
ptr::read_volatile(0x0 as *const _)
}
}

View File

@ -1,4 +1,5 @@
use core::mem;
#[cfg(test)]
use core::fmt;
pub mod add;

View File

@ -1,5 +1,3 @@
use core::intrinsics;
macro_rules! pow {
($intrinsic:ident: $fty:ty, $ity:ident) => {
/// Returns `a` raised to the power `b`

View File

@ -1,5 +1,3 @@
use core::intrinsics;
use int::Int;
macro_rules! div {
@ -13,7 +11,7 @@ macro_rules! div {
let b = (b ^ s_b) - s_b;
let s = s_a ^ s_b;
let r = udiv!((a as $uty), (b as $uty));
let r = udiv!(a as $uty, b as $uty);
(r as $ty ^ s) - s
}
}
@ -29,7 +27,7 @@ macro_rules! mod_ {
let s = a >> (<$ty>::bits() - 1);
let a = (a ^ s) - s;
let r = urem!((a as $uty), (b as $uty));
let r = urem!(a as $uty, b as $uty);
(r as $ty ^ s) - s
}
}

View File

@ -13,6 +13,7 @@
// NOTE cfg(all(feature = "c", ..)) indicate that compiler-rt provides an arch optimized
// implementation of that intrinsic and we'll prefer to use that
// TODO(rust-lang/rust#37029) use e.g. checked_div(_).unwrap_or_else(|| abort())
macro_rules! udiv {
($a:expr, $b:expr) => {
unsafe {
@ -20,9 +21,9 @@ macro_rules! udiv {
let b = $b;
if b == 0 {
intrinsics::abort()
::core::intrinsics::abort()
} else {
intrinsics::unchecked_div(a, b)
::core::intrinsics::unchecked_div(a, b)
}
}
}
@ -35,9 +36,9 @@ macro_rules! sdiv {
let b = $b;
if b == 0 || (b == -1 && a == $sty::min_value()) {
intrinsics::abort()
::core::intrinsics::abort()
} else {
intrinsics::unchecked_div(a, b)
::core::intrinsics::unchecked_div(a, b)
}
}
}
@ -50,9 +51,9 @@ macro_rules! urem {
let b = $b;
if b == 0 {
intrinsics::abort()
::core::intrinsics::abort()
} else {
intrinsics::unchecked_rem(a, b)
::core::intrinsics::unchecked_rem(a, b)
}
}
}
@ -65,9 +66,9 @@ macro_rules! srem {
let b = $b;
if b == 0 || (b == -1 && a == $sty::min_value()) {
intrinsics::abort()
::core::intrinsics::abort()
} else {
intrinsics::unchecked_rem(a, b)
::core::intrinsics::unchecked_rem(a, b)
}
}
}