Skip to content

Commit 036626f

Browse files
committed
Address review feedback
1 parent 097e9e5 commit 036626f

File tree

4 files changed

+11
-18
lines changed

4 files changed

+11
-18
lines changed

src/librustc_codegen_llvm/abi.rs

+7
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,11 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
396396
llvm::Attribute::NoReturn.apply_llfn(llvm::AttributePlace::Function, llfn);
397397
}
398398

399+
// FIXME(eddyb, wesleywiser): apply this to callsites as well?
400+
if !self.can_unwind {
401+
llvm::Attribute::NoUnwind.apply_llfn(llvm::AttributePlace::Function, llfn);
402+
}
403+
399404
let mut i = 0;
400405
let mut apply = |attrs: &ArgAttributes, ty: Option<&Type>| {
401406
attrs.apply_llfn(llvm::AttributePlace::Argument(i), llfn, ty);
@@ -431,6 +436,8 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
431436
}
432437

433438
fn apply_attrs_callsite(&self, bx: &mut Builder<'a, 'll, 'tcx>, callsite: &'ll Value) {
439+
// FIXME(wesleywiser, eddyb): We should apply `nounwind` and `noreturn` as appropriate to this callsite.
440+
434441
let mut i = 0;
435442
let mut apply = |attrs: &ArgAttributes, ty: Option<&Type>| {
436443
attrs.apply_callsite(llvm::AttributePlace::Argument(i), callsite, ty);

src/librustc_codegen_llvm/attributes.rs

+2-16
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE};
1010
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1111
use rustc_middle::ty::layout::HasTyCtxt;
1212
use rustc_middle::ty::query::Providers;
13-
use rustc_middle::ty::{self, Ty, TyCtxt};
13+
use rustc_middle::ty::{self, TyCtxt};
1414
use rustc_session::config::{OptLevel, Sanitizer};
1515
use rustc_session::Session;
1616

17-
use crate::abi::FnAbi;
1817
use crate::attributes;
1918
use crate::llvm::AttributePlace::Function;
2019
use crate::llvm::{self, Attribute};
@@ -75,12 +74,6 @@ pub fn emit_uwtable(val: &'ll Value, emit: bool) {
7574
Attribute::UWTable.toggle_llfn(Function, val, emit);
7675
}
7776

78-
/// Tell LLVM whether the function can or cannot unwind.
79-
#[inline]
80-
fn unwind(val: &'ll Value, can_unwind: bool) {
81-
Attribute::NoUnwind.toggle_llfn(Function, val, !can_unwind);
82-
}
83-
8477
/// Tell LLVM if this function should be 'naked', i.e., skip the epilogue and prologue.
8578
#[inline]
8679
fn naked(val: &'ll Value, is_naked: bool) {
@@ -244,12 +237,7 @@ pub(crate) fn default_optimisation_attrs(sess: &Session, llfn: &'ll Value) {
244237

245238
/// Composite function which sets LLVM attributes for function depending on its AST (`#[attribute]`)
246239
/// attributes.
247-
pub fn from_fn_attrs(
248-
cx: &CodegenCx<'ll, 'tcx>,
249-
llfn: &'ll Value,
250-
instance: ty::Instance<'tcx>,
251-
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
252-
) {
240+
pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty::Instance<'tcx>) {
253241
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
254242

255243
match codegen_fn_attrs.optimize {
@@ -313,8 +301,6 @@ pub fn from_fn_attrs(
313301
}
314302
sanitize(cx, codegen_fn_attrs.flags, llfn);
315303

316-
unwind(llfn, fn_abi.can_unwind);
317-
318304
// Always annotate functions with the target-cpu they are compiled for.
319305
// Without this, ThinLTO won't inline Rust functions into Clang generated
320306
// functions (because Clang annotates functions this way too).

src/librustc_codegen_llvm/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn get_fn(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value
7878
let llfn = cx.declare_fn(&sym, &fn_abi);
7979
debug!("get_fn: not casting pointer!");
8080

81-
attributes::from_fn_attrs(cx, llfn, instance, &fn_abi);
81+
attributes::from_fn_attrs(cx, llfn, instance);
8282

8383
let instance_def_id = instance.def_id();
8484

src/librustc_codegen_llvm/mono_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl PreDefineMethods<'tcx> for CodegenCx<'ll, 'tcx> {
7777

7878
debug!("predefine_fn: instance = {:?}", instance);
7979

80-
attributes::from_fn_attrs(self, lldecl, instance, &fn_abi);
80+
attributes::from_fn_attrs(self, lldecl, instance);
8181

8282
self.instances.borrow_mut().insert(instance, lldecl);
8383
}

0 commit comments

Comments
 (0)