@@ -721,48 +721,40 @@ void JumpScopeChecker::VerifyIndirectOrAsmJumps(bool IsAsmGoto) {
721
721
// If there aren't any address-of-label expressions in this function,
722
722
// complain about the first indirect goto.
723
723
if (JumpTargets.empty ()) {
724
- assert (!IsAsmGoto &&" only indirect goto can get here" );
724
+ assert (!IsAsmGoto && " only indirect goto can get here" );
725
725
S.Diag (GotoJumps[0 ]->getBeginLoc (),
726
726
diag::err_indirect_goto_without_addrlabel);
727
727
return ;
728
728
}
729
729
// Collect a single representative of every scope containing an
730
730
// indirect or asm goto. For most code bases, this substantially cuts
731
731
// down on the number of jump sites we'll have to consider later.
732
- typedef std::pair<unsigned , Stmt*> JumpScope ;
732
+ using JumpScope = std::pair<unsigned , Stmt *> ;
733
733
SmallVector<JumpScope, 32 > JumpScopes;
734
734
{
735
735
llvm::DenseMap<unsigned , Stmt*> JumpScopesMap;
736
- for (SmallVectorImpl<Stmt *>::iterator I = GotoJumps.begin (),
737
- E = GotoJumps.end ();
738
- I != E; ++I) {
739
- Stmt *IG = *I;
736
+ for (Stmt *IG : GotoJumps) {
740
737
if (CHECK_PERMISSIVE (!LabelAndGotoScopes.count (IG)))
741
738
continue ;
742
739
unsigned IGScope = LabelAndGotoScopes[IG];
743
- Stmt *&Entry = JumpScopesMap[ IGScope];
744
- if (!Entry) Entry = IG;
740
+ if (! JumpScopesMap. contains ( IGScope))
741
+ JumpScopesMap[IGScope] = IG;
745
742
}
746
743
JumpScopes.reserve (JumpScopesMap.size ());
747
- for (llvm::DenseMap<unsigned , Stmt *>::iterator I = JumpScopesMap.begin (),
748
- E = JumpScopesMap.end ();
749
- I != E; ++I)
750
- JumpScopes.push_back (*I);
744
+ for (auto &Pair : JumpScopesMap)
745
+ JumpScopes.emplace_back (Pair);
751
746
}
752
747
753
748
// Collect a single representative of every scope containing a
754
749
// label whose address was taken somewhere in the function.
755
750
// For most code bases, there will be only one such scope.
756
751
llvm::DenseMap<unsigned , LabelDecl*> TargetScopes;
757
- for (SmallVectorImpl<LabelDecl *>::iterator I = JumpTargets.begin (),
758
- E = JumpTargets.end ();
759
- I != E; ++I) {
760
- LabelDecl *TheLabel = *I;
752
+ for (LabelDecl *TheLabel : JumpTargets) {
761
753
if (CHECK_PERMISSIVE (!LabelAndGotoScopes.count (TheLabel->getStmt ())))
762
754
continue ;
763
755
unsigned LabelScope = LabelAndGotoScopes[TheLabel->getStmt ()];
764
- LabelDecl *&Target = TargetScopes[ LabelScope];
765
- if (!Target) Target = TheLabel;
756
+ if (! TargetScopes. contains ( LabelScope))
757
+ TargetScopes[LabelScope] = TheLabel;
766
758
}
767
759
768
760
// For each target scope, make sure it's trivially reachable from
@@ -774,11 +766,7 @@ void JumpScopeChecker::VerifyIndirectOrAsmJumps(bool IsAsmGoto) {
774
766
// entered, then verify that every jump scope can be trivially
775
767
// exitted to reach a scope in S.
776
768
llvm::BitVector Reachable (Scopes.size (), false );
777
- for (llvm::DenseMap<unsigned ,LabelDecl*>::iterator
778
- TI = TargetScopes.begin (), TE = TargetScopes.end (); TI != TE; ++TI) {
779
- unsigned TargetScope = TI->first ;
780
- LabelDecl *TargetLabel = TI->second ;
781
-
769
+ for (auto [TargetScope, TargetLabel] : TargetScopes) {
782
770
Reachable.reset ();
783
771
784
772
// Mark all the enclosing scopes from which you can safely jump
@@ -799,10 +787,8 @@ void JumpScopeChecker::VerifyIndirectOrAsmJumps(bool IsAsmGoto) {
799
787
800
788
// Walk through all the jump sites, checking that they can trivially
801
789
// reach this label scope.
802
- for (SmallVectorImpl<JumpScope>::iterator
803
- I = JumpScopes.begin (), E = JumpScopes.end (); I != E; ++I) {
804
- unsigned Scope = I->first ;
805
-
790
+ for (auto [JumpScope, JumpStmt] : JumpScopes) {
791
+ unsigned Scope = JumpScope;
806
792
// Walk out the "scope chain" for this scope, looking for a scope
807
793
// we've marked reachable. For well-formed code this amortizes
808
794
// to O(JumpScopes.size() / Scopes.size()): we only iterate
@@ -813,7 +799,7 @@ void JumpScopeChecker::VerifyIndirectOrAsmJumps(bool IsAsmGoto) {
813
799
if (Reachable.test (Scope)) {
814
800
// If we find something reachable, mark all the scopes we just
815
801
// walked through as reachable.
816
- for (unsigned S = I-> first ; S != Scope; S = Scopes[S].ParentScope )
802
+ for (unsigned S = JumpScope ; S != Scope; S = Scopes[S].ParentScope )
817
803
Reachable.set (S);
818
804
IsReachable = true ;
819
805
break ;
@@ -832,7 +818,7 @@ void JumpScopeChecker::VerifyIndirectOrAsmJumps(bool IsAsmGoto) {
832
818
// Only diagnose if we didn't find something.
833
819
if (IsReachable) continue ;
834
820
835
- DiagnoseIndirectOrAsmJump (I-> second , I-> first , TargetLabel, TargetScope);
821
+ DiagnoseIndirectOrAsmJump (JumpStmt, JumpScope , TargetLabel, TargetScope);
836
822
}
837
823
}
838
824
}
0 commit comments