[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
Fri Sep 15 09:42:06 PDT 2023


================
@@ -330,3 +353,20 @@ DependencyScanningWorkerFilesystem::openFileForRead(const Twine &Path) {
     return Result.getError();
   return DepScanFile::create(Result.get());
 }
+
+std::error_code DependencyScanningWorkerFilesystem::setCurrentWorkingDirectory(
+    const Twine &Path) {
+  updateWorkingDirForCacheLookup(Path.str());
+  return ProxyFileSystem::setCurrentWorkingDirectory(Path);
+}
+
+void DependencyScanningWorkerFilesystem::updateWorkingDirForCacheLookup(
+    llvm::ErrorOr<std::string> CWD) {
+  if (CWD && !CWD->empty()) {
+    WorkingDirForCacheLookup = *CWD;
+  } else {
+    // The cache lookup functions will not accept relative paths for safety, so
+    // at least make it absolute from a "root".
+    WorkingDirForCacheLookup = "/";
----------------
benlangmuir wrote:

In this case the path will be used when **writing** to the cache though, right? That affects scan results for other TUs just like you are fixing in this PR.

I'm not clear what recovery means here: I think what we want is that the scanner reports an error and stops processing the current TU.  We don't get value from partial scanner results for the current TU like we might for an IDE AST query.

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


More information about the cfe-commits mailing list