diff --git a/lib/SILOptimizer/Utils/GenericCloner.cpp b/lib/SILOptimizer/Utils/GenericCloner.cpp index 7a0c8385de5..515d23e9a59 100644 --- a/lib/SILOptimizer/Utils/GenericCloner.cpp +++ b/lib/SILOptimizer/Utils/GenericCloner.cpp @@ -72,7 +72,9 @@ void GenericCloner::populateCloned() { SmallVector 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()); diff --git a/test/DebugInfo/generic-specializer.swift b/test/DebugInfo/generic-specializer.swift new file mode 100644 index 00000000000..0fc415f52a0 --- /dev/null +++ b/test/DebugInfo/generic-specializer.swift @@ -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() { } +}