Index: lib/DebugInfo/DWARF/DWARFDebugLine.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -17,9 +17,7 @@ using namespace dwarf; typedef DILineInfoSpecifier::FileLineInfoKind FileLineInfoKind; -DWARFDebugLine::Prologue::Prologue() { - clear(); -} +DWARFDebugLine::Prologue::Prologue() { clear(); } void DWARFDebugLine::Prologue::clear() { TotalLength = Version = PrologueLength = 0; @@ -44,12 +42,12 @@ << format(" opcode_base: %u\n", OpcodeBase); for (uint32_t i = 0; i < StandardOpcodeLengths.size(); ++i) - OS << format("standard_opcode_lengths[%s] = %u\n", LNStandardString(i+1), + OS << format("standard_opcode_lengths[%s] = %u\n", LNStandardString(i + 1), StandardOpcodeLengths[i]); if (!IncludeDirectories.empty()) for (uint32_t i = 0; i < IncludeDirectories.size(); ++i) - OS << format("include_directories[%3u] = '", i+1) + OS << format("include_directories[%3u] = '", i + 1) << IncludeDirectories[i] << "'\n"; if (!FileNames.empty()) { @@ -57,10 +55,10 @@ << " ---- ---------- ---------- -----------" "----------------\n"; for (uint32_t i = 0; i < FileNames.size(); ++i) { - const FileNameEntry& fileEntry = FileNames[i]; - OS << format("file_names[%3u] %4" PRIu64 " ", i+1, fileEntry.DirIdx) - << format("0x%8.8" PRIx64 " 0x%8.8" PRIx64 " ", - fileEntry.ModTime, fileEntry.Length) + const FileNameEntry &fileEntry = FileNames[i]; + OS << format("file_names[%3u] %4" PRIu64 " ", i + 1, fileEntry.DirIdx) + << format("0x%8.8" PRIx64 " 0x%8.8" PRIx64 " ", fileEntry.ModTime, + fileEntry.Length) << fileEntry.Name << '\n'; } } @@ -82,8 +80,8 @@ if (Version < 2) return false; - PrologueLength = debug_line_data.getUnsigned(offset_ptr, - sizeofPrologueLength()); + PrologueLength = + debug_line_data.getUnsigned(offset_ptr, sizeofPrologueLength()); const uint64_t end_prologue_offset = PrologueLength + *offset_ptr; MinInstLength = debug_line_data.getU8(offset_ptr); if (Version >= 4) @@ -131,9 +129,7 @@ return true; } -DWARFDebugLine::Row::Row(bool default_is_stmt) { - reset(default_is_stmt); -} +DWARFDebugLine::Row::Row(bool default_is_stmt) { reset(default_is_stmt); } void DWARFDebugLine::Row::postAppend() { BasicBlock = false; @@ -158,17 +154,13 @@ void DWARFDebugLine::Row::dump(raw_ostream &OS) const { OS << format("0x%16.16" PRIx64 " %6u %6u", Address, Line, Column) << format(" %6u %3u %13u ", File, Isa, Discriminator) - << (IsStmt ? " is_stmt" : "") - << (BasicBlock ? " basic_block" : "") + << (IsStmt ? " is_stmt" : "") << (BasicBlock ? " basic_block" : "") << (PrologueEnd ? " prologue_end" : "") << (EpilogueBegin ? " epilogue_begin" : "") - << (EndSequence ? " end_sequence" : "") - << '\n'; + << (EndSequence ? " end_sequence" : "") << '\n'; } -DWARFDebugLine::Sequence::Sequence() { - reset(); -} +DWARFDebugLine::Sequence::Sequence() { reset(); } void DWARFDebugLine::Sequence::reset() { LowPC = 0; @@ -178,9 +170,7 @@ Empty = true; } -DWARFDebugLine::LineTable::LineTable() { - clear(); -} +DWARFDebugLine::LineTable::LineTable() { clear(); } void DWARFDebugLine::LineTable::dump(raw_ostream &OS) const { Prologue.dump(OS); @@ -244,7 +234,7 @@ DWARFDebugLine::getOrParseLineTable(DataExtractor debug_line_data, uint32_t offset) { std::pair pos = - LineTableMap.insert(LineTableMapTy::value_type(offset, LineTable())); + LineTableMap.insert(LineTableMapTy::value_type(offset, LineTable())); LineTable *LT = &pos.first->second; if (pos.second) { if (!LT->parse(debug_line_data, RelocMap, &offset)) @@ -266,8 +256,8 @@ return false; } - const uint32_t end_offset = debug_line_offset + Prologue.TotalLength + - Prologue.sizeofTotalLength(); + const uint32_t end_offset = + debug_line_offset + Prologue.TotalLength + Prologue.sizeofTotalLength(); ParsingState State(this); @@ -307,9 +297,9 @@ // If this address is in our relocation map, apply the relocation. RelocAddrMap::const_iterator AI = RMap->find(*offset_ptr); if (AI != RMap->end()) { - const std::pair &R = AI->second; - State.Row.Address = - debug_line_data.getAddress(offset_ptr) + R.second; + const std::pair &R = AI->second; + State.Row.Address = + debug_line_data.getAddress(offset_ptr) + R.second; } else State.Row.Address = debug_line_data.getAddress(offset_ptr); } @@ -509,6 +499,8 @@ State.Row.Line += line_offset; State.Row.Address += addr_offset; State.appendRowToMatrix(*offset_ptr); + // Reset discriminator to 0. + State.Row.Discriminator = 0; } } @@ -566,8 +558,8 @@ sequence.LowPC = address; SequenceIter first_seq = Sequences.begin(); SequenceIter last_seq = Sequences.end(); - SequenceIter seq_pos = std::lower_bound(first_seq, last_seq, sequence, - DWARFDebugLine::Sequence::orderByLowPC); + SequenceIter seq_pos = std::lower_bound( + first_seq, last_seq, sequence, DWARFDebugLine::Sequence::orderByLowPC); DWARFDebugLine::Sequence found_seq; if (seq_pos == last_seq) { found_seq = Sequences.back(); @@ -591,8 +583,8 @@ sequence.LowPC = address; SequenceIter first_seq = Sequences.begin(); SequenceIter last_seq = Sequences.end(); - SequenceIter seq_pos = std::lower_bound(first_seq, last_seq, sequence, - DWARFDebugLine::Sequence::orderByLowPC); + SequenceIter seq_pos = std::lower_bound( + first_seq, last_seq, sequence, DWARFDebugLine::Sequence::orderByLowPC); if (seq_pos == last_seq || seq_pos->LowPC != address) { if (seq_pos == first_seq) return false; @@ -632,11 +624,10 @@ return true; } -bool -DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex, - const char *CompDir, - FileLineInfoKind Kind, - std::string &Result) const { +bool DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex, + const char *CompDir, + FileLineInfoKind Kind, + std::string &Result) const { if (FileIndex == 0 || FileIndex > Prologue.FileNames.size() || Kind == FileLineInfoKind::None) return false; @@ -669,11 +660,9 @@ return true; } -bool -DWARFDebugLine::LineTable::getFileLineInfoForAddress(uint64_t Address, - const char *CompDir, - FileLineInfoKind Kind, - DILineInfo &Result) const { +bool DWARFDebugLine::LineTable::getFileLineInfoForAddress( + uint64_t Address, const char *CompDir, FileLineInfoKind Kind, + DILineInfo &Result) const { // Get the index of row we're looking for in the line table. uint32_t RowIndex = lookupAddress(Address); if (RowIndex == -1U) Index: lib/MC/MCDwarf.cpp =================================================================== --- lib/MC/MCDwarf.cpp +++ lib/MC/MCDwarf.cpp @@ -114,10 +114,6 @@ int64_t LineDelta = static_cast(it->getLine()) - LastLine; - // Discriminator will be cleared if there is line change. - if (LineDelta != 0) - Discriminator = 0; - if (FileNum != it->getFileNum()) { FileNum = it->getFileNum(); MCOS->EmitIntValue(dwarf::DW_LNS_set_file, 1); @@ -161,6 +157,7 @@ MCOS->EmitDwarfAdvanceLineAddr(LineDelta, LastLabel, Label, asmInfo->getPointerSize()); + Discriminator = 0; LastLine = it->getLine(); LastLabel = Label; } Index: test/DebugInfo/X86/discriminator2.ll =================================================================== --- /dev/null +++ test/DebugInfo/X86/discriminator2.ll @@ -0,0 +1,61 @@ +; RUN: llc -mtriple=i386-unknown-unknown -mcpu=core2 %s -o %t -filetype=obj +; RUN: llvm-dwarfdump -debug-dump=line %t | FileCheck %s +; +; Generated from: +; +; #1 void foo(int, int); +; #2 int bar(); +; #3 void baz() { +; #4 foo/*discriminator 1*/(bar(), +; #5 bar());bar()/*discriminator 1*/; +; #6 } +; +; The intent is to test discriminator 1 generated for both line #4 and #5. +; The instruction sequence in the final binary is: +; line 4 discriminator 0 +; line 5 discriminator 0 +; line 4 discriminator 1 +; line 5 discriminator 1 +; We need to ensure that the discriminators for the last two instructions +; are both 1. + +; Function Attrs: uwtable +define void @_Z3bazv() #0 !dbg !6 { + %1 = call i32 @_Z3barv(), !dbg !9 + %2 = call i32 @_Z3barv(), !dbg !10 + call void @_Z3fooii(i32 %1, i32 %2), !dbg !11 + %3 = call i32 @_Z3barv(), !dbg !13 + ret void, !dbg !14 +} + +declare void @_Z3fooii(i32, i32) #1 + +declare i32 @_Z3barv() #1 + +attributes #0 = { uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4} +!llvm.ident = !{!5} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 267219)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "test.cc", directory: ".") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{!"clang version 3.9.0 (trunk 267219)"} +!6 = distinct !DISubprogram(name: "baz", linkageName: "_Z3bazv", scope: !1, file: !1, line: 3, type: !7, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2) +!7 = !DISubroutineType(types: !8) +!8 = !{null} +!9 = !DILocation(line: 4, column: 7, scope: !6) +!10 = !DILocation(line: 5, column: 14, scope: !6) +!11 = !DILocation(line: 4, column: 3, scope: !12) +!12 = !DILexicalBlockFile(scope: !6, file: !1, discriminator: 1) +!13 = !DILocation(line: 5, column: 21, scope: !12) +!14 = !DILocation(line: 6, column: 1, scope: !6) + +; CHECK: Address Line Column File ISA Discriminator Flags +; CHECK: ------------------ ------ ------ ------ --- ------------- ------------- +; CHECK: {{.*}} 4 3 1 0 1 {{.*}} +; CHECK: {{.*}} 5 21 1 0 1 {{.*}} Index: test/DebugInfo/X86/discriminator3.ll =================================================================== --- /dev/null +++ test/DebugInfo/X86/discriminator3.ll @@ -0,0 +1,74 @@ +; RUN: llc -mtriple=i386-unknown-unknown -mcpu=core2 %s -o %t -filetype=obj +; RUN: llvm-dwarfdump -debug-dump=line %t | FileCheck %s +; +; Generated from: +; +; #1 void foo(int); +; #2 void baz(int i) { +; #3 if (i) {foo(i+1);/*discriminator 1*/} +; #4 } +; +; The intent is to test discriminator 1 generated for all instructions in +; the taken branch. + +; Function Attrs: uwtable +define void @_Z3bazi(i32) #0 !dbg !6 { + %2 = alloca i32, align 4 + store i32 %0, i32* %2, align 4 + call void @llvm.dbg.declare(metadata i32* %2, metadata !10, metadata !11), !dbg !12 + %3 = load i32, i32* %2, align 4, !dbg !13 + %4 = icmp ne i32 %3, 0, !dbg !13 + br i1 %4, label %5, label %8, !dbg !15 + +;