@@ -88,8 +88,8 @@ class TrackedRegisters {
88
88
TrackedRegisters (ArrayRef<MCPhysReg> RegsToTrack)
89
89
: Registers(RegsToTrack),
90
90
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 ;
93
93
}
94
94
95
95
ArrayRef<MCPhysReg> getRegisters () const { return Registers; }
@@ -203,9 +203,9 @@ struct SrcState {
203
203
204
204
SafeToDerefRegs &= StateIn.SafeToDerefRegs ;
205
205
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 );
209
209
return *this ;
210
210
}
211
211
@@ -224,11 +224,9 @@ struct SrcState {
224
224
static void printInstsShort (raw_ostream &OS,
225
225
ArrayRef<SetOfRelatedInsts> Insts) {
226
226
OS << " Insts: " ;
227
- for (unsigned I = 0 ; I < Insts.size (); ++I) {
228
- auto &Set = Insts[I];
227
+ for (auto [I, PtrSet] : llvm::enumerate (Insts)) {
229
228
OS << " [" << I << " ](" ;
230
- for (const MCInst *MCInstP : Set)
231
- OS << MCInstP << " " ;
229
+ interleave (PtrSet, OS, " " );
232
230
OS << " )" ;
233
231
}
234
232
}
@@ -416,8 +414,9 @@ class SrcSafetyAnalysis {
416
414
// ... an address can be updated in a safe manner, producing the result
417
415
// which is as trusted as the input address.
418
416
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);
421
420
}
422
421
423
422
// Make sure explicit checker sequence keeps register safe-to-dereference
@@ -469,8 +468,9 @@ class SrcSafetyAnalysis {
469
468
// ... an address can be updated in a safe manner, producing the result
470
469
// which is as trusted as the input address.
471
470
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);
474
474
}
475
475
476
476
return Regs;
@@ -868,9 +868,9 @@ struct DstState {
868
868
return (*this = StateIn);
869
869
870
870
CannotEscapeUnchecked &= StateIn.CannotEscapeUnchecked ;
871
- for (unsigned I = 0 ; I < FirstInstLeakingReg. size (); ++I)
872
- for ( const MCInst *J : StateIn.FirstInstLeakingReg [I] )
873
- FirstInstLeakingReg[I]. insert (J );
871
+ for (auto [ThisSet, OtherSet] :
872
+ llvm::zip_equal (FirstInstLeakingReg, StateIn.FirstInstLeakingReg ) )
873
+ ThisSet. insert_range (OtherSet );
874
874
return *this ;
875
875
}
876
876
@@ -1036,8 +1036,7 @@ class DstSafetyAnalysis {
1036
1036
1037
1037
// ... an address can be updated in a safe manner, or
1038
1038
if (auto DstAndSrc = BC.MIB ->analyzeAddressArithmeticsForPtrAuth (Inst)) {
1039
- MCPhysReg DstReg, SrcReg;
1040
- std::tie (DstReg, SrcReg) = *DstAndSrc;
1039
+ auto [DstReg, SrcReg] = *DstAndSrc;
1041
1040
// Note that *all* registers containing the derived values must be safe,
1042
1041
// both source and destination ones. No temporaries are supported at now.
1043
1042
if (Cur.CannotEscapeUnchecked [SrcReg] &&
@@ -1077,7 +1076,7 @@ class DstSafetyAnalysis {
1077
1076
// If this instruction terminates the program immediately, no
1078
1077
// authentication oracles are possible past this point.
1079
1078
if (BC.MIB ->isTrap (Point)) {
1080
- LLVM_DEBUG ({ traceInst (BC, " Trap instruction found" , Point); } );
1079
+ LLVM_DEBUG (traceInst (BC, " Trap instruction found" , Point));
1081
1080
DstState Next (NumRegs, RegsToTrackInstsFor.getNumTrackedRegisters ());
1082
1081
Next.CannotEscapeUnchecked .set ();
1083
1082
return Next;
@@ -1255,7 +1254,7 @@ class CFGUnawareDstSafetyAnalysis : public DstSafetyAnalysis,
1255
1254
// starting to analyze Inst.
1256
1255
if (BC.MIB ->isCall (Inst) || BC.MIB ->isBranch (Inst) ||
1257
1256
BC.MIB ->isReturn (Inst)) {
1258
- LLVM_DEBUG ({ traceInst (BC, " Control flow instruction" , Inst); } );
1257
+ LLVM_DEBUG (traceInst (BC, " Control flow instruction" , Inst));
1259
1258
S = createUnsafeState ();
1260
1259
}
1261
1260
@@ -1400,12 +1399,12 @@ shouldReportUnsafeTailCall(const BinaryContext &BC, const BinaryFunction &BF,
1400
1399
// such libc, ignore tail calls performed by ELF entry function.
1401
1400
if (BC.StartFunctionAddress &&
1402
1401
*BC.StartFunctionAddress == Inst.getFunction ()->getAddress ()) {
1403
- LLVM_DEBUG ({ dbgs () << " Skipping tail call in ELF entry function.\n " ; } );
1402
+ LLVM_DEBUG (dbgs () << " Skipping tail call in ELF entry function.\n " );
1404
1403
return std::nullopt;
1405
1404
}
1406
1405
1407
1406
if (BC.MIB ->isSafeJumpTableBranchForPtrAuth (Inst)) {
1408
- LLVM_DEBUG ({ dbgs () << " Safe jump table detected, skipping.\n " ; } );
1407
+ LLVM_DEBUG (dbgs () << " Safe jump table detected, skipping.\n " );
1409
1408
return std::nullopt;
1410
1409
}
1411
1410
@@ -1440,7 +1439,7 @@ shouldReportCallGadget(const BinaryContext &BC, const MCInstReference &Inst,
1440
1439
return std::nullopt;
1441
1440
1442
1441
if (BC.MIB ->isSafeJumpTableBranchForPtrAuth (Inst)) {
1443
- LLVM_DEBUG ({ dbgs () << " Safe jump table detected, skipping.\n " ; } );
1442
+ LLVM_DEBUG (dbgs () << " Safe jump table detected, skipping.\n " );
1444
1443
return std::nullopt;
1445
1444
}
1446
1445
@@ -1484,7 +1483,7 @@ shouldReportAuthOracle(const BinaryContext &BC, const MCInstReference &Inst,
1484
1483
});
1485
1484
1486
1485
if (S.empty ()) {
1487
- LLVM_DEBUG ({ dbgs () << " DstState is empty!\n " ; } );
1486
+ LLVM_DEBUG (dbgs () << " DstState is empty!\n " );
1488
1487
return make_generic_report (
1489
1488
Inst, " Warning: no state computed for an authentication instruction "
1490
1489
" (possibly unreachable)" );
@@ -1511,7 +1510,7 @@ collectRegsToTrack(ArrayRef<PartialReport<MCPhysReg>> Reports) {
1511
1510
void FunctionAnalysisContext::findUnsafeUses (
1512
1511
SmallVector<PartialReport<MCPhysReg>> &Reports) {
1513
1512
auto Analysis = SrcSafetyAnalysis::create (BF, AllocatorId, {});
1514
- LLVM_DEBUG ({ dbgs () << " Running src register safety analysis...\n " ; } );
1513
+ LLVM_DEBUG (dbgs () << " Running src register safety analysis...\n " );
1515
1514
Analysis->run ();
1516
1515
LLVM_DEBUG ({
1517
1516
dbgs () << " After src register safety analysis:\n " ;
@@ -1568,8 +1567,7 @@ void FunctionAnalysisContext::findUnsafeUses(
1568
1567
1569
1568
const SrcState &S = Analysis->getStateBefore (Inst);
1570
1569
if (S.empty ()) {
1571
- LLVM_DEBUG (
1572
- { traceInst (BC, " Instruction has no state, skipping" , Inst); });
1570
+ LLVM_DEBUG (traceInst (BC, " Instruction has no state, skipping" , Inst));
1573
1571
assert (UnreachableBBReported && " Should be reported at least once" );
1574
1572
(void )UnreachableBBReported;
1575
1573
return ;
@@ -1596,8 +1594,7 @@ void FunctionAnalysisContext::augmentUnsafeUseReports(
1596
1594
SmallVector<MCPhysReg> RegsToTrack = collectRegsToTrack (Reports);
1597
1595
// Re-compute the analysis with register tracking.
1598
1596
auto Analysis = SrcSafetyAnalysis::create (BF, AllocatorId, RegsToTrack);
1599
- LLVM_DEBUG (
1600
- { dbgs () << " \n Running detailed src register safety analysis...\n " ; });
1597
+ LLVM_DEBUG (dbgs () << " \n Running detailed src register safety analysis...\n " );
1601
1598
Analysis->run ();
1602
1599
LLVM_DEBUG ({
1603
1600
dbgs () << " After detailed src register safety analysis:\n " ;
@@ -1607,7 +1604,7 @@ void FunctionAnalysisContext::augmentUnsafeUseReports(
1607
1604
// Augment gadget reports.
1608
1605
for (auto &Report : Reports) {
1609
1606
MCInstReference Location = Report.Issue ->Location ;
1610
- LLVM_DEBUG ({ traceInst (BC, " Attaching clobbering info to" , Location); } );
1607
+ LLVM_DEBUG (traceInst (BC, " Attaching clobbering info to" , Location));
1611
1608
assert (Report.RequestedDetails &&
1612
1609
" Should be removed by handleSimpleReports" );
1613
1610
auto DetailedInfo =
@@ -1625,7 +1622,7 @@ void FunctionAnalysisContext::findUnsafeDefs(
1625
1622
return ;
1626
1623
1627
1624
auto Analysis = DstSafetyAnalysis::create (BF, AllocatorId, {});
1628
- LLVM_DEBUG ({ dbgs () << " Running dst register safety analysis...\n " ; } );
1625
+ LLVM_DEBUG (dbgs () << " Running dst register safety analysis...\n " );
1629
1626
Analysis->run ();
1630
1627
LLVM_DEBUG ({
1631
1628
dbgs () << " After dst register safety analysis:\n " ;
@@ -1648,8 +1645,7 @@ void FunctionAnalysisContext::augmentUnsafeDefReports(
1648
1645
SmallVector<MCPhysReg> RegsToTrack = collectRegsToTrack (Reports);
1649
1646
// Re-compute the analysis with register tracking.
1650
1647
auto Analysis = DstSafetyAnalysis::create (BF, AllocatorId, RegsToTrack);
1651
- LLVM_DEBUG (
1652
- { dbgs () << " \n Running detailed dst register safety analysis...\n " ; });
1648
+ LLVM_DEBUG (dbgs () << " \n Running detailed dst register safety analysis...\n " );
1653
1649
Analysis->run ();
1654
1650
LLVM_DEBUG ({
1655
1651
dbgs () << " After detailed dst register safety analysis:\n " ;
@@ -1659,7 +1655,7 @@ void FunctionAnalysisContext::augmentUnsafeDefReports(
1659
1655
// Augment gadget reports.
1660
1656
for (auto &Report : Reports) {
1661
1657
MCInstReference Location = Report.Issue ->Location ;
1662
- LLVM_DEBUG ({ traceInst (BC, " Attaching leakage info to" , Location); } );
1658
+ LLVM_DEBUG (traceInst (BC, " Attaching leakage info to" , Location));
1663
1659
assert (Report.RequestedDetails &&
1664
1660
" Should be removed by handleSimpleReports" );
1665
1661
auto DetailedInfo = std::make_shared<LeakageInfo>(
@@ -1792,8 +1788,7 @@ static void printRelatedInstrs(raw_ostream &OS, const MCInstReference Location,
1792
1788
// Sort the references to make output deterministic.
1793
1789
SmallVector<MCInstReference> RI (RelatedInstrs);
1794
1790
llvm::sort (RI);
1795
- for (unsigned I = 0 ; I < RI.size (); ++I) {
1796
- MCInstReference InstRef = RI[I];
1791
+ for (auto [I, InstRef] : llvm::enumerate (RI)) {
1797
1792
OS << " " << (I + 1 ) << " . " ;
1798
1793
BC.printInstruction (OS, InstRef, getAddress (InstRef), &BF);
1799
1794
};
0 commit comments