[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


================
@@ -8,12 +8,12 @@
 ; RUN: llc -o %t.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll
 ; RUN: llvm-objdump --prefix 'myprefix/\' --source %t.o 2>&1 | FileCheck %s -DFILE=%t.o -DPREFIX='myprefix' -DSEP=%{fs-sep}
 
-;; When --prefix is specified and the file path is absolute, sys::path::append
-;; is used to add the file path to the prefix. On Windows, if the file path
-;; starts with a slash, sys::path::append currently does a straight
-;; concatenation, resulting in the first slash being preserved as-is ('/').
-;; The second slash (after 'Inputs') is generated by llc using
-;; sys::path::append to join the directory and filename, which uses the
-;; preferred path separator (controlled by LLVM_WINDOWS_PREFER_FORWARD_SLASH).
-; CHECK: warning: '[[FILE]]': failed to find source [[PREFIX]]/Inputs[[SEP]]source-interleave-x86_64.c
+;; The compilation directory '/Inputs' is joined to the file name with the
+;; preferred separator, so the path recorded in the debug info mixes '/' and
+;; '\'. It is normalized before --prefix is applied, so every separator below is
+;; [[SEP]], the one native to this host: output that still mixed the two, or
+;; that used the other style, would not match. sys::path::append then
+;; concatenates the path onto the prefix without inserting a separator, because
+;; it already starts with one.
----------------
jh7370 wrote:

This is overly complicated and makes it harder to find the key points. How about:
```
;; The compilation directory '/Inputs' is joined to the file name using the
;; preferred separator, producing a mixed-style path. It is normalized before
;; --prefix is applied, so all separators after the prefix are the host's preferred value.
;; sys::path::append then joins it to the prefix without adding a separator
;; because the path already starts with one.
```

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


More information about the llvm-commits mailing list