Skip to content

Commit d40fa08

Browse files
authored
Merge pull request #70518 from eeckstein/fix-forwarding-instruction
SwiftCompilerSources: bridge_object_to_word is not a ForwardingInstruction
2 parents c1af52c + 84e0632 commit d40fa08

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,7 @@ final public class RefToBridgeObjectInst : SingleValueInstruction, ForwardingIns
841841
final public class BridgeObjectToRefInst : SingleValueInstruction,
842842
ConversionInstruction {}
843843

844-
final public class BridgeObjectToWordInst : SingleValueInstruction,
845-
ConversionInstruction {}
844+
final public class BridgeObjectToWordInst : SingleValueInstruction {}
846845

847846
public typealias AccessKind = BridgedInstruction.AccessKind
848847

include/swift/SIL/SILBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct OptionalBridgedBasicBlock;
4646
namespace swift {
4747
class ValueBase;
4848
class Operand;
49+
class ForwardingInstruction;
4950
class SILFunction;
5051
class SILBasicBlock;
5152
class SILSuccessor;
@@ -564,6 +565,7 @@ struct BridgedInstruction {
564565
// Instruction protocols
565566
// =========================================================================//
566567

568+
BRIDGED_INLINE swift::ForwardingInstruction * _Nonnull getAsForwardingInstruction() const;
567569
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedOperand ForwardingInst_singleForwardedOperand() const;
568570
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedOperandArray ForwardingInst_forwardedOperands() const;
569571
BRIDGED_INLINE BridgedValue::Ownership ForwardingInst_forwardingOwnership() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,12 @@ BridgedSuccessorArray BridgedInstruction::TermInst_getSuccessors() const {
702702
return {{successors.data()}, (SwiftInt)successors.size()};
703703
}
704704

705+
swift::ForwardingInstruction * _Nonnull BridgedInstruction::getAsForwardingInstruction() const {
706+
auto *forwardingInst = swift::ForwardingInstruction::get(unbridged());
707+
assert(forwardingInst && "instruction is not defined as ForwardingInstruction");
708+
return forwardingInst;
709+
}
710+
705711
OptionalBridgedOperand BridgedInstruction::ForwardingInst_singleForwardedOperand() const {
706712
return {swift::ForwardingOperation(unbridged()).getSingleForwardingOperand()};
707713
}
@@ -713,17 +719,15 @@ BridgedOperandArray BridgedInstruction::ForwardingInst_forwardedOperands() const
713719
}
714720

715721
BridgedValue::Ownership BridgedInstruction::ForwardingInst_forwardingOwnership() const {
716-
auto *forwardingInst = swift::ForwardingInstruction::get(unbridged());
717-
return castOwnership(forwardingInst->getForwardingOwnershipKind());
722+
return castOwnership(getAsForwardingInstruction()->getForwardingOwnershipKind());
718723
}
719724

720725
void BridgedInstruction::ForwardingInst_setForwardingOwnership(BridgedValue::Ownership ownership) const {
721-
auto *forwardingInst = swift::ForwardingInstruction::get(unbridged());
722-
return forwardingInst->setForwardingOwnershipKind(BridgedValue::castToOwnership(ownership));
726+
return getAsForwardingInstruction()->setForwardingOwnershipKind(BridgedValue::castToOwnership(ownership));
723727
}
724728

725729
bool BridgedInstruction::ForwardingInst_preservesOwnership() const {
726-
return swift::ForwardingInstruction::get(unbridged())->preservesOwnership();
730+
return getAsForwardingInstruction()->preservesOwnership();
727731
}
728732

729733
BridgedStringRef BridgedInstruction::CondFailInst_getMessage() const {

test/SILOptimizer/simplify_begin_borrow.sil

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,20 @@ bb0(%0 : @owned $S2):
220220
return %7 : $()
221221
}
222222

223+
// CHECK-LABEL: sil [ossa] @dont_crash_on_bridge_object_to_word :
224+
// CHECK: bb0(%0 : @owned $Builtin.BridgeObject):
225+
// CHECK-NEXT: destroy_value %0
226+
// CHECK: } // end sil function 'dont_crash_on_bridge_object_to_word'
227+
sil [ossa] @dont_crash_on_bridge_object_to_word : $@convention(thin) (@owned Builtin.BridgeObject) -> () {
228+
bb0(%0 : @owned $Builtin.BridgeObject):
229+
%1 = begin_borrow %0 : $Builtin.BridgeObject
230+
%2 = bridge_object_to_word %1 : $Builtin.BridgeObject to $Builtin.Word
231+
end_borrow %1 : $Builtin.BridgeObject
232+
destroy_value %0: $Builtin.BridgeObject
233+
%6 = tuple ()
234+
return %6 : $()
235+
}
236+
223237
// CHECK-LABEL: sil [ossa] @dont_replace_tuple_extract :
224238
// CHECK: begin_borrow
225239
// CHECK: } // end sil function 'dont_replace_tuple_extract'

0 commit comments

Comments
 (0)