@@ -2218,6 +2218,7 @@ findPrologueEndLoc(const MachineFunction *MF) {
22182218 const auto &TII = *MF->getSubtarget ().getInstrInfo ();
22192219 const MachineInstr *NonTrivialInst = nullptr ;
22202220 const Function &F = MF->getFunction ();
2221+ DISubprogram *SP = const_cast <DISubprogram*>(F.getSubprogram ());
22212222
22222223 // Some instructions may be inserted into prologue after this function. Must
22232224 // keep prologue for these cases.
@@ -2305,15 +2306,36 @@ findPrologueEndLoc(const MachineFunction *MF) {
23052306 return *FoundInst;
23062307 }
23072308
2308- // We choose to ignore line-zero locations when setting the prologue as they
2309- // can't be stepped on anyway; however in very rare scenarios function calls
2310- // can have line zero, and we shouldn't step over those. In these
2311- // extraordinary conditions, just bail out and refuse to set a prologue_end.
2312- if (CurInst->isCall ())
2313- if (const DILocation *Loc = CurInst->getDebugLoc ().get ())
2314- if (Loc->getLine () == 0 )
2309+ // In very rare scenarios function calls can have line zero, and we
2310+ // shouldn't step over such a call while trying to reach prologue_end. In
2311+ // these extraordinary conditions, force an earlier setup instruction to
2312+ // have the scope line and put prologue_end there. This will be suboptimal,
2313+ // and might still be in setup code, but is less catastrophic than missing
2314+ // a call.
2315+ if (CurInst->isCall ()) {
2316+ if (const DILocation *Loc = CurInst->getDebugLoc ().get ();
2317+ Loc && Loc->getLine () == 0 ) {
2318+ // Go back one instruction.
2319+ auto RIt = std::next (CurInst->getIterator ().getReverse ());
2320+ // In the radically unlikely event that there's no prior instruction,
2321+ // meaning the first instruction in the function is a call, don't set a
2322+ // prologue_end at all.
2323+ if (RIt == CurInst->getParent ()->rend ())
23152324 return std::make_pair (nullptr , true );
23162325
2326+ // The prior instruction was either line-zero or unset, or a setup
2327+ // instruction, or otherwise uninteresting. Force it to have the
2328+ // scope line.
2329+ unsigned ScopeLine = SP->getScopeLine ();
2330+ DILocation *ScopeLineDILoc =
2331+ DILocation::get (SP->getContext (), ScopeLine, 0 , SP);
2332+ const_cast <MachineInstr*>(&*RIt)->setDebugLoc (ScopeLineDILoc);
2333+
2334+ // Consider this position to be where prologue_end is placed.
2335+ return std::make_pair (&*RIt, false );
2336+ }
2337+ }
2338+
23172339 // Try to continue searching, but use a backup-location if substantive
23182340 // computation is happening.
23192341 auto NextInst = std::next (CurInst);
0 commit comments