diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index 5322a078797ff..f4e5c146a6eff 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -2653,6 +2653,10 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) { llvm::report_fatal_error( "Instruction resulted in on-stack pack metadata emission but no " "cleanup instructions were added"); + // The markers which indicate where on-stack pack metadata should be + // deallocated were not inserted for I. To fix this, add I's opcode to + // SILInstruction::mayRequirePackMetadata subject to the appropriate + // checks. } } #endif diff --git a/lib/SIL/IR/SILInstruction.cpp b/lib/SIL/IR/SILInstruction.cpp index ed6d6c128d541..086e728907418 100644 --- a/lib/SIL/IR/SILInstruction.cpp +++ b/lib/SIL/IR/SILInstruction.cpp @@ -1296,18 +1296,18 @@ bool SILInstruction::mayRequirePackMetadata() const { } return false; } - case SILInstructionKind::DebugValueInst: { - auto *dvi = cast(this); - return dvi->getOperand()->getType().hasPack(); + case SILInstructionKind::ClassMethodInst: + case SILInstructionKind::DebugValueInst: + case SILInstructionKind::DestroyAddrInst: + case SILInstructionKind::DestroyValueInst: + // Unary instructions. + { + return getOperand(0)->getType().hasPack(); } case SILInstructionKind::MetatypeInst: { auto *mi = cast(this); return mi->getType().hasPack(); } - case SILInstructionKind::ClassMethodInst: { - auto *cmi = cast(this); - return cmi->getOperand()->getType().hasPack(); - } case SILInstructionKind::WitnessMethodInst: { auto *wmi = cast(this); auto ty = wmi->getLookupType(); diff --git a/test/IRGen/rdar112792831.swift b/test/IRGen/rdar112792831.swift new file mode 100644 index 0000000000000..dcbb0c6a72b72 --- /dev/null +++ b/test/IRGen/rdar112792831.swift @@ -0,0 +1,41 @@ +// RUN: %target-swift-frontend -emit-ir -O %s + +@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) +public struct Predicate { + var x: Any? = nil + public func evaluate(_: repeat each Input) -> Bool { return false } +} + +public struct PredicateBindings { +} + +@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) +public protocol PredicateExpression { + associatedtype Output + + func evaluate(_ bindings: PredicateBindings) throws -> Output +} + +@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) +public struct PredicateEvaluate< + Condition : PredicateExpression, + each Input : PredicateExpression +> +where + Condition.Output == Predicate +{ + + public typealias Output = Bool + + public let predicate: Condition + public let input: (repeat each Input) + + public init(predicate: Condition, input: repeat each Input) { + self.predicate = predicate + self.input = (repeat each input) + } + + public func evaluate(_ bindings: PredicateBindings) throws -> Output { + try predicate.evaluate(bindings).evaluate(repeat (each input).evaluate(bindings)) + } +}