File tree Expand file tree Collapse file tree 2 files changed +48
-3
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 2 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -1090,9 +1090,19 @@ static SILBasicBlock *getTrampolineDest(SILBasicBlock *SBB) {
1090
1090
if (!BI)
1091
1091
return nullptr ;
1092
1092
1093
- // Disallow infinite loops.
1094
- if (BI->getDestBB () == SBB)
1095
- return nullptr ;
1093
+ // Disallow infinite loops through SBB.
1094
+ llvm::SmallPtrSet<SILBasicBlock *, 8 > VisitedBBs;
1095
+ BranchInst *NextBI = BI;
1096
+ do {
1097
+ SILBasicBlock *NextBB = NextBI->getDestBB ();
1098
+ // We don't care about infinite loops after SBB.
1099
+ if (!VisitedBBs.insert (NextBB).second )
1100
+ break ;
1101
+ // Only if the infinite loop goes through SBB directly we bail.
1102
+ if (NextBB == SBB)
1103
+ return nullptr ;
1104
+ NextBI = dyn_cast<BranchInst>(NextBB->getTerminator ());
1105
+ } while (NextBI);
1096
1106
1097
1107
auto BrArgs = BI->getArgs ();
1098
1108
if (BrArgs.size () != SBB->getNumArguments ())
Original file line number Diff line number Diff line change @@ -2859,3 +2859,38 @@ bb5(%e : $MyError):
2859
2859
bb6(%44 : $Builtin.Int8):
2860
2860
return %44 : $Builtin.Int8
2861
2861
}
2862
+
2863
+ // CHECK-LABEL: sil @dont_hang
2864
+ // CHECK: bb6:
2865
+ // CHECK: integer_literal $Builtin.Int64, 1
2866
+ // CHECK-NEXT: br bb5
2867
+ // CHECK-NEXT: }
2868
+ sil @dont_hang : $@convention(thin) () -> () {
2869
+ bb0:
2870
+ cond_br undef, bb1, bb4
2871
+
2872
+ bb1:
2873
+ %0 = integer_literal $Builtin.Int64, 1
2874
+ cond_br undef, bb2, bb6
2875
+
2876
+ bb2:
2877
+ br bb3
2878
+
2879
+ bb3:
2880
+ br bb5
2881
+
2882
+ bb4:
2883
+ %1 = integer_literal $Builtin.Int64, 1
2884
+ br bb3
2885
+
2886
+ bb5:
2887
+ br bb2
2888
+
2889
+ bb6:
2890
+ %2 = integer_literal $Builtin.Int64, 1
2891
+ br bb7
2892
+
2893
+ bb7:
2894
+ br bb5
2895
+ }
2896
+
You can’t perform that action at this time.
0 commit comments