Skip to content

Commit 994d30a

Browse files
Merge pull request swiftlang#67493 from nate-chandler/rdar112792831
[IRGen] Add metadata pack markers for destroys.
2 parents ccd6407 + 3f069df commit 994d30a

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2653,6 +2653,10 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
26532653
llvm::report_fatal_error(
26542654
"Instruction resulted in on-stack pack metadata emission but no "
26552655
"cleanup instructions were added");
2656+
// The markers which indicate where on-stack pack metadata should be
2657+
// deallocated were not inserted for I. To fix this, add I's opcode to
2658+
// SILInstruction::mayRequirePackMetadata subject to the appropriate
2659+
// checks.
26562660
}
26572661
}
26582662
#endif

lib/SIL/IR/SILInstruction.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,18 +1296,18 @@ bool SILInstruction::mayRequirePackMetadata() const {
12961296
}
12971297
return false;
12981298
}
1299-
case SILInstructionKind::DebugValueInst: {
1300-
auto *dvi = cast<DebugValueInst>(this);
1301-
return dvi->getOperand()->getType().hasPack();
1299+
case SILInstructionKind::ClassMethodInst:
1300+
case SILInstructionKind::DebugValueInst:
1301+
case SILInstructionKind::DestroyAddrInst:
1302+
case SILInstructionKind::DestroyValueInst:
1303+
// Unary instructions.
1304+
{
1305+
return getOperand(0)->getType().hasPack();
13021306
}
13031307
case SILInstructionKind::MetatypeInst: {
13041308
auto *mi = cast<MetatypeInst>(this);
13051309
return mi->getType().hasPack();
13061310
}
1307-
case SILInstructionKind::ClassMethodInst: {
1308-
auto *cmi = cast<ClassMethodInst>(this);
1309-
return cmi->getOperand()->getType().hasPack();
1310-
}
13111311
case SILInstructionKind::WitnessMethodInst: {
13121312
auto *wmi = cast<WitnessMethodInst>(this);
13131313
auto ty = wmi->getLookupType();

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)