keith created this revision. keith added a reviewer: JDevlieghere. Herald added subscribers: dexonsmith, hiraditya. keith requested review of this revision. Herald added projects: clang, LLVM. Herald added subscribers: llvm-commits, cfe-commits.
This is a follow up to 0be9ca7c0f9a733f846bb6bc4e8e36d46b518162 <https://reviews.llvm.org/rG0be9ca7c0f9a733f846bb6bc4e8e36d46b518162> to make paths in the case of falling back to the external file system use the original format, preserving relative paths, and allow the external filesystem to canonicalize them if needed. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D109128 Files: clang/test/VFS/relative-path-errors.c llvm/lib/Support/VirtualFileSystem.cpp Index: llvm/lib/Support/VirtualFileSystem.cpp =================================================================== --- llvm/lib/Support/VirtualFileSystem.cpp +++ llvm/lib/Support/VirtualFileSystem.cpp @@ -1202,7 +1202,7 @@ if (!Result) { EC = Result.getError(); if (shouldFallBackToExternalFS(EC)) - return ExternalFS->dir_begin(Path, EC); + return ExternalFS->dir_begin(Dir, EC); return {}; } @@ -1967,13 +1967,13 @@ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath(Path); if (!Result) { if (shouldFallBackToExternalFS(Result.getError())) - return ExternalFS->status(Path); + return ExternalFS->status(Path_); return Result.getError(); } ErrorOr<Status> S = status(Path, *Result); if (!S && shouldFallBackToExternalFS(S.getError(), Result->E)) - S = ExternalFS->status(Path); + S = ExternalFS->status(Path_); return S; } @@ -2013,7 +2013,7 @@ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath(Path); if (!Result) { if (shouldFallBackToExternalFS(Result.getError())) - return ExternalFS->openFileForRead(Path); + return ExternalFS->openFileForRead(Path_); return Result.getError(); } @@ -2026,7 +2026,7 @@ auto ExternalFile = ExternalFS->openFileForRead(ExtRedirect); if (!ExternalFile) { if (shouldFallBackToExternalFS(ExternalFile.getError(), Result->E)) - return ExternalFS->openFileForRead(Path); + return ExternalFS->openFileForRead(Path_); return ExternalFile; } @@ -2053,7 +2053,7 @@ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath(Path); if (!Result) { if (shouldFallBackToExternalFS(Result.getError())) - return ExternalFS->getRealPath(Path, Output); + return ExternalFS->getRealPath(Path_, Output); return Result.getError(); } @@ -2062,14 +2062,14 @@ if (auto ExtRedirect = Result->getExternalRedirect()) { auto P = ExternalFS->getRealPath(*ExtRedirect, Output); if (!P && shouldFallBackToExternalFS(P, Result->E)) { - return ExternalFS->getRealPath(Path, Output); + return ExternalFS->getRealPath(Path_, Output); } return P; } // If we found a DirectoryEntry, still fall back to ExternalFS if allowed, // because directories don't have a single external contents path. - return shouldUseExternalFS() ? ExternalFS->getRealPath(Path, Output) + return shouldUseExternalFS() ? ExternalFS->getRealPath(Path_, Output) : llvm::errc::invalid_argument; } Index: clang/test/VFS/relative-path-errors.c =================================================================== --- /dev/null +++ clang/test/VFS/relative-path-errors.c @@ -0,0 +1,8 @@ +// RUN: mkdir -p %t +// RUN: cd %t +// RUN: echo '{"roots": [],"version": 0}' > %t.yaml +// RUN: cp %s main.c +// RUN: not %clang_cc1 -ivfsoverlay %t.yaml main.c 2>&1 | FileCheck %s + +// CHECK: {{^}}main.c:8:1: error: +foobarbaz
Index: llvm/lib/Support/VirtualFileSystem.cpp =================================================================== --- llvm/lib/Support/VirtualFileSystem.cpp +++ llvm/lib/Support/VirtualFileSystem.cpp @@ -1202,7 +1202,7 @@ if (!Result) { EC = Result.getError(); if (shouldFallBackToExternalFS(EC)) - return ExternalFS->dir_begin(Path, EC); + return ExternalFS->dir_begin(Dir, EC); return {}; } @@ -1967,13 +1967,13 @@ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath(Path); if (!Result) { if (shouldFallBackToExternalFS(Result.getError())) - return ExternalFS->status(Path); + return ExternalFS->status(Path_); return Result.getError(); } ErrorOr<Status> S = status(Path, *Result); if (!S && shouldFallBackToExternalFS(S.getError(), Result->E)) - S = ExternalFS->status(Path); + S = ExternalFS->status(Path_); return S; } @@ -2013,7 +2013,7 @@ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath(Path); if (!Result) { if (shouldFallBackToExternalFS(Result.getError())) - return ExternalFS->openFileForRead(Path); + return ExternalFS->openFileForRead(Path_); return Result.getError(); } @@ -2026,7 +2026,7 @@ auto ExternalFile = ExternalFS->openFileForRead(ExtRedirect); if (!ExternalFile) { if (shouldFallBackToExternalFS(ExternalFile.getError(), Result->E)) - return ExternalFS->openFileForRead(Path); + return ExternalFS->openFileForRead(Path_); return ExternalFile; } @@ -2053,7 +2053,7 @@ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath(Path); if (!Result) { if (shouldFallBackToExternalFS(Result.getError())) - return ExternalFS->getRealPath(Path, Output); + return ExternalFS->getRealPath(Path_, Output); return Result.getError(); } @@ -2062,14 +2062,14 @@ if (auto ExtRedirect = Result->getExternalRedirect()) { auto P = ExternalFS->getRealPath(*ExtRedirect, Output); if (!P && shouldFallBackToExternalFS(P, Result->E)) { - return ExternalFS->getRealPath(Path, Output); + return ExternalFS->getRealPath(Path_, Output); } return P; } // If we found a DirectoryEntry, still fall back to ExternalFS if allowed, // because directories don't have a single external contents path. - return shouldUseExternalFS() ? ExternalFS->getRealPath(Path, Output) + return shouldUseExternalFS() ? ExternalFS->getRealPath(Path_, Output) : llvm::errc::invalid_argument; } Index: clang/test/VFS/relative-path-errors.c =================================================================== --- /dev/null +++ clang/test/VFS/relative-path-errors.c @@ -0,0 +1,8 @@ +// RUN: mkdir -p %t +// RUN: cd %t +// RUN: echo '{"roots": [],"version": 0}' > %t.yaml +// RUN: cp %s main.c +// RUN: not %clang_cc1 -ivfsoverlay %t.yaml main.c 2>&1 | FileCheck %s + +// CHECK: {{^}}main.c:8:1: error: +foobarbaz
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits