Skip to content

Commit 7f0e733

Browse files
committed
rustc_trans: Update LLVMBuildLandingPad signature
The C API of this function changed so it no longer takes a personality function. A shim was introduced to call the right LLVM function (depending on which version we're compiled against) to set the personality function on the outer function. The compiler only ever sets one personality function for all generated functions, so this should be equivalent.
1 parent c55d3f1 commit 7f0e733

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

src/librustc_llvm/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,12 +1136,13 @@ extern {
11361136
Catch: BasicBlockRef,
11371137
Name: *const c_char)
11381138
-> ValueRef;
1139-
pub fn LLVMBuildLandingPad(B: BuilderRef,
1140-
Ty: TypeRef,
1141-
PersFn: ValueRef,
1142-
NumClauses: c_uint,
1143-
Name: *const c_char)
1144-
-> ValueRef;
1139+
pub fn LLVMRustBuildLandingPad(B: BuilderRef,
1140+
Ty: TypeRef,
1141+
PersFn: ValueRef,
1142+
NumClauses: c_uint,
1143+
Name: *const c_char,
1144+
F: ValueRef)
1145+
-> ValueRef;
11451146
pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
11461147
pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
11471148

src/librustc_trans/trans/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ pub fn LandingPad(cx: Block, ty: Type, pers_fn: ValueRef,
10391039
num_clauses: usize) -> ValueRef {
10401040
check_not_terminated(cx);
10411041
assert!(!cx.unreachable.get());
1042-
B(cx).landing_pad(ty, pers_fn, num_clauses)
1042+
B(cx).landing_pad(ty, pers_fn, num_clauses, cx.fcx.llfn)
10431043
}
10441044

10451045
pub fn SetCleanup(cx: Block, landing_pad: ValueRef) {

src/librustc_trans/trans/builder.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,11 +927,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
927927
}
928928
}
929929

930-
pub fn landing_pad(&self, ty: Type, pers_fn: ValueRef, num_clauses: usize) -> ValueRef {
930+
pub fn landing_pad(&self, ty: Type, pers_fn: ValueRef,
931+
num_clauses: usize,
932+
llfn: ValueRef) -> ValueRef {
931933
self.count_insn("landingpad");
932934
unsafe {
933-
llvm::LLVMBuildLandingPad(
934-
self.llbuilder, ty.to_ref(), pers_fn, num_clauses as c_uint, noname())
935+
llvm::LLVMRustBuildLandingPad(self.llbuilder, ty.to_ref(), pers_fn,
936+
num_clauses as c_uint, noname(), llfn)
935937
}
936938
}
937939

src/rustllvm/RustWrapper.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,3 +942,18 @@ extern "C" void LLVMWriteSMDiagnosticToString(LLVMSMDiagnosticRef d, RustStringR
942942
raw_rust_string_ostream os(str);
943943
unwrap(d)->print("", os);
944944
}
945+
946+
extern "C" LLVMValueRef
947+
LLVMRustBuildLandingPad(LLVMBuilderRef Builder,
948+
LLVMTypeRef Ty,
949+
LLVMValueRef PersFn,
950+
unsigned NumClauses,
951+
const char* Name,
952+
LLVMValueRef F) {
953+
#if LLVM_VERSION_MINOR >= 7
954+
unwrap<Function>(F)->setPersonalityFn(unwrap<Constant>(PersFn));
955+
return LLVMBuildLandingPad(Builder, Ty, NumClauses, Name);
956+
#else
957+
return LLVMBuildLandingPad(Builder, Ty, PersFn, NumClauses, Name);
958+
#endif
959+
}

0 commit comments

Comments
 (0)