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