[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:18 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.
----------------
jh7370 wrote:

"so whichever host reads the object, one of them is not a separator there" is factually incorrect on Windows, since both directions are permitted (regardless of the preferred direction).

I also found this comment rather verbose and including unnecessary detail (like the path not resolving to a file on either host). How about the following:

```
;; 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.
```

https://github.com/llvm/llvm-project/pull/215225


More information about the llvm-commits mailing list