Skip to content

Commit 050d371

Browse files
committed
[IRGen] Add metadata pack markers for destroys.
Destroys of values whose types feature a pack may require allocating the pack on-stack. Thanks to @slavapestov for the test case. rdar://112792831
1 parent bd9daae commit 050d371

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,6 +2645,10 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
26452645
llvm::report_fatal_error(
26462646
"Instruction resulted in on-stack pack metadata emission but no "
26472647
"cleanup instructions were added");
2648+
// The markers which indicate where on-stack pack metadata should be
2649+
// deallocated were not inserted for I. To fix this, add I's opcode to
2650+
// SILInstruction::mayRequirePackMetadata subject to the appropriate
2651+
// checks.
26482652
}
26492653
}
26502654
#endif

lib/SIL/IR/SILInstruction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,8 @@ bool SILInstruction::mayRequirePackMetadata() const {
13161316
}
13171317
case SILInstructionKind::ClassMethodInst:
13181318
case SILInstructionKind::DebugValueInst:
1319+
case SILInstructionKind::DestroyAddrInst:
1320+
case SILInstructionKind::DestroyValueInst:
13191321
// Unary instructions.
13201322
{
13211323
return getOperand(0)->getType().hasPack();

test/IRGen/rdar112792831.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: %target-swift-frontend -emit-ir -O %s
2+
3+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
4+
public struct Predicate<each Input> {
5+
var x: Any? = nil
6+
public func evaluate(_: repeat each Input) -> Bool { return false }
7+
}
8+
9+
public struct PredicateBindings {
10+
}
11+
12+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
13+
public protocol PredicateExpression<Output> {
14+
associatedtype Output
15+
16+
func evaluate(_ bindings: PredicateBindings) throws -> Output
17+
}
18+
19+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
20+
public struct PredicateEvaluate<
21+
Condition : PredicateExpression,
22+
each Input : PredicateExpression
23+
>
24+
where
25+
Condition.Output == Predicate<repeat (each Input).Output>
26+
{
27+
28+
public typealias Output = Bool
29+
30+
public let predicate: Condition
31+
public let input: (repeat each Input)
32+
33+
public init(predicate: Condition, input: repeat each Input) {
34+
self.predicate = predicate
35+
self.input = (repeat each input)
36+
}
37+
38+
public func evaluate(_ bindings: PredicateBindings) throws -> Output {
39+
try predicate.evaluate(bindings).evaluate(repeat (each input).evaluate(bindings))
40+
}
41+
}

0 commit comments

Comments
 (0)