@@ -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;
@@ -858,9 +858,9 @@ struct DstState {
858
858
return (*this = StateIn);
859
859
860
860
CannotEscapeUnchecked &= StateIn.CannotEscapeUnchecked ;
861
- for (unsigned I = 0 ; I < FirstInstLeakingReg. size (); ++I)
862
- for ( const MCInst *J : StateIn.FirstInstLeakingReg [I] )
863
- FirstInstLeakingReg[I]. insert (J );
861
+ for (auto [ThisSet, OtherSet] :
862
+ llvm::zip_equal (FirstInstLeakingReg, StateIn.FirstInstLeakingReg ) )
863
+ ThisSet. insert_range (OtherSet );
864
864
return *this ;
865
865
}
866
866
@@ -1025,8 +1025,7 @@ class DstSafetyAnalysis {
1025
1025
1026
1026
// ... an address can be updated in a safe manner, or
1027
1027
if (auto DstAndSrc = BC.MIB ->analyzeAddressArithmeticsForPtrAuth (Inst)) {
1028
- MCPhysReg DstReg, SrcReg;
1029
- std::tie (DstReg, SrcReg) = *DstAndSrc;
1028
+ auto [DstReg, SrcReg] = *DstAndSrc;
1030
1029
// Note that *all* registers containing the derived values must be safe,
1031
1030
// both source and destination ones. No temporaries are supported at now.
1032
1031
if (Cur.CannotEscapeUnchecked [SrcReg] &&
@@ -1065,7 +1064,7 @@ class DstSafetyAnalysis {
1065
1064
// If this instruction terminates the program immediately, no
1066
1065
// authentication oracles are possible past this point.
1067
1066
if (BC.MIB ->isTrap (Point )) {
1068
- LLVM_DEBUG ({ traceInst (BC, " Trap instruction found" , Point ); } );
1067
+ LLVM_DEBUG (traceInst (BC, " Trap instruction found" , Point ));
1069
1068
DstState Next (NumRegs, RegsToTrackInstsFor.getNumTrackedRegisters ());
1070
1069
Next.CannotEscapeUnchecked .set ();
1071
1070
return Next;
@@ -1243,7 +1242,7 @@ class CFGUnawareDstSafetyAnalysis : public DstSafetyAnalysis,
1243
1242
// starting to analyze Inst.
1244
1243
if (BC.MIB ->isCall (Inst) || BC.MIB ->isBranch (Inst) ||
1245
1244
BC.MIB ->isReturn (Inst)) {
1246
- LLVM_DEBUG ({ traceInst (BC, " Control flow instruction" , Inst); } );
1245
+ LLVM_DEBUG (traceInst (BC, " Control flow instruction" , Inst));
1247
1246
S = createUnsafeState ();
1248
1247
}
1249
1248
@@ -1381,12 +1380,12 @@ shouldReportUnsafeTailCall(const BinaryContext &BC, const BinaryFunction &BF,
1381
1380
// such libc, ignore tail calls performed by ELF entry function.
1382
1381
if (BC.StartFunctionAddress &&
1383
1382
*BC.StartFunctionAddress == Inst.getFunction ()->getAddress ()) {
1384
- LLVM_DEBUG ({ dbgs () << " Skipping tail call in ELF entry function.\n " ; } );
1383
+ LLVM_DEBUG (dbgs () << " Skipping tail call in ELF entry function.\n " );
1385
1384
return std::nullopt;
1386
1385
}
1387
1386
1388
1387
if (BC.MIB ->isSafeJumpTableBranchForPtrAuth (Inst)) {
1389
- LLVM_DEBUG ({ dbgs () << " Safe jump table detected, skipping.\n " ; } );
1388
+ LLVM_DEBUG (dbgs () << " Safe jump table detected, skipping.\n " );
1390
1389
return std::nullopt;
1391
1390
}
1392
1391
@@ -1421,7 +1420,7 @@ shouldReportCallGadget(const BinaryContext &BC, const MCInstReference &Inst,
1421
1420
return std::nullopt;
1422
1421
1423
1422
if (BC.MIB ->isSafeJumpTableBranchForPtrAuth (Inst)) {
1424
- LLVM_DEBUG ({ dbgs () << " Safe jump table detected, skipping.\n " ; } );
1423
+ LLVM_DEBUG (dbgs () << " Safe jump table detected, skipping.\n " );
1425
1424
return std::nullopt;
1426
1425
}
1427
1426
@@ -1466,7 +1465,7 @@ shouldReportAuthOracle(const BinaryContext &BC, const MCInstReference &Inst,
1466
1465
});
1467
1466
1468
1467
if (S.empty ()) {
1469
- LLVM_DEBUG ({ dbgs () << " DstState is empty!\n " ; } );
1468
+ LLVM_DEBUG (dbgs () << " DstState is empty!\n " );
1470
1469
return make_generic_report (
1471
1470
Inst, " Warning: no state computed for an authentication instruction "
1472
1471
" (possibly unreachable)" );
@@ -1493,7 +1492,7 @@ collectRegsToTrack(ArrayRef<PartialReport<MCPhysReg>> Reports) {
1493
1492
void FunctionAnalysisContext::findUnsafeUses (
1494
1493
SmallVector<PartialReport<MCPhysReg>> &Reports) {
1495
1494
auto Analysis = SrcSafetyAnalysis::create (BF, AllocatorId, {});
1496
- LLVM_DEBUG ({ dbgs () << " Running src register safety analysis...\n " ; } );
1495
+ LLVM_DEBUG (dbgs () << " Running src register safety analysis...\n " );
1497
1496
Analysis->run ();
1498
1497
LLVM_DEBUG ({
1499
1498
dbgs () << " After src register safety analysis:\n " ;
@@ -1545,8 +1544,7 @@ void FunctionAnalysisContext::findUnsafeUses(
1545
1544
1546
1545
const SrcState &S = Analysis->getStateBefore (Inst);
1547
1546
if (S.empty ()) {
1548
- LLVM_DEBUG (
1549
- { traceInst (BC, " Instruction has no state, skipping" , Inst); });
1547
+ LLVM_DEBUG (traceInst (BC, " Instruction has no state, skipping" , Inst));
1550
1548
assert (UnreachableBBReported && " Should be reported at least once" );
1551
1549
(void )UnreachableBBReported;
1552
1550
return ;
@@ -1573,8 +1571,7 @@ void FunctionAnalysisContext::augmentUnsafeUseReports(
1573
1571
SmallVector<MCPhysReg> RegsToTrack = collectRegsToTrack (Reports);
1574
1572
// Re-compute the analysis with register tracking.
1575
1573
auto Analysis = SrcSafetyAnalysis::create (BF, AllocatorId, RegsToTrack);
1576
- LLVM_DEBUG (
1577
- { dbgs () << " \n Running detailed src register safety analysis...\n " ; });
1574
+ LLVM_DEBUG (dbgs () << " \n Running detailed src register safety analysis...\n " );
1578
1575
Analysis->run ();
1579
1576
LLVM_DEBUG ({
1580
1577
dbgs () << " After detailed src register safety analysis:\n " ;
@@ -1584,7 +1581,7 @@ void FunctionAnalysisContext::augmentUnsafeUseReports(
1584
1581
// Augment gadget reports.
1585
1582
for (auto &Report : Reports) {
1586
1583
MCInstReference Location = Report.Issue ->Location ;
1587
- LLVM_DEBUG ({ traceInst (BC, " Attaching clobbering info to" , Location); } );
1584
+ LLVM_DEBUG (traceInst (BC, " Attaching clobbering info to" , Location));
1588
1585
assert (Report.RequestedDetails &&
1589
1586
" Should be removed by handleSimpleReports" );
1590
1587
auto DetailedInfo =
@@ -1602,7 +1599,7 @@ void FunctionAnalysisContext::findUnsafeDefs(
1602
1599
return ;
1603
1600
1604
1601
auto Analysis = DstSafetyAnalysis::create (BF, AllocatorId, {});
1605
- LLVM_DEBUG ({ dbgs () << " Running dst register safety analysis...\n " ; } );
1602
+ LLVM_DEBUG (dbgs () << " Running dst register safety analysis...\n " );
1606
1603
Analysis->run ();
1607
1604
LLVM_DEBUG ({
1608
1605
dbgs () << " After dst register safety analysis:\n " ;
@@ -1625,8 +1622,7 @@ void FunctionAnalysisContext::augmentUnsafeDefReports(
1625
1622
SmallVector<MCPhysReg> RegsToTrack = collectRegsToTrack (Reports);
1626
1623
// Re-compute the analysis with register tracking.
1627
1624
auto Analysis = DstSafetyAnalysis::create (BF, AllocatorId, RegsToTrack);
1628
- LLVM_DEBUG (
1629
- { dbgs () << " \n Running detailed dst register safety analysis...\n " ; });
1625
+ LLVM_DEBUG (dbgs () << " \n Running detailed dst register safety analysis...\n " );
1630
1626
Analysis->run ();
1631
1627
LLVM_DEBUG ({
1632
1628
dbgs () << " After detailed dst register safety analysis:\n " ;
@@ -1636,7 +1632,7 @@ void FunctionAnalysisContext::augmentUnsafeDefReports(
1636
1632
// Augment gadget reports.
1637
1633
for (auto &Report : Reports) {
1638
1634
MCInstReference Location = Report.Issue ->Location ;
1639
- LLVM_DEBUG ({ traceInst (BC, " Attaching leakage info to" , Location); } );
1635
+ LLVM_DEBUG (traceInst (BC, " Attaching leakage info to" , Location));
1640
1636
assert (Report.RequestedDetails &&
1641
1637
" Should be removed by handleSimpleReports" );
1642
1638
auto DetailedInfo = std::make_shared<LeakageInfo>(
@@ -1769,8 +1765,7 @@ static void printRelatedInstrs(raw_ostream &OS, const MCInstReference Location,
1769
1765
// Sort the references to make output deterministic.
1770
1766
SmallVector<MCInstReference> RI (RelatedInstrs);
1771
1767
llvm::sort (RI);
1772
- for (unsigned I = 0 ; I < RI.size (); ++I) {
1773
- MCInstReference InstRef = RI[I];
1768
+ for (auto [I, InstRef] : llvm::enumerate (RI)) {
1774
1769
OS << " " << (I + 1 ) << " . " ;
1775
1770
BC.printInstruction (OS, InstRef, getAddress (InstRef), &BF);
1776
1771
};
0 commit comments