DebugInfo: Restrict DW_AT_high_pc encoding as data4 offset to DWARF 4 as per spec
[oota-llvm.git] / lib / CodeGen / AsmPrinter / WinCodeViewLineTables.cpp
index 1cb69e97c059828ed933849bee426050fd715287..bb8b0735e5064f2687f0b86dbb57894d5afe20bf 100644 (file)
@@ -101,10 +101,19 @@ void WinCodeViewLineTables::maybeRecordLocation(DebugLoc DL,
   InstrInfo[MCL] = InstrInfoTy(Filename, DL.getLine());
 }
 
-WinCodeViewLineTables::WinCodeViewLineTables(AsmPrinter *Asm)
-    : Asm(Asm), CurFn(0) {
+WinCodeViewLineTables::WinCodeViewLineTables(AsmPrinter *AP)
+    : Asm(0), CurFn(0) {
+  MachineModuleInfo *MMI = AP->MMI;
+
+  // If module doesn't have named metadata anchors or COFF debug section
+  // is not available, skip any debug info related stuff.
+  if (!MMI->getModule()->getNamedMetadata("llvm.dbg.cu") ||
+      !AP->getObjFileLowering().getCOFFDebugSymbolsSection())
+    return;
+
   // Tell MMI that we have debug info.
-  Asm->MMI->setDebugInfoAvailability(true);
+  MMI->setDebugInfoAvailability(true);
+  Asm = AP;
 }
 
 static void EmitLabelDiff(MCStreamer &Streamer,
@@ -204,6 +213,7 @@ void WinCodeViewLineTables::endModule() {
   if (FnDebugInfo.empty())
     return;
 
+  assert(Asm != 0);
   Asm->OutStreamer.SwitchSection(
       Asm->getObjFileLowering().getCOFFDebugSymbolsSection());
   Asm->EmitInt32(COFF::DEBUG_SECTION_MAGIC);
@@ -251,7 +261,7 @@ void WinCodeViewLineTables::endModule() {
 void WinCodeViewLineTables::beginFunction(const MachineFunction *MF) {
   assert(!CurFn && "Can't process two functions at once!");
 
-  if (!Asm->MMI->hasDebugInfo())
+  if (!Asm || !Asm->MMI->hasDebugInfo())
     return;
 
   // Grab the lexical scopes for the function, if we don't have any of those
@@ -298,7 +308,7 @@ void WinCodeViewLineTables::beginFunction(const MachineFunction *MF) {
 }
 
 void WinCodeViewLineTables::endFunction(const MachineFunction *) {
-  if (!CurFn)  // We haven't created any debug info for this function.
+  if (!Asm || !CurFn)  // We haven't created any debug info for this function.
     return;
 
   if (CurFn->Instrs.empty())
@@ -313,7 +323,7 @@ void WinCodeViewLineTables::endFunction(const MachineFunction *) {
 
 void WinCodeViewLineTables::beginInstruction(const MachineInstr *MI) {
   // Ignore DBG_VALUE locations and function prologue.
-  if (MI->isDebugValue() || MI->getFlag(MachineInstr::FrameSetup))
+  if (!Asm || MI->isDebugValue() || MI->getFlag(MachineInstr::FrameSetup))
     return;
   DebugLoc DL = MI->getDebugLoc();
   if (DL == PrevInstLoc || DL.isUnknown())