[PATCH] D20530: Proposal for using stricter error checking in SampleProf

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Mon May 23 11:08:30 PDT 2016


vsk created this revision.
vsk added reviewers: dnovillo, danielcdh.
vsk added a subscriber: llvm-commits.

I'd like to change how error handling is done in the SampleProf code to use the new Error/Expected classes. This will bring make it more consistent with the rest of lib/ProfileData, and will make the code easier to debug and maintain.

My plan is to 1) introduce a soft error tracking class (c.f D20082), 2) start handling any errors we might be dropping now, and finally 3) make the switch from std::error_code to llvm::Error.

Does that plan sound good?

http://reviews.llvm.org/D20530

Files:
  include/llvm/ProfileData/SampleProf.h

Index: include/llvm/ProfileData/SampleProf.h
===================================================================
--- include/llvm/ProfileData/SampleProf.h
+++ include/llvm/ProfileData/SampleProf.h
@@ -46,15 +46,27 @@
   return std::error_code(static_cast<int>(E), sampleprof_category());
 }
 
-inline sampleprof_error MergeResult(sampleprof_error &Accumulator,
-                                    sampleprof_error Result) {
-  // Prefer first error encountered as later errors may be secondary effects of
-  // the initial problem.
-  if (Accumulator == sampleprof_error::success &&
-      Result != sampleprof_error::success)
-    Accumulator = Result;
-  return Accumulator;
-}
+class SampleProfError : public ErrorInfo<SampleProfError> {
+public:
+  SampleProfError(sampleprof_error Err) : Err(Err) {
+    assert(Err != sampleprof_error::success && "Not an error");
+  }
+
+  std::string message() const override;
+
+  void log(raw_ostream &OS) const override { OS << message(); }
+
+  std::error_code convertToErrorCode() const override {
+    return make_error_code(Err);
+  }
+
+  sampleprof_error get() const { return Err; }
+
+  static char ID;
+
+private:
+  sampleprof_error Err;
+};
 
 } // end namespace llvm
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20530.58115.patch
Type: text/x-patch
Size: 1224 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160523/aab42cc6/attachment.bin>


More information about the llvm-commits mailing list