diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:04:05 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:04:05 +0000 |
commit | 676fbe8105eeb6ff4bb2ed261cb212fcfdbe7b63 (patch) | |
tree | 02a1ac369cb734d0abfa5000dd86e5b7797e6a74 /lib/CodeGen/CGException.cpp | |
parent | c7e70c433efc6953dc3888b9fbf9f3512d7da2b0 (diff) |
Notes
Diffstat (limited to 'lib/CodeGen/CGException.cpp')
-rw-r--r-- | lib/CodeGen/CGException.cpp | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp index a2ff102e1ab4..5756e13d2623 100644 --- a/lib/CodeGen/CGException.cpp +++ b/lib/CodeGen/CGException.cpp @@ -66,7 +66,7 @@ llvm::Constant *CodeGenModule::getTerminateFn() { name = "__std_terminate"; else name = "?terminate@@YAXXZ"; - } else if (getLangOpts().ObjC1 && + } else if (getLangOpts().ObjC && getLangOpts().ObjCRuntime.hasTerminate()) name = "objc_terminate"; else @@ -224,7 +224,7 @@ const EHPersonality &EHPersonality::get(CodeGenModule &CGM, if (FD && FD->usesSEHTry()) return getSEHPersonalityMSVC(T); - if (L.ObjC1) + if (L.ObjC) return L.CPlusPlus ? getObjCXXPersonality(Target, L) : getObjCPersonality(Target, L); return L.CPlusPlus ? getCXXPersonality(Target, L) @@ -250,7 +250,11 @@ static llvm::Constant *getPersonalityFn(CodeGenModule &CGM, static llvm::Constant *getOpaquePersonalityFn(CodeGenModule &CGM, const EHPersonality &Personality) { llvm::Constant *Fn = getPersonalityFn(CGM, Personality); - return llvm::ConstantExpr::getBitCast(Fn, CGM.Int8PtrTy); + llvm::PointerType* Int8PtrTy = llvm::PointerType::get( + llvm::Type::getInt8Ty(CGM.getLLVMContext()), + CGM.getDataLayout().getProgramAddressSpace()); + + return llvm::ConstantExpr::getBitCast(Fn, Int8PtrTy); } /// Check whether a landingpad instruction only uses C++ features. @@ -315,7 +319,7 @@ static bool PersonalityHasOnlyCXXUses(llvm::Constant *Fn) { /// when it really needs it. void CodeGenModule::SimplifyPersonality() { // If we're not in ObjC++ -fexceptions, there's nothing to do. - if (!LangOpts.CPlusPlus || !LangOpts.ObjC1 || !LangOpts.Exceptions) + if (!LangOpts.CPlusPlus || !LangOpts.ObjC || !LangOpts.Exceptions) return; // Both the problem this endeavors to fix and the way the logic @@ -1248,7 +1252,7 @@ void CodeGenFunction::ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock) { // we follow the false destination for each of the cond branches to reach // the rethrow block. llvm::BasicBlock *RethrowBlock = WasmCatchStartBlock; - while (llvm::TerminatorInst *TI = RethrowBlock->getTerminator()) { + while (llvm::Instruction *TI = RethrowBlock->getTerminator()) { auto *BI = cast<llvm::BranchInst>(TI); assert(BI->isConditional()); RethrowBlock = BI->getSuccessor(1); @@ -1623,8 +1627,16 @@ struct PerformSEHFinally final : EHScopeStack::Cleanup { // Compute the two argument values. QualType ArgTys[2] = {Context.UnsignedCharTy, Context.VoidPtrTy}; - llvm::Value *LocalAddrFn = CGM.getIntrinsic(llvm::Intrinsic::localaddress); - llvm::Value *FP = CGF.Builder.CreateCall(LocalAddrFn); + llvm::Value *FP = nullptr; + // If CFG.IsOutlinedSEHHelper is true, then we are within a finally block. + if (CGF.IsOutlinedSEHHelper) { + FP = &CGF.CurFn->arg_begin()[1]; + } else { + llvm::Value *LocalAddrFn = + CGM.getIntrinsic(llvm::Intrinsic::localaddress); + FP = CGF.Builder.CreateCall(LocalAddrFn); + } + llvm::Value *IsForEH = llvm::ConstantInt::get(CGF.ConvertType(ArgTys[0]), F.isForEHCleanup()); Args.add(RValue::get(IsForEH), ArgTys[0]); @@ -1777,7 +1789,7 @@ void CodeGenFunction::EmitCapturedLocals(CodeGenFunction &ParentCGF, // frame pointer of the parent function. We only need to do this in filters, // since finally funclets recover the parent FP for us. llvm::Function *RecoverFPIntrin = - CGM.getIntrinsic(llvm::Intrinsic::x86_seh_recoverfp); + CGM.getIntrinsic(llvm::Intrinsic::eh_recoverfp); llvm::Constant *ParentI8Fn = llvm::ConstantExpr::getBitCast(ParentCGF.CurFn, Int8PtrTy); ParentFP = Builder.CreateCall(RecoverFPIntrin, {ParentI8Fn, EntryFP}); @@ -1823,13 +1835,13 @@ void CodeGenFunction::EmitCapturedLocals(CodeGenFunction &ParentCGF, void CodeGenFunction::startOutlinedSEHHelper(CodeGenFunction &ParentCGF, bool IsFilter, const Stmt *OutlinedStmt) { - SourceLocation StartLoc = OutlinedStmt->getLocStart(); + SourceLocation StartLoc = OutlinedStmt->getBeginLoc(); // Get the mangled function name. SmallString<128> Name; { llvm::raw_svector_ostream OS(Name); - const FunctionDecl *ParentSEHFn = ParentCGF.CurSEHParent; + const NamedDecl *ParentSEHFn = ParentCGF.CurSEHParent; assert(ParentSEHFn && "No CurSEHParent!"); MangleContext &Mangler = CGM.getCXXABI().getMangleContext(); if (IsFilter) @@ -1871,10 +1883,10 @@ void CodeGenFunction::startOutlinedSEHHelper(CodeGenFunction &ParentCGF, IsOutlinedSEHHelper = true; StartFunction(GlobalDecl(), RetTy, Fn, FnInfo, Args, - OutlinedStmt->getLocStart(), OutlinedStmt->getLocStart()); + OutlinedStmt->getBeginLoc(), OutlinedStmt->getBeginLoc()); CurSEHParent = ParentCGF.CurSEHParent; - CGM.SetLLVMFunctionAttributes(nullptr, FnInfo, CurFn); + CGM.SetLLVMFunctionAttributes(GlobalDecl(), FnInfo, CurFn); EmitCapturedLocals(ParentCGF, OutlinedStmt, IsFilter); } @@ -1893,7 +1905,7 @@ CodeGenFunction::GenerateSEHFilterFunction(CodeGenFunction &ParentCGF, FilterExpr->getType()->isSignedIntegerType()); Builder.CreateStore(R, ReturnValue); - FinishFunction(FilterExpr->getLocEnd()); + FinishFunction(FilterExpr->getEndLoc()); return CurFn; } @@ -1907,7 +1919,7 @@ CodeGenFunction::GenerateSEHFinallyFunction(CodeGenFunction &ParentCGF, // Emit the original filter expression, convert to i32, and return. EmitStmt(FinallyBlock); - FinishFunction(FinallyBlock->getLocEnd()); + FinishFunction(FinallyBlock->getEndLoc()); return CurFn; } @@ -1972,6 +1984,11 @@ llvm::Value *CodeGenFunction::EmitSEHAbnormalTermination() { return Builder.CreateZExt(&*AI, Int32Ty); } +void CodeGenFunction::pushSEHCleanup(CleanupKind Kind, + llvm::Function *FinallyFunc) { + EHStack.pushCleanup<PerformSEHFinally>(Kind, FinallyFunc); +} + void CodeGenFunction::EnterSEHTryStmt(const SEHTryStmt &S) { CodeGenFunction HelperCGF(CGM, /*suppressNewContext=*/true); if (const SEHFinallyStmt *Finally = S.getFinallyHandler()) { |