diff options
author | Reid Kleckner <rnk@google.com> | 2015-12-16 00:26:37 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2015-12-16 00:26:37 +0000 |
commit | 39329d57b59ae6b3e69406f037da69a2a1ba5ab6 (patch) | |
tree | ccaae6d3df69eebe320d393e302d892025a39035 /clang/lib/CodeGen | |
parent | 65c3a4b9c017f09619973b529d32fb1584525a61 (diff) | |
download | bcm5719-llvm-39329d57b59ae6b3e69406f037da69a2a1ba5ab6.tar.gz bcm5719-llvm-39329d57b59ae6b3e69406f037da69a2a1ba5ab6.zip |
Reland "[SEH] Use llvm.x86.seh.recoverfp for SEH filters on x64 as well as 32bit"
I forgot to initialize RecoverFP.
llvm-svn: 255731
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGException.cpp | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp index a064e6246a7..fce2e758196 100644 --- a/clang/lib/CodeGen/CGException.cpp +++ b/clang/lib/CodeGen/CGException.cpp @@ -1493,8 +1493,9 @@ struct CaptureFinder : ConstStmtVisitor<CaptureFinder> { }; } // end anonymous namespace -Address CodeGenFunction::recoverAddrOfEscapedLocal( - CodeGenFunction &ParentCGF, Address ParentVar, llvm::Value *ParentFP) { +Address CodeGenFunction::recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF, + Address ParentVar, + llvm::Value *ParentFP) { llvm::CallInst *RecoverCall = nullptr; CGBuilderTy Builder(*this, AllocaInsertPt); if (auto *ParentAlloca = dyn_cast<llvm::AllocaInst>(ParentVar.getPointer())) { @@ -1548,27 +1549,32 @@ void CodeGenFunction::EmitCapturedLocals(CodeGenFunction &ParentCGF, return; } - llvm::Value *EntryEBP = nullptr; - llvm::Value *ParentFP; + llvm::Value *EntryFP = nullptr; + CGBuilderTy Builder(CGM, AllocaInsertPt); if (IsFilter && CGM.getTarget().getTriple().getArch() == llvm::Triple::x86) { // 32-bit SEH filters need to be careful about FP recovery. The end of the // EH registration is passed in as the EBP physical register. We can - // recover that with llvm.frameaddress(1), and adjust that to recover the - // parent's true frame pointer. - CGBuilderTy Builder(CGM, AllocaInsertPt); - EntryEBP = Builder.CreateCall( + // recover that with llvm.frameaddress(1). + EntryFP = Builder.CreateCall( CGM.getIntrinsic(llvm::Intrinsic::frameaddress), {Builder.getInt32(1)}); - llvm::Function *RecoverFPIntrin = - CGM.getIntrinsic(llvm::Intrinsic::x86_seh_recoverfp); - llvm::Constant *ParentI8Fn = - llvm::ConstantExpr::getBitCast(ParentCGF.CurFn, Int8PtrTy); - ParentFP = Builder.CreateCall(RecoverFPIntrin, {ParentI8Fn, EntryEBP}); } else { // Otherwise, for x64 and 32-bit finally functions, the parent FP is the // second parameter. auto AI = CurFn->arg_begin(); ++AI; - ParentFP = &*AI; + EntryFP = &*AI; + } + + llvm::Value *ParentFP = EntryFP; + if (IsFilter) { + // Given whatever FP the runtime provided us in EntryFP, recover the true + // 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); + llvm::Constant *ParentI8Fn = + llvm::ConstantExpr::getBitCast(ParentCGF.CurFn, Int8PtrTy); + ParentFP = Builder.CreateCall(RecoverFPIntrin, {ParentI8Fn, EntryFP}); } // Create llvm.localrecover calls for all captures. @@ -1592,8 +1598,8 @@ void CodeGenFunction::EmitCapturedLocals(CodeGenFunction &ParentCGF, continue; Address ParentVar = I->second; - setAddrOfLocalVar(VD, - recoverAddrOfEscapedLocal(ParentCGF, ParentVar, ParentFP)); + setAddrOfLocalVar( + VD, recoverAddrOfEscapedLocal(ParentCGF, ParentVar, ParentFP)); } if (Finder.SEHCodeSlot.isValid()) { @@ -1602,7 +1608,7 @@ void CodeGenFunction::EmitCapturedLocals(CodeGenFunction &ParentCGF, } if (IsFilter) - EmitSEHExceptionCodeSave(ParentCGF, ParentFP, EntryEBP); + EmitSEHExceptionCodeSave(ParentCGF, ParentFP, EntryFP); } /// Arrange a function prototype that can be called by Windows exception @@ -1718,7 +1724,7 @@ CodeGenFunction::GenerateSEHFinallyFunction(CodeGenFunction &ParentCGF, void CodeGenFunction::EmitSEHExceptionCodeSave(CodeGenFunction &ParentCGF, llvm::Value *ParentFP, - llvm::Value *EntryEBP) { + llvm::Value *EntryFP) { // Get the pointer to the EXCEPTION_POINTERS struct. This is returned by the // __exception_info intrinsic. if (CGM.getTarget().getTriple().getArch() != llvm::Triple::x86) { @@ -1731,7 +1737,7 @@ void CodeGenFunction::EmitSEHExceptionCodeSave(CodeGenFunction &ParentCGF, // exception registration object. It contains 6 32-bit fields, and the info // pointer is stored in the second field. So, GEP 20 bytes backwards and // load the pointer. - SEHInfo = Builder.CreateConstInBoundsGEP1_32(Int8Ty, EntryEBP, -20); + SEHInfo = Builder.CreateConstInBoundsGEP1_32(Int8Ty, EntryFP, -20); SEHInfo = Builder.CreateBitCast(SEHInfo, Int8PtrTy->getPointerTo()); SEHInfo = Builder.CreateAlignedLoad(Int8PtrTy, SEHInfo, getPointerAlign()); SEHCodeSlotStack.push_back(recoverAddrOfEscapedLocal( |