[clang] [DependencyScanningFilesystem] Make sure the local/shared cache filename lookups use only absolute paths (PR #66122)

Ben Langmuir via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 18 14:17:43 PDT 2023


================
@@ -330,3 +359,24 @@ DependencyScanningWorkerFilesystem::openFileForRead(const Twine &Path) {
     return Result.getError();
   return DepScanFile::create(Result.get());
 }
+
+std::error_code DependencyScanningWorkerFilesystem::setCurrentWorkingDirectory(
+    const Twine &Path) {
+  std::error_code EC = ProxyFileSystem::setCurrentWorkingDirectory(Path);
+  updateWorkingDirForCacheLookup();
+  return EC;
+}
+
+void DependencyScanningWorkerFilesystem::updateWorkingDirForCacheLookup() {
+  llvm::ErrorOr<std::string> CWD =
+      getUnderlyingFS().getCurrentWorkingDirectory();
+  if (!CWD) {
+    WorkingDirForCacheLookup = CWD.getError();
+  } else if (!llvm::sys::path::is_absolute_gnu(*CWD)) {
+    WorkingDirForCacheLookup = llvm::errc::argument_out_of_domain;
----------------
benlangmuir wrote:

Nit: This is a slightly odd usage of `argument_out_of_domain` (`EDOM`). Normally that's for math functions. I would expect something more generic like `invalid_argument` (`EINVAL`).

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


More information about the cfe-commits mailing list