From 1ad45020ec8518a5c9bea7ec1007798a456bff56 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 13 Jun 2014 03:07:50 +0000 Subject: [PATCH] Remove 'using std::error_code' from tools. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210876 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/bugpoint/ExecutionDriver.cpp | 7 +-- tools/bugpoint/ExtractFunction.cpp | 3 +- tools/bugpoint/Miscompilation.cpp | 9 ++- tools/bugpoint/OptimizerDriver.cpp | 3 +- tools/bugpoint/ToolRunner.cpp | 9 ++- tools/gold/gold-plugin.cpp | 5 +- tools/lli/RemoteMemoryManager.cpp | 3 +- tools/lli/lli.cpp | 5 +- tools/llvm-ar/llvm-ar.cpp | 5 +- tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp | 4 +- tools/llvm-cov/llvm-cov.cpp | 5 +- tools/llvm-dis/llvm-dis.cpp | 3 +- tools/llvm-dwarfdump/llvm-dwarfdump.cpp | 5 +- tools/llvm-mc/llvm-mc.cpp | 4 +- tools/llvm-mcmarkup/llvm-mcmarkup.cpp | 3 +- tools/llvm-nm/llvm-nm.cpp | 3 +- tools/llvm-objdump/COFFDump.cpp | 42 +++++++------- tools/llvm-objdump/MachODump.cpp | 5 +- tools/llvm-objdump/llvm-objdump.cpp | 11 ++-- tools/llvm-profdata/llvm-profdata.cpp | 8 +-- tools/llvm-readobj/COFFDumper.cpp | 56 +++++++++--------- tools/llvm-readobj/ELFDumper.cpp | 12 ++-- tools/llvm-readobj/MachODumper.cpp | 9 ++- tools/llvm-readobj/Win64EHDumper.cpp | 18 +++--- tools/llvm-readobj/llvm-readobj.cpp | 16 +++--- tools/llvm-rtdyld/llvm-rtdyld.cpp | 9 ++- tools/llvm-size/llvm-size.cpp | 7 +-- tools/llvm-symbolizer/LLVMSymbolize.cpp | 5 +- tools/llvm-symbolizer/llvm-symbolizer.cpp | 1 - tools/macho-dump/macho-dump.cpp | 3 +- tools/obj2yaml/coff2yaml.cpp | 5 +- tools/obj2yaml/elf2yaml.cpp | 69 ++++++++++++----------- tools/obj2yaml/obj2yaml.cpp | 9 ++- 33 files changed, 167 insertions(+), 194 deletions(-) diff --git a/tools/bugpoint/ExecutionDriver.cpp b/tools/bugpoint/ExecutionDriver.cpp index b41a4b03346..25813b34e62 100644 --- a/tools/bugpoint/ExecutionDriver.cpp +++ b/tools/bugpoint/ExecutionDriver.cpp @@ -22,7 +22,6 @@ #include using namespace llvm; -using std::error_code; namespace { // OutputType - Allow the user to specify the way code should be run, to test @@ -268,7 +267,7 @@ void BugDriver::compileProgram(Module *M, std::string *Error) const { // Emit the program to a bitcode file... SmallString<128> BitcodeFile; int BitcodeFD; - error_code EC = sys::fs::createUniqueFile( + std::error_code EC = sys::fs::createUniqueFile( OutputPrefix + "-test-program-%%%%%%%.bc", BitcodeFD, BitcodeFile); if (EC) { errs() << ToolName << ": Error making unique filename: " << EC.message() @@ -306,7 +305,7 @@ std::string BugDriver::executeProgram(const Module *Program, // Emit the program to a bitcode file... SmallString<128> UniqueFilename; int UniqueFD; - error_code EC = sys::fs::createUniqueFile( + std::error_code EC = sys::fs::createUniqueFile( OutputPrefix + "-test-program-%%%%%%%.bc", UniqueFD, UniqueFilename); if (EC) { errs() << ToolName << ": Error making unique filename: " @@ -332,7 +331,7 @@ std::string BugDriver::executeProgram(const Module *Program, // Check to see if this is a valid output filename... SmallString<128> UniqueFile; - error_code EC = sys::fs::createUniqueFile(OutputFile, UniqueFile); + std::error_code EC = sys::fs::createUniqueFile(OutputFile, UniqueFile); if (EC) { errs() << ToolName << ": Error making unique filename: " << EC.message() << "\n"; diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp index a257840b6e0..4fb68566ac6 100644 --- a/tools/bugpoint/ExtractFunction.cpp +++ b/tools/bugpoint/ExtractFunction.cpp @@ -33,7 +33,6 @@ #include "llvm/Transforms/Utils/CodeExtractor.h" #include using namespace llvm; -using std::error_code; #define DEBUG_TYPE "bugpoint" @@ -367,7 +366,7 @@ Module *BugDriver::ExtractMappedBlocksFromModule(const Module *M) { SmallString<128> Filename; int FD; - error_code EC = sys::fs::createUniqueFile( + std::error_code EC = sys::fs::createUniqueFile( OutputPrefix + "-extractblocks%%%%%%%", FD, Filename); if (EC) { outs() << "*** Basic Block extraction failed!\n"; diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp index 5143fa1f037..3f1f84ef624 100644 --- a/tools/bugpoint/Miscompilation.cpp +++ b/tools/bugpoint/Miscompilation.cpp @@ -27,7 +27,6 @@ #include "llvm/Support/FileUtilities.h" #include "llvm/Transforms/Utils/Cloning.h" using namespace llvm; -using std::error_code; namespace llvm { extern cl::opt OutputPrefix; @@ -965,8 +964,8 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe, SmallString<128> TestModuleBC; int TestModuleFD; - error_code EC = sys::fs::createTemporaryFile("bugpoint.test", "bc", - TestModuleFD, TestModuleBC); + std::error_code EC = sys::fs::createTemporaryFile("bugpoint.test", "bc", + TestModuleFD, TestModuleBC); if (EC) { errs() << BD.getToolName() << "Error making unique filename: " << EC.message() << "\n"; @@ -1059,8 +1058,8 @@ bool BugDriver::debugCodeGenerator(std::string *Error) { SmallString<128> TestModuleBC; int TestModuleFD; - error_code EC = sys::fs::createTemporaryFile("bugpoint.test", "bc", - TestModuleFD, TestModuleBC); + std::error_code EC = sys::fs::createTemporaryFile("bugpoint.test", "bc", + TestModuleFD, TestModuleBC); if (EC) { errs() << getToolName() << "Error making unique filename: " << EC.message() << "\n"; diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp index 85790b0c631..d452fd94c06 100644 --- a/tools/bugpoint/OptimizerDriver.cpp +++ b/tools/bugpoint/OptimizerDriver.cpp @@ -35,7 +35,6 @@ #include using namespace llvm; -using std::error_code; #define DEBUG_TYPE "bugpoint" @@ -130,7 +129,7 @@ bool BugDriver::runPasses(Module *Program, // setup the output file name outs().flush(); SmallString<128> UniqueFilename; - error_code EC = sys::fs::createUniqueFile( + std::error_code EC = sys::fs::createUniqueFile( OutputPrefix + "-output-%%%%%%%.bc", UniqueFilename); if (EC) { errs() << getToolName() << ": Error making unique filename: " diff --git a/tools/bugpoint/ToolRunner.cpp b/tools/bugpoint/ToolRunner.cpp index ec120bb0b2f..4a2401b530f 100644 --- a/tools/bugpoint/ToolRunner.cpp +++ b/tools/bugpoint/ToolRunner.cpp @@ -22,7 +22,6 @@ #include #include using namespace llvm; -using std::error_code; #define DEBUG_TYPE "toolrunner" @@ -143,7 +142,7 @@ static std::string ProcessFailure(StringRef ProgPath, const char** Args, // Rerun the compiler, capturing any error messages to print them. SmallString<128> ErrorFilename; int ErrorFD; - error_code EC = sys::fs::createTemporaryFile( + std::error_code EC = sys::fs::createTemporaryFile( "bugpoint.program_error_messages", "", ErrorFD, ErrorFilename); if (EC) { errs() << "Error making unique filename: " << EC.message() << "\n"; @@ -479,7 +478,7 @@ GCC::FileType LLC::OutputCode(const std::string &Bitcode, const char *Suffix = (UseIntegratedAssembler ? ".llc.o" : ".llc.s"); SmallString<128> UniqueFile; - error_code EC = + std::error_code EC = sys::fs::createUniqueFile(Bitcode + "-%%%%%%%" + Suffix, UniqueFile); if (EC) { errs() << "Error making unique filename: " << EC.message() << "\n"; @@ -716,7 +715,7 @@ int GCC::ExecuteProgram(const std::string &ProgramFile, GCCArgs.push_back("-o"); SmallString<128> OutputBinary; - error_code EC = + std::error_code EC = sys::fs::createUniqueFile(ProgramFile + "-%%%%%%%.gcc.exe", OutputBinary); if (EC) { errs() << "Error making unique filename: " << EC.message() << "\n"; @@ -826,7 +825,7 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType, const std::vector &ArgsForGCC, std::string &Error) { SmallString<128> UniqueFilename; - error_code EC = sys::fs::createUniqueFile( + std::error_code EC = sys::fs::createUniqueFile( InputFile + "-%%%%%%%" + LTDL_SHLIB_EXT, UniqueFilename); if (EC) { errs() << "Error making unique filename: " << EC.message() << "\n"; diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index 2030fbd6c83..371574f2615 100644 --- a/tools/gold/gold-plugin.cpp +++ b/tools/gold/gold-plugin.cpp @@ -44,7 +44,6 @@ #endif using namespace llvm; -using std::error_code; namespace { ld_plugin_status discard_message(int level, const char *format, ...) { @@ -259,7 +258,7 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file, if (file->offset) { offset = file->offset; } - if (error_code ec = MemoryBuffer::getOpenFileSlice( + if (std::error_code ec = MemoryBuffer::getOpenFileSlice( file->fd, file->name, buffer, file->filesize, offset)) { (*message)(LDPL_ERROR, ec.message().c_str()); return LDPS_ERR; @@ -485,7 +484,7 @@ static ld_plugin_status all_symbols_read_hook(void) { static ld_plugin_status cleanup_hook(void) { for (int i = 0, e = Cleanup.size(); i != e; ++i) { - error_code EC = sys::fs::remove(Cleanup[i]); + std::error_code EC = sys::fs::remove(Cleanup[i]); if (EC) (*message)(LDPL_ERROR, "Failed to delete '%s': %s", Cleanup[i].c_str(), EC.message().c_str()); diff --git a/tools/lli/RemoteMemoryManager.cpp b/tools/lli/RemoteMemoryManager.cpp index 041f7c7afd0..481651772af 100644 --- a/tools/lli/RemoteMemoryManager.cpp +++ b/tools/lli/RemoteMemoryManager.cpp @@ -19,7 +19,6 @@ #include "llvm/Support/Format.h" using namespace llvm; -using std::error_code; #define DEBUG_TYPE "lli" @@ -62,7 +61,7 @@ allocateDataSection(uintptr_t Size, unsigned Alignment, } sys::MemoryBlock RemoteMemoryManager::allocateSection(uintptr_t Size) { - error_code ec; + std::error_code ec; sys::MemoryBlock MB = sys::Memory::allocateMappedMemory(Size, &Near, sys::Memory::MF_READ | diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp index 2c8a4749fdb..73a19ac6679 100644 --- a/tools/lli/lli.cpp +++ b/tools/lli/lli.cpp @@ -62,7 +62,6 @@ #endif using namespace llvm; -using std::error_code; #define DEBUG_TYPE "lli" @@ -416,7 +415,7 @@ int main(int argc, char **argv, char * const *envp) { // If not jitting lazily, load the whole bitcode file eagerly too. if (NoLazyCompilation) { - if (error_code EC = Mod->materializeAllPermanently()) { + if (std::error_code EC = Mod->materializeAllPermanently()) { errs() << argv[0] << ": bitcode didn't read correctly.\n"; errs() << "Reason: " << EC.message() << "\n"; exit(1); @@ -540,7 +539,7 @@ int main(int argc, char **argv, char * const *envp) { for (unsigned i = 0, e = ExtraArchives.size(); i != e; ++i) { std::unique_ptr ArBuf; - error_code ec; + std::error_code ec; ec = MemoryBuffer::getFileOrSTDIN(ExtraArchives[i], ArBuf); if (ec) { Err.print(argv[0], errs()); diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index d0d4f1477da..227adb44215 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -36,7 +36,6 @@ #endif using namespace llvm; -using std::error_code; // The name this program was invoked as. static StringRef ToolName; @@ -54,7 +53,7 @@ LLVM_ATTRIBUTE_NORETURN static void fail(Twine Error) { exit(1); } -static void failIfError(error_code EC, Twine Context = "") { +static void failIfError(std::error_code EC, Twine Context = "") { if (!EC) return; @@ -939,7 +938,7 @@ int ar_main(char **argv) { static int performOperation(ArchiveOperation Operation) { // Create or open the archive object. std::unique_ptr Buf; - error_code EC = MemoryBuffer::getFile(ArchiveName, Buf, -1, false); + std::error_code EC = MemoryBuffer::getFile(ArchiveName, Buf, -1, false); if (EC && EC != std::errc::no_such_file_or_directory) { errs() << ToolName << ": error opening '" << ArchiveName << "': " << EC.message() << "!\n"; diff --git a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp index d29c83714ab..fe2b235e53c 100644 --- a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp +++ b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp @@ -43,7 +43,6 @@ #include #include using namespace llvm; -using std::error_code; static cl::opt InputFilename(cl::Positional, cl::desc(""), cl::init("-")); @@ -481,8 +480,7 @@ static int AnalyzeBitcode() { // Read the input file. std::unique_ptr MemBuf; - if (error_code ec = - MemoryBuffer::getFileOrSTDIN(InputFilename, MemBuf)) + if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, MemBuf)) return Error("Error reading '" + InputFilename + "': " + ec.message()); if (MemBuf->getBufferSize() & 3) diff --git a/tools/llvm-cov/llvm-cov.cpp b/tools/llvm-cov/llvm-cov.cpp index 97a91dd544a..b233a90bf58 100644 --- a/tools/llvm-cov/llvm-cov.cpp +++ b/tools/llvm-cov/llvm-cov.cpp @@ -22,7 +22,6 @@ #include "llvm/Support/Signals.h" #include using namespace llvm; -using std::error_code; static cl::opt SourceFile(cl::Positional, cl::Required, cl::desc("SOURCEFILE")); @@ -105,7 +104,7 @@ int main(int argc, char **argv) { GCOVFile GF; std::unique_ptr GCNO_Buff; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, GCNO_Buff)) { + if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, GCNO_Buff)) { errs() << InputGCNO << ": " << ec.message() << "\n"; return 1; } @@ -116,7 +115,7 @@ int main(int argc, char **argv) { } std::unique_ptr GCDA_Buff; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) { + if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) { if (ec != std::errc::no_such_file_or_directory) { errs() << InputGCDA << ": " << ec.message() << "\n"; return 1; diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp index f5dfedbc477..3b0f838f1d7 100644 --- a/tools/llvm-dis/llvm-dis.cpp +++ b/tools/llvm-dis/llvm-dis.cpp @@ -34,7 +34,6 @@ #include "llvm/Support/ToolOutputFile.h" #include using namespace llvm; -using std::error_code; static cl::opt InputFilename(cl::Positional, cl::desc(""), cl::init("-")); @@ -138,7 +137,7 @@ int main(int argc, char **argv) { M.reset(getStreamedBitcodeModule(DisplayFilename, streamer, Context, &ErrorMessage)); if(M.get()) { - if (error_code EC = M->materializeAllPermanently()) { + if (std::error_code EC = M->materializeAllPermanently()) { ErrorMessage = EC.message(); M.reset(); } diff --git a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index 2f10f2994fa..29f0c8707a5 100644 --- a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -33,7 +33,6 @@ using namespace llvm; using namespace object; -using std::error_code; static cl::list InputFilenames(cl::Positional, cl::desc(""), @@ -69,13 +68,13 @@ DumpType("debug-dump", cl::init(DIDT_All), static void DumpInput(const StringRef &Filename) { std::unique_ptr Buff; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) { + if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) { errs() << Filename << ": " << ec.message() << "\n"; return; } ErrorOr ObjOrErr(ObjectFile::createObjectFile(Buff.release())); - if (error_code EC = ObjOrErr.getError()) { + if (std::error_code EC = ObjOrErr.getError()) { errs() << Filename << ": " << EC.message() << '\n'; return; } diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index 24a2d6f208e..a6b74a7b1ba 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -40,7 +40,6 @@ #include "llvm/Support/TargetSelect.h" #include "llvm/Support/ToolOutputFile.h" using namespace llvm; -using std::error_code; static cl::opt InputFilename(cl::Positional, cl::desc(""), cl::init("-")); @@ -368,7 +367,8 @@ int main(int argc, char **argv) { return 1; std::unique_ptr BufferPtr; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, BufferPtr)) { + if (std::error_code ec = + MemoryBuffer::getFileOrSTDIN(InputFilename, BufferPtr)) { errs() << ProgName << ": " << ec.message() << '\n'; return 1; } diff --git a/tools/llvm-mcmarkup/llvm-mcmarkup.cpp b/tools/llvm-mcmarkup/llvm-mcmarkup.cpp index e8416d60126..cbb0d51dd3d 100644 --- a/tools/llvm-mcmarkup/llvm-mcmarkup.cpp +++ b/tools/llvm-mcmarkup/llvm-mcmarkup.cpp @@ -21,7 +21,6 @@ #include "llvm/Support/raw_ostream.h" #include using namespace llvm; -using std::error_code; static cl::list InputFilenames(cl::Positional, cl::desc(""), @@ -137,7 +136,7 @@ MarkupTag MarkupParser::parseTag() { static void parseMCMarkup(StringRef Filename) { std::unique_ptr BufferPtr; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, BufferPtr)) { + if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, BufferPtr)) { errs() << ToolName << ": " << ec.message() << '\n'; return; } diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index 6476a60c7e1..19d9888e8a6 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -45,7 +45,6 @@ #include using namespace llvm; using namespace object; -using std::error_code; namespace { enum OutputFormatTy { bsd, sysv, posix, darwin }; @@ -133,7 +132,7 @@ static void error(Twine Message, Twine Path = Twine()) { errs() << ToolName << ": " << Path << ": " << Message << ".\n"; } -static bool error(error_code EC, Twine Path = Twine()) { +static bool error(std::error_code EC, Twine Path = Twine()) { if (EC) { error(EC.message(), Path); return true; diff --git a/tools/llvm-objdump/COFFDump.cpp b/tools/llvm-objdump/COFFDump.cpp index 84799ec8b00..39d8e8e39f8 100644 --- a/tools/llvm-objdump/COFFDump.cpp +++ b/tools/llvm-objdump/COFFDump.cpp @@ -29,7 +29,6 @@ using namespace llvm; using namespace object; using namespace llvm::Win64EH; -using std::error_code; // Returns the name of the unwind code. static StringRef getUnwindCodeTypeName(uint8_t Code) { @@ -158,14 +157,14 @@ static void printAllUnwindCodes(ArrayRef UCs) { } // Given a symbol sym this functions returns the address and section of it. -static error_code resolveSectionAndAddress(const COFFObjectFile *Obj, - const SymbolRef &Sym, - const coff_section *&ResolvedSection, - uint64_t &ResolvedAddr) { - if (error_code EC = Sym.getAddress(ResolvedAddr)) +static std::error_code +resolveSectionAndAddress(const COFFObjectFile *Obj, const SymbolRef &Sym, + const coff_section *&ResolvedSection, + uint64_t &ResolvedAddr) { + if (std::error_code EC = Sym.getAddress(ResolvedAddr)) return EC; section_iterator iter(Obj->section_begin()); - if (error_code EC = Sym.getSection(iter)) + if (std::error_code EC = Sym.getSection(iter)) return EC; ResolvedSection = Obj->getCOFFSection(*iter); return object_error::success; @@ -173,13 +172,13 @@ static error_code resolveSectionAndAddress(const COFFObjectFile *Obj, // Given a vector of relocations for a section and an offset into this section // the function returns the symbol used for the relocation at the offset. -static error_code resolveSymbol(const std::vector &Rels, - uint64_t Offset, SymbolRef &Sym) { +static std::error_code resolveSymbol(const std::vector &Rels, + uint64_t Offset, SymbolRef &Sym) { for (std::vector::const_iterator I = Rels.begin(), E = Rels.end(); I != E; ++I) { uint64_t Ofs; - if (error_code EC = I->getOffset(Ofs)) + if (std::error_code EC = I->getOffset(Ofs)) return EC; if (Ofs == Offset) { Sym = *I->getSymbol(); @@ -193,18 +192,17 @@ static error_code resolveSymbol(const std::vector &Rels, // the function resolves the symbol used for the relocation at the offset and // returns the section content and the address inside the content pointed to // by the symbol. -static error_code getSectionContents(const COFFObjectFile *Obj, - const std::vector &Rels, - uint64_t Offset, - ArrayRef &Contents, - uint64_t &Addr) { +static std::error_code +getSectionContents(const COFFObjectFile *Obj, + const std::vector &Rels, uint64_t Offset, + ArrayRef &Contents, uint64_t &Addr) { SymbolRef Sym; - if (error_code EC = resolveSymbol(Rels, Offset, Sym)) + if (std::error_code EC = resolveSymbol(Rels, Offset, Sym)) return EC; const coff_section *Section; - if (error_code EC = resolveSectionAndAddress(Obj, Sym, Section, Addr)) + if (std::error_code EC = resolveSectionAndAddress(Obj, Sym, Section, Addr)) return EC; - if (error_code EC = Obj->getSectionContents(Section, Contents)) + if (std::error_code EC = Obj->getSectionContents(Section, Contents)) return EC; return object_error::success; } @@ -212,12 +210,12 @@ static error_code getSectionContents(const COFFObjectFile *Obj, // Given a vector of relocations for a section and an offset into this section // the function returns the name of the symbol used for the relocation at the // offset. -static error_code resolveSymbolName(const std::vector &Rels, - uint64_t Offset, StringRef &Name) { +static std::error_code resolveSymbolName(const std::vector &Rels, + uint64_t Offset, StringRef &Name) { SymbolRef Sym; - if (error_code EC = resolveSymbol(Rels, Offset, Sym)) + if (std::error_code EC = resolveSymbol(Rels, Offset, Sym)) return EC; - if (error_code EC = Sym.getName(Name)) + if (std::error_code EC = Sym.getName(Name)) return EC; return object_error::success; } diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index cba73183546..21c4c96d4c2 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -42,7 +42,6 @@ #include using namespace llvm; using namespace object; -using std::error_code; static cl::opt UseDbg("g", cl::desc("Print line information from debug info if available")); @@ -198,7 +197,7 @@ static void DisassembleInputMachO2(StringRef Filename, void llvm::DisassembleInputMachO(StringRef Filename) { std::unique_ptr Buff; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) { + if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) { errs() << "llvm-objdump: " << Filename << ": " << ec.message() << "\n"; return; } @@ -290,7 +289,7 @@ static void DisassembleInputMachO2(StringRef Filename, // get the sections and supply it to the section name parsing machinery. if (!DSYMFile.empty()) { std::unique_ptr Buf; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(DSYMFile, Buf)) { + if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(DSYMFile, Buf)) { errs() << "llvm-objdump: " << Filename << ": " << ec.message() << '\n'; return; } diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 254c802aec4..e12ff3de2bb 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -64,7 +64,6 @@ using namespace llvm; using namespace object; -using std::error_code; static cl::list InputFilenames(cl::Positional, cl::desc(""),cl::ZeroOrMore); @@ -149,7 +148,7 @@ YAMLCFG("yaml-cfg", static StringRef ToolName; -bool llvm::error(error_code EC) { +bool llvm::error(std::error_code EC) { if (!EC) return false; @@ -396,7 +395,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { // Create a mapping, RelocSecs = SectionRelocMap[S], where sections // in RelocSecs contain the relocations for section S. - error_code EC; + std::error_code EC; std::map> SectionRelocMap; for (const SectionRef &Section : Obj->sections()) { section_iterator Sec2 = Section.getRelocatedSection(); @@ -621,7 +620,7 @@ static void PrintSectionHeaders(const ObjectFile *Obj) { } static void PrintSectionContents(const ObjectFile *Obj) { - error_code EC; + std::error_code EC; for (const SectionRef &Section : Obj->sections()) { StringRef Name; StringRef Contents; @@ -852,7 +851,7 @@ static void DumpArchive(const Archive *a) { for (Archive::child_iterator i = a->child_begin(), e = a->child_end(); i != e; ++i) { std::unique_ptr child; - if (error_code EC = i->getAsBinary(child)) { + if (std::error_code EC = i->getAsBinary(child)) { // Ignore non-object files. if (EC != object_error::invalid_file_type) errs() << ToolName << ": '" << a->getFileName() << "': " << EC.message() @@ -882,7 +881,7 @@ static void DumpInput(StringRef file) { // Attempt to open the binary. ErrorOr BinaryOrErr = createBinary(file); - if (error_code EC = BinaryOrErr.getError()) { + if (std::error_code EC = BinaryOrErr.getError()) { errs() << ToolName << ": '" << file << "': " << EC.message() << ".\n"; return; } diff --git a/tools/llvm-profdata/llvm-profdata.cpp b/tools/llvm-profdata/llvm-profdata.cpp index 9bf0897949f..ba88aad9ec7 100644 --- a/tools/llvm-profdata/llvm-profdata.cpp +++ b/tools/llvm-profdata/llvm-profdata.cpp @@ -24,7 +24,6 @@ #include "llvm/Support/raw_ostream.h" using namespace llvm; -using std::error_code; static void exitWithError(const Twine &Message, StringRef Whence = "") { errs() << "error: "; @@ -57,11 +56,12 @@ int merge_main(int argc, const char *argv[]) { InstrProfWriter Writer; for (const auto &Filename : Inputs) { std::unique_ptr Reader; - if (error_code ec = InstrProfReader::create(Filename, Reader)) + if (std::error_code ec = InstrProfReader::create(Filename, Reader)) exitWithError(ec.message(), Filename); for (const auto &I : *Reader) - if (error_code EC = Writer.addFunctionCounts(I.Name, I.Hash, I.Counts)) + if (std::error_code EC = + Writer.addFunctionCounts(I.Name, I.Hash, I.Counts)) errs() << Filename << ": " << I.Name << ": " << EC.message() << "\n"; if (Reader->hasError()) exitWithError(Reader->getError().message(), Filename); @@ -91,7 +91,7 @@ int show_main(int argc, const char *argv[]) { cl::ParseCommandLineOptions(argc, argv, "LLVM profile data summary\n"); std::unique_ptr Reader; - if (error_code EC = InstrProfReader::create(Filename, Reader)) + if (std::error_code EC = InstrProfReader::create(Filename, Reader)) exitWithError(EC.message(), Filename); if (OutputFilename.empty()) diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp index 0a14c42fe32..8b0dcb3e2c4 100644 --- a/tools/llvm-readobj/COFFDumper.cpp +++ b/tools/llvm-readobj/COFFDumper.cpp @@ -38,7 +38,6 @@ using namespace llvm; using namespace llvm::object; using namespace llvm::Win64EH; -using std::error_code; namespace { @@ -70,10 +69,10 @@ private: void cacheRelocations(); - error_code resolveSymbol(const coff_section *Section, uint64_t Offset, - SymbolRef &Sym); - error_code resolveSymbolName(const coff_section *Section, uint64_t Offset, - StringRef &Name); + std::error_code resolveSymbol(const coff_section *Section, uint64_t Offset, + SymbolRef &Sym); + std::error_code resolveSymbolName(const coff_section *Section, + uint64_t Offset, StringRef &Name); typedef DenseMap > RelocMapTy; @@ -86,8 +85,9 @@ private: namespace llvm { -error_code createCOFFDumper(const object::ObjectFile *Obj, StreamWriter &Writer, - std::unique_ptr &Result) { +std::error_code createCOFFDumper(const object::ObjectFile *Obj, + StreamWriter &Writer, + std::unique_ptr &Result) { const COFFObjectFile *COFFObj = dyn_cast(Obj); if (!COFFObj) return readobj_error::unsupported_obj_file_format; @@ -100,12 +100,12 @@ error_code createCOFFDumper(const object::ObjectFile *Obj, StreamWriter &Writer, // Given a a section and an offset into this section the function returns the // symbol used for the relocation at the offset. -error_code COFFDumper::resolveSymbol(const coff_section *Section, - uint64_t Offset, SymbolRef &Sym) { +std::error_code COFFDumper::resolveSymbol(const coff_section *Section, + uint64_t Offset, SymbolRef &Sym) { const auto &Relocations = RelocMap[Section]; for (const auto &Relocation : Relocations) { uint64_t RelocationOffset; - if (error_code EC = Relocation.getOffset(RelocationOffset)) + if (std::error_code EC = Relocation.getOffset(RelocationOffset)) return EC; if (RelocationOffset == Offset) { @@ -118,12 +118,13 @@ error_code COFFDumper::resolveSymbol(const coff_section *Section, // Given a section and an offset into this section the function returns the name // of the symbol used for the relocation at the offset. -error_code COFFDumper::resolveSymbolName(const coff_section *Section, - uint64_t Offset, StringRef &Name) { +std::error_code COFFDumper::resolveSymbolName(const coff_section *Section, + uint64_t Offset, + StringRef &Name) { SymbolRef Symbol; - if (error_code EC = resolveSymbol(Section, Offset, Symbol)) + if (std::error_code EC = resolveSymbol(Section, Offset, Symbol)) return EC; - if (error_code EC = Symbol.getName(Name)) + if (std::error_code EC = Symbol.getName(Name)) return EC; return object_error::success; } @@ -308,9 +309,10 @@ WeakExternalCharacteristics[] = { { "Alias" , COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS } }; -template -static error_code getSymbolAuxData(const COFFObjectFile *Obj, - const coff_symbol *Symbol, const T* &Aux) { +template +static std::error_code getSymbolAuxData(const COFFObjectFile *Obj, + const coff_symbol *Symbol, + const T *&Aux) { ArrayRef AuxData = Obj->getSymbolAuxData(Symbol); Aux = reinterpret_cast(AuxData.data()); return readobj_error::success; @@ -720,7 +722,7 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) { const coff_symbol *Symbol = Obj->getCOFFSymbol(Sym); const coff_section *Section; - if (error_code EC = Obj->getSection(Symbol->SectionNumber, Section)) { + if (std::error_code EC = Obj->getSection(Symbol->SectionNumber, Section)) { W.startLine() << "Invalid section number: " << EC.message() << "\n"; W.flush(); return; @@ -764,7 +766,7 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) { const coff_symbol *Linked; StringRef LinkedName; - error_code EC; + std::error_code EC; if ((EC = Obj->getSymbol(Aux->TagIndex, Linked)) || (EC = Obj->getSymbolName(Linked, LinkedName))) { LinkedName = ""; @@ -806,7 +808,7 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) { && Aux->Selection == COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE) { const coff_section *Assoc; StringRef AssocName; - error_code EC; + std::error_code EC; if ((EC = Obj->getSection(Aux->Number, Assoc)) || (EC = Obj->getSectionName(Assoc, AssocName))) { AssocName = ""; @@ -822,7 +824,7 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) { const coff_symbol *ReferredSym; StringRef ReferredName; - error_code EC; + std::error_code EC; if ((EC = Obj->getSymbol(Aux->SymbolTableIndex, ReferredSym)) || (EC = Obj->getSymbolName(ReferredSym, ReferredName))) { ReferredName = ""; @@ -850,12 +852,12 @@ void COFFDumper::printUnwindInfo() { switch (Header->Machine) { case COFF::IMAGE_FILE_MACHINE_AMD64: { Win64EH::Dumper Dumper(W); - Win64EH::Dumper::SymbolResolver Resolver = - [](const object::coff_section *Section, uint64_t Offset, - SymbolRef &Symbol, void *user_data) -> error_code { - COFFDumper *Dumper = reinterpret_cast(user_data); - return Dumper->resolveSymbol(Section, Offset, Symbol); - }; + Win64EH::Dumper::SymbolResolver + Resolver = [](const object::coff_section *Section, uint64_t Offset, + SymbolRef &Symbol, void *user_data) -> std::error_code { + COFFDumper *Dumper = reinterpret_cast(user_data); + return Dumper->resolveSymbol(Section, Offset, Symbol); + }; Win64EH::Dumper::Context Ctx(*Obj, Resolver, this); Dumper.printData(Ctx); break; diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index 8ec59bec008..f13b300d6da 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -30,7 +30,6 @@ using namespace llvm; using namespace llvm::object; using namespace ELF; -using std::error_code; #define LLVM_READOBJ_ENUM_CASE(ns, enum) \ case ns::enum: return #enum; @@ -82,15 +81,16 @@ template T errorOrDefault(ErrorOr Val, T Default = T()) { namespace llvm { template -static error_code createELFDumper(const ELFFile *Obj, - StreamWriter &Writer, - std::unique_ptr &Result) { +static std::error_code createELFDumper(const ELFFile *Obj, + StreamWriter &Writer, + std::unique_ptr &Result) { Result.reset(new ELFDumper(Obj, Writer)); return readobj_error::success; } -error_code createELFDumper(const object::ObjectFile *Obj, StreamWriter &Writer, - std::unique_ptr &Result) { +std::error_code createELFDumper(const object::ObjectFile *Obj, + StreamWriter &Writer, + std::unique_ptr &Result) { // Little-endian 32-bit if (const ELF32LEObjectFile *ELFObj = dyn_cast(Obj)) return createELFDumper(ELFObj->getELFFile(), Writer, Result); diff --git a/tools/llvm-readobj/MachODumper.cpp b/tools/llvm-readobj/MachODumper.cpp index 0c31bec993d..d168030a270 100644 --- a/tools/llvm-readobj/MachODumper.cpp +++ b/tools/llvm-readobj/MachODumper.cpp @@ -21,7 +21,6 @@ using namespace llvm; using namespace object; -using std::error_code; namespace { @@ -55,9 +54,9 @@ private: namespace llvm { -error_code createMachODumper(const object::ObjectFile *Obj, - StreamWriter &Writer, - std::unique_ptr &Result) { +std::error_code createMachODumper(const object::ObjectFile *Obj, + StreamWriter &Writer, + std::unique_ptr &Result) { const MachOObjectFile *MachOObj = dyn_cast(Obj); if (!MachOObj) return readobj_error::unsupported_obj_file_format; @@ -278,7 +277,7 @@ void MachODumper::printSections(const MachOObjectFile *Obj) { void MachODumper::printRelocations() { ListScope D(W, "Relocations"); - error_code EC; + std::error_code EC; for (const SectionRef &Section : Obj->sections()) { StringRef Name; if (error(Section.getName(Name))) diff --git a/tools/llvm-readobj/Win64EHDumper.cpp b/tools/llvm-readobj/Win64EHDumper.cpp index f3749fc36cc..f058632a8ce 100644 --- a/tools/llvm-readobj/Win64EHDumper.cpp +++ b/tools/llvm-readobj/Win64EHDumper.cpp @@ -16,7 +16,6 @@ using namespace llvm; using namespace llvm::object; using namespace llvm::Win64EH; -using std::error_code; static const EnumEntry UnwindFlags[] = { { "ExceptionHandler", UNW_ExceptionHandler }, @@ -135,20 +134,21 @@ static std::string formatSymbol(const Dumper::Context &Ctx, return OS.str(); } -static error_code resolveRelocation(const Dumper::Context &Ctx, - const coff_section *Section, - uint64_t Offset, - const coff_section *&ResolvedSection, - uint64_t &ResolvedAddress) { +static std::error_code resolveRelocation(const Dumper::Context &Ctx, + const coff_section *Section, + uint64_t Offset, + const coff_section *&ResolvedSection, + uint64_t &ResolvedAddress) { SymbolRef Symbol; - if (error_code EC = Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData)) + if (std::error_code EC = + Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData)) return EC; - if (error_code EC = Symbol.getAddress(ResolvedAddress)) + if (std::error_code EC = Symbol.getAddress(ResolvedAddress)) return EC; section_iterator SI = Ctx.COFF.section_begin(); - if (error_code EC = Symbol.getSection(SI)) + if (std::error_code EC = Symbol.getSection(SI)) return EC; ResolvedSection = Ctx.COFF.getCOFFSection(*SI); diff --git a/tools/llvm-readobj/llvm-readobj.cpp b/tools/llvm-readobj/llvm-readobj.cpp index 70af4dc4cb4..d66c02f4130 100644 --- a/tools/llvm-readobj/llvm-readobj.cpp +++ b/tools/llvm-readobj/llvm-readobj.cpp @@ -41,7 +41,6 @@ using namespace llvm; using namespace llvm::object; -using std::error_code; namespace opts { cl::list InputFilenames(cl::Positional, @@ -142,7 +141,7 @@ static int ReturnValue = EXIT_SUCCESS; namespace llvm { -bool error(error_code EC) { +bool error(std::error_code EC) { if (!EC) return false; @@ -161,8 +160,7 @@ bool relocAddressLess(RelocationRef a, RelocationRef b) { } // namespace llvm - -static void reportError(StringRef Input, error_code EC) { +static void reportError(StringRef Input, std::error_code EC) { if (Input == "-") Input = ""; @@ -180,8 +178,8 @@ static void reportError(StringRef Input, StringRef Message) { } /// @brief Creates an format-specific object file dumper. -static error_code createDumper(const ObjectFile *Obj, StreamWriter &Writer, - std::unique_ptr &Result) { +static std::error_code createDumper(const ObjectFile *Obj, StreamWriter &Writer, + std::unique_ptr &Result) { if (!Obj) return readobj_error::unsupported_file_format; @@ -200,7 +198,7 @@ static error_code createDumper(const ObjectFile *Obj, StreamWriter &Writer, static void dumpObject(const ObjectFile *Obj) { StreamWriter Writer(outs()); std::unique_ptr Dumper; - if (error_code EC = createDumper(Obj, Writer, Dumper)) { + if (std::error_code EC = createDumper(Obj, Writer, Dumper)) { reportError(Obj->getFileName(), EC); return; } @@ -245,7 +243,7 @@ static void dumpArchive(const Archive *Arc) { ArcE = Arc->child_end(); ArcI != ArcE; ++ArcI) { std::unique_ptr child; - if (error_code EC = ArcI->getAsBinary(child)) { + if (std::error_code EC = ArcI->getAsBinary(child)) { // Ignore non-object files. if (EC != object_error::invalid_file_type) reportError(Arc->getFileName(), EC.message()); @@ -270,7 +268,7 @@ static void dumpInput(StringRef File) { // Attempt to open the binary. ErrorOr BinaryOrErr = createBinary(File); - if (error_code EC = BinaryOrErr.getError()) { + if (std::error_code EC = BinaryOrErr.getError()) { reportError(File, EC); return; } diff --git a/tools/llvm-rtdyld/llvm-rtdyld.cpp b/tools/llvm-rtdyld/llvm-rtdyld.cpp index e86d93bd490..f1364d53503 100644 --- a/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -28,7 +28,6 @@ #include using namespace llvm; using namespace llvm::object; -using std::error_code; static cl::list InputFileList(cl::Positional, cl::ZeroOrMore, @@ -158,8 +157,8 @@ static int printLineInfoForInput() { // Load the input memory buffer. std::unique_ptr InputBuffer; std::unique_ptr LoadedObject; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFileList[i], - InputBuffer)) + if (std::error_code ec = + MemoryBuffer::getFileOrSTDIN(InputFileList[i], InputBuffer)) return Error("unable to read input: '" + ec.message() + "'"); // Load the object file @@ -219,8 +218,8 @@ static int executeInput() { // Load the input memory buffer. std::unique_ptr InputBuffer; std::unique_ptr LoadedObject; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFileList[i], - InputBuffer)) + if (std::error_code ec = + MemoryBuffer::getFileOrSTDIN(InputFileList[i], InputBuffer)) return Error("unable to read input: '" + ec.message() + "'"); // Load the object file diff --git a/tools/llvm-size/llvm-size.cpp b/tools/llvm-size/llvm-size.cpp index f0ec7fa6af6..1ea22a937a0 100644 --- a/tools/llvm-size/llvm-size.cpp +++ b/tools/llvm-size/llvm-size.cpp @@ -30,7 +30,6 @@ #include using namespace llvm; using namespace object; -using std::error_code; enum OutputFormatTy {berkeley, sysv}; static cl::opt @@ -69,7 +68,7 @@ static cl::list static std::string ToolName; /// @brief If ec is not success, print the error and return true. -static bool error(error_code ec) { +static bool error(std::error_code ec) { if (!ec) return false; outs() << ToolName << ": error reading file: " << ec.message() << ".\n"; @@ -236,7 +235,7 @@ static void PrintFileSectionSizes(StringRef file) { // Attempt to open the binary. ErrorOr BinaryOrErr = createBinary(file); - if (error_code EC = BinaryOrErr.getError()) { + if (std::error_code EC = BinaryOrErr.getError()) { errs() << ToolName << ": " << file << ": " << EC.message() << ".\n"; return; } @@ -247,7 +246,7 @@ static void PrintFileSectionSizes(StringRef file) { for (object::Archive::child_iterator i = a->child_begin(), e = a->child_end(); i != e; ++i) { std::unique_ptr child; - if (error_code ec = i->getAsBinary(child)) { + if (std::error_code ec = i->getAsBinary(child)) { errs() << ToolName << ": " << file << ": " << ec.message() << ".\n"; continue; } diff --git a/tools/llvm-symbolizer/LLVMSymbolize.cpp b/tools/llvm-symbolizer/LLVMSymbolize.cpp index 61c4e8ad209..c6bd4e7abfc 100644 --- a/tools/llvm-symbolizer/LLVMSymbolize.cpp +++ b/tools/llvm-symbolizer/LLVMSymbolize.cpp @@ -26,10 +26,9 @@ #include namespace llvm { -using std::error_code; namespace symbolize { -static bool error(error_code ec) { +static bool error(std::error_code ec) { if (!ec) return false; errs() << "LLVMSymbolizer: error reading file: " << ec.message() << ".\n"; @@ -311,7 +310,7 @@ LLVMSymbolizer::getOrCreateBinary(const std::string &Path) { const std::string &ResourcePath = getDarwinDWARFResourceForPath(Path); BinaryOrErr = createBinary(ResourcePath); - error_code EC = BinaryOrErr.getError(); + std::error_code EC = BinaryOrErr.getError(); if (EC != std::errc::no_such_file_or_directory && !error(EC)) { DbgBin = BinaryOrErr.get(); ParsedBinariesAndObjects.push_back(std::unique_ptr(DbgBin)); diff --git a/tools/llvm-symbolizer/llvm-symbolizer.cpp b/tools/llvm-symbolizer/llvm-symbolizer.cpp index 2ee30e816e4..29db172531b 100644 --- a/tools/llvm-symbolizer/llvm-symbolizer.cpp +++ b/tools/llvm-symbolizer/llvm-symbolizer.cpp @@ -29,7 +29,6 @@ using namespace llvm; using namespace symbolize; -using std::error_code; static cl::opt ClUseSymbolTable("use-symbol-table", cl::init(true), diff --git a/tools/macho-dump/macho-dump.cpp b/tools/macho-dump/macho-dump.cpp index 13e8a4b80ca..bfe1a6eaef4 100644 --- a/tools/macho-dump/macho-dump.cpp +++ b/tools/macho-dump/macho-dump.cpp @@ -23,7 +23,6 @@ #include using namespace llvm; using namespace llvm::object; -using std::error_code; static cl::opt InputFile(cl::Positional, cl::desc(""), cl::init("-")); @@ -392,7 +391,7 @@ int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv, "llvm Mach-O dumping tool\n"); ErrorOr BinaryOrErr = createBinary(InputFile); - if (error_code EC = BinaryOrErr.getError()) + if (std::error_code EC = BinaryOrErr.getError()) return Error("unable to read input: '" + EC.message() + "'"); std::unique_ptr Binary(BinaryOrErr.get()); diff --git a/tools/obj2yaml/coff2yaml.cpp b/tools/obj2yaml/coff2yaml.cpp index 816f9e65cde..48462f69fc5 100644 --- a/tools/obj2yaml/coff2yaml.cpp +++ b/tools/obj2yaml/coff2yaml.cpp @@ -14,7 +14,6 @@ #include "llvm/Support/YAMLTraits.h" using namespace llvm; -using std::error_code; namespace { @@ -32,7 +31,7 @@ public: } -static void check(error_code ec) { +static void check(std::error_code ec) { if (ec) report_fatal_error(ec.message()); } @@ -211,7 +210,7 @@ COFFYAML::Object &COFFDumper::getYAMLObj() { return YAMLObj; } -error_code coff2yaml(raw_ostream &Out, const object::COFFObjectFile &Obj) { +std::error_code coff2yaml(raw_ostream &Out, const object::COFFObjectFile &Obj) { COFFDumper Dumper(Obj); yaml::Output Yout(Out); diff --git a/tools/obj2yaml/elf2yaml.cpp b/tools/obj2yaml/elf2yaml.cpp index a20ad6f3e2c..c817e1526da 100644 --- a/tools/obj2yaml/elf2yaml.cpp +++ b/tools/obj2yaml/elf2yaml.cpp @@ -16,7 +16,6 @@ #include "llvm/Support/YAMLTraits.h" using namespace llvm; -using std::error_code; namespace { @@ -27,13 +26,13 @@ class ELFDumper { const object::ELFFile &Obj; - error_code dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S); - error_code dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S); - error_code dumpCommonRelocationSection(const Elf_Shdr *Shdr, - ELFYAML::RelocationSection &S); + std::error_code dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S); + std::error_code dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S); + std::error_code dumpCommonRelocationSection(const Elf_Shdr *Shdr, + ELFYAML::RelocationSection &S); template - error_code dumpRelocation(const Elf_Shdr *Shdr, const RelT *Rel, - ELFYAML::Relocation &R); + std::error_code dumpRelocation(const Elf_Shdr *Shdr, const RelT *Rel, + ELFYAML::Relocation &R); ErrorOr dumpRelSection(const Elf_Shdr *Shdr); ErrorOr dumpRelaSection(const Elf_Shdr *Shdr); @@ -75,14 +74,14 @@ ErrorOr ELFDumper::dump() { break; case ELF::SHT_RELA: { ErrorOr S = dumpRelaSection(&Sec); - if (error_code EC = S.getError()) + if (std::error_code EC = S.getError()) return EC; Y->Sections.push_back(std::unique_ptr(S.get())); break; } case ELF::SHT_REL: { ErrorOr S = dumpRelSection(&Sec); - if (error_code EC = S.getError()) + if (std::error_code EC = S.getError()) return EC; Y->Sections.push_back(std::unique_ptr(S.get())); break; @@ -90,7 +89,7 @@ ErrorOr ELFDumper::dump() { // FIXME: Support SHT_GROUP section format. default: { ErrorOr S = dumpContentSection(&Sec); - if (error_code EC = S.getError()) + if (std::error_code EC = S.getError()) return EC; Y->Sections.push_back(std::unique_ptr(S.get())); } @@ -106,7 +105,7 @@ ErrorOr ELFDumper::dump() { } ELFYAML::Symbol S; - if (error_code EC = ELFDumper::dumpSymbol(SI, S)) + if (std::error_code EC = ELFDumper::dumpSymbol(SI, S)) return EC; switch (SI->getBinding()) @@ -129,14 +128,15 @@ ErrorOr ELFDumper::dump() { } template -error_code ELFDumper::dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S) { +std::error_code ELFDumper::dumpSymbol(Elf_Sym_Iter Sym, + ELFYAML::Symbol &S) { S.Type = Sym->getType(); S.Value = Sym->st_value; S.Size = Sym->st_size; S.Visibility = Sym->st_other & 0x3; ErrorOr NameOrErr = Obj.getSymbolName(Sym); - if (error_code EC = NameOrErr.getError()) + if (std::error_code EC = NameOrErr.getError()) return EC; S.Name = NameOrErr.get(); @@ -145,7 +145,7 @@ error_code ELFDumper::dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S) { return obj2yaml_error::success; NameOrErr = Obj.getSectionName(Shdr); - if (error_code EC = NameOrErr.getError()) + if (std::error_code EC = NameOrErr.getError()) return EC; S.Section = NameOrErr.get(); @@ -154,9 +154,9 @@ error_code ELFDumper::dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S) { template template -error_code ELFDumper::dumpRelocation(const Elf_Shdr *Shdr, - const RelT *Rel, - ELFYAML::Relocation &R) { +std::error_code ELFDumper::dumpRelocation(const Elf_Shdr *Shdr, + const RelT *Rel, + ELFYAML::Relocation &R) { R.Type = Rel->getType(Obj.isMips64EL()); R.Offset = Rel->r_offset; R.Addend = 0; @@ -167,7 +167,7 @@ error_code ELFDumper::dumpRelocation(const Elf_Shdr *Shdr, ErrorOr NameOrErr = Obj.getSymbolName(NamePair.first, NamePair.second); - if (error_code EC = NameOrErr.getError()) + if (std::error_code EC = NameOrErr.getError()) return EC; R.Symbol = NameOrErr.get(); @@ -175,22 +175,22 @@ error_code ELFDumper::dumpRelocation(const Elf_Shdr *Shdr, } template -error_code ELFDumper::dumpCommonSection(const Elf_Shdr *Shdr, - ELFYAML::Section &S) { +std::error_code ELFDumper::dumpCommonSection(const Elf_Shdr *Shdr, + ELFYAML::Section &S) { S.Type = Shdr->sh_type; S.Flags = Shdr->sh_flags; S.Address = Shdr->sh_addr; S.AddressAlign = Shdr->sh_addralign; ErrorOr NameOrErr = Obj.getSectionName(Shdr); - if (error_code EC = NameOrErr.getError()) + if (std::error_code EC = NameOrErr.getError()) return EC; S.Name = NameOrErr.get(); if (Shdr->sh_link != ELF::SHN_UNDEF) { if (const Elf_Shdr *LinkSection = Obj.getSection(Shdr->sh_link)) { NameOrErr = Obj.getSectionName(LinkSection); - if (error_code EC = NameOrErr.getError()) + if (std::error_code EC = NameOrErr.getError()) return EC; S.Link = NameOrErr.get(); } @@ -200,15 +200,15 @@ error_code ELFDumper::dumpCommonSection(const Elf_Shdr *Shdr, } template -error_code +std::error_code ELFDumper::dumpCommonRelocationSection(const Elf_Shdr *Shdr, ELFYAML::RelocationSection &S) { - if (error_code EC = dumpCommonSection(Shdr, S)) + if (std::error_code EC = dumpCommonSection(Shdr, S)) return EC; if (const Elf_Shdr *InfoSection = Obj.getSection(Shdr->sh_info)) { ErrorOr NameOrErr = Obj.getSectionName(InfoSection); - if (error_code EC = NameOrErr.getError()) + if (std::error_code EC = NameOrErr.getError()) return EC; S.Info = NameOrErr.get(); } @@ -222,13 +222,13 @@ ELFDumper::dumpRelSection(const Elf_Shdr *Shdr) { assert(Shdr->sh_type == ELF::SHT_REL && "Section type is not SHT_REL"); auto S = make_unique(); - if (error_code EC = dumpCommonRelocationSection(Shdr, *S)) + if (std::error_code EC = dumpCommonRelocationSection(Shdr, *S)) return EC; for (auto RI = Obj.begin_rel(Shdr), RE = Obj.end_rel(Shdr); RI != RE; ++RI) { ELFYAML::Relocation R; - if (error_code EC = dumpRelocation(Shdr, &*RI, R)) + if (std::error_code EC = dumpRelocation(Shdr, &*RI, R)) return EC; S->Relocations.push_back(R); } @@ -242,13 +242,13 @@ ELFDumper::dumpRelaSection(const Elf_Shdr *Shdr) { assert(Shdr->sh_type == ELF::SHT_RELA && "Section type is not SHT_RELA"); auto S = make_unique(); - if (error_code EC = dumpCommonRelocationSection(Shdr, *S)) + if (std::error_code EC = dumpCommonRelocationSection(Shdr, *S)) return EC; for (auto RI = Obj.begin_rela(Shdr), RE = Obj.end_rela(Shdr); RI != RE; ++RI) { ELFYAML::Relocation R; - if (error_code EC = dumpRelocation(Shdr, &*RI, R)) + if (std::error_code EC = dumpRelocation(Shdr, &*RI, R)) return EC; R.Addend = RI->r_addend; S->Relocations.push_back(R); @@ -262,11 +262,11 @@ ErrorOr ELFDumper::dumpContentSection(const Elf_Shdr *Shdr) { auto S = make_unique(); - if (error_code EC = dumpCommonSection(Shdr, *S)) + if (std::error_code EC = dumpCommonSection(Shdr, *S)) return EC; ErrorOr> ContentOrErr = Obj.getSectionContents(Shdr); - if (error_code EC = ContentOrErr.getError()) + if (std::error_code EC = ContentOrErr.getError()) return EC; S->Content = object::yaml::BinaryRef(ContentOrErr.get()); S->Size = S->Content.binary_size(); @@ -275,10 +275,11 @@ ELFDumper::dumpContentSection(const Elf_Shdr *Shdr) { } template -static error_code elf2yaml(raw_ostream &Out, const object::ELFFile &Obj) { +static std::error_code elf2yaml(raw_ostream &Out, + const object::ELFFile &Obj) { ELFDumper Dumper(Obj); ErrorOr YAMLOrErr = Dumper.dump(); - if (error_code EC = YAMLOrErr.getError()) + if (std::error_code EC = YAMLOrErr.getError()) return EC; std::unique_ptr YAML(YAMLOrErr.get()); @@ -288,7 +289,7 @@ static error_code elf2yaml(raw_ostream &Out, const object::ELFFile &Obj) { return object::object_error::success; } -error_code elf2yaml(raw_ostream &Out, const object::ObjectFile &Obj) { +std::error_code elf2yaml(raw_ostream &Out, const object::ObjectFile &Obj) { if (const auto *ELFObj = dyn_cast(&Obj)) return elf2yaml(Out, *ELFObj->getELFFile()); diff --git a/tools/obj2yaml/obj2yaml.cpp b/tools/obj2yaml/obj2yaml.cpp index 717c68d1c63..944314a923f 100644 --- a/tools/obj2yaml/obj2yaml.cpp +++ b/tools/obj2yaml/obj2yaml.cpp @@ -18,9 +18,8 @@ using namespace llvm; using namespace llvm::object; -using std::error_code; -static error_code dumpObject(const ObjectFile &Obj) { +static std::error_code dumpObject(const ObjectFile &Obj) { if (Obj.isCOFF()) return coff2yaml(outs(), cast(Obj)); if (Obj.isELF()) @@ -29,12 +28,12 @@ static error_code dumpObject(const ObjectFile &Obj) { return obj2yaml_error::unsupported_obj_file_format; } -static error_code dumpInput(StringRef File) { +static std::error_code dumpInput(StringRef File) { if (File != "-" && !sys::fs::exists(File)) return obj2yaml_error::file_not_found; ErrorOr BinaryOrErr = createBinary(File); - if (error_code EC = BinaryOrErr.getError()) + if (std::error_code EC = BinaryOrErr.getError()) return EC; std::unique_ptr Binary(BinaryOrErr.get()); @@ -54,7 +53,7 @@ int main(int argc, char *argv[]) { PrettyStackTraceProgram X(argc, argv); llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. - if (error_code EC = dumpInput(InputFilename)) { + if (std::error_code EC = dumpInput(InputFilename)) { errs() << "Error: '" << EC.message() << "'\n"; return 1; }