[cfe-commits] r141051 - /cfe/trunk/lib/Frontend/CompilerInstance.cpp
Douglas Gregor
dgregor at apple.com
Mon Oct 3 17:21:22 PDT 2011
Author: dgregor
Date: Mon Oct 3 19:21:21 2011
New Revision: 141051
URL: http://llvm.org/viewvc/llvm-project?rev=141051&view=rev
Log:
When build a module on demand, run the module-building job on a
separate thread with the "suitably large" stack, so we don't blow the
stack when building modules recursively.
Modified:
cfe/trunk/lib/Frontend/CompilerInstance.cpp
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=141051&r1=141050&r2=141051&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Mon Oct 3 19:21:21 2011
@@ -39,6 +39,7 @@
#include "llvm/Support/Program.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/system_error.h"
+#include "llvm/Support/CrashRecoveryContext.h"
#include "llvm/Config/config.h"
using namespace clang;
@@ -655,6 +656,20 @@
return LangOpts.CPlusPlus? IK_CXX : IK_C;
}
+namespace {
+ struct CompileModuleData {
+ CompilerInstance &Instance;
+ GeneratePCHAction &CreateModuleAction;
+ };
+}
+
+/// \brief Helper function that executes the module-generating action under
+/// a crash recovery context.
+static void doCompileModule(void *UserData) {
+ CompileModuleData &Data = *reinterpret_cast<CompileModuleData *>(UserData);
+ Data.Instance.ExecuteAction(Data.CreateModuleAction);
+}
+
/// \brief Compile a module file for the given module name with the given
/// umbrella header, using the options provided by the importing compiler
/// instance.
@@ -703,9 +718,12 @@
// Construct a module-generating action.
GeneratePCHAction CreateModuleAction(true);
- // Execute the action to actually build the module in-place.
- // FIXME: Need to synchronize when multiple processes do this.
- Instance.ExecuteAction(CreateModuleAction);
+ // Execute the action to actually build the module in-place. Use a separate
+ // thread so that we get a stack large enough.
+ const unsigned ThreadStackSize = 8 << 20;
+ llvm::CrashRecoveryContext CRC;
+ CompileModuleData Data = { Instance, CreateModuleAction };
+ CRC.RunSafelyOnThread(&doCompileModule, &Data, ThreadStackSize);
}
ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc,
More information about the cfe-commits
mailing list