Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -2650,6 +2650,7 @@ SM.getExpansionLoc(CurLoc) == SM.getExpansionLoc(PrevLoc)) // New Builder may not be in sync with CGDebugInfo. if (!Builder.getCurrentDebugLocation().isUnknown() && + LexicalBlockStack.size() && Builder.getCurrentDebugLocation().getScope(CGM.getLLVMContext()) == LexicalBlockStack.back()) return; @@ -2657,7 +2658,10 @@ // Update last state. PrevLoc = CurLoc; - llvm::MDNode *Scope = LexicalBlockStack.back(); + llvm::MDNode *Scope = + LexicalBlockStack.size() + ? LexicalBlockStack.back() + : Builder.getCurrentDebugLocation().getScope(CGM.getLLVMContext()); Builder.SetCurrentDebugLocation(llvm::DebugLoc::get( getLineNumber(CurLoc), getColumnNumber(CurLoc, ForceColumnInfo), Scope)); }