summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-10-25 04:06:10 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-10-25 04:06:10 +0000
commitd12b4a334b01bb1b39d2b9f76a9a296aacf6e226 (patch)
tree60ce562d184b30ec8aaa0e27582656ab91f07b27 /llvm/tools
parentea51161a9495206bce5b49f552f1a0bdff99a0b1 (diff)
downloadbcm5719-llvm-d12b4a334b01bb1b39d2b9f76a9a296aacf6e226.tar.gz
bcm5719-llvm-d12b4a334b01bb1b39d2b9f76a9a296aacf6e226.zip
Update the error handling of lib/Linker.
Instead of passing a std::string&, use the new diagnostic infrastructure. llvm-svn: 220608
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/bugpoint/BugDriver.cpp7
-rw-r--r--llvm/tools/bugpoint/Miscompilation.cpp30
-rw-r--r--llvm/tools/gold/gold-plugin.cpp5
-rw-r--r--llvm/tools/llvm-link/llvm-link.cpp30
-rw-r--r--llvm/tools/llvm-lto/llvm-lto.cpp6
-rw-r--r--llvm/tools/lto/lto.cpp2
6 files changed, 36 insertions, 44 deletions
diff --git a/llvm/tools/bugpoint/BugDriver.cpp b/llvm/tools/bugpoint/BugDriver.cpp
index a87610422c2..b54ea2387b3 100644
--- a/llvm/tools/bugpoint/BugDriver.cpp
+++ b/llvm/tools/bugpoint/BugDriver.cpp
@@ -126,13 +126,8 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) {
if (!M.get()) return true;
outs() << "Linking in input file: '" << Filenames[i] << "'\n";
- std::string ErrorMessage;
- if (Linker::LinkModules(Program, M.get(), Linker::DestroySource,
- &ErrorMessage)) {
- errs() << ToolName << ": error linking in '" << Filenames[i] << "': "
- << ErrorMessage << '\n';
+ if (Linker::LinkModules(Program, M.get(), Linker::DestroySource))
return true;
- }
}
outs() << "*** All input ok\n";
diff --git a/llvm/tools/bugpoint/Miscompilation.cpp b/llvm/tools/bugpoint/Miscompilation.cpp
index 01624208612..ce16d4d18af 100644
--- a/llvm/tools/bugpoint/Miscompilation.cpp
+++ b/llvm/tools/bugpoint/Miscompilation.cpp
@@ -218,16 +218,12 @@ static Module *TestMergedProgram(const BugDriver &BD, Module *M1, Module *M2,
bool DeleteInputs, std::string &Error,
bool &Broken) {
// Link the two portions of the program back to together.
- std::string ErrorMsg;
if (!DeleteInputs) {
M1 = CloneModule(M1);
M2 = CloneModule(M2);
}
- if (Linker::LinkModules(M1, M2, Linker::DestroySource, &ErrorMsg)) {
- errs() << BD.getToolName() << ": Error linking modules together:"
- << ErrorMsg << '\n';
+ if (Linker::LinkModules(M1, M2, Linker::DestroySource))
exit(1);
- }
delete M2; // We are done with this module.
// Execute the program.
@@ -396,13 +392,9 @@ static bool ExtractLoops(BugDriver &BD,
F->getFunctionType()));
}
- std::string ErrorMsg;
- if (Linker::LinkModules(ToNotOptimize, ToOptimizeLoopExtracted,
- Linker::DestroySource, &ErrorMsg)){
- errs() << BD.getToolName() << ": Error linking modules together:"
- << ErrorMsg << '\n';
+ if (Linker::LinkModules(ToNotOptimize, ToOptimizeLoopExtracted,
+ Linker::DestroySource))
exit(1);
- }
MiscompiledFunctions.clear();
for (unsigned i = 0, e = MisCompFunctions.size(); i != e; ++i) {
@@ -430,13 +422,10 @@ 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.
- std::string ErrorMsg;
- if (Linker::LinkModules(ToNotOptimize, ToOptimizeLoopExtracted,
- Linker::DestroySource, &ErrorMsg)){
- errs() << BD.getToolName() << ": Error linking modules together:"
- << ErrorMsg << '\n';
+ if (Linker::LinkModules(ToNotOptimize, ToOptimizeLoopExtracted,
+ Linker::DestroySource))
exit(1);
- }
+
delete ToOptimizeLoopExtracted;
// All of the Function*'s in the MiscompiledFunctions list are in the old
@@ -612,13 +601,8 @@ static bool ExtractBlocks(BugDriver &BD,
MisCompFunctions.push_back(std::make_pair(I->getName(),
I->getFunctionType()));
- std::string ErrorMsg;
- if (Linker::LinkModules(ProgClone, Extracted.get(), Linker::DestroySource,
- &ErrorMsg)) {
- errs() << BD.getToolName() << ": Error linking modules together:"
- << ErrorMsg << '\n';
+ if (Linker::LinkModules(ProgClone, Extracted.get(), Linker::DestroySource))
exit(1);
- }
// Set the new program and delete the old one.
BD.setNewProgram(ProgClone);
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp
index 2d50f49ffd7..cc0e9f35661 100644
--- a/llvm/tools/gold/gold-plugin.cpp
+++ b/llvm/tools/gold/gold-plugin.cpp
@@ -777,9 +777,8 @@ static ld_plugin_status allSymbolsReadHook(raw_fd_ostream *ApiFile) {
M->setTargetTriple(DefaultTriple);
}
- std::string ErrMsg;
- if (L.linkInModule(M.get(), &ErrMsg))
- message(LDPL_FATAL, "Failed to link module: %s", ErrMsg.c_str());
+ if (L.linkInModule(M.get()))
+ message(LDPL_FATAL, "Failed to link module");
}
for (const auto &Name : Internalize) {
diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp
index 7c2894baa1b..c4a4e49ba74 100644
--- a/llvm/tools/llvm-link/llvm-link.cpp
+++ b/llvm/tools/llvm-link/llvm-link.cpp
@@ -14,6 +14,8 @@
#include "llvm/Linker/Linker.h"
#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h"
@@ -69,6 +71,25 @@ loadFile(const char *argv0, const std::string &FN, LLVMContext &Context) {
return Result;
}
+static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) {
+ unsigned Severity = DI.getSeverity();
+ switch (Severity) {
+ case DS_Error:
+ errs() << "ERROR: ";
+ case DS_Warning:
+ if (SuppressWarnings)
+ return;
+ errs() << "WARNING: ";
+ break;
+ case DS_Remark:
+ case DS_Note:
+ llvm_unreachable("Only expecting warnings and errors");
+ }
+
+ DiagnosticPrinterRawOStream DP(errs());
+ DI.print(DP);
+}
+
int main(int argc, char **argv) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal();
@@ -79,9 +100,9 @@ int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
auto Composite = make_unique<Module>("llvm-link", Context);
- Linker L(Composite.get(), SuppressWarnings);
+ Linker L(Composite.get());
- std::string ErrorMessage;
+ Context.setDiagnosticHandler(diagnosticHandler);
for (unsigned i = 0; i < InputFilenames.size(); ++i) {
std::unique_ptr<Module> M = loadFile(argv[0], InputFilenames[i], Context);
if (!M.get()) {
@@ -91,11 +112,8 @@ int main(int argc, char **argv) {
if (Verbose) errs() << "Linking in '" << InputFilenames[i] << "'\n";
- if (L.linkInModule(M.get(), &ErrorMessage)) {
- errs() << argv[0] << ": link error in '" << InputFilenames[i]
- << "': " << ErrorMessage << "\n";
+ if (L.linkInModule(M.get()))
return 1;
- }
}
if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite;
diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp
index 2bfd9594555..0910df14203 100644
--- a/llvm/tools/llvm-lto/llvm-lto.cpp
+++ b/llvm/tools/llvm-lto/llvm-lto.cpp
@@ -143,12 +143,8 @@ int main(int argc, char **argv) {
return 1;
}
-
- if (!CodeGen.addModule(Module.get(), error)) {
- errs() << argv[0] << ": error adding file '" << InputFilenames[i]
- << "': " << error << "\n";
+ if (!CodeGen.addModule(Module.get()))
return 1;
- }
unsigned NumSyms = Module->getSymbolCount();
for (unsigned I = 0; I < NumSyms; ++I) {
diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp
index 5732996a160..3389425915d 100644
--- a/llvm/tools/lto/lto.cpp
+++ b/llvm/tools/lto/lto.cpp
@@ -205,7 +205,7 @@ lto_code_gen_t lto_codegen_create(void) {
void lto_codegen_dispose(lto_code_gen_t cg) { delete unwrap(cg); }
bool lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod) {
- return !unwrap(cg)->addModule(unwrap(mod), sLastErrorString);
+ return !unwrap(cg)->addModule(unwrap(mod));
}
bool lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model debug) {
OpenPOWER on IntegriCloud