@@ -518,13 +518,11 @@ class SrcSafetyAnalysis {
518
518
public:
519
519
std::vector<MCInstReference>
520
520
getLastClobberingInsts (const MCInst &Inst, BinaryFunction &BF,
521
- std::optional<MCPhysReg> ClobberedReg) const {
522
- if (!ClobberedReg || RegsToTrackInstsFor.empty ())
523
- return {};
521
+ MCPhysReg ClobberedReg) const {
524
522
const SrcState &S = getStateBefore (Inst);
525
523
526
524
std::vector<MCInstReference> Result;
527
- for (const MCInst *Inst : lastWritingInsts (S, * ClobberedReg)) {
525
+ for (const MCInst *Inst : lastWritingInsts (S, ClobberedReg)) {
528
526
MCInstReference Ref = MCInstReference::get (Inst, BF);
529
527
assert (Ref && " Expected Inst to be found" );
530
528
Result.push_back (Ref);
@@ -868,16 +866,29 @@ void FunctionAnalysis::augmentUnsafeUseReports(
868
866
});
869
867
870
868
// Augment gadget reports.
871
- for (auto Report : Reports) {
869
+ for (auto & Report : Reports) {
872
870
MCInstReference Location = Report.Issue ->Location ;
873
871
LLVM_DEBUG ({ traceInst (BC, " Attaching clobbering info to" , Location); });
872
+ assert (Report.RequestedDetails &&
873
+ " Should be removed by handleSimpleReports" );
874
874
auto DetailedInfo =
875
875
std::make_shared<ClobberingInfo>(Analysis->getLastClobberingInsts (
876
- Location, BF, Report.RequestedDetails ));
876
+ Location, BF, * Report.RequestedDetails ));
877
877
Result.Diagnostics .emplace_back (Report.Issue , DetailedInfo);
878
878
}
879
879
}
880
880
881
+ void FunctionAnalysis::handleSimpleReports (
882
+ SmallVector<BriefReport<MCPhysReg>> &Reports) {
883
+ // Before re-running the detailed analysis, process the reports which do not
884
+ // need any additional details to be attached.
885
+ for (auto &Report : Reports) {
886
+ if (!Report.RequestedDetails )
887
+ Result.Diagnostics .emplace_back (Report.Issue , nullptr );
888
+ }
889
+ llvm::erase_if (Reports, [](const auto &R) { return !R.RequestedDetails ; });
890
+ }
891
+
881
892
void FunctionAnalysis::run () {
882
893
LLVM_DEBUG ({
883
894
dbgs () << " Analyzing function " << BF.getPrintName ()
@@ -887,6 +898,7 @@ void FunctionAnalysis::run() {
887
898
888
899
SmallVector<BriefReport<MCPhysReg>> UnsafeUses;
889
900
findUnsafeUses (UnsafeUses);
901
+ handleSimpleReports (UnsafeUses);
890
902
if (!UnsafeUses.empty ())
891
903
augmentUnsafeUseReports (UnsafeUses);
892
904
}
0 commit comments