mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-23 19:59:57 +00:00
[SjLjEHPrepare] Don't grab pointers to functions in doInitialization
Certain optimization passes (like globaldce) can prune function declaration that SjLjEHPrepare assumed would exit when it'd runOnFunction. This fixes PR26669. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261303 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1501a642f5
commit
58cfec65cf
@ -55,7 +55,6 @@ class SjLjEHPrepare : public FunctionPass {
|
||||
Constant *StackAddrFn;
|
||||
Constant *StackRestoreFn;
|
||||
Constant *LSDAAddrFn;
|
||||
Value *PersonalityFn;
|
||||
Constant *CallSiteFn;
|
||||
Constant *FuncCtxFn;
|
||||
AllocaInst *FuncCtx;
|
||||
@ -103,21 +102,6 @@ bool SjLjEHPrepare::doInitialization(Module &M) {
|
||||
VoidPtrTy, // __lsda
|
||||
doubleUnderJBufTy, // __jbuf
|
||||
nullptr);
|
||||
RegisterFn = M.getOrInsertFunction(
|
||||
"_Unwind_SjLj_Register", Type::getVoidTy(M.getContext()),
|
||||
PointerType::getUnqual(FunctionContextTy), (Type *)nullptr);
|
||||
UnregisterFn = M.getOrInsertFunction(
|
||||
"_Unwind_SjLj_Unregister", Type::getVoidTy(M.getContext()),
|
||||
PointerType::getUnqual(FunctionContextTy), (Type *)nullptr);
|
||||
FrameAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::frameaddress);
|
||||
StackAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::stacksave);
|
||||
StackRestoreFn = Intrinsic::getDeclaration(&M, Intrinsic::stackrestore);
|
||||
BuiltinSetupDispatchFn =
|
||||
Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_setup_dispatch);
|
||||
LSDAAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_lsda);
|
||||
CallSiteFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_callsite);
|
||||
FuncCtxFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_functioncontext);
|
||||
PersonalityFn = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -226,8 +210,7 @@ Value *SjLjEHPrepare::setupFunctionContext(Function &F,
|
||||
|
||||
// Personality function
|
||||
IRBuilder<> Builder(EntryBB->getTerminator());
|
||||
if (!PersonalityFn)
|
||||
PersonalityFn = F.getPersonalityFn();
|
||||
Value *PersonalityFn = F.getPersonalityFn();
|
||||
Value *PersonalityFieldPtr = Builder.CreateConstGEP2_32(
|
||||
FunctionContextTy, FuncCtx, 0, 3, "pers_fn_gep");
|
||||
Builder.CreateStore(
|
||||
@ -490,6 +473,22 @@ bool SjLjEHPrepare::setupEntryBlockAndCallSites(Function &F) {
|
||||
}
|
||||
|
||||
bool SjLjEHPrepare::runOnFunction(Function &F) {
|
||||
Module &M = *F.getParent();
|
||||
RegisterFn = M.getOrInsertFunction(
|
||||
"_Unwind_SjLj_Register", Type::getVoidTy(M.getContext()),
|
||||
PointerType::getUnqual(FunctionContextTy), (Type *)nullptr);
|
||||
UnregisterFn = M.getOrInsertFunction(
|
||||
"_Unwind_SjLj_Unregister", Type::getVoidTy(M.getContext()),
|
||||
PointerType::getUnqual(FunctionContextTy), (Type *)nullptr);
|
||||
FrameAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::frameaddress);
|
||||
StackAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::stacksave);
|
||||
StackRestoreFn = Intrinsic::getDeclaration(&M, Intrinsic::stackrestore);
|
||||
BuiltinSetupDispatchFn =
|
||||
Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_setup_dispatch);
|
||||
LSDAAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_lsda);
|
||||
CallSiteFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_callsite);
|
||||
FuncCtxFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_functioncontext);
|
||||
|
||||
bool Res = setupEntryBlockAndCallSites(F);
|
||||
return Res;
|
||||
}
|
||||
|
31
test/CodeGen/ARM/pr26669.ll
Normal file
31
test/CodeGen/ARM/pr26669.ll
Normal file
@ -0,0 +1,31 @@
|
||||
; RUN: opt -S -globaldce -sjljehprepare < %s | FileCheck %s
|
||||
target datalayout = "e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
|
||||
target triple = "thumbv7--ios5.0.0"
|
||||
|
||||
define void @g() personality i32 (...)* @__gxx_personality_sj0 {
|
||||
entry:
|
||||
%exn.slot = alloca i8*
|
||||
%ehselector.slot = alloca i32
|
||||
invoke void @f()
|
||||
to label %try.cont unwind label %lpad
|
||||
|
||||
lpad: ; preds = %entry
|
||||
%0 = landingpad { i8*, i32 }
|
||||
cleanup
|
||||
br label %try.cont
|
||||
|
||||
try.cont: ; preds = %catch, %invoke.cont
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @f()
|
||||
|
||||
declare i32 @__gxx_personality_sj0(...)
|
||||
|
||||
; CHECK-LABEL: define void @g(
|
||||
; CHECK: call void @llvm.eh.sjlj.callsite(
|
||||
; CHECK: call void @_Unwind_SjLj_Register(
|
||||
; CHECK: invoke void @f(
|
||||
; CHECK: landingpad
|
||||
; CHECK-NEXT: cleanup
|
||||
; CHECK: call void @_Unwind_SjLj_Unregister(
|
Loading…
Reference in New Issue
Block a user