Rollup merge of #136358 - clubby789:opt-none-noinline, r=saethlin

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

Fixes #136329
This commit is contained in:
Matthias Krüger 2025-02-02 12:31:57 +01:00 committed by GitHub
commit ce5db2f9f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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() {}