]> git.lizzy.rs Git - rust.git/blobdiff - example/mini_core_hello_world.rs
Fix rotate_left and rotate_right with 128bit shift amount
[rust.git] / example / mini_core_hello_world.rs
index d83fb2aece91d322af5327e121000362f8e570e4..47abe2d1de80057ab3dc3c0d9d38e8e162957985 100644 (file)
@@ -1,9 +1,4 @@
-// Adapted from https://github.com/sunfishcode/mir2cranelift/blob/master/rust-examples/nocore-hello-world.rs
-
-#![feature(
-    no_core, unboxed_closures, start, lang_items, box_syntax, never_type, linkage,
-    extern_types, thread_local
-)]
+#![feature(no_core, lang_items, box_syntax, never_type, linkage, extern_types, thread_local)]
 #![no_core]
 #![allow(dead_code, non_camel_case_types)]
 
@@ -241,19 +236,22 @@ unsafe fn uninitialized<T>() -> T {
 
     assert_eq!(((|()| 42u8) as fn(()) -> u8)(()), 42);
 
-    extern {
-        #[linkage = "extern_weak"]
-        static ABC: *const u8;
-    }
-
+    #[cfg(not(any(jit, windows)))]
     {
         extern {
             #[linkage = "extern_weak"]
             static ABC: *const u8;
         }
-    }
 
-    unsafe { assert_eq!(ABC as usize, 0); }
+        {
+            extern {
+                #[linkage = "extern_weak"]
+                static ABC: *const u8;
+            }
+        }
+
+        unsafe { assert_eq!(ABC as usize, 0); }
+    }
 
     &mut (|| Some(0 as *const ())) as &mut dyn FnMut() -> Option<*const ()>;
 
@@ -263,6 +261,9 @@ unsafe fn uninitialized<T>() -> T {
     assert_eq!(f2 as i8, -128);
     assert_eq!(f2 as u8, 0);
 
+    let amount = 0;
+    assert_eq!(1u128 << amount, 1);
+
     static ANOTHER_STATIC: &u8 = &A_STATIC;
     assert_eq!(*ANOTHER_STATIC, 42);
 
@@ -282,21 +283,32 @@ struct ExternTypeWrapper {
     let slice_ptr = &[] as *const [u8];
     slice_ptr as *const u8;
 
-    #[cfg(not(jit))]
+    let repeat = [Some(42); 2];
+    assert_eq!(repeat[0], Some(42));
+    assert_eq!(repeat[1], Some(42));
+
+    from_decimal_string();
+
+    #[cfg(not(any(jit, windows)))]
     test_tls();
 
-    #[cfg(not(jit))]
+    #[cfg(all(not(jit), target_os = "linux"))]
     unsafe {
         global_asm_test();
     }
+
+    // Both statics have a reference that points to the same anonymous allocation.
+    static REF1: &u8 = &42;
+    static REF2: &u8 = REF1;
+    assert_eq!(*REF1, *REF2);
 }
 
-#[cfg(not(jit))]
+#[cfg(all(not(jit), target_os = "linux"))]
 extern "C" {
     fn global_asm_test();
 }
 
-#[cfg(not(jit))]
+#[cfg(all(not(jit), target_os = "linux"))]
 global_asm! {
     "
     .global global_asm_test
@@ -441,3 +453,23 @@ fn check_niche_behavior () {
         intrinsics::abort();
     }
 }
+
+fn from_decimal_string() {
+    loop {
+        let multiplier = 1;
+
+        take_multiplier_ref(&multiplier);
+
+        if multiplier == 1 {
+            break;
+        }
+
+        unreachable();
+    }
+}
+
+fn take_multiplier_ref(_multiplier: &u128) {}
+
+fn unreachable() -> ! {
+    panic("unreachable")
+}