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

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 26 01:56:13 PDT 2025


================
@@ -83,6 +85,35 @@ static int reportError(const char *ProgName, Twine Msg) {
   return 1;
 }
 
+/// Escape a filename in the dependency file so that it is correctly
+/// interpreted by `make`. This is consistent with Clang, GCC, and lld.
+static TGLexer::DependenciesSetTy::value_type escapeDependencyFilename(
+    const TGLexer::DependenciesSetTy::value_type &Filename) {
+  std::string Res;
+  raw_string_ostream OS(Res);
+
+  SmallString<256> NativePath;
+  sys::path::native(Filename, NativePath);
+
+  for (unsigned I = 0, E = NativePath.size(); I != E; ++I) {
+    if (NativePath[I] == '#') {
+      OS << '\\';
+    } else if (NativePath[I] == ' ') {
+      OS << '\\';
+      unsigned J = I;
+      while (J > 0 && NativePath[--J] == '\\') {
----------------
jayfoad wrote:

Nit: don't need braces around a single physical line

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


More information about the llvm-commits mailing list