aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2013-01-25 00:45:27 +0000
committerDouglas Gregor <dgregor@apple.com>2013-01-25 00:45:27 +0000
commitf575d6e7c3b887ea4c5394d2c7e322c7a929a57e (patch)
tree325c8ea980071f606958a9412bb41b0bdcaa3678
parente169807aaea2464cbe68305f013ec7b41625af30 (diff)
Rename the -cc1 option "-generate-module-index" to
"-fmodules-global-index" and expand its behavior to include both the use and generation of the global module index. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173404 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Driver/CC1Options.td2
-rw-r--r--include/clang/Frontend/CompilerInstance.h10
-rw-r--r--include/clang/Frontend/FrontendOptions.h11
-rw-r--r--include/clang/Serialization/ASTReader.h12
-rw-r--r--lib/Frontend/CompilerInstance.cpp29
-rw-r--r--lib/Frontend/CompilerInvocation.cpp3
-rw-r--r--lib/Frontend/FrontendAction.cpp7
-rw-r--r--lib/Serialization/ASTReader.cpp3
-rw-r--r--test/Modules/global_index.m8
9 files changed, 61 insertions, 24 deletions
diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td
index 77fa82a35d..f9a255869b 100644
--- a/include/clang/Driver/CC1Options.td
+++ b/include/clang/Driver/CC1Options.td
@@ -289,7 +289,7 @@ def ast_dump_filter : Separate<["-"], "ast-dump-filter">,
HelpText<"Use with -ast-dump or -ast-print to dump/print only AST declaration"
" nodes having a certain substring in a qualified name. Use"
" -ast-list to list all filterable declaration node names.">;
-def generate_module_index : Flag<["-"], "generate-module-index">,
+def fmodules_global_index : Flag<["-"], "fmodules-global-index">,
HelpText<"Automatically generate or update the global module index">;
let Group = Action_Group in {
diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h
index d6b3afad8c..a17e1c8f5b 100644
--- a/include/clang/Frontend/CompilerInstance.h
+++ b/include/clang/Frontend/CompilerInstance.h
@@ -117,6 +117,9 @@ class CompilerInstance : public ModuleLoader {
/// have finished with this translation unit.
bool BuildGlobalModuleIndex;
+ /// \brief One or more modules failed to build.
+ bool ModuleBuildFailed;
+
/// \brief Holds information about the output file.
///
/// If TempFilename is not empty we must rename it to Filename at the end.
@@ -191,8 +194,8 @@ public:
void setInvocation(CompilerInvocation *Value);
/// \brief Indicates whether we should (re)build the global module index.
- bool getBuildGlobalModuleIndex() const { return BuildGlobalModuleIndex; }
-
+ bool shouldBuildGlobalModuleIndex() const;
+
/// \brief Set the flag indicating whether we should (re)build the global
/// module index.
void setBuildGlobalModuleIndex(bool Build) {
@@ -549,7 +552,8 @@ public:
bool DisablePCHValidation,
bool AllowPCHWithCompilerErrors,
Preprocessor &PP, ASTContext &Context,
- void *DeserializationListener, bool Preamble);
+ void *DeserializationListener, bool Preamble,
+ bool UseGlobalModuleIndex);
/// Create a code completion consumer using the invocation; note that this
/// will cause the source manager to truncate the input source file at the
diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h
index bb6da349ba..38162110f3 100644
--- a/include/clang/Frontend/FrontendOptions.h
+++ b/include/clang/Frontend/FrontendOptions.h
@@ -137,9 +137,11 @@ public:
/// speed up parsing in cases you do
/// not need them (e.g. with code
/// completion).
- unsigned GenerateModuleIndex : 1; ///< Whether to auto-generate a
- ///< global module index when a new
- ///< module has been built.
+ unsigned UseGlobalModuleIndex : 1; ///< Whether we can use the
+ ///< global module index if available.
+ unsigned GenerateGlobalModuleIndex : 1; ///< Whether we can generate the
+ ///< global module index if needed.
+
CodeCompleteOptions CodeCompleteOpts;
enum {
@@ -211,7 +213,8 @@ public:
ShowStats(false), ShowTimers(false), ShowVersion(false),
FixWhatYouCan(false), FixOnlyWarnings(false), FixAndRecompile(false),
FixToTemporaries(false), ARCMTMigrateEmitARCErrors(false),
- SkipFunctionBodies(false), GenerateModuleIndex(false),
+ SkipFunctionBodies(false), UseGlobalModuleIndex(false),
+ GenerateGlobalModuleIndex(false),
ARCMTAction(ARCMT_None), ObjCMTAction(ObjCMT_None),
ProgramAction(frontend::ParseSyntaxOnly)
{}
diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h
index cbd523b671..5d80e0d730 100644
--- a/include/clang/Serialization/ASTReader.h
+++ b/include/clang/Serialization/ASTReader.h
@@ -692,6 +692,12 @@ private:
/// \brief Whether to accept an AST file with compiler errors.
bool AllowASTWithCompilerErrors;
+ /// \brief Whether we are allowed to use the global module index.
+ bool UseGlobalIndex;
+
+ /// \brief Whether we have tried loading the global module index yet.
+ bool TriedLoadingGlobalIndex;
+
/// \brief The current "generation" of the module file import stack, which
/// indicates how many separate module file load operations have occurred.
unsigned CurrentGeneration;
@@ -1081,9 +1087,13 @@ public:
/// \param AllowASTWithCompilerErrors If true, the AST reader will accept an
/// AST file the was created out of an AST with compiler errors,
/// otherwise it will reject it.
+ ///
+ /// \param UseGlobalIndex If true, the AST reader will try to load and use
+ /// the global module index.
ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot = "",
bool DisableValidation = false,
- bool AllowASTWithCompilerErrors = false);
+ bool AllowASTWithCompilerErrors = false,
+ bool UseGlobalIndex = true);
~ASTReader();
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp
index 07c0248b6c..0e60c39922 100644
--- a/lib/Frontend/CompilerInstance.cpp
+++ b/lib/Frontend/CompilerInstance.cpp
@@ -49,7 +49,7 @@ using namespace clang;
CompilerInstance::CompilerInstance()
: Invocation(new CompilerInvocation()), ModuleManager(0),
- BuildGlobalModuleIndex(false) {
+ BuildGlobalModuleIndex(false), ModuleBuildFailed(false) {
}
CompilerInstance::~CompilerInstance() {
@@ -60,6 +60,10 @@ void CompilerInstance::setInvocation(CompilerInvocation *Value) {
Invocation = Value;
}
+bool CompilerInstance::shouldBuildGlobalModuleIndex() const {
+ return BuildGlobalModuleIndex && !ModuleBuildFailed;
+}
+
void CompilerInstance::setDiagnostics(DiagnosticsEngine *Value) {
Diagnostics = Value;
}
@@ -290,7 +294,8 @@ void CompilerInstance::createPCHExternalASTSource(StringRef Path,
AllowPCHWithCompilerErrors,
getPreprocessor(), getASTContext(),
DeserializationListener,
- Preamble));
+ Preamble,
+ getFrontendOpts().UseGlobalModuleIndex));
ModuleManager = static_cast<ASTReader*>(Source.get());
getASTContext().setExternalSource(Source);
}
@@ -303,12 +308,14 @@ CompilerInstance::createPCHExternalASTSource(StringRef Path,
Preprocessor &PP,
ASTContext &Context,
void *DeserializationListener,
- bool Preamble) {
+ bool Preamble,
+ bool UseGlobalModuleIndex) {
OwningPtr<ASTReader> Reader;
Reader.reset(new ASTReader(PP, Context,
Sysroot.empty() ? "" : Sysroot.c_str(),
DisablePCHValidation,
- AllowPCHWithCompilerErrors));
+ AllowPCHWithCompilerErrors,
+ UseGlobalModuleIndex));
Reader->setDeserializationListener(
static_cast<ASTDeserializationListener *>(DeserializationListener));
@@ -786,7 +793,7 @@ static void compileModule(CompilerInstance &ImportingInstance,
FrontendOptions &FrontendOpts = Invocation->getFrontendOpts();
FrontendOpts.OutputFile = ModuleFileName.str();
FrontendOpts.DisableFree = false;
- FrontendOpts.GenerateModuleIndex = false;
+ FrontendOpts.GenerateGlobalModuleIndex = false;
FrontendOpts.Inputs.clear();
InputKind IK = getSourceInputKindFromOptions(*Invocation->getLangOpts());
@@ -863,7 +870,7 @@ static void compileModule(CompilerInstance &ImportingInstance,
// We've rebuilt a module. If we're allowed to generate or update the global
// module index, record that fact in the importing compiler instance.
- if (ImportingInstance.getFrontendOpts().GenerateModuleIndex) {
+ if (ImportingInstance.getFrontendOpts().GenerateGlobalModuleIndex) {
ImportingInstance.setBuildGlobalModuleIndex(true);
}
}
@@ -953,7 +960,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
getDiagnostics().Report(ModuleNameLoc, diag::err_module_not_built)
<< ModuleName
<< SourceRange(ImportLoc, ModuleNameLoc);
-
+ ModuleBuildFailed = true;
return ModuleLoadResult();
}
@@ -971,6 +978,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
: diag::err_module_not_found)
<< ModuleName
<< SourceRange(ImportLoc, ModuleNameLoc);
+ ModuleBuildFailed = true;
return ModuleLoadResult();
}
@@ -983,7 +991,9 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
const PreprocessorOptions &PPOpts = getPreprocessorOpts();
ModuleManager = new ASTReader(getPreprocessor(), *Context,
Sysroot.empty() ? "" : Sysroot.c_str(),
- PPOpts.DisablePCHValidation);
+ PPOpts.DisablePCHValidation,
+ /*AllowASTWithCompilerErrors=*/false,
+ getFrontendOpts().UseGlobalModuleIndex);
if (hasASTConsumer()) {
ModuleManager->setDeserializationListener(
getASTConsumer().GetASTDeserializationListener());
@@ -1024,6 +1034,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
getDiagnostics().Report(ModuleNameLoc, diag::err_module_not_built)
<< ModuleName
<< SourceRange(ImportLoc, ModuleNameLoc);
+ ModuleBuildFailed = true;
return ModuleLoadResult();
}
@@ -1039,6 +1050,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
if (getPreprocessorOpts().FailedModules)
getPreprocessorOpts().FailedModules->addFailed(ModuleName);
KnownModules[Path[0].first] = 0;
+ ModuleBuildFailed = true;
return ModuleLoadResult();
}
@@ -1057,6 +1069,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
case ASTReader::Failure:
// Already complained, but note now that we failed.
KnownModules[Path[0].first] = 0;
+ ModuleBuildFailed = true;
return ModuleLoadResult();
}
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 9c94dfe87e..e135ad48bd 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -689,7 +689,8 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
Opts.FixAndRecompile = Args.hasArg(OPT_fixit_recompile);
Opts.FixToTemporaries = Args.hasArg(OPT_fixit_to_temp);
Opts.ASTDumpFilter = Args.getLastArgValue(OPT_ast_dump_filter);
- Opts.GenerateModuleIndex = Args.hasArg(OPT_generate_module_index);
+ Opts.UseGlobalModuleIndex = Args.hasArg(OPT_fmodules_global_index);
+ Opts.GenerateGlobalModuleIndex = Opts.UseGlobalModuleIndex;
Opts.CodeCompleteOpts.IncludeMacros
= Args.hasArg(OPT_code_completion_macros);
diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp
index 4b642b395c..05064fbd4f 100644
--- a/lib/Frontend/FrontendAction.cpp
+++ b/lib/Frontend/FrontendAction.cpp
@@ -382,10 +382,9 @@ bool FrontendAction::Execute() {
else ExecuteAction();
// If we are supposed to rebuild the global module index, do so now unless
- // an error occurred.
- if (CI.getBuildGlobalModuleIndex() && CI.hasFileManager() &&
- CI.hasPreprocessor() &&
- (!CI.hasDiagnostics() || !CI.getDiagnostics().hasErrorOccurred())) {
+ // there were any module-build failures.
+ if (CI.shouldBuildGlobalModuleIndex() && CI.hasFileManager() &&
+ CI.hasPreprocessor()) {
GlobalModuleIndex::writeIndex(
CI.getFileManager(),
CI.getPreprocessor().getHeaderSearchInfo().getModuleCachePath());
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index c8bca73452..e24fddfd34 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -6941,13 +6941,14 @@ void ASTReader::FinishedDeserializing() {
ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context,
StringRef isysroot, bool DisableValidation,
- bool AllowASTWithCompilerErrors)
+ bool AllowASTWithCompilerErrors, bool UseGlobalIndex)
: Listener(new PCHValidator(PP, *this)), DeserializationListener(0),
SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()),
Diags(PP.getDiagnostics()), SemaObj(0), PP(PP), Context(Context),
Consumer(0), ModuleMgr(PP.getFileManager()),
isysroot(isysroot), DisableValidation(DisableValidation),
AllowASTWithCompilerErrors(AllowASTWithCompilerErrors),
+ UseGlobalIndex(UseGlobalIndex), TriedLoadingGlobalIndex(false),
CurrentGeneration(0), CurrSwitchCaseStmts(&SwitchCaseStmts),
NumSLocEntriesRead(0), TotalNumSLocEntries(0),
NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0),
diff --git a/test/Modules/global_index.m b/test/Modules/global_index.m
index 423e1113e4..f183b1f94c 100644
--- a/test/Modules/global_index.m
+++ b/test/Modules/global_index.m
@@ -1,7 +1,13 @@
// RUN: rm -rf %t
-// RUN: %clang_cc1 -Wauto-import -fmodule-cache-path %t -fdisable-module-hash -fmodules -generate-module-index -F %S/Inputs %s -verify
+// RUN: %clang_cc1 -Wauto-import -fmodule-cache-path %t -fdisable-module-hash -fmodules -fmodules-global-index -F %S/Inputs %s -verify
// RUN: ls %t|grep modules.idx
+// RUN: %clang_cc1 -Wauto-import -fmodule-cache-path %t -fdisable-module-hash -fmodules -fmodules-global-index -F %S/Inputs %s -verify
+// REQUIRES: shell
// expected-no-diagnostics
@import DependsOnModule;
+@import Module;
+int *get_sub() {
+ return Module_Sub;
+}