Index: tools/llc/llc.cpp =================================================================== --- tools/llc/llc.cpp +++ tools/llc/llc.cpp @@ -25,6 +25,8 @@ #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/TargetPassConfig.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/DiagnosticInfo.h" +#include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/IRPrintingPasses.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/LegacyPassManager.h" @@ -181,6 +183,31 @@ return FDOut; } +static const char *getDiagnosticMessagePrefix(DiagnosticSeverity Severity) { + switch (Severity) { + case DS_Error: + return "error"; + case DS_Warning: + return "warning"; + case DS_Remark: + return "remark"; + case DS_Note: + return "note"; + } + llvm_unreachable("Unknown DiagnosticSeverity"); +} + +static void DiagnosticHandler(const DiagnosticInfo &DI, void *Context) { + bool *HasError = static_cast(Context); + if (DI.getSeverity() == DS_Error) + *HasError = true; + + DiagnosticPrinterRawOStream DP(errs()); + errs() << getDiagnosticMessagePrefix(DI.getSeverity()) << ": "; + DI.print(DP); + errs() << "\n"; +} + // main - Entry point for the llc compiler. // int main(int argc, char **argv) { @@ -215,6 +242,10 @@ Context.setDiscardValueNames(DiscardValueNames); + // Set a diagnostic handler that doesn't exit on the first error + bool HasError = false; + Context.setDiagnosticHandler(DiagnosticHandler, &HasError); + // Compile the module TimeCompilations times to give better compile time // metrics. for (unsigned I = TimeCompilations; I; --I) @@ -441,6 +472,10 @@ PM.run(*M); + auto HasError = *static_cast(Context.getDiagnosticContext()); + if (HasError) + return 1; + // Compare the two outputs and make sure they're the same if (CompileTwice) { if (Buffer.size() != CompileTwiceBuffer.size() ||