@@ -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
@@ -1393,12 +1392,12 @@ shouldReportUnsafeTailCall(const BinaryContext &BC, const BinaryFunction &BF,
1393
1392
// such libc, ignore tail calls performed by ELF entry function.
1394
1393
if (BC.StartFunctionAddress &&
1395
1394
*BC.StartFunctionAddress == Inst.getFunction ()->getAddress ()) {
1396
- LLVM_DEBUG ({ dbgs () << " Skipping tail call in ELF entry function.\n " ; } );
1395
+ LLVM_DEBUG (dbgs () << " Skipping tail call in ELF entry function.\n " );
1397
1396
return std::nullopt;
1398
1397
}
1399
1398
1400
1399
if (BC.MIB ->isSafeJumpTableBranchForPtrAuth (Inst)) {
1401
- LLVM_DEBUG ({ dbgs () << " Safe jump table detected, skipping.\n " ; } );
1400
+ LLVM_DEBUG (dbgs () << " Safe jump table detected, skipping.\n " );
1402
1401
return std::nullopt;
1403
1402
}
1404
1403
@@ -1433,7 +1432,7 @@ shouldReportCallGadget(const BinaryContext &BC, const MCInstReference &Inst,
1433
1432
return std::nullopt;
1434
1433
1435
1434
if (BC.MIB ->isSafeJumpTableBranchForPtrAuth (Inst)) {
1436
- LLVM_DEBUG ({ dbgs () << " Safe jump table detected, skipping.\n " ; } );
1435
+ LLVM_DEBUG (dbgs () << " Safe jump table detected, skipping.\n " );
1437
1436
return std::nullopt;
1438
1437
}
1439
1438
@@ -1477,7 +1476,7 @@ shouldReportAuthOracle(const BinaryContext &BC, const MCInstReference &Inst,
1477
1476
});
1478
1477
1479
1478
if (S.empty ()) {
1480
- LLVM_DEBUG ({ dbgs () << " DstState is empty!\n " ; } );
1479
+ LLVM_DEBUG (dbgs () << " DstState is empty!\n " );
1481
1480
return make_generic_report (
1482
1481
Inst, " Warning: no state computed for an authentication instruction "
1483
1482
" (possibly unreachable)" );
@@ -1504,7 +1503,7 @@ collectRegsToTrack(ArrayRef<PartialReport<MCPhysReg>> Reports) {
1504
1503
void FunctionAnalysisContext::findUnsafeUses (
1505
1504
SmallVector<PartialReport<MCPhysReg>> &Reports) {
1506
1505
auto Analysis = SrcSafetyAnalysis::create (BF, AllocatorId, {});
1507
- LLVM_DEBUG ({ dbgs () << " Running src register safety analysis...\n " ; } );
1506
+ LLVM_DEBUG (dbgs () << " Running src register safety analysis...\n " );
1508
1507
Analysis->run ();
1509
1508
LLVM_DEBUG ({
1510
1509
dbgs () << " After src register safety analysis:\n " ;
@@ -1561,8 +1560,7 @@ void FunctionAnalysisContext::findUnsafeUses(
1561
1560
1562
1561
const SrcState &S = Analysis->getStateBefore (Inst);
1563
1562
if (S.empty ()) {
1564
- LLVM_DEBUG (
1565
- { traceInst (BC, " Instruction has no state, skipping" , Inst); });
1563
+ LLVM_DEBUG (traceInst (BC, " Instruction has no state, skipping" , Inst));
1566
1564
assert (UnreachableBBReported && " Should be reported at least once" );
1567
1565
(void )UnreachableBBReported;
1568
1566
return ;
@@ -1589,8 +1587,7 @@ void FunctionAnalysisContext::augmentUnsafeUseReports(
1589
1587
SmallVector<MCPhysReg> RegsToTrack = collectRegsToTrack (Reports);
1590
1588
// Re-compute the analysis with register tracking.
1591
1589
auto Analysis = SrcSafetyAnalysis::create (BF, AllocatorId, RegsToTrack);
1592
- LLVM_DEBUG (
1593
- { dbgs () << " \n Running detailed src register safety analysis...\n " ; });
1590
+ LLVM_DEBUG (dbgs () << " \n Running detailed src register safety analysis...\n " );
1594
1591
Analysis->run ();
1595
1592
LLVM_DEBUG ({
1596
1593
dbgs () << " After detailed src register safety analysis:\n " ;
@@ -1600,7 +1597,7 @@ void FunctionAnalysisContext::augmentUnsafeUseReports(
1600
1597
// Augment gadget reports.
1601
1598
for (auto &Report : Reports) {
1602
1599
MCInstReference Location = Report.Issue ->Location ;
1603
- LLVM_DEBUG ({ traceInst (BC, " Attaching clobbering info to" , Location); } );
1600
+ LLVM_DEBUG (traceInst (BC, " Attaching clobbering info to" , Location));
1604
1601
assert (Report.RequestedDetails &&
1605
1602
" Should be removed by handleSimpleReports" );
1606
1603
auto DetailedInfo =
@@ -1618,7 +1615,7 @@ void FunctionAnalysisContext::findUnsafeDefs(
1618
1615
return ;
1619
1616
1620
1617
auto Analysis = DstSafetyAnalysis::create (BF, AllocatorId, {});
1621
- LLVM_DEBUG ({ dbgs () << " Running dst register safety analysis...\n " ; } );
1618
+ LLVM_DEBUG (dbgs () << " Running dst register safety analysis...\n " );
1622
1619
Analysis->run ();
1623
1620
LLVM_DEBUG ({
1624
1621
dbgs () << " After dst register safety analysis:\n " ;
@@ -1641,8 +1638,7 @@ void FunctionAnalysisContext::augmentUnsafeDefReports(
1641
1638
SmallVector<MCPhysReg> RegsToTrack = collectRegsToTrack (Reports);
1642
1639
// Re-compute the analysis with register tracking.
1643
1640
auto Analysis = DstSafetyAnalysis::create (BF, AllocatorId, RegsToTrack);
1644
- LLVM_DEBUG (
1645
- { dbgs () << " \n Running detailed dst register safety analysis...\n " ; });
1641
+ LLVM_DEBUG (dbgs () << " \n Running detailed dst register safety analysis...\n " );
1646
1642
Analysis->run ();
1647
1643
LLVM_DEBUG ({
1648
1644
dbgs () << " After detailed dst register safety analysis:\n " ;
@@ -1652,7 +1648,7 @@ void FunctionAnalysisContext::augmentUnsafeDefReports(
1652
1648
// Augment gadget reports.
1653
1649
for (auto &Report : Reports) {
1654
1650
MCInstReference Location = Report.Issue ->Location ;
1655
- LLVM_DEBUG ({ traceInst (BC, " Attaching leakage info to" , Location); } );
1651
+ LLVM_DEBUG (traceInst (BC, " Attaching leakage info to" , Location));
1656
1652
assert (Report.RequestedDetails &&
1657
1653
" Should be removed by handleSimpleReports" );
1658
1654
auto DetailedInfo = std::make_shared<LeakageInfo>(
@@ -1785,8 +1781,7 @@ static void printRelatedInstrs(raw_ostream &OS, const MCInstReference Location,
1785
1781
// Sort the references to make output deterministic.
1786
1782
SmallVector<MCInstReference> RI (RelatedInstrs);
1787
1783
llvm::sort (RI);
1788
- for (unsigned I = 0 ; I < RI.size (); ++I) {
1789
- MCInstReference InstRef = RI[I];
1784
+ for (auto [I, InstRef] : llvm::enumerate (RI)) {
1790
1785
OS << " " << (I + 1 ) << " . " ;
1791
1786
BC.printInstruction (OS, InstRef, getAddress (InstRef), &BF);
1792
1787
};
0 commit comments