forked from OSchip/llvm-project
X86: Stop dereferencing end() in X86FrameLowering::emitEpilogue
On a Windows build of Chromium, r278532 (up to r278539) X86FrameLowering::emitEpilogue because it wasn't wary enough of the return of MachineBasicBlock::getFirstTerminator. Guard all the uses here. Note that r278532 *looks* like an NFC commit (just an API change), but it removes a couple of layers of abstraction and is probably causing optimization differences in MSVC. llvm-svn: 278572
This commit is contained in:
parent
6ee00a2602
commit
69b0650548
|
@ -1480,7 +1480,9 @@ void X86FrameLowering::emitEpilogue(MachineFunction &MF,
|
||||||
const MachineFrameInfo &MFI = MF.getFrameInfo();
|
const MachineFrameInfo &MFI = MF.getFrameInfo();
|
||||||
X86MachineFunctionInfo *X86FI = MF.getInfo<X86MachineFunctionInfo>();
|
X86MachineFunctionInfo *X86FI = MF.getInfo<X86MachineFunctionInfo>();
|
||||||
MachineBasicBlock::iterator MBBI = MBB.getFirstTerminator();
|
MachineBasicBlock::iterator MBBI = MBB.getFirstTerminator();
|
||||||
unsigned RetOpcode = MBBI->getOpcode();
|
Optional<unsigned> RetOpcode;
|
||||||
|
if (MBBI != MBB.end())
|
||||||
|
RetOpcode = MBBI->getOpcode();
|
||||||
DebugLoc DL;
|
DebugLoc DL;
|
||||||
if (MBBI != MBB.end())
|
if (MBBI != MBB.end())
|
||||||
DL = MBBI->getDebugLoc();
|
DL = MBBI->getDebugLoc();
|
||||||
|
@ -1493,7 +1495,7 @@ void X86FrameLowering::emitEpilogue(MachineFunction &MF,
|
||||||
bool IsWin64Prologue = MF.getTarget().getMCAsmInfo()->usesWindowsCFI();
|
bool IsWin64Prologue = MF.getTarget().getMCAsmInfo()->usesWindowsCFI();
|
||||||
bool NeedsWinCFI =
|
bool NeedsWinCFI =
|
||||||
IsWin64Prologue && MF.getFunction()->needsUnwindTableEntry();
|
IsWin64Prologue && MF.getFunction()->needsUnwindTableEntry();
|
||||||
bool IsFunclet = isFuncletReturnInstr(*MBBI);
|
bool IsFunclet = MBBI == MBB.end() ? false : isFuncletReturnInstr(*MBBI);
|
||||||
MachineBasicBlock *TargetMBB = nullptr;
|
MachineBasicBlock *TargetMBB = nullptr;
|
||||||
|
|
||||||
// Get the number of bytes to allocate from the FrameInfo.
|
// Get the number of bytes to allocate from the FrameInfo.
|
||||||
|
@ -1502,7 +1504,7 @@ void X86FrameLowering::emitEpilogue(MachineFunction &MF,
|
||||||
unsigned CSSize = X86FI->getCalleeSavedFrameSize();
|
unsigned CSSize = X86FI->getCalleeSavedFrameSize();
|
||||||
uint64_t NumBytes = 0;
|
uint64_t NumBytes = 0;
|
||||||
|
|
||||||
if (MBBI->getOpcode() == X86::CATCHRET) {
|
if (RetOpcode && *RetOpcode == X86::CATCHRET) {
|
||||||
// SEH shouldn't use catchret.
|
// SEH shouldn't use catchret.
|
||||||
assert(!isAsynchronousEHPersonality(
|
assert(!isAsynchronousEHPersonality(
|
||||||
classifyEHPersonality(MF.getFunction()->getPersonalityFn())) &&
|
classifyEHPersonality(MF.getFunction()->getPersonalityFn())) &&
|
||||||
|
@ -1516,7 +1518,7 @@ void X86FrameLowering::emitEpilogue(MachineFunction &MF,
|
||||||
BuildMI(MBB, MBBI, DL, TII.get(Is64Bit ? X86::POP64r : X86::POP32r),
|
BuildMI(MBB, MBBI, DL, TII.get(Is64Bit ? X86::POP64r : X86::POP32r),
|
||||||
MachineFramePtr)
|
MachineFramePtr)
|
||||||
.setMIFlag(MachineInstr::FrameDestroy);
|
.setMIFlag(MachineInstr::FrameDestroy);
|
||||||
} else if (MBBI->getOpcode() == X86::CLEANUPRET) {
|
} else if (RetOpcode && *RetOpcode == X86::CLEANUPRET) {
|
||||||
NumBytes = getWinEHFuncletFrameSize(MF);
|
NumBytes = getWinEHFuncletFrameSize(MF);
|
||||||
assert(hasFP(MF) && "EH funclets without FP not yet implemented");
|
assert(hasFP(MF) && "EH funclets without FP not yet implemented");
|
||||||
BuildMI(MBB, MBBI, DL, TII.get(Is64Bit ? X86::POP64r : X86::POP32r),
|
BuildMI(MBB, MBBI, DL, TII.get(Is64Bit ? X86::POP64r : X86::POP32r),
|
||||||
|
@ -1629,7 +1631,7 @@ void X86FrameLowering::emitEpilogue(MachineFunction &MF,
|
||||||
if (NeedsWinCFI)
|
if (NeedsWinCFI)
|
||||||
BuildMI(MBB, MBBI, DL, TII.get(X86::SEH_Epilogue));
|
BuildMI(MBB, MBBI, DL, TII.get(X86::SEH_Epilogue));
|
||||||
|
|
||||||
if (!isTailCallOpcode(RetOpcode)) {
|
if (!RetOpcode || !isTailCallOpcode(*RetOpcode)) {
|
||||||
// Add the return addr area delta back since we are not tail calling.
|
// Add the return addr area delta back since we are not tail calling.
|
||||||
int Offset = -1 * X86FI->getTCReturnAddrDelta();
|
int Offset = -1 * X86FI->getTCReturnAddrDelta();
|
||||||
assert(Offset >= 0 && "TCDelta should never be positive");
|
assert(Offset >= 0 && "TCDelta should never be positive");
|
||||||
|
|
Loading…
Reference in New Issue