diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -867,11 +867,17 @@ Row.Address = Address; RowIter FirstRow = Rows.begin() + Seq.FirstRowIndex; RowIter LastRow = Rows.begin() + Seq.LastRowIndex; + // In some cases, e.g. first instruction in a function, the compiler generates + // two entries, both with the same address. We want the last one. LineTable::RowIter RowPos = std::lower_bound( FirstRow, LastRow, Row, DWARFDebugLine::Row::orderByAddress); if (RowPos == LastRow) { return Seq.LastRowIndex - 1; } + while (RowPos->Address.Address == (RowPos + 1)->Address.Address && + RowPos < LastRow) { + ++RowPos; + } assert(Seq.SectionIndex == RowPos->Address.SectionIndex); uint32_t Index = Seq.FirstRowIndex + (RowPos - FirstRow); if (RowPos->Address.Address > Address.Address) { diff --git a/llvm/test/tools/llvm-symbolizer/fission-ranges.test b/llvm/test/tools/llvm-symbolizer/fission-ranges.test --- a/llvm/test/tools/llvm-symbolizer/fission-ranges.test +++ b/llvm/test/tools/llvm-symbolizer/fission-ranges.test @@ -1,4 +1,4 @@ RUN: llvm-symbolizer --obj=%p/Inputs/fission-ranges.elf-x86_64 0x720 | FileCheck %s CHECK: main -CHECK-NEXT: {{.*}}fission-ranges.cc:6 +CHECK-NEXT: {{.*}}fission-ranges.cc:2 diff --git a/llvm/test/tools/llvm-symbolizer/sym-verbose.test b/llvm/test/tools/llvm-symbolizer/sym-verbose.test --- a/llvm/test/tools/llvm-symbolizer/sym-verbose.test +++ b/llvm/test/tools/llvm-symbolizer/sym-verbose.test @@ -19,8 +19,8 @@ #CHECK-NEXT: foo #CHECK-NEXT: Filename: /tmp{{[\\/]}}discrim.c #CHECK-NEXT: Function start line: 4 -#CHECK-NEXT: Line: 9 -#CHECK-NEXT: Column: 0 +#CHECK-NEXT: Line: 5 +#CHECK-NEXT: Column: 7 #CHECK-NEXT: main #CHECK-NEXT: Filename: /tmp{{[\\/]}}discrim.c #CHECK-NEXT: Function start line: 9