@@ -232,12 +232,11 @@ struct SrcState {
232232  bool  operator !=(const  SrcState &RHS) const  { return  !((*this ) == RHS); }
233233};
234234
235- static  void 
236- printLastInsts (raw_ostream &OS,
237-                ArrayRef<SmallPtrSet<const  MCInst *, 4 >> LastInstWritingReg) {
235+ static  void  printInstsShort (raw_ostream &OS,
236+                             ArrayRef<SmallPtrSet<const  MCInst *, 4 >> Insts) {
238237  OS << " Insts: " 
239-   for  (unsigned  I = 0 ; I < LastInstWritingReg .size (); ++I) {
240-     auto  &Set = LastInstWritingReg [I];
238+   for  (unsigned  I = 0 ; I < Insts .size (); ++I) {
239+     auto  &Set = Insts [I];
241240    OS << " [" " ](" 
242241    for  (const  MCInst *MCInstP : Set)
243242      OS << MCInstP << "  " 
@@ -252,7 +251,7 @@ raw_ostream &operator<<(raw_ostream &OS, const SrcState &S) {
252251  } else  {
253252    OS << " SafeToDerefRegs: " SafeToDerefRegs  << " , " 
254253    OS << " TrustedRegs: " TrustedRegs  << " , " 
255-     printLastInsts (OS, S.LastInstWritingReg );
254+     printInstsShort (OS, S.LastInstWritingReg );
256255  }
257256  OS << " >" 
258257  return  OS;
@@ -281,7 +280,7 @@ void SrcStatePrinter::print(raw_ostream &OS, const SrcState &S) const {
281280    OS << " , TrustedRegs: " 
282281    RegStatePrinter.print (OS, S.TrustedRegs );
283282    OS << " , " 
284-     printLastInsts (OS, S.LastInstWritingReg );
283+     printInstsShort (OS, S.LastInstWritingReg );
285284  }
286285  OS << " >" 
287286}
@@ -752,7 +751,7 @@ SrcSafetyAnalysis::create(BinaryFunction &BF,
752751struct  DstState  {
753752  // / The set of registers whose values cannot be inspected by an attacker in
754753  // / a way usable as an authentication oracle. The results of authentication
755-   // / instructions should be written to such registers.
754+   // / instructions should only  be written to such registers.
756755  BitVector CannotEscapeUnchecked;
757756
758757  std::vector<SmallPtrSet<const  MCInst *, 4 >> FirstInstLeakingReg;
@@ -770,6 +769,9 @@ struct DstState {
770769      return  (*this  = StateIn);
771770
772771    CannotEscapeUnchecked &= StateIn.CannotEscapeUnchecked ;
772+     for  (unsigned  I = 0 ; I < FirstInstLeakingReg.size (); ++I)
773+       for  (const  MCInst *J : StateIn.FirstInstLeakingReg [I])
774+         FirstInstLeakingReg[I].insert (J);
773775    return  *this ;
774776  }
775777
@@ -778,7 +780,8 @@ struct DstState {
778780  bool  empty () const  { return  CannotEscapeUnchecked.empty (); }
779781
780782  bool  operator ==(const  DstState &RHS) const  {
781-     return  CannotEscapeUnchecked == RHS.CannotEscapeUnchecked ;
783+     return  CannotEscapeUnchecked == RHS.CannotEscapeUnchecked  &&
784+            FirstInstLeakingReg == RHS.FirstInstLeakingReg ;
782785  }
783786  bool  operator !=(const  DstState &RHS) const  { return  !((*this ) == RHS); }
784787};
@@ -788,7 +791,8 @@ raw_ostream &operator<<(raw_ostream &OS, const DstState &S) {
788791  if  (S.empty ()) {
789792    OS << " empty" 
790793  } else  {
791-     OS << " CannotEscapeUnchecked: " CannotEscapeUnchecked ;
794+     OS << " CannotEscapeUnchecked: " CannotEscapeUnchecked  << " , " 
795+     printInstsShort (OS, S.FirstInstLeakingReg );
792796  }
793797  OS << " >" 
794798  return  OS;
@@ -808,10 +812,13 @@ void DstStatePrinter::print(raw_ostream &OS, const DstState &S) const {
808812  OS << " dst-state<" 
809813  if  (S.empty ()) {
810814    assert (S.CannotEscapeUnchecked .empty ());
815+     assert (S.FirstInstLeakingReg .empty ());
811816    OS << " empty" 
812817  } else  {
813818    OS << " CannotEscapeUnchecked: " 
814819    RegStatePrinter.print (OS, S.CannotEscapeUnchecked );
820+     OS << " , " 
821+     printInstsShort (OS, S.FirstInstLeakingReg );
815822  }
816823  OS << " >" 
817824}
@@ -841,6 +848,7 @@ class DstSafetyAnalysis {
841848  const  unsigned  NumRegs;
842849
843850  const  TrackedRegisters RegsToTrackInstsFor;
851+ 
844852  // / Stores information about the detected instruction sequences emitted to
845853  // / check an authenticated pointer. Specifically, if such sequence is detected
846854  // / in a basic block, it maps the first instruction of that sequence to the
@@ -897,7 +905,6 @@ class DstSafetyAnalysis {
897905                                              const  BitVector &LeakedRegs,
898906                                              const  DstState &Cur) const  {
899907    SmallVector<MCPhysReg> Regs;
900-     const  MCPhysReg NoReg = BC.MIB ->getNoRegister ();
901908
902909    //  A pointer can be checked, or
903910    if  (auto  CheckedReg =
@@ -911,7 +918,7 @@ class DstSafetyAnalysis {
911918      bool  IsAuthenticated;
912919      MCPhysReg BranchDestReg =
913920          BC.MIB ->getRegUsedAsIndirectBranchDest (Inst, IsAuthenticated);
914-       assert (BranchDestReg != NoReg );
921+       assert (BranchDestReg != BC. MIB -> getNoRegister () );
915922      if  (!IsAuthenticated)
916923        Regs.push_back (BranchDestReg);
917924    }
0 commit comments