r369998 - Use FileEntryRef for PPCallbacks::FileSkipped
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 26 18:03:26 PDT 2019
Author: arphaman
Date: Mon Aug 26 18:03:25 2019
New Revision: 369998
URL: http://llvm.org/viewvc/llvm-project?rev=369998&view=rev
Log:
Use FileEntryRef for PPCallbacks::FileSkipped
This fixes the issue where a filename dependendency was missing if the file that
was skipped was included 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/Frontend/Rewrite/InclusionRewriter.cpp
cfe/trunk/lib/Lex/PPDirectives.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=369998&r1=369997&r2=369998&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Mon Aug 26 18:03:25 2019
@@ -57,10 +57,9 @@ public:
/// \param FilenameTok The file name token in \#include "FileName" directive
/// or macro expanded file name token from \#include MACRO(PARAMS) directive.
/// Note that FilenameTok contains corresponding quotes/angles symbols.
- virtual void FileSkipped(const FileEntry &SkippedFile,
+ virtual void FileSkipped(const FileEntryRef &SkippedFile,
const Token &FilenameTok,
- SrcMgr::CharacteristicKind FileType) {
- }
+ SrcMgr::CharacteristicKind FileType) {}
/// Callback invoked whenever an inclusion directive results in a
/// file-not-found error.
@@ -390,8 +389,7 @@ public:
Second->FileChanged(Loc, Reason, FileType, PrevFID);
}
- void FileSkipped(const FileEntry &SkippedFile,
- const Token &FilenameTok,
+ void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok,
SrcMgr::CharacteristicKind FileType) override {
First->FileSkipped(SkippedFile, FilenameTok, FileType);
Second->FileSkipped(SkippedFile, FilenameTok, FileType);
Modified: cfe/trunk/lib/Frontend/DependencyFile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DependencyFile.cpp?rev=369998&r1=369997&r2=369998&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/DependencyFile.cpp (original)
+++ cfe/trunk/lib/Frontend/DependencyFile.cpp Mon Aug 26 18:03:25 2019
@@ -59,7 +59,7 @@ struct DepCollectorPPCallbacks : public
/*IsModuleFile*/false, /*IsMissing*/false);
}
- void FileSkipped(const FileEntry &SkippedFile, const Token &FilenameTok,
+ void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok,
SrcMgr::CharacteristicKind FileType) override {
StringRef Filename =
llvm::sys::path::remove_leading_dotslash(SkippedFile.getName());
Modified: cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp?rev=369998&r1=369997&r2=369998&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp (original)
+++ cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp Mon Aug 26 18:03:25 2019
@@ -70,7 +70,7 @@ private:
void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override;
- void FileSkipped(const FileEntry &SkippedFile, const Token &FilenameTok,
+ void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok,
SrcMgr::CharacteristicKind FileType) override;
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
@@ -169,8 +169,8 @@ void InclusionRewriter::FileChanged(Sour
/// Called whenever an inclusion is skipped due to canonical header protection
/// macros.
-void InclusionRewriter::FileSkipped(const FileEntry &/*SkippedFile*/,
- const Token &/*FilenameTok*/,
+void InclusionRewriter::FileSkipped(const FileEntryRef & /*SkippedFile*/,
+ const Token & /*FilenameTok*/,
SrcMgr::CharacteristicKind /*FileType*/) {
assert(LastInclusionLocation.isValid() &&
"A file, that wasn't found via an inclusion directive, was skipped");
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=369998&r1=369997&r2=369998&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Mon Aug 26 18:03:25 2019
@@ -2029,7 +2029,7 @@ Preprocessor::ImportAction Preprocessor:
RelativePath, Action == Import ? SuggestedModule.getModule() : nullptr,
FileCharacter);
if (Action == Skip && File)
- Callbacks->FileSkipped(File->getFileEntry(), FilenameTok, FileCharacter);
+ Callbacks->FileSkipped(*File, FilenameTok, FileCharacter);
}
if (!File)
Modified: cfe/trunk/unittests/Tooling/DependencyScannerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/DependencyScannerTest.cpp?rev=369998&r1=369997&r2=369998&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/DependencyScannerTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/DependencyScannerTest.cpp Mon Aug 26 18:03:25 2019
@@ -37,7 +37,8 @@ public:
: DependencyFileGenerator(Opts), Deps(Deps) {}
void finishedMainFile(DiagnosticsEngine &Diags) override {
- Deps = getDependencies();
+ auto NewDeps = getDependencies();
+ Deps.insert(Deps.end(), NewDeps.begin(), NewDeps.end());
}
private:
@@ -121,5 +122,44 @@ TEST(DependencyScanner, ScanDepsReuseFil
EXPECT_EQ(Files.getNumUniqueRealFiles(), 2u);
}
+TEST(DependencyScanner, ScanDepsReuseFilemanagerSkippedFile) {
+ 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);
+ std::string Test2Path = llvm::formatv("{0}root{0}test2.cpp", Sept);
+
+ VFS->addFile(HeaderPath, 0,
+ llvm::MemoryBuffer::getMemBuffer("#pragma once\n"));
+ VFS->addHardLink(SymlinkPath, HeaderPath);
+ VFS->addFile(TestPath, 0,
+ llvm::MemoryBuffer::getMemBuffer(
+ "#include \"header.h\"\n#include \"symlink.h\"\n"));
+ VFS->addFile(Test2Path, 0,
+ llvm::MemoryBuffer::getMemBuffer(
+ "#include \"symlink.h\"\n#include \"header.h\"\n"));
+
+ ClangTool Tool(CDB, {"test.cpp", "test2.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/test2.cpp");
+ EXPECT_EQ(convert_to_slash(Deps[4]), "/root/symlink.h");
+ EXPECT_EQ(convert_to_slash(Deps[5]), "/root/header.h");
+}
+
} // end namespace tooling
} // end namespace clang
More information about the cfe-commits
mailing list