Selaa lähdekoodia

fix unsafe warnings

Jorge Aparicio 8 vuotta sitten
vanhempi
commit
c82403551d
7 muutettua tiedostoa jossa 16 lisäystä ja 22 poistoa
  1. 0 3
      Cargo.toml
  2. 3 2
      ci/run.sh
  3. 1 3
      src/bin/intrinsics.rs
  4. 1 0
      src/float/mod.rs
  5. 0 2
      src/float/pow.rs
  6. 2 4
      src/int/sdiv.rs
  7. 9 8
      src/lib.rs

+ 0 - 3
Cargo.toml

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

+ 3 - 2
ci/run.sh

@@ -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

+ 1 - 3
src/bin/intrinsics.rs

@@ -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 _)
         }
     }
 

+ 1 - 0
src/float/mod.rs

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

+ 0 - 2
src/float/pow.rs

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

+ 2 - 4
src/int/sdiv.rs

@@ -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
         }
     }

+ 9 - 8
src/lib.rs

@@ -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)
             }
         }
     }