[llvm] [TableGen] correctly escape dependency filenames (PR #160834)

Ruoyu Zhong via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 26 03:52:48 PDT 2025


================
@@ -0,0 +1,38 @@
+// RUN: rm -rf %t; split-file %s %t
+
+//--- normal-file.td
+class NormalClass {}
+
+//--- file with spaces.td
+class SpaceClass {}
+
+//--- file#with#hash.td
+class HashClass {}
+
+//--- file$with$dollar.td
+class DollarClass {}
+
+//--- file with escape\ before spaces.td
+class EscapeBeforeSpacesClass {}
+
+//--- main.td
+include "normal-file.td"
+include "file with spaces.td"
+include "file#with#hash.td"
+include "file$with$dollar.td"
+include "file with escape\\ before spaces.td" // backslash itself needs escaping
+
+def Normal : NormalClass;
+def Spaces : SpaceClass;
+def Hash : HashClass;
+def Dollar : DollarClass;
+def EscapeBeforeSpaces : EscapeBeforeSpacesClass;
+
+// RUN: llvm-tblgen -I %t -d %t.d -o %t.out %t/main.td
+// RUN: FileCheck --input-file=%t.d %s
+
+// CHECK-DAG: normal-file.td
+// CHECK-DAG: file\ with\ spaces.td
+// CHECK-DAG: file\#with\#hash.td
+// CHECK-DAG: file$$with$$dollar.td
+// CHECK-DAG: file\ with\ escape\\\ before\ spaces.td
----------------
ZhongRuoyu wrote:

This test actually failed before 67488def1c78584690f932b48a0d4fd2671bc934 as the filename was escaped as `file\ with\ space/\ before\ spaces.td` suggesting that the backslash in the filename was mistakenly transformed to the path separator `/` due to this:

https://github.com/llvm/llvm-project/blob/2cacf7117ba0fb7c134413a1a51302f8d6649052/llvm/lib/Support/Path.cpp#L564

So I believe it's more correct to do this without transforming the path with `sys::path::native` due to its "On Unix, it converts all '\' to '/'" behaviour:

https://github.com/llvm/llvm-project/blob/2cacf7117ba0fb7c134413a1a51302f8d6649052/llvm/include/llvm/Support/Path.h#L258-L265


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


More information about the llvm-commits mailing list