summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_codegen_cranelift/example
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /compiler/rustc_codegen_cranelift/example
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_codegen_cranelift/example')
-rw-r--r--compiler/rustc_codegen_cranelift/example/alloc_example.rs2
-rw-r--r--compiler/rustc_codegen_cranelift/example/arbitrary_self_types_pointers_and_wrappers.rs3
-rw-r--r--compiler/rustc_codegen_cranelift/example/dst-field-align.rs41
-rw-r--r--compiler/rustc_codegen_cranelift/example/example.rs6
-rw-r--r--compiler/rustc_codegen_cranelift/example/issue-72793.rs4
-rw-r--r--compiler/rustc_codegen_cranelift/example/issue-91827-extern-types.rs5
-rw-r--r--compiler/rustc_codegen_cranelift/example/mini_core.rs52
-rw-r--r--compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs3
-rw-r--r--compiler/rustc_codegen_cranelift/example/mod_bench.rs8
-rw-r--r--compiler/rustc_codegen_cranelift/example/std_example.rs27
-rw-r--r--compiler/rustc_codegen_cranelift/example/subslice-patterns-const-eval.rs11
11 files changed, 100 insertions, 62 deletions
diff --git a/compiler/rustc_codegen_cranelift/example/alloc_example.rs b/compiler/rustc_codegen_cranelift/example/alloc_example.rs
index 4ede2fe4e..d994e2fbc 100644
--- a/compiler/rustc_codegen_cranelift/example/alloc_example.rs
+++ b/compiler/rustc_codegen_cranelift/example/alloc_example.rs
@@ -18,7 +18,7 @@ extern "C" {
}
#[panic_handler]
-fn panic_handler(_: &core::panic::PanicInfo) -> ! {
+fn panic_handler(_: &core::panic::PanicInfo<'_>) -> ! {
core::intrinsics::abort();
}
diff --git a/compiler/rustc_codegen_cranelift/example/arbitrary_self_types_pointers_and_wrappers.rs b/compiler/rustc_codegen_cranelift/example/arbitrary_self_types_pointers_and_wrappers.rs
index d270fec6b..f7edfa960 100644
--- a/compiler/rustc_codegen_cranelift/example/arbitrary_self_types_pointers_and_wrappers.rs
+++ b/compiler/rustc_codegen_cranelift/example/arbitrary_self_types_pointers_and_wrappers.rs
@@ -3,8 +3,8 @@
#![feature(arbitrary_self_types, unsize, coerce_unsized, dispatch_from_dyn)]
use std::{
- ops::{Deref, CoerceUnsized, DispatchFromDyn},
marker::Unsize,
+ ops::{CoerceUnsized, Deref, DispatchFromDyn},
};
struct Ptr<T: ?Sized>(Box<T>);
@@ -33,7 +33,6 @@ impl<T: ?Sized> Deref for Wrapper<T> {
impl<T: CoerceUnsized<U>, U> CoerceUnsized<Wrapper<U>> for Wrapper<T> {}
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<Wrapper<U>> for Wrapper<T> {}
-
trait Trait {
// This method isn't object-safe yet. Unsized by-value `self` is object-safe (but not callable
// without unsized_locals), but wrappers around `Self` currently are not.
diff --git a/compiler/rustc_codegen_cranelift/example/dst-field-align.rs b/compiler/rustc_codegen_cranelift/example/dst-field-align.rs
index 6c338e999..22fc6ff33 100644
--- a/compiler/rustc_codegen_cranelift/example/dst-field-align.rs
+++ b/compiler/rustc_codegen_cranelift/example/dst-field-align.rs
@@ -2,7 +2,7 @@
#![allow(dead_code)]
struct Foo<T: ?Sized> {
a: u16,
- b: T
+ b: T,
}
trait Bar {
@@ -10,58 +10,57 @@ trait Bar {
}
impl Bar for usize {
- fn get(&self) -> usize { *self }
+ fn get(&self) -> usize {
+ *self
+ }
}
struct Baz<T: ?Sized> {
- a: T
+ a: T,
}
struct HasDrop<T: ?Sized> {
ptr: Box<usize>,
- data: T
+ data: T,
}
fn main() {
// Test that zero-offset works properly
- let b : Baz<usize> = Baz { a: 7 };
+ let b: Baz<usize> = Baz { a: 7 };
assert_eq!(b.a.get(), 7);
- let b : &Baz<dyn Bar> = &b;
+ let b: &Baz<dyn Bar> = &b;
assert_eq!(b.a.get(), 7);
// Test that the field is aligned properly
- let f : Foo<usize> = Foo { a: 0, b: 11 };
+ let f: Foo<usize> = Foo { a: 0, b: 11 };
assert_eq!(f.b.get(), 11);
- let ptr1 : *const u8 = &f.b as *const _ as *const u8;
+ let ptr1: *const u8 = &f.b as *const _ as *const u8;
- let f : &Foo<dyn Bar> = &f;
- let ptr2 : *const u8 = &f.b as *const _ as *const u8;
+ let f: &Foo<dyn Bar> = &f;
+ let ptr2: *const u8 = &f.b as *const _ as *const u8;
assert_eq!(f.b.get(), 11);
// The pointers should be the same
assert_eq!(ptr1, ptr2);
// Test that nested DSTs work properly
- let f : Foo<Foo<usize>> = Foo { a: 0, b: Foo { a: 1, b: 17 }};
+ let f: Foo<Foo<usize>> = Foo { a: 0, b: Foo { a: 1, b: 17 } };
assert_eq!(f.b.b.get(), 17);
- let f : &Foo<Foo<dyn Bar>> = &f;
+ let f: &Foo<Foo<dyn Bar>> = &f;
assert_eq!(f.b.b.get(), 17);
// Test that get the pointer via destructuring works
- let f : Foo<usize> = Foo { a: 0, b: 11 };
- let f : &Foo<dyn Bar> = &f;
+ let f: Foo<usize> = Foo { a: 0, b: 11 };
+ let f: &Foo<dyn Bar> = &f;
let &Foo { a: _, b: ref bar } = f;
assert_eq!(bar.get(), 11);
// Make sure that drop flags don't screw things up
- let d : HasDrop<Baz<[i32; 4]>> = HasDrop {
- ptr: Box::new(0),
- data: Baz { a: [1,2,3,4] }
- };
- assert_eq!([1,2,3,4], d.data.a);
+ let d: HasDrop<Baz<[i32; 4]>> = HasDrop { ptr: Box::new(0), data: Baz { a: [1, 2, 3, 4] } };
+ assert_eq!([1, 2, 3, 4], d.data.a);
- let d : &HasDrop<Baz<[i32]>> = &d;
- assert_eq!(&[1,2,3,4], &d.data.a);
+ let d: &HasDrop<Baz<[i32]>> = &d;
+ assert_eq!(&[1, 2, 3, 4], &d.data.a);
}
diff --git a/compiler/rustc_codegen_cranelift/example/example.rs b/compiler/rustc_codegen_cranelift/example/example.rs
index d5c122bf6..885e55bc7 100644
--- a/compiler/rustc_codegen_cranelift/example/example.rs
+++ b/compiler/rustc_codegen_cranelift/example/example.rs
@@ -11,11 +11,7 @@ pub fn abc(a: u8) -> u8 {
}
pub fn bcd(b: bool, a: u8) -> u8 {
- if b {
- a * 2
- } else {
- a * 3
- }
+ if b { a * 2 } else { a * 3 }
}
pub fn call() {
diff --git a/compiler/rustc_codegen_cranelift/example/issue-72793.rs b/compiler/rustc_codegen_cranelift/example/issue-72793.rs
index b1bb9b8e1..166b00600 100644
--- a/compiler/rustc_codegen_cranelift/example/issue-72793.rs
+++ b/compiler/rustc_codegen_cranelift/example/issue-72793.rs
@@ -2,7 +2,9 @@
#![feature(type_alias_impl_trait)]
-trait T { type Item; }
+trait T {
+ type Item;
+}
type Alias<'a> = impl T<Item = &'a ()>;
diff --git a/compiler/rustc_codegen_cranelift/example/issue-91827-extern-types.rs b/compiler/rustc_codegen_cranelift/example/issue-91827-extern-types.rs
index 039100696..6f39c5edc 100644
--- a/compiler/rustc_codegen_cranelift/example/issue-91827-extern-types.rs
+++ b/compiler/rustc_codegen_cranelift/example/issue-91827-extern-types.rs
@@ -40,10 +40,7 @@ impl<T, const N: usize> ListImpl<T, N> {
}
}
-pub static A: ListImpl<u128, 3> = ListImpl {
- len: 3,
- data: [5, 6, 7],
-};
+pub static A: ListImpl<u128, 3> = ListImpl { len: 3, data: [5, 6, 7] };
pub static A_REF: &'static List<u128> = A.as_list();
pub static A_TAIL_OFFSET: isize = tail_offset(A.as_list());
diff --git a/compiler/rustc_codegen_cranelift/example/mini_core.rs b/compiler/rustc_codegen_cranelift/example/mini_core.rs
index 73b83b89f..ea97e9f06 100644
--- a/compiler/rustc_codegen_cranelift/example/mini_core.rs
+++ b/compiler/rustc_codegen_cranelift/example/mini_core.rs
@@ -37,13 +37,13 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
pub trait DispatchFromDyn<T> {}
// &T -> &U
-impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
+impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
// &mut T -> &mut U
-impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
+impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
// *const T -> *const U
-impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
+impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
// *mut T -> *mut U
-impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
+impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U>> for Box<T> {}
#[lang = "receiver"]
@@ -288,7 +288,6 @@ impl PartialEq for u32 {
}
}
-
impl PartialEq for u64 {
fn eq(&self, other: &u64) -> bool {
(*self) == (*other)
@@ -361,7 +360,7 @@ impl<T: ?Sized> PartialEq for *const T {
}
}
-impl <T: PartialEq> PartialEq for Option<T> {
+impl<T: PartialEq> PartialEq for Option<T> {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Some(lhs), Some(rhs)) => *lhs == *rhs,
@@ -472,7 +471,20 @@ pub fn panic(_msg: &'static str) -> ! {
#[track_caller]
fn panic_bounds_check(index: usize, len: usize) -> ! {
unsafe {
- libc::printf("index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8, len, index);
+ libc::printf(
+ "index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8,
+ len,
+ index,
+ );
+ intrinsics::abort();
+ }
+}
+
+#[lang = "panic_cannot_unwind"]
+#[track_caller]
+fn panic_cannot_unwind() -> ! {
+ unsafe {
+ libc::puts("panic in a function that cannot unwind\n\0" as *const str as *const i8);
intrinsics::abort();
}
}
@@ -599,7 +611,7 @@ pub mod libc {
// functions. legacy_stdio_definitions.lib which provides the printf wrapper functions as normal
// symbols to link against.
#[cfg_attr(unix, link(name = "c"))]
- #[cfg_attr(target_env="msvc", link(name="legacy_stdio_definitions"))]
+ #[cfg_attr(target_env = "msvc", link(name = "legacy_stdio_definitions"))]
extern "C" {
pub fn printf(format: *const i8, ...) -> i32;
}
@@ -638,7 +650,7 @@ impl<T> Index<usize> for [T] {
}
}
-extern {
+extern "C" {
type VaListImpl;
}
@@ -648,23 +660,33 @@ pub struct VaList<'a>(&'a mut VaListImpl);
#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
-pub macro stringify($($t:tt)*) { /* compiler built-in */ }
+pub macro stringify($($t:tt)*) {
+ /* compiler built-in */
+}
#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
-pub macro file() { /* compiler built-in */ }
+pub macro file() {
+ /* compiler built-in */
+}
#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
-pub macro line() { /* compiler built-in */ }
+pub macro line() {
+ /* compiler built-in */
+}
#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
-pub macro cfg() { /* compiler built-in */ }
+pub macro cfg() {
+ /* compiler built-in */
+}
#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
-pub macro global_asm() { /* compiler built-in */ }
+pub macro global_asm() {
+ /* compiler built-in */
+}
pub static A_STATIC: u8 = 42;
@@ -676,7 +698,7 @@ struct PanicLocation {
}
#[no_mangle]
-#[cfg(not(windows))]
+#[cfg(not(all(windows, target_env = "gnu")))]
pub fn get_tls() -> u8 {
#[thread_local]
static A: u8 = 42;
diff --git a/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs b/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs
index 6ad3268e7..5a55aa215 100644
--- a/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs
+++ b/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs
@@ -319,7 +319,7 @@ fn main() {
from_decimal_string();
- #[cfg(not(any(jit, windows)))]
+ #[cfg(all(not(jit), not(all(windows, target_env = "gnu"))))]
test_tls();
#[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "darwin")))]
@@ -524,6 +524,7 @@ pub enum E1 {
// Computing the discriminant used to be done using the niche type (here `u8`,
// from the `bool` field of `V1`), overflowing for variants with large enough
// indices (`V3` and `V4`), causing them to be interpreted as other variants.
+#[rustfmt::skip]
pub enum E2<X> {
V1 { f: bool },
diff --git a/compiler/rustc_codegen_cranelift/example/mod_bench.rs b/compiler/rustc_codegen_cranelift/example/mod_bench.rs
index e3e8a3c2d..f15e48acc 100644
--- a/compiler/rustc_codegen_cranelift/example/mod_bench.rs
+++ b/compiler/rustc_codegen_cranelift/example/mod_bench.rs
@@ -3,15 +3,15 @@
#[cfg_attr(unix, link(name = "c"))]
#[cfg_attr(target_env = "msvc", link(name = "msvcrt"))]
-extern {}
+extern "C" {}
#[panic_handler]
-fn panic_handler(_: &core::panic::PanicInfo) -> ! {
+fn panic_handler(_: &core::panic::PanicInfo<'_>) -> ! {
core::intrinsics::abort();
}
-#[lang="eh_personality"]
-fn eh_personality(){}
+#[lang = "eh_personality"]
+fn eh_personality() {}
// Required for rustc_codegen_llvm
#[no_mangle]
diff --git a/compiler/rustc_codegen_cranelift/example/std_example.rs b/compiler/rustc_codegen_cranelift/example/std_example.rs
index e34b35d5c..ab4045d11 100644
--- a/compiler/rustc_codegen_cranelift/example/std_example.rs
+++ b/compiler/rustc_codegen_cranelift/example/std_example.rs
@@ -1,4 +1,4 @@
-#![feature(core_intrinsics, generators, generator_trait, is_sorted)]
+#![feature(core_intrinsics, generators, generator_trait, is_sorted, repr_simd)]
#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::*;
@@ -56,7 +56,10 @@ fn main() {
assert_eq!(0b0000000000000000000000000010000010000000000000000000000000000000_0000000000100000000000000000000000001000000000000100000000000000u128.leading_zeros(), 26);
assert_eq!(0b0000000000000000000000000010000000000000000000000000000000000000_0000000000000000000000000000000000001000000000000000000010000000u128.trailing_zeros(), 7);
- assert_eq!(core::intrinsics::saturating_sub(0, -170141183460469231731687303715884105728i128), 170141183460469231731687303715884105727i128);
+ assert_eq!(
+ core::intrinsics::saturating_sub(0, -170141183460469231731687303715884105728i128),
+ 170141183460469231731687303715884105727i128
+ );
std::hint::black_box(std::hint::black_box(7571400400375753350092698930310845914i128) * 10);
assert!(0i128.checked_div(2i128).is_some());
@@ -113,7 +116,9 @@ fn main() {
Box::pin(move |mut _task_context| {
yield ();
- }).as_mut().resume(0);
+ })
+ .as_mut()
+ .resume(0);
#[derive(Copy, Clone)]
enum Nums {
@@ -148,12 +153,20 @@ fn main() {
enum Never {}
}
+
+ foo(I64X2(0, 0));
}
fn panic(_: u128) {
panic!();
}
+#[repr(simd)]
+struct I64X2(i64, i64);
+
+#[allow(improper_ctypes_definitions)]
+extern "C" fn foo(_a: I64X2) {}
+
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "sse2")]
unsafe fn test_simd() {
@@ -168,7 +181,10 @@ unsafe fn test_simd() {
let (zero0, zero1) = std::mem::transmute::<_, (u64, u64)>(x);
assert_eq!((zero0, zero1), (0, 0));
assert_eq!(std::mem::transmute::<_, [u16; 8]>(or), [7, 7, 7, 7, 7, 7, 7, 7]);
- assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_eq), [0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff]);
+ assert_eq!(
+ std::mem::transmute::<_, [u16; 8]>(cmp_eq),
+ [0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff]
+ );
assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_lt), [0, 0, 0, 0, 0, 0, 0, 0]);
test_mm_slli_si128();
@@ -182,6 +198,7 @@ unsafe fn test_simd() {
test_mm_extract_epi8();
test_mm_insert_epi16();
+ #[rustfmt::skip]
let mask1 = _mm_movemask_epi8(dbg!(_mm_setr_epi8(255u8 as i8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)));
assert_eq!(mask1, 1);
}
@@ -343,7 +360,7 @@ fn test_checked_mul() {
#[derive(PartialEq)]
enum LoopState {
Continue(()),
- Break(())
+ Break(()),
}
pub enum Instruction {
diff --git a/compiler/rustc_codegen_cranelift/example/subslice-patterns-const-eval.rs b/compiler/rustc_codegen_cranelift/example/subslice-patterns-const-eval.rs
index 2cb84786f..3c8789166 100644
--- a/compiler/rustc_codegen_cranelift/example/subslice-patterns-const-eval.rs
+++ b/compiler/rustc_codegen_cranelift/example/subslice-patterns-const-eval.rs
@@ -19,7 +19,9 @@ macro_rules! n {
// This macro has an unused variable so that it can be repeated base on the
// number of times a repeated variable (`$e` in `z`) occurs.
macro_rules! zed {
- ($e:expr) => { Z }
+ ($e:expr) => {
+ Z
+ };
}
macro_rules! z {
@@ -32,12 +34,14 @@ macro_rules! z {
macro_rules! compare_evaluation {
($e:expr, $t:ty $(,)?) => {{
const CONST_EVAL: $t = $e;
- const fn const_eval() -> $t { $e }
+ const fn const_eval() -> $t {
+ $e
+ }
static CONST_EVAL2: $t = const_eval();
let runtime_eval = $e;
assert_eq!(CONST_EVAL, runtime_eval);
assert_eq!(CONST_EVAL2, runtime_eval);
- }}
+ }};
}
// Repeat `$test`, substituting the given macro variables with the given
@@ -65,6 +69,7 @@ macro_rules! repeat {
}
}
+#[rustfmt::skip]
fn main() {
repeat! {
($arr $Ty); n, N; z, Z: