@@ -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;
@@ -845,9 +845,9 @@ struct DstState {
845
845
return (*this = StateIn);
846
846
847
847
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 );
851
851
return *this ;
852
852
}
853
853
@@ -1012,8 +1012,7 @@ class DstSafetyAnalysis {
1012
1012
1013
1013
// ... an address can be updated in a safe manner, or
1014
1014
if (auto DstAndSrc = BC.MIB ->analyzeAddressArithmeticsForPtrAuth (Inst)) {
1015
- MCPhysReg DstReg, SrcReg;
1016
- std::tie (DstReg, SrcReg) = *DstAndSrc;
1015
+ auto [DstReg, SrcReg] = *DstAndSrc;
1017
1016
// Note that *all* registers containing the derived values must be safe,
1018
1017
// both source and destination ones. No temporaries are supported at now.
1019
1018
if (Cur.CannotEscapeUnchecked [SrcReg] &&
@@ -1052,7 +1051,7 @@ class DstSafetyAnalysis {
1052
1051
// If this instruction terminates the program immediately, no
1053
1052
// authentication oracles are possible past this point.
1054
1053
if (BC.MIB ->isTrap (Point)) {
1055
- LLVM_DEBUG ({ traceInst (BC, " Trap instruction found" , Point); } );
1054
+ LLVM_DEBUG (traceInst (BC, " Trap instruction found" , Point));
1056
1055
DstState Next (NumRegs, RegsToTrackInstsFor.getNumTrackedRegisters ());
1057
1056
Next.CannotEscapeUnchecked .set ();
1058
1057
return Next;
@@ -1234,7 +1233,7 @@ class CFGUnawareDstSafetyAnalysis : public DstSafetyAnalysis,
1234
1233
// starting to analyze Inst.
1235
1234
if (BC.MIB ->isCall (Inst) || BC.MIB ->isBranch (Inst) ||
1236
1235
BC.MIB ->isReturn (Inst)) {
1237
- LLVM_DEBUG ({ traceInst (BC, " Control flow instruction" , Inst); } );
1236
+ LLVM_DEBUG (traceInst (BC, " Control flow instruction" , Inst));
1238
1237
S = createUnsafeState ();
1239
1238
}
1240
1239
@@ -1372,12 +1371,12 @@ shouldReportUnsafeTailCall(const BinaryContext &BC, const BinaryFunction &BF,
1372
1371
// such libc, ignore tail calls performed by ELF entry function.
1373
1372
if (BC.StartFunctionAddress &&
1374
1373
*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 " );
1376
1375
return std::nullopt;
1377
1376
}
1378
1377
1379
1378
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 " );
1381
1380
return std::nullopt;
1382
1381
}
1383
1382
@@ -1412,7 +1411,7 @@ shouldReportCallGadget(const BinaryContext &BC, const MCInstReference &Inst,
1412
1411
return std::nullopt;
1413
1412
1414
1413
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 " );
1416
1415
return std::nullopt;
1417
1416
}
1418
1417
@@ -1457,7 +1456,7 @@ shouldReportAuthOracle(const BinaryContext &BC, const MCInstReference &Inst,
1457
1456
});
1458
1457
1459
1458
if (S.empty ()) {
1460
- LLVM_DEBUG ({ dbgs () << " DstState is empty!\n " ; } );
1459
+ LLVM_DEBUG (dbgs () << " DstState is empty!\n " );
1461
1460
return make_generic_report (
1462
1461
Inst, " Warning: no state computed for an authentication instruction "
1463
1462
" (possibly unreachable)" );
@@ -1484,7 +1483,7 @@ collectRegsToTrack(ArrayRef<PartialReport<MCPhysReg>> Reports) {
1484
1483
void FunctionAnalysisContext::findUnsafeUses (
1485
1484
SmallVector<PartialReport<MCPhysReg>> &Reports) {
1486
1485
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 " );
1488
1487
Analysis->run ();
1489
1488
LLVM_DEBUG ({
1490
1489
dbgs () << " After src register safety analysis:\n " ;
@@ -1536,8 +1535,7 @@ void FunctionAnalysisContext::findUnsafeUses(
1536
1535
1537
1536
const SrcState &S = Analysis->getStateBefore (Inst);
1538
1537
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));
1541
1539
assert (UnreachableBBReported && " Should be reported at least once" );
1542
1540
(void )UnreachableBBReported;
1543
1541
return ;
@@ -1564,8 +1562,7 @@ void FunctionAnalysisContext::augmentUnsafeUseReports(
1564
1562
SmallVector<MCPhysReg> RegsToTrack = collectRegsToTrack (Reports);
1565
1563
// Re-compute the analysis with register tracking.
1566
1564
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 " );
1569
1566
Analysis->run ();
1570
1567
LLVM_DEBUG ({
1571
1568
dbgs () << " After detailed src register safety analysis:\n " ;
@@ -1575,7 +1572,7 @@ void FunctionAnalysisContext::augmentUnsafeUseReports(
1575
1572
// Augment gadget reports.
1576
1573
for (auto &Report : Reports) {
1577
1574
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));
1579
1576
assert (Report.RequestedDetails &&
1580
1577
" Should be removed by handleSimpleReports" );
1581
1578
auto DetailedInfo =
@@ -1593,7 +1590,7 @@ void FunctionAnalysisContext::findUnsafeDefs(
1593
1590
return ;
1594
1591
1595
1592
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 " );
1597
1594
Analysis->run ();
1598
1595
LLVM_DEBUG ({
1599
1596
dbgs () << " After dst register safety analysis:\n " ;
@@ -1616,8 +1613,7 @@ void FunctionAnalysisContext::augmentUnsafeDefReports(
1616
1613
SmallVector<MCPhysReg> RegsToTrack = collectRegsToTrack (Reports);
1617
1614
// Re-compute the analysis with register tracking.
1618
1615
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 " );
1621
1617
Analysis->run ();
1622
1618
LLVM_DEBUG ({
1623
1619
dbgs () << " After detailed dst register safety analysis:\n " ;
@@ -1627,7 +1623,7 @@ void FunctionAnalysisContext::augmentUnsafeDefReports(
1627
1623
// Augment gadget reports.
1628
1624
for (auto &Report : Reports) {
1629
1625
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));
1631
1627
assert (Report.RequestedDetails &&
1632
1628
" Should be removed by handleSimpleReports" );
1633
1629
auto DetailedInfo = std::make_shared<LeakageInfo>(
@@ -1760,8 +1756,7 @@ static void printRelatedInstrs(raw_ostream &OS, const MCInstReference Location,
1760
1756
// Sort the references to make output deterministic.
1761
1757
SmallVector<MCInstReference> RI (RelatedInstrs);
1762
1758
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)) {
1765
1760
OS << " " << (I + 1 ) << " . " ;
1766
1761
BC.printInstruction (OS, InstRef, getAddress (InstRef), &BF);
1767
1762
};
0 commit comments