@@ -517,13 +517,11 @@ class SrcSafetyAnalysis {
517517public:
518518 std::vector<MCInstReference>
519519 getLastClobberingInsts (const MCInst &Inst, BinaryFunction &BF,
520- std::optional<MCPhysReg> ClobberedReg) const {
521- if (!ClobberedReg || RegsToTrackInstsFor.empty ())
522- return {};
520+ MCPhysReg ClobberedReg) const {
523521 const SrcState &S = getStateBefore (Inst);
524522
525523 std::vector<MCInstReference> Result;
526- for (const MCInst *Inst : lastWritingInsts (S, * ClobberedReg)) {
524+ for (const MCInst *Inst : lastWritingInsts (S, ClobberedReg)) {
527525 MCInstReference Ref = MCInstReference::get (Inst, BF);
528526 assert (Ref && " Expected Inst to be found" );
529527 Result.push_back (Ref);
@@ -871,16 +869,29 @@ void FunctionAnalysis::augmentUnsafeUseReports(
871869 });
872870
873871 // Augment gadget reports.
874- for (auto Report : Reports) {
872+ for (auto & Report : Reports) {
875873 MCInstReference Location = Report.Issue ->Location ;
876874 LLVM_DEBUG ({ traceInst (BC, " Attaching clobbering info to" , Location); });
875+ assert (Report.RequestedDetails &&
876+ " Should be removed by handleSimpleReports" );
877877 auto DetailedInfo =
878878 std::make_shared<ClobberingInfo>(Analysis->getLastClobberingInsts (
879- Location, BF, Report.RequestedDetails ));
879+ Location, BF, * Report.RequestedDetails ));
880880 Result.Diagnostics .emplace_back (Report.Issue , DetailedInfo);
881881 }
882882}
883883
884+ void FunctionAnalysis::handleSimpleReports (
885+ SmallVector<BriefReport<MCPhysReg>> &Reports) {
886+ // Before re-running the detailed analysis, process the reports which do not
887+ // need any additional details to be attached.
888+ for (auto &Report : Reports) {
889+ if (!Report.RequestedDetails )
890+ Result.Diagnostics .emplace_back (Report.Issue , nullptr );
891+ }
892+ llvm::erase_if (Reports, [](const auto &R) { return !R.RequestedDetails ; });
893+ }
894+
884895void FunctionAnalysis::run () {
885896 LLVM_DEBUG ({
886897 dbgs () << " Analyzing function " << BF.getPrintName ()
@@ -890,6 +901,7 @@ void FunctionAnalysis::run() {
890901
891902 SmallVector<BriefReport<MCPhysReg>> UnsafeUses;
892903 findUnsafeUses (UnsafeUses);
904+ handleSimpleReports (UnsafeUses);
893905 if (!UnsafeUses.empty ())
894906 augmentUnsafeUseReports (UnsafeUses);
895907}
0 commit comments