-; RUN: sed -e "s,SRC_COMPDIR,%/p/Inputs,g" %s > %t.ll
-; RUN: llc -o %t.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll
-; RUN: llvm-objdump -d -l %t.o >%t0
-; RUN: llvm-objdump -dl %t.o >%t1
-; RUN: llvm-objdump -d -S %t.o >%t2
-; RUN: llvm-objdump -dS %t.o >%t3
-; RUN: cmp %t0 %t1
-; RUN: cmp %t2 %t3
-; RUN: FileCheck --check-prefix=LINES %t.ll < %t0
-; RUN: FileCheck --check-prefix=SOURCE --strict-whitespace %t.ll < %t2
+; NOTE: To be able to use this file as an input, the string SRC_CMPDIR needs
+; replacing with a directory path by using sed or similar.
+
; ModuleID = 'source-interleave-x86_64.bc'
source_filename = "source-interleave-x86_64.c"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
!21 = !DILocation(line: 8, column: 15, scope: !14)
!22 = !DILocation(line: 8, column: 13, scope: !14)
!23 = !DILocation(line: 8, column: 3, scope: !14)
-; LINES: main:
-; LINES-NEXT: ; {{[ -\(\)_A-Za-z0-9.\\/:]+}}source-interleave-x86_64.c:6
-
-; SOURCE: main:
-; SOURCE-NEXT: ; int main() {
-; SOURCE: ; int *b = &a;
--- /dev/null
+## Test llvm-objdump's --source behaviour when a line number is greater than the
+## file length.
+
+# RUN: sed -e "s,SRC_COMPDIR,%/p/Inputs,g" %p/Inputs/source-interleave.ll > %t.ll
+# RUN: sed -e "s,line: 7,line: 9999,g" %t.ll > %t2.ll
+
+# RUN: llc -o %t.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll
+# RUN: llc -o %t2.o -filetype=obj -mtriple=x86_64-pc-linux %t2.ll
+
+# RUN: llvm-objdump --source %t.o | FileCheck %s --check-prefixes=CHECK,GOOD
+# RUN: llvm-objdump --source %t2.o | FileCheck %s --implicit-check-not="int *b = &a;"
+
+# CHECK: main:
+# CHECK-NEXT: ; int main() {
+# GOOD: ; int *b = &a;
+# CHECK: ; return *b + foo();
--- /dev/null
+## Test that if the source cannot be found that disassembly is still printed,
+## and that no source is printed.
+
+# RUN: sed -e "s,SRC_COMPDIR,%/t,g" %p/Inputs/source-interleave.ll > %t.ll
+# RUN: sed -e "s,SRC_COMPDIR,%/p/Inputs,g" %p/Inputs/source-interleave.ll > %t2.ll
+
+# RUN: llc -o %t.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll
+# RUN: llc -o %t2.o -filetype=obj -mtriple=x86_64-pc-linux %t2.ll
+
+# RUN: llvm-objdump --source %t.o | FileCheck %s --implicit-check-not=main
+# RUN: llvm-objdump --source %t2.o | FileCheck %s --check-prefixes=CHECK,SOURCE
+
+# CHECK: 0000000000000010 main:
+# SOURCE-NEXT: ; int main() {
+# CHECK-NEXT: 10: 55 pushq %rbp
--- /dev/null
+## Test that if an object has no debug information, only the disassembly is
+## printed when --source is specified.
+
+# RUN: sed -e "s,SRC_COMPDIR,%/p/Inputs,g" %p/Inputs/source-interleave.ll > %t.ll
+# RUN: llc -o %t.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll
+# RUN: llvm-objcopy --strip-debug %t.o %t2.o
+
+# RUN: llvm-objdump --source %t.o | FileCheck %s --check-prefixes=CHECK,SOURCE
+# RUN: llvm-objdump --source %t2.o | FileCheck %s --implicit-check-not=main
+
+# CHECK: 0000000000000010 main:
+# SOURCE-NEXT: ; int main() {
+# CHECK-NEXT: 10: 55 pushq %rbp
--- /dev/null
+## Test that llvm-objdump prints source and disassembly for relative directory
+## paths for appropriate working directories. We also test that when the directory
+## string is empty the behaviour is the same as the current working directory.
+
+# RUN: mkdir -p %t/a/b
+# RUN: cp %p/Inputs/source-interleave-x86_64.c %t/a/source-interleave-x86_64.c
+
+# RUN: sed -e "s,SRC_COMPDIR,a,g" %p/Inputs/source-interleave.ll > %t.ll
+# RUN: sed -e "s,SRC_COMPDIR,,g" %p/Inputs/source-interleave.ll > %t2.ll
+# RUN: sed -e "s,SRC_COMPDIR,.,g" %p/Inputs/source-interleave.ll > %t3.ll
+# RUN: sed -e "s,SRC_COMPDIR,..,g" %p/Inputs/source-interleave.ll > %t4.ll
+
+# RUN: llc -o %t/a/a.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll
+# RUN: llc -o %t/a/b.o -filetype=obj -mtriple=x86_64-pc-linux %t2.ll
+# RUN: llc -o %t/a/c.o -filetype=obj -mtriple=x86_64-pc-linux %t3.ll
+# RUN: llc -o %t/a/d.o -filetype=obj -mtriple=x86_64-pc-linux %t4.ll
+
+# RUN: cd %t
+# RUN: llvm-objdump --source a/a.o | FileCheck %s --check-prefixes=CHECK,SOURCE
+# RUN: llvm-objdump --source a/b.o | FileCheck %s --implicit-check-not=main
+# RUN: llvm-objdump --source a/c.o | FileCheck %s --implicit-check-not=main
+# RUN: llvm-objdump --source a/d.o | FileCheck %s --implicit-check-not=main
+# RUN: cd a
+# RUN: llvm-objdump --source a.o | FileCheck %s --implicit-check-not=main
+# RUN: llvm-objdump --source b.o | FileCheck %s --check-prefixes=CHECK,SOURCE
+# RUN: llvm-objdump --source c.o | FileCheck %s --check-prefixes=CHECK,SOURCE
+# RUN: llvm-objdump --source d.o | FileCheck %s --implicit-check-not=main
+# RUN: cd b
+# RUN: llvm-objdump --source ../a.o | FileCheck %s --implicit-check-not=main
+# RUN: llvm-objdump --source ../b.o | FileCheck %s --implicit-check-not=main
+# RUN: llvm-objdump --source ../c.o | FileCheck %s --implicit-check-not=main
+# RUN: llvm-objdump --source ../d.o | FileCheck %s --check-prefixes=CHECK,SOURCE
+
+# CHECK: 0000000000000010 main:
+# SOURCE-NEXT: ; int main() {
+# CHECK-NEXT: 10: 55 pushq %rbp
--- /dev/null
+# RUN: sed -e "s,SRC_COMPDIR,%/p/Inputs,g" %p/Inputs/source-interleave.ll > %t.ll
+# RUN: llc -o %t.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll
+# RUN: llvm-objdump -d -l %t.o >%t0
+# RUN: llvm-objdump -dl %t.o >%t1
+# RUN: llvm-objdump -d -S %t.o >%t2
+# RUN: llvm-objdump -dS %t.o >%t3
+# RUN: cmp %t0 %t1
+# RUN: cmp %t2 %t3
+# RUN: FileCheck --check-prefix=LINES %s < %t0
+# RUN: FileCheck --check-prefix=SOURCE --strict-whitespace %s < %t2
+
+# LINES: main:
+# LINES-NEXT: ; {{[ -\(\)_A-Za-z0-9.\\/:]+}}source-interleave-x86_64.c:6
+
+# SOURCE: main:
+# SOURCE-NEXT: ; int main() {
+# SOURCE: ; int *b = &a;