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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to