[PATCH] D67091: Fix for headers having the same name as a directory
Kousik Kumar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 12 07:42:07 PDT 2019
kousikk updated this revision to Diff 219917.
kousikk added a comment.
- Add tests and remove the fix inside createFile since it fails in other cases
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D67091/new/
https://reviews.llvm.org/D67091
Files:
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
clang/test/ClangScanDeps/Inputs/foodir
clang/test/ClangScanDeps/Inputs/headerwithdirname.json
clang/test/ClangScanDeps/headerwithdirname.cpp
Index: clang/test/ClangScanDeps/headerwithdirname.cpp
===================================================================
--- /dev/null
+++ clang/test/ClangScanDeps/headerwithdirname.cpp
@@ -0,0 +1,17 @@
+// 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 %t.dir/headerwithdirname.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/headerwithdirname.json > %t.cdb
+//
+// RUN: clang-scan-deps -compilation-database %t.cdb -j 1 | FileCheck %s
+
+#include <foodir>
+
+// CHECK: clang-scan-deps dependency
+// CHECK-NEXT: headerwithdirname.cpp
+// CHECK-NEXT: Inputs{{/|\\}}foodir
\ No newline at end of file
Index: clang/test/ClangScanDeps/Inputs/headerwithdirname.json
===================================================================
--- /dev/null
+++ clang/test/ClangScanDeps/Inputs/headerwithdirname.json
@@ -0,0 +1,7 @@
+[
+ {
+ "directory": "DIR",
+ "command": "clang -c -IDIR -IDIR/foodir -IInputs DIR/headerwithdirname.cpp",
+ "file": "DIR/headerwithdirname.cpp"
+ }
+]
Index: clang/test/ClangScanDeps/Inputs/foodir
===================================================================
--- /dev/null
+++ clang/test/ClangScanDeps/Inputs/foodir
@@ -0,0 +1 @@
+// A C++ header with same name as that of a directory in the include path.
\ No newline at end of file
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===================================================================
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -190,8 +190,11 @@
StringRef Filename = Path.toStringRef(OwnedFilename);
// Check the local cache first.
- if (const CachedFileSystemEntry *Entry = getCachedEntry(Filename))
+ if (const CachedFileSystemEntry *Entry = getCachedEntry(Filename)) {
+ if (Entry->isDirectory())
+ return llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>(std::make_error_code(std::errc::is_a_directory));
return createFile(Entry);
+ }
// FIXME: Handle PCM/PCH files.
// FIXME: Handle module map files.
Index: clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
===================================================================
--- clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -55,6 +55,11 @@
/// \returns True if the entry is valid.
bool isValid() const { return !MaybeStat || MaybeStat->isStatusKnown(); }
+ /// \returns True if the current entry points to a directory.
+ bool isDirectory() const {
+ return MaybeStat && MaybeStat->isDirectory();
+ }
+
/// \returns The error or the file's contents.
llvm::ErrorOr<StringRef> getContents() const {
if (!MaybeStat)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67091.219917.patch
Type: text/x-patch
Size: 2997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190912/e8ceb84d/attachment.bin>
More information about the cfe-commits
mailing list