diff options
| author | clubby789 <jamie@hill-daniel.co.uk> | 2024-12-09 19:00:43 +0000 |
|---|---|---|
| committer | clubby789 <jamie@hill-daniel.co.uk> | 2025-01-23 17:19:53 +0000 |
| commit | cd848c9f3eebcb4a0940e1370d3e6ba9b0fe4bca (patch) | |
| tree | 624c404e33ed83c8d84234c7c5337a8f6ffa68d3 /compiler/rustc_codegen_llvm/src/attributes.rs | |
| parent | dee7d0e730a3a3ed98c89dd33c4ac16edc82de8a (diff) | |
| download | rust-cd848c9f3eebcb4a0940e1370d3e6ba9b0fe4bca.tar.gz rust-cd848c9f3eebcb4a0940e1370d3e6ba9b0fe4bca.zip | |
Implement `optimize(none)` attribute
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/attributes.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/attributes.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 95e0481b035..cb1758c467c 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -336,6 +336,9 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>( OptimizeAttr::None => { to_add.extend(default_optimisation_attrs(cx)); } + OptimizeAttr::DoNotOptimize => { + to_add.push(llvm::AttributeKind::OptimizeNone.create_attr(cx.llcx)); + } OptimizeAttr::Size => { to_add.push(llvm::AttributeKind::MinSize.create_attr(cx.llcx)); to_add.push(llvm::AttributeKind::OptimizeForSize.create_attr(cx.llcx)); @@ -343,12 +346,12 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>( OptimizeAttr::Speed => {} } - let inline = - if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) { - InlineAttr::Hint - } else { - codegen_fn_attrs.inline - }; + // `optnone` requires `noinline` + let inline = match (codegen_fn_attrs.inline, &codegen_fn_attrs.optimize) { + (_, OptimizeAttr::DoNotOptimize) => InlineAttr::Never, + (InlineAttr::None, _) if instance.def.requires_inline(cx.tcx) => InlineAttr::Hint, + (inline, _) => inline, + }; to_add.extend(inline_attr(cx, inline)); // The `uwtable` attribute according to LLVM is: |
