Skip to content

Commit 57914f6

Browse files
Move eh_personality() onto CrateContext
1 parent 3198797 commit 57914f6

File tree

6 files changed

+51
-53
lines changed

6 files changed

+51
-53
lines changed

src/librustc_trans/cleanup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<'tcx> DropValue<'tcx> {
5858

5959
let mut pad_bcx = fcx.build_new_block("unwind_custom_");
6060

61-
let llpersonality = pad_bcx.fcx().eh_personality();
61+
let llpersonality = pad_bcx.ccx.eh_personality();
6262

6363
let resume_bcx = fcx.build_new_block("resume");
6464
let val = if base::wants_msvc_seh(fcx.ccx.sess()) {

src/librustc_trans/common.rs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -285,50 +285,6 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
285285
BlockAndBuilder::new(self.new_block(name), self)
286286
}
287287

288-
pub fn eh_personality(&self) -> ValueRef {
289-
// The exception handling personality function.
290-
//
291-
// If our compilation unit has the `eh_personality` lang item somewhere
292-
// within it, then we just need to translate that. Otherwise, we're
293-
// building an rlib which will depend on some upstream implementation of
294-
// this function, so we just codegen a generic reference to it. We don't
295-
// specify any of the types for the function, we just make it a symbol
296-
// that LLVM can later use.
297-
//
298-
// Note that MSVC is a little special here in that we don't use the
299-
// `eh_personality` lang item at all. Currently LLVM has support for
300-
// both Dwarf and SEH unwind mechanisms for MSVC targets and uses the
301-
// *name of the personality function* to decide what kind of unwind side
302-
// tables/landing pads to emit. It looks like Dwarf is used by default,
303-
// injecting a dependency on the `_Unwind_Resume` symbol for resuming
304-
// an "exception", but for MSVC we want to force SEH. This means that we
305-
// can't actually have the personality function be our standard
306-
// `rust_eh_personality` function, but rather we wired it up to the
307-
// CRT's custom personality function, which forces LLVM to consider
308-
// landing pads as "landing pads for SEH".
309-
let ccx = self.ccx;
310-
let tcx = ccx.tcx();
311-
match tcx.lang_items.eh_personality() {
312-
Some(def_id) if !base::wants_msvc_seh(ccx.sess()) => {
313-
Callee::def(ccx, def_id, tcx.intern_substs(&[])).reify(ccx)
314-
}
315-
_ => {
316-
if let Some(llpersonality) = ccx.eh_personality().get() {
317-
return llpersonality
318-
}
319-
let name = if base::wants_msvc_seh(ccx.sess()) {
320-
"__CxxFrameHandler3"
321-
} else {
322-
"rust_eh_personality"
323-
};
324-
let fty = Type::variadic_func(&[], &Type::i32(ccx));
325-
let f = declare::declare_cfn(ccx, name, fty);
326-
ccx.eh_personality().set(Some(f));
327-
f
328-
}
329-
}
330-
}
331-
332288
// Returns a ValueRef of the "eh_unwind_resume" lang item if one is defined,
333289
// otherwise declares it as an external function.
334290
pub fn eh_unwind_resume(&self) -> Callee<'tcx> {

src/librustc_trans/context.rs

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use rustc::hir::def::ExportMap;
1616
use rustc::hir::def_id::DefId;
1717
use rustc::traits;
1818
use debuginfo;
19+
use callee::Callee;
20+
use base;
1921
use declare;
2022
use glue::DropGlueKind;
2123
use monomorphize::Instance;
@@ -825,10 +827,6 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
825827
&self.local().dbg_cx
826828
}
827829

828-
pub fn eh_personality<'a>(&'a self) -> &'a Cell<Option<ValueRef>> {
829-
&self.local().eh_personality
830-
}
831-
832830
pub fn eh_unwind_resume<'a>(&'a self) -> &'a Cell<Option<ValueRef>> {
833831
&self.local().eh_unwind_resume
834832
}
@@ -909,6 +907,50 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
909907
base_n::push_str(idx as u64, base_n::ALPHANUMERIC_ONLY, &mut name);
910908
name
911909
}
910+
911+
pub fn eh_personality(&self) -> ValueRef {
912+
// The exception handling personality function.
913+
//
914+
// If our compilation unit has the `eh_personality` lang item somewhere
915+
// within it, then we just need to translate that. Otherwise, we're
916+
// building an rlib which will depend on some upstream implementation of
917+
// this function, so we just codegen a generic reference to it. We don't
918+
// specify any of the types for the function, we just make it a symbol
919+
// that LLVM can later use.
920+
//
921+
// Note that MSVC is a little special here in that we don't use the
922+
// `eh_personality` lang item at all. Currently LLVM has support for
923+
// both Dwarf and SEH unwind mechanisms for MSVC targets and uses the
924+
// *name of the personality function* to decide what kind of unwind side
925+
// tables/landing pads to emit. It looks like Dwarf is used by default,
926+
// injecting a dependency on the `_Unwind_Resume` symbol for resuming
927+
// an "exception", but for MSVC we want to force SEH. This means that we
928+
// can't actually have the personality function be our standard
929+
// `rust_eh_personality` function, but rather we wired it up to the
930+
// CRT's custom personality function, which forces LLVM to consider
931+
// landing pads as "landing pads for SEH".
932+
let tcx = self.tcx();
933+
match tcx.lang_items.eh_personality() {
934+
Some(def_id) if !base::wants_msvc_seh(self.sess()) => {
935+
Callee::def(self, def_id, tcx.intern_substs(&[])).reify(self)
936+
}
937+
_ => {
938+
if let Some(llpersonality) = self.local().eh_personality.get() {
939+
return llpersonality
940+
}
941+
let name = if base::wants_msvc_seh(self.sess()) {
942+
"__CxxFrameHandler3"
943+
} else {
944+
"rust_eh_personality"
945+
};
946+
let fty = Type::variadic_func(&[], &Type::i32(self));
947+
let f = declare::declare_cfn(self, name, fty);
948+
self.local().eh_personality.set(Some(f));
949+
f
950+
}
951+
}
952+
}
953+
912954
}
913955

914956
pub struct TypeOfDepthLock<'a, 'tcx: 'a>(&'a LocalCrateContext<'tcx>);

src/librustc_trans/intrinsic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ fn trans_msvc_try<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
718718
let llfn = get_rust_try_fn(bcx.fcx(), &mut |bcx| {
719719
let ccx = bcx.ccx;
720720

721-
bcx.set_personality_fn(bcx.fcx().eh_personality());
721+
bcx.set_personality_fn(bcx.ccx.eh_personality());
722722

723723
let normal = bcx.fcx().build_new_block("normal");
724724
let catchswitch = bcx.fcx().build_new_block("catchswitch");
@@ -855,7 +855,7 @@ fn trans_gnu_try<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
855855
// rust_try ignores the selector.
856856
let lpad_ty = Type::struct_(ccx, &[Type::i8p(ccx), Type::i32(ccx)],
857857
false);
858-
let vals = catch.landing_pad(lpad_ty, bcx.fcx().eh_personality(), 1, catch.fcx().llfn);
858+
let vals = catch.landing_pad(lpad_ty, bcx.ccx.eh_personality(), 1, catch.fcx().llfn);
859859
catch.add_clause(vals, C_null(Type::i8p(ccx)));
860860
let ptr = catch.extract_value(vals, 0);
861861
catch.store(ptr, catch.bitcast(local_ptr, Type::i8p(ccx).ptr_to()));

src/librustc_trans/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
848848
self.landing_pads[target_bb] = Some(bcx.llbb());
849849

850850
let ccx = bcx.ccx;
851-
let llpersonality = self.fcx.eh_personality();
851+
let llpersonality = self.ccx.eh_personality();
852852
let llretty = Type::struct_(ccx, &[Type::i8p(ccx), Type::i32(ccx)], false);
853853
let llretval = bcx.landing_pad(llretty, llpersonality, 1, self.fcx.llfn);
854854
bcx.set_cleanup(llretval);

src/librustc_trans/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ pub fn trans_mir<'a, 'tcx: 'a>(
313313
mircx.cleanup_kinds.iter_enumerated().map(|(bb, cleanup_kind)| {
314314
if let CleanupKind::Funclet = *cleanup_kind {
315315
let bcx = mircx.build_block(bb);
316-
bcx.set_personality_fn(fcx.eh_personality());
316+
bcx.set_personality_fn(mircx.ccx.eh_personality());
317317
if base::wants_msvc_seh(fcx.ccx.sess()) {
318318
return Some(Funclet::new(bcx.cleanup_pad(None, &[])));
319319
}

0 commit comments

Comments
 (0)