From 7f2b717b52f9a3884ef0f1d8a3704097892d988c Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Fri, 26 May 2017 17:05:15 +0000 Subject: [PATCH] DebugInfo: Don't include locations for debug-having code inlined into nodebug functions This produced 'strange' DWARF anyway - the CU would have no ranges (or at least not a range including the inlined code) nor any subprogram or inlined_subroutine - yet the line table would have entries for these instructions. (this actually becomes more relevant with changes coming after this, where a CU without any contents will be omitted entirely - so there would be no line table to put this on anyway) llvm-svn: 304004 --- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 4 ++++ llvm/test/DebugInfo/Generic/nodebug.ll | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index b696312..3ea4c1c 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1036,6 +1036,10 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) { DebugHandlerBase::beginInstruction(MI); assert(CurMI); + const auto *SP = MI->getParent()->getParent()->getFunction()->getSubprogram(); + if (!SP || SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug) + return; + // Check if source location changes, but ignore DBG_VALUE and CFI locations. if (MI->isMetaInstruction()) return; diff --git a/llvm/test/DebugInfo/Generic/nodebug.ll b/llvm/test/DebugInfo/Generic/nodebug.ll index f85b00bf..93ed49d 100644 --- a/llvm/test/DebugInfo/Generic/nodebug.ll +++ b/llvm/test/DebugInfo/Generic/nodebug.ll @@ -1,6 +1,6 @@ ; REQUIRES: object-emission -; RUN: %llc_dwarf < %s -filetype=obj | llvm-dwarfdump -debug-dump=info - | FileCheck %s +; RUN: %llc_dwarf < %s -filetype=obj | llvm-dwarfdump - | FileCheck %s ; Test that a nodebug function (a function not appearing in the debug info IR ; metadata subprogram list) with DebugLocs on its IR doesn't cause crashes/does @@ -17,9 +17,16 @@ ; } ; Check that there's no DW_TAG_subprogram, not even for the 'f2' function. +; CHECK: .debug_info contents: ; CHECK: DW_TAG_compile_unit ; CHECK-NOT: DW_TAG_subprogram +; Expect no line table entry since there are no functions and file references in this compile unit +; CHECK: .debug_line contents: +; CHECK: Line table prologue: +; CHECK: total_length: 0x00000019 +; CHECK-NOT: file_names[ + @i = external global i32 ; Function Attrs: uwtable -- 2.7.4