From 6fb01a7750e3edd73a7fba957e7f55f5956a760d Mon Sep 17 00:00:00 2001 From: Sanjiv Gupta Date: Sat, 14 Nov 2009 06:19:49 +0000 Subject: [PATCH] Fix debug info crashes for PIC16. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@88761 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 2 +- lib/Target/PIC16/PIC16DebugInfo.cpp | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 7c5c23b268f..6d660a60c3e 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -138,7 +138,7 @@ bool AsmPrinter::doInitialization(Module &M) { if (MMI) MMI->AnalyzeModule(M); DW = getAnalysisIfAvailable(); - if (DW) + if (DW && MAI->doesSupportDebugInformation()) DW->BeginModule(&M, MMI, O, this, MAI); return false; diff --git a/lib/Target/PIC16/PIC16DebugInfo.cpp b/lib/Target/PIC16/PIC16DebugInfo.cpp index 0ed44d21fc4..49df457af7e 100644 --- a/lib/Target/PIC16/PIC16DebugInfo.cpp +++ b/lib/Target/PIC16/PIC16DebugInfo.cpp @@ -467,12 +467,18 @@ void PIC16DbgInfo::EmitVarDebugInfo(Module &M) { void PIC16DbgInfo::SwitchToCU(MDNode *CU) { // Get the file path from CU. DICompileUnit cu(CU); - std::string DirName = cu.getDirectory(); - std::string FileName = cu.getFilename(); - std::string FilePath = DirName + "/" + FileName; + std::string FilePath = ""; + if (cu.getDirectory()) { + std::string DirName = cu.getDirectory(); + FilePath = FilePath + DirName + "/"; + } + if (cu.getFilename()) { + std::string FileName = cu.getFilename(); + FilePath = FilePath + FileName; + } - // Nothing to do if source file is still same. - if ( FilePath == CurFile ) return; + // Nothing to do if source file is still same or it is empty. + if ( FilePath == CurFile || FilePath == "") return; // Else, close the current one and start a new. if (CurFile != "") O << "\n\t.eof";