@@ -517,13 +517,11 @@ class SrcSafetyAnalysis {
517
517
public:
518
518
std::vector<MCInstReference>
519
519
getLastClobberingInsts (const MCInst &Inst, BinaryFunction &BF,
520
- std::optional<MCPhysReg> ClobberedReg) const {
521
- if (!ClobberedReg || RegsToTrackInstsFor.empty ())
522
- return {};
520
+ MCPhysReg ClobberedReg) const {
523
521
const SrcState &S = getStateBefore (Inst);
524
522
525
523
std::vector<MCInstReference> Result;
526
- for (const MCInst *Inst : lastWritingInsts (S, * ClobberedReg)) {
524
+ for (const MCInst *Inst : lastWritingInsts (S, ClobberedReg)) {
527
525
MCInstReference Ref = MCInstReference::get (Inst, BF);
528
526
assert (Ref && " Expected Inst to be found" );
529
527
Result.push_back (Ref);
@@ -871,16 +869,29 @@ void FunctionAnalysis::augmentUnsafeUseReports(
871
869
});
872
870
873
871
// Augment gadget reports.
874
- for (auto Report : Reports) {
872
+ for (auto & Report : Reports) {
875
873
MCInstReference Location = Report.Issue ->Location ;
876
874
LLVM_DEBUG ({ traceInst (BC, " Attaching clobbering info to" , Location); });
875
+ assert (Report.RequestedDetails &&
876
+ " Should be removed by handleSimpleReports" );
877
877
auto DetailedInfo =
878
878
std::make_shared<ClobberingInfo>(Analysis->getLastClobberingInsts (
879
- Location, BF, Report.RequestedDetails ));
879
+ Location, BF, * Report.RequestedDetails ));
880
880
Result.Diagnostics .emplace_back (Report.Issue , DetailedInfo);
881
881
}
882
882
}
883
883
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
+
884
895
void FunctionAnalysis::run () {
885
896
LLVM_DEBUG ({
886
897
dbgs () << " Analyzing function " << BF.getPrintName ()
@@ -890,6 +901,7 @@ void FunctionAnalysis::run() {
890
901
891
902
SmallVector<BriefReport<MCPhysReg>> UnsafeUses;
892
903
findUnsafeUses (UnsafeUses);
904
+ handleSimpleReports (UnsafeUses);
893
905
if (!UnsafeUses.empty ())
894
906
augmentUnsafeUseReports (UnsafeUses);
895
907
}
0 commit comments