Don't inline tainted MIR bodies

This commit is contained in:
Michael Goulet 2024-08-03 15:33:02 -04:00
parent c7b0d4e81f
commit 65b029b468
3 changed files with 42 additions and 2 deletions

View File

@ -505,6 +505,10 @@ fn check_mir_body(
) -> Result<(), &'static str> { ) -> Result<(), &'static str> {
let tcx = self.tcx; 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 { let mut threshold = if self.caller_is_inline_forwarder {
self.tcx.sess.opts.unstable_opts.inline_mir_forwarder_threshold.unwrap_or(30) self.tcx.sess.opts.unstable_opts.inline_mir_forwarder_threshold.unwrap_or(30)
} else if cross_crate_inlinable { } else if cross_crate_inlinable {

View File

@ -1,15 +1,21 @@
//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes //@ 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<T>(); pub struct WeakOnce<T>();
//~^ ERROR type parameter `T` is never used
impl<T> WeakOnce<T> { impl<T> WeakOnce<T> {
extern "rust-call" fn try_get(&self) -> Option<Arc<T>> {} extern "rust-call" fn try_get(&self) -> Option<Arc<T>> {}
//~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument
//~| ERROR mismatched types
pub fn get(&self) -> Arc<T> { pub fn get(&self) -> Arc<T> {
self.try_get() self.try_get()
.unwrap_or_else(|| panic!("Singleton {} not available", std::any::type_name::<T>())) .unwrap_or_else(|| panic!("Singleton {} not available", std::any::type_name::<T>()))
} }
} }
fn main() {}

View File

@ -0,0 +1,30 @@
error[E0392]: type parameter `T` is never used
--> $DIR/inline-tainted-body.rs:7:21
|
LL | pub struct WeakOnce<T>();
| ^ 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<Arc<T>> {}
| ^^^^^
error[E0308]: mismatched types
--> $DIR/inline-tainted-body.rs:11:45
|
LL | extern "rust-call" fn try_get(&self) -> Option<Arc<T>> {}
| ------- ^^^^^^^^^^^^^^ expected `Option<Arc<T>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Option<Arc<T>>`
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`.