use std::ffi::CString;
-use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags;
-use rustc::session::config::{OptLevel, Sanitizer};
-use rustc::session::Session;
-use rustc::ty::layout::HasTyCtxt;
-use rustc::ty::query::Providers;
-use rustc::ty::{self, Ty, TyCtxt};
use rustc_codegen_ssa::traits::*;
use rustc_data_structures::const_cstr;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::small_c_str::SmallCStr;
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
-use rustc_target::abi::call::Conv;
-use rustc_target::spec::PanicStrategy;
+use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
+use rustc_middle::ty::layout::HasTyCtxt;
+use rustc_middle::ty::query::Providers;
+use rustc_middle::ty::{self, TyCtxt};
+use rustc_session::config::{OptLevel, Sanitizer};
+use rustc_session::Session;
-use crate::abi::FnAbi;
use crate::attributes;
use crate::llvm::AttributePlace::Function;
use crate::llvm::{self, Attribute};
use crate::llvm_util;
-pub use rustc_attr::{self as attr, InlineAttr, OptimizeAttr};
+pub use rustc_attr::{InlineAttr, OptimizeAttr};
use crate::context::CodegenCx;
use crate::value::Value;
Attribute::UWTable.toggle_llfn(Function, val, emit);
}
-/// Tell LLVM whether the function can or cannot unwind.
-#[inline]
-fn unwind(val: &'ll Value, can_unwind: bool) {
- Attribute::NoUnwind.toggle_llfn(Function, val, !can_unwind);
-}
-
/// Tell LLVM if this function should be 'naked', i.e., skip the epilogue and prologue.
#[inline]
fn naked(val: &'ll Value, is_naked: bool) {
pub fn set_frame_pointer_elimination(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
if cx.sess().must_not_eliminate_frame_pointers() {
- if llvm_util::get_major_version() >= 8 {
- llvm::AddFunctionAttrStringValue(
- llfn,
- llvm::AttributePlace::Function,
- const_cstr!("frame-pointer"),
- const_cstr!("all"),
- );
- } else {
- llvm::AddFunctionAttrStringValue(
- llfn,
- llvm::AttributePlace::Function,
- const_cstr!("no-frame-pointer-elim"),
- const_cstr!("true"),
- );
- }
+ llvm::AddFunctionAttrStringValue(
+ llfn,
+ llvm::AttributePlace::Function,
+ const_cstr!("frame-pointer"),
+ const_cstr!("all"),
+ );
}
}
// sanitizer and thread sanitizer. With asan we're already protected from
// stack overflow anyway so we don't really need stack probes regardless.
match cx.sess().opts.debugging_opts.sanitizer {
- Some(Sanitizer::Address) | Some(Sanitizer::Thread) => return,
+ Some(Sanitizer::Address | Sanitizer::Thread) => return,
_ => {}
}
/// Composite function which sets LLVM attributes for function depending on its AST (`#[attribute]`)
/// attributes.
-pub fn from_fn_attrs(
- cx: &CodegenCx<'ll, 'tcx>,
- llfn: &'ll Value,
- instance: ty::Instance<'tcx>,
- fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
-) {
+pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty::Instance<'tcx>) {
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
match codegen_fn_attrs.optimize {
}
sanitize(cx, codegen_fn_attrs.flags, llfn);
- unwind(
- llfn,
- if cx.tcx.sess.panic_strategy() != PanicStrategy::Unwind {
- // In panic=abort mode we assume nothing can unwind anywhere, so
- // optimize based on this!
- false
- } else if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::UNWIND) {
- // If a specific #[unwind] attribute is present, use that.
- true
- } else if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_ALLOCATOR_NOUNWIND) {
- // Special attribute for allocator functions, which can't unwind.
- false
- } else {
- if fn_abi.conv == Conv::Rust {
- // Any Rust method (or `extern "Rust" fn` or `extern
- // "rust-call" fn`) is explicitly allowed to unwind
- // (unless it has no-unwind attribute, handled above).
- true
- } else {
- // Anything else is either:
- //
- // 1. A foreign item using a non-Rust ABI (like `extern "C" { fn foo(); }`), or
- //
- // 2. A Rust item using a non-Rust ABI (like `extern "C" fn foo() { ... }`).
- //
- // Foreign items (case 1) are assumed to not unwind; it is
- // UB otherwise. (At least for now; see also
- // rust-lang/rust#63909 and Rust RFC 2753.)
- //
- // Items defined in Rust with non-Rust ABIs (case 2) are also
- // not supposed to unwind. Whether this should be enforced
- // (versus stating it is UB) and *how* it would be enforced
- // is currently under discussion; see rust-lang/rust#58794.
- //
- // In either case, we mark item as explicitly nounwind.
- false
- }
- },
- );
-
// Always annotate functions with the target-cpu they are compiled for.
// Without this, ThinLTO won't inline Rust functions into Clang generated
// functions (because Clang annotates functions this way too).