[PATCH] D19901: [ProfileData] (llvm) Use Error in InstrProf and Coverage

David Li via llvm-commits llvm-commits at lists.llvm.org
Fri May 6 13:23:10 PDT 2016


davidxl added inline comments.

================
Comment at: include/llvm/ProfileData/InstrProf.h:303-321
@@ -282,5 +302,21 @@
 
-inline std::error_code make_error_code(instrprof_error E) {
-  return std::error_code(static_cast<int>(E), instrprof_category());
-}
+class InstrProfError : public EnumBasedError<instrprof_error, InstrProfError> {
+public:
+  InstrProfError(instrprof_error Err)
+      : EnumBasedError<instrprof_error, InstrProfError>(Err) {}
+
+  void log(raw_ostream &OS) const override;
+
+  std::string message() const override;
+
+  /// Consume an Error and return the raw enum value contained within it. The
+  /// Error must either be a success value, or contain a single InstrProfError.
+  static instrprof_error take(Error E) {
+    auto Err = instrprof_error::success;
+    handleAllErrors(std::move(E), [&Err](const InstrProfError &IPE) {
+      assert(Err == instrprof_error::success && "Multiple errors encountered");
+      Err = IPE.get();
+    });
+    return Err;
+  }
 
----------------
vsk wrote:
> lhames wrote:
> > InstrProfError (and CoverageMappingError) need their own ID members. If they don't have them the Error RTTI will treat them both as EnumBasedErrors.
> Yikes! Is this true even if I define distinct ID's for them? Specifically:
> 
> ```
> template <> char EnumBasedError<instrprof_error, InstrProfError>::ID = 0; // InstrProf.cpp
> template <> char EnumBasedError<coveragemap_error, CoverageMapError>::ID = 0; // CoverageMapping.cpp
> ```
Can you elaborate on the RTTI issue?  Also what is the problem that can be caused with this (both Error treated as EnumBasedErrors)?


http://reviews.llvm.org/D19901





More information about the llvm-commits mailing list