Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,18 @@ impl SingleAttributeParser for OptimizeParser {

let res = match single.meta_item_no_args().and_then(|i| i.path().word().map(|i| i.name)) {
Some(sym::size) => OptimizeAttr::Size,
Some(sym::speed) => OptimizeAttr::Speed,
Some(sym::speed) => {
if !cx.features().optimize_speed() {
feature_err(
cx.sess(),
sym::optimize_speed,
cx.attr_span,
"`#[optimize(speed)]` is currently unstable",
)
.emit();
}
OptimizeAttr::Speed
}
Some(sym::none) => OptimizeAttr::DoNotOptimize,
_ => {
cx.adcx()
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,10 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
to_add.push(llvm::AttributeKind::MinSize.create_attr(cx.llcx));
to_add.push(llvm::AttributeKind::OptimizeForSize.create_attr(cx.llcx));
}
OptimizeAttr::Speed => {}
OptimizeAttr::Speed => {
// Suppress default attrs (such as a global opt-for-size).
// We cannot actually tell LLVM to optimize *more* per-function.
}
}

if let Some(instance) = instance {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ declare_features! (
(unstable, offset_of_enum, "1.75.0", Some(120141)),
/// Allows using fields with slice type in offset_of!
(unstable, offset_of_slice, "1.81.0", Some(126151)),
/// Allows using `#[optimize(speed)]`.
(unstable, optimize_speed, "CURRENT_RUSTC_VERSION", Some(165590)),
/// Allows specifying nop padding on functions for dynamic patching.
(unstable, patchable_function_entry, "1.81.0", Some(123115)),
/// Experimental features that make `Pin` more ergonomic.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,7 @@ symbols! {
opt_out_copy,
optimize,
optimize_attribute,
optimize_speed,
optimized,
optin_builtin_traits,
option,
Expand Down
1 change: 1 addition & 0 deletions tests/codegen-llvm/optimize-attr-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//@[SPEED-OPT] compile-flags: -Copt-level=3 -Ccodegen-units=1

#![crate_type = "rlib"]
#![feature(optimize_speed)]

// CHECK-LABEL: define{{.*}}i32 @nothing
// CHECK-SAME: [[NOTHING_ATTRS:#[0-9]+]]
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/attributes/malformed-attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
//~^ ERROR malformed
#[optimize(none, speed)]
//~^ ERROR malformed
#[optimize(banana)]
//~^ ERROR malformed
#[cold = 1]
//~^ ERROR malformed
#[must_use()]
Expand Down
Loading
Loading