@@ -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;
@@ -845,9 +845,9 @@ struct DstState {
845845 return (*this = StateIn);
846846
847847 CannotEscapeUnchecked &= StateIn.CannotEscapeUnchecked ;
848- for (unsigned I = 0 ; I < FirstInstLeakingReg. size (); ++I)
849- for ( const MCInst *J : StateIn.FirstInstLeakingReg [I] )
850- FirstInstLeakingReg[I]. insert (J );
848+ for (auto [ThisSet, OtherSet] :
849+ llvm::zip_equal (FirstInstLeakingReg, StateIn.FirstInstLeakingReg ) )
850+ ThisSet. insert_range (OtherSet );
851851 return *this ;
852852 }
853853
@@ -1012,8 +1012,7 @@ class DstSafetyAnalysis {
10121012
10131013 // ... an address can be updated in a safe manner, or
10141014 if (auto DstAndSrc = BC.MIB ->analyzeAddressArithmeticsForPtrAuth (Inst)) {
1015- MCPhysReg DstReg, SrcReg;
1016- std::tie (DstReg, SrcReg) = *DstAndSrc;
1015+ auto [DstReg, SrcReg] = *DstAndSrc;
10171016 // Note that *all* registers containing the derived values must be safe,
10181017 // both source and destination ones. No temporaries are supported at now.
10191018 if (Cur.CannotEscapeUnchecked [SrcReg] &&
@@ -1052,7 +1051,7 @@ class DstSafetyAnalysis {
10521051 // If this instruction terminates the program immediately, no
10531052 // authentication oracles are possible past this point.
10541053 if (BC.MIB ->isTrap (Point)) {
1055- LLVM_DEBUG ({ traceInst (BC, " Trap instruction found" , Point); } );
1054+ LLVM_DEBUG (traceInst (BC, " Trap instruction found" , Point));
10561055 DstState Next (NumRegs, RegsToTrackInstsFor.getNumTrackedRegisters ());
10571056 Next.CannotEscapeUnchecked .set ();
10581057 return Next;
@@ -1234,7 +1233,7 @@ class CFGUnawareDstSafetyAnalysis : public DstSafetyAnalysis,
12341233 // starting to analyze Inst.
12351234 if (BC.MIB ->isCall (Inst) || BC.MIB ->isBranch (Inst) ||
12361235 BC.MIB ->isReturn (Inst)) {
1237- LLVM_DEBUG ({ traceInst (BC, " Control flow instruction" , Inst); } );
1236+ LLVM_DEBUG (traceInst (BC, " Control flow instruction" , Inst));
12381237 S = createUnsafeState ();
12391238 }
12401239
@@ -1372,12 +1371,12 @@ shouldReportUnsafeTailCall(const BinaryContext &BC, const BinaryFunction &BF,
13721371 // such libc, ignore tail calls performed by ELF entry function.
13731372 if (BC.StartFunctionAddress &&
13741373 *BC.StartFunctionAddress == Inst.getFunction ()->getAddress ()) {
1375- LLVM_DEBUG ({ dbgs () << " Skipping tail call in ELF entry function.\n " ; } );
1374+ LLVM_DEBUG (dbgs () << " Skipping tail call in ELF entry function.\n " );
13761375 return std::nullopt ;
13771376 }
13781377
13791378 if (BC.MIB ->isSafeJumpTableBranchForPtrAuth (Inst)) {
1380- LLVM_DEBUG ({ dbgs () << " Safe jump table detected, skipping.\n " ; } );
1379+ LLVM_DEBUG (dbgs () << " Safe jump table detected, skipping.\n " );
13811380 return std::nullopt ;
13821381 }
13831382
@@ -1412,7 +1411,7 @@ shouldReportCallGadget(const BinaryContext &BC, const MCInstReference &Inst,
14121411 return std::nullopt ;
14131412
14141413 if (BC.MIB ->isSafeJumpTableBranchForPtrAuth (Inst)) {
1415- LLVM_DEBUG ({ dbgs () << " Safe jump table detected, skipping.\n " ; } );
1414+ LLVM_DEBUG (dbgs () << " Safe jump table detected, skipping.\n " );
14161415 return std::nullopt ;
14171416 }
14181417
@@ -1457,7 +1456,7 @@ shouldReportAuthOracle(const BinaryContext &BC, const MCInstReference &Inst,
14571456 });
14581457
14591458 if (S.empty ()) {
1460- LLVM_DEBUG ({ dbgs () << " DstState is empty!\n " ; } );
1459+ LLVM_DEBUG (dbgs () << " DstState is empty!\n " );
14611460 return make_generic_report (
14621461 Inst, " Warning: no state computed for an authentication instruction "
14631462 " (possibly unreachable)" );
@@ -1484,7 +1483,7 @@ collectRegsToTrack(ArrayRef<PartialReport<MCPhysReg>> Reports) {
14841483void FunctionAnalysisContext::findUnsafeUses (
14851484 SmallVector<PartialReport<MCPhysReg>> &Reports) {
14861485 auto Analysis = SrcSafetyAnalysis::create (BF, AllocatorId, {});
1487- LLVM_DEBUG ({ dbgs () << " Running src register safety analysis...\n " ; } );
1486+ LLVM_DEBUG (dbgs () << " Running src register safety analysis...\n " );
14881487 Analysis->run ();
14891488 LLVM_DEBUG ({
14901489 dbgs () << " After src register safety analysis:\n " ;
@@ -1536,8 +1535,7 @@ void FunctionAnalysisContext::findUnsafeUses(
15361535
15371536 const SrcState &S = Analysis->getStateBefore (Inst);
15381537 if (S.empty ()) {
1539- LLVM_DEBUG (
1540- { traceInst (BC, " Instruction has no state, skipping" , Inst); });
1538+ LLVM_DEBUG (traceInst (BC, " Instruction has no state, skipping" , Inst));
15411539 assert (UnreachableBBReported && " Should be reported at least once" );
15421540 (void )UnreachableBBReported;
15431541 return ;
@@ -1564,8 +1562,7 @@ void FunctionAnalysisContext::augmentUnsafeUseReports(
15641562 SmallVector<MCPhysReg> RegsToTrack = collectRegsToTrack (Reports);
15651563 // Re-compute the analysis with register tracking.
15661564 auto Analysis = SrcSafetyAnalysis::create (BF, AllocatorId, RegsToTrack);
1567- LLVM_DEBUG (
1568- { dbgs () << " \n Running detailed src register safety analysis...\n " ; });
1565+ LLVM_DEBUG (dbgs () << " \n Running detailed src register safety analysis...\n " );
15691566 Analysis->run ();
15701567 LLVM_DEBUG ({
15711568 dbgs () << " After detailed src register safety analysis:\n " ;
@@ -1575,7 +1572,7 @@ void FunctionAnalysisContext::augmentUnsafeUseReports(
15751572 // Augment gadget reports.
15761573 for (auto &Report : Reports) {
15771574 MCInstReference Location = Report.Issue ->Location ;
1578- LLVM_DEBUG ({ traceInst (BC, " Attaching clobbering info to" , Location); } );
1575+ LLVM_DEBUG (traceInst (BC, " Attaching clobbering info to" , Location));
15791576 assert (Report.RequestedDetails &&
15801577 " Should be removed by handleSimpleReports" );
15811578 auto DetailedInfo =
@@ -1593,7 +1590,7 @@ void FunctionAnalysisContext::findUnsafeDefs(
15931590 return ;
15941591
15951592 auto Analysis = DstSafetyAnalysis::create (BF, AllocatorId, {});
1596- LLVM_DEBUG ({ dbgs () << " Running dst register safety analysis...\n " ; } );
1593+ LLVM_DEBUG (dbgs () << " Running dst register safety analysis...\n " );
15971594 Analysis->run ();
15981595 LLVM_DEBUG ({
15991596 dbgs () << " After dst register safety analysis:\n " ;
@@ -1616,8 +1613,7 @@ void FunctionAnalysisContext::augmentUnsafeDefReports(
16161613 SmallVector<MCPhysReg> RegsToTrack = collectRegsToTrack (Reports);
16171614 // Re-compute the analysis with register tracking.
16181615 auto Analysis = DstSafetyAnalysis::create (BF, AllocatorId, RegsToTrack);
1619- LLVM_DEBUG (
1620- { dbgs () << " \n Running detailed dst register safety analysis...\n " ; });
1616+ LLVM_DEBUG (dbgs () << " \n Running detailed dst register safety analysis...\n " );
16211617 Analysis->run ();
16221618 LLVM_DEBUG ({
16231619 dbgs () << " After detailed dst register safety analysis:\n " ;
@@ -1627,7 +1623,7 @@ void FunctionAnalysisContext::augmentUnsafeDefReports(
16271623 // Augment gadget reports.
16281624 for (auto &Report : Reports) {
16291625 MCInstReference Location = Report.Issue ->Location ;
1630- LLVM_DEBUG ({ traceInst (BC, " Attaching leakage info to" , Location); } );
1626+ LLVM_DEBUG (traceInst (BC, " Attaching leakage info to" , Location));
16311627 assert (Report.RequestedDetails &&
16321628 " Should be removed by handleSimpleReports" );
16331629 auto DetailedInfo = std::make_shared<LeakageInfo>(
@@ -1760,8 +1756,7 @@ static void printRelatedInstrs(raw_ostream &OS, const MCInstReference Location,
17601756 // Sort the references to make output deterministic.
17611757 SmallVector<MCInstReference> RI (RelatedInstrs);
17621758 llvm::sort (RI);
1763- for (unsigned I = 0 ; I < RI.size (); ++I) {
1764- MCInstReference InstRef = RI[I];
1759+ for (auto [I, InstRef] : llvm::enumerate (RI)) {
17651760 OS << " " << (I + 1 ) << " . " ;
17661761 BC.printInstruction (OS, InstRef, getAddress (InstRef), &BF);
17671762 };
0 commit comments