diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2126,12 +2126,16 @@ DebugLoc DwarfDebug::emitInitialLocDirective(const MachineFunction &MF, unsigned CUID) { + // If we have code without debug information we need to give up. + DISubprogram *MFSP = MF.getFunction().getSubprogram(); + if (!MFSP) + return DebugLoc(); + // Get beginning of function. if (DebugLoc PrologEndLoc = findPrologueEndLoc(&MF)) { // Ensure the compile unit is created if the function is called before // beginFunction(). - (void)getOrCreateDwarfCompileUnit( - MF.getFunction().getSubprogram()->getUnit()); + (void)getOrCreateDwarfCompileUnit(MFSP->getUnit()); // We'd like to list the prologue as "not statements" but GDB behaves // poorly if we do that. Revisit this with caution/GDB (7.5+) testing. const DISubprogram *SP = PrologEndLoc->getInlinedAtScope()->getSubprogram();