From 32605d8b606def024d84af5bf7ae2141f30951ac Mon Sep 17 00:00:00 2001 From: sayantn Date: Thu, 5 Jun 2025 20:41:41 +0530 Subject: [PATCH 001/160] Implement `simd_round_ties_even` for miri, cg_clif and cg_gcc --- src/intrinsics/simd.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 46a441488fa6a..f928ad8bc021d 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -495,7 +495,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( | sym::simd_flog | sym::simd_flog10 | sym::simd_flog2 - | sym::simd_round => { + | sym::simd_round + | sym::simd_round_ties_even => { intrinsic_args!(fx, args => (a); intrinsic); if !a.layout().ty.is_simd() { @@ -526,6 +527,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( (sym::simd_flog2, types::F64) => "log2", (sym::simd_round, types::F32) => "roundf", (sym::simd_round, types::F64) => "round", + (sym::simd_round_ties_even, types::F32) => "rintf", + (sym::simd_round_ties_even, types::F64) => "rint", _ => unreachable!("{:?}", intrinsic), }; fx.lib_call( From aaea8ebdba45344e1f012b396d2e26b457261c1b Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 24 Jun 2025 09:00:20 +0000 Subject: [PATCH 002/160] Fix normalization in linker-warning Ensure rustc_codegen_cranelift doesn't get normalized to rustc. And handle -Cpanic=abort. --- scripts/test_rustc_tests.sh | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 32c71f433b0ff..7e356b4b462b2 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -151,20 +151,6 @@ rm tests/ui/process/process-panic-after-fork.rs # same cp ../dist/bin/rustdoc-clif ../dist/bin/rustdoc # some tests expect bin/rustdoc to exist cat < Date: Tue, 24 Jun 2025 11:32:02 +0000 Subject: [PATCH 003/160] Merge commit '8c848e0604b5d26fad120914f822f564fe05c52a' into sync_cg_clif-2025-06-24 --- Cargo.lock | 84 +++++++++++-------- Cargo.toml | 24 +++--- build_system/abi_cafe.rs | 8 +- .../0002-abi-cafe-Disable-broken-tests.patch | 69 --------------- rust-toolchain | 2 +- scripts/abi-cafe-rules.toml | 17 ++++ src/constant.rs | 2 +- src/intrinsics/llvm_x86.rs | 7 +- src/intrinsics/simd.rs | 7 +- 9 files changed, 95 insertions(+), 125 deletions(-) delete mode 100644 patches/0002-abi-cafe-Disable-broken-tests.patch create mode 100644 scripts/abi-cafe-rules.toml diff --git a/Cargo.lock b/Cargo.lock index a906bec8b7e23..b893a2be9a2cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,42 +43,42 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-assembler-x64" -version = "0.120.0" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ff8e35182c7372df00447cb90a04e584e032c42b9b9b6e8c50ddaaf0d7900d5" +checksum = "f6f53499803b1607b6ee0ba0de4ba036e6da700c2e489fe8f9d0f683d0b84d31" dependencies = [ "cranelift-assembler-x64-meta", ] [[package]] name = "cranelift-assembler-x64-meta" -version = "0.120.0" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14220f9c2698015c3b94dc6b84ae045c1c45509ddc406e43c6139252757fdb7a" +checksum = "1aadaa5bc8430d0e7bb999459369bedd0e5816ad4a82a0e20748341c4e333eda" dependencies = [ "cranelift-srcgen", ] [[package]] name = "cranelift-bforest" -version = "0.120.0" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d372ef2777ceefd75829e1390211ac240e9196bc60699218f7ea2419038288ee" +checksum = "2005fda2fc52a2dbce58229b4fb4483b70cbc806ba8ecc11b3f050c1a2d26cac" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-bitset" -version = "0.120.0" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56323783e423818fa89ce8078e90a3913d2a6e0810399bfce8ebd7ee87baa81f" +checksum = "56935e02452ca1249d39ad5c45a96304d0b4300a158a391fd113451e0cd4483d" [[package]] name = "cranelift-codegen" -version = "0.120.0" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74ffb780aab6186c6e9ba26519654b1ac55a09c0a866f6088a4efbbd84da68ed" +checksum = "62612786bf00e10999f50217d6f455d02b31591155881a45a903d1a95d1a4043" dependencies = [ "bumpalo", "cranelift-assembler-x64", @@ -97,13 +97,14 @@ dependencies = [ "serde", "smallvec", "target-lexicon", + "wasmtime-math", ] [[package]] name = "cranelift-codegen-meta" -version = "0.120.0" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c23ef13814d3b39c869650d5961128cbbecad83fbdff4e6836a03ecf6862d7ed" +checksum = "07bae789df91ef236079733af9df11d852256c64af196f0bc6471ea0f5f301be" dependencies = [ "cranelift-assembler-x64-meta", "cranelift-codegen-shared", @@ -112,33 +113,33 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" -version = "0.120.0" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f623300657679f847803ce80811454bfff89cea4f6bf684be5c468d4a73631" +checksum = "1be319616d36527782558a8312508757815f64deb19b094c7b8f4337229a9bc6" [[package]] name = "cranelift-control" -version = "0.120.0" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f4168af69989aa6b91fab46799ed4df6096f3209f4a6c8fb4358f49c60188f" +checksum = "8810ee1ab5e9bd5cff4c0c8d240e2009cb5c2b79888fde1d5256d605712314b7" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.120.0" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6fa9bae1c8de26d71ac2162f069447610fd91e7780cb480ee0d76ac81eabb8" +checksum = "086452c97cfbe116bf17dbe622dc5fdf2ea97299c7d4ce42460f284387c9928a" dependencies = [ "cranelift-bitset", ] [[package]] name = "cranelift-frontend" -version = "0.120.0" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8219205608aa0b0e6769b580284a7e055c7e0c323c1041cde7ca078add3e412" +checksum = "4c27947010ab759330f252610c17a8cd64d123358be4f33164233d04fcd77b80" dependencies = [ "cranelift-codegen", "log", @@ -148,15 +149,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.120.0" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "588d0c5964f10860b04043e55aab26d7f7a206b0fd4f10c5260e8aa5773832bd" +checksum = "ec67bfb8bd55b1e9760eb9f5186dca8d81bd4d86110f8d5af01154a044c91802" [[package]] name = "cranelift-jit" -version = "0.120.0" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56bd917ddc524f84f4066f954062875bdfc0dffea068ee94e906d98de5ac7c33" +checksum = "d67cdfc447f2abdb46bb30a6582cce189539c3c051c1d5330692376e1400edff" dependencies = [ "anyhow", "cranelift-codegen", @@ -174,9 +175,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.120.0" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a03c057d8a992e06596c871341e446af43ff9224f941e5b8adea39137a5391" +checksum = "e4597eaa52bca1ed111986c7a7f70cdbe192f83d271d627201365078e37b7e84" dependencies = [ "anyhow", "cranelift-codegen", @@ -185,9 +186,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.120.0" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19ed3c94cb97b14f92b6a94a1d45ef8c851f6a2ad9114e5d91d233f7da638fed" +checksum = "75a9b63edea46e013fce459c46e500462cb03a0490fdd9c18fe42b1dd7b93aa1" dependencies = [ "cranelift-codegen", "libc", @@ -196,9 +197,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.120.0" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a64dacef362a69375a604f6636e5e9a174fb96dba3b273646fcd9fa85c1d0997" +checksum = "ce706f0166d5b7f31693dff521e87cb9858e12adf22ffcde93c4a2826f8f04a9" dependencies = [ "anyhow", "cranelift-codegen", @@ -211,9 +212,9 @@ dependencies = [ [[package]] name = "cranelift-srcgen" -version = "0.120.0" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85256fac1519a7d25a040c1d850fba67478f3f021ad5fdf738ba4425ee862dbf" +checksum = "7d5870e266df8237b56cc98b04f5739c228565c92dd629ec6c66efa87271a158" [[package]] name = "crc32fast" @@ -288,6 +289,12 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "libm" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" + [[package]] name = "log" version = "0.4.22" @@ -446,9 +453,9 @@ checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "wasmtime-jit-icache-coherence" -version = "33.0.0" +version = "34.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "175e924dbc944c185808466d1e90b5a7feb610f3b9abdfe26f8ee25fd1086d1c" +checksum = "2eedc0324e37cf39b049f4dca0c30997eaab49f09006d5f4c1994e64e7b7dba8" dependencies = [ "anyhow", "cfg-if", @@ -456,6 +463,15 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "wasmtime-math" +version = "34.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd35fae4cf51d2b4a9bd2ef04b0eb309fa1849cab6a6ab5ac27cbd054ea284d" +dependencies = [ + "libm", +] + [[package]] name = "windows-sys" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index 94fcbd0a5023d..9066e4dbbb528 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.120.0", default-features = false, features = ["std", "timing", "unwind", "all-native-arch"] } -cranelift-frontend = { version = "0.120.0" } -cranelift-module = { version = "0.120.0" } -cranelift-native = { version = "0.120.0" } -cranelift-jit = { version = "0.120.0", optional = true } -cranelift-object = { version = "0.120.0" } +cranelift-codegen = { version = "0.121.0", default-features = false, features = ["std", "timing", "unwind", "all-native-arch"] } +cranelift-frontend = { version = "0.121.0" } +cranelift-module = { version = "0.121.0" } +cranelift-native = { version = "0.121.0" } +cranelift-jit = { version = "0.121.0", optional = true } +cranelift-object = { version = "0.121.0" } target-lexicon = "0.13" gimli = { version = "0.31", default-features = false, features = ["write"] } object = { version = "0.36", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } @@ -24,12 +24,12 @@ smallvec = "1.8.1" [patch.crates-io] # Uncomment to use an unreleased version of cranelift -#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-33.0.0", version = "0.120.0" } -#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-33.0.0", version = "0.120.0" } -#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-33.0.0", version = "0.120.0" } -#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-33.0.0", version = "0.120.0" } -#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-33.0.0", version = "0.120.0" } -#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-33.0.0", version = "0.120.0" } +#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-34.0.0", version = "0.121.0" } +#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-34.0.0", version = "0.121.0" } +#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-34.0.0", version = "0.121.0" } +#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-34.0.0", version = "0.121.0" } +#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-34.0.0", version = "0.121.0" } +#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-34.0.0", version = "0.121.0" } # Uncomment to use local checkout of cranelift #cranelift-codegen = { path = "../wasmtime/cranelift/codegen" } diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs index 674acfbd3097c..43025137bc6bb 100644 --- a/build_system/abi_cafe.rs +++ b/build_system/abi_cafe.rs @@ -6,8 +6,8 @@ use crate::{CodegenBackend, SysrootKind, build_sysroot}; static ABI_CAFE_REPO: GitRepo = GitRepo::github( "Gankra", "abi-cafe", - "f1220cfd13b57f5c0082c26529163865ee25e115", - "fe93a9acd461425d", + "94d38030419eb00a1ba80e5e2b4d763dcee58db4", + "6efb4457893c8670", "abi-cafe", ); @@ -46,6 +46,10 @@ pub(crate) fn run( let mut cmd = ABI_CAFE.run(bootstrap_host_compiler, dirs); cmd.arg("--"); + cmd.arg("--debug"); + + cmd.arg("--rules").arg(dirs.source_dir.join("scripts/abi-cafe-rules.toml")); + // stdcall, vectorcall and such don't work yet cmd.arg("--conventions").arg("c").arg("--conventions").arg("rust"); diff --git a/patches/0002-abi-cafe-Disable-broken-tests.patch b/patches/0002-abi-cafe-Disable-broken-tests.patch deleted file mode 100644 index 01b6a990b7202..0000000000000 --- a/patches/0002-abi-cafe-Disable-broken-tests.patch +++ /dev/null @@ -1,69 +0,0 @@ -From 236df390f3bc4ed69c26f4d51d584bea246da886 Mon Sep 17 00:00:00 2001 -From: bjorn3 <17426603+bjorn3@users.noreply.github.com> -Date: Tue, 9 Jul 2024 11:25:14 +0000 -Subject: [PATCH] Disable broken tests - ---- - src/report.rs | 36 ++++++++++++++++++++++++++++++++++++ - 1 file changed, 36 insertions(+) - -diff --git a/src/toolchains/rust.rs b/src/toolchains/rust.rs -index 0c50f7a..bfde2b1 100644 ---- a/src/toolchains/rust.rs -+++ b/src/toolchains/rust.rs -@@ -83,6 +83,7 @@ impl Toolchain for RustcToolchain { - .arg(out_dir) - .arg("--target") - .arg(built_info::TARGET) -+ .arg("-g") - .arg(format!("-Cmetadata={lib_name}")) - .arg(src_path); - if let Some(codegen_backend) = &self.codegen_backend { -diff --git a/src/report.rs b/src/report.rs -index 958ab43..dcf1044 100644 ---- a/src/report.rs -+++ b/src/report.rs -@@ -48,6 +48,40 @@ pub fn get_test_rules(test: &TestKey, caller: &dyn Toolchain, callee: &dyn Toolc - // - // THIS AREA RESERVED FOR VENDORS TO APPLY PATCHES - -+ if cfg!(all(target_arch = "aarch64", target_os = "linux")) { -+ if test.test == "F32Array" && test.options.convention == CallingConvention::C { -+ result.check = Busted(Check); -+ } -+ } -+ -+ if cfg!(all(target_arch = "aarch64", target_os = "macos")) { -+ if test.test == "SingleVariantUnion" && test.options.convention == CallingConvention::C && test.options.repr == LangRepr::C { -+ result.check = Busted(Check); -+ } -+ -+ if test.test == "OptionU128" && test.caller == "rustc" && test.options.convention == CallingConvention::Rust && test.options.repr == LangRepr::C { -+ result.check = Busted(Run); -+ } -+ -+ if test.test == "OptionU128" && test.caller == "cgclif" && test.options.convention == CallingConvention::Rust && test.options.repr == LangRepr::C { -+ result.check = Busted(Check); -+ } -+ } -+ -+ if cfg!(all(target_arch = "x86_64", windows)) { -+ if test.test == "simple" && test.options.convention == CallingConvention::Rust { -+ result.check = Busted(Check); -+ } -+ -+ if test.test == "simple" && test.options.convention == CallingConvention::Rust && test.caller == "rustc" { -+ result.check = Busted(Run); -+ } -+ } -+ -+ if test.test == "f16" || test.test == "f128" { -+ result.run = Skip; -+ } -+ - // END OF VENDOR RESERVED AREA - // - // --- -2.34.1 - diff --git a/rust-toolchain b/rust-toolchain index af4bd6dc6b851..150bb562f74a7 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-05-25" +channel = "nightly-2025-06-24" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" diff --git a/scripts/abi-cafe-rules.toml b/scripts/abi-cafe-rules.toml new file mode 100644 index 0000000000000..54f9445c8e524 --- /dev/null +++ b/scripts/abi-cafe-rules.toml @@ -0,0 +1,17 @@ +[target.'cfg(all(target_arch = "aarch64", target_os = "linux"))'] +'F32Array::conv_c'.busted = "check" + +[target.'cfg(all(target_arch = "aarch64", target_os = "macos"))'] +'SingleVariantUnion::conv_c::repr_c'.busted = "check" +'OptionU128::conv_rust::repr_c::rustc_caller'.busted = "run" +'OptionU128::conv_rust::repr_c::cgclif_caller'.busted = "check" + +[target.'cfg(all(target_arch = "x86_64", windows))'] +'simple::conv_rust'.busted = "check" +'simple::conv_rust::rustc_caller'.busted = "run" + +[target.'*'.'f16'] +run = "skip" + +[target.'*'.'f128'] +run = "skip" diff --git a/src/constant.rs b/src/constant.rs index c8527c3a57dfe..3a62cd52a9d94 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -228,7 +228,7 @@ fn pointer_for_allocation<'tcx>( crate::pointer::Pointer::new(global_ptr) } -pub(crate) fn data_id_for_alloc_id( +fn data_id_for_alloc_id( cx: &mut ConstantCx, module: &mut dyn Module, alloc_id: AllocId, diff --git a/src/intrinsics/llvm_x86.rs b/src/intrinsics/llvm_x86.rs index 615f6c47d902f..37fbe4be1b0fe 100644 --- a/src/intrinsics/llvm_x86.rs +++ b/src/intrinsics/llvm_x86.rs @@ -202,9 +202,10 @@ pub(super) fn codegen_x86_llvm_intrinsic_call<'tcx>( }; let x = codegen_operand(fx, &x.node); let y = codegen_operand(fx, &y.node); - let kind = match &kind.node { - Operand::Constant(const_) => crate::constant::eval_mir_constant(fx, const_).0, - Operand::Copy(_) | Operand::Move(_) => unreachable!("{kind:?}"), + let kind = if let Some(const_) = kind.node.constant() { + crate::constant::eval_mir_constant(fx, const_).0 + } else { + unreachable!("{kind:?}") }; let flt_cc = match kind diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 46a441488fa6a..68ff0b622c8fb 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -205,9 +205,10 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( // Find a way to reuse `immediate_const_vector` from `codegen_ssa` instead. let indexes = { use rustc_middle::mir::interpret::*; - let idx_const = match &idx.node { - Operand::Constant(const_) => crate::constant::eval_mir_constant(fx, const_).0, - Operand::Copy(_) | Operand::Move(_) => unreachable!("{idx:?}"), + let idx_const = if let Some(const_) = idx.node.constant() { + crate::constant::eval_mir_constant(fx, const_).0 + } else { + unreachable!("{idx:?}") }; let idx_bytes = match idx_const { From d0ee10d2f8603c847ea0be0fbb186af281e9714d Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 26 Jun 2025 10:16:27 +0000 Subject: [PATCH 004/160] Rustup to rustc 1.90.0-nightly (0fa4ec6cd 2025-06-25) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 150bb562f74a7..57b45c7706b18 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-06-24" +channel = "nightly-2025-06-26" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 8bf928a2e56b3d1a930973d5c97b031ea9e7803c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 24 Jun 2025 14:00:26 +0200 Subject: [PATCH 005/160] Move inline_asm_index from CodegenCx to FunctionCx --- src/base.rs | 1 + src/common.rs | 2 ++ src/inline_asm.rs | 14 ++++++++------ src/lib.rs | 2 -- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/base.rs b/src/base.rs index 0b641ba64b7a4..c6352ba6112fd 100644 --- a/src/base.rs +++ b/src/base.rs @@ -104,6 +104,7 @@ pub(crate) fn codegen_fn<'tcx>( clif_comments, next_ssa_var: 0, + inline_asm_index: 0, }; tcx.prof.generic_activity("codegen clif ir").run(|| codegen_fn_body(&mut fx, start_block)); diff --git a/src/common.rs b/src/common.rs index 2f11b2d2dcc1a..5a342a3fe989d 100644 --- a/src/common.rs +++ b/src/common.rs @@ -292,6 +292,8 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> { /// This should only be accessed by `CPlace::new_var`. pub(crate) next_ssa_var: u32, + + pub(crate) inline_asm_index: u32, } impl<'tcx> LayoutOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> { diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 120d6ff9e38e0..b4aa0651a6b86 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -103,11 +103,12 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>( // be exported from the main codegen unit and may thus be unreachable from the // object file created by an external assembler. let wrapper_name = format!( - "__inline_asm_{}_wrapper_n{}", + "{}__inline_asm_{}_wrapper_n{}", + fx.symbol_name, fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"), - fx.cx.inline_asm_index + fx.inline_asm_index, ); - fx.cx.inline_asm_index += 1; + fx.inline_asm_index += 1; let sig = get_function_sig(fx.tcx, fx.target_config.default_call_conv, instance); create_wrapper_function(fx.module, sig, &wrapper_name, symbol.name); @@ -166,11 +167,12 @@ pub(crate) fn codegen_inline_asm_inner<'tcx>( asm_gen.allocate_stack_slots(); let asm_name = format!( - "__inline_asm_{}_n{}", + "{}__inline_asm_{}_n{}", + fx.symbol_name, fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"), - fx.cx.inline_asm_index + fx.inline_asm_index, ); - fx.cx.inline_asm_index += 1; + fx.inline_asm_index += 1; let generated_asm = asm_gen.generate_asm_wrapper(&asm_name); fx.cx.global_asm.push_str(&generated_asm); diff --git a/src/lib.rs b/src/lib.rs index 8e34436fb5e0a..d3aa9c532243f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -129,7 +129,6 @@ struct CodegenCx { invocation_temp: Option, should_write_ir: bool, global_asm: String, - inline_asm_index: usize, debug_context: Option, cgu_name: Symbol, } @@ -148,7 +147,6 @@ impl CodegenCx { invocation_temp: tcx.sess.invocation_temp.clone(), should_write_ir: crate::pretty_clif::should_write_ir(tcx), global_asm: String::new(), - inline_asm_index: 0, debug_context, cgu_name, } From 9ead1c10aac15e748fb3ae30111fc54cdadac460 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 24 Jun 2025 14:02:11 +0200 Subject: [PATCH 006/160] Move invocation_temp out of CodegenCx --- src/driver/aot.rs | 5 +++-- src/lib.rs | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 442151fe32de8..b3f91fc84b0ee 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -593,6 +593,7 @@ fn module_codegen( let producer = crate::debuginfo::producer(tcx.sess); let profiler = tcx.prof.clone(); + let invocation_temp = tcx.sess.invocation_temp.clone(); OngoingModuleCodegen::Async(std::thread::spawn(move || { profiler.clone().generic_activity_with_arg("compile functions", &*cgu_name).run(|| { @@ -618,7 +619,7 @@ fn module_codegen( &global_asm_config, &cgu_name, &cx.global_asm, - cx.invocation_temp.as_deref(), + invocation_temp.as_deref(), ) })?; @@ -626,7 +627,7 @@ fn module_codegen( profiler.generic_activity_with_arg("write object file", &*cgu_name).run(|| { emit_cgu( &global_asm_config.output_filenames, - cx.invocation_temp.as_deref(), + invocation_temp.as_deref(), &profiler, cgu_name, module, diff --git a/src/lib.rs b/src/lib.rs index d3aa9c532243f..39bfeb1bf3031 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -126,7 +126,6 @@ impl String> Drop for PrintOnPanic { /// inside a single codegen unit with the exception of the Cranelift [`Module`](cranelift_module::Module). struct CodegenCx { output_filenames: Arc, - invocation_temp: Option, should_write_ir: bool, global_asm: String, debug_context: Option, @@ -144,7 +143,6 @@ impl CodegenCx { }; CodegenCx { output_filenames: tcx.output_filenames(()).clone(), - invocation_temp: tcx.sess.invocation_temp.clone(), should_write_ir: crate::pretty_clif::should_write_ir(tcx), global_asm: String::new(), debug_context, From 23110bdf763142b1c3ecd688ce95bf819f2da461 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 24 Jun 2025 14:13:53 +0200 Subject: [PATCH 007/160] Remove output_filenames from CodegenCx --- src/base.rs | 6 ++++-- src/driver/aot.rs | 2 ++ src/driver/jit.rs | 13 ++++++++++++- src/lib.rs | 2 -- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/base.rs b/src/base.rs index c6352ba6112fd..57009b4ff8eb5 100644 --- a/src/base.rs +++ b/src/base.rs @@ -12,6 +12,7 @@ use rustc_middle::ty::TypeVisitableExt; use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv}; use rustc_middle::ty::print::with_no_trimmed_paths; +use rustc_session::config::OutputFilenames; use crate::constant::ConstantCx; use crate::debuginfo::{FunctionDebugContext, TypeDebugContext}; @@ -138,6 +139,7 @@ pub(crate) fn codegen_fn<'tcx>( pub(crate) fn compile_fn( cx: &mut crate::CodegenCx, profiler: &SelfProfilerRef, + output_filenames: &OutputFilenames, cached_context: &mut Context, module: &mut dyn Module, codegened_func: CodegenedFunction, @@ -215,7 +217,7 @@ pub(crate) fn compile_fn( if cx.should_write_ir { // Write optimized function to file for debugging crate::pretty_clif::write_clif_file( - &cx.output_filenames, + output_filenames, &codegened_func.symbol_name, "opt", module.isa(), @@ -225,7 +227,7 @@ pub(crate) fn compile_fn( if let Some(disasm) = &context.compiled_code().unwrap().vcode { crate::pretty_clif::write_ir_file( - &cx.output_filenames, + output_filenames, &format!("{}.vcode", codegened_func.symbol_name), |file| file.write_all(disasm.as_bytes()), ) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index b3f91fc84b0ee..d2337c0059b8a 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -594,6 +594,7 @@ fn module_codegen( let profiler = tcx.prof.clone(); let invocation_temp = tcx.sess.invocation_temp.clone(); + let output_filenames = tcx.output_filenames(()).clone(); OngoingModuleCodegen::Async(std::thread::spawn(move || { profiler.clone().generic_activity_with_arg("compile functions", &*cgu_name).run(|| { @@ -606,6 +607,7 @@ fn module_codegen( crate::base::compile_fn( &mut cx, &profiler, + &output_filenames, &mut cached_context, &mut module, codegened_func, diff --git a/src/driver/jit.rs b/src/driver/jit.rs index b1f185b551c3c..52551d7c07679 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -9,6 +9,7 @@ use rustc_codegen_ssa::CrateInfo; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::mono::MonoItem; use rustc_session::Session; +use rustc_session::config::OutputFilenames; use rustc_span::sym; use crate::CodegenCx; @@ -41,6 +42,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec) -> ! { tcx.dcx().fatal("can't jit non-executable crate"); } + let output_filenames = tcx.output_filenames(()); let (mut jit_module, mut cx) = create_jit_module(tcx); let mut cached_context = Context::new(); @@ -60,6 +62,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec) -> ! { MonoItem::Fn(inst) => { codegen_and_compile_fn( tcx, + &output_filenames, &mut cx, &mut cached_context, &mut jit_module, @@ -122,6 +125,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec) -> ! { fn codegen_and_compile_fn<'tcx>( tcx: TyCtxt<'tcx>, + output_filenames: &OutputFilenames, cx: &mut crate::CodegenCx, cached_context: &mut Context, module: &mut dyn Module, @@ -149,7 +153,14 @@ fn codegen_and_compile_fn<'tcx>( module, instance, ); - crate::base::compile_fn(cx, &tcx.prof, cached_context, module, codegened_func); + crate::base::compile_fn( + cx, + &tcx.prof, + output_filenames, + cached_context, + module, + codegened_func, + ); }); } diff --git a/src/lib.rs b/src/lib.rs index 39bfeb1bf3031..3e4351f660bb5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -125,7 +125,6 @@ impl String> Drop for PrintOnPanic { /// The codegen context holds any information shared between the codegen of individual functions /// inside a single codegen unit with the exception of the Cranelift [`Module`](cranelift_module::Module). struct CodegenCx { - output_filenames: Arc, should_write_ir: bool, global_asm: String, debug_context: Option, @@ -142,7 +141,6 @@ impl CodegenCx { None }; CodegenCx { - output_filenames: tcx.output_filenames(()).clone(), should_write_ir: crate::pretty_clif::should_write_ir(tcx), global_asm: String::new(), debug_context, From 4042f4026617ed7bc5dffdb999a34848d409f3d6 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 24 Jun 2025 14:28:08 +0200 Subject: [PATCH 008/160] Remove global_asm from CodegenCx --- src/base.rs | 7 ++++++- src/common.rs | 1 + src/driver/aot.rs | 15 +++++++++------ src/driver/jit.rs | 10 ++++++---- src/global_asm.rs | 2 +- src/inline_asm.rs | 2 +- src/lib.rs | 2 -- 7 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/base.rs b/src/base.rs index 57009b4ff8eb5..7f799b5730b44 100644 --- a/src/base.rs +++ b/src/base.rs @@ -26,6 +26,7 @@ pub(crate) struct CodegenedFunction { func: Function, clif_comments: CommentWriter, func_debug_cx: Option, + inline_asm: String, } pub(crate) fn codegen_fn<'tcx>( @@ -105,6 +106,7 @@ pub(crate) fn codegen_fn<'tcx>( clif_comments, next_ssa_var: 0, + inline_asm: String::new(), inline_asm_index: 0, }; @@ -116,6 +118,7 @@ pub(crate) fn codegen_fn<'tcx>( let symbol_name = fx.symbol_name; let clif_comments = fx.clif_comments; let func_debug_cx = fx.func_debug_cx; + let inline_asm = fx.inline_asm; fx.constants_cx.finalize(fx.tcx, &mut *fx.module); @@ -133,7 +136,7 @@ pub(crate) fn codegen_fn<'tcx>( // Verify function verify_func(tcx, &clif_comments, &func); - CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx } + CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx, inline_asm } } pub(crate) fn compile_fn( @@ -142,12 +145,14 @@ pub(crate) fn compile_fn( output_filenames: &OutputFilenames, cached_context: &mut Context, module: &mut dyn Module, + global_asm: &mut String, codegened_func: CodegenedFunction, ) { let _timer = profiler.generic_activity_with_arg("compile function", &*codegened_func.symbol_name); let clif_comments = codegened_func.clif_comments; + global_asm.push_str(&codegened_func.inline_asm); // Store function in context let context = cached_context; diff --git a/src/common.rs b/src/common.rs index 5a342a3fe989d..b47b2a4ee4a58 100644 --- a/src/common.rs +++ b/src/common.rs @@ -293,6 +293,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> { /// This should only be accessed by `CPlace::new_var`. pub(crate) next_ssa_var: u32, + pub(crate) inline_asm: String, pub(crate) inline_asm_index: u32, } diff --git a/src/driver/aot.rs b/src/driver/aot.rs index d2337c0059b8a..9e793fc52545a 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -512,7 +512,7 @@ fn codegen_cgu_content( tcx: TyCtxt<'_>, module: &mut dyn Module, cgu_name: rustc_span::Symbol, -) -> (CodegenCx, Vec) { +) -> (CodegenCx, Vec, String) { let _timer = tcx.prof.generic_activity_with_arg("codegen cgu", cgu_name.as_str()); let cgu = tcx.codegen_unit(cgu_name); @@ -524,6 +524,7 @@ fn codegen_cgu_content( tcx.sess.opts.debuginfo != DebugInfo::None, cgu_name, ); + let mut global_asm = String::new(); let mut type_dbg = TypeDebugContext::default(); super::predefine_mono_items(tcx, module, &mono_items); let mut codegened_functions = vec![]; @@ -533,7 +534,7 @@ fn codegen_cgu_content( if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED) { rustc_codegen_ssa::mir::naked_asm::codegen_naked_asm( - &mut GlobalAsmContext { tcx, global_asm: &mut cx.global_asm }, + &mut GlobalAsmContext { tcx, global_asm: &mut global_asm }, instance, MonoItemData { linkage: RLinkage::External, @@ -565,7 +566,7 @@ fn codegen_cgu_content( } MonoItem::GlobalAsm(item_id) => { rustc_codegen_ssa::base::codegen_global_asm( - &mut GlobalAsmContext { tcx, global_asm: &mut cx.global_asm }, + &mut GlobalAsmContext { tcx, global_asm: &mut global_asm }, item_id, ); } @@ -573,7 +574,7 @@ fn codegen_cgu_content( } crate::main_shim::maybe_create_entry_wrapper(tcx, module, false, cgu.is_primary()); - (cx, codegened_functions) + (cx, codegened_functions, global_asm) } fn module_codegen( @@ -586,7 +587,8 @@ fn module_codegen( ) -> OngoingModuleCodegen { let mut module = make_module(tcx.sess, cgu_name.as_str().to_string()); - let (mut cx, codegened_functions) = codegen_cgu_content(tcx, &mut module, cgu_name); + let (mut cx, codegened_functions, mut global_asm) = + codegen_cgu_content(tcx, &mut module, cgu_name); let cgu_name = cgu_name.as_str().to_owned(); @@ -610,6 +612,7 @@ fn module_codegen( &output_filenames, &mut cached_context, &mut module, + &mut global_asm, codegened_func, ); } @@ -620,7 +623,7 @@ fn module_codegen( crate::global_asm::compile_global_asm( &global_asm_config, &cgu_name, - &cx.global_asm, + global_asm, invocation_temp.as_deref(), ) })?; diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 52551d7c07679..ab1544e62b0a3 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -80,10 +80,6 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec) -> ! { } }); - if !cx.global_asm.is_empty() { - tcx.dcx().fatal("Inline asm is not supported in JIT mode"); - } - crate::main_shim::maybe_create_entry_wrapper(tcx, &mut jit_module, true, true); tcx.dcx().abort_if_errors(); @@ -153,14 +149,20 @@ fn codegen_and_compile_fn<'tcx>( module, instance, ); + + let mut global_asm = String::new(); crate::base::compile_fn( cx, &tcx.prof, output_filenames, cached_context, module, + &mut global_asm, codegened_func, ); + if !global_asm.is_empty() { + tcx.dcx().fatal("Inline asm is not supported in JIT mode"); + } }); } diff --git a/src/global_asm.rs b/src/global_asm.rs index 203b443269fa7..db40d84be0aa5 100644 --- a/src/global_asm.rs +++ b/src/global_asm.rs @@ -168,7 +168,7 @@ impl GlobalAsmConfig { pub(crate) fn compile_global_asm( config: &GlobalAsmConfig, cgu_name: &str, - global_asm: &str, + global_asm: String, invocation_temp: Option<&str>, ) -> Result, String> { if global_asm.is_empty() { diff --git a/src/inline_asm.rs b/src/inline_asm.rs index b4aa0651a6b86..832f24b38bce4 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -175,7 +175,7 @@ pub(crate) fn codegen_inline_asm_inner<'tcx>( fx.inline_asm_index += 1; let generated_asm = asm_gen.generate_asm_wrapper(&asm_name); - fx.cx.global_asm.push_str(&generated_asm); + fx.inline_asm.push_str(&generated_asm); let mut inputs = Vec::new(); let mut outputs = Vec::new(); diff --git a/src/lib.rs b/src/lib.rs index 3e4351f660bb5..a5ec796c1c2da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -126,7 +126,6 @@ impl String> Drop for PrintOnPanic { /// inside a single codegen unit with the exception of the Cranelift [`Module`](cranelift_module::Module). struct CodegenCx { should_write_ir: bool, - global_asm: String, debug_context: Option, cgu_name: Symbol, } @@ -142,7 +141,6 @@ impl CodegenCx { }; CodegenCx { should_write_ir: crate::pretty_clif::should_write_ir(tcx), - global_asm: String::new(), debug_context, cgu_name, } From b2cafc96ec61a2bfa43caf1ef68be0cc348e9140 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 24 Jun 2025 15:47:17 +0200 Subject: [PATCH 009/160] Use ConstantCx for defining anonymous strings As opposed to directly defining them in the module. --- src/base.rs | 2 +- src/common.rs | 15 --------------- src/constant.rs | 18 ++++++++++-------- src/lib.rs | 1 + 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/base.rs b/src/base.rs index 7f799b5730b44..d79cf5aa58425 100644 --- a/src/base.rs +++ b/src/base.rs @@ -1084,7 +1084,7 @@ pub(crate) fn codegen_panic_nounwind<'tcx>( msg_str: &str, span: Span, ) { - let msg_ptr = fx.anonymous_str(msg_str); + let msg_ptr = crate::constant::pointer_for_anonymous_str(fx, msg_str); let msg_len = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(msg_str.len()).unwrap()); let args = [msg_ptr, msg_len]; diff --git a/src/common.rs b/src/common.rs index b47b2a4ee4a58..80b1f0881347c 100644 --- a/src/common.rs +++ b/src/common.rs @@ -420,21 +420,6 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { crate::constant::codegen_const_value(self, const_loc, self.tcx.caller_location_ty()) }) } - - pub(crate) fn anonymous_str(&mut self, msg: &str) -> Value { - let mut data = DataDescription::new(); - data.define(msg.as_bytes().to_vec().into_boxed_slice()); - let msg_id = self.module.declare_anonymous_data(false, false).unwrap(); - - // Ignore DuplicateDefinition error, as the data will be the same - let _ = self.module.define_data(msg_id, &data); - - let local_msg_id = self.module.declare_data_in_func(msg_id, self.bcx.func); - if self.clif_comments.enabled() { - self.add_comment(local_msg_id, msg); - } - self.bcx.ins().global_value(self.pointer_type, local_msg_id) - } } pub(crate) struct FullyMonomorphizedLayoutCx<'tcx>(pub(crate) TyCtxt<'tcx>); diff --git a/src/constant.rs b/src/constant.rs index 3a62cd52a9d94..ff2c0d577bb48 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -3,6 +3,7 @@ use std::cmp::Ordering; use cranelift_module::*; +use rustc_const_eval::interpret::CTFE_ALLOC_SALT; use rustc_data_structures::fx::FxHashSet; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::interpret::{AllocId, GlobalAlloc, Scalar, read_target_uint}; @@ -199,23 +200,20 @@ pub(crate) fn codegen_const_value<'tcx>( } }, ConstValue::Indirect { alloc_id, offset } => CValue::by_ref( - pointer_for_allocation(fx, alloc_id) + Pointer::new(pointer_for_allocation(fx, alloc_id)) .offset_i64(fx, i64::try_from(offset.bytes()).unwrap()), layout, ), ConstValue::Slice { data, meta } => { let alloc_id = fx.tcx.reserve_and_set_memory_alloc(data); - let ptr = pointer_for_allocation(fx, alloc_id).get_addr(fx); + let ptr = pointer_for_allocation(fx, alloc_id); let len = fx.bcx.ins().iconst(fx.pointer_type, meta as i64); CValue::by_val_pair(ptr, len, layout) } } } -fn pointer_for_allocation<'tcx>( - fx: &mut FunctionCx<'_, '_, 'tcx>, - alloc_id: AllocId, -) -> crate::pointer::Pointer { +fn pointer_for_allocation<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, alloc_id: AllocId) -> Value { let alloc = fx.tcx.global_alloc(alloc_id).unwrap_memory(); let data_id = data_id_for_alloc_id(&mut fx.constants_cx, fx.module, alloc_id, alloc.inner().mutability); @@ -224,8 +222,7 @@ fn pointer_for_allocation<'tcx>( if fx.clif_comments.enabled() { fx.add_comment(local_data_id, format!("{:?}", alloc_id)); } - let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id); - crate::pointer::Pointer::new(global_ptr) + fx.bcx.ins().global_value(fx.pointer_type, local_data_id) } fn data_id_for_alloc_id( @@ -251,6 +248,11 @@ pub(crate) fn data_id_for_vtable<'tcx>( data_id_for_alloc_id(cx, module, alloc_id, Mutability::Not) } +pub(crate) fn pointer_for_anonymous_str(fx: &mut FunctionCx<'_, '_, '_>, msg: &str) -> Value { + let alloc_id = fx.tcx.allocate_bytes_dedup(msg.as_bytes(), CTFE_ALLOC_SALT); + pointer_for_allocation(fx, alloc_id) +} + fn data_id_for_static( tcx: TyCtxt<'_>, module: &mut dyn Module, diff --git a/src/lib.rs b/src/lib.rs index a5ec796c1c2da..678580a237239 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,7 @@ extern crate rustc_middle; extern crate rustc_abi; extern crate rustc_ast; extern crate rustc_codegen_ssa; +extern crate rustc_const_eval; extern crate rustc_data_structures; extern crate rustc_errors; extern crate rustc_fs_util; From ac8ce3e3be305fae748fa7e2c98b4bfaa3f1dd88 Mon Sep 17 00:00:00 2001 From: Bastian Kersting Date: Thu, 15 May 2025 19:09:13 +0000 Subject: [PATCH 010/160] Insert checks for enum discriminants when debug assertions are enabled Similar to the existing nullpointer and alignment checks, this checks for valid enum discriminants on creation of enums through unsafe transmutes. Essentially this sanitizes patterns like the following: ```rust let val: MyEnum = unsafe { std::mem::transmute(42) }; ``` An extension of this check will be done in a follow-up that explicitly sanitizes for extern enum values that come into Rust from e.g. C/C++. This check is similar to Miri's capabilities of checking for valid construction of enum values. This PR is inspired by saethlin@'s PR https://github.com/rust-lang/rust/pull/104862. Thank you so much for keeping this code up and the detailed comments! I also pair-programmed large parts of this together with vabr-g@. --- src/base.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/base.rs b/src/base.rs index 0b641ba64b7a4..1b68c6535da5f 100644 --- a/src/base.rs +++ b/src/base.rs @@ -407,6 +407,18 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { source_info.span, ) } + AssertKind::InvalidEnumConstruction(source) => { + let source = codegen_operand(fx, source).load_scalar(fx); + let location = fx.get_caller_location(source_info).load_scalar(fx); + + codegen_panic_inner( + fx, + rustc_hir::LangItem::PanicInvalidEnumConstruction, + &[source, location], + *unwind, + source_info.span, + ) + } _ => { let location = fx.get_caller_location(source_info).load_scalar(fx); From 0bd5a21843eea25a77fd191539caae3d20d67308 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 28 Jun 2025 15:20:33 +0200 Subject: [PATCH 011/160] give Pointer::into_parts a more scary name and offer a safer alternative --- src/constant.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constant.rs b/src/constant.rs index 3a62cd52a9d94..ee43eb736e651 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -133,7 +133,7 @@ pub(crate) fn codegen_const_value<'tcx>( } } Scalar::Ptr(ptr, _size) => { - let (prov, offset) = ptr.into_parts(); // we know the `offset` is relative + let (prov, offset) = ptr.prov_and_relative_offset(); let alloc_id = prov.alloc_id(); let base_addr = match fx.tcx.global_alloc(alloc_id) { GlobalAlloc::Memory(alloc) => { From 95281ed1c16a994d5d3f69c3dbbfd5203fb15b6f Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Sat, 21 Jun 2025 11:26:27 +0000 Subject: [PATCH 012/160] Stop backends from needing to support nullary intrinsics --- example/mini_core.rs | 2 +- example/mini_core_hello_world.rs | 23 ++++++++++++++++++----- src/intrinsics/mod.rs | 15 --------------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/example/mini_core.rs b/example/mini_core.rs index 524ebde1c743f..2f53bbf8b7934 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -660,7 +660,7 @@ pub mod intrinsics { #[rustc_intrinsic] pub unsafe fn ctlz_nonzero(x: T) -> u32; #[rustc_intrinsic] - pub fn needs_drop() -> bool; + pub const fn needs_drop() -> bool; #[rustc_intrinsic] pub fn bitreverse(x: T) -> T; #[rustc_intrinsic] diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 1499f948deb3c..246bd3104ec41 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -1,4 +1,13 @@ -#![feature(no_core, lang_items, never_type, linkage, extern_types, thread_local, repr_simd)] +#![feature( + no_core, + lang_items, + never_type, + linkage, + extern_types, + thread_local, + repr_simd, + rustc_private +)] #![no_core] #![allow(dead_code, non_camel_case_types, internal_features)] @@ -207,10 +216,14 @@ fn main() { assert_eq!(intrinsics::align_of::() as u8, 2); assert_eq!(intrinsics::align_of_val(&a) as u8, intrinsics::align_of::<&str>() as u8); - assert!(!intrinsics::needs_drop::()); - assert!(!intrinsics::needs_drop::<[u8]>()); - assert!(intrinsics::needs_drop::()); - assert!(intrinsics::needs_drop::()); + let u8_needs_drop = const { intrinsics::needs_drop::() }; + assert!(!u8_needs_drop); + let slice_needs_drop = const { intrinsics::needs_drop::<[u8]>() }; + assert!(!slice_needs_drop); + let noisy_drop = const { intrinsics::needs_drop::() }; + assert!(noisy_drop); + let noisy_unsized_drop = const { intrinsics::needs_drop::() }; + assert!(noisy_unsized_drop); Unique { pointer: NonNull(1 as *mut &str), _marker: PhantomData } as Unique; diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index df5748c34d110..4ff5773a06cb2 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -812,21 +812,6 @@ fn codegen_regular_intrinsic_call<'tcx>( dest.write_cvalue(fx, val); } - sym::needs_drop | sym::type_id | sym::type_name | sym::variant_count => { - intrinsic_args!(fx, args => (); intrinsic); - - let const_val = fx - .tcx - .const_eval_instance( - ty::TypingEnv::fully_monomorphized(), - instance, - source_info.span, - ) - .unwrap(); - let val = crate::constant::codegen_const_value(fx, const_val, ret.layout().ty); - ret.write_cvalue(fx, val); - } - sym::ptr_offset_from | sym::ptr_offset_from_unsigned => { intrinsic_args!(fx, args => (ptr, base); intrinsic); let ptr = ptr.load_scalar(fx); From ede659174d95d1c2b65aa1d97fc1b907b6d82ba9 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 9 Apr 2025 13:35:35 +0000 Subject: [PATCH 013/160] Implement exception handling support --- src/abi/mod.rs | 179 +++++++++++++++++--- src/base.rs | 47 ++++-- src/common.rs | 5 +- src/debuginfo/gcc_except_table.rs | 272 ++++++++++++++++++++++++++++++ src/debuginfo/mod.rs | 3 +- src/debuginfo/unwind.rs | 160 +++++++++++++++++- src/inline_asm.rs | 1 + src/intrinsics/mod.rs | 66 +++++++- 8 files changed, 675 insertions(+), 58 deletions(-) create mode 100644 src/debuginfo/gcc_except_table.rs diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 4c6fd90781543..fea4e73b18e39 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -7,7 +7,7 @@ mod returning; use std::borrow::Cow; use std::mem; -use cranelift_codegen::ir::{ArgumentPurpose, SigRef}; +use cranelift_codegen::ir::{ArgumentPurpose, BlockArg, ExceptionTableData, ExceptionTag, SigRef}; use cranelift_codegen::isa::CallConv; use cranelift_module::ModuleError; use rustc_abi::{CanonAbi, ExternAbi, X86Call}; @@ -20,10 +20,12 @@ use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_session::Session; use rustc_span::source_map::Spanned; use rustc_target::callconv::{FnAbi, PassMode}; -use smallvec::SmallVec; +use smallvec::{SmallVec, smallvec}; use self::pass_mode::*; pub(crate) use self::returning::codegen_return; +use crate::base::codegen_unwind_terminate; +use crate::debuginfo::EXCEPTION_HANDLER_CLEANUP; use crate::prelude::*; fn clif_sig_from_fn_abi<'tcx>( @@ -380,7 +382,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( args: &[Spanned>], destination: Place<'tcx>, target: Option, - _unwind: UnwindAction, + unwind: UnwindAction, ) { let func = codegen_operand(fx, func); let fn_sig = func.layout().ty.fn_sig(fx.tcx); @@ -515,12 +517,6 @@ pub(crate) fn codegen_terminator_call<'tcx>( let args = args; assert_eq!(fn_abi.args.len(), args.len()); - #[derive(Copy, Clone)] - enum CallTarget { - Direct(FuncRef), - Indirect(SigRef, Value), - } - let (func_ref, first_arg_override) = match instance { // Trait object call Some(Instance { def: InstanceKind::Virtual(_, idx), .. }) => { @@ -582,18 +578,12 @@ pub(crate) fn codegen_terminator_call<'tcx>( adjust_call_for_c_variadic(fx, &fn_abi, source_info, func_ref, &mut call_args); } - let call_inst = match func_ref { - CallTarget::Direct(func_ref) => fx.bcx.ins().call(func_ref, &call_args), - CallTarget::Indirect(sig, func_ptr) => { - fx.bcx.ins().call_indirect(sig, func_ptr, &call_args) - } - }; - if fx.clif_comments.enabled() { - with_no_trimmed_paths!(fx.add_comment(call_inst, format!("abi: {:?}", fn_abi))); + let nop_inst = fx.bcx.ins().nop(); + with_no_trimmed_paths!(fx.add_post_comment(nop_inst, format!("abi: {:?}", fn_abi))); } - fx.bcx.func.dfg.inst_results(call_inst).iter().copied().collect::>() + codegen_call_with_unwind_action(fx, source_info.span, func_ref, unwind, &call_args, None) }); if let Some(dest) = target { @@ -703,7 +693,7 @@ pub(crate) fn codegen_drop<'tcx>( source_info: mir::SourceInfo, drop_place: CPlace<'tcx>, target: BasicBlock, - _unwind: UnwindAction, + unwind: UnwindAction, ) { let ty = drop_place.layout().ty; let drop_instance = Instance::resolve_drop_in_place(fx.tcx, ty); @@ -749,9 +739,14 @@ pub(crate) fn codegen_drop<'tcx>( let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi); let sig = fx.bcx.import_signature(sig); - // FIXME implement cleanup on exceptions - fx.bcx.ins().call_indirect(sig, drop_fn, &[ptr]); - fx.bcx.ins().jump(ret_block, &[]); + codegen_call_with_unwind_action( + fx, + source_info.span, + CallTarget::Indirect(sig, drop_fn), + unwind, + &[ptr], + Some(ret_block), + ); } ty::Dynamic(_, _, ty::DynStar) => { // IN THIS ARM, WE HAVE: @@ -794,9 +789,14 @@ pub(crate) fn codegen_drop<'tcx>( let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi); let sig = fx.bcx.import_signature(sig); - fx.bcx.ins().call_indirect(sig, drop_fn, &[data]); - // FIXME implement cleanup on exceptions - fx.bcx.ins().jump(ret_block, &[]); + codegen_call_with_unwind_action( + fx, + source_info.span, + CallTarget::Indirect(sig, drop_fn), + unwind, + &[data], + Some(ret_block), + ); } _ => { assert!(!matches!(drop_instance.def, InstanceKind::Virtual(_, _))); @@ -821,9 +821,132 @@ pub(crate) fn codegen_drop<'tcx>( } let func_ref = fx.get_function_ref(drop_instance); - fx.bcx.ins().call(func_ref, &call_args); - // FIXME implement cleanup on exceptions - fx.bcx.ins().jump(ret_block, &[]); + codegen_call_with_unwind_action( + fx, + source_info.span, + CallTarget::Direct(func_ref), + unwind, + &call_args, + Some(ret_block), + ); + } + } + } +} + +#[derive(Copy, Clone)] +pub(crate) enum CallTarget { + Direct(FuncRef), + Indirect(SigRef, Value), +} + +pub(crate) fn codegen_call_with_unwind_action( + fx: &mut FunctionCx<'_, '_, '_>, + span: Span, + func_ref: CallTarget, + unwind: UnwindAction, + call_args: &[Value], + target_block: Option, +) -> SmallVec<[Value; 2]> { + let sig_ref = match func_ref { + CallTarget::Direct(func_ref) => fx.bcx.func.dfg.ext_funcs[func_ref].signature, + CallTarget::Indirect(sig_ref, _func_ptr) => sig_ref, + }; + + if target_block.is_some() { + assert!(fx.bcx.func.dfg.signatures[sig_ref].returns.is_empty()); + } + match unwind { + UnwindAction::Continue | UnwindAction::Unreachable => { + let call_inst = match func_ref { + CallTarget::Direct(func_ref) => fx.bcx.ins().call(func_ref, &call_args), + CallTarget::Indirect(sig, func_ptr) => { + fx.bcx.ins().call_indirect(sig, func_ptr, &call_args) + } + }; + + if let Some(target_block) = target_block { + fx.bcx.ins().jump(target_block, &[]); + smallvec![] + } else { + fx.bcx + .func + .dfg + .inst_results(call_inst) + .iter() + .copied() + .collect::>() + } + } + UnwindAction::Cleanup(_) | UnwindAction::Terminate(_) => { + let returns_types = fx.bcx.func.dfg.signatures[sig_ref] + .returns + .iter() + .map(|return_param| return_param.value_type) + .collect::>(); + + let fallthrough_block = fx.bcx.create_block(); + let fallthrough_block_call_args = returns_types + .iter() + .enumerate() + .map(|(i, _)| BlockArg::TryCallRet(i.try_into().unwrap())) + .collect::>(); + let fallthrough_block_call = fx.bcx.func.dfg.block_call( + target_block.unwrap_or(fallthrough_block), + &fallthrough_block_call_args, + ); + let pre_cleanup_block = fx.bcx.create_block(); + let pre_cleanup_block_call = + fx.bcx.func.dfg.block_call(pre_cleanup_block, &[BlockArg::TryCallExn(0)]); + let exception_table = fx.bcx.func.dfg.exception_tables.push(ExceptionTableData::new( + sig_ref, + fallthrough_block_call, + [( + Some(ExceptionTag::with_number(EXCEPTION_HANDLER_CLEANUP).unwrap()), + pre_cleanup_block_call, + )], + )); + + match func_ref { + CallTarget::Direct(func_ref) => { + fx.bcx.ins().try_call(func_ref, &call_args, exception_table); + } + CallTarget::Indirect(_sig, func_ptr) => { + fx.bcx.ins().try_call_indirect(func_ptr, &call_args, exception_table); + } + } + + fx.bcx.seal_block(pre_cleanup_block); + fx.bcx.switch_to_block(pre_cleanup_block); + fx.bcx.set_cold_block(pre_cleanup_block); + match unwind { + UnwindAction::Continue | UnwindAction::Unreachable => unreachable!(), + UnwindAction::Cleanup(cleanup) => { + let exception_ptr = + fx.bcx.append_block_param(pre_cleanup_block, fx.pointer_type); + fx.bcx.def_var(fx.exception_slot, exception_ptr); + let cleanup_block = fx.get_block(cleanup); + fx.bcx.ins().jump(cleanup_block, &[]); + } + UnwindAction::Terminate(reason) => { + // FIXME dedup terminate blocks + fx.bcx.append_block_param(pre_cleanup_block, fx.pointer_type); + + codegen_unwind_terminate(fx, span, reason); + } + } + + if target_block.is_none() { + fx.bcx.seal_block(fallthrough_block); + fx.bcx.switch_to_block(fallthrough_block); + let returns = returns_types + .into_iter() + .map(|ty| fx.bcx.append_block_param(fallthrough_block, ty)) + .collect(); + fx.bcx.ins().nop(); + returns + } else { + smallvec![] } } } diff --git a/src/base.rs b/src/base.rs index d79cf5aa58425..ddc1013c25adf 100644 --- a/src/base.rs +++ b/src/base.rs @@ -2,7 +2,7 @@ use cranelift_codegen::CodegenError; use cranelift_codegen::ir::UserFuncName; -use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext}; +use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable}; use cranelift_module::ModuleError; use rustc_ast::InlineAsmOptions; use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization; @@ -85,6 +85,9 @@ pub(crate) fn codegen_fn<'tcx>( None }; + let exception_slot = Variable::from_u32(0); + bcx.declare_var(exception_slot, pointer_type); + let mut fx = FunctionCx { cx, module, @@ -103,9 +106,10 @@ pub(crate) fn codegen_fn<'tcx>( block_map, local_map: IndexVec::with_capacity(mir.local_decls.len()), caller_location: None, // set by `codegen_fn_prelude` + exception_slot, clif_comments, - next_ssa_var: 0, + next_ssa_var: 1, // var0 is used for the exception slot inline_asm: String::new(), inline_asm_index: 0, }; @@ -304,11 +308,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { } if bb_data.is_cleanup { - // Unwinding after panicking is not supported - continue; - - // FIXME Once unwinding is supported and Cranelift supports marking blocks as cold, do - // so for cleanup blocks. + fx.bcx.set_cold_block(block); } fx.bcx.ins().nop(); @@ -542,7 +542,13 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { codegen_unwind_terminate(fx, source_info.span, *reason); } TerminatorKind::UnwindResume => { - // FIXME implement unwinding + let exception_ptr = fx.bcx.use_var(fx.exception_slot); + fx.lib_call( + "_Unwind_Resume", + vec![AbiParam::new(fx.pointer_type)], + vec![], + &[exception_ptr], + ); fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap()); } TerminatorKind::Unreachable => { @@ -1109,7 +1115,7 @@ fn codegen_panic_inner<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, lang_item: rustc_hir::LangItem, args: &[Value], - _unwind: UnwindAction, + unwind: UnwindAction, span: Span, ) { fx.bcx.set_cold_block(fx.bcx.current_block().unwrap()); @@ -1125,14 +1131,23 @@ fn codegen_panic_inner<'tcx>( let symbol_name = fx.tcx.symbol_name(instance).name; - // FIXME implement cleanup on exceptions + let sig = Signature { + params: args.iter().map(|&arg| AbiParam::new(fx.bcx.func.dfg.value_type(arg))).collect(), + returns: vec![], + call_conv: fx.target_config.default_call_conv, + }; + let func_id = fx.module.declare_function(symbol_name, Linkage::Import, &sig).unwrap(); + let func_ref = fx.module.declare_func_in_func(func_id, &mut fx.bcx.func); + if fx.clif_comments.enabled() { + fx.add_comment(func_ref, format!("{:?}", symbol_name)); + } + + let nop_inst = fx.bcx.ins().nop(); + if fx.clif_comments.enabled() { + fx.add_comment(nop_inst, format!("panic {}", symbol_name)); + } - fx.lib_call( - symbol_name, - args.iter().map(|&arg| AbiParam::new(fx.bcx.func.dfg.value_type(arg))).collect(), - vec![], - args, - ); + codegen_call_with_unwind_action(fx, span, CallTarget::Direct(func_ref), unwind, &args, None); fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap()); } diff --git a/src/common.rs b/src/common.rs index 80b1f0881347c..6596b27fb1ffc 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,5 +1,5 @@ use cranelift_codegen::isa::TargetFrontendConfig; -use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext}; +use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable}; use rustc_abi::{Float, Integer, Primitive}; use rustc_index::IndexVec; use rustc_middle::ty::TypeFoldable; @@ -288,6 +288,9 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> { /// When `#[track_caller]` is used, the implicit caller location is stored in this variable. pub(crate) caller_location: Option>, + /// During cleanup the exception pointer will be stored in this variable. + pub(crate) exception_slot: Variable, + pub(crate) clif_comments: crate::pretty_clif::CommentWriter, /// This should only be accessed by `CPlace::new_var`. diff --git a/src/debuginfo/gcc_except_table.rs b/src/debuginfo/gcc_except_table.rs new file mode 100644 index 0000000000000..b8e602c76a8c0 --- /dev/null +++ b/src/debuginfo/gcc_except_table.rs @@ -0,0 +1,272 @@ +use gimli::write::{Address, Writer}; +use gimli::{DW_EH_PE_omit, DW_EH_PE_uleb128, Encoding, LittleEndian}; + +pub(super) struct GccExceptTable { + pub call_sites: CallSiteTable, + pub actions: ActionTable, + pub type_info: TypeInfoTable, +} + +impl GccExceptTable { + pub(super) fn write( + &self, + w: &mut W, + encoding: Encoding, + ) -> gimli::write::Result<()> { + // lpStartEncoding + w.write_u8(DW_EH_PE_omit.0)?; + // lpStart (omitted) + let type_info_padding = if self.type_info.type_info.is_empty() { + // ttypeEncoding + w.write_u8(DW_EH_PE_omit.0)?; + None + } else { + // ttypeEncoding + w.write_u8(self.type_info.ttype_encoding.0)?; + + // classInfoOffset + let class_info_offset_field_offset = w.len() as u64; + + // Note: The offset in classInfoOffset is relative to position right after classInfoOffset + // itself. + let class_info_offset_no_padding = self.call_sites.encoded_size() + + self.actions.encoded_size() + + self.type_info.encoded_size(encoding); + + let type_info_is_aligned = |type_info_padding: u64| { + (class_info_offset_field_offset + + gimli::leb128::write::uleb128_size( + class_info_offset_no_padding + type_info_padding, + ) as u64 + + self.call_sites.encoded_size() + + self.actions.encoded_size() + + type_info_padding) + % 4 + == 0 + }; + + let mut type_info_padding = 0; + while !type_info_is_aligned(type_info_padding) { + type_info_padding += 1; + } + + w.write_uleb128(class_info_offset_no_padding + type_info_padding)?; + + Some(type_info_padding) + }; + + // call site table + self.call_sites.write(w)?; + + // action table + self.actions.write(w)?; + + // align to 4 bytes + if let Some(type_info_padding) = type_info_padding { + for _ in 0..type_info_padding { + w.write_u8(0)?; + } + // In this case we calculated the expected padding amount and used it to write the + // classInfoOffset field. Assert that the expected value matched the actual value to catch + // any inconsistency. + assert!(w.len() % 4 == 0, "type_info must be aligned to 4 bytes"); + } else { + while w.len() % 4 != 0 { + w.write_u8(0)?; + } + } + + // type_info + self.type_info.write(w, encoding)?; + + // exception specs (unused for rust) + + // align to 4 bytes + while w.len() % 4 != 0 { + w.write_u8(0)?; + } + + Ok(()) + } +} + +pub(super) struct CallSiteTable(pub Vec); + +impl CallSiteTable { + fn encoded_size(&self) -> u64 { + let mut len = LenWriter(0); + self.write(&mut len).unwrap(); + len.0 as u64 + } + + fn write(&self, w: &mut W) -> gimli::write::Result<()> { + let callsite_table_length = self.0.iter().map(|call_site| call_site.encoded_size()).sum(); + + // callsiteEncoding + w.write_u8(DW_EH_PE_uleb128.0)?; + // callsiteTableLength + w.write_uleb128(callsite_table_length)?; + + for call_site in &self.0 { + call_site.write(w)?; + } + + Ok(()) + } +} + +pub(super) struct CallSite { + pub start: u64, + pub length: u64, + pub landing_pad: u64, + pub action_entry: Option, +} + +impl CallSite { + fn encoded_size(&self) -> u64 { + let mut len = LenWriter(0); + self.write(&mut len).unwrap(); + len.0 as u64 + } + + fn write(&self, w: &mut W) -> gimli::write::Result<()> { + w.write_uleb128(self.start)?; + w.write_uleb128(self.length)?; + w.write_uleb128(self.landing_pad)?; + w.write_uleb128(match self.action_entry { + Some(action_offset) => action_offset.0 + 1, + None => 0, + })?; + Ok(()) + } +} + +pub(super) struct ActionTable { + actions: Vec, + encoded_length: u64, +} + +impl ActionTable { + pub(super) fn new() -> ActionTable { + ActionTable { actions: vec![], encoded_length: 0 } + } + + pub(super) fn add(&mut self, action: Action) -> ActionOffset { + let id = ActionOffset(self.encoded_length); + self.encoded_length += action.encoded_size(self.encoded_length); + self.actions.push(action); + id + } + + fn encoded_size(&self) -> u64 { + let mut len = LenWriter(0); + self.write(&mut len).unwrap(); + len.0 as u64 + } + + fn write(&self, w: &mut W) -> gimli::write::Result<()> { + let action_table_start = w.len() as u64; + for action in &self.actions { + action.write(w, w.len() as u64 - action_table_start)?; + } + + Ok(()) + } +} + +#[derive(Copy, Clone)] +pub(super) struct ActionOffset(u64); + +pub(super) struct Action { + pub(super) kind: ActionKind, + pub(super) next_action: Option, +} + +impl Action { + fn encoded_size(&self, action_table_offset: u64) -> u64 { + let mut len = LenWriter(0); + self.write(&mut len, action_table_offset).unwrap(); + len.0 as u64 + } + + fn write(&self, w: &mut W, action_table_offset: u64) -> gimli::write::Result<()> { + // ttypeIndex + let ttype_index = match self.kind { + ActionKind::Catch(type_info_id) => type_info_id.0 as i64 + 1, + }; + w.write_sleb128(ttype_index)?; + // actionOffset + let action_offset_field_offset = + action_table_offset + gimli::leb128::write::sleb128_size(ttype_index) as u64; + w.write_sleb128(match self.next_action { + Some(next_action_offset) => { + next_action_offset.0 as i64 - action_offset_field_offset as i64 + } + None => 0, + })?; + Ok(()) + } +} + +#[derive(Copy, Clone)] +pub(super) enum ActionKind { + Catch(TypeInfoId), +} + +pub(super) struct TypeInfoTable { + ttype_encoding: gimli::DwEhPe, + type_info: Vec
, +} + +impl TypeInfoTable { + pub(super) fn new(ttype_encoding: gimli::DwEhPe) -> TypeInfoTable { + TypeInfoTable { ttype_encoding, type_info: vec![] } + } + + pub(super) fn add(&mut self, type_info: Address) -> TypeInfoId { + let id = TypeInfoId(self.type_info.len() as u64); + self.type_info.push(type_info); + id + } + + fn encoded_size(&self, encoding: Encoding) -> u64 { + let mut len = LenWriter(0); + self.write(&mut len, encoding).unwrap(); + len.0 as u64 + } + + fn write(&self, w: &mut W, encoding: Encoding) -> gimli::write::Result<()> { + for &type_info in self.type_info.iter().rev() { + w.write_eh_pointer(type_info, self.ttype_encoding, encoding.address_size)?; + } + + Ok(()) + } +} + +#[derive(Copy, Clone)] +pub(super) struct TypeInfoId(u64); + +struct LenWriter(usize); + +impl Writer for LenWriter { + type Endian = LittleEndian; + + fn endian(&self) -> LittleEndian { + LittleEndian + } + + fn len(&self) -> usize { + self.0 + } + + fn write(&mut self, bytes: &[u8]) -> gimli::write::Result<()> { + self.0 += bytes.len(); + Ok(()) + } + + fn write_at(&mut self, offset: usize, bytes: &[u8]) -> gimli::write::Result<()> { + assert!(offset + bytes.len() < self.0); + Ok(()) + } +} diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index 286e02b986b3c..35f92609982ed 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -1,6 +1,7 @@ //! Handling of everything related to debuginfo. mod emit; +mod gcc_except_table; mod line_info; mod object; mod types; @@ -24,7 +25,7 @@ use rustc_target::callconv::FnAbi; pub(crate) use self::emit::{DebugReloc, DebugRelocName}; pub(crate) use self::types::TypeDebugContext; -pub(crate) use self::unwind::UnwindContext; +pub(crate) use self::unwind::{EXCEPTION_HANDLER_CATCH, EXCEPTION_HANDLER_CLEANUP, UnwindContext}; use crate::debuginfo::emit::{address_for_data, address_for_func}; use crate::prelude::*; diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs index 74b82a7139ab0..fb93648332b8e 100644 --- a/src/debuginfo/unwind.rs +++ b/src/debuginfo/unwind.rs @@ -2,14 +2,21 @@ use cranelift_codegen::ir::Endianness; use cranelift_codegen::isa::unwind::UnwindInfo; +use cranelift_module::DataId; use cranelift_object::ObjectProduct; -use gimli::RunTimeEndian; -use gimli::write::{CieId, EhFrame, FrameTable, Section}; +use gimli::write::{Address, CieId, EhFrame, FrameTable, Section}; +use gimli::{Encoding, Format, RunTimeEndian}; -use super::emit::address_for_func; +use super::emit::{DebugRelocName, address_for_data, address_for_func}; +use super::gcc_except_table::{ + Action, ActionKind, ActionTable, CallSite, CallSiteTable, GccExceptTable, TypeInfoTable, +}; use super::object::WriteDebugInfo; use crate::prelude::*; +pub(crate) const EXCEPTION_HANDLER_CLEANUP: u32 = 0; +pub(crate) const EXCEPTION_HANDLER_CATCH: u32 = 1; + pub(crate) struct UnwindContext { endian: RunTimeEndian, frame_table: FrameTable, @@ -28,7 +35,68 @@ impl UnwindContext { if pic_eh_frame { cie.fde_address_encoding = gimli::DwEhPe(gimli::DW_EH_PE_pcrel.0 | gimli::DW_EH_PE_sdata4.0); + cie.lsda_encoding = + Some(gimli::DwEhPe(gimli::DW_EH_PE_pcrel.0 | gimli::DW_EH_PE_sdata4.0)); + } else { + cie.fde_address_encoding = gimli::DW_EH_PE_absptr; + cie.lsda_encoding = Some(gimli::DW_EH_PE_absptr); } + // FIXME use eh_personality lang item instead + let personality = module + .declare_function( + "rust_eh_personality", + Linkage::Import, + &Signature { + params: vec![ + AbiParam::new(types::I32), + AbiParam::new(types::I32), + AbiParam::new(types::I64), + AbiParam::new(module.target_config().pointer_type()), + AbiParam::new(module.target_config().pointer_type()), + ], + returns: vec![AbiParam::new(types::I32)], + call_conv: module.target_config().default_call_conv, + }, + ) + .unwrap(); + + // Use indirection here to support PIC the case where rust_eh_personality is defined in + // another DSO. + let personality_ref = module + .declare_data("DW.ref.rust_eh_personality", Linkage::Local, false, false) + .unwrap(); + + let mut personality_ref_data = DataDescription::new(); + // Note: Must not use define_zeroinit. The unwinder can't handle this being in the .bss + // section. + let pointer_bytes = usize::from(module.target_config().pointer_bytes()); + personality_ref_data.define(vec![0; pointer_bytes].into_boxed_slice()); + let personality_func_ref = + module.declare_func_in_data(personality, &mut personality_ref_data); + personality_ref_data.write_function_addr(0, personality_func_ref); + + module.define_data(personality_ref, &personality_ref_data).unwrap(); + + cie.personality = Some(( + if module.isa().triple().architecture == target_lexicon::Architecture::X86_64 { + gimli::DwEhPe( + gimli::DW_EH_PE_indirect.0 + | gimli::DW_EH_PE_pcrel.0 + | gimli::DW_EH_PE_sdata4.0, + ) + } else if let target_lexicon::Architecture::Aarch64(_) = + module.isa().triple().architecture + { + gimli::DwEhPe( + gimli::DW_EH_PE_indirect.0 + | gimli::DW_EH_PE_pcrel.0 + | gimli::DW_EH_PE_sdata8.0, + ) + } else { + todo!() + }, + address_for_data(personality_ref), + )); Some(frame_table.add_cie(cie)) } else { None @@ -63,8 +131,90 @@ impl UnwindContext { match unwind_info { UnwindInfo::SystemV(unwind_info) => { - self.frame_table - .add_fde(self.cie_id.unwrap(), unwind_info.to_fde(address_for_func(func_id))); + let mut fde = unwind_info.to_fde(address_for_func(func_id)); + // FIXME use unique symbol name derived from function name + let lsda = module.declare_anonymous_data(false, false).unwrap(); + + let encoding = Encoding { + format: Format::Dwarf32, + version: 1, + address_size: module.isa().frontend_config().pointer_bytes(), + }; + + let mut gcc_except_table_data = GccExceptTable { + call_sites: CallSiteTable(vec![]), + actions: ActionTable::new(), + type_info: TypeInfoTable::new(gimli::DW_EH_PE_udata4), + }; + + let catch_type = gcc_except_table_data.type_info.add(Address::Constant(0)); + let catch_action = gcc_except_table_data + .actions + .add(Action { kind: ActionKind::Catch(catch_type), next_action: None }); + + for call_site in context.compiled_code().unwrap().buffer.call_sites() { + if call_site.exception_handlers.is_empty() { + gcc_except_table_data.call_sites.0.push(CallSite { + start: u64::from(call_site.ret_addr - 1), + length: 1, + landing_pad: 0, + action_entry: None, + }); + } + for &(tag, landingpad) in call_site.exception_handlers { + match tag.expand().unwrap().as_u32() { + EXCEPTION_HANDLER_CLEANUP => { + gcc_except_table_data.call_sites.0.push(CallSite { + start: u64::from(call_site.ret_addr - 1), + length: 1, + landing_pad: u64::from(landingpad), + action_entry: None, + }) + } + EXCEPTION_HANDLER_CATCH => { + gcc_except_table_data.call_sites.0.push(CallSite { + start: u64::from(call_site.ret_addr - 1), + length: 1, + landing_pad: u64::from(landingpad), + action_entry: Some(catch_action), + }) + } + _ => unreachable!(), + } + } + } + + let mut gcc_except_table = super::emit::WriterRelocate::new(self.endian); + + gcc_except_table_data.write(&mut gcc_except_table, encoding).unwrap(); + + let mut data = DataDescription::new(); + data.define(gcc_except_table.writer.into_vec().into_boxed_slice()); + data.set_segment_section("", ".gcc_except_table"); + + for reloc in &gcc_except_table.relocs { + match reloc.name { + DebugRelocName::Section(_id) => unreachable!(), + DebugRelocName::Symbol(id) => { + let id = id.try_into().unwrap(); + if id & 1 << 31 == 0 { + let func_ref = + module.declare_func_in_data(FuncId::from_u32(id), &mut data); + data.write_function_addr(reloc.offset, func_ref); + } else { + let gv = module.declare_data_in_data( + DataId::from_u32(id & !(1 << 31)), + &mut data, + ); + data.write_data_addr(reloc.offset, gv, 0); + } + } + }; + } + + module.define_data(lsda, &data).unwrap(); + fde.lsda = Some(address_for_data(lsda)); + self.frame_table.add_fde(self.cie_id.unwrap(), fde); } UnwindInfo::WindowsX64(_) | UnwindInfo::WindowsArm64(_) => { // Windows does not have debug info for its unwind info. diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 832f24b38bce4..5f4956c801bea 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -829,6 +829,7 @@ fn call_inline_asm<'tcx>( } let stack_slot_addr = stack_slot.get_addr(fx); + // FIXME use try_call once unwinding inline assembly is supported fx.bcx.ins().call(inline_asm_func, &[stack_slot_addr]); for (offset, place) in outputs { diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index df5748c34d110..da740cb88e415 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -17,17 +17,19 @@ mod llvm_aarch64; mod llvm_x86; mod simd; -use cranelift_codegen::ir::AtomicRmwOp; +use cranelift_codegen::ir::{AtomicRmwOp, BlockArg, ExceptionTableData, ExceptionTag}; use rustc_middle::ty; use rustc_middle::ty::GenericArgsRef; use rustc_middle::ty::layout::ValidityRequirement; use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths}; use rustc_span::source_map::Spanned; use rustc_span::{Symbol, sym}; +use rustc_target::spec::PanicStrategy; pub(crate) use self::llvm::codegen_llvm_intrinsic_call; use crate::cast::clif_intcast; use crate::codegen_f16_f128; +use crate::debuginfo::EXCEPTION_HANDLER_CATCH; use crate::prelude::*; fn bug_on_incorrect_arg_count(intrinsic: impl std::fmt::Display) -> ! { @@ -1352,23 +1354,73 @@ fn codegen_regular_intrinsic_call<'tcx>( } sym::catch_unwind => { + let ret_block = fx.get_block(destination.unwrap()); + intrinsic_args!(fx, args => (f, data, catch_fn); intrinsic); let f = f.load_scalar(fx); let data = data.load_scalar(fx); - let _catch_fn = catch_fn.load_scalar(fx); + let catch_fn = catch_fn.load_scalar(fx); - // FIXME once unwinding is supported, change this to actually catch panics let f_sig = fx.bcx.func.import_signature(Signature { call_conv: fx.target_config.default_call_conv, params: vec![AbiParam::new(pointer_ty(fx.tcx))], returns: vec![], }); - fx.bcx.ins().call_indirect(f_sig, f, &[data]); + if fx.tcx.sess.panic_strategy() == PanicStrategy::Abort { + fx.bcx.ins().call_indirect(f_sig, f, &[data]); + + let layout = fx.layout_of(fx.tcx.types.i32); + let ret_val = CValue::by_val(fx.bcx.ins().iconst(types::I32, 0), layout); + ret.write_cvalue(fx, ret_val); + + fx.bcx.ins().jump(ret_block, &[]); + } else { + let catch_fn_sig = fx.bcx.func.import_signature(Signature { + call_conv: fx.target_config.default_call_conv, + params: vec![ + AbiParam::new(pointer_ty(fx.tcx)), + AbiParam::new(pointer_ty(fx.tcx)), + ], + returns: vec![], + }); + + let fallthrough_block = fx.bcx.create_block(); + let fallthrough_block_call = fx.bcx.func.dfg.block_call(fallthrough_block, &[]); + let catch_block = fx.bcx.create_block(); + let catch_block_call = + fx.bcx.func.dfg.block_call(catch_block, &[BlockArg::TryCallExn(0)]); + let exception_table = + fx.bcx.func.dfg.exception_tables.push(ExceptionTableData::new( + f_sig, + fallthrough_block_call, + [( + Some(ExceptionTag::with_number(EXCEPTION_HANDLER_CATCH).unwrap()), + catch_block_call, + )], + )); + + fx.bcx.ins().try_call_indirect(f, &[data], exception_table); + + fx.bcx.seal_block(fallthrough_block); + fx.bcx.switch_to_block(fallthrough_block); + let layout = fx.layout_of(fx.tcx.types.i32); + let ret_val = CValue::by_val(fx.bcx.ins().iconst(types::I32, 0), layout); + ret.write_cvalue(fx, ret_val); + fx.bcx.ins().jump(ret_block, &[]); + + fx.bcx.seal_block(catch_block); + fx.bcx.switch_to_block(catch_block); + fx.bcx.set_cold_block(catch_block); + let exception = fx.bcx.append_block_param(catch_block, pointer_ty(fx.tcx)); + fx.bcx.ins().call_indirect(catch_fn_sig, catch_fn, &[data, exception]); + let layout = fx.layout_of(fx.tcx.types.i32); + let ret_val = CValue::by_val(fx.bcx.ins().iconst(types::I32, 1), layout); + ret.write_cvalue(fx, ret_val); + fx.bcx.ins().jump(ret_block, &[]); + } - let layout = fx.layout_of(fx.tcx.types.i32); - let ret_val = CValue::by_val(fx.bcx.ins().iconst(types::I32, 0), layout); - ret.write_cvalue(fx, ret_val); + return Ok(()); } sym::fadd_fast From 0c7e953885ad3754538f0fce150ecf5247878e82 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 7 May 2025 13:08:21 +0000 Subject: [PATCH 014/160] Fix panic=unwind for JIT --- src/debuginfo/unwind.rs | 58 +++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs index fb93648332b8e..940075e250e0c 100644 --- a/src/debuginfo/unwind.rs +++ b/src/debuginfo/unwind.rs @@ -32,15 +32,36 @@ impl UnwindContext { let mut frame_table = FrameTable::default(); let cie_id = if let Some(mut cie) = module.isa().create_systemv_cie() { - if pic_eh_frame { - cie.fde_address_encoding = - gimli::DwEhPe(gimli::DW_EH_PE_pcrel.0 | gimli::DW_EH_PE_sdata4.0); - cie.lsda_encoding = - Some(gimli::DwEhPe(gimli::DW_EH_PE_pcrel.0 | gimli::DW_EH_PE_sdata4.0)); + let ptr_encoding = if pic_eh_frame { + gimli::DwEhPe(gimli::DW_EH_PE_pcrel.0 | gimli::DW_EH_PE_sdata4.0) } else { - cie.fde_address_encoding = gimli::DW_EH_PE_absptr; - cie.lsda_encoding = Some(gimli::DW_EH_PE_absptr); - } + gimli::DW_EH_PE_absptr + }; + let code_ptr_encoding = if pic_eh_frame { + if module.isa().triple().architecture == target_lexicon::Architecture::X86_64 { + gimli::DwEhPe( + gimli::DW_EH_PE_indirect.0 + | gimli::DW_EH_PE_pcrel.0 + | gimli::DW_EH_PE_sdata4.0, + ) + } else if let target_lexicon::Architecture::Aarch64(_) = + module.isa().triple().architecture + { + gimli::DwEhPe( + gimli::DW_EH_PE_indirect.0 + | gimli::DW_EH_PE_pcrel.0 + | gimli::DW_EH_PE_sdata8.0, + ) + } else { + todo!() + } + } else { + gimli::DwEhPe(gimli::DW_EH_PE_indirect.0 | gimli::DW_EH_PE_absptr.0) + }; + + cie.fde_address_encoding = ptr_encoding; + cie.lsda_encoding = Some(ptr_encoding); + // FIXME use eh_personality lang item instead let personality = module .declare_function( @@ -77,26 +98,7 @@ impl UnwindContext { module.define_data(personality_ref, &personality_ref_data).unwrap(); - cie.personality = Some(( - if module.isa().triple().architecture == target_lexicon::Architecture::X86_64 { - gimli::DwEhPe( - gimli::DW_EH_PE_indirect.0 - | gimli::DW_EH_PE_pcrel.0 - | gimli::DW_EH_PE_sdata4.0, - ) - } else if let target_lexicon::Architecture::Aarch64(_) = - module.isa().triple().architecture - { - gimli::DwEhPe( - gimli::DW_EH_PE_indirect.0 - | gimli::DW_EH_PE_pcrel.0 - | gimli::DW_EH_PE_sdata8.0, - ) - } else { - todo!() - }, - address_for_data(personality_ref), - )); + cie.personality = Some((code_ptr_encoding, address_for_data(personality_ref))); Some(frame_table.add_cie(cie)) } else { None From e0ea4b016a8137f7953ee4f2ec765eec78574c94 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 7 May 2025 13:34:29 +0000 Subject: [PATCH 015/160] Put unwinding support behind a cargo feature --- Cargo.toml | 1 + build_system/abi_cafe.rs | 2 + build_system/build_backend.rs | 5 + build_system/build_sysroot.rs | 17 ++- build_system/main.rs | 7 + build_system/tests.rs | 21 ++- build_system/usage.txt | 4 + scripts/cargo-clif.rs | 6 +- scripts/rustc-clif.rs | 6 +- scripts/rustdoc-clif.rs | 6 +- src/abi/mod.rs | 7 +- src/base.rs | 20 ++- src/debuginfo/unwind.rs | 275 ++++++++++++++++++---------------- src/intrinsics/mod.rs | 4 +- 14 files changed, 231 insertions(+), 150 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9066e4dbbb528..51bb5d9db0ea6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,7 @@ smallvec = "1.8.1" unstable-features = ["jit", "inline_asm_sym"] jit = ["cranelift-jit", "libloading"] inline_asm_sym = [] +unwinding = [] # Not yet included in unstable-features for performance reasons [package.metadata.rust-analyzer] rustc_private = true diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs index 43025137bc6bb..5a393a217c278 100644 --- a/build_system/abi_cafe.rs +++ b/build_system/abi_cafe.rs @@ -19,6 +19,7 @@ pub(crate) fn run( cg_clif_dylib: &CodegenBackend, rustup_toolchain_name: Option<&str>, bootstrap_host_compiler: &Compiler, + panic_unwind_support: bool, ) { std::fs::create_dir_all(&dirs.download_dir).unwrap(); ABI_CAFE_REPO.fetch(dirs); @@ -32,6 +33,7 @@ pub(crate) fn run( bootstrap_host_compiler, rustup_toolchain_name, bootstrap_host_compiler.triple.clone(), + panic_unwind_support, ); eprintln!("Running abi-cafe"); diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index bf7cf1c0a346f..a1f19a1afd093 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -12,6 +12,7 @@ pub(crate) fn build_backend( dirs: &Dirs, bootstrap_host_compiler: &Compiler, use_unstable_features: bool, + panic_unwind_support: bool, ) -> PathBuf { let _group = LogGroup::guard("Build backend"); @@ -31,6 +32,10 @@ pub(crate) fn build_backend( cmd.arg("--features").arg("unstable-features"); } + if panic_unwind_support { + cmd.arg("--features").arg("unwinding"); + } + cmd.arg("--release"); eprintln!("[BUILD] rustc_codegen_cranelift"); diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 00955998e703d..fec6ff2415502 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -17,6 +17,7 @@ pub(crate) fn build_sysroot( bootstrap_host_compiler: &Compiler, rustup_toolchain_name: Option<&str>, target_triple: String, + panic_unwind_support: bool, ) -> Compiler { let _guard = LogGroup::guard("Build sysroot"); @@ -52,6 +53,9 @@ pub(crate) fn build_sysroot( .arg("-o") .arg(&wrapper_path) .arg("-Cstrip=debuginfo"); + if panic_unwind_support { + build_cargo_wrapper_cmd.arg("--cfg").arg("support_panic_unwind"); + } if let Some(rustup_toolchain_name) = &rustup_toolchain_name { build_cargo_wrapper_cmd .env("TOOLCHAIN_NAME", rustup_toolchain_name) @@ -77,6 +81,7 @@ pub(crate) fn build_sysroot( bootstrap_host_compiler.clone(), &cg_clif_dylib_path, sysroot_kind, + panic_unwind_support, ); host.install_into_sysroot(dist_dir); @@ -91,6 +96,7 @@ pub(crate) fn build_sysroot( }, &cg_clif_dylib_path, sysroot_kind, + panic_unwind_support, ) .install_into_sysroot(dist_dir); } @@ -141,12 +147,15 @@ fn build_sysroot_for_triple( compiler: Compiler, cg_clif_dylib_path: &CodegenBackend, sysroot_kind: SysrootKind, + panic_unwind_support: bool, ) -> SysrootTarget { match sysroot_kind { SysrootKind::None => build_rtstartup(dirs, &compiler) .unwrap_or(SysrootTarget { triple: compiler.triple, libs: vec![] }), SysrootKind::Llvm => build_llvm_sysroot_for_triple(compiler), - SysrootKind::Clif => build_clif_sysroot_for_triple(dirs, compiler, cg_clif_dylib_path), + SysrootKind::Clif => { + build_clif_sysroot_for_triple(dirs, compiler, cg_clif_dylib_path, panic_unwind_support) + } } } @@ -188,6 +197,7 @@ fn build_clif_sysroot_for_triple( dirs: &Dirs, mut compiler: Compiler, cg_clif_dylib_path: &CodegenBackend, + panic_unwind_support: bool, ) -> SysrootTarget { let mut target_libs = SysrootTarget { triple: compiler.triple.clone(), libs: vec![] }; @@ -206,7 +216,10 @@ fn build_clif_sysroot_for_triple( } // Build sysroot - let mut rustflags = vec!["-Zforce-unstable-if-unmarked".to_owned(), "-Cpanic=abort".to_owned()]; + let mut rustflags = vec!["-Zforce-unstable-if-unmarked".to_owned()]; + if !panic_unwind_support { + rustflags.push("-Cpanic=abort".to_owned()); + } match cg_clif_dylib_path { CodegenBackend::Local(path) => { rustflags.push(format!("-Zcodegen-backend={}", path.to_str().unwrap())); diff --git a/build_system/main.rs b/build_system/main.rs index 3ff9751a3ef2d..fc00931283002 100644 --- a/build_system/main.rs +++ b/build_system/main.rs @@ -83,6 +83,7 @@ fn main() { let mut download_dir = None; let mut sysroot_kind = SysrootKind::Clif; let mut use_unstable_features = true; + let mut panic_unwind_support = false; let mut frozen = false; let mut skip_tests = vec![]; let mut use_backend = None; @@ -108,6 +109,7 @@ fn main() { } } "--no-unstable-features" => use_unstable_features = false, + "--panic-unwind-support" => panic_unwind_support = true, "--frozen" => frozen = true, "--skip-test" => { // FIXME check that all passed in tests actually exist @@ -201,6 +203,7 @@ fn main() { &dirs, &bootstrap_host_compiler, use_unstable_features, + panic_unwind_support, )) }; match command { @@ -212,6 +215,7 @@ fn main() { &dirs, sysroot_kind, use_unstable_features, + panic_unwind_support, &skip_tests.iter().map(|test| &**test).collect::>(), &cg_clif_dylib, &bootstrap_host_compiler, @@ -230,6 +234,7 @@ fn main() { &cg_clif_dylib, rustup_toolchain_name.as_deref(), &bootstrap_host_compiler, + panic_unwind_support, ); } Command::Build => { @@ -240,6 +245,7 @@ fn main() { &bootstrap_host_compiler, rustup_toolchain_name.as_deref(), target_triple, + panic_unwind_support, ); } Command::Bench => { @@ -250,6 +256,7 @@ fn main() { &bootstrap_host_compiler, rustup_toolchain_name.as_deref(), target_triple, + panic_unwind_support, ); bench::benchmark(&dirs, &compiler); } diff --git a/build_system/tests.rs b/build_system/tests.rs index eec89c026b26a..8cd84a79f9f74 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -233,6 +233,7 @@ pub(crate) fn run_tests( dirs: &Dirs, sysroot_kind: SysrootKind, use_unstable_features: bool, + panic_unwind_support: bool, skip_tests: &[&str], cg_clif_dylib: &CodegenBackend, bootstrap_host_compiler: &Compiler, @@ -251,12 +252,14 @@ pub(crate) fn run_tests( bootstrap_host_compiler, rustup_toolchain_name, target_triple.clone(), + panic_unwind_support, ); let runner = TestRunner::new( dirs.clone(), target_compiler, use_unstable_features, + panic_unwind_support, skip_tests, bootstrap_host_compiler.triple == target_triple, stdlib_source.clone(), @@ -283,12 +286,14 @@ pub(crate) fn run_tests( bootstrap_host_compiler, rustup_toolchain_name, target_triple.clone(), + panic_unwind_support, ); let mut runner = TestRunner::new( dirs.clone(), target_compiler, use_unstable_features, + panic_unwind_support, skip_tests, bootstrap_host_compiler.triple == target_triple, stdlib_source, @@ -314,6 +319,7 @@ pub(crate) fn run_tests( struct TestRunner<'a> { is_native: bool, jit_supported: bool, + panic_unwind_support: bool, skip_tests: &'a [&'a str], dirs: Dirs, target_compiler: Compiler, @@ -325,6 +331,7 @@ impl<'a> TestRunner<'a> { dirs: Dirs, mut target_compiler: Compiler, use_unstable_features: bool, + panic_unwind_support: bool, skip_tests: &'a [&'a str], is_native: bool, stdlib_source: PathBuf, @@ -335,7 +342,15 @@ impl<'a> TestRunner<'a> { let jit_supported = use_unstable_features && is_native && !target_compiler.triple.contains("windows"); - Self { is_native, jit_supported, skip_tests, dirs, target_compiler, stdlib_source } + Self { + is_native, + jit_supported, + panic_unwind_support, + skip_tests, + dirs, + target_compiler, + stdlib_source, + } } fn run_testsuite(&self, tests: &[TestCase]) { @@ -404,7 +419,9 @@ impl<'a> TestRunner<'a> { cmd.arg("-Cdebuginfo=2"); cmd.arg("--target"); cmd.arg(&self.target_compiler.triple); - cmd.arg("-Cpanic=abort"); + if !self.panic_unwind_support { + cmd.arg("-Cpanic=abort"); + } cmd.arg("--check-cfg=cfg(jit)"); cmd.args(args); cmd diff --git a/build_system/usage.txt b/build_system/usage.txt index 5c333fe2db596..6c98087e52399 100644 --- a/build_system/usage.txt +++ b/build_system/usage.txt @@ -25,6 +25,10 @@ OPTIONS: Some features are not yet ready for production usage. This option will disable these features. This includes the JIT mode and inline assembly support. + --panic-unwind-support + Enable support for unwinding when -Cpanic=unwind is used. This currently regresses build + performance. + --frozen Require Cargo.lock and cache are up to date diff --git a/scripts/cargo-clif.rs b/scripts/cargo-clif.rs index e6c63bf5e6508..e391cc7f75a92 100644 --- a/scripts/cargo-clif.rs +++ b/scripts/cargo-clif.rs @@ -12,7 +12,11 @@ fn main() { sysroot = sysroot.parent().unwrap(); } - let mut rustflags = vec!["-Cpanic=abort".to_owned(), "-Zpanic-abort-tests".to_owned()]; + let mut rustflags = vec![]; + if !cfg!(support_panic_unwind) { + rustflags.push("-Cpanic=abort".to_owned()); + rustflags.push("-Zpanic-abort-tests".to_owned()); + } if let Some(name) = option_env!("BUILTIN_BACKEND") { rustflags.push(format!("-Zcodegen-backend={name}")); } else { diff --git a/scripts/rustc-clif.rs b/scripts/rustc-clif.rs index 528031af82a84..15d929d0f5a51 100644 --- a/scripts/rustc-clif.rs +++ b/scripts/rustc-clif.rs @@ -17,8 +17,10 @@ fn main() { let passed_args = std::env::args_os().skip(1).collect::>(); let mut args = vec![]; - args.push(OsString::from("-Cpanic=abort")); - args.push(OsString::from("-Zpanic-abort-tests")); + if !cfg!(support_panic_unwind) { + args.push(OsString::from("-Cpanic=abort")); + args.push(OsString::from("-Zpanic-abort-tests")); + } if let Some(name) = option_env!("BUILTIN_BACKEND") { args.push(OsString::from(format!("-Zcodegen-backend={name}"))) } else { diff --git a/scripts/rustdoc-clif.rs b/scripts/rustdoc-clif.rs index 6ebe060d8bbd1..dc5bef18cda8c 100644 --- a/scripts/rustdoc-clif.rs +++ b/scripts/rustdoc-clif.rs @@ -17,8 +17,10 @@ fn main() { let passed_args = std::env::args_os().skip(1).collect::>(); let mut args = vec![]; - args.push(OsString::from("-Cpanic=abort")); - args.push(OsString::from("-Zpanic-abort-tests")); + if !cfg!(support_panic_unwind) { + args.push(OsString::from("-Cpanic=abort")); + args.push(OsString::from("-Zpanic-abort-tests")); + } if let Some(name) = option_env!("BUILTIN_BACKEND") { args.push(OsString::from(format!("-Zcodegen-backend={name}"))) } else { diff --git a/src/abi/mod.rs b/src/abi/mod.rs index fea4e73b18e39..23fe0c32895d8 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -844,7 +844,7 @@ pub(crate) fn codegen_call_with_unwind_action( fx: &mut FunctionCx<'_, '_, '_>, span: Span, func_ref: CallTarget, - unwind: UnwindAction, + mut unwind: UnwindAction, call_args: &[Value], target_block: Option, ) -> SmallVec<[Value; 2]> { @@ -856,6 +856,11 @@ pub(crate) fn codegen_call_with_unwind_action( if target_block.is_some() { assert!(fx.bcx.func.dfg.signatures[sig_ref].returns.is_empty()); } + + if cfg!(not(feature = "unwinding")) { + unwind = UnwindAction::Unreachable; + } + match unwind { UnwindAction::Continue | UnwindAction::Unreachable => { let call_inst = match func_ref { diff --git a/src/base.rs b/src/base.rs index ddc1013c25adf..9a5a575f79e3f 100644 --- a/src/base.rs +++ b/src/base.rs @@ -308,6 +308,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { } if bb_data.is_cleanup { + if cfg!(not(feature = "unwinding")) { + continue; + } + fx.bcx.set_cold_block(block); } @@ -542,13 +546,15 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { codegen_unwind_terminate(fx, source_info.span, *reason); } TerminatorKind::UnwindResume => { - let exception_ptr = fx.bcx.use_var(fx.exception_slot); - fx.lib_call( - "_Unwind_Resume", - vec![AbiParam::new(fx.pointer_type)], - vec![], - &[exception_ptr], - ); + if cfg!(feature = "unwinding") { + let exception_ptr = fx.bcx.use_var(fx.exception_slot); + fx.lib_call( + "_Unwind_Resume", + vec![AbiParam::new(fx.pointer_type)], + vec![], + &[exception_ptr], + ); + } fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap()); } TerminatorKind::Unreachable => { diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs index 940075e250e0c..ff114811975ef 100644 --- a/src/debuginfo/unwind.rs +++ b/src/debuginfo/unwind.rs @@ -37,68 +37,74 @@ impl UnwindContext { } else { gimli::DW_EH_PE_absptr }; - let code_ptr_encoding = if pic_eh_frame { - if module.isa().triple().architecture == target_lexicon::Architecture::X86_64 { - gimli::DwEhPe( - gimli::DW_EH_PE_indirect.0 - | gimli::DW_EH_PE_pcrel.0 - | gimli::DW_EH_PE_sdata4.0, - ) - } else if let target_lexicon::Architecture::Aarch64(_) = - module.isa().triple().architecture - { - gimli::DwEhPe( - gimli::DW_EH_PE_indirect.0 - | gimli::DW_EH_PE_pcrel.0 - | gimli::DW_EH_PE_sdata8.0, - ) - } else { - todo!() - } - } else { - gimli::DwEhPe(gimli::DW_EH_PE_indirect.0 | gimli::DW_EH_PE_absptr.0) - }; cie.fde_address_encoding = ptr_encoding; - cie.lsda_encoding = Some(ptr_encoding); - - // FIXME use eh_personality lang item instead - let personality = module - .declare_function( - "rust_eh_personality", - Linkage::Import, - &Signature { - params: vec![ - AbiParam::new(types::I32), - AbiParam::new(types::I32), - AbiParam::new(types::I64), - AbiParam::new(module.target_config().pointer_type()), - AbiParam::new(module.target_config().pointer_type()), - ], - returns: vec![AbiParam::new(types::I32)], - call_conv: module.target_config().default_call_conv, - }, - ) - .unwrap(); - - // Use indirection here to support PIC the case where rust_eh_personality is defined in - // another DSO. - let personality_ref = module - .declare_data("DW.ref.rust_eh_personality", Linkage::Local, false, false) - .unwrap(); - - let mut personality_ref_data = DataDescription::new(); - // Note: Must not use define_zeroinit. The unwinder can't handle this being in the .bss - // section. - let pointer_bytes = usize::from(module.target_config().pointer_bytes()); - personality_ref_data.define(vec![0; pointer_bytes].into_boxed_slice()); - let personality_func_ref = - module.declare_func_in_data(personality, &mut personality_ref_data); - personality_ref_data.write_function_addr(0, personality_func_ref); - - module.define_data(personality_ref, &personality_ref_data).unwrap(); - - cie.personality = Some((code_ptr_encoding, address_for_data(personality_ref))); + + // FIXME only add personality function and lsda when necessary: https://github.com/rust-lang/rust/blob/1f76d219c906f0112bb1872f33aa977164c53fa6/compiler/rustc_codegen_ssa/src/mir/mod.rs#L200-L204 + if cfg!(feature = "unwinding") { + let code_ptr_encoding = if pic_eh_frame { + if module.isa().triple().architecture == target_lexicon::Architecture::X86_64 { + gimli::DwEhPe( + gimli::DW_EH_PE_indirect.0 + | gimli::DW_EH_PE_pcrel.0 + | gimli::DW_EH_PE_sdata4.0, + ) + } else if let target_lexicon::Architecture::Aarch64(_) = + module.isa().triple().architecture + { + gimli::DwEhPe( + gimli::DW_EH_PE_indirect.0 + | gimli::DW_EH_PE_pcrel.0 + | gimli::DW_EH_PE_sdata8.0, + ) + } else { + todo!() + } + } else { + gimli::DwEhPe(gimli::DW_EH_PE_indirect.0 | gimli::DW_EH_PE_absptr.0) + }; + + cie.lsda_encoding = Some(ptr_encoding); + + // FIXME use eh_personality lang item instead + let personality = module + .declare_function( + "rust_eh_personality", + Linkage::Import, + &Signature { + params: vec![ + AbiParam::new(types::I32), + AbiParam::new(types::I32), + AbiParam::new(types::I64), + AbiParam::new(module.target_config().pointer_type()), + AbiParam::new(module.target_config().pointer_type()), + ], + returns: vec![AbiParam::new(types::I32)], + call_conv: module.target_config().default_call_conv, + }, + ) + .unwrap(); + + // Use indirection here to support PIC the case where rust_eh_personality is defined in + // another DSO. + let personality_ref = module + .declare_data("DW.ref.rust_eh_personality", Linkage::Local, false, false) + .unwrap(); + + let mut personality_ref_data = DataDescription::new(); + // Note: Must not use define_zeroinit. The unwinder can't handle this being in the .bss + // section. + let pointer_bytes = usize::from(module.target_config().pointer_bytes()); + personality_ref_data.define(vec![0; pointer_bytes].into_boxed_slice()); + let personality_func_ref = + module.declare_func_in_data(personality, &mut personality_ref_data); + personality_ref_data.write_function_addr(0, personality_func_ref); + + module.define_data(personality_ref, &personality_ref_data).unwrap(); + + cie.personality = Some((code_ptr_encoding, address_for_data(personality_ref))); + } + Some(frame_table.add_cie(cie)) } else { None @@ -134,88 +140,93 @@ impl UnwindContext { match unwind_info { UnwindInfo::SystemV(unwind_info) => { let mut fde = unwind_info.to_fde(address_for_func(func_id)); - // FIXME use unique symbol name derived from function name - let lsda = module.declare_anonymous_data(false, false).unwrap(); - let encoding = Encoding { - format: Format::Dwarf32, - version: 1, - address_size: module.isa().frontend_config().pointer_bytes(), - }; + // FIXME only add personality function and lsda when necessary: https://github.com/rust-lang/rust/blob/1f76d219c906f0112bb1872f33aa977164c53fa6/compiler/rustc_codegen_ssa/src/mir/mod.rs#L200-L204 + if cfg!(feature = "unwinding") { + // FIXME use unique symbol name derived from function name + let lsda = module.declare_anonymous_data(false, false).unwrap(); - let mut gcc_except_table_data = GccExceptTable { - call_sites: CallSiteTable(vec![]), - actions: ActionTable::new(), - type_info: TypeInfoTable::new(gimli::DW_EH_PE_udata4), - }; + let encoding = Encoding { + format: Format::Dwarf32, + version: 1, + address_size: module.isa().frontend_config().pointer_bytes(), + }; - let catch_type = gcc_except_table_data.type_info.add(Address::Constant(0)); - let catch_action = gcc_except_table_data - .actions - .add(Action { kind: ActionKind::Catch(catch_type), next_action: None }); - - for call_site in context.compiled_code().unwrap().buffer.call_sites() { - if call_site.exception_handlers.is_empty() { - gcc_except_table_data.call_sites.0.push(CallSite { - start: u64::from(call_site.ret_addr - 1), - length: 1, - landing_pad: 0, - action_entry: None, - }); - } - for &(tag, landingpad) in call_site.exception_handlers { - match tag.expand().unwrap().as_u32() { - EXCEPTION_HANDLER_CLEANUP => { - gcc_except_table_data.call_sites.0.push(CallSite { - start: u64::from(call_site.ret_addr - 1), - length: 1, - landing_pad: u64::from(landingpad), - action_entry: None, - }) - } - EXCEPTION_HANDLER_CATCH => { - gcc_except_table_data.call_sites.0.push(CallSite { - start: u64::from(call_site.ret_addr - 1), - length: 1, - landing_pad: u64::from(landingpad), - action_entry: Some(catch_action), - }) + let mut gcc_except_table_data = GccExceptTable { + call_sites: CallSiteTable(vec![]), + actions: ActionTable::new(), + type_info: TypeInfoTable::new(gimli::DW_EH_PE_udata4), + }; + + let catch_type = gcc_except_table_data.type_info.add(Address::Constant(0)); + let catch_action = gcc_except_table_data + .actions + .add(Action { kind: ActionKind::Catch(catch_type), next_action: None }); + + for call_site in context.compiled_code().unwrap().buffer.call_sites() { + if call_site.exception_handlers.is_empty() { + gcc_except_table_data.call_sites.0.push(CallSite { + start: u64::from(call_site.ret_addr - 1), + length: 1, + landing_pad: 0, + action_entry: None, + }); + } + for &(tag, landingpad) in call_site.exception_handlers { + match tag.expand().unwrap().as_u32() { + EXCEPTION_HANDLER_CLEANUP => { + gcc_except_table_data.call_sites.0.push(CallSite { + start: u64::from(call_site.ret_addr - 1), + length: 1, + landing_pad: u64::from(landingpad), + action_entry: None, + }) + } + EXCEPTION_HANDLER_CATCH => { + gcc_except_table_data.call_sites.0.push(CallSite { + start: u64::from(call_site.ret_addr - 1), + length: 1, + landing_pad: u64::from(landingpad), + action_entry: Some(catch_action), + }) + } + _ => unreachable!(), } - _ => unreachable!(), } } - } - let mut gcc_except_table = super::emit::WriterRelocate::new(self.endian); - - gcc_except_table_data.write(&mut gcc_except_table, encoding).unwrap(); - - let mut data = DataDescription::new(); - data.define(gcc_except_table.writer.into_vec().into_boxed_slice()); - data.set_segment_section("", ".gcc_except_table"); - - for reloc in &gcc_except_table.relocs { - match reloc.name { - DebugRelocName::Section(_id) => unreachable!(), - DebugRelocName::Symbol(id) => { - let id = id.try_into().unwrap(); - if id & 1 << 31 == 0 { - let func_ref = - module.declare_func_in_data(FuncId::from_u32(id), &mut data); - data.write_function_addr(reloc.offset, func_ref); - } else { - let gv = module.declare_data_in_data( - DataId::from_u32(id & !(1 << 31)), - &mut data, - ); - data.write_data_addr(reloc.offset, gv, 0); + let mut gcc_except_table = super::emit::WriterRelocate::new(self.endian); + + gcc_except_table_data.write(&mut gcc_except_table, encoding).unwrap(); + + let mut data = DataDescription::new(); + data.define(gcc_except_table.writer.into_vec().into_boxed_slice()); + data.set_segment_section("", ".gcc_except_table"); + + for reloc in &gcc_except_table.relocs { + match reloc.name { + DebugRelocName::Section(_id) => unreachable!(), + DebugRelocName::Symbol(id) => { + let id = id.try_into().unwrap(); + if id & 1 << 31 == 0 { + let func_ref = module + .declare_func_in_data(FuncId::from_u32(id), &mut data); + data.write_function_addr(reloc.offset, func_ref); + } else { + let gv = module.declare_data_in_data( + DataId::from_u32(id & !(1 << 31)), + &mut data, + ); + data.write_data_addr(reloc.offset, gv, 0); + } } - } - }; + }; + } + + module.define_data(lsda, &data).unwrap(); + fde.lsda = Some(address_for_data(lsda)); } - module.define_data(lsda, &data).unwrap(); - fde.lsda = Some(address_for_data(lsda)); self.frame_table.add_fde(self.cie_id.unwrap(), fde); } UnwindInfo::WindowsX64(_) | UnwindInfo::WindowsArm64(_) => { diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index da740cb88e415..1fcd5871476c6 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -1367,7 +1367,9 @@ fn codegen_regular_intrinsic_call<'tcx>( returns: vec![], }); - if fx.tcx.sess.panic_strategy() == PanicStrategy::Abort { + if cfg!(not(feature = "unwinding")) + || fx.tcx.sess.panic_strategy() == PanicStrategy::Abort + { fx.bcx.ins().call_indirect(f_sig, f, &[data]); let layout = fx.layout_of(fx.tcx.types.i32); From c02a509168352da21fb065f8d8bc392350730c21 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 26 May 2025 09:51:17 +0000 Subject: [PATCH 016/160] Update readme --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 4d1e4d843ffeb..9989cc7e7eaf5 100644 --- a/Readme.md +++ b/Readme.md @@ -104,7 +104,7 @@ See [rustc_testing.md](docs/rustc_testing.md). ## Not yet supported * SIMD ([tracked here](https://github.com/rust-lang/rustc_codegen_cranelift/issues/171), `std::simd` fully works, `std::arch` is partially supported) -* Unwinding on panics ([no cranelift support](https://github.com/bytecodealliance/wasmtime/issues/1677), `-Cpanic=abort` is enabled by default) +* Unwinding on panics ([experimental and not supported on Windows and macOS](https://github.com/rust-lang/rustc_codegen_cranelift/issues/1567), `-Cpanic=abort` is enabled by default) ## License From b3eb17c1151f1666f9f36afb603ea75cdc3ac9e0 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 1 Jul 2025 07:59:41 +0000 Subject: [PATCH 017/160] Rustup to rustc 1.90.0-nightly (f26e58023 2025-06-30) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 57b45c7706b18..78dfd8d1f9fce 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-06-26" +channel = "nightly-2025-07-01" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 2eccb7a5f8e08d551c3b09deaa318609f1e3497b Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 1 Jul 2025 08:21:45 +0000 Subject: [PATCH 018/160] Fix rustc test suite --- 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 7e356b4b462b2..f9a3fc85de450 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -34,6 +34,7 @@ git checkout -- tests/ui/entry-point/auxiliary/bad_main_functions.rs # vendor intrinsics rm tests/ui/asm/x86_64/evex512-implicit-feature.rs # unimplemented AVX512 x86 vendor intrinsic rm tests/ui/simd/dont-invalid-bitcast-x86_64.rs # unimplemented llvm.x86.sse41.round.ps +rm tests/ui/simd/intrinsic/generic-arithmetic-pass.rs # unimplemented simd_funnel_{shl,shr} # exotic linkages rm tests/incremental/hashes/function_interfaces.rs @@ -58,6 +59,7 @@ rm tests/ui/asm/naked-asm-mono-sym-fn.rs # same rm tests/ui/asm/x86_64/goto.rs # inline asm labels not supported rm tests/ui/simd/simd-bitmask-notpow2.rs # non-pow-of-2 simd vector sizes rm -r tests/run-make/embed-source-dwarf # embedding sources in debuginfo +rm -r tests/run-make/used-proc-macro # used(linker) isn't supported yet # requires LTO rm -r tests/run-make/cdylib From c2d7ac4717d85087caa409f7e786a366c6bbe4e2 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 1 Jul 2025 08:22:44 +0000 Subject: [PATCH 019/160] Revert enabling rustc_private for mini_core_hello_world --- example/mini_core_hello_world.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 246bd3104ec41..66ecc9ec034a2 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -1,13 +1,4 @@ -#![feature( - no_core, - lang_items, - never_type, - linkage, - extern_types, - thread_local, - repr_simd, - rustc_private -)] +#![feature(no_core, lang_items, never_type, linkage, extern_types, thread_local, repr_simd)] #![no_core] #![allow(dead_code, non_camel_case_types, internal_features)] From c4743bd2b9b2831320e758c9f74a84c32325b24c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 1 Jul 2025 08:57:02 +0000 Subject: [PATCH 020/160] Move to the 2024 edition --- Cargo.toml | 2 +- src/abi/mod.rs | 4 ++-- src/base.rs | 6 +++--- src/compiler_builtins.rs | 2 +- src/constant.rs | 2 +- src/debuginfo/emit.rs | 2 +- src/debuginfo/unwind.rs | 6 +++--- src/lib.rs | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 51bb5d9db0ea6..a1f406df8c259 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rustc_codegen_cranelift" version = "0.1.0" -edition = "2021" +edition = "2024" [lib] crate-type = ["dylib"] diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 23fe0c32895d8..73f1485c90cda 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -268,7 +268,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_ // individual function arguments. let tupled_arg_tys = match arg_ty.kind() { - ty::Tuple(ref tys) => tys, + ty::Tuple(tys) => tys, _ => bug!("spread argument isn't a tuple?! but {:?}", arg_ty), }; @@ -491,7 +491,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( }; let tupled_arguments = match pack_arg.value.layout().ty.kind() { - ty::Tuple(ref tupled_arguments) => tupled_arguments, + ty::Tuple(tupled_arguments) => tupled_arguments, _ => bug!("argument to function with \"rust-call\" ABI is not a tuple"), }; diff --git a/src/base.rs b/src/base.rs index 5f7c49f5d749b..72b17623b7854 100644 --- a/src/base.rs +++ b/src/base.rs @@ -382,7 +382,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { fx.bcx.ins().nop(); match &**msg { - AssertKind::BoundsCheck { ref len, ref index } => { + AssertKind::BoundsCheck { len, index } => { let len = codegen_operand(fx, len).load_scalar(fx); let index = codegen_operand(fx, index).load_scalar(fx); let location = fx.get_caller_location(source_info).load_scalar(fx); @@ -395,7 +395,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { source_info.span, ); } - AssertKind::MisalignedPointerDereference { ref required, ref found } => { + AssertKind::MisalignedPointerDereference { required, found } => { let required = codegen_operand(fx, required).load_scalar(fx); let found = codegen_operand(fx, found).load_scalar(fx); let location = fx.get_caller_location(source_info).load_scalar(fx); @@ -977,7 +977,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt: | StatementKind::AscribeUserType(..) => {} StatementKind::Coverage { .. } => unreachable!(), - StatementKind::Intrinsic(ref intrinsic) => match &**intrinsic { + StatementKind::Intrinsic(intrinsic) => match &**intrinsic { // We ignore `assume` intrinsics, they are only useful for optimizations NonDivergingIntrinsic::Assume(_) => {} NonDivergingIntrinsic::CopyNonOverlapping(mir::CopyNonOverlapping { diff --git a/src/compiler_builtins.rs b/src/compiler_builtins.rs index 6eea19211fa1b..d3784f8e56ace 100644 --- a/src/compiler_builtins.rs +++ b/src/compiler_builtins.rs @@ -18,7 +18,7 @@ macro_rules! builtin_functions { ) => { #[cfg(feature = "jit")] #[allow(improper_ctypes)] - extern "C" { + unsafe extern "C" { $( $(#[$attr])? fn $name($($arg_name: $arg_ty),*) -> $ret_ty; diff --git a/src/constant.rs b/src/constant.rs index ff2c0d577bb48..389c6546aaba3 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -576,7 +576,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>( { return None; } - StatementKind::Intrinsic(ref intrinsic) => match **intrinsic { + StatementKind::Intrinsic(intrinsic) => match **intrinsic { NonDivergingIntrinsic::CopyNonOverlapping(..) => return None, NonDivergingIntrinsic::Assume(..) => {} }, diff --git a/src/debuginfo/emit.rs b/src/debuginfo/emit.rs index 0f4696b9337e7..53b513ded9c46 100644 --- a/src/debuginfo/emit.rs +++ b/src/debuginfo/emit.rs @@ -96,7 +96,7 @@ impl WriterRelocate { if jit_module.declarations().get_function_decl(func_id).name.as_deref() == Some("rust_eh_personality") { - extern "C" { + unsafe extern "C" { fn rust_eh_personality() -> !; } rust_eh_personality as *const u8 diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs index ff114811975ef..02f6b1d39bc22 100644 --- a/src/debuginfo/unwind.rs +++ b/src/debuginfo/unwind.rs @@ -279,7 +279,7 @@ impl UnwindContext { // 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")] - { + unsafe { // On macOS, `__register_frame` takes a pointer to a single FDE let start = eh_frame.as_ptr(); let end = start.add(eh_frame.len()); @@ -301,12 +301,12 @@ 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.as_ptr()); + unsafe { __register_frame(eh_frame.as_ptr()) }; } } } -extern "C" { +unsafe extern "C" { // libunwind import fn __register_frame(fde: *const u8); } diff --git a/src/lib.rs b/src/lib.rs index 678580a237239..62ba9974f726b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -382,7 +382,7 @@ fn build_isa(sess: &Session, jit: bool) -> Arc { } /// This is the entrypoint for a hot plugged rustc_codegen_cranelift -#[no_mangle] +#[unsafe(no_mangle)] pub fn __rustc_codegen_backend() -> Box { Box::new(CraneliftCodegenBackend { config: None }) } From b87f756d4d5dfa3cdfd3c79d2ac6d1810fe3c948 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 1 Jul 2025 08:57:27 +0000 Subject: [PATCH 021/160] Fix building std_detect on s390x --- src/inline_asm.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 5f4956c801bea..95c249f5af1f7 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -51,6 +51,26 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>( return; } + if fx.tcx.sess.target.arch == "s390x" + && template.len() == 3 + && template[0] == InlineAsmTemplatePiece::String("stfle 0(".into()) + && let InlineAsmTemplatePiece::Placeholder { operand_idx: 0, modifier: None, span: _ } = + template[1] + && template[2] == InlineAsmTemplatePiece::String(")".into()) + { + // FIXME no inline asm support for s390x yet, but stdarch needs it for feature detection + match destination { + Some(destination) => { + let destination_block = fx.get_block(destination); + fx.bcx.ins().jump(destination_block, &[]); + } + None => { + fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap()); + } + } + return; + } + let operands = operands .iter() .map(|operand| match *operand { From ef78e985fbf350d1df42eadb3fc9a03155a4eb9e Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 26 Jun 2025 02:01:38 +0000 Subject: [PATCH 022/160] Remove support for dyn* --- src/abi/mod.rs | 45 ------------------------------------------ src/base.rs | 8 -------- src/unsize.rs | 33 ------------------------------- src/value_and_place.rs | 37 ---------------------------------- src/vtable.rs | 40 +++++++++++++------------------------ 5 files changed, 14 insertions(+), 149 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 4c6fd90781543..8965e4a944d48 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -753,51 +753,6 @@ pub(crate) fn codegen_drop<'tcx>( fx.bcx.ins().call_indirect(sig, drop_fn, &[ptr]); fx.bcx.ins().jump(ret_block, &[]); } - ty::Dynamic(_, _, ty::DynStar) => { - // IN THIS ARM, WE HAVE: - // ty = *mut (dyn* Trait) - // which is: *mut exists (T, Vtable) - // - // args = [ * ] - // | - // v - // ( Data, Vtable ) - // | - // v - // /-------\ - // | ... | - // \-------/ - // - // - // WE CAN CONVERT THIS INTO THE ABOVE LOGIC BY DOING - // - // data = &(*args[0]).0 // gives a pointer to Data above (really the same pointer) - // vtable = (*args[0]).1 // loads the vtable out - // (data, vtable) // an equivalent Rust `*mut dyn Trait` - // - // SO THEN WE CAN USE THE ABOVE CODE. - let (data, vtable) = drop_place.to_cvalue(fx).dyn_star_force_data_on_stack(fx); - let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable); - - let is_null = fx.bcx.ins().icmp_imm(IntCC::Equal, drop_fn, 0); - let target_block = fx.get_block(target); - let continued = fx.bcx.create_block(); - fx.bcx.ins().brif(is_null, target_block, &[], continued, &[]); - fx.bcx.switch_to_block(continued); - - let virtual_drop = Instance { - def: ty::InstanceKind::Virtual(drop_instance.def_id(), 0), - args: drop_instance.args, - }; - let fn_abi = FullyMonomorphizedLayoutCx(fx.tcx) - .fn_abi_of_instance(virtual_drop, ty::List::empty()); - - let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi); - let sig = fx.bcx.import_signature(sig); - fx.bcx.ins().call_indirect(sig, drop_fn, &[data]); - // FIXME implement cleanup on exceptions - fx.bcx.ins().jump(ret_block, &[]); - } _ => { assert!(!matches!(drop_instance.def, InstanceKind::Virtual(_, _))); diff --git a/src/base.rs b/src/base.rs index 1b68c6535da5f..bc0a0f034b236 100644 --- a/src/base.rs +++ b/src/base.rs @@ -790,14 +790,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt: let operand = codegen_operand(fx, operand); crate::unsize::coerce_unsized_into(fx, operand, lval); } - Rvalue::Cast( - CastKind::PointerCoercion(PointerCoercion::DynStar, _), - ref operand, - _, - ) => { - let operand = codegen_operand(fx, operand); - crate::unsize::coerce_dyn_star(fx, operand, lval); - } Rvalue::Cast(CastKind::Transmute, ref operand, _to_ty) => { let operand = codegen_operand(fx, operand); lval.write_cvalue_transmute(fx, operand); diff --git a/src/unsize.rs b/src/unsize.rs index df60b05c4636c..2aee0b2e97424 100644 --- a/src/unsize.rs +++ b/src/unsize.rs @@ -112,21 +112,6 @@ fn unsize_ptr<'tcx>( } } -/// Coerces `src` to `dst_ty` which is guaranteed to be a `dyn*` type. -pub(crate) fn cast_to_dyn_star<'tcx>( - fx: &mut FunctionCx<'_, '_, 'tcx>, - src: Value, - src_ty_and_layout: TyAndLayout<'tcx>, - dst_ty: Ty<'tcx>, - old_info: Option, -) -> (Value, Value) { - assert!( - matches!(dst_ty.kind(), ty::Dynamic(_, _, ty::DynStar)), - "destination type must be a dyn*" - ); - (src, unsized_info(fx, src_ty_and_layout.ty, dst_ty, old_info)) -} - /// Coerce `src`, which is a reference to a value of type `src_ty`, /// to a value of type `dst_ty` and store the result in `dst` pub(crate) fn coerce_unsized_into<'tcx>( @@ -174,24 +159,6 @@ pub(crate) fn coerce_unsized_into<'tcx>( } } -pub(crate) fn coerce_dyn_star<'tcx>( - fx: &mut FunctionCx<'_, '_, 'tcx>, - src: CValue<'tcx>, - dst: CPlace<'tcx>, -) { - let (data, extra) = if let ty::Dynamic(_, _, ty::DynStar) = src.layout().ty.kind() { - let (data, vtable) = src.load_scalar_pair(fx); - (data, Some(vtable)) - } else { - let data = src.load_scalar(fx); - (data, None) - }; - - let (data, vtable) = cast_to_dyn_star(fx, data, src.layout(), dst.layout().ty, extra); - - dst.write_cvalue(fx, CValue::by_val_pair(data, vtable, dst.layout())); -} - // Adapted from https://github.com/rust-lang/rust/blob/2a663555ddf36f6b041445894a8c175cd1bc718c/src/librustc_codegen_ssa/glue.rs pub(crate) fn size_and_align_of<'tcx>( diff --git a/src/value_and_place.rs b/src/value_and_place.rs index cbfb215a892a4..9d73f200afe2b 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -121,43 +121,6 @@ impl<'tcx> CValue<'tcx> { } } - // FIXME remove - /// Forces the data value of a dyn* value to the stack and returns a pointer to it as well as the - /// vtable pointer. - pub(crate) fn dyn_star_force_data_on_stack( - self, - fx: &mut FunctionCx<'_, '_, 'tcx>, - ) -> (Value, Value) { - assert!(self.1.ty.is_dyn_star()); - - match self.0 { - CValueInner::ByRef(ptr, None) => { - let (a_scalar, b_scalar) = match self.1.backend_repr { - BackendRepr::ScalarPair(a, b) => (a, b), - _ => unreachable!("dyn_star_force_data_on_stack({:?})", self), - }; - let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar); - let clif_ty2 = scalar_to_clif_type(fx.tcx, b_scalar); - let mut flags = MemFlags::new(); - flags.set_notrap(); - let vtable = ptr.offset(fx, b_offset).load(fx, clif_ty2, flags); - (ptr.get_addr(fx), vtable) - } - CValueInner::ByValPair(data, vtable) => { - let data_ptr = fx.create_stack_slot( - u32::try_from(fx.target_config.pointer_type().bytes()).unwrap(), - u32::try_from(fx.target_config.pointer_type().bytes()).unwrap(), - ); - data_ptr.store(fx, data, MemFlags::trusted()); - - (data_ptr.get_addr(fx), vtable) - } - CValueInner::ByRef(_, Some(_)) | CValueInner::ByVal(_) => { - unreachable!("dyn_star_force_data_on_stack({:?})", self) - } - } - } - pub(crate) fn try_to_ptr(self) -> Option<(Pointer, Option)> { match self.0 { CValueInner::ByRef(ptr, meta) => Some((ptr, meta)), diff --git a/src/vtable.rs b/src/vtable.rs index 1fae56949bc05..423cc8d225be1 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -46,34 +46,22 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>( mut arg: CValue<'tcx>, idx: usize, ) -> (Pointer, Value) { - let (ptr, vtable) = 'block: { - if let BackendRepr::Scalar(_) = arg.layout().backend_repr { - while !arg.layout().ty.is_raw_ptr() && !arg.layout().ty.is_ref() { - let (idx, _) = arg - .layout() - .non_1zst_field(fx) - .expect("not exactly one non-1-ZST field in a `DispatchFromDyn` type"); - arg = arg.value_field(fx, idx); - } - } - - if let ty::Ref(_, ty, _) = arg.layout().ty.kind() { - if ty.is_dyn_star() { - let inner_layout = fx.layout_of(arg.layout().ty.builtin_deref(true).unwrap()); - let dyn_star = CPlace::for_ptr(Pointer::new(arg.load_scalar(fx)), inner_layout); - let ptr = dyn_star.place_field(fx, FieldIdx::ZERO).to_ptr(); - let vtable = dyn_star.place_field(fx, FieldIdx::ONE).to_cvalue(fx).load_scalar(fx); - break 'block (ptr, vtable); - } + if let BackendRepr::Scalar(_) = arg.layout().backend_repr { + while !arg.layout().ty.is_raw_ptr() && !arg.layout().ty.is_ref() { + let (idx, _) = arg + .layout() + .non_1zst_field(fx) + .expect("not exactly one non-1-ZST field in a `DispatchFromDyn` type"); + arg = arg.value_field(fx, idx); } + } - if let BackendRepr::ScalarPair(_, _) = arg.layout().backend_repr { - let (ptr, vtable) = arg.load_scalar_pair(fx); - (Pointer::new(ptr), vtable) - } else { - let (ptr, vtable) = arg.try_to_ptr().unwrap(); - (ptr, vtable.unwrap()) - } + let (ptr, vtable) = if let BackendRepr::ScalarPair(_, _) = arg.layout().backend_repr { + let (ptr, vtable) = arg.load_scalar_pair(fx); + (Pointer::new(ptr), vtable) + } else { + let (ptr, vtable) = arg.try_to_ptr().unwrap(); + (ptr, vtable.unwrap()) }; let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes(); From 2f9af6b67401f5664e6c4033c9a9bc3f77bdea4c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 2 Jul 2025 13:10:48 +0000 Subject: [PATCH 023/160] Rustup to rustc 1.90.0-nightly (71e4c005c 2025-07-01) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 78dfd8d1f9fce..2c6ecd32c7c82 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-07-01" +channel = "nightly-2025-07-02" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From a0c1a29f58acd1cb2cab3526a2ae924fddc2eada Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 3 Jul 2025 08:55:34 +0000 Subject: [PATCH 024/160] Rustup to rustc 1.90.0-nightly (667787527 2025-07-02) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 2c6ecd32c7c82..56d1bda88ca65 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-07-02" +channel = "nightly-2025-07-03" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 588c630b79c9446ee0145eb7cd33408032f7a950 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 3 Jul 2025 10:15:26 +0000 Subject: [PATCH 025/160] Escape { and } before passing to global_asm!() --- src/global_asm.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/global_asm.rs b/src/global_asm.rs index db40d84be0aa5..cbb4c3131b2c4 100644 --- a/src/global_asm.rs +++ b/src/global_asm.rs @@ -202,6 +202,9 @@ pub(crate) fn compile_global_asm( return Err(format!("Failed to assemble `{}`", global_asm)); } } else { + // Escape { and } + let global_asm = global_asm.replace('{', "{{").replace('}', "}}"); + let mut child = Command::new(std::env::current_exe().unwrap()) // Avoid a warning about the jobserver fd not being passed .env_remove("CARGO_MAKEFLAGS") From 868d953b7a13bbc1ebf1635ff6c5fddaed441050 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 3 Jul 2025 10:16:13 +0000 Subject: [PATCH 026/160] Avoid q modifier for user references to arm64 vector registers It should only be necessary for the clobber save/restore sequences. --- src/inline_asm.rs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 95c249f5af1f7..eec8b08a1bcd9 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -568,20 +568,6 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { .emit(&mut generated_asm, InlineAsmArch::X86_64, *modifier) .unwrap(), }, - InlineAsmArch::AArch64 => match reg { - InlineAsmReg::AArch64(reg) if reg.vreg_index().is_some() => { - // rustc emits v0 rather than q0 - reg.emit( - &mut generated_asm, - InlineAsmArch::AArch64, - Some(modifier.unwrap_or('q')), - ) - .unwrap() - } - _ => reg - .emit(&mut generated_asm, InlineAsmArch::AArch64, *modifier) - .unwrap(), - }, _ => reg.emit(&mut generated_asm, self.arch, *modifier).unwrap(), } } From de58bdc3db9ca033adafcf9c798e227ffd0f8559 Mon Sep 17 00:00:00 2001 From: Daniel Paoliello Date: Thu, 3 Jul 2025 09:17:48 -0700 Subject: [PATCH 027/160] Make __rust_alloc_error_handler_should_panic a function --- src/allocator.rs | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index ffb932a3c38e6..04f1129d87c1f 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -84,19 +84,34 @@ fn codegen_inner( &mangle_internal_symbol(tcx, alloc_error_handler_name(alloc_error_handler_kind)), ); - let data_id = module - .declare_data( - &mangle_internal_symbol(tcx, OomStrategy::SYMBOL), - Linkage::Export, - false, - false, - ) - .unwrap(); - let mut data = DataDescription::new(); - data.set_align(1); - let val = oom_strategy.should_panic(); - data.define(Box::new([val])); - module.define_data(data_id, &data).unwrap(); + { + let sig = Signature { + call_conv: module.target_config().default_call_conv, + params: vec![], + returns: vec![AbiParam::new(types::I8)], + }; + let func_id = module + .declare_function( + &mangle_internal_symbol(tcx, OomStrategy::SYMBOL), + Linkage::Export, + &sig, + ) + .unwrap(); + let mut ctx = Context::new(); + ctx.func.signature = sig; + { + let mut func_ctx = FunctionBuilderContext::new(); + let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx); + + let block = bcx.create_block(); + bcx.switch_to_block(block); + let value = bcx.ins().iconst(types::I8, oom_strategy.should_panic() as i64); + bcx.ins().return_(&[value]); + bcx.seal_all_blocks(); + bcx.finalize(); + } + module.define_function(func_id, &mut ctx).unwrap(); + } { let sig = Signature { From d24852f515c98fb39b2fda3b52968400d27c55c7 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 7 Jan 2025 15:19:57 +0000 Subject: [PATCH 028/160] Migrate all tests to the 2024 edition --- .vscode/settings.json | 6 +-- build_system/tests.rs | 11 +---- example/example.rs | 16 +++--- example/mini_core.rs | 22 +++++---- example/mini_core_hello_world.rs | 85 +++++++++++++++++--------------- 5 files changed, 73 insertions(+), 67 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 68bd93aea8901..2a3ec5e1c905a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,13 +20,13 @@ "crates": [ { "root_module": "./example/mini_core.rs", - "edition": "2015", + "edition": "2024", "deps": [], "cfg": [], }, { "root_module": "./example/mini_core_hello_world.rs", - "edition": "2015", + "edition": "2024", "deps": [ { "crate": 0, @@ -37,7 +37,7 @@ }, { "root_module": "./example/std_example.rs", - "edition": "2015", + "edition": "2024", "deps": [], "cfg": [], }, diff --git a/build_system/tests.rs b/build_system/tests.rs index 8cd84a79f9f74..3c22450a15f62 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -89,15 +89,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ TestCase::build_bin_and_run("aot.issue-72793", "example/issue-72793.rs", &[]), TestCase::build_bin("aot.issue-59326", "example/issue-59326.rs"), TestCase::build_bin_and_run("aot.neon", "example/neon.rs", &[]), - TestCase::custom("aot.gen_block_iterate", &|runner| { - runner.run_rustc([ - "example/gen_block_iterate.rs", - "--edition", - "2024", - "-Zunstable-options", - ]); - runner.run_out_command("gen_block_iterate", &[]); - }), + TestCase::build_bin_and_run("aot.gen_block_iterate", "example/gen_block_iterate.rs", &[]), TestCase::build_bin_and_run("aot.raw-dylib", "example/raw-dylib.rs", &[]), TestCase::custom("test.sysroot", &|runner| { apply_patches( @@ -423,6 +415,7 @@ impl<'a> TestRunner<'a> { cmd.arg("-Cpanic=abort"); } cmd.arg("--check-cfg=cfg(jit)"); + cmd.arg("--edition=2024"); cmd.args(args); cmd } diff --git a/example/example.rs b/example/example.rs index aeb38331edb02..e86bb8f59339c 100644 --- a/example/example.rs +++ b/example/example.rs @@ -81,12 +81,16 @@ pub fn use_size_of() -> usize { } pub unsafe fn use_copy_intrinsic(src: *const u8, dst: *mut u8) { - intrinsics::copy::(src, dst, 1); + unsafe { + intrinsics::copy::(src, dst, 1); + } } pub unsafe fn use_copy_intrinsic_ref(src: *const u8, dst: *mut u8) { - let copy2 = &intrinsics::copy::; - copy2(src, dst, 1); + unsafe { + let copy2 = &intrinsics::copy::; + copy2(src, dst, 1); + } } pub const ABC: u8 = 6 * 7; @@ -130,11 +134,11 @@ pub fn eq_char(a: char, b: char) -> bool { } pub unsafe fn transmute(c: char) -> u32 { - intrinsics::transmute(c) + unsafe { intrinsics::transmute(c) } } pub unsafe fn deref_str_ptr(s: *const str) -> &'static str { - &*s + unsafe { &*s } } pub fn use_array(arr: [u8; 3]) -> u8 { @@ -150,7 +154,7 @@ pub fn array_as_slice(arr: &[u8; 3]) -> &[u8] { } pub unsafe fn use_ctlz_nonzero(a: u16) -> u32 { - intrinsics::ctlz_nonzero(a) + unsafe { intrinsics::ctlz_nonzero(a) } } pub fn ptr_as_usize(ptr: *const u8) -> usize { diff --git a/example/mini_core.rs b/example/mini_core.rs index 2f53bbf8b7934..3f846d393ba64 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -545,7 +545,7 @@ fn panic_in_cleanup() -> ! { #[cfg(all(unix, not(target_vendor = "apple")))] #[link(name = "gcc_s")] -extern "C" { +unsafe extern "C" { fn _Unwind_Resume(exc: *mut ()) -> !; } @@ -554,7 +554,9 @@ extern "C" { pub unsafe fn drop_in_place(to_drop: *mut T) { // Code here does not matter - this is replaced by the // real drop glue by the compiler. - drop_in_place(to_drop); + unsafe { + drop_in_place(to_drop); + } } #[lang = "unpin"] @@ -621,7 +623,7 @@ impl Deref for Box { #[lang = "exchange_malloc"] unsafe fn allocate(size: usize, _align: usize) -> *mut u8 { - libc::malloc(size) + unsafe { libc::malloc(size) } } #[lang = "drop"] @@ -648,11 +650,11 @@ pub mod intrinsics { #[rustc_intrinsic] pub fn size_of() -> usize; #[rustc_intrinsic] - pub unsafe fn size_of_val(val: *const T) -> usize; + pub unsafe fn size_of_val(val: *const T) -> usize; #[rustc_intrinsic] pub fn align_of() -> usize; #[rustc_intrinsic] - pub unsafe fn align_of_val(val: *const T) -> usize; + pub unsafe fn align_of_val(val: *const T) -> usize; #[rustc_intrinsic] pub unsafe fn copy(src: *const T, dst: *mut T, count: usize); #[rustc_intrinsic] @@ -660,7 +662,7 @@ pub mod intrinsics { #[rustc_intrinsic] pub unsafe fn ctlz_nonzero(x: T) -> u32; #[rustc_intrinsic] - pub const fn needs_drop() -> bool; + pub const fn needs_drop() -> bool; #[rustc_intrinsic] pub fn bitreverse(x: T) -> T; #[rustc_intrinsic] @@ -677,13 +679,13 @@ pub mod libc { // symbols to link against. #[cfg_attr(unix, link(name = "c"))] #[cfg_attr(target_env = "msvc", link(name = "legacy_stdio_definitions"))] - extern "C" { + unsafe extern "C" { pub fn printf(format: *const i8, ...) -> i32; } #[cfg_attr(unix, link(name = "c"))] #[cfg_attr(target_env = "msvc", link(name = "msvcrt"))] - extern "C" { + unsafe extern "C" { pub fn puts(s: *const i8) -> i32; pub fn malloc(size: usize) -> *mut u8; pub fn free(ptr: *mut u8); @@ -715,7 +717,7 @@ impl Index for [T] { } } -extern "C" { +unsafe extern "C" { type VaListImpl; } @@ -774,7 +776,7 @@ struct PanicLocation { column: u32, } -#[no_mangle] +#[unsafe(no_mangle)] #[cfg(not(all(windows, target_env = "gnu")))] pub fn get_tls() -> u8 { #[thread_local] diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 66ecc9ec034a2..3a5bcc55584fb 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -115,9 +115,11 @@ static mut NUM: u8 = 6 * 7; static NUM_REF: &'static u8 = unsafe { &*&raw const NUM }; unsafe fn zeroed() -> T { - let mut uninit = MaybeUninit { uninit: () }; - intrinsics::write_bytes(&mut uninit.value.value as *mut T, 0, 1); - uninit.value.value + unsafe { + let mut uninit = MaybeUninit { uninit: () }; + intrinsics::write_bytes(&mut uninit.value.value as *mut T, 0, 1); + uninit.value.value + } } fn take_f32(_f: f32) {} @@ -228,7 +230,7 @@ fn main() { } unsafe fn uninitialized() -> T { - MaybeUninit { uninit: () }.value.value + unsafe { MaybeUninit { uninit: () }.value.value } } zeroed::<(u8, u8)>(); @@ -261,20 +263,20 @@ fn main() { let x = &[0u32, 42u32] as &[u32]; match x { [] => assert_eq!(0u32, 1), - [_, ref y @ ..] => assert_eq!(&x[1] as *const u32 as usize, &y[0] as *const u32 as usize), + [_, y @ ..] => assert_eq!(&x[1] as *const u32 as usize, &y[0] as *const u32 as usize), } assert_eq!(((|()| 42u8) as fn(()) -> u8)(()), 42); #[cfg(not(any(jit, target_vendor = "apple", windows)))] { - extern "C" { + unsafe extern "C" { #[linkage = "extern_weak"] static ABC: *const u8; } { - extern "C" { + unsafe extern "C" { #[linkage = "extern_weak"] static ABC: *const u8; } @@ -301,7 +303,7 @@ fn main() { check_niche_behavior(); - extern "C" { + unsafe extern "C" { type ExternType; } @@ -354,7 +356,7 @@ fn stack_val_align() { } #[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "macos")))] -extern "C" { +unsafe extern "C" { fn global_asm_test(); } @@ -402,7 +404,7 @@ struct pthread_attr_t { #[link(name = "pthread")] #[cfg(unix)] -extern "C" { +unsafe extern "C" { fn pthread_attr_init(attr: *mut pthread_attr_t) -> c_int; fn pthread_create( @@ -423,7 +425,7 @@ type HANDLE = *mut c_void; #[link(name = "msvcrt")] #[cfg(windows)] -extern "C" { +unsafe extern "C" { fn WaitForSingleObject(hHandle: LPVOID, dwMilliseconds: DWORD) -> DWORD; fn CreateThread( @@ -445,46 +447,51 @@ struct Thread { impl Thread { unsafe fn create(f: extern "C" fn(_: *mut c_void) -> *mut c_void) -> Self { - #[cfg(unix)] - { - let mut attr: pthread_attr_t = zeroed(); - let mut thread: pthread_t = 0; + unsafe { + #[cfg(unix)] + { + let mut attr: pthread_attr_t = zeroed(); + let mut thread: pthread_t = 0; - if pthread_attr_init(&mut attr) != 0 { - assert!(false); - } + if pthread_attr_init(&mut attr) != 0 { + assert!(false); + } + + if pthread_create(&mut thread, &attr, f, 0 as *mut c_void) != 0 { + assert!(false); + } - if pthread_create(&mut thread, &attr, f, 0 as *mut c_void) != 0 { - assert!(false); + Thread { handle: thread } } - Thread { handle: thread } - } + #[cfg(windows)] + { + let handle = + CreateThread(0 as *mut c_void, 0, f, 0 as *mut c_void, 0, 0 as *mut u32); - #[cfg(windows)] - { - let handle = CreateThread(0 as *mut c_void, 0, f, 0 as *mut c_void, 0, 0 as *mut u32); + if (handle as u64) == 0 { + assert!(false); + } - if (handle as u64) == 0 { - assert!(false); + Thread { handle } } - - Thread { handle } } } unsafe fn join(self) { - #[cfg(unix)] - { - let mut res = 0 as *mut c_void; - pthread_join(self.handle, &mut res); - } + unsafe { + #[cfg(unix)] + { + let mut res = 0 as *mut c_void; + pthread_join(self.handle, &mut res); + } - #[cfg(windows)] - { - // The INFINITE macro is used to signal operations that do not timeout. - let infinite = 0xffffffff; - assert!(WaitForSingleObject(self.handle, infinite) == 0); + #[cfg(windows)] + { + // The INFINITE macro is used to signal operations that do not timeout. + let infinite = 0xffffffff; + assert!(WaitForSingleObject(self.handle, infinite) == 0); + } } } } From f02793c37f5c0698b84de1e6f72b2ea4bff7d50a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 4 Jul 2025 09:47:01 +0000 Subject: [PATCH 029/160] Fix std_example on x86 --- example/std_example.rs | 158 ++++++++++++++++++++++------------------- 1 file changed, 86 insertions(+), 72 deletions(-) diff --git a/example/std_example.rs b/example/std_example.rs index 5d83066cffb88..c569ef0ef8297 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -230,51 +230,53 @@ unsafe fn test_crc32() { #[cfg(target_arch = "x86_64")] #[target_feature(enable = "sse2")] unsafe fn test_simd() { - assert!(is_x86_feature_detected!("sse2")); - - let x = _mm_setzero_si128(); - let y = _mm_set1_epi16(7); - let or = _mm_or_si128(x, y); - let cmp_eq = _mm_cmpeq_epi8(y, y); - let cmp_lt = _mm_cmplt_epi8(y, y); - - let (zero0, zero1) = std::mem::transmute::<_, (u64, u64)>(x); - assert_eq!((zero0, zero1), (0, 0)); - assert_eq!(std::mem::transmute::<_, [u16; 8]>(or), [7, 7, 7, 7, 7, 7, 7, 7]); - assert_eq!( - std::mem::transmute::<_, [u16; 8]>(cmp_eq), - [0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff] - ); - assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_lt), [0, 0, 0, 0, 0, 0, 0, 0]); - - test_mm_slli_si128(); - test_mm_movemask_epi8(); - test_mm256_movemask_epi8(); - test_mm_add_epi8(); - test_mm_add_pd(); - test_mm_cvtepi8_epi16(); - #[cfg(not(jit))] - test_mm_cvtps_epi32(); - test_mm_cvttps_epi32(); - test_mm_cvtsi128_si64(); - - test_mm_extract_epi8(); - test_mm_insert_epi16(); - test_mm_shuffle_epi8(); - - #[cfg(not(jit))] - test_mm_cmpestri(); - - test_mm256_shuffle_epi8(); - test_mm256_permute2x128_si256(); - test_mm256_permutevar8x32_epi32(); - - #[rustfmt::skip] + unsafe { + assert!(is_x86_feature_detected!("sse2")); + + let x = _mm_setzero_si128(); + let y = _mm_set1_epi16(7); + let or = _mm_or_si128(x, y); + let cmp_eq = _mm_cmpeq_epi8(y, y); + let cmp_lt = _mm_cmplt_epi8(y, y); + + let (zero0, zero1) = std::mem::transmute::<_, (u64, u64)>(x); + assert_eq!((zero0, zero1), (0, 0)); + assert_eq!(std::mem::transmute::<_, [u16; 8]>(or), [7, 7, 7, 7, 7, 7, 7, 7]); + assert_eq!( + std::mem::transmute::<_, [u16; 8]>(cmp_eq), + [0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff] + ); + assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_lt), [0, 0, 0, 0, 0, 0, 0, 0]); + + test_mm_slli_si128(); + test_mm_movemask_epi8(); + test_mm256_movemask_epi8(); + test_mm_add_epi8(); + test_mm_add_pd(); + test_mm_cvtepi8_epi16(); + #[cfg(not(jit))] + test_mm_cvtps_epi32(); + test_mm_cvttps_epi32(); + test_mm_cvtsi128_si64(); + + test_mm_extract_epi8(); + test_mm_insert_epi16(); + test_mm_shuffle_epi8(); + + #[cfg(not(jit))] + test_mm_cmpestri(); + + test_mm256_shuffle_epi8(); + test_mm256_permute2x128_si256(); + test_mm256_permutevar8x32_epi32(); + + #[rustfmt::skip] let mask1 = _mm_movemask_epi8(dbg!(_mm_setr_epi8(255u8 as i8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))); - assert_eq!(mask1, 1); + assert_eq!(mask1, 1); - #[cfg(not(jit))] - test_crc32(); + #[cfg(not(jit))] + test_crc32(); + } } #[cfg(target_arch = "x86_64")] @@ -361,7 +363,7 @@ fn assert_eq_m128i(x: std::arch::x86_64::__m128i, y: std::arch::x86_64::__m128i) #[cfg(target_arch = "x86_64")] #[target_feature(enable = "sse2")] -pub unsafe fn assert_eq_m128d(a: __m128d, b: __m128d) { +pub fn assert_eq_m128d(a: __m128d, b: __m128d) { if _mm_movemask_pd(_mm_cmpeq_pd(a, b)) != 0b11 { panic!("{:?} != {:?}", a, b); } @@ -369,15 +371,19 @@ pub unsafe fn assert_eq_m128d(a: __m128d, b: __m128d) { #[cfg(target_arch = "x86_64")] #[target_feature(enable = "avx")] -pub unsafe fn assert_eq_m256i(a: __m256i, b: __m256i) { - assert_eq!(std::mem::transmute::<_, [u64; 4]>(a), std::mem::transmute::<_, [u64; 4]>(b)) +pub fn assert_eq_m256i(a: __m256i, b: __m256i) { + unsafe { + assert_eq!(std::mem::transmute::<_, [u64; 4]>(a), std::mem::transmute::<_, [u64; 4]>(b)) + } } #[cfg(target_arch = "x86_64")] #[target_feature(enable = "sse2")] unsafe fn test_mm_cvtsi128_si64() { - let r = _mm_cvtsi128_si64(std::mem::transmute::<[i64; 2], _>([5, 0])); - assert_eq!(r, 5); + unsafe { + let r = _mm_cvtsi128_si64(std::mem::transmute::<[i64; 2], _>([5, 0])); + assert_eq!(r, 5); + } } #[cfg(target_arch = "x86_64")] @@ -445,20 +451,24 @@ unsafe fn test_mm_shuffle_epi8() { #[cfg(target_arch = "x86_64")] #[target_feature(enable = "sse4.2")] unsafe fn str_to_m128i(s: &[u8]) -> __m128i { - assert!(s.len() <= 16); - let slice = &mut [0u8; 16]; - std::ptr::copy_nonoverlapping(s.as_ptr(), slice.as_mut_ptr(), s.len()); - _mm_loadu_si128(slice.as_ptr() as *const _) + unsafe { + assert!(s.len() <= 16); + let slice = &mut [0u8; 16]; + std::ptr::copy_nonoverlapping(s.as_ptr(), slice.as_mut_ptr(), s.len()); + _mm_loadu_si128(slice.as_ptr() as *const _) + } } #[cfg(not(jit))] #[cfg(target_arch = "x86_64")] #[target_feature(enable = "sse4.2")] unsafe fn test_mm_cmpestri() { - let a = str_to_m128i(b"bar - garbage"); - let b = str_to_m128i(b"foobar"); - let i = _mm_cmpestri::<_SIDD_CMP_EQUAL_ORDERED>(a, 3, b, 6); - assert_eq!(3, i); + unsafe { + let a = str_to_m128i(b"bar - garbage"); + let b = str_to_m128i(b"foobar"); + let i = _mm_cmpestri::<_SIDD_CMP_EQUAL_ORDERED>(a, 3, b, 6); + assert_eq!(3, i); + } } #[cfg(target_arch = "x86_64")] @@ -513,35 +523,39 @@ unsafe fn test_mm256_permutevar8x32_epi32() { #[target_feature(enable = "avx2")] #[cfg(not(jit))] unsafe fn test_mm_cvtps_epi32() { - let floats: [f32; 4] = [1.5, -2.5, i32::MAX as f32 + 1.0, f32::NAN]; + unsafe { + let floats: [f32; 4] = [1.5, -2.5, i32::MAX as f32 + 1.0, f32::NAN]; - let float_vec = _mm_loadu_ps(floats.as_ptr()); - let int_vec = _mm_cvtps_epi32(float_vec); + let float_vec = _mm_loadu_ps(floats.as_ptr()); + let int_vec = _mm_cvtps_epi32(float_vec); - let mut ints: [i32; 4] = [0; 4]; - _mm_storeu_si128(ints.as_mut_ptr() as *mut __m128i, int_vec); + let mut ints: [i32; 4] = [0; 4]; + _mm_storeu_si128(ints.as_mut_ptr() as *mut __m128i, int_vec); - // this is very different from `floats.map(|f| f as i32)`! - let expected_ints: [i32; 4] = [2, -2, i32::MIN, i32::MIN]; + // this is very different from `floats.map(|f| f as i32)`! + let expected_ints: [i32; 4] = [2, -2, i32::MIN, i32::MIN]; - assert_eq!(ints, expected_ints); + assert_eq!(ints, expected_ints); + } } #[cfg(target_arch = "x86_64")] #[target_feature(enable = "avx2")] unsafe fn test_mm_cvttps_epi32() { - let floats: [f32; 4] = [1.5, -2.5, i32::MAX as f32 + 1.0, f32::NAN]; + unsafe { + let floats: [f32; 4] = [1.5, -2.5, i32::MAX as f32 + 1.0, f32::NAN]; - let float_vec = _mm_loadu_ps(floats.as_ptr()); - let int_vec = _mm_cvttps_epi32(float_vec); + let float_vec = _mm_loadu_ps(floats.as_ptr()); + let int_vec = _mm_cvttps_epi32(float_vec); - let mut ints: [i32; 4] = [0; 4]; - _mm_storeu_si128(ints.as_mut_ptr() as *mut __m128i, int_vec); + let mut ints: [i32; 4] = [0; 4]; + _mm_storeu_si128(ints.as_mut_ptr() as *mut __m128i, int_vec); - // this is very different from `floats.map(|f| f as i32)`! - let expected_ints: [i32; 4] = [1, -2, i32::MIN, i32::MIN]; + // this is very different from `floats.map(|f| f as i32)`! + let expected_ints: [i32; 4] = [1, -2, i32::MIN, i32::MIN]; - assert_eq!(ints, expected_ints); + assert_eq!(ints, expected_ints); + } } fn test_checked_mul() { From cdf5236ee8fc1c4534c3e186e0f2584cca3ea108 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 4 Jul 2025 09:55:07 +0000 Subject: [PATCH 030/160] Fix neon.rs --- example/neon.rs | 52 ++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/example/neon.rs b/example/neon.rs index 704f866e2c4f5..fb3e10a41c025 100644 --- a/example/neon.rs +++ b/example/neon.rs @@ -14,7 +14,7 @@ unsafe fn test_vpmin_s8() { let a = i8x8::from([1, -2, 3, -4, 5, 6, 7, 8]); let b = i8x8::from([0, 3, 2, 5, 4, 7, 6, 9]); let e = i8x8::from([-2, -4, 5, 7, 0, 2, 4, 6]); - let r: i8x8 = transmute(vpmin_s8(transmute(a), transmute(b))); + let r: i8x8 = unsafe { transmute(vpmin_s8(transmute(a), transmute(b))) }; assert_eq!(r, e); } @@ -23,7 +23,7 @@ unsafe fn test_vpmin_s16() { let a = i16x4::from([1, 2, 3, -4]); let b = i16x4::from([0, 3, 2, 5]); let e = i16x4::from([1, -4, 0, 2]); - let r: i16x4 = transmute(vpmin_s16(transmute(a), transmute(b))); + let r: i16x4 = unsafe { transmute(vpmin_s16(transmute(a), transmute(b))) }; assert_eq!(r, e); } @@ -32,7 +32,7 @@ unsafe fn test_vpmin_s32() { let a = i32x2::from([1, -2]); let b = i32x2::from([0, 3]); let e = i32x2::from([-2, 0]); - let r: i32x2 = transmute(vpmin_s32(transmute(a), transmute(b))); + let r: i32x2 = unsafe { transmute(vpmin_s32(transmute(a), transmute(b))) }; assert_eq!(r, e); } @@ -41,7 +41,7 @@ unsafe fn test_vpmin_u8() { let a = u8x8::from([1, 2, 3, 4, 5, 6, 7, 8]); let b = u8x8::from([0, 3, 2, 5, 4, 7, 6, 9]); let e = u8x8::from([1, 3, 5, 7, 0, 2, 4, 6]); - let r: u8x8 = transmute(vpmin_u8(transmute(a), transmute(b))); + let r: u8x8 = unsafe { transmute(vpmin_u8(transmute(a), transmute(b))) }; assert_eq!(r, e); } @@ -50,7 +50,7 @@ unsafe fn test_vpmin_u16() { let a = u16x4::from([1, 2, 3, 4]); let b = u16x4::from([0, 3, 2, 5]); let e = u16x4::from([1, 3, 0, 2]); - let r: u16x4 = transmute(vpmin_u16(transmute(a), transmute(b))); + let r: u16x4 = unsafe { transmute(vpmin_u16(transmute(a), transmute(b))) }; assert_eq!(r, e); } @@ -59,7 +59,7 @@ unsafe fn test_vpmin_u32() { let a = u32x2::from([1, 2]); let b = u32x2::from([0, 3]); let e = u32x2::from([1, 0]); - let r: u32x2 = transmute(vpmin_u32(transmute(a), transmute(b))); + let r: u32x2 = unsafe { transmute(vpmin_u32(transmute(a), transmute(b))) }; assert_eq!(r, e); } @@ -68,7 +68,7 @@ unsafe fn test_vpmin_f32() { let a = f32x2::from([1., -2.]); let b = f32x2::from([0., 3.]); let e = f32x2::from([-2., 0.]); - let r: f32x2 = transmute(vpmin_f32(transmute(a), transmute(b))); + let r: f32x2 = unsafe { transmute(vpmin_f32(transmute(a), transmute(b))) }; assert_eq!(r, e); } @@ -77,7 +77,7 @@ unsafe fn test_vpmax_s8() { let a = i8x8::from([1, -2, 3, -4, 5, 6, 7, 8]); let b = i8x8::from([0, 3, 2, 5, 4, 7, 6, 9]); let e = i8x8::from([1, 3, 6, 8, 3, 5, 7, 9]); - let r: i8x8 = transmute(vpmax_s8(transmute(a), transmute(b))); + let r: i8x8 = unsafe { transmute(vpmax_s8(transmute(a), transmute(b))) }; assert_eq!(r, e); } @@ -86,7 +86,7 @@ unsafe fn test_vpmax_s16() { let a = i16x4::from([1, 2, 3, -4]); let b = i16x4::from([0, 3, 2, 5]); let e = i16x4::from([2, 3, 3, 5]); - let r: i16x4 = transmute(vpmax_s16(transmute(a), transmute(b))); + let r: i16x4 = unsafe { transmute(vpmax_s16(transmute(a), transmute(b))) }; assert_eq!(r, e); } @@ -95,7 +95,7 @@ unsafe fn test_vpmax_s32() { let a = i32x2::from([1, -2]); let b = i32x2::from([0, 3]); let e = i32x2::from([1, 3]); - let r: i32x2 = transmute(vpmax_s32(transmute(a), transmute(b))); + let r: i32x2 = unsafe { transmute(vpmax_s32(transmute(a), transmute(b))) }; assert_eq!(r, e); } @@ -104,7 +104,7 @@ unsafe fn test_vpmax_u8() { let a = u8x8::from([1, 2, 3, 4, 5, 6, 7, 8]); let b = u8x8::from([0, 3, 2, 5, 4, 7, 6, 9]); let e = u8x8::from([2, 4, 6, 8, 3, 5, 7, 9]); - let r: u8x8 = transmute(vpmax_u8(transmute(a), transmute(b))); + let r: u8x8 = unsafe { transmute(vpmax_u8(transmute(a), transmute(b))) }; assert_eq!(r, e); } @@ -113,7 +113,7 @@ unsafe fn test_vpmax_u16() { let a = u16x4::from([1, 2, 3, 4]); let b = u16x4::from([0, 3, 2, 5]); let e = u16x4::from([2, 4, 3, 5]); - let r: u16x4 = transmute(vpmax_u16(transmute(a), transmute(b))); + let r: u16x4 = unsafe { transmute(vpmax_u16(transmute(a), transmute(b))) }; assert_eq!(r, e); } @@ -122,7 +122,7 @@ unsafe fn test_vpmax_u32() { let a = u32x2::from([1, 2]); let b = u32x2::from([0, 3]); let e = u32x2::from([2, 3]); - let r: u32x2 = transmute(vpmax_u32(transmute(a), transmute(b))); + let r: u32x2 = unsafe { transmute(vpmax_u32(transmute(a), transmute(b))) }; assert_eq!(r, e); } @@ -131,7 +131,7 @@ unsafe fn test_vpmax_f32() { let a = f32x2::from([1., -2.]); let b = f32x2::from([0., 3.]); let e = f32x2::from([1., 3.]); - let r: f32x2 = transmute(vpmax_f32(transmute(a), transmute(b))); + let r: f32x2 = unsafe { transmute(vpmax_f32(transmute(a), transmute(b))) }; assert_eq!(r, e); } @@ -139,7 +139,7 @@ unsafe fn test_vpmax_f32() { unsafe fn test_vpadd_s16() { let a = i16x4::from([1, 2, 3, 4]); let b = i16x4::from([0, -1, -2, -3]); - let r: i16x4 = transmute(vpadd_s16(transmute(a), transmute(b))); + let r: i16x4 = unsafe { transmute(vpadd_s16(transmute(a), transmute(b))) }; let e = i16x4::from([3, 7, -1, -5]); assert_eq!(r, e); } @@ -147,7 +147,7 @@ unsafe fn test_vpadd_s16() { unsafe fn test_vpadd_s32() { let a = i32x2::from([1, 2]); let b = i32x2::from([0, -1]); - let r: i32x2 = transmute(vpadd_s32(transmute(a), transmute(b))); + let r: i32x2 = unsafe { transmute(vpadd_s32(transmute(a), transmute(b))) }; let e = i32x2::from([3, -1]); assert_eq!(r, e); } @@ -155,7 +155,7 @@ unsafe fn test_vpadd_s32() { unsafe fn test_vpadd_s8() { let a = i8x8::from([1, 2, 3, 4, 5, 6, 7, 8]); let b = i8x8::from([0, -1, -2, -3, -4, -5, -6, -7]); - let r: i8x8 = transmute(vpadd_s8(transmute(a), transmute(b))); + let r: i8x8 = unsafe { transmute(vpadd_s8(transmute(a), transmute(b))) }; let e = i8x8::from([3, 7, 11, 15, -1, -5, -9, -13]); assert_eq!(r, e); } @@ -163,7 +163,7 @@ unsafe fn test_vpadd_s8() { unsafe fn test_vpadd_u16() { let a = u16x4::from([1, 2, 3, 4]); let b = u16x4::from([30, 31, 32, 33]); - let r: u16x4 = transmute(vpadd_u16(transmute(a), transmute(b))); + let r: u16x4 = unsafe { transmute(vpadd_u16(transmute(a), transmute(b))) }; let e = u16x4::from([3, 7, 61, 65]); assert_eq!(r, e); } @@ -171,7 +171,7 @@ unsafe fn test_vpadd_u16() { unsafe fn test_vpadd_u32() { let a = u32x2::from([1, 2]); let b = u32x2::from([30, 31]); - let r: u32x2 = transmute(vpadd_u32(transmute(a), transmute(b))); + let r: u32x2 = unsafe { transmute(vpadd_u32(transmute(a), transmute(b))) }; let e = u32x2::from([3, 61]); assert_eq!(r, e); } @@ -179,7 +179,7 @@ unsafe fn test_vpadd_u32() { unsafe fn test_vpadd_u8() { let a = u8x8::from([1, 2, 3, 4, 5, 6, 7, 8]); let b = u8x8::from([30, 31, 32, 33, 34, 35, 36, 37]); - let r: u8x8 = transmute(vpadd_u8(transmute(a), transmute(b))); + let r: u8x8 = unsafe { transmute(vpadd_u8(transmute(a), transmute(b))) }; let e = u8x8::from([3, 7, 11, 15, 61, 65, 69, 73]); assert_eq!(r, e); } @@ -188,7 +188,7 @@ unsafe fn test_vpadd_u8() { unsafe fn test_vqsub_u8() { let a = u8x8::from([1, 2, 3, 4, 5, 6, 7, 0xff]); let b = u8x8::from([30, 1, 1, 1, 34, 0xff, 36, 37]); - let r: u8x8 = transmute(vqsub_u8(transmute(a), transmute(b))); + let r: u8x8 = unsafe { transmute(vqsub_u8(transmute(a), transmute(b))) }; let e = u8x8::from([0, 1, 2, 3, 0, 0, 0, 218]); assert_eq!(r, e); } @@ -197,7 +197,7 @@ unsafe fn test_vqsub_u8() { unsafe fn test_vqadd_u8() { let a = u8x8::from([1, 2, 3, 4, 5, 6, 7, 0xff]); let b = u8x8::from([30, 1, 1, 1, 34, 0xff, 36, 37]); - let r: u8x8 = transmute(vqadd_u8(transmute(a), transmute(b))); + let r: u8x8 = unsafe { transmute(vqadd_u8(transmute(a), transmute(b))) }; let e = u8x8::from([31, 3, 4, 5, 39, 0xff, 43, 0xff]); assert_eq!(r, e); } @@ -208,7 +208,7 @@ unsafe fn test_vmaxq_f32() { let a = f32x4::from([0., -1., 2., -3.]); let b = f32x4::from([-4., 5., -6., 7.]); let e = f32x4::from([0., 5., 2., 7.]); - let r: f32x4 = transmute(vmaxq_f32(transmute(a), transmute(b))); + let r: f32x4 = unsafe { transmute(vmaxq_f32(transmute(a), transmute(b))) }; assert_eq!(r, e); } @@ -218,7 +218,7 @@ unsafe fn test_vminq_f32() { let a = f32x4::from([0., -1., 2., -3.]); let b = f32x4::from([-4., 5., -6., 7.]); let e = f32x4::from([-4., -1., -6., -3.]); - let r: f32x4 = transmute(vminq_f32(transmute(a), transmute(b))); + let r: f32x4 = unsafe { transmute(vminq_f32(transmute(a), transmute(b))) }; assert_eq!(r, e); } @@ -227,7 +227,7 @@ unsafe fn test_vaddvq_f32() { // AArch64 llvm intrinsic: llvm.aarch64.neon.faddv.f32.v4f32 let a = f32x4::from([0., 1., 2., 3.]); let e = 6f32; - let r = vaddvq_f32(transmute(a)); + let r = unsafe { vaddvq_f32(transmute(a)) }; assert_eq!(r, e); } @@ -236,7 +236,7 @@ unsafe fn test_vrndnq_f32() { // llvm intrinsic: llvm.roundeven.v4f32 let a = f32x4::from([0.1, -1.9, 4.5, 5.5]); let e = f32x4::from([0., -2., 4., 6.]); - let r: f32x4 = transmute(vrndnq_f32(transmute(a))); + let r: f32x4 = unsafe { transmute(vrndnq_f32(transmute(a))) }; assert_eq!(r, e); } From d117c77a0e0bb7468e25eef66c79f87989104810 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 4 Jul 2025 09:55:39 +0000 Subject: [PATCH 031/160] Fix raw-dylib.rs --- example/raw-dylib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/raw-dylib.rs b/example/raw-dylib.rs index 4711884f76af6..5f5bde7d4dc5e 100644 --- a/example/raw-dylib.rs +++ b/example/raw-dylib.rs @@ -5,7 +5,7 @@ fn main() { #[cfg(windows)] { #[link(name = "kernel32", kind = "raw-dylib")] - extern "C" { + unsafe extern "C" { fn GetModuleFileNameA( module: *mut std::ffi::c_void, filename: *mut u8, From 989bb25293f6d53f89821ea56f4b5e3ce5db3421 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 4 Jul 2025 10:32:41 +0000 Subject: [PATCH 032/160] Remove reference to deleted test --- config.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/config.txt b/config.txt index 6ae4767adfdf5..85748a4f8a789 100644 --- a/config.txt +++ b/config.txt @@ -20,7 +20,6 @@ aot.mini_core_hello_world testsuite.base_sysroot aot.arbitrary_self_types_pointers_and_wrappers -aot.issue_91827_extern_types jit.std_example aot.std_example aot.dst_field_align From 805f843f194d57af5892a6775f0a6e3014542c11 Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Sun, 29 Jun 2025 12:11:51 +0200 Subject: [PATCH 033/160] compiler: Parse `p-` specs in datalayout string, allow definition of custom default data address space --- src/abi/mod.rs | 2 +- src/abi/pass_mode.rs | 2 +- src/common.rs | 2 +- src/constant.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 8965e4a944d48..7d0731c77bdc4 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -786,7 +786,7 @@ pub(crate) fn codegen_drop<'tcx>( pub(crate) fn lib_call_arg_param(tcx: TyCtxt<'_>, ty: Type, is_signed: bool) -> AbiParam { let param = AbiParam::new(ty); - if ty.is_int() && u64::from(ty.bits()) < tcx.data_layout.pointer_size.bits() { + if ty.is_int() && u64::from(ty.bits()) < tcx.data_layout.pointer_size().bits() { match (&*tcx.sess.target.arch, &*tcx.sess.target.vendor) { ("x86_64", _) | ("aarch64", "apple") => match (ty, is_signed) { (types::I8 | types::I16, true) => param.sext(), diff --git a/src/abi/pass_mode.rs b/src/abi/pass_mode.rs index cd0afee0cfb2f..2031842062d97 100644 --- a/src/abi/pass_mode.rs +++ b/src/abi/pass_mode.rs @@ -127,7 +127,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { PassMode::Indirect { attrs, meta_attrs: None, on_stack } => { if on_stack { // Abi requires aligning struct size to pointer size - let size = self.layout.size.align_to(tcx.data_layout.pointer_align.abi); + let size = self.layout.size.align_to(tcx.data_layout.pointer_align().abi); let size = u32::try_from(size.bytes()).unwrap(); smallvec![apply_attrs_to_abi_param( AbiParam::special(pointer_ty(tcx), ArgumentPurpose::StructArgument(size),), diff --git a/src/common.rs b/src/common.rs index 2f11b2d2dcc1a..2fbe5c02802ab 100644 --- a/src/common.rs +++ b/src/common.rs @@ -15,7 +15,7 @@ use crate::debuginfo::FunctionDebugContext; use crate::prelude::*; pub(crate) fn pointer_ty(tcx: TyCtxt<'_>) -> types::Type { - match tcx.data_layout.pointer_size.bits() { + match tcx.data_layout.pointer_size().bits() { 16 => types::I16, 32 => types::I32, 64 => types::I64, diff --git a/src/constant.rs b/src/constant.rs index ee43eb736e651..ed06423b260fc 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -443,7 +443,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant let addend = { let endianness = tcx.data_layout.endian; let offset = offset.bytes() as usize; - let ptr_size = tcx.data_layout.pointer_size; + let ptr_size = tcx.data_layout.pointer_size(); let bytes = &alloc.inspect_with_uninit_and_ptr_outside_interpreter( offset..offset + ptr_size.bytes() as usize, ); From 9360f7c24465ae9fbb6df707332bfc268c05ae66 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 27 Jun 2025 14:32:43 +0200 Subject: [PATCH 034/160] Don't call collect_debug_info when debuginfo is disabled --- src/base.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/base.rs b/src/base.rs index 9b0a59c0dfc75..fad747b9c274a 100644 --- a/src/base.rs +++ b/src/base.rs @@ -63,7 +63,9 @@ pub(crate) fn codegen_fn<'tcx>( func.clear(); func.name = UserFuncName::user(0, func_id.as_u32()); func.signature = sig; - func.collect_debug_info(); + if cx.debug_context.is_some() { + func.collect_debug_info(); + } let mut bcx = FunctionBuilder::new(&mut func, &mut func_ctx); From 8dab8de9d204fe417eec467370142dd3824237a7 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 4 Jul 2025 15:57:32 +0200 Subject: [PATCH 035/160] Get rid of CodegenCx --- src/base.rs | 22 +++++++++++++--------- src/common.rs | 6 ++++-- src/debuginfo/mod.rs | 19 ++++++++++++++++--- src/driver/aot.rs | 27 ++++++++++++--------------- src/driver/jit.rs | 20 ++++++++++++-------- src/inline_asm.rs | 4 ++-- src/lib.rs | 25 ------------------------- src/pretty_clif.rs | 7 ++++--- 8 files changed, 63 insertions(+), 67 deletions(-) diff --git a/src/base.rs b/src/base.rs index fad747b9c274a..5c826b50e8d1b 100644 --- a/src/base.rs +++ b/src/base.rs @@ -13,6 +13,7 @@ use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv}; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_session::config::OutputFilenames; +use rustc_span::Symbol; use crate::constant::ConstantCx; use crate::debuginfo::{FunctionDebugContext, TypeDebugContext}; @@ -31,7 +32,8 @@ pub(crate) struct CodegenedFunction { pub(crate) fn codegen_fn<'tcx>( tcx: TyCtxt<'tcx>, - cx: &mut crate::CodegenCx, + cgu_name: Symbol, + mut debug_context: Option<&mut DebugContext>, type_dbg: &mut TypeDebugContext<'tcx>, cached_func: Function, module: &mut dyn Module, @@ -63,7 +65,7 @@ pub(crate) fn codegen_fn<'tcx>( func.clear(); func.name = UserFuncName::user(0, func_id.as_u32()); func.signature = sig; - if cx.debug_context.is_some() { + if debug_context.is_some() { func.collect_debug_info(); } @@ -79,9 +81,10 @@ pub(crate) fn codegen_fn<'tcx>( // Make FunctionCx let target_config = module.target_config(); let pointer_type = target_config.pointer_type(); + assert_eq!(pointer_ty(tcx), pointer_type); let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance, fn_abi); - let func_debug_cx = if let Some(debug_context) = &mut cx.debug_context { + let func_debug_cx = if let Some(debug_context) = debug_context.as_deref_mut() { Some(debug_context.define_function(tcx, type_dbg, instance, fn_abi, &symbol_name, mir.span)) } else { None @@ -91,14 +94,15 @@ pub(crate) fn codegen_fn<'tcx>( bcx.declare_var(exception_slot, pointer_type); let mut fx = FunctionCx { - cx, module, + debug_context, tcx, target_config, pointer_type, constants_cx: ConstantCx::new(), func_debug_cx, + cgu_name, instance, symbol_name, mir, @@ -128,7 +132,7 @@ pub(crate) fn codegen_fn<'tcx>( fx.constants_cx.finalize(fx.tcx, &mut *fx.module); - if cx.should_write_ir { + if crate::pretty_clif::should_write_ir(tcx.sess) { crate::pretty_clif::write_clif_file( tcx.output_filenames(()), &symbol_name, @@ -146,11 +150,12 @@ pub(crate) fn codegen_fn<'tcx>( } pub(crate) fn compile_fn( - cx: &mut crate::CodegenCx, profiler: &SelfProfilerRef, output_filenames: &OutputFilenames, + should_write_ir: bool, cached_context: &mut Context, module: &mut dyn Module, + debug_context: Option<&mut DebugContext>, global_asm: &mut String, codegened_func: CodegenedFunction, ) { @@ -195,7 +200,7 @@ pub(crate) fn compile_fn( // Define function profiler.generic_activity("define function").run(|| { - context.want_disasm = cx.should_write_ir; + context.want_disasm = should_write_ir; match module.define_function(codegened_func.func_id, context) { Ok(()) => {} Err(ModuleError::Compilation(CodegenError::ImplLimitExceeded)) => { @@ -225,7 +230,7 @@ pub(crate) fn compile_fn( } }); - if cx.should_write_ir { + if should_write_ir { // Write optimized function to file for debugging crate::pretty_clif::write_clif_file( output_filenames, @@ -246,7 +251,6 @@ pub(crate) fn compile_fn( } // Define debuginfo for function - let debug_context = &mut cx.debug_context; profiler.generic_activity("generate debug info").run(|| { if let Some(debug_context) = debug_context { codegened_func.func_debug_cx.unwrap().finalize( diff --git a/src/common.rs b/src/common.rs index 6596b27fb1ffc..035643d2fa2b4 100644 --- a/src/common.rs +++ b/src/common.rs @@ -6,6 +6,7 @@ use rustc_middle::ty::TypeFoldable; use rustc_middle::ty::layout::{ self, FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, }; +use rustc_span::Symbol; use rustc_span::source_map::Spanned; use rustc_target::callconv::FnAbi; use rustc_target::spec::{HasTargetSpec, Target}; @@ -268,14 +269,15 @@ pub(crate) fn create_wrapper_function( } pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> { - pub(crate) cx: &'clif mut crate::CodegenCx, pub(crate) module: &'m mut dyn Module, + pub(crate) debug_context: Option<&'clif mut DebugContext>, pub(crate) tcx: TyCtxt<'tcx>, pub(crate) target_config: TargetFrontendConfig, // Cached from module pub(crate) pointer_type: Type, // Cached from module pub(crate) constants_cx: ConstantCx, pub(crate) func_debug_cx: Option, + pub(crate) cgu_name: Symbol, pub(crate) instance: Instance<'tcx>, pub(crate) symbol_name: String, pub(crate) mir: &'tcx Body<'tcx>, @@ -407,7 +409,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { } pub(crate) fn set_debug_loc(&mut self, source_info: mir::SourceInfo) { - if let Some(debug_context) = &mut self.cx.debug_context { + if let Some(debug_context) = &mut self.debug_context { let (file_id, line, column) = debug_context.get_span_loc(self.tcx, self.mir.span, source_info.span); diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index 35f92609982ed..391ce52008478 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -20,6 +20,7 @@ use rustc_codegen_ssa::debuginfo::type_names; use rustc_hir::def::DefKind; use rustc_hir::def_id::DefIdMap; use rustc_session::Session; +use rustc_session::config::DebugInfo; use rustc_span::{FileNameDisplayPreference, SourceFileHash, StableSourceFileId}; use rustc_target::callconv::FnAbi; @@ -53,7 +54,19 @@ pub(crate) struct FunctionDebugContext { } impl DebugContext { - pub(crate) fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa, cgu_name: &str) -> Self { + pub(crate) fn new( + tcx: TyCtxt<'_>, + isa: &dyn TargetIsa, + force_disable_debuginfo: bool, + cgu_name: &str, + ) -> Option { + if tcx.sess.opts.debuginfo == DebugInfo::None + || force_disable_debuginfo + || tcx.sess.target.options.is_like_windows + { + return None; + } + let encoding = Encoding { format: Format::Dwarf32, // FIXME this should be configurable @@ -146,7 +159,7 @@ impl DebugContext { AttributeValue::Udata(isa.frontend_config().pointer_bytes().into()), ); - DebugContext { + Some(DebugContext { endian, dwarf, unit_range_list: RangeList(Vec::new()), @@ -155,7 +168,7 @@ impl DebugContext { namespace_map: DefIdMap::default(), array_size_type, filename_display_preference, - } + }) } fn item_namespace(&mut self, tcx: TyCtxt<'_>, def_id: DefId) -> UnitEntryId { diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 9e793fc52545a..ea50af77c9f23 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -25,9 +25,8 @@ use rustc_middle::mir::mono::{ CodegenUnit, Linkage as RLinkage, MonoItem, MonoItemData, Visibility, }; use rustc_session::Session; -use rustc_session::config::{DebugInfo, OutFileName, OutputFilenames, OutputType}; +use rustc_session::config::{OutFileName, OutputFilenames, OutputType}; -use crate::CodegenCx; use crate::base::CodegenedFunction; use crate::concurrency_limiter::{ConcurrencyLimiter, ConcurrencyLimiterToken}; use crate::debuginfo::TypeDebugContext; @@ -512,18 +511,13 @@ fn codegen_cgu_content( tcx: TyCtxt<'_>, module: &mut dyn Module, cgu_name: rustc_span::Symbol, -) -> (CodegenCx, Vec, String) { +) -> (Option, Vec, String) { let _timer = tcx.prof.generic_activity_with_arg("codegen cgu", cgu_name.as_str()); let cgu = tcx.codegen_unit(cgu_name); let mono_items = cgu.items_in_deterministic_order(tcx); - let mut cx = crate::CodegenCx::new( - tcx, - module.isa(), - tcx.sess.opts.debuginfo != DebugInfo::None, - cgu_name, - ); + let mut debug_context = DebugContext::new(tcx, module.isa(), false, cgu_name.as_str()); let mut global_asm = String::new(); let mut type_dbg = TypeDebugContext::default(); super::predefine_mono_items(tcx, module, &mono_items); @@ -550,7 +544,8 @@ fn codegen_cgu_content( } let codegened_function = crate::base::codegen_fn( tcx, - &mut cx, + cgu_name, + debug_context.as_mut(), &mut type_dbg, Function::new(), module, @@ -560,7 +555,7 @@ fn codegen_cgu_content( } MonoItem::Static(def_id) => { let data_id = crate::constant::codegen_static(tcx, module, def_id); - if let Some(debug_context) = &mut cx.debug_context { + if let Some(debug_context) = debug_context.as_mut() { debug_context.define_static(tcx, &mut type_dbg, def_id, data_id); } } @@ -574,7 +569,7 @@ fn codegen_cgu_content( } crate::main_shim::maybe_create_entry_wrapper(tcx, module, false, cgu.is_primary()); - (cx, codegened_functions, global_asm) + (debug_context, codegened_functions, global_asm) } fn module_codegen( @@ -587,7 +582,7 @@ fn module_codegen( ) -> OngoingModuleCodegen { let mut module = make_module(tcx.sess, cgu_name.as_str().to_string()); - let (mut cx, codegened_functions, mut global_asm) = + let (mut debug_context, codegened_functions, mut global_asm) = codegen_cgu_content(tcx, &mut module, cgu_name); let cgu_name = cgu_name.as_str().to_owned(); @@ -597,6 +592,7 @@ fn module_codegen( let profiler = tcx.prof.clone(); let invocation_temp = tcx.sess.invocation_temp.clone(); let output_filenames = tcx.output_filenames(()).clone(); + let should_write_ir = crate::pretty_clif::should_write_ir(tcx.sess); OngoingModuleCodegen::Async(std::thread::spawn(move || { profiler.clone().generic_activity_with_arg("compile functions", &*cgu_name).run(|| { @@ -607,11 +603,12 @@ fn module_codegen( let mut cached_context = Context::new(); for codegened_func in codegened_functions { crate::base::compile_fn( - &mut cx, &profiler, &output_filenames, + should_write_ir, &mut cached_context, &mut module, + debug_context.as_mut(), &mut global_asm, codegened_func, ); @@ -636,7 +633,7 @@ fn module_codegen( &profiler, cgu_name, module, - cx.debug_context, + debug_context, global_asm_object_file, &producer, ) diff --git a/src/driver/jit.rs b/src/driver/jit.rs index ab1544e62b0a3..697deae155459 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -12,12 +12,11 @@ use rustc_session::Session; use rustc_session::config::OutputFilenames; use rustc_span::sym; -use crate::CodegenCx; use crate::debuginfo::TypeDebugContext; use crate::prelude::*; use crate::unwind_module::UnwindModule; -fn create_jit_module(tcx: TyCtxt<'_>) -> (UnwindModule, CodegenCx) { +fn create_jit_module(tcx: TyCtxt<'_>) -> (UnwindModule, Option) { let crate_info = CrateInfo::new(tcx, "dummy_target_cpu".to_string()); let isa = crate::build_isa(tcx.sess, true); @@ -26,7 +25,7 @@ fn create_jit_module(tcx: TyCtxt<'_>) -> (UnwindModule, CodegenCx) { jit_builder.symbol_lookup_fn(dep_symbol_lookup_fn(tcx.sess, crate_info)); let mut jit_module = UnwindModule::new(JITModule::new(jit_builder), false); - let cx = crate::CodegenCx::new(tcx, jit_module.isa(), false, sym::dummy_cgu_name); + let cx = DebugContext::new(tcx, jit_module.isa(), false, "dummy_cgu_name"); crate::allocator::codegen(tcx, &mut jit_module); @@ -43,7 +42,8 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec) -> ! { } let output_filenames = tcx.output_filenames(()); - let (mut jit_module, mut cx) = create_jit_module(tcx); + let should_write_ir = crate::pretty_clif::should_write_ir(tcx.sess); + let (mut jit_module, mut debug_context) = create_jit_module(tcx); let mut cached_context = Context::new(); let cgus = tcx.collect_and_partition_mono_items(()).codegen_units; @@ -63,7 +63,8 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec) -> ! { codegen_and_compile_fn( tcx, &output_filenames, - &mut cx, + should_write_ir, + debug_context.as_mut(), &mut cached_context, &mut jit_module, inst, @@ -122,7 +123,8 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec) -> ! { fn codegen_and_compile_fn<'tcx>( tcx: TyCtxt<'tcx>, output_filenames: &OutputFilenames, - cx: &mut crate::CodegenCx, + should_write_ir: bool, + mut debug_context: Option<&mut DebugContext>, cached_context: &mut Context, module: &mut dyn Module, instance: Instance<'tcx>, @@ -143,7 +145,8 @@ fn codegen_and_compile_fn<'tcx>( let cached_func = std::mem::replace(&mut cached_context.func, Function::new()); let codegened_func = crate::base::codegen_fn( tcx, - cx, + sym::dummy_cgu_name, + debug_context.as_deref_mut(), &mut TypeDebugContext::default(), cached_func, module, @@ -152,11 +155,12 @@ fn codegen_and_compile_fn<'tcx>( let mut global_asm = String::new(); crate::base::compile_fn( - cx, &tcx.prof, output_filenames, + should_write_ir, cached_context, module, + debug_context.as_deref_mut(), &mut global_asm, codegened_func, ); diff --git a/src/inline_asm.rs b/src/inline_asm.rs index eec8b08a1bcd9..5a29961f7d71f 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -125,7 +125,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>( let wrapper_name = format!( "{}__inline_asm_{}_wrapper_n{}", fx.symbol_name, - fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"), + fx.cgu_name.as_str().replace('.', "__").replace('-', "_"), fx.inline_asm_index, ); fx.inline_asm_index += 1; @@ -189,7 +189,7 @@ pub(crate) fn codegen_inline_asm_inner<'tcx>( let asm_name = format!( "{}__inline_asm_{}_n{}", fx.symbol_name, - fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"), + fx.cgu_name.as_str().replace('.', "__").replace('-', "_"), fx.inline_asm_index, ); fx.inline_asm_index += 1; diff --git a/src/lib.rs b/src/lib.rs index 62ba9974f726b..835fd9a4d72ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -123,31 +123,6 @@ impl String> Drop for PrintOnPanic { } } -/// The codegen context holds any information shared between the codegen of individual functions -/// inside a single codegen unit with the exception of the Cranelift [`Module`](cranelift_module::Module). -struct CodegenCx { - should_write_ir: bool, - debug_context: Option, - cgu_name: Symbol, -} - -impl CodegenCx { - fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa, debug_info: bool, cgu_name: Symbol) -> Self { - assert_eq!(pointer_ty(tcx), isa.pointer_type()); - - let debug_context = if debug_info && !tcx.sess.target.options.is_like_windows { - Some(DebugContext::new(tcx, isa, cgu_name.as_str())) - } else { - None - }; - CodegenCx { - should_write_ir: crate::pretty_clif::should_write_ir(tcx), - debug_context, - cgu_name, - } - } -} - pub struct CraneliftCodegenBackend { pub config: Option, } diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index 9400ae9fcff0f..3655faf598a73 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -64,6 +64,7 @@ use cranelift_codegen::ir::Fact; use cranelift_codegen::ir::entities::AnyEntity; use cranelift_codegen::write::{FuncWriter, PlainWriter}; use rustc_middle::ty::print::with_no_trimmed_paths; +use rustc_session::Session; use rustc_session::config::{OutputFilenames, OutputType}; use rustc_target::callconv::FnAbi; @@ -83,7 +84,7 @@ impl CommentWriter { instance: Instance<'tcx>, fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>, ) -> Self { - let enabled = should_write_ir(tcx); + let enabled = should_write_ir(tcx.sess); let global_comments = if enabled { with_no_trimmed_paths!({ vec![ @@ -247,8 +248,8 @@ impl FunctionCx<'_, '_, '_> { } } -pub(crate) fn should_write_ir(tcx: TyCtxt<'_>) -> bool { - tcx.sess.opts.output_types.contains_key(&OutputType::LlvmAssembly) +pub(crate) fn should_write_ir(sess: &Session) -> bool { + sess.opts.output_types.contains_key(&OutputType::LlvmAssembly) } pub(crate) fn write_ir_file( From 5df82239b004c815570b74847ed39e3d9c5ef53f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 7 Jul 2025 12:42:37 +0000 Subject: [PATCH 036/160] Rustup to rustc 1.90.0-nightly (a84ab0ce6 2025-07-06) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 56d1bda88ca65..75a305809b1c8 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-07-03" +channel = "nightly-2025-07-07" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 87e71fe07529e2eac43bb6d14fa58fa4fdb4f669 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 7 Jul 2025 12:48:18 +0000 Subject: [PATCH 037/160] Fix rustc test suite --- scripts/test_rustc_tests.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index f9a3fc85de450..22822d121d2f5 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -146,8 +146,7 @@ rm tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rs # same rm tests/ui/async-await/async-drop/async-drop-initial.rs # same (rust-lang/rust#140493) rm -r tests/ui/codegen/equal-pointers-unequal # make incorrect assumptions about the location of stack variables -rm tests/ui/stdio-is-blocking.rs # really slow with unoptimized libstd -rm tests/ui/intrinsics/panic-uninitialized-zeroed.rs # same +rm tests/ui/intrinsics/panic-uninitialized-zeroed.rs # really slow with unoptimized libstd rm tests/ui/process/process-panic-after-fork.rs # same cp ../dist/bin/rustdoc-clif ../dist/bin/rustdoc # some tests expect bin/rustdoc to exist From 3bd80454602a41cc4d7d1dc3fe6dce671d4fb033 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 8 Jul 2025 14:31:31 +0000 Subject: [PATCH 038/160] Rustup to rustc 1.90.0-nightly (a2d45f73c 2025-07-07) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 75a305809b1c8..e3e55123592e7 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-07-07" +channel = "nightly-2025-07-08" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 2f84e16016cd3f8039c5da77cb8a2696e8ff5a7f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 8 Jul 2025 14:47:46 +0000 Subject: [PATCH 039/160] Fix rustc test suite --- scripts/test_rustc_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 22822d121d2f5..78582e4ecdced 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -60,6 +60,7 @@ rm tests/ui/asm/x86_64/goto.rs # inline asm labels not supported rm tests/ui/simd/simd-bitmask-notpow2.rs # non-pow-of-2 simd vector sizes rm -r tests/run-make/embed-source-dwarf # embedding sources in debuginfo rm -r tests/run-make/used-proc-macro # used(linker) isn't supported yet +rm tests/ui/attributes/fn-align-dyn.rs # per-function alignment not supported # requires LTO rm -r tests/run-make/cdylib From 08dac6fc6c1634ab60c0b30589b443e31a212e7a Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 12 Mar 2025 10:26:37 +0000 Subject: [PATCH 040/160] Add opaque TypeId handles for CTFE --- src/constant.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/constant.rs b/src/constant.rs index ed06423b260fc..85adf0f3716b2 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -175,6 +175,13 @@ pub(crate) fn codegen_const_value<'tcx>( fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); fx.bcx.ins().global_value(fx.pointer_type, local_data_id) } + GlobalAlloc::TypeId { .. } => { + return CValue::const_val( + fx, + layout, + ScalarInt::try_from_target_usize(offset.bytes(), fx.tcx).unwrap(), + ); + } GlobalAlloc::Static(def_id) => { assert!(fx.tcx.is_static(def_id)); let data_id = data_id_for_static( @@ -360,6 +367,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant GlobalAlloc::Memory(alloc) => alloc, GlobalAlloc::Function { .. } | GlobalAlloc::Static(_) + | GlobalAlloc::TypeId { .. } | GlobalAlloc::VTable(..) => { unreachable!() } @@ -471,6 +479,11 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant .principal() .map(|principal| tcx.instantiate_bound_regions_with_erased(principal)), ), + GlobalAlloc::TypeId { .. } => { + // Nothing to do, the bytes/offset of this pointer have already been written together with all other bytes, + // so we just need to drop this provenance. + continue; + } GlobalAlloc::Static(def_id) => { if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) { From fb6de82523a613a63f55fceeae1ef09d66c84d03 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 10 Jul 2025 10:37:15 +0000 Subject: [PATCH 041/160] Rustup to rustc 1.90.0-nightly (e43d139a8 2025-07-09) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index e3e55123592e7..9f547841f83c1 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-07-08" +channel = "nightly-2025-07-10" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 503612e92fa768cdef191c9cfb5c7108381f6e58 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 10 Jul 2025 13:12:51 +0000 Subject: [PATCH 042/160] Fix rustc testsuite --- scripts/test_rustc_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 78582e4ecdced..d32fd17d2eae1 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -60,6 +60,7 @@ rm tests/ui/asm/x86_64/goto.rs # inline asm labels not supported rm tests/ui/simd/simd-bitmask-notpow2.rs # non-pow-of-2 simd vector sizes rm -r tests/run-make/embed-source-dwarf # embedding sources in debuginfo rm -r tests/run-make/used-proc-macro # used(linker) isn't supported yet +rm tests/ui/linking/no-gc-encapsulation-symbols.rs # same rm tests/ui/attributes/fn-align-dyn.rs # per-function alignment not supported # requires LTO From 5d1bc9b8c4e98702c1643cff6d793e9113e4a5fd Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 11 Jul 2025 10:29:10 +0000 Subject: [PATCH 043/160] Rustup to rustc 1.90.0-nightly (2a023bf80 2025-07-10) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 9f547841f83c1..61bcbc3373edf 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-07-10" +channel = "nightly-2025-07-11" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 8e7174905ee670a76ec174294c5c2a238c1a256b Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 12 Jul 2025 15:52:14 +0000 Subject: [PATCH 044/160] Fix rustc testsuite --- scripts/test_rustc_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index d32fd17d2eae1..87e6dc3696d54 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -96,7 +96,7 @@ rm -r tests/run-make/llvm-location-discriminator-limit-dummy-span # same rm tests/ui/abi/stack-protector.rs # requires stack protector support rm -r tests/run-make/emit-stack-sizes # requires support for -Z emit-stack-sizes rm -r tests/run-make/optimization-remarks-dir # remarks are LLVM specific -rm -r tests/ui/optimization-remark.rs # same +rm -r tests/ui/codegen/remark-flag-functionality.rs # same rm -r tests/run-make/print-to-output # requires --print relocation-models # requires asm, llvm-ir and/or llvm-bc emit support From e0860f807c451f95d5ba68a10de38ea90fa237ef Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 13 Jul 2025 15:41:29 +0000 Subject: [PATCH 045/160] MinGW misses some f16/f128 intrinsics --- src/compiler_builtins.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/compiler_builtins.rs b/src/compiler_builtins.rs index d3784f8e56ace..155bf866889ad 100644 --- a/src/compiler_builtins.rs +++ b/src/compiler_builtins.rs @@ -85,6 +85,7 @@ builtin_functions! { fn __divtf3(a: f128, b: f128) -> f128; fn fmodf(a: f32, b: f32) -> f32; fn fmod(a: f64, b: f64) -> f64; + #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn fmodf128(a: f128, b: f128) -> f128; // float comparison fn __eqtf2(a: f128, b: f128) -> i32; @@ -93,7 +94,9 @@ builtin_functions! { fn __letf2(a: f128, b: f128) -> i32; fn __gttf2(a: f128, b: f128) -> i32; fn __getf2(a: f128, b: f128) -> i32; + #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn fminimumf128(a: f128, b: f128) -> f128; + #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn fmaximumf128(a: f128, b: f128) -> f128; // Cranelift float libcalls fn fmaf(a: f32, b: f32, c: f32) -> f32; @@ -127,16 +130,27 @@ builtin_functions! { fn sin(f: f64) -> f64; fn cosf(f: f32) -> f32; fn cos(f: f64) -> f64; + #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn fmaf128(a: f128, b: f128, c: f128) -> f128; + #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn floorf16(f: f16) -> f16; + #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn floorf128(f: f128) -> f128; + #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn ceilf16(f: f16) -> f16; + #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn ceilf128(f: f128) -> f128; + #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn truncf16(f: f16) -> f16; + #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn truncf128(f: f128) -> f128; + #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn rintf16(f: f16) -> f16; + #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn rintf128(f: f128) -> f128; + #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn sqrtf16(f: f16) -> f16; + #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn sqrtf128(f: f128) -> f128; // FIXME(f16_f128): Add other float intrinsics as compiler-builtins gains support (meaning they // are available on all targets). From a3796c7147334828635674c2486ec82e8eb093d3 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 15 Jul 2025 09:05:29 +0000 Subject: [PATCH 046/160] Rustup to rustc 1.90.0-nightly (a00149764 2025-07-14) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 61bcbc3373edf..26bd5523957ca 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-07-11" +channel = "nightly-2025-07-15" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 46fa9ad1f0d0bcc173d44a9a6d721158e2af5ed1 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 15 Jul 2025 09:25:27 +0000 Subject: [PATCH 047/160] Directly use symbol_value and tls_value global_value gets legalized to either of the two. --- src/constant.rs | 17 +++++++++++++---- src/vtable.rs | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 023cd000b5de9..3bd907b38cf6f 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -153,7 +153,7 @@ pub(crate) fn codegen_const_value<'tcx>( if fx.clif_comments.enabled() { fx.add_comment(local_data_id, format!("{:?}", alloc_id)); } - fx.bcx.ins().global_value(fx.pointer_type, local_data_id) + fx.bcx.ins().symbol_value(fx.pointer_type, local_data_id) } } GlobalAlloc::Function { instance, .. } => { @@ -174,7 +174,7 @@ pub(crate) fn codegen_const_value<'tcx>( ); let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); - fx.bcx.ins().global_value(fx.pointer_type, local_data_id) + fx.bcx.ins().symbol_value(fx.pointer_type, local_data_id) } GlobalAlloc::TypeId { .. } => { return CValue::const_val( @@ -195,7 +195,16 @@ pub(crate) fn codegen_const_value<'tcx>( if fx.clif_comments.enabled() { fx.add_comment(local_data_id, format!("{:?}", def_id)); } - fx.bcx.ins().global_value(fx.pointer_type, local_data_id) + if fx + .tcx + .codegen_fn_attrs(def_id) + .flags + .contains(CodegenFnAttrFlags::THREAD_LOCAL) + { + fx.bcx.ins().tls_value(fx.pointer_type, local_data_id) + } else { + fx.bcx.ins().symbol_value(fx.pointer_type, local_data_id) + } } }; let val = if offset.bytes() != 0 { @@ -229,7 +238,7 @@ fn pointer_for_allocation<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, alloc_id: All if fx.clif_comments.enabled() { fx.add_comment(local_data_id, format!("{:?}", alloc_id)); } - fx.bcx.ins().global_value(fx.pointer_type, local_data_id) + fx.bcx.ins().symbol_value(fx.pointer_type, local_data_id) } fn data_id_for_alloc_id( diff --git a/src/vtable.rs b/src/vtable.rs index 423cc8d225be1..b5d241d8f39f2 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -84,5 +84,5 @@ pub(crate) fn get_vtable<'tcx>( if fx.clif_comments.enabled() { fx.add_comment(local_data_id, "vtable"); } - fx.bcx.ins().global_value(fx.pointer_type, local_data_id) + fx.bcx.ins().symbol_value(fx.pointer_type, local_data_id) } From 5320b81d1ba23214981e9f55da6cab9ee9bc4e11 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Tue, 1 Jul 2025 20:02:31 +0200 Subject: [PATCH 048/160] fix `-Zsanitizer=kcfi` on `#[naked]` functions And more broadly only codegen `InstanceKind::Item` using the naked function codegen code. Other instance kinds should follow the normal path. --- 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 442151fe32de8..727f2760c0f93 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -530,8 +530,12 @@ fn codegen_cgu_content( for (mono_item, item_data) in mono_items { match mono_item { MonoItem::Fn(instance) => { - if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED) - { + // Other `InstanceKind`s (e.g. `ReifyShim` generated by indirect calls) should be + // codegened like a normal function. + let is_item_instance = matches!(instance.def, InstanceKind::Item(_)); + + let flags = tcx.codegen_fn_attrs(instance.def_id()).flags; + if is_item_instance && flags.contains(CodegenFnAttrFlags::NAKED) { rustc_codegen_ssa::mir::naked_asm::codegen_naked_asm( &mut GlobalAsmContext { tcx, global_asm: &mut cx.global_asm }, instance, From 70d199a6398570c1fe4b5efe1e85bc2227152f40 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Wed, 2 Jul 2025 10:46:15 +0200 Subject: [PATCH 049/160] add `codegen_instance_attrs` query and use it for naked functions --- src/driver/aot.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 727f2760c0f93..8ec3599b63d89 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -530,12 +530,8 @@ fn codegen_cgu_content( for (mono_item, item_data) in mono_items { match mono_item { MonoItem::Fn(instance) => { - // Other `InstanceKind`s (e.g. `ReifyShim` generated by indirect calls) should be - // codegened like a normal function. - let is_item_instance = matches!(instance.def, InstanceKind::Item(_)); - - let flags = tcx.codegen_fn_attrs(instance.def_id()).flags; - if is_item_instance && flags.contains(CodegenFnAttrFlags::NAKED) { + let flags = tcx.codegen_instance_attrs(instance.def).flags; + if flags.contains(CodegenFnAttrFlags::NAKED) { rustc_codegen_ssa::mir::naked_asm::codegen_naked_asm( &mut GlobalAsmContext { tcx, global_asm: &mut cx.global_asm }, instance, From 8e5e64750c6339f4c77e596ac72d56ab17378e97 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Wed, 2 Jul 2025 11:12:54 +0200 Subject: [PATCH 050/160] use `codegen_instance_attrs` where an instance is (easily) available --- src/driver/jit.rs | 2 +- src/driver/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/driver/jit.rs b/src/driver/jit.rs index b1f185b551c3c..b3497503bf068 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -127,7 +127,7 @@ fn codegen_and_compile_fn<'tcx>( module: &mut dyn Module, instance: Instance<'tcx>, ) { - if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED) { + if tcx.codegen_instance_attrs(instance.def).flags.contains(CodegenFnAttrFlags::NAKED) { tcx.dcx() .span_fatal(tcx.def_span(instance.def_id()), "Naked asm is not supported in JIT mode"); } diff --git a/src/driver/mod.rs b/src/driver/mod.rs index ffd47cace3807..8f83c30b598d8 100644 --- a/src/driver/mod.rs +++ b/src/driver/mod.rs @@ -35,7 +35,7 @@ fn predefine_mono_items<'tcx>( is_compiler_builtins, ); let is_naked = tcx - .codegen_fn_attrs(instance.def_id()) + .codegen_instance_attrs(instance.def) .flags .contains(CodegenFnAttrFlags::NAKED); module From 7fa842965ee7e655191a5a1a5ab72a55c2bc62c2 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 12 Jul 2025 17:11:47 -0700 Subject: [PATCH 051/160] Update cranelift tests --- example/float-minmax-pass.rs | 22 ++++++++++++++-------- example/mini_core_hello_world.rs | 3 ++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/example/float-minmax-pass.rs b/example/float-minmax-pass.rs index ad46e18c11c0d..b7491b7e522f3 100644 --- a/example/float-minmax-pass.rs +++ b/example/float-minmax-pass.rs @@ -11,6 +11,12 @@ #[derive(Copy, Clone, PartialEq, Debug)] struct f32x4(pub [f32; 4]); +impl f32x4 { + fn into_array(self) -> [f32; 4] { + unsafe { std::mem::transmute(self) } + } +} + use std::intrinsics::simd::*; fn main() { @@ -29,22 +35,22 @@ fn main() { unsafe { let min0 = simd_fmin(x, y); let min1 = simd_fmin(y, x); - assert_eq!(min0, min1); + assert_eq!(min0.into_array(), min1.into_array()); let e = f32x4([1.0, 1.0, 3.0, 3.0]); - assert_eq!(min0, e); + assert_eq!(min0.into_array(), e.into_array()); let minn = simd_fmin(x, n); - assert_eq!(minn, x); + assert_eq!(minn.into_array(), x.into_array()); let minn = simd_fmin(y, n); - assert_eq!(minn, y); + assert_eq!(minn.into_array(), y.into_array()); let max0 = simd_fmax(x, y); let max1 = simd_fmax(y, x); - assert_eq!(max0, max1); + assert_eq!(max0.into_array(), max1.into_array()); let e = f32x4([2.0, 2.0, 4.0, 4.0]); - assert_eq!(max0, e); + assert_eq!(max0.into_array(), e.into_array()); let maxn = simd_fmax(x, n); - assert_eq!(maxn, x); + assert_eq!(maxn.into_array(), x.into_array()); let maxn = simd_fmax(y, n); - assert_eq!(maxn, y); + assert_eq!(maxn.into_array(), y.into_array()); } } diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 246bd3104ec41..86602c6b2a3fd 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -348,7 +348,8 @@ fn main() { struct V([f64; 2]); let f = V([0.0, 1.0]); - let _a = f.0[0]; + let fp = (&raw const f) as *const [f64; 2]; + let _a = (unsafe { &*fp })[0]; stack_val_align(); } From 959755f22456445cf9696afad66e073280531f5c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 21 Jul 2025 08:44:33 +0000 Subject: [PATCH 052/160] Rustup to rustc 1.90.0-nightly (9982d6462 2025-07-20) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 26bd5523957ca..b0c39f661ecf6 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-07-15" +channel = "nightly-2025-07-21" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 87c661ebbcf115116c87674d7760a1e8fb1e87e8 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 21 Jul 2025 08:55:47 +0000 Subject: [PATCH 053/160] Re-enable some rustc tests --- scripts/test_rustc_tests.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 87e6dc3696d54..8cc70ffc9c82c 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -10,7 +10,7 @@ pushd rust command -v rg >/dev/null 2>&1 || cargo install ripgrep -rm -r tests/ui/{unsized-locals/,lto/,linkage*} || true +rm -r tests/ui/{lto/,linkage*} || true for test in $(rg --files-with-matches "lto" tests/{codegen-units,ui,incremental}); do rm $test done @@ -39,7 +39,6 @@ rm tests/ui/simd/intrinsic/generic-arithmetic-pass.rs # unimplemented simd_funne # exotic linkages rm tests/incremental/hashes/function_interfaces.rs rm tests/incremental/hashes/statics.rs -rm -r tests/run-make/naked-symbol-visibility # variadic arguments rm tests/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs From e7c7bf04a7fb8b563cd5c393936118ae487c3999 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 21 Jul 2025 09:14:09 +0000 Subject: [PATCH 054/160] Fix rustc testsuite --- scripts/test_rustc_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 8cc70ffc9c82c..1cd592a09ca67 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -39,6 +39,7 @@ rm tests/ui/simd/intrinsic/generic-arithmetic-pass.rs # unimplemented simd_funne # exotic linkages rm tests/incremental/hashes/function_interfaces.rs rm tests/incremental/hashes/statics.rs +rm -r tests/run-make/naked-symbol-visibility # variadic arguments rm tests/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs From 57fb209e76f5922e8bd5fdb264034ba20472535e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 21 Jul 2025 13:56:39 +0000 Subject: [PATCH 055/160] Update dependencies --- Cargo.lock | 84 +++++++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b893a2be9a2cb..4a599f8d76a1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" [[package]] name = "anyhow" -version = "1.0.95" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" +checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" [[package]] name = "arbitrary" @@ -28,18 +28,18 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bumpalo" -version = "3.16.0" +version = "3.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" dependencies = [ "allocator-api2", ] [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "cranelift-assembler-x64" @@ -218,18 +218,18 @@ checksum = "7d5870e266df8237b56cc98b04f5739c228565c92dd629ec6c66efa87271a158" [[package]] name = "crc32fast" -version = "1.4.2" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" dependencies = [ "cfg-if", ] [[package]] name = "equivalent" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "fallible-iterator" @@ -239,9 +239,9 @@ checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" [[package]] name = "foldhash" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" [[package]] name = "gimli" @@ -256,18 +256,18 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.2" +version = "0.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" dependencies = [ "foldhash", ] [[package]] name = "indexmap" -version = "2.7.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" +checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" dependencies = [ "equivalent", "hashbrown", @@ -275,9 +275,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.169" +version = "0.2.174" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" [[package]] name = "libloading" @@ -297,24 +297,24 @@ checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" [[package]] name = "log" -version = "0.4.22" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "mach2" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +checksum = "d640282b302c0bb0a2a8e0233ead9035e3bed871f0b7e81fe4a1ec829765db44" dependencies = [ "libc", ] [[package]] name = "memchr" -version = "2.7.4" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" [[package]] name = "object" @@ -330,18 +330,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.92" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.38" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] @@ -374,9 +374,9 @@ dependencies = [ [[package]] name = "rustc-hash" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" [[package]] name = "rustc_codegen_cranelift" @@ -398,18 +398,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.217" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.217" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", @@ -418,9 +418,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.2" +version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "stable_deref_trait" @@ -430,9 +430,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "syn" -version = "2.0.95" +version = "2.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46f71c0377baf4ef1cc3e3402ded576dccc315800fbc62dfc7fe04b009773b4a" +checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" dependencies = [ "proc-macro2", "quote", @@ -441,15 +441,15 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc12939a1c9b9d391e0b7135f72fd30508b73450753e28341fed159317582a77" +checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a" [[package]] name = "unicode-ident" -version = "1.0.14" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "wasmtime-jit-icache-coherence" From 66503c1a83c141bff7779c165d6dcdda86cfa755 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 19 Jul 2025 23:23:40 +0200 Subject: [PATCH 056/160] atomicrmw on pointers: move integer-pointer cast hacks into backend --- src/intrinsics/mod.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 4ff5773a06cb2..ed40901ac9b8b 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -969,7 +969,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let layout = amount.layout(); match layout.ty.kind() { - ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + ty::Uint(_) | ty::Int(_) => {} _ => { report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return Ok(()); @@ -982,7 +982,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Add, ptr, amount); - let old = CValue::by_val(old, layout); + let old = CValue::by_val(old, ret.layout()); ret.write_cvalue(fx, old); } sym::atomic_xsub => { @@ -991,7 +991,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let layout = amount.layout(); match layout.ty.kind() { - ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + ty::Uint(_) | ty::Int(_) => {} _ => { report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return Ok(()); @@ -1004,7 +1004,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Sub, ptr, amount); - let old = CValue::by_val(old, layout); + let old = CValue::by_val(old, ret.layout()); ret.write_cvalue(fx, old); } sym::atomic_and => { @@ -1013,7 +1013,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let layout = src.layout(); match layout.ty.kind() { - ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + ty::Uint(_) | ty::Int(_) => {} _ => { report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return Ok(()); @@ -1025,7 +1025,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::And, ptr, src); - let old = CValue::by_val(old, layout); + let old = CValue::by_val(old, ret.layout()); ret.write_cvalue(fx, old); } sym::atomic_or => { @@ -1034,7 +1034,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let layout = src.layout(); match layout.ty.kind() { - ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + ty::Uint(_) | ty::Int(_) => {} _ => { report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return Ok(()); @@ -1046,7 +1046,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Or, ptr, src); - let old = CValue::by_val(old, layout); + let old = CValue::by_val(old, ret.layout()); ret.write_cvalue(fx, old); } sym::atomic_xor => { @@ -1055,7 +1055,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let layout = src.layout(); match layout.ty.kind() { - ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + ty::Uint(_) | ty::Int(_) => {} _ => { report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return Ok(()); @@ -1067,7 +1067,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Xor, ptr, src); - let old = CValue::by_val(old, layout); + let old = CValue::by_val(old, ret.layout()); ret.write_cvalue(fx, old); } sym::atomic_nand => { @@ -1076,7 +1076,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let layout = src.layout(); match layout.ty.kind() { - ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + ty::Uint(_) | ty::Int(_) => {} _ => { report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return Ok(()); @@ -1088,7 +1088,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Nand, ptr, src); - let old = CValue::by_val(old, layout); + let old = CValue::by_val(old, ret.layout()); ret.write_cvalue(fx, old); } sym::atomic_max => { From 6098fb9e48e7358fa916329acd38a5e1889c2824 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 23 Jul 2025 14:42:01 +0000 Subject: [PATCH 057/160] Rustup to rustc 1.90.0-nightly (a7a1618e6 2025-07-22) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index b0c39f661ecf6..b1a53d70b1ae4 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-07-21" +channel = "nightly-2025-07-23" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 17f2c4db532d4ae643387797eca93b9628444ce3 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 27 Jun 2025 14:33:16 +0200 Subject: [PATCH 058/160] Update to Cranelift 0.122 --- Cargo.lock | 80 +++++++++++++++++++++--------------------- Cargo.toml | 24 ++++++------- src/base.rs | 6 ++-- src/common.rs | 3 -- src/value_and_place.rs | 13 ++----- 5 files changed, 57 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a599f8d76a1e..0187e07a6bba9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,42 +43,42 @@ checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "cranelift-assembler-x64" -version = "0.121.0" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f53499803b1607b6ee0ba0de4ba036e6da700c2e489fe8f9d0f683d0b84d31" +checksum = "0ae7b60ec3fd7162427d3b3801520a1908bef7c035b52983cd3ca11b8e7deb51" dependencies = [ "cranelift-assembler-x64-meta", ] [[package]] name = "cranelift-assembler-x64-meta" -version = "0.121.0" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aadaa5bc8430d0e7bb999459369bedd0e5816ad4a82a0e20748341c4e333eda" +checksum = "6511c200fed36452697b4b6b161eae57d917a2044e6333b1c1389ed63ccadeee" dependencies = [ "cranelift-srcgen", ] [[package]] name = "cranelift-bforest" -version = "0.121.0" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2005fda2fc52a2dbce58229b4fb4483b70cbc806ba8ecc11b3f050c1a2d26cac" +checksum = "5f7086a645aa58bae979312f64e3029ac760ac1b577f5cd2417844842a2ca07f" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-bitset" -version = "0.121.0" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56935e02452ca1249d39ad5c45a96304d0b4300a158a391fd113451e0cd4483d" +checksum = "5225b4dec45f3f3dbf383f12560fac5ce8d780f399893607e21406e12e77f491" [[package]] name = "cranelift-codegen" -version = "0.121.0" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62612786bf00e10999f50217d6f455d02b31591155881a45a903d1a95d1a4043" +checksum = "858fb3331e53492a95979378d6df5208dd1d0d315f19c052be8115f4efc888e0" dependencies = [ "bumpalo", "cranelift-assembler-x64", @@ -97,14 +97,14 @@ dependencies = [ "serde", "smallvec", "target-lexicon", - "wasmtime-math", + "wasmtime-internal-math", ] [[package]] name = "cranelift-codegen-meta" -version = "0.121.0" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07bae789df91ef236079733af9df11d852256c64af196f0bc6471ea0f5f301be" +checksum = "456715b9d5f12398f156d5081096e7b5d039f01b9ecc49790a011c8e43e65b5f" dependencies = [ "cranelift-assembler-x64-meta", "cranelift-codegen-shared", @@ -113,33 +113,33 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" -version = "0.121.0" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1be319616d36527782558a8312508757815f64deb19b094c7b8f4337229a9bc6" +checksum = "0306041099499833f167a0ddb707e1e54100f1a84eab5631bc3dad249708f482" [[package]] name = "cranelift-control" -version = "0.121.0" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8810ee1ab5e9bd5cff4c0c8d240e2009cb5c2b79888fde1d5256d605712314b7" +checksum = "1672945e1f9afc2297f49c92623f5eabc64398e2cb0d824f8f72a2db2df5af23" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.121.0" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "086452c97cfbe116bf17dbe622dc5fdf2ea97299c7d4ce42460f284387c9928a" +checksum = "aa3cd55eb5f3825b9ae5de1530887907360a6334caccdc124c52f6d75246c98a" dependencies = [ "cranelift-bitset", ] [[package]] name = "cranelift-frontend" -version = "0.121.0" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c27947010ab759330f252610c17a8cd64d123358be4f33164233d04fcd77b80" +checksum = "781f9905f8139b8de22987b66b522b416fe63eb76d823f0b3a8c02c8fd9500c7" dependencies = [ "cranelift-codegen", "log", @@ -149,15 +149,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.121.0" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec67bfb8bd55b1e9760eb9f5186dca8d81bd4d86110f8d5af01154a044c91802" +checksum = "a05337a2b02c3df00b4dd9a263a027a07b3dff49f61f7da3b5d195c21eaa633d" [[package]] name = "cranelift-jit" -version = "0.121.0" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d67cdfc447f2abdb46bb30a6582cce189539c3c051c1d5330692376e1400edff" +checksum = "593f8ff2c1a1785d9ab61a4b112ec1c9e8a3b976d8857ed1e70a79d4a07dd5ba" dependencies = [ "anyhow", "cranelift-codegen", @@ -169,15 +169,15 @@ dependencies = [ "log", "region", "target-lexicon", - "wasmtime-jit-icache-coherence", + "wasmtime-internal-jit-icache-coherence", "windows-sys 0.59.0", ] [[package]] name = "cranelift-module" -version = "0.121.0" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4597eaa52bca1ed111986c7a7f70cdbe192f83d271d627201365078e37b7e84" +checksum = "f9f7a4b804066f3e62d8fc943e25adc135acbb39288aa6c68e67021a9f6a0c58" dependencies = [ "anyhow", "cranelift-codegen", @@ -186,9 +186,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.121.0" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75a9b63edea46e013fce459c46e500462cb03a0490fdd9c18fe42b1dd7b93aa1" +checksum = "2eee7a496dd66380082c9c5b6f2d5fa149cec0ec383feec5caf079ca2b3671c2" dependencies = [ "cranelift-codegen", "libc", @@ -197,9 +197,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.121.0" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce706f0166d5b7f31693dff521e87cb9858e12adf22ffcde93c4a2826f8f04a9" +checksum = "0dc322ace52184f0ece213f4194f49762e7e854fafdf27b9bfd9fc738ba67708" dependencies = [ "anyhow", "cranelift-codegen", @@ -212,9 +212,9 @@ dependencies = [ [[package]] name = "cranelift-srcgen" -version = "0.121.0" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d5870e266df8237b56cc98b04f5739c228565c92dd629ec6c66efa87271a158" +checksum = "b530783809a55cb68d070e0de60cfbb3db0dc94c8850dd5725411422bedcf6bb" [[package]] name = "crc32fast" @@ -452,10 +452,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] -name = "wasmtime-jit-icache-coherence" -version = "34.0.0" +name = "wasmtime-internal-jit-icache-coherence" +version = "35.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eedc0324e37cf39b049f4dca0c30997eaab49f09006d5f4c1994e64e7b7dba8" +checksum = "4417e06b7f80baff87d9770852c757a39b8d7f11d78b2620ca992b8725f16f50" dependencies = [ "anyhow", "cfg-if", @@ -464,10 +464,10 @@ dependencies = [ ] [[package]] -name = "wasmtime-math" -version = "34.0.0" +name = "wasmtime-internal-math" +version = "35.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd35fae4cf51d2b4a9bd2ef04b0eb309fa1849cab6a6ab5ac27cbd054ea284d" +checksum = "7710d5c4ecdaa772927fd11e5dc30a9a62d1fc8fe933e11ad5576ad596ab6612" dependencies = [ "libm", ] diff --git a/Cargo.toml b/Cargo.toml index a1f406df8c259..274ea16ed9c70 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.121.0", default-features = false, features = ["std", "timing", "unwind", "all-native-arch"] } -cranelift-frontend = { version = "0.121.0" } -cranelift-module = { version = "0.121.0" } -cranelift-native = { version = "0.121.0" } -cranelift-jit = { version = "0.121.0", optional = true } -cranelift-object = { version = "0.121.0" } +cranelift-codegen = { version = "0.122.0", default-features = false, features = ["std", "timing", "unwind", "all-native-arch"] } +cranelift-frontend = { version = "0.122.0" } +cranelift-module = { version = "0.122.0" } +cranelift-native = { version = "0.122.0" } +cranelift-jit = { version = "0.122.0", optional = true } +cranelift-object = { version = "0.122.0" } target-lexicon = "0.13" gimli = { version = "0.31", default-features = false, features = ["write"] } object = { version = "0.36", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } @@ -24,12 +24,12 @@ smallvec = "1.8.1" [patch.crates-io] # Uncomment to use an unreleased version of cranelift -#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-34.0.0", version = "0.121.0" } -#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-34.0.0", version = "0.121.0" } -#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-34.0.0", version = "0.121.0" } -#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-34.0.0", version = "0.121.0" } -#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-34.0.0", version = "0.121.0" } -#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-34.0.0", version = "0.121.0" } +#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-35.0.0" } +#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-35.0.0" } +#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-35.0.0" } +#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-35.0.0" } +#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-35.0.0" } +#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-35.0.0" } # Uncomment to use local checkout of cranelift #cranelift-codegen = { path = "../wasmtime/cranelift/codegen" } diff --git a/src/base.rs b/src/base.rs index 5c826b50e8d1b..e4802e301bb2f 100644 --- a/src/base.rs +++ b/src/base.rs @@ -2,7 +2,7 @@ use cranelift_codegen::CodegenError; use cranelift_codegen::ir::UserFuncName; -use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable}; +use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext}; use cranelift_module::ModuleError; use rustc_ast::InlineAsmOptions; use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization; @@ -90,8 +90,7 @@ pub(crate) fn codegen_fn<'tcx>( None }; - let exception_slot = Variable::from_u32(0); - bcx.declare_var(exception_slot, pointer_type); + let exception_slot = bcx.declare_var(pointer_type); let mut fx = FunctionCx { module, @@ -115,7 +114,6 @@ pub(crate) fn codegen_fn<'tcx>( exception_slot, clif_comments, - next_ssa_var: 1, // var0 is used for the exception slot inline_asm: String::new(), inline_asm_index: 0, }; diff --git a/src/common.rs b/src/common.rs index 2272075c71a60..91b28164b6866 100644 --- a/src/common.rs +++ b/src/common.rs @@ -295,9 +295,6 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> { pub(crate) clif_comments: crate::pretty_clif::CommentWriter, - /// This should only be accessed by `CPlace::new_var`. - pub(crate) next_ssa_var: u32, - pub(crate) inline_asm: String, pub(crate) inline_asm_index: u32, } diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 9d73f200afe2b..269a35b958585 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -393,9 +393,7 @@ impl<'tcx> CPlace<'tcx> { local: Local, layout: TyAndLayout<'tcx>, ) -> CPlace<'tcx> { - let var = Variable::from_u32(fx.next_ssa_var); - fx.next_ssa_var += 1; - fx.bcx.declare_var(var, fx.clif_type(layout.ty).unwrap()); + let var = fx.bcx.declare_var(fx.clif_type(layout.ty).unwrap()); CPlace { inner: CPlaceInner::Var(local, var), layout } } @@ -404,14 +402,9 @@ impl<'tcx> CPlace<'tcx> { local: Local, layout: TyAndLayout<'tcx>, ) -> CPlace<'tcx> { - let var1 = Variable::from_u32(fx.next_ssa_var); - fx.next_ssa_var += 1; - let var2 = Variable::from_u32(fx.next_ssa_var); - fx.next_ssa_var += 1; - let (ty1, ty2) = fx.clif_pair_type(layout.ty).unwrap(); - fx.bcx.declare_var(var1, ty1); - fx.bcx.declare_var(var2, ty2); + let var1 = fx.bcx.declare_var(ty1); + let var2 = fx.bcx.declare_var(ty2); CPlace { inner: CPlaceInner::VarPair(local, var1, var2), layout } } From 8483461b090db76f0da9d9196fcacbb2baed1da5 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 9 Jul 2025 10:15:35 +0000 Subject: [PATCH 059/160] Support used(linker) --- src/constant.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 3bd907b38cf6f..735bbb10b35f8 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -372,6 +372,8 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant continue; } + let mut data = DataDescription::new(); + let (data_id, alloc, section_name) = match todo_item { TodoItem::Alloc(alloc_id) => { let alloc = match tcx.global_alloc(alloc_id) { @@ -390,7 +392,10 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant (data_id, alloc, None) } TodoItem::Static(def_id) => { - let section_name = tcx.codegen_fn_attrs(def_id).link_section; + let codegen_fn_attrs = tcx.codegen_fn_attrs(def_id); + let section_name = codegen_fn_attrs.link_section; + + data.set_used(codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)); let alloc = tcx.eval_static_initializer(def_id).unwrap(); @@ -405,7 +410,6 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant } }; - let mut data = DataDescription::new(); let alloc = alloc.inner(); data.set_align(alloc.align.bytes()); From ae8c473c9f9571f47c01416732facee7df8fb49c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 13 Oct 2023 20:20:57 +0000 Subject: [PATCH 060/160] Give an AllocId to ConstValue::Slice. --- src/constant.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 85adf0f3716b2..a7e9d7c7bae55 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -210,8 +210,7 @@ pub(crate) fn codegen_const_value<'tcx>( .offset_i64(fx, i64::try_from(offset.bytes()).unwrap()), layout, ), - ConstValue::Slice { data, meta } => { - let alloc_id = fx.tcx.reserve_and_set_memory_alloc(data); + ConstValue::Slice { alloc_id, meta, phantom: _ } => { let ptr = pointer_for_allocation(fx, alloc_id).get_addr(fx); let len = fx.bcx.ins().iconst(fx.pointer_type, meta as i64); CValue::by_val_pair(ptr, len, layout) From 83907452bffc4951d5e5a022c23fee097825e844 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 3 Jul 2025 18:41:12 +0000 Subject: [PATCH 061/160] Remove useless lifetime parameter. --- src/constant.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index a7e9d7c7bae55..a04cfa2723763 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -74,7 +74,7 @@ pub(crate) fn codegen_tls_ref<'tcx>( pub(crate) fn eval_mir_constant<'tcx>( fx: &FunctionCx<'_, '_, 'tcx>, constant: &ConstOperand<'tcx>, -) -> (ConstValue<'tcx>, Ty<'tcx>) { +) -> (ConstValue, Ty<'tcx>) { let cv = fx.monomorphize(constant.const_); // This cannot fail because we checked all required_consts in advance. let val = cv @@ -93,7 +93,7 @@ pub(crate) fn codegen_constant_operand<'tcx>( pub(crate) fn codegen_const_value<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, - const_val: ConstValue<'tcx>, + const_val: ConstValue, ty: Ty<'tcx>, ) -> CValue<'tcx> { let layout = fx.layout_of(ty); @@ -210,7 +210,7 @@ pub(crate) fn codegen_const_value<'tcx>( .offset_i64(fx, i64::try_from(offset.bytes()).unwrap()), layout, ), - ConstValue::Slice { alloc_id, meta, phantom: _ } => { + ConstValue::Slice { alloc_id, meta } => { let ptr = pointer_for_allocation(fx, alloc_id).get_addr(fx); let len = fx.bcx.ins().iconst(fx.pointer_type, meta as i64); CValue::by_val_pair(ptr, len, layout) From d47ae4a9b6db4a589850d7f35ac7abd8dd3b3612 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 25 Jul 2025 13:00:22 +0000 Subject: [PATCH 062/160] Rustup to rustc 1.90.0-nightly (b56aaec52 2025-07-24) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index b1a53d70b1ae4..307a0ad12cc82 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-07-23" +channel = "nightly-2025-07-25" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 812388a717cbc1311aa7ab3f321d6503b56ecd16 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 25 Jul 2025 13:27:09 +0000 Subject: [PATCH 063/160] Remove unnecessary download-ci-llvm from setup_rust_fork.sh --- scripts/setup_rust_fork.sh | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index 532702bb1a469..724912973569f 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -25,9 +25,6 @@ git -c user.name=Dummy -c user.email=dummy@example.com -c commit.gpgSign=false \ cat > config.toml < Date: Tue, 1 Jul 2025 09:33:35 -0700 Subject: [PATCH 064/160] Remove `[T]::array_chunks(_mut)` --- patches/0027-sysroot_tests-128bit-atomic-operations.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/0027-sysroot_tests-128bit-atomic-operations.patch b/patches/0027-sysroot_tests-128bit-atomic-operations.patch index f6e6bbc2387c2..f3d1d5c43ea10 100644 --- a/patches/0027-sysroot_tests-128bit-atomic-operations.patch +++ b/patches/0027-sysroot_tests-128bit-atomic-operations.patch @@ -19,7 +19,7 @@ index 1e336bf..35e6f54 100644 -#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))] #![cfg_attr(test, feature(cfg_select))] #![feature(alloc_layout_extra)] - #![feature(array_chunks)] + #![feature(array_ptr_get)] diff --git a/coretests/tests/atomic.rs b/coretests/tests/atomic.rs index b735957..ea728b6 100644 --- a/coretests/tests/atomic.rs From bfdb1c16426131d4d304bc457fbf043e841cd9be Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 29 Jul 2025 14:19:28 +0000 Subject: [PATCH 065/160] Skip pre-defining naked functions --- src/driver/mod.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/driver/mod.rs b/src/driver/mod.rs index 8f83c30b598d8..9f2b7b4b09f22 100644 --- a/src/driver/mod.rs +++ b/src/driver/mod.rs @@ -38,16 +38,12 @@ fn predefine_mono_items<'tcx>( .codegen_instance_attrs(instance.def) .flags .contains(CodegenFnAttrFlags::NAKED); - module - .declare_function( - name, - // Naked functions are defined in a separate object - // file from the codegen unit rustc expects them to - // be defined in. - if is_naked { Linkage::Import } else { linkage }, - &sig, - ) - .unwrap(); + if is_naked { + // Naked functions are defined in a separate object + // file, so they can be declared on the fly. + continue; + } + module.declare_function(name, linkage, &sig).unwrap(); } MonoItem::Static(_) | MonoItem::GlobalAsm(_) => {} } From 00fd153d0d4e3e4956bdbaa8ba2c65e1d0bc1ba6 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 29 Jul 2025 14:41:03 +0000 Subject: [PATCH 066/160] Rustup to rustc 1.90.0-nightly (498ae9fed 2025-07-28) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 307a0ad12cc82..5f9602e509e07 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-07-25" +channel = "nightly-2025-07-29" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 91afcca7c5977fa325a683184ab196f4e2ea811e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 29 Jul 2025 14:55:10 +0000 Subject: [PATCH 067/160] Fix rustc testsuite --- scripts/test_rustc_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 1cd592a09ca67..895088c869d1e 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -62,6 +62,7 @@ rm -r tests/run-make/embed-source-dwarf # embedding sources in debuginfo rm -r tests/run-make/used-proc-macro # used(linker) isn't supported yet rm tests/ui/linking/no-gc-encapsulation-symbols.rs # same rm tests/ui/attributes/fn-align-dyn.rs # per-function alignment not supported +rm -r tests/ui/c-variadic/same-program-multiple-abis.rs # variadics for calling conventions other than C unsupported # requires LTO rm -r tests/run-make/cdylib From 54db8a58d31bf4ac3f329222c0ea513f8286712c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 29 Jul 2025 15:00:41 +0000 Subject: [PATCH 068/160] Revert "Remove unnecessary download-ci-llvm from setup_rust_fork.sh" It caused LLVM to be cloned on CI. This reverts commit 812388a717cbc1311aa7ab3f321d6503b56ecd16. --- scripts/setup_rust_fork.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index 724912973569f..532702bb1a469 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -25,6 +25,9 @@ git -c user.name=Dummy -c user.email=dummy@example.com -c commit.gpgSign=false \ cat > config.toml < Date: Wed, 30 Jul 2025 16:27:33 +0800 Subject: [PATCH 069/160] Update `codegen_{cranelift,gcc}` and `opt-dist` to use `build.compiletest-allow-stage0` --- scripts/setup_rust_fork.sh | 1 + scripts/test_rustc_tests.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index 532702bb1a469..492f4dc445277 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -33,6 +33,7 @@ rustc = "$(pwd)/../dist/bin/rustc-clif" cargo = "$(rustup which cargo)" full-bootstrap = true local-rebuild = true +compiletest-allow-stage0 = true [rust] download-rustc = false diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 7e356b4b462b2..52e02c857c7ad 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -166,5 +166,5 @@ index 073116933bd..c3e4578204d 100644 EOF echo "[TEST] rustc test suite" -COMPILETEST_FORCE_STAGE0=1 ./x.py test --stage 0 --test-args=--no-capture tests/{codegen-units,run-make,ui,incremental} +./x.py test --stage 0 --test-args=--no-capture tests/{codegen-units,run-make,ui,incremental} popd From 0ac38e3fca5d43ae9d31bacb31f3559ece9c1c88 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 31 Jul 2025 09:31:58 +0000 Subject: [PATCH 070/160] Rustup to rustc 1.90.0-nightly (3048886e5 2025-07-30) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 5f9602e509e07..fc01f8c3ccc21 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-07-29" +channel = "nightly-2025-07-31" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 8b11468ac1116e5a50575c5bbd1a49f98a769d89 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 31 Jul 2025 09:47:43 +0000 Subject: [PATCH 071/160] Workaround portable-simd examples compilation failure --- build_system/tests.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/build_system/tests.rs b/build_system/tests.rs index 3c22450a15f62..6dd9ebb845875 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -209,13 +209,15 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ PORTABLE_SIMD.clean(&runner.dirs); - let mut build_cmd = PORTABLE_SIMD.build(&runner.target_compiler, &runner.dirs); - build_cmd.arg("--all-targets"); + let build_cmd = PORTABLE_SIMD.build(&runner.target_compiler, &runner.dirs); + // FIXME uncomment once examples work: https://github.com/rust-lang/portable-simd/issues/470 + //build_cmd.arg("--all-targets"); spawn_and_wait(build_cmd); if runner.is_native { let mut test_cmd = PORTABLE_SIMD.test(&runner.target_compiler, &runner.dirs); - test_cmd.arg("-q"); + // FIXME remove --tests once examples work: https://github.com/rust-lang/portable-simd/issues/470 + test_cmd.arg("-q").arg("--tests"); spawn_and_wait(test_cmd); } }), From 0056e5638e3524edf61143c768bf28284891b1f9 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 5 Aug 2025 08:25:06 +0000 Subject: [PATCH 072/160] Rustup to rustc 1.91.0-nightly (0060d5a2a 2025-08-04) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index fc01f8c3ccc21..7fac7e81e9597 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-07-31" +channel = "nightly-2025-08-05" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 878f3198818e0d2cd9563d44287f028d5392cdff Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 5 Aug 2025 08:32:33 +0000 Subject: [PATCH 073/160] Fix rustc test suite --- scripts/test_rustc_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index fa6b6bffe9ecd..3feda057a4dd2 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -63,6 +63,7 @@ rm -r tests/run-make/used-proc-macro # used(linker) isn't supported yet rm tests/ui/linking/no-gc-encapsulation-symbols.rs # same rm tests/ui/attributes/fn-align-dyn.rs # per-function alignment not supported rm -r tests/ui/c-variadic/same-program-multiple-abis.rs # variadics for calling conventions other than C unsupported +rm -r tests/ui/explicit-tail-calls # tail calls # requires LTO rm -r tests/run-make/cdylib From f4fde2092b3ad19f7b39fda98f6763a22b69ff1c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 7 Aug 2025 13:13:04 +0000 Subject: [PATCH 074/160] Prevent name collisions with internal implementation details The implementation of the linkage attribute inside extern blocks defines symbols starting with _rust_extern_with_linkage_. If someone tries to also define this symbol you will get a symbol conflict or even an ICE. By adding an unpredictable component to the symbol name, this becomes less of an issue. --- src/constant.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/constant.rs b/src/constant.rs index a04cfa2723763..bec546badc9cf 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -310,7 +310,10 @@ fn data_id_for_static( // `extern_with_linkage_foo` will instead be initialized to // zero. - let ref_name = format!("_rust_extern_with_linkage_{}", symbol_name); + let ref_name = format!( + "_rust_extern_with_linkage_{:016x}_{symbol_name}", + tcx.stable_crate_id(LOCAL_CRATE) + ); let ref_data_id = module.declare_data(&ref_name, Linkage::Local, false, false).unwrap(); let mut data = DataDescription::new(); data.set_align(align); From 20cc800415b4b491033d6a53b7fb31b5895b97ce Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 13 Aug 2025 13:39:03 +0000 Subject: [PATCH 075/160] Rustup to rustc 1.91.0-nightly (8e62bfd31 2025-08-12) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 7fac7e81e9597..603413f6a78f8 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-08-05" +channel = "nightly-2025-08-13" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From d962e00471936cbbefbca80666c4566dd5ac08d5 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 13 Aug 2025 13:46:55 +0000 Subject: [PATCH 076/160] Fix rustc test suite --- scripts/setup_rust_fork.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index 492f4dc445277..84c7ad534561a 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -50,23 +50,23 @@ EOF cat <( + ); + } -- if b && self.is_running_on_ci { -- // On CI, we must always rebuild LLVM if there were any modifications to it -- panic!( -- "\`llvm.download-ci-llvm\` cannot be set to \`true\` on CI. Use \`if-unchanged\` instead." -- ); -- } +- if b && dwn_ctx.is_running_on_ci { +- // On CI, we must always rebuild LLVM if there were any modifications to it +- panic!( +- "\`llvm.download-ci-llvm\` cannot be set to \`true\` on CI. Use \`if-unchanged\` instead." +- ); +- } - - // If download-ci-llvm=true we also want to check that CI llvm is available - b && llvm::is_ci_llvm_available_for_target(self, asserts) - } + // If download-ci-llvm=true we also want to check that CI llvm is available + b && llvm::is_ci_llvm_available_for_target(&dwn_ctx.host_target, asserts) + } EOF popd From 69402da11eacde8945bbf3551a2d9db23965a982 Mon Sep 17 00:00:00 2001 From: Sasha Pourcelot Date: Tue, 12 Aug 2025 20:22:45 +0200 Subject: [PATCH 077/160] Port the `#[linkage]` attribute to the new attribute system --- src/constant.rs | 8 ++++---- src/driver/aot.rs | 5 ++--- src/linkage.rs | 3 ++- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index bec546badc9cf..a56466750e75c 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -281,8 +281,8 @@ fn data_id_for_static( .abi .bytes(); - let linkage = if import_linkage == rustc_middle::mir::mono::Linkage::ExternalWeak - || import_linkage == rustc_middle::mir::mono::Linkage::WeakAny + let linkage = if import_linkage == rustc_hir::attrs::Linkage::ExternalWeak + || import_linkage == rustc_hir::attrs::Linkage::WeakAny { Linkage::Preemptible } else { @@ -332,8 +332,8 @@ fn data_id_for_static( let linkage = if definition { crate::linkage::get_static_linkage(tcx, def_id) - } else if attrs.linkage == Some(rustc_middle::mir::mono::Linkage::ExternalWeak) - || attrs.linkage == Some(rustc_middle::mir::mono::Linkage::WeakAny) + } else if attrs.linkage == Some(rustc_hir::attrs::Linkage::ExternalWeak) + || attrs.linkage == Some(rustc_hir::attrs::Linkage::WeakAny) { Linkage::Preemptible } else { diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 8ec3599b63d89..7e77781dc2fc1 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -18,12 +18,11 @@ use rustc_codegen_ssa::{ use rustc_data_structures::profiling::SelfProfilerRef; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::{IntoDynSyncSend, par_map}; +use rustc_hir::attrs::Linkage as RLinkage; use rustc_metadata::fs::copy_to_stdout; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; -use rustc_middle::mir::mono::{ - CodegenUnit, Linkage as RLinkage, MonoItem, MonoItemData, Visibility, -}; +use rustc_middle::mir::mono::{CodegenUnit, MonoItem, MonoItemData, Visibility}; use rustc_session::Session; use rustc_session::config::{DebugInfo, OutFileName, OutputFilenames, OutputType}; diff --git a/src/linkage.rs b/src/linkage.rs index ca853aac15892..d76ab9d0109f0 100644 --- a/src/linkage.rs +++ b/src/linkage.rs @@ -1,4 +1,5 @@ -use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility}; +use rustc_hir::attrs::Linkage as RLinkage; +use rustc_middle::mir::mono::{MonoItem, Visibility}; use crate::prelude::*; From 420235c0f87bd379e3bd318b401ebbf08d82c44d Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 18 Aug 2025 16:24:09 +0000 Subject: [PATCH 078/160] Rustup to rustc 1.91.0-nightly (425a9c0a0 2025-08-17) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 603413f6a78f8..4cd356e94b782 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-08-13" +channel = "nightly-2025-08-18" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From f4383ffa732267b74a9e23ae30a092f9ea4c2071 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 18 Aug 2025 16:43:49 +0000 Subject: [PATCH 079/160] Fix rustc test suite --- scripts/test_rustc_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 3feda057a4dd2..7257cf97a3655 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -149,6 +149,7 @@ rm tests/ui/backtrace/synchronized-panic-handler.rs # missing needs-unwind annot rm tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rs # same rm tests/ui/async-await/async-drop/async-drop-initial.rs # same (rust-lang/rust#140493) rm -r tests/ui/codegen/equal-pointers-unequal # make incorrect assumptions about the location of stack variables +rm -r tests/run-make/rustdoc-scrape-examples-paths # FIXME(rust-lang/rust#145580) incr comp bug rm tests/ui/intrinsics/panic-uninitialized-zeroed.rs # really slow with unoptimized libstd rm tests/ui/process/process-panic-after-fork.rs # same From 8cb157c17d01e7130cd177f3c327663c01035376 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 6 Aug 2025 10:57:09 +0000 Subject: [PATCH 080/160] Update to Cranelift 0.123 --- Cargo.lock | 188 ++++++++++++++++++++++++++++------------ Cargo.toml | 28 +++--- src/abi/mod.rs | 8 +- src/debuginfo/mod.rs | 1 + src/debuginfo/unwind.rs | 40 +++++---- src/intrinsics/mod.rs | 8 +- 6 files changed, 181 insertions(+), 92 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0187e07a6bba9..2f58bcc00b18c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,42 +43,42 @@ checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "cranelift-assembler-x64" -version = "0.122.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ae7b60ec3fd7162427d3b3801520a1908bef7c035b52983cd3ca11b8e7deb51" +checksum = "ed4b70d50ef7f5a1fe6acd4dd5fe1050abb96da29cfd9dbd816425468b077054" dependencies = [ "cranelift-assembler-x64-meta", ] [[package]] name = "cranelift-assembler-x64-meta" -version = "0.122.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6511c200fed36452697b4b6b161eae57d917a2044e6333b1c1389ed63ccadeee" +checksum = "e2a0508022f39d640b5830b831dd3cb98e4d5e2d35b46cf9fc2a098805234365" dependencies = [ "cranelift-srcgen", ] [[package]] name = "cranelift-bforest" -version = "0.122.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f7086a645aa58bae979312f64e3029ac760ac1b577f5cd2417844842a2ca07f" +checksum = "56f60341caf62338f84d8e1a6261d9b72b00932564094d37d12215028a3fae95" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-bitset" -version = "0.122.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5225b4dec45f3f3dbf383f12560fac5ce8d780f399893607e21406e12e77f491" +checksum = "9f01687e7f1cb4ec9394b4ba13c1e1835edbec012304cf2f854537deec901aeb" [[package]] name = "cranelift-codegen" -version = "0.122.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "858fb3331e53492a95979378d6df5208dd1d0d315f19c052be8115f4efc888e0" +checksum = "7c24d59006f532c84fae3c7bae9fadfc569d9912c5d0bf67ea8c20de289b5786" dependencies = [ "bumpalo", "cranelift-assembler-x64", @@ -102,44 +102,45 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.122.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456715b9d5f12398f156d5081096e7b5d039f01b9ecc49790a011c8e43e65b5f" +checksum = "0b250ca6c45149339f3908f1137f28faa4dba0f12673f8b6c6201a733f6e012a" dependencies = [ "cranelift-assembler-x64-meta", "cranelift-codegen-shared", "cranelift-srcgen", + "heck", ] [[package]] name = "cranelift-codegen-shared" -version = "0.122.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0306041099499833f167a0ddb707e1e54100f1a84eab5631bc3dad249708f482" +checksum = "4923507eb61e357184e4c5e11052dbca7abcee3a306dfaa62cd2f2bdd9851c51" [[package]] name = "cranelift-control" -version = "0.122.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1672945e1f9afc2297f49c92623f5eabc64398e2cb0d824f8f72a2db2df5af23" +checksum = "ed6bf355bddc171ac2d5a62e6cfa8f1eb1b37667924210e400cbc65e53870bf2" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.122.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa3cd55eb5f3825b9ae5de1530887907360a6334caccdc124c52f6d75246c98a" +checksum = "60f0c0e4057964aa3c6597606986ed5df32d465838ad389f226461bf562555c7" dependencies = [ "cranelift-bitset", ] [[package]] name = "cranelift-frontend" -version = "0.122.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "781f9905f8139b8de22987b66b522b416fe63eb76d823f0b3a8c02c8fd9500c7" +checksum = "f39ca2f29e01050443d5d4d59fe674b7107641d79a9a847d5a01fded8264b9f2" dependencies = [ "cranelift-codegen", "log", @@ -149,15 +150,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.122.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a05337a2b02c3df00b4dd9a263a027a07b3dff49f61f7da3b5d195c21eaa633d" +checksum = "14633795ccf9b5f3ef8484dc6bfed943118330fc18a2172dc7aac661473558b1" [[package]] name = "cranelift-jit" -version = "0.122.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "593f8ff2c1a1785d9ab61a4b112ec1c9e8a3b976d8857ed1e70a79d4a07dd5ba" +checksum = "de5044e1a2211eaf40348f387334566f266531b7a6ae60fb7d0c944db0ad8731" dependencies = [ "anyhow", "cranelift-codegen", @@ -170,14 +171,14 @@ dependencies = [ "region", "target-lexicon", "wasmtime-internal-jit-icache-coherence", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "cranelift-module" -version = "0.122.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9f7a4b804066f3e62d8fc943e25adc135acbb39288aa6c68e67021a9f6a0c58" +checksum = "625cb9020a5358a194da5a3a918d1ff29ee89f8191a3ccd7a485255364f32776" dependencies = [ "anyhow", "cranelift-codegen", @@ -186,9 +187,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.122.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eee7a496dd66380082c9c5b6f2d5fa149cec0ec383feec5caf079ca2b3671c2" +checksum = "2a178fab381ece04958d895eff2bd5ddecb8537e08fb1af3eb92e45dd3e50301" dependencies = [ "cranelift-codegen", "libc", @@ -197,9 +198,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.122.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc322ace52184f0ece213f4194f49762e7e854fafdf27b9bfd9fc738ba67708" +checksum = "11fc0edb2994ccc8802801c35c08572c443dca716e988110e63bfc9d81f0bbf1" dependencies = [ "anyhow", "cranelift-codegen", @@ -212,9 +213,9 @@ dependencies = [ [[package]] name = "cranelift-srcgen" -version = "0.122.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b530783809a55cb68d070e0de60cfbb3db0dc94c8850dd5725411422bedcf6bb" +checksum = "07a6f374259f252ae78cbf9aad469091d6a51adda43cb91d23610532cf2b978e" [[package]] name = "crc32fast" @@ -245,9 +246,9 @@ checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" [[package]] name = "gimli" -version = "0.31.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +checksum = "93563d740bc9ef04104f9ed6f86f1e3275c2cdafb95664e26584b9ca807a8ffe" dependencies = [ "fallible-iterator", "indexmap", @@ -263,6 +264,12 @@ dependencies = [ "foldhash", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "indexmap" version = "2.10.0" @@ -286,7 +293,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -318,9 +325,9 @@ checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" [[package]] name = "object" -version = "0.36.7" +version = "0.37.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe" dependencies = [ "crc32fast", "hashbrown", @@ -453,41 +460,47 @@ checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "wasmtime-internal-jit-icache-coherence" -version = "35.0.0" +version = "36.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4417e06b7f80baff87d9770852c757a39b8d7f11d78b2620ca992b8725f16f50" +checksum = "118c225f1c3c688c423de99d590b6e06fa811207090eeb9f4423b6a2d0113ff5" dependencies = [ "anyhow", "cfg-if", "libc", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "wasmtime-internal-math" -version = "35.0.0" +version = "36.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7710d5c4ecdaa772927fd11e5dc30a9a62d1fc8fe933e11ad5576ad596ab6612" +checksum = "8b2378d723f821a5f24076bd9bed4ec849c24717c7af188d4f31fff1d7fc6cfe" dependencies = [ "libm", ] +[[package]] +name = "windows-link" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] name = "windows-sys" -version = "0.59.0" +version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" dependencies = [ - "windows-targets", + "windows-targets 0.53.3", ] [[package]] @@ -496,14 +509,31 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.0", + "windows_aarch64_msvc 0.53.0", + "windows_i686_gnu 0.53.0", + "windows_i686_gnullvm 0.53.0", + "windows_i686_msvc 0.53.0", + "windows_x86_64_gnu 0.53.0", + "windows_x86_64_gnullvm 0.53.0", + "windows_x86_64_msvc 0.53.0", ] [[package]] @@ -512,44 +542,92 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" diff --git a/Cargo.toml b/Cargo.toml index 274ea16ed9c70..945854842f2d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,15 +8,15 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.122.0", default-features = false, features = ["std", "timing", "unwind", "all-native-arch"] } -cranelift-frontend = { version = "0.122.0" } -cranelift-module = { version = "0.122.0" } -cranelift-native = { version = "0.122.0" } -cranelift-jit = { version = "0.122.0", optional = true } -cranelift-object = { version = "0.122.0" } +cranelift-codegen = { version = "0.123.0", default-features = false, features = ["std", "timing", "unwind", "all-native-arch"] } +cranelift-frontend = { version = "0.123.0" } +cranelift-module = { version = "0.123.0" } +cranelift-native = { version = "0.123.0" } +cranelift-jit = { version = "0.123.0", optional = true } +cranelift-object = { version = "0.123.0" } target-lexicon = "0.13" -gimli = { version = "0.31", default-features = false, features = ["write"] } -object = { version = "0.36", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } +gimli = { version = "0.32", default-features = false, features = ["write"] } +object = { version = "0.37.3", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } indexmap = "2.0.0" libloading = { version = "0.8.0", optional = true } @@ -24,12 +24,12 @@ smallvec = "1.8.1" [patch.crates-io] # Uncomment to use an unreleased version of cranelift -#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-35.0.0" } -#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-35.0.0" } -#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-35.0.0" } -#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-35.0.0" } -#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-35.0.0" } -#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-35.0.0" } +#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-36.0.0" } +#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-36.0.0" } +#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-36.0.0" } +#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-36.0.0" } +#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-36.0.0" } +#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-36.0.0" } # Uncomment to use local checkout of cranelift #cranelift-codegen = { path = "../wasmtime/cranelift/codegen" } diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 52f1a946762f8..075f2e2f59778 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -7,7 +7,9 @@ mod returning; use std::borrow::Cow; use std::mem; -use cranelift_codegen::ir::{ArgumentPurpose, BlockArg, ExceptionTableData, ExceptionTag, SigRef}; +use cranelift_codegen::ir::{ + ArgumentPurpose, BlockArg, ExceptionTableData, ExceptionTableItem, ExceptionTag, SigRef, +}; use cranelift_codegen::isa::CallConv; use cranelift_module::ModuleError; use rustc_abi::{CanonAbi, ExternAbi, X86Call}; @@ -856,8 +858,8 @@ pub(crate) fn codegen_call_with_unwind_action( let exception_table = fx.bcx.func.dfg.exception_tables.push(ExceptionTableData::new( sig_ref, fallthrough_block_call, - [( - Some(ExceptionTag::with_number(EXCEPTION_HANDLER_CLEANUP).unwrap()), + [ExceptionTableItem::Tag( + ExceptionTag::with_number(EXCEPTION_HANDLER_CLEANUP).unwrap(), pre_cleanup_block_call, )], )); diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index 391ce52008478..05b0253eff972 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -120,6 +120,7 @@ impl DebugContext { encoding, LineEncoding::default(), LineString::new(comp_dir.as_bytes(), encoding, &mut dwarf.line_strings), + None, LineString::new(name.as_bytes(), encoding, &mut dwarf.line_strings), file_info, ); diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs index 02f6b1d39bc22..ecaf88a26259e 100644 --- a/src/debuginfo/unwind.rs +++ b/src/debuginfo/unwind.rs @@ -1,5 +1,6 @@ //! Unwind info generation (`.eh_frame`) +use cranelift_codegen::FinalizedMachExceptionHandler; use cranelift_codegen::ir::Endianness; use cranelift_codegen::isa::unwind::UnwindInfo; use cranelift_module::DataId; @@ -172,23 +173,28 @@ impl UnwindContext { action_entry: None, }); } - for &(tag, landingpad) in call_site.exception_handlers { - match tag.expand().unwrap().as_u32() { - EXCEPTION_HANDLER_CLEANUP => { - gcc_except_table_data.call_sites.0.push(CallSite { - start: u64::from(call_site.ret_addr - 1), - length: 1, - landing_pad: u64::from(landingpad), - action_entry: None, - }) - } - EXCEPTION_HANDLER_CATCH => { - gcc_except_table_data.call_sites.0.push(CallSite { - start: u64::from(call_site.ret_addr - 1), - length: 1, - landing_pad: u64::from(landingpad), - action_entry: Some(catch_action), - }) + for &handler in call_site.exception_handlers { + match handler { + FinalizedMachExceptionHandler::Tag(tag, landingpad) => { + match tag.as_u32() { + EXCEPTION_HANDLER_CLEANUP => { + gcc_except_table_data.call_sites.0.push(CallSite { + start: u64::from(call_site.ret_addr - 1), + length: 1, + landing_pad: u64::from(landingpad), + action_entry: None, + }) + } + EXCEPTION_HANDLER_CATCH => { + gcc_except_table_data.call_sites.0.push(CallSite { + start: u64::from(call_site.ret_addr - 1), + length: 1, + landing_pad: u64::from(landingpad), + action_entry: Some(catch_action), + }) + } + _ => unreachable!(), + } } _ => unreachable!(), } diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index d240ff3b3dd3b..eab1a506fd0e9 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -17,7 +17,9 @@ mod llvm_aarch64; mod llvm_x86; mod simd; -use cranelift_codegen::ir::{AtomicRmwOp, BlockArg, ExceptionTableData, ExceptionTag}; +use cranelift_codegen::ir::{ + AtomicRmwOp, BlockArg, ExceptionTableData, ExceptionTableItem, ExceptionTag, +}; use rustc_middle::ty; use rustc_middle::ty::GenericArgsRef; use rustc_middle::ty::layout::ValidityRequirement; @@ -1381,8 +1383,8 @@ fn codegen_regular_intrinsic_call<'tcx>( fx.bcx.func.dfg.exception_tables.push(ExceptionTableData::new( f_sig, fallthrough_block_call, - [( - Some(ExceptionTag::with_number(EXCEPTION_HANDLER_CATCH).unwrap()), + [ExceptionTableItem::Tag( + ExceptionTag::with_number(EXCEPTION_HANDLER_CATCH).unwrap(), catch_block_call, )], )); From 4a47066323a5d4b0068126101d6ac4fb81b3c463 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 13 Aug 2025 11:29:36 +0000 Subject: [PATCH 081/160] Update libloading This pulls in a newer version of windows-targets. The region crate still pulls in the older version though. --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2f58bcc00b18c..2c6acb600b772 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -288,12 +288,12 @@ checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" [[package]] name = "libloading" -version = "0.8.6" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" +checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" dependencies = [ "cfg-if", - "windows-targets 0.52.6", + "windows-targets 0.53.3", ] [[package]] From 69d5855ba3a100fadda5692eb4e1bc90e67528ac Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 21 Aug 2025 13:19:08 +0000 Subject: [PATCH 082/160] Rustup to rustc 1.91.0-nightly (040a98af7 2025-08-20) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 4cd356e94b782..f017fe3c30242 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-08-18" +channel = "nightly-2025-08-21" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 8c3a60c0879c03266c7f589e44450fc14af6b3e0 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 21 Aug 2025 13:25:12 +0000 Subject: [PATCH 083/160] Fix rustc test suite --- scripts/test_rustc_tests.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 7257cf97a3655..0517b16acdf49 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -75,7 +75,6 @@ rm -r tests/run-make/reachable-extern-fn-available-lto # coverage instrumentation rm tests/ui/consts/precise-drop-with-coverage.rs -rm tests/ui/issues/issue-85461.rs rm -r tests/ui/instrument-coverage/ # optimization tests From dbca51abe68f0fbc562cb7a0309bf8b7a337d60e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 21 Aug 2025 13:37:30 +0000 Subject: [PATCH 084/160] Temporarily disable x86_64 macOS Upstream rustc broke it when turning it into a tier 2 target --- .github/workflows/abi-cafe.yml | 7 ++++--- .github/workflows/main.yml | 14 ++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/abi-cafe.yml b/.github/workflows/abi-cafe.yml index 6ad041a796c92..75a506868a0fa 100644 --- a/.github/workflows/abi-cafe.yml +++ b/.github/workflows/abi-cafe.yml @@ -28,9 +28,10 @@ jobs: - os: ubuntu-24.04-arm env: TARGET_TRIPLE: aarch64-unknown-linux-gnu - - os: macos-13 - env: - TARGET_TRIPLE: x86_64-apple-darwin + # FIXME(rust-lang/rust#145699) + #- os: macos-13 + # env: + # TARGET_TRIPLE: x86_64-apple-darwin - os: macos-latest env: TARGET_TRIPLE: aarch64-apple-darwin diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d92e0fdce99a8..c7409fa634291 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -56,9 +56,10 @@ jobs: - os: ubuntu-24.04-arm env: TARGET_TRIPLE: aarch64-unknown-linux-gnu - - os: macos-13 - env: - TARGET_TRIPLE: x86_64-apple-darwin + # FIXME(rust-lang/rust#145699) + #- os: macos-13 + # env: + # TARGET_TRIPLE: x86_64-apple-darwin - os: macos-latest env: TARGET_TRIPLE: aarch64-apple-darwin @@ -187,9 +188,10 @@ jobs: - os: ubuntu-24.04-arm env: TARGET_TRIPLE: aarch64-unknown-linux-gnu - - os: macos-13 - env: - TARGET_TRIPLE: x86_64-apple-darwin + # FIXME(rust-lang/rust#145699) + #- os: macos-13 + # env: + # TARGET_TRIPLE: x86_64-apple-darwin - os: macos-latest env: TARGET_TRIPLE: aarch64-apple-darwin From cdab4cc90ead3845ac3c78a3c6a2a01299281684 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 24 Aug 2025 13:22:55 +0000 Subject: [PATCH 085/160] Rustup to rustc 1.91.0-nightly (69b76df90 2025-08-23) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index f017fe3c30242..53ef4a76f41aa 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-08-21" +channel = "nightly-2025-08-24" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 03505e815c9c3f159febcd57e7d6dca19b0cc605 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 24 Aug 2025 13:49:04 +0000 Subject: [PATCH 086/160] Fix rustc test suite --- scripts/test_rustc_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 0517b16acdf49..13951c0a70a8d 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -62,7 +62,7 @@ rm -r tests/run-make/embed-source-dwarf # embedding sources in debuginfo rm -r tests/run-make/used-proc-macro # used(linker) isn't supported yet rm tests/ui/linking/no-gc-encapsulation-symbols.rs # same rm tests/ui/attributes/fn-align-dyn.rs # per-function alignment not supported -rm -r tests/ui/c-variadic/same-program-multiple-abis.rs # variadics for calling conventions other than C unsupported +rm tests/ui/c-variadic/same-program-multiple-abis-x86_64.rs # variadics for calling conventions other than C unsupported rm -r tests/ui/explicit-tail-calls # tail calls # requires LTO From 2da17a63843f81f6f006f5116834bb8c0a827a5d Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 28 Aug 2025 09:45:53 +0000 Subject: [PATCH 087/160] Rustup to rustc 1.91.0-nightly (cdb45c87e 2025-08-27) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 53ef4a76f41aa..6fe2ec48e6068 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-08-24" +channel = "nightly-2025-08-28" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 42943a93cc6f9ba87213e212da7ee4c84a9bcf98 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 29 Aug 2025 18:41:14 +0000 Subject: [PATCH 088/160] Re-enable x86_64 macOS CI builds --- .github/workflows/main.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c7409fa634291..d92e0fdce99a8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -56,10 +56,9 @@ jobs: - os: ubuntu-24.04-arm env: TARGET_TRIPLE: aarch64-unknown-linux-gnu - # FIXME(rust-lang/rust#145699) - #- os: macos-13 - # env: - # TARGET_TRIPLE: x86_64-apple-darwin + - os: macos-13 + env: + TARGET_TRIPLE: x86_64-apple-darwin - os: macos-latest env: TARGET_TRIPLE: aarch64-apple-darwin @@ -188,10 +187,9 @@ jobs: - os: ubuntu-24.04-arm env: TARGET_TRIPLE: aarch64-unknown-linux-gnu - # FIXME(rust-lang/rust#145699) - #- os: macos-13 - # env: - # TARGET_TRIPLE: x86_64-apple-darwin + - os: macos-13 + env: + TARGET_TRIPLE: x86_64-apple-darwin - os: macos-latest env: TARGET_TRIPLE: aarch64-apple-darwin From b494d3e73dd17318032fa406f3deb73cc7b659ac Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 15 Aug 2025 09:13:23 +1000 Subject: [PATCH 089/160] Avoid unnecessary `mut`-ness for various closures. --- src/base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base.rs b/src/base.rs index bc0a0f034b236..aefb9c9a11564 100644 --- a/src/base.rs +++ b/src/base.rs @@ -46,7 +46,7 @@ pub(crate) fn codegen_fn<'tcx>( with_no_trimmed_paths!({ use rustc_middle::mir::pretty; let options = pretty::PrettyPrintMirOptions::from_cli(tcx); - pretty::write_mir_fn(tcx, mir, &mut |_, _| Ok(()), &mut buf, options).unwrap(); + pretty::write_mir_fn(tcx, mir, &|_, _| Ok(()), &mut buf, options).unwrap(); }); String::from_utf8_lossy(&buf).into_owned() }); From 3293a0b6b7973f816652c4a2380eb897b4f262ed Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 15 Aug 2025 14:38:17 +1000 Subject: [PATCH 090/160] Introduce `MirDumper` and `MirWriter`. MIR dumping is a mess. There are lots of functions and entry points, e.g. `dump_mir`, `dump_mir_with_options`, `dump_polonius_mir`, `dump_mir_to_writer`. Also, it's crucial that `create_dump_file` is never called without `dump_enabled` first being checked, but there is no mechanism for ensuring this and it's hard to tell if it is satisfied on all paths. (`dump_enabled` is checked twice on some paths, however!) This commit introduces `MirWriter`, which controls the MIR writing, and encapsulates the `extra_data` closure and `options`. Two existing functions are now methods of this type. It sets reasonable defaults, allowing the removal of many `|_, _| Ok(())` closures. The commit also introduces `MirDumper`, which is layered on top of `MirWriter`, and which manages the creation of the dump files, encapsulating pass names, disambiguators, etc. Four existing functions are now methods of this type. - `MirDumper::new` will only succeed if dumps are enabled, and will return `None` otherwise, which makes it impossible to dump when you shouldn't. - It also sets reasonable defaults for various things like disambiguators, which means you no longer need to specify them in many cases. When they do need to be specified, it's now done via setter methods. - It avoids some repetition. E.g. `dump_nll_mir` previously specifed the pass name `"nll"` four times and the disambiguator `&0` three times; now it specifies them just once, to put them in the `MirDumper`. - For Polonius, the `extra_data` closure can now be specified earlier, which avoids having to pass some arguments through some functions. --- src/base.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/base.rs b/src/base.rs index aefb9c9a11564..3a28dd7e73cb3 100644 --- a/src/base.rs +++ b/src/base.rs @@ -44,9 +44,8 @@ pub(crate) fn codegen_fn<'tcx>( let _mir_guard = crate::PrintOnPanic(|| { let mut buf = Vec::new(); with_no_trimmed_paths!({ - use rustc_middle::mir::pretty; - let options = pretty::PrettyPrintMirOptions::from_cli(tcx); - pretty::write_mir_fn(tcx, mir, &|_, _| Ok(()), &mut buf, options).unwrap(); + let writer = pretty::MirWriter::new(tcx); + writer.write_mir_fn(mir, &mut buf).unwrap(); }); String::from_utf8_lossy(&buf).into_owned() }); From 9de73c86f373edec2381d17da180d9d533190519 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 2 Sep 2025 17:23:07 +0000 Subject: [PATCH 091/160] Rename the default branch to main --- scripts/rustup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/rustup.sh b/scripts/rustup.sh index 152c243aa6adc..fdfd03029b160 100755 --- a/scripts/rustup.sh +++ b/scripts/rustup.sh @@ -46,7 +46,7 @@ case $1 in git pull origin master branch=sync_cg_clif-$(date +%Y-%m-%d) git checkout -b "$branch" - "$cg_clif/git-fixed-subtree.sh" pull --prefix=compiler/rustc_codegen_cranelift/ https://github.com/rust-lang/rustc_codegen_cranelift.git master + "$cg_clif/git-fixed-subtree.sh" pull --prefix=compiler/rustc_codegen_cranelift/ https://github.com/rust-lang/rustc_codegen_cranelift.git main git push -u my "$branch" # immediately merge the merge commit into cg_clif to prevent merge conflicts when syncing From 3b311c32e59c2040c8c2d62762a01bb4a400fccd Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 2 Sep 2025 20:03:41 +0000 Subject: [PATCH 092/160] Rustup to rustc 1.91.0-nightly (7aef4bec4 2025-09-01) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 6fe2ec48e6068..ee94deedfe4ce 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-08-28" +channel = "nightly-2025-09-02" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 8878a67f1bb5c90884cc60ea567e38f933b9e831 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 28 Aug 2025 10:26:29 +0000 Subject: [PATCH 093/160] Special case allocator module submission to avoid special casing it elsewhere A lot of places had special handling just in case they would get an allocator module even though most of these places could never get one or would have a trivial implementation for the allocator module. Moving all handling of the allocator module to a single place simplifies things a fair bit. --- src/driver/aot.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 7e77781dc2fc1..c3adb5e767e25 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -12,9 +12,7 @@ use cranelift_object::{ObjectBuilder, ObjectModule}; use rustc_codegen_ssa::assert_module_sources::CguReuse; use rustc_codegen_ssa::back::link::ensure_removed; use rustc_codegen_ssa::base::determine_cgu_reuse; -use rustc_codegen_ssa::{ - CodegenResults, CompiledModule, CrateInfo, ModuleKind, errors as ssa_errors, -}; +use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, errors as ssa_errors}; use rustc_data_structures::profiling::SelfProfilerRef; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::{IntoDynSyncSend, par_map}; @@ -363,7 +361,6 @@ fn emit_cgu( invocation_temp, prof, product.object, - ModuleKind::Regular, name.clone(), producer, )?; @@ -372,7 +369,6 @@ fn emit_cgu( module_regular, module_global_asm: global_asm_object_file.map(|global_asm_object_file| CompiledModule { name: format!("{name}.asm"), - kind: ModuleKind::Regular, object: Some(global_asm_object_file), dwarf_object: None, bytecode: None, @@ -389,7 +385,6 @@ fn emit_module( invocation_temp: Option<&str>, prof: &SelfProfilerRef, mut object: cranelift_object::object::write::Object<'_>, - kind: ModuleKind, name: String, producer_str: &str, ) -> Result { @@ -430,7 +425,6 @@ fn emit_module( Ok(CompiledModule { name, - kind, object: Some(tmp_file), dwarf_object: None, bytecode: None, @@ -485,7 +479,6 @@ fn reuse_workproduct_for_cgu( Ok(ModuleCodegenResult { module_regular: CompiledModule { name: cgu.name().to_string(), - kind: ModuleKind::Regular, object: Some(obj_out_regular), dwarf_object: None, bytecode: None, @@ -495,7 +488,6 @@ fn reuse_workproduct_for_cgu( }, module_global_asm: source_file_global_asm.map(|source_file| CompiledModule { name: cgu.name().to_string(), - kind: ModuleKind::Regular, object: Some(obj_out_global_asm), dwarf_object: None, bytecode: None, @@ -651,7 +643,6 @@ fn emit_allocator_module(tcx: TyCtxt<'_>) -> Option { tcx.sess.invocation_temp.as_deref(), &tcx.sess.prof, product.object, - ModuleKind::Allocator, "allocator_shim".to_owned(), &crate::debuginfo::producer(tcx.sess), ) { From 39d8f6a7a32e6322b526fd266fe32622ead219dc Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Fri, 5 Sep 2025 16:35:36 +0800 Subject: [PATCH 094/160] cg_clif: account for moved `tests/run-make-cargo/compiler-builtins` --- scripts/test_rustc_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 52e02c857c7ad..476a6f311bbf4 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -121,7 +121,7 @@ rm tests/ui/abi/large-byval-align.rs # exceeds implementation limit of Cranelift # ============================================================ rm -r tests/run-make/remap-path-prefix-dwarf # requires llvm-dwarfdump rm -r tests/run-make/strip # same -rm -r tests/run-make/compiler-builtins # Expects lib/rustlib/src/rust to contains the standard library source +rm -r tests/run-make-cargo/compiler-builtins # Expects lib/rustlib/src/rust to contains the standard library source rm -r tests/run-make/translation # same rm -r tests/run-make/missing-unstable-trait-bound # This disables support for unstable features, but running cg_clif needs some unstable features rm -r tests/run-make/const-trait-stable-toolchain # same From 719b14c3a73f84d1a1a64277bee37ce48f5bc929 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Fri, 5 Sep 2025 21:24:45 +0800 Subject: [PATCH 095/160] cg_clif: run `run-make-cargo` test suite --- scripts/test_rustc_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 476a6f311bbf4..62f1cc6a8933b 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -166,5 +166,5 @@ index 073116933bd..c3e4578204d 100644 EOF echo "[TEST] rustc test suite" -./x.py test --stage 0 --test-args=--no-capture tests/{codegen-units,run-make,ui,incremental} +./x.py test --stage 0 --test-args=--no-capture tests/{codegen-units,run-make,run-make-cargo,ui,incremental} popd From 877448730a206d8b773adf99b4fb162465c95528 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 5 Sep 2025 19:09:39 +0000 Subject: [PATCH 096/160] Ensure fat LTO doesn't merge everything into the allocator module --- src/driver/aot.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index c3adb5e767e25..7e77781dc2fc1 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -12,7 +12,9 @@ use cranelift_object::{ObjectBuilder, ObjectModule}; use rustc_codegen_ssa::assert_module_sources::CguReuse; use rustc_codegen_ssa::back::link::ensure_removed; use rustc_codegen_ssa::base::determine_cgu_reuse; -use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, errors as ssa_errors}; +use rustc_codegen_ssa::{ + CodegenResults, CompiledModule, CrateInfo, ModuleKind, errors as ssa_errors, +}; use rustc_data_structures::profiling::SelfProfilerRef; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::{IntoDynSyncSend, par_map}; @@ -361,6 +363,7 @@ fn emit_cgu( invocation_temp, prof, product.object, + ModuleKind::Regular, name.clone(), producer, )?; @@ -369,6 +372,7 @@ fn emit_cgu( module_regular, module_global_asm: global_asm_object_file.map(|global_asm_object_file| CompiledModule { name: format!("{name}.asm"), + kind: ModuleKind::Regular, object: Some(global_asm_object_file), dwarf_object: None, bytecode: None, @@ -385,6 +389,7 @@ fn emit_module( invocation_temp: Option<&str>, prof: &SelfProfilerRef, mut object: cranelift_object::object::write::Object<'_>, + kind: ModuleKind, name: String, producer_str: &str, ) -> Result { @@ -425,6 +430,7 @@ fn emit_module( Ok(CompiledModule { name, + kind, object: Some(tmp_file), dwarf_object: None, bytecode: None, @@ -479,6 +485,7 @@ fn reuse_workproduct_for_cgu( Ok(ModuleCodegenResult { module_regular: CompiledModule { name: cgu.name().to_string(), + kind: ModuleKind::Regular, object: Some(obj_out_regular), dwarf_object: None, bytecode: None, @@ -488,6 +495,7 @@ fn reuse_workproduct_for_cgu( }, module_global_asm: source_file_global_asm.map(|source_file| CompiledModule { name: cgu.name().to_string(), + kind: ModuleKind::Regular, object: Some(obj_out_global_asm), dwarf_object: None, bytecode: None, @@ -643,6 +651,7 @@ fn emit_allocator_module(tcx: TyCtxt<'_>) -> Option { tcx.sess.invocation_temp.as_deref(), &tcx.sess.prof, product.object, + ModuleKind::Allocator, "allocator_shim".to_owned(), &crate::debuginfo::producer(tcx.sess), ) { From 39aa1ee936da62047dbb2652a2171c237e9e95f1 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 7 Sep 2025 11:59:30 +0000 Subject: [PATCH 097/160] Rustup to rustc 1.91.0-nightly (1ed3cd703 2025-09-06) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index ee94deedfe4ce..e20c05056ff79 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-09-02" +channel = "nightly-2025-09-07" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From d077c1e30c18cb726b432b21dbce0c31a737c0c3 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 7 Sep 2025 14:55:38 +0000 Subject: [PATCH 098/160] Fix rustc test suite --- scripts/test_rustc_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index b50580ba623e0..75b614ff4bd48 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -148,7 +148,7 @@ rm tests/ui/backtrace/synchronized-panic-handler.rs # missing needs-unwind annot rm tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rs # same rm tests/ui/async-await/async-drop/async-drop-initial.rs # same (rust-lang/rust#140493) rm -r tests/ui/codegen/equal-pointers-unequal # make incorrect assumptions about the location of stack variables -rm -r tests/run-make/rustdoc-scrape-examples-paths # FIXME(rust-lang/rust#145580) incr comp bug +rm -r tests/run-make-cargo/rustdoc-scrape-examples-paths # FIXME(rust-lang/rust#145580) incr comp bug rm tests/ui/intrinsics/panic-uninitialized-zeroed.rs # really slow with unoptimized libstd rm tests/ui/process/process-panic-after-fork.rs # same From 8977078e1f71164ab9a1fb647d981130f5a41780 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 12 Sep 2025 15:22:44 +0000 Subject: [PATCH 099/160] Rustup to rustc 1.91.0-nightly (5eda692e7 2025-09-11) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index e20c05056ff79..86cd3abad35a2 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-09-07" +channel = "nightly-2025-09-12" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 1d61b61f69d014802d9656db99286eca13e87ea3 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 12 Sep 2025 15:49:37 +0000 Subject: [PATCH 100/160] Fix rustc test suite --- scripts/test_rustc_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 75b614ff4bd48..9c9dc2f589130 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -45,6 +45,7 @@ rm -r tests/run-make/naked-symbol-visibility rm tests/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs rm tests/ui/abi/variadic-ffi.rs # requires callee side vararg support rm -r tests/run-make/c-link-to-rust-va-list-fn # requires callee side vararg support +rm tests/ui/c-variadic/valid.rs # same rm tests/ui/delegation/fn-header.rs # misc unimplemented things From 7fdb85538d9d13c68bde46a26def632390b48a05 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 15 Sep 2025 14:20:54 +0000 Subject: [PATCH 101/160] Rustup to rustc 1.92.0-nightly (52618eb33 2025-09-14) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 86cd3abad35a2..d82f5180317d9 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-09-12" +channel = "nightly-2025-09-15" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 1988e68a35c70775d385d8a1253353eabe13ed70 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 15 Sep 2025 15:03:03 +0000 Subject: [PATCH 102/160] Fix rustc test suite --- scripts/test_rustc_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 9c9dc2f589130..1a65d70205d81 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -46,6 +46,7 @@ rm tests/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs rm tests/ui/abi/variadic-ffi.rs # requires callee side vararg support rm -r tests/run-make/c-link-to-rust-va-list-fn # requires callee side vararg support rm tests/ui/c-variadic/valid.rs # same +rm tests/ui/c-variadic/naked.rs # same rm tests/ui/delegation/fn-header.rs # misc unimplemented things From 8b7d5f1a45653a218d39499e31b5ae6057b6e30c Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Sun, 14 Sep 2025 22:29:04 +0000 Subject: [PATCH 103/160] Remove Rvalue::Len. --- src/base.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/base.rs b/src/base.rs index 3a28dd7e73cb3..41e11e1de6163 100644 --- a/src/base.rs +++ b/src/base.rs @@ -834,12 +834,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt: fx.bcx.ins().nop(); } } - Rvalue::Len(place) => { - let place = codegen_place(fx, place); - let usize_layout = fx.layout_of(fx.tcx.types.usize); - let len = codegen_array_len(fx, place); - lval.write_cvalue(fx, CValue::by_val(len, usize_layout)); - } Rvalue::ShallowInitBox(ref operand, content_ty) => { let content_ty = fx.monomorphize(content_ty); let box_layout = fx.layout_of(Ty::new_box(fx.tcx, content_ty)); From e53af72d29dcb7e175bddba96583bcdd73b0ecc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Wed, 17 Sep 2025 04:16:47 +0200 Subject: [PATCH 104/160] Remove `DynKind` --- src/abi/mod.rs | 2 +- src/unsize.rs | 4 +--- src/value_and_place.rs | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 7d0731c77bdc4..29ee46194de19 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -715,7 +715,7 @@ pub(crate) fn codegen_drop<'tcx>( fx.bcx.ins().jump(ret_block, &[]); } else { match ty.kind() { - ty::Dynamic(_, _, ty::Dyn) => { + ty::Dynamic(_, _) => { // IN THIS ARM, WE HAVE: // ty = *mut (dyn Trait) // which is: exists ( *mut T, Vtable ) diff --git a/src/unsize.rs b/src/unsize.rs index 2aee0b2e97424..643c7feb89a26 100644 --- a/src/unsize.rs +++ b/src/unsize.rs @@ -30,9 +30,7 @@ pub(crate) fn unsized_info<'tcx>( fx.pointer_type, len.try_to_target_usize(fx.tcx).expect("expected monomorphic const in codegen") as i64, ), - (&ty::Dynamic(data_a, _, src_dyn_kind), &ty::Dynamic(data_b, _, target_dyn_kind)) - if src_dyn_kind == target_dyn_kind => - { + (&ty::Dynamic(data_a, _), &ty::Dynamic(data_b, _)) => { let old_info = old_info.expect("unsized_info: missing old info for trait upcasting coercion"); let b_principal_def_id = data_b.principal_def_id(); diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 9d73f200afe2b..4519fa1a270e4 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -909,8 +909,7 @@ pub(crate) fn assert_assignable<'tcx>( ); // fn(&T) -> for<'l> fn(&'l T) is allowed } - (&ty::Dynamic(from_traits, _, _from_kind), &ty::Dynamic(to_traits, _, _to_kind)) => { - // FIXME(dyn-star): Do the right thing with DynKinds + (&ty::Dynamic(from_traits, _), &ty::Dynamic(to_traits, _)) => { for (from, to) in from_traits.iter().zip(to_traits) { let from = fx.tcx.normalize_erasing_late_bound_regions(fx.typing_env(), from); let to = fx.tcx.normalize_erasing_late_bound_regions(fx.typing_env(), to); From 0e9595e648f9982694e5b84b5f63830308a591ed Mon Sep 17 00:00:00 2001 From: Igor kehrazy Date: Sun, 21 Sep 2025 10:14:13 +0300 Subject: [PATCH 105/160] Support -Zembed-source in debuginfo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - honour the session DWARF version, enabling v5 when embed-source is requested and plumb the flag through the debug context - attach embedded source bytes to line table FileInfo records alongside existing MD5 hashes - stop excluding rustc’s embed-source-dwarf run-make test so CG_CLIF exercises the feature --- scripts/test_rustc_tests.sh | 1 - src/debuginfo/line_info.rs | 50 +++++++++++++++++++++---------------- src/debuginfo/mod.rs | 28 +++++++++++++-------- 3 files changed, 47 insertions(+), 32 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 1a65d70205d81..5e54acb3a6b0b 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -60,7 +60,6 @@ rm tests/ui/asm/global-asm-mono-sym-fn.rs # same rm tests/ui/asm/naked-asm-mono-sym-fn.rs # same rm tests/ui/asm/x86_64/goto.rs # inline asm labels not supported rm tests/ui/simd/simd-bitmask-notpow2.rs # non-pow-of-2 simd vector sizes -rm -r tests/run-make/embed-source-dwarf # embedding sources in debuginfo rm -r tests/run-make/used-proc-macro # used(linker) isn't supported yet rm tests/ui/linking/no-gc-encapsulation-symbols.rs # same rm tests/ui/attributes/fn-align-dyn.rs # per-function alignment not supported diff --git a/src/debuginfo/line_info.rs b/src/debuginfo/line_info.rs index fa7b39c836f64..6fe22f5c6dd9b 100644 --- a/src/debuginfo/line_info.rs +++ b/src/debuginfo/line_info.rs @@ -6,9 +6,7 @@ use std::path::{Component, Path}; use cranelift_codegen::MachSrcLoc; use cranelift_codegen::binemit::CodeOffset; use gimli::write::{AttributeValue, FileId, FileInfo, LineProgram, LineString, LineStringTable}; -use rustc_span::{ - FileName, Pos, SourceFile, SourceFileAndLine, SourceFileHash, SourceFileHashAlgorithm, hygiene, -}; +use rustc_span::{FileName, Pos, SourceFile, SourceFileAndLine, SourceFileHashAlgorithm, hygiene}; use crate::debuginfo::FunctionDebugContext; use crate::debuginfo::emit::address_for_func; @@ -44,21 +42,27 @@ fn osstr_as_utf8_bytes(path: &OsStr) -> &[u8] { } } -const MD5_LEN: usize = 16; - -fn make_file_info(hash: SourceFileHash) -> Option { - if hash.kind == SourceFileHashAlgorithm::Md5 { - let mut buf = [0u8; MD5_LEN]; - buf.copy_from_slice(hash.hash_bytes()); - Some(FileInfo { - timestamp: 0, - size: 0, - md5: buf, - source: None, // FIXME implement -Zembed-source - }) - } else { - None +fn make_file_info(source_file: &SourceFile, embed_source: bool) -> Option { + let has_md5 = source_file.src_hash.kind == SourceFileHashAlgorithm::Md5; + let has_source = embed_source && source_file.src.is_some(); + + if !has_md5 && !has_source { + return None; + } + + let mut info = FileInfo::default(); + + if has_md5 { + info.md5.copy_from_slice(source_file.src_hash.hash_bytes()); } + + if embed_source { + if let Some(src) = &source_file.src { + info.source = Some(LineString::String(src.as_bytes().to_vec())); + } + } + + Some(info) } impl DebugContext { @@ -105,15 +109,19 @@ impl DebugContext { let file_name = LineString::new(file_name, line_program.encoding(), line_strings); - let info = make_file_info(source_file.src_hash); + let info = make_file_info(source_file, self.embed_source); - line_program.file_has_md5 &= info.is_some(); + let has_md5 = source_file.src_hash.kind == SourceFileHashAlgorithm::Md5; + line_program.file_has_md5 &= has_md5; line_program.add_file(file_name, dir_id, info) } filename => { - let dir_id = line_program.default_directory(); + // For anonymous sources, create an empty directory instead of using the default + let empty_dir = LineString::new(b"", line_program.encoding(), line_strings); + let dir_id = line_program.add_directory(empty_dir); + let dummy_file_name = LineString::new( - filename.display(self.filename_display_preference).to_string().into_bytes(), + filename.prefer_remapped_unconditionally().to_string().into_bytes(), line_program.encoding(), line_strings, ); diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index 05b0253eff972..e552376e3452e 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -45,6 +45,7 @@ pub(crate) struct DebugContext { array_size_type: UnitEntryId, filename_display_preference: FileNameDisplayPreference, + embed_source: bool, } pub(crate) struct FunctionDebugContext { @@ -67,21 +68,24 @@ impl DebugContext { return None; } + let mut requested_dwarf_version = tcx.sess.dwarf_version(); + if tcx.sess.target.is_like_darwin && requested_dwarf_version > 4 { + // Apple’s shipped debuggers still expect DWARF <= 4 by default. + // Stay on v4 unless the user explicitly opts into a feature that + // only works with v5 (e.g. -Zembed-source). + if !tcx.sess.opts.unstable_opts.embed_source { + requested_dwarf_version = 4; + } + } + let encoding = Encoding { format: Format::Dwarf32, - // FIXME this should be configurable - // macOS doesn't seem to support DWARF > 3 - // 5 version is required for md5 file hash - version: if tcx.sess.target.is_like_darwin { - 3 - } else { - // FIXME change to version 5 once the gdb and lldb shipping with the latest debian - // support it. - 4 - }, + version: requested_dwarf_version as u16, address_size: isa.frontend_config().pointer_bytes(), }; + let embed_source = tcx.sess.opts.unstable_opts.embed_source && encoding.version >= 5; + let endian = match isa.endianness() { Endianness::Little => RunTimeEndian::Little, Endianness::Big => RunTimeEndian::Big, @@ -125,6 +129,9 @@ impl DebugContext { file_info, ); line_program.file_has_md5 = file_has_md5; + if embed_source { + line_program.file_has_source = true; + } dwarf.unit.line_program = line_program; @@ -169,6 +176,7 @@ impl DebugContext { namespace_map: DefIdMap::default(), array_size_type, filename_display_preference, + embed_source, }) } From fd7ec3a2c4938fc00ac0e43c9a26cc16b17362b4 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 23 Sep 2025 09:00:27 +0000 Subject: [PATCH 106/160] Rustup to rustc 1.92.0-nightly (f6092f224 2025-09-22) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index d82f5180317d9..8078c586edac7 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-09-15" +channel = "nightly-2025-09-23" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 72d8b6c7d52a4d5e9fae77ac5476643ef9263723 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 23 Sep 2025 09:22:47 +0000 Subject: [PATCH 107/160] Fix rustc test suite And re-enable a no longer failing test. --- scripts/setup_rust_fork.sh | 7 ++++--- scripts/test_rustc_tests.sh | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index 84c7ad534561a..c16cb4e538fe4 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -53,12 +53,13 @@ diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/co index a656927b1f6..44fc5546fac 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs -@@ -2249,13 +2249,6 @@ pub fn parse_download_ci_llvm<'a>( +@@ -2249,14 +2249,6 @@ pub fn parse_download_ci_llvm<'a>( ); } -- if b && dwn_ctx.is_running_on_ci { -- // On CI, we must always rebuild LLVM if there were any modifications to it +- #[cfg(not(test))] +- if b && dwn_ctx.is_running_on_ci && CiEnv::is_rust_lang_managed_ci_job() { +- // On rust-lang CI, we must always rebuild LLVM if there were any modifications to it - panic!( - "\`llvm.download-ci-llvm\` cannot be set to \`true\` on CI. Use \`if-unchanged\` instead." - ); diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 1a65d70205d81..91c855fe678ac 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -46,7 +46,9 @@ rm tests/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs rm tests/ui/abi/variadic-ffi.rs # requires callee side vararg support rm -r tests/run-make/c-link-to-rust-va-list-fn # requires callee side vararg support rm tests/ui/c-variadic/valid.rs # same -rm tests/ui/c-variadic/naked.rs # same +rm tests/ui/c-variadic/trait-method.rs # same +rm tests/ui/c-variadic/inherent-method.rs # same +rm tests/ui/c-variadic/same-program-multiple-abis-x86_64.rs # variadics for calling conventions other than C unsupported rm tests/ui/delegation/fn-header.rs # misc unimplemented things @@ -64,7 +66,6 @@ rm -r tests/run-make/embed-source-dwarf # embedding sources in debuginfo rm -r tests/run-make/used-proc-macro # used(linker) isn't supported yet rm tests/ui/linking/no-gc-encapsulation-symbols.rs # same rm tests/ui/attributes/fn-align-dyn.rs # per-function alignment not supported -rm tests/ui/c-variadic/same-program-multiple-abis-x86_64.rs # variadics for calling conventions other than C unsupported rm -r tests/ui/explicit-tail-calls # tail calls # requires LTO From 64ec3592834b907c12f0316cd08c342fa474314a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 23 Sep 2025 09:35:57 +0000 Subject: [PATCH 108/160] Ignore rustc test again that still fails --- scripts/test_rustc_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 91c855fe678ac..ebe3385d0b0a5 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -43,6 +43,7 @@ rm -r tests/run-make/naked-symbol-visibility # variadic arguments rm tests/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs +rm tests/ui/c-variadic/naked.rs # same rm tests/ui/abi/variadic-ffi.rs # requires callee side vararg support rm -r tests/run-make/c-link-to-rust-va-list-fn # requires callee side vararg support rm tests/ui/c-variadic/valid.rs # same From 13748073d830211b7c57fec188ffe6cc379310d1 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 23 Sep 2025 08:47:03 +0000 Subject: [PATCH 109/160] Update to Cranelift 0.124.1 --- Cargo.lock | 76 +++++++++++++++++++++++++++--------------------------- Cargo.toml | 24 ++++++++--------- 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2c6acb600b772..a81f72e17fb82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,42 +43,42 @@ checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "cranelift-assembler-x64" -version = "0.123.0" +version = "0.124.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed4b70d50ef7f5a1fe6acd4dd5fe1050abb96da29cfd9dbd816425468b077054" +checksum = "d3e8ca189363907c025c5debe2bfe56c8c18503d4575d750f87e4ccbbfbd8681" dependencies = [ "cranelift-assembler-x64-meta", ] [[package]] name = "cranelift-assembler-x64-meta" -version = "0.123.0" +version = "0.124.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2a0508022f39d640b5830b831dd3cb98e4d5e2d35b46cf9fc2a098805234365" +checksum = "e169461bfd463df68b01b196522f263c905eadc852f6e57fd4ce4c5d76115ead" dependencies = [ "cranelift-srcgen", ] [[package]] name = "cranelift-bforest" -version = "0.123.0" +version = "0.124.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56f60341caf62338f84d8e1a6261d9b72b00932564094d37d12215028a3fae95" +checksum = "2a98298338375075287834defe333d552847110f3a04db0ce19bd308b4c40fbb" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-bitset" -version = "0.123.0" +version = "0.124.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f01687e7f1cb4ec9394b4ba13c1e1835edbec012304cf2f854537deec901aeb" +checksum = "edf5f49a2e2ae284db75437a49cc13220a7fb394983d5545af1209ab0bbadee3" [[package]] name = "cranelift-codegen" -version = "0.123.0" +version = "0.124.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c24d59006f532c84fae3c7bae9fadfc569d9912c5d0bf67ea8c20de289b5786" +checksum = "c354d6db9e344f647f38c88849c482c6014b79a295aca23fa82f73b62caeda2d" dependencies = [ "bumpalo", "cranelift-assembler-x64", @@ -102,9 +102,9 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.123.0" +version = "0.124.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b250ca6c45149339f3908f1137f28faa4dba0f12673f8b6c6201a733f6e012a" +checksum = "9bb8008396957de750e26d0b40a76bea6e5623d970a5bfe4266ef0a79ccb8341" dependencies = [ "cranelift-assembler-x64-meta", "cranelift-codegen-shared", @@ -114,33 +114,33 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" -version = "0.123.0" +version = "0.124.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4923507eb61e357184e4c5e11052dbca7abcee3a306dfaa62cd2f2bdd9851c51" +checksum = "98ecb53eafe1ad1f7d7f7d0585ae5d42b2050978fa812216b0420d4752eb41cb" [[package]] name = "cranelift-control" -version = "0.123.0" +version = "0.124.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed6bf355bddc171ac2d5a62e6cfa8f1eb1b37667924210e400cbc65e53870bf2" +checksum = "b9c43ac27fe178cadb17e7f4cf1320ba89b8875cc2bdee265cccfca49bc76c95" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.123.0" +version = "0.124.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60f0c0e4057964aa3c6597606986ed5df32d465838ad389f226461bf562555c7" +checksum = "15513ee4bf648d366654c6a9864fe870ca64f1eed4acabf9139056e68b3d44dc" dependencies = [ "cranelift-bitset", ] [[package]] name = "cranelift-frontend" -version = "0.123.0" +version = "0.124.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f39ca2f29e01050443d5d4d59fe674b7107641d79a9a847d5a01fded8264b9f2" +checksum = "c5e4399d31f06b50fcb3fa0117ff4c393c22e521574eecf524cf932fc99cd78f" dependencies = [ "cranelift-codegen", "log", @@ -150,15 +150,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.123.0" +version = "0.124.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14633795ccf9b5f3ef8484dc6bfed943118330fc18a2172dc7aac661473558b1" +checksum = "9a751ec2b7c2f281274a3798e37ba2344b55f60789e67aaa10d6bbea3f3f8a6b" [[package]] name = "cranelift-jit" -version = "0.123.0" +version = "0.124.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de5044e1a2211eaf40348f387334566f266531b7a6ae60fb7d0c944db0ad8731" +checksum = "8b22769d71584df8b6a083e11a248da38c40c0b91b565c8c202b173b26cc861c" dependencies = [ "anyhow", "cranelift-codegen", @@ -176,9 +176,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.123.0" +version = "0.124.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "625cb9020a5358a194da5a3a918d1ff29ee89f8191a3ccd7a485255364f32776" +checksum = "4fb364ea65183c3961faf6cc5038bd88ceb957c3cd3480958bce28d02b194625" dependencies = [ "anyhow", "cranelift-codegen", @@ -187,9 +187,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.123.0" +version = "0.124.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a178fab381ece04958d895eff2bd5ddecb8537e08fb1af3eb92e45dd3e50301" +checksum = "546500d7cb424c423e118dfddc169aa61ed611c47fc1cf48783ed4e3f9800619" dependencies = [ "cranelift-codegen", "libc", @@ -198,9 +198,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.123.0" +version = "0.124.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11fc0edb2994ccc8802801c35c08572c443dca716e988110e63bfc9d81f0bbf1" +checksum = "c3aae694e5dd436c87ac90d1468a1032ff63d54faa33dcfece7e8fc7072fbe73" dependencies = [ "anyhow", "cranelift-codegen", @@ -213,9 +213,9 @@ dependencies = [ [[package]] name = "cranelift-srcgen" -version = "0.123.0" +version = "0.124.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07a6f374259f252ae78cbf9aad469091d6a51adda43cb91d23610532cf2b978e" +checksum = "edeb6b718b23108a123ad1c8eecf6fa34d21a6b5518fc340dda80ce5bdf42377" [[package]] name = "crc32fast" @@ -355,9 +355,9 @@ dependencies = [ [[package]] name = "regalloc2" -version = "0.12.2" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5216b1837de2149f8bc8e6d5f88a9326b63b8c836ed58ce4a0a29ec736a59734" +checksum = "efd8138ce7c3d7c13be4f61893154b5d711bd798d2d7be3ecb8dcc7e7a06ca98" dependencies = [ "allocator-api2", "bumpalo", @@ -460,9 +460,9 @@ checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "wasmtime-internal-jit-icache-coherence" -version = "36.0.0" +version = "37.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "118c225f1c3c688c423de99d590b6e06fa811207090eeb9f4423b6a2d0113ff5" +checksum = "4aea2b284343796fbbe749c36db092b43809762f8b9e46626561a8be4003dd85" dependencies = [ "anyhow", "cfg-if", @@ -472,9 +472,9 @@ dependencies = [ [[package]] name = "wasmtime-internal-math" -version = "36.0.0" +version = "37.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b2378d723f821a5f24076bd9bed4ec849c24717c7af188d4f31fff1d7fc6cfe" +checksum = "5a058122e659373c3648a71de03436105f213037d8016bb68550c259d4b37931" dependencies = [ "libm", ] diff --git a/Cargo.toml b/Cargo.toml index 945854842f2d4..3adf9f415c9a8 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.123.0", default-features = false, features = ["std", "timing", "unwind", "all-native-arch"] } -cranelift-frontend = { version = "0.123.0" } -cranelift-module = { version = "0.123.0" } -cranelift-native = { version = "0.123.0" } -cranelift-jit = { version = "0.123.0", optional = true } -cranelift-object = { version = "0.123.0" } +cranelift-codegen = { version = "0.124.1", default-features = false, features = ["std", "timing", "unwind", "all-native-arch"] } +cranelift-frontend = { version = "0.124.1" } +cranelift-module = { version = "0.124.1" } +cranelift-native = { version = "0.124.1" } +cranelift-jit = { version = "0.124.1", optional = true } +cranelift-object = { version = "0.124.1" } target-lexicon = "0.13" gimli = { version = "0.32", default-features = false, features = ["write"] } object = { version = "0.37.3", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } @@ -24,12 +24,12 @@ smallvec = "1.8.1" [patch.crates-io] # Uncomment to use an unreleased version of cranelift -#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-36.0.0" } -#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-36.0.0" } -#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-36.0.0" } -#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-36.0.0" } -#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-36.0.0" } -#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-36.0.0" } +#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-37.0.0" } +#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-37.0.0" } +#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-37.0.0" } +#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-37.0.0" } +#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-37.0.0" } +#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-37.0.0" } # Uncomment to use local checkout of cranelift #cranelift-codegen = { path = "../wasmtime/cranelift/codegen" } From b53c717e6ab8e093e18fb1df9b8a8f22197469e1 Mon Sep 17 00:00:00 2001 From: Caleb Zulawski Date: Tue, 16 Sep 2025 02:23:24 -0400 Subject: [PATCH 110/160] Add an attribute to check the number of lanes in a SIMD vector after monomorphization Unify zero-length and oversized SIMD errors --- src/common.rs | 9 +++++++-- src/global_asm.rs | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/common.rs b/src/common.rs index 2fbe5c02802ab..81b1814605a12 100644 --- a/src/common.rs +++ b/src/common.rs @@ -439,7 +439,10 @@ pub(crate) struct FullyMonomorphizedLayoutCx<'tcx>(pub(crate) TyCtxt<'tcx>); impl<'tcx> LayoutOfHelpers<'tcx> for FullyMonomorphizedLayoutCx<'tcx> { #[inline] fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! { - if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err { + if let LayoutError::SizeOverflow(_) + | LayoutError::InvalidSimd { .. } + | LayoutError::ReferencesError(_) = err + { self.0.sess.dcx().span_fatal(span, err.to_string()) } else { self.0 @@ -458,7 +461,9 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for FullyMonomorphizedLayoutCx<'tcx> { span: Span, fn_abi_request: FnAbiRequest<'tcx>, ) -> ! { - if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err { + if let FnAbiError::Layout(LayoutError::SizeOverflow(_) | LayoutError::InvalidSimd { .. }) = + err + { self.0.sess.dcx().emit_fatal(Spanned { span, node: err }) } else { match fn_abi_request { diff --git a/src/global_asm.rs b/src/global_asm.rs index 203b443269fa7..1306c6aa5179c 100644 --- a/src/global_asm.rs +++ b/src/global_asm.rs @@ -42,7 +42,10 @@ impl<'tcx> AsmCodegenMethods<'tcx> for GlobalAsmContext<'_, 'tcx> { impl<'tcx> LayoutOfHelpers<'tcx> for GlobalAsmContext<'_, 'tcx> { #[inline] fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! { - if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err { + if let LayoutError::SizeOverflow(_) + | LayoutError::InvalidSimd { .. } + | LayoutError::ReferencesError(_) = err + { self.tcx.sess.dcx().span_fatal(span, err.to_string()) } else { self.tcx From 34eb0ce741af853d448d2feccf2c8220fdee9934 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 25 Sep 2025 10:11:14 +0000 Subject: [PATCH 111/160] Use macos-15-intel runners for x86_64 --- .github/workflows/abi-cafe.yml | 7 +++---- .github/workflows/main.yml | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/abi-cafe.yml b/.github/workflows/abi-cafe.yml index 75a506868a0fa..170c7126c296b 100644 --- a/.github/workflows/abi-cafe.yml +++ b/.github/workflows/abi-cafe.yml @@ -28,10 +28,9 @@ jobs: - os: ubuntu-24.04-arm env: TARGET_TRIPLE: aarch64-unknown-linux-gnu - # FIXME(rust-lang/rust#145699) - #- os: macos-13 - # env: - # TARGET_TRIPLE: x86_64-apple-darwin + - os: macos-15-intel + env: + TARGET_TRIPLE: x86_64-apple-darwin - os: macos-latest env: TARGET_TRIPLE: aarch64-apple-darwin diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d92e0fdce99a8..52a8eeee13d4b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -56,7 +56,7 @@ jobs: - os: ubuntu-24.04-arm env: TARGET_TRIPLE: aarch64-unknown-linux-gnu - - os: macos-13 + - os: macos-15-intel env: TARGET_TRIPLE: x86_64-apple-darwin - os: macos-latest @@ -187,7 +187,7 @@ jobs: - os: ubuntu-24.04-arm env: TARGET_TRIPLE: aarch64-unknown-linux-gnu - - os: macos-13 + - os: macos-15-intel env: TARGET_TRIPLE: x86_64-apple-darwin - os: macos-latest From a7454d18803b44c7f22bcbbb7373ec43dd3619ef Mon Sep 17 00:00:00 2001 From: beepster4096 <19316085+beepster4096@users.noreply.github.com> Date: Thu, 25 Sep 2025 20:54:54 -0700 Subject: [PATCH 112/160] ProjectionElem::Subtype -> CastKind::Subtype --- src/base.rs | 4 ++-- src/value_and_place.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/base.rs b/src/base.rs index 41e11e1de6163..a2f844642f85e 100644 --- a/src/base.rs +++ b/src/base.rs @@ -789,7 +789,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt: let operand = codegen_operand(fx, operand); crate::unsize::coerce_unsized_into(fx, operand, lval); } - Rvalue::Cast(CastKind::Transmute, ref operand, _to_ty) => { + Rvalue::Cast(CastKind::Transmute | CastKind::Subtype, ref operand, _to_ty) => { let operand = codegen_operand(fx, operand); lval.write_cvalue_transmute(fx, operand); } @@ -996,7 +996,7 @@ pub(crate) fn codegen_place<'tcx>( cplace = cplace.place_deref(fx); } PlaceElem::OpaqueCast(ty) => bug!("encountered OpaqueCast({ty}) in codegen"), - PlaceElem::Subtype(ty) | PlaceElem::UnwrapUnsafeBinder(ty) => { + PlaceElem::UnwrapUnsafeBinder(ty) => { cplace = cplace.place_transmute_type(fx, fx.monomorphize(ty)); } PlaceElem::Field(field, _ty) => { diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 4519fa1a270e4..25bba48a9e3af 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -660,7 +660,7 @@ impl<'tcx> CPlace<'tcx> { } } - /// Used for `ProjectionElem::Subtype`, `ty` has to be monomorphized before + /// Used for `ProjectionElem::UnwrapUnsafeBinder`, `ty` has to be monomorphized before /// passed on. pub(crate) fn place_transmute_type( self, From f1ce0ecb4d0e281323627c14c7f0410b3cbf3f2c Mon Sep 17 00:00:00 2001 From: EriKWDev Date: Fri, 26 Sep 2025 11:26:52 +0200 Subject: [PATCH 113/160] Remove $ (#1595) Consider removing the redundant $:s that needs to be removed when copying commands --- Readme.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Readme.md b/Readme.md index 9989cc7e7eaf5..48003ad270e6f 100644 --- a/Readme.md +++ b/Readme.md @@ -11,7 +11,7 @@ The Cranelift codegen backend is distributed in nightly builds on Linux, macOS a install it using Rustup, you can do that by running: ```bash -$ rustup component add rustc-codegen-cranelift-preview --toolchain nightly +rustup component add rustc-codegen-cranelift-preview --toolchain nightly ``` Once it is installed, you can enable it with one of the following approaches: @@ -47,16 +47,16 @@ If you want to use `cargo clif build` instead of having to specify the full path If you want to build the backend manually, you can download it from GitHub and build it yourself: ```bash -$ git clone https://github.com/rust-lang/rustc_codegen_cranelift -$ cd rustc_codegen_cranelift -$ ./y.sh build +git clone https://github.com/rust-lang/rustc_codegen_cranelift +cd rustc_codegen_cranelift +./y.sh build ``` To run the test suite replace the last command with: ```bash -$ ./y.sh prepare # only needs to be run the first time -$ ./test.sh +./y.sh prepare # only needs to be run the first time +./test.sh ``` For more docs on how to build and test see [build_system/usage.txt](build_system/usage.txt) or the help message of `./y.sh`. @@ -90,7 +90,7 @@ Assuming `$cg_clif_dir` is the directory you cloned this repo into and you follo In the directory with your project (where you can do the usual `cargo build`), run: ```bash -$ $cg_clif_dir/dist/cargo-clif build +$cg_clif_dir/dist/cargo-clif build ``` This will build your project with rustc_codegen_cranelift instead of the usual LLVM backend. From 9b24d96173603d11dd36c6c98136c97ebf882d16 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 26 Sep 2025 13:50:17 +0000 Subject: [PATCH 114/160] Re-enable Cirrus CI --- .cirrus.yml | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index ee5de8b42f465..1ec99eb3d17a5 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,21 +1,20 @@ -# FIXME re-enable once https://github.com/rust-lang/rust/issues/134863 is fixed. -# task: -# name: freebsd -# freebsd_instance: -# image: freebsd-13-2-release-amd64 -# setup_rust_script: -# - pkg install -y git-tiny binutils -# - curl https://sh.rustup.rs -sSf --output rustup.sh -# - sh rustup.sh --default-toolchain none -y --profile=minimal -# target_cache: -# folder: build/cg_clif -# prepare_script: -# - . $HOME/.cargo/env -# - ./y.sh prepare -# test_script: -# - . $HOME/.cargo/env -# # Disabling incr comp reduces cache size and incr comp doesn't save as much -# # on CI anyway. -# - export CARGO_BUILD_INCREMENTAL=false -# # Skip rand as it fails on FreeBSD due to rust-random/rand#1355 -# - ./y.sh test --skip-test test.rust-random/rand +task: + name: freebsd + freebsd_instance: + image: freebsd-13-2-release-amd64 + setup_rust_script: + - pkg install -y git-tiny binutils + - curl https://sh.rustup.rs -sSf --output rustup.sh + - sh rustup.sh --default-toolchain none -y --profile=minimal + target_cache: + folder: build/cg_clif + prepare_script: + - . $HOME/.cargo/env + - ./y.sh prepare + test_script: + - . $HOME/.cargo/env + # Disabling incr comp reduces cache size and incr comp doesn't save as much + # on CI anyway. + - export CARGO_BUILD_INCREMENTAL=false + # Skip rand as it fails on FreeBSD due to rust-random/rand#1355 + - ./y.sh test --skip-test test.rust-random/rand From f2798d6233d21d95550a5fa1d762365aba383b09 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 26 Sep 2025 13:56:59 +0000 Subject: [PATCH 115/160] Workaround for TLS issue on FreeBSD --- .cirrus.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.cirrus.yml b/.cirrus.yml index 1ec99eb3d17a5..85527699530b0 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -16,5 +16,8 @@ task: # Disabling incr comp reduces cache size and incr comp doesn't save as much # on CI anyway. - export CARGO_BUILD_INCREMENTAL=false + # FIXME(rust-lang/rust#134863) necessary to avoid error when dlopening proc + # macros during compilation of cg_clif. + - export LD_STATIC_TLS_EXTRA=4096 # Skip rand as it fails on FreeBSD due to rust-random/rand#1355 - ./y.sh test --skip-test test.rust-random/rand From 3e563b840e50291a55b5e567162523ffb6a35f8b Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 26 Sep 2025 14:29:41 +0000 Subject: [PATCH 116/160] Improve ArgAbi left behind panic message --- src/abi/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 1b21315046faf..9e9bc2e93b719 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -300,7 +300,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_ Some(cvalue_for_param(fx, None, None, arg_abi, &mut block_params_iter).unwrap()); } - assert!(arg_abis_iter.next().is_none(), "ArgAbi left behind"); + assert_eq!(arg_abis_iter.next(), None, "ArgAbi left behind for {:?}", fx.fn_abi); assert!(block_params_iter.next().is_none(), "arg_value left behind"); self::comments::add_locals_header_comment(fx); From de53737f637054a32e8ea7536f077c96d9d2131c Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 28 Sep 2025 12:08:44 -0400 Subject: [PATCH 117/160] Add a leading dash to linker plugin arguments in the gcc codegen --- src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 8e34436fb5e0a..5fd7c4d4f41bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -165,6 +165,10 @@ impl CodegenBackend for CraneliftCodegenBackend { "" } + fn name(&self) -> &'static str { + "cranelift" + } + fn init(&self, sess: &Session) { use rustc_session::config::{InstrumentCoverage, Lto}; match sess.lto() { From 5569e6b2053a6488c398d9bd8f8b48f2959a90bc Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 28 Sep 2025 14:40:39 -0700 Subject: [PATCH 118/160] remove explicit deref of AbiAlign for most methods Much of the compiler calls functions on Align projected from AbiAlign. AbiAlign impls Deref to its inner Align, so we can simplify these away. Also, it will minimize disruption when AbiAlign is removed. For now, preserve usages that might resolve to PartialOrd or PartialEq, as those have odd inference. --- src/abi/comments.rs | 2 +- src/abi/pass_mode.rs | 2 +- src/base.rs | 2 +- src/debuginfo/mod.rs | 2 +- src/debuginfo/types.rs | 6 ++---- src/unsize.rs | 6 +++--- src/value_and_place.rs | 6 +++--- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/abi/comments.rs b/src/abi/comments.rs index c74efeb59f3fc..d1b2b9a502ac2 100644 --- a/src/abi/comments.rs +++ b/src/abi/comments.rs @@ -89,7 +89,7 @@ pub(super) fn add_local_place_comments<'tcx>( format!("{:?}", local), format!("{:?}", ty), size.bytes(), - align.abi.bytes(), + align.bytes(), if extra.is_empty() { "" } else { " " }, extra, )); diff --git a/src/abi/pass_mode.rs b/src/abi/pass_mode.rs index 2031842062d97..7a909a740b054 100644 --- a/src/abi/pass_mode.rs +++ b/src/abi/pass_mode.rs @@ -233,7 +233,7 @@ pub(super) fn from_casted_value<'tcx>( // It may also be smaller for example when the type is a wrapper around an integer with a // larger alignment than the integer. std::cmp::max(abi_param_size, layout_size), - u32::try_from(layout.align.abi.bytes()).unwrap(), + u32::try_from(layout.align.bytes()).unwrap(), ); let mut block_params_iter = block_params.iter().copied(); for (offset, _) in abi_params { diff --git a/src/base.rs b/src/base.rs index 41e11e1de6163..2cc5b82ddd345 100644 --- a/src/base.rs +++ b/src/base.rs @@ -846,7 +846,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt: let layout = fx.layout_of(fx.monomorphize(ty)); let val = match null_op { NullOp::SizeOf => layout.size.bytes(), - NullOp::AlignOf => layout.align.abi.bytes(), + NullOp::AlignOf => layout.align.bytes(), NullOp::OffsetOf(fields) => fx .tcx .offset_of_subfield( diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index 286e02b986b3c..4c438742f3d22 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -304,7 +304,7 @@ impl DebugContext { entry.set(gimli::DW_AT_decl_file, AttributeValue::FileIndex(Some(file_id))); entry.set(gimli::DW_AT_decl_line, AttributeValue::Udata(line)); - entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(static_layout.align.abi.bytes())); + entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(static_layout.align.bytes())); let mut expr = Expression::new(); expr.op_addr(address_for_data(data_id)); diff --git a/src/debuginfo/types.rs b/src/debuginfo/types.rs index 25b922c8be4c7..0d49f32373caa 100644 --- a/src/debuginfo/types.rs +++ b/src/debuginfo/types.rs @@ -166,7 +166,7 @@ impl DebugContext { let tuple_entry = self.dwarf.unit.get_mut(tuple_type_id); tuple_entry.set(gimli::DW_AT_name, AttributeValue::StringRef(self.dwarf.strings.add(name))); tuple_entry.set(gimli::DW_AT_byte_size, AttributeValue::Udata(layout.size.bytes())); - tuple_entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(layout.align.abi.bytes())); + tuple_entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(layout.align.bytes())); for (i, (ty, dw_ty)) in components.into_iter().enumerate() { let member_id = self.dwarf.unit.add(tuple_type_id, gimli::DW_TAG_member); @@ -178,9 +178,7 @@ impl DebugContext { member_entry.set(gimli::DW_AT_type, AttributeValue::UnitRef(dw_ty)); member_entry.set( gimli::DW_AT_alignment, - AttributeValue::Udata( - FullyMonomorphizedLayoutCx(tcx).layout_of(ty).align.abi.bytes(), - ), + AttributeValue::Udata(FullyMonomorphizedLayoutCx(tcx).layout_of(ty).align.bytes()), ); member_entry.set( gimli::DW_AT_data_member_location, diff --git a/src/unsize.rs b/src/unsize.rs index 643c7feb89a26..d994f3e32ec3c 100644 --- a/src/unsize.rs +++ b/src/unsize.rs @@ -167,7 +167,7 @@ pub(crate) fn size_and_align_of<'tcx>( if layout.is_sized() { return ( fx.bcx.ins().iconst(fx.pointer_type, layout.size.bytes() as i64), - fx.bcx.ins().iconst(fx.pointer_type, layout.align.abi.bytes() as i64), + fx.bcx.ins().iconst(fx.pointer_type, layout.align.bytes() as i64), ); } @@ -186,7 +186,7 @@ pub(crate) fn size_and_align_of<'tcx>( // times the unit size. ( fx.bcx.ins().imul_imm(info.unwrap(), unit.size.bytes() as i64), - fx.bcx.ins().iconst(fx.pointer_type, unit.align.abi.bytes() as i64), + fx.bcx.ins().iconst(fx.pointer_type, unit.align.bytes() as i64), ) } ty::Foreign(_) => { @@ -224,7 +224,7 @@ pub(crate) fn size_and_align_of<'tcx>( let unsized_offset_unadjusted = layout.fields.offset(i).bytes(); let unsized_offset_unadjusted = fx.bcx.ins().iconst(fx.pointer_type, unsized_offset_unadjusted as i64); - let sized_align = layout.align.abi.bytes(); + let sized_align = layout.align.bytes(); let sized_align = fx.bcx.ins().iconst(fx.pointer_type, sized_align as i64); // Recurse to get the size of the dynamically sized field (must be diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 4519fa1a270e4..04e10cf17088c 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -383,7 +383,7 @@ impl<'tcx> CPlace<'tcx> { let stack_slot = fx.create_stack_slot( u32::try_from(layout.size.bytes()).unwrap(), - u32::try_from(layout.align.abi.bytes()).unwrap(), + u32::try_from(layout.align.bytes()).unwrap(), ); CPlace { inner: CPlaceInner::Addr(stack_slot, None), layout } } @@ -641,8 +641,8 @@ impl<'tcx> CPlace<'tcx> { let size = dst_layout.size.bytes(); // `emit_small_memory_copy` uses `u8` for alignments, just use the maximum // alignment that fits in a `u8` if the actual alignment is larger. - let src_align = src_layout.align.abi.bytes().try_into().unwrap_or(128); - let dst_align = dst_layout.align.abi.bytes().try_into().unwrap_or(128); + let src_align = src_layout.align.bytes().try_into().unwrap_or(128); + let dst_align = dst_layout.align.bytes().try_into().unwrap_or(128); fx.bcx.emit_small_memory_copy( fx.target_config, to_addr, From 6b3ada06c3c7ee6148f2a1f91eb3d4bc30e8eb11 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 1 Oct 2025 10:00:48 +0000 Subject: [PATCH 119/160] Use rustc --print host-tuple --- build_system/rustc_info.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index 5b71504e90a4f..61d56795efa3a 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -2,19 +2,13 @@ use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; pub(crate) fn get_host_triple(rustc: &Path) -> String { - let version_info = - Command::new(rustc).stderr(Stdio::inherit()).args(&["-vV"]).output().unwrap().stdout; - String::from_utf8(version_info) - .unwrap() - .lines() - .to_owned() - .find(|line| line.starts_with("host")) - .unwrap() - .split(":") - .nth(1) + let version_info = Command::new(rustc) + .stderr(Stdio::inherit()) + .args(&["--print", "host-tuple"]) + .output() .unwrap() - .trim() - .to_owned() + .stdout; + String::from_utf8(version_info).unwrap().trim().to_owned() } pub(crate) fn get_toolchain_name() -> String { From d923ff4f4bd787bfb59d2b7d3a8ecd229213816b Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 1 Oct 2025 10:17:28 +0000 Subject: [PATCH 120/160] Rustup to rustc 1.92.0-nightly (fa3155a64 2025-09-30) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 8078c586edac7..2697f26e8e85e 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-09-23" +channel = "nightly-2025-10-01" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 160c1091fbef7161372ac1d4e02949e1838621f1 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 1 Oct 2025 10:30:11 +0000 Subject: [PATCH 121/160] Fix rustc test suite --- scripts/test_rustc_tests.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 30e73d898ec14..3981a42eb1199 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -67,6 +67,7 @@ rm -r tests/run-make/used-proc-macro # used(linker) isn't supported yet rm tests/ui/linking/no-gc-encapsulation-symbols.rs # same rm tests/ui/attributes/fn-align-dyn.rs # per-function alignment not supported rm -r tests/ui/explicit-tail-calls # tail calls +rm -r tests/run-make/pointer-auth-link-with-c # pointer auth # requires LTO rm -r tests/run-make/cdylib @@ -131,6 +132,8 @@ rm -r tests/run-make/remap-path-prefix-dwarf # requires llvm-dwarfdump rm -r tests/run-make/strip # same rm -r tests/run-make-cargo/compiler-builtins # Expects lib/rustlib/src/rust to contains the standard library source rm -r tests/run-make/translation # same +rm -r tests/run-make-cargo/panic-immediate-abort-works # same +rm -r tests/run-make-cargo/panic-immediate-abort-codegen # same rm -r tests/run-make/missing-unstable-trait-bound # This disables support for unstable features, but running cg_clif needs some unstable features rm -r tests/run-make/const-trait-stable-toolchain # same rm -r tests/run-make/print-request-help-stable-unstable # same From 099e5d2572f9920022b9286f9d330c3d5a562c11 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:50:21 +0000 Subject: [PATCH 122/160] Update Cirrus CI to FreeBSD 14.2 --- .cirrus.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cirrus.yml b/.cirrus.yml index 85527699530b0..3ed89beceb7fe 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,7 +1,7 @@ task: name: freebsd freebsd_instance: - image: freebsd-13-2-release-amd64 + image_family: freebsd-14-2 setup_rust_script: - pkg install -y git-tiny binutils - curl https://sh.rustup.rs -sSf --output rustup.sh From 992c2c6b01d2bdfaa0bbb4a736670fdce9d76a08 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:40:02 +0000 Subject: [PATCH 123/160] Use the correct return type for compiler-builtins float compares --- src/codegen_f16_f128.rs | 8 +++----- src/compiler_builtins.rs | 35 +++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/codegen_f16_f128.rs b/src/codegen_f16_f128.rs index 1e202be1f1855..c2406197f3039 100644 --- a/src/codegen_f16_f128.rs +++ b/src/codegen_f16_f128.rs @@ -1,3 +1,4 @@ +use crate::compiler_builtins::CMP_RESULT_TY; use crate::prelude::*; pub(crate) fn f16_to_f32(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value { @@ -70,13 +71,10 @@ pub(crate) fn fcmp(fx: &mut FunctionCx<'_, '_, '_>, cc: FloatCC, lhs: Value, rhs let res = fx.lib_call( name, vec![AbiParam::new(types::F128), AbiParam::new(types::F128)], - // FIXME(rust-lang/compiler-builtins#919): This should be `I64` on non-AArch64 - // architectures, but switching it before compiler-builtins is fixed causes test - // failures. - vec![AbiParam::new(types::I32)], + vec![AbiParam::new(CMP_RESULT_TY)], &[lhs, rhs], )[0]; - let zero = fx.bcx.ins().iconst(types::I32, 0); + let zero = fx.bcx.ins().iconst(CMP_RESULT_TY, 0); let res = fx.bcx.ins().icmp(int_cc, res, zero); res } diff --git a/src/compiler_builtins.rs b/src/compiler_builtins.rs index 155bf866889ad..ca9157daae584 100644 --- a/src/compiler_builtins.rs +++ b/src/compiler_builtins.rs @@ -3,11 +3,34 @@ use std::ffi::c_int; #[cfg(feature = "jit")] use std::ffi::c_void; +use cranelift_codegen::ir::{Type, types}; + // FIXME replace with core::ffi::c_size_t once stabilized #[allow(non_camel_case_types)] #[cfg(feature = "jit")] type size_t = usize; +// Needs to stay in sync with compiler-builtins + +// Aarch64 uses `int` rather than a pointer-sized value. +#[cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))] +#[cfg(feature = "jit")] +type CmpResult = i32; +#[cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))] +pub(crate) const CMP_RESULT_TY: Type = types::I32; + +// In compiler-rt, LLP64 ABIs use `long long` and everything else uses `long`. In effect, +// this means the return value is always pointer-sized. +#[cfg(not(any(target_arch = "aarch64", target_arch = "arm64ec")))] +#[cfg(feature = "jit")] +type CmpResult = isize; +#[cfg(not(any(target_arch = "aarch64", target_arch = "arm64ec")))] +#[cfg(target_pointer_width = "32")] +pub(crate) const CMP_RESULT_TY: Type = types::I32; +#[cfg(not(any(target_arch = "aarch64", target_arch = "arm64ec")))] +#[cfg(target_pointer_width = "64")] +pub(crate) const CMP_RESULT_TY: Type = types::I64; + macro_rules! builtin_functions { ( $register:ident; @@ -88,12 +111,12 @@ builtin_functions! { #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn fmodf128(a: f128, b: f128) -> f128; // float comparison - fn __eqtf2(a: f128, b: f128) -> i32; - fn __netf2(a: f128, b: f128) -> i32; - fn __lttf2(a: f128, b: f128) -> i32; - fn __letf2(a: f128, b: f128) -> i32; - fn __gttf2(a: f128, b: f128) -> i32; - fn __getf2(a: f128, b: f128) -> i32; + fn __eqtf2(a: f128, b: f128) -> CmpResult; + fn __netf2(a: f128, b: f128) -> CmpResult; + fn __lttf2(a: f128, b: f128) -> CmpResult; + fn __letf2(a: f128, b: f128) -> CmpResult; + fn __gttf2(a: f128, b: f128) -> CmpResult; + fn __getf2(a: f128, b: f128) -> CmpResult; #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn fminimumf128(a: f128, b: f128) -> f128; #[cfg(not(all(target_os = "windows", target_env = "gnu")))] From ed6fbc28e3f0d74094e4d8f01272466c202c46c0 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 1 Oct 2025 13:17:17 +0000 Subject: [PATCH 124/160] Stop building rtstartup It is no longer used by rustc on 64bit MinGW and we don't support 32bit MinGW anyway. --- build_system/build_sysroot.rs | 54 +++++------------------------------ 1 file changed, 7 insertions(+), 47 deletions(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index fec6ff2415502..c0ccf506262a9 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -140,7 +140,6 @@ impl SysrootTarget { static STDLIB_SRC: RelPath = RelPath::build("stdlib"); static STANDARD_LIBRARY: CargoProject = CargoProject::new(&RelPath::build("stdlib/library/sysroot"), "stdlib_target"); -static RTSTARTUP_SYSROOT: RelPath = RelPath::build("rtstartup"); fn build_sysroot_for_triple( dirs: &Dirs, @@ -150,8 +149,7 @@ fn build_sysroot_for_triple( panic_unwind_support: bool, ) -> SysrootTarget { match sysroot_kind { - SysrootKind::None => build_rtstartup(dirs, &compiler) - .unwrap_or(SysrootTarget { triple: compiler.triple, libs: vec![] }), + SysrootKind::None => SysrootTarget { triple: compiler.triple, libs: vec![] }, SysrootKind::Llvm => build_llvm_sysroot_for_triple(compiler), SysrootKind::Clif => { build_clif_sysroot_for_triple(dirs, compiler, cg_clif_dylib_path, panic_unwind_support) @@ -201,15 +199,14 @@ fn build_clif_sysroot_for_triple( ) -> SysrootTarget { let mut target_libs = SysrootTarget { triple: compiler.triple.clone(), libs: vec![] }; - if let Some(rtstartup_target_libs) = build_rtstartup(dirs, &compiler) { - rtstartup_target_libs.install_into_sysroot(&RTSTARTUP_SYSROOT.to_path(dirs)); - - target_libs.libs.extend(rtstartup_target_libs.libs); - } - let build_dir = STANDARD_LIBRARY.target_dir(dirs).join(&compiler.triple).join("release"); if !config::get_bool("keep_sysroot") { + let sysroot_src_orig = get_default_sysroot(&compiler.rustc).join("lib/rustlib/src/rust"); + assert!(sysroot_src_orig.exists()); + + apply_patches(dirs, "stdlib", &sysroot_src_orig, &STDLIB_SRC.to_path(dirs)); + // Cleanup the deps dir, but keep build scripts and the incremental cache for faster // recompilation as they are not affected by changes in cg_clif. ensure_empty_dir(&build_dir.join("deps")); @@ -228,9 +225,7 @@ fn build_clif_sysroot_for_triple( rustflags.push(format!("-Zcodegen-backend={name}")); } }; - // Necessary for MinGW to find rsbegin.o and rsend.o - rustflags.push("--sysroot".to_owned()); - rustflags.push(RTSTARTUP_SYSROOT.to_path(dirs).to_str().unwrap().to_owned()); + rustflags.push("--sysroot=/dev/null".to_owned()); // Incremental compilation by default disables mir inlining. This leads to both a decent // compile perf and a significant runtime perf regression. As such forcefully enable mir @@ -271,38 +266,3 @@ fn build_clif_sysroot_for_triple( target_libs } - -fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option { - if !config::get_bool("keep_sysroot") { - let sysroot_src_orig = get_default_sysroot(&compiler.rustc).join("lib/rustlib/src/rust"); - assert!(sysroot_src_orig.exists()); - - apply_patches(dirs, "stdlib", &sysroot_src_orig, &STDLIB_SRC.to_path(dirs)); - } - - if !compiler.triple.ends_with("windows-gnu") { - return None; - } - - let rtstartup_sysroot = RTSTARTUP_SYSROOT.to_path(dirs); - ensure_empty_dir(&rtstartup_sysroot); - - let rtstartup_src = STDLIB_SRC.to_path(dirs).join("library").join("rtstartup"); - let mut target_libs = SysrootTarget { triple: compiler.triple.clone(), libs: vec![] }; - - for file in ["rsbegin", "rsend"] { - let obj = rtstartup_sysroot.join(format!("{file}.o")); - let mut build_rtstartup_cmd = Command::new(&compiler.rustc); - build_rtstartup_cmd - .arg("--target") - .arg(&compiler.triple) - .arg("--emit=obj") - .arg("-o") - .arg(&obj) - .arg(rtstartup_src.join(format!("{file}.rs"))); - spawn_and_wait(build_rtstartup_cmd); - target_libs.libs.push(obj.clone()); - } - - Some(target_libs) -} From fdaf80466eb04bf28486fee2eda02a7a2029b250 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 1 Oct 2025 13:37:35 +0000 Subject: [PATCH 125/160] Add note about FreeBSD TLS problems to Readme.md --- Readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 48003ad270e6f..c5436cf67c80a 100644 --- a/Readme.md +++ b/Readme.md @@ -66,7 +66,7 @@ For more docs on how to build and test see [build_system/usage.txt](build_system |OS \ architecture|x86\_64|AArch64|Riscv64|s390x (System-Z)| |---|---|---|---|---| |Linux|✅|✅|✅[^no-rustup]|✅[^no-rustup]| -|FreeBSD|✅[^no-rustup]|❓|❓|❓| +|FreeBSD|✅[^no-rustup][^tls]|❓|❓|❓| |AIX|❌[^xcoff]|N/A|N/A|❌[^xcoff]| |Other unixes|❓|❓|❓|❓| |macOS|✅|✅|N/A|N/A| @@ -80,6 +80,7 @@ Not all targets are available as rustup component for nightly. See notes in the [^xcoff]: XCOFF object file format is not supported. [^no-rustup]: Not available as [rustup component for nightly](https://rust-lang.github.io/rustup-components-history/). You can build it yourself. +[^tls]: FreeBSD requires setting `LD_STATIC_TLS_EXTRA=4096` to build cg_clif. In addition you need at least FreeBSD 14. ## Usage From b038641a28ea1bd77bb35ef84d0afafacc38e215 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 1 Oct 2025 14:38:26 +0000 Subject: [PATCH 126/160] Use #[ignore] rather than commenting out for disabling sysroot tests --- ...oot_tests-Disable-long-running-tests.patch | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/patches/0028-sysroot_tests-Disable-long-running-tests.patch b/patches/0028-sysroot_tests-Disable-long-running-tests.patch index 357b8d306cf6a..853acab2773b5 100644 --- a/patches/0028-sysroot_tests-Disable-long-running-tests.patch +++ b/patches/0028-sysroot_tests-Disable-long-running-tests.patch @@ -11,38 +11,41 @@ diff --git a/coretests/tests/slice.rs b/coretests/tests/slice.rs index 8402833..84592e0 100644 --- a/coretests/tests/slice.rs +++ b/coretests/tests/slice.rs -@@ -1809,6 +1809,7 @@ fn sort_unstable() { - } - } +@@ -1619,7 +1619,7 @@ fn brute_force_rotate_test_1() { -+/* #[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]); - } -+*/ +-#[cfg_attr(miri, ignore)] // Miri is too slow ++#[ignore] // Miri is too slow + fn select_nth_unstable() { + use core::cmp::Ordering::{Equal, Greater, Less}; - #[test] - #[should_panic(expected = "index 0 greater than length of slice")] -@@ -2462,6 +2462,7 @@ take_tests! { - #[cfg(not(miri))] // unused in Miri +@@ -2303,14 +2303,14 @@ split_off_tests! { const EMPTY_MAX: &'static [()] = &[(); usize::MAX]; -+/* // can't be a constant due to const mutability rules - #[cfg(not(miri))] // unused in Miri +-#[cfg(not(miri))] // unused in Miri ++#[cfg(any())] // unused in Miri macro_rules! empty_max_mut { -@@ -2485,6 +2486,7 @@ take_tests! { - (split_off_mut_oob_max_range_to_inclusive, (..=usize::MAX), None, empty_max_mut!()), - (split_off_mut_in_bounds_max_range_from, (usize::MAX..), Some(&mut [] as _), empty_max_mut!()), + () => { + &mut [(); usize::MAX] as _ + }; } -+*/ - #[test] - fn test_slice_from_ptr_range() { +-#[cfg(not(miri))] // Comparing usize::MAX many elements takes forever in Miri (and in rustc without optimizations) ++#[cfg(any())] // Comparing usize::MAX many elements takes forever in Miri (and in rustc without optimizations) + split_off_tests! { + slice: &[(); usize::MAX], method: split_off, + (split_off_in_bounds_max_range_to, (..usize::MAX), Some(EMPTY_MAX), &[(); 0]), +@@ -2318,7 +2318,7 @@ split_off_tests! { + (split_off_in_bounds_max_range_from, (usize::MAX..), Some(&[] as _), EMPTY_MAX), + } + +-#[cfg(not(miri))] // Comparing usize::MAX many elements takes forever in Miri (and in rustc without optimizations) ++#[cfg(any())] // Comparing usize::MAX many elements takes forever in Miri (and in rustc without optimizations) + split_off_tests! { + slice: &mut [(); usize::MAX], method: split_off_mut, + (split_off_mut_in_bounds_max_range_to, (..usize::MAX), Some(empty_max_mut!()), &mut [(); 0]), diff --git a/alloctests/tests/sort/tests.rs b/alloctests/tests/sort/tests.rs index d321f8d..8b2040a 100644 --- a/alloctests/tests/sort/tests.rs From dd7c7d028dd5b9f97e09a6c57fc62f1f7fb8f735 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Thu, 21 Aug 2025 22:19:40 +0200 Subject: [PATCH 127/160] use `codegen_instance_attrs` in some additional places --- src/abi/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 29ee46194de19..9a9a1f4a2c0f8 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -467,7 +467,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( true } else { instance.is_some_and(|inst| { - fx.tcx.codegen_fn_attrs(inst.def_id()).flags.contains(CodegenFnAttrFlags::COLD) + fx.tcx.codegen_instance_attrs(inst.def).flags.contains(CodegenFnAttrFlags::COLD) }) }; if is_cold { From c7b4a1d58a72b66f2dffe0f822bb879191593beb Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 6 Oct 2025 10:11:18 +0000 Subject: [PATCH 128/160] Rustup to rustc 1.92.0-nightly (839222065 2025-10-05) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 2697f26e8e85e..9259a33c8c90e 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-10-01" +channel = "nightly-2025-10-06" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 7f0b2bb7d283785493a97c0fa8739078a9a55114 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 6 Oct 2025 10:29:01 +0000 Subject: [PATCH 129/160] Fix rustc test suite --- scripts/test_rustc_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 3981a42eb1199..78802f97af2c1 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -141,6 +141,7 @@ rm -r tests/run-make/incr-add-rust-src-component rm tests/ui/errors/remap-path-prefix-sysroot.rs # different sysroot source path rm -r tests/run-make/export/extern-opt # something about rustc version mismatches rm -r tests/run-make/export # same +rm -r tests/ui/compiletest-self-test/compile-flags-incremental.rs # needs compiletest compiled with panic=unwind # genuine bugs # ============ From 7201c1b95f0f4762d9db0141cb1183e03bab6f1c Mon Sep 17 00:00:00 2001 From: beepster4096 <19316085+beepster4096@users.noreply.github.com> Date: Wed, 13 Aug 2025 02:09:20 -0700 Subject: [PATCH 130/160] remove DerefTemp and CopyFromDeref from runtime mir --- src/base.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/base.rs b/src/base.rs index ebf2ccf74de20..a529692c0743c 100644 --- a/src/base.rs +++ b/src/base.rs @@ -600,11 +600,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt: let val = codegen_operand(fx, operand); lval.write_cvalue(fx, val); } - Rvalue::CopyForDeref(place) => { - let cplace = codegen_place(fx, place); - let val = cplace.to_cvalue(fx); - lval.write_cvalue(fx, val) - } Rvalue::Ref(_, _, place) | Rvalue::RawPtr(_, place) => { let place = codegen_place(fx, place); let ref_ = place.place_ref(fx, lval.layout()); @@ -928,6 +923,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt: let operand = codegen_operand(fx, operand); lval.write_cvalue_transmute(fx, operand); } + Rvalue::CopyForDeref(_) => bug!("`CopyForDeref` in codegen"), } } StatementKind::StorageLive(_) From 0e4df746ad940dc7b9d103e5e9c3cd1ae4fae841 Mon Sep 17 00:00:00 2001 From: yukang Date: Thu, 9 Oct 2025 01:24:55 +0800 Subject: [PATCH 131/160] prefer to use repeat_n over repeat and take --- src/constant.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constant.rs b/src/constant.rs index a56466750e75c..faca92957e1a6 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -318,7 +318,7 @@ fn data_id_for_static( let mut data = DataDescription::new(); data.set_align(align); let data_gv = module.declare_data_in_data(data_id, &mut data); - data.define(std::iter::repeat(0).take(pointer_ty(tcx).bytes() as usize).collect()); + data.define(std::iter::repeat_n(0, pointer_ty(tcx).bytes() as usize).collect()); data.write_data_addr(0, data_gv, 0); match module.define_data(ref_data_id, &data) { // Every time the static is referenced there will be another definition of this global, From 0f2b4700b07aeb037569282412cd356c3da21a7c Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Fri, 10 Oct 2025 01:48:09 +0000 Subject: [PATCH 132/160] Remove StatementKind::Deinit. --- src/base.rs | 1 - src/constant.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/src/base.rs b/src/base.rs index ebf2ccf74de20..b3f9f598926c2 100644 --- a/src/base.rs +++ b/src/base.rs @@ -932,7 +932,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt: } StatementKind::StorageLive(_) | StatementKind::StorageDead(_) - | StatementKind::Deinit(_) | StatementKind::ConstEvalCounter | StatementKind::Nop | StatementKind::FakeRead(..) diff --git a/src/constant.rs b/src/constant.rs index faca92957e1a6..293459cc11c2f 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -597,7 +597,6 @@ pub(crate) fn mir_operand_get_const_val<'tcx>( StatementKind::Assign(_) | StatementKind::FakeRead(_) | StatementKind::SetDiscriminant { .. } - | StatementKind::Deinit(_) | StatementKind::StorageLive(_) | StatementKind::StorageDead(_) | StatementKind::Retag(_, _) From 67b7b7f66b0c23e0d0aa4cd10578cc1511eedcb4 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 26 Jun 2025 13:44:01 +0000 Subject: [PATCH 133/160] Support #[alloc_error_handler] without the allocator shim Currently it is possible to avoid linking the allocator shim when __rust_no_alloc_shim_is_unstable_v2 is defined when linking rlibs directly as some build systems need. However this requires liballoc to be compiled with --cfg no_global_oom_handling, which places huge restrictions on what functions you can call and makes it impossible to use libstd. Or alternatively you have to define __rust_alloc_error_handler and (when using libstd) __rust_alloc_error_handler_should_panic using #[rustc_std_internal_symbol]. With this commit you can either use libstd and define __rust_alloc_error_handler_should_panic or not use libstd and use #[alloc_error_handler] instead. Both options are still unstable though. Eventually the alloc_error_handler may either be removed entirely (though the PR for that has been stale for years now) or we may start using weak symbols for it instead. For the latter case this commit is a prerequisite anyway. --- src/allocator.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index 04f1129d87c1f..9533f870434ab 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -3,8 +3,8 @@ use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext}; use rustc_ast::expand::allocator::{ - ALLOCATOR_METHODS, AllocatorKind, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, - alloc_error_handler_name, default_fn_name, global_fn_name, + ALLOC_ERROR_HANDLER, ALLOCATOR_METHODS, AllocatorKind, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, + default_fn_name, global_fn_name, }; use rustc_codegen_ssa::base::allocator_kind_for_codegen; use rustc_session::config::OomStrategy; @@ -72,17 +72,19 @@ fn codegen_inner( } } - let sig = Signature { - call_conv: module.target_config().default_call_conv, - params: vec![AbiParam::new(usize_ty), AbiParam::new(usize_ty)], - returns: vec![], - }; - crate::common::create_wrapper_function( - module, - sig, - &mangle_internal_symbol(tcx, "__rust_alloc_error_handler"), - &mangle_internal_symbol(tcx, alloc_error_handler_name(alloc_error_handler_kind)), - ); + if alloc_error_handler_kind == AllocatorKind::Default { + let sig = Signature { + call_conv: module.target_config().default_call_conv, + params: vec![AbiParam::new(usize_ty), AbiParam::new(usize_ty)], + returns: vec![], + }; + crate::common::create_wrapper_function( + module, + sig, + &mangle_internal_symbol(tcx, &global_fn_name(ALLOC_ERROR_HANDLER)), + &mangle_internal_symbol(tcx, &default_fn_name(ALLOC_ERROR_HANDLER)), + ); + } { let sig = Signature { From b453c19e91900d7f494446c37c3e25a04fac6478 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 9 Oct 2025 14:08:55 +0000 Subject: [PATCH 134/160] Move computation of allocator shim contents to cg_ssa In the future this should make it easier to use weak symbols for the allocator shim on platforms that properly support weak symbols. And it would allow reusing the allocator shim code for handling default implementations of the upcoming externally implementable items feature on platforms that don't properly support weak symbols. --- src/allocator.rs | 79 ++++++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 50 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index 9533f870434ab..67b89114356b5 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -3,10 +3,9 @@ use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext}; use rustc_ast::expand::allocator::{ - ALLOC_ERROR_HANDLER, ALLOCATOR_METHODS, AllocatorKind, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, - default_fn_name, global_fn_name, + AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, default_fn_name, global_fn_name, }; -use rustc_codegen_ssa::base::allocator_kind_for_codegen; +use rustc_codegen_ssa::base::{allocator_kind_for_codegen, allocator_shim_contents}; use rustc_session::config::OomStrategy; use rustc_symbol_mangling::mangle_internal_symbol; @@ -15,74 +14,54 @@ use crate::prelude::*; /// Returns whether an allocator shim was created pub(crate) fn codegen(tcx: TyCtxt<'_>, module: &mut dyn Module) -> bool { let Some(kind) = allocator_kind_for_codegen(tcx) else { return false }; - codegen_inner( - tcx, - module, - kind, - tcx.alloc_error_handler_kind(()).unwrap(), - tcx.sess.opts.unstable_opts.oom, - ); + let methods = allocator_shim_contents(tcx, kind); + codegen_inner(tcx, module, &methods, tcx.sess.opts.unstable_opts.oom); true } fn codegen_inner( tcx: TyCtxt<'_>, module: &mut dyn Module, - kind: AllocatorKind, - alloc_error_handler_kind: AllocatorKind, + methods: &[AllocatorMethod], oom_strategy: OomStrategy, ) { let usize_ty = module.target_config().pointer_type(); - if kind == AllocatorKind::Default { - for method in ALLOCATOR_METHODS { - let mut arg_tys = Vec::with_capacity(method.inputs.len()); - for input in method.inputs.iter() { - match input.ty { - AllocatorTy::Layout => { - arg_tys.push(usize_ty); // size - arg_tys.push(usize_ty); // align - } - AllocatorTy::Ptr => arg_tys.push(usize_ty), - AllocatorTy::Usize => arg_tys.push(usize_ty), - - AllocatorTy::ResultPtr | AllocatorTy::Unit => panic!("invalid allocator arg"), + for method in methods { + let mut arg_tys = Vec::with_capacity(method.inputs.len()); + for input in method.inputs.iter() { + match input.ty { + AllocatorTy::Layout => { + arg_tys.push(usize_ty); // size + arg_tys.push(usize_ty); // align } - } - let output = match method.output { - AllocatorTy::ResultPtr => Some(usize_ty), - AllocatorTy::Unit => None, + AllocatorTy::Ptr => arg_tys.push(usize_ty), + AllocatorTy::Usize => arg_tys.push(usize_ty), - AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => { - panic!("invalid allocator output") + AllocatorTy::Never | AllocatorTy::ResultPtr | AllocatorTy::Unit => { + panic!("invalid allocator arg") } - }; - - let sig = Signature { - call_conv: module.target_config().default_call_conv, - params: arg_tys.iter().cloned().map(AbiParam::new).collect(), - returns: output.into_iter().map(AbiParam::new).collect(), - }; - crate::common::create_wrapper_function( - module, - sig, - &mangle_internal_symbol(tcx, &global_fn_name(method.name)), - &mangle_internal_symbol(tcx, &default_fn_name(method.name)), - ); + } } - } + let output = match method.output { + AllocatorTy::ResultPtr => Some(usize_ty), + AllocatorTy::Never | AllocatorTy::Unit => None, + + AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => { + panic!("invalid allocator output") + } + }; - if alloc_error_handler_kind == AllocatorKind::Default { let sig = Signature { call_conv: module.target_config().default_call_conv, - params: vec![AbiParam::new(usize_ty), AbiParam::new(usize_ty)], - returns: vec![], + params: arg_tys.iter().cloned().map(AbiParam::new).collect(), + returns: output.into_iter().map(AbiParam::new).collect(), }; crate::common::create_wrapper_function( module, sig, - &mangle_internal_symbol(tcx, &global_fn_name(ALLOC_ERROR_HANDLER)), - &mangle_internal_symbol(tcx, &default_fn_name(ALLOC_ERROR_HANDLER)), + &mangle_internal_symbol(tcx, &global_fn_name(method.name)), + &mangle_internal_symbol(tcx, &default_fn_name(method.name)), ); } From f3d5c10e9e3224413061baeb38f35f750302ea9c Mon Sep 17 00:00:00 2001 From: Diggory Blake Date: Sun, 6 Jul 2025 20:58:14 +0100 Subject: [PATCH 135/160] Restrict sysroot crate imports to those defined in this repo. It's common to import dependencies from the sysroot via `extern crate` rather than use an explicit cargo dependency, when it's necessary to use the same dependency version as used by rustc itself. However, this is dangerous for crates.io crates, since rustc may not pull in the dependency on some targets, or may pull in multiple versions. In both cases, the `extern crate` fails to resolve. To address this, re-export all such dependencies from the appropriate `rustc_*` crates, and use this alias from crates which would otherwise need to use `extern crate`. --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5fd7c4d4f41bb..5d48d0c94c581 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,13 +26,12 @@ extern crate rustc_fs_util; extern crate rustc_hir; extern crate rustc_incremental; extern crate rustc_index; +extern crate rustc_log; extern crate rustc_metadata; extern crate rustc_session; extern crate rustc_span; extern crate rustc_symbol_mangling; extern crate rustc_target; -#[macro_use] -extern crate tracing; // This prevents duplicating functions and statics that are already part of the host rustc process. #[allow(unused_extern_crates)] @@ -46,6 +45,7 @@ use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::settings::{self, Configurable}; use rustc_codegen_ssa::traits::CodegenBackend; use rustc_codegen_ssa::{CodegenResults, TargetConfig}; +use rustc_log::tracing::info; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_session::Session; use rustc_session::config::OutputFilenames; From 10ee204ff7a4a39bb75ae10db3d62689dceb4f50 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 10 Oct 2025 21:29:29 -0400 Subject: [PATCH 136/160] Fix ICE on offsetted ZST pointer A grep for `const_usize.*align` found the same code copied to rustc_codegen_gcc but I don't see other cases where we get this wrong. --- src/constant.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 293459cc11c2f..3243e12e69999 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -5,7 +5,9 @@ use std::cmp::Ordering; use cranelift_module::*; use rustc_data_structures::fx::FxHashSet; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; -use rustc_middle::mir::interpret::{AllocId, GlobalAlloc, Scalar, read_target_uint}; +use rustc_middle::mir::interpret::{ + AllocId, GlobalAlloc, PointerArithmetic, Scalar, read_target_uint, +}; use rustc_middle::ty::{ExistentialTraitRef, ScalarInt}; use crate::prelude::*; @@ -138,8 +140,11 @@ pub(crate) fn codegen_const_value<'tcx>( let base_addr = match fx.tcx.global_alloc(alloc_id) { GlobalAlloc::Memory(alloc) => { if alloc.inner().len() == 0 { - assert_eq!(offset, Size::ZERO); - fx.bcx.ins().iconst(fx.pointer_type, alloc.inner().align.bytes() as i64) + let val = alloc.inner().align.bytes().wrapping_add(offset.bytes()); + fx.bcx.ins().iconst( + fx.pointer_type, + fx.tcx.truncate_to_target_usize(val) as i64, + ) } else { let data_id = data_id_for_alloc_id( &mut fx.constants_cx, From 2d8a0c18160abfdd903ac55d54c852038c303605 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 17 Oct 2025 10:54:47 +0000 Subject: [PATCH 137/160] Rustup to rustc 1.92.0-nightly (53a741fc4 2025-10-16) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 9259a33c8c90e..4196e4872dffe 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-10-06" +channel = "nightly-2025-10-17" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From ca23203edb4512047565297ce11784b11f427a50 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 17 Oct 2025 11:35:42 +0000 Subject: [PATCH 138/160] Fix rustc test suite --- scripts/test_rustc_tests.sh | 2 ++ src/constant.rs | 10 ++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 78802f97af2c1..cbea3caf1211e 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -49,6 +49,7 @@ rm -r tests/run-make/c-link-to-rust-va-list-fn # requires callee side vararg sup rm tests/ui/c-variadic/valid.rs # same rm tests/ui/c-variadic/trait-method.rs # same rm tests/ui/c-variadic/inherent-method.rs # same +rm tests/ui/sanitizer/kcfi-c-variadic.rs # same rm tests/ui/c-variadic/same-program-multiple-abis-x86_64.rs # variadics for calling conventions other than C unsupported rm tests/ui/delegation/fn-header.rs @@ -62,6 +63,7 @@ rm tests/ui/asm/x86_64/issue-96797.rs # const and sym inline asm operands don't rm tests/ui/asm/global-asm-mono-sym-fn.rs # same rm tests/ui/asm/naked-asm-mono-sym-fn.rs # same rm tests/ui/asm/x86_64/goto.rs # inline asm labels not supported +rm tests/ui/asm/label-operand.rs # same rm tests/ui/simd/simd-bitmask-notpow2.rs # non-pow-of-2 simd vector sizes rm -r tests/run-make/used-proc-macro # used(linker) isn't supported yet rm tests/ui/linking/no-gc-encapsulation-symbols.rs # same diff --git a/src/constant.rs b/src/constant.rs index 5ad78e97d2b8e..38b66256ea300 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -141,11 +141,7 @@ pub(crate) fn codegen_const_value<'tcx>( let base_addr = match fx.tcx.global_alloc(alloc_id) { GlobalAlloc::Memory(alloc) => { if alloc.inner().len() == 0 { - let val = alloc.inner().align.bytes().wrapping_add(offset.bytes()); - fx.bcx.ins().iconst( - fx.pointer_type, - fx.tcx.truncate_to_target_usize(val) as i64, - ) + fx.bcx.ins().iconst(fx.pointer_type, alloc.inner().align.bytes() as i64) } else { let data_id = data_id_for_alloc_id( &mut fx.constants_cx, @@ -213,7 +209,9 @@ pub(crate) fn codegen_const_value<'tcx>( } }; let val = if offset.bytes() != 0 { - fx.bcx.ins().iadd_imm(base_addr, i64::try_from(offset.bytes()).unwrap()) + fx.bcx + .ins() + .iadd_imm(base_addr, fx.tcx.truncate_to_target_usize(offset.bytes()) as i64) } else { base_addr }; From a20a4c25133b6e259979ddb07e4d277cb1b1878b Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 9 Oct 2025 10:58:27 +0000 Subject: [PATCH 139/160] Update to Cranelift 0.125 --- Cargo.lock | 72 +++++++++++++++++++++++++++--------------------------- Cargo.toml | 24 +++++++++--------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a81f72e17fb82..09b6c6b87c300 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,42 +43,42 @@ checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "cranelift-assembler-x64" -version = "0.124.1" +version = "0.125.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e8ca189363907c025c5debe2bfe56c8c18503d4575d750f87e4ccbbfbd8681" +checksum = "f502c60b6af2025c312b37788c089943ef03156a2910da1aa046bb39eb8f61c7" dependencies = [ "cranelift-assembler-x64-meta", ] [[package]] name = "cranelift-assembler-x64-meta" -version = "0.124.1" +version = "0.125.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e169461bfd463df68b01b196522f263c905eadc852f6e57fd4ce4c5d76115ead" +checksum = "2b7e21a74bcf08443a4ef800a4a257063e5c51ee4d7a3bd58da5262d10340830" dependencies = [ "cranelift-srcgen", ] [[package]] name = "cranelift-bforest" -version = "0.124.1" +version = "0.125.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a98298338375075287834defe333d552847110f3a04db0ce19bd308b4c40fbb" +checksum = "f337d268865c292ad5df0669a9bbf6223ca41460292a20ad5b0a57b8e9f27f93" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-bitset" -version = "0.124.1" +version = "0.125.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edf5f49a2e2ae284db75437a49cc13220a7fb394983d5545af1209ab0bbadee3" +checksum = "c0e60319a8242c8d1c7b5a2444d140c416f903f75e0d84da3256fceb822bab85" [[package]] name = "cranelift-codegen" -version = "0.124.1" +version = "0.125.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c354d6db9e344f647f38c88849c482c6014b79a295aca23fa82f73b62caeda2d" +checksum = "78dee669e447a1c68760bf7acee33835e99d564f0137b067f74d4718dfc9970d" dependencies = [ "bumpalo", "cranelift-assembler-x64", @@ -102,9 +102,9 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.124.1" +version = "0.125.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8008396957de750e26d0b40a76bea6e5623d970a5bfe4266ef0a79ccb8341" +checksum = "601f629d172b7230f41dd0e78ee797efaf7ec1a5e113c8f395f4027dff6a92ca" dependencies = [ "cranelift-assembler-x64-meta", "cranelift-codegen-shared", @@ -114,33 +114,33 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" -version = "0.124.1" +version = "0.125.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98ecb53eafe1ad1f7d7f7d0585ae5d42b2050978fa812216b0420d4752eb41cb" +checksum = "15755c2660902c7d59d96f6551a66ef629650dc3fd405f9dad841e8c58c1a4a2" [[package]] name = "cranelift-control" -version = "0.124.1" +version = "0.125.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9c43ac27fe178cadb17e7f4cf1320ba89b8875cc2bdee265cccfca49bc76c95" +checksum = "727bfca18705101a294ab9077ad214a8b762ea2bc9844389d0db233d7c61ec3b" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.124.1" +version = "0.125.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15513ee4bf648d366654c6a9864fe870ca64f1eed4acabf9139056e68b3d44dc" +checksum = "15564c6f0c72750ca4374f40b044857cbc8087571e46d4c7ccdbdcc29b1dec8b" dependencies = [ "cranelift-bitset", ] [[package]] name = "cranelift-frontend" -version = "0.124.1" +version = "0.125.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e4399d31f06b50fcb3fa0117ff4c393c22e521574eecf524cf932fc99cd78f" +checksum = "16c681f2731f1cf68eed9f3b6811571823a5ac498f59c52b73736b68599defb3" dependencies = [ "cranelift-codegen", "log", @@ -150,15 +150,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.124.1" +version = "0.125.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a751ec2b7c2f281274a3798e37ba2344b55f60789e67aaa10d6bbea3f3f8a6b" +checksum = "40cedc02f08307da019a3e06d3f20f772f829ff813aec975accb012f8930b688" [[package]] name = "cranelift-jit" -version = "0.124.1" +version = "0.125.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b22769d71584df8b6a083e11a248da38c40c0b91b565c8c202b173b26cc861c" +checksum = "c2864461448c72d15ae3311ea63df9c7e35f22f04683785f6715a0cf17e6577d" dependencies = [ "anyhow", "cranelift-codegen", @@ -176,9 +176,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.124.1" +version = "0.125.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb364ea65183c3961faf6cc5038bd88ceb957c3cd3480958bce28d02b194625" +checksum = "2b31d249bbbccc4c1ae54701087d4d49d05951897691eef44f4a60e70252743b" dependencies = [ "anyhow", "cranelift-codegen", @@ -187,9 +187,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.124.1" +version = "0.125.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "546500d7cb424c423e118dfddc169aa61ed611c47fc1cf48783ed4e3f9800619" +checksum = "db03ab51c60710eb83d0217725b77db4062aca83b35359f5e6aa99ed1c275977" dependencies = [ "cranelift-codegen", "libc", @@ -198,9 +198,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.124.1" +version = "0.125.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3aae694e5dd436c87ac90d1468a1032ff63d54faa33dcfece7e8fc7072fbe73" +checksum = "7131e0eb45ee10b0bd6082d0c0114c2e9a670b034d46774b39d0fc5c0ed7cedf" dependencies = [ "anyhow", "cranelift-codegen", @@ -213,9 +213,9 @@ dependencies = [ [[package]] name = "cranelift-srcgen" -version = "0.124.1" +version = "0.125.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edeb6b718b23108a123ad1c8eecf6fa34d21a6b5518fc340dda80ce5bdf42377" +checksum = "3d7a06c330b7994a891ad5b622ebc9aefcd17beae832dd25f577cf60c13426bf" [[package]] name = "crc32fast" @@ -460,9 +460,9 @@ checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "wasmtime-internal-jit-icache-coherence" -version = "37.0.1" +version = "38.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4aea2b284343796fbbe749c36db092b43809762f8b9e46626561a8be4003dd85" +checksum = "8d0a76f1a6e887cc1b551b02dfd6e2ce5f6738e8cacd9ad7284f6ac1aac4698f" dependencies = [ "anyhow", "cfg-if", @@ -472,9 +472,9 @@ dependencies = [ [[package]] name = "wasmtime-internal-math" -version = "37.0.1" +version = "38.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a058122e659373c3648a71de03436105f213037d8016bb68550c259d4b37931" +checksum = "b900df4252ad86547e7f2b2c00201b006db4e864893bedfb3aca32b23d81868a" dependencies = [ "libm", ] diff --git a/Cargo.toml b/Cargo.toml index 3adf9f415c9a8..f2001123e579d 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.124.1", default-features = false, features = ["std", "timing", "unwind", "all-native-arch"] } -cranelift-frontend = { version = "0.124.1" } -cranelift-module = { version = "0.124.1" } -cranelift-native = { version = "0.124.1" } -cranelift-jit = { version = "0.124.1", optional = true } -cranelift-object = { version = "0.124.1" } +cranelift-codegen = { version = "0.125.0", default-features = false, features = ["std", "timing", "unwind", "all-native-arch"] } +cranelift-frontend = { version = "0.125.0" } +cranelift-module = { version = "0.125.0" } +cranelift-native = { version = "0.125.0" } +cranelift-jit = { version = "0.125.0", optional = true } +cranelift-object = { version = "0.125.0" } target-lexicon = "0.13" gimli = { version = "0.32", default-features = false, features = ["write"] } object = { version = "0.37.3", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } @@ -24,12 +24,12 @@ smallvec = "1.8.1" [patch.crates-io] # Uncomment to use an unreleased version of cranelift -#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-37.0.0" } -#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-37.0.0" } -#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-37.0.0" } -#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-37.0.0" } -#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-37.0.0" } -#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-37.0.0" } +#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-38.0.0" } +#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-38.0.0" } +#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-38.0.0" } +#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-38.0.0" } +#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-38.0.0" } +#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-38.0.0" } # Uncomment to use local checkout of cranelift #cranelift-codegen = { path = "../wasmtime/cranelift/codegen" } From 6031dfdaed2b4c59de9b53544961e633c7e1d42a Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 16 Apr 2025 11:39:04 +0000 Subject: [PATCH 140/160] Allow unsizing pattern types with pointer base --- src/unsize.rs | 5 +++++ src/value_and_place.rs | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/src/unsize.rs b/src/unsize.rs index d994f3e32ec3c..c97eb3874b02c 100644 --- a/src/unsize.rs +++ b/src/unsize.rs @@ -131,6 +131,11 @@ pub(crate) fn coerce_unsized_into<'tcx>( dst.write_cvalue(fx, CValue::by_val_pair(base, info, dst.layout())); }; match (&src_ty.kind(), &dst_ty.kind()) { + (ty::Pat(a, _), ty::Pat(b, _)) => { + let src = src.cast_pat_ty_to_base(fx.layout_of(*a)); + let dst = dst.place_transmute_type(fx, *b); + return coerce_unsized_into(fx, src, dst); + } (&ty::Ref(..), &ty::Ref(..)) | (&ty::Ref(..), &ty::RawPtr(..)) | (&ty::RawPtr(..), &ty::RawPtr(..)) => coerce_ptr(), diff --git a/src/value_and_place.rs b/src/value_and_place.rs index db9b80c0f6a07..9dcd4a33d44f6 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -342,6 +342,14 @@ impl<'tcx> CValue<'tcx> { assert_eq!(self.layout().backend_repr, layout.backend_repr); CValue(self.0, layout) } + + pub(crate) fn cast_pat_ty_to_base(self, layout: TyAndLayout<'tcx>) -> Self { + let ty::Pat(base, _) = *self.layout().ty.kind() else { + panic!("not a pattern type: {:#?}", self.layout()) + }; + assert_eq!(layout.ty, base); + CValue(self.0, layout) + } } /// A place where you can write a value to or read a value from From 9d63e8c13597d8de412efd4f0a57f283c06be86a Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Sun, 12 Oct 2025 22:01:08 +0000 Subject: [PATCH 141/160] Elaborate ShallowInitBox too. --- src/base.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/base.rs b/src/base.rs index 7e99eb09b91ab..c97218797107b 100644 --- a/src/base.rs +++ b/src/base.rs @@ -829,13 +829,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt: fx.bcx.ins().nop(); } } - Rvalue::ShallowInitBox(ref operand, content_ty) => { - let content_ty = fx.monomorphize(content_ty); - let box_layout = fx.layout_of(Ty::new_box(fx.tcx, content_ty)); - let operand = codegen_operand(fx, operand); - let operand = operand.load_scalar(fx); - lval.write_cvalue(fx, CValue::by_val(operand, box_layout)); - } Rvalue::NullaryOp(ref null_op, ty) => { assert!(lval.layout().ty.is_sized(fx.tcx, fx.typing_env())); let layout = fx.layout_of(fx.monomorphize(ty)); @@ -924,6 +917,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt: lval.write_cvalue_transmute(fx, operand); } Rvalue::CopyForDeref(_) => bug!("`CopyForDeref` in codegen"), + Rvalue::ShallowInitBox(..) => bug!("`ShallowInitBox` in codegen"), } } StatementKind::StorageLive(_) From cc27b04473f65d6c080a54a678f7e08a74f423f1 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Thu, 16 Oct 2025 21:23:43 +0000 Subject: [PATCH 142/160] Replace NullOp::SizeOf and NullOp::AlignOf by lang items. --- example/example.rs | 4 ---- example/mini_core.rs | 24 +++++++++++++++++++++--- example/mini_core_hello_world.rs | 8 ++++---- src/base.rs | 2 -- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/example/example.rs b/example/example.rs index aeb38331edb02..769d262b9ebb5 100644 --- a/example/example.rs +++ b/example/example.rs @@ -72,10 +72,6 @@ pub fn debug_tuple() -> DebugTuple { DebugTuple(()) } -pub fn size_of() -> usize { - intrinsics::size_of::() -} - pub fn use_size_of() -> usize { size_of::() } diff --git a/example/mini_core.rs b/example/mini_core.rs index 2f53bbf8b7934..304d0d648561e 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -6,6 +6,7 @@ extern_types, decl_macro, rustc_attrs, + rustc_private, transparent_unions, auto_traits, freeze_impls, @@ -594,7 +595,7 @@ impl, U: ?Sized> CoerceUnsized> for Box {} impl Box { pub fn new(val: T) -> Box { unsafe { - let size = intrinsics::size_of::(); + let size = size_of::(); let ptr = libc::malloc(size); intrinsics::copy(&val as *const T as *const u8, ptr, size); Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, Global) @@ -646,11 +647,11 @@ pub mod intrinsics { #[rustc_intrinsic] pub fn abort() -> !; #[rustc_intrinsic] - pub fn size_of() -> usize; + pub const fn size_of() -> usize; #[rustc_intrinsic] pub unsafe fn size_of_val(val: *const T) -> usize; #[rustc_intrinsic] - pub fn align_of() -> usize; + pub const fn align_of() -> usize; #[rustc_intrinsic] pub unsafe fn align_of_val(val: *const T) -> usize; #[rustc_intrinsic] @@ -715,6 +716,23 @@ impl Index for [T] { } } +pub const fn size_of() -> usize { + ::SIZE +} + +pub const fn align_of() -> usize { + ::ALIGN +} + +trait SizedTypeProperties: Sized { + #[lang = "mem_size_const"] + const SIZE: usize = intrinsics::size_of::(); + + #[lang = "mem_align_const"] + const ALIGN: usize = intrinsics::align_of::(); +} +impl SizedTypeProperties for T {} + extern "C" { type VaListImpl; } diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 86602c6b2a3fd..a9388814a7f59 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -109,10 +109,10 @@ fn start( puts(*argv as *const i8); } unsafe { - puts(*((argv as usize + intrinsics::size_of::<*const u8>()) as *const *const i8)); + puts(*((argv as usize + size_of::<*const u8>()) as *const *const i8)); } unsafe { - puts(*((argv as usize + 2 * intrinsics::size_of::<*const u8>()) as *const *const i8)); + puts(*((argv as usize + 2 * size_of::<*const u8>()) as *const *const i8)); } } @@ -213,8 +213,8 @@ fn main() { assert_eq!(intrinsics::size_of_val(a) as u8, 16); assert_eq!(intrinsics::size_of_val(&0u32) as u8, 4); - assert_eq!(intrinsics::align_of::() as u8, 2); - assert_eq!(intrinsics::align_of_val(&a) as u8, intrinsics::align_of::<&str>() as u8); + assert_eq!(align_of::() as u8, 2); + assert_eq!(intrinsics::align_of_val(&a) as u8, align_of::<&str>() as u8); let u8_needs_drop = const { intrinsics::needs_drop::() }; assert!(!u8_needs_drop); diff --git a/src/base.rs b/src/base.rs index c97218797107b..7d50548b40262 100644 --- a/src/base.rs +++ b/src/base.rs @@ -833,8 +833,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt: assert!(lval.layout().ty.is_sized(fx.tcx, fx.typing_env())); let layout = fx.layout_of(fx.monomorphize(ty)); let val = match null_op { - NullOp::SizeOf => layout.size.bytes(), - NullOp::AlignOf => layout.align.bytes(), NullOp::OffsetOf(fields) => fx .tcx .offset_of_subfield( From bc6f1ef74a55ba5097dd80e898bea9cbe37c802e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 23 Oct 2025 11:43:38 +0000 Subject: [PATCH 143/160] Rustup to rustc 1.92.0-nightly (1d23d0680 2025-10-22) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 4196e4872dffe..3bede572d2c2b 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-10-17" +channel = "nightly-2025-10-23" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From b548b29e10dafaa433da634f07f2519cc502ecd8 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 23 Oct 2025 14:45:51 +0000 Subject: [PATCH 144/160] Skip codegen_crate call in check mode --- src/driver/aot.rs | 13 +------------ src/driver/jit.rs | 4 +--- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 7e77781dc2fc1..7bf1efc10653f 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -671,18 +671,7 @@ pub(crate) fn run_aot(tcx: TyCtxt<'_>) -> Box { } .to_owned(); - let cgus = if tcx.sess.opts.output_types.should_codegen() { - tcx.collect_and_partition_mono_items(()).codegen_units - } else { - // If only `--emit metadata` is used, we shouldn't perform any codegen. - // Also `tcx.collect_and_partition_mono_items` may panic in that case. - return Box::new(OngoingCodegen { - modules: vec![], - allocator_module: None, - crate_info: CrateInfo::new(tcx, target_cpu), - concurrency_limiter: ConcurrencyLimiter::new(0), - }); - }; + let cgus = tcx.collect_and_partition_mono_items(()).codegen_units; if tcx.dep_graph.is_fully_enabled() { for cgu in cgus { diff --git a/src/driver/jit.rs b/src/driver/jit.rs index b3497503bf068..fec46bf26975d 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -33,9 +33,7 @@ fn create_jit_module(tcx: TyCtxt<'_>) -> (UnwindModule, CodegenCx) { } pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec) -> ! { - if !tcx.sess.opts.output_types.should_codegen() { - tcx.dcx().fatal("JIT mode doesn't work with `cargo check`"); - } + // FIXME error on check mode or crate types other than bin in CodegenBackend::init() if !tcx.crate_types().contains(&rustc_session::config::CrateType::Executable) { tcx.dcx().fatal("can't jit non-executable crate"); From 5aabbb63219eeb66adbfab2b9562d04f900fd56e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 24 Oct 2025 19:02:01 +0000 Subject: [PATCH 145/160] Fix dev release after renaming the default branch to main --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 52a8eeee13d4b..0930b924d1773 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -231,7 +231,7 @@ jobs: release: runs-on: ubuntu-latest timeout-minutes: 10 - if: ${{ github.ref == 'refs/heads/master' }} + if: ${{ github.ref == 'refs/heads/main' }} needs: [rustfmt, test, bench, dist] permissions: From 022bb60b8e170cb7c2e884cf7c4187af5ca55edb Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 28 Oct 2025 15:17:46 +0000 Subject: [PATCH 146/160] Rustup to rustc 1.93.0-nightly (adaa83897 2025-10-27) --- example/mini_core.rs | 1 - rust-toolchain | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/example/mini_core.rs b/example/mini_core.rs index b522ea1937166..2dd75563a34d3 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -6,7 +6,6 @@ extern_types, decl_macro, rustc_attrs, - rustc_private, transparent_unions, auto_traits, freeze_impls, diff --git a/rust-toolchain b/rust-toolchain index 3bede572d2c2b..0836d830186cb 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-10-23" +channel = "nightly-2025-10-28" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From bbedad249cd0a7723403f48b2a5fe0ce60746687 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 28 Oct 2025 15:34:36 +0000 Subject: [PATCH 147/160] Error when combining check mode and jit mode --- src/config.rs | 2 +- src/driver/jit.rs | 2 -- src/lib.rs | 21 ++++++++++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index d328b33a704f5..31bc0374460f4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,5 @@ /// Configuration of cg_clif as passed in through `-Cllvm-args` and various env vars. -#[derive(Clone, Debug)] +#[derive(Debug)] pub struct BackendConfig { /// Should the crate be AOT compiled or JIT executed. /// diff --git a/src/driver/jit.rs b/src/driver/jit.rs index e35df7a5e787a..9dba46363936f 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -33,8 +33,6 @@ fn create_jit_module(tcx: TyCtxt<'_>) -> (UnwindModule, Option, jit_args: Vec) -> ! { - // FIXME error on check mode or crate types other than bin in CodegenBackend::init() - if !tcx.crate_types().contains(&rustc_session::config::CrateType::Executable) { tcx.dcx().fatal("can't jit non-executable crate"); } diff --git a/src/lib.rs b/src/lib.rs index a45407497f686..1815f990fc16f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,6 +39,7 @@ extern crate rustc_target; extern crate rustc_driver; use std::any::Any; +use std::cell::OnceCell; use std::env; use std::sync::Arc; @@ -124,7 +125,7 @@ impl String> Drop for PrintOnPanic { } pub struct CraneliftCodegenBackend { - pub config: Option, + pub config: OnceCell, } impl CodegenBackend for CraneliftCodegenBackend { @@ -150,6 +151,15 @@ impl CodegenBackend for CraneliftCodegenBackend { sess.dcx() .fatal("`-Cinstrument-coverage` is LLVM specific and not supported by Cranelift"); } + + let config = self.config.get_or_init(|| { + BackendConfig::from_opts(&sess.opts.cg.llvm_args) + .unwrap_or_else(|err| sess.dcx().fatal(err)) + }); + + if config.jit_mode && !sess.opts.output_types.should_codegen() { + sess.dcx().fatal("JIT mode doesn't work with `cargo check`"); + } } fn target_config(&self, sess: &Session) -> TargetConfig { @@ -211,13 +221,10 @@ impl CodegenBackend for CraneliftCodegenBackend { fn codegen_crate(&self, tcx: TyCtxt<'_>) -> Box { info!("codegen crate {}", tcx.crate_name(LOCAL_CRATE)); - let config = self.config.clone().unwrap_or_else(|| { - BackendConfig::from_opts(&tcx.sess.opts.cg.llvm_args) - .unwrap_or_else(|err| tcx.sess.dcx().fatal(err)) - }); + let config = self.config.get().unwrap(); if config.jit_mode { #[cfg(feature = "jit")] - driver::jit::run_jit(tcx, config.jit_args); + driver::jit::run_jit(tcx, config.jit_args.clone()); #[cfg(not(feature = "jit"))] tcx.dcx().fatal("jit support was disabled when compiling rustc_codegen_cranelift"); @@ -363,5 +370,5 @@ fn build_isa(sess: &Session, jit: bool) -> Arc { /// This is the entrypoint for a hot plugged rustc_codegen_cranelift #[unsafe(no_mangle)] pub fn __rustc_codegen_backend() -> Box { - Box::new(CraneliftCodegenBackend { config: None }) + Box::new(CraneliftCodegenBackend { config: OnceCell::new() }) } From eaa91b8f04b2f7adde1db8a8c49c44543344dc6a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 28 Oct 2025 16:05:34 +0000 Subject: [PATCH 148/160] Bunch of clippy fixes --- src/abi/mod.rs | 35 +++++++++++++++++-------------- src/abi/pass_mode.rs | 7 +------ src/base.rs | 10 ++++----- src/codegen_f16_f128.rs | 3 +-- src/common.rs | 6 +++--- src/constant.rs | 23 ++++++++------------ src/debuginfo/emit.rs | 4 ++-- src/debuginfo/gcc_except_table.rs | 9 ++++---- src/debuginfo/types.rs | 4 ++-- src/driver/aot.rs | 18 ++++++++-------- src/intrinsics/mod.rs | 6 +++--- src/intrinsics/simd.rs | 2 +- src/lib.rs | 4 ++-- src/main_shim.rs | 6 +++--- src/pretty_clif.rs | 2 +- src/unsize.rs | 2 +- src/value_and_place.rs | 8 +++---- 17 files changed, 70 insertions(+), 79 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 576fc453e7907..773a134e90415 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -85,7 +85,7 @@ pub(crate) fn get_function_sig<'tcx>( clif_sig_from_fn_abi( tcx, default_call_conv, - &FullyMonomorphizedLayoutCx(tcx).fn_abi_of_instance(inst, ty::List::empty()), + FullyMonomorphizedLayoutCx(tcx).fn_abi_of_instance(inst, ty::List::empty()), ) } @@ -114,7 +114,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { /// Instance must be monomorphized pub(crate) fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef { let func_id = import_function(self.tcx, self.module, inst); - let func_ref = self.module.declare_func_in_func(func_id, &mut self.bcx.func); + let func_ref = self.module.declare_func_in_func(func_id, self.bcx.func); if self.clif_comments.enabled() { self.add_comment(func_ref, format!("{:?}", inst)); @@ -185,7 +185,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { ) -> &[Value] { 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); + let func_ref = self.module.declare_func_in_func(func_id, self.bcx.func); let call_inst = self.bcx.ins().call(func_ref, args); if self.clif_comments.enabled() { self.add_comment(func_ref, format!("{:?}", name)); @@ -419,7 +419,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( if fx.tcx.symbol_name(instance).name.starts_with("llvm.") { crate::intrinsics::codegen_llvm_intrinsic_call( fx, - &fx.tcx.symbol_name(instance).name, + fx.tcx.symbol_name(instance).name, args, ret_place, target, @@ -534,7 +534,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( } let (ptr, method) = crate::vtable::get_ptr_and_method_ref(fx, args[0].value, idx); - let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi); + let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, fn_abi); let sig = fx.bcx.import_signature(sig); (CallTarget::Indirect(sig, method), Some(ptr.get_addr(fx))) @@ -554,7 +554,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( } let func = func.load_scalar(fx); - let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi); + let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, fn_abi); let sig = fx.bcx.import_signature(sig); (CallTarget::Indirect(sig, func), None) @@ -564,7 +564,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( self::returning::codegen_with_call_return_arg(fx, &fn_abi.ret, ret_place, |fx, return_ptr| { let mut call_args = return_ptr .into_iter() - .chain(first_arg_override.into_iter()) + .chain(first_arg_override) .chain( args.into_iter() .enumerate() @@ -577,7 +577,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( // FIXME: Find a cleaner way to support varargs. if fn_abi.c_variadic { - adjust_call_for_c_variadic(fx, &fn_abi, source_info, func_ref, &mut call_args); + adjust_call_for_c_variadic(fx, fn_abi, source_info, func_ref, &mut call_args); } if fx.clif_comments.enabled() { @@ -739,7 +739,7 @@ pub(crate) fn codegen_drop<'tcx>( let fn_abi = FullyMonomorphizedLayoutCx(fx.tcx) .fn_abi_of_instance(virtual_drop, ty::List::empty()); - let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi); + let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, fn_abi); let sig = fx.bcx.import_signature(sig); codegen_call_with_unwind_action( fx, @@ -767,9 +767,12 @@ pub(crate) fn codegen_drop<'tcx>( if drop_instance.def.requires_caller_location(fx.tcx) { // Pass the caller location for `#[track_caller]`. let caller_location = fx.get_caller_location(source_info); - call_args.extend( - adjust_arg_for_abi(fx, caller_location, &fn_abi.args[1], false).into_iter(), - ); + call_args.extend(adjust_arg_for_abi( + fx, + caller_location, + &fn_abi.args[1], + false, + )); } let func_ref = fx.get_function_ref(drop_instance); @@ -816,9 +819,9 @@ pub(crate) fn codegen_call_with_unwind_action( match unwind { UnwindAction::Continue | UnwindAction::Unreachable => { let call_inst = match func_ref { - CallTarget::Direct(func_ref) => fx.bcx.ins().call(func_ref, &call_args), + CallTarget::Direct(func_ref) => fx.bcx.ins().call(func_ref, call_args), CallTarget::Indirect(sig, func_ptr) => { - fx.bcx.ins().call_indirect(sig, func_ptr, &call_args) + fx.bcx.ins().call_indirect(sig, func_ptr, call_args) } }; @@ -866,10 +869,10 @@ pub(crate) fn codegen_call_with_unwind_action( match func_ref { CallTarget::Direct(func_ref) => { - fx.bcx.ins().try_call(func_ref, &call_args, exception_table); + fx.bcx.ins().try_call(func_ref, call_args, exception_table); } CallTarget::Indirect(_sig, func_ptr) => { - fx.bcx.ins().try_call_indirect(func_ptr, &call_args, exception_table); + fx.bcx.ins().try_call_indirect(func_ptr, call_args, exception_table); } } diff --git a/src/abi/pass_mode.rs b/src/abi/pass_mode.rs index 7a909a740b054..44b63aa95f83c 100644 --- a/src/abi/pass_mode.rs +++ b/src/abi/pass_mode.rs @@ -209,12 +209,7 @@ pub(super) fn to_casted_value<'tcx>( cast_target_to_abi_params(cast) .into_iter() .map(|(offset, param)| { - let val = ptr.offset_i64(fx, offset.bytes() as i64).load( - fx, - param.value_type, - MemFlags::new(), - ); - val + ptr.offset_i64(fx, offset.bytes() as i64).load(fx, param.value_type, MemFlags::new()) }) .collect() } diff --git a/src/base.rs b/src/base.rs index 0e95ab5de66bf..0d3b38d52c8da 100644 --- a/src/base.rs +++ b/src/base.rs @@ -266,12 +266,12 @@ fn verify_func(tcx: TyCtxt<'_>, writer: &crate::pretty_clif::CommentWriter, func tcx.prof.generic_activity("verify clif ir").run(|| { let flags = cranelift_codegen::settings::Flags::new(cranelift_codegen::settings::builder()); - match cranelift_codegen::verify_function(&func, &flags) { + match cranelift_codegen::verify_function(func, &flags) { Ok(_) => {} Err(err) => { tcx.dcx().err(format!("{:?}", err)); let pretty_error = cranelift_codegen::print_errors::pretty_verifier_error( - &func, + func, Some(Box::new(writer)), err, ); @@ -554,7 +554,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { template, operands, *options, - targets.get(0).copied(), + targets.first().copied(), ); } TerminatorKind::UnwindTerminate(reason) => { @@ -1131,7 +1131,7 @@ fn codegen_panic_inner<'tcx>( call_conv: fx.target_config.default_call_conv, }; let func_id = fx.module.declare_function(symbol_name, Linkage::Import, &sig).unwrap(); - let func_ref = fx.module.declare_func_in_func(func_id, &mut fx.bcx.func); + let func_ref = fx.module.declare_func_in_func(func_id, fx.bcx.func); if fx.clif_comments.enabled() { fx.add_comment(func_ref, format!("{:?}", symbol_name)); } @@ -1141,7 +1141,7 @@ fn codegen_panic_inner<'tcx>( fx.add_comment(nop_inst, format!("panic {}", symbol_name)); } - codegen_call_with_unwind_action(fx, span, CallTarget::Direct(func_ref), unwind, &args, None); + codegen_call_with_unwind_action(fx, span, CallTarget::Direct(func_ref), unwind, args, None); fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap()); } diff --git a/src/codegen_f16_f128.rs b/src/codegen_f16_f128.rs index c2406197f3039..e5e5064ce1406 100644 --- a/src/codegen_f16_f128.rs +++ b/src/codegen_f16_f128.rs @@ -75,8 +75,7 @@ pub(crate) fn fcmp(fx: &mut FunctionCx<'_, '_, '_>, cc: FloatCC, lhs: Value, rhs &[lhs, rhs], )[0]; let zero = fx.bcx.ins().iconst(CMP_RESULT_TY, 0); - let res = fx.bcx.ins().icmp(int_cc, res, zero); - res + fx.bcx.ins().icmp(int_cc, res, zero) } _ => unreachable!("{ty:?}"), } diff --git a/src/common.rs b/src/common.rs index 16adc84747ff7..c7c0ffa79de77 100644 --- a/src/common.rs +++ b/src/common.rs @@ -257,7 +257,7 @@ pub(crate) fn create_wrapper_function( .map(|param| func.dfg.append_block_param(block, param.value_type)) .collect::>(); - let callee_func_ref = module.declare_func_in_func(callee_func_id, &mut bcx.func); + let callee_func_ref = module.declare_func_in_func(callee_func_id, bcx.func); let call_inst = bcx.ins().call(callee_func_ref, &args); let results = bcx.inst_results(call_inst).to_vec(); // Clone to prevent borrow error @@ -374,7 +374,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { pub(crate) fn create_stack_slot(&mut self, size: u32, align: u32) -> Pointer { assert!( - size % align == 0, + size.is_multiple_of(align), "size must be a multiple of alignment (size={size}, align={align})" ); @@ -384,7 +384,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { kind: StackSlotKind::ExplicitSlot, // FIXME Don't force the size to a multiple of bytes once Cranelift gets // a way to specify stack slot alignment. - size: (size + abi_align - 1) / abi_align * abi_align, + size: size.div_ceil(abi_align) * abi_align, align_shift: 4, }); Pointer::stack_slot(stack_slot) diff --git a/src/constant.rs b/src/constant.rs index 38b66256ea300..2b65b82906818 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -65,7 +65,7 @@ pub(crate) fn codegen_tls_ref<'tcx>( // For a declaration the stated mutability doesn't matter. false, ); - let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); + let local_data_id = fx.module.declare_data_in_func(data_id, fx.bcx.func); if fx.clif_comments.enabled() { fx.add_comment(local_data_id, format!("tls {:?}", def_id)); } @@ -111,7 +111,7 @@ pub(crate) fn codegen_const_value<'tcx>( ConstValue::Scalar(x) => match x { Scalar::Int(int) => { if fx.clif_type(layout.ty).is_some() { - return CValue::const_val(fx, layout, int); + CValue::const_val(fx, layout, int) } else { let raw_val = int.size().truncate(int.to_bits(int.size())); let val = match int.size().bytes() { @@ -150,7 +150,7 @@ pub(crate) fn codegen_const_value<'tcx>( alloc.inner().mutability, ); let local_data_id = - fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); + fx.module.declare_data_in_func(data_id, fx.bcx.func); if fx.clif_comments.enabled() { fx.add_comment(local_data_id, format!("{:?}", alloc_id)); } @@ -159,8 +159,7 @@ pub(crate) fn codegen_const_value<'tcx>( } GlobalAlloc::Function { instance, .. } => { let func_id = crate::abi::import_function(fx.tcx, fx.module, instance); - let local_func_id = - fx.module.declare_func_in_func(func_id, &mut fx.bcx.func); + let local_func_id = fx.module.declare_func_in_func(func_id, fx.bcx.func); fx.bcx.ins().func_addr(fx.pointer_type, local_func_id) } GlobalAlloc::VTable(ty, dyn_ty) => { @@ -173,8 +172,7 @@ pub(crate) fn codegen_const_value<'tcx>( fx.tcx.instantiate_bound_regions_with_erased(principal) }), ); - let local_data_id = - fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); + let local_data_id = fx.module.declare_data_in_func(data_id, fx.bcx.func); fx.bcx.ins().symbol_value(fx.pointer_type, local_data_id) } GlobalAlloc::TypeId { .. } => { @@ -191,8 +189,7 @@ pub(crate) fn codegen_const_value<'tcx>( // For a declaration the stated mutability doesn't matter. false, ); - let local_data_id = - fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); + let local_data_id = fx.module.declare_data_in_func(data_id, fx.bcx.func); if fx.clif_comments.enabled() { fx.add_comment(local_data_id, format!("{:?}", def_id)); } @@ -236,7 +233,7 @@ fn pointer_for_allocation<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, alloc_id: All let data_id = data_id_for_alloc_id(&mut fx.constants_cx, fx.module, alloc_id, alloc.inner().mutability); - let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); + let local_data_id = fx.module.declare_data_in_func(data_id, fx.bcx.func); if fx.clif_comments.enabled() { fx.add_comment(local_data_id, format!("{:?}", alloc_id)); } @@ -354,7 +351,7 @@ fn data_id_for_static( Linkage::Import }; - let data_id = match module.declare_data( + match module.declare_data( symbol_name, linkage, definition_writable, @@ -365,9 +362,7 @@ fn data_id_for_static( "attempt to declare `{symbol_name}` as static, but it was already declared as function" )), Err(err) => Err::<_, _>(err).unwrap(), - }; - - data_id + } } fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut ConstantCx) { diff --git a/src/debuginfo/emit.rs b/src/debuginfo/emit.rs index 53b513ded9c46..8016c5a3005a2 100644 --- a/src/debuginfo/emit.rs +++ b/src/debuginfo/emit.rs @@ -222,12 +222,12 @@ impl Writer for WriterRelocate { gimli::DW_EH_PE_absptr => { self.relocs.push(DebugReloc { offset: self.len() as u32, - size: size.into(), + size, name: DebugRelocName::Symbol(symbol), addend, kind: object::RelocationKind::Absolute, }); - self.write_udata(0, size.into()) + self.write_udata(0, size) } _ => Err(gimli::write::Error::UnsupportedPointerEncoding(eh_pe)), }, diff --git a/src/debuginfo/gcc_except_table.rs b/src/debuginfo/gcc_except_table.rs index b8e602c76a8c0..ff1c6aacd2f98 100644 --- a/src/debuginfo/gcc_except_table.rs +++ b/src/debuginfo/gcc_except_table.rs @@ -41,8 +41,7 @@ impl GccExceptTable { + self.call_sites.encoded_size() + self.actions.encoded_size() + type_info_padding) - % 4 - == 0 + .is_multiple_of(4) }; let mut type_info_padding = 0; @@ -69,9 +68,9 @@ impl GccExceptTable { // In this case we calculated the expected padding amount and used it to write the // classInfoOffset field. Assert that the expected value matched the actual value to catch // any inconsistency. - assert!(w.len() % 4 == 0, "type_info must be aligned to 4 bytes"); + assert!(w.len().is_multiple_of(4), "type_info must be aligned to 4 bytes"); } else { - while w.len() % 4 != 0 { + while !w.len().is_multiple_of(4) { w.write_u8(0)?; } } @@ -82,7 +81,7 @@ impl GccExceptTable { // exception specs (unused for rust) // align to 4 bytes - while w.len() % 4 != 0 { + while !w.len().is_multiple_of(4) { w.write_u8(0)?; } diff --git a/src/debuginfo/types.rs b/src/debuginfo/types.rs index 0d49f32373caa..a292429cdfad9 100644 --- a/src/debuginfo/types.rs +++ b/src/debuginfo/types.rs @@ -56,7 +56,7 @@ impl DebugContext { // ty::FnDef(..) | ty::FnPtr(..) // ty::Closure(..) // ty::Adt(def, ..) - ty::Tuple(components) => self.tuple_type(tcx, type_dbg, ty, *components), + ty::Tuple(components) => self.tuple_type(tcx, type_dbg, ty, components), // ty::Param(_) // FIXME implement remaining types and add unreachable!() to the fallback branch _ => self.placeholder_for_type(tcx, type_dbg, ty), @@ -152,7 +152,7 @@ impl DebugContext { components: &'tcx [Ty<'tcx>], ) -> UnitEntryId { let components = components - .into_iter() + .iter() .map(|&ty| (ty, self.debug_type(tcx, type_dbg, ty))) .collect::>(); diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 286ec1bea7546..760e23f2171bc 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -97,8 +97,8 @@ impl OngoingCodegen { sess, &module_regular.name, &[ - ("o", &module_regular.object.as_ref().unwrap()), - ("asm.o", &module_global_asm.object.as_ref().unwrap()), + ("o", module_regular.object.as_ref().unwrap()), + ("asm.o", module_global_asm.object.as_ref().unwrap()), ], &[], ) @@ -106,7 +106,7 @@ impl OngoingCodegen { rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir( sess, &module_regular.name, - &[("o", &module_regular.object.as_ref().unwrap())], + &[("o", module_regular.object.as_ref().unwrap())], &[], ) }; @@ -308,7 +308,7 @@ fn produce_final_output_artifacts( module.for_each_output(|path, ty| { if sess.opts.output_types.contains_key(&ty) { let descr = ty.shorthand(); - sess.dcx().emit_artifact_notification(&path, descr); + sess.dcx().emit_artifact_notification(path, descr); } }); } @@ -450,8 +450,8 @@ fn reuse_workproduct_for_cgu( tcx.sess.invocation_temp.as_deref(), ); let source_file_regular = rustc_incremental::in_incr_comp_dir_sess( - &tcx.sess, - &work_product.saved_files.get("o").expect("no saved object file in work product"), + tcx.sess, + work_product.saved_files.get("o").expect("no saved object file in work product"), ); if let Err(err) = rustc_fs_util::link_or_copy(&source_file_regular, &obj_out_regular) { @@ -466,7 +466,7 @@ fn reuse_workproduct_for_cgu( let obj_out_global_asm = crate::global_asm::add_file_stem_postfix(obj_out_regular.clone(), ".asm"); let source_file_global_asm = if let Some(asm_o) = work_product.saved_files.get("asm.o") { - let source_file_global_asm = rustc_incremental::in_incr_comp_dir_sess(&tcx.sess, asm_o); + let source_file_global_asm = rustc_incremental::in_incr_comp_dir_sess(tcx.sess, asm_o); if let Err(err) = rustc_fs_util::link_or_copy(&source_file_global_asm, &obj_out_global_asm) { return Err(format!( @@ -684,7 +684,7 @@ pub(crate) fn run_aot(tcx: TyCtxt<'_>) -> Box { // Calculate the CGU reuse let cgu_reuse = tcx.sess.time("find_cgu_reuse", || { - cgus.iter().map(|cgu| determine_cgu_reuse(tcx, &cgu)).collect::>() + cgus.iter().map(|cgu| determine_cgu_reuse(tcx, cgu)).collect::>() }); rustc_codegen_ssa::assert_module_sources::assert_module_sources(tcx, &|cgu_reuse_tracker| { @@ -698,7 +698,7 @@ pub(crate) fn run_aot(tcx: TyCtxt<'_>) -> Box { let disable_incr_cache = disable_incr_cache(); let (todo_cgus, done_cgus) = - cgus.into_iter().enumerate().partition::, _>(|&(i, _)| match cgu_reuse[i] { + cgus.iter().enumerate().partition::, _>(|&(i, _)| match cgu_reuse[i] { _ if disable_incr_cache => true, CguReuse::No => true, CguReuse::PreLto | CguReuse::PostLto => false, diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index eab1a506fd0e9..a78c6e0a4e7ac 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -3,7 +3,7 @@ macro_rules! intrinsic_args { ($fx:expr, $args:expr => ($($arg:tt),*); $intrinsic:expr) => { - #[allow(unused_parens)] + #[allow(unused_parens, clippy::unused_unit)] let ($($arg),*) = if let [$($arg),*] = $args { ($(codegen_operand($fx, &($arg).node)),*) } else { @@ -483,7 +483,7 @@ fn codegen_float_intrinsic_call<'tcx>( }; let input_tys: Vec<_> = vec![AbiParam::new(clif_ty), lib_call_arg_param(fx.tcx, types::I32, true)]; - let ret_val = fx.lib_call(name, input_tys, vec![AbiParam::new(clif_ty)], &args)[0]; + let ret_val = fx.lib_call(name, input_tys, vec![AbiParam::new(clif_ty)], args)[0]; let ret_val = if intrinsic == sym::powif16 { codegen_f16_f128::f32_to_f16(fx, ret_val) } else { @@ -505,7 +505,7 @@ fn codegen_float_intrinsic_call<'tcx>( } _ => { let input_tys: Vec<_> = args.iter().map(|_| AbiParam::new(clif_ty)).collect(); - let ret_val = fx.lib_call(name, input_tys, vec![AbiParam::new(clif_ty)], &args)[0]; + let ret_val = fx.lib_call(name, input_tys, vec![AbiParam::new(clif_ty)], args)[0]; CValue::by_val(ret_val, fx.layout_of(ty)) } }; diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 6281089ee244c..70add5b84d248 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -812,7 +812,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( Endian::Big => lane_count - 1 - lane, Endian::Little => lane, }; - let m_lane = fx.bcx.ins().ushr_imm(m, u64::from(mask_lane) as i64); + let m_lane = fx.bcx.ins().ushr_imm(m, mask_lane.cast_signed()); let m_lane = fx.bcx.ins().band_imm(m_lane, 1); let a_lane = a.value_lane(fx, lane).load_scalar(fx); let b_lane = b.value_lane(fx, lane).load_scalar(fx); diff --git a/src/lib.rs b/src/lib.rs index 1815f990fc16f..f1d5eeb76dd66 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -271,8 +271,8 @@ fn build_isa(sess: &Session, jit: bool) -> Arc { flags_builder.set("enable_verifier", enable_verifier).unwrap(); flags_builder.set("regalloc_checker", enable_verifier).unwrap(); - let mut frame_ptr = sess.target.options.frame_pointer.clone(); - frame_ptr.ratchet(sess.opts.cg.force_frame_pointers); + let frame_ptr = + { sess.target.options.frame_pointer }.ratchet(sess.opts.cg.force_frame_pointers); let preserve_frame_pointer = frame_ptr != rustc_target::spec::FramePointer::MayOmit; flags_builder .set("preserve_frame_pointers", if preserve_frame_pointer { "true" } else { "false" }) diff --git a/src/main_shim.rs b/src/main_shim.rs index bf756860b6499..c3e4bf1f0c275 100644 --- a/src/main_shim.rs +++ b/src/main_shim.rs @@ -93,7 +93,7 @@ pub(crate) fn maybe_create_entry_wrapper( let arg_argv = bcx.append_block_param(block, m.target_config().pointer_type()); let arg_sigpipe = bcx.ins().iconst(types::I8, sigpipe as i64); - let main_func_ref = m.declare_func_in_func(main_func_id, &mut bcx.func); + let main_func_ref = m.declare_func_in_func(main_func_id, bcx.func); let result = if ignore_lang_start_wrapper { // ignoring #[lang = "start"] as we are running in the jit @@ -123,7 +123,7 @@ pub(crate) fn maybe_create_entry_wrapper( let report_sig = get_function_sig(tcx, m.target_config().default_call_conv, report); let report_func_id = m.declare_function(report_name, Linkage::Import, &report_sig).unwrap(); - let report_func_ref = m.declare_func_in_func(report_func_id, &mut bcx.func); + let report_func_ref = m.declare_func_in_func(report_func_id, bcx.func); // FIXME do proper abi handling instead of expecting the pass mode to be identical // for returns and arguments. @@ -148,7 +148,7 @@ pub(crate) fn maybe_create_entry_wrapper( let main_val = bcx.ins().func_addr(m.target_config().pointer_type(), main_func_ref); - let func_ref = m.declare_func_in_func(start_func_id, &mut bcx.func); + let func_ref = m.declare_func_in_func(start_func_id, bcx.func); let call_inst = bcx.ins().call(func_ref, &[main_val, arg_argc, arg_argv, arg_sigpipe]); bcx.inst_results(call_inst)[0] diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index 3655faf598a73..2878fa7aa298a 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -312,7 +312,7 @@ impl fmt::Debug for FunctionCx<'_, '_, '_> { ::cranelift_codegen::write::decorate_function( &mut &self.clif_comments, &mut clif, - &self.bcx.func, + self.bcx.func, ) .unwrap(); writeln!(f, "\n{}", clif) diff --git a/src/unsize.rs b/src/unsize.rs index c97eb3874b02c..3dbb689cccd26 100644 --- a/src/unsize.rs +++ b/src/unsize.rs @@ -134,7 +134,7 @@ pub(crate) fn coerce_unsized_into<'tcx>( (ty::Pat(a, _), ty::Pat(b, _)) => { let src = src.cast_pat_ty_to_base(fx.layout_of(*a)); let dst = dst.place_transmute_type(fx, *b); - return coerce_unsized_into(fx, src, dst); + coerce_unsized_into(fx, src, dst) } (&ty::Ref(..), &ty::Ref(..)) | (&ty::Ref(..), &ty::RawPtr(..)) diff --git a/src/value_and_place.rs b/src/value_and_place.rs index cc8e872b9aefb..5b76a4cb97793 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -310,13 +310,13 @@ impl<'tcx> CValue<'tcx> { fx.bcx.ins().iconst(clif_ty, raw_val as i64) } ty::Float(FloatTy::F16) => { - fx.bcx.ins().f16const(Ieee16::with_bits(u16::try_from(const_val).unwrap())) + fx.bcx.ins().f16const(Ieee16::with_bits(u16::from(const_val))) } ty::Float(FloatTy::F32) => { - fx.bcx.ins().f32const(Ieee32::with_bits(u32::try_from(const_val).unwrap())) + fx.bcx.ins().f32const(Ieee32::with_bits(u32::from(const_val))) } ty::Float(FloatTy::F64) => { - fx.bcx.ins().f64const(Ieee64::with_bits(u64::try_from(const_val).unwrap())) + fx.bcx.ins().f64const(Ieee64::with_bits(u64::from(const_val))) } ty::Float(FloatTy::F128) => { let value = fx @@ -324,7 +324,7 @@ impl<'tcx> CValue<'tcx> { .func .dfg .constants - .insert(Ieee128::with_bits(u128::try_from(const_val).unwrap()).into()); + .insert(Ieee128::with_bits(u128::from(const_val)).into()); fx.bcx.ins().f128const(value) } _ => panic!( From ca44758e509949485e3048d9a9a0b53230caa618 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 28 Oct 2025 16:08:46 +0000 Subject: [PATCH 149/160] Fix a bunch of clippy lints in the build system --- build_system/bench.rs | 2 +- build_system/build_backend.rs | 2 +- build_system/build_sysroot.rs | 2 +- build_system/rustc_info.rs | 14 +++++++------- build_system/tests.rs | 2 +- build_system/utils.rs | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/build_system/bench.rs b/build_system/bench.rs index 8359b7b527903..192cb499536f1 100644 --- a/build_system/bench.rs +++ b/build_system/bench.rs @@ -144,7 +144,7 @@ fn hyperfine_command( } for &(name, cmd) in cmds { - if name != "" { + if !name.is_empty() { bench.arg("-n").arg(name); } bench.arg(cmd); diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index a1f19a1afd093..b9fa0ff2d94c3 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -16,7 +16,7 @@ pub(crate) fn build_backend( ) -> PathBuf { let _group = LogGroup::guard("Build backend"); - let mut cmd = CG_CLIF.build(&bootstrap_host_compiler, dirs); + let mut cmd = CG_CLIF.build(bootstrap_host_compiler, dirs); let mut rustflags = rustflags_from_env("RUSTFLAGS"); rustflags.push("-Zallow-features=rustc_private,f16,f128".to_owned()); diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index c0ccf506262a9..72140c651a9a4 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -49,7 +49,7 @@ pub(crate) fn build_sysroot( let mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc); let wrapper_path = dist_dir.join(&wrapper_name); build_cargo_wrapper_cmd - .arg(dirs.source_dir.join("scripts").join(&format!("{wrapper}.rs"))) + .arg(dirs.source_dir.join("scripts").join(format!("{wrapper}.rs"))) .arg("-o") .arg(&wrapper_path) .arg("-Cstrip=debuginfo"); diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index 61d56795efa3a..2fa827498de93 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -4,7 +4,7 @@ use std::process::{Command, Stdio}; pub(crate) fn get_host_triple(rustc: &Path) -> String { let version_info = Command::new(rustc) .stderr(Stdio::inherit()) - .args(&["--print", "host-tuple"]) + .args(["--print", "host-tuple"]) .output() .unwrap() .stdout; @@ -14,7 +14,7 @@ pub(crate) fn get_host_triple(rustc: &Path) -> String { pub(crate) fn get_toolchain_name() -> String { let active_toolchain = Command::new("rustup") .stderr(Stdio::inherit()) - .args(&["show", "active-toolchain"]) + .args(["show", "active-toolchain"]) .output() .unwrap() .stdout; @@ -27,7 +27,7 @@ pub(crate) fn get_cargo_path() -> PathBuf { } let cargo_path = Command::new("rustup") .stderr(Stdio::inherit()) - .args(&["which", "cargo"]) + .args(["which", "cargo"]) .output() .unwrap() .stdout; @@ -40,7 +40,7 @@ pub(crate) fn get_rustc_path() -> PathBuf { } let rustc_path = Command::new("rustup") .stderr(Stdio::inherit()) - .args(&["which", "rustc"]) + .args(["which", "rustc"]) .output() .unwrap() .stdout; @@ -53,7 +53,7 @@ pub(crate) fn get_rustdoc_path() -> PathBuf { } let rustc_path = Command::new("rustup") .stderr(Stdio::inherit()) - .args(&["which", "rustdoc"]) + .args(["which", "rustdoc"]) .output() .unwrap() .stdout; @@ -63,7 +63,7 @@ pub(crate) fn get_rustdoc_path() -> PathBuf { pub(crate) fn get_default_sysroot(rustc: &Path) -> PathBuf { let default_sysroot = Command::new(rustc) .stderr(Stdio::inherit()) - .args(&["--print", "sysroot"]) + .args(["--print", "sysroot"]) .output() .unwrap() .stdout; @@ -74,7 +74,7 @@ pub(crate) fn get_default_sysroot(rustc: &Path) -> PathBuf { pub(crate) fn get_file_name(rustc: &Path, crate_name: &str, crate_type: &str) -> String { let file_name = Command::new(rustc) .stderr(Stdio::inherit()) - .args(&[ + .args([ "--crate-name", crate_name, "--crate-type", diff --git a/build_system/tests.rs b/build_system/tests.rs index 6dd9ebb845875..dd8cf929bc2f0 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -355,7 +355,7 @@ impl<'a> TestRunner<'a> { let _guard = if !config::get_bool(config) || (is_jit_test && !self.jit_supported) - || self.skip_tests.contains(&config) + || self.skip_tests.contains(config) { eprintln!("[{tag}] {testname} (skipped)"); continue; diff --git a/build_system/utils.rs b/build_system/utils.rs index d9807155a3d5d..3266aa0ce8b64 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -162,7 +162,7 @@ impl CargoProject { pub(crate) fn try_hard_link(src: impl AsRef, dst: impl AsRef) { let src = src.as_ref(); let dst = dst.as_ref(); - if let Err(_) = fs::hard_link(src, dst) { + if fs::hard_link(src, dst).is_err() { fs::copy(src, dst).unwrap(); // Fallback to copying if hardlinking failed } } @@ -179,7 +179,7 @@ pub(crate) fn spawn_and_wait(mut cmd: Command) { /// Create the specified directory if it doesn't exist yet and delete all contents. pub(crate) fn ensure_empty_dir(path: &Path) { fs::create_dir_all(path).unwrap(); - let read_dir = match fs::read_dir(&path) { + let read_dir = match fs::read_dir(path) { Ok(read_dir) => read_dir, Err(err) if err.kind() == io::ErrorKind::NotFound => { return; From d28c5a51c4350514242291d8a09413c585596481 Mon Sep 17 00:00:00 2001 From: sayantn Date: Fri, 10 Oct 2025 20:49:13 +0530 Subject: [PATCH 150/160] Implement the alignment parameter in cg_clif --- src/intrinsics/simd.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 6281089ee244c..ca41381f0abc7 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -2,6 +2,7 @@ use cranelift_codegen::ir::immediates::Offset32; use rustc_abi::Endian; +use rustc_middle::ty::SimdAlign; use super::*; use crate::prelude::*; @@ -960,6 +961,15 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( let lane_clif_ty = fx.clif_type(val_lane_ty).unwrap(); let ptr_val = ptr.load_scalar(fx); + let alignment = generic_args[3].expect_const().to_value().valtree.unwrap_branch()[0] + .unwrap_leaf() + .to_simd_alignment(); + + let memflags = match alignment { + SimdAlign::Unaligned => MemFlags::new().with_notrap(), + _ => MemFlags::trusted(), + }; + for lane_idx in 0..val_lane_count { let val_lane = val.value_lane(fx, lane_idx).load_scalar(fx); let mask_lane = mask.value_lane(fx, lane_idx).load_scalar(fx); @@ -972,7 +982,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( fx.bcx.switch_to_block(if_enabled); let offset = lane_idx as i32 * lane_clif_ty.bytes() as i32; - fx.bcx.ins().store(MemFlags::trusted(), val_lane, ptr_val, Offset32::new(offset)); + fx.bcx.ins().store(memflags, val_lane, ptr_val, Offset32::new(offset)); fx.bcx.ins().jump(next, &[]); fx.bcx.seal_block(next); @@ -996,6 +1006,15 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( let lane_clif_ty = fx.clif_type(val_lane_ty).unwrap(); let ret_lane_layout = fx.layout_of(ret_lane_ty); + let alignment = generic_args[3].expect_const().to_value().valtree.unwrap_branch()[0] + .unwrap_leaf() + .to_simd_alignment(); + + let memflags = match alignment { + SimdAlign::Unaligned => MemFlags::new().with_notrap(), + _ => MemFlags::trusted(), + }; + for lane_idx in 0..ptr_lane_count { let val_lane = val.value_lane(fx, lane_idx).load_scalar(fx); let ptr_lane = ptr.value_lane(fx, lane_idx).load_scalar(fx); @@ -1011,7 +1030,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( fx.bcx.seal_block(if_disabled); fx.bcx.switch_to_block(if_enabled); - let res = fx.bcx.ins().load(lane_clif_ty, MemFlags::trusted(), ptr_lane, 0); + let res = fx.bcx.ins().load(lane_clif_ty, memflags, ptr_lane, 0); fx.bcx.ins().jump(next, &[res.into()]); fx.bcx.switch_to_block(if_disabled); From b49a1f7aad244d1cd901060808488e825b159811 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 13 Oct 2025 12:41:24 -0400 Subject: [PATCH 151/160] rustc_target: introduce Arch Improve type safety by using an enum rather than strings. --- src/abi/mod.rs | 17 +++++++++-------- src/codegen_f16_f128.rs | 10 +++++++--- src/common.rs | 4 ++-- src/lib.rs | 23 ++++++++++++----------- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 9a9a1f4a2c0f8..6ea26b02c2619 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -20,6 +20,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_session::Session; use rustc_span::source_map::Spanned; use rustc_target::callconv::{FnAbi, PassMode}; +use rustc_target::spec::Arch; use smallvec::SmallVec; use self::pass_mode::*; @@ -155,7 +156,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { let ret = self.lib_call_unadjusted(name, params, returns, &args)[0]; Cow::Owned(vec![codegen_bitcast(self, types::I128, ret)]) - } else if ret_single_i128 && self.tcx.sess.target.arch == "s390x" { + } else if ret_single_i128 && self.tcx.sess.target.arch == Arch::S390x { // Return i128 using a return area pointer on s390x. let mut params = params; let mut args = args.to_vec(); @@ -641,7 +642,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( .flat_map(|arg_abi| arg_abi.get_abi_param(fx.tcx).into_iter()), ); - if fx.tcx.sess.target.is_like_darwin && fx.tcx.sess.target.arch == "aarch64" { + if fx.tcx.sess.target.is_like_darwin && fx.tcx.sess.target.arch == Arch::AArch64 { // Add any padding arguments needed for Apple AArch64. // There's no need to pad the argument list unless variadic arguments are actually being // passed. @@ -787,25 +788,25 @@ pub(crate) fn codegen_drop<'tcx>( pub(crate) fn lib_call_arg_param(tcx: TyCtxt<'_>, ty: Type, is_signed: bool) -> AbiParam { let param = AbiParam::new(ty); if ty.is_int() && u64::from(ty.bits()) < tcx.data_layout.pointer_size().bits() { - match (&*tcx.sess.target.arch, &*tcx.sess.target.vendor) { - ("x86_64", _) | ("aarch64", "apple") => match (ty, is_signed) { + match (tcx.sess.target.arch, tcx.sess.target.vendor.as_ref()) { + (Arch::X86_64, _) | (Arch::AArch64, "apple") => match (ty, is_signed) { (types::I8 | types::I16, true) => param.sext(), (types::I8 | types::I16, false) => param.uext(), _ => param, }, - ("aarch64", _) => param, - ("riscv64", _) => match (ty, is_signed) { + (Arch::AArch64, _) => param, + (Arch::RiscV64, _) => match (ty, is_signed) { (types::I32, _) | (_, true) => param.sext(), _ => param.uext(), }, - ("s390x", _) => { + (Arch::S390x, _) => { if is_signed { param.sext() } else { param.uext() } } - _ => unimplemented!("{:?}", tcx.sess.target.arch), + (arch, _) => unimplemented!("{arch:?}"), } } else { param diff --git a/src/codegen_f16_f128.rs b/src/codegen_f16_f128.rs index 1e202be1f1855..c0f6d9d853db2 100644 --- a/src/codegen_f16_f128.rs +++ b/src/codegen_f16_f128.rs @@ -1,8 +1,10 @@ +use rustc_target::spec::Arch; + use crate::prelude::*; pub(crate) fn f16_to_f32(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value { let (value, arg_ty) = - if fx.tcx.sess.target.vendor == "apple" && fx.tcx.sess.target.arch == "x86_64" { + if fx.tcx.sess.target.vendor == "apple" && fx.tcx.sess.target.arch == Arch::X86_64 { ( fx.bcx.ins().bitcast(types::I16, MemFlags::new(), value), lib_call_arg_param(fx.tcx, types::I16, false), @@ -19,7 +21,8 @@ fn f16_to_f64(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value { } pub(crate) fn f32_to_f16(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value { - let ret_ty = if fx.tcx.sess.target.vendor == "apple" && fx.tcx.sess.target.arch == "x86_64" { + let ret_ty = if fx.tcx.sess.target.vendor == "apple" && fx.tcx.sess.target.arch == Arch::X86_64 + { types::I16 } else { types::F16 @@ -34,7 +37,8 @@ pub(crate) fn f32_to_f16(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value } fn f64_to_f16(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value { - let ret_ty = if fx.tcx.sess.target.vendor == "apple" && fx.tcx.sess.target.arch == "x86_64" { + let ret_ty = if fx.tcx.sess.target.vendor == "apple" && fx.tcx.sess.target.arch == Arch::X86_64 + { types::I16 } else { types::F16 diff --git a/src/common.rs b/src/common.rs index 81b1814605a12..de3d2f31af103 100644 --- a/src/common.rs +++ b/src/common.rs @@ -8,7 +8,7 @@ use rustc_middle::ty::layout::{ }; use rustc_span::source_map::Spanned; use rustc_target::callconv::FnAbi; -use rustc_target::spec::{HasTargetSpec, Target}; +use rustc_target::spec::{Arch, HasTargetSpec, Target}; use crate::constant::ConstantCx; use crate::debuginfo::FunctionDebugContext; @@ -373,7 +373,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { "size must be a multiple of alignment (size={size}, align={align})" ); - let abi_align = if self.tcx.sess.target.arch == "s390x" { 8 } else { 16 }; + let abi_align = if self.tcx.sess.target.arch == Arch::S390x { 8 } else { 16 }; if align <= abi_align { let stack_slot = self.bcx.create_sized_stack_slot(StackSlotData { kind: StackSlotKind::ExplicitSlot, diff --git a/src/lib.rs b/src/lib.rs index 5d48d0c94c581..5c23cd02e0d3a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,6 +50,7 @@ use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_session::Session; use rustc_session::config::OutputFilenames; use rustc_span::{Symbol, sym}; +use rustc_target::spec::Arch; pub use crate::config::*; use crate::prelude::*; @@ -186,20 +187,20 @@ impl CodegenBackend for CraneliftCodegenBackend { fn target_config(&self, sess: &Session) -> TargetConfig { // FIXME return the actually used target features. this is necessary for #[cfg(target_feature)] - let target_features = if sess.target.arch == "x86_64" && sess.target.os != "none" { - // x86_64 mandates SSE2 support and rustc requires the x87 feature to be enabled - vec![sym::fxsr, sym::sse, sym::sse2, Symbol::intern("x87")] - } else if sess.target.arch == "aarch64" { - match &*sess.target.os { + let target_features = match sess.target.arch { + Arch::X86_64 if sess.target.os != "none" => { + // x86_64 mandates SSE2 support and rustc requires the x87 feature to be enabled + vec![sym::fxsr, sym::sse, sym::sse2, Symbol::intern("x87")] + } + Arch::AArch64 => match &*sess.target.os { "none" => vec![], // On macOS the aes, sha2 and sha3 features are enabled by default and ring // fails to compile on macOS when they are not present. "macos" => vec![sym::neon, sym::aes, sym::sha2, sym::sha3], // AArch64 mandates Neon support _ => vec![sym::neon], - } - } else { - vec![] + }, + _ => vec![], }; // FIXME do `unstable_target_features` properly let unstable_target_features = target_features.clone(); @@ -208,14 +209,14 @@ impl CodegenBackend for CraneliftCodegenBackend { // Windows, whereas LLVM 21+ and Cranelift pass it indirectly. This means that `f128` won't // work when linking against a LLVM-built sysroot. let has_reliable_f128 = !sess.target.is_like_windows; - let has_reliable_f16 = match &*sess.target.arch { + let has_reliable_f16 = match sess.target.arch { // FIXME(f16_f128): LLVM 20 does not support `f16` on s390x, meaning the required // builtins are not available in `compiler-builtins`. - "s390x" => false, + Arch::S390x => false, // FIXME(f16_f128): `rustc_codegen_llvm` currently disables support on Windows GNU // targets due to GCC using a different ABI than LLVM. Therefore `f16` won't be // available when using a LLVM-built sysroot. - "x86_64" + Arch::X86_64 if sess.target.os == "windows" && sess.target.env == "gnu" && sess.target.abi != "llvm" => From f47ad448861edb5f1c9f3bb3cb0228b3c7cd27bd Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 28 Oct 2025 19:48:56 -0400 Subject: [PATCH 152/160] rustc_target: allow unenumerated architectures --- src/abi/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 6ea26b02c2619..d7f17795815de 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -788,7 +788,7 @@ pub(crate) fn codegen_drop<'tcx>( pub(crate) fn lib_call_arg_param(tcx: TyCtxt<'_>, ty: Type, is_signed: bool) -> AbiParam { let param = AbiParam::new(ty); if ty.is_int() && u64::from(ty.bits()) < tcx.data_layout.pointer_size().bits() { - match (tcx.sess.target.arch, tcx.sess.target.vendor.as_ref()) { + match (&tcx.sess.target.arch, tcx.sess.target.vendor.as_ref()) { (Arch::X86_64, _) | (Arch::AArch64, "apple") => match (ty, is_signed) { (types::I8 | types::I16, true) => param.sext(), (types::I8 | types::I16, false) => param.uext(), From bb6f965464d5ff9682a1ab349cdd374b88b58763 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 5 Nov 2025 10:21:42 +0000 Subject: [PATCH 153/160] Rustup to rustc 1.93.0-nightly (f15a7f385 2025-11-04) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 0836d830186cb..0e770c49340fb 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-10-28" +channel = "nightly-2025-11-05" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 296501b2fa7429c31980947fbd4e4956ddeb60fe Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 5 Nov 2025 11:07:47 +0000 Subject: [PATCH 154/160] Fix rustc test suite --- scripts/test_rustc_tests.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index cbea3caf1211e..b5af585a732e3 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -87,8 +87,7 @@ rm -r tests/ui/instrument-coverage/ # ================== rm tests/ui/codegen/issue-28950.rs # depends on stack size optimizations rm tests/ui/codegen/init-large-type.rs # same -rm -r tests/run-make/fmt-write-bloat/ # tests an optimization -rm tests/ui/statics/const_generics.rs # same +rm tests/ui/statics/const_generics.rs # tests an optimization rm tests/ui/linking/executable-no-mangle-strip.rs # requires --gc-sections to work for statics # backend specific tests From 2073d1209d755b91873e382747ac8d9fb4038baf Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 5 Nov 2025 10:16:39 +0000 Subject: [PATCH 155/160] Unify the configuration of the compiler docs Previously it was rather inconsistent which crates got the rust logo and which didn't and setting html_root_url was forgotten in many cases. --- src/lib.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5c23cd02e0d3a..b63773053d3fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,6 @@ // tidy-alphabetical-start #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] -#![cfg_attr(doc, allow(internal_features))] -#![cfg_attr(doc, doc(rust_logo))] -#![cfg_attr(doc, feature(rustdoc_internals))] // Note: please avoid adding other feature gates where possible #![feature(rustc_private)] // Only used to define intrinsics in `compiler_builtins.rs`. From 28eb8499c3629bf2330c68f34c42f33d0c179640 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 5 Nov 2025 13:29:42 +0000 Subject: [PATCH 156/160] Allow f16 and f128 on s390x and non-mingw windows --- src/lib.rs | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f1d5eeb76dd66..ac0d50fc5b1e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -182,36 +182,23 @@ impl CodegenBackend for CraneliftCodegenBackend { // FIXME do `unstable_target_features` properly let unstable_target_features = target_features.clone(); - // FIXME(f16_f128): LLVM 20 (currently used by `rustc`) passes `f128` in XMM registers on - // Windows, whereas LLVM 21+ and Cranelift pass it indirectly. This means that `f128` won't - // work when linking against a LLVM-built sysroot. - let has_reliable_f128 = !sess.target.is_like_windows; - let has_reliable_f16 = match &*sess.target.arch { - // FIXME(f16_f128): LLVM 20 does not support `f16` on s390x, meaning the required - // builtins are not available in `compiler-builtins`. - "s390x" => false, - // FIXME(f16_f128): `rustc_codegen_llvm` currently disables support on Windows GNU - // targets due to GCC using a different ABI than LLVM. Therefore `f16` won't be - // available when using a LLVM-built sysroot. - "x86_64" - if sess.target.os == "windows" - && sess.target.env == "gnu" - && sess.target.abi != "llvm" => - { - false - } - _ => true, - }; + // FIXME(f16_f128): `rustc_codegen_llvm` currently disables support on Windows GNU + // targets due to GCC using a different ABI than LLVM. Therefore `f16` and `f128` + // won't be available when using a LLVM-built sysroot. + let has_reliable_f16_f128 = !(sess.target.arch == "x86_64" + && sess.target.os == "windows" + && sess.target.env == "gnu" + && sess.target.abi != "llvm"); TargetConfig { target_features, unstable_target_features, // `rustc_codegen_cranelift` polyfills functionality not yet // available in Cranelift. - has_reliable_f16, - has_reliable_f16_math: has_reliable_f16, - has_reliable_f128, - has_reliable_f128_math: has_reliable_f128, + has_reliable_f16: has_reliable_f16_f128, + has_reliable_f16_math: has_reliable_f16_f128, + has_reliable_f128: has_reliable_f16_f128, + has_reliable_f128_math: has_reliable_f16_f128, } } From 18882dd5478c38429ebc0e1519b6836c11a85788 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 8 Nov 2025 13:25:51 +0000 Subject: [PATCH 157/160] Rustup to rustc 1.93.0-nightly (843f8ce2e 2025-11-07) --- rust-toolchain | 2 +- src/inline_asm.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/rust-toolchain b/rust-toolchain index 0e770c49340fb..17c2cc5ac6609 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-11-05" +channel = "nightly-2025-11-08" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 5a29961f7d71f..08cabe9d695c3 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -7,6 +7,7 @@ use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_hir::LangItem; use rustc_span::sym; use rustc_target::asm::*; +use rustc_target::spec::Arch; use target_lexicon::BinaryFormat; use crate::prelude::*; @@ -51,7 +52,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>( return; } - if fx.tcx.sess.target.arch == "s390x" + if fx.tcx.sess.target.arch == Arch::S390x && template.len() == 3 && template[0] == InlineAsmTemplatePiece::String("stfle 0(".into()) && let InlineAsmTemplatePiece::Placeholder { operand_idx: 0, modifier: None, span: _ } = From a0b865dc8782500efe9623859017dd5e16f85407 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 8 Nov 2025 13:35:51 +0000 Subject: [PATCH 158/160] Fix simd_gather intrinsic --- src/intrinsics/simd.rs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 59f46cbefe2db..1504869b89e00 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -1006,15 +1006,6 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( let lane_clif_ty = fx.clif_type(val_lane_ty).unwrap(); let ret_lane_layout = fx.layout_of(ret_lane_ty); - let alignment = generic_args[3].expect_const().to_value().valtree.unwrap_branch()[0] - .unwrap_leaf() - .to_simd_alignment(); - - let memflags = match alignment { - SimdAlign::Unaligned => MemFlags::new().with_notrap(), - _ => MemFlags::trusted(), - }; - for lane_idx in 0..ptr_lane_count { let val_lane = val.value_lane(fx, lane_idx).load_scalar(fx); let ptr_lane = ptr.value_lane(fx, lane_idx).load_scalar(fx); @@ -1030,7 +1021,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( fx.bcx.seal_block(if_disabled); fx.bcx.switch_to_block(if_enabled); - let res = fx.bcx.ins().load(lane_clif_ty, memflags, ptr_lane, 0); + let res = fx.bcx.ins().load(lane_clif_ty, MemFlags::trusted(), ptr_lane, 0); fx.bcx.ins().jump(next, &[res.into()]); fx.bcx.switch_to_block(if_disabled); @@ -1059,6 +1050,15 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( let ret_lane_layout = fx.layout_of(ret_lane_ty); let ptr_val = ptr.load_scalar(fx); + let alignment = generic_args[3].expect_const().to_value().valtree.unwrap_branch()[0] + .unwrap_leaf() + .to_simd_alignment(); + + let memflags = match alignment { + SimdAlign::Unaligned => MemFlags::new().with_notrap(), + _ => MemFlags::trusted(), + }; + for lane_idx in 0..ret_lane_count { let val_lane = val.value_lane(fx, lane_idx).load_scalar(fx); let mask_lane = mask.value_lane(fx, lane_idx).load_scalar(fx); @@ -1074,12 +1074,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( fx.bcx.switch_to_block(if_enabled); let offset = lane_idx as i32 * lane_clif_ty.bytes() as i32; - let res = fx.bcx.ins().load( - lane_clif_ty, - MemFlags::trusted(), - ptr_val, - Offset32::new(offset), - ); + let res = fx.bcx.ins().load(lane_clif_ty, memflags, ptr_val, Offset32::new(offset)); fx.bcx.ins().jump(next, &[res.into()]); fx.bcx.switch_to_block(if_disabled); From b2a66027fe57cff63a76a66518f8eaffb0921561 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 8 Nov 2025 14:26:36 +0000 Subject: [PATCH 159/160] Update tidy allowed dependencies --- src/tools/tidy/src/deps.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 6a1721df1642e..c8bd215a1cb42 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -576,6 +576,7 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[ "foldhash", "gimli", "hashbrown", + "heck", "indexmap", "libc", "libloading", @@ -596,8 +597,9 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[ "syn", "target-lexicon", "unicode-ident", - "wasmtime-jit-icache-coherence", - "wasmtime-math", + "wasmtime-internal-jit-icache-coherence", + "wasmtime-internal-math", + "windows-link", "windows-sys", "windows-targets", "windows_aarch64_gnullvm", From 61c3458105ebf1cd119059aa0a97b816831841b4 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 8 Nov 2025 15:04:45 +0000 Subject: [PATCH 160/160] Add missing --check-cfg --- compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs b/compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs index 72140c651a9a4..70504ee8007d2 100644 --- a/compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs +++ b/compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs @@ -52,7 +52,8 @@ pub(crate) fn build_sysroot( .arg(dirs.source_dir.join("scripts").join(format!("{wrapper}.rs"))) .arg("-o") .arg(&wrapper_path) - .arg("-Cstrip=debuginfo"); + .arg("-Cstrip=debuginfo") + .arg("--check-cfg=cfg(support_panic_unwind)"); if panic_unwind_support { build_cargo_wrapper_cmd.arg("--cfg").arg("support_panic_unwind"); }