Skip to content

Commit 054959b

Browse files
committed
SIL: verify forwarding conformances
Verify that the C++ view of forwarding instructions agrees with the swift ForwardInstruction conformances.
1 parent 960956c commit 054959b

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/Verifier.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ extension Function {
2727
func verify(_ context: FunctionPassContext) {
2828
for block in blocks {
2929
for inst in block.instructions {
30+
31+
inst.checkForwardingConformance()
32+
3033
if let verifyableInst = inst as? VerifyableInstruction {
3134
verifyableInst.verify(context)
3235
}
@@ -35,6 +38,16 @@ extension Function {
3538
}
3639
}
3740

41+
private extension Instruction {
42+
func checkForwardingConformance() {
43+
if bridged.shouldBeForwarding() {
44+
require(self is ForwardingInstruction, "instruction \(self)\nshould conform to ForwardingInstruction")
45+
} else {
46+
require(!(self is ForwardingInstruction), "instruction \(self)\nshould not conform to ForwardingInstruction")
47+
}
48+
}
49+
}
50+
3851
func registerVerifier() {
3952
BridgedUtilities.registerVerifier(
4053
{ (bridgedCtxt: BridgedPassContext, bridgedFunction: BridgedFunction) in

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ struct BridgedInstruction {
770770
bool mayLoadWeakOrUnowned() const;
771771
bool maySynchronize() const;
772772
bool mayBeDeinitBarrierNotConsideringSideEffects() const;
773+
BRIDGED_INLINE bool shouldBeForwarding() const;
773774

774775
// =========================================================================//
775776
// Generalized instruction subclasses

include/swift/SIL/SILBridgingImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,12 @@ bool BridgedInstruction::maySuspend() const {
846846
return unbridged()->maySuspend();
847847
}
848848

849+
bool BridgedInstruction::shouldBeForwarding() const {
850+
return llvm::isa<swift::OwnershipForwardingSingleValueInstruction>(unbridged()) ||
851+
llvm::isa<swift::OwnershipForwardingTermInst>(unbridged()) ||
852+
llvm::isa<swift::OwnershipForwardingMultipleValueInstruction>(unbridged());
853+
}
854+
849855
SwiftInt BridgedInstruction::MultipleValueInstruction_getNumResults() const {
850856
return getAs<swift::MultipleValueInstruction>()->getNumResults();
851857
}

0 commit comments

Comments
 (0)