https://github.com/matts1 created https://github.com/llvm/llvm-project/pull/174050
Fixes #174037 >From f3ebe11689570a418f53e80a015fbeeff8ee39ba Mon Sep 17 00:00:00 2001 From: Matt Stark <[email protected]> Date: Wed, 31 Dec 2025 11:56:27 +1100 Subject: [PATCH] [modules] Normalize filenames in AST files. Fixes #174037 --- clang/lib/Serialization/ASTReader.cpp | 6 ++++++ clang/lib/Serialization/ASTWriter.cpp | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 57771aad0c317..cb60c2cba48f1 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -3014,6 +3014,12 @@ ASTReader::TemporarilyOwnedStringRef ASTReader::ResolveImportedPath(SmallString<0> &Buf, StringRef Path, StringRef Prefix) { assert(Buf.capacity() != 0 && "Overlapping ResolveImportedPath calls"); + // ASTWriter always writes in posix form. + // Thus, we skip converting it to native form if we're already in posix + // (since that would convert backslashes to forward slashes). + // if (!llvm::sys::path::is_style_posix(llvm::sys::path::Style::native)) { + // llvm::sys::path::native(Buf, llvm::sys::path::Style::native); + // } if (Prefix.empty() || Path.empty() || llvm::sys::path::is_absolute(Path) || Path == "<built-in>" || Path == "<command line>") diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 234615522e773..0fa5e9832a0f4 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -5372,6 +5372,20 @@ bool ASTWriter::PreparePathForOutput(SmallVectorImpl<char> &Path) { Changed = true; } + // We convert all paths to their slash forms to ensure that a + // Linux -> $TARGET and a Windows -> $TARGET compile can share PCMs. + // The below is the equivalent of llvm::sys::path::convert_to_slash. + // We don't use it directly because: + // * It creates a copy rather than mutating the path. + // * There's no way to detect whether it's changed without the copy, + // so the copy can't be optimized out. + if (llvm::sys::path::is_style_windows(llvm::sys::path::Style::native)) { + if (llvm::is_contained(Path, '\\')) { + llvm::replace(Path, '\\', '/'); + Changed = true; + } + } + return Changed; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
