[llvm] r212341 - Convert these functions to use ErrorOr.

Rafael Espindola rafael.espindola at gmail.com
Fri Jul 4 06:52:01 PDT 2014


Author: rafael
Date: Fri Jul  4 08:52:01 2014
New Revision: 212341

URL: http://llvm.org/viewvc/llvm-project?rev=212341&view=rev
Log:
Convert these functions to use ErrorOr.

Modified:
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=212341&r1=212340&r2=212341&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Fri Jul  4 08:52:01 2014
@@ -2116,12 +2116,13 @@ std::error_code BitcodeReader::ParseBitc
   }
 }
 
-std::error_code BitcodeReader::ParseModuleTriple(std::string &Triple) {
+ErrorOr<std::string> BitcodeReader::parseModuleTriple() {
   if (Stream.EnterSubBlock(bitc::MODULE_BLOCK_ID))
     return Error(InvalidRecord);
 
   SmallVector<uint64_t, 64> Record;
 
+  std::string Triple;
   // Read all the records for this module.
   while (1) {
     BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
@@ -2150,9 +2151,10 @@ std::error_code BitcodeReader::ParseModu
     }
     Record.clear();
   }
+  return Triple;
 }
 
-std::error_code BitcodeReader::ParseTriple(std::string &Triple) {
+ErrorOr<std::string> BitcodeReader::parseTriple() {
   if (std::error_code EC = InitStream())
     return EC;
 
@@ -2178,7 +2180,7 @@ std::error_code BitcodeReader::ParseTrip
 
     case BitstreamEntry::SubBlock:
       if (Entry.ID == bitc::MODULE_BLOCK_ID)
-        return ParseModuleTriple(Triple);
+        return parseModuleTriple();
 
       // Ignore other sub-blocks.
       if (Stream.SkipBlock())
@@ -3470,11 +3472,10 @@ ErrorOr<Module *> llvm::parseBitcodeFile
 std::string llvm::getBitcodeTargetTriple(MemoryBuffer *Buffer,
                                          LLVMContext &Context) {
   BitcodeReader *R = new BitcodeReader(Buffer, Context);
-
-  std::string Triple("");
-  R->ParseTriple(Triple);
-
+  ErrorOr<std::string> Triple = R->parseTriple();
   R->releaseBuffer();
   delete R;
-  return Triple;
+  if (Triple.getError())
+    return "";
+  return Triple.get();
 }

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h?rev=212341&r1=212340&r2=212341&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h Fri Jul  4 08:52:01 2014
@@ -252,7 +252,7 @@ public:
 
   /// @brief Cheap mechanism to just extract module triple
   /// @returns true if an error occurred.
-  std::error_code ParseTriple(std::string &Triple);
+  ErrorOr<std::string> parseTriple();
 
   static uint64_t decodeSignRotatedValue(uint64_t V);
 
@@ -354,7 +354,7 @@ private:
   std::error_code ResolveGlobalAndAliasInits();
   std::error_code ParseMetadata();
   std::error_code ParseMetadataAttachment();
-  std::error_code ParseModuleTriple(std::string &Triple);
+  ErrorOr<std::string> parseModuleTriple();
   std::error_code ParseUseLists();
   std::error_code InitStream();
   std::error_code InitStreamFromBuffer();





More information about the llvm-commits mailing list