Author: arphaman Date: Tue Aug 27 10:32:42 2019 New Revision: 370081 URL: http://llvm.org/viewvc/llvm-project?rev=370081&view=rev Log: 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. Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h cfe/trunk/lib/Frontend/DependencyFile.cpp cfe/trunk/lib/Lex/PPMacroExpansion.cpp cfe/trunk/unittests/Tooling/DependencyScannerTest.cpp Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=370081&r1=370080&r2=370081&view=diff ============================================================================== --- cfe/trunk/include/clang/Lex/PPCallbacks.h (original) +++ cfe/trunk/include/clang/Lex/PPCallbacks.h Tue Aug 27 10:32:42 2019 @@ -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); Modified: cfe/trunk/lib/Frontend/DependencyFile.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DependencyFile.cpp?rev=370081&r1=370080&r2=370081&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/DependencyFile.cpp (original) +++ cfe/trunk/lib/Frontend/DependencyFile.cpp Tue Aug 27 10:32:42 2019 @@ -83,7 +83,7 @@ struct DepCollectorPPCallbacks : public } void HasInclude(SourceLocation Loc, StringRef SpelledFilename, bool IsAngled, - const FileEntry *File, + Optional<FileEntryRef> File, SrcMgr::CharacteristicKind FileType) override { if (!File) return; Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=370081&r1=370080&r2=370081&view=diff ============================================================================== --- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original) +++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Tue Aug 27 10:32:42 2019 @@ -1219,8 +1219,7 @@ static bool EvaluateHasIncludeCommon(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. Modified: cfe/trunk/unittests/Tooling/DependencyScannerTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/DependencyScannerTest.cpp?rev=370081&r1=370080&r2=370081&view=diff ============================================================================== --- cfe/trunk/unittests/Tooling/DependencyScannerTest.cpp (original) +++ cfe/trunk/unittests/Tooling/DependencyScannerTest.cpp Tue Aug 27 10:32:42 2019 @@ -161,5 +161,40 @@ TEST(DependencyScanner, ScanDepsReuseFil 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits