diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-12-04 22:08:53 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-12-04 22:08:53 +0000 |
commit | f49a38fc0887baac3a21ecebf8d13b7e416ac2c6 (patch) | |
tree | 7dfeace7a0801214395aeac03256f92c28c19dce /llvm/tools | |
parent | 8213072a453bcb012b31d231dae4f44a589ddd52 (diff) | |
download | bcm5719-llvm-f49a38fc0887baac3a21ecebf8d13b7e416ac2c6.tar.gz bcm5719-llvm-f49a38fc0887baac3a21ecebf8d13b7e416ac2c6.zip |
Always pass a diagnostic handler to the linker.
Before this patch the diagnostic handler was optional. If it was not
passed, the one in the LLVMContext was used.
That is probably not a pattern we want to follow. If each area has an
optional callback, there is a sea of callbacks and it is hard to follow
which one is called.
Doing this also found cases where the callback is a nice addition, like
testing that no errors or warnings are reported.
The other option is to always use the diagnostic handler in the
LLVMContext. That has a few problems
* To implement the C API we would have to set the diag handler and then
set it back to the original value.
* Code that creates the context might be far away from code that wants
the diagnostics.
I do have a patch that implements the second option and will send that as
an RFC.
llvm-svn: 254777
Diffstat (limited to 'llvm/tools')
-rw-r--r-- | llvm/tools/bugpoint/BugDriver.cpp | 9 | ||||
-rw-r--r-- | llvm/tools/bugpoint/Miscompilation.cpp | 19 | ||||
-rw-r--r-- | llvm/tools/gold/gold-plugin.cpp | 2 |
3 files changed, 24 insertions, 6 deletions
diff --git a/llvm/tools/bugpoint/BugDriver.cpp b/llvm/tools/bugpoint/BugDriver.cpp index 39887d5d59d..9edc242d470 100644 --- a/llvm/tools/bugpoint/BugDriver.cpp +++ b/llvm/tools/bugpoint/BugDriver.cpp @@ -15,6 +15,7 @@ #include "BugDriver.h" #include "ToolRunner.h" +#include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/Module.h" #include "llvm/IR/Verifier.h" #include "llvm/IRReader/IRReader.h" @@ -112,6 +113,12 @@ std::unique_ptr<Module> llvm::parseInputFile(StringRef Filename, return Result; } +static void diagnosticHandler(const DiagnosticInfo &DI) { + DiagnosticPrinterRawOStream DP(errs()); + DI.print(DP); + errs() << '\n'; +} + // This method takes the specified list of LLVM input files, attempts to load // them, either as assembly or bitcode, then link them together. It returns // true on failure (if, for example, an input bitcode file could not be @@ -132,7 +139,7 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) { if (!M.get()) return true; outs() << "Linking in input file: '" << Filenames[i] << "'\n"; - if (Linker::linkModules(*Program, *M)) + if (Linker::linkModules(*Program, *M, diagnosticHandler)) return true; } diff --git a/llvm/tools/bugpoint/Miscompilation.cpp b/llvm/tools/bugpoint/Miscompilation.cpp index e7eae40ec95..0b61b096985 100644 --- a/llvm/tools/bugpoint/Miscompilation.cpp +++ b/llvm/tools/bugpoint/Miscompilation.cpp @@ -18,6 +18,7 @@ #include "llvm/Config/config.h" // for HAVE_LINK_R #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" #include "llvm/IR/Verifier.h" @@ -207,6 +208,14 @@ namespace { }; } +static void diagnosticHandler(const DiagnosticInfo &DI) { + DiagnosticPrinterRawOStream DP(errs()); + DI.print(DP); + errs() << '\n'; + if (DI.getSeverity() == DS_Error) + exit(1); +} + /// TestMergedProgram - Given two modules, link them together and run the /// program, checking to see if the program matches the diff. If there is /// an error, return NULL. If not, return the merged module. The Broken argument @@ -222,7 +231,7 @@ static Module *TestMergedProgram(const BugDriver &BD, Module *M1, Module *M2, M1 = CloneModule(M1); M2 = CloneModule(M2); } - if (Linker::linkModules(*M1, *M2)) + if (Linker::linkModules(*M1, *M2, diagnosticHandler)) exit(1); delete M2; // We are done with this module. @@ -390,7 +399,8 @@ static bool ExtractLoops(BugDriver &BD, MisCompFunctions.emplace_back(F->getName(), F->getFunctionType()); } - if (Linker::linkModules(*ToNotOptimize, *ToOptimizeLoopExtracted)) + if (Linker::linkModules(*ToNotOptimize, *ToOptimizeLoopExtracted, + diagnosticHandler)) exit(1); MiscompiledFunctions.clear(); @@ -418,7 +428,8 @@ static bool ExtractLoops(BugDriver &BD, // extraction both didn't break the program, and didn't mask the problem. // Replace the current program with the loop extracted version, and try to // extract another loop. - if (Linker::linkModules(*ToNotOptimize, *ToOptimizeLoopExtracted)) + if (Linker::linkModules(*ToNotOptimize, *ToOptimizeLoopExtracted, + diagnosticHandler)) exit(1); delete ToOptimizeLoopExtracted; @@ -594,7 +605,7 @@ static bool ExtractBlocks(BugDriver &BD, if (!I->isDeclaration()) MisCompFunctions.emplace_back(I->getName(), I->getFunctionType()); - if (Linker::linkModules(*ProgClone, *Extracted)) + if (Linker::linkModules(*ProgClone, *Extracted, diagnosticHandler)) exit(1); // Set the new program and delete the old one. diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp index 1bd2f8afb29..8eacdc3ff23 100644 --- a/llvm/tools/gold/gold-plugin.cpp +++ b/llvm/tools/gold/gold-plugin.cpp @@ -938,7 +938,7 @@ static ld_plugin_status allSymbolsReadHook(raw_fd_ostream *ApiFile) { } std::unique_ptr<Module> Combined(new Module("ld-temp.o", Context)); - Linker L(*Combined); + Linker L(*Combined, diagnosticHandler); std::string DefaultTriple = sys::getDefaultTargetTriple(); |