about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/declare.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-03-02 08:48:33 +0000
committerbors <bors@rust-lang.org>2022-03-02 08:48:33 +0000
commitc42d846add941a26bd254911e16f02c4a3f9346f (patch)
tree8d1dc6001d9de975c088cb6b7f56c1a0891848e7 /compiler/rustc_codegen_llvm/src/declare.rs
parent2a280de64fb34378174fa33b6866a7ee920ceb8d (diff)
parentdce14cfacc232e80dbed68430183085fd39dea02 (diff)
downloadrust-c42d846add941a26bd254911e16f02c4a3f9346f.tar.gz
rust-c42d846add941a26bd254911e16f02c4a3f9346f.zip
Auto merge of #94229 - erikdesjardins:rem2, r=nikic
Remove LLVM attribute removal

This was necessary before, because `declare_raw_fn` would always apply
the default optimization attributes to every declared function.
Then `attributes::from_fn_attrs` would have to remove the default
attributes in the case of, e.g. `#[optimize(speed)]` in a `-Os` build.
(see [`src/test/codegen/optimize-attr-1.rs`](https://github.com/rust-lang/rust/blob/03a8cc7df1d65554a4d40825b0490c93ac0f0236/src/test/codegen/optimize-attr-1.rs#L33))

However, every relevant callsite of `declare_raw_fn` (i.e. where we
actually generate code for the function, and not e.g. a call to an
intrinsic, where optimization attributes don't [?] matter)
calls `from_fn_attrs`, so we can remove the attribute setting
from `declare_raw_fn`, and rely on `from_fn_attrs` to apply the correct
attributes all at once.

r? `@ghost` (blocked on #94221)
`@rustbot` label S-blocked
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/declare.rs')
-rw-r--r--compiler/rustc_codegen_llvm/src/declare.rs14
1 files changed, 4 insertions, 10 deletions
diff --git a/compiler/rustc_codegen_llvm/src/declare.rs b/compiler/rustc_codegen_llvm/src/declare.rs
index 43d1a1f2389..5a5c4f7f860 100644
--- a/compiler/rustc_codegen_llvm/src/declare.rs
+++ b/compiler/rustc_codegen_llvm/src/declare.rs
@@ -41,21 +41,15 @@ fn declare_raw_fn<'ll>(
     llvm::SetFunctionCallConv(llfn, callconv);
     llvm::SetUnnamedAddress(llfn, unnamed);
 
-    let mut attrs_to_remove = SmallVec::<[_; 4]>::new();
-    let mut attrs_to_add = SmallVec::<[_; 4]>::new();
+    let mut attrs = SmallVec::<[_; 4]>::new();
 
     if cx.tcx.sess.opts.cg.no_redzone.unwrap_or(cx.tcx.sess.target.disable_redzone) {
-        attrs_to_add.push(llvm::AttributeKind::NoRedZone.create_attr(cx.llcx));
+        attrs.push(llvm::AttributeKind::NoRedZone.create_attr(cx.llcx));
     }
 
-    let (to_remove, to_add) = attributes::default_optimisation_attrs(cx);
-    attrs_to_remove.extend(to_remove);
-    attrs_to_add.extend(to_add);
+    attrs.extend(attributes::non_lazy_bind_attr(cx));
 
-    attrs_to_add.extend(attributes::non_lazy_bind_attr(cx));
-
-    attributes::remove_from_llfn(llfn, Function, &attrs_to_remove);
-    attributes::apply_to_llfn(llfn, Function, &attrs_to_add);
+    attributes::apply_to_llfn(llfn, Function, &attrs);
 
     llfn
 }