[PATCH] D30881: Track skipped files in dependency scanning
Pete Cooper via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 13 00:10:59 PDT 2017
pete created this revision.
Its possible for a header to be a symlink to another header. In this case, both are actually the same underlying file, and will both have the same include guards.
Because of this, if we #include the header, then #include the symlink, or vice versa, then one will get a FileChanged callback, and the next FileSkipped.
So that we get an accurate dependency file, we therefore need to also implement the FileSkipped callback in dependency scanning.
https://reviews.llvm.org/D30881
Files:
lib/Frontend/DependencyFile.cpp
test/Frontend/dependency-gen-symlink.c
Index: test/Frontend/dependency-gen-symlink.c
===================================================================
--- /dev/null
+++ test/Frontend/dependency-gen-symlink.c
@@ -0,0 +1,20 @@
+// REQUIRES: shell
+
+// Basic test
+// RUN: rm -rf %t.dir
+// RUN: mkdir %t.dir
+// RUN: mkdir %t.dir/a
+// RUN: mkdir %t.dir/b
+// RUN: echo "#ifndef HEADER_A" > %t.dir/a/header.h
+// RUN: echo "#define HEADER_A" >> %t.dir/a/header.h
+// RUN: echo "#endif" >> %t.dir/a/header.h
+// RUN: ln %t.dir/a/header.h %t.dir/b/header.h
+
+// RUN: %clang -MD -MF %t.dir/file.deps %s -fsyntax-only -I %t.dir
+// RUN: FileCheck -input-file=%t.dir/file.deps %s
+// CHECK: dependency-gen-symlink.o
+// CHECK: dependency-gen-symlink.c
+// CHECK: a/header.h
+// CHECK: b/header.h
+#include "a/header.h"
+#include "b/header.h"
Index: lib/Frontend/DependencyFile.cpp
===================================================================
--- lib/Frontend/DependencyFile.cpp
+++ lib/Frontend/DependencyFile.cpp
@@ -185,6 +185,11 @@
void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override;
+
+ void FileSkipped(const FileEntry &SkippedFile,
+ const Token &FilenameTok,
+ SrcMgr::CharacteristicKind FileType) override;
+
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange, const FileEntry *File,
@@ -291,6 +296,12 @@
AddFilename(llvm::sys::path::remove_leading_dotslash(Filename));
}
+void DFGImpl::FileSkipped(const FileEntry &SkippedFile,
+ const Token &FilenameTok,
+ SrcMgr::CharacteristicKind FileType) {
+ AddFilename(llvm::sys::path::remove_leading_dotslash(SkippedFile.getName()));
+}
+
void DFGImpl::InclusionDirective(SourceLocation HashLoc,
const Token &IncludeTok,
StringRef FileName,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30881.91518.patch
Type: text/x-patch
Size: 2063 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170313/18161690/attachment-0001.bin>
More information about the cfe-commits
mailing list