#[optimize(none)] implies #[inline(never)]

This commit is contained in:
clubby789 2025-01-31 16:10:21 +00:00
parent 7f36543a48
commit 2c35bd0499
2 changed files with 26 additions and 1 deletions

View file

@ -4,7 +4,7 @@ use std::iter;
use std::ops::{Range, RangeFrom};
use rustc_abi::{ExternAbi, FieldIdx};
use rustc_attr_parsing::InlineAttr;
use rustc_attr_parsing::{InlineAttr, OptimizeAttr};
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId;
use rustc_index::Idx;
@ -770,6 +770,10 @@ fn check_codegen_attributes<'tcx, I: Inliner<'tcx>>(
return Err("never inline attribute");
}
if let OptimizeAttr::DoNotOptimize = callee_attrs.optimize {
return Err("has DoNotOptimize attribute");
}
// Reachability pass defines which functions are eligible for inlining. Generally inlining
// other functions is incorrect because they could reference symbols that aren't exported.
let is_generic = callsite.callee.args.non_erasable_generics().next().is_some();

View file

@ -0,0 +1,21 @@
//! Ensure that `#[optimize(none)]` functions are never inlined
//@ compile-flags: -Copt-level=3
#![feature(optimize_attribute)]
#[optimize(none)]
pub fn foo() {
let _x = 123;
}
// CHECK-LABEL: define{{.*}}void @bar
// CHECK: start:
// CHECK: {{.*}}call {{.*}}void
// CHECK: ret void
#[no_mangle]
pub fn bar() {
foo();
}
fn main() {}