From 4e2b922131ae617cb8738d1871e9d918c44bdb69 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 13 Jun 2014 02:24:39 +0000 Subject: Remove 'using std::errro_code' from lib. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210871 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AsmParser/Parser.cpp | 3 +- lib/Bitcode/Reader/BitReader.cpp | 5 +- lib/Bitcode/Reader/BitcodeReader.cpp | 161 +++++++------ lib/DebugInfo/DWARFContext.cpp | 3 +- lib/ExecutionEngine/Interpreter/Interpreter.cpp | 3 +- lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp | 9 +- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | 15 +- lib/IR/Core.cpp | 5 +- lib/IR/GCOV.cpp | 3 +- lib/IR/Module.cpp | 13 +- lib/IRReader/IRReader.cpp | 9 +- lib/LTO/LTOCodeGenerator.cpp | 6 +- lib/LTO/LTOModule.cpp | 7 +- lib/MC/MCContext.cpp | 3 +- lib/MC/MCModuleYAML.cpp | 3 +- lib/Object/Archive.cpp | 30 +-- lib/Object/COFFObjectFile.cpp | 254 +++++++++++---------- lib/Object/ELFObjectFile.cpp | 3 +- lib/Object/IRObjectFile.cpp | 9 +- lib/Object/MachOObjectFile.cpp | 1 - lib/Object/MachOUniversal.cpp | 18 +- lib/Object/Object.cpp | 29 ++- lib/Object/ObjectFile.cpp | 13 +- lib/ProfileData/InstrProfReader.cpp | 41 ++-- lib/Support/DataStream.cpp | 7 +- lib/Support/FileOutputBuffer.cpp | 17 +- lib/Support/FileUtilities.cpp | 5 +- lib/Support/LockFileManager.cpp | 11 +- lib/Support/MemoryBuffer.cpp | 107 ++++----- lib/Support/Path.cpp | 106 ++++----- lib/Support/Unix/Memory.inc | 27 ++- lib/Support/Unix/Path.inc | 128 ++++++----- lib/Support/Unix/Process.inc | 10 +- lib/Support/Unix/Program.inc | 9 +- lib/Support/Windows/Memory.inc | 25 +- lib/Support/Windows/Process.inc | 9 +- lib/Support/Windows/Program.inc | 19 +- lib/Support/YAMLTraits.cpp | 5 +- lib/TableGen/Main.cpp | 4 +- lib/Transforms/Scalar/SampleProfile.cpp | 3 +- lib/Transforms/Scalar/SimplifyCFGPass.cpp | 1 - lib/Transforms/Utils/SpecialCaseList.cpp | 3 +- 42 files changed, 562 insertions(+), 580 deletions(-) (limited to 'lib') diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp index 1dfcc191cb..067cac8578 100644 --- a/lib/AsmParser/Parser.cpp +++ b/lib/AsmParser/Parser.cpp @@ -20,7 +20,6 @@ #include #include using namespace llvm; -using std::error_code; Module *llvm::ParseAssembly(MemoryBuffer *F, Module *M, @@ -43,7 +42,7 @@ Module *llvm::ParseAssembly(MemoryBuffer *F, Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err, LLVMContext &Context) { std::unique_ptr File; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, File)) { + if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, File)) { Err = SMDiagnostic(Filename, SourceMgr::DK_Error, "Could not open input file: " + ec.message()); return nullptr; diff --git a/lib/Bitcode/Reader/BitReader.cpp b/lib/Bitcode/Reader/BitReader.cpp index 2610e7f96e..b5886c16fa 100644 --- a/lib/Bitcode/Reader/BitReader.cpp +++ b/lib/Bitcode/Reader/BitReader.cpp @@ -16,7 +16,6 @@ #include using namespace llvm; -using std::error_code; /* Builds a module from the bitcode in the specified memory buffer, returning a reference to the module via the OutModule parameter. Returns 0 on success. @@ -33,7 +32,7 @@ LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef, char **OutMessage) { ErrorOr ModuleOrErr = parseBitcodeFile(unwrap(MemBuf), *unwrap(ContextRef)); - if (error_code EC = ModuleOrErr.getError()) { + if (std::error_code EC = ModuleOrErr.getError()) { if (OutMessage) *OutMessage = strdup(EC.message().c_str()); *OutModule = wrap((Module*)nullptr); @@ -55,7 +54,7 @@ LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef, ErrorOr ModuleOrErr = getLazyBitcodeModule(unwrap(MemBuf), *unwrap(ContextRef)); - if (error_code EC = ModuleOrErr.getError()) { + if (std::error_code EC = ModuleOrErr.getError()) { *OutM = wrap((Module *)nullptr); if (OutMessage) *OutMessage = strdup(EC.message().c_str()); diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index cafdd12529..cd40857e3c 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -26,7 +26,6 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; -using std::error_code; enum { SWITCH_INST_MAGIC = 0x4B5 // May 2012 => 1205 => Hex @@ -471,7 +470,7 @@ static void decodeLLVMAttributesForBitcode(AttrBuilder &B, (EncodedAttrs & 0xffff)); } -error_code BitcodeReader::ParseAttributeBlock() { +std::error_code BitcodeReader::ParseAttributeBlock() { if (Stream.EnterSubBlock(bitc::PARAMATTR_BLOCK_ID)) return Error(InvalidRecord); @@ -491,7 +490,7 @@ error_code BitcodeReader::ParseAttributeBlock() { case BitstreamEntry::Error: return Error(MalformedBlock); case BitstreamEntry::EndBlock: - return error_code(); + return std::error_code(); case BitstreamEntry::Record: // The interesting case. break; @@ -617,15 +616,15 @@ static Attribute::AttrKind GetAttrFromCode(uint64_t Code) { } } -error_code BitcodeReader::ParseAttrKind(uint64_t Code, - Attribute::AttrKind *Kind) { +std::error_code BitcodeReader::ParseAttrKind(uint64_t Code, + Attribute::AttrKind *Kind) { *Kind = GetAttrFromCode(Code); if (*Kind == Attribute::None) return Error(InvalidValue); - return error_code(); + return std::error_code(); } -error_code BitcodeReader::ParseAttributeGroupBlock() { +std::error_code BitcodeReader::ParseAttributeGroupBlock() { if (Stream.EnterSubBlock(bitc::PARAMATTR_GROUP_BLOCK_ID)) return Error(InvalidRecord); @@ -643,7 +642,7 @@ error_code BitcodeReader::ParseAttributeGroupBlock() { case BitstreamEntry::Error: return Error(MalformedBlock); case BitstreamEntry::EndBlock: - return error_code(); + return std::error_code(); case BitstreamEntry::Record: // The interesting case. break; @@ -665,13 +664,13 @@ error_code BitcodeReader::ParseAttributeGroupBlock() { for (unsigned i = 2, e = Record.size(); i != e; ++i) { if (Record[i] == 0) { // Enum attribute Attribute::AttrKind Kind; - if (error_code EC = ParseAttrKind(Record[++i], &Kind)) + if (std::error_code EC = ParseAttrKind(Record[++i], &Kind)) return EC; B.addAttribute(Kind); } else if (Record[i] == 1) { // Align attribute Attribute::AttrKind Kind; - if (error_code EC = ParseAttrKind(Record[++i], &Kind)) + if (std::error_code EC = ParseAttrKind(Record[++i], &Kind)) return EC; if (Kind == Attribute::Alignment) B.addAlignmentAttr(Record[++i]); @@ -707,14 +706,14 @@ error_code BitcodeReader::ParseAttributeGroupBlock() { } } -error_code BitcodeReader::ParseTypeTable() { +std::error_code BitcodeReader::ParseTypeTable() { if (Stream.EnterSubBlock(bitc::TYPE_BLOCK_ID_NEW)) return Error(InvalidRecord); return ParseTypeTableBody(); } -error_code BitcodeReader::ParseTypeTableBody() { +std::error_code BitcodeReader::ParseTypeTableBody() { if (!TypeList.empty()) return Error(InvalidMultipleBlocks); @@ -734,7 +733,7 @@ error_code BitcodeReader::ParseTypeTableBody() { case BitstreamEntry::EndBlock: if (NumRecords != TypeList.size()) return Error(MalformedBlock); - return error_code(); + return std::error_code(); case BitstreamEntry::Record: // The interesting case. break; @@ -934,7 +933,7 @@ error_code BitcodeReader::ParseTypeTableBody() { } } -error_code BitcodeReader::ParseValueSymbolTable() { +std::error_code BitcodeReader::ParseValueSymbolTable() { if (Stream.EnterSubBlock(bitc::VALUE_SYMTAB_BLOCK_ID)) return Error(InvalidRecord); @@ -950,7 +949,7 @@ error_code BitcodeReader::ParseValueSymbolTable() { case BitstreamEntry::Error: return Error(MalformedBlock); case BitstreamEntry::EndBlock: - return error_code(); + return std::error_code(); case BitstreamEntry::Record: // The interesting case. break; @@ -988,7 +987,7 @@ error_code BitcodeReader::ParseValueSymbolTable() { } } -error_code BitcodeReader::ParseMetadata() { +std::error_code BitcodeReader::ParseMetadata() { unsigned NextMDValueNo = MDValueList.size(); if (Stream.EnterSubBlock(bitc::METADATA_BLOCK_ID)) @@ -1005,7 +1004,7 @@ error_code BitcodeReader::ParseMetadata() { case BitstreamEntry::Error: return Error(MalformedBlock); case BitstreamEntry::EndBlock: - return error_code(); + return std::error_code(); case BitstreamEntry::Record: // The interesting case. break; @@ -1099,7 +1098,7 @@ uint64_t BitcodeReader::decodeSignRotatedValue(uint64_t V) { /// ResolveGlobalAndAliasInits - Resolve all of the initializers for global /// values and aliases that we can. -error_code BitcodeReader::ResolveGlobalAndAliasInits() { +std::error_code BitcodeReader::ResolveGlobalAndAliasInits() { std::vector > GlobalInitWorklist; std::vector > AliasInitWorklist; std::vector > FunctionPrefixWorklist; @@ -1148,7 +1147,7 @@ error_code BitcodeReader::ResolveGlobalAndAliasInits() { FunctionPrefixWorklist.pop_back(); } - return error_code(); + return std::error_code(); } static APInt ReadWideAPInt(ArrayRef Vals, unsigned TypeBits) { @@ -1159,7 +1158,7 @@ static APInt ReadWideAPInt(ArrayRef Vals, unsigned TypeBits) { return APInt(TypeBits, Words); } -error_code BitcodeReader::ParseConstants() { +std::error_code BitcodeReader::ParseConstants() { if (Stream.EnterSubBlock(bitc::CONSTANTS_BLOCK_ID)) return Error(InvalidRecord); @@ -1182,7 +1181,7 @@ error_code BitcodeReader::ParseConstants() { // Once all the constants have been read, go through and resolve forward // references. ValueList.ResolveConstantForwardRefs(); - return error_code(); + return std::error_code(); case BitstreamEntry::Record: // The interesting case. break; @@ -1597,7 +1596,7 @@ error_code BitcodeReader::ParseConstants() { } } -error_code BitcodeReader::ParseUseLists() { +std::error_code BitcodeReader::ParseUseLists() { if (Stream.EnterSubBlock(bitc::USELIST_BLOCK_ID)) return Error(InvalidRecord); @@ -1612,7 +1611,7 @@ error_code BitcodeReader::ParseUseLists() { case BitstreamEntry::Error: return Error(MalformedBlock); case BitstreamEntry::EndBlock: - return error_code(); + return std::error_code(); case BitstreamEntry::Record: // The interesting case. break; @@ -1637,7 +1636,7 @@ error_code BitcodeReader::ParseUseLists() { /// RememberAndSkipFunctionBody - When we see the block for a function body, /// remember where it is and then skip it. This lets us lazily deserialize the /// functions. -error_code BitcodeReader::RememberAndSkipFunctionBody() { +std::error_code BitcodeReader::RememberAndSkipFunctionBody() { // Get the function we are talking about. if (FunctionsWithBodies.empty()) return Error(InsufficientFunctionProtos); @@ -1652,10 +1651,10 @@ error_code BitcodeReader::RememberAndSkipFunctionBody() { // Skip over the function block for now. if (Stream.SkipBlock()) return Error(InvalidRecord); - return error_code(); + return std::error_code(); } -error_code BitcodeReader::GlobalCleanup() { +std::error_code BitcodeReader::GlobalCleanup() { // Patch the initializers for globals and aliases up. ResolveGlobalAndAliasInits(); if (!GlobalInits.empty() || !AliasInits.empty()) @@ -1681,10 +1680,10 @@ error_code BitcodeReader::GlobalCleanup() { // want lazy deserialization. std::vector >().swap(GlobalInits); std::vector >().swap(AliasInits); - return error_code(); + return std::error_code(); } -error_code BitcodeReader::ParseModule(bool Resume) { +std::error_code BitcodeReader::ParseModule(bool Resume) { if (Resume) Stream.JumpToBit(NextUnreadBit); else if (Stream.EnterSubBlock(bitc::MODULE_BLOCK_ID)) @@ -1715,30 +1714,30 @@ error_code BitcodeReader::ParseModule(bool Resume) { return Error(MalformedBlock); break; case bitc::PARAMATTR_BLOCK_ID: - if (error_code EC = ParseAttributeBlock()) + if (std::error_code EC = ParseAttributeBlock()) return EC; break; case bitc::PARAMATTR_GROUP_BLOCK_ID: - if (error_code EC = ParseAttributeGroupBlock()) + if (std::error_code EC = ParseAttributeGroupBlock()) return EC; break; case bitc::TYPE_BLOCK_ID_NEW: - if (error_code EC = ParseTypeTable()) + if (std::error_code EC = ParseTypeTable()) return EC; break; case bitc::VALUE_SYMTAB_BLOCK_ID: - if (error_code EC = ParseValueSymbolTable()) + if (std::error_code EC = ParseValueSymbolTable()) return EC; SeenValueSymbolTable = true; break; case bitc::CONSTANTS_BLOCK_ID: - if (error_code EC = ParseConstants()) + if (std::error_code EC = ParseConstants()) return EC; - if (error_code EC = ResolveGlobalAndAliasInits()) + if (std::error_code EC = ResolveGlobalAndAliasInits()) return EC; break; case bitc::METADATA_BLOCK_ID: - if (error_code EC = ParseMetadata()) + if (std::error_code EC = ParseMetadata()) return EC; break; case bitc::FUNCTION_BLOCK_ID: @@ -1746,12 +1745,12 @@ error_code BitcodeReader::ParseModule(bool Resume) { // FunctionsWithBodies list. if (!SeenFirstFunctionBody) { std::reverse(FunctionsWithBodies.begin(), FunctionsWithBodies.end()); - if (error_code EC = GlobalCleanup()) + if (std::error_code EC = GlobalCleanup()) return EC; SeenFirstFunctionBody = true; } - if (error_code EC = RememberAndSkipFunctionBody()) + if (std::error_code EC = RememberAndSkipFunctionBody()) return EC; // For streaming bitcode, suspend parsing when we reach the function // bodies. Subsequent materialization calls will resume it when @@ -1761,11 +1760,11 @@ error_code BitcodeReader::ParseModule(bool Resume) { // just finish the parse now. if (LazyStreamer && SeenValueSymbolTable) { NextUnreadBit = Stream.GetCurrentBitNo(); - return error_code(); + return std::error_code(); } break; case bitc::USELIST_BLOCK_ID: - if (error_code EC = ParseUseLists()) + if (std::error_code EC = ParseUseLists()) return EC; break; } @@ -2007,10 +2006,10 @@ error_code BitcodeReader::ParseModule(bool Resume) { } } -error_code BitcodeReader::ParseBitcodeInto(Module *M) { +std::error_code BitcodeReader::ParseBitcodeInto(Module *M) { TheModule = nullptr; - if (error_code EC = InitStream()) + if (std::error_code EC = InitStream()) return EC; // Sniff for the signature. @@ -2026,7 +2025,7 @@ error_code BitcodeReader::ParseBitcodeInto(Module *M) { // need to understand them all. while (1) { if (Stream.AtEndOfStream()) - return error_code(); + return std::error_code(); BitstreamEntry Entry = Stream.advance(BitstreamCursor::AF_DontAutoprocessAbbrevs); @@ -2035,7 +2034,7 @@ error_code BitcodeReader::ParseBitcodeInto(Module *M) { case BitstreamEntry::Error: return Error(MalformedBlock); case BitstreamEntry::EndBlock: - return error_code(); + return std::error_code(); case BitstreamEntry::SubBlock: switch (Entry.ID) { @@ -2048,10 +2047,10 @@ error_code BitcodeReader::ParseBitcodeInto(Module *M) { if (TheModule) return Error(InvalidMultipleBlocks); TheModule = M; - if (error_code EC = ParseModule(false)) + if (std::error_code EC = ParseModule(false)) return EC; if (LazyStreamer) - return error_code(); + return std::error_code(); break; default: if (Stream.SkipBlock()) @@ -2068,14 +2067,14 @@ error_code BitcodeReader::ParseBitcodeInto(Module *M) { if (Stream.getAbbrevIDWidth() == 2 && Entry.ID == 2 && Stream.Read(6) == 2 && Stream.Read(24) == 0xa0a0a && Stream.AtEndOfStream()) - return error_code(); + return std::error_code(); return Error(InvalidRecord); } } } -error_code BitcodeReader::ParseModuleTriple(std::string &Triple) { +std::error_code BitcodeReader::ParseModuleTriple(std::string &Triple) { if (Stream.EnterSubBlock(bitc::MODULE_BLOCK_ID)) return Error(InvalidRecord); @@ -2090,7 +2089,7 @@ error_code BitcodeReader::ParseModuleTriple(std::string &Triple) { case BitstreamEntry::Error: return Error(MalformedBlock); case BitstreamEntry::EndBlock: - return error_code(); + return std::error_code(); case BitstreamEntry::Record: // The interesting case. break; @@ -2111,8 +2110,8 @@ error_code BitcodeReader::ParseModuleTriple(std::string &Triple) { } } -error_code BitcodeReader::ParseTriple(std::string &Triple) { - if (error_code EC = InitStream()) +std::error_code BitcodeReader::ParseTriple(std::string &Triple) { + if (std::error_code EC = InitStream()) return EC; // Sniff for the signature. @@ -2133,7 +2132,7 @@ error_code BitcodeReader::ParseTriple(std::string &Triple) { case BitstreamEntry::Error: return Error(MalformedBlock); case BitstreamEntry::EndBlock: - return error_code(); + return std::error_code(); case BitstreamEntry::SubBlock: if (Entry.ID == bitc::MODULE_BLOCK_ID) @@ -2152,7 +2151,7 @@ error_code BitcodeReader::ParseTriple(std::string &Triple) { } /// ParseMetadataAttachment - Parse metadata attachments. -error_code BitcodeReader::ParseMetadataAttachment() { +std::error_code BitcodeReader::ParseMetadataAttachment() { if (Stream.EnterSubBlock(bitc::METADATA_ATTACHMENT_ID)) return Error(InvalidRecord); @@ -2165,7 +2164,7 @@ error_code BitcodeReader::ParseMetadataAttachment() { case BitstreamEntry::Error: return Error(MalformedBlock); case BitstreamEntry::EndBlock: - return error_code(); + return std::error_code(); case BitstreamEntry::Record: // The interesting case. break; @@ -2199,7 +2198,7 @@ error_code BitcodeReader::ParseMetadataAttachment() { } /// ParseFunctionBody - Lazily parse the specified function body block. -error_code BitcodeReader::ParseFunctionBody(Function *F) { +std::error_code BitcodeReader::ParseFunctionBody(Function *F) { if (Stream.EnterSubBlock(bitc::FUNCTION_BLOCK_ID)) return Error(InvalidRecord); @@ -2235,20 +2234,20 @@ error_code BitcodeReader::ParseFunctionBody(Function *F) { return Error(InvalidRecord); break; case bitc::CONSTANTS_BLOCK_ID: - if (error_code EC = ParseConstants()) + if (std::error_code EC = ParseConstants()) return EC; NextValueNo = ValueList.size(); break; case bitc::VALUE_SYMTAB_BLOCK_ID: - if (error_code EC = ParseValueSymbolTable()) + if (std::error_code EC = ParseValueSymbolTable()) return EC; break; case bitc::METADATA_ATTACHMENT_ID: - if (error_code EC = ParseMetadataAttachment()) + if (std::error_code EC = ParseMetadataAttachment()) return EC; break; case bitc::METADATA_BLOCK_ID: - if (error_code EC = ParseMetadata()) + if (std::error_code EC = ParseMetadata()) return EC; break; } @@ -3118,21 +3117,22 @@ OutOfRecordLoop: ValueList.shrinkTo(ModuleValueListSize); MDValueList.shrinkTo(ModuleMDValueListSize); std::vector().swap(FunctionBBs); - return error_code(); + return std::error_code(); } /// Find the function body in the bitcode stream -error_code BitcodeReader::FindFunctionInStream(Function *F, - DenseMap::iterator DeferredFunctionInfoIterator) { +std::error_code BitcodeReader::FindFunctionInStream( + Function *F, + DenseMap::iterator DeferredFunctionInfoIterator) { while (DeferredFunctionInfoIterator->second == 0) { if (Stream.AtEndOfStream()) return Error(CouldNotFindFunctionInStream); // ParseModule will parse the next body in the stream and set its // position in the DeferredFunctionInfo map. - if (error_code EC = ParseModule(true)) + if (std::error_code EC = ParseModule(true)) return EC; } - return error_code(); + return std::error_code(); } //===----------------------------------------------------------------------===// @@ -3148,24 +3148,24 @@ bool BitcodeReader::isMaterializable(const GlobalValue *GV) const { return false; } -error_code BitcodeReader::Materialize(GlobalValue *GV) { +std::error_code BitcodeReader::Materialize(GlobalValue *GV) { Function *F = dyn_cast(GV); // If it's not a function or is already material, ignore the request. if (!F || !F->isMaterializable()) - return error_code(); + return std::error_code(); DenseMap::iterator DFII = DeferredFunctionInfo.find(F); assert(DFII != DeferredFunctionInfo.end() && "Deferred function not found!"); // If its position is recorded as 0, its body is somewhere in the stream // but we haven't seen it yet. if (DFII->second == 0 && LazyStreamer) - if (error_code EC = FindFunctionInStream(F, DFII)) + if (std::error_code EC = FindFunctionInStream(F, DFII)) return EC; // Move the bit stream to the saved position of the deferred function body. Stream.JumpToBit(DFII->second); - if (error_code EC = ParseFunctionBody(F)) + if (std::error_code EC = ParseFunctionBody(F)) return EC; // Upgrade any old intrinsic calls in the function. @@ -3180,7 +3180,7 @@ error_code BitcodeReader::Materialize(GlobalValue *GV) { } } - return error_code(); + return std::error_code(); } bool BitcodeReader::isDematerializable(const GlobalValue *GV) const { @@ -3202,8 +3202,7 @@ void BitcodeReader::Dematerialize(GlobalValue *GV) { F->deleteBody(); } - -error_code BitcodeReader::MaterializeModule(Module *M) { +std::error_code BitcodeReader::MaterializeModule(Module *M) { assert(M == TheModule && "Can only Materialize the Module this BitcodeReader is attached to."); // Iterate over the module, deserializing any functions that are still on @@ -3211,7 +3210,7 @@ error_code BitcodeReader::MaterializeModule(Module *M) { for (Module::iterator F = TheModule->begin(), E = TheModule->end(); F != E; ++F) { if (F->isMaterializable()) { - if (error_code EC = Materialize(F)) + if (std::error_code EC = Materialize(F)) return EC; } } @@ -3244,16 +3243,16 @@ error_code BitcodeReader::MaterializeModule(Module *M) { UpgradeInstWithTBAATag(InstsWithTBAATag[I]); UpgradeDebugInfo(*M); - return error_code(); + return std::error_code(); } -error_code BitcodeReader::InitStream() { +std::error_code BitcodeReader::InitStream() { if (LazyStreamer) return InitLazyStream(); return InitStreamFromBuffer(); } -error_code BitcodeReader::InitStreamFromBuffer() { +std::error_code BitcodeReader::InitStreamFromBuffer() { const unsigned char *BufPtr = (const unsigned char*)Buffer->getBufferStart(); const unsigned char *BufEnd = BufPtr+Buffer->getBufferSize(); @@ -3273,10 +3272,10 @@ error_code BitcodeReader::InitStreamFromBuffer() { StreamFile.reset(new BitstreamReader(BufPtr, BufEnd)); Stream.init(*StreamFile); - return error_code(); + return std::error_code(); } -error_code BitcodeReader::InitLazyStream() { +std::error_code BitcodeReader::InitLazyStream() { // Check and strip off the bitcode wrapper; BitstreamReader expects never to // see it. StreamingMemoryObject *Bytes = new StreamingMemoryObject(LazyStreamer); @@ -3297,7 +3296,7 @@ error_code BitcodeReader::InitLazyStream() { Bytes->dropLeadingBytes(bitcodeStart - buf); Bytes->setKnownObjectSize(bitcodeEnd - bitcodeStart); } - return error_code(); + return std::error_code(); } namespace { @@ -3368,7 +3367,7 @@ ErrorOr llvm::getLazyBitcodeModule(MemoryBuffer *Buffer, Module *M = new Module(Buffer->getBufferIdentifier(), Context); BitcodeReader *R = new BitcodeReader(Buffer, Context); M->setMaterializer(R); - if (error_code EC = R->ParseBitcodeInto(M)) { + if (std::error_code EC = R->ParseBitcodeInto(M)) { delete M; // Also deletes R. return EC; } @@ -3388,7 +3387,7 @@ Module *llvm::getStreamedBitcodeModule(const std::string &name, Module *M = new Module(name, Context); BitcodeReader *R = new BitcodeReader(streamer, Context); M->setMaterializer(R); - if (error_code EC = R->ParseBitcodeInto(M)) { + if (std::error_code EC = R->ParseBitcodeInto(M)) { if (ErrMsg) *ErrMsg = EC.message(); delete M; // Also deletes R. @@ -3410,7 +3409,7 @@ ErrorOr llvm::parseBitcodeFile(MemoryBuffer *Buffer, static_cast(M->getMaterializer())->setBufferOwned(false); // Read in the entire module, and destroy the BitcodeReader. - if (error_code EC = M->materializeAllPermanently()) { + if (std::error_code EC = M->materializeAllPermanently()) { delete M; return EC; } @@ -3429,7 +3428,7 @@ std::string llvm::getBitcodeTargetTriple(MemoryBuffer *Buffer, R->setBufferOwned(false); std::string Triple(""); - if (error_code EC = R->ParseTriple(Triple)) + if (std::error_code EC = R->ParseTriple(Triple)) if (ErrMsg) *ErrMsg = EC.message(); diff --git a/lib/DebugInfo/DWARFContext.cpp b/lib/DebugInfo/DWARFContext.cpp index 110fd815da..3961905f65 100644 --- a/lib/DebugInfo/DWARFContext.cpp +++ b/lib/DebugInfo/DWARFContext.cpp @@ -21,7 +21,6 @@ using namespace llvm; using namespace dwarf; using namespace object; -using std::error_code; #define DEBUG_TYPE "dwarf" @@ -735,7 +734,7 @@ DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) object::RelocToApply R(V.visit(Type, Reloc, 0, SymAddr)); if (V.error()) { SmallString<32> Name; - error_code ec(Reloc.getTypeName(Name)); + std::error_code ec(Reloc.getTypeName(Name)); if (ec) { errs() << "Aaaaaa! Nameless relocation! Aaaaaa!\n"; } diff --git a/lib/ExecutionEngine/Interpreter/Interpreter.cpp b/lib/ExecutionEngine/Interpreter/Interpreter.cpp index e3e63f4d5f..814efcc27f 100644 --- a/lib/ExecutionEngine/Interpreter/Interpreter.cpp +++ b/lib/ExecutionEngine/Interpreter/Interpreter.cpp @@ -19,7 +19,6 @@ #include "llvm/IR/Module.h" #include using namespace llvm; -using std::error_code; namespace { @@ -35,7 +34,7 @@ extern "C" void LLVMLinkInInterpreter() { } /// ExecutionEngine *Interpreter::create(Module *M, std::string* ErrStr) { // Tell this Module to materialize everything and release the GVMaterializer. - if (error_code EC = M->materializeAllPermanently()) { + if (std::error_code EC = M->materializeAllPermanently()) { if (ErrStr) *ErrStr = EC.message(); // We got an error, just return 0 diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp index b1558c029f..9dfd1678de 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -23,7 +23,6 @@ using namespace llvm; using namespace llvm::object; -using std::error_code; #define DEBUG_TYPE "dyld" @@ -74,9 +73,9 @@ void RuntimeDyldImpl::mapSectionAddress(const void *LocalAddress, llvm_unreachable("Attempting to remap address of unknown section!"); } -static error_code getOffset(const SymbolRef &Sym, uint64_t &Result) { +static std::error_code getOffset(const SymbolRef &Sym, uint64_t &Result) { uint64_t Address; - if (error_code EC = Sym.getAddress(Address)) + if (std::error_code EC = Sym.getAddress(Address)) return EC; if (Address == UnknownAddressOrSize) { @@ -86,7 +85,7 @@ static error_code getOffset(const SymbolRef &Sym, uint64_t &Result) { const ObjectFile *Obj = Sym.getObject(); section_iterator SecI(Obj->section_begin()); - if (error_code EC = Sym.getSection(SecI)) + if (std::error_code EC = Sym.getSection(SecI)) return EC; if (SecI == Obj->section_end()) { @@ -95,7 +94,7 @@ static error_code getOffset(const SymbolRef &Sym, uint64_t &Result) { } uint64_t SectionAddress; - if (error_code EC = SecI->getAddress(SectionAddress)) + if (std::error_code EC = SecI->getAddress(SectionAddress)) return EC; Result = Address - SectionAddress; diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index ec825b82ee..56471f43b2 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -27,13 +27,12 @@ using namespace llvm; using namespace llvm::object; -using std::error_code; #define DEBUG_TYPE "dyld" namespace { -static inline error_code check(error_code Err) { +static inline std::error_code check(std::error_code Err) { if (Err) { report_fatal_error(Err.message()); } @@ -56,9 +55,9 @@ template class DyldELFObject : public ELFObjectFile { public: DyldELFObject(std::unique_ptr UnderlyingFile, - MemoryBuffer *Wrapper, error_code &ec); + MemoryBuffer *Wrapper, std::error_code &ec); - DyldELFObject(MemoryBuffer *Wrapper, error_code &ec); + DyldELFObject(MemoryBuffer *Wrapper, std::error_code &ec); void updateSectionAddress(const SectionRef &Sec, uint64_t Addr); void updateSymbolAddress(const SymbolRef &Sym, uint64_t Addr); @@ -110,14 +109,14 @@ public: // actual memory. Ultimately, the Binary parent class will take ownership of // this MemoryBuffer object but not the underlying memory. template -DyldELFObject::DyldELFObject(MemoryBuffer *Wrapper, error_code &ec) +DyldELFObject::DyldELFObject(MemoryBuffer *Wrapper, std::error_code &ec) : ELFObjectFile(Wrapper, ec) { this->isDyldELFObject = true; } template DyldELFObject::DyldELFObject(std::unique_ptr UnderlyingFile, - MemoryBuffer *Wrapper, error_code &ec) + MemoryBuffer *Wrapper, std::error_code &ec) : ELFObjectFile(Wrapper, ec), UnderlyingFile(std::move(UnderlyingFile)) { this->isDyldELFObject = true; @@ -183,7 +182,7 @@ RuntimeDyldELF::createObjectImageFromFile(std::unique_ptr Ob if (!ObjFile) return nullptr; - error_code ec; + std::error_code ec; MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(ObjFile->getData(), "", false); @@ -219,7 +218,7 @@ ObjectImage *RuntimeDyldELF::createObjectImage(ObjectBuffer *Buffer) { std::pair Ident = std::make_pair((uint8_t)Buffer->getBufferStart()[ELF::EI_CLASS], (uint8_t)Buffer->getBufferStart()[ELF::EI_DATA]); - error_code ec; + std::error_code ec; if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2LSB) { auto Obj = diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 5dfe9a68a2..197b6cb905 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -41,7 +41,6 @@ #include using namespace llvm; -using std::error_code; #define DEBUG_TYPE "ir" @@ -2602,7 +2601,7 @@ LLVMBool LLVMCreateMemoryBufferWithContentsOfFile( char **OutMessage) { std::unique_ptr MB; - error_code ec; + std::error_code ec; if (!(ec = MemoryBuffer::getFile(Path, MB))) { *OutMemBuf = wrap(MB.release()); return 0; @@ -2615,7 +2614,7 @@ LLVMBool LLVMCreateMemoryBufferWithContentsOfFile( LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf, char **OutMessage) { std::unique_ptr MB; - error_code ec; + std::error_code ec; if (!(ec = MemoryBuffer::getSTDIN(MB))) { *OutMemBuf = wrap(MB.release()); return 0; diff --git a/lib/IR/GCOV.cpp b/lib/IR/GCOV.cpp index c8dc951a9b..b4c7977d52 100644 --- a/lib/IR/GCOV.cpp +++ b/lib/IR/GCOV.cpp @@ -22,7 +22,6 @@ #include #include using namespace llvm; -using std::error_code; //===----------------------------------------------------------------------===// // GCOVFile implementation. @@ -439,7 +438,7 @@ class LineConsumer { StringRef Remaining; public: LineConsumer(StringRef Filename) { - if (error_code EC = MemoryBuffer::getFileOrSTDIN(Filename, Buffer)) { + if (std::error_code EC = MemoryBuffer::getFileOrSTDIN(Filename, Buffer)) { errs() << Filename << ": " << EC.message() << "\n"; Remaining = ""; } else diff --git a/lib/IR/Module.cpp b/lib/IR/Module.cpp index bc72a67917..6a5b386c19 100644 --- a/lib/IR/Module.cpp +++ b/lib/IR/Module.cpp @@ -28,7 +28,6 @@ #include #include using namespace llvm; -using std::error_code; //===----------------------------------------------------------------------===// // Methods to implement the globals and functions lists. @@ -382,7 +381,7 @@ bool Module::Materialize(GlobalValue *GV, std::string *ErrInfo) { if (!Materializer) return false; - error_code EC = Materializer->Materialize(GV); + std::error_code EC = Materializer->Materialize(GV); if (!EC) return false; if (ErrInfo) @@ -395,18 +394,18 @@ void Module::Dematerialize(GlobalValue *GV) { return Materializer->Dematerialize(GV); } -error_code Module::materializeAll() { +std::error_code Module::materializeAll() { if (!Materializer) - return error_code(); + return std::error_code(); return Materializer->MaterializeModule(this); } -error_code Module::materializeAllPermanently() { - if (error_code EC = materializeAll()) +std::error_code Module::materializeAllPermanently() { + if (std::error_code EC = materializeAll()) return EC; Materializer.reset(); - return error_code(); + return std::error_code(); } //===----------------------------------------------------------------------===// diff --git a/lib/IRReader/IRReader.cpp b/lib/IRReader/IRReader.cpp index e170a3c85a..01aa074aba 100644 --- a/lib/IRReader/IRReader.cpp +++ b/lib/IRReader/IRReader.cpp @@ -21,7 +21,6 @@ #include using namespace llvm; -using std::error_code; namespace llvm { extern bool TimePassesIsEnabled; @@ -37,7 +36,7 @@ Module *llvm::getLazyIRModule(MemoryBuffer *Buffer, SMDiagnostic &Err, (const unsigned char *)Buffer->getBufferEnd())) { std::string ErrMsg; ErrorOr ModuleOrErr = getLazyBitcodeModule(Buffer, Context); - if (error_code EC = ModuleOrErr.getError()) { + if (std::error_code EC = ModuleOrErr.getError()) { Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error, EC.message()); // ParseBitcodeFile does not take ownership of the Buffer in the @@ -54,7 +53,7 @@ Module *llvm::getLazyIRModule(MemoryBuffer *Buffer, SMDiagnostic &Err, Module *llvm::getLazyIRFileModule(const std::string &Filename, SMDiagnostic &Err, LLVMContext &Context) { std::unique_ptr File; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, File)) { + if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, File)) { Err = SMDiagnostic(Filename, SourceMgr::DK_Error, "Could not open input file: " + ec.message()); return nullptr; @@ -71,7 +70,7 @@ Module *llvm::ParseIR(MemoryBuffer *Buffer, SMDiagnostic &Err, (const unsigned char *)Buffer->getBufferEnd())) { ErrorOr ModuleOrErr = parseBitcodeFile(Buffer, Context); Module *M = nullptr; - if (error_code EC = ModuleOrErr.getError()) + if (std::error_code EC = ModuleOrErr.getError()) Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error, EC.message()); else @@ -87,7 +86,7 @@ Module *llvm::ParseIR(MemoryBuffer *Buffer, SMDiagnostic &Err, Module *llvm::ParseIRFile(const std::string &Filename, SMDiagnostic &Err, LLVMContext &Context) { std::unique_ptr File; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, File)) { + if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, File)) { Err = SMDiagnostic(Filename, SourceMgr::DK_Error, "Could not open input file: " + ec.message()); return nullptr; diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index c263f8f477..9009958613 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -53,7 +53,6 @@ #include "llvm/Transforms/ObjCARC.h" #include using namespace llvm; -using std::error_code; const char* LTOCodeGenerator::getVersionString() { #ifdef LLVM_VERSION_INFO @@ -209,7 +208,8 @@ bool LTOCodeGenerator::compile_to_file(const char** name, // make unique temp .o file to put generated object file SmallString<128> Filename; int FD; - error_code EC = sys::fs::createTemporaryFile("lto-llvm", "o", FD, Filename); + std::error_code EC = + sys::fs::createTemporaryFile("lto-llvm", "o", FD, Filename); if (EC) { errMsg = EC.message(); return false; @@ -253,7 +253,7 @@ const void* LTOCodeGenerator::compile(size_t* length, // read .o file into memory buffer std::unique_ptr BuffPtr; - if (error_code ec = MemoryBuffer::getFile(name, BuffPtr, -1, false)) { + if (std::error_code ec = MemoryBuffer::getFile(name, BuffPtr, -1, false)) { errMsg = ec.message(); sys::fs::remove(NativeObjectPath); return nullptr; diff --git a/lib/LTO/LTOModule.cpp b/lib/LTO/LTOModule.cpp index aee0ef8cdc..eac48e16e8 100644 --- a/lib/LTO/LTOModule.cpp +++ b/lib/LTO/LTOModule.cpp @@ -43,7 +43,6 @@ #include "llvm/Transforms/Utils/GlobalStatus.h" #include using namespace llvm; -using std::error_code; LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t) : _module(m), _target(t), @@ -99,7 +98,7 @@ bool LTOModule::isTargetMatch(MemoryBuffer *buffer, const char *triplePrefix) { LTOModule *LTOModule::makeLTOModule(const char *path, TargetOptions options, std::string &errMsg) { std::unique_ptr buffer; - if (error_code ec = MemoryBuffer::getFile(path, buffer)) { + if (std::error_code ec = MemoryBuffer::getFile(path, buffer)) { errMsg = ec.message(); return nullptr; } @@ -118,7 +117,7 @@ LTOModule *LTOModule::makeLTOModule(int fd, const char *path, TargetOptions options, std::string &errMsg) { std::unique_ptr buffer; - if (error_code ec = + if (std::error_code ec = MemoryBuffer::getOpenFileSlice(fd, path, buffer, map_size, offset)) { errMsg = ec.message(); return nullptr; @@ -141,7 +140,7 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer, // parse bitcode buffer ErrorOr ModuleOrErr = getLazyBitcodeModule(buffer, getGlobalContext()); - if (error_code EC = ModuleOrErr.getError()) { + if (std::error_code EC = ModuleOrErr.getError()) { errMsg = EC.message(); delete buffer; return nullptr; diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 4ec621fea0..cc98be6ea6 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -28,7 +28,6 @@ #include using namespace llvm; -using std::error_code; MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri, const MCObjectFileInfo *mofi, const SourceMgr *mgr, @@ -40,7 +39,7 @@ MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri, AllowTemporaryLabels(true), DwarfCompileUnitID(0), AutoReset(DoAutoReset) { - error_code EC = llvm::sys::fs::current_path(CompilationDir); + std::error_code EC = llvm::sys::fs::current_path(CompilationDir); if (EC) CompilationDir.clear(); diff --git a/lib/MC/MCModuleYAML.cpp b/lib/MC/MCModuleYAML.cpp index 0df6afd9f0..f6b7431eb3 100644 --- a/lib/MC/MCModuleYAML.cpp +++ b/lib/MC/MCModuleYAML.cpp @@ -25,7 +25,6 @@ #include namespace llvm { -using std::error_code; namespace { @@ -454,7 +453,7 @@ StringRef yaml2mcmodule(std::unique_ptr &MCM, StringRef YamlContent, InstrRegInfoHolder IRI(MII, MRI); yaml::Input YIn(YamlContent, (void *)&IRI); YIn >> YAMLModule; - if (error_code ec = YIn.error()) + if (std::error_code ec = YIn.error()) return ec.message(); StringRef err = Parser.parse(YAMLModule); if (!err.empty()) diff --git a/lib/Object/Archive.cpp b/lib/Object/Archive.cpp index 1e66da0639..8b362d66db 100644 --- a/lib/Object/Archive.cpp +++ b/lib/Object/Archive.cpp @@ -20,7 +20,6 @@ using namespace llvm; using namespace object; -using std::error_code; static const char *const Magic = "!\n"; @@ -116,7 +115,7 @@ Archive::Child Archive::Child::getNext() const { return Child(Parent, NextLoc); } -error_code Archive::Child::getName(StringRef &Result) const { +std::error_code Archive::Child::getName(StringRef &Result) const { StringRef name = getRawName(); // Check if it's a special name. if (name[0] == '/') { @@ -169,10 +168,11 @@ error_code Archive::Child::getName(StringRef &Result) const { return object_error::success; } -error_code Archive::Child::getMemoryBuffer(std::unique_ptr &Result, - bool FullPath) const { +std::error_code +Archive::Child::getMemoryBuffer(std::unique_ptr &Result, + bool FullPath) const { StringRef Name; - if (error_code ec = getName(Name)) + if (std::error_code ec = getName(Name)) return ec; SmallString<128> Path; Result.reset(MemoryBuffer::getMemBuffer( @@ -180,32 +180,32 @@ error_code Archive::Child::getMemoryBuffer(std::unique_ptr &Result .toStringRef(Path) : Name, false)); - return error_code(); + return std::error_code(); } -error_code Archive::Child::getAsBinary(std::unique_ptr &Result, - LLVMContext *Context) const { +std::error_code Archive::Child::getAsBinary(std::unique_ptr &Result, + LLVMContext *Context) const { std::unique_ptr ret; std::unique_ptr Buff; - if (error_code ec = getMemoryBuffer(Buff)) + if (std::error_code ec = getMemoryBuffer(Buff)) return ec; ErrorOr BinaryOrErr = createBinary(Buff.release(), Context); - if (error_code EC = BinaryOrErr.getError()) + if (std::error_code EC = BinaryOrErr.getError()) return EC; Result.reset(BinaryOrErr.get()); return object_error::success; } ErrorOr Archive::create(MemoryBuffer *Source) { - error_code EC; + std::error_code EC; std::unique_ptr Ret(new Archive(Source, EC)); if (EC) return EC; return Ret.release(); } -Archive::Archive(MemoryBuffer *source, error_code &ec) - : Binary(Binary::ID_Archive, source), SymbolTable(child_end()) { +Archive::Archive(MemoryBuffer *source, std::error_code &ec) + : Binary(Binary::ID_Archive, source), SymbolTable(child_end()) { // Check for sufficient magic. assert(source); if (source->getBufferSize() < 8 || @@ -336,12 +336,12 @@ Archive::child_iterator Archive::child_end() const { return Child(this, nullptr); } -error_code Archive::Symbol::getName(StringRef &Result) const { +std::error_code Archive::Symbol::getName(StringRef &Result) const { Result = StringRef(Parent->SymbolTable->getBuffer().begin() + StringIndex); return object_error::success; } -error_code Archive::Symbol::getMember(child_iterator &Result) const { +std::error_code Archive::Symbol::getMember(child_iterator &Result) const { const char *Buf = Parent->SymbolTable->getBuffer().begin(); const char *Offsets = Buf + 4; uint32_t Offset = 0; diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index 8528840e12..186d64bafd 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -24,7 +24,6 @@ using namespace llvm; using namespace object; -using std::error_code; using support::ulittle8_t; using support::ulittle16_t; @@ -32,7 +31,8 @@ using support::ulittle32_t; using support::little16_t; // Returns false if size is greater than the buffer size. And sets ec. -static bool checkSize(const MemoryBuffer *M, error_code &EC, uint64_t Size) { +static bool checkSize(const MemoryBuffer *M, std::error_code &EC, + uint64_t Size) { if (M->getBufferSize() < Size) { EC = object_error::unexpected_eof; return false; @@ -42,9 +42,10 @@ static bool checkSize(const MemoryBuffer *M, error_code &EC, uint64_t Size) { // Sets Obj unless any bytes in [addr, addr + size) fall outsize of m. // Returns unexpected_eof if error. -template -static error_code getObject(const T *&Obj, const MemoryBuffer *M, - const uint8_t *Ptr, const size_t Size = sizeof(T)) { +template +static std::error_code getObject(const T *&Obj, const MemoryBuffer *M, + const uint8_t *Ptr, + const size_t Size = sizeof(T)) { uintptr_t Addr = uintptr_t(Ptr); if (Addr + Size < Addr || Addr + Size < Size || @@ -130,17 +131,17 @@ void COFFObjectFile::moveSymbolNext(DataRefImpl &Ref) const { Ref.p = reinterpret_cast(Symb); } -error_code COFFObjectFile::getSymbolName(DataRefImpl Ref, - StringRef &Result) const { +std::error_code COFFObjectFile::getSymbolName(DataRefImpl Ref, + StringRef &Result) const { const coff_symbol *Symb = toSymb(Ref); return getSymbolName(Symb, Result); } -error_code COFFObjectFile::getSymbolAddress(DataRefImpl Ref, - uint64_t &Result) const { +std::error_code COFFObjectFile::getSymbolAddress(DataRefImpl Ref, + uint64_t &Result) const { const coff_symbol *Symb = toSymb(Ref); const coff_section *Section = nullptr; - if (error_code EC = getSection(Symb->SectionNumber, Section)) + if (std::error_code EC = getSection(Symb->SectionNumber, Section)) return EC; if (Symb->SectionNumber == COFF::IMAGE_SYM_UNDEFINED) @@ -152,8 +153,8 @@ error_code COFFObjectFile::getSymbolAddress(DataRefImpl Ref, return object_error::success; } -error_code COFFObjectFile::getSymbolType(DataRefImpl Ref, - SymbolRef::Type &Result) const { +std::error_code COFFObjectFile::getSymbolType(DataRefImpl Ref, + SymbolRef::Type &Result) const { const coff_symbol *Symb = toSymb(Ref); Result = SymbolRef::ST_Other; if (Symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL && @@ -165,7 +166,7 @@ error_code COFFObjectFile::getSymbolType(DataRefImpl Ref, uint32_t Characteristics = 0; if (!COFF::isReservedSectionNumber(Symb->SectionNumber)) { const coff_section *Section = nullptr; - if (error_code EC = getSection(Symb->SectionNumber, Section)) + if (std::error_code EC = getSection(Symb->SectionNumber, Section)) return EC; Characteristics = Section->Characteristics; } @@ -203,14 +204,14 @@ uint32_t COFFObjectFile::getSymbolFlags(DataRefImpl Ref) const { return Result; } -error_code COFFObjectFile::getSymbolSize(DataRefImpl Ref, - uint64_t &Result) const { +std::error_code COFFObjectFile::getSymbolSize(DataRefImpl Ref, + uint64_t &Result) const { // FIXME: Return the correct size. This requires looking at all the symbols // in the same section as this symbol, and looking for either the next // symbol, or the end of the section. const coff_symbol *Symb = toSymb(Ref); const coff_section *Section = nullptr; - if (error_code EC = getSection(Symb->SectionNumber, Section)) + if (std::error_code EC = getSection(Symb->SectionNumber, Section)) return EC; if (Symb->SectionNumber == COFF::IMAGE_SYM_UNDEFINED) @@ -222,14 +223,16 @@ error_code COFFObjectFile::getSymbolSize(DataRefImpl Ref, return object_error::success; } -error_code COFFObjectFile::getSymbolSection(DataRefImpl Ref, - section_iterator &Result) const { +std::error_code +COFFObjectFile::getSymbolSection(DataRefImpl Ref, + section_iterator &Result) const { const coff_symbol *Symb = toSymb(Ref); if (COFF::isReservedSectionNumber(Symb->SectionNumber)) { Result = section_end(); } else { const coff_section *Sec = nullptr; - if (error_code EC = getSection(Symb->SectionNumber, Sec)) return EC; + if (std::error_code EC = getSection(Symb->SectionNumber, Sec)) + return EC; DataRefImpl Ref; Ref.p = reinterpret_cast(Sec); Result = section_iterator(SectionRef(Ref, this)); @@ -243,37 +246,37 @@ void COFFObjectFile::moveSectionNext(DataRefImpl &Ref) const { Ref.p = reinterpret_cast(Sec); } -error_code COFFObjectFile::getSectionName(DataRefImpl Ref, - StringRef &Result) const { +std::error_code COFFObjectFile::getSectionName(DataRefImpl Ref, + StringRef &Result) const { const coff_section *Sec = toSec(Ref); return getSectionName(Sec, Result); } -error_code COFFObjectFile::getSectionAddress(DataRefImpl Ref, - uint64_t &Result) const { +std::error_code COFFObjectFile::getSectionAddress(DataRefImpl Ref, + uint64_t &Result) const { const coff_section *Sec = toSec(Ref); Result = Sec->VirtualAddress; return object_error::success; } -error_code COFFObjectFile::getSectionSize(DataRefImpl Ref, - uint64_t &Result) const { +std::error_code COFFObjectFile::getSectionSize(DataRefImpl Ref, + uint64_t &Result) const { const coff_section *Sec = toSec(Ref); Result = Sec->SizeOfRawData; return object_error::success; } -error_code COFFObjectFile::getSectionContents(DataRefImpl Ref, - StringRef &Result) const { +std::error_code COFFObjectFile::getSectionContents(DataRefImpl Ref, + StringRef &Result) const { const coff_section *Sec = toSec(Ref); ArrayRef Res; - error_code EC = getSectionContents(Sec, Res); + std::error_code EC = getSectionContents(Sec, Res); Result = StringRef(reinterpret_cast(Res.data()), Res.size()); return EC; } -error_code COFFObjectFile::getSectionAlignment(DataRefImpl Ref, - uint64_t &Res) const { +std::error_code COFFObjectFile::getSectionAlignment(DataRefImpl Ref, + uint64_t &Res) const { const coff_section *Sec = toSec(Ref); if (!Sec) return object_error::parse_failed; @@ -281,62 +284,64 @@ error_code COFFObjectFile::getSectionAlignment(DataRefImpl Ref, return object_error::success; } -error_code COFFObjectFile::isSectionText(DataRefImpl Ref, - bool &Result) const { +std::error_code COFFObjectFile::isSectionText(DataRefImpl Ref, + bool &Result) const { const coff_section *Sec = toSec(Ref); Result = Sec->Characteristics & COFF::IMAGE_SCN_CNT_CODE; return object_error::success; } -error_code COFFObjectFile::isSectionData(DataRefImpl Ref, - bool &Result) const { +std::error_code COFFObjectFile::isSectionData(DataRefImpl Ref, + bool &Result) const { const coff_section *Sec = toSec(Ref); Result = Sec->Characteristics & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA; return object_error::success; } -error_code COFFObjectFile::isSectionBSS(DataRefImpl Ref, - bool &Result) const { +std::error_code COFFObjectFile::isSectionBSS(DataRefImpl Ref, + bool &Result) const { const coff_section *Sec = toSec(Ref); Result = Sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA; return object_error::success; } -error_code COFFObjectFile::isSectionRequiredForExecution(DataRefImpl Ref, - bool &Result) const { +std::error_code +COFFObjectFile::isSectionRequiredForExecution(DataRefImpl Ref, + bool &Result) const { // FIXME: Unimplemented Result = true; return object_error::success; } -error_code COFFObjectFile::isSectionVirtual(DataRefImpl Ref, - bool &Result) const { +std::error_code COFFObjectFile::isSectionVirtual(DataRefImpl Ref, + bool &Result) const { const coff_section *Sec = toSec(Ref); Result = Sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA; return object_error::success; } -error_code COFFObjectFile::isSectionZeroInit(DataRefImpl Ref, - bool &Result) const { +std::error_code COFFObjectFile::isSectionZeroInit(DataRefImpl Ref, + bool &Result) const { // FIXME: Unimplemented. Result = false; return object_error::success; } -error_code COFFObjectFile::isSectionReadOnlyData(DataRefImpl Ref, - bool &Result) const { +std::error_code COFFObjectFile::isSectionReadOnlyData(DataRefImpl Ref, + bool &Result) const { // FIXME: Unimplemented. Result = false; return object_error::success; } -error_code COFFObjectFile::sectionContainsSymbol(DataRefImpl SecRef, - DataRefImpl SymbRef, - bool &Result) const { +std::error_code COFFObjectFile::sectionContainsSymbol(DataRefImpl SecRef, + DataRefImpl SymbRef, + bool &Result) const { const coff_section *Sec = toSec(SecRef); const coff_symbol *Symb = toSymb(SymbRef); const coff_section *SymbSec = nullptr; - if (error_code EC = getSection(Symb->SectionNumber, SymbSec)) return EC; + if (std::error_code EC = getSection(Symb->SectionNumber, SymbSec)) + return EC; if (SymbSec == Sec) Result = true; else @@ -391,8 +396,8 @@ relocation_iterator COFFObjectFile::section_rel_end(DataRefImpl Ref) const { } // Initialize the pointer to the symbol table. -error_code COFFObjectFile::initSymbolTablePtr() { - if (error_code EC = getObject( +std::error_code COFFObjectFile::initSymbolTablePtr() { + if (std::error_code EC = getObject( SymbolTable, Data, base() + COFFHeader->PointerToSymbolTable, COFFHeader->NumberOfSymbols * sizeof(coff_symbol))) return EC; @@ -404,11 +409,11 @@ error_code COFFObjectFile::initSymbolTablePtr() { base() + COFFHeader->PointerToSymbolTable + COFFHeader->NumberOfSymbols * sizeof(coff_symbol); const ulittle32_t *StringTableSizePtr; - if (error_code EC = getObject(StringTableSizePtr, Data, StringTableAddr)) + if (std::error_code EC = getObject(StringTableSizePtr, Data, StringTableAddr)) return EC; StringTableSize = *StringTableSizePtr; - if (error_code EC = - getObject(StringTable, Data, StringTableAddr, StringTableSize)) + if (std::error_code EC = + getObject(StringTable, Data, StringTableAddr, StringTableSize)) return EC; // Treat table sizes < 4 as empty because contrary to the PECOFF spec, some @@ -423,7 +428,7 @@ error_code COFFObjectFile::initSymbolTablePtr() { } // Returns the file offset for the given VA. -error_code COFFObjectFile::getVaPtr(uint64_t Addr, uintptr_t &Res) const { +std::error_code COFFObjectFile::getVaPtr(uint64_t Addr, uintptr_t &Res) const { uint64_t ImageBase = PE32Header ? (uint64_t)PE32Header->ImageBase : (uint64_t)PE32PlusHeader->ImageBase; uint64_t Rva = Addr - ImageBase; @@ -432,7 +437,7 @@ error_code COFFObjectFile::getVaPtr(uint64_t Addr, uintptr_t &Res) const { } // Returns the file offset for the given RVA. -error_code COFFObjectFile::getRvaPtr(uint32_t Addr, uintptr_t &Res) const { +std::error_code COFFObjectFile::getRvaPtr(uint32_t Addr, uintptr_t &Res) const { for (const SectionRef &S : sections()) { const coff_section *Section = getCOFFSection(S); uint32_t SectionStart = Section->VirtualAddress; @@ -448,10 +453,10 @@ error_code COFFObjectFile::getRvaPtr(uint32_t Addr, uintptr_t &Res) const { // Returns hint and name fields, assuming \p Rva is pointing to a Hint/Name // table entry. -error_code COFFObjectFile:: -getHintName(uint32_t Rva, uint16_t &Hint, StringRef &Name) const { +std::error_code COFFObjectFile::getHintName(uint32_t Rva, uint16_t &Hint, + StringRef &Name) const { uintptr_t IntPtr = 0; - if (error_code EC = getRvaPtr(Rva, IntPtr)) + if (std::error_code EC = getRvaPtr(Rva, IntPtr)) return EC; const uint8_t *Ptr = reinterpret_cast(IntPtr); Hint = *reinterpret_cast(Ptr); @@ -460,7 +465,7 @@ getHintName(uint32_t Rva, uint16_t &Hint, StringRef &Name) const { } // Find the import table. -error_code COFFObjectFile::initImportTablePtr() { +std::error_code COFFObjectFile::initImportTablePtr() { // First, we get the RVA of the import table. If the file lacks a pointer to // the import table, do nothing. const data_directory *DataEntry; @@ -478,7 +483,7 @@ error_code COFFObjectFile::initImportTablePtr() { // Find the section that contains the RVA. This is needed because the RVA is // the import table's memory address which is different from its file offset. uintptr_t IntPtr = 0; - if (error_code EC = getRvaPtr(ImportTableRva, IntPtr)) + if (std::error_code EC = getRvaPtr(ImportTableRva, IntPtr)) return EC; ImportDirectory = reinterpret_cast< const import_directory_table_entry *>(IntPtr); @@ -486,7 +491,7 @@ error_code COFFObjectFile::initImportTablePtr() { } // Find the export table. -error_code COFFObjectFile::initExportTablePtr() { +std::error_code COFFObjectFile::initExportTablePtr() { // First, we get the RVA of the export table. If the file lacks a pointer to // the export table, do nothing. const data_directory *DataEntry; @@ -499,14 +504,14 @@ error_code COFFObjectFile::initExportTablePtr() { uint32_t ExportTableRva = DataEntry->RelativeVirtualAddress; uintptr_t IntPtr = 0; - if (error_code EC = getRvaPtr(ExportTableRva, IntPtr)) + if (std::error_code EC = getRvaPtr(ExportTableRva, IntPtr)) return EC; ExportDirectory = reinterpret_cast(IntPtr); return object_error::success; } -COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &EC, +COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, std::error_code &EC, bool BufferOwned) : ObjectFile(Binary::ID_COFF, Object, BufferOwned), COFFHeader(nullptr), PE32Header(nullptr), PE32PlusHeader(nullptr), DataDirectory(nullptr), @@ -687,28 +692,30 @@ unsigned COFFObjectFile::getArch() const { // This method is kept here because lld uses this. As soon as we make // lld to use getCOFFHeader, this method will be removed. -error_code COFFObjectFile::getHeader(const coff_file_header *&Res) const { +std::error_code COFFObjectFile::getHeader(const coff_file_header *&Res) const { return getCOFFHeader(Res); } -error_code COFFObjectFile::getCOFFHeader(const coff_file_header *&Res) const { +std::error_code +COFFObjectFile::getCOFFHeader(const coff_file_header *&Res) const { Res = COFFHeader; return object_error::success; } -error_code COFFObjectFile::getPE32Header(const pe32_header *&Res) const { +std::error_code COFFObjectFile::getPE32Header(const pe32_header *&Res) const { Res = PE32Header; return object_error::success; } -error_code +std::error_code COFFObjectFile::getPE32PlusHeader(const pe32plus_header *&Res) const { Res = PE32PlusHeader; return object_error::success; } -error_code COFFObjectFile::getDataDirectory(uint32_t Index, - const data_directory *&Res) const { +std::error_code +COFFObjectFile::getDataDirectory(uint32_t Index, + const data_directory *&Res) const { // Error if if there's no data directory or the index is out of range. if (!DataDirectory) return object_error::parse_failed; @@ -721,8 +728,8 @@ error_code COFFObjectFile::getDataDirectory(uint32_t Index, return object_error::success; } -error_code COFFObjectFile::getSection(int32_t Index, - const coff_section *&Result) const { +std::error_code COFFObjectFile::getSection(int32_t Index, + const coff_section *&Result) const { // Check for special index values. if (COFF::isReservedSectionNumber(Index)) Result = nullptr; @@ -734,8 +741,8 @@ error_code COFFObjectFile::getSection(int32_t Index, return object_error::success; } -error_code COFFObjectFile::getString(uint32_t Offset, - StringRef &Result) const { +std::error_code COFFObjectFile::getString(uint32_t Offset, + StringRef &Result) const { if (StringTableSize <= 4) // Tried to get a string from an empty string table. return object_error::parse_failed; @@ -745,8 +752,8 @@ error_code COFFObjectFile::getString(uint32_t Offset, return object_error::success; } -error_code COFFObjectFile::getSymbol(uint32_t Index, - const coff_symbol *&Result) const { +std::error_code COFFObjectFile::getSymbol(uint32_t Index, + const coff_symbol *&Result) const { if (Index < COFFHeader->NumberOfSymbols) Result = SymbolTable + Index; else @@ -754,12 +761,12 @@ error_code COFFObjectFile::getSymbol(uint32_t Index, return object_error::success; } -error_code COFFObjectFile::getSymbolName(const coff_symbol *Symbol, - StringRef &Res) const { +std::error_code COFFObjectFile::getSymbolName(const coff_symbol *Symbol, + StringRef &Res) const { // Check for string table entry. First 4 bytes are 0. if (Symbol->Name.Offset.Zeroes == 0) { uint32_t Offset = Symbol->Name.Offset.Offset; - if (error_code EC = getString(Offset, Res)) + if (std::error_code EC = getString(Offset, Res)) return EC; return object_error::success; } @@ -796,8 +803,8 @@ ArrayRef COFFObjectFile::getSymbolAuxData( Symbol->NumberOfAuxSymbols * sizeof(coff_symbol)); } -error_code COFFObjectFile::getSectionName(const coff_section *Sec, - StringRef &Res) const { +std::error_code COFFObjectFile::getSectionName(const coff_section *Sec, + StringRef &Res) const { StringRef Name; if (Sec->Name[7] == 0) // Null terminated, let ::strlen figure out the length. @@ -816,7 +823,7 @@ error_code COFFObjectFile::getSectionName(const coff_section *Sec, if (Name.substr(1).getAsInteger(10, Offset)) return object_error::parse_failed; } - if (error_code EC = getString(Offset, Name)) + if (std::error_code EC = getString(Offset, Name)) return EC; } @@ -824,8 +831,9 @@ error_code COFFObjectFile::getSectionName(const coff_section *Sec, return object_error::success; } -error_code COFFObjectFile::getSectionContents(const coff_section *Sec, - ArrayRef &Res) const { +std::error_code +COFFObjectFile::getSectionContents(const coff_section *Sec, + ArrayRef &Res) const { // The only thing that we need to verify is that the contents is contained // within the file bounds. We don't need to make sure it doesn't cover other // data, as there's nothing that says that is not allowed. @@ -847,13 +855,13 @@ void COFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const { reinterpret_cast(Rel.p) + 1); } -error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel, - uint64_t &Res) const { +std::error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel, + uint64_t &Res) const { report_fatal_error("getRelocationAddress not implemented in COFFObjectFile"); } -error_code COFFObjectFile::getRelocationOffset(DataRefImpl Rel, - uint64_t &Res) const { +std::error_code COFFObjectFile::getRelocationOffset(DataRefImpl Rel, + uint64_t &Res) const { Res = toRel(Rel)->VirtualAddress; return object_error::success; } @@ -865,8 +873,8 @@ symbol_iterator COFFObjectFile::getRelocationSymbol(DataRefImpl Rel) const { return symbol_iterator(SymbolRef(Ref, this)); } -error_code COFFObjectFile::getRelocationType(DataRefImpl Rel, - uint64_t &Res) const { +std::error_code COFFObjectFile::getRelocationType(DataRefImpl Rel, + uint64_t &Res) const { const coff_relocation* R = toRel(Rel); Res = R->Type; return object_error::success; @@ -892,8 +900,9 @@ COFFObjectFile::getCOFFRelocation(const RelocationRef &Reloc) const { Res = #reloc_type; \ break; -error_code COFFObjectFile::getRelocationTypeName(DataRefImpl Rel, - SmallVectorImpl &Result) const { +std::error_code +COFFObjectFile::getRelocationTypeName(DataRefImpl Rel, + SmallVectorImpl &Result) const { const coff_relocation *Reloc = toRel(Rel); StringRef Res; switch (COFFHeader->Machine) { @@ -967,26 +976,29 @@ error_code COFFObjectFile::getRelocationTypeName(DataRefImpl Rel, #undef LLVM_COFF_SWITCH_RELOC_TYPE_NAME -error_code COFFObjectFile::getRelocationValueString(DataRefImpl Rel, - SmallVectorImpl &Result) const { +std::error_code +COFFObjectFile::getRelocationValueString(DataRefImpl Rel, + SmallVectorImpl &Result) const { const coff_relocation *Reloc = toRel(Rel); const coff_symbol *Symb = nullptr; - if (error_code EC = getSymbol(Reloc->SymbolTableIndex, Symb)) return EC; + if (std::error_code EC = getSymbol(Reloc->SymbolTableIndex, Symb)) + return EC; DataRefImpl Sym; Sym.p = reinterpret_cast(Symb); StringRef SymName; - if (error_code EC = getSymbolName(Sym, SymName)) return EC; + if (std::error_code EC = getSymbolName(Sym, SymName)) + return EC; Result.append(SymName.begin(), SymName.end()); return object_error::success; } -error_code COFFObjectFile::getLibraryNext(DataRefImpl LibData, - LibraryRef &Result) const { +std::error_code COFFObjectFile::getLibraryNext(DataRefImpl LibData, + LibraryRef &Result) const { report_fatal_error("getLibraryNext not implemented in COFFObjectFile"); } -error_code COFFObjectFile::getLibraryPath(DataRefImpl LibData, - StringRef &Result) const { +std::error_code COFFObjectFile::getLibraryPath(DataRefImpl LibData, + StringRef &Result) const { report_fatal_error("getLibraryPath not implemented in COFFObjectFile"); } @@ -999,24 +1011,25 @@ void ImportDirectoryEntryRef::moveNext() { ++Index; } -error_code ImportDirectoryEntryRef:: -getImportTableEntry(const import_directory_table_entry *&Result) const { +std::error_code ImportDirectoryEntryRef::getImportTableEntry( + const import_directory_table_entry *&Result) const { Result = ImportTable; return object_error::success; } -error_code ImportDirectoryEntryRef::getName(StringRef &Result) const { +std::error_code ImportDirectoryEntryRef::getName(StringRef &Result) const { uintptr_t IntPtr = 0; - if (error_code EC = OwningObject->getRvaPtr(ImportTable->NameRVA, IntPtr)) + if (std::error_code EC = + OwningObject->getRvaPtr(ImportTable->NameRVA, IntPtr)) return EC; Result = StringRef(reinterpret_cast(IntPtr)); return object_error::success; } -error_code ImportDirectoryEntryRef::getImportLookupEntry( +std::error_code ImportDirectoryEntryRef::getImportLookupEntry( const import_lookup_table_entry32 *&Result) const { uintptr_t IntPtr = 0; - if (error_code EC = + if (std::error_code EC = OwningObject->getRvaPtr(ImportTable->ImportLookupTableRVA, IntPtr)) return EC; Result = reinterpret_cast(IntPtr); @@ -1034,31 +1047,33 @@ void ExportDirectoryEntryRef::moveNext() { // Returns the name of the current export symbol. If the symbol is exported only // by ordinal, the empty string is set as a result. -error_code ExportDirectoryEntryRef::getDllName(StringRef &Result) const { +std::error_code ExportDirectoryEntryRef::getDllName(StringRef &Result) const { uintptr_t IntPtr = 0; - if (error_code EC = OwningObject->getRvaPtr(ExportTable->NameRVA, IntPtr)) + if (std::error_code EC = + OwningObject->getRvaPtr(ExportTable->NameRVA, IntPtr)) return EC; Result = StringRef(reinterpret_cast(IntPtr)); return object_error::success; } // Returns the starting ordinal number. -error_code ExportDirectoryEntryRef::getOrdinalBase(uint32_t &Result) const { +std::error_code +ExportDirectoryEntryRef::getOrdinalBase(uint32_t &Result) const { Result = ExportTable->OrdinalBase; return object_error::success; } // Returns the export ordinal of the current export symbol. -error_code ExportDirectoryEntryRef::getOrdinal(uint32_t &Result) const { +std::error_code ExportDirectoryEntryRef::getOrdinal(uint32_t &Result) const { Result = ExportTable->OrdinalBase + Index; return object_error::success; } // Returns the address of the current export symbol. -error_code ExportDirectoryEntryRef::getExportRVA(uint32_t &Result) const { +std::error_code ExportDirectoryEntryRef::getExportRVA(uint32_t &Result) const { uintptr_t IntPtr = 0; - if (error_code EC = OwningObject->getRvaPtr( - ExportTable->ExportAddressTableRVA, IntPtr)) + if (std::error_code EC = + OwningObject->getRvaPtr(ExportTable->ExportAddressTableRVA, IntPtr)) return EC; const export_address_table_entry *entry = reinterpret_cast(IntPtr); @@ -1068,10 +1083,11 @@ error_code ExportDirectoryEntryRef::getExportRVA(uint32_t &Result) const { // Returns the name of the current export symbol. If the symbol is exported only // by ordinal, the empty string is set as a result. -error_code ExportDirectoryEntryRef::getSymbolName(StringRef &Result) const { +std::error_code +ExportDirectoryEntryRef::getSymbolName(StringRef &Result) const { uintptr_t IntPtr = 0; - if (error_code EC = OwningObject->getRvaPtr( - ExportTable->OrdinalTableRVA, IntPtr)) + if (std::error_code EC = + OwningObject->getRvaPtr(ExportTable->OrdinalTableRVA, IntPtr)) return EC; const ulittle16_t *Start = reinterpret_cast(IntPtr); @@ -1081,11 +1097,11 @@ error_code ExportDirectoryEntryRef::getSymbolName(StringRef &Result) const { I < E; ++I, ++Offset) { if (*I != Index) continue; - if (error_code EC = OwningObject->getRvaPtr( - ExportTable->NamePointerRVA, IntPtr)) + if (std::error_code EC = + OwningObject->getRvaPtr(ExportTable->NamePointerRVA, IntPtr)) return EC; const ulittle32_t *NamePtr = reinterpret_cast(IntPtr); - if (error_code EC = OwningObject->getRvaPtr(NamePtr[Offset], IntPtr)) + if (std::error_code EC = OwningObject->getRvaPtr(NamePtr[Offset], IntPtr)) return EC; Result = StringRef(reinterpret_cast(IntPtr)); return object_error::success; @@ -1096,7 +1112,7 @@ error_code ExportDirectoryEntryRef::getSymbolName(StringRef &Result) const { ErrorOr ObjectFile::createCOFFObjectFile(MemoryBuffer *Object, bool BufferOwned) { - error_code EC; + std::error_code EC; std::unique_ptr Ret( new COFFObjectFile(Object, EC, BufferOwned)); if (EC) diff --git a/lib/Object/ELFObjectFile.cpp b/lib/Object/ELFObjectFile.cpp index de05abb43b..a11a9e016d 100644 --- a/lib/Object/ELFObjectFile.cpp +++ b/lib/Object/ELFObjectFile.cpp @@ -15,7 +15,6 @@ #include "llvm/Support/MathExtras.h" namespace llvm { -using std::error_code; using namespace object; ErrorOr ObjectFile::createELFObjectFile(MemoryBuffer *Obj, @@ -24,7 +23,7 @@ ErrorOr ObjectFile::createELFObjectFile(MemoryBuffer *Obj, std::size_t MaxAlignment = 1ULL << countTrailingZeros(uintptr_t(Obj->getBufferStart())); - error_code EC; + std::error_code EC; std::unique_ptr R; if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2LSB) #if !LLVM_IS_UNALIGNED_ACCESS_FAST diff --git a/lib/Object/IRObjectFile.cpp b/lib/Object/IRObjectFile.cpp index 57c2232d47..48820361d4 100644 --- a/lib/Object/IRObjectFile.cpp +++ b/lib/Object/IRObjectFile.cpp @@ -19,9 +19,8 @@ #include "llvm/Support/raw_ostream.h" using namespace llvm; using namespace object; -using std::error_code; -IRObjectFile::IRObjectFile(MemoryBuffer *Object, error_code &EC, +IRObjectFile::IRObjectFile(MemoryBuffer *Object, std::error_code &EC, LLVMContext &Context, bool BufferOwned) : SymbolicFile(Binary::ID_IR, Object, BufferOwned) { ErrorOr MOrErr = parseBitcodeFile(Object, Context); @@ -93,8 +92,8 @@ void IRObjectFile::moveSymbolNext(DataRefImpl &Symb) const { Symb.p = Res; } -error_code IRObjectFile::printSymbolName(raw_ostream &OS, - DataRefImpl Symb) const { +std::error_code IRObjectFile::printSymbolName(raw_ostream &OS, + DataRefImpl Symb) const { const GlobalValue &GV = getGV(Symb); if (Mang) @@ -143,7 +142,7 @@ basic_symbol_iterator IRObjectFile::symbol_end_impl() const { ErrorOr llvm::object::SymbolicFile::createIRObjectFile( MemoryBuffer *Object, LLVMContext &Context, bool BufferOwned) { - error_code EC; + std::error_code EC; std::unique_ptr Ret( new IRObjectFile(Object, EC, Context, BufferOwned)); if (EC) diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index a71a139b02..e61422885b 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -28,7 +28,6 @@ using namespace llvm; using namespace object; namespace llvm { -using std::error_code; namespace object { diff --git a/lib/Object/MachOUniversal.cpp b/lib/Object/MachOUniversal.cpp index 1d45004273..ea4773feee 100644 --- a/lib/Object/MachOUniversal.cpp +++ b/lib/Object/MachOUniversal.cpp @@ -21,7 +21,6 @@ using namespace llvm; using namespace object; -using std::error_code; template static void SwapValue(T &Value) { @@ -73,7 +72,7 @@ MachOUniversalBinary::ObjectForArch::ObjectForArch( } } -error_code MachOUniversalBinary::ObjectForArch::getAsObjectFile( +std::error_code MachOUniversalBinary::ObjectForArch::getAsObjectFile( std::unique_ptr &Result) const { if (Parent) { StringRef ParentData = Parent->getData(); @@ -84,7 +83,7 @@ error_code MachOUniversalBinary::ObjectForArch::getAsObjectFile( MemoryBuffer *ObjBuffer = MemoryBuffer::getMemBuffer( ObjectData, ObjectName, false); ErrorOr Obj = ObjectFile::createMachOObjectFile(ObjBuffer); - if (error_code EC = Obj.getError()) + if (std::error_code EC = Obj.getError()) return EC; Result.reset(Obj.get()); return object_error::success; @@ -92,7 +91,7 @@ error_code MachOUniversalBinary::ObjectForArch::getAsObjectFile( return object_error::parse_failed; } -error_code MachOUniversalBinary::ObjectForArch::getAsArchive( +std::error_code MachOUniversalBinary::ObjectForArch::getAsArchive( std::unique_ptr &Result) const { if (Parent) { StringRef ParentData = Parent->getData(); @@ -103,7 +102,7 @@ error_code MachOUniversalBinary::ObjectForArch::getAsArchive( MemoryBuffer *ObjBuffer = MemoryBuffer::getMemBuffer( ObjectData, ObjectName, false); ErrorOr Obj = Archive::create(ObjBuffer); - if (error_code EC = Obj.getError()) + if (std::error_code EC = Obj.getError()) return EC; Result.reset(Obj.get()); return object_error::success; @@ -115,7 +114,7 @@ void MachOUniversalBinary::anchor() { } ErrorOr MachOUniversalBinary::create(MemoryBuffer *Source) { - error_code EC; + std::error_code EC; std::unique_ptr Ret( new MachOUniversalBinary(Source, EC)); if (EC) @@ -124,9 +123,8 @@ MachOUniversalBinary::create(MemoryBuffer *Source) { } MachOUniversalBinary::MachOUniversalBinary(MemoryBuffer *Source, - error_code &ec) - : Binary(Binary::ID_MachOUniversalBinary, Source), - NumberOfObjects(0) { + std::error_code &ec) + : Binary(Binary::ID_MachOUniversalBinary, Source), NumberOfObjects(0) { if (Source->getBufferSize() < sizeof(MachO::fat_header)) { ec = object_error::invalid_file_type; return; @@ -156,7 +154,7 @@ static bool getCTMForArch(Triple::ArchType Arch, MachO::CPUType &CTM) { } } -error_code MachOUniversalBinary::getObjectForArch( +std::error_code MachOUniversalBinary::getObjectForArch( Triple::ArchType Arch, std::unique_ptr &Result) const { MachO::CPUType CTM; if (!getCTMForArch(Arch, CTM)) diff --git a/lib/Object/Object.cpp b/lib/Object/Object.cpp index 8792345c79..7282f468b0 100644 --- a/lib/Object/Object.cpp +++ b/lib/Object/Object.cpp @@ -18,7 +18,6 @@ using namespace llvm; using namespace object; -using std::error_code; inline ObjectFile *unwrap(LLVMObjectFileRef OF) { return reinterpret_cast(OF); @@ -90,7 +89,7 @@ void LLVMMoveToNextSection(LLVMSectionIteratorRef SI) { void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect, LLVMSymbolIteratorRef Sym) { - if (error_code ec = (*unwrap(Sym))->getSection(*unwrap(Sect))) + if (std::error_code ec = (*unwrap(Sym))->getSection(*unwrap(Sect))) report_fatal_error(ec.message()); } @@ -116,28 +115,28 @@ void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI) { // SectionRef accessors const char *LLVMGetSectionName(LLVMSectionIteratorRef SI) { StringRef ret; - if (error_code ec = (*unwrap(SI))->getName(ret)) + if (std::error_code ec = (*unwrap(SI))->getName(ret)) report_fatal_error(ec.message()); return ret.data(); } uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI) { uint64_t ret; - if (error_code ec = (*unwrap(SI))->getSize(ret)) + if (std::error_code ec = (*unwrap(SI))->getSize(ret)) report_fatal_error(ec.message()); return ret; } const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI) { StringRef ret; - if (error_code ec = (*unwrap(SI))->getContents(ret)) + if (std::error_code ec = (*unwrap(SI))->getContents(ret)) report_fatal_error(ec.message()); return ret.data(); } uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI) { uint64_t ret; - if (error_code ec = (*unwrap(SI))->getAddress(ret)) + if (std::error_code ec = (*unwrap(SI))->getAddress(ret)) report_fatal_error(ec.message()); return ret; } @@ -145,7 +144,7 @@ uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI) { LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI, LLVMSymbolIteratorRef Sym) { bool ret; - if (error_code ec = (*unwrap(SI))->containsSymbol(**unwrap(Sym), ret)) + if (std::error_code ec = (*unwrap(SI))->containsSymbol(**unwrap(Sym), ret)) report_fatal_error(ec.message()); return ret; } @@ -173,21 +172,21 @@ void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef SI) { // SymbolRef accessors const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) { StringRef ret; - if (error_code ec = (*unwrap(SI))->getName(ret)) + if (std::error_code ec = (*unwrap(SI))->getName(ret)) report_fatal_error(ec.message()); return ret.data(); } uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI) { uint64_t ret; - if (error_code ec = (*unwrap(SI))->getAddress(ret)) + if (std::error_code ec = (*unwrap(SI))->getAddress(ret)) report_fatal_error(ec.message()); return ret; } uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI) { uint64_t ret; - if (error_code ec = (*unwrap(SI))->getSize(ret)) + if (std::error_code ec = (*unwrap(SI))->getSize(ret)) report_fatal_error(ec.message()); return ret; } @@ -195,14 +194,14 @@ uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI) { // RelocationRef accessors uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI) { uint64_t ret; - if (error_code ec = (*unwrap(RI))->getAddress(ret)) + if (std::error_code ec = (*unwrap(RI))->getAddress(ret)) report_fatal_error(ec.message()); return ret; } uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI) { uint64_t ret; - if (error_code ec = (*unwrap(RI))->getOffset(ret)) + if (std::error_code ec = (*unwrap(RI))->getOffset(ret)) report_fatal_error(ec.message()); return ret; } @@ -214,7 +213,7 @@ LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI) { uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI) { uint64_t ret; - if (error_code ec = (*unwrap(RI))->getType(ret)) + if (std::error_code ec = (*unwrap(RI))->getType(ret)) report_fatal_error(ec.message()); return ret; } @@ -222,7 +221,7 @@ uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI) { // NOTE: Caller takes ownership of returned string. const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI) { SmallVector ret; - if (error_code ec = (*unwrap(RI))->getTypeName(ret)) + if (std::error_code ec = (*unwrap(RI))->getTypeName(ret)) report_fatal_error(ec.message()); char *str = static_cast(malloc(ret.size())); @@ -233,7 +232,7 @@ const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI) { // NOTE: Caller takes ownership of returned string. const char *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI) { SmallVector ret; - if (error_code ec = (*unwrap(RI))->getValueString(ret)) + if (std::error_code ec = (*unwrap(RI))->getValueString(ret)) report_fatal_error(ec.message()); char *str = static_cast(malloc(ret.size())); diff --git a/lib/Object/ObjectFile.cpp b/lib/Object/ObjectFile.cpp index 5d43249234..7666ed53c3 100644 --- a/lib/Object/ObjectFile.cpp +++ b/lib/Object/ObjectFile.cpp @@ -20,7 +20,6 @@ using namespace llvm; using namespace object; -using std::error_code; void ObjectFile::anchor() { } @@ -28,17 +27,17 @@ ObjectFile::ObjectFile(unsigned int Type, MemoryBuffer *Source, bool BufferOwned) : SymbolicFile(Type, Source, BufferOwned) {} -error_code ObjectFile::printSymbolName(raw_ostream &OS, - DataRefImpl Symb) const { +std::error_code ObjectFile::printSymbolName(raw_ostream &OS, + DataRefImpl Symb) const { StringRef Name; - if (error_code EC = getSymbolName(Symb, Name)) + if (std::error_code EC = getSymbolName(Symb, Name)) return EC; OS << Name; return object_error::success; } -error_code ObjectFile::getSymbolAlignment(DataRefImpl DRI, - uint32_t &Result) const { +std::error_code ObjectFile::getSymbolAlignment(DataRefImpl DRI, + uint32_t &Result) const { Result = 0; return object_error::success; } @@ -88,7 +87,7 @@ ErrorOr ObjectFile::createObjectFile(MemoryBuffer *Object, ErrorOr ObjectFile::createObjectFile(StringRef ObjectPath) { std::unique_ptr File; - if (error_code EC = MemoryBuffer::getFile(ObjectPath, File)) + if (std::error_code EC = MemoryBuffer::getFile(ObjectPath, File)) return EC; return createObjectFile(File.release()); } diff --git a/lib/ProfileData/InstrProfReader.cpp b/lib/ProfileData/InstrProfReader.cpp index 8d3ec5d2a3..c7809b8b8c 100644 --- a/lib/ProfileData/InstrProfReader.cpp +++ b/lib/ProfileData/InstrProfReader.cpp @@ -20,11 +20,10 @@ #include using namespace llvm; -using std::error_code; -static error_code setupMemoryBuffer(std::string Path, - std::unique_ptr &Buffer) { - if (error_code EC = MemoryBuffer::getFileOrSTDIN(Path, Buffer)) +static std::error_code +setupMemoryBuffer(std::string Path, std::unique_ptr &Buffer) { + if (std::error_code EC = MemoryBuffer::getFileOrSTDIN(Path, Buffer)) return EC; // Sanity check the file. @@ -33,15 +32,16 @@ static error_code setupMemoryBuffer(std::string Path, return instrprof_error::success; } -static error_code initializeReader(InstrProfReader &Reader) { +static std::error_code initializeReader(InstrProfReader &Reader) { return Reader.readHeader(); } -error_code InstrProfReader::create(std::string Path, - std::unique_ptr &Result) { +std::error_code +InstrProfReader::create(std::string Path, + std::unique_ptr &Result) { // Set up the buffer to read. std::unique_ptr Buffer; - if (error_code EC = setupMemoryBuffer(Path, Buffer)) + if (std::error_code EC = setupMemoryBuffer(Path, Buffer)) return EC; // Create the reader. @@ -58,11 +58,11 @@ error_code InstrProfReader::create(std::string Path, return initializeReader(*Result); } -error_code IndexedInstrProfReader::create( +std::error_code IndexedInstrProfReader::create( std::string Path, std::unique_ptr &Result) { // Set up the buffer to read. std::unique_ptr Buffer; - if (error_code EC = setupMemoryBuffer(Path, Buffer)) + if (std::error_code EC = setupMemoryBuffer(Path, Buffer)) return EC; // Create the reader. @@ -79,7 +79,7 @@ void InstrProfIterator::Increment() { *this = InstrProfIterator(); } -error_code TextInstrProfReader::readNextRecord(InstrProfRecord &Record) { +std::error_code TextInstrProfReader::readNextRecord(InstrProfRecord &Record) { // Skip empty lines. while (!Line.is_at_end() && Line->empty()) ++Line; @@ -162,7 +162,7 @@ bool RawInstrProfReader::hasFormat(const MemoryBuffer &DataBuffer) { } template -error_code RawInstrProfReader::readHeader() { +std::error_code RawInstrProfReader::readHeader() { if (!hasFormat(*DataBuffer)) return error(instrprof_error::bad_magic); if (DataBuffer->getBufferSize() < sizeof(RawHeader)) @@ -174,7 +174,8 @@ error_code RawInstrProfReader::readHeader() { } template -error_code RawInstrProfReader::readNextHeader(const char *CurrentPos) { +std::error_code +RawInstrProfReader::readNextHeader(const char *CurrentPos) { const char *End = DataBuffer->getBufferEnd(); // Skip zero padding between profiles. while (CurrentPos != End && *CurrentPos == 0) @@ -201,7 +202,8 @@ static uint64_t getRawVersion() { } template -error_code RawInstrProfReader::readHeader(const RawHeader &Header) { +std::error_code +RawInstrProfReader::readHeader(const RawHeader &Header) { if (swap(Header.Version) != getRawVersion()) return error(instrprof_error::unsupported_version); @@ -230,10 +232,10 @@ error_code RawInstrProfReader::readHeader(const RawHeader &Header) { } template -error_code +std::error_code RawInstrProfReader::readNextRecord(InstrProfRecord &Record) { if (Data == DataEnd) - if (error_code EC = readNextHeader(ProfileEnd)) + if (std::error_code EC = readNextHeader(ProfileEnd)) return EC; // Get the raw data. @@ -287,7 +289,7 @@ bool IndexedInstrProfReader::hasFormat(const MemoryBuffer &DataBuffer) { return Magic == IndexedInstrProf::Magic; } -error_code IndexedInstrProfReader::readHeader() { +std::error_code IndexedInstrProfReader::readHeader() { const unsigned char *Start = (const unsigned char *)DataBuffer->getBufferStart(); const unsigned char *Cur = Start; @@ -325,7 +327,7 @@ error_code IndexedInstrProfReader::readHeader() { return success(); } -error_code IndexedInstrProfReader::getFunctionCounts( +std::error_code IndexedInstrProfReader::getFunctionCounts( StringRef FuncName, uint64_t &FuncHash, std::vector &Counts) { const auto &Iter = Index->find(FuncName); if (Iter == Index->end()) @@ -340,7 +342,8 @@ error_code IndexedInstrProfReader::getFunctionCounts( return success(); } -error_code IndexedInstrProfReader::readNextRecord(InstrProfRecord &Record) { +std::error_code +IndexedInstrProfReader::readNextRecord(InstrProfRecord &Record) { // Are we out of records? if (RecordIterator == Index->data_end()) return error(instrprof_error::eof); diff --git a/lib/Support/DataStream.cpp b/lib/Support/DataStream.cpp index 0d8a800d70..32653de519 100644 --- a/lib/Support/DataStream.cpp +++ b/lib/Support/DataStream.cpp @@ -28,7 +28,6 @@ #include #endif using namespace llvm; -using std::error_code; #define DEBUG_TYPE "Data-stream" @@ -65,11 +64,11 @@ public: return read(Fd, buf, len); } - error_code OpenFile(const std::string &Filename) { + std::error_code OpenFile(const std::string &Filename) { if (Filename == "-") { Fd = 0; sys::ChangeStdinToBinary(); - return error_code(); + return std::error_code(); } return sys::fs::openFileForRead(Filename, Fd); @@ -82,7 +81,7 @@ namespace llvm { DataStreamer *getDataFileStreamer(const std::string &Filename, std::string *StrError) { DataFileStreamer *s = new DataFileStreamer(); - if (error_code e = s->OpenFile(Filename)) { + if (std::error_code e = s->OpenFile(Filename)) { *StrError = std::string("Could not open ") + Filename + ": " + e.message() + "\n"; return nullptr; diff --git a/lib/Support/FileOutputBuffer.cpp b/lib/Support/FileOutputBuffer.cpp index 68f6fa16f9..8a7b0d73f9 100644 --- a/lib/Support/FileOutputBuffer.cpp +++ b/lib/Support/FileOutputBuffer.cpp @@ -17,7 +17,6 @@ #include using llvm::sys::fs::mapped_file_region; -using std::error_code; namespace llvm { FileOutputBuffer::FileOutputBuffer(mapped_file_region * R, @@ -31,13 +30,13 @@ FileOutputBuffer::~FileOutputBuffer() { sys::fs::remove(Twine(TempPath)); } -error_code FileOutputBuffer::create(StringRef FilePath, - size_t Size, - std::unique_ptr &Result, - unsigned Flags) { +std::error_code +FileOutputBuffer::create(StringRef FilePath, size_t Size, + std::unique_ptr &Result, + unsigned Flags) { // If file already exists, it must be a regular file (to be mappable). sys::fs::file_status Stat; - error_code EC = sys::fs::status(FilePath, Stat); + std::error_code EC = sys::fs::status(FilePath, Stat); switch (Stat.type()) { case sys::fs::file_type::file_not_found: // If file does not exist, we'll create one. @@ -82,16 +81,16 @@ error_code FileOutputBuffer::create(StringRef FilePath, if (Result) MappedFile.release(); - return error_code(); + return std::error_code(); } -error_code FileOutputBuffer::commit(int64_t NewSmallerSize) { +std::error_code FileOutputBuffer::commit(int64_t NewSmallerSize) { // Unmap buffer, letting OS flush dirty pages to file on disk. Region.reset(nullptr); // If requested, resize file as part of commit. if ( NewSmallerSize != -1 ) { - error_code EC = sys::fs::resize_file(Twine(TempPath), NewSmallerSize); + std::error_code EC = sys::fs::resize_file(Twine(TempPath), NewSmallerSize); if (EC) return EC; } diff --git a/lib/Support/FileUtilities.cpp b/lib/Support/FileUtilities.cpp index 729e44789c..0d26bafd77 100644 --- a/lib/Support/FileUtilities.cpp +++ b/lib/Support/FileUtilities.cpp @@ -22,7 +22,6 @@ #include #include using namespace llvm; -using std::error_code; static bool isSignedChar(char C) { return (C == '+' || C == '-'); @@ -178,13 +177,13 @@ int llvm::DiffFilesWithTolerance(StringRef NameA, // Now its safe to mmap the files into memory because both files // have a non-zero size. std::unique_ptr F1; - if (error_code ec = MemoryBuffer::getFile(NameA, F1)) { + if (std::error_code ec = MemoryBuffer::getFile(NameA, F1)) { if (Error) *Error = ec.message(); return 2; } std::unique_ptr F2; - if (error_code ec = MemoryBuffer::getFile(NameB, F2)) { + if (std::error_code ec = MemoryBuffer::getFile(NameB, F2)) { if (Error) *Error = ec.message(); return 2; diff --git a/lib/Support/LockFileManager.cpp b/lib/Support/LockFileManager.cpp index 0204e75f84..0ca631cb63 100644 --- a/lib/Support/LockFileManager.cpp +++ b/lib/Support/LockFileManager.cpp @@ -22,7 +22,6 @@ #include #endif using namespace llvm; -using std::error_code; /// \brief Attempt to read the lock file with the given name, if it exists. /// @@ -72,7 +71,7 @@ bool LockFileManager::processStillExecuting(StringRef Hostname, int PID) { LockFileManager::LockFileManager(StringRef FileName) { this->FileName = FileName; - if (error_code EC = sys::fs::make_absolute(this->FileName)) { + if (std::error_code EC = sys::fs::make_absolute(this->FileName)) { Error = EC; return; } @@ -88,10 +87,8 @@ LockFileManager::LockFileManager(StringRef FileName) UniqueLockFileName = LockFileName; UniqueLockFileName += "-%%%%%%%%"; int UniqueLockFileID; - if (error_code EC - = sys::fs::createUniqueFile(UniqueLockFileName.str(), - UniqueLockFileID, - UniqueLockFileName)) { + if (std::error_code EC = sys::fs::createUniqueFile( + UniqueLockFileName.str(), UniqueLockFileID, UniqueLockFileName)) { Error = EC; return; } @@ -123,7 +120,7 @@ LockFileManager::LockFileManager(StringRef FileName) while (1) { // Create a link from the lock file name. If this succeeds, we're done. - error_code EC = + std::error_code EC = sys::fs::create_link(UniqueLockFileName.str(), LockFileName.str()); if (!EC) return; diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp index c395ce72b8..a8f3385de4 100644 --- a/lib/Support/MemoryBuffer.cpp +++ b/lib/Support/MemoryBuffer.cpp @@ -33,7 +33,6 @@ #include #endif using namespace llvm; -using std::error_code; //===----------------------------------------------------------------------===// // MemoryBuffer implementation itself. @@ -157,9 +156,10 @@ MemoryBuffer *MemoryBuffer::getNewMemBuffer(size_t Size, StringRef BufferName) { /// if the Filename is "-". If an error occurs, this returns null and fills /// in *ErrStr with a reason. If stdin is empty, this API (unlike getSTDIN) /// returns an empty buffer. -error_code MemoryBuffer::getFileOrSTDIN(StringRef Filename, - std::unique_ptr &Result, - int64_t FileSize) { +std::error_code +MemoryBuffer::getFileOrSTDIN(StringRef Filename, + std::unique_ptr &Result, + int64_t FileSize) { if (Filename == "-") return getSTDIN(Result); return getFile(Filename, Result, FileSize); @@ -191,7 +191,7 @@ class MemoryBufferMMapFile : public MemoryBuffer { public: MemoryBufferMMapFile(bool RequiresNullTerminator, int FD, uint64_t Len, - uint64_t Offset, error_code EC) + uint64_t Offset, std::error_code EC) : MFR(FD, false, sys::fs::mapped_file_region::readonly, getLegalMapSize(Len, Offset), getLegalMapOffset(Offset), EC) { if (!EC) { @@ -211,9 +211,9 @@ public: }; } -static error_code getMemoryBufferForStream(int FD, - StringRef BufferName, - std::unique_ptr &Result) { +static std::error_code +getMemoryBufferForStream(int FD, StringRef BufferName, + std::unique_ptr &Result) { const ssize_t ChunkSize = 4096*4; SmallString Buffer; ssize_t ReadBytes; @@ -223,26 +223,25 @@ static error_code getMemoryBufferForStream(int FD, ReadBytes = read(FD, Buffer.end(), ChunkSize); if (ReadBytes == -1) { if (errno == EINTR) continue; - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); } Buffer.set_size(Buffer.size() + ReadBytes); } while (ReadBytes != 0); Result.reset(MemoryBuffer::getMemBufferCopy(Buffer, BufferName)); - return error_code(); + return std::error_code(); } -static error_code getFileAux(const char *Filename, - std::unique_ptr &Result, - int64_t FileSize, - bool RequiresNullTerminator, - bool IsVolatileSize); - -error_code MemoryBuffer::getFile(Twine Filename, - std::unique_ptr &Result, - int64_t FileSize, - bool RequiresNullTerminator, - bool IsVolatileSize) { +static std::error_code getFileAux(const char *Filename, + std::unique_ptr &Result, + int64_t FileSize, bool RequiresNullTerminator, + bool IsVolatileSize); + +std::error_code MemoryBuffer::getFile(Twine Filename, + std::unique_ptr &Result, + int64_t FileSize, + bool RequiresNullTerminator, + bool IsVolatileSize) { // Ensure the path is null terminated. SmallString<256> PathBuf; StringRef NullTerminatedName = Filename.toNullTerminatedStringRef(PathBuf); @@ -250,23 +249,25 @@ error_code MemoryBuffer::getFile(Twine Filename, RequiresNullTerminator, IsVolatileSize); } -static error_code getOpenFileImpl(int FD, const char *Filename, - std::unique_ptr &Result, - uint64_t FileSize, uint64_t MapSize, - int64_t Offset, bool RequiresNullTerminator, - bool IsVolatileSize); +static std::error_code getOpenFileImpl(int FD, const char *Filename, + std::unique_ptr &Result, + uint64_t FileSize, uint64_t MapSize, + int64_t Offset, + bool RequiresNullTerminator, + bool IsVolatileSize); -static error_code getFileAux(const char *Filename, - std::unique_ptr &Result, int64_t FileSize, - bool RequiresNullTerminator, - bool IsVolatileSize) { +static std::error_code getFileAux(const char *Filename, + std::unique_ptr &Result, + int64_t FileSize, bool RequiresNullTerminator, + bool IsVolatileSize) { int FD; - error_code EC = sys::fs::openFileForRead(Filename, FD); + std::error_code EC = sys::fs::openFileForRead(Filename, FD); if (EC) return EC; - error_code ret = getOpenFileImpl(FD, Filename, Result, FileSize, FileSize, 0, - RequiresNullTerminator, IsVolatileSize); + std::error_code ret = + getOpenFileImpl(FD, Filename, Result, FileSize, FileSize, 0, + RequiresNullTerminator, IsVolatileSize); close(FD); return ret; } @@ -319,11 +320,12 @@ static bool shouldUseMmap(int FD, return true; } -static error_code getOpenFileImpl(int FD, const char *Filename, - std::unique_ptr &Result, - uint64_t FileSize, uint64_t MapSize, - int64_t Offset, bool RequiresNullTerminator, - bool IsVolatileSize) { +static std::error_code getOpenFileImpl(int FD, const char *Filename, + std::unique_ptr &Result, + uint64_t FileSize, uint64_t MapSize, + int64_t Offset, + bool RequiresNullTerminator, + bool IsVolatileSize) { static int PageSize = sys::process::get_self()->page_size(); // Default is to map the full file. @@ -332,7 +334,7 @@ static error_code getOpenFileImpl(int FD, const char *Filename, // file descriptor is cheaper than stat on a random path. if (FileSize == uint64_t(-1)) { sys::fs::file_status Status; - error_code EC = sys::fs::status(FD, Status); + std::error_code EC = sys::fs::status(FD, Status); if (EC) return EC; @@ -351,11 +353,11 @@ static error_code getOpenFileImpl(int FD, const char *Filename, if (shouldUseMmap(FD, FileSize, MapSize, Offset, RequiresNullTerminator, PageSize, IsVolatileSize)) { - error_code EC; + std::error_code EC; Result.reset(new (NamedBufferAlloc(Filename)) MemoryBufferMMapFile( RequiresNullTerminator, FD, MapSize, Offset, EC)); if (!EC) - return error_code(); + return std::error_code(); } MemoryBuffer *Buf = MemoryBuffer::getNewUninitMemBuffer(MapSize, Filename); @@ -384,7 +386,7 @@ static error_code getOpenFileImpl(int FD, const char *Filename, if (errno == EINTR) continue; // Error while reading. - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); } if (NumRead == 0) { memset(BufPtr, 0, BytesLeft); // zero-initialize rest of the buffer. @@ -395,22 +397,21 @@ static error_code getOpenFileImpl(int FD, const char *Filename, } Result.swap(SB); - return error_code(); + return std::error_code(); } -error_code MemoryBuffer::getOpenFile(int FD, const char *Filename, - std::unique_ptr &Result, - uint64_t FileSize, - bool RequiresNullTerminator, - bool IsVolatileSize) { +std::error_code MemoryBuffer::getOpenFile(int FD, const char *Filename, + std::unique_ptr &Result, + uint64_t FileSize, + bool RequiresNullTerminator, + bool IsVolatileSize) { return getOpenFileImpl(FD, Filename, Result, FileSize, FileSize, 0, RequiresNullTerminator, IsVolatileSize); } -error_code MemoryBuffer::getOpenFileSlice(int FD, const char *Filename, - std::unique_ptr &Result, - uint64_t MapSize, int64_t Offset, - bool IsVolatileSize) { +std::error_code MemoryBuffer::getOpenFileSlice( + int FD, const char *Filename, std::unique_ptr &Result, + uint64_t MapSize, int64_t Offset, bool IsVolatileSize) { return getOpenFileImpl(FD, Filename, Result, -1, MapSize, Offset, false, IsVolatileSize); } @@ -419,7 +420,7 @@ error_code MemoryBuffer::getOpenFileSlice(int FD, const char *Filename, // MemoryBuffer::getSTDIN implementation. //===----------------------------------------------------------------------===// -error_code MemoryBuffer::getSTDIN(std::unique_ptr &Result) { +std::error_code MemoryBuffer::getSTDIN(std::unique_ptr &Result) { // Read in all of the data from stdin, we cannot mmap stdin. // // FIXME: That isn't necessarily true, we should try to mmap stdin and diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index 13e3a8ad02..1f843d8f2a 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -28,7 +28,6 @@ #endif using namespace llvm; -using std::error_code; namespace { using llvm::StringRef; @@ -165,12 +164,12 @@ enum FSEntity { }; // Implemented in Unix/Path.inc and Windows/Path.inc. -static error_code TempDir(SmallVectorImpl &result); +static std::error_code TempDir(SmallVectorImpl &result); -static error_code createUniqueEntity(const Twine &Model, int &ResultFD, - SmallVectorImpl &ResultPath, - bool MakeAbsolute, unsigned Mode, - FSEntity Type) { +static std::error_code createUniqueEntity(const Twine &Model, int &ResultFD, + SmallVectorImpl &ResultPath, + bool MakeAbsolute, unsigned Mode, + FSEntity Type) { SmallString<128> ModelStorage; Model.toVector(ModelStorage); @@ -178,7 +177,7 @@ static error_code createUniqueEntity(const Twine &Model, int &ResultFD, // Make model absolute by prepending a temp directory if it's not already. if (!sys::path::is_absolute(Twine(ModelStorage))) { SmallString<128> TDir; - if (error_code EC = TempDir(TDir)) + if (std::error_code EC = TempDir(TDir)) return EC; sys::path::append(TDir, Twine(ModelStorage)); ModelStorage.swap(TDir); @@ -202,7 +201,7 @@ retry_random_path: // Try to open + create the file. switch (Type) { case FS_File: { - if (error_code EC = + if (std::error_code EC = sys::fs::openFileForWrite(Twine(ResultPath.begin()), ResultFD, sys::fs::F_RW | sys::fs::F_Excl, Mode)) { if (EC == std::errc::file_exists) @@ -210,26 +209,27 @@ retry_random_path: return EC; } - return error_code(); + return std::error_code(); } case FS_Name: { bool Exists; - error_code EC = sys::fs::exists(ResultPath.begin(), Exists); + std::error_code EC = sys::fs::exists(ResultPath.begin(), Exists); if (EC) return EC; if (Exists) goto retry_random_path; - return error_code(); + return std::error_code(); } case FS_Dir: { - if (error_code EC = sys::fs::create_directory(ResultPath.begin(), false)) { + if (std::error_code EC = + sys::fs::create_directory(ResultPath.begin(), false)) { if (EC == std::errc::file_exists) goto retry_random_path; return EC; } - return error_code(); + return std::error_code(); } } llvm_unreachable("Invalid Type"); @@ -706,29 +706,30 @@ bool is_relative(const Twine &path) { namespace fs { -error_code getUniqueID(const Twine Path, UniqueID &Result) { +std::error_code getUniqueID(const Twine Path, UniqueID &Result) { file_status Status; - error_code EC = status(Path, Status); + std::error_code EC = status(Path, Status); if (EC) return EC; Result = Status.getUniqueID(); - return error_code(); + return std::error_code(); } -error_code createUniqueFile(const Twine &Model, int &ResultFd, - SmallVectorImpl &ResultPath, unsigned Mode) { +std::error_code createUniqueFile(const Twine &Model, int &ResultFd, + SmallVectorImpl &ResultPath, + unsigned Mode) { return createUniqueEntity(Model, ResultFd, ResultPath, false, Mode, FS_File); } -error_code createUniqueFile(const Twine &Model, - SmallVectorImpl &ResultPath) { +std::error_code createUniqueFile(const Twine &Model, + SmallVectorImpl &ResultPath) { int Dummy; return createUniqueEntity(Model, Dummy, ResultPath, false, 0, FS_Name); } -static error_code createTemporaryFile(const Twine &Model, int &ResultFD, - llvm::SmallVectorImpl &ResultPath, - FSEntity Type) { +static std::error_code +createTemporaryFile(const Twine &Model, int &ResultFD, + llvm::SmallVectorImpl &ResultPath, FSEntity Type) { SmallString<128> Storage; StringRef P = Model.toNullTerminatedStringRef(Storage); assert(P.find_first_of(separators) == StringRef::npos && @@ -738,24 +739,22 @@ static error_code createTemporaryFile(const Twine &Model, int &ResultFD, true, owner_read | owner_write, Type); } -static error_code +static std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, - llvm::SmallVectorImpl &ResultPath, - FSEntity Type) { + llvm::SmallVectorImpl &ResultPath, FSEntity Type) { const char *Middle = Suffix.empty() ? "-%%%%%%" : "-%%%%%%."; return createTemporaryFile(Prefix + Middle + Suffix, ResultFD, ResultPath, Type); } - -error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, - int &ResultFD, - SmallVectorImpl &ResultPath) { +std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, + int &ResultFD, + SmallVectorImpl &ResultPath) { return createTemporaryFile(Prefix, Suffix, ResultFD, ResultPath, FS_File); } -error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, - SmallVectorImpl &ResultPath) { +std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, + SmallVectorImpl &ResultPath) { int Dummy; return createTemporaryFile(Prefix, Suffix, Dummy, ResultPath, FS_Name); } @@ -763,14 +762,14 @@ error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, // This is a mkdtemp with a different pattern. We use createUniqueEntity mostly // for consistency. We should try using mkdtemp. -error_code createUniqueDirectory(const Twine &Prefix, - SmallVectorImpl &ResultPath) { +std::error_code createUniqueDirectory(const Twine &Prefix, + SmallVectorImpl &ResultPath) { int Dummy; return createUniqueEntity(Prefix + "-%%%%%%", Dummy, ResultPath, true, 0, FS_Dir); } -error_code make_absolute(SmallVectorImpl &path) { +std::error_code make_absolute(SmallVectorImpl &path) { StringRef p(path.data(), path.size()); bool rootDirectory = path::has_root_directory(p), @@ -782,11 +781,12 @@ error_code make_absolute(SmallVectorImpl &path) { // Already absolute. if (rootName && rootDirectory) - return error_code(); + return std::error_code(); // All of the following conditions will need the current directory. SmallString<128> current_dir; - if (error_code ec = current_path(current_dir)) return ec; + if (std::error_code ec = current_path(current_dir)) + return ec; // Relative path. Prepend the current directory. if (!rootName && !rootDirectory) { @@ -794,7 +794,7 @@ error_code make_absolute(SmallVectorImpl &path) { path::append(current_dir, p); // Set path to the result. path.swap(current_dir); - return error_code(); + return std::error_code(); } if (!rootName && rootDirectory) { @@ -803,7 +803,7 @@ error_code make_absolute(SmallVectorImpl &path) { path::append(curDirRootName, p); // Set path to the result. path.swap(curDirRootName); - return error_code(); + return std::error_code(); } if (rootName && !rootDirectory) { @@ -815,19 +815,19 @@ error_code make_absolute(SmallVectorImpl &path) { SmallString<128> res; path::append(res, pRootName, bRootDirectory, bRelativePath, pRelativePath); path.swap(res); - return error_code(); + return std::error_code(); } llvm_unreachable("All rootName and rootDirectory combinations should have " "occurred above!"); } -error_code create_directories(const Twine &Path, bool IgnoreExisting) { +std::error_code create_directories(const Twine &Path, bool IgnoreExisting) { SmallString<128> PathStorage; StringRef P = Path.toStringRef(PathStorage); // Be optimistic and try to create the directory - error_code EC = create_directory(P, IgnoreExisting); + std::error_code EC = create_directory(P, IgnoreExisting); // If we succeeded, or had any error other than the parent not existing, just // return it. if (EC != std::errc::no_such_file_or_directory) @@ -857,24 +857,24 @@ bool is_directory(file_status status) { return status.type() == file_type::directory_file; } -error_code is_directory(const Twine &path, bool &result) { +std::error_code is_directory(const Twine &path, bool &result) { file_status st; - if (error_code ec = status(path, st)) + if (std::error_code ec = status(path, st)) return ec; result = is_directory(st); - return error_code(); + return std::error_code(); } bool is_regular_file(file_status status) { return status.type() == file_type::regular_file; } -error_code is_regular_file(const Twine &path, bool &result) { +std::error_code is_regular_file(const Twine &path, bool &result) { file_status st; - if (error_code ec = status(path, st)) + if (std::error_code ec = status(path, st)) return ec; result = is_regular_file(st); - return error_code(); + return std::error_code(); } bool is_other(file_status status) { @@ -1023,21 +1023,21 @@ void directory_entry::replace_filename(const Twine &filename, file_status st) { return file_magic::unknown; } -error_code identify_magic(const Twine &Path, file_magic &Result) { +std::error_code identify_magic(const Twine &Path, file_magic &Result) { int FD; - if (error_code EC = openFileForRead(Path, FD)) + if (std::error_code EC = openFileForRead(Path, FD)) return EC; char Buffer[32]; int Length = read(FD, Buffer, sizeof(Buffer)); if (Length < 0) - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); Result = identify_magic(StringRef(Buffer, Length)); - return error_code(); + return std::error_code(); } -error_code directory_entry::status(file_status &result) const { +std::error_code directory_entry::status(file_status &result) const { return fs::status(Path, result); } diff --git a/lib/Support/Unix/Memory.inc b/lib/Support/Unix/Memory.inc index cca3782949..c9d89a8247 100644 --- a/lib/Support/Unix/Memory.inc +++ b/lib/Support/Unix/Memory.inc @@ -37,7 +37,6 @@ extern "C" void sys_icache_invalidate(const void *Addr, size_t len); #else extern "C" void __clear_cache(void *, void*); #endif -using std::error_code; namespace { @@ -84,8 +83,8 @@ MemoryBlock Memory::allocateMappedMemory(size_t NumBytes, const MemoryBlock *const NearBlock, unsigned PFlags, - error_code &EC) { - EC = error_code(); + std::error_code &EC) { + EC = std::error_code(); if (NumBytes == 0) return MemoryBlock(); @@ -96,7 +95,7 @@ Memory::allocateMappedMemory(size_t NumBytes, #ifdef NEED_DEV_ZERO_FOR_MMAP static int zero_fd = open("/dev/zero", O_RDWR); if (zero_fd == -1) { - EC = error_code(errno, std::generic_category()); + EC = std::error_code(errno, std::generic_category()); return MemoryBlock(); } fd = zero_fd; @@ -124,7 +123,7 @@ Memory::allocateMappedMemory(size_t NumBytes, if (NearBlock) //Try again without a near hint return allocateMappedMemory(NumBytes, nullptr, PFlags, EC); - EC = error_code(errno, std::generic_category()); + EC = std::error_code(errno, std::generic_category()); return MemoryBlock(); } @@ -138,38 +137,38 @@ Memory::allocateMappedMemory(size_t NumBytes, return Result; } -error_code +std::error_code Memory::releaseMappedMemory(MemoryBlock &M) { if (M.Address == nullptr || M.Size == 0) - return error_code(); + return std::error_code(); if (0 != ::munmap(M.Address, M.Size)) - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); M.Address = nullptr; M.Size = 0; - return error_code(); + return std::error_code(); } -error_code +std::error_code Memory::protectMappedMemory(const MemoryBlock &M, unsigned Flags) { if (M.Address == nullptr || M.Size == 0) - return error_code(); + return std::error_code(); if (!Flags) - return error_code(EINVAL, std::generic_category()); + return std::error_code(EINVAL, std::generic_category()); int Protect = getPosixProtectionFlags(Flags); int Result = ::mprotect(M.Address, M.Size, Protect); if (Result != 0) - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); if (Flags & MF_EXEC) Memory::InvalidateInstructionCache(M.Address, M.Size); - return error_code(); + return std::error_code(); } /// AllocateRWX - Allocate a slab of memory with read/write/execute diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc index 6a343bd06d..824673649c 100644 --- a/lib/Support/Unix/Path.inc +++ b/lib/Support/Unix/Path.inc @@ -87,7 +87,7 @@ namespace { }; } -static error_code TempDir(SmallVectorImpl &result) { +static std::error_code TempDir(SmallVectorImpl &result) { // FIXME: Don't use TMPDIR if program is SUID or SGID enabled. const char *dir = nullptr; (dir = std::getenv("TMPDIR")) || (dir = std::getenv("TMP")) || @@ -100,7 +100,7 @@ static error_code TempDir(SmallVectorImpl &result) { result.clear(); StringRef d(dir); result.append(d.begin(), d.end()); - return error_code(); + return std::error_code(); } namespace llvm { @@ -225,7 +225,7 @@ UniqueID file_status::getUniqueID() const { return UniqueID(fs_st_dev, fs_st_ino); } -error_code current_path(SmallVectorImpl &result) { +std::error_code current_path(SmallVectorImpl &result) { result.clear(); const char *pwd = ::getenv("PWD"); @@ -235,7 +235,7 @@ error_code current_path(SmallVectorImpl &result) { !llvm::sys::fs::status(".", DotStatus) && PWDStatus.getUniqueID() == DotStatus.getUniqueID()) { result.append(pwd, pwd + strlen(pwd)); - return error_code(); + return std::error_code(); } #ifdef MAXPATHLEN @@ -249,7 +249,7 @@ error_code current_path(SmallVectorImpl &result) { if (::getcwd(result.data(), result.capacity()) == nullptr) { // See if there was a real error. if (errno != ENOMEM) - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); // Otherwise there just wasn't enough space. result.reserve(result.capacity() * 2); } else @@ -257,22 +257,22 @@ error_code current_path(SmallVectorImpl &result) { } result.set_size(strlen(result.data())); - return error_code(); + return std::error_code(); } -error_code create_directory(const Twine &path, bool IgnoreExisting) { +std::error_code create_directory(const Twine &path, bool IgnoreExisting) { SmallString<128> path_storage; StringRef p = path.toNullTerminatedStringRef(path_storage); if (::mkdir(p.begin(), S_IRWXU | S_IRWXG) == -1) { if (errno != EEXIST || !IgnoreExisting) - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); } - return error_code(); + return std::error_code(); } -error_code normalize_separators(SmallVectorImpl &Path) { +std::error_code normalize_separators(SmallVectorImpl &Path) { for (auto PI = Path.begin(), PE = Path.end(); PI < PE; ++PI) { if (*PI == '\\') { auto PN = PI + 1; @@ -282,12 +282,12 @@ error_code normalize_separators(SmallVectorImpl &Path) { *PI = '/'; } } - return error_code(); + return std::error_code(); } // Note that we are using symbolic link because hard links are not supported by // all filesystems (SMB doesn't). -error_code create_link(const Twine &to, const Twine &from) { +std::error_code create_link(const Twine &to, const Twine &from) { // Get arguments. SmallString<128> from_storage; SmallString<128> to_storage; @@ -295,20 +295,20 @@ error_code create_link(const Twine &to, const Twine &from) { StringRef t = to.toNullTerminatedStringRef(to_storage); if (::symlink(t.begin(), f.begin()) == -1) - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); - return error_code(); + return std::error_code(); } -error_code remove(const Twine &path, bool IgnoreNonExisting) { +std::error_code remove(const Twine &path, bool IgnoreNonExisting) { SmallString<128> path_storage; StringRef p = path.toNullTerminatedStringRef(path_storage); struct stat buf; if (lstat(p.begin(), &buf) != 0) { if (errno != ENOENT || !IgnoreNonExisting) - return error_code(errno, std::generic_category()); - return error_code(); + return std::error_code(errno, std::generic_category()); + return std::error_code(); } // Note: this check catches strange situations. In all cases, LLVM should @@ -321,13 +321,13 @@ error_code remove(const Twine &path, bool IgnoreNonExisting) { if (::remove(p.begin()) == -1) { if (errno != ENOENT || !IgnoreNonExisting) - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); } - return error_code(); + return std::error_code(); } -error_code rename(const Twine &from, const Twine &to) { +std::error_code rename(const Twine &from, const Twine &to) { // Get arguments. SmallString<128> from_storage; SmallString<128> to_storage; @@ -335,33 +335,33 @@ error_code rename(const Twine &from, const Twine &to) { StringRef t = to.toNullTerminatedStringRef(to_storage); if (::rename(f.begin(), t.begin()) == -1) - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); - return error_code(); + return std::error_code(); } -error_code resize_file(const Twine &path, uint64_t size) { +std::error_code resize_file(const Twine &path, uint64_t size) { SmallString<128> path_storage; StringRef p = path.toNullTerminatedStringRef(path_storage); if (::truncate(p.begin(), size) == -1) - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); - return error_code(); + return std::error_code(); } -error_code exists(const Twine &path, bool &result) { +std::error_code exists(const Twine &path, bool &result) { SmallString<128> path_storage; StringRef p = path.toNullTerminatedStringRef(path_storage); if (::access(p.begin(), F_OK) == -1) { if (errno != ENOENT) - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); result = false; } else result = true; - return error_code(); + return std::error_code(); } bool can_write(const Twine &Path) { @@ -390,18 +390,20 @@ bool equivalent(file_status A, file_status B) { A.fs_st_ino == B.fs_st_ino; } -error_code equivalent(const Twine &A, const Twine &B, bool &result) { +std::error_code equivalent(const Twine &A, const Twine &B, bool &result) { file_status fsA, fsB; - if (error_code ec = status(A, fsA)) return ec; - if (error_code ec = status(B, fsB)) return ec; + if (std::error_code ec = status(A, fsA)) + return ec; + if (std::error_code ec = status(B, fsB)) + return ec; result = equivalent(fsA, fsB); - return error_code(); + return std::error_code(); } -static error_code fillStatus(int StatRet, const struct stat &Status, +static std::error_code fillStatus(int StatRet, const struct stat &Status, file_status &Result) { if (StatRet != 0) { - error_code ec(errno, std::generic_category()); + std::error_code ec(errno, std::generic_category()); if (ec == std::errc::no_such_file_or_directory) Result = file_status(file_type::file_not_found); else @@ -429,10 +431,10 @@ static error_code fillStatus(int StatRet, const struct stat &Status, file_status(Type, Perms, Status.st_dev, Status.st_ino, Status.st_mtime, Status.st_uid, Status.st_gid, Status.st_size); - return error_code(); + return std::error_code(); } -error_code status(const Twine &Path, file_status &Result) { +std::error_code status(const Twine &Path, file_status &Result) { SmallString<128> PathStorage; StringRef P = Path.toNullTerminatedStringRef(PathStorage); @@ -441,36 +443,36 @@ error_code status(const Twine &Path, file_status &Result) { return fillStatus(StatRet, Status, Result); } -error_code status(int FD, file_status &Result) { +std::error_code status(int FD, file_status &Result) { struct stat Status; int StatRet = ::fstat(FD, &Status); return fillStatus(StatRet, Status, Result); } -error_code setLastModificationAndAccessTime(int FD, TimeValue Time) { +std::error_code setLastModificationAndAccessTime(int FD, TimeValue Time) { #if defined(HAVE_FUTIMENS) timespec Times[2]; Times[0].tv_sec = Time.toEpochTime(); Times[0].tv_nsec = 0; Times[1] = Times[0]; if (::futimens(FD, Times)) - return error_code(errno, std::generic_category()); - return error_code(); + return std::error_code(errno, std::generic_category()); + return std::error_code(); #elif defined(HAVE_FUTIMES) timeval Times[2]; Times[0].tv_sec = Time.toEpochTime(); Times[0].tv_usec = 0; Times[1] = Times[0]; if (::futimes(FD, Times)) - return error_code(errno, std::generic_category()); - return error_code(); + return std::error_code(errno, std::generic_category()); + return std::error_code(); #else #warning Missing futimes() and futimens() return make_error_code(std::errc::not_supported); #endif } -error_code mapped_file_region::init(int FD, bool CloseFD, uint64_t Offset) { +std::error_code mapped_file_region::init(int FD, bool CloseFD, uint64_t Offset) { AutoFD ScopedFD(FD); if (!CloseFD) ScopedFD.take(); @@ -478,7 +480,7 @@ error_code mapped_file_region::init(int FD, bool CloseFD, uint64_t Offset) { // Figure out how large the file is. struct stat FileInfo; if (fstat(FD, &FileInfo) == -1) - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); uint64_t FileSize = FileInfo.st_size; if (Size == 0) @@ -486,7 +488,7 @@ error_code mapped_file_region::init(int FD, bool CloseFD, uint64_t Offset) { else if (FileSize < Size) { // We need to grow the file. if (ftruncate(FD, Size) == -1) - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); } int flags = (Mode == readwrite) ? MAP_SHARED : MAP_PRIVATE; @@ -496,15 +498,15 @@ error_code mapped_file_region::init(int FD, bool CloseFD, uint64_t Offset) { #endif Mapping = ::mmap(nullptr, Size, prot, flags, FD, Offset); if (Mapping == MAP_FAILED) - return error_code(errno, std::generic_category()); - return error_code(); + return std::error_code(errno, std::generic_category()); + return std::error_code(); } mapped_file_region::mapped_file_region(const Twine &path, mapmode mode, uint64_t length, uint64_t offset, - error_code &ec) + std::error_code &ec) : Mode(mode) , Size(length) , Mapping() { @@ -519,7 +521,7 @@ mapped_file_region::mapped_file_region(const Twine &path, int oflags = (mode == readonly) ? O_RDONLY : O_RDWR; int ofd = ::open(name.begin(), oflags); if (ofd == -1) { - ec = error_code(errno, std::generic_category()); + ec = std::error_code(errno, std::generic_category()); return; } @@ -533,7 +535,7 @@ mapped_file_region::mapped_file_region(int fd, mapmode mode, uint64_t length, uint64_t offset, - error_code &ec) + std::error_code &ec) : Mode(mode) , Size(length) , Mapping() { @@ -583,12 +585,12 @@ int mapped_file_region::alignment() { return process::get_self()->page_size(); } -error_code detail::directory_iterator_construct(detail::DirIterState &it, +std::error_code detail::directory_iterator_construct(detail::DirIterState &it, StringRef path){ SmallString<128> path_null(path); DIR *directory = ::opendir(path_null.c_str()); if (!directory) - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); it.IterationHandle = reinterpret_cast(directory); // Add something for replace_filename to replace. @@ -597,19 +599,19 @@ error_code detail::directory_iterator_construct(detail::DirIterState &it, return directory_iterator_increment(it); } -error_code detail::directory_iterator_destruct(detail::DirIterState &it) { +std::error_code detail::directory_iterator_destruct(detail::DirIterState &it) { if (it.IterationHandle) ::closedir(reinterpret_cast(it.IterationHandle)); it.IterationHandle = 0; it.CurrentEntry = directory_entry(); - return error_code(); + return std::error_code(); } -error_code detail::directory_iterator_increment(detail::DirIterState &it) { +std::error_code detail::directory_iterator_increment(detail::DirIterState &it) { errno = 0; dirent *cur_dir = ::readdir(reinterpret_cast(it.IterationHandle)); if (cur_dir == nullptr && errno != 0) { - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); } else if (cur_dir != nullptr) { StringRef name(cur_dir->d_name, NAMLEN(cur_dir)); if ((name.size() == 1 && name[0] == '.') || @@ -619,20 +621,20 @@ error_code detail::directory_iterator_increment(detail::DirIterState &it) { } else return directory_iterator_destruct(it); - return error_code(); + return std::error_code(); } -error_code openFileForRead(const Twine &Name, int &ResultFD) { +std::error_code openFileForRead(const Twine &Name, int &ResultFD) { SmallString<128> Storage; StringRef P = Name.toNullTerminatedStringRef(Storage); while ((ResultFD = open(P.begin(), O_RDONLY)) < 0) { if (errno != EINTR) - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); } - return error_code(); + return std::error_code(); } -error_code openFileForWrite(const Twine &Name, int &ResultFD, +std::error_code openFileForWrite(const Twine &Name, int &ResultFD, sys::fs::OpenFlags Flags, unsigned Mode) { // Verify that we don't have both "append" and "excl". assert((!(Flags & sys::fs::F_Excl) || !(Flags & sys::fs::F_Append)) && @@ -657,9 +659,9 @@ error_code openFileForWrite(const Twine &Name, int &ResultFD, StringRef P = Name.toNullTerminatedStringRef(Storage); while ((ResultFD = open(P.begin(), OpenFlags, Mode)) < 0) { if (errno != EINTR) - return error_code(errno, std::generic_category()); + return std::error_code(errno, std::generic_category()); } - return error_code(); + return std::error_code(); } } // end namespace fs diff --git a/lib/Support/Unix/Process.inc b/lib/Support/Unix/Process.inc index ea2b8dcda2..d2c5dbcf6e 100644 --- a/lib/Support/Unix/Process.inc +++ b/lib/Support/Unix/Process.inc @@ -46,7 +46,6 @@ using namespace llvm; using namespace sys; -using std::error_code; process::id_type self_process::get_id() { return getpid(); @@ -190,12 +189,13 @@ Optional Process::GetEnv(StringRef Name) { return std::string(Val); } -error_code Process::GetArgumentVector(SmallVectorImpl &ArgsOut, - ArrayRef ArgsIn, - SpecificBumpPtrAllocator &) { +std::error_code +Process::GetArgumentVector(SmallVectorImpl &ArgsOut, + ArrayRef ArgsIn, + SpecificBumpPtrAllocator &) { ArgsOut.append(ArgsIn.begin(), ArgsIn.end()); - return error_code(); + return std::error_code(); } bool Process::StandardInIsUserInput() { diff --git a/lib/Support/Unix/Program.inc b/lib/Support/Unix/Program.inc index d850664334..50f973a850 100644 --- a/lib/Support/Unix/Program.inc +++ b/lib/Support/Unix/Program.inc @@ -48,7 +48,6 @@ #endif namespace llvm { -using std::error_code; using namespace sys; @@ -427,14 +426,14 @@ ProcessInfo sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait, return WaitResult; } -error_code sys::ChangeStdinToBinary(){ + std::error_code sys::ChangeStdinToBinary(){ // Do nothing, as Unix doesn't differentiate between text and binary. - return error_code(); + return std::error_code(); } -error_code sys::ChangeStdoutToBinary(){ + std::error_code sys::ChangeStdoutToBinary(){ // Do nothing, as Unix doesn't differentiate between text and binary. - return error_code(); + return std::error_code(); } bool llvm::sys::argumentsFitWithinSystemLimits(ArrayRef Args) { diff --git a/lib/Support/Windows/Memory.inc b/lib/Support/Windows/Memory.inc index 431cfb6cf9..ae8371abf5 100644 --- a/lib/Support/Windows/Memory.inc +++ b/lib/Support/Windows/Memory.inc @@ -19,7 +19,6 @@ // The Windows.h header must be the last one included. #include "WindowsSupport.h" -using std::error_code; namespace { @@ -71,8 +70,8 @@ namespace sys { MemoryBlock Memory::allocateMappedMemory(size_t NumBytes, const MemoryBlock *const NearBlock, unsigned Flags, - error_code &EC) { - EC = error_code(); + std::error_code &EC) { + EC = std::error_code(); if (NumBytes == 0) return MemoryBlock(); @@ -115,9 +114,9 @@ MemoryBlock Memory::allocateMappedMemory(size_t NumBytes, return Result; } -error_code Memory::releaseMappedMemory(MemoryBlock &M) { + std::error_code Memory::releaseMappedMemory(MemoryBlock &M) { if (M.Address == 0 || M.Size == 0) - return error_code(); + return std::error_code(); if (!VirtualFree(M.Address, 0, MEM_RELEASE)) return mapWindowsError(::GetLastError()); @@ -125,13 +124,13 @@ error_code Memory::releaseMappedMemory(MemoryBlock &M) { M.Address = 0; M.Size = 0; - return error_code(); + return std::error_code(); } -error_code Memory::protectMappedMemory(const MemoryBlock &M, + std::error_code Memory::protectMappedMemory(const MemoryBlock &M, unsigned Flags) { if (M.Address == 0 || M.Size == 0) - return error_code(); + return std::error_code(); DWORD Protect = getWindowsProtectionFlags(Flags); @@ -142,7 +141,7 @@ error_code Memory::protectMappedMemory(const MemoryBlock &M, if (Flags & MF_EXEC) Memory::InvalidateInstructionCache(M.Address, M.Size); - return error_code(); + return std::error_code(); } /// InvalidateInstructionCache - Before the JIT can run a block of code @@ -158,18 +157,18 @@ MemoryBlock Memory::AllocateRWX(size_t NumBytes, const MemoryBlock *NearBlock, std::string *ErrMsg) { MemoryBlock MB; - error_code EC; + std::error_code EC; MB = allocateMappedMemory(NumBytes, NearBlock, MF_READ|MF_WRITE|MF_EXEC, EC); - if (EC != error_code() && ErrMsg) { + if (EC != std::error_code() && ErrMsg) { MakeErrMsg(ErrMsg, EC.message()); } return MB; } bool Memory::ReleaseRWX(MemoryBlock &M, std::string *ErrMsg) { - error_code EC = releaseMappedMemory(M); - if (EC == error_code()) + std::error_code EC = releaseMappedMemory(M); + if (EC == std::error_code()) return false; MakeErrMsg(ErrMsg, EC.message()); return true; diff --git a/lib/Support/Windows/Process.inc b/lib/Support/Windows/Process.inc index c88557c5ee..81aee0e1b6 100644 --- a/lib/Support/Windows/Process.inc +++ b/lib/Support/Windows/Process.inc @@ -48,7 +48,6 @@ using namespace llvm; using namespace sys; -using std::error_code; process::id_type self_process::get_id() { return GetCurrentProcessId(); @@ -180,16 +179,16 @@ Optional Process::GetEnv(StringRef Name) { return std::string(Res.data()); } -static error_code windows_error(DWORD E) { +static std::error_code windows_error(DWORD E) { return mapWindowsError(E); } -error_code +std::error_code Process::GetArgumentVector(SmallVectorImpl &Args, ArrayRef, SpecificBumpPtrAllocator &ArgAllocator) { int NewArgCount; - error_code ec; + std::error_code ec; wchar_t **UnicodeCommandLine = CommandLineToArgvW(GetCommandLineW(), &NewArgCount); @@ -214,7 +213,7 @@ Process::GetArgumentVector(SmallVectorImpl &Args, if (ec) return ec; - return error_code(); + return std::error_code(); } bool Process::StandardInIsUserInput() { diff --git a/lib/Support/Windows/Program.inc b/lib/Support/Windows/Program.inc index 8d1df5ffc9..b2f71aed0c 100644 --- a/lib/Support/Windows/Program.inc +++ b/lib/Support/Windows/Program.inc @@ -24,7 +24,6 @@ //===----------------------------------------------------------------------===// namespace llvm { -using std::error_code; using namespace sys; ProcessInfo::ProcessInfo() : ProcessHandle(0), Pid(0), ReturnCode(0) {} @@ -227,7 +226,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **args, // an environment block by concatenating them. for (unsigned i = 0; envp[i]; ++i) { SmallVector EnvString; - if (error_code ec = windows::UTF8ToUTF16(envp[i], EnvString)) { + if (std::error_code ec = windows::UTF8ToUTF16(envp[i], EnvString)) { SetLastError(ec.value()); MakeErrMsg(ErrMsg, "Unable to convert environment variable to UTF-16"); return false; @@ -291,7 +290,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **args, fflush(stderr); SmallVector ProgramUtf16; - if (error_code ec = windows::UTF8ToUTF16(Program, ProgramUtf16)) { + if (std::error_code ec = windows::UTF8ToUTF16(Program, ProgramUtf16)) { SetLastError(ec.value()); MakeErrMsg(ErrMsg, std::string("Unable to convert application name to UTF-16")); @@ -299,7 +298,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **args, } SmallVector CommandUtf16; - if (error_code ec = windows::UTF8ToUTF16(command.get(), CommandUtf16)) { + if (std::error_code ec = windows::UTF8ToUTF16(command.get(), CommandUtf16)) { SetLastError(ec.value()); MakeErrMsg(ErrMsg, std::string("Unable to convert command-line to UTF-16")); @@ -423,18 +422,18 @@ ProcessInfo sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait, return WaitResult; } -error_code sys::ChangeStdinToBinary(){ + std::error_code sys::ChangeStdinToBinary(){ int result = _setmode( _fileno(stdin), _O_BINARY ); if (result == -1) - return error_code(errno, std::generic_category()); - return error_code(); + return std::error_code(errno, std::generic_category()); + return std::error_code(); } -error_code sys::ChangeStdoutToBinary(){ + std::error_code sys::ChangeStdoutToBinary(){ int result = _setmode( _fileno(stdout), _O_BINARY ); if (result == -1) - return error_code(errno, std::generic_category()); - return error_code(); + return std::error_code(errno, std::generic_category()); + return std::error_code(); } bool llvm::sys::argumentsFitWithinSystemLimits(ArrayRef Args) { diff --git a/lib/Support/YAMLTraits.cpp b/lib/Support/YAMLTraits.cpp index 0042c29036..0bf9cf8908 100644 --- a/lib/Support/YAMLTraits.cpp +++ b/lib/Support/YAMLTraits.cpp @@ -18,7 +18,6 @@ #include using namespace llvm; using namespace yaml; -using std::error_code; //===----------------------------------------------------------------------===// // IO @@ -57,9 +56,7 @@ Input::Input(StringRef InputContent, Input::~Input() { } -error_code Input::error() { - return EC; -} +std::error_code Input::error() { return EC; } // Pin the vtables to this file. void Input::HNode::anchor() {} diff --git a/lib/TableGen/Main.cpp b/lib/TableGen/Main.cpp index c757b852a4..191307a66b 100644 --- a/lib/TableGen/Main.cpp +++ b/lib/TableGen/Main.cpp @@ -27,7 +27,6 @@ #include #include using namespace llvm; -using std::error_code; namespace { cl::opt @@ -83,8 +82,7 @@ int TableGenMain(char *argv0, TableGenMainFn *MainFn) { // Parse the input file. std::unique_ptr File; - if (error_code ec = - MemoryBuffer::getFileOrSTDIN(InputFilename, File)) { + if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, File)) { errs() << "Could not open input file '" << InputFilename << "': " << ec.message() <<"\n"; return 1; diff --git a/lib/Transforms/Scalar/SampleProfile.cpp b/lib/Transforms/Scalar/SampleProfile.cpp index 4b97295d17..888e252738 100644 --- a/lib/Transforms/Scalar/SampleProfile.cpp +++ b/lib/Transforms/Scalar/SampleProfile.cpp @@ -51,7 +51,6 @@ #include using namespace llvm; -using std::error_code; #define DEBUG_TYPE "sample-profile" @@ -452,7 +451,7 @@ void SampleModuleProfile::dump() { /// \returns true if the file was loaded successfully, false otherwise. bool SampleModuleProfile::loadText() { std::unique_ptr Buffer; - error_code EC = MemoryBuffer::getFile(Filename, Buffer); + std::error_code EC = MemoryBuffer::getFile(Filename, Buffer); if (EC) { std::string Msg(EC.message()); M.getContext().diagnose(DiagnosticInfoSampleProfile(Filename.data(), Msg)); diff --git a/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/lib/Transforms/Scalar/SimplifyCFGPass.cpp index a09e4853fb..5d5606ba47 100644 --- a/lib/Transforms/Scalar/SimplifyCFGPass.cpp +++ b/lib/Transforms/Scalar/SimplifyCFGPass.cpp @@ -36,7 +36,6 @@ #include "llvm/Pass.h" #include "llvm/Transforms/Utils/Local.h" using namespace llvm; -using std::error_code; #define DEBUG_TYPE "simplifycfg" diff --git a/lib/Transforms/Utils/SpecialCaseList.cpp b/lib/Transforms/Utils/SpecialCaseList.cpp index 8ae36fe833..45a2b618a7 100644 --- a/lib/Transforms/Utils/SpecialCaseList.cpp +++ b/lib/Transforms/Utils/SpecialCaseList.cpp @@ -31,7 +31,6 @@ #include namespace llvm { -using std::error_code; /// Represents a set of regular expressions. Regular expressions which are /// "literal" (i.e. no regex metacharacters) are stored in Strings, while all @@ -56,7 +55,7 @@ SpecialCaseList *SpecialCaseList::create( if (Path.empty()) return new SpecialCaseList(); std::unique_ptr File; - if (error_code EC = MemoryBuffer::getFile(Path, File)) { + if (std::error_code EC = MemoryBuffer::getFile(Path, File)) { Error = (Twine("Can't open file '") + Path + "': " + EC.message()).str(); return nullptr; } -- cgit v1.2.3