aboutsummaryrefslogtreecommitdiff
path: root/lib/Driver/Compilation.cpp
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@apple.com>2011-07-20 20:26:32 +0000
committerChad Rosier <mcrosier@apple.com>2011-07-20 20:26:32 +0000
commit2da13b15959365df7edf1ed12a049b599b39c276 (patch)
tree9ae0d63ccefc306b330032a070310175e4589f70 /lib/Driver/Compilation.cpp
parent66488ed140f00daee0c3f0370bac337819ee8bc0 (diff)
When the compiler crashes, the compiler driver now produces diagnostic information
including the fully preprocessed source file(s) and command line arguments. The developer is asked to attach this diagnostic information to a bug report. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135614 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/Compilation.cpp')
-rw-r--r--lib/Driver/Compilation.cpp39
1 files changed, 35 insertions, 4 deletions
diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp
index 2657faa0d3..b0e46ff5ae 100644
--- a/lib/Driver/Compilation.cpp
+++ b/lib/Driver/Compilation.cpp
@@ -25,7 +25,7 @@ using namespace clang::driver;
Compilation::Compilation(const Driver &D, const ToolChain &_DefaultToolChain,
InputArgList *_Args, DerivedArgList *_TranslatedArgs)
: TheDriver(D), DefaultToolChain(_DefaultToolChain), Args(_Args),
- TranslatedArgs(_TranslatedArgs) {
+ TranslatedArgs(_TranslatedArgs), Redirects(0) {
}
Compilation::~Compilation() {
@@ -43,6 +43,13 @@ Compilation::~Compilation() {
for (ActionList::iterator it = Actions.begin(), ie = Actions.end();
it != ie; ++it)
delete *it;
+
+ // Free redirections of stdout/stderr.
+ if (Redirects) {
+ delete Redirects[1];
+ delete Redirects[2];
+ delete Redirects;
+ }
}
const DerivedArgList &Compilation::getArgsForToolChain(const ToolChain *TC,
@@ -135,8 +142,8 @@ int Compilation::ExecuteCommand(const Command &C,
std::copy(C.getArguments().begin(), C.getArguments().end(), Argv+1);
Argv[C.getArguments().size() + 1] = 0;
- if (getDriver().CCCEcho || getDriver().CCPrintOptions ||
- getArgs().hasArg(options::OPT_v)) {
+ if ((getDriver().CCCEcho || getDriver().CCPrintOptions ||
+ getArgs().hasArg(options::OPT_v)) && !getDriver().CCGenDiagnostics) {
llvm::raw_ostream *OS = &llvm::errs();
// Follow gcc implementation of CC_PRINT_OPTIONS; we could also cache the
@@ -167,7 +174,7 @@ int Compilation::ExecuteCommand(const Command &C,
std::string Error;
int Res =
llvm::sys::Program::ExecuteAndWait(Prog, Argv,
- /*env*/0, /*redirects*/0,
+ /*env*/0, Redirects,
/*secondsToWait*/0, /*memoryLimit*/0,
&Error);
if (!Error.empty()) {
@@ -195,3 +202,27 @@ int Compilation::ExecuteJob(const Job &J,
return 0;
}
}
+
+void Compilation::initCompilationForDiagnostics(void) {
+ // Free actions and jobs, if built.
+ for (ActionList::iterator it = Actions.begin(), ie = Actions.end();
+ it != ie; ++it)
+ delete *it;
+ Actions.clear();
+ Jobs.clear();
+
+ // Clear temporary and results file lists.
+ TempFiles.clear();
+ ResultFiles.clear();
+
+ // Remove any user specified output. Claim any unclaimed arguments, so as
+ // to avoid emitting warnings about unused args.
+ if (TranslatedArgs->hasArg(options::OPT_o))
+ TranslatedArgs->eraseArg(options::OPT_o);
+ TranslatedArgs->ClaimAllArgs();
+
+ // Redirect stdout/stderr to /dev/null.
+ Redirects = new const llvm::sys::Path*[3]();
+ Redirects[1] = new const llvm::sys::Path();
+ Redirects[2] = new const llvm::sys::Path();
+}