From d1904e5855a173416008346be24f42bd4d1794ed Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 20 Mar 2022 16:55:21 +0100 Subject: [PATCH 01/22] Merge commit '370c397ec9169809e5ad270079712e0043514240' into sync_cg_clif-2022-03-20 --- Cargo.lock | 67 ++++---- Cargo.toml | 13 +- build_sysroot/Cargo.lock | 8 +- build_sysroot/Cargo.toml | 12 +- build_system/prepare.rs | 92 +++++++---- example/alloc_system.rs | 144 ++++-------------- ...itrary_self_types_pointers_and_wrappers.rs | 1 - example/mini_core.rs | 29 +++- example/mini_core_hello_world.rs | 10 -- ...ins-Disable-128bit-atomic-operations.patch | 48 ------ ...1-rand-Enable-c2-chacha-simd-feature.patch | 23 --- patches/0002-rand-Disable-failing-test.patch | 15 +- ...-sysroot-Disable-not-compiling-tests.patch | 37 +---- ...8-sysroot-Disable-long-running-tests.patch | 40 +++-- rust-toolchain | 2 +- scripts/setup_rust_fork.sh | 46 ++++-- scripts/test_rustc_tests.sh | 142 +++++++++-------- scripts/tests.sh | 1 - src/abi/mod.rs | 10 +- src/base.rs | 35 +++-- src/bin/cg_clif.rs | 16 +- src/compiler_builtins.rs | 26 ++-- src/debuginfo/line_info.rs | 1 - src/debuginfo/unwind.rs | 13 +- src/discriminant.rs | 9 +- src/driver/jit.rs | 7 +- src/intrinsics/llvm.rs | 9 +- src/intrinsics/mod.rs | 82 ++++++---- src/intrinsics/simd.rs | 2 + src/lib.rs | 12 +- src/trap.rs | 21 --- y.rs | 4 +- 32 files changed, 462 insertions(+), 515 deletions(-) delete mode 100644 patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch delete mode 100644 patches/0001-rand-Enable-c2-chacha-simd-feature.patch diff --git a/Cargo.lock b/Cargo.lock index f15e319e3b8..30e9627c48d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "anyhow" -version = "1.0.53" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0" +checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27" [[package]] name = "ar" @@ -15,9 +15,9 @@ source = "git+https://github.com/bjorn3/rust-ar.git?branch=do_not_remove_cg_clif [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" @@ -33,18 +33,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.81.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71447555acc6c875c52c407d572fc1327dc5c34cba72b4b2e7ad048aa4e4fd19" +checksum = "d16922317bd7dd104d509a373887822caa0242fc1def00de66abb538db221db4" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.81.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec9a10261891a7a919b0d4f6aa73582e88441d9a8f6173c88efbe4a5a362ea67" +checksum = "8b80bf40380256307b68a3dcbe1b91cac92a533e212b5b635abc3e4525781a0a" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -59,30 +59,30 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.81.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "815755d76fcbcf6e17ab888545b28ab775f917cb12ce0797e60cd41a2288692c" +checksum = "703d0ed7d3bc6c7a814ca12858175bf4e93167a3584127858c686e4b5dd6e432" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.81.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23ea92f2a67335a2e4d3c9c65624c3b14ae287d595b0650822c41824febab66b" +checksum = "80f52311e1c90de12dcf8c4b9999c6ebfd1ed360373e88c357160936844511f6" [[package]] name = "cranelift-entity" -version = "0.81.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd25847875e388c500ad3624b4d2e14067955c93185194a7222246a25b91c975" +checksum = "66bc82ef522c1f643baf7d4d40b7c52643ee4549d8960b0e6a047daacb83f897" [[package]] name = "cranelift-frontend" -version = "0.81.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308bcfb7eb47bdf5ff6e1ace262af4ed39ec19f204c751fffb037e0e82a0c8bf" +checksum = "3cc35e4251864b17515845ba47447bca88fec9ca1a4186b19fe42526e36140e8" dependencies = [ "cranelift-codegen", "log", @@ -92,9 +92,9 @@ dependencies = [ [[package]] name = "cranelift-jit" -version = "0.81.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f560b3a314b8d15facf411e5d29b917c3e787a2bbc3fcdc5183bc0c5b7d4fe01" +checksum = "93c66d594ad3bfe4e58b1fbd8d17877a7c6564a5f2d6f78cbbf4b0182af1927f" dependencies = [ "anyhow", "cranelift-codegen", @@ -110,9 +110,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.81.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a57aba9e603d694d1430ff38bd914bae23ef9c2e44b25a65e318905807e654c" +checksum = "bf356697c40232aa09e1e3fb8a350ee894e849ccecc4eac56ff0570a4575c325" dependencies = [ "anyhow", "cranelift-codegen", @@ -120,9 +120,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.81.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12cdc799aee673be2317e631d4569a1ba0a7e77a07a7ce45557086d2e02e9514" +checksum = "b882b2251c9845d509d92aebfdb6c8bb3b3b48e207ac951f21fbd20cfe7f90b3" dependencies = [ "cranelift-codegen", "libc", @@ -131,9 +131,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.81.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "502a7333836052fcdf4425d7f7a21264d99f862d32b9c3a0e47cd920487a9b60" +checksum = "2d3f1a88e654e567d2591169239ed157ab290811a729a6468f53999c01001263" dependencies = [ "anyhow", "cranelift-codegen", @@ -145,9 +145,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.3.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2209c310e29876f7f0b2721e7e26b84aff178aa3da5d091f9bfbf47669e60e3" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" dependencies = [ "cfg-if", ] @@ -179,9 +179,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.116" +version = "0.2.119" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565dbd88872dbe4cc8a46e527f26483c1d1f7afa6b884a3bd6cd893d4f98da74" +checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" [[package]] name = "libloading" @@ -228,6 +228,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "once_cell" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" + [[package]] name = "regalloc" version = "0.0.34" @@ -272,6 +278,7 @@ dependencies = [ "indexmap", "libloading", "object", + "once_cell", "smallvec", "target-lexicon", ] @@ -284,9 +291,9 @@ checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" [[package]] name = "target-lexicon" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9bffcddbc2458fa3e6058414599e3c838a022abae82e5c67b4f7f80298d5bff" +checksum = "d7fa7e55043acb85fca6b3c01485a2eeb6b69c5d21002e273c79e465f43b7ac1" [[package]] name = "winapi" diff --git a/Cargo.toml b/Cargo.toml index 178404af42d..70c03da3f29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,12 +8,12 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.81.0", features = ["unwind", "all-arch"] } -cranelift-frontend = "0.81.0" -cranelift-module = "0.81.0" -cranelift-native = "0.81.0" -cranelift-jit = { version = "0.81.0", optional = true } -cranelift-object = "0.81.0" +cranelift-codegen = { version = "0.82.1", features = ["unwind", "all-arch"] } +cranelift-frontend = "0.82.1" +cranelift-module = "0.82.1" +cranelift-native = "0.82.1" +cranelift-jit = { version = "0.82.1", optional = true } +cranelift-object = "0.82.1" target-lexicon = "0.12.0" gimli = { version = "0.26.0", default-features = false, features = ["write"]} object = { version = "0.27.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } @@ -21,6 +21,7 @@ object = { version = "0.27.0", default-features = false, features = ["std", "rea ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" } indexmap = "1.8.0" libloading = { version = "0.6.0", optional = true } +once_cell = "1.10.0" smallvec = "1.6.1" [patch.crates-io] diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index b9786395142..f584f54e106 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -56,7 +56,9 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.70" +version = "0.1.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "163437f05ca8f29d7e9128ea728dedf5eb620e445fbca273641d3a3050305f23" dependencies = [ "rustc-std-workspace-core", ] @@ -132,9 +134,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.119" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" +checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" dependencies = [ "rustc-std-workspace-core", ] diff --git a/build_sysroot/Cargo.toml b/build_sysroot/Cargo.toml index f25d87e60c0..d0e5fc4a3b9 100644 --- a/build_sysroot/Cargo.toml +++ b/build_sysroot/Cargo.toml @@ -14,7 +14,6 @@ compiler_builtins = { version = "0.1.39", default-features = false, features = [ rustc-std-workspace-core = { path = "./sysroot_src/library/rustc-std-workspace-core" } rustc-std-workspace-alloc = { path = "./sysroot_src/library/rustc-std-workspace-alloc" } rustc-std-workspace-std = { path = "./sysroot_src/library/rustc-std-workspace-std" } -compiler_builtins = { path = "./compiler-builtins" } [profile.dev] lto = "off" @@ -23,3 +22,14 @@ lto = "off" debug = true incremental = true lto = "off" + +# Mandatory for correctly compiling compiler-builtins +[profile.dev.package.compiler_builtins] +debug-assertions = false +overflow-checks = false +codegen-units = 10000 + +[profile.release.package.compiler_builtins] +debug-assertions = false +overflow-checks = false +codegen-units = 10000 diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 4a7df2cebbc..8bb00352d3f 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -14,29 +14,33 @@ pub(crate) fn prepare() { eprintln!("[INSTALL] hyperfine"); Command::new("cargo").arg("install").arg("hyperfine").spawn().unwrap().wait().unwrap(); - clone_repo( + clone_repo_shallow_github( + "rand", + "rust-random", "rand", - "https://github.com/rust-random/rand.git", "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", ); apply_patches("rand", Path::new("rand")); - clone_repo( + clone_repo_shallow_github( + "regex", + "rust-lang", "regex", - "https://github.com/rust-lang/regex.git", "341f207c1071f7290e3f228c710817c280c8dca1", ); - clone_repo( + clone_repo_shallow_github( + "portable-simd", + "rust-lang", "portable-simd", - "https://github.com/rust-lang/portable-simd", "b8d6b6844602f80af79cd96401339ec594d472d8", ); apply_patches("portable-simd", Path::new("portable-simd")); - clone_repo( + clone_repo_shallow_github( + "simple-raytracer", + "ebobby", "simple-raytracer", - "https://github.com/ebobby/simple-raytracer", "804a7a21b9e673a482797aa289a18ed480e4d813", ); @@ -74,29 +78,12 @@ fn prepare_sysroot() { git_init_cmd.arg("init").arg("-q").current_dir(&sysroot_src); spawn_and_wait(git_init_cmd); - let mut git_add_cmd = Command::new("git"); - git_add_cmd.arg("add").arg(".").current_dir(&sysroot_src); - spawn_and_wait(git_add_cmd); - - let mut git_commit_cmd = Command::new("git"); - git_commit_cmd - .arg("commit") - .arg("-m") - .arg("Initial commit") - .arg("-q") - .current_dir(&sysroot_src); - spawn_and_wait(git_commit_cmd); + init_git_repo(&sysroot_src); apply_patches("sysroot", &sysroot_src); - - clone_repo( - "build_sysroot/compiler-builtins", - "https://github.com/rust-lang/compiler-builtins.git", - "0.1.70", - ); - apply_patches("compiler-builtins", Path::new("build_sysroot/compiler-builtins")); } +#[allow(dead_code)] fn clone_repo(target_dir: &str, repo: &str, rev: &str) { eprintln!("[CLONE] {}", repo); // Ignore exit code as the repo may already have been checked out @@ -111,6 +98,57 @@ fn clone_repo(target_dir: &str, repo: &str, rev: &str) { spawn_and_wait(checkout_cmd); } +fn clone_repo_shallow_github(target_dir: &str, username: &str, repo: &str, rev: &str) { + if cfg!(windows) { + // Older windows doesn't have tar or curl by default. Fall back to using git. + clone_repo(target_dir, &format!("https://github.com/{}/{}.git", username, repo), rev); + return; + } + + let archive_url = format!("https://github.com/{}/{}/archive/{}.tar.gz", username, repo, rev); + let archive_file = format!("{}.tar.gz", rev); + let archive_dir = format!("{}-{}", repo, rev); + + eprintln!("[DOWNLOAD] {}/{} from {}", username, repo, archive_url); + + // Remove previous results if they exists + let _ = std::fs::remove_file(&archive_file); + let _ = std::fs::remove_dir_all(&archive_dir); + let _ = std::fs::remove_dir_all(target_dir); + + // Download zip archive + let mut download_cmd = Command::new("curl"); + download_cmd.arg("--location").arg("--output").arg(&archive_file).arg(archive_url); + spawn_and_wait(download_cmd); + + // Unpack tar archive + let mut unpack_cmd = Command::new("tar"); + unpack_cmd.arg("xf").arg(&archive_file); + spawn_and_wait(unpack_cmd); + + // Rename unpacked dir to the expected name + std::fs::rename(archive_dir, target_dir).unwrap(); + + init_git_repo(Path::new(target_dir)); + + // Cleanup + std::fs::remove_file(archive_file).unwrap(); +} + +fn init_git_repo(repo_dir: &Path) { + let mut git_init_cmd = Command::new("git"); + git_init_cmd.arg("init").arg("-q").current_dir(repo_dir); + spawn_and_wait(git_init_cmd); + + let mut git_add_cmd = Command::new("git"); + git_add_cmd.arg("add").arg(".").current_dir(repo_dir); + spawn_and_wait(git_add_cmd); + + let mut git_commit_cmd = Command::new("git"); + git_commit_cmd.arg("commit").arg("-m").arg("Initial commit").arg("-q").current_dir(repo_dir); + spawn_and_wait(git_commit_cmd); +} + fn get_patches(crate_name: &str) -> Vec { let mut patches: Vec<_> = fs::read_dir("patches") .unwrap() diff --git a/example/alloc_system.rs b/example/alloc_system.rs index 5f66ca67f2d..cf95c89bc31 100644 --- a/example/alloc_system.rs +++ b/example/alloc_system.rs @@ -8,33 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. #![no_std] -#![feature(allocator_api, rustc_private)] -#![cfg_attr(any(unix, target_os = "redox"), feature(libc))] - -// The minimum alignment guaranteed by the architecture. This value is used to -// add fast paths for low alignment values. -#[cfg(all(any(target_arch = "x86", - target_arch = "arm", - target_arch = "mips", - target_arch = "powerpc", - target_arch = "powerpc64")))] -const MIN_ALIGN: usize = 8; -#[cfg(all(any(target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "mips64", - target_arch = "s390x", - target_arch = "sparc64")))] -const MIN_ALIGN: usize = 16; pub struct System; + #[cfg(any(windows, unix, target_os = "redox"))] mod realloc_fallback { use core::alloc::{GlobalAlloc, Layout}; use core::cmp; use core::ptr; impl super::System { - pub(crate) unsafe fn realloc_fallback(&self, ptr: *mut u8, old_layout: Layout, - new_size: usize) -> *mut u8 { + pub(crate) unsafe fn realloc_fallback( + &self, + ptr: *mut u8, + old_layout: Layout, + new_size: usize, + ) -> *mut u8 { // Docs for GlobalAlloc::realloc require this to be valid: let new_layout = Layout::from_size_align_unchecked(new_size, old_layout.align()); let new_ptr = GlobalAlloc::alloc(self, new_layout); @@ -49,97 +37,47 @@ mod realloc_fallback { } #[cfg(any(unix, target_os = "redox"))] mod platform { - extern crate libc; - use core::ptr; - use MIN_ALIGN; - use System; use core::alloc::{GlobalAlloc, Layout}; + use core::ffi::c_void; + use core::ptr; + use System; + extern "C" { + fn posix_memalign(memptr: *mut *mut c_void, align: usize, size: usize) -> i32; + fn free(p: *mut c_void); + } unsafe impl GlobalAlloc for System { #[inline] unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() { - libc::malloc(layout.size()) as *mut u8 - } else { - #[cfg(target_os = "macos")] - { - if layout.align() > (1 << 31) { - return ptr::null_mut() - } - } - aligned_malloc(&layout) - } + aligned_malloc(&layout) } #[inline] unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { - if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() { - libc::calloc(layout.size(), 1) as *mut u8 - } else { - let ptr = self.alloc(layout.clone()); - if !ptr.is_null() { - ptr::write_bytes(ptr, 0, layout.size()); - } - ptr + let ptr = self.alloc(layout.clone()); + if !ptr.is_null() { + ptr::write_bytes(ptr, 0, layout.size()); } + ptr } #[inline] unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { - libc::free(ptr as *mut libc::c_void) + free(ptr as *mut c_void) } #[inline] unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { - if layout.align() <= MIN_ALIGN && layout.align() <= new_size { - libc::realloc(ptr as *mut libc::c_void, new_size) as *mut u8 - } else { - self.realloc_fallback(ptr, layout, new_size) - } + self.realloc_fallback(ptr, layout, new_size) } } - #[cfg(any(target_os = "android", - target_os = "hermit", - target_os = "redox", - target_os = "solaris"))] - #[inline] - unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { - // On android we currently target API level 9 which unfortunately - // doesn't have the `posix_memalign` API used below. Instead we use - // `memalign`, but this unfortunately has the property on some systems - // where the memory returned cannot be deallocated by `free`! - // - // Upon closer inspection, however, this appears to work just fine with - // Android, so for this platform we should be fine to call `memalign` - // (which is present in API level 9). Some helpful references could - // possibly be chromium using memalign [1], attempts at documenting that - // memalign + free is ok [2] [3], or the current source of chromium - // which still uses memalign on android [4]. - // - // [1]: https://codereview.chromium.org/10796020/ - // [2]: https://code.google.com/p/android/issues/detail?id=35391 - // [3]: https://bugs.chromium.org/p/chromium/issues/detail?id=138579 - // [4]: https://chromium.googlesource.com/chromium/src/base/+/master/ - // /memory/aligned_memory.cc - libc::memalign(layout.align(), layout.size()) as *mut u8 - } - #[cfg(not(any(target_os = "android", - target_os = "hermit", - target_os = "redox", - target_os = "solaris")))] - #[inline] unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { let mut out = ptr::null_mut(); - let ret = libc::posix_memalign(&mut out, layout.align(), layout.size()); - if ret != 0 { - ptr::null_mut() - } else { - out as *mut u8 - } + let ret = posix_memalign(&mut out, layout.align(), layout.size()); + if ret != 0 { ptr::null_mut() } else { out as *mut u8 } } } #[cfg(windows)] #[allow(nonstandard_style)] mod platform { - use MIN_ALIGN; - use System; use core::alloc::{GlobalAlloc, Layout}; + use System; type LPVOID = *mut u8; type HANDLE = LPVOID; type SIZE_T = usize; @@ -165,18 +103,9 @@ mod platform { } #[inline] unsafe fn allocate_with_flags(layout: Layout, flags: DWORD) -> *mut u8 { - let ptr = if layout.align() <= MIN_ALIGN { - HeapAlloc(GetProcessHeap(), flags, layout.size()) - } else { - let size = layout.size() + layout.align(); - let ptr = HeapAlloc(GetProcessHeap(), flags, size); - if ptr.is_null() { - ptr - } else { - align_ptr(ptr, layout.align()) - } - }; - ptr as *mut u8 + let size = layout.size() + layout.align(); + let ptr = HeapAlloc(GetProcessHeap(), flags, size); + (if ptr.is_null() { ptr } else { align_ptr(ptr, layout.align()) }) as *mut u8 } unsafe impl GlobalAlloc for System { #[inline] @@ -189,24 +118,13 @@ mod platform { } #[inline] unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { - if layout.align() <= MIN_ALIGN { - let err = HeapFree(GetProcessHeap(), 0, ptr as LPVOID); - debug_assert!(err != 0, "Failed to free heap memory: {}", - GetLastError()); - } else { - let header = get_header(ptr); - let err = HeapFree(GetProcessHeap(), 0, header.0 as LPVOID); - debug_assert!(err != 0, "Failed to free heap memory: {}", - GetLastError()); - } + let header = get_header(ptr); + let err = HeapFree(GetProcessHeap(), 0, header.0 as LPVOID); + debug_assert!(err != 0, "Failed to free heap memory: {}", GetLastError()); } #[inline] unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { - if layout.align() <= MIN_ALIGN { - HeapReAlloc(GetProcessHeap(), 0, ptr as LPVOID, new_size) as *mut u8 - } else { - self.realloc_fallback(ptr, layout, new_size) - } + self.realloc_fallback(ptr, layout, new_size) } } } diff --git a/example/arbitrary_self_types_pointers_and_wrappers.rs b/example/arbitrary_self_types_pointers_and_wrappers.rs index ddeb752f93e..e9876837dd8 100644 --- a/example/arbitrary_self_types_pointers_and_wrappers.rs +++ b/example/arbitrary_self_types_pointers_and_wrappers.rs @@ -1,7 +1,6 @@ // Adapted from rustc run-pass test suite #![feature(arbitrary_self_types, unsize, coerce_unsized, dispatch_from_dyn)] -#![feature(rustc_attrs)] use std::{ ops::{Deref, CoerceUnsized, DispatchFromDyn}, diff --git a/example/mini_core.rs b/example/mini_core.rs index c4834c80408..7efc8dc785a 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -1,7 +1,14 @@ #![feature( - no_core, lang_items, intrinsics, unboxed_closures, type_ascription, extern_types, - untagged_unions, decl_macro, rustc_attrs, transparent_unions, auto_traits, - thread_local, + no_core, + lang_items, + intrinsics, + unboxed_closures, + extern_types, + decl_macro, + rustc_attrs, + transparent_unions, + auto_traits, + thread_local )] #![no_core] #![allow(dead_code)] @@ -55,6 +62,7 @@ unsafe impl Copy for i16 {} unsafe impl Copy for i32 {} unsafe impl Copy for isize {} unsafe impl Copy for f32 {} +unsafe impl Copy for f64 {} unsafe impl Copy for char {} unsafe impl<'a, T: ?Sized> Copy for &'a T {} unsafe impl Copy for *const T {} @@ -483,8 +491,17 @@ pub trait Deref { fn deref(&self) -> &Self::Target; } +pub struct Unique { + pub pointer: *const T, + pub _marker: PhantomData, +} + +impl CoerceUnsized> for Unique where T: Unsize {} + +impl DispatchFromDyn> for Unique where T: Unsize {} + #[lang = "owned_box"] -pub struct Box(*mut T); +pub struct Box(Unique, ()); impl, U: ?Sized> CoerceUnsized> for Box {} @@ -508,8 +525,8 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 { } #[lang = "box_free"] -unsafe fn box_free(ptr: *mut T) { - libc::free(ptr as *mut u8); +unsafe fn box_free(ptr: Unique, alloc: ()) { + libc::free(ptr.pointer as *mut u8); } #[lang = "drop"] diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index ef3b575d393..c4730581335 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -7,10 +7,6 @@ extern crate mini_core; use mini_core::*; use mini_core::libc::*; -unsafe extern "C" fn my_puts(s: *const i8) { - puts(s); -} - macro_rules! assert { ($e:expr) => { if !$e { @@ -105,12 +101,6 @@ fn start( static mut NUM: u8 = 6 * 7; static NUM_REF: &'static u8 = unsafe { &NUM }; -struct Unique { - pointer: *const T, - _marker: PhantomData, -} - -impl CoerceUnsized> for Unique where T: Unsize {} unsafe fn zeroed() -> T { let mut uninit = MaybeUninit { uninit: () }; diff --git a/patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch b/patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch deleted file mode 100644 index 460e42d1d8c..00000000000 --- a/patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch +++ /dev/null @@ -1,48 +0,0 @@ -From 1d574bf5e32d51641dcacaf8ef777e95b44f6f2a Mon Sep 17 00:00:00 2001 -From: bjorn3 -Date: Thu, 18 Feb 2021 18:30:55 +0100 -Subject: [PATCH] Disable 128bit atomic operations - -Cranelift doesn't support them yet ---- - src/mem/mod.rs | 12 ------------ - 1 file changed, 12 deletions(-) - -diff --git a/src/mem/mod.rs b/src/mem/mod.rs -index 107762c..2d1ae10 100644 ---- a/src/mem/mod.rs -+++ b/src/mem/mod.rs -@@ -137,10 +137,6 @@ intrinsics! { - pub unsafe extern "C" fn __llvm_memcpy_element_unordered_atomic_8(dest: *mut u64, src: *const u64, bytes: usize) -> () { - memcpy_element_unordered_atomic(dest, src, bytes); - } -- #[cfg(target_has_atomic_load_store = "128")] -- pub unsafe extern "C" fn __llvm_memcpy_element_unordered_atomic_16(dest: *mut u128, src: *const u128, bytes: usize) -> () { -- memcpy_element_unordered_atomic(dest, src, bytes); -- } - - #[cfg(target_has_atomic_load_store = "8")] - pub unsafe extern "C" fn __llvm_memmove_element_unordered_atomic_1(dest: *mut u8, src: *const u8, bytes: usize) -> () { -@@ -158,10 +154,6 @@ intrinsics! { - pub unsafe extern "C" fn __llvm_memmove_element_unordered_atomic_8(dest: *mut u64, src: *const u64, bytes: usize) -> () { - memmove_element_unordered_atomic(dest, src, bytes); - } -- #[cfg(target_has_atomic_load_store = "128")] -- pub unsafe extern "C" fn __llvm_memmove_element_unordered_atomic_16(dest: *mut u128, src: *const u128, bytes: usize) -> () { -- memmove_element_unordered_atomic(dest, src, bytes); -- } - - #[cfg(target_has_atomic_load_store = "8")] - pub unsafe extern "C" fn __llvm_memset_element_unordered_atomic_1(s: *mut u8, c: u8, bytes: usize) -> () { -@@ -179,8 +171,4 @@ intrinsics! { - pub unsafe extern "C" fn __llvm_memset_element_unordered_atomic_8(s: *mut u64, c: u8, bytes: usize) -> () { - memset_element_unordered_atomic(s, c, bytes); - } -- #[cfg(target_has_atomic_load_store = "128")] -- pub unsafe extern "C" fn __llvm_memset_element_unordered_atomic_16(s: *mut u128, c: u8, bytes: usize) -> () { -- memset_element_unordered_atomic(s, c, bytes); -- } - } --- -2.26.2.7.g19db9cfb68 - diff --git a/patches/0001-rand-Enable-c2-chacha-simd-feature.patch b/patches/0001-rand-Enable-c2-chacha-simd-feature.patch deleted file mode 100644 index 01dc0fcc537..00000000000 --- a/patches/0001-rand-Enable-c2-chacha-simd-feature.patch +++ /dev/null @@ -1,23 +0,0 @@ -From 9c5663e36391fa20becf84f3af2e82afa5bb720b Mon Sep 17 00:00:00 2001 -From: bjorn3 -Date: Sat, 15 Aug 2020 19:56:03 +0200 -Subject: [PATCH] [rand] Enable c2-chacha simd feature - ---- - rand_chacha/Cargo.toml | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/rand_chacha/Cargo.toml b/rand_chacha/Cargo.toml -index 9190b7f..872cca2 100644 ---- a/rand_chacha/Cargo.toml -+++ b/rand_chacha/Cargo.toml -@@ -24,5 +24,5 @@ ppv-lite86 = { version = "0.2.8", default-features = false } - - [features] - default = ["std"] --std = ["ppv-lite86/std"] -+std = ["ppv-lite86/std", "ppv-lite86/simd"] - simd = [] # deprecated --- -2.20.1 - diff --git a/patches/0002-rand-Disable-failing-test.patch b/patches/0002-rand-Disable-failing-test.patch index 19fd20d7269..ae13ab3b0ca 100644 --- a/patches/0002-rand-Disable-failing-test.patch +++ b/patches/0002-rand-Disable-failing-test.patch @@ -4,27 +4,18 @@ Date: Sat, 15 Aug 2020 20:04:38 +0200 Subject: [PATCH] [rand] Disable failing test --- - src/distributions/uniform.rs | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) + src/distributions/uniform.rs | 1 + + 1 file changed, 1 insertion(+), 0 deletions(-) diff --git a/src/distributions/uniform.rs b/src/distributions/uniform.rs index 480b859..c80bb6f 100644 --- a/src/distributions/uniform.rs +++ b/src/distributions/uniform.rs -@@ -1085,7 +1085,7 @@ mod tests { - _ => panic!("`UniformDurationMode` was not serialized/deserialized correctly") - } - } -- -+ - #[test] - #[cfg(feature = "serde1")] - fn test_uniform_serialization() { @@ -1314,6 +1314,7 @@ mod tests { not(target_arch = "wasm32"), not(target_arch = "asmjs") ))] -+ #[ignore] // FIXME ++ #[ignore] // Requires unwinding fn test_float_assertions() { use super::SampleUniform; use std::panic::catch_unwind; diff --git a/patches/0022-sysroot-Disable-not-compiling-tests.patch b/patches/0022-sysroot-Disable-not-compiling-tests.patch index 1c45c7573c8..108a97bd7c6 100644 --- a/patches/0022-sysroot-Disable-not-compiling-tests.patch +++ b/patches/0022-sysroot-Disable-not-compiling-tests.patch @@ -18,7 +18,7 @@ new file mode 100644 index 0000000..46fd999 --- /dev/null +++ b/library/core/tests/Cargo.toml -@@ -0,0 +1,8 @@ +@@ -0,0 +1,11 @@ +[package] +name = "core" +version = "0.0.0" @@ -27,18 +27,9 @@ index 0000000..46fd999 +[lib] +name = "coretests" +path = "lib.rs" -diff --git a/library/core/tests/num/flt2dec/mod.rs b/library/core/tests/num/flt2dec/mod.rs -index a35897e..f0bf645 100644 ---- a/library/core/tests/num/flt2dec/mod.rs -+++ b/library/core/tests/num/flt2dec/mod.rs -@@ -13,7 +13,6 @@ mod strategy { - mod dragon; - mod grisu; - } --mod random; - - pub fn decode_finite(v: T) -> Decoded { - match decode(v).1 { ++ ++[dependencies] ++rand = "0.7" diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 1a6be3a..42dbd59 100644 --- a/library/core/tests/ptr.rs @@ -59,25 +50,5 @@ index 1a6be3a..42dbd59 100644 #[test] fn write_unaligned_drop() { -diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs -index 6609bc3..241b497 100644 ---- a/library/core/tests/slice.rs -+++ b/library/core/tests/slice.rs -@@ -1209,6 +1209,7 @@ fn brute_force_rotate_test_1() { - } - } - -+/* - #[test] - #[cfg(not(target_arch = "wasm32"))] - fn sort_unstable() { -@@ -1394,6 +1395,7 @@ fn partition_at_index() { - v.select_nth_unstable(0); - assert!(v == [0xDEADBEEF]); - } -+*/ - - #[test] - #[should_panic(expected = "index 0 greater than length of slice")] -- 2.21.0 (Apple Git-122) diff --git a/patches/0028-sysroot-Disable-long-running-tests.patch b/patches/0028-sysroot-Disable-long-running-tests.patch index bf74a74c7c4..d804a78cc10 100644 --- a/patches/0028-sysroot-Disable-long-running-tests.patch +++ b/patches/0028-sysroot-Disable-long-running-tests.patch @@ -1,30 +1,48 @@ -From 0ffdd8eda8df364391c8ac6e1ce92c73ba9254d4 Mon Sep 17 00:00:00 2001 +From eb703e627e7a84f1cd8d0d87f0f69da1f0acf765 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 3 Dec 2021 12:16:30 +0100 Subject: [PATCH] Disable long running tests --- - library/core/tests/slice.rs | 3 +++ - 1 file changed, 3 insertions(+) + library/core/tests/slice.rs | 2 ++ + 1 file changed, 2 insertions(+) diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs -index 2c8f00a..44847ee 100644 +index 8402833..84592e0 100644 --- a/library/core/tests/slice.rs +++ b/library/core/tests/slice.rs -@@ -2332,7 +2332,8 @@ macro_rules! empty_max_mut { - }; +@@ -1809,6 +1809,7 @@ fn sort_unstable() { + assert!(v == [0xDEADBEEF]); } +/* - #[cfg(not(miri))] // Comparing usize::MAX many elements takes forever in Miri (and in rustc without optimizations) - take_tests! { - slice: &[(); usize::MAX], method: take, - (take_in_bounds_max_range_to, (..usize::MAX), Some(EMPTY_MAX), &[(); 0]), -@@ -2345,3 +2347,4 @@ take_tests! { + #[test] + #[cfg(not(target_arch = "wasm32"))] + #[cfg_attr(miri, ignore)] // Miri is too slow +@@ -1914,6 +1915,7 @@ fn select_nth_unstable() { + v.select_nth_unstable(0); + assert!(v == [0xDEADBEEF]); + } ++*/ + + #[test] + #[should_panic(expected = "index 0 greater than length of slice")] +@@ -2462,6 +2462,7 @@ take_tests! { + #[cfg(not(miri))] // unused in Miri + const EMPTY_MAX: &'static [()] = &[(); usize::MAX]; + ++/* + // can't be a constant due to const mutability rules + #[cfg(not(miri))] // unused in Miri + macro_rules! empty_max_mut { +@@ -2485,6 +2486,7 @@ take_tests! { (take_mut_oob_max_range_to_inclusive, (..=usize::MAX), None, empty_max_mut!()), (take_mut_in_bounds_max_range_from, (usize::MAX..), Some(&mut [] as _), empty_max_mut!()), } +*/ + + #[test] + fn test_slice_from_ptr_range() { -- 2.26.2.7.g19db9cfb68 diff --git a/rust-toolchain b/rust-toolchain index 1019b1f069e..84d90e5db02 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-02-23" +channel = "nightly-2022-03-19" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index 73600faa1e9..85c0109c6f6 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -12,18 +12,6 @@ git checkout -- . git checkout "$(rustc -V | cut -d' ' -f3 | tr -d '(')" git apply - <( + cfg: Option<&str>, + ) -> test::TestDesc { + let mut ignore = false; + #[cfg(not(bootstrap))] +- let ignore_message: Option = None; ++ let ignore_message: Option<&str> = None; + let mut should_fail = false; + + let rustc_has_profiler_support = env::var_os("RUSTC_PROFILER_SUPPORT").is_some(); + +diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs +index 8431aa7b818..a3ff7e68ce5 100644 +--- a/src/tools/compiletest/src/runtest.rs ++++ b/src/tools/compiletest/src/runtest.rs +@@ -3489,11 +3489,7 @@ fn normalize_output(&self, output: &str, custom_rules: &[(String, String)]) -> S + .join("library"); + normalize_path(&src_dir, "$(echo '$SRC_DIR')"); + +- if let Some(virtual_rust_source_base_dir) = +- option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").map(PathBuf::from) +- { +- normalize_path(&virtual_rust_source_base_dir.join("library"), "$(echo '$SRC_DIR')"); +- } ++ normalize_path(&Path::new("$(cd ../build_sysroot/sysroot_src/library; pwd)"), "$(echo '$SRC_DIR')"); + + // Paths into the build directory + let test_build_dir = &self.config.build_base; EOF cat > config.toml </dev/null 2>&1 || cargo install ripgrep -rm -r src/test/ui/{extern/,panics/,unsized-locals/,lto/,simd*,linkage*,unwind-*.rs} || true -for test in $(rg --files-with-matches "asm!|catch_unwind|should_panic|lto|// needs-asm-support" src/test/ui); do +rm -r src/test/ui/{extern/,unsized-locals/,lto/,linkage*} || true +for test in $(rg --files-with-matches "asm!|lto|// needs-asm-support|// needs-unwind" src/test/{ui,incremental}); do rm $test done -for test in $(rg -i --files-with-matches "//(\[\w+\])?~|// error-pattern:|// build-fail|// run-fail|-Cllvm-args" src/test/ui); do +for test in $(rg -i --files-with-matches "//(\[\w+\])?~[^\|]*\s*ERR|// error-pattern:|// build-fail|// run-fail|-Cllvm-args" src/test/ui); do rm $test done git checkout -- src/test/ui/issues/auxiliary/issue-3136-a.rs # contains //~ERROR, but shouldn't be removed -# these all depend on unwinding support -rm src/test/ui/backtrace.rs -rm src/test/ui/array-slice-vec/box-of-array-of-drop-*.rs -rm src/test/ui/array-slice-vec/slice-panic-*.rs -rm src/test/ui/array-slice-vec/nested-vec-3.rs -rm src/test/ui/cleanup-rvalue-temp-during-incomplete-alloc.rs -rm src/test/ui/issues/issue-26655.rs -rm src/test/ui/issues/issue-29485.rs -rm src/test/ui/issues/issue-30018-panic.rs -rm src/test/ui/process/multi-panic.rs -rm src/test/ui/sepcomp/sepcomp-unwind.rs -rm src/test/ui/structs-enums/unit-like-struct-drop-run.rs -rm src/test/ui/drop/terminate-in-initializer.rs -rm src/test/ui/threads-sendsync/task-stderr.rs -rm src/test/ui/numbers-arithmetic/int-abs-overflow.rs -rm src/test/ui/drop/drop-trait-enum.rs -rm src/test/ui/numbers-arithmetic/issue-8460.rs -rm src/test/ui/runtime/rt-explody-panic-payloads.rs -rm src/test/incremental/change_crate_dep_kind.rs -rm src/test/ui/threads-sendsync/unwind-resource.rs +# missing features +# ================ -rm src/test/ui/issues/issue-28950.rs # depends on stack size optimizations -rm src/test/ui/codegen/init-large-type.rs # same -rm src/test/ui/sse2.rs # cpuid not supported, so sse2 not detected -rm src/test/ui/issues/issue-33992.rs # unsupported linkages -rm src/test/ui/issues/issue-51947.rs # same -rm src/test/incremental/hashes/function_interfaces.rs # same -rm src/test/incremental/hashes/statics.rs # same -rm src/test/ui/numbers-arithmetic/saturating-float-casts.rs # intrinsic gives different but valid result -rm src/test/ui/mir/mir_misc_casts.rs # depends on deduplication of constants -rm src/test/ui/mir/mir_raw_fat_ptr.rs # same -rm src/test/ui/consts/issue-33537.rs # same +# requires stack unwinding +rm src/test/ui/backtrace.rs +rm src/test/ui/process/multi-panic.rs +rm src/test/ui/numbers-arithmetic/issue-8460.rs +rm src/test/incremental/change_crate_dep_kind.rs +rm src/test/incremental/issue-80691-bad-eval-cache.rs # -Cpanic=abort causes abort instead of exit(101) +rm src/test/ui/panic-while-printing.rs +rm src/test/ui/test-attrs/test-panic-while-printing.rs +rm src/test/ui/test-attrs/test-type.rs + +# requires compiling with -Cpanic=unwind +rm src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs # "Cannot run dynamic test fn out-of-process" rm src/test/ui/async-await/async-fn-size-moved-locals.rs # -Cpanic=abort shrinks some generator by one byte rm src/test/ui/async-await/async-fn-size-uninit-locals.rs # same rm src/test/ui/generator/size-moved-locals.rs # same -rm src/test/ui/fn/dyn-fn-alignment.rs # wants a 256 byte alignment -rm src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs # "Cannot run dynamic test fn out-of-process" + +# vendor intrinsics +rm src/test/ui/sse2.rs # cpuid not supported, so sse2 not detected +rm src/test/ui/intrinsics/const-eval-select-x86_64.rs # requires x86_64 vendor intrinsics +rm src/test/ui/simd/array-type.rs # "Index argument for `simd_insert` is not a constant" +rm src/test/ui/simd/intrinsic/generic-bitmask-pass.rs # simd_bitmask unimplemented +rm src/test/ui/simd/intrinsic/generic-as.rs # simd_as unimplemented +rm src/test/ui/simd/intrinsic/generic-arithmetic-saturating-pass.rs # simd_saturating_add unimplemented +rm src/test/ui/simd/intrinsic/float-math-pass.rs # simd_fcos unimplemented +rm src/test/ui/simd/intrinsic/generic-gather-pass.rs # simd_gather unimplemented +rm src/test/ui/simd/intrinsic/generic-select-pass.rs # simd_select_bitmask unimplemented +rm src/test/ui/simd/issue-85915-simd-ptrs.rs # simd_gather unimplemented +rm src/test/ui/simd/issue-89193.rs # simd_gather unimplemented +rm src/test/ui/simd/simd-bitmask.rs # simd_bitmask unimplemented + +# exotic linkages +rm src/test/ui/issues/issue-33992.rs # unsupported linkages +rm src/test/incremental/hashes/function_interfaces.rs # same +rm src/test/incremental/hashes/statics.rs # same + +# variadic arguments +rm src/test/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs +rm src/test/ui/abi/variadic-ffi.rs # requires callee side vararg support + +# unsized locals +rm -r src/test/run-pass-valgrind/unsized-locals + +# misc unimplemented things rm src/test/ui/intrinsics/intrinsic-nearby.rs # unimplemented nearbyintf32 and nearbyintf64 intrinsics +rm src/test/ui/target-feature/missing-plusminus.rs # error not implemented +rm src/test/ui/fn/dyn-fn-alignment.rs # wants a 256 byte alignment +rm -r src/test/run-make/emit-named-files # requires full --emit support -rm src/test/incremental/hashes/inline_asm.rs # inline asm -rm src/test/incremental/issue-72386.rs # same -rm src/test/incremental/lto.rs # requires lto -rm src/test/incremental/dirty_clean.rs # TODO +# optimization tests +# ================== +rm src/test/ui/issues/issue-28950.rs # depends on stack size optimizations +rm src/test/ui/codegen/init-large-type.rs # same +rm -r src/test/run-make/fmt-write-bloat/ # tests an optimization +# backend specific tests +# ====================== +rm src/test/incremental/thinlto/cgu_invalidated_when_import_{added,removed}.rs # requires LLVM +rm src/test/ui/abi/stack-protector.rs # requires stack protector support + +# giving different but possibly correct results +# ============================================= +rm src/test/ui/numbers-arithmetic/saturating-float-casts.rs # intrinsic gives different but valid result +rm src/test/ui/simd/intrinsic/float-minmax-pass.rs # same +rm src/test/ui/mir/mir_misc_casts.rs # depends on deduplication of constants +rm src/test/ui/mir/mir_raw_fat_ptr.rs # same +rm src/test/ui/consts/issue-33537.rs # same + +# doesn't work due to the way the rustc test suite is invoked. +# should work when using ./x.py test the way it is intended +# ============================================================ rm -r src/test/run-make/emit-shared-files # requires the rustdoc executable in build/bin/ rm -r src/test/run-make/unstable-flag-required # same rm -r src/test/run-make/rustdoc-* # same -rm -r src/test/run-make/emit-named-files # requires full --emit support - -rm -r src/test/run-pass-valgrind/unsized-locals - -rm src/test/ui/json-bom-plus-crlf-multifile.rs # differing warning -rm src/test/ui/json-bom-plus-crlf.rs # same -rm src/test/ui/intrinsics/const-eval-select-x86_64.rs # same -rm src/test/ui/match/issue-82392.rs # differing error -rm src/test/ui/consts/min_const_fn/address_of_const.rs # same -rm src/test/ui/consts/issue-miri-1910.rs # same -rm src/test/ui/generic-associated-types/bugs/issue-80626.rs # same -rm src/test/ui/generic-associated-types/bugs/issue-89008.rs # same -rm src/test/ui/type-alias-impl-trait/cross_crate_ice*.rs # requires removed aux dep +# genuine bugs +# ============ rm src/test/ui/allocator/no_std-alloc-error-handler-default.rs # missing rust_oom definition -rm src/test/ui/cfg/cfg-panic.rs -rm -r src/test/ui/hygiene/ rm -r src/test/ui/polymorphization/ # polymorphization not yet supported rm src/test/codegen-units/polymorphization/unused_type_parameters.rs # same -rm -r src/test/run-make/fmt-write-bloat/ # tests an optimization -rm src/test/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs -rm src/test/ui/abi/variadic-ffi.rs # requires callee side vararg support - -rm src/test/ui/command/command-current-dir.rs # can't find libstd.so - -rm src/test/ui/abi/stack-protector.rs # requires stack protector support - -rm src/test/incremental/issue-80691-bad-eval-cache.rs # wrong exit code rm src/test/incremental/spike-neg1.rs # errors out for some reason rm src/test/incremental/spike-neg2.rs # same rm src/test/ui/issues/issue-74564-if-expr-stack-overflow.rs # gives a stackoverflow before the backend runs +rm src/test/ui/mir/ssa-analysis-regression-50041.rs # produces ICE -rm src/test/incremental/thinlto/cgu_invalidated_when_import_{added,removed}.rs # requires LLVM +rm src/test/ui/simd/intrinsic/generic-reduction-pass.rs # simd_reduce_add_unordered doesn't accept an accumulator for integer vectors + +# bugs in the test suite +# ====================== +rm src/test/ui/unsafe/union.rs # has UB caught by cg_clif. see rust-lang/rust#95075 echo "[TEST] rustc test suite" RUST_TEST_NOCAPTURE=1 COMPILETEST_FORCE_STAGE0=1 ./x.py test --stage 0 src/test/{codegen-units,run-make,run-pass-valgrind,ui,incremental} diff --git a/scripts/tests.sh b/scripts/tests.sh index bdb3de0936d..fee1012c8f1 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -57,7 +57,6 @@ function base_sysroot_tests() { fi echo "[AOT] dst_field_align" - # FIXME Re-add -Zmir-opt-level=2 once rust-lang/rust#67529 is fixed. $MY_RUSTC example/dst-field-align.rs --crate-name dst_field_align --crate-type bin --target "$TARGET_TRIPLE" $RUN_WRAPPER ./target/out/dst_field_align || (echo $?; false) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index a249e5fa8ac..ef56fb191bf 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -94,6 +94,9 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { let sig = Signature { params, returns, call_conv: self.target_config.default_call_conv }; let func_id = self.module.declare_function(name, Linkage::Import, &sig).unwrap(); let func_ref = self.module.declare_func_in_func(func_id, &mut self.bcx.func); + if self.clif_comments.enabled() { + self.add_comment(func_ref, format!("{:?}", name)); + } let call_inst = self.bcx.ins().call(func_ref, args); if self.clif_comments.enabled() { self.add_comment(call_inst, format!("easy_call {}", name)); @@ -367,7 +370,10 @@ pub(crate) fn codegen_terminator_call<'tcx>( .map(|inst| fx.tcx.codegen_fn_attrs(inst.def_id()).flags.contains(CodegenFnAttrFlags::COLD)) .unwrap_or(false); if is_cold { - // FIXME Mark current_block block as cold once Cranelift supports it + fx.bcx.set_cold_block(fx.bcx.current_block().unwrap()); + if let Some((_place, destination_block)) = destination { + fx.bcx.set_cold_block(fx.get_block(destination_block)); + } } // Unpack arguments tuple for closures @@ -501,7 +507,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( let ret_block = fx.get_block(dest); fx.bcx.ins().jump(ret_block, &[]); } else { - trap_unreachable(fx, "[corruption] Diverging function returned"); + fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } } diff --git a/src/base.rs b/src/base.rs index 0a6ef6441fa..a9ff710c91e 100644 --- a/src/base.rs +++ b/src/base.rs @@ -4,6 +4,7 @@ use rustc_ast::InlineAsmOptions; use rustc_index::vec::IndexVec; use rustc_middle::ty::adjustment::PointerCast; use rustc_middle::ty::layout::FnAbiOf; +use rustc_middle::ty::print::with_no_trimmed_paths; use indexmap::IndexSet; @@ -25,7 +26,10 @@ pub(crate) fn codegen_fn<'tcx>( let mir = tcx.instance_mir(instance.def); let _mir_guard = crate::PrintOnPanic(|| { let mut buf = Vec::new(); - rustc_middle::mir::write_mir_pretty(tcx, Some(instance.def_id()), &mut buf).unwrap(); + with_no_trimmed_paths!({ + rustc_middle::mir::pretty::write_mir_fn(tcx, mir, &mut |_, _| Ok(()), &mut buf) + .unwrap(); + }); String::from_utf8_lossy(&buf).into_owned() }); @@ -90,7 +94,7 @@ pub(crate) fn codegen_fn<'tcx>( } else if arg_uninhabited { fx.bcx.append_block_params_for_function_params(fx.block_map[START_BLOCK]); fx.bcx.switch_to_block(fx.block_map[START_BLOCK]); - crate::trap::trap_unreachable(&mut fx, "function has uninhabited argument"); + fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } else { tcx.sess.time("codegen clif ir", || { tcx.sess @@ -258,7 +262,9 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { if fx.clif_comments.enabled() { let mut terminator_head = "\n".to_string(); - bb_data.terminator().kind.fmt_head(&mut terminator_head).unwrap(); + with_no_trimmed_paths!({ + bb_data.terminator().kind.fmt_head(&mut terminator_head).unwrap(); + }); let inst = fx.bcx.func.layout.last_inst(block).unwrap(); fx.add_comment(inst, terminator_head); } @@ -303,7 +309,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { let target = fx.get_block(*target); let failure = fx.bcx.create_block(); - // FIXME Mark failure block as cold once Cranelift supports it + fx.bcx.set_cold_block(failure); if *expected { fx.bcx.ins().brz(cond, failure, &[]); @@ -424,18 +430,16 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { fx.bcx.ins().jump(destination_block, &[]); } None => { - crate::trap::trap_unreachable( - fx, - "[corruption] Returned from noreturn inline asm", - ); + fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } } } TerminatorKind::Resume | TerminatorKind::Abort => { - trap_unreachable(fx, "[corruption] Unwinding bb reached."); + // FIXME implement unwinding + fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } TerminatorKind::Unreachable => { - trap_unreachable(fx, "[corruption] Hit unreachable code."); + fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } TerminatorKind::Yield { .. } | TerminatorKind::FalseEdge { .. } @@ -813,7 +817,14 @@ pub(crate) fn codegen_place<'tcx>( for elem in place.projection { match elem { PlaceElem::Deref => { - cplace = cplace.place_deref(fx); + if cplace.layout().ty.is_box() { + cplace = cplace + .place_field(fx, Field::new(0)) // Box -> Unique + .place_field(fx, Field::new(0)) // Unique -> *const T + .place_deref(fx); + } else { + cplace = cplace.place_deref(fx); + } } PlaceElem::Field(field, _ty) => { cplace = cplace.place_field(fx, field); @@ -918,5 +929,5 @@ pub(crate) fn codegen_panic_inner<'tcx>( args, ); - crate::trap::trap_unreachable(fx, "panic lang item returned"); + fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } diff --git a/src/bin/cg_clif.rs b/src/bin/cg_clif.rs index b924f2085a0..5984ec8412a 100644 --- a/src/bin/cg_clif.rs +++ b/src/bin/cg_clif.rs @@ -1,4 +1,4 @@ -#![feature(rustc_private, once_cell)] +#![feature(rustc_private)] #![warn(rust_2018_idioms)] #![warn(unused_lifetimes)] #![warn(unreachable_pub)] @@ -9,19 +9,21 @@ extern crate rustc_interface; extern crate rustc_session; extern crate rustc_target; -use std::lazy::SyncLazy; use std::panic; use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry}; use rustc_interface::interface; -use rustc_session::config::ErrorOutputType; +use rustc_session::config::{ErrorOutputType, TrimmedDefPaths}; use rustc_session::early_error; use rustc_target::spec::PanicStrategy; +// FIXME use std::lazy::SyncLazy once it stabilizes +use once_cell::sync::Lazy; + const BUG_REPORT_URL: &str = "https://github.com/bjorn3/rustc_codegen_cranelift/issues/new"; -static DEFAULT_HOOK: SyncLazy) + Sync + Send + 'static>> = - SyncLazy::new(|| { +static DEFAULT_HOOK: Lazy) + Sync + Send + 'static>> = + Lazy::new(|| { let hook = panic::take_hook(); panic::set_hook(Box::new(|info| { // Invoke the default handler, which prints the actual panic message and optionally a backtrace @@ -53,6 +55,8 @@ impl rustc_driver::Callbacks for CraneliftPassesCallbacks { config.opts.maybe_sysroot = Some(config.opts.maybe_sysroot.clone().unwrap_or_else(|| { std::env::current_exe().unwrap().parent().unwrap().parent().unwrap().to_owned() })); + + config.opts.trimmed_def_paths = TrimmedDefPaths::GoodPath; } } @@ -61,7 +65,7 @@ fn main() { let start_rss = get_resident_set_size(); rustc_driver::init_rustc_env_logger(); let mut callbacks = CraneliftPassesCallbacks::default(); - SyncLazy::force(&DEFAULT_HOOK); // Install ice hook + Lazy::force(&DEFAULT_HOOK); // Install ice hook let exit_code = rustc_driver::catch_with_exit_code(|| { let args = std::env::args_os() .enumerate() diff --git a/src/compiler_builtins.rs b/src/compiler_builtins.rs index 100c3b43160..c6a247cf59e 100644 --- a/src/compiler_builtins.rs +++ b/src/compiler_builtins.rs @@ -1,16 +1,18 @@ -macro builtin_functions($register:ident; $(fn $name:ident($($arg_name:ident: $arg_ty:ty),*) -> $ret_ty:ty;)*) { - #[cfg(feature = "jit")] - #[allow(improper_ctypes)] - extern "C" { - $(fn $name($($arg_name: $arg_ty),*) -> $ret_ty;)* - } - - #[cfg(feature = "jit")] - pub(crate) fn $register(builder: &mut cranelift_jit::JITBuilder) { - for (name, val) in [$((stringify!($name), $name as *const u8)),*] { - builder.symbol(name, val); +macro_rules! builtin_functions { + ($register:ident; $(fn $name:ident($($arg_name:ident: $arg_ty:ty),*) -> $ret_ty:ty;)*) => { + #[cfg(feature = "jit")] + #[allow(improper_ctypes)] + extern "C" { + $(fn $name($($arg_name: $arg_ty),*) -> $ret_ty;)* } - } + + #[cfg(feature = "jit")] + pub(crate) fn $register(builder: &mut cranelift_jit::JITBuilder) { + for (name, val) in [$((stringify!($name), $name as *const u8)),*] { + builder.symbol(name, val); + } + } + }; } builtin_functions! { diff --git a/src/debuginfo/line_info.rs b/src/debuginfo/line_info.rs index c7e15f81e03..476d6a54e12 100644 --- a/src/debuginfo/line_info.rs +++ b/src/debuginfo/line_info.rs @@ -110,7 +110,6 @@ impl<'tcx> DebugContext<'tcx> { entry.set(gimli::DW_AT_decl_file, AttributeValue::FileIndex(Some(file_id))); entry.set(gimli::DW_AT_decl_line, AttributeValue::Udata(loc.line as u64)); - // FIXME: probably omit this entry.set(gimli::DW_AT_decl_column, AttributeValue::Udata(loc.col.to_usize() as u64)); } diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs index e4f28338096..d26392c4913 100644 --- a/src/debuginfo/unwind.rs +++ b/src/debuginfo/unwind.rs @@ -81,6 +81,8 @@ impl UnwindContext { #[cfg(all(feature = "jit", not(windows)))] pub(crate) unsafe fn register_jit(self, jit_module: &cranelift_jit::JITModule) { + use std::mem::ManuallyDrop; + let mut eh_frame = EhFrame::from(super::emit::WriterRelocate::new(self.endian)); self.frame_table.write_eh_frame(&mut eh_frame).unwrap(); @@ -95,17 +97,16 @@ impl UnwindContext { // FIXME support unregistering unwind tables once cranelift-jit supports deallocating // individual functions - #[allow(unused_variables)] - let (eh_frame, eh_frame_len, _) = Vec::into_raw_parts(eh_frame); + let eh_frame = ManuallyDrop::new(eh_frame); // ======================================================================= - // Everything after this line up to the end of the file is loosly based on + // Everything after this line up to the end of the file is loosely based on // https://github.com/bytecodealliance/wasmtime/blob/4471a82b0c540ff48960eca6757ccce5b1b5c3e4/crates/jit/src/unwind/systemv.rs #[cfg(target_os = "macos")] { // On macOS, `__register_frame` takes a pointer to a single FDE - let start = eh_frame; - let end = start.add(eh_frame_len); + let start = eh_frame.as_ptr(); + let end = start.add(eh_frame.len()); let mut current = start; // Walk all of the entries in the frame table and register them @@ -124,7 +125,7 @@ impl UnwindContext { #[cfg(not(target_os = "macos"))] { // On other platforms, `__register_frame` will walk the FDEs until an entry of length 0 - __register_frame(eh_frame); + __register_frame(eh_frame.as_ptr()); } } } diff --git a/src/discriminant.rs b/src/discriminant.rs index 3326f87f000..6b2893fdaeb 100644 --- a/src/discriminant.rs +++ b/src/discriminant.rs @@ -68,11 +68,10 @@ pub(crate) fn codegen_get_discriminant<'tcx>( let layout = value.layout(); if layout.abi == Abi::Uninhabited { - return trap_unreachable_ret_value( - fx, - dest_layout, - "[panic] Tried to get discriminant for uninhabited type.", - ); + let true_ = fx.bcx.ins().iconst(types::I32, 1); + fx.bcx.ins().trapnz(true_, TrapCode::UnreachableCodeReached); + // Return a dummy value + return CValue::by_ref(Pointer::const_addr(fx, 0), dest_layout); } let (tag_scalar, tag_field, tag_encoding) = match &layout.variants { diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 9e07528313d..6c22296db71 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -3,7 +3,6 @@ use std::cell::RefCell; use std::ffi::CString; -use std::lazy::SyncOnceCell; use std::os::raw::{c_char, c_int}; use std::sync::{mpsc, Mutex}; @@ -14,6 +13,9 @@ use rustc_span::Symbol; use cranelift_jit::{JITBuilder, JITModule}; +// FIXME use std::lazy::SyncOnceCell once it stabilizes +use once_cell::sync::OnceCell; + use crate::{prelude::*, BackendConfig}; use crate::{CodegenCx, CodegenMode}; @@ -27,8 +29,7 @@ thread_local! { } /// The Sender owned by the rustc thread -static GLOBAL_MESSAGE_SENDER: SyncOnceCell>> = - SyncOnceCell::new(); +static GLOBAL_MESSAGE_SENDER: OnceCell>> = OnceCell::new(); /// A message that is sent from the jitted runtime to the rustc thread. /// Senders are responsible for upholding `Send` semantics. diff --git a/src/intrinsics/llvm.rs b/src/intrinsics/llvm.rs index 098862b0662..0e4f7ee907a 100644 --- a/src/intrinsics/llvm.rs +++ b/src/intrinsics/llvm.rs @@ -126,12 +126,9 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( }; } - if let Some((_, dest)) = destination { - let ret_block = fx.get_block(dest); - fx.bcx.ins().jump(ret_block, &[]); - } else { - trap_unreachable(fx, "[corruption] Diverging intrinsic returned."); - } + let dest = destination.expect("all llvm intrinsics used by stdlib should return").1; + let ret_block = fx.get_block(dest); + fx.bcx.ins().jump(ret_block, &[]); } // llvm.x86.avx2.vperm2i128 diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 6489b96be4b..310d27c6dec 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -1,46 +1,32 @@ //! Codegen of intrinsics. This includes `extern "rust-intrinsic"`, `extern "platform-intrinsic"` //! and LLVM intrinsics that have symbol names starting with `llvm.`. -mod cpuid; -mod llvm; -mod simd; - -pub(crate) use cpuid::codegen_cpuid_call; -pub(crate) use llvm::codegen_llvm_intrinsic_call; - -use rustc_middle::ty::print::with_no_trimmed_paths; -use rustc_middle::ty::subst::SubstsRef; -use rustc_span::symbol::{kw, sym, Symbol}; - -use crate::prelude::*; -use cranelift_codegen::ir::AtomicRmwOp; - -macro intrinsic_pat { +macro_rules! intrinsic_pat { (_) => { _ - }, + }; ($name:ident) => { sym::$name - }, + }; (kw.$name:ident) => { kw::$name - }, + }; ($name:literal) => { $name - }, + }; } -macro intrinsic_arg { - (o $fx:expr, $arg:ident) => {}, +macro_rules! intrinsic_arg { + (o $fx:expr, $arg:ident) => {}; (c $fx:expr, $arg:ident) => { let $arg = codegen_operand($fx, $arg); - }, + }; (v $fx:expr, $arg:ident) => { let $arg = codegen_operand($fx, $arg).load_scalar($fx); - } + }; } -macro intrinsic_match { +macro_rules! intrinsic_match { ($fx:expr, $intrinsic:expr, $args:expr, _ => $unknown:block; $( @@ -62,6 +48,20 @@ macro intrinsic_match { } } +mod cpuid; +mod llvm; +mod simd; + +pub(crate) use cpuid::codegen_cpuid_call; +pub(crate) use llvm::codegen_llvm_intrinsic_call; + +use rustc_middle::ty::print::with_no_trimmed_paths; +use rustc_middle::ty::subst::SubstsRef; +use rustc_span::symbol::{kw, sym, Symbol}; + +use crate::prelude::*; +use cranelift_codegen::ir::AtomicRmwOp; + fn report_atomic_type_validation_error<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, intrinsic: Symbol, @@ -229,7 +229,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( // Insert non returning intrinsics here match intrinsic { sym::abort => { - trap_abort(fx, "Called intrinsic::abort."); + fx.bcx.ins().trap(TrapCode::User(0)); } sym::transmute => { crate::base::codegen_panic(fx, "Transmuting to uninhabited type.", span); @@ -749,6 +749,18 @@ fn codegen_regular_intrinsic_call<'tcx>( _ if intrinsic.as_str().starts_with("atomic_load"), (v ptr) { let ty = substs.type_at(0); match ty.kind() { + ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => { + // FIXME implement 128bit atomics + if fx.tcx.is_compiler_builtins(LOCAL_CRATE) { + // special case for compiler-builtins to avoid having to patch it + crate::trap::trap_unimplemented(fx, "128bit atomics not yet supported"); + let ret_block = fx.get_block(destination.unwrap().1); + fx.bcx.ins().jump(ret_block, &[]); + return; + } else { + fx.tcx.sess.span_fatal(span, "128bit atomics not yet supported"); + } + } ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { report_atomic_type_validation_error(fx, intrinsic, span, ty); @@ -765,6 +777,18 @@ fn codegen_regular_intrinsic_call<'tcx>( _ if intrinsic.as_str().starts_with("atomic_store"), (v ptr, c val) { let ty = substs.type_at(0); match ty.kind() { + ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => { + // FIXME implement 128bit atomics + if fx.tcx.is_compiler_builtins(LOCAL_CRATE) { + // special case for compiler-builtins to avoid having to patch it + crate::trap::trap_unimplemented(fx, "128bit atomics not yet supported"); + let ret_block = fx.get_block(destination.unwrap().1); + fx.bcx.ins().jump(ret_block, &[]); + return; + } else { + fx.tcx.sess.span_fatal(span, "128bit atomics not yet supported"); + } + } ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { report_atomic_type_validation_error(fx, intrinsic, span, ty); @@ -1115,10 +1139,6 @@ fn codegen_regular_intrinsic_call<'tcx>( }; } - if let Some((_, dest)) = destination { - let ret_block = fx.get_block(dest); - fx.bcx.ins().jump(ret_block, &[]); - } else { - trap_unreachable(fx, "[corruption] Diverging intrinsic returned."); - } + let ret_block = fx.get_block(destination.unwrap().1); + fx.bcx.ins().jump(ret_block, &[]); } diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 49022ebd3e2..bc21d736166 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -409,6 +409,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( }; simd_reduce_add_ordered | simd_reduce_add_unordered, (c v, v acc) { + // FIXME there must be no acc param for integer vectors if !v.layout().ty.is_simd() { report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty); return; @@ -424,6 +425,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( }; simd_reduce_mul_ordered | simd_reduce_mul_unordered, (c v, v acc) { + // FIXME there must be no acc param for integer vectors if !v.layout().ty.is_simd() { report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty); return; diff --git a/src/lib.rs b/src/lib.rs index 331e3e8f5df..878b9390e13 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ -#![feature(rustc_private, decl_macro)] -#![cfg_attr(feature = "jit", feature(never_type, vec_into_raw_parts, once_cell))] +#![feature(rustc_private)] +// Note: please avoid adding other feature gates where possible #![warn(rust_2018_idioms)] #![warn(unused_lifetimes)] #![warn(unreachable_pub)] @@ -105,7 +105,6 @@ mod prelude { pub(crate) use crate::common::*; pub(crate) use crate::debuginfo::{DebugContext, UnwindContext}; pub(crate) use crate::pointer::Pointer; - pub(crate) use crate::trap::*; pub(crate) use crate::value_and_place::{CPlace, CPlaceInner, CValue}; } @@ -196,7 +195,7 @@ impl CodegenBackend for CraneliftCodegenBackend { CodegenMode::Aot => driver::aot::run_aot(tcx, config, metadata, need_metadata_module), CodegenMode::Jit | CodegenMode::JitLazy => { #[cfg(feature = "jit")] - let _: ! = driver::jit::run_jit(tcx, config); + driver::jit::run_jit(tcx, config); #[cfg(not(feature = "jit"))] tcx.sess.fatal("jit support was disabled when compiling rustc_codegen_cranelift"); @@ -301,7 +300,10 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box target_isa, + Err(err) => sess.fatal(&format!("failed to build TargetIsa: {}", err)), + } } /// This is the entrypoint for a hot plugged rustc_codegen_cranelift diff --git a/src/trap.rs b/src/trap.rs index 99b5366e349..923269c4de9 100644 --- a/src/trap.rs +++ b/src/trap.rs @@ -25,12 +25,6 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, '_>, msg: &str) { fx.bcx.ins().call(puts, &[msg_ptr]); } -/// Trap code: user1 -pub(crate) fn trap_abort(fx: &mut FunctionCx<'_, '_, '_>, msg: impl AsRef) { - codegen_print(fx, msg.as_ref()); - fx.bcx.ins().trap(TrapCode::User(1)); -} - /// Use this for example when a function call should never return. This will fill the current block, /// so you can **not** add instructions to it afterwards. /// @@ -39,21 +33,6 @@ pub(crate) fn trap_unreachable(fx: &mut FunctionCx<'_, '_, '_>, msg: impl AsRef< codegen_print(fx, msg.as_ref()); fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } - -/// Like `trap_unreachable` but returns a fake value of the specified type. -/// -/// Trap code: user65535 -pub(crate) fn trap_unreachable_ret_value<'tcx>( - fx: &mut FunctionCx<'_, '_, 'tcx>, - dest_layout: TyAndLayout<'tcx>, - msg: impl AsRef, -) -> CValue<'tcx> { - codegen_print(fx, msg.as_ref()); - let true_ = fx.bcx.ins().iconst(types::I32, 1); - fx.bcx.ins().trapnz(true_, TrapCode::UnreachableCodeReached); - CValue::by_ref(Pointer::const_addr(fx, 0), dest_layout) -} - /// Use this when something is unimplemented, but `libcore` or `libstd` requires it to codegen. /// Unlike `trap_unreachable` this will not fill the current block, so you **must** add instructions /// to it afterwards. diff --git a/y.rs b/y.rs index 18528d54297..f177b91c2c4 100755 --- a/y.rs +++ b/y.rs @@ -1,9 +1,9 @@ #!/usr/bin/env bash -#![allow()] /*This line is ignored by bash +#![deny(unsafe_code)] /*This line is ignored by bash # This block is ignored by rustc set -e echo "[BUILD] y.rs" 1>&2 -rustc $0 -o ${0/.rs/.bin} -g +rustc $0 -o ${0/.rs/.bin} -Cdebuginfo=1 exec ${0/.rs/.bin} $@ */ From 1bd90f86447a4b5460d53d412e376d1cc8055d97 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 18 Mar 2022 20:34:27 +0100 Subject: [PATCH 02/22] Don't declare test_variadic_fnptr with two conflicting signatures It is UB for LLVM and results in a compile error for Cranelift --- ...-sysroot-Disable-not-compiling-tests.patch | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/patches/0022-sysroot-Disable-not-compiling-tests.patch b/patches/0022-sysroot-Disable-not-compiling-tests.patch index 108a97bd7c6..8d9ee3f25c4 100644 --- a/patches/0022-sysroot-Disable-not-compiling-tests.patch +++ b/patches/0022-sysroot-Disable-not-compiling-tests.patch @@ -30,25 +30,5 @@ index 0000000..46fd999 + +[dependencies] +rand = "0.7" -diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs -index 1a6be3a..42dbd59 100644 ---- a/library/core/tests/ptr.rs -+++ b/library/core/tests/ptr.rs -@@ -250,6 +250,7 @@ fn test_unsized_nonnull() { - }; - } - -+/* - #[test] - #[allow(warnings)] - // Have a symbol for the test below. It doesn’t need to be an actual variadic function, match the -@@ -277,6 +277,7 @@ pub fn test_variadic_fnptr() { - let mut s = SipHasher::new(); - assert_eq!(p.hash(&mut s), q.hash(&mut s)); - } -+*/ - - #[test] - fn write_unaligned_drop() { -- 2.21.0 (Apple Git-122) From 998fef81194f72e2bce8491b77503d7886eef56e Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 22 Mar 2022 12:02:50 +0100 Subject: [PATCH 03/22] Rustup to rustc 1.61.0-nightly (3c17c84a3 2022-03-21) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 84d90e5db02..cf3fff23a2a 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-03-19" +channel = "nightly-2022-03-22" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From cf1149fb383105629157c87c086be1323f4789b0 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 22 Mar 2022 12:35:49 +0100 Subject: [PATCH 04/22] Update list of ignored rustc tests --- scripts/test_rustc_tests.sh | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index a32e6df2208..f03a921d6a3 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -11,7 +11,7 @@ pushd rust command -v rg >/dev/null 2>&1 || cargo install ripgrep rm -r src/test/ui/{extern/,unsized-locals/,lto/,linkage*} || true -for test in $(rg --files-with-matches "asm!|lto|// needs-asm-support|// needs-unwind" src/test/{ui,incremental}); do +for test in $(rg --files-with-matches "lto|// needs-asm-support|// needs-unwind" src/test/{ui,incremental}); do rm $test done @@ -25,14 +25,8 @@ git checkout -- src/test/ui/issues/auxiliary/issue-3136-a.rs # contains //~ERROR # ================ # requires stack unwinding -rm src/test/ui/backtrace.rs -rm src/test/ui/process/multi-panic.rs -rm src/test/ui/numbers-arithmetic/issue-8460.rs rm src/test/incremental/change_crate_dep_kind.rs rm src/test/incremental/issue-80691-bad-eval-cache.rs # -Cpanic=abort causes abort instead of exit(101) -rm src/test/ui/panic-while-printing.rs -rm src/test/ui/test-attrs/test-panic-while-printing.rs -rm src/test/ui/test-attrs/test-type.rs # requires compiling with -Cpanic=unwind rm src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs # "Cannot run dynamic test fn out-of-process" @@ -114,7 +108,10 @@ rm src/test/ui/simd/intrinsic/generic-reduction-pass.rs # simd_reduce_add_unorde # bugs in the test suite # ====================== -rm src/test/ui/unsafe/union.rs # has UB caught by cg_clif. see rust-lang/rust#95075 +rm src/test/ui/backtrace.rs # TODO warning +rm src/test/ui/empty_global_asm.rs # TODO add needs-asm-support +rm src/test/ui/simple_global_asm.rs # TODO add needs-asm-support +rm src/test/ui/test-attrs/test-type.rs # TODO panic message on stderr. correct stdout echo "[TEST] rustc test suite" RUST_TEST_NOCAPTURE=1 COMPILETEST_FORCE_STAGE0=1 ./x.py test --stage 0 src/test/{codegen-units,run-make,run-pass-valgrind,ui,incremental} From e336e1bccf3831097283469243b0228accea85d4 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 25 Mar 2022 17:28:39 +0100 Subject: [PATCH 05/22] Rustup to rustc 1.61.0-nightly (63b8f01bb 2022-03-24) --- example/mini_core.rs | 3 +++ rust-toolchain | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/example/mini_core.rs b/example/mini_core.rs index 7efc8dc785a..956bed3ccd8 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -16,6 +16,9 @@ #[lang = "sized"] pub trait Sized {} +#[lang = "destruct"] +pub trait Destruct {} + #[lang = "unsize"] pub trait Unsize {} diff --git a/rust-toolchain b/rust-toolchain index cf3fff23a2a..cd8c5f8fb79 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-03-22" +channel = "nightly-2022-03-25" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From f3d97cce279fd2372aafec3761791b4110d70bf5 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 25 Mar 2022 19:17:19 +0100 Subject: [PATCH 06/22] Fix saturating float casts test Fixes #737 --- example/std_example.rs | 6 +++++- scripts/test_rustc_tests.sh | 1 - src/cast.rs | 29 +++++++++++++++++++++-------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/example/std_example.rs b/example/std_example.rs index 5bc51a541b5..0a2bce2621d 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -1,7 +1,8 @@ -#![feature(core_intrinsics, generators, generator_trait, is_sorted)] +#![feature(core_intrinsics, generators, generator_trait, is_sorted, bench_black_box)] #[cfg(target_arch = "x86_64")] use std::arch::x86_64::*; +use std::hint::black_box; use std::io::Write; use std::ops::Generator; @@ -86,6 +87,9 @@ fn main() { assert_eq!(houndred_f64 as i128, 100); assert_eq!(1u128.rotate_left(2), 4); + assert_eq!(black_box(f32::NAN) as i128, 0); + assert_eq!(black_box(f32::NAN) as u128, 0); + // Test signed 128bit comparing let max = usize::MAX as i128; if 100i128 < 0i128 || 100i128 > max { diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index f03a921d6a3..5f47e7204ea 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -79,7 +79,6 @@ rm src/test/ui/abi/stack-protector.rs # requires stack protector support # giving different but possibly correct results # ============================================= -rm src/test/ui/numbers-arithmetic/saturating-float-casts.rs # intrinsic gives different but valid result rm src/test/ui/simd/intrinsic/float-minmax-pass.rs # same rm src/test/ui/mir/mir_misc_casts.rs # depends on deduplication of constants rm src/test/ui/mir/mir_raw_fat_ptr.rs # same diff --git a/src/cast.rs b/src/cast.rs index e7e6afeb865..e19070774c6 100644 --- a/src/cast.rs +++ b/src/cast.rs @@ -84,7 +84,7 @@ pub(crate) fn clif_int_or_float_cast( fx.bcx.ins().fcvt_from_uint(to_ty, from) } } else if from_ty.is_float() && to_ty.is_int() { - if to_ty == types::I128 { + let val = if to_ty == types::I128 { // _____sssf___ // __fix sfti: f32 -> i128 // __fix dfti: f64 -> i128 @@ -109,13 +109,9 @@ pub(crate) fn clif_int_or_float_cast( let to_rust_ty = if to_signed { fx.tcx.types.i128 } else { fx.tcx.types.u128 }; - return fx - .easy_call(&name, &[CValue::by_val(from, fx.layout_of(from_rust_ty))], to_rust_ty) - .load_scalar(fx); - } - - // float -> int-like - if to_ty == types::I8 || to_ty == types::I16 { + fx.easy_call(&name, &[CValue::by_val(from, fx.layout_of(from_rust_ty))], to_rust_ty) + .load_scalar(fx) + } else if to_ty == types::I8 || to_ty == types::I16 { // FIXME implement fcvt_to_*int_sat.i8/i16 let val = if to_signed { fx.bcx.ins().fcvt_to_sint_sat(types::I32, from) @@ -146,6 +142,23 @@ pub(crate) fn clif_int_or_float_cast( fx.bcx.ins().fcvt_to_sint_sat(to_ty, from) } else { fx.bcx.ins().fcvt_to_uint_sat(to_ty, from) + }; + + if let Some(false) = fx.tcx.sess.opts.debugging_opts.saturating_float_casts { + return val; + } + + let is_not_nan = fx.bcx.ins().fcmp(FloatCC::Equal, from, from); + if to_ty == types::I128 { + // FIXME(bytecodealliance/wasmtime#3963): select.i128 on fcmp eq miscompiles + let (lsb, msb) = fx.bcx.ins().isplit(val); + let zero = fx.bcx.ins().iconst(types::I64, 0); + let lsb = fx.bcx.ins().select(is_not_nan, lsb, zero); + let msb = fx.bcx.ins().select(is_not_nan, msb, zero); + fx.bcx.ins().iconcat(lsb, msb) + } else { + let zero = fx.bcx.ins().iconst(to_ty, 0); + fx.bcx.ins().select(is_not_nan, val, zero) } } else if from_ty.is_float() && to_ty.is_float() { // float -> float From 3c030e2425bb1fdb165ac87797076072ec991970 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 25 Mar 2022 20:24:47 +0100 Subject: [PATCH 07/22] Fix NaN handling of simd float min and max operations --- example/float-minmax-pass.rs | 53 +++++++++++++++++++ ...table-simd-Disable-unsupported-tests.patch | 16 ------ scripts/test_rustc_tests.sh | 1 - scripts/tests.sh | 4 ++ src/intrinsics/mod.rs | 24 ++------- src/intrinsics/simd.rs | 8 +-- src/num.rs | 18 +++++++ 7 files changed, 83 insertions(+), 41 deletions(-) create mode 100644 example/float-minmax-pass.rs diff --git a/example/float-minmax-pass.rs b/example/float-minmax-pass.rs new file mode 100644 index 00000000000..b8f901d1ba1 --- /dev/null +++ b/example/float-minmax-pass.rs @@ -0,0 +1,53 @@ +// Copied from https://github.com/rust-lang/rust/blob/3fe3b89cd57229343eeca753fdd8c63d9b03c65c/src/test/ui/simd/intrinsic/float-minmax-pass.rs +// run-pass +// ignore-emscripten + +// Test that the simd_f{min,max} intrinsics produce the correct results. + +#![feature(repr_simd, platform_intrinsics)] +#![allow(non_camel_case_types)] + +#[repr(simd)] +#[derive(Copy, Clone, PartialEq, Debug)] +struct f32x4(pub f32, pub f32, pub f32, pub f32); + +extern "platform-intrinsic" { + fn simd_fmin(x: T, y: T) -> T; + fn simd_fmax(x: T, y: T) -> T; +} + +fn main() { + let x = f32x4(1.0, 2.0, 3.0, 4.0); + let y = f32x4(2.0, 1.0, 4.0, 3.0); + + #[cfg(not(any(target_arch = "mips", target_arch = "mips64")))] + let nan = f32::NAN; + // MIPS hardware treats f32::NAN as SNAN. Clear the signaling bit. + // See https://github.com/rust-lang/rust/issues/52746. + #[cfg(any(target_arch = "mips", target_arch = "mips64"))] + let nan = f32::from_bits(f32::NAN.to_bits() - 1); + + let n = f32x4(nan, nan, nan, nan); + + unsafe { + let min0 = simd_fmin(x, y); + let min1 = simd_fmin(y, x); + assert_eq!(min0, min1); + let e = f32x4(1.0, 1.0, 3.0, 3.0); + assert_eq!(min0, e); + let minn = simd_fmin(x, n); + assert_eq!(minn, x); + let minn = simd_fmin(y, n); + assert_eq!(minn, y); + + let max0 = simd_fmax(x, y); + let max1 = simd_fmax(y, x); + assert_eq!(max0, max1); + let e = f32x4(2.0, 2.0, 4.0, 4.0); + assert_eq!(max0, e); + let maxn = simd_fmax(x, n); + assert_eq!(maxn, x); + let maxn = simd_fmax(y, n); + assert_eq!(maxn, y); + } +} diff --git a/patches/0001-portable-simd-Disable-unsupported-tests.patch b/patches/0001-portable-simd-Disable-unsupported-tests.patch index c1325908691..b952b21e6e6 100644 --- a/patches/0001-portable-simd-Disable-unsupported-tests.patch +++ b/patches/0001-portable-simd-Disable-unsupported-tests.patch @@ -106,22 +106,6 @@ diff --git a/crates/core_simd/tests/ops_macros.rs b/crates/core_simd/tests/ops_m index 31b7ee2..bd04b3c 100644 --- a/crates/core_simd/tests/ops_macros.rs +++ b/crates/core_simd/tests/ops_macros.rs -@@ -567,6 +567,7 @@ macro_rules! impl_float_tests { - }); - } - -+ /* - fn horizontal_max() { - test_helpers::test_1(&|x| { - let vmax = Vector::::from_array(x).horizontal_max(); -@@ -590,6 +591,7 @@ macro_rules! impl_float_tests { - Ok(()) - }); - } -+ */ - } - - #[cfg(feature = "std")] @@ -604,6 +606,7 @@ macro_rules! impl_float_tests { ) } diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 5f47e7204ea..3d6bd887459 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -79,7 +79,6 @@ rm src/test/ui/abi/stack-protector.rs # requires stack protector support # giving different but possibly correct results # ============================================= -rm src/test/ui/simd/intrinsic/float-minmax-pass.rs # same rm src/test/ui/mir/mir_misc_casts.rs # depends on deduplication of constants rm src/test/ui/mir/mir_raw_fat_ptr.rs # same rm src/test/ui/consts/issue-33537.rs # same diff --git a/scripts/tests.sh b/scripts/tests.sh index fee1012c8f1..aae626081f6 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -72,6 +72,10 @@ function base_sysroot_tests() { $MY_RUSTC example/track-caller-attribute.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE" $RUN_WRAPPER ./target/out/track-caller-attribute + echo "[AOT] float-minmax-pass" + $MY_RUSTC example/float-minmax-pass.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE" + $RUN_WRAPPER ./target/out/float-minmax-pass + echo "[AOT] mod_bench" $MY_RUSTC example/mod_bench.rs --crate-type bin --target "$TARGET_TRIPLE" $RUN_WRAPPER ./target/out/mod_bench diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 310d27c6dec..d76dfca7960 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -1019,39 +1019,23 @@ fn codegen_regular_intrinsic_call<'tcx>( ret.write_cvalue(fx, old); }; - // In Rust floating point min and max don't propagate NaN. In Cranelift they do however. - // For this reason it is necessary to use `a.is_nan() ? b : (a >= b ? b : a)` for `minnumf*` - // and `a.is_nan() ? b : (a <= b ? b : a)` for `maxnumf*`. NaN checks are done by comparing - // a float against itself. Only in case of NaN is it not equal to itself. minnumf32, (v a, v b) { - let a_is_nan = fx.bcx.ins().fcmp(FloatCC::NotEqual, a, a); - let a_ge_b = fx.bcx.ins().fcmp(FloatCC::GreaterThanOrEqual, a, b); - let temp = fx.bcx.ins().select(a_ge_b, b, a); - let val = fx.bcx.ins().select(a_is_nan, b, temp); + let val = crate::num::codegen_float_min(fx, a, b); let val = CValue::by_val(val, fx.layout_of(fx.tcx.types.f32)); ret.write_cvalue(fx, val); }; minnumf64, (v a, v b) { - let a_is_nan = fx.bcx.ins().fcmp(FloatCC::NotEqual, a, a); - let a_ge_b = fx.bcx.ins().fcmp(FloatCC::GreaterThanOrEqual, a, b); - let temp = fx.bcx.ins().select(a_ge_b, b, a); - let val = fx.bcx.ins().select(a_is_nan, b, temp); + let val = crate::num::codegen_float_min(fx, a, b); let val = CValue::by_val(val, fx.layout_of(fx.tcx.types.f64)); ret.write_cvalue(fx, val); }; maxnumf32, (v a, v b) { - let a_is_nan = fx.bcx.ins().fcmp(FloatCC::NotEqual, a, a); - let a_le_b = fx.bcx.ins().fcmp(FloatCC::LessThanOrEqual, a, b); - let temp = fx.bcx.ins().select(a_le_b, b, a); - let val = fx.bcx.ins().select(a_is_nan, b, temp); + let val = crate::num::codegen_float_max(fx, a, b); let val = CValue::by_val(val, fx.layout_of(fx.tcx.types.f32)); ret.write_cvalue(fx, val); }; maxnumf64, (v a, v b) { - let a_is_nan = fx.bcx.ins().fcmp(FloatCC::NotEqual, a, a); - let a_le_b = fx.bcx.ins().fcmp(FloatCC::LessThanOrEqual, a, b); - let temp = fx.bcx.ins().select(a_le_b, b, a); - let val = fx.bcx.ins().select(a_is_nan, b, temp); + let val = crate::num::codegen_float_max(fx, a, b); let val = CValue::by_val(val, fx.layout_of(fx.tcx.types.f64)); ret.write_cvalue(fx, val); }; diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index bc21d736166..25755f8c7ec 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -354,8 +354,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( _ => unreachable!("{:?}", lane_ty), } match intrinsic { - sym::simd_fmin => fx.bcx.ins().fmin(x_lane, y_lane), - sym::simd_fmax => fx.bcx.ins().fmax(x_lane, y_lane), + sym::simd_fmin => crate::num::codegen_float_min(fx, x_lane, y_lane), + sym::simd_fmax => crate::num::codegen_float_max(fx, x_lane, y_lane), _ => unreachable!(), } }); @@ -495,7 +495,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( let lt = match ty.kind() { ty::Int(_) => fx.bcx.ins().icmp(IntCC::SignedLessThan, a, b), ty::Uint(_) => fx.bcx.ins().icmp(IntCC::UnsignedLessThan, a, b), - ty::Float(_) => fx.bcx.ins().fcmp(FloatCC::LessThan, a, b), + ty::Float(_) => return crate::num::codegen_float_min(fx, a, b), _ => unreachable!(), }; fx.bcx.ins().select(lt, a, b) @@ -512,7 +512,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( let gt = match ty.kind() { ty::Int(_) => fx.bcx.ins().icmp(IntCC::SignedGreaterThan, a, b), ty::Uint(_) => fx.bcx.ins().icmp(IntCC::UnsignedGreaterThan, a, b), - ty::Float(_) => fx.bcx.ins().fcmp(FloatCC::GreaterThan, a, b), + ty::Float(_) => return crate::num::codegen_float_max(fx, a, b), _ => unreachable!(), }; fx.bcx.ins().select(gt, a, b) diff --git a/src/num.rs b/src/num.rs index 545d390e269..4ce8adb182e 100644 --- a/src/num.rs +++ b/src/num.rs @@ -420,3 +420,21 @@ pub(crate) fn codegen_ptr_binop<'tcx>( CValue::by_val(fx.bcx.ins().bint(types::I8, res), fx.layout_of(fx.tcx.types.bool)) } } + +// In Rust floating point min and max don't propagate NaN. In Cranelift they do however. +// For this reason it is necessary to use `a.is_nan() ? b : (a >= b ? b : a)` for `minnumf*` +// and `a.is_nan() ? b : (a <= b ? b : a)` for `maxnumf*`. NaN checks are done by comparing +// a float against itself. Only in case of NaN is it not equal to itself. +pub(crate) fn codegen_float_min(fx: &mut FunctionCx<'_, '_, '_>, a: Value, b: Value) -> Value { + let a_is_nan = fx.bcx.ins().fcmp(FloatCC::NotEqual, a, a); + let a_ge_b = fx.bcx.ins().fcmp(FloatCC::GreaterThanOrEqual, a, b); + let temp = fx.bcx.ins().select(a_ge_b, b, a); + fx.bcx.ins().select(a_is_nan, b, temp) +} + +pub(crate) fn codegen_float_max(fx: &mut FunctionCx<'_, '_, '_>, a: Value, b: Value) -> Value { + let a_is_nan = fx.bcx.ins().fcmp(FloatCC::NotEqual, a, a); + let a_le_b = fx.bcx.ins().fcmp(FloatCC::LessThanOrEqual, a, b); + let temp = fx.bcx.ins().select(a_le_b, b, a); + fx.bcx.ins().select(a_is_nan, b, temp) +} From 11007c02f70130cdc70b98f0909e5c150a2751a6 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 25 Mar 2022 20:42:58 +0100 Subject: [PATCH 08/22] Use fma(f) libm function for simd_fma intrinsic --- ...table-simd-Disable-unsupported-tests.patch | 20 ------------------ src/intrinsics/simd.rs | 21 ++++++++++--------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/patches/0001-portable-simd-Disable-unsupported-tests.patch b/patches/0001-portable-simd-Disable-unsupported-tests.patch index b952b21e6e6..54e13b090ab 100644 --- a/patches/0001-portable-simd-Disable-unsupported-tests.patch +++ b/patches/0001-portable-simd-Disable-unsupported-tests.patch @@ -102,26 +102,6 @@ index 6a8ecd3..68fcb49 100644 } } } -diff --git a/crates/core_simd/tests/ops_macros.rs b/crates/core_simd/tests/ops_macros.rs -index 31b7ee2..bd04b3c 100644 ---- a/crates/core_simd/tests/ops_macros.rs -+++ b/crates/core_simd/tests/ops_macros.rs -@@ -604,6 +606,7 @@ macro_rules! impl_float_tests { - ) - } - -+ /* - fn mul_add() { - test_helpers::test_ternary_elementwise( - &Vector::::mul_add, -@@ -611,6 +614,7 @@ macro_rules! impl_float_tests { - &|_, _, _| true, - ) - } -+ */ - } - } - } -- 2.26.2.7.g19db9cfb68 diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 25755f8c7ec..d1ca9edf2e0 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -322,20 +322,21 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( } assert_eq!(a.layout(), b.layout()); assert_eq!(a.layout(), c.layout()); - let layout = a.layout(); + assert_eq!(a.layout(), ret.layout()); - let (lane_count, _lane_ty) = layout.ty.simd_size_and_type(fx.tcx); - let (ret_lane_count, ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx); - assert_eq!(lane_count, ret_lane_count); - let ret_lane_layout = fx.layout_of(ret_lane_ty); + let layout = a.layout(); + let (lane_count, lane_ty) = layout.ty.simd_size_and_type(fx.tcx); for lane in 0..lane_count { - let a_lane = a.value_lane(fx, lane).load_scalar(fx); - let b_lane = b.value_lane(fx, lane).load_scalar(fx); - let c_lane = c.value_lane(fx, lane).load_scalar(fx); + let a_lane = a.value_lane(fx, lane); + let b_lane = b.value_lane(fx, lane); + let c_lane = c.value_lane(fx, lane); - let mul_lane = fx.bcx.ins().fmul(a_lane, b_lane); - let res_lane = CValue::by_val(fx.bcx.ins().fadd(mul_lane, c_lane), ret_lane_layout); + let res_lane = match lane_ty.kind() { + ty::Float(FloatTy::F32) => fx.easy_call("fmaf", &[a_lane, b_lane, c_lane], lane_ty), + ty::Float(FloatTy::F64) => fx.easy_call("fma", &[a_lane, b_lane, c_lane], lane_ty), + _ => unreachable!(), + }; ret.place_lane(fx, lane).write_cvalue(fx, res_lane); } From 93aedb67df4cd03b742c9a25874cb716574c48ff Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 30 Mar 2022 01:39:38 -0400 Subject: [PATCH 09/22] Spellchecking some comments This PR attempts to clean up some minor spelling mistakes in comments --- example/arbitrary_self_types_pointers_and_wrappers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/arbitrary_self_types_pointers_and_wrappers.rs b/example/arbitrary_self_types_pointers_and_wrappers.rs index e9876837dd8..d270fec6b71 100644 --- a/example/arbitrary_self_types_pointers_and_wrappers.rs +++ b/example/arbitrary_self_types_pointers_and_wrappers.rs @@ -36,7 +36,7 @@ impl, U> DispatchFromDyn> for Wrapper {} trait Trait { // This method isn't object-safe yet. Unsized by-value `self` is object-safe (but not callable - // without unsized_locals), but wrappers arond `Self` currently are not. + // without unsized_locals), but wrappers around `Self` currently are not. // FIXME (mikeyhew) uncomment this when unsized rvalues object-safety is implemented // fn wrapper(self: Wrapper) -> i32; fn ptr_wrapper(self: Ptr>) -> i32; From ae2f203e24202c8e8337cf8500cb17d8359d611f Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 30 Mar 2022 01:42:10 -0400 Subject: [PATCH 10/22] Spellchecking compiler code Address some spelling mistakes in strings, private function names, and function params. --- scripts/rustup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/rustup.sh b/scripts/rustup.sh index cc34c080886..bc4c06ed7d2 100755 --- a/scripts/rustup.sh +++ b/scripts/rustup.sh @@ -11,7 +11,7 @@ case $1 in sed -i "s/\"nightly-.*\"/\"nightly-${TOOLCHAIN}\"/" rust-toolchain rustup component add rustfmt || true - echo "=> Uninstalling all old nighlies" + echo "=> Uninstalling all old nightlies" for nightly in $(rustup toolchain list | grep nightly | grep -v "$TOOLCHAIN" | grep -v nightly-x86_64); do rustup toolchain uninstall "$nightly" done From 421baaff3f87742d00f5ed57f6a6c9dfd6c2b263 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 30 Mar 2022 15:14:15 -0400 Subject: [PATCH 11/22] Spellchecking compiler comments This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues. --- src/pretty_clif.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index ca7116b887d..90024c5921a 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -23,7 +23,7 @@ //! ss2 = explicit_slot 8 ; _4: (&&[u16],) size=8 align=8,8 //! sig0 = (i64, i64, i64) system_v //! sig1 = (i64, i64, i64) system_v -//! fn0 = colocated u0:6 sig1 ; Instance { def: Item(DefId(0/0:31 ~ example[8787]::{{impl}}[1]::call_mut[0])), substs: [ReErased, ReErased] } +//! fn0 = collocated u0:6 sig1 ; Instance { def: Item(DefId(0/0:31 ~ example[8787]::{{impl}}[1]::call_mut[0])), substs: [ReErased, ReErased] } //! //! block0(v0: i64, v1: i64, v2: i64): //! v3 = stack_addr.i64 ss0 From 7665d876389d3bb0674f33859c620e516394bcf8 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 30 Mar 2022 17:04:46 -0400 Subject: [PATCH 12/22] Addressed comments by @compiler-errors and @bjorn3 --- src/pretty_clif.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index 90024c5921a..ca7116b887d 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -23,7 +23,7 @@ //! ss2 = explicit_slot 8 ; _4: (&&[u16],) size=8 align=8,8 //! sig0 = (i64, i64, i64) system_v //! sig1 = (i64, i64, i64) system_v -//! fn0 = collocated u0:6 sig1 ; Instance { def: Item(DefId(0/0:31 ~ example[8787]::{{impl}}[1]::call_mut[0])), substs: [ReErased, ReErased] } +//! fn0 = colocated u0:6 sig1 ; Instance { def: Item(DefId(0/0:31 ~ example[8787]::{{impl}}[1]::call_mut[0])), substs: [ReErased, ReErased] } //! //! block0(v0: i64, v1: i64, v2: i64): //! v3 = stack_addr.i64 ss0 From 69046fa8fdb2505367a4375be78eae5b47e15fe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20BRANSTETT?= Date: Sun, 3 Apr 2022 18:42:39 +0200 Subject: [PATCH 13/22] Cleanup after some refactoring in rustc_target --- src/driver/aot.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 2e047c7eea1..5e1e1c81d26 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -304,8 +304,12 @@ pub(crate) fn run_aot( }; // FIXME handle `-Ctarget-cpu=native` - let target_cpu = - tcx.sess.opts.cg.target_cpu.as_ref().unwrap_or(&tcx.sess.target.cpu).to_owned(); + let target_cpu = match tcx.sess.opts.cg.target_cpu { + Some(ref name) => name, + None => tcx.sess.target.cpu.as_ref(), + } + .to_owned(); + Box::new(( CodegenResults { modules, From b87d7834c0c272f74fec72ccdb10d3b0e227e89a Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 5 Apr 2022 11:44:41 +0200 Subject: [PATCH 14/22] Rustup to rustc 1.62.0-nightly (60e50fc1c 2022-04-04) --- build_sysroot/Cargo.lock | 4 ++-- rust-toolchain | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index f584f54e106..0d9ae67342e 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -56,9 +56,9 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.71" +version = "0.1.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "163437f05ca8f29d7e9128ea728dedf5eb620e445fbca273641d3a3050305f23" +checksum = "afdbb35d279238cf77f0c9e8d90ad50d6c7bff476ab342baafa29440f0f10bff" dependencies = [ "rustc-std-workspace-core", ] diff --git a/rust-toolchain b/rust-toolchain index cd8c5f8fb79..763aceac2df 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-03-25" +channel = "nightly-2022-04-05" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 557a09f6b543ec36597d2dfdf1d26262a3a4b235 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 5 Apr 2022 12:46:56 +0200 Subject: [PATCH 15/22] Ignore broken rustc test --- scripts/test_rustc_tests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 3d6bd887459..7e539209c39 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -104,6 +104,8 @@ rm src/test/ui/mir/ssa-analysis-regression-50041.rs # produces ICE rm src/test/ui/simd/intrinsic/generic-reduction-pass.rs # simd_reduce_add_unordered doesn't accept an accumulator for integer vectors +rm src/test/ui/rfc-2091-track-caller/intrinsic-wrapper.rs # wrong result from `Location::caller()` + # bugs in the test suite # ====================== rm src/test/ui/backtrace.rs # TODO warning From 2efede77493df5912800fc358f28277642f56bc9 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 3 Mar 2022 12:02:12 +0000 Subject: [PATCH 16/22] Mark scalar layout unions so that backends that do not support partially initialized scalars can special case them. --- src/common.rs | 2 +- src/discriminant.rs | 2 +- src/value_and_place.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common.rs b/src/common.rs index 89fd0bfa8bb..ffa629ca16c 100644 --- a/src/common.rs +++ b/src/common.rs @@ -21,7 +21,7 @@ pub(crate) fn pointer_ty(tcx: TyCtxt<'_>) -> types::Type { } pub(crate) fn scalar_to_clif_type(tcx: TyCtxt<'_>, scalar: Scalar) -> Type { - match scalar.value { + match scalar.primitive() { Primitive::Int(int, _sign) => match int { Integer::I8 => types::I8, Integer::I16 => types::I16, diff --git a/src/discriminant.rs b/src/discriminant.rs index 6b2893fdaeb..357cb4a6d24 100644 --- a/src/discriminant.rs +++ b/src/discriminant.rs @@ -105,7 +105,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>( // Decode the discriminant (specifically if it's niche-encoded). match *tag_encoding { TagEncoding::Direct => { - let signed = match tag_scalar.value { + let signed = match tag_scalar.primitive() { Int(_, signed) => signed, _ => false, }; diff --git a/src/value_and_place.rs b/src/value_and_place.rs index afe8797a030..8f80b02ae0d 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -50,7 +50,7 @@ fn codegen_field<'tcx>( } fn scalar_pair_calculate_b_offset(tcx: TyCtxt<'_>, a_scalar: Scalar, b_scalar: Scalar) -> Offset32 { - let b_offset = a_scalar.value.size(&tcx).align_to(b_scalar.value.align(&tcx).abi); + let b_offset = a_scalar.size(&tcx).align_to(b_scalar.align(&tcx).abi); Offset32::new(b_offset.bytes().try_into().unwrap()) } From f2d2ec3e93532feb28a2d5e86632c38d8d75f9a5 Mon Sep 17 00:00:00 2001 From: klensy Date: Tue, 5 Apr 2022 15:52:53 +0300 Subject: [PATCH 17/22] check_doc_keyword: don't alloc string for emptiness check check_doc_alias_value: get argument as Symbol to prevent needless string convertions check_doc_attrs: don't alloc vec, iterate over slice. Vec introduced in #83149, but no perf run posted on merge replace as_str() check with symbol check get_single_str_from_tts: don't prealloc string trivial string to str replace LifetimeScopeForPath::NonElided use Vec instead of Vec AssertModuleSource use BTreeSet instead of BTreeSet CrateInfo.crate_name replace FxHashMap with FxHashMap --- src/driver/jit.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 6c22296db71..7f15bc75fda 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -288,8 +288,8 @@ fn load_imported_symbols_for_jit( match data[cnum.as_usize() - 1] { Linkage::NotLinked | Linkage::IncludedFromDylib => {} Linkage::Static => { - let name = &crate_info.crate_name[&cnum]; - let mut err = sess.struct_err(&format!("Can't load static lib {}", name.as_str())); + let name = crate_info.crate_name[&cnum]; + let mut err = sess.struct_err(&format!("Can't load static lib {}", name)); err.note("rustc_codegen_cranelift can only load dylibs in JIT mode."); err.emit(); } From a923e9211a6adf4c78dd5f095a514455039e5fb4 Mon Sep 17 00:00:00 2001 From: Jakob Degen Date: Tue, 5 Apr 2022 17:14:59 -0400 Subject: [PATCH 18/22] Add new `Deinit` statement kind --- src/base.rs | 1 + src/constant.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/base.rs b/src/base.rs index a9ff710c91e..8c45993a8b7 100644 --- a/src/base.rs +++ b/src/base.rs @@ -772,6 +772,7 @@ fn codegen_stmt<'tcx>( } StatementKind::StorageLive(_) | StatementKind::StorageDead(_) + | StatementKind::Deinit(_) | StatementKind::Nop | StatementKind::FakeRead(..) | StatementKind::Retag { .. } diff --git a/src/constant.rs b/src/constant.rs index 4657791345b..57074f00210 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -518,6 +518,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>( StatementKind::Assign(_) | StatementKind::FakeRead(_) | StatementKind::SetDiscriminant { .. } + | StatementKind::Deinit(_) | StatementKind::StorageLive(_) | StatementKind::StorageDead(_) | StatementKind::Retag(_, _) From 83d470d91c15d0cb5890705291e6ee9e5be8a842 Mon Sep 17 00:00:00 2001 From: MikaelUrankar <49529234+MikaelUrankar@users.noreply.github.com> Date: Thu, 14 Apr 2022 14:18:13 +0200 Subject: [PATCH 19/22] Don't assume /bin/bash is available on every system. (#1223) Co-authored-by: MikaelUrankar --- scripts/filter_profile.rs | 2 +- scripts/setup_rust_fork.sh | 2 +- scripts/test_rustc_tests.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/filter_profile.rs b/scripts/filter_profile.rs index a0e99267c2b..f4e863e5494 100755 --- a/scripts/filter_profile.rs +++ b/scripts/filter_profile.rs @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash #![forbid(unsafe_code)]/* This line is ignored by bash # This block is ignored by rustc pushd $(dirname "$0")/../ diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index 85c0109c6f6..cabbaaa8922 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e ./y.rs build --no-unstable-features diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 7e539209c39..4cf24c02235 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e cd $(dirname "$0")/../ From 89c67a87bc84be74632e0099584223b537a6abac Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 17 Apr 2022 19:41:24 +0200 Subject: [PATCH 20/22] Remove option to select regalloc algorithm The main branch of Cranelift has switched to a new register allocator. This register allocator doesn't have any alternative regalloc algorithms unlike the old register allocator. --- src/config.rs | 9 --------- src/lib.rs | 2 -- 2 files changed, 11 deletions(-) diff --git a/src/config.rs b/src/config.rs index eef3c8c8d6e..e59a0cb0a23 100644 --- a/src/config.rs +++ b/src/config.rs @@ -48,12 +48,6 @@ pub struct BackendConfig { /// Can be set using `-Cllvm-args=display_cg_time=...`. pub display_cg_time: bool, - /// The register allocator to use. - /// - /// Defaults to the value of `CG_CLIF_REGALLOC` or `backtracking` otherwise. Can be set using - /// `-Cllvm-args=regalloc=...`. - pub regalloc: String, - /// Enable the Cranelift ir verifier for all compilation passes. If not set it will only run /// once before passing the clif ir to Cranelift for compilation. /// @@ -80,8 +74,6 @@ impl Default for BackendConfig { args.split(' ').map(|arg| arg.to_string()).collect() }, display_cg_time: bool_env_var("CG_CLIF_DISPLAY_CG_TIME"), - regalloc: std::env::var("CG_CLIF_REGALLOC") - .unwrap_or_else(|_| "backtracking".to_string()), enable_verifier: cfg!(debug_assertions) || bool_env_var("CG_CLIF_ENABLE_VERIFIER"), disable_incr_cache: bool_env_var("CG_CLIF_DISABLE_INCR_CACHE"), } @@ -101,7 +93,6 @@ impl BackendConfig { match name { "mode" => config.codegen_mode = value.parse()?, "display_cg_time" => config.display_cg_time = parse_bool(name, value)?, - "regalloc" => config.regalloc = value.to_string(), "enable_verifier" => config.enable_verifier = parse_bool(name, value)?, "disable_incr_cache" => config.disable_incr_cache = parse_bool(name, value)?, _ => return Err(format!("Unknown option `{}`", name)), diff --git a/src/lib.rs b/src/lib.rs index 878b9390e13..9d2e12f9898 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -256,8 +256,6 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box { From a177a7f9df81993158ff3338af57bf9929d41971 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 21 Apr 2022 19:22:12 +0200 Subject: [PATCH 21/22] Update Cranelift to 0.83.0 --- Cargo.lock | 40 ++++++++++++++++++++-------------------- Cargo.toml | 12 ++++++------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 30e9627c48d..7b8e43b639f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,18 +33,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.82.1" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d16922317bd7dd104d509a373887822caa0242fc1def00de66abb538db221db4" +checksum = "ed44413e7e2fe3260d0ed73e6956ab188b69c10ee92b892e401e0f4f6808c68b" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.82.1" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b80bf40380256307b68a3dcbe1b91cac92a533e212b5b635abc3e4525781a0a" +checksum = "0b5d83f0f26bf213f971f45589d17e5b65e4861f9ed22392b0cbb6eaa5bd329c" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -59,30 +59,30 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.82.1" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "703d0ed7d3bc6c7a814ca12858175bf4e93167a3584127858c686e4b5dd6e432" +checksum = "6800dc386177df6ecc5a32680607ed8ba1fa0d31a2a59c8c61fbf44826b8191d" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.82.1" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80f52311e1c90de12dcf8c4b9999c6ebfd1ed360373e88c357160936844511f6" +checksum = "c961f85070985ebc8fcdb81b838a5cf842294d1e6ed4852446161c7e246fd455" [[package]] name = "cranelift-entity" -version = "0.82.1" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66bc82ef522c1f643baf7d4d40b7c52643ee4549d8960b0e6a047daacb83f897" +checksum = "2347b2b8d1d5429213668f2a8e36c85ee3c73984a2f6a79007e365d3e575e7ed" [[package]] name = "cranelift-frontend" -version = "0.82.1" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cc35e4251864b17515845ba47447bca88fec9ca1a4186b19fe42526e36140e8" +checksum = "4cbcdbf7bed29e363568b778649b69dabc3d727256d5d25236096ef693757654" dependencies = [ "cranelift-codegen", "log", @@ -92,9 +92,9 @@ dependencies = [ [[package]] name = "cranelift-jit" -version = "0.82.1" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93c66d594ad3bfe4e58b1fbd8d17877a7c6564a5f2d6f78cbbf4b0182af1927f" +checksum = "7c769d4e0d76f59c8b2a3bf0477d89ee149bb0731b53fbb245ee081d49063095" dependencies = [ "anyhow", "cranelift-codegen", @@ -110,9 +110,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.82.1" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf356697c40232aa09e1e3fb8a350ee894e849ccecc4eac56ff0570a4575c325" +checksum = "0ab57d399a2401074bb0cc40b3031e420f3d66d46ec0cf21eeae53ac04bd73e2" dependencies = [ "anyhow", "cranelift-codegen", @@ -120,9 +120,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.82.1" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b882b2251c9845d509d92aebfdb6c8bb3b3b48e207ac951f21fbd20cfe7f90b3" +checksum = "8f4cdf93552e5ceb2e3c042829ebb4de4378492705f769eadc6a7c6c5251624c" dependencies = [ "cranelift-codegen", "libc", @@ -131,9 +131,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.82.1" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d3f1a88e654e567d2591169239ed157ab290811a729a6468f53999c01001263" +checksum = "cf8e65f4839c26e6237fc0744911d79b0a2ac5e76b4e4eebd14db2b8d849fd31" dependencies = [ "anyhow", "cranelift-codegen", diff --git a/Cargo.toml b/Cargo.toml index 70c03da3f29..74f50808a98 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,12 +8,12 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.82.1", features = ["unwind", "all-arch"] } -cranelift-frontend = "0.82.1" -cranelift-module = "0.82.1" -cranelift-native = "0.82.1" -cranelift-jit = { version = "0.82.1", optional = true } -cranelift-object = "0.82.1" +cranelift-codegen = { version = "0.83.0", features = ["unwind", "all-arch"] } +cranelift-frontend = "0.83.0" +cranelift-module = "0.83.0" +cranelift-native = "0.83.0" +cranelift-jit = { version = "0.83.0", optional = true } +cranelift-object = "0.83.0" target-lexicon = "0.12.0" gimli = { version = "0.26.0", default-features = false, features = ["write"]} object = { version = "0.27.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } From f2cdd4a78d89c009342197cf5844a21f8aa813df Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 21 Apr 2022 20:54:50 +0200 Subject: [PATCH 22/22] Rustup to rustc 1.62.0-nightly (879aff385 2022-04-20) --- build_sysroot/Cargo.lock | 5 +++-- example/mini_core.rs | 13 ++++++++++--- example/mini_core_hello_world.rs | 4 ++-- rust-toolchain | 2 +- src/base.rs | 3 ++- src/discriminant.rs | 12 ++++++++++-- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 0d9ae67342e..51ba0dbfcc7 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -134,9 +134,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.121" +version = "0.2.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" +checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50" dependencies = [ "rustc-std-workspace-core", ] @@ -203,6 +203,7 @@ dependencies = [ name = "proc_macro" version = "0.0.0" dependencies = [ + "core", "std", ] diff --git a/example/mini_core.rs b/example/mini_core.rs index 956bed3ccd8..8da705e0cb0 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -494,13 +494,20 @@ pub trait Deref { fn deref(&self) -> &Self::Target; } +#[repr(transparent)] +#[rustc_layout_scalar_valid_range_start(1)] +#[rustc_nonnull_optimization_guaranteed] +pub struct NonNull(pub *mut T); + +impl CoerceUnsized> for NonNull where T: Unsize {} +impl DispatchFromDyn> for NonNull where T: Unsize {} + pub struct Unique { - pub pointer: *const T, + pub pointer: NonNull, pub _marker: PhantomData, } impl CoerceUnsized> for Unique where T: Unsize {} - impl DispatchFromDyn> for Unique where T: Unsize {} #[lang = "owned_box"] @@ -529,7 +536,7 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 { #[lang = "box_free"] unsafe fn box_free(ptr: Unique, alloc: ()) { - libc::free(ptr.pointer as *mut u8); + libc::free(ptr.pointer.0 as *mut u8); } #[lang = "drop"] diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index c4730581335..85ca908d0a2 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -122,7 +122,7 @@ fn call_return_u128_pair() { #[allow(unreachable_code)] // FIXME false positive fn main() { take_unique(Unique { - pointer: 0 as *const (), + pointer: unsafe { NonNull(1 as *mut ()) }, _marker: PhantomData, }); take_f32(0.1); @@ -173,7 +173,7 @@ fn main() { assert!(intrinsics::needs_drop::()); Unique { - pointer: 0 as *const &str, + pointer: NonNull(1 as *mut &str), _marker: PhantomData, } as Unique; diff --git a/rust-toolchain b/rust-toolchain index 763aceac2df..966097c248b 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-04-05" +channel = "nightly-2022-04-21" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/src/base.rs b/src/base.rs index 8c45993a8b7..65346cb3962 100644 --- a/src/base.rs +++ b/src/base.rs @@ -821,7 +821,8 @@ pub(crate) fn codegen_place<'tcx>( if cplace.layout().ty.is_box() { cplace = cplace .place_field(fx, Field::new(0)) // Box -> Unique - .place_field(fx, Field::new(0)) // Unique -> *const T + .place_field(fx, Field::new(0)) // Unique -> NonNull + .place_field(fx, Field::new(0)) // NonNull -> *mut T .place_deref(fx); } else { cplace = cplace.place_deref(fx); diff --git a/src/discriminant.rs b/src/discriminant.rs index 357cb4a6d24..f619bb5ed5e 100644 --- a/src/discriminant.rs +++ b/src/discriminant.rs @@ -128,8 +128,16 @@ pub(crate) fn codegen_get_discriminant<'tcx>( let relative_discr = if niche_start == 0 { tag } else { - // FIXME handle niche_start > i64::MAX - fx.bcx.ins().iadd_imm(tag, -i64::try_from(niche_start).unwrap()) + let niche_start = match fx.bcx.func.dfg.value_type(tag) { + types::I128 => { + let lsb = fx.bcx.ins().iconst(types::I64, niche_start as u64 as i64); + let msb = + fx.bcx.ins().iconst(types::I64, (niche_start >> 64) as u64 as i64); + fx.bcx.ins().iconcat(lsb, msb) + } + ty => fx.bcx.ins().iconst(ty, niche_start as i64), + }; + fx.bcx.ins().isub(tag, niche_start) }; let relative_max = niche_variants.end().as_u32() - niche_variants.start().as_u32(); let is_niche = {