From 0ccb60f70447698ffbd15dc47e272c7b1f5d4536 Mon Sep 17 00:00:00 2001 From: Michael Pozulp Date: Fri, 7 Jun 2019 06:23:54 +0000 Subject: [PATCH] [llvm-objdump] Print source when subsequent lines in the translation unit come from the same line in two different headers. Reviewers: grimar, rupprecht, jhenderson Reviewed By: grimar, jhenderson Subscribers: llvm-commits, jhenderson Tags: #llvm Differential Revision: https://reviews.llvm.org/D62461 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362771 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../X86/Inputs/source-interleave-header1.h | 1 + .../X86/Inputs/source-interleave-header2.h | 1 + .../source-interleave-same-line-different-file.c | 2 + .../source-interleave-same-line-different-file.ll | 61 ++++++++++++++++++++++ .../llvm-objdump/X86/Inputs/source-interleave.ll | 2 +- ...source-interleave-same-line-different-file.test | 12 +++++ tools/llvm-objdump/llvm-objdump.cpp | 5 +- 7 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 test/tools/llvm-objdump/X86/Inputs/source-interleave-header1.h create mode 100644 test/tools/llvm-objdump/X86/Inputs/source-interleave-header2.h create mode 100644 test/tools/llvm-objdump/X86/Inputs/source-interleave-same-line-different-file.c create mode 100644 test/tools/llvm-objdump/X86/Inputs/source-interleave-same-line-different-file.ll create mode 100644 test/tools/llvm-objdump/X86/source-interleave-same-line-different-file.test diff --git a/test/tools/llvm-objdump/X86/Inputs/source-interleave-header1.h b/test/tools/llvm-objdump/X86/Inputs/source-interleave-header1.h new file mode 100644 index 00000000000..c2cf1cdcaab --- /dev/null +++ b/test/tools/llvm-objdump/X86/Inputs/source-interleave-header1.h @@ -0,0 +1 @@ +int add1(int a) { return a + 1; } diff --git a/test/tools/llvm-objdump/X86/Inputs/source-interleave-header2.h b/test/tools/llvm-objdump/X86/Inputs/source-interleave-header2.h new file mode 100644 index 00000000000..e9a8ee3e86f --- /dev/null +++ b/test/tools/llvm-objdump/X86/Inputs/source-interleave-header2.h @@ -0,0 +1 @@ +int return4() { return 4; } diff --git a/test/tools/llvm-objdump/X86/Inputs/source-interleave-same-line-different-file.c b/test/tools/llvm-objdump/X86/Inputs/source-interleave-same-line-different-file.c new file mode 100644 index 00000000000..17946a4c509 --- /dev/null +++ b/test/tools/llvm-objdump/X86/Inputs/source-interleave-same-line-different-file.c @@ -0,0 +1,2 @@ +#include "source-interleave-header1.h" +#include "source-interleave-header2.h" diff --git a/test/tools/llvm-objdump/X86/Inputs/source-interleave-same-line-different-file.ll b/test/tools/llvm-objdump/X86/Inputs/source-interleave-same-line-different-file.ll new file mode 100644 index 00000000000..4d4ec355794 --- /dev/null +++ b/test/tools/llvm-objdump/X86/Inputs/source-interleave-same-line-different-file.ll @@ -0,0 +1,61 @@ +; NOTE: To be able to use this file as an input, the string SRC_COMPDIR needs +; replacing with a directory path by using sed or similar. + +; NOTE: This file was generated by running +; clang -g -S -emit-llvm source-interleave-same-line-different-file.c -o \ +; source-interleave-same-line-different-file.ll + +; ModuleID = 'source-interleave-same-line-different-file.c' +source_filename = "source-interleave-same-line-different-file.c" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local i32 @add1(i32 %a) #0 !dbg !7 { +entry: + %a.addr = alloca i32, align 4 + store i32 %a, i32* %a.addr, align 4 + call void @llvm.dbg.declare(metadata i32* %a.addr, metadata !12, metadata !DIExpression()), !dbg !13 + %0 = load i32, i32* %a.addr, align 4, !dbg !14 + %add = add nsw i32 %0, 1, !dbg !15 + ret i32 %add, !dbg !16 +} + +; Function Attrs: nounwind readnone speculatable +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local i32 @return4() #0 !dbg !17 { +entry: + ret i32 4, !dbg !21 +} + +attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "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" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind readnone speculatable } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git af0add6c39f7fcc641a2ae38753a9bc4eae47b28)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "source-interleave-same-line-different-file.c", directory: "SRC_COMPDIR") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 4} +!6 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git af0add6c39f7fcc641a2ae38753a9bc4eae47b28)"} +!7 = distinct !DISubprogram(name: "add1", scope: !8, file: !8, line: 1, type: !9, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!8 = !DIFile(filename: "./source-interleave-header1.h", directory: "SRC_COMPDIR") +!9 = !DISubroutineType(types: !10) +!10 = !{!11, !11} +!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!12 = !DILocalVariable(name: "a", arg: 1, scope: !7, file: !8, line: 1, type: !11) +!13 = !DILocation(line: 1, column: 14, scope: !7) +!14 = !DILocation(line: 1, column: 26, scope: !7) +!15 = !DILocation(line: 1, column: 28, scope: !7) +!16 = !DILocation(line: 1, column: 19, scope: !7) +!17 = distinct !DISubprogram(name: "return4", scope: !18, file: !18, line: 1, type: !19, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!18 = !DIFile(filename: "./source-interleave-header2.h", directory: "SRC_COMPDIR") +!19 = !DISubroutineType(types: !20) +!20 = !{!11} +!21 = !DILocation(line: 1, column: 17, scope: !17) diff --git a/test/tools/llvm-objdump/X86/Inputs/source-interleave.ll b/test/tools/llvm-objdump/X86/Inputs/source-interleave.ll index 1db42f5aaa8..8d49d01f024 100644 --- a/test/tools/llvm-objdump/X86/Inputs/source-interleave.ll +++ b/test/tools/llvm-objdump/X86/Inputs/source-interleave.ll @@ -1,4 +1,4 @@ -; NOTE: To be able to use this file as an input, the string SRC_CMPDIR needs +; NOTE: To be able to use this file as an input, the string SRC_COMPDIR needs ; replacing with a directory path by using sed or similar. ; ModuleID = 'source-interleave-x86_64.bc' diff --git a/test/tools/llvm-objdump/X86/source-interleave-same-line-different-file.test b/test/tools/llvm-objdump/X86/source-interleave-same-line-different-file.test new file mode 100644 index 00000000000..dfd0ce178e9 --- /dev/null +++ b/test/tools/llvm-objdump/X86/source-interleave-same-line-different-file.test @@ -0,0 +1,12 @@ +## Test that source is printed when subsequent lines in the translation unit +## come from the same line in two different files. + +# RUN: sed -e "s,SRC_COMPDIR,%/p/Inputs,g" %p/Inputs/source-interleave-same-line-different-file.ll > %t.ll +# RUN: llc -o %t.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll +# RUN: llvm-objdump --source %t.o | FileCheck %s + +# CHECK: 0000000000000000 add1: +# CHECK-NEXT: ; int add1(int a) { return a + 1; } +# +# CHECK: 0000000000000010 return4: +# CHECK-NEXT: ; int return4() { return 4; } diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index c384ba82feb..bbd65d9a9a7 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -579,8 +579,9 @@ void SourcePrinter::printSourceLine(raw_ostream &OS, else LineInfo = *ExpectedLineInfo; - if ((LineInfo.FileName == "") || OldLineInfo.Line == LineInfo.Line || - LineInfo.Line == 0) + if ((LineInfo.FileName == "") || LineInfo.Line == 0 || + ((OldLineInfo.Line == LineInfo.Line) && + (OldLineInfo.FileName == LineInfo.FileName))) return; if (PrintLines) -- 2.11.0