Skip to content

Commit cbba008

Browse files
authored
Merge pull request #79835 from eeckstein/fix-generic-specializer
GenericSpecializer: avoid an infinite loop when looking up GenericSpecializationInformation
2 parents accd108 + 43cb79d commit cbba008

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

include/swift/SIL/SILCloner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3625,8 +3625,8 @@ template <typename ImplClass>
36253625
void SILCloner<ImplClass>::visitKeyPathInst(KeyPathInst *Inst) {
36263626
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
36273627
SmallVector<SILValue, 4> opValues;
3628-
for (auto &op : Inst->getAllOperands())
3629-
opValues.push_back(getOpValue(op.get()));
3628+
for (Operand *op : Inst->getRealOperands())
3629+
opValues.push_back(getOpValue(op->get()));
36303630

36313631
recordClonedInstruction(Inst,
36323632
getBuilder().createKeyPath(

lib/SIL/IR/SILInstructions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3176,7 +3176,7 @@ KeyPathInst::create(SILDebugLocation Loc,
31763176
ArrayRef<SILValue> Args,
31773177
SILType Ty,
31783178
SILFunction &F) {
3179-
assert(Args.size() == Pattern->getNumOperands()
3179+
ASSERT(Args.size() == Pattern->getNumOperands()
31803180
&& "number of key path args doesn't match pattern");
31813181

31823182
SmallVector<SILValue, 8> allOperands(Args.begin(), Args.end());

lib/SILOptimizer/Utils/Generics.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ static bool createsInfiniteSpecializationLoop(ApplySite Apply) {
370370
LLVM_DEBUG(llvm::dbgs() << "Scan caller's specialization history\n");
371371
}
372372

373+
llvm::SmallSet<const GenericSpecializationInformation *, 8> visited;
374+
373375
while (CurSpecializationInfo) {
374376
LLVM_DEBUG(llvm::dbgs() << "Current caller is a specialization:\n"
375377
<< "Caller: "
@@ -385,6 +387,10 @@ static bool createsInfiniteSpecializationLoop(ApplySite Apply) {
385387
Replacement->dump(llvm::dbgs());
386388
});
387389

390+
if (!visited.insert(CurSpecializationInfo).second) {
391+
return true;
392+
}
393+
388394
if (CurSpecializationInfo->getParent() == GenericFunc) {
389395
LLVM_DEBUG(llvm::dbgs() << "Found a call graph loop, checking "
390396
"substitutions\n");

0 commit comments

Comments
 (0)