Skip to content

Commit 65e8d37

Browse files
committed
Add a madeUpdate check to createApplyWithConcreteType to prevent
infinite loop
1 parent a0fb139 commit 65e8d37

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,11 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
871871
ArgIdx < EndIdx; ++ArgIdx) {
872872
NewArgs.push_back(Apply.getArgument(ArgIdx));
873873
}
874+
875+
// Keep track of weather we made any updates at all. Otherwise, we will
876+
// have an infinite loop.
877+
bool madeUpdate = false;
878+
874879
// Transform the parameter arguments.
875880
SmallVector<ConcreteArgumentCopy, 4> concreteArgCopies;
876881
for (unsigned EndIdx = Apply.getNumArguments(); ArgIdx < EndIdx; ++ArgIdx) {
@@ -898,6 +903,7 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
898903
if (argSub) {
899904
concreteArgCopies.push_back(*argSub);
900905
NewArgs.push_back(argSub->tempArg);
906+
madeUpdate = true;
901907
} else {
902908
NewArgs.push_back(CEI.ConcreteValue);
903909
}
@@ -939,7 +945,7 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
939945
return canUpdate;
940946
}();
941947

942-
if (!canUpdateArgs) {
948+
if (!canUpdateArgs || !madeUpdate) {
943949
// Remove any new instructions created while attempting to optimize this
944950
// apply. Since the apply was never rewritten, if they aren't removed here,
945951
// they will be removed later as dead when visited by SILCombine, causing

0 commit comments

Comments
 (0)