Fix long standing issue with propagating error message back to caller. This
has been a problem since exceptions were removed from the BytecodeReader.
Error messages are now captured from ModuleProvider::releaseModule as well
as after a longjmp.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32608 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index e2ab8c1..1c747af 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -1758,8 +1758,13 @@
 /// @see ParseBytecode
 bool BytecodeReader::ParseFunction(Function* Func, std::string* ErrMsg) {
 
-  if (setjmp(context))
+  if (setjmp(context)) {
+    // Set caller's error message, if requested
+    if (ErrMsg)
+      *ErrMsg = ErrorMsg;
+    // Indicate an error occurred
     return true;
+  }
 
   // Find {start, end} pointers and slot in the map. If not there, we're done.
   LazyFunctionMap::iterator Fi = LazyFunctionLoadMap.find(Func);
@@ -1788,8 +1793,13 @@
 /// to materialize the functions.
 /// @see ParseBytecode
 bool BytecodeReader::ParseAllFunctionBodies(std::string* ErrMsg) {
-  if (setjmp(context))
+  if (setjmp(context)) {
+    // Set caller's error message, if requested
+    if (ErrMsg)
+      *ErrMsg = ErrorMsg;
+    // Indicate an error occurred
     return true;
+  }
 
   LazyFunctionMap::iterator Fi = LazyFunctionLoadMap.begin();
   LazyFunctionMap::iterator Fe = LazyFunctionLoadMap.end();
diff --git a/lib/Bytecode/Reader/ReaderWrappers.cpp b/lib/Bytecode/Reader/ReaderWrappers.cpp
index d45a0f7..a69f297 100644
--- a/lib/Bytecode/Reader/ReaderWrappers.cpp
+++ b/lib/Bytecode/Reader/ReaderWrappers.cpp
@@ -309,7 +309,7 @@
   ModuleProvider *MP = 
     getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, ErrMsg, 0);
   if (!MP) return 0;
-  Module *M = MP->releaseModule();
+  Module *M = MP->releaseModule(ErrMsg);
   delete MP;
   return M;
 }
@@ -341,7 +341,7 @@
                                 std::string *ErrMsg) {
   ModuleProvider* MP = getBytecodeModuleProvider(Filename, ErrMsg);
   if (!MP) return 0;
-  Module *M = MP->releaseModule();
+  Module *M = MP->releaseModule(ErrMsg);
   delete MP;
   return M;
 }
@@ -356,7 +356,7 @@
   BytecodeHandler* AH = createBytecodeAnalyzerHandler(bca,output);
   ModuleProvider* MP = getBytecodeModuleProvider(Filename, ErrMsg, AH);
   if (!MP) return 0;
-  Module *M = MP->releaseModule();
+  Module *M = MP->releaseModule(ErrMsg);
   delete MP;
   return M;
 }
@@ -375,7 +375,7 @@
   ModuleProvider* MP = 
     getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, ErrMsg, hdlr);
   if (!MP) return 0;
-  Module *M = MP->releaseModule();
+  Module *M = MP->releaseModule(ErrMsg);
   delete MP;
   return M;
 }
@@ -388,7 +388,7 @@
     deplibs.clear();
     return true;
   }
-  Module* M = MP->releaseModule();
+  Module* M = MP->releaseModule(ErrMsg);
   deplibs = M->getLibraries();
   delete M;
   delete MP;