[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: refactor issue reporting (PR #135662)

Kristof Beyls via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Apr 29 00:24:43 PDT 2025


================
@@ -720,16 +713,30 @@ SrcSafetyAnalysis::create(BinaryFunction &BF,
                                                        RegsToTrackInstsFor);
 }
 
-static std::shared_ptr<Report>
+static BriefReport<MCPhysReg> make_generic_report(MCInstReference Location,
+                                                  StringRef Text) {
+  auto Report = std::make_shared<GenericDiagnostic>(Location, Text);
+  return BriefReport<MCPhysReg>(Report, std::nullopt);
+}
+
+template <typename T>
+static BriefReport<T> make_report(const GadgetKind &Kind,
+                                  MCInstReference Location,
----------------
kbeyls wrote:

If the first function is called `make_generic_report`, would it be more consistent to call the second function `make_gadget_report`?

I started wondering if it'd be possible to unify the two functions into a more general templated function, something like
```
template <typename DiagT, typename DiagParam, typename ReqDetailsT>
static BriefReport<T> make_brief_report(MCInstReference Location, DiagParam P, ReqDetailsT ReqDetails) {
  auto Report = std::make_shared<DiagT>(Location, P);
  return BriefReport<T>(Report, ReqDetails);
}
```

and then it gets called like
`make_brief_report<GenericDiagnostic, StringRef, MCPhysReg>(Location, Text, std::nullopt)` or
`make_brief_report<GadgetDiagnostic, GadgetKind, RequestedDetailsT>(Location, Kind, RequestedDetails)`
(sorry, haven't spent time thinking about reducing the number of explicit template parameters).

I'm guessing you might have thought about this and come to the conclusion that having two `make_report` functions is better?



https://github.com/llvm/llvm-project/pull/135662


More information about the llvm-branch-commits mailing list