GenericCloner: Generate a valid debug location if no decl is available for a SILArgument

Without this we used to crash in a test case in IRGen trying to generate code
for an invalid debug location.

rdar://87565600
This commit is contained in:
Arnold Schwaighofer
2022-01-18 13:45:56 -08:00
parent dc0ab28ec5
commit 2bc8ad27e3
2 changed files with 35 additions and 1 deletions

View File

@@ -72,7 +72,9 @@ void GenericCloner::populateCloned() {
SmallVector<SILValue, 4> entryArgs;
entryArgs.reserve(OrigEntryBB->getArguments().size());
for (auto &OrigArg : OrigEntryBB->getArguments()) {
RegularLocation Loc((Decl *)OrigArg->getDecl());
RegularLocation Loc = OrigArg->getDecl() ?
RegularLocation((Decl *)OrigArg->getDecl()) :
RegularLocation::getAutoGeneratedLocation();
AllocStackInst *ASI = nullptr;
SILType mappedType = remapType(OrigArg->getType());

View File

@@ -0,0 +1,32 @@
// RUN: %target-swift-frontend %s -O -enable-library-evolution -emit-ir -g
// REQUIRES: objc_interop
import Foundation
public struct MyThing {}
public struct ThingSequence: Sequence, IteratorProtocol {
private var enumerator: NSEnumerator?
public init() { }
public mutating func next() -> MyThing? {
guard let enumerator = enumerator else { return nil }
guard let nextObject = enumerator.nextObject(),
let nextThing = nextObject as? MyThing else {
self.enumerator = nil
return nil
}
return nextThing
}
}
public struct Manager {
public func sequence() -> ThingSequence {
ThingSequence()
}
}
public func test(m: Manager) {
for _ in m.sequence() { }
}