[PATCH] DebugInfo: fix crash with null streamer

Alp Toker alp at nuanti.com
Mon Jun 16 10:13:12 PDT 2014


The attached patch fixes crashes when emitting debug info with a 
MCNullStreamer.

The only test case I could come up with uses clang's EmitBackendOutput 
in -emit-codegen-only mode to reproduce the crash:

   echo 'void f() {}' | clang -cc1 - -gline-tables-only -emit-codegen-only

I'm not familiar enough with backend debug testing info to pull together 
a standalone test. Suggestions welcome!

Alp.

-- 
http://www.nuanti.com
the browser experts

-------------- next part --------------
diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 9538bee..df86812 100644
--- a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -421,7 +421,9 @@ void DwarfUnit::addSourceLine(DIE &Die, unsigned Line, StringRef File,
     return;
 
   unsigned FileID = getOrCreateSourceID(File, Directory);
-  assert(FileID && "Invalid file id");
+  // MCNullStreamer can't provide FileIDs.
+  if (!FileID)
+    return;
   addUInt(Die, dwarf::DW_AT_decl_file, None, FileID);
   addUInt(Die, dwarf::DW_AT_decl_line, None, Line);
 }


More information about the llvm-commits mailing list