From 599bcb5cf1ea524a6636949726f0724bb3537425 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 8 Aug 2024 01:30:39 +0000 Subject: [PATCH 1/4] run-make: enable msvc for redundant-libs --- tests/run-make/redundant-libs/foo.c | 10 ++++++++-- tests/run-make/redundant-libs/rmake.rs | 6 ------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/run-make/redundant-libs/foo.c b/tests/run-make/redundant-libs/foo.c index 339ee86c99eae..551b85d182450 100644 --- a/tests/run-make/redundant-libs/foo.c +++ b/tests/run-make/redundant-libs/foo.c @@ -1,2 +1,8 @@ -void foo1() {} -void foo2() {} +#ifdef _MSC_VER +#define DllExport __declspec(dllexport) +#else +#define DllExport +#endif + +DllExport void foo1() {} +DllExport void foo2() {} diff --git a/tests/run-make/redundant-libs/rmake.rs b/tests/run-make/redundant-libs/rmake.rs index fb1b3bca8ade3..43bb30bde702d 100644 --- a/tests/run-make/redundant-libs/rmake.rs +++ b/tests/run-make/redundant-libs/rmake.rs @@ -10,12 +10,6 @@ //@ ignore-cross-compile // Reason: the compiled binary is executed -//@ ignore-windows-msvc -// Reason: this test links libraries via link.exe, which only accepts the import library -// for the dynamic library, i.e. `foo.dll.lib`. However, build_native_dynamic_lib only -// produces `foo.dll` - the dynamic library itself. To make this test work on MSVC, one -// would need to derive the import library from the dynamic library. -// See https://stackoverflow.com/questions/9360280/ use run_make_support::{ build_native_dynamic_lib, build_native_static_lib, cwd, is_msvc, rfs, run, rustc, From 8725f7ee4c4af1c961464117aa9f643bae859924 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 8 Aug 2024 12:16:29 +0000 Subject: [PATCH 2/4] run-make: enable msvc for staticlib-dylib-linkage --- tests/run-make/staticlib-dylib-linkage/rmake.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/run-make/staticlib-dylib-linkage/rmake.rs b/tests/run-make/staticlib-dylib-linkage/rmake.rs index 415491bb8ee0a..8dd1ac0ffbdcd 100644 --- a/tests/run-make/staticlib-dylib-linkage/rmake.rs +++ b/tests/run-make/staticlib-dylib-linkage/rmake.rs @@ -8,13 +8,8 @@ // Reason: the compiled binary is executed. //@ ignore-wasm // Reason: WASM does not support dynamic libraries -//@ ignore-msvc -//FIXME(Oneirical): Getting this to work on MSVC requires passing libcmt.lib to CC, -// which is not trivial to do. -// Tracking issue: https://github.com/rust-lang/rust/issues/128602 -// Discussion: https://github.com/rust-lang/rust/pull/128407#discussion_r1702439172 -use run_make_support::{cc, regex, run, rustc}; +use run_make_support::{cc, is_msvc, regex, run, rustc, static_lib_name}; fn main() { rustc().arg("-Cprefer-dynamic").input("bar.rs").run(); @@ -29,9 +24,13 @@ fn main() { let re = regex::Regex::new(r#"note: native-static-libs:\s*(.+)"#).unwrap(); let libs = re.find(&libs).unwrap().as_str().trim(); // remove the note - let (_, library_search_paths) = libs.split_once("note: native-static-libs: ").unwrap(); + let (_, native_link_args) = libs.split_once("note: native-static-libs: ").unwrap(); // divide the command-line arguments in a vec - let library_search_paths = library_search_paths.split(' ').collect::>(); - cc().input("foo.c").arg("-lfoo").args(library_search_paths).out_exe("foo").run(); + let mut native_link_args = native_link_args.split(' ').collect::>(); + if is_msvc() { + // For MSVC pass the arguments on to the linker. + native_link_args.insert(0, "-link"); + } + cc().input("foo.c").input(static_lib_name("foo")).args(native_link_args).out_exe("foo").run(); run("foo"); } From 6d69b2e40833cb0ef6feae3047ab0ab8343b51da Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 8 Aug 2024 14:42:44 +0200 Subject: [PATCH 3/4] Update compiler-builtins version to 0.1.118 --- .../rustc_codegen_gcc/build_system/build_sysroot/Cargo.lock | 2 +- .../rustc_codegen_gcc/build_system/build_sysroot/Cargo.toml | 4 +--- library/Cargo.lock | 4 ++-- library/alloc/Cargo.toml | 2 +- library/std/Cargo.toml | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_codegen_gcc/build_system/build_sysroot/Cargo.lock b/compiler/rustc_codegen_gcc/build_system/build_sysroot/Cargo.lock index d6ec1f87d0103..771f2f18dce7b 100644 --- a/compiler/rustc_codegen_gcc/build_system/build_sysroot/Cargo.lock +++ b/compiler/rustc_codegen_gcc/build_system/build_sysroot/Cargo.lock @@ -50,7 +50,7 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.109" +version = "0.1.118" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f11973008a8cf741fe6d22f339eba21fd0ca81e2760a769ba8243ed6c21edd7e" dependencies = [ diff --git a/compiler/rustc_codegen_gcc/build_system/build_sysroot/Cargo.toml b/compiler/rustc_codegen_gcc/build_system/build_sysroot/Cargo.toml index e466992362386..05503128f2af0 100644 --- a/compiler/rustc_codegen_gcc/build_system/build_sysroot/Cargo.toml +++ b/compiler/rustc_codegen_gcc/build_system/build_sysroot/Cargo.toml @@ -6,9 +6,7 @@ resolver = "2" [dependencies] core = { path = "./sysroot_src/library/core" } -# TODO: after the sync, revert to using version 0.1. -# compiler_builtins = "0.1" -compiler_builtins = "=0.1.109" +compiler_builtins = "0.1" alloc = { path = "./sysroot_src/library/alloc" } std = { path = "./sysroot_src/library/std", features = ["panic_unwind", "backtrace"] } test = { path = "./sysroot_src/library/test" } diff --git a/library/Cargo.lock b/library/Cargo.lock index c5182516f7d14..b36399d880e5d 100644 --- a/library/Cargo.lock +++ b/library/Cargo.lock @@ -58,9 +58,9 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.117" +version = "0.1.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91dae36d82fe12621dfb5b596d7db766187747749b22e33ac068e1bfc356f4a" +checksum = "92afe7344b64cccf3662ca26d5d1c0828ab826f04206b97d856e3625e390e4b5" dependencies = [ "cc", "rustc-std-workspace-core", diff --git a/library/alloc/Cargo.toml b/library/alloc/Cargo.toml index 82d5893dc5e55..bdf16257c7cd0 100644 --- a/library/alloc/Cargo.toml +++ b/library/alloc/Cargo.toml @@ -10,7 +10,7 @@ edition = "2021" [dependencies] core = { path = "../core" } -compiler_builtins = { version = "0.1.117", features = ['rustc-dep-of-std'] } +compiler_builtins = { version = "0.1.118", features = ['rustc-dep-of-std'] } [dev-dependencies] rand = { version = "0.8.5", default-features = false, features = ["alloc"] } diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 06e818fb7c09d..2ce284c85e2d6 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -17,7 +17,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] } panic_unwind = { path = "../panic_unwind", optional = true } panic_abort = { path = "../panic_abort" } core = { path = "../core", public = true } -compiler_builtins = { version = "0.1.117" } +compiler_builtins = { version = "0.1.118" } profiler_builtins = { path = "../profiler_builtins", optional = true } unwind = { path = "../unwind" } hashbrown = { version = "0.14", default-features = false, features = [ From 65b029b4680313aee06362552e31187b00b6929b Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 3 Aug 2024 15:33:02 -0400 Subject: [PATCH 4/4] Don't inline tainted MIR bodies --- compiler/rustc_mir_transform/src/inline.rs | 4 +++ .../polymorphization/inline-tainted-body.rs} | 10 +++++-- .../inline-tainted-body.stderr | 30 +++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) rename tests/{crashes/122909.rs => ui/polymorphization/inline-tainted-body.rs} (58%) create mode 100644 tests/ui/polymorphization/inline-tainted-body.stderr diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 0f012242c3738..324ddc5e799d5 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -505,6 +505,10 @@ impl<'tcx> Inliner<'tcx> { ) -> Result<(), &'static str> { let tcx = self.tcx; + if let Some(_) = callee_body.tainted_by_errors { + return Err("Body is tainted"); + } + let mut threshold = if self.caller_is_inline_forwarder { self.tcx.sess.opts.unstable_opts.inline_mir_forwarder_threshold.unwrap_or(30) } else if cross_crate_inlinable { diff --git a/tests/crashes/122909.rs b/tests/ui/polymorphization/inline-tainted-body.rs similarity index 58% rename from tests/crashes/122909.rs rename to tests/ui/polymorphization/inline-tainted-body.rs index 9d17ed83ea99b..13aec97e22bdd 100644 --- a/tests/crashes/122909.rs +++ b/tests/ui/polymorphization/inline-tainted-body.rs @@ -1,15 +1,21 @@ //@ compile-flags: -Zvalidate-mir -Zinline-mir=yes -//@ known-bug: #122909 +#![feature(unboxed_closures)] -use std::sync::{Arc, Context, Weak}; +use std::sync::Arc; pub struct WeakOnce(); +//~^ ERROR type parameter `T` is never used + impl WeakOnce { extern "rust-call" fn try_get(&self) -> Option> {} + //~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument + //~| ERROR mismatched types pub fn get(&self) -> Arc { self.try_get() .unwrap_or_else(|| panic!("Singleton {} not available", std::any::type_name::())) } } + +fn main() {} diff --git a/tests/ui/polymorphization/inline-tainted-body.stderr b/tests/ui/polymorphization/inline-tainted-body.stderr new file mode 100644 index 0000000000000..5c3bd70adae00 --- /dev/null +++ b/tests/ui/polymorphization/inline-tainted-body.stderr @@ -0,0 +1,30 @@ +error[E0392]: type parameter `T` is never used + --> $DIR/inline-tainted-body.rs:7:21 + | +LL | pub struct WeakOnce(); + | ^ unused type parameter + | + = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead + +error: functions with the "rust-call" ABI must take a single non-self tuple argument + --> $DIR/inline-tainted-body.rs:11:35 + | +LL | extern "rust-call" fn try_get(&self) -> Option> {} + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/inline-tainted-body.rs:11:45 + | +LL | extern "rust-call" fn try_get(&self) -> Option> {} + | ------- ^^^^^^^^^^^^^^ expected `Option>`, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression + | + = note: expected enum `Option>` + found unit type `()` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0308, E0392. +For more information about an error, try `rustc --explain E0308`.