[clang-tools-extra] r370081 - Use FileEntryRef for PPCallbacks::HasInclude

2019-08-27 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Aug 27 10:32:42 2019
New Revision: 370081

URL: http://llvm.org/viewvc/llvm-project?rev=370081=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:
clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.h

Modified: clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.cpp?rev=370081=370080=370081=diff
==
--- clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.cpp Tue 
Aug 27 10:32:42 2019
@@ -210,7 +210,7 @@ void ExpandModularHeadersPPCallbacks::Pr
   parseToLocation(Loc);
 }
 void ExpandModularHeadersPPCallbacks::HasInclude(SourceLocation Loc, StringRef,
- bool, const FileEntry *,
+ bool, Optional,
  SrcMgr::CharacteristicKind) {
   parseToLocation(Loc);
 }

Modified: clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.h?rev=370081=370080=370081=diff
==
--- clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.h 
(original)
+++ clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.h Tue 
Aug 27 10:32:42 2019
@@ -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 ,
   SrcMgr::CharacteristicKind) override;
   void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *,
  SourceLocation StateLoc, unsigned) override;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r370081 - Use FileEntryRef for PPCallbacks::HasInclude

2019-08-27 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Aug 27 10:32:42 2019
New Revision: 370081

URL: http://llvm.org/viewvc/llvm-project?rev=370081=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=370080=370081=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 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 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=370080=370081=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 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=370080=370081=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(>getFileEntry());
-Callbacks->HasInclude(FilenameLoc, Filename, isAngled,
-  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=370080=370081=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 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(), VFS);
+  Tool.clearArgumentsAdjusters();
+  std::vector Deps;
+  TestDependencyScanningAction Action(Deps);
+  Tool.run();
+  using llvm::sys::path::convert_to_slash;
+  ASSERT_EQ(Deps.size(), 6u);
+