[WinEH] Don't let UnwindHelp alias the return address
[oota-llvm.git] / lib / Target / X86 / X86FrameLowering.cpp
index 3c557fe8a1161b669482bc88c5af974a69e7f990..72baa078661ad2051d6cc0eda53b4f256b89810e 100644 (file)
@@ -2662,17 +2662,17 @@ void X86FrameLowering::processFunctionBeforeFrameFinalized(
   // If this function isn't doing Win64-style C++ EH, we don't need to do
   // anything.
   const Function *Fn = MF.getFunction();
-  if (!STI.is64Bit() || !Fn->hasPersonalityFn() ||
-      classifyEHPersonality(MF.getFunction()->getPersonalityFn()) !=
-          EHPersonality::MSVC_CXX)
+  if (!STI.is64Bit() || !MF.getMMI().hasEHFunclets() ||
+      classifyEHPersonality(Fn->getPersonalityFn()) != EHPersonality::MSVC_CXX)
     return;
 
   // Win64 C++ EH needs to allocate the UnwindHelp object at some fixed offset
   // relative to RSP after the prologue.  Find the offset of the last fixed
-  // object, so that we can allocate a slot immediately following it. Fixed
-  // objects have negative frame indices.
+  // object, so that we can allocate a slot immediately following it. If there
+  // were no fixed objects, use offset -SlotSize, which is immediately after the
+  // return address. Fixed objects have negative frame indices.
   MachineFrameInfo *MFI = MF.getFrameInfo();
-  int64_t MinFixedObjOffset = 0;
+  int64_t MinFixedObjOffset = -SlotSize;
   for (int I = MFI->getObjectIndexBegin(); I < 0; ++I)
     MinFixedObjOffset = std::min(MinFixedObjOffset, MFI->getObjectOffset(I));