diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp @@ -233,8 +233,15 @@ CachedFileSystemEntry &CacheEntry = SharedCacheEntry.Value; if (!CacheEntry.isValid()) { + llvm::vfs::FileSystem &FS = getUnderlyingFS(); + auto MaybeStatus = FS.status(Filename); + + if (MaybeStatus && MaybeStatus->isDirectory()) + return llvm::ErrorOr>( + std::make_error_code(std::errc::is_a_directory)); + CacheEntry = CachedFileSystemEntry::createFileEntry( - Filename, getUnderlyingFS(), !KeepOriginalSource); + Filename, FS, !KeepOriginalSource); } Result = &CacheEntry; diff --git a/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json b/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json new file mode 100644 --- /dev/null +++ b/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" + } +] diff --git a/clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp b/clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp new file mode 100644 --- /dev/null +++ b/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 +#include "foodir/foodirheader.h" + +// CHECK: headerwithdirname_input.o +// CHECK-NEXT: headerwithdirname_input.cpp +// CHECK-NEXT: Inputs{{/|\\}}foodir