Index: lib/CodeGen/AsmPrinter/DwarfDebug.h =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.h +++ lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -242,6 +242,8 @@ /// debug info. DebugLoc PrevInstLoc; MCSymbol *PrevLabel; + const MachineBasicBlock *CurBB; + bool LastWasCall; /// This location indicates end of function prologue and beginning of /// function body. Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1032,7 +1032,13 @@ const MDNode *Scope = DL.getScope(); recordSourceLine(DL.getLine(), DL.getCol(), Scope, Flags); - } else if (UnknownLocations) { + } else if (UnknownLocations || PrevLabel || LastWasCall || + CurBB != MI->getParent()) { + // We want to ensure that any instruction starting a block or + // referenced from somewhere else (eg. debug information) has + // a source location. Instead of making up a location from the + // surrounding instructions, just use a line 0 location that + // the debugger will ignore. PrevInstLoc = DL; recordSourceLine(0, 0, nullptr, 0); } @@ -1063,8 +1069,11 @@ assert(CurMI != nullptr); // Don't create a new label after DBG_VALUE instructions. // They don't generate code. - if (!CurMI->isDebugValue()) + if (!CurMI->isDebugValue()) { PrevLabel = nullptr; + CurBB = CurMI->getParent(); + LastWasCall = CurMI->isCall(); + } DenseMap::iterator I = LabelsAfterInsn.find(CurMI); @@ -1207,6 +1216,8 @@ PrevInstLoc = DebugLoc(); PrevLabel = Asm->getFunctionBegin(); + CurBB = nullptr; + LastWasCall = false; // Record beginning of function. PrologEndLoc = findPrologueEndLoc(MF);