Resolve breakage

This commit is contained in:
Simonas Kazlauskas 2019-01-19 00:37:52 +02:00
parent 89e34d3e32
commit ce289c6c99
7 changed files with 46 additions and 61 deletions

View file

@ -144,6 +144,28 @@ pub fn non_lazy_bind(sess: &Session, llfn: &'ll Value) {
}
}
pub(crate) fn default_optimisation_attrs(sess: &Session, llfn: &'ll Value) {
match sess.opts.optimize {
OptLevel::Size => {
llvm::Attribute::MinSize.unapply_llfn(Function, llfn);
llvm::Attribute::OptimizeForSize.apply_llfn(Function, llfn);
llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
},
OptLevel::SizeMin => {
llvm::Attribute::MinSize.apply_llfn(Function, llfn);
llvm::Attribute::OptimizeForSize.apply_llfn(Function, llfn);
llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
}
OptLevel::No => {
llvm::Attribute::MinSize.unapply_llfn(Function, llfn);
llvm::Attribute::OptimizeForSize.unapply_llfn(Function, llfn);
llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
}
_ => {}
}
}
/// Composite function which sets LLVM attributes for function depending on its AST (`#[attribute]`)
/// attributes.
pub fn from_fn_attrs(
@ -157,24 +179,7 @@ pub fn from_fn_attrs(
match codegen_fn_attrs.optimize {
OptimizeAttr::None => {
match cx.tcx.sess.opts.optimize {
OptLevel::Size => {
llvm::Attribute::MinSize.unapply_llfn(Function, llfn);
llvm::Attribute::OptimizeForSize.apply_llfn(Function, llfn);
llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
},
OptLevel::SizeMin => {
llvm::Attribute::MinSize.apply_llfn(Function, llfn);
llvm::Attribute::OptimizeForSize.apply_llfn(Function, llfn);
llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
}
OptLevel::No => {
llvm::Attribute::MinSize.unapply_llfn(Function, llfn);
llvm::Attribute::OptimizeForSize.unapply_llfn(Function, llfn);
llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
}
_ => {}
}
default_optimisation_attrs(cx.tcx.sess, llfn);
}
OptimizeAttr::Speed => {
llvm::Attribute::MinSize.unapply_llfn(Function, llfn);

View file

@ -15,7 +15,7 @@ use llvm;
use llvm::AttributePlace::Function;
use rustc::ty::{self, PolyFnSig};
use rustc::ty::layout::LayoutOf;
use rustc::session::config::{Sanitizer, OptLevel};
use rustc::session::config::Sanitizer;
use rustc_data_structures::small_c_str::SmallCStr;
use abi::{FnType, FnTypeExt};
use attributes;
@ -65,28 +65,8 @@ fn declare_raw_fn(
}
}
// FIXME(opt): this is kinda duplicated with similar code in attributes::from_fn_attrs…
match cx.tcx.sess.opts.optimize {
OptLevel::Size => {
llvm::Attribute::MinSize.unapply_llfn(Function, llfn);
llvm::Attribute::OptimizeForSize.apply_llfn(Function, llfn);
llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
},
OptLevel::SizeMin => {
llvm::Attribute::MinSize.apply_llfn(Function, llfn);
llvm::Attribute::OptimizeForSize.apply_llfn(Function, llfn);
llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
}
OptLevel::No => {
llvm::Attribute::MinSize.unapply_llfn(Function, llfn);
llvm::Attribute::OptimizeForSize.unapply_llfn(Function, llfn);
llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
}
_ => {}
}
attributes::default_optimisation_attrs(cx.tcx.sess, llfn);
attributes::non_lazy_bind(cx.sess(), llfn);
llfn
}

View file

@ -2379,7 +2379,7 @@ fn codegen_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> Codegen
if attr.path != "optimize" {
return ia;
}
let err = |sp, s| span_err!(tcx.sess.diagnostic(), sp, E0720, "{}", s);
let err = |sp, s| span_err!(tcx.sess.diagnostic(), sp, E0722, "{}", s);
match attr.meta().map(|i| i.node) {
Some(MetaItemKind::Word) => {
err(attr.span, "expected one argument");

View file

@ -4719,5 +4719,5 @@ register_diagnostics! {
E0645, // trait aliases not finished
E0698, // type inside generator must be known in this context
E0719, // duplicate values for associated type binding
E0720, // Malformed #[optimize] attribute
E0722, // Malformed #[optimize] attribute
}

View file

@ -1219,7 +1219,7 @@ pub const BUILTIN_ATTRIBUTES: &[(&str, AttributeType, AttributeTemplate, Attribu
cfg_fn!(alloc_error_handler))),
// RFC 2412
("optimize", Whitelisted, Gated(Stability::Unstable,
("optimize", Whitelisted, template!(List: "size|speed"), Gated(Stability::Unstable,
"optimize_attribute",
"#[optimize] attribute is an unstable feature",
cfg_fn!(optimize_attribute))),

View file

@ -1,12 +1,3 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type="rlib"]
#![optimize(speed)] //~ ERROR #54882
@ -19,7 +10,9 @@ fn size() {}
#[optimize(speed)] //~ ERROR #54882
fn speed() {}
#[optimize(banana)] //~ ERROR #54882
#[optimize(banana)]
//~^ ERROR #54882
//~| ERROR E0722
fn not_known() {}
}

View file

@ -1,5 +1,5 @@
error[E0658]: #[optimize] attribute is an unstable feature (see issue #54882)
--> $DIR/feature-gate-optimize_attribute.rs:16:1
--> $DIR/feature-gate-optimize_attribute.rs:7:1
|
LL | #[optimize(size)] //~ ERROR #54882
| ^^^^^^^^^^^^^^^^^
@ -7,7 +7,7 @@ LL | #[optimize(size)] //~ ERROR #54882
= help: add #![feature(optimize_attribute)] to the crate attributes to enable
error[E0658]: #[optimize] attribute is an unstable feature (see issue #54882)
--> $DIR/feature-gate-optimize_attribute.rs:19:1
--> $DIR/feature-gate-optimize_attribute.rs:10:1
|
LL | #[optimize(speed)] //~ ERROR #54882
| ^^^^^^^^^^^^^^^^^^
@ -15,15 +15,15 @@ LL | #[optimize(speed)] //~ ERROR #54882
= help: add #![feature(optimize_attribute)] to the crate attributes to enable
error[E0658]: #[optimize] attribute is an unstable feature (see issue #54882)
--> $DIR/feature-gate-optimize_attribute.rs:22:1
--> $DIR/feature-gate-optimize_attribute.rs:13:1
|
LL | #[optimize(banana)] //~ ERROR #54882
LL | #[optimize(banana)]
| ^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(optimize_attribute)] to the crate attributes to enable
error[E0658]: #[optimize] attribute is an unstable feature (see issue #54882)
--> $DIR/feature-gate-optimize_attribute.rs:13:1
--> $DIR/feature-gate-optimize_attribute.rs:4:1
|
LL | #[optimize(size)] //~ ERROR #54882
| ^^^^^^^^^^^^^^^^^
@ -31,13 +31,20 @@ LL | #[optimize(size)] //~ ERROR #54882
= help: add #![feature(optimize_attribute)] to the crate attributes to enable
error[E0658]: #[optimize] attribute is an unstable feature (see issue #54882)
--> $DIR/feature-gate-optimize_attribute.rs:11:1
--> $DIR/feature-gate-optimize_attribute.rs:2:1
|
LL | #![optimize(speed)] //~ ERROR #54882
| ^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(optimize_attribute)] to the crate attributes to enable
error: aborting due to 5 previous errors
error[E0722]: invalid argument
--> $DIR/feature-gate-optimize_attribute.rs:13:12
|
LL | #[optimize(banana)]
| ^^^^^^
For more information about this error, try `rustc --explain E0658`.
error: aborting due to 6 previous errors
Some errors occurred: E0658, E0722.
For more information about an error, try `rustc --explain E0658`.