Reland 196270 "Generalize debug info / EH emission in AsmPrinter"
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DwarfDebug.cpp
index 04bdfe7ae8dfd7037d148156510a52b8d435d5b2..010dcdf05556a9a687d99055dafefd2f8cfc86a9 100644 (file)
@@ -1146,6 +1146,7 @@ void DwarfDebug::endSections() {
 // Emit all Dwarf sections that should come after the content.
 void DwarfDebug::endModule() {
   assert(CurFn == 0);
+  assert(CurMI == 0);
 
   if (!FirstCU)
     return;
@@ -1796,7 +1797,14 @@ void DwarfDebug::addScopeVariable(LexicalScope *LS, DbgVariable *Var) {
 }
 
 // Gather and emit post-function debug information.
-void DwarfDebug::endFunction() {
+void DwarfDebug::endFunction(const MachineFunction *MF) {
+  // Every beginFunction(MF) call should be followed by an endFunction(MF) call,
+  // though the beginFunction may not be called at all.
+  // We should handle both cases.
+  if (CurFn == 0)
+    CurFn = MF;
+  else
+    assert(CurFn == MF);
   assert(CurFn != 0);
 
   if (!MMI->hasDebugInfo() || LScopes.empty()) {