]> granicus.if.org Git - llvm/commitdiff
[llvm-exegesis] Fix error propagation from yaml writing (from serialization)
authorRoman Lebedev <lebedev.ri@gmail.com>
Wed, 10 Apr 2019 12:19:57 +0000 (12:19 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Wed, 10 Apr 2019 12:19:57 +0000 (12:19 +0000)
Investigating https://bugs.llvm.org/show_bug.cgi?id=41448

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358076 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-exegesis/lib/BenchmarkResult.cpp
tools/llvm-exegesis/lib/BenchmarkResult.h

index c7a0c8470bbd2523d2fc7be5852bed65df80840d..ed8531f4400362c559bd2b7e8b9862dfcdc3989f 100644 (file)
@@ -365,27 +365,34 @@ InstructionBenchmark::readYamls(const LLVMState &State,
   }
 }
 
-void InstructionBenchmark::writeYamlTo(const LLVMState &State,
-                                       llvm::raw_ostream &OS) {
+llvm::Error InstructionBenchmark::writeYamlTo(const LLVMState &State,
+                                              llvm::raw_ostream &OS) {
   llvm::yaml::Output Yout(OS, nullptr /*Ctx*/, 200 /*WrapColumn*/);
   YamlContext Context(State);
   Yout.beginDocuments();
   llvm::yaml::yamlize(Yout, *this, /*unused*/ true, Context);
+  if (!Context.getLastError().empty())
+    return llvm::make_error<BenchmarkFailure>(Context.getLastError());
   Yout.endDocuments();
+  return Error::success();
 }
 
-void InstructionBenchmark::readYamlFrom(const LLVMState &State,
-                                        llvm::StringRef InputContent) {
+llvm::Error InstructionBenchmark::readYamlFrom(const LLVMState &State,
+                                               llvm::StringRef InputContent) {
   llvm::yaml::Input Yin(InputContent);
   YamlContext Context(State);
   if (Yin.setCurrentDocument())
     llvm::yaml::yamlize(Yin, *this, /*unused*/ true, Context);
+  if (!Context.getLastError().empty())
+    return llvm::make_error<BenchmarkFailure>(Context.getLastError());
+  return Error::success();
 }
 
 llvm::Error InstructionBenchmark::writeYaml(const LLVMState &State,
                                             const llvm::StringRef Filename) {
   if (Filename == "-") {
-    writeYamlTo(State, llvm::outs());
+    if (auto Err = writeYamlTo(State, llvm::outs()))
+      return std::move(Err);
   } else {
     int ResultFD = 0;
     if (auto E = llvm::errorCodeToError(
@@ -394,7 +401,8 @@ llvm::Error InstructionBenchmark::writeYaml(const LLVMState &State,
       return E;
     }
     llvm::raw_fd_ostream Ostr(ResultFD, true /*shouldClose*/);
-    writeYamlTo(State, Ostr);
+    if (auto Err = writeYamlTo(State, Ostr))
+      return std::move(Err);
   }
   return llvm::Error::success();
 }
index d75e18b74896c8b645caedf9a60b3f77ebe06996..e54e8c2a8dac9b3f21510cc9b767909359a67634 100644 (file)
@@ -79,10 +79,11 @@ struct InstructionBenchmark {
   static llvm::Expected<std::vector<InstructionBenchmark>>
   readYamls(const LLVMState &State, llvm::StringRef Filename);
 
-  void readYamlFrom(const LLVMState &State, llvm::StringRef InputContent);
+  llvm::Error readYamlFrom(const LLVMState &State,
+                           llvm::StringRef InputContent);
 
   // Write functions, non-const because of YAML traits.
-  void writeYamlTo(const LLVMState &State, llvm::raw_ostream &S);
+  llvm::Error writeYamlTo(const LLVMState &State, llvm::raw_ostream &S);
 
   llvm::Error writeYaml(const LLVMState &State, const llvm::StringRef Filename);
 };