From c77a7749ffee133e5f888c8aa6bbb50c4f85f70a Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 4 Jul 2014 20:02:42 +0000 Subject: [PATCH] Revert "Convert a few std::strings to StringRef." This reverts commit r212342. We can get a StringRef into the current Record, but not one in the bitcode itself since the string is compressed in it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212356 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Bitcode/ReaderWriter.h | 4 ++-- lib/Bitcode/Reader/BitcodeReader.cpp | 29 ++++++++++------------------ lib/Bitcode/Reader/BitcodeReader.h | 9 +++------ lib/LTO/LTOModule.cpp | 4 ++-- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/include/llvm/Bitcode/ReaderWriter.h b/include/llvm/Bitcode/ReaderWriter.h index 29c15af9ac6..8cf573544f8 100644 --- a/include/llvm/Bitcode/ReaderWriter.h +++ b/include/llvm/Bitcode/ReaderWriter.h @@ -14,7 +14,6 @@ #ifndef LLVM_BITCODE_READERWRITER_H #define LLVM_BITCODE_READERWRITER_H -#include "llvm/ADT/StringRef.h" #include "llvm/Support/ErrorOr.h" #include @@ -45,7 +44,8 @@ namespace llvm { /// Read the header of the specified bitcode buffer and extract just the /// triple information. If successful, this returns a string and *does not* /// take ownership of 'buffer'. On error, this returns "". - StringRef getBitcodeTargetTriple(MemoryBuffer *Buffer, LLVMContext &Context); + std::string getBitcodeTargetTriple(MemoryBuffer *Buffer, + LLVMContext &Context); /// Read the specified bitcode file, returning the module. /// This method *never* takes ownership of Buffer. diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 348234da095..c02b587e3fc 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -71,15 +71,6 @@ static bool ConvertToString(ArrayRef Record, unsigned Idx, return false; } -ErrorOr BitcodeReader::convertToStringRef(ArrayRef Record, - unsigned Idx) { - if (Idx > Record.size()) - return Error(InvalidRecord); - - return StringRef((char*)&Record[Idx], Record.size() - Idx); -} - - static GlobalValue::LinkageTypes GetDecodedLinkage(unsigned Val) { switch (Val) { default: // Map unknown/new linkages to external @@ -2125,13 +2116,13 @@ std::error_code BitcodeReader::ParseBitcodeInto(Module *M) { } } -ErrorOr BitcodeReader::parseModuleTriple() { +ErrorOr BitcodeReader::parseModuleTriple() { if (Stream.EnterSubBlock(bitc::MODULE_BLOCK_ID)) return Error(InvalidRecord); SmallVector Record; - StringRef Triple; + std::string Triple; // Read all the records for this module. while (1) { BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); @@ -2151,10 +2142,10 @@ ErrorOr BitcodeReader::parseModuleTriple() { switch (Stream.readRecord(Entry.ID, Record)) { default: break; // Default behavior, ignore unknown content. case bitc::MODULE_CODE_TRIPLE: { // TRIPLE: [strchr x N] - ErrorOr S = convertToStringRef(Record, 0); - if (std::error_code EC = S.getError()) - return EC; - Triple = S.get(); + std::string S; + if (ConvertToString(Record, 0, S)) + return Error(InvalidRecord); + Triple = S; break; } } @@ -2163,7 +2154,7 @@ ErrorOr BitcodeReader::parseModuleTriple() { return Triple; } -ErrorOr BitcodeReader::parseTriple() { +ErrorOr BitcodeReader::parseTriple() { if (std::error_code EC = InitStream()) return EC; @@ -3478,10 +3469,10 @@ ErrorOr llvm::parseBitcodeFile(MemoryBuffer *Buffer, return M; } -StringRef llvm::getBitcodeTargetTriple(MemoryBuffer *Buffer, - LLVMContext &Context) { +std::string llvm::getBitcodeTargetTriple(MemoryBuffer *Buffer, + LLVMContext &Context) { BitcodeReader *R = new BitcodeReader(Buffer, Context); - ErrorOr Triple = R->parseTriple(); + ErrorOr Triple = R->parseTriple(); R->releaseBuffer(); delete R; if (Triple.getError()) diff --git a/lib/Bitcode/Reader/BitcodeReader.h b/lib/Bitcode/Reader/BitcodeReader.h index e831ea59231..1d4869a2d5a 100644 --- a/lib/Bitcode/Reader/BitcodeReader.h +++ b/lib/Bitcode/Reader/BitcodeReader.h @@ -196,9 +196,6 @@ class BitcodeReader : public GVMaterializer { static const std::error_category &BitcodeErrorCategory(); - static ErrorOr convertToStringRef(ArrayRef Record, - unsigned Idx); - public: enum ErrorType { BitcodeStreamInvalidSize, @@ -223,7 +220,7 @@ public: InvalidValue // Invalid version, inst number, attr number, etc }; - static std::error_code Error(ErrorType E) { + std::error_code Error(ErrorType E) { return std::error_code(E, BitcodeErrorCategory()); } @@ -255,7 +252,7 @@ public: /// @brief Cheap mechanism to just extract module triple /// @returns true if an error occurred. - ErrorOr parseTriple(); + ErrorOr parseTriple(); static uint64_t decodeSignRotatedValue(uint64_t V); @@ -357,7 +354,7 @@ private: std::error_code ResolveGlobalAndAliasInits(); std::error_code ParseMetadata(); std::error_code ParseMetadataAttachment(); - ErrorOr parseModuleTriple(); + ErrorOr parseModuleTriple(); std::error_code ParseUseLists(); std::error_code InitStream(); std::error_code InitStreamFromBuffer(); diff --git a/lib/LTO/LTOModule.cpp b/lib/LTO/LTOModule.cpp index 2fa450fd9d9..5b3057177e2 100644 --- a/lib/LTO/LTOModule.cpp +++ b/lib/LTO/LTOModule.cpp @@ -63,8 +63,8 @@ bool LTOModule::isBitcodeFile(const char *path) { bool LTOModule::isBitcodeForTarget(MemoryBuffer *buffer, StringRef triplePrefix) { - StringRef Triple = getBitcodeTargetTriple(buffer, getGlobalContext()); - return Triple.startswith(triplePrefix); + std::string Triple = getBitcodeTargetTriple(buffer, getGlobalContext()); + return StringRef(Triple).startswith(triplePrefix); } LTOModule *LTOModule::createFromFile(const char *path, TargetOptions options, -- 2.49.0