[clang] Relative Path Handling for Cross-Platform Compatibility (PR #133526)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 28 14:56:51 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Ayush Pareek (ayushpareek2003)
<details>
<summary>Changes</summary>
Both Unix (./, ../) and Windows (.\, ..\) path formats are handled properly
---
Full diff: https://github.com/llvm/llvm-project/pull/133526.diff
1 Files Affected:
- (modified) clang/lib/Tooling/Tooling.cpp (+13-2)
``````````diff
diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 03523c3f17eda..51508d123eb32 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -255,8 +255,19 @@ llvm::Expected<std::string> getAbsolutePath(llvm::vfs::FileSystem &FS,
StringRef File) {
StringRef RelativePath(File);
// FIXME: Should '.\\' be accepted on Win32?
- RelativePath.consume_front("./");
-
+ if (RelativePath.startswith("./")) {
+ // Unix-like relative path
+ RelativePath = RelativePath.drop_front(2);
+ } else if (RelativePath.startswith(".\\")) {
+ // Windows-style relative path
+ RelativePath = RelativePath.drop_front(2);
+ } else if (RelativePath.startswith("../")) {
+ // Unix-like parent directory reference
+ RelativePath = RelativePath.drop_front(3);
+ } else if (RelativePath.startswith("..\\")) {
+ // Windows-style parent directory reference
+ RelativePath = RelativePath.drop_front(3);
+ }
SmallString<1024> AbsolutePath = RelativePath;
if (auto EC = FS.makeAbsolute(AbsolutePath))
return llvm::errorCodeToError(EC);
``````````
</details>
https://github.com/llvm/llvm-project/pull/133526
More information about the cfe-commits
mailing list