summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2014-03-14 03:07:38 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2014-03-14 03:07:38 +0000
commit6d0753d42a8344a23cc8b170ac29184cac47e8ce (patch)
tree92be428f1d5353a65c290af8d61f710f614380ca
parentf88731f293c7c6e9268e7d298a806bf29ea8aa2d (diff)
downloadbcm5719-llvm-6d0753d42a8344a23cc8b170ac29184cac47e8ce.tar.gz
bcm5719-llvm-6d0753d42a8344a23cc8b170ac29184cac47e8ce.zip
[Modules] Emit the module file paths as dependencies of the PCH when we are building one.
This is because the PCH is tied to the module files, if one of the module files changes or gets removed the build system should re-build the PCH file. rdar://16321245 llvm-svn: 203885
-rw-r--r--clang/include/clang/Driver/CC1Options.td2
-rw-r--r--clang/include/clang/Frontend/DependencyOutputOptions.h2
-rw-r--r--clang/include/clang/Serialization/ASTReader.h4
-rw-r--r--clang/lib/Driver/Tools.cpp3
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp1
-rw-r--r--clang/lib/Frontend/DependencyFile.cpp10
-rw-r--r--clang/lib/Serialization/ASTReader.cpp7
-rw-r--r--clang/test/Driver/pch-deps.c10
-rw-r--r--clang/test/Modules/dependency-gen-pch.m12
9 files changed, 50 insertions, 1 deletions
diff --git a/clang/include/clang/Driver/CC1Options.td b/clang/include/clang/Driver/CC1Options.td
index 66674ab442e..c6963816220 100644
--- a/clang/include/clang/Driver/CC1Options.td
+++ b/clang/include/clang/Driver/CC1Options.td
@@ -223,6 +223,8 @@ def dependent_lib : Joined<["--"], "dependent-lib=">,
def sys_header_deps : Flag<["-"], "sys-header-deps">,
HelpText<"Include system headers in dependency output">;
+def module_file_deps : Flag<["-"], "module-file-deps">,
+ HelpText<"Include module files in dependency output">;
def header_include_file : Separate<["-"], "header-include-file">,
HelpText<"Filename (or -) to write header include output to">;
def show_includes : Flag<["--"], "show-includes">,
diff --git a/clang/include/clang/Frontend/DependencyOutputOptions.h b/clang/include/clang/Frontend/DependencyOutputOptions.h
index fefb6f3eda8..d275249987f 100644
--- a/clang/include/clang/Frontend/DependencyOutputOptions.h
+++ b/clang/include/clang/Frontend/DependencyOutputOptions.h
@@ -26,6 +26,7 @@ public:
/// problems.
unsigned AddMissingHeaderDeps : 1; ///< Add missing headers to dependency list
unsigned PrintShowIncludes : 1; ///< Print cl.exe style /showIncludes info.
+ unsigned IncludeModuleFiles : 1; ///< Include module file dependencies.
/// The file to write dependency output to.
std::string OutputFile;
@@ -50,6 +51,7 @@ public:
UsePhonyTargets = 0;
AddMissingHeaderDeps = 0;
PrintShowIncludes = 0;
+ IncludeModuleFiles = 0;
}
};
diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h
index d636795a397..07ab9e372e4 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -171,6 +171,9 @@ public:
virtual void ReadCounter(const serialization::ModuleFile &M,
unsigned Value) {}
+ /// This is called for each AST file loaded.
+ virtual void visitModuleFile(StringRef Filename) {}
+
/// \brief Returns true if this \c ASTReaderListener wants to receive the
/// input files of the AST file via \c visitInputFile, false otherwise.
virtual bool needsInputFileVisitation() { return false; }
@@ -217,6 +220,7 @@ public:
void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
bool needsInputFileVisitation() override;
bool needsSystemInputFileVisitation() override;
+ void visitModuleFile(StringRef Filename) override;
bool visitInputFile(StringRef Filename, bool isSystem,
bool isOverridden) override;
};
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index 72f781d3cff..73f8aa8aafe 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -295,6 +295,9 @@ void Clang::AddPreprocessingOptions(Compilation &C,
if (A->getOption().matches(options::OPT_M) ||
A->getOption().matches(options::OPT_MD))
CmdArgs.push_back("-sys-header-deps");
+
+ if (isa<PrecompileJobAction>(JA))
+ CmdArgs.push_back("-module-file-deps");
}
if (Args.hasArg(options::OPT_MG)) {
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index f368837a5f0..7cc0b1bee30 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -528,6 +528,7 @@ static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts,
Opts.OutputFile = Args.getLastArgValue(OPT_dependency_file);
Opts.Targets = Args.getAllArgValues(OPT_MT);
Opts.IncludeSystemHeaders = Args.hasArg(OPT_sys_header_deps);
+ Opts.IncludeModuleFiles = Args.hasArg(OPT_module_file_deps);
Opts.UsePhonyTargets = Args.hasArg(OPT_MP);
Opts.ShowHeaderIncludes = Args.hasArg(OPT_H);
Opts.HeaderIncludeOutputFile = Args.getLastArgValue(OPT_header_include_file);
diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp
index 8457770abb9..b472eaaae05 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -40,6 +40,7 @@ class DFGImpl : public PPCallbacks {
bool PhonyTarget;
bool AddMissingHeaderDeps;
bool SeenMissingHeader;
+ bool IncludeModuleFiles;
private:
bool FileMatchesDepCriteria(const char *Filename,
SrcMgr::CharacteristicKind FileType);
@@ -51,7 +52,8 @@ public:
IncludeSystemHeaders(Opts.IncludeSystemHeaders),
PhonyTarget(Opts.UsePhonyTargets),
AddMissingHeaderDeps(Opts.AddMissingHeaderDeps),
- SeenMissingHeader(false) {}
+ SeenMissingHeader(false),
+ IncludeModuleFiles(Opts.IncludeModuleFiles) {}
void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
@@ -68,6 +70,7 @@ public:
void AddFilename(StringRef Filename);
bool includeSystemHeaders() const { return IncludeSystemHeaders; }
+ bool includeModuleFiles() const { return IncludeModuleFiles; }
};
class DFGASTReaderListener : public ASTReaderListener {
@@ -79,6 +82,7 @@ public:
bool needsSystemInputFileVisitation() override {
return Parent.includeSystemHeaders();
}
+ void visitModuleFile(StringRef Filename) override;
bool visitInputFile(StringRef Filename, bool isSystem,
bool isOverridden) override;
};
@@ -268,3 +272,7 @@ bool DFGASTReaderListener::visitInputFile(llvm::StringRef Filename,
return true;
}
+void DFGASTReaderListener::visitModuleFile(llvm::StringRef Filename) {
+ if (Parent.includeModuleFiles())
+ Parent.AddFilename(Filename);
+}
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index cc425c5695a..766fe27bc6c 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -118,6 +118,10 @@ bool ChainedASTReaderListener::needsSystemInputFileVisitation() {
return First->needsSystemInputFileVisitation() ||
Second->needsSystemInputFileVisitation();
}
+void ChainedASTReaderListener::visitModuleFile(StringRef Filename) {
+ First->visitModuleFile(Filename);
+ Second->visitModuleFile(Filename);
+}
bool ChainedASTReaderListener::visitInputFile(StringRef Filename,
bool isSystem,
bool isOverridden) {
@@ -2118,6 +2122,9 @@ ASTReader::ReadControlBlock(ModuleFile &F,
}
}
+ if (Listener)
+ Listener->visitModuleFile(F.FileName);
+
if (Listener && Listener->needsInputFileVisitation()) {
unsigned N = Listener->needsSystemInputFileVisitation() ? NumInputs
: NumUserInputs;
diff --git a/clang/test/Driver/pch-deps.c b/clang/test/Driver/pch-deps.c
new file mode 100644
index 00000000000..30486364cd4
--- /dev/null
+++ b/clang/test/Driver/pch-deps.c
@@ -0,0 +1,10 @@
+// RUN: %clang -x c-header %s -o %t.pch -MMD -MT dependencies -MF %t.d -### 2> %t
+// RUN: FileCheck %s -input-file=%t
+// CHECK: -emit-pch
+// CHECK: -dependency-file
+// CHECK: -module-file-deps
+
+// RUN: %clang -c %s -o %t -MMD -MT dependencies -MF %t.d -### 2> %t
+// RUN: FileCheck %s -check-prefix=CHECK-NOPCH -input-file=%t
+// CHECK-NOPCH: -dependency-file
+// CHECK-NOPCH-NOT: -module-file-deps
diff --git a/clang/test/Modules/dependency-gen-pch.m b/clang/test/Modules/dependency-gen-pch.m
new file mode 100644
index 00000000000..b0c75513d92
--- /dev/null
+++ b/clang/test/Modules/dependency-gen-pch.m
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t-mcp
+// RUN: mkdir -p %t-mcp
+
+// RUN: %clang_cc1 -isysroot %S/Inputs/System -triple x86_64-apple-darwin10 -module-file-deps -dependency-file %t.d -MT %s.o -I %S/Inputs -fmodules -fmodules-cache-path=%t-mcp -emit-pch -o %t.pch %s
+// RUN: FileCheck %s < %t.d
+// CHECK: dependency-gen-pch.m.o
+// CHECK-NEXT: dependency-gen-pch.m
+// CHECK-NEXT: diamond_top.pcm
+// CHECK-NEXT: Inputs{{.}}diamond_top.h
+// CHECK-NEXT: Inputs{{.}}module.map
+
+#import "diamond_top.h"
OpenPOWER on IntegriCloud