r220234 - Driver: Make FailingCommand mandatory for generateCompilationDiagnostics
Justin Bogner
mail at justinbogner.com
Mon Oct 20 14:02:05 PDT 2014
Author: bogner
Date: Mon Oct 20 16:02:05 2014
New Revision: 220234
URL: http://llvm.org/viewvc/llvm-project?rev=220234&view=rev
Log:
Driver: Make FailingCommand mandatory for generateCompilationDiagnostics
We currently use a null FailingCommand when generating crash reports
as an indication that the cause is FORCE_CLANG_DIAGNOSTICS_CRASH, the
environment variable that exists to test crash dumps. This means that
our tests don't actually cover real crashes at all, and adds a more
complicated code path that's only used in the tests.
Instead, we can have the driver synthesize that every command failed
and just call generateCompilationDiagnostics normally.
Modified:
cfe/trunk/include/clang/Driver/Driver.h
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/tools/driver/driver.cpp
Modified: cfe/trunk/include/clang/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=220234&r1=220233&r2=220234&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Mon Oct 20 16:02:05 2014
@@ -304,7 +304,7 @@ public:
/// including preprocessed source file(s).
///
void generateCompilationDiagnostics(Compilation &C,
- const Command *FailingCommand);
+ const Command &FailingCommand);
/// @}
/// @name Helper Methods
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=220234&r1=220233&r2=220234&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Mon Oct 20 16:02:05 2014
@@ -403,13 +403,13 @@ Compilation *Driver::BuildCompilation(Ar
// preprocessed source file(s). Request that the developer attach the
// diagnostic information to a bug report.
void Driver::generateCompilationDiagnostics(Compilation &C,
- const Command *FailingCommand) {
+ const Command &FailingCommand) {
if (C.getArgs().hasArg(options::OPT_fno_crash_diagnostics))
return;
// Don't try to generate diagnostics for link or dsymutil jobs.
- if (FailingCommand && (FailingCommand->getCreator().isLinkJob() ||
- FailingCommand->getCreator().isDsymutilJob()))
+ if (FailingCommand.getCreator().isLinkJob() ||
+ FailingCommand.getCreator().isDsymutilJob())
return;
// Print the version of the compiler.
@@ -426,12 +426,7 @@ void Driver::generateCompilationDiagnost
// Save the original job command(s).
std::string Cmd;
llvm::raw_string_ostream OS(Cmd);
- if (FailingCommand)
- FailingCommand->Print(OS, "\n", /*Quote*/ false, /*CrashReport*/ true);
- else
- // Crash triggered by FORCE_CLANG_DIAGNOSTICS_CRASH, which doesn't have an
- // associated FailingCommand, so just pass all jobs.
- C.getJobs().Print(OS, "\n", /*Quote*/ false, /*CrashReport*/ true);
+ FailingCommand.Print(OS, "\n", /*Quote*/ false, /*CrashReport*/ true);
OS.flush();
// Keep track of whether we produce any errors while trying to produce
Modified: cfe/trunk/tools/driver/driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/driver.cpp?rev=220234&r1=220233&r2=220234&view=diff
==============================================================================
--- cfe/trunk/tools/driver/driver.cpp (original)
+++ cfe/trunk/tools/driver/driver.cpp Mon Oct 20 16:02:05 2014
@@ -464,8 +464,12 @@ int main(int argc_, const char **argv_)
// Force a crash to test the diagnostics.
if (::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH")) {
Diags.Report(diag::err_drv_force_crash) << "FORCE_CLANG_DIAGNOSTICS_CRASH";
- const Command *FailingCommand = nullptr;
- FailingCommands.push_back(std::make_pair(-1, FailingCommand));
+
+ // Pretend that every command failed.
+ FailingCommands.clear();
+ for (const auto &J : C->getJobs())
+ if (const Command *C = dyn_cast<Command>(&J))
+ FailingCommands.push_back(std::make_pair(-1, C));
}
for (const auto &P : FailingCommands) {
@@ -483,7 +487,7 @@ int main(int argc_, const char **argv_)
DiagnoseCrash |= CommandRes == 3;
#endif
if (DiagnoseCrash) {
- TheDriver.generateCompilationDiagnostics(*C, FailingCommand);
+ TheDriver.generateCompilationDiagnostics(*C, *FailingCommand);
break;
}
}
More information about the cfe-commits
mailing list