blob: 93c193bf476f635b9e7dd43ae03f6cfbc35fd4ed [file] [edit]
;; Test --substitute-path and --source-dir with --source and --line-numbers.
;;
;; The object records source paths under /wrong/Inputs, but the source file
;; lives in this test's Inputs directory. Without path remapping, --source
;; cannot load the file from disk.
;;
;; --source-dir: each flag appends one directory to the search list, so when
;; several --source-dir paths could supply the same file name, the first
;; flag on the command line is tried before later ones.
;;
;; --substitute-path: rules are tried in command-line order; the first match
;; wins (same as GDB set substitute-path).
; RUN: sed -e "s,SRC_COMPDIR,/wrong/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 --no-print-imm-hex -d --line-numbers %t.o | FileCheck %s --check-prefix=LINE
; LINE: <foo>:
; LINE-NEXT: ; foo():
; LINE-NEXT: ; {{.*}}source-interleave-x86_64.c:2
; LINE-NEXT: pushq
; LINE: ; {{.*}}source-interleave-x86_64.c:3
; LINE-NEXT: movq
; LINE-NEXT: movl
; LINE-NEXT: popq
; LINE-NEXT: retq
; RUN: llvm-objdump --no-print-imm-hex -d --source %t.o 2>&1 | \
; RUN: FileCheck %s --check-prefix=SOURCE-MISSING -DFILE=%t.o -DSEP=%{fs-sep}
;; The compilation directory is spelled with '/' but is joined to the file name
;; with the preferred directory separator. On Windows, when
;; LLVM_WINDOWS_PREFER_FORWARD_SLASH is not enabled, this means the path
;; contains a mix of slash directions, which llvm-objdump then normalises.
; SOURCE-MISSING: warning: '[[FILE]]': failed to find source [[SEP]]wrong[[SEP]]Inputs[[SEP]]source-interleave-x86_64.c
; RUN: llvm-objdump --no-print-imm-hex -d --source --substitute-path /wrong %/p %t.o | \
; RUN: FileCheck %s --check-prefix=SOURCE
; RUN: llvm-objdump --no-print-imm-hex -d --source --source-dir %/p/Inputs %t.o | \
; RUN: FileCheck %s --check-prefix=SOURCE
;; --prefix alone cannot fix /wrong/Inputs, but --source-dir finds the file
;; via basename lookup under the search directory.
; RUN: llvm-objdump --no-print-imm-hex -d --source \
; RUN: --prefix %/p --source-dir %/p/Inputs %t.o | \
; RUN: FileCheck %s --check-prefix=SOURCE
;; All three: substitute and prefix produce a missing path; --source-dir
;; resolves the file from the search directory.
; RUN: llvm-objdump --no-print-imm-hex -d --source \
; RUN: --substitute-path /wrong/Inputs /missing \
; RUN: --prefix %/p --source-dir %/p/Inputs %t.o | \
; RUN: FileCheck %s --check-prefix=SOURCE
;; When substitute-path yields a relative path, --prefix is ignored (as in
;; source-interleave-prefix.test) but --source-dir still resolves the file.
; RUN: llvm-objdump --no-print-imm-hex -d --source --substitute-path /wrong "" %t.o \
; RUN: --prefix myprefix --source-dir %/p/Inputs %t.o | \
; RUN: FileCheck %s --check-prefix=SOURCE
;; %/p/Inputs is listed first and already contains the source; %/p is only
;; needed if the first directories do not resolve the file.
; RUN: llvm-objdump --no-print-imm-hex -d --source \
; RUN: --source-dir %/p/Inputs --source-dir %/p %t.o | \
; RUN: FileCheck %s --check-prefix=SOURCE
;; More specific rule listed first wins (GDB example: /wrong/Inputs before /wrong).
; RUN: llvm-objdump --no-print-imm-hex -d --source \
; RUN: --substitute-path /wrong/Inputs %/p/Inputs \
; RUN: --substitute-path /wrong /nowhere %t.o | \
; RUN: FileCheck %s --check-prefix=SOURCE
; SOURCE: <foo>:
; SOURCE-NEXT: ; int foo() {
; SOURCE-NEXT: pushq
; SOURCE: ; return a;
; SOURCE-NEXT: movq
; SOURCE-NEXT: movl
; SOURCE-NEXT: popq
; SOURCE-NEXT: retq
; RUN: llvm-objdump --no-print-imm-hex -d --source --substitute-path /wron %/p %t.o 2>&1 | \
; RUN: FileCheck %s --check-prefix=SOURCE-MISSING -DFILE=%t.o -DSEP=%{fs-sep}
;; Two --source-dir trees both contain source-interleave-x86_64.c (same line
;; count; distinct in-line markers). The copy from the **earlier** flag must
;; be the one interleaved (search order is first-to-last on the command line).
; RUN: mkdir -p %t.sd1 %t.sd2
; RUN: sed -e 's/int foo() {/int foo() { \/\/SDR-FIRST/' \
; RUN: %p/Inputs/source-interleave-x86_64.c > %t.sd1/source-interleave-x86_64.c
; RUN: sed -e 's/int foo() {/int foo() { \/\/SDR-SECOND/' \
; RUN: %p/Inputs/source-interleave-x86_64.c > %t.sd2/source-interleave-x86_64.c
; RUN: llvm-objdump --no-print-imm-hex -d --source \
; RUN: --source-dir %t.sd1 --source-dir %t.sd2 %t.o | \
; RUN: FileCheck %s --check-prefix=SOURCE-DIR-ORDER12 --implicit-check-not=SDR-SECOND
; RUN: llvm-objdump --no-print-imm-hex -d --source \
; RUN: --source-dir %t.sd2 --source-dir %t.sd1 %t.o | \
; RUN: FileCheck %s --check-prefix=SOURCE-DIR-ORDER21 --implicit-check-not=SDR-FIRST
; SOURCE-DIR-ORDER12: <foo>:
; SOURCE-DIR-ORDER12-NEXT: ; int foo() { //SDR-FIRST
; SOURCE-DIR-ORDER12-NEXT: pushq
; SOURCE-DIR-ORDER21: <foo>:
; SOURCE-DIR-ORDER21-NEXT: ; int foo() { //SDR-SECOND
; SOURCE-DIR-ORDER21-NEXT: pushq
;; Broader rule listed first matches; later rule is not applied (miss on remapped path).
; RUN: llvm-objdump --no-print-imm-hex -d --source \
; RUN: --substitute-path /wrong /nowhere \
; RUN: --substitute-path /wrong/Inputs %/p/Inputs %t.o 2>&1 | \
; RUN: FileCheck %s --check-prefix=SOURCE-MISSING-SUBST -DFILE=%t.o -DSEP=%{fs-sep}
; SOURCE-MISSING-SUBST: warning: '[[FILE]]': failed to find source [[SEP]]nowhere[[SEP]]Inputs[[SEP]]source-interleave-x86_64.c
;; First substitute rule is a no-match; second matching rule remaps the path.
; RUN: llvm-objdump --no-print-imm-hex -d --source \
; RUN: --substitute-path /wron /nowhere \
; RUN: --substitute-path /wrong %/p %t.o | \
; RUN: FileCheck %s --check-prefix=SOURCE
;; Empty <to> strips the matched prefix; use --source-dir to
;; resolve the resulting relative path.
; RUN: llvm-objdump --no-print-imm-hex -d --source --substitute-path /wrong "" \
; RUN: --source-dir %/p/Inputs %t.o | FileCheck %s --check-prefix=SOURCE
;; Empty <to> without --source-dir: relative path is not resolved; warn once, no crash.
; RUN: llvm-objdump --no-print-imm-hex -d --source --substitute-path /wrong "" %t.o 2>&1 | \
; RUN: FileCheck %s --check-prefix=SOURCE-EMPTY-TO -DFILE=%t.o -DSEP=%{fs-sep} \
; RUN: --implicit-check-not="foo()"
; SOURCE-EMPTY-TO: <foo>:
; SOURCE-EMPTY-TO: warning: '[[FILE]]': failed to find source Inputs[[SEP]]source-interleave-x86_64.c
; SOURCE-EMPTY-TO: pushq
;; Empty <from> is rejected .
; RUN: not llvm-objdump --substitute-path "" %/p %t.o 2>&1 | \
; RUN: FileCheck %s --check-prefix=SUBST-ERR-FROM
; SUBST-ERR-FROM: llvm-objdump{{.*}}: error: --substitute-path: <from> must not be empty
;; --substitute-path runs before --prefix: remap /wrong/Inputs to the
;; root-relative /Inputs, then prepend the test directory.
; RUN: llvm-objdump --no-print-imm-hex -d --source \
; RUN: --substitute-path /wrong/Inputs /Inputs --prefix %/p %t.o | \
; RUN: FileCheck %s --check-prefix=SOURCE
; RUN: llvm-objdump --no-print-imm-hex -d --line-numbers \
; RUN: --substitute-path /wrong/Inputs /Inputs --prefix %/p %t.o | \
; RUN: FileCheck %s --check-prefix=LINE-SUBST-PREFIX -DPREFIX=%/p -DSEP=%{fs-sep}
;; --prefix is prepended after normalization and keeps whatever spelling it was
;; given, which is why [[PREFIX]] still reads with '/' while the part that came
;; from the debug info uses the host separator.
; LINE-SUBST-PREFIX: <foo>:
; LINE-SUBST-PREFIX-NEXT: ; foo():
; LINE-SUBST-PREFIX-NEXT: ; [[PREFIX]][[SEP]]Inputs[[SEP]]source-interleave-x86_64.c:2
; LINE-SUBST-PREFIX-NEXT: pushq
; LINE-SUBST-PREFIX: ; [[PREFIX]][[SEP]]Inputs[[SEP]]source-interleave-x86_64.c:3
; LINE-SUBST-PREFIX-NEXT: movq
;; Source paths recorded in objects may use either path separator. They are
;; treated as strings here: --line-numbers reports them without accessing the
;; named file.
;;
;; The compilation directory deliberately contains mixed separators. llc
;; preserves it as spelled and appends the file name using the host separator,
;; so the resulting path may also have mixed separators. The '\' is doubled
;; for sed. llvm-objdump then normalizes the slash direction when printing.
; RUN: sed -e 's,SRC_COMPDIR,dx12\\compute/no_rs,g' %p/Inputs/source-interleave.ll > %t-winpath.ll
; RUN: llc -o %t-winpath.o -filetype=obj -mtriple=x86_64-pc-linux %t-winpath.ll
; RUN: llvm-objdump --no-print-imm-hex -d --line-numbers %t-winpath.o | \
; RUN: FileCheck %s --check-prefix=WINPATH-LINE -DSEP=%{fs-sep}
; WINPATH-LINE: <foo>:
; WINPATH-LINE-NEXT: ; foo():
; WINPATH-LINE-NEXT: ; dx12[[SEP]]compute[[SEP]]no_rs[[SEP]]source-interleave-x86_64.c:2
;; <from> may be spelled with either separator; both name the same directory.
; RUN: llvm-objdump --no-print-imm-hex -d --source \
; RUN: --substitute-path 'dx12\compute\no_rs' %/p/Inputs %t-winpath.o | \
; RUN: FileCheck %s --check-prefix=SOURCE
; RUN: llvm-objdump --no-print-imm-hex -d --source \
; RUN: --substitute-path dx12/compute/no_rs %/p/Inputs %t-winpath.o | \
; RUN: FileCheck %s --check-prefix=SOURCE
;; --source-dir finds the same file by its base name.
; RUN: llvm-objdump --no-print-imm-hex -d --source --source-dir %/p/Inputs \
; RUN: %t-winpath.o | FileCheck %s --check-prefix=SOURCE