@@ -88,8 +88,8 @@ class TrackedRegisters {
8888 TrackedRegisters (ArrayRef<MCPhysReg> RegsToTrack)
8989 : Registers(RegsToTrack),
9090 RegToIndexMapping (getMappingSize(RegsToTrack), NoIndex) {
91- for (unsigned I = 0 ; I < RegsToTrack. size (); ++I )
92- RegToIndexMapping[RegsToTrack[I]] = I ;
91+ for (auto [MappedIndex, Reg] : llvm::enumerate (RegsToTrack) )
92+ RegToIndexMapping[Reg] = MappedIndex ;
9393 }
9494
9595 ArrayRef<MCPhysReg> getRegisters () const { return Registers; }
@@ -203,9 +203,9 @@ struct SrcState {
203203
204204 SafeToDerefRegs &= StateIn.SafeToDerefRegs ;
205205 TrustedRegs &= StateIn.TrustedRegs ;
206- for (unsigned I = 0 ; I < LastInstWritingReg. size (); ++I)
207- for ( const MCInst *J : StateIn.LastInstWritingReg [I] )
208- LastInstWritingReg[I]. insert (J );
206+ for (auto [ThisSet, OtherSet] :
207+ llvm::zip_equal (LastInstWritingReg, StateIn.LastInstWritingReg ) )
208+ ThisSet. insert_range (OtherSet );
209209 return *this ;
210210 }
211211
@@ -224,11 +224,9 @@ struct SrcState {
224224static void printInstsShort (raw_ostream &OS,
225225 ArrayRef<SetOfRelatedInsts> Insts) {
226226 OS << " Insts: " ;
227- for (unsigned I = 0 ; I < Insts.size (); ++I) {
228- auto &Set = Insts[I];
227+ for (auto [I, PtrSet] : llvm::enumerate (Insts)) {
229228 OS << " [" << I << " ](" ;
230- for (const MCInst *MCInstP : Set)
231- OS << MCInstP << " " ;
229+ interleave (PtrSet, OS, " " );
232230 OS << " )" ;
233231 }
234232}
@@ -416,8 +414,9 @@ class SrcSafetyAnalysis {
416414 // ... an address can be updated in a safe manner, producing the result
417415 // which is as trusted as the input address.
418416 if (auto DstAndSrc = BC.MIB ->analyzeAddressArithmeticsForPtrAuth (Point)) {
419- if (Cur.SafeToDerefRegs [DstAndSrc->second ])
420- Regs.push_back (DstAndSrc->first );
417+ auto [DstReg, SrcReg] = *DstAndSrc;
418+ if (Cur.SafeToDerefRegs [SrcReg])
419+ Regs.push_back (DstReg);
421420 }
422421
423422 // Make sure explicit checker sequence keeps register safe-to-dereference
@@ -469,8 +468,9 @@ class SrcSafetyAnalysis {
469468 // ... an address can be updated in a safe manner, producing the result
470469 // which is as trusted as the input address.
471470 if (auto DstAndSrc = BC.MIB ->analyzeAddressArithmeticsForPtrAuth (Point)) {
472- if (Cur.TrustedRegs [DstAndSrc->second ])
473- Regs.push_back (DstAndSrc->first );
471+ auto [DstReg, SrcReg] = *DstAndSrc;
472+ if (Cur.TrustedRegs [SrcReg])
473+ Regs.push_back (DstReg);
474474 }
475475
476476 return Regs;
@@ -865,9 +865,9 @@ struct DstState {
865865 return (*this = StateIn);
866866
867867 CannotEscapeUnchecked &= StateIn.CannotEscapeUnchecked ;
868- for (unsigned I = 0 ; I < FirstInstLeakingReg. size (); ++I)
869- for ( const MCInst *J : StateIn.FirstInstLeakingReg [I] )
870- FirstInstLeakingReg[I]. insert (J );
868+ for (auto [ThisSet, OtherSet] :
869+ llvm::zip_equal (FirstInstLeakingReg, StateIn.FirstInstLeakingReg ) )
870+ ThisSet. insert_range (OtherSet );
871871 return *this ;
872872 }
873873
@@ -1033,8 +1033,7 @@ class DstSafetyAnalysis {
10331033
10341034 // ... an address can be updated in a safe manner, or
10351035 if (auto DstAndSrc = BC.MIB ->analyzeAddressArithmeticsForPtrAuth (Inst)) {
1036- MCPhysReg DstReg, SrcReg;
1037- std::tie (DstReg, SrcReg) = *DstAndSrc;
1036+ auto [DstReg, SrcReg] = *DstAndSrc;
10381037 // Note that *all* registers containing the derived values must be safe,
10391038 // both source and destination ones. No temporaries are supported at now.
10401039 if (Cur.CannotEscapeUnchecked [SrcReg] &&
@@ -1074,7 +1073,7 @@ class DstSafetyAnalysis {
10741073 // If this instruction terminates the program immediately, no
10751074 // authentication oracles are possible past this point.
10761075 if (BC.MIB ->isTrap (Point)) {
1077- LLVM_DEBUG ({ traceInst (BC, " Trap instruction found" , Point); } );
1076+ LLVM_DEBUG (traceInst (BC, " Trap instruction found" , Point));
10781077 DstState Next (NumRegs, RegsToTrackInstsFor.getNumTrackedRegisters ());
10791078 Next.CannotEscapeUnchecked .set ();
10801079 return Next;
@@ -1249,7 +1248,7 @@ class CFGUnawareDstSafetyAnalysis : public DstSafetyAnalysis,
12491248 // starting to analyze Inst.
12501249 if (BC.MIB ->isCall (Inst) || BC.MIB ->isBranch (Inst) ||
12511250 BC.MIB ->isReturn (Inst)) {
1252- LLVM_DEBUG ({ traceInst (BC, " Control flow instruction" , Inst); } );
1251+ LLVM_DEBUG (traceInst (BC, " Control flow instruction" , Inst));
12531252 S = createUnsafeState ();
12541253 }
12551254
@@ -1394,7 +1393,7 @@ shouldReportUnsafeTailCall(const BinaryContext &BC, const BinaryFunction &BF,
13941393 // such libc, ignore tail calls performed by ELF entry function.
13951394 if (BC.StartFunctionAddress &&
13961395 *BC.StartFunctionAddress == Inst.getFunction ()->getAddress ()) {
1397- LLVM_DEBUG ({ dbgs () << " Skipping tail call in ELF entry function.\n " ; } );
1396+ LLVM_DEBUG (dbgs () << " Skipping tail call in ELF entry function.\n " );
13981397 return std::nullopt ;
13991398 }
14001399
@@ -1468,7 +1467,7 @@ shouldReportAuthOracle(const BinaryContext &BC, const MCInstReference &Inst,
14681467 });
14691468
14701469 if (S.empty ()) {
1471- LLVM_DEBUG ({ dbgs () << " DstState is empty!\n " ; } );
1470+ LLVM_DEBUG (dbgs () << " DstState is empty!\n " );
14721471 return make_generic_report (
14731472 Inst, " Warning: no state computed for an authentication instruction "
14741473 " (possibly unreachable)" );
@@ -1495,7 +1494,7 @@ collectRegsToTrack(ArrayRef<PartialReport<MCPhysReg>> Reports) {
14951494void FunctionAnalysisContext::findUnsafeUses (
14961495 SmallVector<PartialReport<MCPhysReg>> &Reports) {
14971496 auto Analysis = SrcSafetyAnalysis::create (BF, AllocatorId, {});
1498- LLVM_DEBUG ({ dbgs () << " Running src register safety analysis...\n " ; } );
1497+ LLVM_DEBUG (dbgs () << " Running src register safety analysis...\n " );
14991498 Analysis->run ();
15001499 LLVM_DEBUG ({
15011500 dbgs () << " After src register safety analysis:\n " ;
@@ -1552,8 +1551,7 @@ void FunctionAnalysisContext::findUnsafeUses(
15521551
15531552 const SrcState &S = Analysis->getStateBefore (Inst);
15541553 if (S.empty ()) {
1555- LLVM_DEBUG (
1556- { traceInst (BC, " Instruction has no state, skipping" , Inst); });
1554+ LLVM_DEBUG (traceInst (BC, " Instruction has no state, skipping" , Inst));
15571555 assert (UnreachableBBReported && " Should be reported at least once" );
15581556 (void )UnreachableBBReported;
15591557 return ;
@@ -1580,8 +1578,7 @@ void FunctionAnalysisContext::augmentUnsafeUseReports(
15801578 SmallVector<MCPhysReg> RegsToTrack = collectRegsToTrack (Reports);
15811579 // Re-compute the analysis with register tracking.
15821580 auto Analysis = SrcSafetyAnalysis::create (BF, AllocatorId, RegsToTrack);
1583- LLVM_DEBUG (
1584- { dbgs () << " \n Running detailed src register safety analysis...\n " ; });
1581+ LLVM_DEBUG (dbgs () << " \n Running detailed src register safety analysis...\n " );
15851582 Analysis->run ();
15861583 LLVM_DEBUG ({
15871584 dbgs () << " After detailed src register safety analysis:\n " ;
@@ -1591,7 +1588,7 @@ void FunctionAnalysisContext::augmentUnsafeUseReports(
15911588 // Augment gadget reports.
15921589 for (auto &Report : Reports) {
15931590 MCInstReference Location = Report.Issue ->Location ;
1594- LLVM_DEBUG ({ traceInst (BC, " Attaching clobbering info to" , Location); } );
1591+ LLVM_DEBUG (traceInst (BC, " Attaching clobbering info to" , Location));
15951592 assert (Report.RequestedDetails &&
15961593 " Should be removed by handleSimpleReports" );
15971594 auto DetailedInfo =
@@ -1609,7 +1606,7 @@ void FunctionAnalysisContext::findUnsafeDefs(
16091606 return ;
16101607
16111608 auto Analysis = DstSafetyAnalysis::create (BF, AllocatorId, {});
1612- LLVM_DEBUG ({ dbgs () << " Running dst register safety analysis...\n " ; } );
1609+ LLVM_DEBUG (dbgs () << " Running dst register safety analysis...\n " );
16131610 Analysis->run ();
16141611 LLVM_DEBUG ({
16151612 dbgs () << " After dst register safety analysis:\n " ;
@@ -1632,8 +1629,7 @@ void FunctionAnalysisContext::augmentUnsafeDefReports(
16321629 SmallVector<MCPhysReg> RegsToTrack = collectRegsToTrack (Reports);
16331630 // Re-compute the analysis with register tracking.
16341631 auto Analysis = DstSafetyAnalysis::create (BF, AllocatorId, RegsToTrack);
1635- LLVM_DEBUG (
1636- { dbgs () << " \n Running detailed dst register safety analysis...\n " ; });
1632+ LLVM_DEBUG (dbgs () << " \n Running detailed dst register safety analysis...\n " );
16371633 Analysis->run ();
16381634 LLVM_DEBUG ({
16391635 dbgs () << " After detailed dst register safety analysis:\n " ;
@@ -1643,7 +1639,7 @@ void FunctionAnalysisContext::augmentUnsafeDefReports(
16431639 // Augment gadget reports.
16441640 for (auto &Report : Reports) {
16451641 MCInstReference Location = Report.Issue ->Location ;
1646- LLVM_DEBUG ({ traceInst (BC, " Attaching leakage info to" , Location); } );
1642+ LLVM_DEBUG (traceInst (BC, " Attaching leakage info to" , Location));
16471643 assert (Report.RequestedDetails &&
16481644 " Should be removed by handleSimpleReports" );
16491645 auto DetailedInfo = std::make_shared<LeakageInfo>(
0 commit comments