[llvm] Normalize file path to fix problems with different folder separators. (PR #215225)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 18 02:12:20 PDT 2026
================
@@ -143,33 +147,40 @@
; 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
+; 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]]{{[/\\]}}Inputs{{[/\\]}}source-interleave-x86_64.c:2
+; LINE-SUBST-PREFIX-NEXT: ; [[PREFIX]][[SEP]]Inputs[[SEP]]source-interleave-x86_64.c:2
; LINE-SUBST-PREFIX-NEXT: pushq
-; LINE-SUBST-PREFIX: ; [[PREFIX]]{{[/\\]}}Inputs{{[/\\]}}source-interleave-x86_64.c:3
+; LINE-SUBST-PREFIX: ; [[PREFIX]][[SEP]]Inputs[[SEP]]source-interleave-x86_64.c:3
; LINE-SUBST-PREFIX-NEXT: movq
-;; Objects built on Windows record source paths with '\' separators, which are
-;; not separators on a POSIX host. Paths from the debug info are normalized
-;; before the rules below are applied, so the same object behaves the same way
-;; whatever the host is.
+;; Objects built on Windows may record source paths with '\' separators, which
+;; are not separators on a POSIX host. Such a path is only ever a string here:
+;; no file of that name exists on either host, and --line-numbers reports the
+;; path without looking for it.
+;;
+;; The compilation directory below mixes the two separators, so whichever host
+;; reads the object, one of them is not a separator there. llc keeps it as
+;; spelled and joins the file name on with the host separator, so what reaches
+;; llvm-objdump is of a mixed style on any host. The '\' is doubled for sed.
-; RUN: llc -o %t-winpath.o -filetype=obj -mtriple=x86_64-pc-linux \
-; RUN: %p/Inputs/source-interleave-windows-path.ll
+; 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
-;; Which separator a path is printed with depends on the host and, on Windows,
-;; on LLVM_WINDOWS_PREFER_FORWARD_SLASH, so it is not checked for here. What is
-;; checked is that one path does not mix the two styles: the separator is
-;; captured from its first occurrence and has to be the same one throughout.
+;; The path has to come back out spelled with [[SEP]] throughout, the separator
+;; native to this host, which is what would regress if it stopped being
----------------
jh7370 wrote:
I actually think this comment is completely unnecessary, with the minor addition I added in my suggestion above. The SEP variable is self-descriptive and we don't need to specifically point out that this is the thing that would break if normalization went wrong.
https://github.com/llvm/llvm-project/pull/215225
More information about the llvm-commits
mailing list