kousikk updated this revision to Diff 222953.
kousikk added a comment.
Update diff to include all commits
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68193/new/
https://reviews.llvm.org/D68193
Files:
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
Index: clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
===================================================================
--- /dev/null
+++ clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
@@ -0,0 +1,21 @@
+// RUN: rm -rf %t.dir
+// RUN: rm -rf %t.dir/foodir
+// RUN: rm -rf %t.cdb
+
+// RUN: mkdir -p %t.dir
+// RUN: mkdir -p %t.dir/foodir
+
+// RUN: cp %S/Inputs/header.h %t.dir/foodir/foodirheader.h
+// RUN: cp %s %t.dir/headerwithdirname_input.cpp
+// RUN: mkdir %t.dir/Inputs
+// RUN: cp %S/Inputs/foodir %t.dir/Inputs/foodir
+// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/headerwithdirnamefollowedbyinclude.json > %t.cdb
+//
+// RUN: clang-scan-deps -compilation-database %t.cdb -j 1 | FileCheck %s
+
+#include <foodir>
+#include "foodir/foodirheader.h"
+
+// CHECK: headerwithdirname_input.o
+// CHECK-NEXT: headerwithdirname_input.cpp
+// CHECK-NEXT: Inputs{{/|\\}}foodir
Index: clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
===================================================================
--- /dev/null
+++ clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
@@ -0,0 +1,7 @@
+[
+ {
+ "directory": "DIR",
+ "command": "clang -c -IDIR -IInputs DIR/headerwithdirname_input.cpp",
+ "file": "DIR/headerwithdirname_input.cpp"
+ }
+]
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===================================================================
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -15,20 +15,19 @@
using namespace tooling;
using namespace dependencies;
+
CachedFileSystemEntry CachedFileSystemEntry::createFileEntry(
- StringRef Filename, llvm::vfs::FileSystem &FS, bool Minimize) {
+ llvm::vfs::Status &&Stat, llvm::vfs::FileSystem &FS, bool Minimize) {
// Load the file and its content from the file system.
+ StringRef Filename = Stat.getName();
llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>> MaybeFile =
FS.openFileForRead(Filename);
if (!MaybeFile)
return MaybeFile.getError();
- llvm::ErrorOr<llvm::vfs::Status> Stat = (*MaybeFile)->status();
- if (!Stat)
- return Stat.getError();
llvm::vfs::File &F = **MaybeFile;
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MaybeBuffer =
- F.getBuffer(Stat->getName());
+ F.getBuffer(Filename);
if (!MaybeBuffer)
return MaybeBuffer.getError();
@@ -42,7 +41,7 @@
// if the minimization failed.
// FIXME: Propage the diagnostic if desired by the client.
CachedFileSystemEntry Result;
- Result.MaybeStat = std::move(*Stat);
+ Result.MaybeStat = Stat;
Result.Contents.reserve(Buffer->getBufferSize() + 1);
Result.Contents.append(Buffer->getBufferStart(), Buffer->getBufferEnd());
// Implicitly null terminate the contents for Clang's lexer.
@@ -53,10 +52,10 @@
CachedFileSystemEntry Result;
size_t Size = MinimizedFileContents.size();
- Result.MaybeStat = llvm::vfs::Status(Stat->getName(), Stat->getUniqueID(),
- Stat->getLastModificationTime(),
- Stat->getUser(), Stat->getGroup(), Size,
- Stat->getType(), Stat->getPermissions());
+ Result.MaybeStat = llvm::vfs::Status(Stat.getName(), Stat.getUniqueID(),
+ Stat.getLastModificationTime(),
+ Stat.getUser(), Stat.getGroup(), Size,
+ Stat.getType(), Stat.getPermissions());
// The contents produced by the minimizer must be null terminated.
assert(MinimizedFileContents.data()[MinimizedFileContents.size()] == '\0' &&
"not null terminated contents");
@@ -122,14 +121,11 @@
return It.first->getValue();
}
-llvm::ErrorOr<llvm::vfs::Status>
-DependencyScanningWorkerFilesystem::status(const Twine &Path) {
- SmallString<256> OwnedFilename;
- StringRef Filename = Path.toStringRef(OwnedFilename);
-
- // Check the local cache first.
- if (const CachedFileSystemEntry *Entry = getCachedEntry(Filename))
- return Entry->getStatus();
+llvm::ErrorOr<const CachedFileSystemEntry *>
+DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry(const StringRef Filename) {
+ if (const CachedFileSystemEntry* Entry = getCachedEntry(Filename)) {
+ return Entry;
+ }
// FIXME: Handle PCM/PCH files.
// FIXME: Handle module map files.
@@ -152,7 +148,7 @@
std::move(*MaybeStatus));
else
CacheEntry = CachedFileSystemEntry::createFileEntry(
- Filename, FS, !KeepOriginalSource);
+ std::move(*MaybeStatus), FS, !KeepOriginalSource);
}
Result = &CacheEntry;
@@ -160,7 +156,17 @@
// Store the result in the local cache.
setCachedEntry(Filename, Result);
- return Result->getStatus();
+ return Result;
+}
+
+llvm::ErrorOr<llvm::vfs::Status>
+DependencyScanningWorkerFilesystem::status(const Twine &Path) {
+ SmallString<256> OwnedFilename;
+ StringRef Filename = Path.toStringRef(OwnedFilename);
+ const llvm::ErrorOr<const CachedFileSystemEntry *> Result = getOrCreateFileSystemEntry(Filename);
+ if (!Result)
+ return Result.getError();
+ return (*Result)->getStatus();
}
namespace {
@@ -217,30 +223,8 @@
SmallString<256> OwnedFilename;
StringRef Filename = Path.toStringRef(OwnedFilename);
- // Check the local cache first.
- if (const CachedFileSystemEntry *Entry = getCachedEntry(Filename))
- return createFile(Entry, PPSkipMappings);
-
- // FIXME: Handle PCM/PCH files.
- // FIXME: Handle module map files.
-
- bool KeepOriginalSource = IgnoredFiles.count(Filename);
- DependencyScanningFilesystemSharedCache::SharedFileSystemEntry
- &SharedCacheEntry = SharedCache.get(Filename);
- const CachedFileSystemEntry *Result;
- {
- std::unique_lock<std::mutex> LockGuard(SharedCacheEntry.ValueLock);
- CachedFileSystemEntry &CacheEntry = SharedCacheEntry.Value;
-
- if (!CacheEntry.isValid()) {
- CacheEntry = CachedFileSystemEntry::createFileEntry(
- Filename, getUnderlyingFS(), !KeepOriginalSource);
- }
-
- Result = &CacheEntry;
- }
-
- // Store the result in the local cache.
- setCachedEntry(Filename, Result);
- return createFile(Result, PPSkipMappings);
+ const llvm::ErrorOr<const CachedFileSystemEntry *> Result = getOrCreateFileSystemEntry(Filename);
+ if (!Result)
+ return Result.getError();
+ return createFile(Result.get(), PPSkipMappings);
}
Index: clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
===================================================================
--- clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -46,7 +46,7 @@
/// mismatching size of the file. If file is not minimized, the full file is
/// read and copied into memory to ensure that it's not memory mapped to avoid
/// running out of file descriptors.
- static CachedFileSystemEntry createFileEntry(StringRef Filename,
+ static CachedFileSystemEntry createFileEntry(llvm::vfs::Status &&Stat,
llvm::vfs::FileSystem &FS,
bool Minimize = true);
@@ -80,6 +80,11 @@
return MaybeStat->getName();
}
+ std::error_code getError() const {
+ assert(isValid() && "not initialized");
+ return MaybeStat.getError();
+ }
+
/// Return the mapping between location -> distance that is used to speed up
/// the block skipping in the preprocessor.
const PreprocessorSkippedRangeMapping &getPPSkippedRangeMapping() const {
@@ -168,6 +173,9 @@
return It == Cache.end() ? nullptr : It->getValue();
}
+ llvm::ErrorOr<const CachedFileSystemEntry *>
+ getOrCreateFileSystemEntry(const StringRef Filename);
+
DependencyScanningFilesystemSharedCache &SharedCache;
/// The local cache is used by the worker thread to cache file system queries
/// locally instead of querying the global cache every time.
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits