summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2019-08-27 17:32:42 +0000
committerAlex Lorenz <arphaman@gmail.com>2019-08-27 17:32:42 +0000
commit1c8a4b7204d311ecd7681ef907c4aab99fd91308 (patch)
tree048842701bd54ec5becd7ea88a192834e4e00c2a
parent3d9b39b733df56a97f47cf88d09b327e78d3d21c (diff)
downloadbcm5719-llvm-1c8a4b7204d311ecd7681ef907c4aab99fd91308.tar.gz
bcm5719-llvm-1c8a4b7204d311ecd7681ef907c4aab99fd91308.zip
Use FileEntryRef for PPCallbacks::HasInclude
This fixes the issue where a filename dependendency was missing if the file that was referenced with __has_include() was accessed through a symlink in an earlier run, if the file manager was reused between runs. llvm-svn: 370081
-rw-r--r--clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h2
-rw-r--r--clang/include/clang/Lex/PPCallbacks.h4
-rw-r--r--clang/lib/Frontend/DependencyFile.cpp2
-rw-r--r--clang/lib/Lex/PPMacroExpansion.cpp3
-rw-r--r--clang/unittests/Tooling/DependencyScannerTest.cpp35
6 files changed, 41 insertions, 7 deletions
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index 8da3c7ed721..d200718c6af 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -210,7 +210,7 @@ void ExpandModularHeadersPPCallbacks::PragmaDiagnostic(SourceLocation Loc,
parseToLocation(Loc);
}
void ExpandModularHeadersPPCallbacks::HasInclude(SourceLocation Loc, StringRef,
- bool, const FileEntry *,
+ bool, Optional<FileEntryRef>,
SrcMgr::CharacteristicKind) {
parseToLocation(Loc);
}
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
index 86028058770..30c8236e7f9 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
@@ -83,7 +83,7 @@ private:
void PragmaDiagnosticPop(SourceLocation Loc, StringRef) override;
void PragmaDiagnostic(SourceLocation Loc, StringRef, diag::Severity,
StringRef) override;
- void HasInclude(SourceLocation Loc, StringRef, bool, const FileEntry *,
+ void HasInclude(SourceLocation Loc, StringRef, bool, Optional<FileEntryRef> ,
SrcMgr::CharacteristicKind) override;
void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *,
SourceLocation StateLoc, unsigned) override;
diff --git a/clang/include/clang/Lex/PPCallbacks.h b/clang/include/clang/Lex/PPCallbacks.h
index 5f31b98a3cc..1edcb567de6 100644
--- a/clang/include/clang/Lex/PPCallbacks.h
+++ b/clang/include/clang/Lex/PPCallbacks.h
@@ -307,7 +307,7 @@ public:
/// Hook called when a '__has_include' or '__has_include_next' directive is
/// read.
virtual void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
- const FileEntry *File,
+ Optional<FileEntryRef> File,
SrcMgr::CharacteristicKind FileType) {}
/// Hook called when a source range is skipped.
@@ -489,7 +489,7 @@ public:
}
void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
- const FileEntry *File,
+ Optional<FileEntryRef> File,
SrcMgr::CharacteristicKind FileType) override {
First->HasInclude(Loc, FileName, IsAngled, File, FileType);
Second->HasInclude(Loc, FileName, IsAngled, File, FileType);
diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp
index 86e9ccfe3a4..b9c753d909a 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -83,7 +83,7 @@ struct DepCollectorPPCallbacks : public PPCallbacks {
}
void HasInclude(SourceLocation Loc, StringRef SpelledFilename, bool IsAngled,
- const FileEntry *File,
+ Optional<FileEntryRef> File,
SrcMgr::CharacteristicKind FileType) override {
if (!File)
return;
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp
index 3f5ee08b743..dfbcaedcacf 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1219,8 +1219,7 @@ static bool EvaluateHasIncludeCommon(Token &Tok,
if (File)
FileType =
PP.getHeaderSearchInfo().getFileDirFlavor(&File->getFileEntry());
- Callbacks->HasInclude(FilenameLoc, Filename, isAngled,
- File ? &File->getFileEntry() : nullptr, FileType);
+ Callbacks->HasInclude(FilenameLoc, Filename, isAngled, File, FileType);
}
// Get the result value. A result of true means the file exists.
diff --git a/clang/unittests/Tooling/DependencyScannerTest.cpp b/clang/unittests/Tooling/DependencyScannerTest.cpp
index 458bb9e0174..60f65661509 100644
--- a/clang/unittests/Tooling/DependencyScannerTest.cpp
+++ b/clang/unittests/Tooling/DependencyScannerTest.cpp
@@ -161,5 +161,40 @@ TEST(DependencyScanner, ScanDepsReuseFilemanagerSkippedFile) {
EXPECT_EQ(convert_to_slash(Deps[5]), "/root/header.h");
}
+TEST(DependencyScanner, ScanDepsReuseFilemanagerHasInclude) {
+ std::vector<std::string> Compilation = {"-c", "-E", "-MT", "test.cpp.o"};
+ StringRef CWD = "/root";
+ FixedCompilationDatabase CDB(CWD, Compilation);
+
+ auto VFS = new llvm::vfs::InMemoryFileSystem();
+ VFS->setCurrentWorkingDirectory(CWD);
+ auto Sept = llvm::sys::path::get_separator();
+ std::string HeaderPath = llvm::formatv("{0}root{0}header.h", Sept);
+ std::string SymlinkPath = llvm::formatv("{0}root{0}symlink.h", Sept);
+ std::string TestPath = llvm::formatv("{0}root{0}test.cpp", Sept);
+
+ VFS->addFile(HeaderPath, 0, llvm::MemoryBuffer::getMemBuffer("\n"));
+ VFS->addHardLink(SymlinkPath, HeaderPath);
+ VFS->addFile(
+ TestPath, 0,
+ llvm::MemoryBuffer::getMemBuffer("#if __has_include(\"header.h\") && "
+ "__has_include(\"symlink.h\")\n#endif"));
+
+ ClangTool Tool(CDB, {"test.cpp", "test.cpp"},
+ std::make_shared<PCHContainerOperations>(), VFS);
+ Tool.clearArgumentsAdjusters();
+ std::vector<std::string> Deps;
+ TestDependencyScanningAction Action(Deps);
+ Tool.run(&Action);
+ using llvm::sys::path::convert_to_slash;
+ ASSERT_EQ(Deps.size(), 6u);
+ EXPECT_EQ(convert_to_slash(Deps[0]), "/root/test.cpp");
+ EXPECT_EQ(convert_to_slash(Deps[1]), "/root/header.h");
+ EXPECT_EQ(convert_to_slash(Deps[2]), "/root/symlink.h");
+ EXPECT_EQ(convert_to_slash(Deps[3]), "/root/test.cpp");
+ EXPECT_EQ(convert_to_slash(Deps[4]), "/root/header.h");
+ EXPECT_EQ(convert_to_slash(Deps[5]), "/root/symlink.h");
+}
+
} // end namespace tooling
} // end namespace clang
OpenPOWER on IntegriCloud