Skip to content

Commit

Permalink
Fix a crash when serializing variadic generic tuple code under -wmo
Browse files Browse the repository at this point in the history
It seems really unfortunate that we use SILCloner to, basically,
implement a recursive visitor of the types used in a SIL function,
but apparently it's what we do.

Fixes apple#72117.
  • Loading branch information
rjmccall committed Apr 11, 2024
1 parent c531f29 commit 82d9e4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions include/swift/SIL/SILCloner.h
Expand Up @@ -293,14 +293,18 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
continue;
}

// Substitute the shape class of the expansion.
// Substitute the shape class of the expansion. If this doesn't
// give us a pack (e.g. if this isn't a substituting clone),
// we're never erasing tuple structure.
auto newShapeClass = getOpASTType(expansion.getCountType());
auto newShapePack = dyn_cast<PackType>(newShapeClass);
if (!newShapePack)
return false;

// If the element has a name, then the tuple sticks around unless
// the expansion disappears completely.
if (type->getElement(index).hasName()) {
if (newShapePack && newShapePack->getNumElements() == 0)
if (newShapePack->getNumElements() == 0)
continue;
return false;
}
Expand Down
10 changes: 10 additions & 0 deletions test/SILOptimizer/Inputs/cross-module/cross-module.swift
Expand Up @@ -295,3 +295,13 @@ public func getEmptySet() -> Set<Int> {
return Set()
}

public protocol Visitable {
func visit()
}
@available(SwiftStdlib 6.0, *)
public struct S<each T : Visitable> {
var storage: (repeat each T)
public func visit() {
_ = (repeat (each storage).visit())
}
}

0 comments on commit 82d9e4c

Please sign in to comment.